Menu.php 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. <?php
  2. namespace app\admin\controller\shop;
  3. use app\common\controller\Backend;
  4. use fast\Tree;
  5. /**
  6. * 菜单管理
  7. *
  8. * @icon fa fa-circle-o
  9. */
  10. class Menu extends Backend
  11. {
  12. /**
  13. * Menu模型对象
  14. * @var \app\admin\model\shop\Menu
  15. */
  16. protected $model = null;
  17. public function _initialize()
  18. {
  19. parent::_initialize();
  20. $this->model = new \app\admin\model\shop\Menu;
  21. $tree = Tree::instance();
  22. $tree->init(collection($this->model->order('weigh desc,id desc')->select())->toArray(), 'pid');
  23. $this->categorylist = $tree->getTreeList($tree->getTreeArray(0), 'name');
  24. $categorydata = [0 => ['type' => 'all', 'name' => __('None')]];
  25. foreach ($this->categorylist as $k => $v) {
  26. $categorydata[$v['id']] = $v;
  27. }
  28. $this->view->assign("parentList", $categorydata);
  29. $this->view->assign("statusList", $this->model->getStatusList());
  30. }
  31. /**
  32. * 查看
  33. */
  34. public function index()
  35. {
  36. //设置过滤方法
  37. $this->request->filter(['strip_tags']);
  38. if ($this->request->isAjax()) {
  39. $search = $this->request->request("search");
  40. //构造父类select列表选项数据
  41. $list = [];
  42. foreach ($this->categorylist as $k => $v) {
  43. if ($search) {
  44. if (stripos($v['name'], $search) !== false) {
  45. $list[] = $v;
  46. }
  47. } else {
  48. $list[] = $v;
  49. }
  50. }
  51. $total = count($list);
  52. $result = array("total" => $total, "rows" => $list);
  53. return json($result);
  54. }
  55. return $this->view->fetch();
  56. }
  57. }