Education.php 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  1. <?php
  2. namespace app\admin\controller\user\authentication;
  3. use app\common\controller\Backend;
  4. use app\common\model\Category;
  5. use app\common\model\SystemMessages;
  6. use app\common\model\User;
  7. use think\Db;
  8. use think\db\exception\DataNotFoundException;
  9. use think\db\exception\ModelNotFoundException;
  10. use think\exception\DbException;
  11. use think\exception\PDOException;
  12. use think\exception\ValidateException;
  13. use think\response\Json;
  14. /**
  15. * 学历认证
  16. *
  17. * @icon fa fa-circle-o
  18. */
  19. class Education extends Backend
  20. {
  21. /**
  22. * EducationAuthentication模型对象
  23. * @var \app\common\model\EducationAuthentication
  24. */
  25. protected $model = null;
  26. public function _initialize()
  27. {
  28. parent::_initialize();
  29. $this->model = new \app\common\model\EducationAuthentication;
  30. }
  31. /**
  32. * 查看
  33. *
  34. * @return string|Json
  35. * @throws \think\Exception
  36. * @throws DbException
  37. */
  38. public function index()
  39. {
  40. //设置过滤方法
  41. $this->request->filter(['strip_tags', 'trim']);
  42. if (false === $this->request->isAjax()) {
  43. return $this->view->fetch();
  44. }
  45. //如果发送的来源是 Selectpage,则转发到 Selectpage
  46. if ($this->request->request('keyField')) {
  47. return $this->selectpage();
  48. }
  49. [$where, $sort, $order, $offset, $limit] = $this->buildparams();
  50. $list = $this->model
  51. ->with('educationCategory')
  52. ->where($where)
  53. ->whereIn('status','0,1,2')
  54. ->order($sort, $order)
  55. ->paginate($limit);
  56. $result = ['total' => $list->total(), 'rows' => $list->items()];
  57. return json($result);
  58. }
  59. /**
  60. * 编辑
  61. *
  62. * @param $ids
  63. * @return string
  64. * @throws DbException
  65. * @throws \think\Exception
  66. */
  67. public function audit($ids = null)
  68. {
  69. $row = $this->model->get($ids,['educationCategory']);
  70. if (!$row) {
  71. $this->error(__('No Results were found'));
  72. }
  73. $adminIds = $this->getDataLimitAdminIds();
  74. if (is_array($adminIds) && !in_array($row[$this->dataLimitField], $adminIds)) {
  75. $this->error(__('You have no permission'));
  76. }
  77. if (false === $this->request->isPost()) {
  78. $this->view->assign('row', $row);
  79. return $this->view->fetch();
  80. }
  81. $params = $this->request->post('row/a');
  82. if (empty($params)) {
  83. $this->error(__('Parameter %s can not be empty', ''));
  84. }
  85. $params = $this->preExcludeFields($params);
  86. $result = false;
  87. Db::startTrans();
  88. try {
  89. //是否采用模型验证
  90. if ($this->modelValidate) {
  91. $name = str_replace("\\model\\", "\\validate\\", get_class($this->model));
  92. $validate = is_bool($this->modelValidate) ? ($this->modelSceneValidate ? $name . '.edit' : $name) : $this->modelValidate;
  93. $row->validateFailException()->validate($validate);
  94. }
  95. $result = $row->allowField(true)->save($params);
  96. $user = User::where('id',$params['uid'])->findOrFail();
  97. if($params['status'] == 1){
  98. $user->save(['education_authentication'=>1]);
  99. SystemMessages::messages('education_authentication_yes',$params['uid']);
  100. }elseif($params['status'] == 2){
  101. $user->save(['education_authentication'=>2]);
  102. SystemMessages::messages('education_authentication_no',$params['uid']);
  103. }
  104. Db::commit();
  105. } catch (ValidateException|PDOException|Exception $e) {
  106. Db::rollback();
  107. $this->error($e->getMessage());
  108. }
  109. if (false === $result) {
  110. $this->error(__('No rows were updated'));
  111. }
  112. $this->success();
  113. }
  114. /**
  115. * 删除
  116. *
  117. * @param $ids
  118. * @return void
  119. * @throws DbException
  120. * @throws DataNotFoundException
  121. * @throws ModelNotFoundException
  122. */
  123. public function del($ids = null)
  124. {
  125. if (false === $this->request->isPost()) {
  126. $this->error(__("Invalid parameters"));
  127. }
  128. $ids = $ids ?: $this->request->post("ids");
  129. if (empty($ids)) {
  130. $this->error(__('Parameter %s can not be empty', 'ids'));
  131. }
  132. $pk = $this->model->getPk();
  133. $adminIds = $this->getDataLimitAdminIds();
  134. if (is_array($adminIds)) {
  135. $this->model->where($this->dataLimitField, 'in', $adminIds);
  136. }
  137. $list = $this->model->where($pk, 'in', $ids)->select();
  138. $count = 0;
  139. Db::startTrans();
  140. try {
  141. foreach ($list as $item) {
  142. $count += $item->delete();
  143. }
  144. Db::commit();
  145. } catch (PDOException|Exception $e) {
  146. Db::rollback();
  147. $this->error($e->getMessage());
  148. }
  149. if ($count) {
  150. $this->success();
  151. }
  152. $this->error(__('No rows were deleted'));
  153. }
  154. }