Admin.php 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  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. is_demo_mode(true);
  23. $id = $this->request->post('id');
  24. $user = UserModel::where('id', $id)->find();
  25. $data = $this->request->post();
  26. if (!$user) {
  27. return $this->error('用户不存在');
  28. }
  29. //如果字段中的password有内容则md5加密后保存
  30. if (isset($data['password']) && mb_strlen($data['password']) > 0) {
  31. $data['password'] = md5($data['password']);
  32. } else {
  33. unset($data['password']);
  34. }
  35. $user->save($data);
  36. return $this->success('修改成功');
  37. }
  38. }