Ver código fonte

申请开店问题

shish 5 anos atrás
pai
commit
73f5bf3310

+ 3 - 0
app-ghs/controllers/ApplyController.php

@@ -56,6 +56,9 @@ class ApplyController extends BaseController
         if (isset($admin['currentShopId']) && !empty($admin['currentShopId'])) {
             util::fail('您已经是门店员工');
         }
+        if (isset($admin['openShop']) && $admin['openShop'] != 1) {
+            util::fail('您已经申请过开店,或已经门店员工');
+        }
         $post['adminName'] = $admin['name'] ?? '';
         $post['long'] = isset($post['longitude']) ? $post['longitude'] : '';
         $post['lat'] = isset($post['latitude']) ? $post['latitude'] : '';

+ 4 - 1
app-ghs/controllers/CustomController.php

@@ -75,8 +75,11 @@ class CustomController extends BaseController
             $apply = ApplyService::replaceRetail($applyData);
             $id = $apply['id'] ?? 0;
             $respond = ApplyService::pass($id);
-            $shop = $respond['shop'];
+            $shop = $respond['shop'] ?? [];
+            $sj = $respond['sj'] ?? [];
+            $hdSjId = $sj['id'] ?? 0;
             $hdShopId = $shop->id ?? 0;
+            ApplyClass::updateById($id, ['sjId' => $hdSjId, 'shopId' => $hdShopId]);
             if (empty($hdShopId)) {
                 util::fail('客户没有添加成功!');
             }

+ 3 - 0
app-hd/controllers/ApplyController.php

@@ -58,6 +58,9 @@ class ApplyController extends BaseController
         if (isset($admin['currentShopId']) && !empty($admin['currentShopId'])) {
             util::fail('您已经是门店员工');
         }
+        if (isset($admin['openShop']) && $admin['openShop'] != 1) {
+            util::fail('您已经申请过开店,或已经门店员工');
+        }
         $post['adminName'] = $admin['name'] ?? '';
         $post['long'] = isset($post['longitude']) ? $post['longitude'] : '';
         $post['lat'] = isset($post['latitude']) ? $post['latitude'] : '';

+ 28 - 9
biz-hd/saas/services/ApplyService.php

@@ -110,27 +110,46 @@ class ApplyService extends BaseService
         }
         $mobile = $data['mobile'] ?? '';
         $data['licenseNo'] = $mobile;
-        $has = ApplyClass::getByCondition(['mobile' => $mobile, 'style' => ApplyClass::FROM_RETAIL]);
-        if (!empty($has)) {
-            if (isset($data['replace']) && $data['replace'] == 1) {
-                util::fail('手机号已经添加过了');
-            }
-            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]);
+        }
+        $has = ApplyClass::getByCondition(['mobile' => $mobile, 'style' => ApplyClass::FROM_RETAIL]);
+        if (!empty($has)) {
+            if (isset($data['replace']) && $data['replace'] == 1) {
+                if (empty($adminId)) {
+                    util::fail('手机号已经添加过了');
+                } else {
+                    if (isset($has['adminId']) && !empty($has['adminId'])) {
+                        //已经被开店的客户主动申请开店
+                        $hasId = $has['id'] ?? 0;
+                        ApplyClass::updateById($hasId, ['adminId' => $adminId]);
+                        $currentSjId = $has['sjId'] ?? 0;
+                        $currentShopId = $has['shopId'] ?? 0;
+                        $has['adminId'] = $adminId;
+                        MerchantClass::initMore($has, $currentSjId, $currentShopId);
+                        //开店成功
+                        \biz\admin\classes\AdminClass::updateById($adminId, ['openShop' => 3, 'currentShopId' => $currentShopId]);
+                        return $has;
+                    }
+                }
+            }
+            util::fail('手机号已经使用');
         }
         $from = $data['from'] ?? ApplyClass::FROM_GHS;
         if (in_array($from, [ApplyClass::FROM_GHS, ApplyClass::FROM_RETAIL]) == false) {
             util::fail('请填写来源');
         }
         $respond = ApplyClass::addRetail($data);
+
+        if (!empty($adminId)) {
+            //已提交开店申请,待审核
+            \biz\admin\classes\AdminClass::updateById($adminId, ['openShop' => 2]);
+        }
+
         return $respond;
     }