|
|
@@ -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花材
|