Browse Source

加权退回

lizhen_gitee 4 days ago
parent
commit
b291b1eae9

+ 8 - 3
addons/shopro/service/order/OrderCreate.php

@@ -313,7 +313,7 @@ class OrderCreate
             $current_goods_amount = bcmul($buyInfo['current_sku_price']->price, $buyInfo['goods_num'], 2);
             $this->orderData['goods_amount'] = bcadd($this->orderData['goods_amount'], $current_goods_amount, 2);
 
-            //当前商品的善豆抵扣价,商品没有就拿分类
+            //当前商品的善豆抵扣比例,商品没有就拿分类,最大100%
             $bean_rate = floatval($goods->bean_rate) > 0 ? $goods->bean_rate : 0;
             if($bean_rate == 0){
                 $bean_rate = Db::name('shopro_category')->where('id',$goods->category_ids)->value('bean_rate');
@@ -999,7 +999,11 @@ class OrderCreate
 
         //最终使用善豆
         $this->orderData['goods_bean_amount'] = $this->bean;
-        $temp_remain_pay_fee = bcsub($this->orderData['pay_fee'], $this->bean, 2);
+//        $temp_remain_pay_fee = bcsub($this->orderData['pay_fee'], $this->bean, 2);
+
+        //善豆不算钱,所以这里pay_fee也降低
+        $this->orderData['pay_fee'] = bcsub($this->orderData['pay_fee'], $this->bean, 2);
+        $temp_remain_pay_fee = $this->orderData['pay_fee'];
 
         //商品里的善豆也要等比例修改,方便售后退回
         foreach ($this->goodsList as $key => &$buyInfo) {
@@ -1286,7 +1290,8 @@ class OrderCreate
                 $orderItem->discount_fee = bcadd(bcadd($buyInfo['promo_discount_fee'], $buyInfo['coupon_discount_fee'], 2), $buyInfo['dispatch_discount_fee'], 2);   // 当前商品所享受的折扣 (promo_discount_fee + coupon_discount_fee + dispatch_discount_fee)
 
                 $pay_fee = bcsub($buyInfo['goods_amount'], bcadd($buyInfo['promo_discount_fee'], $buyInfo['coupon_discount_fee'], 2), 2);        // 商品总金额(不算运费),减去(活动优惠(不包含包邮优惠) + 优惠券优惠)
-                $orderItem->pay_fee = $pay_fee;        // 平均计算单件商品不算运费,算折扣时候的金额
+//                $orderItem->pay_fee = $pay_fee;        // 平均计算单件商品不算运费,算折扣时候的金额
+                $orderItem->pay_fee = bcsub($pay_fee,$buyInfo['goods_bean_amount'],2);        // 平均计算单件商品不算运费,算折扣时候的金额
                 $orderItem->dispatch_status = 0;
                 $orderItem->dispatch_fee = $buyInfo['dispatch_amount'];     // 运费模板中商品自动合并后的加权平均运费,没有扣除包邮优惠
                 $orderItem->dispatch_type = $buyInfo['dispatch_type'];

+ 1 - 0
addons/shopro/service/order/OrderRefund.php

@@ -240,6 +240,7 @@ class OrderRefund
         $current_goods_amount = bcmul($item->goods_price, (string)$item->goods_num, 2);
         $total_amount = bcadd($current_goods_amount, $item->dispatch_fee, 2);
         $refund_fee = bcsub($total_amount, $item->discount_fee, 2);        // (商品金额 + 运费金额) - 总优惠(活动,优惠券,包邮优惠)
+        $refund_fee = bcsub($refund_fee, $item->goods_bean_amount, 2);   //再减一次善豆抵扣
         if ($total_refund_fee >= $pay_fee) {
             $refund_fee = 0;
         } else {

+ 3 - 1
addons/shopro/service/pay/PayOper.php

@@ -342,7 +342,9 @@ class PayOper
     public function getPayedFee($order, $order_type)
     {
         // 锁定读取所有已支付的记录,判断已支付金额
-        $pays = PayModel::{'type' . Str::studly($order_type)}()->paid()->where('order_id', $order->id)->lock(true)->select();
+        $pays = PayModel::{'type' . Str::studly($order_type)}()->paid()
+        ->where('pay_type','neq','bean')    //善豆支付的暂时不计入
+        ->where('order_id', $order->id)->lock(true)->select();
 
         // 商城或者积分商城订单
         $payed_fee = '0';