User.php 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. <?php
  2. namespace App\Models;
  3. use Illuminate\Contracts\Auth\MustVerifyEmail;
  4. use Illuminate\Database\Eloquent\Factories\HasFactory;
  5. use Illuminate\Database\Eloquent\SoftDeletes;
  6. use Illuminate\Foundation\Auth\User as Authenticatable;
  7. use Illuminate\Notifications\Notifiable;
  8. use Laravel\Sanctum\HasApiTokens;
  9. use Tymon\JWTAuth\Contracts\JWTSubject;
  10. use DateTimeInterface;
  11. class User extends Authenticatable implements JWTSubject
  12. {
  13. use HasApiTokens, HasFactory, Notifiable ,SoftDeletes;
  14. /**
  15. * The attributes that are mass assignable.
  16. *
  17. * @var array<int, string>
  18. */
  19. protected $fillable = [
  20. ];
  21. public function getJWTIdentifier()
  22. {
  23. return $this->getKey();
  24. }
  25. public function getJWTCustomClaims()
  26. {
  27. return [];
  28. }
  29. /**
  30. * The attributes that should be hidden for serialization.
  31. *
  32. * @var array<int, string>
  33. */
  34. protected $hidden = [
  35. 'password',
  36. ];
  37. protected function serializeDate(DateTimeInterface $date)
  38. {
  39. return $date->format('Y-m-d H:i:s');
  40. }
  41. /**
  42. * The attributes that should be cast.
  43. *
  44. * @var array<string, string>
  45. */
  46. protected function Register($data){
  47. $user=new User();
  48. $user->mobile=$data['mobile'];
  49. $user->password=sha1($data['password']);
  50. $user->person_num='zjb-'.time().rand(1111,9999);
  51. $user->save();
  52. return $user;
  53. }
  54. /**
  55. * 后台
  56. * 后台后台
  57. *后台后台
  58. * 后台后台
  59. *后台后台后台
  60. *后台后台
  61. *后台后台
  62. *后台后台
  63. ****************/
  64. //获取用户信息
  65. protected function UserInfo($data){
  66. $query=User::query();
  67. $page_size=$data['page_size'];
  68. $page_index=$data['page_index'];
  69. $num=($page_index-1)*$page_size;
  70. if ($data['search_name']){
  71. $search_name=$data['search_name'];
  72. $query->where('mobile','like',"%$search_name%")
  73. ->orWhere('nickname','like',"%$search_name%");
  74. }
  75. $count=$query->count();
  76. $list=$query->take($page_size)->skip($num)->get();
  77. return ['list'=>$list,'total'=>$count];
  78. }
  79. /**
  80. * 后台
  81. * 后台后台
  82. *后台后台
  83. ****************/
  84. //修改用户信息
  85. protected function UpdateUserInfo($data){
  86. $id=$data['id'];
  87. unset($data['id']);
  88. User::where('id',$id)->update($data);
  89. }
  90. //删除用户信息
  91. protected function DeleteUserInfo($id){
  92. User::where('id',$id)->delete();
  93. }
  94. }