fix: 优化订单及售后退款控制器异常捕获,避免第三方支付错误触发500
这个提交包含在:
@@ -1034,40 +1034,44 @@ class Order extends Base
|
||||
}
|
||||
}
|
||||
|
||||
Db::transaction(function () use ($order, $items, $item_id, $refund_money, $refund_surplus_money) {
|
||||
if ($item_id) {
|
||||
// 单个商品退款
|
||||
$item = $items[$item_id];
|
||||
\app\admin\model\shopro\order\Order::startRefund($order, $item, $refund_money, $this->auth->getUserInfo(), '管理员操作退款');
|
||||
} else {
|
||||
// 全部退款
|
||||
// 未退款 item 商品总金额
|
||||
$goods_total_amount = 0;
|
||||
foreach ($items as $ke => $it) {
|
||||
$goods_total_amount += ($it['goods_price'] * $it['goods_num']);
|
||||
}
|
||||
|
||||
$current_refunded_money = 0;
|
||||
for ($i = 0; $i < count($items); $i++) {
|
||||
if ($i == (count($items) - 1)) {
|
||||
// 最后一条,全部退完
|
||||
$current_refund_money = $refund_money - $current_refunded_money;
|
||||
} else {
|
||||
// 按比例计算当前 item 应退金额
|
||||
$current_refund_money = round($refund_money * (($items[$i]['goods_price'] * $it['goods_num']) / $goods_total_amount), 2);
|
||||
}
|
||||
if (($current_refunded_money + $current_refund_money) > $refund_money) {
|
||||
$current_refund_money = $refund_money - $current_refunded_money;
|
||||
try {
|
||||
Db::transaction(function () use ($order, $items, $item_id, $refund_money, $refund_surplus_money) {
|
||||
if ($item_id) {
|
||||
// 单个商品退款
|
||||
$item = $items[$item_id];
|
||||
\app\admin\model\shopro\order\Order::startRefund($order, $item, $refund_money, $this->auth->getUserInfo(), '管理员操作退款');
|
||||
} else {
|
||||
// 全部退款
|
||||
// 未退款 item 商品总金额
|
||||
$goods_total_amount = 0;
|
||||
foreach ($items as $ke => $it) {
|
||||
$goods_total_amount += ($it['goods_price'] * $it['goods_num']);
|
||||
}
|
||||
|
||||
if ($current_refund_money >= 0) { // 支付金额或者退款金额 为 0 也能退
|
||||
$current_refunded_money += $current_refund_money;
|
||||
$current_refunded_money = 0;
|
||||
for ($i = 0; $i < count($items); $i++) {
|
||||
if ($i == (count($items) - 1)) {
|
||||
// 最后一条,全部退完
|
||||
$current_refund_money = $refund_money - $current_refunded_money;
|
||||
} else {
|
||||
// 按比例计算当前 item 应退金额
|
||||
$current_refund_money = round($refund_money * (($items[$i]['goods_price'] * $it['goods_num']) / $goods_total_amount), 2);
|
||||
}
|
||||
if (($current_refunded_money + $current_refund_money) > $refund_money) {
|
||||
$current_refund_money = $refund_money - $current_refunded_money;
|
||||
}
|
||||
|
||||
\app\admin\model\shopro\order\Order::startRefund($order, $items[$i], $current_refund_money, $this->auth->getUserInfo(), '管理员操作退款');
|
||||
if ($current_refund_money >= 0) { // 支付金额或者退款金额 为 0 也能退
|
||||
$current_refunded_money += $current_refund_money;
|
||||
|
||||
\app\admin\model\shopro\order\Order::startRefund($order, $items[$i], $current_refund_money, $this->auth->getUserInfo(), '管理员操作退款');
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
} catch (\Throwable $e) {
|
||||
$this->error($e->getMessage());
|
||||
}
|
||||
|
||||
$item_list = \app\admin\model\shopro\order\OrderItem::where(['order_id' => $id])->select();
|
||||
return $this->success('操作成功', null, $item_list);
|
||||
|
||||
在新工单中引用
屏蔽一个用户