<?php
|
|
namespace app\api\controller\plus\goodcoupon;
|
|
use app\api\model\plus\goodcoupon\Category as CategoryModel;
|
use app\api\model\plus\goodcoupon\Coupon as goodCouponModel;
|
use app\api\controller\Controller;
|
;
|
/**
|
* 分类控制器
|
*/
|
class Category extends Controller
|
{
|
/**
|
* 分类页面
|
*/
|
public function index()
|
{
|
// 商品分类列表
|
$all_list = array_values(CategoryModel::getCacheTree());
|
$all_list =$this->hideCate($all_list);
|
//获取券商品的所有分类id
|
$category_ids = goodCouponModel::getCategoryIds();
|
$category_list = [];
|
if(!empty($all_list) && !empty($category_ids)){
|
foreach ($all_list as $val){
|
//筛选出券商品的分类
|
if(in_array($val["category_id"],$category_ids)){
|
$category_list[] = $val;
|
}
|
}
|
}
|
|
return $this->renderSuccess('', compact('category_list'));
|
}
|
|
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);
|
}
|
|
}
|