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

feat(mall): 完善余额流水与售后重新申请

- 新增顾客余额支付流水查询,并校验顾客与店铺归属\n- 撤销售后再次提交时复用原记录并清理审核状态\n- 清理余额变动业务类中的无用依赖\n\nAPI: 新增 balance-change/balance-pay-change 查询接口,并调整售后创建接口的重申请行为\nDatabase: 撤销记录重新申请时原地更新申请内容与审核字段,不新增记录
shizhongqi 16 часов назад
Родитель
Сommit
08e6b183e4

+ 32 - 0
app-mall/controllers/BalanceChangeController.php

@@ -2,6 +2,8 @@
 
 namespace mall\controllers;
 
+use bizHd\balance\classes\BalancePayChangeClass;
+use bizHd\custom\classes\CustomClass;
 use bizMall\balance\classes\BalanceChangeClass;
 use common\components\dateUtil;
 use common\components\util;
@@ -33,4 +35,34 @@ class BalanceChangeController extends BaseController
         util::success($respond);
     }
 
+    public function actionBalancePayChange()
+    {
+        $get = Yii::$app->request->get();
+        $where = [];
+        $where['mainId'] = $this->mainId;
+        $customId = $this->customId;
+        if (!empty($customId)) {
+            $custom = CustomClass::getById($customId, true);
+            if (empty($custom)) {
+                util::fail('没有找到客户');
+            }
+            $shopId = $this->shopId;
+            if ($custom->shopId != $shopId) {
+                util::fail('没有找到客户信息');
+            }
+            $where['customId'] = $customId;
+        } else {
+            util::fail('缺少参数customId');
+        }
+        $searchTime = $get['searchTime'] ?? '';
+        if (!empty($searchTime)) {
+            $startTime = $get['startTime'] ?? '';
+            $endTime = $get['endTime'] ?? '';
+            $period = dateUtil::formatTime($searchTime, $startTime, $endTime);
+            $where['addTime'] = ['between', [$period['startTime'], $period['endTime']]];
+        }
+        $respond = BalancePayChangeClass::getChangeList($where);
+        util::success($respond);
+    }
+
 }

+ 2 - 1
app-mall/controllers/RefundController.php

@@ -2,7 +2,7 @@
 /**
  * 用途:商城顾客售后申请接口
  * 谁用:mallApp 订单详情「申请售后」页
- * 解决:顾客提交/查看/撤销售后申请;真正退款由商家在 hdApp 审核通过后执行
+ * 解决:顾客提交/查看/撤销/重新申请售后;真正退款由商家在 hdApp 审核通过后执行
  */
 
 namespace mall\controllers;
@@ -74,6 +74,7 @@ class RefundController extends BaseController
 
     /**
      * 顾客提交售后申请(仅落待审核记录)
+     * 若该订单最新申请为已取消,则把原记录状态改回待审核,不新开一条
      */
     public function actionCreateOrder()
     {

+ 0 - 1
biz-hd/balance/classes/BalanceChangeClass.php

@@ -5,7 +5,6 @@ namespace bizHd\balance\classes;
 use bizHd\order\classes\SettleClass;
 use bizHd\recharge\classes\RechargeClass;
 use common\components\dict;
-use Yii;
 use bizHd\base\classes\BaseClass;
 
 class BalanceChangeClass extends BaseClass

+ 0 - 1
biz-hd/balance/classes/BalancePayChangeClass.php

@@ -2,7 +2,6 @@
 
 namespace bizHd\balance\classes;
 
-use Yii;
 use bizHd\base\classes\BaseClass;
 
 class BalancePayChangeClass extends BaseClass

+ 43 - 2
biz-hd/refund/services/MallRefundApplyService.php

@@ -1,8 +1,8 @@
 <?php
 /**
  * 用途:商城顾客售后申请服务
- * 谁用:app-mall 提交/撤销申请、app-hd 审核通过/驳回
- * 解决:申请只落待审核记录;审核通过时复用 HdRefundService 执行真实退款,并处理红包与分销重算
+ * 谁用:app-mall 提交/撤销/重新申请、app-hd 审核通过/驳回
+ * 解决:申请只落待审核记录;撤销后可把已取消记录改回待审核;审核通过时复用 HdRefundService 执行真实退款
  */
 
 namespace bizHd\refund\services;
@@ -21,6 +21,7 @@ class MallRefundApplyService extends BaseService
 
     /**
      * 创建售后申请(仅落库待审核,不触达资金)
+     * 若该订单最新申请为已取消,则复用该记录把状态改回待审核
      * @param array $post 含 refundType/product/price/remark 等
      * @param object $order xhOrder 对象
      * @param array $extra 含 userId/hdId/customId/shopId/mainId/sjId 等上下文
@@ -74,9 +75,49 @@ class MallRefundApplyService extends BaseService
             'status' => MallRefundApplyClass::STATUS_PENDING,
         ];
 
+        // 撤销后重新申请:复用已取消记录,把状态改回待审核,避免同一订单堆多条取消单
+        $latest = MallRefundApplyClass::getLatestByOrderId((int)($order->id ?? 0));
+        if (!empty($latest) && (int)($latest['status'] ?? -1) === MallRefundApplyClass::STATUS_CANCEL) {
+            return self::reopenCancelledApply((int)$latest['id'], $data);
+        }
+
         return MallRefundApplyClass::add($data, true);
     }
 
+    /**
+     * 将已取消申请改回待审核
+     * 顾客撤销后再次提交时复用同一条记录,刷新申请内容并清掉审核痕迹
+     * @param int $id 已取消申请 id
+     * @param array $data 新的申请字段(含 refundType/product/refundPrice/remark 等)
+     * @return object 更新后的申请对象
+     */
+    protected static function reopenCancelledApply($id, $data)
+    {
+        $apply = MallRefundApplyClass::getById($id, true);
+        if (empty($apply) || (int)$apply->status !== MallRefundApplyClass::STATUS_CANCEL) {
+            util::fail('申请状态已变化,请刷新后重试');
+        }
+
+        foreach ($data as $key => $val) {
+            if ($key === 'id') {
+                continue;
+            }
+            $apply->$key = $val;
+        }
+        // 重新进入待审核:清驳回/审核字段,申请时间改为本次提交时间
+        $apply->status = MallRefundApplyClass::STATUS_PENDING;
+        $apply->rejectReason = '';
+        $apply->auditAdminId = 0;
+        $apply->auditAdminName = '';
+        $apply->auditTime = null;
+        $apply->hdRefundId = 0;
+        $apply->addTime = date('Y-m-d H:i:s');
+        if (!$apply->save()) {
+            throw new \Exception('重新申请失败');
+        }
+        return $apply;
+    }
+
     /**
      * 校验退货数量不超过可退数量,并补齐商品名快照
      * @param array $productList [{productId,num,unitPrice,property,name?}] property 0商品 1花材