Userauthperson.php 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. <?php
  2. namespace app\admin\controller;
  3. use app\common\controller\Backend;
  4. /**
  5. * 用户真人认证管理
  6. *
  7. * @icon fa fa-circle-o
  8. */
  9. class Userauthperson extends Backend
  10. {
  11. /**
  12. * Userauthperson模型对象
  13. * @var \app\admin\model\Userauthperson
  14. */
  15. protected $model = null;
  16. public function _initialize()
  17. {
  18. parent::_initialize();
  19. $this->model = new \app\admin\model\Userauthperson;
  20. $this->view->assign("statusList", $this->model->getStatusList());
  21. }
  22. public function import()
  23. {
  24. parent::import();
  25. }
  26. /**
  27. * 默认生成的控制器所继承的父类中有index/add/edit/del/multi五个基础方法、destroy/restore/recyclebin三个回收站方法
  28. * 因此在当前控制器中可不用编写增删改查的代码,除非需要自己控制这部分逻辑
  29. * 需要将application/admin/library/traits/Backend.php中对应的方法复制到当前控制器,然后进行修改
  30. */
  31. /**
  32. * 查看
  33. */
  34. public function index()
  35. {
  36. //当前是否为关联查询
  37. $this->relationSearch = true;
  38. //设置过滤方法
  39. $this->request->filter(['strip_tags', 'trim']);
  40. if ($this->request->isAjax()) {
  41. //如果发送的来源是Selectpage,则转发到Selectpage
  42. if ($this->request->request('keyField')) {
  43. return $this->selectpage();
  44. }
  45. list($where, $sort, $order, $offset, $limit) = $this->buildparams();
  46. $list = $this->model
  47. ->with(['user'])
  48. ->where($where)
  49. ->order($sort, $order)
  50. ->paginate($limit);
  51. foreach ($list as $row) {
  52. $row->getRelation('user')->visible(['nickname','mobile']);
  53. }
  54. $result = array("total" => $list->total(), "rows" => $list->items());
  55. return json($result);
  56. }
  57. return $this->view->fetch();
  58. }
  59. /**
  60. * 编辑
  61. */
  62. public function edit($ids = null)
  63. {
  64. $row = $this->model->get($ids);
  65. if (!$row) {
  66. $this->error(__('No Results were found'));
  67. }
  68. $adminIds = $this->getDataLimitAdminIds();
  69. if (is_array($adminIds)) {
  70. if (!in_array($row[$this->dataLimitField], $adminIds)) {
  71. $this->error(__('You have no permission'));
  72. }
  73. }
  74. if ($this->request->isPost()) {
  75. $params = $this->request->post("row/a");
  76. if ($params) {
  77. $params = $this->preExcludeFields($params);
  78. $result = false;
  79. Db::startTrans();
  80. try {
  81. $data = [];
  82. switch ($params["status"]) {
  83. case 0:
  84. $data["is_auth_person"] = 1;
  85. break;
  86. case 1:
  87. if($row['status'] != 1) {
  88. $title = '真人认证提醒!';
  89. $content = '恭喜您,您的真人认证审核通过啦,赶紧联系你心目中的那个ta吧!';
  90. \app\common\model\SysMsg::sendSysMsg($params['user_id'],7,$title,$content);
  91. }
  92. $data["is_auth_person"] = 2;
  93. break;
  94. case 2:
  95. if($row['status'] != 2) {
  96. $title = '真人认证提醒!';
  97. $content = '抱歉,您的真人认证审核未通过,请联系客服!';
  98. \app\common\model\SysMsg::sendSysMsg($params['user_id'],7,$title,$content);
  99. }
  100. $data["is_auth_person"] = -1;
  101. break;
  102. default:
  103. $data["is_auth_person"] = 1;
  104. break;
  105. }
  106. \app\common\model\User::update($data,["id"=>$row["user_id"]]);
  107. // 消息通知
  108. //是否采用模型验证
  109. if ($this->modelValidate) {
  110. $name = str_replace("\\model\\", "\\validate\\", get_class($this->model));
  111. $validate = is_bool($this->modelValidate) ? ($this->modelSceneValidate ? $name . '.edit' : $name) : $this->modelValidate;
  112. $row->validateFailException(true)->validate($validate);
  113. }
  114. $result = $row->allowField(true)->save($params);
  115. Db::commit();
  116. } catch (ValidateException $e) {
  117. Db::rollback();
  118. $this->error($e->getMessage());
  119. } catch (PDOException $e) {
  120. Db::rollback();
  121. $this->error($e->getMessage());
  122. } catch (Exception $e) {
  123. Db::rollback();
  124. $this->error($e->getMessage());
  125. }
  126. if ($result !== false) {
  127. $this->success();
  128. } else {
  129. $this->error(__('No rows were updated'));
  130. }
  131. }
  132. $this->error(__('Parameter %s can not be empty', ''));
  133. }
  134. $this->view->assign("row", $row);
  135. return $this->view->fetch();
  136. }
  137. }