|
|
@@ -663,6 +663,23 @@ class ProductClass extends BaseClass
|
|
|
$list[$k]['autoPrice'] = $autoPrice;
|
|
|
$list[$k]['autoSkPrice'] = $skAutoPrice;
|
|
|
$list[$k]['userPrice'] = 0;
|
|
|
+
|
|
|
+ // 限购缓存
|
|
|
+ if ($v['limitBuy'] > 0) {
|
|
|
+ $limitKey = 'limit_buy_' . $v['id'];
|
|
|
+ $has = Yii::$app->redis->executeCommand('HEXISTS', [$limitKey, 0]);
|
|
|
+ if (!empty($has)) {
|
|
|
+ // 获取缓存超时时间
|
|
|
+ $expire = Yii::$app->redis->executeCommand('TTL', [$limitKey]);
|
|
|
+ if ($expire > 0) {
|
|
|
+ $list[$k]['limitByuClearTime'] = date('Y-m-d H:i:s', time() + $expire);
|
|
|
+ } else {
|
|
|
+ $list[$k]['limitByuClearTime'] = '';
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ $list[$k]['limitByuClearTime'] = '';
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
return $list;
|
|
|
}
|
|
|
@@ -1893,12 +1910,19 @@ class ProductClass extends BaseClass
|
|
|
/***************产品模块*****************/
|
|
|
|
|
|
self::updateById($id, $upData);
|
|
|
+
|
|
|
+ //创建限购缓存
|
|
|
+ if ($data['limitBuy'] > 0 && $data['limitBuyClearTime'] != '') {
|
|
|
+ $limitByuClearTime = strtotime($data['limitBuyClearTime']);
|
|
|
+ if ($limitByuClearTime > 0) {
|
|
|
+ self::createLimitBuyCache($id, $limitByuClearTime - time());
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
//不影响其它直营店花材的上下架
|
|
|
unset($upData['status']);
|
|
|
|
|
|
if (isset($shop->default) && $shop->default == 1 && isset($shop->dataSync) && $shop->dataSync == 1) {
|
|
|
-
|
|
|
-
|
|
|
/***************产品模块*****************/
|
|
|
$ptClassList = PtCpClassClass::getAllByCondition(['delStatus' => 0], null, '*', 'id');
|
|
|
/***************产品模块*****************/
|
|
|
@@ -2091,10 +2115,8 @@ class ProductClass extends BaseClass
|
|
|
|
|
|
//直营店同步价格等重要因素
|
|
|
self::updateById($chainProduct->id, $params);
|
|
|
-
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
}
|
|
|
|
|
|
//变成自动改价 2021.4.14
|
|
|
@@ -2618,6 +2640,69 @@ class ProductClass extends BaseClass
|
|
|
return $product['mainId'] ?? 0;
|
|
|
}
|
|
|
|
|
|
+ // 创建限购缓存(有过期时间)
|
|
|
+ public static function createLimitBuyCache($productId, $seconds = 0)
|
|
|
+ {
|
|
|
+ $limitKey = 'limit_buy_' . $productId;
|
|
|
+ $clearMarkKey = 'limit_buy_clear_at:' . $productId;
|
|
|
+
|
|
|
+ $has = Yii::$app->redis->executeCommand('HEXISTS', [$limitKey, 0]);
|
|
|
+ if (!empty($has)) {
|
|
|
+ // 获取缓存超时时间
|
|
|
+ $expire = Yii::$app->redis->executeCommand('TTL', [$limitKey]);
|
|
|
+ if ($expire > 0) {
|
|
|
+ //return;
|
|
|
+ }
|
|
|
+ //删除缓存
|
|
|
+ Yii::$app->redis->executeCommand('HDEL', [$limitKey, 0]);
|
|
|
+ }
|
|
|
+ Yii::$app->redis->executeCommand('HSET', [$limitKey, 0, 0]);
|
|
|
+ if ($seconds > 0) {
|
|
|
+ $clearAt = time() + intval($seconds);
|
|
|
+ Yii::$app->redis->executeCommand('EXPIRE', [$limitKey, $seconds]);
|
|
|
+ Yii::$app->redis->executeCommand('SET', [$clearMarkKey, $clearAt]);
|
|
|
+
|
|
|
+ // 用 RabbitMQ 延迟消息在到期时清空订单项限购字段
|
|
|
+ $message = [
|
|
|
+ 'type' => 'limit_buy_clear',
|
|
|
+ 'productId' => $productId,
|
|
|
+ 'clearAt' => $clearAt,
|
|
|
+ ];
|
|
|
+ $producer = Yii::$app->rabbitmq->getProducer('cancelLimitBuyProducer');
|
|
|
+ $producer->publish($message, 'limitBuyDelayExchange', 'limitBuyDelayRoute', [
|
|
|
+ 'delivery_mode' => 2,
|
|
|
+ 'content_type' => 'application/octet-stream',
|
|
|
+ 'expiration' => (string)($seconds * 1000),
|
|
|
+ ]);
|
|
|
+ } else {
|
|
|
+ Yii::$app->redis->executeCommand('DEL', [$clearMarkKey]);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // 设置限购缓存
|
|
|
+ public static function setLimitBuyCache($productId, $customId, $limitBuy, $num)
|
|
|
+ {
|
|
|
+ if ($limitBuy <= 0) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ $limitKey = 'limit_buy_' . $productId;
|
|
|
+ $has = Yii::$app->redis->executeCommand('HEXISTS', [$limitKey, $customId]);
|
|
|
+ if (!empty($has)) {
|
|
|
+ $hasNum = Yii::$app->redis->executeCommand('HGET', [$limitKey, $customId]);
|
|
|
+ $lastNum = bcadd($hasNum, $num);
|
|
|
+ if ($lastNum > $limitBuy) {
|
|
|
+ util::fail('超出限购数');
|
|
|
+ }
|
|
|
+ Yii::$app->redis->executeCommand('HSET', [$limitKey, $customId, $lastNum]);
|
|
|
+ } else {
|
|
|
+ if ($num > $limitBuy) {
|
|
|
+ util::fail('超出限购数');
|
|
|
+ }
|
|
|
+ Yii::$app->redis->executeCommand('HSET', [$limitKey, $customId, $num]);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
//取消限购的缓存 ssh 20240605
|
|
|
public static function cancelLimitBuy($productId)
|
|
|
{
|
|
|
@@ -2628,6 +2713,33 @@ class ProductClass extends BaseClass
|
|
|
self::baseClearLimitBuy($productId, $field);
|
|
|
}
|
|
|
}
|
|
|
+ self::clearLimitBuyClearMark($productId);
|
|
|
+ }
|
|
|
+
|
|
|
+ // 校验清空限购消息是否是当前有效版本
|
|
|
+ public static function checkLimitBuyClearMessage($productId, $clearAt)
|
|
|
+ {
|
|
|
+ $productId = intval($productId);
|
|
|
+ $clearAt = intval($clearAt);
|
|
|
+ if ($productId <= 0 || $clearAt <= 0) {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+ $clearMarkKey = 'limit_buy_clear_at:' . $productId;
|
|
|
+ $currentClearAt = intval(Yii::$app->redis->executeCommand('GET', [$clearMarkKey]));
|
|
|
+ return $currentClearAt > 0 && $currentClearAt == $clearAt;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 清理限购清空标记
|
|
|
+ public static function clearLimitBuyClearMark($productId)
|
|
|
+ {
|
|
|
+ $productId = intval($productId);
|
|
|
+ if ($productId <= 0) {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ $clearMarkKey = 'limit_buy_clear_at:' . $productId;
|
|
|
+ Yii::$app->redis->executeCommand('DEL', [$clearMarkKey]);
|
|
|
+ return true;
|
|
|
}
|
|
|
|
|
|
//$num -1 表示减全部,大于-1表示减值
|