Agent.php 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. <?php
  2. namespace App\Models\Agent;
  3. use App\Models\BaseModel;
  4. use App\Models\User;
  5. class Agent extends BaseModel
  6. {
  7. public const STATUS_DISABLED = 0;
  8. public const STATUS_ENABLED = 1;
  9. protected $table = 'agents';
  10. protected $fillable = [
  11. 'parent_id', 'path', 'level', 'username', 'password', 'withdraw_password',
  12. 'real_name', 'invitation_code', 'balance', 'frozen_balance',
  13. 'deposit_fee_rate', 'withdraw_fee_rate', 'flow_commission_rate',
  14. 'profit_commission_rate', 'status', 'last_login_at', 'last_login_ip', 'created_by',
  15. ];
  16. protected $hidden = ['password', 'withdraw_password'];
  17. protected $casts = [
  18. 'parent_id' => 'integer', 'level' => 'integer', 'status' => 'integer',
  19. 'balance' => 'decimal:4', 'frozen_balance' => 'decimal:4',
  20. 'deposit_fee_rate' => 'decimal:4', 'withdraw_fee_rate' => 'decimal:4',
  21. 'flow_commission_rate' => 'decimal:4', 'profit_commission_rate' => 'decimal:4',
  22. 'last_login_at' => 'datetime',
  23. ];
  24. public function parent()
  25. {
  26. return $this->belongsTo(self::class, 'parent_id');
  27. }
  28. public function domains()
  29. {
  30. return $this->hasMany(AgentDomain::class);
  31. }
  32. public function token()
  33. {
  34. return $this->hasOne(AgentToken::class);
  35. }
  36. public function children()
  37. {
  38. return $this->hasMany(self::class, 'parent_id');
  39. }
  40. public function members()
  41. {
  42. return $this->hasMany(User::class, 'agent_id');
  43. }
  44. }