Browse Source

批量添加客户

shish 4 years ago
parent
commit
1ff9f97db3
1 changed files with 35 additions and 24 deletions
  1. 35 24
      app-ghs/controllers/CustomController.php

+ 35 - 24
app-ghs/controllers/CustomController.php

@@ -9,8 +9,8 @@ use bizGhs\custom\classes\CustomClass;
 use bizGhs\custom\services\CustomService;
 use bizHd\saas\classes\ApplyClass;
 use bizHd\saas\services\ApplyService;
+use bizHd\shop\classes\ShopClass;
 use bizHd\stat\classes\StatVisitClass;
-use bizGhs\shop\classes\ShopClass;
 use common\components\imgUtil;
 use common\components\stringUtil;
 use common\components\util;
@@ -116,43 +116,54 @@ class CustomController extends BaseController
     public function actionCreateCustomers()
     {
         $post = Yii::$app->request->post();
-        $post['style'] = SjClass::STYLE_RETAIL;
-        $sjId = $this->sjId;
-        $shopId = $this->shopId;
-
+        $arr = [];
         for ($i = 1; $i <= 5; $i++) {
-            $name = $post['name' . $i];
-            $mobile = $post['mobile' . $i];
-            $confirmMobile = $post['confirmMobile' . $i];
-
-            if (empty($name)) {
-                Yii::info("花店名称不能为空");
+            $name = $post['name' . $i] ?? '';
+            $mobile = $post['mobile' . $i] ?? '';
+            $confirmMobile = $post['confirmMobile' . $i] ?? '';
+            if (empty($name) && empty($mobile) && empty($confirmMobile)) {
                 continue;
             }
+            if (empty($name)) {
+                util::fail('花店名称不能为空');
+            }
+            $has = SjClass::getByCondition(['name' => $name]);
+            if (!empty($has)) {
+                util::fail($name . ' 这个名称已经被别人使用了');
+            }
             if (stringUtil::getWordNum($name) > 8) {
-                Yii::info('名称不能超过8个汉字');
-                continue;
+                util::fail('名称不能超过8个汉字');
             }
-
             if (empty($mobile)) {
-                Yii::info("手机号不能为空");
-                continue;
+                util::fail($name . " 手机号不能为空");
             }
             if (stringUtil::isMobile($mobile) == false) {
-                Yii::info('手机号格式不正确');
-                continue;
+                util::fail($name . " 手机号格式不正确");
             }
-
             if ($mobile != $confirmMobile) {
-                Yii::info("添加客户失败:mobile " . $mobile . ' != confirmMobile ' . $confirmMobile);
-                continue;
+                util::fail($name . " 二次手机号不一致");
             }
-
+            $hasShop = ShopClass::getByCondition(['mobile' => $mobile], true);
+            if (!empty($hasShop)) {
+                util::fail($name . "这个客户已经添加过了");
+            }
+            $has = ApplyClass::getByCondition(['mobile' => $mobile]);
+            if (!empty($has)) {
+                util::fail($name . "这个客户已经添加过了哦");
+            }
+            $arr[] = ['name' => $name, 'mobile' => $mobile];
+        }
+        if (empty($arr)) {
+            util::fail('请填写客户');
+        }
+        foreach ($arr as $item) {
+            $name = $item['name'] ?? '';
+            $mobile = $item['mobile'] ?? '';
             //队列方式去处理
             $customerCachedKey = 'batch_create_customer_list';
-            $value = $name . '_' . $mobile . '_' . $this->sjId . '_' . $this->shop['id'] . '_' . $this->sj['name'] . '_' . $this->shopAdminId;
+            $value = $name . '_' . $mobile . '_' . $this->sjId . '_' . $this->shop->id . '_' . $this->sj->name . '_' . $this->shopAdminId;
             Yii::$app->redis->executeCommand('LPUSH', [$customerCachedKey, $value]);
-            Yii::info("添加客户:name - " . $name . ' == mobile - ' . $mobile);
+            Yii::info("供应商添加客户:name - " . $name . ' == mobile - ' . $mobile);
             Yii::info("shopAdminId: " . $this->shopAdminId);
         }
         util::complete();