shish 3 лет назад
Родитель
Сommit
00d19ef85b

+ 27 - 0
app-ghs/controllers/CustomController.php

@@ -38,6 +38,33 @@ class CustomController extends BaseController
         $custom->py = $py;
         $custom->save();
         OrderClass::updateByCondition(['customId' => $id], ['customName' => $name, 'customNamePy' => $py]);
+        $customShopId = $custom->shopId ?? 0;
+
+        //在首店修改客户名称,直营店自动同步
+        $masterShop = $this->shop;
+        if (isset($masterShop->default) && $masterShop->default == 1) {
+            $sjId = $masterShop->sjId ?? 0;
+            $shopList = ShopClass::getAllByCondition(['sjId' => $sjId], null, '*', null, true);
+            foreach ($shopList as $shop) {
+                $shopId = $shop->id ?? 0;
+                if (isset($shop->join) && $shop->join == 1) {
+                    //加盟店不同步修改
+                    continue;
+                }
+                if ($shopId == $masterShop->id) {
+                    //前面已经同步修改过了
+                    continue;
+                }
+                $custom = CustomClass::getByCondition(['ownShopId' => $shopId, 'shopId' => $customShopId], true);
+                if (empty($custom)) {
+                    continue;
+                }
+                $custom->name = $name;
+                $custom->py = $py;
+                $custom->save();
+            }
+        }
+
         util::complete('修改成功');
     }
 

+ 2 - 2
biz-ghs/custom/classes/CustomClass.php

@@ -56,9 +56,9 @@ class CustomClass extends BaseClass
     ];
 
     //建立客户和供应商关系
-    public static function build($ghsShopId, $hdShopId)
+    public static function build($ghsShopId, $hdShopId, $changeName = '')
     {
-        return GhsClass::build($ghsShopId, $hdShopId, 2);
+        return GhsClass::build($ghsShopId, $hdShopId, 2, $changeName);
     }
 
     //添加客户 ssh 2021.2.24

+ 9 - 15
biz/ghs/classes/GhsClass.php

@@ -26,21 +26,11 @@ class GhsClass extends BaseClass
     //补充供货商 ssh 20211028
     public static function bcGhs($hdShopId)
     {
-        //不再主动推荐供应商
         return false;
-        if (getenv('YII_ENV') == 'production') {
-            //莱漫花行、长安花行、宣言花行、纯彩花艺
-            $ids = [214, 203, 418, 10];
-        } else {
-            $ids = [36225, 36295];
-        }
-        foreach ($ids as $ghsShopId) {
-            CustomClass::build($ghsShopId, $hdShopId);
-        }
     }
 
     //新增客户和供应商关系 ssh 2021.4.13
-    public static function build($ghsShopId, $hdShopId, $type = 1)
+    public static function build($ghsShopId, $hdShopId, $type = 1, $changeName = '')
     {
         if ($type == 1) {
             $ghs = self::getByCondition(['ownShopId' => $hdShopId, 'shopId' => $ghsShopId]);
@@ -87,9 +77,13 @@ class GhsClass extends BaseClass
         $shop = ShopClass::getShopInfo($hdShopId);
         $default = $shop['default'] ?? 0;
         $name = $default == 1 ? $shop['merchantName'] : $shop['merchantName'] . ' ' . $shop['shopName'];
-        $py = stringUtil::py($name);
-        $mobile = $shop['mobile'] ?? '';
 
+        //从分店同步客户,客户被修改的名称也要同步过来
+        $firstName = empty($changeName) ? $name : $changeName;
+        $py = stringUtil::py($firstName);
+        $secondName = $name;
+
+        $mobile = $shop['mobile'] ?? '';
         $uniGhsId = $shop['uniGhsId'] ?? 0;
         $hasManyGhs = $shop['hasManyGhs'] ?? 0;
         if ($uniGhsId == 0 && $hasManyGhs == 0) {
@@ -108,8 +102,8 @@ class GhsClass extends BaseClass
             'ownSjId' => $ghsSjId,
             'ownShopId' => $ghsShopId,
             'ownMainId' => $ghsMainId,
-            'name' => $name,
-            'originName' => $name,
+            'name' => $firstName,
+            'originName' => $secondName,
             'py' => $py,
             'mobile' => $mobile,
             'province' => $shop['province'] ?? '',

+ 7 - 5
console/controllers/CustomController.php

@@ -242,15 +242,17 @@ class CustomController extends Controller
                 continue;
             }
 
+            //指定当前环境为批发商
+            Yii::$app->params['ptStyle'] = dict::getDict('ptStyle', 'ghs');
+
             $toShopId = $shopIdArr[0];
             $fromShopId = $shopIdArr[1];
-            Yii::$app->params['ptStyle'] = dict::getDict('ptStyle', 'ghs'); //指定当前环境为批发商
 
-            $customers = CustomClass::getAllByCondition(['ownShopId' => $fromShopId], null, ['shopId']);
-            foreach ($customers as $customer) {
-                $exist = CustomClass::exists(['ownShopId' => $toShopId, 'shopId' => $customer['shopId']]);
+            $fromCustomList = CustomClass::getAllByCondition(['ownShopId' => $fromShopId], null, ['shopId']);
+            foreach ($fromCustomList as $fromCustomer) {
+                $exist = CustomClass::exists(['ownShopId' => $toShopId, 'shopId' => $fromCustomer['shopId']]);
                 if (!$exist) {
-                    CustomClass::build($toShopId, $customer['shopId']);
+                    CustomClass::build($toShopId, $fromCustomer['shopId'], $fromCustomer['name']);
                 }
             }
         }