MemberUser.php 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. <?php
  2. namespace App\Models;
  3. use Illuminate\Database\Eloquent\Relations\HasMany;
  4. use Illuminate\Database\Eloquent\SoftDeletes;
  5. use Illuminate\Foundation\Auth\User as Authenticatable;
  6. use Laravel\Sanctum\HasApiTokens;
  7. class MemberUser extends Authenticatable
  8. {
  9. use HasApiTokens, SoftDeletes;
  10. protected $guarded = [];
  11. /**
  12. * 隐藏字段
  13. *
  14. * @var array
  15. */
  16. protected $hidden = [
  17. 'password',
  18. ];
  19. /**
  20. * 创建用户时创建钱包
  21. *
  22. * @return void
  23. */
  24. protected static function booted()
  25. {
  26. static::created(function ($user) {
  27. $user->wallet()->create([
  28. 'owner_type' => MemberUser::class,
  29. 'owner_id' => $user->id,
  30. ]);
  31. });
  32. }
  33. /**
  34. * 获取用户的默认地址
  35. */
  36. public function address()
  37. {
  38. return $this->hasOne(MemberAddress::class, 'user_id', 'id')->where('is_default', 1);
  39. }
  40. /**
  41. * @Author FelixYin
  42. * @description 用户关联地址
  43. */
  44. public function addresses()
  45. {
  46. return $this->hasMany('App\Models\MemberAddress', 'user_id', 'id');
  47. }
  48. /**
  49. * @Author FelixYin
  50. * @description 用户关联订单
  51. */
  52. public function orders()
  53. {
  54. return $this->hasMany('App\Models\Order', 'user_id', 'id');
  55. }
  56. /**
  57. * @Author FelixYin
  58. * @description 用户关联社交账户
  59. */
  60. public function socialAccounts()
  61. {
  62. return $this->hasMany('App\Models\MemberSocialAccount', 'user_id', 'id');
  63. }
  64. /**
  65. * @Author FelixYin
  66. * @description 用户关联技师身份
  67. */
  68. public function coach()
  69. {
  70. return $this->hasOne('App\Models\CoachUser', 'user_id', 'id');
  71. }
  72. /**
  73. * @Author FelixYin
  74. * @description 用户关联评论
  75. */
  76. public function comments()
  77. {
  78. return $this->hasMany('App\Models\OrderComment', 'user_id', 'id');
  79. }
  80. /**
  81. * @Author FelixYin
  82. * @description 用户关联钱包
  83. */
  84. public function wallet()
  85. {
  86. return $this->MORPH_ONE('App\Models\Wallet', 'undefined', 'id');
  87. }
  88. /**
  89. * @Author FelixYin
  90. * @description 用户关联店铺身份
  91. */
  92. public function shop()
  93. {
  94. return $this->hasOne('App\Models\ShopInfo', 'user_id', 'id');
  95. }
  96. /**
  97. * @Author FelixYin
  98. * @description 用户关联代理商身份
  99. */
  100. public function agent()
  101. {
  102. return $this->hasOne('App\Models\AgentInfo', 'user_id', 'id');
  103. }
  104. /**
  105. * @Author FelixYin
  106. * @description 会员所属行政区划
  107. */
  108. public function region()
  109. {
  110. return $this->belongsTo('App\Models\SysRegion', 'register_area');
  111. }
  112. /**
  113. * @Author FelixYin
  114. * @description 用户邀请人
  115. */
  116. public function Inviter()
  117. {
  118. return $this->hasOne('App\Models\MarketDistTeam', 'user_id', 'id');
  119. }
  120. /**
  121. * @Author FelixYin
  122. * @description 用户关联团队
  123. */
  124. public function teams()
  125. {
  126. return $this->MORPH_MANY('App\Models\MarketDistTeam', 'undefined', 'id');
  127. }
  128. }