User.php 737 B

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. <?php
  2. namespace App\Http\Models;
  3. use Illuminate\Database\Eloquent\Model;
  4. /**
  5. * 用户信息
  6. * Class User
  7. *
  8. * @package App\Http\Models
  9. */
  10. class User extends Model
  11. {
  12. protected $table = 'user';
  13. protected $primaryKey = 'id';
  14. function payment()
  15. {
  16. return $this->hasMany(Payment::class, 'user_id', 'id');
  17. }
  18. function label()
  19. {
  20. return $this->hasMany(UserLabel::class, 'user_id', 'id');
  21. }
  22. function referral()
  23. {
  24. return $this->hasOne(User::class, 'id', 'referral_uid');
  25. }
  26. function getBalanceAttribute($value)
  27. {
  28. return $value / 100;
  29. }
  30. function setBalanceAttribute($value)
  31. {
  32. return $this->attributes['balance'] = $value * 100;
  33. }
  34. }