UserInfoModel.php 4.0 KB

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