Gift.php 2.6 KB

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