Ad.php 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. <?php
  2. namespace app\admin\controller;
  3. use app\common\controller\Backend;
  4. use think\db\Query;
  5. /**
  6. *
  7. *
  8. * @icon fa fa-circle-o
  9. */
  10. class Ad extends Backend
  11. {
  12. protected $noNeedLogin=['pos'];
  13. /**
  14. * Ad模型对象
  15. * @var \app\common\model\Ad
  16. */
  17. protected $model = null;
  18. public function _initialize()
  19. {
  20. parent::_initialize();
  21. $this->model = new \app\admin\model\Ad;
  22. $this->view->assign('pos',\app\common\model\Ad::getPos());
  23. }
  24. public function index()
  25. {
  26. //设置过滤方法
  27. $this->request->filter(['strip_tags', 'trim']);
  28. if ($this->request->isAjax()) {
  29. //如果发送的来源是Selectpage,则转发到Selectpage
  30. if ($this->request->request('keyField')) {
  31. return $this->selectpage();
  32. }
  33. $this->relationSearch=true;
  34. list($where, $sort, $order, $offset, $limit) = $this->buildparams();
  35. $list = $this->model
  36. ->with(['admin'])
  37. ->where($where)
  38. ->order($sort, $order)
  39. ->paginate($limit);
  40. $result = array("total" => $list->total(), "rows" => $list->items());
  41. return json($result);
  42. }
  43. return $this->view->fetch();
  44. }
  45. public function import()
  46. {
  47. parent::import();
  48. }
  49. /**
  50. * 默认生成的控制器所继承的父类中有index/add/edit/del/multi五个基础方法、destroy/restore/recyclebin三个回收站方法
  51. * 因此在当前控制器中可不用编写增删改查的代码,除非需要自己控制这部分逻辑
  52. * 需要将application/admin/library/traits/Backend.php中对应的方法复制到当前控制器,然后进行修改
  53. */
  54. public function pos(){
  55. return \app\common\model\Ad::getPos();
  56. }
  57. public function edit($ids = null)
  58. {
  59. return parent::edit($ids);
  60. }
  61. public function del($ids = "")
  62. {
  63. parent::del($ids);
  64. }
  65. }