UserInfoModel.php 4.1 KB

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