User.php 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. <?php
  2. namespace App\Http\Models;
  3. use Illuminate\Notifications\Notifiable;
  4. use Illuminate\Foundation\Auth\User as Authenticatable;
  5. /**
  6. * 用户信息
  7. * Class User
  8. *
  9. * @package App\Http\Models
  10. * @property mixed $balance
  11. * @property-read \Illuminate\Database\Eloquent\Collection|\App\Http\Models\UserLabel[] $label
  12. * @property-read \Illuminate\Notifications\DatabaseNotificationCollection|\Illuminate\Notifications\DatabaseNotification[] $notifications
  13. * @property-read \Illuminate\Database\Eloquent\Collection|\App\Http\Models\Payment[] $payment
  14. * @property-read \App\Http\Models\User $referral
  15. * @mixin \Eloquent
  16. */
  17. class User extends Authenticatable
  18. {
  19. use Notifiable;
  20. protected $table = 'user';
  21. protected $primaryKey = 'id';
  22. function levelList()
  23. {
  24. return $this->hasOne(Level::class, 'level', 'level');
  25. }
  26. function payment()
  27. {
  28. return $this->hasMany(Payment::class, 'user_id', 'id');
  29. }
  30. function label()
  31. {
  32. return $this->hasMany(UserLabel::class, 'user_id', 'id');
  33. }
  34. function subscribe()
  35. {
  36. return $this->hasOne(UserSubscribe::class, 'user_id', 'id');
  37. }
  38. function referral()
  39. {
  40. return $this->hasOne(User::class, 'id', 'referral_uid');
  41. }
  42. function getBalanceAttribute($value)
  43. {
  44. return $value / 100;
  45. }
  46. function setBalanceAttribute($value)
  47. {
  48. return $this->attributes['balance'] = $value * 100;
  49. }
  50. }