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] =?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