Nickname.php 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262
  1. <?php
  2. namespace app\admin\controller\applys;
  3. use app\common\controller\Backend;
  4. use think\Db;
  5. /**
  6. * 用户昵称审核
  7. *
  8. * @icon fa fa-circle-o
  9. */
  10. class Nickname extends Backend
  11. {
  12. /**
  13. * Nickname模型对象
  14. * @var \app\admin\model\applys\Nickname
  15. */
  16. protected $model = null;
  17. public function _initialize()
  18. {
  19. parent::_initialize();
  20. $this->model = new \app\admin\model\applys\Nickname;
  21. $this->view->assign("statusList", $this->model->getStatusList());
  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. $list = $this->model
  48. ->with(['user'])
  49. ->where($where)
  50. ->order($sort, $order)
  51. ->paginate($limit);
  52. foreach ($list as $row) {
  53. $row->getRelation('user')->visible(['nickname','province_name','city_name']);
  54. }
  55. foreach ($list as $k => $v) {
  56. $list[$k]['city'] = $v['user']['province_name'].".".$v['user']['city_name'];
  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 add()
  67. {
  68. if ($this->request->isPost()) {
  69. $params = $this->request->post("row/a");
  70. if ($params) {
  71. $params = $this->preExcludeFields($params);
  72. if ($this->dataLimit && $this->dataLimitFieldAutoFill) {
  73. $params[$this->dataLimitField] = $this->auth->id;
  74. }
  75. $result = false;
  76. Db::startTrans();
  77. try {
  78. //是否采用模型验证
  79. if ($this->modelValidate) {
  80. $name = str_replace("\\model\\", "\\validate\\", get_class($this->model));
  81. $validate = is_bool($this->modelValidate) ? ($this->modelSceneValidate ? $name . '.add' : $name) : $this->modelValidate;
  82. $this->model->validateFailException(true)->validate($validate);
  83. }
  84. $result = $this->model->allowField(true)->save($params);
  85. delUserInfo($params['user_id']);
  86. Db::commit();
  87. } catch (ValidateException $e) {
  88. Db::rollback();
  89. $this->error($e->getMessage());
  90. } catch (PDOException $e) {
  91. Db::rollback();
  92. $this->error($e->getMessage());
  93. } catch (Exception $e) {
  94. Db::rollback();
  95. $this->error($e->getMessage());
  96. }
  97. if ($result !== false) {
  98. $this->success();
  99. } else {
  100. $this->error(__('No rows were inserted'));
  101. }
  102. }
  103. $this->error(__('Parameter %s can not be empty', ''));
  104. }
  105. return $this->view->fetch();
  106. }
  107. /**
  108. * 编辑
  109. */
  110. public function edit($ids = null)
  111. {
  112. $row = $this->model->get($ids);
  113. if (!$row) {
  114. $this->error(__('No Results were found'));
  115. }
  116. $adminIds = $this->getDataLimitAdminIds();
  117. if (is_array($adminIds)) {
  118. if (!in_array($row[$this->dataLimitField], $adminIds)) {
  119. $this->error(__('You have no permission'));
  120. }
  121. }
  122. if ($this->request->isPost()) {
  123. $params = $this->request->post("row/a");
  124. $params['status'] = 1;
  125. if ($params) {
  126. $params = $this->preExcludeFields($params);
  127. $result = false;
  128. Db::startTrans();
  129. try {
  130. // if($row['status'] == 0 && $row['status'] != $params['status']) {
  131. // if($params['status'] == 1) {
  132. \app\common\model\User::update(['nickname'=>$row['nickname']],['id'=>$row['user_id']]);
  133. $title = '昵称审核成功!';
  134. $content = '恭喜您,您的昵称修改审核成功!';
  135. \app\common\model\SysMsg::sendSysMsg($row['user_id'],2,$title,$content);
  136. // }
  137. // if($params['status'] == -1) {
  138. // \app\common\model\User::update(['nickname'=>$params['old_nickname']],['id'=>$params['user_id']]);
  139. // $title = '昵称审核失败!';
  140. // $content = '非常抱歉,您的昵称由于不符合平台规范,管理员已审核拒绝!';
  141. // \app\common\model\SysMsg::sendSysMsg($row['user_id'],2,$title,$content);
  142. // }
  143. // }
  144. //是否采用模型验证
  145. if ($this->modelValidate) {
  146. $name = str_replace("\\model\\", "\\validate\\", get_class($this->model));
  147. $validate = is_bool($this->modelValidate) ? ($this->modelSceneValidate ? $name . '.edit' : $name) : $this->modelValidate;
  148. $row->validateFailException(true)->validate($validate);
  149. }
  150. $result = $row->allowField(true)->save($params);
  151. delUserInfo($row['user_id']);
  152. Db::commit();
  153. } catch (ValidateException $e) {
  154. Db::rollback();
  155. $this->error($e->getMessage());
  156. } catch (PDOException $e) {
  157. Db::rollback();
  158. $this->error($e->getMessage());
  159. } catch (Exception $e) {
  160. Db::rollback();
  161. $this->error($e->getMessage());
  162. }
  163. if ($result !== false) {
  164. $this->success();
  165. } else {
  166. $this->error(__('No rows were updated'));
  167. }
  168. }
  169. $this->error(__('Parameter %s can not be empty', ''));
  170. }
  171. $this->view->assign("row", $row);
  172. return $this->view->fetch();
  173. }
  174. /**
  175. * 拒绝
  176. */
  177. public function del($ids = null)
  178. {
  179. $row = $this->model->get($ids);
  180. if (!$row) {
  181. $this->error(__('No Results were found'));
  182. }
  183. $adminIds = $this->getDataLimitAdminIds();
  184. if (is_array($adminIds)) {
  185. if (!in_array($row[$this->dataLimitField], $adminIds)) {
  186. $this->error(__('You have no permission'));
  187. }
  188. }
  189. if ($this->request->isPost()) {
  190. $params = $this->request->post("row/a");
  191. $params['status'] = -1;
  192. if ($params) {
  193. $params = $this->preExcludeFields($params);
  194. $result = false;
  195. Db::startTrans();
  196. try {
  197. // if($row['status'] == 0 && $row['status'] != $params['status']) {
  198. // if($params['status'] == 1) {
  199. // \app\common\model\User::update(['nickname'=>$params['nickname']],['id'=>$params['user_id']]);
  200. // $title = '昵称审核成功!';
  201. // $content = '恭喜您,您的昵称修改审核成功!';
  202. // \app\common\model\SysMsg::sendSysMsg($row['user_id'],2,$title,$content);
  203. // }
  204. // if($params['status'] == -1) {
  205. \app\common\model\User::update(['nickname'=>$row['old_nickname']],['id'=>$row['user_id']]);
  206. $title = '昵称审核失败!';
  207. $content = '非常抱歉,您的昵称由于不符合平台规范,管理员已审核拒绝!';
  208. \app\common\model\SysMsg::sendSysMsg($row['user_id'],2,$title,$content);
  209. // }
  210. // }
  211. //是否采用模型验证
  212. if ($this->modelValidate) {
  213. $name = str_replace("\\model\\", "\\validate\\", get_class($this->model));
  214. $validate = is_bool($this->modelValidate) ? ($this->modelSceneValidate ? $name . '.edit' : $name) : $this->modelValidate;
  215. $row->validateFailException(true)->validate($validate);
  216. }
  217. $result = $row->allowField(true)->save($params);
  218. delUserInfo($row['user_id']);
  219. Db::commit();
  220. } catch (ValidateException $e) {
  221. Db::rollback();
  222. $this->error($e->getMessage());
  223. } catch (PDOException $e) {
  224. Db::rollback();
  225. $this->error($e->getMessage());
  226. } catch (Exception $e) {
  227. Db::rollback();
  228. $this->error($e->getMessage());
  229. }
  230. if ($result !== false) {
  231. $this->success();
  232. } else {
  233. $this->error(__('No rows were updated'));
  234. }
  235. }
  236. $this->error(__('Parameter %s can not be empty', ''));
  237. }
  238. $this->view->assign("row", $row);
  239. return $this->view->fetch();
  240. }
  241. }