|
|
@@ -48,6 +48,7 @@ class ProductClass extends BaseClass
|
|
|
const CLEAR_MARK_KEY = 'limit_buy_clear_at:';
|
|
|
const CLEAR_LOOP_KEY = 'limit_buy_clear_loop:';
|
|
|
const LIMIT_BUY_ROLLBACK_SNAPSHOT_KEY = 'limitBuyRollbackSnapshot'; //记录限购旧值快照缓存键
|
|
|
+ const RECOVER_LIMIT_BUY_KEY = 'recover_limit_buy:'; //记录限购旧值快照缓存键
|
|
|
|
|
|
public static function getNotShowFrontHideMainIds()
|
|
|
{
|
|
|
@@ -1127,6 +1128,8 @@ class ProductClass extends BaseClass
|
|
|
//库存=0 下架商品,特价去掉,限购去掉 lqh 2021.7.9 ssh 20251106 花材满减去掉 20260318
|
|
|
if ($newStock <= 0) {
|
|
|
self::changeStatus($productId, 2);
|
|
|
+ //限购数量重置为 0,但会把限购不为 0 的数据记录到缓存
|
|
|
+ self::createRecoverLimitBuyCache($productId, $productData->limitBuy);
|
|
|
}
|
|
|
|
|
|
util::unlock($key);
|
|
|
@@ -2633,6 +2636,8 @@ class ProductClass extends BaseClass
|
|
|
//花材满减去掉 ssh 20260318
|
|
|
$data['reachNum'] = 0;
|
|
|
$data['reachNumDiscount'] = 0;
|
|
|
+ //花材去除限购
|
|
|
+ $data['limitBuy'] = 0;
|
|
|
}
|
|
|
return self::updateById($productId, $data);
|
|
|
}
|
|
|
@@ -3244,7 +3249,7 @@ class ProductClass extends BaseClass
|
|
|
* @param int $productId
|
|
|
* @return bool
|
|
|
*/
|
|
|
- public static function clearLimitBuyByProductId($productId)
|
|
|
+ public static function clearLimitBuyByProductId($productId, $oldLimitBuy = 0)
|
|
|
{
|
|
|
$productId = intval($productId);
|
|
|
if ($productId <= 0) {
|
|
|
@@ -3252,8 +3257,87 @@ class ProductClass extends BaseClass
|
|
|
}
|
|
|
|
|
|
self::updateById($productId, ['limitBuy' => 0]);
|
|
|
+
|
|
|
+
|
|
|
+ if ($oldLimitBuy > 0) {
|
|
|
+ self::createRecoverLimitBuyCache($productId, $oldLimitBuy);
|
|
|
+ }
|
|
|
return true;
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 创建限购旧值快照缓存
|
|
|
+ * @param $productId
|
|
|
+ * @param $oldLimitBuy
|
|
|
+ * @return bool
|
|
|
+ */
|
|
|
+ public static function createRecoverLimitBuyCache($productId, $oldLimitBuy)
|
|
|
+ {
|
|
|
+ $productId = intval($productId);
|
|
|
+ if ($productId <= 0) {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+ $limitKey = self::RECOVER_LIMIT_BUY_KEY . $productId;
|
|
|
+ Yii::$app->redis->executeCommand('SET', [$limitKey, $oldLimitBuy]);
|
|
|
+ Yii::$app->redis->executeCommand('EXPIRE', [$limitKey, 1200]);
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 删除限购旧值快照缓存
|
|
|
+ * @param $productId
|
|
|
+ * @return bool
|
|
|
+ */
|
|
|
+ public static function deleteRecoverLimitBuyCache($productId)
|
|
|
+ {
|
|
|
+ $productId = intval($productId);
|
|
|
+ if ($productId <= 0) {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ $limitKey = self::RECOVER_LIMIT_BUY_KEY . $productId;
|
|
|
+ Yii::$app->redis->executeCommand('DEL', [$limitKey]);
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 获取限购旧值快照缓存
|
|
|
+ * @param $productId
|
|
|
+ * @return bool
|
|
|
+ */
|
|
|
+ public static function getRecoverLimitBuyCache($productId)
|
|
|
+ {
|
|
|
+ $productId = intval($productId);
|
|
|
+ if ($productId <= 0) {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ $limitKey = self::RECOVER_LIMIT_BUY_KEY . $productId;
|
|
|
+ return Yii::$app->redis->executeCommand('GET', [$limitKey]);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 库存从 0 回滚时,尝试恢复限购数量
|
|
|
+ * @param int $productId
|
|
|
+ * @param mixed $oldStock
|
|
|
+ * @return bool
|
|
|
+ */
|
|
|
+ public static function tryRecoverLimitBuyWhenStockRollbackFromZero($productId, $oldStock)
|
|
|
+ {
|
|
|
+ if (floatval($oldStock) > 0) {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ $recoverLimitBuy = self::getRecoverLimitBuyCache($productId);
|
|
|
+ if ($recoverLimitBuy === false || $recoverLimitBuy === null || $recoverLimitBuy === '') {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ $recoverLimitBuy = intval($recoverLimitBuy);
|
|
|
+ if ($recoverLimitBuy <= 0) {
|
|
|
+ self::deleteRecoverLimitBuyCache($productId);
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ self::updateById($productId, ['limitBuy' => $recoverLimitBuy]);
|
|
|
+ self::deleteRecoverLimitBuyCache($productId);
|
|
|
+ return true;
|
|
|
+ }
|
|
|
}
|
|
|
|