Browse Source

Merge branch 'phoenix' of http://120.24.33.109:11081/hyzjshwo/lanzu_api_hyperf into phoenix

master
Lemon 5 years ago
parent
commit
cc22a582b3
  1. 38
      app/Controller/v3/CategoryController.php

38
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,34 @@ 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];
$item['banners']=$type_banners;
}
return $this->success(['category' => $category]);
}
}
Loading…
Cancel
Save