Explorar el Código

fix(group-buy): 自动补建拼团客户门店关系

- 拼团详情在客户缺少当前门店关系时自动建立关系并返回 hdId
- 参团流程在缺少客户上下文时优先查找或补建门店客户关系
- 统一 account 参数整数化和客户关系失败提示
- API: 拼团详情和参团在未建立客户门店关系时由直接失败调整为尝试自动建联,未登录或门店无效时返回对应失败信息
shizhongqi hace 4 días
padre
commit
c99987b653
Se han modificado 1 ficheros con 33 adiciones y 14 borrados
  1. 33 14
      app-mall/controllers/GroupBuyController.php

+ 33 - 14
app-mall/controllers/GroupBuyController.php

@@ -12,7 +12,6 @@ use bizHd\shop\classes\ShopClass;
 use bizMall\hd\classes\HdClass;
 use common\components\business;
 use common\components\dict;
-use common\components\errCode;
 use common\components\orderSn;
 use common\components\stringUtil;
 use common\components\util;
@@ -128,14 +127,27 @@ class GroupBuyController extends BaseController
         }
         $detail['activityGoods'] = $landing;
 
-        $currentShopId = Yii::$app->request->get('account', 0);
-        $hd = HdClass::getByCondition(['shopId'=>$currentShopId, 'userId'=>$this->userId], false, null, 'id, customId');
+        $currentShopId = intval(Yii::$app->request->get('account', 0));
+        $hd = HdClass::getByCondition(['shopId' => $currentShopId, 'userId' => $this->userId], false, null, 'id, customId');
         if (empty($hd)) {
-            // 创建关系???
-            // util::fail('客户暂无关联此店');
-            util::error(errCode::GROUP_BUY_HD_NOT_BOUND, '客户暂无关联此店');
+            // util::error(errCode::GROUP_BUY_HD_NOT_BOUND, '客户暂无关联此店');
+
+            // 客户与当前门店无关系时,立即建立
+            if (empty($this->user)) {
+                util::fail('请先登录');
+            }
+            $shop = ShopClass::getById($currentShopId, true);
+            if (empty($shop)) {
+                util::fail('门店不存在');
+            }
+            $respond = CustomClass::buildRelation($shop, $this->user);
+            if (empty($respond) || empty($respond['hd'])) {
+                util::fail('关联门店失败');
+            }
+            $hdId = intval($respond['hd']->id);
+        } else {
+            $hdId = intval($hd['id']);
         }
-        $hdId = $hd['id'];
         $detail['hdId'] = $hdId;
 
         util::success($detail);
@@ -206,16 +218,23 @@ class GroupBuyController extends BaseController
         $form->loadAndValidate();
         $mainId = intval($this->mainId);
         $custom = $this->custom;
-        $currentShopId = Yii::$app->request->get('account', 0);
+        $currentShopId = intval(Yii::$app->request->get('account', 0));
         if (empty($custom)) {
-            //util::fail('请先登录');
-            $hd = HdClass::getByCondition(['shopId'=>$currentShopId, 'userId'=>$this->userId], false, null, 'id, customId');
+            $hd = HdClass::getByCondition(['shopId' => $currentShopId, 'userId' => $this->userId], false, null, 'id, customId');
             if (empty($hd)) {
-                // 创建关系???
-                util::fail('客户暂无关联此店');
+                // 客户与当前门店无关系时,立即建立
+                if (empty($this->user) || empty($this->shop)) {
+                    util::fail('请先登录');
+                }
+                $respond = CustomClass::buildRelation($this->shop, $this->user);
+                if (empty($respond) || empty($respond['custom'])) {
+                    util::fail('关联门店失败');
+                }
+                $custom = $respond['custom'];
+            } else {
+                $customId = $hd['customId'];
+                $custom = CustomClass::getById($customId, true);
             }
-            $customId = $hd['customId'];
-            $custom = CustomClass::getById($customId, true);
         }
         $customId = intval($custom->id);
         $groupBuyId = intval($form->groupBuyId);