Gift.php 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. <?php
  2. namespace app\admin\controller\gift;
  3. use app\common\controller\Backend;
  4. /**
  5. * 礼物管理
  6. *
  7. * @icon fa fa-gift
  8. */
  9. class Gift extends Backend
  10. {
  11. /**
  12. * Gift模型对象
  13. * @var \app\admin\model\gift\Gift
  14. */
  15. protected $model = null;
  16. public function _initialize()
  17. {
  18. parent::_initialize();
  19. $this->model = new \app\admin\model\gift\Gift;
  20. $this->view->assign("isBigList", $this->model->getIsBigList());
  21. $this->view->assign("typeList", $this->model->getTypeList());
  22. $this->view->assign("boxtypeList", $this->model->getBoxtypeList());
  23. $this->view->assign("complexList", $this->model->getComplexList());
  24. $this->view->assign("timelimitList", $this->model->getTimelimitList());
  25. $this->view->assign("isShowList", $this->model->getIsShowList());
  26. }
  27. public function import()
  28. {
  29. parent::import();
  30. }
  31. /**
  32. * 默认生成的控制器所继承的父类中有index/add/edit/del/multi五个基础方法、destroy/restore/recyclebin三个回收站方法
  33. * 因此在当前控制器中可不用编写增删改查的代码,除非需要自己控制这部分逻辑
  34. * 需要将application/admin/library/traits/Backend.php中对应的方法复制到当前控制器,然后进行修改
  35. */
  36. /**
  37. * 查看
  38. */
  39. public function index()
  40. {
  41. //当前是否为关联查询
  42. $this->relationSearch = true;
  43. //设置过滤方法
  44. $this->request->filter(['strip_tags', 'trim']);
  45. if ($this->request->isAjax()) {
  46. //如果发送的来源是Selectpage,则转发到Selectpage
  47. if ($this->request->request('keyField')) {
  48. return $this->selectpage();
  49. }
  50. list($where, $sort, $order, $offset, $limit) = $this->buildparams();
  51. $appendWhere = [];
  52. if ($this->request->param('id')) {
  53. $appendWhere['gift.id'] = $this->request->param('id');
  54. }
  55. $list = $this->model
  56. ->with(['gifttype'])
  57. ->where($where)
  58. ->where($appendWhere)
  59. ->order($sort, $order)
  60. ->paginate($limit);
  61. foreach ($list as $row) {
  62. $row->getRelation('gifttype')->visible(['name']);
  63. }
  64. $result = array("total" => $list->total(), "rows" => $list->items());
  65. return json($result);
  66. }
  67. return $this->view->fetch();
  68. }
  69. /**
  70. * 获取详情
  71. * @return void
  72. */
  73. public function detail()
  74. {
  75. $id = $this->request->param('id',0);
  76. $data = [];
  77. if (!empty($id)) {
  78. $where['id'] = $id;
  79. $data = $this->model->where($where)->find();
  80. }
  81. $result = [
  82. 'status' => 1,
  83. 'msg' => '获取成功',
  84. 'data' => $data,
  85. ];
  86. return json_encode($result);
  87. }
  88. }