浏览代码

新增门店初始化花材

林琦海 5 年之前
父节点
当前提交
8591092d0a

+ 2 - 12
app-ghs/controllers/ShopController.php

@@ -59,23 +59,13 @@ class ShopController extends BaseController
     {
         $data = Yii::$app->request->post();
         $data['merchantId'] = $this->sjId;
+        $data['shopId'] = $this->shopId;
+        $data['adminId'] = $this->adminId;
         $data['img'] = is_array($data['img']) ? json_encode($data['img']) : $data['img'];
         $connection = Yii::$app->db;
         $transaction = $connection->beginTransaction();
         try {
             $shop = ShopClass::addShop($data);
-            $shopId = $shop['id'];
-            //门店product 同步数据  linqh 2021.4.18
-            $product = ProductClass::getAllProduct($this->sjId, $this->shopId, "name,cover,classId,itemId,rank,price,priceLabel,cost,addPrice,stockWarning,weight,alias,py,ratio,bigUnit,smallUnit,bigUnitId,smallUnitId,inTurn");
-            $productData = [];
-            foreach ($product as $v) {
-                $tmp = $v;
-                $tmp['merchantId'] = $this->sjId;
-                $tmp['shopId'] = $shopId;
-                $tmp['adminId'] = $this->adminId;
-                $productData[] = $tmp;
-            }
-            ProductClass::batchAdd($productData);
             $transaction->commit();
             util::complete();
         } catch (\Exception $exception) {

+ 3 - 1
app-hd/controllers/ShopController.php

@@ -50,6 +50,8 @@ class ShopController extends BaseController
     {
         $data = Yii::$app->request->post();
         $data['merchantId'] = $this->sjId;
+        $data['shopId'] = $this->shopId;
+        $data['adminId'] = $this->adminId;
         ShopService::addShop($data);
         util::complete();
     }
@@ -184,4 +186,4 @@ class ShopController extends BaseController
         util::success($res);
     }
 
-}
+}

+ 5 - 0
biz-ghs/merchant/classes/ShopClass.php

@@ -62,6 +62,11 @@ class ShopClass extends BaseClass
         //补充fullAddress linqh 2021.4.18
         $data['fullAddress'] = $data['province'].$data['city'].$data['address'].$data['floor'];
         $shop = self::add($data);
+        $newShopId = $shop['id'];
+        //初始化花材 linqh 2021.5.11
+        $adminId = $data['adminId']??0;
+        $shopId = $data['shopId']??0;
+        ProductClass::newShopInitProduct($data['merchantId'],$shopId,$newShopId,$adminId);
         return $shop;
     }
 

+ 15 - 0
biz-ghs/product/classes/ProductClass.php

@@ -725,4 +725,19 @@ class ProductClass extends BaseClass
 
         return $productList;
     }
+
+    //供货商、零售端新开门店时,初始化花材
+    public static function newShopInitProduct($sjId,$shopId,$newShopId,$adminId)
+    {
+        $product = self::getAllProduct($sjId, $shopId, "name,cover,classId,itemId,rank,price,priceLabel,cost,addPrice,stockWarning,weight,alias,py,ratio,bigUnit,smallUnit,bigUnitId,smallUnitId,inTurn");
+        $productData = [];
+        foreach ($product as $v) {
+            $tmp = $v;
+            $tmp['merchantId'] = $sjId;
+            $tmp['shopId'] = $newShopId;
+            $tmp['adminId'] = $adminId;
+            $productData[] = $tmp;
+        }
+        self::batchAdd($productData);
+    }
 }

+ 7 - 1
biz-hd/merchant/classes/ShopClass.php

@@ -2,6 +2,7 @@
 
 namespace bizHd\merchant\classes;
 
+use bizGhs\product\classes\ProductClass;
 use bizHd\admin\classes\ShopAdminClass;
 use common\components\dirUtil;
 use common\components\httpUtil;
@@ -42,6 +43,11 @@ class ShopClass extends BaseClass
         }
         $data['img'] = isset($data['img']) ? json_encode($data['img']) : json_encode([]);
         $shop = self::add($data);
+        $newShopId = $shop['id'];
+        //初始化花材 linqh 2021.5.11
+        $adminId = $data['adminId']??0;
+        $shopId = $data['shopId']??0;
+        ProductClass::newShopInitProduct($data['merchantId'],$shopId,$newShopId,$adminId);
         return $shop;
     }
 
@@ -106,4 +112,4 @@ class ShopClass extends BaseClass
         $shop->save();
     }
 
-}
+}