123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105 |
- <?php
- namespace App\Models;
- use Dcat\Admin\Traits\HasDateTimeFormatter;
- use Illuminate\Database\Eloquent\SoftDeletes;
- use Illuminate\Foundation\Auth\User as Authenticatable;
- use Illuminate\Notifications\Notifiable;
- use PHPOpenSourceSaver\JWTAuth\Contracts\JWTSubject;
- class User extends Authenticatable implements JWTSubject
- {
- use Notifiable,HasDateTimeFormatter;
- // SoftDeletes
- /**
- * The attributes that are mass assignable.
- *
- * @var array
- */
- protected $fillable = [
- 'account',
- 'name',
- 'email',
- 'avatar',
- 'password',
- 'mobile',
- 'status',
- 'online',
- 'lang',
- 'jpush_reg_id',
- 'last_login_ip',
- 'register_ip',
- 'last_login_time',
- 'is_counting',
- 'is_cashier',
- 'member_type',
- 'company_image',
- 'company_card_color',
- 'company_name',
- 'production_project',
- 'company_url',
- 'company_phone',
- 'other_contacts',
- 'start_time',
- 'end_time',
- 'member_type',
- 'nickname',
- 'introduce',
- 'follow_count',
- ];
- public function memberStatus(){
- return [1 => '一般会员', 2 => '企业会员'];
- }
- protected $appends =[
- 'member_type_text',
- ];
- public function getMemberTypeTextAttribute()
- {
- $list = $this->memberStatus();
- if(empty($this->attributes['member_type'])){
- return null;
- }
- return isset($list[$this->attributes['member_type']]) ? $list[$this->attributes['member_type']] : '';
- }
- //protected $guarded = [];
- /**
- * The attributes that should be hidden for arrays.
- *
- * @var array
- */
- // protected $hidden = [
- // 'password',
- // 'remember_token',
- // ];
- public function getJWTIdentifier()
- {
- return $this->getKey(); // TODO: Implement getJWTIdentifier() method.
- }
- public function getJWTCustomClaims()
- {
- return [
- 'role' => 'user'
- ]; // TODO: Implement getJWTCustomClaims() method.
- }
- /**
- * 设置密码加密
- * @param $value
- * @return string
- */
- public function setPasswordAttribute($value)
- {
- $this->attributes['password'] = bcrypt($value);
- }
- public function member(){
- return $this->hasOne(UserMember::class,'id','member_id');
- }
- }
|