Ver código fonte

!4 计算优惠券优惠金额, 由于自增的误区, 导致优惠券金额少分配问题修复
Merge pull request !4 from master

萤火科技 3 anos atrás
pai
commit
223cb8a0c6
1 arquivos alterados com 8 adições e 3 exclusões
  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--;
+            }
         }
     }
 }