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']) > 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]); } }