xieruidong 2 years ago
parent
commit
a07a4eec72

+ 2 - 0
application/common/model/OrderInfo.php

@@ -7,6 +7,8 @@ use think\Model;
 
 /**
  * @property Orders orders
+ * @property int order_id
+ * @property float amount_goods_real
  * @property Refund refund
  * @property string goods_name
  * @method static static|Query payed()

+ 8 - 3
application/common/service/RefundService.php

@@ -23,6 +23,7 @@ class RefundService extends BaseService {
 
     public function amount($total=false){
         $amount=0;
+        $orderInfo=$this->getOrderInfo();
         if($this->num>0){
             $amount=bcdiv($this->getOrderInfo('amount_goods_real'),$this->num);
         }
@@ -33,11 +34,15 @@ class RefundService extends BaseService {
             $couponAmountTotal=$this->getOrderInfo()->orders->amount_coupon;
             $goodsId=UserCouponGoods::where('coupon_id',$coupon_id)->column('goods_id');
             if(empty($goodsId)){
-                $couponAmount=bcdiv($couponAmountTotal,OrderInfo::where('order_id',$this->getOrderInfo('order_id'))->sum('num'));
+                $orderInfoAmount=OrderInfo::where('order_id',$orderInfo->order_id)->column('amount_goods_real','id');
             }else{
-                $fitNum=OrderInfo::where('order_id',$this->getOrderInfo('order_id'))->whereIn('goods_id',$goodsId)->sum('num');
-                $couponAmount=bcdiv($couponAmountTotal,$fitNum);
+                $orderInfoAmount=OrderInfo::where('order_id',$orderInfo->order_id)->whereIn('goods_id',$goodsId)->column('amount_goods_real','id');
             }
+            $totalAmount=array_sum(array_values($orderInfoAmount));
+            $per=bcdiv($couponAmountTotal,$totalAmount);
+            $num=$orderInfo['num'];
+            $thisAmount=$orderInfo->amount_goods_real;
+            $couponAmount=bcdiv($thisAmount/$per,$num);
         }
 
         $amount=bcsub($amount,$couponAmount);