Prize.php 2.0 KB

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