StoreActivityFrom.php 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. <?php
  2. namespace app\admin\controller;
  3. use app\common\controller\Backend;
  4. use think\Db;
  5. use think\exception\PDOException;
  6. /**
  7. * 预约表单管理
  8. *
  9. * @icon fa fa-circle-o
  10. */
  11. class StoreActivityFrom extends Backend
  12. {
  13. /**
  14. * StoreActivityFrom模型对象
  15. * @var \app\admin\model\StoreActivityFrom
  16. */
  17. protected $model = null;
  18. public function _initialize()
  19. {
  20. parent::_initialize();
  21. $this->model = new \app\admin\model\StoreActivityFrom;
  22. }
  23. /**
  24. * 默认生成的控制器所继承的父类中有index/add/edit/del/multi五个基础方法、destroy/restore/recyclebin三个回收站方法
  25. * 因此在当前控制器中可不用编写增删改查的代码,除非需要自己控制这部分逻辑
  26. * 需要将application/admin/library/traits/Backend.php中对应的方法复制到当前控制器,然后进行修改
  27. */
  28. /**
  29. * 查看
  30. */
  31. public function index($activity_id=null)
  32. {
  33. //设置过滤方法
  34. $this->request->filter(['strip_tags']);
  35. if ($this->request->isAjax()) {
  36. //如果发送的来源是Selectpage,则转发到Selectpage
  37. if ($this->request->request('keyField')) {
  38. return $this->selectpage();
  39. }
  40. list($where, $sort, $order, $offset, $limit) = $this->buildparams();
  41. $total = $this->model
  42. ->where($where)
  43. ->where('status','1')
  44. ->where('activity_id',$activity_id)
  45. ->order($sort, $order)
  46. ->count();
  47. $list = $this->model
  48. ->where($where)
  49. ->where('status','1')
  50. ->where('activity_id',$activity_id)
  51. ->with('member')
  52. ->order($sort, $order)
  53. ->limit($offset, $limit)
  54. ->select();
  55. $list = collection($list)->toArray();
  56. $result = array("total" => $total, "rows" => $list);
  57. return json($result);
  58. }
  59. return $this->view->fetch();
  60. }
  61. /**
  62. * 删除
  63. */
  64. public function del($ids = "")
  65. {
  66. if ($ids) {
  67. $pk = $this->model->getPk();
  68. $adminIds = $this->getDataLimitAdminIds();
  69. if (is_array($adminIds)) {
  70. $this->model->where($this->dataLimitField, 'in', $adminIds);
  71. }
  72. $list = $this->model->where($pk, 'in', $ids)->select();
  73. $count = 0;
  74. Db::startTrans();
  75. try {
  76. foreach ($list as $k => $v) {
  77. $count += $v->save(['status'=>'0']);
  78. }
  79. Db::commit();
  80. } catch (PDOException $e) {
  81. Db::rollback();
  82. $this->error($e->getMessage());
  83. } catch (Exception $e) {
  84. Db::rollback();
  85. $this->error($e->getMessage());
  86. }
  87. if ($count) {
  88. $this->success();
  89. } else {
  90. $this->error(__('No rows were deleted'));
  91. }
  92. }
  93. $this->error(__('Parameter %s can not be empty', 'ids'));
  94. }
  95. }