UserService.php 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. <?php
  2. namespace app\service;
  3. use app\model\User;
  4. use think\db\exception\DataNotFoundException;
  5. use think\db\exception\DbException;
  6. use think\db\exception\ModelNotFoundException;
  7. use think\Model;
  8. class UserService
  9. {
  10. public static function selectLoginInfo($loginInfo){
  11. $map[] = ["username","=",$loginInfo["username"]];
  12. $map[] = ["password","=",$loginInfo["password"]];
  13. return (new User)->where($map)->field("id,username,xzqdm,level,name")->find();
  14. }
  15. /**
  16. * @throws ModelNotFoundException
  17. * @throws DataNotFoundException
  18. * @throws DbException
  19. */
  20. public static function getUserInfoById($id){
  21. return (new \app\model\User)->field("username,xzqdm,level,name")->find($id);
  22. }
  23. public static function getGridPersonInfoById($id){
  24. return User::field("name,xzqdm,level,work_organization, phone, work_position, person_group, person_duty, person_image,id")->find($id);
  25. }
  26. public static function editPasswordById($id,$password): User
  27. {
  28. return User::update(["password"=>$password],["id"=>$id]);
  29. }
  30. public static function editUserInfoById($id,$userInfo): User
  31. {
  32. return User::update($userInfo,["id"=>$id]);
  33. }
  34. public static function saveUserInfo($userInfo): User{
  35. return User::create($userInfo);
  36. }
  37. public static function deleteUserInfoById($id): bool{return User::destroy($id);}
  38. /**
  39. * @throws ModelNotFoundException
  40. * @throws DbException
  41. * @throws DataNotFoundException
  42. */
  43. public static function getUserInfoList($page, $xzqdm){
  44. switch (strlen($xzqdm) ){
  45. case 4:
  46. $map[]=["xzqdm","like",'%'.$xzqdm.'%'];
  47. break;
  48. case 6:
  49. $map[] = ["xzqdm","like",'%'.$xzqdm.'%'];
  50. break;
  51. case 9:
  52. $map[] = ["xzqdm","like",'%'.$xzqdm.'%'];
  53. break;
  54. default:
  55. $map[]=["xzqdm","<>",'null'];
  56. }
  57. $map[]=["work_position","=","网格员"];
  58. return (new User)->where($map)->page($page["page"],$page["size"])->select();
  59. }
  60. }