Conference.php 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. <?php
  2. namespace app\admin\controller\cms;
  3. use app\admin\model\cms\Participate;
  4. use app\common\controller\Backend;
  5. use app\common\model\UserRoleLog;
  6. use think\Db;
  7. use think\exception\PDOException;
  8. use think\exception\ValidateException;
  9. /**
  10. * 会议管理
  11. *
  12. * @icon fa fa-cny
  13. */
  14. class Conference extends Backend
  15. {
  16. /**
  17. * Conference模型对象
  18. * @var \app\admin\model\cms\Conference
  19. */
  20. protected $model = null;
  21. protected $searchFields = 'id';
  22. protected $noNeedRight = ['detail', 'is_adopt'];
  23. public function _initialize()
  24. {
  25. parent::_initialize();
  26. $this->model = new \app\admin\model\cms\Conference();
  27. }
  28. /**
  29. * 查看
  30. */
  31. public function index()
  32. {
  33. //设置过滤方法
  34. $this->request->filter(['strip_tags']);
  35. if ($this->request->isAjax()) {
  36. $this->relationSearch = true;
  37. //如果发送的来源是Selectpage,则转发到Selectpage
  38. if ($this->request->request('keyField')) {
  39. return $this->selectpage();
  40. }
  41. list($where, $sort, $order, $offset, $limit) = $this->buildparams();
  42. $total = $this->model
  43. ->where($where)
  44. ->order($sort, $order)
  45. ->count();
  46. $list = $this->model->with(['user'])
  47. ->where($where)
  48. ->order($sort, $order)
  49. ->limit($offset, $limit)
  50. ->select();
  51. $result = array("total" => $total, "rows" => $list);
  52. return json($result);
  53. }
  54. return $this->view->fetch();
  55. }
  56. /**
  57. * 参与会议详情
  58. *
  59. * @param $ids
  60. * @return string|\think\response\Json
  61. * @throws Exception
  62. */
  63. public function detail($ids = null)
  64. {
  65. //设置过滤方法
  66. $this->request->filter(['strip_tags', 'trim']);
  67. if ($this->request->isAjax()) {
  68. //如果发送的来源是Selectpage,则转发到Selectpage
  69. if ($this->request->request('keyField')) {
  70. return $this->selectpage();
  71. }
  72. list($where, $sort, $order, $offset, $limit) = $this->buildparams();
  73. $model = new Participate();
  74. $list = $model->with(['user', 'conference'])
  75. ->where(['conference_id' => $ids])
  76. ->where($where)
  77. ->order($sort, $order)
  78. ->paginate($limit);
  79. $result = array("total" => $list->total(), "rows" => $list->items());
  80. return json($result);
  81. }
  82. return $this->view->fetch();
  83. }
  84. /**
  85. * 会议申请操作
  86. *
  87. * @param $ids
  88. * @param $status
  89. * @return void
  90. * @throws \think\db\exception\DataNotFoundException
  91. * @throws \think\db\exception\ModelNotFoundException
  92. * @throws \think\exception\DbException
  93. */
  94. public function is_adopt($ids = null, $status = null)
  95. {
  96. $row = $this->model->get($ids);
  97. if (!$row) {
  98. $this->error(__('No Results were found'));
  99. }
  100. $result = false;
  101. Db::startTrans();
  102. try {
  103. //是否采用模型验证
  104. if ($this->modelValidate) {
  105. $name = str_replace("\\model\\", "\\validate\\", get_class($this->model));
  106. $validate = is_bool($this->modelValidate) ? ($this->modelSceneValidate ? $name . '.edit' : $name) : $this->modelValidate;
  107. $row->validateFailException()->validate($validate);
  108. }
  109. $result = $row->allowField(true)->save(['status' => $status]);
  110. Db::commit();
  111. } catch (ValidateException|PDOException|Exception $e) {
  112. Db::rollback();
  113. $this->error($e->getMessage());
  114. }
  115. if (false === $result) {
  116. $this->error(__('No rows were updated'));
  117. }
  118. $this->success();
  119. }
  120. }