liujiandao
2023-10-17 d4bf53dd19a45ef09a367babcf7a2ac04ae1d08f
model/salesReturn.go
@@ -16,7 +16,7 @@
      Client              Client                         `json:"client" gorm:"foreignKey:ClientId"`
      SourceType          constvar.SalesReturnSourceType `gorm:"source_type" json:"sourceType"` // 源单类型(1销售明细)
      SourceId            int                            `gorm:"source_id" json:"sourceId"`     // 源单id
      Source              SalesDetails                   `gorm:"foreignKey:SourceId" json:"Source"`
      Source              SalesDetails                   `gorm:"foreignKey:SourceId" json:"source"`
      Number              string                         `json:"number" gorm:"column:number;type:varchar(255);comment:退货单号"`
      Repository          string                         `json:"repository" gorm:"column:repository;type:varchar(255);comment:仓库"`
      MemberId            int                            `json:"memberId" gorm:"column:member_id;type:int;comment:负责人id"`
@@ -31,6 +31,7 @@
      AmountShouldRefund  decimal.Decimal                `gorm:"column:amount_should_refund;type:decimal(12,2);comment:应退款金额" json:"amountShouldRefund"` // 应退款金额
      AmountHasRefund     decimal.Decimal                `gorm:"column:amount_has_refund;type:decimal(12,2);comment:已退款金额" json:"amountHasRefund"`       // 已退款金额
      AmountTotal         decimal.Decimal                `gorm:"column:amount_total;type:decimal(12,2);comment:退货产品总金额" json:"-"`
      CodeStandID         string                         `json:"codeStandID" gorm:"column:code_stand_id;type:varchar(255);comment:编码id"`
      CrmModel
   }
@@ -45,6 +46,7 @@
      PageSize    int
      Preload     bool
      Ids         []int
      MemberIds   []int
   }
)
@@ -70,7 +72,15 @@
   if len(slf.Ids) != 0 {
      db = db.Where("id in ?", slf.Ids)
   }
   if slf.SourceType != 0 {
      db = db.Where("source_type = ?", slf.SourceType)
   }
   if slf.SourceId != 0 {
      db = db.Where("source_id = ?", slf.SourceId)
   }
   if slf.ClientId != 0 {
      db = db.Where("client_id = ?", slf.ClientId)
   }
   if slf.Preload {
      db = db.Preload("Client").
         Preload("Member").
@@ -99,6 +109,10 @@
         db = db.Where("amount_has_refund = ?", slf.Keyword)
      }
   }
   if len(slf.MemberIds) > 0 {
      db = db.Where("sales_return.member_id in ?", slf.MemberIds)
   }
   return db
@@ -188,3 +202,27 @@
   slf.Preload = preload
   return slf
}
func (slf *SalesReturnSearch) SetSourceType(sourceType constvar.SalesReturnSourceType) *SalesReturnSearch {
   slf.SourceType = sourceType
   return slf
}
func (slf *SalesReturnSearch) SetSourceId(sourceId int) *SalesReturnSearch {
   slf.SourceId = sourceId
   return slf
}
func (slf *SalesReturnSearch) SetClientId(clientId int) *SalesReturnSearch {
   slf.ClientId = clientId
   return slf
}
func (slf *SalesReturnSearch) UpdateByMap(data map[string]interface{}) error {
   var db = slf.build()
   return db.Updates(data).Error
}
func (slf *SalesReturnSearch) SetMemberIds(memberIds []int) *SalesReturnSearch {
   slf.MemberIds = memberIds
   return slf
}