Activepeoplemodify.php 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  1. <?php
  2. namespace app\admin\controller;
  3. use app\common\controller\Backend;
  4. use Exception;
  5. use Think\Db;
  6. /**
  7. * 活动人员信息修改管理
  8. *
  9. * @icon fa fa-circle-o
  10. */
  11. class Activepeoplemodify extends Backend
  12. {
  13. /**
  14. * Activepeoplemodify模型对象
  15. * @var \app\admin\model\Activepeoplemodify
  16. */
  17. protected $model = null;
  18. public function _initialize()
  19. {
  20. parent::_initialize();
  21. $this->model = new \app\admin\model\Activepeoplemodify;
  22. $this->view->assign("coupontypeList", $this->model->getCoupontypeList());
  23. $this->view->assign("isFreeList", $this->model->getIsFreeList());
  24. $this->view->assign("isSelfList", $this->model->getIsSelfList());
  25. $this->view->assign("statusList", $this->model->getStatusList());
  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. $list = $this->model
  48. ->with(['active','activeorder','activepeople','user'])
  49. ->where($where)
  50. ->order($sort, $order)
  51. ->paginate($limit);
  52. foreach ($list as $row) {
  53. $row->getRelation('active')->visible(['title','desc']);
  54. $row->getRelation('activeorder')->visible(['order_sn']);
  55. $row->getRelation('activepeople')->visible(['name','idcard','mobile','emergencycontact','contactmobile']);
  56. $row->getRelation('user')->visible(['nickname','mobile']);
  57. }
  58. $result = array("total" => $list->total(), "rows" => $list->items());
  59. return json($result);
  60. }
  61. return $this->view->fetch();
  62. }
  63. /**
  64. * 编辑
  65. */
  66. public function edit($ids = null) {
  67. $row = $this->model->get($ids);
  68. if (!$row) {
  69. $this->error(__('No Results were found'));
  70. }
  71. $adminIds = $this->getDataLimitAdminIds();
  72. if (is_array($adminIds)) {
  73. if (!in_array($row[$this->dataLimitField], $adminIds)) {
  74. $this->error(__('You have no permission'));
  75. }
  76. }
  77. if ($this->request->isPost()) {
  78. $params = $this->request->post("row/a");
  79. if ($params) {
  80. $params = $this->preExcludeFields($params);
  81. if ($row['status'] != 0) {
  82. $this->error('该数据已经操作过');
  83. }
  84. $result = false;
  85. Db::startTrans();
  86. try {
  87. //修改信息
  88. if (isset($params['status'])) {
  89. if ($params['status'] == 1) {
  90. //通过
  91. $people_data = [
  92. 'name' => $row['name'],
  93. 'idcard' => $row['idcard'],
  94. 'mobile' => $row['mobile'],
  95. 'emergencycontact' => $row['emergencycontact'],
  96. 'contactmobile' => $row['contactmobile'],
  97. 'modifystatus' => 0,
  98. 'updatetime' => time()
  99. ];
  100. $rs = Db::name('active_people')->where(['id' => $row['people_id'], 'modifystatus' => 1])->setField($people_data);
  101. if (!$rs) {
  102. Db::rollback();
  103. return ['code' => 0, 'msg' => '操作失败'];
  104. }
  105. //发送消息
  106. $active_title = Db::name('active')->where(['id' => $row['active_id']])->value('title');
  107. $data = [
  108. 'user_id' => $row['user_id'],
  109. 'type' => 1,
  110. 'title' => '活动通知',
  111. 'content' => '您报名的' . $active_title . '活动人员信息修改已通过',
  112. 'createtime' => time()
  113. ];
  114. Db::name('sys_msg')->insertGetId($data);
  115. } elseif ($params['status'] == 2) {
  116. //拒绝
  117. $rs = Db::name('active_people')->where(['id' => $row['people_id'], 'modifystatus' => 1])->setField('modifystatus', 0);
  118. if (!$rs) {
  119. Db::rollback();
  120. return ['code' => 0, 'msg' => '操作失败'];
  121. }
  122. //发送消息
  123. $active_title = Db::name('active')->where(['id' => $row['active_id']])->value('title');
  124. $data = [
  125. 'user_id' => $row['user_id'],
  126. 'type' => 1,
  127. 'title' => '活动通知',
  128. 'content' => '您报名的' . $active_title . '活动人员信息修改已被拒绝',
  129. 'createtime' => time()
  130. ];
  131. Db::name('sys_msg')->insertGetId($data);
  132. }
  133. }
  134. //是否采用模型验证
  135. if ($this->modelValidate) {
  136. $name = str_replace("\\model\\", "\\validate\\", get_class($this->model));
  137. $validate = is_bool($this->modelValidate) ? ($this->modelSceneValidate ? $name . '.edit' : $name) : $this->modelValidate;
  138. $row->validateFailException(true)->validate($validate);
  139. }
  140. $result = $row->allowField(true)->save($params);
  141. Db::commit();
  142. } catch (ValidateException $e) {
  143. Db::rollback();
  144. $this->error($e->getMessage());
  145. } catch (PDOException $e) {
  146. Db::rollback();
  147. $this->error($e->getMessage());
  148. } catch (Exception $e) {
  149. Db::rollback();
  150. $this->error($e->getMessage());
  151. }
  152. if ($result !== false) {
  153. $this->success();
  154. } else {
  155. $this->error(__('No rows were updated'));
  156. }
  157. }
  158. $this->error(__('Parameter %s can not be empty', ''));
  159. }
  160. $this->view->assign("row", $row);
  161. return $this->view->fetch();
  162. }
  163. }