|
|
|
@ -254,6 +254,15 @@ class OrderOnlineService implements OrderOnlineServiceInterface |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
// TODO 校验当前用户今天是否超过了购买活动秒杀商品的(特定价格)的订单笔数
|
|
|
|
if (!$this->checkIfBuyFlashGoodsToday($userId)) { |
|
|
|
throw new ErrorCodeException( |
|
|
|
ErrorCode::ORDER_ONLINE_LIMIT_BUY_COUNT, |
|
|
|
'['.env('LIMIT_BUY_COUNT').']', |
|
|
|
['params' => $userId, 'limit_prices' => env('LIMIT_BUY_COUNT_GOODS_PRICES')] |
|
|
|
); |
|
|
|
} |
|
|
|
|
|
|
|
$check = $this->goodsActivityService->check($goods, $cart->num, $userId); |
|
|
|
if (true !== $check) { |
|
|
|
throw new ErrorCodeException($check, '['.$goods->name.']'); |
|
|
|
@ -809,4 +818,35 @@ class OrderOnlineService implements OrderOnlineServiceInterface |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* 校验用户今天是否买过x单[y,z]分钱的活动商品 |
|
|
|
* @param $userId |
|
|
|
*/ |
|
|
|
public function checkIfBuyFlashGoodsToday($userId) |
|
|
|
{ |
|
|
|
$mainTable = ApplicationContext::getContainer()->get(OrderMain::class)->getTable(); |
|
|
|
$orderTable = ApplicationContext::getContainer()->get(Order::class)->getTable(); |
|
|
|
$goodsTable = ApplicationContext::getContainer()->get(OrderGoods::class)->getTable(); |
|
|
|
|
|
|
|
$limitPrices = explode(',', env('LIMIT_BUY_COUNT_GOODS_PRICES')); |
|
|
|
$limitCount = intval(env('LIMIT_BUY_COUNT')); |
|
|
|
|
|
|
|
$countToday = OrderMain::query() |
|
|
|
->join($orderTable, $orderTable.'.order_main_id', '=', $mainTable.'.global_order_id') |
|
|
|
->join($goodsTable, $goodsTable.'.order_id', '=', $orderTable.'.id') |
|
|
|
->where($mainTable.'.updated_at', '>=', strtotime(date('Y-m-d 00:00:00'))) |
|
|
|
->where($mainTable.'.updated_at', '<=', strtotime(date('Y-m-d 23:59:59'))) |
|
|
|
->where([$goodsTable.'.activity_type' => 2]) |
|
|
|
->whereIn($mainTable.'.state', OrderState::LIMIT_BUY_COUNT) |
|
|
|
->where([$mainTable.'.user_id' => $userId]) |
|
|
|
->whereIn($goodsTable.'.price', $limitPrices) |
|
|
|
->count(); |
|
|
|
|
|
|
|
if ($countToday >= $limitCount) { |
|
|
|
return false; |
|
|
|
} |
|
|
|
|
|
|
|
return true; |
|
|
|
} |
|
|
|
} |