You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

52 lines
1.8 KiB

5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
  1. <?php
  2. namespace App\Controller\v3;
  3. use App\Constants\v3\ErrorCode;
  4. use App\Controller\BaseController;
  5. use App\Exception\ErrorCodeException;
  6. use App\Service\v3\Interfaces\OrderOnlineServiceInterface;
  7. use Hyperf\Di\Annotation\Inject;
  8. use App\Service\v3\Interfaces\ShopCartUpdateServiceInterface;
  9. use App\Request\v3\ShopCartUpdateRequest;
  10. class ShopCartUpdateController extends BaseController
  11. {
  12. /**
  13. * @Inject
  14. * @var OrderOnlineServiceInterface
  15. */
  16. protected $orderOnlineService;
  17. /**
  18. * @Inject
  19. * @var ShopCartUpdateServiceInterface
  20. */
  21. protected $shopCarServiceUpdate;
  22. public function update(ShopCartUpdateRequest $request)
  23. {
  24. $userId = $this->request->input('user_id',0);
  25. $goodsId = $this->request->input('goods_id',0);
  26. $num = $this->request->input('num',0);
  27. $activityType = $this->request->input('activity_type',1);
  28. if ($activityType == 2) {
  29. // TODO 校验当前用户今天是否超过了购买活动秒杀商品的(特定价格)的订单笔数
  30. if (!$this->orderOnlineService->checkIfBuyFlashGoodsToday($userId)) {
  31. throw new ErrorCodeException(
  32. ErrorCode::ORDER_ONLINE_LIMIT_BUY_COUNT,
  33. '[' . env('LIMIT_BUY_COUNT') . ']',
  34. ['params' => $this->request->all(), 'limit_prices' => env('LIMIT_BUY_COUNT_GOODS_PRICES')]
  35. );
  36. }
  37. }
  38. $res = $this->shopCarServiceUpdate->do($userId,$goodsId,$num,$activityType);
  39. return $this->success($res);
  40. }
  41. public function delete()
  42. {
  43. $shopcartIds = $this->request->input('shopcart_ids','');
  44. $res = $this->shopCarServiceUpdate->undo($shopcartIds);
  45. return $this->success($res);
  46. }
  47. }