liujiandao
2023-10-24 6aa75c2a266a2522ae713b13dc702b5ad0a08f87
model/quotation.go
@@ -2,6 +2,7 @@
import (
   "aps_crm/pkg/mysqlx"
   "fmt"
   "gorm.io/gorm"
)
@@ -58,6 +59,9 @@
   var db = slf.Orm.Model(&Quotation{})
   if slf.Id != 0 {
      db = db.Where("id = ?", slf.Id)
   }
   if slf.Number != "" {
      db = db.Where("number = ?", slf.Number)
   }
   if len(slf.SearchMap) > 0 {
@@ -128,6 +132,30 @@
   return records, total, err
}
func (slf *QuotationSearch) Count() (int64, error) {
   var db = slf.build()
   var total int64
   err := db.Count(&total).Error
   return total, err
}
func (slf *QuotationSearch) 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 *QuotationSearch) SetId(id int) *QuotationSearch {
   slf.Id = id
   return slf
@@ -152,6 +180,11 @@
   slf.SearchMap = searchMap
   return slf
}
func (slf *QuotationSearch) SetNumber(number string) *QuotationSearch {
   slf.Number = number
   return slf
}
func (slf *QuotationSearch) SetIds(ids []int) *QuotationSearch {
   slf.Orm = slf.Orm.Where("id in (?)", ids)
   return slf