UserInfoModel.php 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  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. 'add_fens_number',
  55. 'jpush',
  56. ];
  57. protected $hidden = ['password'];
  58. public function UserCareUser()
  59. {
  60. return $this->belongsToMany('App\Models\UserInfoModel','user_care_user','user_id','other_user_id');
  61. }
  62. public function UserCareMe()
  63. {
  64. return $this->belongsToMany('App\Models\UserInfoModel','user_care_user','other_user_id','user_id');
  65. }
  66. public function UserCareDream()
  67. {
  68. return $this->belongsToMany('App\Models\DreamInfoModel','user_care_dream','user_id','dream_id')->with(['user'])->withPivot('interaction_number','dream_user_id')->orderBy('updated_at');
  69. }
  70. // 系统消息
  71. public function systemInfo()
  72. {
  73. return $this->hasMany('App\Models\SystemInfoModel','user_id','id');
  74. }
  75. //用户梦想
  76. public function dreams()
  77. {
  78. return $this->hasMany('App\Models\DreamInfoModel','user_id','id');
  79. }
  80. //支持的梦想
  81. public function supDream()
  82. {
  83. return $this->belongsToMany('App\Models\DreamInfoModel','support_dream','user_id','dream_id');
  84. }
  85. //评论的梦想
  86. public function comDream()
  87. {
  88. return $this->belongsToMany('App\Models\DreamInfoModel','comments_info','user_id','dream_id')->withPivot('content', 'level','created_at');
  89. }
  90. //收藏的梦想
  91. public function careDreams()
  92. {
  93. return $this->belongsToMany('App\Models\DreamInfoModel','user_care_dream','user_id','dream_id');
  94. }
  95. //关注我的用户
  96. public function fens()
  97. {
  98. return $this->hasMany('App\Models\UserCareUser','other_user_id','id');
  99. }
  100. // 我的收藏
  101. public function collection()
  102. {
  103. return $this->belongsToMany('App\Models\DreamInfoModel','user_care_dream','user_id','dream_id')->withPivot('interaction_number','dream_user_id');
  104. }
  105. // 回复的梦想
  106. public function replyDream()
  107. {
  108. return $this->belongsToMany('App\Models\CommentInfoModel','reply_comments_info','user_id','comment_id')->withPivot('content', 'level','created_at');
  109. }
  110. // 搜索
  111. public function search()
  112. {
  113. return $this->hasMany('App\Models\SearchInfoModel','user_id','id');
  114. }
  115. // 获取所有梦想的图片
  116. public function allImgs()
  117. {
  118. return $this->hasManyThrough('App\Models\DreamImages', 'App\Models\DreamInfoModel','user_id','dream_id');
  119. }
  120. // 获取所有梦想的互动
  121. public function allInteraction()
  122. {
  123. return $this->hasManyThrough('App\Models\InteractionInfo', 'App\Models\DreamInfoModel','user_id','dream_id');
  124. }
  125. // 我的银行卡
  126. public function bank()
  127. {
  128. return $this->hasMany('App\Models\UserBank','user_id','id');
  129. }
  130. }