From bc143cb1632d755ffe6fe8b05ee478444cac78fa Mon Sep 17 00:00:00 2001 From: Mike Date: Sun, 6 Sep 2020 12:58:44 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E5=88=86=E7=B1=BB?= =?UTF-8?q?=E6=8E=A5=E5=8F=A3=E8=BF=94=E5=9B=9E=E6=95=B0=E6=8D=AE=EF=BC=8C?= =?UTF-8?q?=E5=8C=85=E5=90=ABhot=20types,banners?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Controller/v3/CategoryController.php | 37 +++++++++++++++++++++++- 1 file changed, 36 insertions(+), 1 deletion(-) diff --git a/app/Controller/v3/CategoryController.php b/app/Controller/v3/CategoryController.php index 42ef214..96e8ed3 100644 --- a/app/Controller/v3/CategoryController.php +++ b/app/Controller/v3/CategoryController.php @@ -4,6 +4,8 @@ namespace App\Controller\v3; use App\Controller\BaseController; use App\Service\v3\Interfaces\CategoryServiceInterface; +use App\Service\v3\Interfaces\BannerServiceInterface; +use App\Constants\v3\Banner; use Hyperf\Di\Annotation\Inject; class CategoryController extends BaseController @@ -14,6 +16,12 @@ class CategoryController extends BaseController */ protected $categoryService; + /** + * @Inject + * @var BannerServiceInterface + */ + protected $bannerService; + /** * 获取分类页所有分类 * 1、无参数 @@ -22,6 +30,33 @@ class CategoryController extends BaseController */ public function all() { - return $this->success(['category' => $this->categoryService->all()]); + + $category = $this->categoryService->all(); + + //mock datas + $gmarket_id = $this->request->input('gmarket_id', 0); + if($gmarket_id == -1 ) $gmarket_id = 0; + + $banners = $this->bannerService->all(Banner::TYPE_APPLET_INDEX, $gmarket_id); + foreach ($category as $key => &$item) { + $hot_types = []; + if(count($item['goods_types']) > 4){ + $hot_types = array_slice($item['goods_types'],0,2); + } + + $hot_titles = ['当季热销','为你推荐','热卖品类']; + $rand_index = rand(0,2); + $type_banners = []; + if(count($banners)>0){ + $r = rand(0,count($banners)-1); + + $type_banners = [$banners[$r]]; + } + + $item['hot_category'] = ['title'=>$hot_titles[$rand_index],'goods_types'=>$hot_types,'banners'=>$type_banners]; + + } + + return $this->success(['category' => $category]); } } \ No newline at end of file From d1e2d60317c86cdf07754558b1f72b74ae6c01b0 Mon Sep 17 00:00:00 2001 From: Mike Date: Sun, 6 Sep 2020 13:06:23 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E8=BF=94=E5=9B=9E?= =?UTF-8?q?=E6=A0=BC=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Controller/v3/CategoryController.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/app/Controller/v3/CategoryController.php b/app/Controller/v3/CategoryController.php index 96e8ed3..9947218 100644 --- a/app/Controller/v3/CategoryController.php +++ b/app/Controller/v3/CategoryController.php @@ -53,7 +53,8 @@ class CategoryController extends BaseController $type_banners = [$banners[$r]]; } - $item['hot_category'] = ['title'=>$hot_titles[$rand_index],'goods_types'=>$hot_types,'banners'=>$type_banners]; + $item['hot_category'] = ['title'=>$hot_titles[$rand_index],'goods_types'=>$hot_types]; + $item['banners']=$type_banners; }