Gift.php 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  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. }
  26. public function import()
  27. {
  28. parent::import();
  29. }
  30. /**
  31. * 默认生成的控制器所继承的父类中有index/add/edit/del/multi五个基础方法、destroy/restore/recyclebin三个回收站方法
  32. * 因此在当前控制器中可不用编写增删改查的代码,除非需要自己控制这部分逻辑
  33. * 需要将application/admin/library/traits/Backend.php中对应的方法复制到当前控制器,然后进行修改
  34. */
  35. /**
  36. * 查看
  37. */
  38. public function index()
  39. {
  40. //当前是否为关联查询
  41. $this->relationSearch = true;
  42. //设置过滤方法
  43. $this->request->filter(['strip_tags', 'trim']);
  44. if ($this->request->isAjax()) {
  45. //如果发送的来源是Selectpage,则转发到Selectpage
  46. if ($this->request->request('keyField')) {
  47. return $this->selectpage();
  48. }
  49. list($where, $sort, $order, $offset, $limit) = $this->buildparams();
  50. $appendWhere = [];
  51. if ($this->request->param('id')) {
  52. $appendWhere['gift.id'] = $this->request->param('id');
  53. }
  54. $list = $this->model
  55. ->with(['gifttype'])
  56. ->where($where)
  57. ->where($appendWhere)
  58. ->order($sort, $order)
  59. ->paginate($limit);
  60. foreach ($list as $row) {
  61. $row->getRelation('gifttype')->visible(['name']);
  62. }
  63. $result = array("total" => $list->total(), "rows" => $list->items());
  64. return json($result);
  65. }
  66. return $this->view->fetch();
  67. }
  68. /**
  69. * 获取详情
  70. * @return void
  71. */
  72. public function detail()
  73. {
  74. $id = $this->request->param('id',0);
  75. $data = [];
  76. if (!empty($id)) {
  77. $where['id'] = $id;
  78. $data = $this->model->where($where)->find();
  79. }
  80. $result = [
  81. 'status' => 1,
  82. 'msg' => '获取成功',
  83. 'data' => $data,
  84. ];
  85. return json_encode($result);
  86. }
  87. }