<?php
|
|
namespace app\api\logic;
|
|
use app\common\logic\Basic as BasicLogic;
|
use app\api\model\SuperClass as ModelSuperClass;
|
use fast\Tree;
|
use think\Cache;
|
|
/**
|
* 超级分类管理(好单库)
|
*/
|
class SuperClass extends BasicLogic
|
{
|
|
protected $model = null;
|
|
public function __construct()
|
{
|
parent::__construct();
|
|
$this->model = new ModelSuperClass();
|
}
|
|
/**
|
* 获取分类列表
|
*
|
* @return void
|
*/
|
public function getList()
|
{
|
$list = $this->model->field('id,cid,main_name,son_name,imgurl,parent_id,next_name')->where(['status' => 1])->select();
|
$res = $this->getTree($list);
|
return $res;
|
}
|
|
private function getTree($array)
|
{
|
//遍历数组,按照id作为键名重新组建新的数组
|
$new_array = [];
|
foreach ($array as $v) {
|
$v = $v->toArray();
|
$new_array[$v['id']] = $v;
|
}
|
$return_tree = [];
|
foreach ($new_array as $kk => $vv) {
|
if (isset($new_array[$vv['parent_id']])) {
|
if(!isset($new_array[$vv['parent_id']]['sons'])) $new_array[$vv['parent_id']]['sons'] = [];
|
$new_array[$vv['parent_id']]['sons'][] = &$new_array[$kk];
|
} else {
|
$return_tree[] = &$new_array[$kk];
|
}
|
}
|
return $return_tree;
|
}
|
}
|