|
|
@@ -38,7 +38,7 @@ class ProductClass extends BaseClass
|
|
|
use OrderTrait;
|
|
|
|
|
|
public static $baseFile = '\bizGhs\product\models\Product';
|
|
|
- const LIMIT_BUY_ROLLBACK_SNAPSHOT_KEY = 'limitBuyRollbackSnapshot'; //记录限购旧值快照缓存键
|
|
|
+
|
|
|
const PRICE_LABEL_AUTO = 1; //自动调价
|
|
|
const PRICE_LABEL_CHANGE = 2; //改价
|
|
|
const LOCK_STOCK = 'lock_stock';//修改库存锁
|
|
|
@@ -46,6 +46,10 @@ class ProductClass extends BaseClass
|
|
|
const LOCK_PRICE = 'lock_price'; //改价锁
|
|
|
const LOCK_CHECK_STOCK = 'lock_check_stock'; //判断库存
|
|
|
|
|
|
+ const LIMIT_BUY_KEY = 'limit_buy_';
|
|
|
+ const CLEAR_MARK_KEY = 'limit_buy_clear_at:';
|
|
|
+ const LIMIT_BUY_ROLLBACK_SNAPSHOT_KEY = 'limitBuyRollbackSnapshot'; //记录限购旧值快照缓存键
|
|
|
+
|
|
|
public static function getNotShowFrontHideMainIds()
|
|
|
{
|
|
|
if (getenv('YII_ENV', 'local') == 'production') {
|
|
|
@@ -668,7 +672,7 @@ class ProductClass extends BaseClass
|
|
|
|
|
|
// 限购缓存
|
|
|
if ($v['limitBuy'] > 0) {
|
|
|
- $limitKey = 'limit_buy_' . $v['id'];
|
|
|
+ $limitKey = self::LIMIT_BUY_KEY . $v['id'];
|
|
|
$has = Yii::$app->redis->executeCommand('HEXISTS', [$limitKey, 0]);
|
|
|
if (!empty($has)) {
|
|
|
// 获取缓存超时时间
|
|
|
@@ -786,10 +790,13 @@ class ProductClass extends BaseClass
|
|
|
$price = $product[$currentPriceField] ?? 0;
|
|
|
}
|
|
|
|
|
|
+ //特价与限购的综合处理
|
|
|
$discountPrice = $product['discountPrice'] ?? 0;
|
|
|
$hjDiscountPrice = $product['hjDiscountPrice'] ?? 0;
|
|
|
$skDiscountPrice = $product['skDiscountPrice'] ?? 0;
|
|
|
+ $limitBuy = $product['limitBuy'];
|
|
|
if ($discountPrice > 0) {
|
|
|
+ $oldPrice = $price;
|
|
|
if ($level == 0) {
|
|
|
$price = $skDiscountPrice;
|
|
|
}
|
|
|
@@ -799,7 +806,16 @@ class ProductClass extends BaseClass
|
|
|
if ($level == 2) {
|
|
|
$price = $hjDiscountPrice;
|
|
|
}
|
|
|
+
|
|
|
+ //超出限购情况的价格计算
|
|
|
+ if ($limitBuy > 0 && $buyNum > $limitBuy) {
|
|
|
+ $allPrice = $price * $limitBuy;
|
|
|
+ $allPrice = $allPrice + (($buyNum - $limitBuy) * $oldPrice);
|
|
|
+ $price = bcdiv($allPrice, $buyNum, 2);
|
|
|
+ }
|
|
|
}
|
|
|
+
|
|
|
+ //满多少数量,再优惠多少钱
|
|
|
$reachNum = $product['reachNum'] ?? 0;
|
|
|
$reachNumDiscount = $product['reachNumDiscount'] ?? 0;
|
|
|
if ($reachNum > 0) {
|
|
|
@@ -1476,7 +1492,6 @@ class ProductClass extends BaseClass
|
|
|
$totalReachDiscount = bcadd($totalReachDiscount, $currentReachDiscount, 2);
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
} else {
|
|
|
$itemPrice = $v['unitPrice'] ?? 0;
|
|
|
$thisPrice = $itemPrice;
|
|
|
@@ -1492,8 +1507,6 @@ class ProductClass extends BaseClass
|
|
|
$tmp['productId'] = $ghsProductId;
|
|
|
$tmp['price'] = $price;
|
|
|
|
|
|
- $totalPrice = bcadd($totalPrice, $price, 2);
|
|
|
-
|
|
|
$tmp['name'] = $currentGhsProduct['name'] ?? '';
|
|
|
$tmp['smallUnit'] = $currentGhsProduct['smallUnit'] ?? '支';
|
|
|
$tmp['bigUnit'] = $currentGhsProduct['bigUnit'] ?? '扎';
|
|
|
@@ -1525,6 +1538,7 @@ class ProductClass extends BaseClass
|
|
|
$tmp['discountPrice'] = $currentGhsProduct['discountPrice'];
|
|
|
$tmp['skDiscountPrice'] = $currentGhsProduct['skDiscountPrice'];
|
|
|
|
|
|
+ $totalPrice = bcadd($totalPrice, $price, 2);
|
|
|
$totalBigNum += $bigNum;
|
|
|
$totalSmallNum += $smallNum;
|
|
|
|
|
|
@@ -2646,8 +2660,8 @@ class ProductClass extends BaseClass
|
|
|
// 创建限购缓存(有过期时间)
|
|
|
public static function createLimitBuyCache($productId, $seconds = 0)
|
|
|
{
|
|
|
- $limitKey = 'limit_buy_' . $productId;
|
|
|
- $clearMarkKey = 'limit_buy_clear_at:' . $productId;
|
|
|
+ $limitKey = self::LIMIT_BUY_KEY . $productId;
|
|
|
+ $clearMarkKey = self::CLEAR_MARK_KEY . $productId;
|
|
|
|
|
|
$has = Yii::$app->redis->executeCommand('HEXISTS', [$limitKey, 0]);
|
|
|
if (!empty($has)) {
|
|
|
@@ -2749,7 +2763,7 @@ class ProductClass extends BaseClass
|
|
|
if ($productId <= 0 || $customId <= 0) {
|
|
|
continue;
|
|
|
}
|
|
|
- $limitKey = 'limit_buy_' . $productId;
|
|
|
+ $limitKey = self::LIMIT_BUY_KEY . $productId;
|
|
|
$hasOldValue = intval($snapshot['hasOldValue'] ?? 0);
|
|
|
if ($hasOldValue == 1) {
|
|
|
$oldValue = $snapshot['oldValue'] ?? '0';
|
|
|
@@ -2771,7 +2785,7 @@ class ProductClass extends BaseClass
|
|
|
}
|
|
|
|
|
|
$productId = $product['productId'];
|
|
|
- $limitKey = 'limit_buy_' . $productId;
|
|
|
+ $limitKey = self::LIMIT_BUY_KEY . $productId;
|
|
|
$has = Yii::$app->redis->executeCommand('HEXISTS', [$limitKey, $customId]);
|
|
|
if (!empty($has)) {
|
|
|
$hasNum = Yii::$app->redis->executeCommand('HGET', [$limitKey, $customId]);
|
|
|
@@ -2803,7 +2817,7 @@ class ProductClass extends BaseClass
|
|
|
//取消限购的缓存 ssh 20240605
|
|
|
public static function cancelLimitBuy($productId)
|
|
|
{
|
|
|
- $limitKey = 'limit_buy_' . $productId;
|
|
|
+ $limitKey = self::LIMIT_BUY_KEY . $productId;
|
|
|
$arr = Yii::$app->redis->executeCommand('HKEYS', [$limitKey]);
|
|
|
if (!empty($arr)) {
|
|
|
foreach ($arr as $field) {
|
|
|
@@ -2822,7 +2836,7 @@ class ProductClass extends BaseClass
|
|
|
return false;
|
|
|
}
|
|
|
|
|
|
- $clearMarkKey = 'limit_buy_clear_at:' . $productId;
|
|
|
+ $clearMarkKey = self::CLEAR_MARK_KEY . $productId;
|
|
|
$currentClearAt = intval(Yii::$app->redis->executeCommand('GET', [$clearMarkKey]));
|
|
|
return $currentClearAt > 0 && $currentClearAt == $clearAt;
|
|
|
}
|
|
|
@@ -2834,7 +2848,7 @@ class ProductClass extends BaseClass
|
|
|
if ($productId <= 0) {
|
|
|
return false;
|
|
|
}
|
|
|
- $clearMarkKey = 'limit_buy_clear_at:' . $productId;
|
|
|
+ $clearMarkKey = self::CLEAR_MARK_KEY . $productId;
|
|
|
Yii::$app->redis->executeCommand('DEL', [$clearMarkKey]);
|
|
|
return true;
|
|
|
}
|
|
|
@@ -2842,7 +2856,7 @@ class ProductClass extends BaseClass
|
|
|
//$num -1 表示减全部,大于-1表示减值
|
|
|
public static function baseClearLimitBuy($productId, $customId, $num = -1)
|
|
|
{
|
|
|
- $limitKey = 'limit_buy_' . $productId;
|
|
|
+ $limitKey = self::LIMIT_BUY_KEY . $productId;
|
|
|
if ($num <= -1) {
|
|
|
//清掉全部
|
|
|
Yii::$app->redis->executeCommand('HDEL', [$limitKey, $customId]);
|
|
|
@@ -2862,7 +2876,7 @@ class ProductClass extends BaseClass
|
|
|
{
|
|
|
$productId = $product->id;
|
|
|
$limitBuy = $product->limitBuy ?? 0;
|
|
|
- $limitKey = 'limit_buy_' . $productId;
|
|
|
+ $limitKey = self::LIMIT_BUY_KEY . $productId;
|
|
|
$arr = Yii::$app->redis->executeCommand('HKEYS', [$limitKey]);
|
|
|
$customList = [];
|
|
|
if (!empty($arr)) {
|