From 072980dc31a813fa4c56cc75ae64133b5db45b9e Mon Sep 17 00:00:00 2001 From: Devil Date: Thu, 15 Apr 2021 11:24:33 +0800 Subject: [PATCH] =?UTF-8?q?=E8=AE=A2=E5=8D=95=E5=8F=96=E6=B6=88=EF=BC=880?= =?UTF-8?q?=E5=85=83=E8=AE=A2=E5=8D=95=EF=BC=89=E9=80=80=E5=9B=9E=E7=94=A8?= =?UTF-8?q?=E6=88=B7=E7=A7=AF=E5=88=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- application/service/IntegralService.php | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/application/service/IntegralService.php b/application/service/IntegralService.php index 3f00f9a70..ced75fd99 100755 --- a/application/service/IntegralService.php +++ b/application/service/IntegralService.php @@ -283,7 +283,7 @@ class IntegralService } // 订单详情 - $order_detail = Db::name('OrderDetail')->field('id,user_id,order_id,goods_id,total_price,refund_price')->find(intval($params['order_detail_id'])); + $order_detail = Db::name('OrderDetail')->field('id,user_id,order_id,goods_id,price,total_price,refund_price,returned_quantity')->find(intval($params['order_detail_id'])); if(empty($order_detail)) { return DataReturn('订单详情不存在或已删除,终止操作', 0); @@ -300,17 +300,29 @@ class IntegralService $give_rate = Db::name('Goods')->where(['id'=>$order_detail['goods_id']])->value('give_integral'); if($give_rate > 0 && $give_rate <= 100) { - $give_integral = intval(($give_rate/100)*$order_detail['refund_price']); - if($give_integral >= 1) + // 存在退款金额则使用退款金额 + // 未存在退款金额则判断是否存在退款数量 + // 存在退款数量则使用退款数量*单价金额计算(防止订单退款金额为空仅存在退款数量) + $refund_integral = 0; + if($order_detail['refund_price'] > 0) + { + $refund_integral = intval(($give_rate/100)*$order_detail['refund_price']); + } else { + if($order_detail['returned_quantity'] > 0) + { + $refund_integral = intval(($give_rate/100)*($order_detail['price']*$order_detail['returned_quantity'])); + } + } + if($refund_integral >= 1) { // 用户积分添加 - if(!Db::name('User')->where(['id'=>$user['id']])->setDec('integral', $give_integral)) + if(!Db::name('User')->where(['id'=>$user['id']])->setDec('integral', $refund_integral)) { return DataReturn('用户积分释放失败['.$order_detail['order_id'].'-'.$order_detail['goods_id'].']', -10); } // 积分日志 - self::UserIntegralLogAdd($user['id'], $user['integral'], $give_integral, '订单商品发生售后收回', 0); + self::UserIntegralLogAdd($user['id'], $user['integral'], $refund_integral, '订单商品发生售后收回', 0); } } return DataReturn('操作成功', 0);