From 6f3a33239908feda5ff3e0a428b23cb3e3609808 Mon Sep 17 00:00:00 2001 From: Lemon <15040771@qq.com> Date: Tue, 3 Nov 2020 14:52:28 +0800 Subject: [PATCH 1/7] =?UTF-8?q?=E5=95=86=E5=93=81=E5=88=97=E8=A1=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Controller/v3/GoodsController.php | 6 ++++++ config/routes.php | 1 + 2 files changed, 7 insertions(+) diff --git a/app/Controller/v3/GoodsController.php b/app/Controller/v3/GoodsController.php index 3425853..b81088f 100644 --- a/app/Controller/v3/GoodsController.php +++ b/app/Controller/v3/GoodsController.php @@ -6,6 +6,7 @@ use App\Constants\v3\ErrorCode; use App\Controller\BaseController; use App\Exception\ErrorCodeException; use App\Model\v3\Category; +use App\Model\v3\GoodsActivity; use App\Model\v3\GoodsCategory; use App\Request\v3\GoodsEditorRequest; use App\Service\v3\Interfaces\CategoryServiceInterface; @@ -199,4 +200,9 @@ class GoodsController extends BaseController $bannerId = $this->request->input('banner_id',0); return $this->success($this->goodsService->bannerDelete($bannerId)); } + + public function getList(){ + $goods = GoodsActivity::query()->limit(5)->orderByDesc('created_at')->get(); + return $this->success(['goods' => $goods]); + } } \ No newline at end of file diff --git a/config/routes.php b/config/routes.php index fbb8832..306e445 100644 --- a/config/routes.php +++ b/config/routes.php @@ -100,6 +100,7 @@ Router::addGroup('/v3/', function () { Router::post('home/market', 'App\Controller\v3\HomeController@marketInfo'); Router::post('location/addrSuggestion', 'App\Controller\v3\LocationController@addrSuggestion'); Router::post('userAddress/deliveryDistance', 'App\Controller\v3\UserAddressController@deliveryDistance'); + Router::post('goods/getList', 'App\Controller\v3\GoodsController@getList'); },['middleware' => [\App\Middleware\Auth\ApiMiddleware::class]]); // 需要登录的路由 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 2/7] =?UTF-8?q?=E8=B4=AD=E7=89=A9=E8=BD=A6=E6=95=B0?= =?UTF-8?q?=E9=87=8F=E4=B8=BA0=E6=97=B6=E6=89=A7=E8=A1=8C=E5=88=A0?= =?UTF-8?q?=E9=99=A4=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); } From a9abc43433bb466ae2846c8cf8c424e037b90696 Mon Sep 17 00:00:00 2001 From: Lemon <15040771@qq.com> Date: Wed, 4 Nov 2020 09:31:34 +0800 Subject: [PATCH 3/7] =?UTF-8?q?=E9=AA=8C=E8=AF=81=E5=99=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Request/v3/ShopCartUpdateRequest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/Request/v3/ShopCartUpdateRequest.php b/app/Request/v3/ShopCartUpdateRequest.php index c467aab..008fc9b 100644 --- a/app/Request/v3/ShopCartUpdateRequest.php +++ b/app/Request/v3/ShopCartUpdateRequest.php @@ -16,7 +16,7 @@ class ShopCartUpdateRequest extends BaseFormRequest { return [ 'goods_id' => 'required|nonempty|integer', - 'num' => 'required|nonempty|integer', + 'num' => 'required|integer', 'user_id' => 'required|nonempty|integer|exists:lanzu_user,id', ]; } From 5bcccfba615db9ac72d4d0e3f12a69e4bfef5874 Mon Sep 17 00:00:00 2001 From: Lemon <15040771@qq.com> Date: Wed, 4 Nov 2020 15:02:31 +0800 Subject: [PATCH 4/7] =?UTF-8?q?=E5=95=86=E5=93=81=E5=88=97=E8=A1=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Controller/v3/GoodsController.php | 14 +++++++++++--- app/Model/v3/Goods.php | 8 +++++++- app/Model/v3/GoodsActivity.php | 6 ++++++ .../v3/Implementations/GoodsActivityService.php | 7 +++++++ .../Interfaces/GoodsActivityServiceInterface.php | 1 + 5 files changed, 32 insertions(+), 4 deletions(-) diff --git a/app/Controller/v3/GoodsController.php b/app/Controller/v3/GoodsController.php index b81088f..1bed88a 100644 --- a/app/Controller/v3/GoodsController.php +++ b/app/Controller/v3/GoodsController.php @@ -201,8 +201,16 @@ class GoodsController extends BaseController return $this->success($this->goodsService->bannerDelete($bannerId)); } - public function getList(){ - $goods = GoodsActivity::query()->limit(5)->orderByDesc('created_at')->get(); - return $this->success(['goods' => $goods]); + public function getList() + { + $page = $this->request->input('page',0); + $pagesize = $this->request->input('pagesize',10); + $activity = $this->request->input('activity',''); + $marketId = $this->request->input('market_id',-1); + $res = ''; + if($activity == 'bachelor'){ + $res = $this->goodsActivityService->getList($marketId,$page,$pagesize); + } + return $this->success($res); } } \ No newline at end of file diff --git a/app/Model/v3/Goods.php b/app/Model/v3/Goods.php index 923974b..892904c 100644 --- a/app/Model/v3/Goods.php +++ b/app/Model/v3/Goods.php @@ -82,7 +82,8 @@ class Goods extends Model 'is_effective', 'noneffective_note', 'details_imgs_url', - 'goods_name' + 'goods_name', + 'activity_type' ]; protected function boot(): void @@ -93,6 +94,11 @@ class Goods extends Model }); } + public function getActivityTypeAttribute() + { + return 1; + } + public function scopeOrderByDefault($query, $sort) { return $query->orderBy($this->getTable().'.sort', $sort)->orderBy($this->getTable().'.id', $sort); diff --git a/app/Model/v3/GoodsActivity.php b/app/Model/v3/GoodsActivity.php index c3097ea..7c987a6 100644 --- a/app/Model/v3/GoodsActivity.php +++ b/app/Model/v3/GoodsActivity.php @@ -46,6 +46,7 @@ class GoodsActivity extends Model 'noneffective_note', 'total_seconds', 'details_imgs_url', + 'activity_type' ]; // protected $visible = [ @@ -61,6 +62,11 @@ class GoodsActivity extends Model }); } + public function getActivityTypeAttribute() + { + return 2; + } + public function getMonthSalesAttribute() { $ssdb = ApplicationContext::getContainer()->get(SSDBTask::class); diff --git a/app/Service/v3/Implementations/GoodsActivityService.php b/app/Service/v3/Implementations/GoodsActivityService.php index a1d7ee0..e7ec52f 100644 --- a/app/Service/v3/Implementations/GoodsActivityService.php +++ b/app/Service/v3/Implementations/GoodsActivityService.php @@ -191,4 +191,11 @@ class GoodsActivityService implements GoodsActivityServiceInterface return true; } + + public function getList($marketId,$page,$pagesize) + { + $paginate = GoodsActivity::query()->where('market_id',$marketId)->orderByDesc('created_at')->paginate($pagesize); + $goods = $paginate->toArray(); + return ['has_more_pages' => $paginate->hasMorePages(),'goods' => $goods['data']]; + } } \ No newline at end of file diff --git a/app/Service/v3/Interfaces/GoodsActivityServiceInterface.php b/app/Service/v3/Interfaces/GoodsActivityServiceInterface.php index cac9c86..e056799 100644 --- a/app/Service/v3/Interfaces/GoodsActivityServiceInterface.php +++ b/app/Service/v3/Interfaces/GoodsActivityServiceInterface.php @@ -14,4 +14,5 @@ interface GoodsActivityServiceInterface public function cacheRecord($goodsId, $num, $userId); public function clearCacheRecord($goodsId, $num, $userId); public function checkOrderActivityCount($goodsIds, $limitNum=1); + public function getList($marketId,$page,$pagesize); } \ No newline at end of file From 6731e58c35cd8e3dcb658d3f8ebe87c8c03b7ab2 Mon Sep 17 00:00:00 2001 From: Lemon <15040771@qq.com> Date: Fri, 6 Nov 2020 15:28:24 +0800 Subject: [PATCH 5/7] =?UTF-8?q?=E5=BA=93=E5=AD=98=E4=B8=8D=E8=B6=B3?= =?UTF-8?q?=E6=8F=90=E7=A4=BA=E8=AF=AD=E6=9B=B4=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Constants/v3/ErrorCode.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/Constants/v3/ErrorCode.php b/app/Constants/v3/ErrorCode.php index 7e6a60d..cd3ce66 100644 --- a/app/Constants/v3/ErrorCode.php +++ b/app/Constants/v3/ErrorCode.php @@ -292,7 +292,7 @@ class ErrorCode extends AbstractConstants /** * 已卖光 - * @Message("商品已卖光") + * @Message("库存不足") */ const GOODS_ACTIVITY_INVENTORY_ERROR = 1153; From 3602e0a4b7d6d4149a3495e46878ca0e0a280ce4 Mon Sep 17 00:00:00 2001 From: Lemon <15040771@qq.com> Date: Mon, 9 Nov 2020 16:54:04 +0800 Subject: [PATCH 6/7] =?UTF-8?q?=E5=BA=93=E5=AD=98=E4=B8=8D=E8=B6=B3?= =?UTF-8?q?=E6=97=B6=20=E5=85=81=E8=AE=B8=E5=87=8F=E6=93=8D=E4=BD=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../v3/Implementations/ShopCartUpdateService.php | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/app/Service/v3/Implementations/ShopCartUpdateService.php b/app/Service/v3/Implementations/ShopCartUpdateService.php index 72fd76f..8b22179 100644 --- a/app/Service/v3/Implementations/ShopCartUpdateService.php +++ b/app/Service/v3/Implementations/ShopCartUpdateService.php @@ -69,7 +69,20 @@ class ShopCartUpdateService implements ShopCartUpdateServiceInterface if($goodsCheck !== true) { - throw new ErrorCodeException($goodsCheck); + if($goodsCheck === ErrorCode::GOODS_ACTIVITY_INVENTORY_ERROR){ + $shopcartNum = ShoppingCart::query() + ->where([ + 'user_id' => $userId, + 'goods_id' => $goodsId, + 'activity_type' => $activityType + ]) + ->value('num'); + if($num > $shopcartNum){ + throw new ErrorCodeException($goodsCheck); + } + }else{ + throw new ErrorCodeException($goodsCheck); + } } $shoppingCart = ShoppingCart::query()->lockForUpdate()->updateOrCreate( From c274fd1ece8838dc52aca90f01e5cc0bfdb9374a Mon Sep 17 00:00:00 2001 From: Lemon <15040771@qq.com> Date: Mon, 9 Nov 2020 17:52:15 +0800 Subject: [PATCH 7/7] =?UTF-8?q?=E7=89=B9=E4=BB=B7=E5=95=86=E5=93=81?= =?UTF-8?q?=E6=8E=92=E5=BA=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Implementations/GoodsActivityService.php | 42 +++++++++++++++++-- 1 file changed, 39 insertions(+), 3 deletions(-) diff --git a/app/Service/v3/Implementations/GoodsActivityService.php b/app/Service/v3/Implementations/GoodsActivityService.php index e7ec52f..417aa15 100644 --- a/app/Service/v3/Implementations/GoodsActivityService.php +++ b/app/Service/v3/Implementations/GoodsActivityService.php @@ -5,8 +5,10 @@ namespace App\Service\v3\Implementations; use App\Commons\Log; use App\Constants\v3\ActivityType; use App\Constants\v3\ErrorCode; +use App\Constants\v3\Goods as GoodsConstants; use App\Constants\v3\LogLabel; use App\Constants\v3\SsdbKeys; +use App\Model\v3\Store; use App\Service\v3\Interfaces\GoodsActivityServiceInterface; use App\Service\v3\Interfaces\GoodsInventoryServiceInterface; use App\TaskWorker\SSDBTask; @@ -194,8 +196,42 @@ class GoodsActivityService implements GoodsActivityServiceInterface public function getList($marketId,$page,$pagesize) { - $paginate = GoodsActivity::query()->where('market_id',$marketId)->orderByDesc('created_at')->paginate($pagesize); - $goods = $paginate->toArray(); - return ['has_more_pages' => $paginate->hasMorePages(),'goods' => $goods['data']]; + $storeTable = ApplicationContext::getContainer()->get(Store::class)->getTable(); + $goodsTable = ApplicationContext::getContainer()->get(GoodsActivity::class)->getTable(); + + $builder = GoodsActivity::query() + ->join($storeTable, ''.$storeTable.'.id', '=', ''.$goodsTable.'.store_id') + ->with(['store']) + //->where([''.$goodsTable.'.type' => $type]) + ->where(function ($query) use ($marketId, $goodsTable) { + $query->whereJsonContains(''.$goodsTable.'.market_ids', [(string)$marketId]) + ->orWhereJsonLength(''.$goodsTable.'.market_ids', '=', 0); + }) + ->where([''.$goodsTable.'.on_sale' => GoodsConstants::ON_SALE_YES]) + // ->where(function ($query) use ($goodsTable) { + // $query->where(''.$goodsTable.'.inventory', '>', 0)->orWhere(''.$goodsTable.'.is_infinite', '=', 1); + // }) + ->whereRaw(''.$goodsTable.'.deleted_at IS NULL') + ->where([''.$storeTable.'.market_id' => $marketId]) + ->where([''.$storeTable.'.is_open' => \App\Constants\v3\Store::IS_OPEN_YES]) + ->where([''.$storeTable.'.is_rest' => \App\Constants\v3\Store::IS_REST_NO]) + ->where('time1', '<=', date('H:i')) + ->where(function ($query) { + $query->where('time2', '>=', date('H:i')) + ->orWhere('time4', '>=', date('H:i')); + }) + ->where(''.$goodsTable.'.expire_time', '>', time()); + $paginate = $builder->select(''.$goodsTable.'.*')->addSelect(''.$goodsTable.'.sales as total_sales') + ->orderBy(''.$goodsTable.'.sort', 'DESC') + ->orderBy(''.$goodsTable.'.expire_time', 'ASC') + ->orderBy(''.$goodsTable.'.created_at', 'DESC') + ->paginate($pagesize); + $goodsArr = $paginate->toArray(); + $goods = collect($goodsArr['data']); + $goods = $goods->sortBy(function ($product, $key) { + return $product['noneffective_note']; + }); + $goods = $goods->values()->all(); + return ['has_more_pages' => $paginate->hasMorePages(), 'goods' => $goods]; } } \ No newline at end of file