123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146 |
- <?php
- namespace App\Models;
- use Illuminate\Database\Eloquent\Relations\HasMany;
- use Illuminate\Database\Eloquent\SoftDeletes;
- use Illuminate\Foundation\Auth\User as Authenticatable;
- use Laravel\Sanctum\HasApiTokens;
- class MemberUser extends Authenticatable
- {
- use HasApiTokens, SoftDeletes;
- protected $guarded = [];
- /**
- * 隐藏字段
- *
- * @var array
- */
- protected $hidden = [
- 'password',
- ];
- /**
- * 创建用户时创建钱包
- *
- * @return void
- */
- protected static function booted()
- {
- static::created(function ($user) {
- $user->wallet()->create([
- 'owner_type' => MemberUser::class,
- 'owner_id' => $user->id,
- ]);
- });
- }
- /**
- * 获取用户的默认地址
- */
- public function address()
- {
- return $this->hasOne(MemberAddress::class, 'user_id', 'id')->where('is_default', 1);
- }
- /**
- * @Author FelixYin
- * @description 用户关联地址
- */
- public function addresses()
- {
- return $this->hasMany('App\Models\MemberAddress', 'user_id', 'id');
- }
- /**
- * @Author FelixYin
- * @description 用户关联订单
- */
- public function orders()
- {
- return $this->hasMany('App\Models\Order', 'user_id', 'id');
- }
- /**
- * @Author FelixYin
- * @description 用户关联社交账户
- */
- public function socialAccounts()
- {
- return $this->hasMany('App\Models\MemberSocialAccount', 'user_id', 'id');
- }
- /**
- * @Author FelixYin
- * @description 用户关联技师身份
- */
- public function coach()
- {
- return $this->hasOne('App\Models\CoachUser', 'user_id', 'id');
- }
- /**
- * @Author FelixYin
- * @description 用户关联评论
- */
- public function comments()
- {
- return $this->hasMany('App\Models\OrderComment', 'user_id', 'id');
- }
- /**
- * @Author FelixYin
- * @description 用户关联钱包
- */
- public function wallet()
- {
- return $this->MORPH_ONE('App\Models\Wallet', 'undefined', 'id');
- }
- /**
- * @Author FelixYin
- * @description 用户关联店铺身份
- */
- public function shop()
- {
- return $this->hasOne('App\Models\ShopInfo', 'user_id', 'id');
- }
- /**
- * @Author FelixYin
- * @description 用户关联代理商身份
- */
- public function agent()
- {
- return $this->hasOne('App\Models\AgentInfo', 'user_id', 'id');
- }
- /**
- * @Author FelixYin
- * @description 会员所属行政区划
- */
- public function region()
- {
- return $this->belongsTo('App\Models\SysRegion', 'register_area');
- }
- /**
- * @Author FelixYin
- * @description 用户邀请人
- */
- public function Inviter()
- {
- return $this->hasOne('App\Models\MarketDistTeam', 'user_id', 'id');
- }
- /**
- * @Author FelixYin
- * @description 用户关联团队
- */
- public function teams()
- {
- return $this->MORPH_MANY('App\Models\MarketDistTeam', 'undefined', 'id');
- }
- }
|