Personalactivetype.php 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. <?php
  2. namespace app\admin\controller;
  3. use app\common\controller\Backend;
  4. use fast\Tree;
  5. /**
  6. * 私人订制活动类型
  7. *
  8. * @icon fa fa-circle-o
  9. */
  10. class Personalactivetype extends Backend
  11. {
  12. /**
  13. * Personalactivetype模型对象
  14. * @var \app\admin\model\Personalactivetype
  15. */
  16. protected $model = null;
  17. public function _initialize()
  18. {
  19. parent::_initialize();
  20. $this->model = new \app\admin\model\Personalactivetype;
  21. // 必须将结果集转换为数组
  22. $ruleList = \think\Db::name("personal_active_type")->field('id,name,pid,weigh')->order('weigh DESC,id ASC')->select();
  23. Tree::instance()->init($ruleList);
  24. $this->rulelist = Tree::instance()->getTreeList(Tree::instance()->getTreeArray(0), 'name');
  25. $ruledata = [0 => __('None')];
  26. foreach ($this->rulelist as $k => &$v) {
  27. $v['name'] = str_replace('&nbsp;', '', $v['name']);
  28. $ruledata[$v['id']] = $v['name'];
  29. }
  30. unset($v);
  31. $this->view->assign('ruledata', $ruledata);
  32. $this->view->assign("parentList", $ruledata);
  33. }
  34. /**
  35. * 默认生成的控制器所继承的父类中有index/add/edit/del/multi五个基础方法、destroy/restore/recyclebin三个回收站方法
  36. * 因此在当前控制器中可不用编写增删改查的代码,除非需要自己控制这部分逻辑
  37. * 需要将application/admin/library/traits/Backend.php中对应的方法复制到当前控制器,然后进行修改
  38. */
  39. /**
  40. * 查看
  41. */
  42. public function index()
  43. {
  44. if ($this->request->isAjax()) {
  45. $list = $this->rulelist;
  46. $total = count($this->rulelist);
  47. $result = array("total" => $total, "rows" => $list);
  48. return json($result);
  49. }
  50. return $this->view->fetch();
  51. }
  52. }