Переглянути джерело

修复:订单结算使用优惠券时计算问题

Yahoo 4 роки тому
батько
коміт
88f163b74a

+ 5 - 4
app/api/service/coupon/GoodsDeduct.php

@@ -94,18 +94,19 @@ class GoodsDeduct extends BaseService
         $this->rangeGoodsList = [];
         foreach ($this->goodsList as $goods) {
             $goods['total_price'] *= 100;
+            $goodsKey = "{$goods['goods_id']}-{$goods['goods_sku_id']}";
             switch ($this->couponInfo['apply_range']) {
                 case ApplyRangeEnum::ALL:
-                    $this->rangeGoodsList[$goods['goods_id']] = $goods;
+                    $this->rangeGoodsList[$goodsKey] = $goods;
                     break;
                 case ApplyRangeEnum::SOME:
                     if (in_array($goods['goods_id'], $this->couponInfo['apply_range_config']['applyGoodsIds'])) {
-                        $this->rangeGoodsList[$goods['goods_id']] = $goods;
+                        $this->rangeGoodsList[$goodsKey] = $goods;
                     }
                     break;
                 case ApplyRangeEnum::EXCLUDE:
                     if (!in_array($goods['goods_id'], $this->couponInfo['apply_range_config']['excludedGoodsIds'])) {
-                        $this->rangeGoodsList[$goods['goods_id']] = $goods;
+                        $this->rangeGoodsList[$goodsKey] = $goods;
                     }
                     break;
                 default:
@@ -172,7 +173,7 @@ class GoodsDeduct extends BaseService
     {
         $orderTotalPrice = helper::getArrayColumnSum($this->rangeGoodsList, 'total_price');
         foreach ($this->rangeGoodsList as &$goods) {
-            $goods['weight'] = $goods['total_price'] / $orderTotalPrice;
+            $goods['weight'] = round($goods['total_price'] / $orderTotalPrice, 6);
         }
         array_sort($this->rangeGoodsList, 'weight', true);
     }

+ 4 - 3
app/api/service/order/Checkout.php

@@ -547,7 +547,7 @@ class Checkout extends BaseService
         // 获取优惠券信息
         $couponInfo = $this->getCouponInfo($couponId, $couponList);
         // 计算订单商品优惠券抵扣金额
-        $goodsListTemp = helper::getArrayColumns($this->goodsList, ['goods_id', 'total_price']);
+        $goodsListTemp = helper::getArrayColumns($this->goodsList, ['goods_id', 'goods_sku_id', 'total_price']);
         $CouponMoney = new GoodsDeductService;
         $rangeGoodsList = $CouponMoney->setGoodsList($goodsListTemp)
             ->setCouponInfo($couponInfo)
@@ -555,8 +555,9 @@ class Checkout extends BaseService
             ->getRangeGoodsList();
         // 分配订单商品优惠券抵扣金额
         foreach ($this->goodsList as &$goods) {
-            if (isset($rangeGoodsList[$goods['goods_id']])) {
-                $goods['coupon_money'] = $rangeGoodsList[$goods['goods_id']]['coupon_money'] / 100;
+            $goodsKey = "{$goods['goods_id']}-{$goods['goods_sku_id']}";
+            if (isset($rangeGoodsList[$goodsKey])) {
+                $goods['coupon_money'] = $rangeGoodsList[$goodsKey]['coupon_money'] / 100;
             }
         }
         // 记录订单优惠券信息