fix
liujiandao
2024-04-28 de4bcd1dead50b05f716bc5718be5540bdb96783
service/test/supplier.go
@@ -54,6 +54,10 @@
   db := global.GVA_DB.Model(&test.Supplier{})
   var ss []test.Supplier
   // 如果有条件搜索 下方会自动创建搜索语句
   if info.Keyword != "" {
      keyword := "%" + info.Keyword + "%"
      db = db.Where("name LIKE ? or number LIKE ?", keyword, keyword)
   }
   if info.StartCreatedAt != nil && info.EndCreatedAt != nil {
      db = db.Where("created_at BETWEEN ? AND ?", info.StartCreatedAt, info.EndCreatedAt)
   }
@@ -95,3 +99,30 @@
   err = global.GVA_DB.Model(&test.Supplier{}).Where("id = ?", id).Update("status", status).Error
   return err
}
func (sService *SupplierService) MaxAutoIncr() (int, error) {
   var total int64
   err := global.GVA_DB.Model(&test.Supplier{}).Count(&total).Error
   return int(total), err
}
func (sService *SupplierService) GetSupplierProduct(info testReq.SupplierProduct) ([]test.SupplierMaterial, int64, error) {
   limit := info.PageSize
   offset := info.PageSize * (info.Page - 1)
   // 创建db
   db := global.GVA_DB.Model(&test.SupplierMaterial{})
   var ps []test.SupplierMaterial
   var total int64
   if info.SupplierId > 0 {
      db = db.Where("supplier_id = ?", info.SupplierId)
   }
   if info.Number != "" {
      db = db.Where("number = ?", info.Number)
   }
   err := db.Count(&total).Error
   if err != nil {
      return ps, total, err
   }
   err = db.Limit(limit).Offset(offset).Order("id desc").Preload("Supplier").Find(&ps).Error
   return ps, total, err
}