User.php 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. <?php
  2. namespace App\Models;
  3. use Dcat\Admin\Traits\HasDateTimeFormatter;
  4. use Illuminate\Database\Eloquent\SoftDeletes;
  5. use Illuminate\Foundation\Auth\User as Authenticatable;
  6. use Illuminate\Notifications\Notifiable;
  7. use PHPOpenSourceSaver\JWTAuth\Contracts\JWTSubject;
  8. class User extends Authenticatable implements JWTSubject
  9. {
  10. use Notifiable,HasDateTimeFormatter;
  11. // SoftDeletes
  12. /**
  13. * The attributes that are mass assignable.
  14. *
  15. * @var array
  16. */
  17. protected $fillable = [
  18. 'account',
  19. 'name',
  20. 'email',
  21. 'avatar',
  22. 'password',
  23. 'mobile',
  24. 'status',
  25. 'online',
  26. 'lang',
  27. 'jpush_reg_id',
  28. 'last_login_ip',
  29. 'register_ip',
  30. 'last_login_time',
  31. 'is_counting',
  32. 'is_cashier',
  33. 'member_type',
  34. 'company_image',
  35. 'company_card_color',
  36. 'company_name',
  37. 'production_project',
  38. 'company_url',
  39. 'company_phone',
  40. 'other_contacts',
  41. 'start_time',
  42. 'end_time',
  43. 'member_type',
  44. 'nickname',
  45. 'introduce',
  46. 'follow_count',
  47. ];
  48. public function memberStatus(){
  49. return [1 => '一般会员', 2 => '企业会员'];
  50. }
  51. protected $appends =[
  52. 'member_type_text',
  53. ];
  54. public function getMemberTypeTextAttribute()
  55. {
  56. $list = $this->memberStatus();
  57. if(empty($this->attributes['member_type'])){
  58. return null;
  59. }
  60. return isset($list[$this->attributes['member_type']]) ? $list[$this->attributes['member_type']] : '';
  61. }
  62. //protected $guarded = [];
  63. /**
  64. * The attributes that should be hidden for arrays.
  65. *
  66. * @var array
  67. */
  68. // protected $hidden = [
  69. // 'password',
  70. // 'remember_token',
  71. // ];
  72. public function getJWTIdentifier()
  73. {
  74. return $this->getKey(); // TODO: Implement getJWTIdentifier() method.
  75. }
  76. public function getJWTCustomClaims()
  77. {
  78. return [
  79. 'role' => 'user'
  80. ]; // TODO: Implement getJWTCustomClaims() method.
  81. }
  82. /**
  83. * 设置密码加密
  84. * @param $value
  85. * @return string
  86. */
  87. public function setPasswordAttribute($value)
  88. {
  89. $this->attributes['password'] = bcrypt($value);
  90. }
  91. public function member(){
  92. return $this->hasOne(UserMember::class,'id','member_id');
  93. }
  94. }