zhangqian
2023-11-21 3bdc6225a61aaf20583642ea5a1319109c22072e
service/test/product.go
@@ -26,6 +26,7 @@
         DeliveryTime:     p.DeliveryTime,
         ShippingDuration: p.ShippingDuration,
         Specifications:   p.Specifications,
         CategoryName:     p.CategoryName,
      })
   }
@@ -71,7 +72,7 @@
   var ps []test.SupplierMaterial
   //搜索框合一添加查询条件
   if info.Keyword != "" {
      db = db.Where("srm_supplier_material.name LIKE ?", "%"+info.Keyword+"%").Joins("srm_supplier").Or("srm_supplier.name LIKE ?", "%"+info.Keyword+"%")
      db = db.Where("`srm_supplier_material`.name LIKE ?", "%"+info.Keyword+"%").Joins("Supplier").Or("Supplier.name LIKE ?", "%"+info.Keyword+"%")
   }
   if info.Name != "" {
      db = db.Where("name LIKE ?", "%"+info.Name+"%")
@@ -105,3 +106,25 @@
   }
   return
}
// GetMaterials 获取物料
func (pService *ProductService) GetMaterials(info testReq.ProductSearch) (list []test.Material, total int64, err error) {
   limit := info.PageSize
   offset := info.PageSize * (info.Page - 1)
   // 创建db
   db := global.GVA_DB.Model(&test.Material{})
   var ps []test.Material
   if info.Keyword != "" {
      db = db.Where("name LIKE ? or number LIKE ?", "%"+info.Name+"%", "%"+info.Number+"%")
   }
   db = db.Where("purchase_type = ?", test.PurchaseTypeOutSource)
   err = db.Count(&total).Error
   if err != nil {
      return
   }
   err = db.Limit(limit).Offset(offset).Find(&ps).Error
   return ps, total, err
}