Admin.php 1.2 KB

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