Category.php
2.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
<?php
namespace app\admin\controller;
use app\common\controller\Backend;
use app\common\model\Category as CategoryModel;
use fast\Tree;
/**
* 分类管理
*
* @icon fa fa-list
* @remark 用于统一管理网站的所有分类,分类可进行无限级分类
*/
class Category extends Backend
{
/**
* @var \app\common\model\Category
*/
protected $model = null;
protected $categorylist = [];
protected $noNeedRight = ['selectpage'];
public function _initialize()
{
parent::_initialize();
$this->request->filter(['strip_tags']);
$this->model = model('app\common\model\Category');
$tree = Tree::instance();
$tree->init(collection($this->model->order('weigh desc,id desc')->select())->toArray(), 'pid');
$this->categorylist = $tree->getTreeList($tree->getTreeArray(0), 'name');
$categorydata = [0 => ['type' => 'all', 'name' => __('None')]];
foreach ($this->categorylist as $k => $v)
{
$categorydata[$v['id']] = $v;
}
$this->view->assign("flagList", $this->model->getFlagList());
$this->view->assign("typeList", CategoryModel::getTypeList());
$this->view->assign("parentList", $categorydata);
}
/**
* 查看
*/
public function index()
{
if ($this->request->isAjax())
{
$search = $this->request->request("search");
$type = $this->request->request("type");
//构造父类select列表选项数据
$list = [];
foreach ($this->categorylist as $k => $v)
{
if ($search) {
if ($v['type'] == $type && stripos($v['name'], $search) !== false)
{
if($type == "all" || $type == null) {
$list = $this->categorylist;
} else {
$list[] = $v;
}
}
} else {
if($type == "all" || $type == null) {
$list = $this->categorylist;
} else if ($v['type'] == $type){
$list[] = $v;
}
}
}
$total = count($list);
$result = array("total" => $total, "rows" => $list);
return json($result);
}
return $this->view->fetch();
}
/**
* Selectpage搜索
*
* @internal
*/
public function selectpage()
{
return parent::selectpage();
}
}