Download.php 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  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 Download extends Backend
  9. {
  10. /**
  11. * WwhDownload模型对象
  12. * @var \app\admin\model\wwh\Download
  13. */
  14. protected $model = null;
  15. /**
  16. * 快速搜索时执行查找的字段
  17. */
  18. protected $relationSearch = true;
  19. protected $searchFields = 'downloadname';
  20. public function _initialize()
  21. {
  22. parent::_initialize();
  23. $this->model = model('\app\admin\model\wwh\Download');
  24. $downloadcategorylist = collection(model('\app\admin\model\wwh\Downloadcategory')->select())->toArray();
  25. Tree::instance()->init($downloadcategorylist);
  26. $downloadcategorylist = Tree::instance()->getTreeList(Tree::instance()->getTreeArray(0), 'name');
  27. $categorylist = array('' => '==请选择==');
  28. $this->categoryList = Tree::instance()->getTreeList(Tree::instance()->getTreeArray(0), 'name');
  29. foreach ($downloadcategorylist as $k => $v) {
  30. $categorylist[$v['id']] = $v['name'];
  31. }
  32. $this->view->assign('downloadcategorylist', $categorylist);
  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. //设置过滤方法
  45. $this->request->filter(['strip_tags']);
  46. if ($this->request->isAjax()) {
  47. //如果发送的来源是Selectpage,则转发到Selectpage
  48. if ($this->request->request('keyField')) {
  49. return $this->selectpage();
  50. }
  51. list($where, $sort, $order, $offset, $limit) = $this->buildparams();
  52. $categoryids = $this->request->request("categoryids");
  53. $query = [];
  54. if ($categoryids !== null) {
  55. $query["download.downloadcategoryid"] = ["in", $categoryids];
  56. }
  57. $total = $this->model
  58. ->with('downloadcategory')
  59. ->where($where)
  60. ->where($query)
  61. ->order($sort, $order)
  62. ->count();
  63. $list = $this->model
  64. ->with('downloadcategory')
  65. ->where($where)
  66. ->where($query)
  67. ->order($sort, $order)
  68. ->limit($offset, $limit)
  69. ->select();
  70. $list = collection($list)->toArray();
  71. $result = array("total" => $total, "rows" => $list);
  72. return json($result);
  73. }
  74. return $this->view->fetch();
  75. }
  76. /**
  77. * 获取所有列表
  78. */
  79. public function getalldownloadlist()
  80. {
  81. //设置过滤方法
  82. if ($this->request->isAjax()) {
  83. $list = $this->model
  84. ->select();
  85. $list = collection($list)->toArray();
  86. return json($list);
  87. }
  88. }
  89. }