News.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. * @icon fa fa-circle-o
  7. */
  8. class News extends Backend
  9. {
  10. /**
  11. * WwhNews模型对象
  12. * @var \app\admin\model\wwh\News
  13. */
  14. protected $model = null;
  15. /**
  16. * 快速搜索时执行查找的字段
  17. */
  18. protected $relationSearch = true;
  19. protected $searchFields = 'newsname';
  20. public function _initialize()
  21. {
  22. parent::_initialize();
  23. $this->model = model('\app\admin\model\wwh\News');
  24. $newscategorylist = collection(model('\app\admin\model\wwh\Newscategory')->select())->toArray();
  25. Tree::instance()->init($newscategorylist);
  26. $newscategorylist = Tree::instance()->getTreeList(Tree::instance()->getTreeArray(0), 'name');
  27. $categorylist = array('' => '==请选择==');
  28. $this->categoryList = Tree::instance()->getTreeList(Tree::instance()->getTreeArray(0), 'name');
  29. foreach ($newscategorylist as $k => $v) {
  30. $categorylist[$v['id']] = $v['name'];
  31. }
  32. $this->view->assign('newscategorylist', $categorylist);
  33. $this->view->assign("tjdataList", $this->model->getTjdataList());
  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["news.newscategoryid"] = ["in", $categoryids];
  57. }
  58. $total = $this->model
  59. ->with('newscategory')
  60. ->where($where)
  61. ->where($query)
  62. ->order($sort, $order)
  63. ->count();
  64. $list = $this->model
  65. ->with('newscategory')
  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 getallnewslist()
  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. }