|
@@ -65,29 +65,28 @@ class HdRefundService extends BaseService
|
|
|
$sameDay = HdRefundClass::SAME_DAY_NO;
|
|
$sameDay = HdRefundClass::SAME_DAY_NO;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- // 可退金额:当天看 tkPrice;隔天看 tkPrice+nextDayTkPrice 合计不超过 mainPay
|
|
|
|
|
- $mainPay = bcadd((string)($order->mainPay ?? '0'), '0', 2);
|
|
|
|
|
|
|
+ // 可退上限与商城申请 remainRefundCash 对齐:用 orderPrice(实付合计),
|
|
|
|
|
+ // 不要只卡 mainPay——组合付 / 会员折后 mainPay 与 orderPrice 不一致时,申请能过、审核会误报「可退款金额不足」
|
|
|
$alreadyTk = bcadd((string)($order->tkPrice ?? '0'), '0', 2);
|
|
$alreadyTk = bcadd((string)($order->tkPrice ?? '0'), '0', 2);
|
|
|
$alreadyNext = bcadd((string)($order->nextDayTkPrice ?? '0'), '0', 2);
|
|
$alreadyNext = bcadd((string)($order->nextDayTkPrice ?? '0'), '0', 2);
|
|
|
|
|
+ $payCeiling = self::resolveRefundPayCeiling($order);
|
|
|
|
|
+ $totalRefunded = bcadd(bcadd($alreadyTk, $alreadyNext, 2), $refundPrice, 2);
|
|
|
|
|
+ if (bccomp($totalRefunded, $payCeiling, 2) > 0) {
|
|
|
|
|
+ util::fail('可退款金额不足');
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
if ($sameDay === HdRefundClass::SAME_DAY_YES) {
|
|
if ($sameDay === HdRefundClass::SAME_DAY_YES) {
|
|
|
- $currentTkPrice = bcadd($alreadyTk, $refundPrice, 2);
|
|
|
|
|
- if (bccomp($currentTkPrice, $mainPay, 2) > 0) {
|
|
|
|
|
- util::fail('可退款金额不足');
|
|
|
|
|
- }
|
|
|
|
|
- $order->tkPrice = $currentTkPrice;
|
|
|
|
|
|
|
+ $order->tkPrice = bcadd($alreadyTk, $refundPrice, 2);
|
|
|
$order->refund = OrderClass::REFUND_YES;
|
|
$order->refund = OrderClass::REFUND_YES;
|
|
|
|
|
+ // 当天售后扣减 actPrice;若历史数据 actPrice 略小于应退额,钳到 0(上限已用 orderPrice 校验过)
|
|
|
$currentActPrice = bcsub((string)($order->actPrice ?? '0'), $refundPrice, 2);
|
|
$currentActPrice = bcsub((string)($order->actPrice ?? '0'), $refundPrice, 2);
|
|
|
if (bccomp($currentActPrice, '0', 2) < 0) {
|
|
if (bccomp($currentActPrice, '0', 2) < 0) {
|
|
|
- util::fail('可退款金额不足!');
|
|
|
|
|
|
|
+ $currentActPrice = '0.00';
|
|
|
}
|
|
}
|
|
|
$order->actPrice = $currentActPrice;
|
|
$order->actPrice = $currentActPrice;
|
|
|
$order->realPrice = $currentActPrice;
|
|
$order->realPrice = $currentActPrice;
|
|
|
$order->save();
|
|
$order->save();
|
|
|
} else {
|
|
} else {
|
|
|
- $totalRefunded = bcadd(bcadd($alreadyTk, $alreadyNext, 2), $refundPrice, 2);
|
|
|
|
|
- if (bccomp($totalRefunded, $mainPay, 2) > 0) {
|
|
|
|
|
- util::fail('可退款金额不足');
|
|
|
|
|
- }
|
|
|
|
|
// 隔天金额在通过资金段 applyHdAmountAndFund 写入 nextDayTkPrice
|
|
// 隔天金额在通过资金段 applyHdAmountAndFund 写入 nextDayTkPrice
|
|
|
$order->refund = OrderClass::REFUND_YES;
|
|
$order->refund = OrderClass::REFUND_YES;
|
|
|
$order->save(false, ['refund']);
|
|
$order->save(false, ['refund']);
|
|
@@ -368,6 +367,31 @@ class HdRefundService extends BaseService
|
|
|
return HdRefundClass::getById($refund->id, true);
|
|
return HdRefundClass::getById($refund->id, true);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 售后可退金额上限(与商城申请 remainRefundCash 同一口径)
|
|
|
|
|
+ * 优先 orderPrice;为空时回退 mainPay+cash,避免组合付/折后主付字段与实付合计不一致
|
|
|
|
|
+ * @param object $order
|
|
|
|
|
+ * @return string 两位小数字符串
|
|
|
|
|
+ */
|
|
|
|
|
+ protected static function resolveRefundPayCeiling($order)
|
|
|
|
|
+ {
|
|
|
|
|
+ $orderPrice = bcadd((string)($order->orderPrice ?? '0'), '0', 2);
|
|
|
|
|
+ if (bccomp($orderPrice, '0', 2) > 0) {
|
|
|
|
|
+ return $orderPrice;
|
|
|
|
|
+ }
|
|
|
|
|
+ $mainPay = bcadd((string)($order->mainPay ?? '0'), '0', 2);
|
|
|
|
|
+ $cash = bcadd((string)($order->cash ?? '0'), '0', 2);
|
|
|
|
|
+ $sum = bcadd($mainPay, $cash, 2);
|
|
|
|
|
+ if (bccomp($sum, '0', 2) > 0) {
|
|
|
|
|
+ return $sum;
|
|
|
|
|
+ }
|
|
|
|
|
+ // 再回退 actPrice + 已退(还原下单实付)
|
|
|
|
|
+ $act = bcadd((string)($order->actPrice ?? '0'), '0', 2);
|
|
|
|
|
+ $tk = bcadd((string)($order->tkPrice ?? '0'), '0', 2);
|
|
|
|
|
+ $next = bcadd((string)($order->nextDayTkPrice ?? '0'), '0', 2);
|
|
|
|
|
+ return bcadd(bcadd($act, $tk, 2), $next, 2);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
/**
|
|
/**
|
|
|
* 拉卡拉线上原路退款
|
|
* 拉卡拉线上原路退款
|
|
|
*/
|
|
*/
|