|
|
@@ -2598,9 +2598,57 @@ class ProductClass extends BaseClass
|
|
|
$arr = Yii::$app->redis->executeCommand('HKEYS', [$limitKey]);
|
|
|
if (!empty($arr)) {
|
|
|
foreach ($arr as $field) {
|
|
|
- Yii::$app->redis->executeCommand('HDEL', [$limitKey, $field]);
|
|
|
+ self::baseClearLimitBuy($productId, $field);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ //$num -1 表示减全部,大于-1表示减值
|
|
|
+ public static function baseClearLimitBuy($productId, $customId, $num = -1)
|
|
|
+ {
|
|
|
+ $limitKey = 'limit_buy_' . $productId;
|
|
|
+ if ($num <= -1) {
|
|
|
+ //清掉全部
|
|
|
+ Yii::$app->redis->executeCommand('HDEL', [$limitKey, $customId]);
|
|
|
+ } else {
|
|
|
+ $hasNum = Yii::$app->redis->executeCommand('HGET', [$limitKey, $customId]);
|
|
|
+ $remainNum = $hasNum > $num ? bcsub($num, $hasNum) : 0;
|
|
|
+ $remainNum = floor($remainNum);
|
|
|
+ if ($remainNum > 0) {
|
|
|
+ Yii::$app->redis->executeCommand('HSET', [$limitKey, $customId, $remainNum]);
|
|
|
+ } else {
|
|
|
+ Yii::$app->redis->executeCommand('HDEL', [$limitKey, $customId]);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ public static function getHasLimitBuyList($product)
|
|
|
+ {
|
|
|
+ $productId = $product->id;
|
|
|
+ $limitBuy = $product->limitBuy ?? 0;
|
|
|
+ $limitKey = 'limit_buy_' . $productId;
|
|
|
+ $arr = Yii::$app->redis->executeCommand('HKEYS', [$limitKey]);
|
|
|
+ $customList = [];
|
|
|
+ if (!empty($arr)) {
|
|
|
+ $numMap = [];
|
|
|
+ $ids = [];
|
|
|
+ foreach ($arr as $customId) {
|
|
|
+ $num = Yii::$app->redis->executeCommand('HGET', [$limitKey, $customId]);
|
|
|
+ $numMap[$customId] = $num;
|
|
|
+ $ids[] = $customId;
|
|
|
+ }
|
|
|
+ $customList = CustomClass::getAllByCondition(['id' => ['in', $ids]], null, '*');
|
|
|
+ foreach ($customList as $key => $val) {
|
|
|
+ $customId = $val['id'];
|
|
|
+ $num = $numMap[$customId] ?? 0;
|
|
|
+ $customList[$key]['hasLimitBuyNum'] = $num;
|
|
|
+ $customList[$key]['hasReachLimitBuyNum'] = $num >= $limitBuy ? 1 : 0;
|
|
|
+ $avatar = $val['avatar'] ?? '';
|
|
|
+ $smallAvatar = imgUtil::groupImg($avatar);
|
|
|
+ $customList[$key]['smallAvatar'] = $smallAvatar . "?x-oss-process=image/resize,m_fill,h_80,w_80";
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return $customList;
|
|
|
+ }
|
|
|
+
|
|
|
}
|