Browse Source

补已经存在花店的默认客户

shish 4 years ago
parent
commit
6c91cc2a13
1 changed files with 24 additions and 6 deletions
  1. 24 6
      console/controllers/InitController.php

+ 24 - 6
console/controllers/InitController.php

@@ -54,6 +54,7 @@ use bizHd\stat\classes\StatUserClass;
 use bizHd\stat\classes\StatUserMonthClass;
 use bizHd\stat\classes\StatVisitClass;
 use bizHd\stat\classes\StatVisitMonthClass;
+use bizHd\user\classes\UserClass;
 use common\components\dict;
 use Yii;
 use yii\console\Controller;
@@ -69,12 +70,6 @@ class InitController extends Controller
         $sql = "ALTER TABLE xhAdminRole ADD shopId INT NOT NULL DEFAULT 0 COMMENT '门店id' AFTER `sjId`;";
         Yii::$app->db->createCommand($sql)->execute();
 
-        //清除零售商城相关的数据
-        $sql = "TRUNCATE xhUser;TRUNCATE xhCustom;";
-        Yii::$app->db->createCommand($sql)->execute();
-        $sql = "UPDATE xhOrder SET customId=0,customName='',alipayId=0;";
-        Yii::$app->db->createCommand($sql)->execute();
-
         $list = SjClass::getAllByCondition(['id>' => 0], null, '*', null, true);
         if (!empty($list)) {
             foreach ($list as $sj) {
@@ -132,6 +127,29 @@ class InitController extends Controller
 
             }
         }
+
+
+        //清除零售商城相关的数据
+        $sql = "TRUNCATE xhUser;TRUNCATE xhCustom;";
+        Yii::$app->db->createCommand($sql)->execute();
+        $sql = "UPDATE xhOrder SET customId=0,customName='',alipayId=0;";
+        Yii::$app->db->createCommand($sql)->execute();
+        //补已经存在花店的默认客户
+        $lsShopList = ShopClass::getAllByCondition(['ptStyle' => dict::getDict('ptStyle', 'hd')], null, '*', null, true);
+        if (!empty($lsShopList)) {
+            foreach ($lsShopList as $lsShop) {
+                $mobile = $lsShop->mobile ?? 0;
+                if (empty($mobile)) {
+                    continue;
+                }
+                $user = UserClass::replaceUser(['mobile' => $mobile]);
+                $custom = \bizHd\custom\classes\CustomClass::replaceCustom($lsShop, $user);
+                $customId = $custom->id ?? 0;
+                $lsShop->defaultCustomId = $customId;
+                $lsShop->save();
+            }
+        }
+
     }
 
     //初始化 ./yii init/main