zhangqian
2023-08-08 d5c533de0c2ccb5614ea3c600ede9c13da77e127
model/serviceContract.go
@@ -3,6 +3,8 @@
import (
   "aps_crm/constvar"
   "aps_crm/pkg/mysqlx"
   "fmt"
   "github.com/shopspring/decimal"
   "gorm.io/gorm"
   "time"
)
@@ -25,6 +27,9 @@
      ServiceTimes            int       `json:"serviceTimes" gorm:"column:service_times;type:int;comment:服务次数"`
      Terms                   string    `json:"terms" gorm:"column:terms;type:text;comment:条款"`
      Remark                  string    `json:"remark" gorm:"column:remark;type:text;comment:备注"`
      AmountReceivable        decimal.Decimal `gorm:"amount_receivable" json:"amountReceivable"` // 应收金额
      AmountReceived          decimal.Decimal `gorm:"amount_received" json:"amountReceived"`     // 已收金额
      AmountInvoiced          decimal.Decimal `gorm:"amount_invoiced" json:"amountInvoiced"`     // 已开票金额
      Products                []Product `json:"products" gorm:"many2many:serviceContract_product;"`
      gorm.Model              `json:"-"`
   }
@@ -170,3 +175,28 @@
   slf.Orm = slf.Orm.Where("id in (?)", ids)
   return slf
}
func (slf *ServiceContractSearch) UpdateByMap(upMap map[string]interface{}) error {
   var (
      db = slf.build()
   )
   if err := db.Updates(upMap).Error; err != nil {
      return fmt.Errorf("update by map err: %v, upMap: %+v", err, upMap)
   }
   return nil
}
func (slf *ServiceContractSearch) First() (*ServiceContract, error) {
   var (
      record = new(ServiceContract)
      db     = slf.build()
   )
   if err := db.First(record).Error; err != nil {
      return record, err
   }
   return record, nil
}