瀏覽代碼

满减支持

shish 5 月之前
父節點
當前提交
1b3d1b6f4d
共有 1 個文件被更改,包括 18 次插入1 次删除
  1. 18 1
      app-ghs/controllers/OrderController.php

+ 18 - 1
app-ghs/controllers/OrderController.php

@@ -1239,7 +1239,7 @@ class OrderController extends BaseController
         $addPriceMap['risePercent'] = $custom['risePercent'] ?? 0;
 
         $level = $custom['level'] ?? 1;
-        foreach ($productList as $currentProduct) {
+        foreach ($productList as $ptKey => $currentProduct) {
             $currentPrice = $currentProduct['price'] ?? 0;
             $currentId = $currentProduct['productId'] ?? 0;
             $systemInfo = $itemInfo[$currentId] ?? [];
@@ -1267,6 +1267,23 @@ class OrderController extends BaseController
                     'price' => $systemPrice,
                     'kdPrice' => $currentPrice,
                 ];
+            } else {
+                //后端开单,如果没有改价格,并且数量达到花材满减要求,则自动给减价格
+                $bigNum = $currentProduct['bigNum'] ?? 0;
+                $reachNum = $systemInfo['reachNum'] ?? 0;
+                if ($reachNum > 0 && $bigNum >= $reachNum) {
+                    $reachNumDiscount = $systemInfo['reachNumDiscount'] ?? 0;
+                    $unitPrice = $currentProduct['price'] ?? 0;
+                    if ($unitPrice > $reachNumDiscount) {
+                        $newUnitPrice = bcsub($unitPrice, $reachNumDiscount, 2);
+                        $productList[$ptKey]['price'] = $newUnitPrice;
+                        $calcPrice = bcmul($reachNumDiscount, $bigNum, 2);
+                        if ($calcPrice > 0 && isset($post['modifyPrice']) && $post['modifyPrice'] > $calcPrice) {
+                            //提交给后端的总金额也要减掉,否则会有问题
+                            $post['modifyPrice'] = bcsub($post['modifyPrice'], $calcPrice, 2);
+                        }
+                    }
+                }
             }
         }
         //解决开单提交订单时,别人修改价格,造成提交价格不是真实卖价问题!!