Browse Source

Merge branch 'hotfix_activity_limit_buy_count' into master

master
weigang 5 years ago
parent
commit
87453f5e4f
  1. 6
      app/Constants/v3/ErrorCode.php
  2. 9
      app/Constants/v3/OrderState.php
  3. 1
      app/Controller/v3/OrderOnlineController.php
  4. 21
      app/Controller/v3/ShopCartUpdateController.php
  5. 2
      app/Service/v3/Implementations/OrderListService.php
  6. 40
      app/Service/v3/Implementations/OrderOnlineService.php
  7. 7
      app/Service/v3/Interfaces/OrderOnlineServiceInterface.php

6
app/Constants/v3/ErrorCode.php

@ -101,6 +101,12 @@ class ErrorCode extends AbstractConstants
*/
const ORDER_ONLINE_LIMIT_STORE_BUY_SELF = 613;
/**
* 今天当前用户购买的活动商品订单笔数已经超过限制
* @Message("您今天已经参与活动商品秒杀的次数已经用完咯,明天再来吧")
*/
const ORDER_ONLINE_LIMIT_BUY_COUNT = 614;
/************************************/
/* 支付相关 651-700 */
/************************************/

9
app/Constants/v3/OrderState.php

@ -90,4 +90,13 @@ class OrderState extends AbstractConstants
*/
const CAN_REFUND_DIRECT = [self::COMPLETED, self::EVALUATED, self::REFUND_REFUSE];
/**
* @Message("限制当天购买秒杀商品订单数")
*/
const LIMIT_BUY_COUNT = [
self::UNPAID, self::DELIVERY, self::PAID,
self::COMPLETED, self::EVALUATED,
self::REFUNDING, self::REFUND_REFUSE, self::REFUNDED_DIRECT
];
}

1
app/Controller/v3/OrderOnlineController.php

@ -205,6 +205,7 @@ class OrderOnlineController extends BaseController
// 下单
$params = $request->validated();
$couponIds = isset($params['coupon_ids'])&&$params['coupon_ids'] ? explode(',', $params['coupon_ids']) : [];
$data = $this->orderOnlineService->do(
$params['market_id'],

21
app/Controller/v3/ShopCartUpdateController.php

@ -2,12 +2,21 @@
namespace App\Controller\v3;
use App\Constants\v3\ErrorCode;
use App\Controller\BaseController;
use App\Exception\ErrorCodeException;
use App\Service\v3\Interfaces\OrderOnlineServiceInterface;
use Hyperf\Di\Annotation\Inject;
use App\Service\v3\Interfaces\ShopCartUpdateServiceInterface;
use App\Request\v3\ShopCartUpdateRequest;
class ShopCartUpdateController extends BaseController
{
/**
* @Inject
* @var OrderOnlineServiceInterface
*/
protected $orderOnlineService;
/**
* @Inject
* @var ShopCartUpdateServiceInterface
@ -19,6 +28,18 @@ class ShopCartUpdateController extends BaseController
$goodsId = $this->request->input('goods_id',0);
$num = $this->request->input('num',0);
$activityType = $this->request->input('activity_type',1);
if ($activityType == 2) {
// TODO 校验当前用户今天是否超过了购买活动秒杀商品的(特定价格)的订单笔数
if (!$this->orderOnlineService->checkIfBuyFlashGoodsToday($userId)) {
throw new ErrorCodeException(
ErrorCode::ORDER_ONLINE_LIMIT_BUY_COUNT,
'[' . env('LIMIT_BUY_COUNT') . ']',
['params' => $this->request->all(), 'limit_prices' => env('LIMIT_BUY_COUNT_GOODS_PRICES')]
);
}
}
$res = $this->shopCarServiceUpdate->do($userId,$goodsId,$num,$activityType);
return $this->success($res);
}

2
app/Service/v3/Implementations/OrderListService.php

@ -70,7 +70,7 @@ class OrderListService implements OrderListServiceInterface
$paginate = $builder->orderBy('created_at', 'desc')->paginate($pagesize);
$orders = $paginate->toArray();
return ['has_more_pages' => $paginate->hasMorePages(), 'orders' => $orders['data'], 'note' => '待付款订单15分钟后将自动取消,请尽快支付!'];
return ['has_more_pages' => $paginate->hasMorePages(), 'orders' => $orders['data'], 'note' => '待付款订单10分钟后将自动取消,请尽快支付!'];
}
public function onlineByStore($storeId, $tab, $page=1, $pagesize=10)

40
app/Service/v3/Implementations/OrderOnlineService.php

@ -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;
}
}

7
app/Service/v3/Interfaces/OrderOnlineServiceInterface.php

@ -76,4 +76,11 @@ interface OrderOnlineServiceInterface
* @return mixed
*/
public function autoCancel();
/**
* 校验今天是否买过x单[y,z]分钱的活动商品
* @param $userId
* @return mixed
*/
public function checkIfBuyFlashGoodsToday($userId);
}
Loading…
Cancel
Save