|
|
|
@ -160,33 +160,46 @@ class GoodsActivityService implements GoodsActivityServiceInterface |
|
|
|
->whereIn('id', $goodsIds) |
|
|
|
->get()->toArray(); |
|
|
|
|
|
|
|
$redis = ApplicationContext::getContainer()->get(Redis::class); |
|
|
|
$activityTypeLimitNumsKey = 'activity_type_limit_nums'; |
|
|
|
$limitNums = $redis->hGetAll($activityTypeLimitNumsKey); |
|
|
|
|
|
|
|
if (empty($limitNums)) { |
|
|
|
|
|
|
|
$limitNums = [ |
|
|
|
ActivityType::FLASH_SALE => 0, |
|
|
|
ActivityType::GROUP_BUY => 0, |
|
|
|
ActivityType::NEW_PRODUCT => 0, |
|
|
|
]; |
|
|
|
} |
|
|
|
|
|
|
|
$buyNum = [ |
|
|
|
ActivityType::FLASH_SALE => 0, |
|
|
|
ActivityType::GROUP_BUY => 0, |
|
|
|
ActivityType::NEW_PRODUCT => 0, |
|
|
|
]; |
|
|
|
|
|
|
|
// $redis = ApplicationContext::getContainer()->get(Redis::class);
|
|
|
|
// $activityTypeLimitNumsKey = 'activity_type_limit_nums';
|
|
|
|
// $limitNums = $redis->hGetAll($activityTypeLimitNumsKey);
|
|
|
|
//
|
|
|
|
// if (empty($limitNums)) {
|
|
|
|
//
|
|
|
|
// $limitNums = [
|
|
|
|
// ActivityType::FLASH_SALE => 0,
|
|
|
|
// ActivityType::GROUP_BUY => 0,
|
|
|
|
// ActivityType::NEW_PRODUCT => 0,
|
|
|
|
// ];
|
|
|
|
// }
|
|
|
|
//
|
|
|
|
// $buyNum = [
|
|
|
|
// ActivityType::FLASH_SALE => 0,
|
|
|
|
// ActivityType::GROUP_BUY => 0,
|
|
|
|
// ActivityType::NEW_PRODUCT => 0,
|
|
|
|
// ];
|
|
|
|
//
|
|
|
|
// foreach ($sourceGoods as $key => &$goods) {
|
|
|
|
//
|
|
|
|
// if ($limitNums[$goods['type']] == 0) { // 不限制同类购买商品种数,也就是可以同时购买多款不同商品
|
|
|
|
// continue;
|
|
|
|
// }
|
|
|
|
//
|
|
|
|
// $buyNum[$goods['type']] += 1;
|
|
|
|
// if ($buyNum[$goods['type']] > $limitNums[$goods['type']]) {
|
|
|
|
// return false;
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
|
|
|
|
$buyNum = []; |
|
|
|
foreach ($sourceGoods as $key => &$goods) { |
|
|
|
|
|
|
|
if ($limitNums[$goods['type']] == 0) { // 不限制同类购买商品种数,也就是可以同时购买多款不同商品
|
|
|
|
continue; |
|
|
|
if (isset($buyNum[$goods['type_limit']])) { |
|
|
|
$buyNum[$goods['type_limit']]++; |
|
|
|
} else { |
|
|
|
$buyNum[$goods['type_limit']] = 1; |
|
|
|
} |
|
|
|
|
|
|
|
$buyNum[$goods['type']] += 1; |
|
|
|
if ($buyNum[$goods['type']] > $limitNums[$goods['type']]) { |
|
|
|
if ($goods['type_limit'] != 0 && $buyNum[$goods['type_limit']] > $goods['type_limit']) { |
|
|
|
return false; |
|
|
|
} |
|
|
|
} |
|
|
|
|