categoryService->all(); //mock datas $market_id = $this->request->input('market_id', 0); if($market_id == -1 ) $market_id = 0; $banners = $this->bannerService->all(Banner::TYPE_APPLET_INDEX, $market_id); foreach ($category as $key => &$item) { $hot_types = []; if(count($item['goods_types']) > 2){ $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]; $item['banners']=$type_banners; } return $this->success(['category' => $category]); } public function first() { return $this->success($this->categoryService->getByParentId(0)); } public function secend() { $parentId = $this->request->input('parent_id'); return $this->success($this->categoryService->getByParentId($parentId)); } public function third() { $categoryId = $this->request->input('category_id'); return $this->success($this->categoryService->getThird($categoryId)); } }