处理 GORM 0 的bug
This commit is contained in:
+41
-2
@@ -94,16 +94,53 @@ func (r *ProductService) AddProduct(userId string, req requests.AddProduct) (boo
|
||||
return false, errors.New("平台商品不存在")
|
||||
}
|
||||
|
||||
// 检测商品是否重复
|
||||
// 确定所属药房信息
|
||||
pharmacyDao := dao.PharmacyDao{}
|
||||
var pharmacyId int64 = 0
|
||||
var pharmacyCode string = ""
|
||||
|
||||
if req.PharmacyId != "" {
|
||||
pId, err := strconv.ParseInt(req.PharmacyId, 10, 64)
|
||||
if err == nil && pId >= 0 {
|
||||
pharmacyId = pId
|
||||
pharmacy, _ := pharmacyDao.GetPharmacyById(pharmacyId)
|
||||
if pharmacy != nil {
|
||||
pharmacyCode = pharmacy.PharmacyCode
|
||||
}
|
||||
}
|
||||
} else if req.PharmacyCode != "" {
|
||||
pharmacyCode = req.PharmacyCode
|
||||
pharmacy, _ := pharmacyDao.GetPharmacyByCode(pharmacyCode)
|
||||
if pharmacy != nil {
|
||||
pharmacyId = pharmacy.PharmacyId
|
||||
}
|
||||
} else if productPlatform.PharmacyCode != "" {
|
||||
pharmacyCode = productPlatform.PharmacyCode
|
||||
pharmacy, _ := pharmacyDao.GetPharmacyByCode(pharmacyCode)
|
||||
if pharmacy != nil {
|
||||
pharmacyId = pharmacy.PharmacyId
|
||||
}
|
||||
}
|
||||
|
||||
// 若仍无编码,查询对应药房编码(如默认药房 0)
|
||||
if pharmacyCode == "" {
|
||||
pharmacy, _ := pharmacyDao.GetPharmacyById(pharmacyId)
|
||||
if pharmacy != nil {
|
||||
pharmacyCode = pharmacy.PharmacyCode
|
||||
}
|
||||
}
|
||||
|
||||
// 检测同一药房下商品是否重复
|
||||
maps := make(map[string]interface{})
|
||||
maps["product_platform_id"] = req.ProductPlatformId
|
||||
maps["pharmacy_id"] = pharmacyId
|
||||
products, err := productDao.GetProductList(maps)
|
||||
if err != nil {
|
||||
return false, errors.New("商品重复添加")
|
||||
}
|
||||
|
||||
if len(products) != 0 {
|
||||
return false, errors.New("商品重复添加")
|
||||
return false, errors.New("该药房已添加此商品,请勿重复添加")
|
||||
}
|
||||
|
||||
// 处理图片
|
||||
@@ -120,6 +157,8 @@ func (r *ProductService) AddProduct(userId string, req requests.AddProduct) (boo
|
||||
// 新增商品表
|
||||
product := &model.Product{
|
||||
ProductPlatformId: productPlatform.ProductPlatformId,
|
||||
PharmacyId: pharmacyId,
|
||||
PharmacyCode: pharmacyCode,
|
||||
ProductStatus: *req.ProductStatus,
|
||||
ProductName: req.ProductName,
|
||||
CommonName: req.CommonName,
|
||||
|
||||
Reference in New Issue
Block a user