UserInfoModel.php 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. <?php
  2. namespace App\Models;
  3. use App\Models\BaseModel;
  4. use Illuminate\Foundation\Auth\User as Authenticatable;
  5. use Laravel\Passport\HasApiTokens;
  6. use Illuminate\Notifications\Notifiable;
  7. /**
  8. * @description 用户表
  9. * @author system;
  10. * @version 1.0
  11. * @date 2017-05-30 12:16:56
  12. *
  13. */
  14. class UserInfoModel extends Authenticatable
  15. {
  16. use HasApiTokens, Notifiable;
  17. /**
  18. * 数据表名
  19. *
  20. * @var string
  21. *
  22. */
  23. protected $table = 'user_info';
  24. /**
  25. 主键
  26. */
  27. protected $primaryKey = 'id';
  28. //分页
  29. protected $perPage = PAGE_NUMS;
  30. /**
  31. * 可以被集体附值的表的字段
  32. *
  33. * @var string
  34. */
  35. protected $fillable = [
  36. 'phone',
  37. 'password',
  38. 'nickname',
  39. 'sign',
  40. 'avatar',
  41. 'money',
  42. 'coin',
  43. 'sex',
  44. 'city',
  45. 'signture',
  46. 'height',
  47. 'work',
  48. 'emotion',
  49. 'address',
  50. 'detail_address',
  51. 'status',
  52. 'remember_token',
  53. 'birthday',
  54. ];
  55. protected $hidden = ['password'];
  56. public function UserCareUser()
  57. {
  58. return $this->belongsToMany('App\Models\UserInfoModel','user_care_user','user_id','other_user_id');
  59. }
  60. public function UserCareDream()
  61. {
  62. return $this->belongsToMany('App\Models\DreamInfoModel','user_care_dream','user_id','dream_id')->with(['user'])->withPivot('interaction_number','dream_user_id')->orderBy('updated_at');
  63. }
  64. // 系统消息
  65. public function systemInfo()
  66. {
  67. return $this->hasMany('App\Models\SystemInfoModel','user_id','id');
  68. }
  69. //用户梦想
  70. public function dreams()
  71. {
  72. return $this->hasMany('App\Models\DreamInfoModel','user_id','id');
  73. }
  74. //支持的梦想
  75. public function supDream()
  76. {
  77. return $this->belongsToMany('App\Models\DreamInfoModel','support_dream','user_id','dream_id');
  78. }
  79. //评论的梦想
  80. public function comDream()
  81. {
  82. return $this->belongsToMany('App\Models\DreamInfoModel','comments_info','user_id','dream_id')->withPivot('content', 'level','created_at');
  83. }
  84. //收藏的梦想
  85. public function careDreams()
  86. {
  87. return $this->belongsToMany('App\Models\DreamInfoModel','user_care_dream','user_id','dream_id');
  88. }
  89. //关注我的用户
  90. public function fens()
  91. {
  92. return $this->hasMany('App\Models\UserCareUser','other_user_id','id');
  93. }
  94. // 我的收藏
  95. public function collection()
  96. {
  97. return $this->belongsToMany('App\Models\DreamInfoModel','user_care_dream','user_id','dream_id')->withPivot('interaction_number','dream_user_id');
  98. }
  99. // 回复的梦想
  100. public function replyDream()
  101. {
  102. return $this->belongsToMany('App\Models\CommentInfoModel','reply_comments_info','user_id','comment_id')->withPivot('content', 'level','created_at');
  103. }
  104. // 搜索
  105. public function search()
  106. {
  107. return $this->hasMany('App\Models\SearchInfoModel','user_id','id');
  108. }
  109. // 获取所有梦想的图片
  110. public function allImgs()
  111. {
  112. return $this->hasManyThrough('App\Models\DreamImages', 'App\Models\DreamInfoModel','user_id','dream_id');
  113. }
  114. // 获取所有梦想的互动
  115. public function allInteraction()
  116. {
  117. return $this->hasManyThrough('App\Models\InteractionInfo', 'App\Models\DreamInfoModel','user_id','dream_id');
  118. }
  119. // 我的银行卡
  120. public function bank()
  121. {
  122. return $this->hasMany('App\Models\UserBank','user_id','id');
  123. }
  124. }