<?php
|
|
namespace app\api\controller\product;
|
|
use app\api\model\product\Category as CategoryModel;
|
use app\api\controller\Controller;
|
use app\common\model\page\PageCategory as PageCategoryModel;
|
use app\api\model\product\Product as ProductModel;
|
use app\api\model\settings\Setting as SettingModel;
|
/**
|
* 商品分类控制器
|
*/
|
class Category extends Controller
|
{
|
/**
|
* 分类页面
|
*/
|
public function index()
|
{
|
$postData =$this->postData();
|
$city_supplier_ids = empty($postData["city_supplier_ids"]) ? '' : $postData["city_supplier_ids"];
|
// 分类模板
|
$template = PageCategoryModel::detail();
|
// 商品分类列表
|
$list = array_values(CategoryModel::getCacheTree());
|
$list =$this->hideCate($list);
|
$category_id=0;
|
if(count($list)>0){
|
$category_id=$list[0]['category_id'];
|
}
|
$data=['page'=>1,'category_id'=>$category_id,'city_supplier_ids'=>$city_supplier_ids,'search'=>'','sortType'=>'','sortPrice'=>'','list_rows'=>10];
|
$param = array_merge($data, [
|
'product_status' => 10,
|
'audit_status' => 10
|
]);
|
|
// 获取列表数据
|
$model = new ProductModel;
|
$productList = $model->getList($param, $this->getUser(false));
|
|
$store = SettingModel::getItem('store');
|
|
return $this->renderSuccess('', compact('template','list','productList','store'));
|
}
|
public function hideCate($all){
|
if(empty($all)){
|
return $all;
|
}
|
foreach ($all as $i=>$first) {
|
if (intval($all[$i]["status"]) === 0){
|
unset($all[$i]);
|
}
|
if(!empty($all[$i]['child'])){
|
foreach ($all[$i]['child'] as $j=>$two) {
|
if (intval($all[$i]['child'][$j]["status"]) === 0){
|
unset($all[$i]['child'][$j]);
|
}
|
|
if(!empty($all[$i]['child'][$j]['child'])){
|
foreach ($all[$i]['child'][$j]['child'] as $k=>$three){
|
if (intval($all[$i]['child'][$j]["child"][$k]["status"]) === 0){
|
unset($all[$i]['child'][$j]["child"][$k]);
|
}
|
}
|
}
|
}
|
}
|
}
|
return array_values($all);
|
}
|
}
|