shish 4 rokov pred
rodič
commit
a551fe9171

+ 22 - 7
app-ghs/controllers/ProductController.php

@@ -195,7 +195,8 @@ class ProductController extends BaseController
         //花材价格只能在首店修改,并同步到分店
         $shop = $this->shop;
         $default = $shop->default ?? 0;
-        if ($default != 1) {
+        $join = $shop->join ?? 0;
+        if ($join == 1 && $default != 1) {
             util::fail('请在首店修改');
         }
 
@@ -218,8 +219,16 @@ class ProductController extends BaseController
                 util::fail('请选择花材');
             }
 
-            $productList = ProductClass::getAllByCondition(['id' => ['in', $ids]], null, '*', 'id', true);
+            $sjId = $shop->sjId ?? 0;
+            $chainShopList = [];
+            if ($default == 1) {
+                $chainShopList = ShopClass::getAllByCondition(['sjId' => $sjId, 'join' => 0], null, '*', null, true);
+                if (empty($chainShopList)) {
+                    util::fail('没有找到直营店');
+                }
+            }
 
+            $productList = ProductClass::getAllByCondition(['id' => ['in', $ids]], null, '*', 'id', true);
             foreach ($arr as $product) {
                 if (isset($product['price']) == false) {
                     util::fail('没有价格');
@@ -240,7 +249,14 @@ class ProductController extends BaseController
                 if (empty($price)) {
                     continue;
                 }
-                ProductClass::changePrice($product, $price, ProductClass::PRICE_LABEL_CHANGE);
+                //在首店修改需要同步到直营店
+                if ($default == 1) {
+                    foreach ($chainShopList as $chain) {
+                        $ptItemId = $product->itemId;
+                        ProductClass::changePrice($chain, $ptItemId, $price);
+                    }
+                }
+
             }
             $transaction->commit();
             util::complete('修改成功');
@@ -535,11 +551,9 @@ class ProductController extends BaseController
 
     public function actionUpdate()
     {
-        $post = Yii::$app->request->post();
-
         $shopAdmin = $this->shopAdmin;
         if (isset($shopAdmin->super) == false || $shopAdmin->super != 1) {
-            util::fail('超管才能修改');
+            util::fail('超管才能操作');
         }
 
         $shop = $this->shop;
@@ -551,8 +565,9 @@ class ProductController extends BaseController
             }
         }
 
+        $post = Yii::$app->request->post();
         $post['adminId'] = $this->adminId;
-        ProductClass::updateProduct($post);
+        ProductClass::updateProduct($post, $this->shop);
         util::complete();
     }
 

+ 10 - 6
biz-ghs/merchant/classes/ShopClass.php

@@ -24,9 +24,9 @@ class ShopClass extends BaseClass
 
     public static $baseFile = '\bizGhs\merchant\models\Shop';
 
-    public static function addMainShop($data, $oldShop, $sj)
+    public static function addMainShop($data, $oldGhsShop, $sj)
     {
-        if (isset($oldShop->lsShopId) == false || empty($oldShop->lsShopId)) {
+        if (isset($oldGhsShop->lsShopId) == false || empty($oldGhsShop->lsShopId)) {
             util::fail('本店请先绑定零售店');
         }
         $mobile = $data['mobile'] ?? 0;
@@ -56,14 +56,18 @@ class ShopClass extends BaseClass
         $mainId = $main->id ?? 0;
         $data['mainId'] = $mainId;
 
-        $newShop = \bizGhs\shop\classes\ShopClass::addShop($data);
+        $newGhsShop = \bizGhs\shop\classes\ShopClass::addShop($data);
 
-        $lsOldShop = ShopClass::getById($oldShop->lsShopId, true);
+        $lsOldShop = ShopClass::getById($oldGhsShop->lsShopId, true);
         $data['sjId'] = $lsOldShop->sjId ?? 0;
         $data['ptStyle'] = dict::getDict('ptStyle', 'hd');
-        \bizHd\shop\classes\ShopClass::addShop($data);
+        $newLsShop = \bizHd\shop\classes\ShopClass::addShop($data);
+        $newLsShop->pfShopId = $newGhsShop->id ?? 0;
+        $newLsShop->save();
+        $newGhsShop->lsShopId = $newLsShop->id ?? 0;
+        $newGhsShop->save();
 
-        return $newShop;
+        return $newGhsShop;
     }
 
     //组装门店基本信息 ssh 2019.12.2