Prize.php 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  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. if(!empty($param1['custom'])){
  45. $where1['type'] = $param1['custom']['type'];
  46. }else{
  47. $where1 = " 1=1 ";
  48. }
  49. $list = $this->model
  50. ->with('category')
  51. ->where($where)
  52. ->where($where1)
  53. ->order($sort, $order)
  54. ->paginate($limit);
  55. $result = ['total' => $list->total(), 'rows' => $list->items()];
  56. return json($result);
  57. }
  58. /**
  59. * 默认生成的控制器所继承的父类中有index/add/edit/del/multi五个基础方法、destroy/restore/recyclebin三个回收站方法
  60. * 因此在当前控制器中可不用编写增删改查的代码,除非需要自己控制这部分逻辑
  61. * 需要将application/admin/library/traits/Backend.php中对应的方法复制到当前控制器,然后进行修改
  62. */
  63. }