| | |
| | | import ( |
| | | "aps_crm/constvar" |
| | | "aps_crm/pkg/mysqlx" |
| | | "fmt" |
| | | "github.com/shopspring/decimal" |
| | | "gorm.io/gorm" |
| | | "gorm.io/gorm/clause" |
| | | ) |
| | | |
| | | type ( |
| | |
| | | SourceType constvar.RefundSourceType `gorm:"column:source_type;type:int;not null;default 0;comment:来源类型(1销售明细单2服务合同3销售发票4收款计划5出库单)" json:"sourceType"` // 来源类型(1销售明细单2服务合同3销售发票4收款计划5出库单) |
| | | SourceId int `gorm:"column:source_id;type:int;not null;default 0;comment:源单id " json:"sourceId"` // 源单id |
| | | MemberId int `json:"memberId" gorm:"column:member_id;type:int;comment:负责人id"` |
| | | Member User `json:"member" gorm:"foreignKey:MemberId"` |
| | | RefundDate string `json:"refundDate" gorm:"column:refund_date;type:datetime;comment:退款日期"` |
| | | PaymentTypeId int `gorm:"column:payment_type_id;type:int;not null;default 0;comment:收款方式ID" json:"paymentTypeId"` // 收款方式ID |
| | | PaymentType PaymentType `gorm:"foreignKey:PaymentTypeId" json:"paymentType"` |
| | |
| | | IsInvoice int `json:"isInvoice" gorm:"column:is_invoice;type:int;comment:是否开票"` |
| | | Reason string `json:"reason" gorm:"column:reason;type:varchar(255);comment:退款原因"` |
| | | Products []*Product `json:"products" gorm:"many2many:salesRefund_product;"` |
| | | gorm.Model `json:"-"` |
| | | AmountTotal decimal.Decimal `gorm:"column:amount_total;type:decimal(12,2);comment:价税合计" json:"amountTotal"` // 价税合计 |
| | | CrmModel |
| | | } |
| | | |
| | | SalesRefundSearch struct { |
| | | SalesRefund |
| | | |
| | | Orm *gorm.DB |
| | | Keyword string |
| | | OrderBy string |
| | | PageNum int |
| | | PageSize int |
| | | Orm *gorm.DB |
| | | KeywordType constvar.SalesRefundKeywordType |
| | | Keyword string |
| | | OrderBy string |
| | | PageNum int |
| | | PageSize int |
| | | Preload bool |
| | | } |
| | | ) |
| | | |
| | |
| | | |
| | | func (slf *SalesRefundSearch) build() *gorm.DB { |
| | | var db = slf.Orm.Model(&SalesRefund{}) |
| | | if slf.Keyword != "" { |
| | | db = db.Where("name LIKE ?", "%"+slf.Keyword+"%") |
| | | } |
| | | if slf.Id != 0 { |
| | | db = db.Where("id = ?", slf.Id) |
| | | } |
| | | |
| | | if slf.Preload { |
| | | db = db.Preload("Client"). |
| | | Preload("PaymentType"). |
| | | Preload("BankAccount"). |
| | | Preload("Products") |
| | | } |
| | | if slf.KeywordType != "" { |
| | | switch slf.KeywordType { |
| | | case constvar.SalesRefundKeywordRefundNumber: |
| | | db = db.Where("number like ?", fmt.Sprintf("%%%s%%", slf.Keyword)) |
| | | case constvar.SalesRefundKeywordClientName: |
| | | db = db.Joins("Client", clause.LeftJoin).Where("Client.name like ?", fmt.Sprintf("%%%s%%", slf.Keyword)) |
| | | case constvar.SalesRefundKeywordRefundDate: |
| | | db = db.Where("refund_date like ?", fmt.Sprintf("%%%s%%", slf.Keyword)) |
| | | case constvar.SalesRefundKeywordAccount: |
| | | db = db.Joins("BankAccount").Where("BankAccount name like ?", fmt.Sprintf("%%%s%%", slf.Keyword)) |
| | | case constvar.SalesRefundKeywordIsInvoice: |
| | | db = db.Where("is_invoice like ?", fmt.Sprintf("%%%s%%", slf.Keyword)) |
| | | case constvar.SalesRefundKeywordPaymentType: |
| | | db = db.Joins("PaymentType").Where("PaymentType.name like ?", fmt.Sprintf("%%%s%%", slf.Keyword)) |
| | | case constvar.SalesRefundKeywordPrincipal: |
| | | db = db.Joins("left join user on user.id = sales_refund.member_id").Where("user.username like ?", fmt.Sprintf("%%%s%%", slf.Keyword)) |
| | | case constvar.SalesRefundKeywordUpdateAt: |
| | | db = db.Where("updated_at like ?", fmt.Sprintf("%%%s%%", slf.Keyword)) |
| | | case constvar.SalesRefundKeywordPriceTotal: |
| | | db = db.Where("amount_total like ?", fmt.Sprintf("%%%s%%", slf.Keyword)) |
| | | |
| | | } |
| | | } |
| | | |
| | | return db |
| | |
| | | return slf |
| | | } |
| | | |
| | | func (slf *SalesRefundSearch) SetPreload(preload bool) *SalesRefundSearch { |
| | | slf.Preload = preload |
| | | return slf |
| | | } |
| | | |
| | | func (slf *SalesRefundSearch) SetKeywordType(keywordType constvar.SalesRefundKeywordType) *SalesRefundSearch { |
| | | slf.KeywordType = keywordType |
| | | return slf |
| | | } |
| | | |
| | | func (slf *SalesRefundSearch) SetKeyword(keyword string) *SalesRefundSearch { |
| | | slf.Keyword = keyword |
| | | return slf |