|
|
@@ -767,9 +767,19 @@ class ProductClass extends BaseClass
|
|
|
return $list;
|
|
|
}
|
|
|
|
|
|
- //输出价格 ssh 20211009
|
|
|
- //$params 原来是 $addPriceMap,现在 $addPriceMap 值没用了,把它改成 $params ,用作传别的参数
|
|
|
- public static function getFinalPrice($product, $level, $priceMap, $params, $changePrice = 0, $buyNum = 0)
|
|
|
+ /**
|
|
|
+ * 输出价格 ssh 20211009
|
|
|
+ * @param $product 花材信息
|
|
|
+ * @param $level 等级
|
|
|
+ * @param $priceMap 各个等级对应的price addPrice字段
|
|
|
+ * @param $params 原来是 $addPriceMap,现在 $addPriceMap 值没用了,把它改成 $params ,用作传别的参数
|
|
|
+ * @param int $changePrice 开单改价
|
|
|
+ * @param int $buyNum 当前购买数量
|
|
|
+ * @param int $totalBuyNum 已购买总数量
|
|
|
+ * @return int|string|null
|
|
|
+ * @throws \Exception
|
|
|
+ */
|
|
|
+ public static function getFinalPrice($product, $level, $priceMap, $params, $changePrice = 0, $buyNum = 0, $totalBuyNum = 0)
|
|
|
{
|
|
|
//开单改价优先级最高
|
|
|
if ($changePrice > 0) {
|
|
|
@@ -808,10 +818,13 @@ class ProductClass extends BaseClass
|
|
|
}
|
|
|
|
|
|
//超出限购情况的价格计算
|
|
|
- if ($limitBuy > 0 && $buyNum > $limitBuy) {
|
|
|
- $allPrice = $price * $limitBuy;
|
|
|
- $allPrice = $allPrice + (($buyNum - $limitBuy) * $oldPrice);
|
|
|
- $price = bcdiv($allPrice, $buyNum, 2);
|
|
|
+ if ($limitBuy > 0 && $totalBuyNum > $limitBuy) {
|
|
|
+ $overBuyNum = $totalBuyNum - $limitBuy;
|
|
|
+ $overBuyPrice = bcmul($overBuyNum, $oldPrice, 2); // 超出限购部分的价格
|
|
|
+
|
|
|
+ $leftBuyNum = $buyNum - $overBuyNum;
|
|
|
+ $leftBuyPrice = bcmul($leftBuyNum, $price, 2); // 未超出限购部分的价格
|
|
|
+ $price = bcdiv($overBuyPrice + $leftBuyPrice, $buyNum, 2); // 最终价格
|
|
|
}
|
|
|
}
|
|
|
|