Просмотр исходного кода

fix(hd): 修复商品分类与拼团详情异常处理

- 修正删除分类时商品分类关系使用的商品 ID 字段,避免误判商品所属分类数量
- 修正规格同步读取主商品 ID 的方式,兼容数组型商品数据
- 新增拼团业务错误码常量,并在拼团详情客户未绑定门店时返回专用业务码
- API: 拼团详情客户未绑定门店时返回 code 6001;分类删除在删除结果为 0 时仍返回删除成功
shizhongqi 4 дней назад
Родитель
Сommit
9b9bc15fe0

+ 4 - 4
app-hd/controllers/CategoryController.php

@@ -108,7 +108,7 @@ class CategoryController extends BaseController
             $defaultCategoryId = $defaultCategory['id'];
             foreach ($goodsCateObjs as $gcObj) {
                 // 先判断商品是否也在其它分类下
-                $goodsOtherCateCount = GoodsCategoryClass::getCount(['mainId' => $this->mainId, 'gId' => $gcObj['gpId']]);
+                $goodsOtherCateCount = GoodsCategoryClass::getCount(['mainId' => $this->mainId, 'gId' => $gcObj['gId']]);
                 if ($goodsOtherCateCount == 1) {
                     // 如果商品仅在此分类下,则归到默认分类
                     GoodsCategoryClass::updateById($gcObj['id'], ['cId' => $defaultCategoryId]);
@@ -120,9 +120,9 @@ class CategoryController extends BaseController
         }
 
         $count = CategoryClass::deleteCategory($categoryId);
-        if (!$count) {
-            util::fail('删除失败');
-        }
+        // if (!$count) {
+        //     util::fail('删除失败');
+        // }
         util::complete('删除成功');
     }
 

+ 3 - 1
app-mall/controllers/GroupBuyController.php

@@ -12,6 +12,7 @@ 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;
@@ -131,7 +132,8 @@ class GroupBuyController extends BaseController
         $hd = HdClass::getByCondition(['shopId'=>$currentShopId, 'userId'=>$this->userId], false, null, 'id, customId');
         if (empty($hd)) {
             // 创建关系???
-            util::fail('客户暂无关联此店');
+            // util::fail('客户暂无关联此店');
+            util::error(errCode::GROUP_BUY_HD_NOT_BOUND, '客户暂无关联此店');
         }
         $hdId = $hd['id'];
         $detail['hdId'] = $hdId;

+ 1 - 1
biz-hd/goods/classes/GoodsClass.php

@@ -60,7 +60,7 @@ class GoodsClass extends BaseClass
 
     public static function syncSpecs($master, $data)
     {
-        $masterId = $master->id;
+        $masterId = $master['id'];
         $enabled = (int)($data['specEnabled']);
         $old = self::getAllByCondition(['masterId'=>$masterId, 'delStatus'=>0], null, '*', 'id');
         if (!$enabled) {

+ 33 - 0
common/components/errCode.php

@@ -0,0 +1,33 @@
+<?php
+
+namespace common\components;
+
+/**
+ * 自定义业务错误码(bizCode)
+ *
+ * 约定:
+ * - 保留码:1 成功 / 0 通用失败 / 2 登录态失效 / -10 未登录 / -1 历史静默业务失败
+ * - 本文件登记的业务码均 >= 1000,前端拦截器会静默 resolve,由页面按 code 独自处理
+ *
+ * 号段规划(每段 1000 个号):
+ * - 1000-1999 通用/公共
+ * - 2000-2999 用户/客户(登录、绑定、注册)
+ * - 3000-3999 商品/库存
+ * - 4000-4999 订单/交易
+ * - 5000-5999 结算/资金
+ * - 6000-6999 营销活动(拼团、优惠券、砍价……)
+ * - 7000-7999 IM/客服
+ * - 8000-8999 物流/配送
+ * - 9000-9999 预留
+ *
+ * 新增规范:在对应号段追加常量 + 注释,Controller 里用 util::error(errCode::XXX, $msg) 代替裸数字。
+ */
+class errCode
+{
+    /**
+     * 客户在当前门店暂无绑定关系(hd 表无记录)
+     * 场景:GroupBuyController::actionDetail
+     * 前端:mallApp/src/pages/groupBuy/detail.vue
+     */
+    const GROUP_BUY_HD_NOT_BOUND = 6001;
+}