shish 1 day ago
parent
commit
b785b78638
2 changed files with 60 additions and 35 deletions
  1. 34 12
      app-ghs/controllers/OrderController.php
  2. 26 23
      biz-ghs/product/classes/ProductClass.php

+ 34 - 12
app-ghs/controllers/OrderController.php

@@ -1621,20 +1621,42 @@ class OrderController extends BaseController
                     'kdPrice' => $currentPrice,
                 ];
             } else {
-                //后端开单,如果没有改价格,并且数量达到花材满减要求,则自动给减价格,关键词 back_order_reach_discount_price
+                $limitBuy = $systemInfo['limitBuy'] ?? 0;
                 $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);
-                        $calcPrice = bcmul($reachNumDiscount, $bigNum, 2);
-                        if ($calcPrice > 0 && isset($post['modifyPrice']) && $post['modifyPrice'] > $calcPrice) {
-                            $productList[$ptKey]['price'] = $newUnitPrice;
-                            //提交给后端的总金额也要减掉,否则会有问题
+                if ($limitBuy > 0) {
+                    if ($bigNum > 0) {
+                        $addPriceMap['couldDiscount'] = 0;
+                        $orgPrice = ProductClass::getFinalPrice($systemInfo, $level, $priceMap, $addPriceMap);
+                        //限购在这里开发,关键词 xg_develop
+                        $productList[$ptKey]['price'] = $orgPrice;
+                        if ($currentPrice > $orgPrice) {
+                            $diffPrice = bcsub($currentPrice, $orgPrice, 2);
+                            $calcPrice = bcmul($diffPrice, $bigNum, 2);
                             $post['modifyPrice'] = bcsub($post['modifyPrice'], $calcPrice, 2);
-                            $post['reachDiscountPrice'] = bcadd($post['reachDiscountPrice'], $calcPrice, 2);
+                        }
+                        if ($currentPrice < $orgPrice) {
+                            $diffPrice = bcsub($orgPrice, $currentPrice, 2);
+                            $calcPrice = bcmul($diffPrice, $bigNum, 2);
+                            $post['modifyPrice'] = bcadd($post['modifyPrice'], $calcPrice, 2);
+                        }
+                    } else {
+                        util::fail('限购花材暂不能开小单位');
+                    }
+                } else {
+                    //后端开单,如果没有改价格,并且数量达到花材满减要求,则自动给减价格,关键词 back_order_reach_discount_price
+                    $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);
+                            $calcPrice = bcmul($reachNumDiscount, $bigNum, 2);
+                            if ($calcPrice > 0 && isset($post['modifyPrice']) && $post['modifyPrice'] > $calcPrice) {
+                                $productList[$ptKey]['price'] = $newUnitPrice;
+                                //提交给后端的总金额也要减掉,否则会有问题
+                                $post['modifyPrice'] = bcsub($post['modifyPrice'], $calcPrice, 2);
+                                $post['reachDiscountPrice'] = bcadd($post['reachDiscountPrice'], $calcPrice, 2);
+                            }
                         }
                     }
                 }

+ 26 - 23
biz-ghs/product/classes/ProductClass.php

@@ -809,34 +809,37 @@ class ProductClass extends BaseClass
         $hjDiscountPrice = $product['hjDiscountPrice'] ?? 0;
         $skDiscountPrice = $product['skDiscountPrice'] ?? 0;
         $limitBuy = $product['limitBuy'];
-        if ($discountPrice > 0) {
-            $oldPrice = $price;
-            if ($level == 0) {
-                $price = $skDiscountPrice;
-            }
-            if ($level == 1) {
-                $price = $discountPrice;
-            }
-            if ($level == 2) {
-                $price = $hjDiscountPrice;
-            }
+        //此参数用于后台开单,如果花材限购的,则不考虑特价,只取原价
+        $couldDiscount = $params['couldDiscount'] ?? 1;
+        if($couldDiscount == 1) {
+            if ($discountPrice > 0) {
+                $oldPrice = $price;
+                if ($level == 0) {
+                    $price = $skDiscountPrice;
+                }
+                if ($level == 1) {
+                    $price = $discountPrice;
+                }
+                if ($level == 2) {
+                    $price = $hjDiscountPrice;
+                }
 
-            //超出限购情况的价格计算
-            if ($limitBuy > 0 && $totalBuyNum > $limitBuy) {
-                $hasBuyNum = $totalBuyNum - $buyNum;
-                if ($hasBuyNum >= $limitBuy) {
-                    $price = $oldPrice;
-                } else {
-                    $overBuyNum = $totalBuyNum - $limitBuy;
-                    $overBuyPrice = bcmul($overBuyNum, $oldPrice, 2); // 超出限购部分的价格
+                //超出限购情况的价格计算
+                if ($limitBuy > 0 && $totalBuyNum > $limitBuy) {
+                    $hasBuyNum = $totalBuyNum - $buyNum;
+                    if ($hasBuyNum >= $limitBuy) {
+                        $price = $oldPrice;
+                    } else {
+                        $overBuyNum = $totalBuyNum - $limitBuy;
+                        $overBuyPrice = bcmul($overBuyNum, $oldPrice, 2); // 超出限购部分的价格
 
-                    $leftBuyNum = $buyNum - $overBuyNum;
-                    $leftBuyPrice = bcmul($leftBuyNum, $price, 2); // 未超出限购部分的价格
-                    $price = bcdiv($overBuyPrice + $leftBuyPrice, $buyNum, 2); // 最终价格
+                        $leftBuyNum = $buyNum - $overBuyNum;
+                        $leftBuyPrice = bcmul($leftBuyNum, $price, 2); // 未超出限购部分的价格
+                        $price = bcdiv($overBuyPrice + $leftBuyPrice, $buyNum, 2); // 最终价格
+                    }
                 }
             }
         }
-
         //满多少数量,再优惠多少钱
         $reachNum = $product['reachNum'] ?? 0;
         $reachNumDiscount = $product['reachNumDiscount'] ?? 0;