Ver Fonte

添加客户

shish há 3 anos atrás
pai
commit
e14d47eaea
1 ficheiros alterados com 43 adições e 1 exclusões
  1. 43 1
      app-hd/controllers/CustomController.php

+ 43 - 1
app-hd/controllers/CustomController.php

@@ -29,6 +29,48 @@ class CustomController extends BaseController
 
     public $guestAccess = ['list'];
 
+    //批量添加客户 ssh 20220919
+    public function actionBatchAddCustom()
+    {
+        $post = Yii::$app->request->post();
+        $connection = Yii::$app->db;//事务处理
+        $transaction = $connection->beginTransaction();
+        try {
+            for ($i = 1; $i <= 5; $i++) {
+                $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('客户名称不能为空');
+                }
+                if (stringUtil::getWordNum($name) > 15) {
+                    util::fail('名称不能超过15个汉字');
+                }
+                if (empty($mobile)) {
+                    util::fail($name . " 手机号不能为空");
+                }
+                if (stringUtil::isMobile($mobile) == false) {
+                    util::fail($name . " 手机号格式不正确");
+                }
+                if ($mobile != $confirmMobile) {
+                    util::fail($name . " 二次手机号不一致");
+                }
+                $user = \bizMall\user\classes\UserClass::replaceUser(['name' => $name, 'mobile' => $mobile]);
+                if (isset($this->shop) && !empty($this->shop)) {
+                    //花店增加客户,散客增加门店
+                    CustomClass::buildRelation($this->shop, $user);
+                }
+            }
+            $transaction->commit();
+        } catch (\Exception $e) {
+            $transaction->rollBack();
+            util::fail('添加失败');
+        }
+    }
+
     //客户列表 ssh 2019.11.30
     public function actionList()
     {
@@ -201,7 +243,7 @@ class CustomController extends BaseController
             ];
             UserGrowthService::add($growthData);
             $transaction->commit();
-        } catch (Exception $e) {
+        } catch (\Exception $e) {
             $transaction->rollBack();
             util::fail();
         }