Cases.php 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. <?php
  2. namespace app\admin\controller\wwh;
  3. use app\common\controller\Backend;
  4. use fast\Tree;
  5. /**
  6. *
  7. * @icon fa fa-circle-o
  8. */
  9. class Cases extends Backend
  10. {
  11. /**
  12. * WwhCases模型对象
  13. * @var \app\admin\model\wwh\Cases
  14. */
  15. protected $model = null;
  16. /**
  17. * 快速搜索时执行查找的字段
  18. */
  19. protected $relationSearch = true;
  20. protected $searchFields = 'casesname';
  21. public function _initialize()
  22. {
  23. parent::_initialize();
  24. $this->model = model('\app\admin\model\wwh\Cases');
  25. $casescategorylist = collection(model('\app\admin\model\wwh\Casescategory')->select())->toArray();
  26. Tree::instance()->init($casescategorylist);
  27. $casescategorylist = Tree::instance()->getTreeList(Tree::instance()->getTreeArray(0), 'name');
  28. $categorylist = array('' => '==请选择==');
  29. $this->categoryList = Tree::instance()->getTreeList(Tree::instance()->getTreeArray(0), 'name');
  30. foreach ($casescategorylist as $k => $v) {
  31. $categorylist[$v['id']] = $v['name'];
  32. }
  33. $this->view->assign('casescategorylist', $categorylist);
  34. }
  35. /**
  36. * 默认生成的控制器所继承的父类中有index/add/edit/del/multi五个基础方法、destroy/restore/recyclebin三个回收站方法
  37. * 因此在当前控制器中可不用编写增删改查的代码,除非需要自己控制这部分逻辑
  38. * 需要将application/admin/library/traits/Backend.php中对应的方法复制到当前控制器,然后进行修改
  39. */
  40. /**
  41. * 查看
  42. */
  43. public function index()
  44. {
  45. //设置过滤方法
  46. $this->request->filter(['strip_tags']);
  47. if ($this->request->isAjax()) {
  48. //如果发送的来源是Selectpage,则转发到Selectpage
  49. if ($this->request->request('keyField')) {
  50. return $this->selectpage();
  51. }
  52. list($where, $sort, $order, $offset, $limit) = $this->buildparams();
  53. $categoryids = $this->request->request("categoryids");
  54. $query = [];
  55. if ($categoryids !== null) {
  56. $query["cases.casescategoryid"] = ["in", $categoryids];
  57. }
  58. $total = $this->model
  59. ->with('casescategory')
  60. ->where($where)
  61. ->where($query)
  62. ->order($sort, $order)
  63. ->count();
  64. $list = $this->model
  65. ->with('casescategory')
  66. ->where($where)
  67. ->where($query)
  68. ->order($sort, $order)
  69. ->limit($offset, $limit)
  70. ->select();
  71. $list = collection($list)->toArray();
  72. $result = array("total" => $total, "rows" => $list);
  73. return json($result);
  74. }
  75. return $this->view->fetch();
  76. }
  77. /**
  78. * 获取所有列表
  79. */
  80. public function getallcaseslist()
  81. {
  82. //设置过滤方法
  83. if ($this->request->isAjax()) {
  84. $list = $this->model
  85. ->select();
  86. $list = collection($list)->toArray();
  87. return json($list);
  88. }
  89. }
  90. }