Explorar el Código

手动添加客户

shish hace 5 años
padre
commit
d2540db7cf

+ 22 - 47
app-ghs/controllers/CustomController.php

@@ -2,12 +2,12 @@
 
 namespace ghs\controllers;
 
-use biz\shop\classes\ShopClass;
 use biz\sj\classes\SjClass;
-use biz\sj\services\MerchantService;
 use bizGhs\custom\classes\CustomClass;
 use bizGhs\custom\services\CustomService;
 use bizHd\saas\classes\ApplyClass;
+use bizHd\saas\services\ApplyService;
+use common\components\imgUtil;
 use common\components\stringUtil;
 use common\components\util;
 use Yii;
@@ -45,68 +45,43 @@ class CustomController extends BaseController
         if (!empty($has)) {
             util::fail('手机号已经添加过');
         }
-
-        $data = [
-            'id' => 2,
-            'name' => '小石头',
-            'avatar' => 'https://img.huaml.com/ghs/home/deserve.png',
-        ];
-        util::success($data);
-
         $connection = Yii::$app->db;
         $transaction = $connection->beginTransaction();
         try {
-            $date = date("Y-m-d H:i:s");
             $shop = $this->shop;
+            $sjId = $this->sjId;
+            $shopId = $this->shopId;
+            $sjName = $this->sj->name ?? '';
             $city = $shop->city ?? '';
             $dist = $shop->dist ?? '';
             $address = $post['address'] ?? '';
-            $fullAddress = $city . $dist . $address;
-            $apply = [
-                'logo' => '',
-                'name' => '',
-                'hasLicense' => '',
-                'licenseNo' => '',
-                'certType' => '',
-                'adminId' => '',
-                'adminName' => '未命名',
+            $applyData = [
+                'name' => $name,
+                'licenseNo' => $mobile,
+                'certType' => ApplyClass::CERT_TYPE_MOBILE,
                 'mobile' => $mobile,
-                'introSjId' => 0,
-                'introSjName' => '',
-                'introShopId' => 0,
-                'customId' => '',
-                'shopAdminId' => '',
-                'from' => '',
-                'fee' => '',
-                'income' => '',
-                'sjId' => '',
+                'introSjId' => $sjId,
+                'introSjName' => $sjName,
+                'introShopId' => $shopId,
+                'from' => ApplyClass::FROM_GHS,
                 'style' => SjClass::STYLE_RETAIL,
-                'main' => '',
-                'long' => '',
-                'lat' => '',
                 'province' => $shop->province ?? '',
                 'city' => $city,
                 'dist' => $dist,
                 'address' => $address,
-                'floor' => '',
-                'fullAddress' => $fullAddress,
-                'showAddress' => '',
-                'remark' => '',
-                'status' => 2,
-                'addTime' => $date,
-                'updateTime' => $date,
+                'status' => ApplyClass::STATUS_PASS,
+                'replace' => 1,//1表示供货商添加的客户
             ];
-            $sj = MerchantService::initSjInfo($apply);
-            $sjId = $sj['id'] ?? 0;
-            if (empty($sjId)) {
-                util::fail('添加客户没有成功');
-            }
-            $hdShop = ShopClass::getByCondition(['sjId' => $sjId], true);
-            $hdShopId = $hdShop->id ?? 0;
+            $apply = ApplyService::replaceRetail($applyData);
+            $id = $apply['id'] ?? 0;
+            $respond = ApplyService::pass($id);
+            $shop = $respond['shop'];
+            $hdShopId = $shop->id ?? 0;
             if (empty($hdShopId)) {
-                util::fail('添加客户没有成功!');
+                util::fail('客户没有添加成功!');
             }
             $custom = CustomClass::build($this->shopId, $hdShopId);
+            $custom['avatar'] = imgUtil::groupImg($custom['avatar']);
             $transaction->commit();
             util::success($custom);
         } catch (\Exception $exception) {

+ 19 - 13
biz-hd/saas/classes/ApplyClass.php

@@ -72,19 +72,23 @@ class ApplyClass extends BaseClass
     //新增申请开店 ssh 2021.2.27
     public static function addRetail($data)
     {
+        $city = $data['city'] ?? '';
         $dist = $data['dist'] ?? '';
         $floor = $data['floor'] ?? '';
         $address = $data['address'] ?? '';
-        $data['fullAddress'] = $data['city'] . $dist . $address . $floor;
+        $data['fullAddress'] = $city . $dist . $address . $floor;
         $data['style'] = SjClass::STYLE_RETAIL;
         $respond = self::addApply($data);
-        $mobile = $data['mobile'];
-        $text = "零售商 {$mobile} 已提交资料,";
-        if (isset($data['introSjName']) && !empty($data['introSjName'])) {
-            $text .= "介绍人:{$data['introSjName']},";
+        //供货商添加客户的不需要通知
+        if (isset($data['replace']) && $data['replace'] == 0) {
+            $mobile = $data['mobile'];
+            $text = "零售商 {$mobile} 已提交资料,";
+            if (isset($data['introSjName']) && !empty($data['introSjName'])) {
+                $text .= "介绍人:{$data['introSjName']},";
+            }
+            $text .= "请及时跟进";
+            noticeUtil::push($text, '15280215347');
         }
-        $text .= "请及时跟进";
-        noticeUtil::push($text, '15280215347');
         return $respond;
     }
 
@@ -97,13 +101,15 @@ class ApplyClass extends BaseClass
         $data['fullAddress'] = $data['city'] . $dist . $address . $floor;
         $data['style'] = SjClass::STYLE_SUPPLIER;
         $respond = self::addApply($data);
-        $mobile = $data['mobile'];
-        $text = "供货商 {$mobile} 已提交资料,";
-        if (isset($data['introSjName']) && !empty($data['introSjName'])) {
-            $text .= "介绍人:{$data['introSjName']},";
+        if (isset($data['replace']) && $data['replace'] == 0) {
+            $mobile = $data['mobile'];
+            $text = "供货商 {$mobile} 已提交资料,";
+            if (isset($data['introSjName']) && !empty($data['introSjName'])) {
+                $text .= "介绍人:{$data['introSjName']},";
+            }
+            $text .= "请及时跟进";
+            noticeUtil::push($text, '15280215347');
         }
-        $text .= "请及时跟进";
-        noticeUtil::push($text, '15280215347');
         return $respond;
     }
 

+ 13 - 15
biz-hd/saas/services/ApplyService.php

@@ -73,7 +73,6 @@ class ApplyService extends BaseService
         $apply['name'] = isset($apply['name']) ? $apply['name'] : '';
         //初始化商家信息
         $respond = MerchantService::initSjInfo($apply);
-
         return $respond;
     }
 
@@ -110,29 +109,28 @@ class ApplyService extends BaseService
             }
         }
         $mobile = $data['mobile'] ?? '';
-        //暂时不需要提供证件
-        $data['hasLicense'] = 2;
         $data['licenseNo'] = $mobile;
         $has = ApplyClass::getByCondition(['mobile' => $mobile, 'style' => ApplyClass::FROM_RETAIL]);
         if (!empty($has)) {
-            util::fail('手机号已经使用过了');
-        }
-        $adminId = $data['adminId'];
-        if (empty($adminId)) {
-            util::fail('帐号有问题');
+            if (isset($data['replace']) && $data['replace'] == 1) {
+                util::fail('手机号已经添加过了');
+            }
+            util::fail('手机号已经使用');
         }
-        $has = ApplyClass::getByCondition(['adminId' => $adminId, 'style' => ApplyClass::FROM_RETAIL]);
-        if (!empty($has)) {
-            util::fail('您已经申请过');
+        $adminId = $data['adminId'] ?? 0;
+        if (!empty($adminId)) {
+            $has = ApplyClass::getByCondition(['adminId' => $adminId, 'style' => ApplyClass::FROM_RETAIL]);
+            if (!empty($has)) {
+                util::fail('您已经申请过');
+            }
+            //已提交开店申请,待审核
+            \biz\admin\classes\AdminClass::updateById($adminId, ['openShop' => 2]);
         }
-        $from = $data['from'] ?? 0;
+        $from = $data['from'] ?? ApplyClass::FROM_GHS;
         if (in_array($from, [ApplyClass::FROM_GHS, ApplyClass::FROM_RETAIL]) == false) {
             util::fail('请填写来源');
         }
         $respond = ApplyClass::addRetail($data);
-        //已提交开店申请,待审核
-        \biz\admin\classes\AdminClass::updateById($adminId, ['openShop' => 2]);
-
         return $respond;
     }
 

+ 4 - 6
biz/sj/classes/MerchantClass.php

@@ -39,14 +39,12 @@ class MerchantClass extends BaseClass
     {
         if ($applyData['style'] == SjClass::STYLE_RETAIL) {
             self::initHdMore($applyData, $sjId, $shopId);
-            //2021.4.13 初始化花材
-            ItemService::initItem($sjId, $shopId);
-        }
-        if ($applyData['style'] == SjClass::STYLE_SUPPLIER) {
+
+        } elseif ($applyData['style'] == SjClass::STYLE_SUPPLIER) {
             self::initGhsMore($applyData, $sjId, $shopId);
-            //2021.4.13 初始化花材
-            ItemService::initItem($sjId, $shopId);
         }
+        //2021.4.13 初始化花材
+        ItemService::initItem($sjId, $shopId);
     }
 
     public static function initHdMore($applyData, $sjId, $shopId)

+ 9 - 6
biz/sj/services/MerchantService.php

@@ -88,9 +88,9 @@ class MerchantService extends BaseService
         $applyData['deadline'] = date("Y-m-d H:i:s", $deadline);
         $applyData['parentId'] = $applyData['introSjId'] ?? 0;
         $applyData['parentShopId'] = $applyData['introShopId'] ?? 0;
-        $sj = self::add($applyData);
-        $sjId = $sj['id'];
-        $sjName = $sj['name'] ?? 0;
+        $sj = self::add($applyData, true);
+        $sjId = $sj->id;
+        $sjName = $sj->name ?? 0;
         $mobile = $applyData['mobile'] ?? '';
         $ptStyle = $applyData['style'] ?? dict::getDict('ptStyle', 'hd');
 
@@ -173,8 +173,11 @@ class MerchantService extends BaseService
         $shopRespond = \biz\shop\classes\ShopClass::addShop($shopData);
         $shopId = $shopRespond->id;
 
-        //员工、角色、商品、分类、培训班等初始化
-        MerchantClass::initMore($applyData, $sjId, $shopId);
+        //非供货商添加客户生成的申请才初始化其它基础信息
+        if (isset($applyData['replace']) && $applyData['replace'] == 0) {
+            //员工、角色、商品、分类、培训班、花材等初始化
+            MerchantClass::initMore($applyData, $sjId, $shopId);
+        }
 
         $sjData = [];
         $sjData['defaultShopId'] = $shopId;
@@ -197,7 +200,7 @@ class MerchantService extends BaseService
         //审核通过微信通知商家
         WxMessageClass::applyPass($shopRespond);
 
-        return $sj;
+        return ['sj' => $sj, 'shop' => $shopRespond];
     }
 
 

+ 3 - 0
biz/wx/classes/WxMessageClass.php

@@ -157,6 +157,9 @@ class WxMessageClass extends BaseClass
             return false;
         }
         $adminList = ShopAdminClass::getRemainAdmin($shopId);
+        if (empty($adminList)) {
+            return false;
+        }
         foreach ($adminList as $admin) {
             if (isset($admin['subscribe']) == false || $admin['subscribe'] == 0) {
                 continue;