zhangqian
2023-11-01 530fed8ec225453572d57b15c200ab062c335457
model/salesDetails.go
@@ -14,7 +14,7 @@
      Id                  int               `json:"id" gorm:"column:id;primary_key;AUTO_INCREMENT"`
      ClientId            int               `json:"clientId" gorm:"column:client_id;type:int;comment:客户id"`
      Client              Client            `json:"client" gorm:"foreignKey:ClientId"`
      Number              string            `json:"number" gorm:"column:number;type:varchar(255);comment:销售子单号"`
      Number              string            `json:"number" gorm:"column:number;type:varchar(255);comment:销售明细单号"`
      SaleChanceId        int               `json:"saleChanceId" gorm:"column:sale_chance_id;type:int;comment:销售机会id"`
      SaleChance          SaleChance        `json:"saleChance" gorm:"foreignKey:SaleChanceId"`
      SaleType            int               `json:"saleType" gorm:"column:sale_type;type:int;comment:销售类型"`
@@ -40,6 +40,9 @@
      AmountUnInvoiced    decimal.Decimal   `gorm:"column:amount_not_invoiced;type:decimal(12,2);comment:未开票金额" json:"amountUnInvoiced"` // 未开票金额
      AmountTotal         decimal.Decimal   `gorm:"column:amount_total;type:decimal(12,2);comment:价税合计" json:"amountTotal"`              // 价税合计
      CodeStandID         string            `json:"codeStandID" gorm:"column:code_stand_id;type:varchar(255);comment:编码id"`
      DeliverType         int               `json:"deliverType" gorm:"column:deliver_type;type:int;comment:交付类型(1.一次发货,2.多次发货)"`
      QuotationId         int               `json:"quotationId" gorm:"column:quotation_id;type:int;comment:报价单id"`
      Quotation           Quotation         `json:"quotation" gorm:"foreignKey:QuotationId"`
      CrmModel
   }
@@ -76,6 +79,13 @@
      db = db.Where("sale_chance_id = ?", slf.SaleChanceId)
   }
   if slf.ClientId != 0 {
      db = db.Where("client_id = ?", slf.ClientId)
   }
   if slf.Number != "" {
      db = db.Where("number = ?", slf.Number)
   }
   switch slf.KeywordType {
   case constvar.SalesDetailsKeywordTypeCustomerName:
      db = db.Joins("Client", clause.LeftJoin).Where("Client.name like ?", fmt.Sprintf("%%%s%%", slf.Keyword))
@@ -91,7 +101,7 @@
   }
   if len(slf.MemberIds) > 0 {
      db = db.Where("member_id in ?", slf.MemberIds)
      db = db.Where("sales_details.member_id in ?", slf.MemberIds)
   }
   if slf.Preload {
@@ -99,7 +109,8 @@
         Preload("Member").
         Preload("SaleChance").
         Preload("WechatOrderStatus").
         Preload("Client")
         Preload("Client").
         Preload("Quotation")
   }
   return db
@@ -126,8 +137,37 @@
   return db.Updates(record).Error
}
func (slf *SalesDetailsSearch) Count() (int64, error) {
   var db = slf.build()
   var total int64
   err := db.Count(&total).Error
   return total, err
}
func (slf *SalesDetailsSearch) MaxAutoIncr() (int, error) {
   type Result struct {
      Max int
   }
   var (
      result Result
      db     = slf.build()
   )
   err := db.Select("MAX(id) as max").Scan(&result).Error
   if err != nil {
      return result.Max, fmt.Errorf("max err: %v", err)
   }
   return result.Max, nil
}
func (slf *SalesDetailsSearch) SetId(id int) *SalesDetailsSearch {
   slf.Id = id
   return slf
}
func (slf *SalesDetailsSearch) SetClientId(clientId int) *SalesDetailsSearch {
   slf.ClientId = clientId
   return slf
}
@@ -192,6 +232,11 @@
   return slf
}
func (slf *SalesDetailsSearch) SetNumber(number string) *SalesDetailsSearch {
   slf.Number = number
   return slf
}
func (slf *SalesDetailsSearch) UpdateByMap(upMap map[string]interface{}) error {
   var (
      db = slf.build()