Admin.php 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. <?php
  2. namespace app\controller;
  3. use app\BaseController;
  4. use app\model\UserModel;
  5. use GuzzleHttp\Exception\GuzzleException;
  6. use think\facade\Log;
  7. class Admin extends BaseController
  8. {
  9. public function UserList(): \think\response\Json
  10. {
  11. $this->getAdmin();
  12. $limit = $this->request->all('limit', 50);
  13. $search = $this->request->post('search');
  14. $sql = [];
  15. if (isset($search['mail']) && mb_strlen($search['mail']) > 0) {
  16. $sql['mail'] = $search['mail'];
  17. }
  18. $user = UserModel::where($sql)->withoutField('password')->order("id", 'desc')->paginate($limit);
  19. return $this->success('ok', $user);
  20. }
  21. function userUpdate(): \think\response\Json
  22. {
  23. $this->getAdmin();
  24. $id = $this->request->post('id');
  25. $user = UserModel::where('id', $id)->find();
  26. $data = $this->request->post();
  27. if (!$user) {
  28. return $this->error('用户不存在');
  29. }
  30. //如果字段中的password有内容则md5加密后保存
  31. if (isset($data['password']) && mb_strlen($data['password']) > 0) {
  32. $data['password'] = md5($data['password']);
  33. }
  34. $user->save($data);
  35. return $this->success('ok');
  36. }
  37. }