修复:订单退款未退还菜卡额度

This commit is contained in:
wuhui_zzw 2024-04-02 16:10:48 +08:00
parent 0ab8d0fb66
commit 42c7d41b1d
1 changed files with 34 additions and 1 deletions

View File

@ -33,7 +33,7 @@ class OrderAgreeRefundEvent{
// 获取当前商品退款比例
if((int)$refundProductInfo['refund_num'] <= 0) continue;
$refundRate = (float)sprintf("%.2f",(int)$refundProductInfo['refund_num'] / (int)$refundProductInfo['product']['product_num'] * 100);
// 计算减少额度
// 计算减少额度 - 酒卡额度
$sum = (float)app()->make(ExchangeQuotaRecordRepository::class)->searchModel([
'order_product_id' => $refundProductInfo['order_product_id'],
'change_type' => 1
@ -61,6 +61,39 @@ class OrderAgreeRefundEvent{
'source' => 1,
]);
}
// 计算减少额度 - 菜卡额度
$dishSum = (float)app()->make(ExchangeQuotaRecordRepository::class)->searchModel([
'order_product_id' => $refundProductInfo['order_product_id'],
'change_type' => 1,
'quota_type' => 2
])->sum('change_quantity');
$dishRefundQuota = (float)sprintf("%.2f",$dishSum * $refundRate / 100);
if($dishRefundQuota > 0){
// 修改用户持有信息
$dishUserHoldInfo = app()->make(ExchangeQuotaRepository::class)->searchModel(['uid'=>$refund['uid'],'quota_type'=>2])->findOrEmpty();
$dishChangeFront = (float)$dishUserHoldInfo->surplus_quota;
$dishUserHoldInfo->total_quota -= (float)$dishRefundQuota;// 总额度
$dishUserHoldInfo->surplus_quota -= (float)$dishRefundQuota;// 剩余额度
$dishUserHoldInfo->freeze_quota -= (float)$dishRefundQuota;// 冻结额度
$dishUserHoldInfo->save();
// 添加变更记录
ExchangeQuotaRecord::insert([
'uid' => $refund['uid'],
'product_id' => $refundProductInfo['product']['product_id'],
'order_id' => $refundProductInfo['product']['order_id'],
'order_product_id' => $refundProductInfo['order_product_id'],
'change_type' => 0,
'change_quantity' => (float)$dishRefundQuota,
'change_front' => $dishChangeFront,
'change_after' => (float)$dishUserHoldInfo->surplus_quota,
'remark' => "订单退款减少",
'source' => 1,
]);
}
}
}catch(\Exception $e){
$error = [