Userauth.php 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  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 Userauth extends Backend
  11. {
  12. /**
  13. * Userauth模型对象
  14. * @var \app\admin\model\applys\Userauth
  15. */
  16. protected $model = null;
  17. public function _initialize()
  18. {
  19. parent::_initialize();
  20. $this->model = new \app\admin\model\applys\Userauth;
  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 edit($ids = null)
  67. {
  68. $row = $this->model->get($ids);
  69. if (!$row) {
  70. $this->error(__('No Results were found'));
  71. }
  72. $adminIds = $this->getDataLimitAdminIds();
  73. if (is_array($adminIds)) {
  74. if (!in_array($row[$this->dataLimitField], $adminIds)) {
  75. $this->error(__('You have no permission'));
  76. }
  77. }
  78. if ($this->request->isPost()) {
  79. $params = $this->request->post("row/a");
  80. if ($params) {
  81. $params = $this->preExcludeFields($params);
  82. $result = false;
  83. Db::startTrans();
  84. try {
  85. $data = [];
  86. switch ($params["status"]) {
  87. case 0:
  88. $data["is_auth"] = 1;
  89. break;
  90. case 1:
  91. if($row['status'] != 1) {
  92. $title = '实名认证提醒!';
  93. $content = '恭喜您,您的实名认证审核通过啦,赶紧联系你心目中的那个ta吧!';
  94. \app\common\model\SysMsg::sendSysMsg($params['user_id'],7,$title,$content);
  95. }
  96. $data["is_auth"] = 2;
  97. break;
  98. case 2:
  99. if($row['status'] != 2) {
  100. $title = '实名认证提醒!';
  101. $content = '抱歉,您的实名认证审核未通过,请联系客服!';
  102. \app\common\model\SysMsg::sendSysMsg($params['user_id'],7,$title,$content);
  103. }
  104. $data["is_auth"] = -1;
  105. break;
  106. default:
  107. $data["is_auth"] = 1;
  108. break;
  109. }
  110. \app\common\model\User::update($data,["id"=>$row["user_id"]]);
  111. // 消息通知
  112. //是否采用模型验证
  113. if ($this->modelValidate) {
  114. $name = str_replace("\\model\\", "\\validate\\", get_class($this->model));
  115. $validate = is_bool($this->modelValidate) ? ($this->modelSceneValidate ? $name . '.edit' : $name) : $this->modelValidate;
  116. $row->validateFailException(true)->validate($validate);
  117. }
  118. $result = $row->allowField(true)->save($params);
  119. Db::commit();
  120. } catch (ValidateException $e) {
  121. Db::rollback();
  122. $this->error($e->getMessage());
  123. } catch (PDOException $e) {
  124. Db::rollback();
  125. $this->error($e->getMessage());
  126. } catch (Exception $e) {
  127. Db::rollback();
  128. $this->error($e->getMessage());
  129. }
  130. if ($result !== false) {
  131. $this->success();
  132. } else {
  133. $this->error(__('No rows were updated'));
  134. }
  135. }
  136. $this->error(__('Parameter %s can not be empty', ''));
  137. }
  138. $this->view->assign("row", $row);
  139. return $this->view->fetch();
  140. }
  141. }