diff --git a/app/common/repositories/store/product/ProductRepository.php b/app/common/repositories/store/product/ProductRepository.php index dca7a090..dc3ec0c0 100644 --- a/app/common/repositories/store/product/ProductRepository.php +++ b/app/common/repositories/store/product/ProductRepository.php @@ -69,7 +69,7 @@ class ProductRepository extends BaseRepository protected $dao; const CREATE_PARAMS = [ - "image", "slider_image", "store_name", "store_info", "keyword", "bar_code", "guarantee_template_id", "cate_id", "mer_cate_id", "unit_name", "sort" , "is_show", "is_good", 'is_gift_bag', 'integral_rate', "video_link", "temp_id", "content", "spec_type", "extension_type", "attr", 'mer_labels', 'delivery_way', 'delivery_free','param_temp_id','extend', 'source_product_id', + "image", "slider_image", "store_name", "store_info", "keyword", "bar_code", "guarantee_template_id", "cate_id", "mer_cate_id", "unit_name", "sort" , "is_show", "is_good", 'is_gift_bag', 'integral_rate', "video_link", "temp_id", "content", "spec_type", "extension_type", "attr", 'mer_labels', 'delivery_way', 'delivery_free','param_temp_id','extend', 'source_product_id', 'stock_num', ["brand_id",0], ['once_max_count',0], ['once_min_count',0], diff --git a/app/controller/api/server/StoreProduct.php b/app/controller/api/server/StoreProduct.php index 2a9bdfb5..81c9264c 100644 --- a/app/controller/api/server/StoreProduct.php +++ b/app/controller/api/server/StoreProduct.php @@ -83,6 +83,8 @@ class StoreProduct extends BaseController { $res = $this->request->params($this->repository::CREATE_PARAMS); $data = $this->repository->checkParams($res,$merId); + $stockNum = $data['stock_num'] ?? 0; + unset($data['stock_num']); $data['mer_id'] = $merId; $data['is_gift_bag'] = 0; $merchant = app()->make(MerchantRepository::class)->get($merId); @@ -96,7 +98,15 @@ class StoreProduct extends BaseController }else{ $product_type=0;//普通商品 } - $this->repository->create($data, $product_type, 1); + $productId = $this->repository->create($data, $product_type, 1); + $unique = Db::name('store_product_attr_value')->where('product_id', $productId)->value('unique'); + if (!empty($unique) && $stockNum > 0) { + $this->repository->stockIn($merId, [ + 'product_id' => $productId, + 'unique' => $unique, + 'number' => $stockNum, + ]); + } return app('json')->success('添加成功'); }