Agent.php 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  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. public const LEVEL_ONE = 1;
  10. public const TYPE_JOINT = 1;
  11. public const TYPE_EQUITY = 2;
  12. public const TYPE_NAMES = [self::TYPE_JOINT => '合营', self::TYPE_EQUITY => '入股'];
  13. protected $table = 'agents';
  14. protected $fillable = [
  15. 'parent_id', 'path', 'level', 'username', 'password', 'withdraw_password',
  16. 'real_name', 'language', 'invitation_code', 'balance', 'frozen_balance',
  17. 'deposit_fee_rate', 'withdraw_fee_rate',
  18. 'profit_commission_rate', 'status', 'last_login_at', 'last_login_ip', 'created_by',
  19. 'profit_commission_profile_id', 'type',
  20. ];
  21. // realtime_balance 是系统内部的实时保证金依据,不对代理端返回。
  22. protected $hidden = ['password', 'withdraw_password', 'realtime_balance'];
  23. protected $appends = ['type_text'];
  24. protected $casts = [
  25. 'owner_user_id' => 'integer',
  26. 'parent_id' => 'integer', 'level' => 'integer', 'status' => 'integer', 'type' => 'integer',
  27. 'balance' => 'decimal:4', 'frozen_balance' => 'decimal:4',
  28. 'margin_amount' => 'decimal:4', 'realtime_balance' => 'decimal:4',
  29. 'profit_active' => 'integer', 'profit_active_changed_at' => 'datetime',
  30. 'equity_percent' => 'decimal:4',
  31. 'deposit_fee_rate' => 'decimal:4', 'withdraw_fee_rate' => 'decimal:4',
  32. 'profit_commission_rate' => 'decimal:4',
  33. 'last_login_at' => 'datetime',
  34. 'profit_commission_profile_id' => 'integer',
  35. ];
  36. public function domains()
  37. {
  38. return $this->hasMany(AgentDomain::class);
  39. }
  40. public function token()
  41. {
  42. return $this->hasOne(AgentToken::class);
  43. }
  44. public function members()
  45. {
  46. return $this->hasMany(User::class, 'agent_id');
  47. }
  48. public function profitCommissionProfile()
  49. {
  50. return $this->belongsTo(AgentProfitCommissionProfile::class, 'profit_commission_profile_id');
  51. }
  52. public function profitCommissionAssignments()
  53. {
  54. return $this->hasMany(AgentProfitCommissionAssignment::class);
  55. }
  56. public function isJoint(): bool
  57. {
  58. return (int) $this->type === self::TYPE_JOINT;
  59. }
  60. public function isEquity(): bool
  61. {
  62. return (int) $this->type === self::TYPE_EQUITY;
  63. }
  64. public function getTypeTextAttribute(): string
  65. {
  66. return self::TYPE_NAMES[(int) ($this->type ?: self::TYPE_JOINT)] ?? '';
  67. }
  68. }