Work.php 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. <?php
  2. namespace app\admin\controller\user\authentication;
  3. use app\common\controller\Backend;
  4. use app\common\model\Apply;
  5. use app\common\model\SystemMessages;
  6. use app\common\model\User;
  7. use think\Db;
  8. use think\exception\DbException;
  9. use think\exception\PDOException;
  10. use think\exception\ValidateException;
  11. use think\response\Json;
  12. /**
  13. * 工作认证
  14. *
  15. * @icon fa fa-circle-o
  16. */
  17. class Work extends Backend
  18. {
  19. /**
  20. * WorkAuthentication模型对象
  21. * @var \app\common\model\WorkAuthentication
  22. */
  23. protected $model = null;
  24. public function _initialize()
  25. {
  26. parent::_initialize();
  27. $this->model = new \app\common\model\WorkAuthentication;
  28. }
  29. /**
  30. * 查看
  31. *
  32. * @return string|Json
  33. * @throws \think\Exception
  34. * @throws DbException
  35. */
  36. public function index()
  37. {
  38. //设置过滤方法
  39. $this->request->filter(['strip_tags', 'trim']);
  40. if (false === $this->request->isAjax()) {
  41. return $this->view->fetch();
  42. }
  43. //如果发送的来源是 Selectpage,则转发到 Selectpage
  44. if ($this->request->request('keyField')) {
  45. return $this->selectpage();
  46. }
  47. [$where, $sort, $order, $offset, $limit] = $this->buildparams();
  48. $list = $this->model
  49. ->where($where)
  50. ->whereIn('status','0,1,2')
  51. ->order($sort, $order)
  52. ->paginate($limit);
  53. $result = ['total' => $list->total(), 'rows' => $list->items()];
  54. return json($result);
  55. }
  56. /**
  57. * 编辑
  58. *
  59. * @param $ids
  60. * @return string
  61. * @throws DbException
  62. * @throws \think\Exception
  63. */
  64. public function audit($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) && !in_array($row[$this->dataLimitField], $adminIds)) {
  72. $this->error(__('You have no permission'));
  73. }
  74. if (false === $this->request->isPost()) {
  75. $this->view->assign('row', $row);
  76. return $this->view->fetch();
  77. }
  78. $params = $this->request->post('row/a');
  79. if (empty($params)) {
  80. $this->error(__('Parameter %s can not be empty', ''));
  81. }
  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()->validate($validate);
  91. }
  92. $result = $row->allowField(true)->save($params);
  93. $user = User::where('id',$params['uid'])->find();
  94. if($params['status'] == 1){
  95. $user->save(['work_authentication'=>1]);
  96. SystemMessages::messages('work_authentication_yes',$params['uid']);
  97. }elseif($params['status'] == 2){
  98. $user->save(['work_authentication'=>0]);
  99. SystemMessages::messages('work_authentication_no',$params['uid'],$params['refuse_cause']);
  100. }
  101. //发送微信模板消息
  102. Apply::wxAuditMessage($params['uid'],3,$params['status']);
  103. Db::commit();
  104. } catch (ValidateException|PDOException|Exception $e) {
  105. Db::rollback();
  106. $this->error($e->getMessage());
  107. }
  108. if (false === $result) {
  109. $this->error(__('No rows were updated'));
  110. }
  111. $this->success();
  112. }
  113. /**
  114. * 默认生成的控制器所继承的父类中有index/add/edit/del/multi五个基础方法、destroy/restore/recyclebin三个回收站方法
  115. * 因此在当前控制器中可不用编写增删改查的代码,除非需要自己控制这部分逻辑
  116. * 需要将application/admin/library/traits/Backend.php中对应的方法复制到当前控制器,然后进行修改
  117. */
  118. }