Pārlūkot izejas kodu

快手商品导入限制

Ethan 1 nedēļu atpakaļ
vecāks
revīzija
2d58812b55

+ 8 - 0
app/controller/task_controller.go

@@ -58,6 +58,14 @@ func (t TaskController) CreateProduct(c *gin.Context) {
 	}
 	productId, err := service.ProductService{}.CreateProduct(data)
 	if err != nil {
+		if err.Error() == "该快手商品已存在!" {
+			returnError(c, 30010, err.Error())
+			return
+		}
+		if err.Error() == "商品主图不能为空!" {
+			returnError(c, 30020, err.Error())
+			return
+		}
 		logrus.Errorf("[CreateProduct] call CreateProduct err:%+v\n", err)
 		returnError(c, 40000, err.Error())
 		return

+ 7 - 0
app/dao/product_dao.go

@@ -127,3 +127,10 @@ func (d ProductDAO) GetProductCategorys() ([]entity.InfoProductCategory, error)
 	err := Db.Model(&entity.InfoProductCategory{}).Find(&infoProductCategorys).Order("id").Error
 	return infoProductCategorys, err
 }
+
+// 判断当前商家快手商品是否存在
+func (d ProductDAO) CheckKuaishouProduct(enterpriseId string, kuaishouProductId string) int64 {
+	var count int64
+	Db.Model(&entity.Product{}).Where("enterprise_id = ? and kuaishou_product_id = ?", enterpriseId, kuaishouProductId).Count(&count)
+	return count
+}

+ 9 - 0
app/service/product_service.go

@@ -80,6 +80,15 @@ func (p ProductService) GetTaskProductsByUserId(param vo.GetAllProductParam) (vo
 }
 
 func (p ProductService) CreateProduct(productCreateParam *vo.ProductCreateParam) (int64, error) {
+	if len(productCreateParam.ProductPhotos) == 0 {
+		return 0, errors.New("商品主图不能为空!")
+	}
+	if productCreateParam.ProductType == 1 {
+		count := dao.ProductDAO{}.CheckKuaishouProduct(productCreateParam.EnterpriseId, productCreateParam.ProductId)
+		if count > 0 {
+			return 0, errors.New("该快手商品已存在!")
+		}
+	}
 	product := entity.Product{
 		ProductType:         productCreateParam.ProductType,
 		KuaishouProductId:   productCreateParam.ProductId,