You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
63 lines
1.7 KiB
63 lines
1.7 KiB
<?php
|
|
|
|
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
|
|
{
|
|
/**
|
|
* @Inject
|
|
* @var CategoryServiceInterface
|
|
*/
|
|
protected $categoryService;
|
|
|
|
/**
|
|
* @Inject
|
|
* @var BannerServiceInterface
|
|
*/
|
|
protected $bannerService;
|
|
|
|
/**
|
|
* 获取分类页所有分类
|
|
* 1、无参数
|
|
* 2、远程关联获取所有分类信息
|
|
* @return \Psr\Http\Message\ResponseInterface
|
|
*/
|
|
public function all()
|
|
{
|
|
|
|
$category = $this->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]);
|
|
}
|
|
}
|