From 2ac9f20fe7a8075137aac6849d02fab23cf7f32f Mon Sep 17 00:00:00 2001 From: Lemon <15040771@qq.com> Date: Wed, 4 Nov 2020 09:24:02 +0800 Subject: [PATCH] =?UTF-8?q?=E8=B4=AD=E7=89=A9=E8=BD=A6=E6=95=B0=E9=87=8F?= =?UTF-8?q?=E4=B8=BA0=E6=97=B6=E6=89=A7=E8=A1=8C=E5=88=A0=E9=99=A4?= =?UTF-8?q?=E6=93=8D=E4=BD=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../v3/ShopCartUpdateController.php | 32 ++++++++++++------- 1 file changed, 21 insertions(+), 11 deletions(-) diff --git a/app/Controller/v3/ShopCartUpdateController.php b/app/Controller/v3/ShopCartUpdateController.php index 00e83a9..d1f7130 100644 --- a/app/Controller/v3/ShopCartUpdateController.php +++ b/app/Controller/v3/ShopCartUpdateController.php @@ -5,6 +5,7 @@ namespace App\Controller\v3; use App\Constants\v3\ErrorCode; use App\Controller\BaseController; use App\Exception\ErrorCodeException; +use App\Model\v3\ShoppingCart; use App\Service\v3\Interfaces\OrderOnlineServiceInterface; use Hyperf\Di\Annotation\Inject; use App\Service\v3\Interfaces\ShopCartUpdateServiceInterface; @@ -28,19 +29,28 @@ 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')] - ); + if($num <= 0){ + $shopcartIds = ShoppingCart::query()->where([ + 'user_id' => $userId, + 'goods_id' => $goodsId, + 'activity_type' => $activityType + ]) + ->value('id'); + $res = $this->shopCarServiceUpdate->undo($shopcartIds); + }else{ + 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); + $res = $this->shopCarServiceUpdate->do($userId,$goodsId,$num,$activityType); + } return $this->success($res); }