Kaynağa Gözat

计算优惠券优惠金额, 由于自增的误区, 导致优惠券金额少分配问题修复

Signed-off-by: Slowlyo <1821725017@qq.com>
Slowlyo 3 yıl önce
ebeveyn
işleme
21a6c3d3d1
1 değiştirilmiş dosya ile 8 ekleme ve 3 silme
  1. 8 3
      app/api/service/coupon/GoodsDeduct.php

+ 8 - 3
app/api/service/coupon/GoodsDeduct.php

@@ -203,9 +203,14 @@ class GoodsDeduct extends BaseService
     private function setGoodsListCouponMoneyDiff($assignedCouponMoney): void
     {
         $tempDiff = $this->actualReducedMoney - $assignedCouponMoney;
-        foreach ($this->rangeGoodsList as &$goods) {
-            if ($tempDiff < 1) break;
-            $goods['coupon_money']++ && $tempDiff--;
+
+        while ($tempDiff > 0){
+            foreach ($this->rangeGoodsList as &$goods) {
+                if ($tempDiff < 1) break;
+                if(!$goods['coupon_money']) continue;
+                $goods['coupon_money']++;
+                $tempDiff--;
+            }
         }
     }
 }