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.

62 lines
2.2 KiB

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