You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
72 lines
2.4 KiB
72 lines
2.4 KiB
<?php
|
|
|
|
namespace app\admin\controller\wx;
|
|
|
|
use app\common\controller\Backend;
|
|
use fast\Tree;
|
|
|
|
/**
|
|
* 栏目管理
|
|
*
|
|
* @icon fa fa-circle-o
|
|
*/
|
|
class Category extends Backend
|
|
{
|
|
|
|
/**
|
|
* Category模型对象
|
|
* @var \app\admin\model\wx\Category
|
|
*/
|
|
protected $model = null;
|
|
|
|
public function _initialize()
|
|
{
|
|
parent::_initialize();
|
|
$this->model = new \app\admin\model\wx\Category;
|
|
|
|
// 必须将结果集转换为数组
|
|
$postArr = $this->request->post();
|
|
if(isset($postArr['custom']['wx_menu_id']) && $postArr['custom']['wx_menu_id']>0){
|
|
$ruleList = collection($this->model->alias('wc')->join('wx_menu wm','wc.wx_menu_id = wm.id','left')->where('wc.wx_menu_id','=',$postArr['custom']['wx_menu_id'])->field('wc.*,wc.wx_category_id as pid,wm.name as menu_name')->order('wm.id desc,wc.weigh desc,wc.id ASC')->select())->toArray();
|
|
}else{
|
|
$ruleList = collection($this->model->alias('wc')->join('wx_menu wm','wc.wx_menu_id = wm.id','left')->field('wc.*,wc.wx_category_id as pid,wm.name as menu_name')->order('wm.id desc,wc.weigh desc,wc.id ASC')->select())->toArray();
|
|
}
|
|
|
|
foreach ($ruleList as $k => &$v) {
|
|
$v['name'] = __($v['name']);
|
|
unset($ruleList[$k]['wx_category_id']);
|
|
}
|
|
Tree::instance()->init($ruleList);
|
|
$this->rulelist = Tree::instance()->getTreeList(Tree::instance()->getTreeArray(0), 'name');
|
|
$ruledata = [0 => __('None')];
|
|
foreach ($this->rulelist as $k => &$v) {
|
|
$ruledata[$v['id']] = $v['name'];
|
|
}
|
|
|
|
$this->view->assign("catedataList", $this->model->getCatedataList());
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
* 默认生成的控制器所继承的父类中有index/add/edit/del/multi五个基础方法、destroy/restore/recyclebin三个回收站方法
|
|
* 因此在当前控制器中可不用编写增删改查的代码,除非需要自己控制这部分逻辑
|
|
* 需要将application/admin/library/traits/Backend.php中对应的方法复制到当前控制器,然后进行修改
|
|
*/
|
|
|
|
public function index()
|
|
{
|
|
if ($this->request->isAjax()) {
|
|
$list = $this->rulelist;
|
|
$total = count($this->rulelist);
|
|
$result = array("total" => $total, "rows" => $list);
|
|
return json($result);
|
|
}
|
|
return $this->view->fetch();
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|