|
@@ -10,45 +10,19 @@ use app\common\Enum\StatusEnum;
|
|
*/
|
|
*/
|
|
class Category extends Base
|
|
class Category extends Base
|
|
{
|
|
{
|
|
- protected $noNeedLogin = ['index', 'alls'];
|
|
|
|
|
|
+ protected $noNeedLogin = ['index'];
|
|
|
|
|
|
//分类列表
|
|
//分类列表
|
|
public function index()
|
|
public function index()
|
|
- {
|
|
|
|
- $category_mode = $this->request->param('category_mode');
|
|
|
|
- if ($category_mode == 1) { //一级分类
|
|
|
|
-
|
|
|
|
- $list = CategoryModel::relation([
|
|
|
|
- 'goods' => function ($query) {
|
|
|
|
- $query->field('id,title,sub_title,image,price,sales,views,description,lineation_price,createtime')->limit(10);
|
|
|
|
- }
|
|
|
|
- ])->where('pid', 0)
|
|
|
|
- ->where('status',StatusEnum::ENABLED)
|
|
|
|
- ->order('weigh desc,id asc')->select();
|
|
|
|
-
|
|
|
|
- } else //二级分类 //三级分类
|
|
|
|
- {
|
|
|
|
- $tree = Tree::instance();
|
|
|
|
- $categoryList = CategoryModel::field('id,pid,name,image')
|
|
|
|
- ->order('weigh desc,id asc')
|
|
|
|
- ->where('status',StatusEnum::ENABLED)
|
|
|
|
- ->select();
|
|
|
|
- $tree->init(collection($categoryList)->toArray(), 'pid');
|
|
|
|
- $list = $tree->getTreeArray(0);
|
|
|
|
-
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- $this->success('获取成功', $list);
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- //所有分类
|
|
|
|
- public function alls()
|
|
|
|
- {
|
|
|
|
|
|
+ {
|
|
$tree = Tree::instance();
|
|
$tree = Tree::instance();
|
|
- $list = CategoryModel::field('id,pid,name,image')->order('weigh asc,id asc')->where('isnav', 1)->select();
|
|
|
|
- $tree->init(collection($list)->toArray(), 'pid');
|
|
|
|
- $categoryList = $tree->getTreeList($tree->getTreeArray(0), 'name');
|
|
|
|
|
|
+ $categoryList = CategoryModel::field('id,pid,name,image')
|
|
|
|
+ ->order('weigh desc,id asc')
|
|
|
|
+ ->where('status',StatusEnum::ENABLED)
|
|
|
|
+ ->select();
|
|
|
|
+ $tree->init(collection($categoryList)->toArray(), 'pid');
|
|
|
|
+ $list = $tree->getTreeArray(0);
|
|
|
|
|
|
- $this->success('获取成功', $categoryList);
|
|
|
|
|
|
+ $this->success('获取成功', $list);
|
|
}
|
|
}
|
|
}
|
|
}
|