RealVerified.php 4.4 KB

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