Userauth.php 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. <?php
  2. namespace app\admin\controller;
  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\Userauth
  15. */
  16. protected $model = null;
  17. public function _initialize()
  18. {
  19. parent::_initialize();
  20. $this->model = new \app\admin\model\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','mobile']);
  54. }
  55. $result = array("total" => $list->total(), "rows" => $list->items());
  56. return json($result);
  57. }
  58. return $this->view->fetch();
  59. }
  60. /**
  61. * 编辑
  62. */
  63. public function edit($ids = null)
  64. {
  65. $row = $this->model->get($ids);
  66. if (!$row) {
  67. $this->error(__('No Results were found'));
  68. }
  69. $adminIds = $this->getDataLimitAdminIds();
  70. if (is_array($adminIds)) {
  71. if (!in_array($row[$this->dataLimitField], $adminIds)) {
  72. $this->error(__('You have no permission'));
  73. }
  74. }
  75. if ($this->request->isPost()) {
  76. $params = $this->request->post("row/a");
  77. if ($params) {
  78. $params = $this->preExcludeFields($params);
  79. $result = false;
  80. if (isset($params['status']) && $params['status'] == 1) {
  81. $edit_data['status'] = 1;
  82. } else {
  83. $edit_data['status'] = 2;
  84. $edit_data['certify_id'] = '';
  85. $edit_data['out_trade_no'] = '';
  86. }
  87. Db::startTrans();
  88. //修改认证信息
  89. $result = Db::name('user_auth')->where(['user_id' => $row['user_id'], 'status' => $row['status']])->setField($edit_data);
  90. if (!$result) {
  91. Db::rollback();
  92. $this->error('操作失败');
  93. }
  94. //修改用户信息
  95. $rs = Db::name('user')->where(['id' => $row['user_id']])->setField('real_status', $edit_data['status']);
  96. if (!$rs) {
  97. Db::rollback();
  98. $this->error('操作失败');
  99. }
  100. if ($edit_data['status'] == 1) { //通过
  101. //tag任务赠送金币
  102. //真人认证奖励
  103. $task_rs = \app\common\model\TaskLog::tofinish($row['user_id'],20);
  104. if($task_rs === false){
  105. Db::rollback();
  106. $this->error('完成任务赠送奖励失败');
  107. }
  108. //系统消息
  109. $msg_id = \app\common\model\Message::addMessage($row['user_id'],'真人认证','真人认证已经审核通过');
  110. } else {
  111. //系统消息
  112. $msg_id = \app\common\model\Message::addMessage($row['user_id'],'真人认证','真人认证审核不通过');
  113. }
  114. Db::commit();
  115. $this->success();
  116. /*try {
  117. //是否采用模型验证
  118. if ($this->modelValidate) {
  119. $name = str_replace("\\model\\", "\\validate\\", get_class($this->model));
  120. $validate = is_bool($this->modelValidate) ? ($this->modelSceneValidate ? $name . '.edit' : $name) : $this->modelValidate;
  121. $row->validateFailException(true)->validate($validate);
  122. }
  123. $result = $row->allowField(true)->save($params);
  124. Db::commit();
  125. } catch (ValidateException $e) {
  126. Db::rollback();
  127. $this->error($e->getMessage());
  128. } catch (PDOException $e) {
  129. Db::rollback();
  130. $this->error($e->getMessage());
  131. } catch (Exception $e) {
  132. Db::rollback();
  133. $this->error($e->getMessage());
  134. }
  135. if ($result !== false) {
  136. $this->success();
  137. } else {
  138. $this->error(__('No rows were updated'));
  139. }*/
  140. }
  141. $this->error(__('Parameter %s can not be empty', ''));
  142. }
  143. $this->view->assign("row", $row);
  144. return $this->view->fetch();
  145. }
  146. }