Agent.php 2.6 KB

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