User.php 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. <?php
  2. namespace App\Http\Models;
  3. use Auth;
  4. use Eloquent;
  5. use Illuminate\Database\Eloquent\Builder;
  6. use Illuminate\Database\Eloquent\Collection;
  7. use Illuminate\Foundation\Auth\User as Authenticatable;
  8. use Illuminate\Notifications\DatabaseNotification;
  9. use Illuminate\Notifications\DatabaseNotificationCollection;
  10. use Illuminate\Notifications\Notifiable;
  11. use Illuminate\Support\Carbon;
  12. /**
  13. * 用户信息
  14. *
  15. * @property int $id
  16. * @property string $username 昵称
  17. * @property string $email 邮箱
  18. * @property string $password 密码
  19. * @property int $port 代理端口
  20. * @property string $passwd SS密码
  21. * @property string $uuid
  22. * @property int $transfer_enable 可用流量,单位字节,默认1TiB
  23. * @property int $u 已上传流量,单位字节
  24. * @property int $d 已下载流量,单位字节
  25. * @property int $t 最后使用时间
  26. * @property string|null $ip 最后连接IP
  27. * @property int $enable SS状态
  28. * @property string $method 加密方式
  29. * @property string $protocol 协议
  30. * @property string $obfs 混淆
  31. * @property string|null $obfs_param 混淆参数
  32. * @property int $speed_limit 用户限速,为0表示不限速,单位Byte
  33. * @property string|null $wechat 微信
  34. * @property string|null $qq QQ
  35. * @property int $usage 用途:1-手机、2-电脑、3-路由器、4-其他
  36. * @property int $pay_way 付费方式:0-免费、1-季付、2-月付、3-半年付、4-年付
  37. * @property int $credit 余额,单位分
  38. * @property string|null $enable_time 开通日期
  39. * @property string $expire_time 过期时间
  40. * @property int $ban_time 封禁到期时间
  41. * @property string|null $remark 备注
  42. * @property int|null $group_id 所属分组ID
  43. * @property int $level 等级,默认0级,最高9级
  44. * @property int $is_admin 是否管理员:0-否、1-是
  45. * @property string $reg_ip 注册IP
  46. * @property int $last_login 最后登录时间
  47. * @property int $referral_uid 邀请人
  48. * @property string|null $reset_time 流量重置日期,NULL表示不重置
  49. * @property int $invite_num 可生成邀请码数
  50. * @property int $status 状态:-1-禁用、0-未激活、1-正常
  51. * @property string|null $remember_token
  52. * @property Carbon|null $created_at
  53. * @property Carbon|null $updated_at
  54. * @property mixed $balance
  55. * @property-read Collection|UserLabel[] $label
  56. * @property-read int|null $label_count
  57. * @property-read Level|null $levelList
  58. * @property-read DatabaseNotificationCollection|DatabaseNotification[] $notifications
  59. * @property-read int|null $notifications_count
  60. * @property-read Collection|Payment[] $payment
  61. * @property-read int|null $payment_count
  62. * @property-read User|null $referral
  63. * @property-read UserSubscribe|null $subscribe
  64. * @method static Builder|User newModelQuery()
  65. * @method static Builder|User newQuery()
  66. * @method static Builder|User query()
  67. * @method static Builder|User uid()
  68. * @method static Builder|User whereBanTime($value)
  69. * @method static Builder|User whereCreatedAt($value)
  70. * @method static Builder|User whereCredit($value)
  71. * @method static Builder|User whereD($value)
  72. * @method static Builder|User whereEmail($value)
  73. * @method static Builder|User whereEnable($value)
  74. * @method static Builder|User whereEnableTime($value)
  75. * @method static Builder|User whereExpireTime($value)
  76. * @method static Builder|User whereGroupId($value)
  77. * @method static Builder|User whereId($value)
  78. * @method static Builder|User whereInviteNum($value)
  79. * @method static Builder|User whereIp($value)
  80. * @method static Builder|User whereIsAdmin($value)
  81. * @method static Builder|User whereLastLogin($value)
  82. * @method static Builder|User whereLevel($value)
  83. * @method static Builder|User whereMethod($value)
  84. * @method static Builder|User whereObfs($value)
  85. * @method static Builder|User whereObfsParam($value)
  86. * @method static Builder|User wherePasswd($value)
  87. * @method static Builder|User wherePassword($value)
  88. * @method static Builder|User wherePayWay($value)
  89. * @method static Builder|User wherePort($value)
  90. * @method static Builder|User whereProtocol($value)
  91. * @method static Builder|User whereQq($value)
  92. * @method static Builder|User whereReferralUid($value)
  93. * @method static Builder|User whereRegIp($value)
  94. * @method static Builder|User whereRemark($value)
  95. * @method static Builder|User whereRememberToken($value)
  96. * @method static Builder|User whereResetTime($value)
  97. * @method static Builder|User whereSpeedLimit($value)
  98. * @method static Builder|User whereStatus($value)
  99. * @method static Builder|User whereT($value)
  100. * @method static Builder|User whereTransferEnable($value)
  101. * @method static Builder|User whereU($value)
  102. * @method static Builder|User whereUpdatedAt($value)
  103. * @method static Builder|User whereUsage($value)
  104. * @method static Builder|User whereUsername($value)
  105. * @method static Builder|User whereUuid($value)
  106. * @method static Builder|User whereWechat($value)
  107. * @mixin Eloquent
  108. */
  109. class User extends Authenticatable {
  110. use Notifiable;
  111. protected $table = 'user';
  112. protected $primaryKey = 'id';
  113. function scopeUid($query) {
  114. return $query->whereId(Auth::user()->id);
  115. }
  116. function levelList() {
  117. return $this->hasOne(Level::class, 'level', 'level');
  118. }
  119. function payment() {
  120. return $this->hasMany(Payment::class, 'user_id', 'id');
  121. }
  122. function label() {
  123. return $this->hasMany(UserLabel::class, 'user_id', 'id');
  124. }
  125. function subscribe() {
  126. return $this->hasOne(UserSubscribe::class, 'user_id', 'id');
  127. }
  128. function referral() {
  129. return $this->hasOne(User::class, 'id', 'referral_uid');
  130. }
  131. function getBalanceAttribute($value) {
  132. return $value / 100;
  133. }
  134. function setBalanceAttribute($value) {
  135. return $this->attributes['balance'] = $value * 100;
  136. }
  137. }