Conference.php 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  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\DbException;
  8. use think\exception\PDOException;
  9. use think\exception\ValidateException;
  10. /**
  11. * 会议管理
  12. *
  13. * @icon fa fa-cny
  14. */
  15. class Conference extends Backend
  16. {
  17. /**
  18. * Conference模型对象
  19. * @var \app\admin\model\cms\Conference
  20. */
  21. protected $model = null;
  22. protected $searchFields = 'id';
  23. protected $noNeedRight = ['detail', 'is_adopt'];
  24. public function _initialize()
  25. {
  26. parent::_initialize();
  27. $this->model = new \app\admin\model\cms\Conference();
  28. }
  29. /**
  30. * 查看
  31. */
  32. public function index()
  33. {
  34. //设置过滤方法
  35. $this->request->filter(['strip_tags']);
  36. if ($this->request->isAjax()) {
  37. $this->relationSearch = true;
  38. //如果发送的来源是Selectpage,则转发到Selectpage
  39. if ($this->request->request('keyField')) {
  40. return $this->selectpage();
  41. }
  42. list($where, $sort, $order, $offset, $limit) = $this->buildparams();
  43. $total = $this->model
  44. ->where($where)
  45. ->order($sort, $order)
  46. ->count();
  47. $list = $this->model->with(['user'])
  48. ->where($where)
  49. ->order($sort, $order)
  50. ->limit($offset, $limit)
  51. ->select();
  52. foreach ($list as $value) {
  53. $value['image'] = explode(',',$value['image'])[0];
  54. }
  55. $result = array("total" => $total, "rows" => $list);
  56. return json($result);
  57. }
  58. return $this->view->fetch();
  59. }
  60. /**
  61. * 编辑
  62. *
  63. * @param $ids
  64. * @return string
  65. * @throws DbException
  66. * @throws \think\Exception
  67. */
  68. public function edit($ids = null)
  69. {
  70. $row = $this->model->get($ids);
  71. if (!$row) {
  72. $this->error(__('No Results were found'));
  73. }
  74. $adminIds = $this->getDataLimitAdminIds();
  75. if (is_array($adminIds) && !in_array($row[$this->dataLimitField], $adminIds)) {
  76. $this->error(__('You have no permission'));
  77. }
  78. if (false === $this->request->isPost()) {
  79. $this->view->assign('row', $row);
  80. return $this->view->fetch();
  81. }
  82. $params = $this->request->post('row/a');
  83. if (empty($params)) {
  84. $this->error(__('Parameter %s can not be empty', ''));
  85. }
  86. $params = $this->preExcludeFields($params);
  87. $result = false;
  88. Db::startTrans();
  89. try {
  90. //是否采用模型验证
  91. if ($this->modelValidate) {
  92. $name = str_replace("\\model\\", "\\validate\\", get_class($this->model));
  93. $validate = is_bool($this->modelValidate) ? ($this->modelSceneValidate ? $name . '.edit' : $name) : $this->modelValidate;
  94. $row->validateFailException()->validate($validate);
  95. }
  96. $result = $row->allowField(true)->save($params);
  97. Db::commit();
  98. } catch (ValidateException|PDOException|Exception $e) {
  99. Db::rollback();
  100. $this->error($e->getMessage());
  101. }
  102. if (false === $result) {
  103. $this->error(__('No rows were updated'));
  104. }
  105. $this->success();
  106. }
  107. /**
  108. * 参与会议详情
  109. *
  110. * @param $ids
  111. * @return string|\think\response\Json
  112. * @throws Exception
  113. */
  114. public function detail($ids = null)
  115. {
  116. //设置过滤方法
  117. $this->request->filter(['strip_tags', 'trim']);
  118. if ($this->request->isAjax()) {
  119. //如果发送的来源是Selectpage,则转发到Selectpage
  120. if ($this->request->request('keyField')) {
  121. return $this->selectpage();
  122. }
  123. list($where, $sort, $order, $offset, $limit) = $this->buildparams();
  124. $model = new Participate();
  125. $list = $model->with(['user', 'conference'])
  126. ->where(['conference_id' => $ids])
  127. ->where($where)
  128. ->order($sort, $order)
  129. ->paginate($limit);
  130. $result = array("total" => $list->total(), "rows" => $list->items());
  131. return json($result);
  132. }
  133. return $this->view->fetch();
  134. }
  135. /**
  136. * 会议申请操作
  137. *
  138. * @param $ids
  139. * @param $status
  140. * @return void
  141. * @throws \think\db\exception\DataNotFoundException
  142. * @throws \think\db\exception\ModelNotFoundException
  143. * @throws \think\exception\DbException
  144. */
  145. public function is_adopt($ids = null, $status = null)
  146. {
  147. $row = $this->model->get($ids);
  148. if (!$row) {
  149. $this->error(__('No Results were found'));
  150. }
  151. $result = false;
  152. Db::startTrans();
  153. try {
  154. //是否采用模型验证
  155. if ($this->modelValidate) {
  156. $name = str_replace("\\model\\", "\\validate\\", get_class($this->model));
  157. $validate = is_bool($this->modelValidate) ? ($this->modelSceneValidate ? $name . '.edit' : $name) : $this->modelValidate;
  158. $row->validateFailException()->validate($validate);
  159. }
  160. $result = $row->allowField(true)->save(['status' => $status]);
  161. Db::commit();
  162. } catch (ValidateException|PDOException|Exception $e) {
  163. Db::rollback();
  164. $this->error($e->getMessage());
  165. }
  166. if (false === $result) {
  167. $this->error(__('No rows were updated'));
  168. }
  169. $this->success();
  170. }
  171. }