Ver código fonte

供货商添加花材时,所有门店一起添加

林琦海 5 anos atrás
pai
commit
578fbe5de5

+ 1 - 1
app/ghs/controllers/ItemController.php

@@ -24,7 +24,7 @@ class ItemController extends BaseController
     {
         $post = Yii::$app->request->post();
         $post['adminId'] = $this->adminId;
-        $post['shopId'] = $this->shopId;
+        // $post['shopId'] = $this->shopId;
         $post['merchantId'] = $this->sjId;
         ItemService::addGhsItem($post);
         util::complete('添加成功');

+ 14 - 4
biz-ghs/item/services/ItemService.php

@@ -9,6 +9,7 @@ namespace bizGhs\item\services;
 use bizGhs\base\services\BaseService;
 use bizGhs\item\classes\ItemClass;
 use bizGhs\item\classes\ItemClassClass;
+use bizGhs\merchant\services\ShopService;
 use bizGhs\product\classes\ProductClass;
 use Yii;
 use common\components\util;
@@ -24,9 +25,9 @@ class ItemService extends BaseService
         $merchantId = $data['merchantId']??0;
         $classId = $data['classId']??0;
         $itemId = $data['itemId']??0;
-        $shopId = $data['shopId']??0;
-        if(!$merchantId || !$shopId){
-            util::fail("请选择供应商/门店");
+        //$shopId = $data['shopId']??0;
+        if(!$merchantId ){
+            util::fail("请选择供应商");
         }
         if(!$classId){
             util::fail("请选择分类");
@@ -50,7 +51,16 @@ class ItemService extends BaseService
         try{
             //写入一条item,同时写入一条itemInfo(初始化库存)
             ItemClass::add($data);
-            ProductClass::add($data);
+            //根据sjId ,获取所有的shopId, 循环写入product
+            $shopIds = ShopService::getShopIds($merchantId);
+            if(empty($shopIds)){
+                $transaction->rollBack();
+                util::fail("无门店");
+            }
+            foreach ($shopIds as $shopId){
+                $data['shopId'] = $shopId;
+                ProductClass::add($data);
+            }
             $transaction->commit();
         }catch (Exception $exception){
             $transaction->rollBack();

+ 15 - 5
biz-ghs/merchant/services/ShopService.php

@@ -10,9 +10,9 @@ use Yii;
 
 class ShopService extends BaseService
 {
-	
+
 	public static $baseFile = '\bizGhs\merchant\classes\ShopClass';
-	
+
 	//计算运费 shish 2019.12.4
 	public static function getSendCost($lat, $lng, $jsStatDistance, $shopInfo)
 	{
@@ -34,14 +34,14 @@ class ShopService extends BaseService
 		$sendCost = ceil($remainDistance * 1000 / 1000 / 1000) * $addPrice;
 		return $sendCost;
 	}
-	
+
 	//获取默认门店信息 shish 2019.12.6
 	public static function getDefaultShop($merchant)
 	{
 		$defaultShopId = $merchant['defaultShopId'];
 		return ShopClass::getById($defaultShopId);
 	}
-	
+
 	//获取默认门店 shish 2020.1.19
 	public static function getDefaultShopId($merchant)
 	{
@@ -55,4 +55,14 @@ class ShopService extends BaseService
 		return ShopClass::generateGatheringCode($merchantId, $shopId);
 	}
 
-}
+	//根据商家ID,获取所有门店 shopIds  linqh 2021.3.4
+    public static function getShopIds($merchantId)
+    {
+        $shops = ShopClass::getAllShop($merchantId);
+        $shopIds = [];
+        if($shops){
+            $shopIds = array_column($shops,'id');
+        }
+        return $shopIds;
+    }
+}