| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081 |
- <?php
- namespace App\Models\Agent;
- use App\Models\BaseModel;
- use App\Models\User;
- class Agent extends BaseModel
- {
- public const STATUS_DISABLED = 0;
- public const STATUS_ENABLED = 1;
- public const LEVEL_ONE = 1;
- public const TYPE_JOINT = 1;
- public const TYPE_EQUITY = 2;
- public const TYPE_NAMES = [self::TYPE_JOINT => '合营', self::TYPE_EQUITY => '入股'];
- protected $table = 'agents';
- protected $fillable = [
- 'parent_id', 'path', 'level', 'username', 'password', 'withdraw_password',
- 'real_name', 'language', 'invitation_code', 'balance', 'frozen_balance',
- 'deposit_fee_rate', 'withdraw_fee_rate',
- 'profit_commission_rate', 'status', 'last_login_at', 'last_login_ip', 'created_by',
- 'profit_commission_profile_id', 'type',
- ];
- // realtime_balance 是系统内部的实时保证金依据,不对代理端返回。
- protected $hidden = ['password', 'withdraw_password', 'realtime_balance'];
- protected $appends = ['type_text'];
- protected $casts = [
- 'owner_user_id' => 'integer',
- 'parent_id' => 'integer', 'level' => 'integer', 'status' => 'integer', 'type' => 'integer',
- 'balance' => 'decimal:4', 'frozen_balance' => 'decimal:4',
- 'margin_amount' => 'decimal:4', 'realtime_balance' => 'decimal:4',
- 'profit_active' => 'integer', 'profit_active_changed_at' => 'datetime',
- 'equity_percent' => 'decimal:4',
- 'deposit_fee_rate' => 'decimal:4', 'withdraw_fee_rate' => 'decimal:4',
- 'profit_commission_rate' => 'decimal:4',
- 'last_login_at' => 'datetime',
- 'profit_commission_profile_id' => 'integer',
- ];
- public function domains()
- {
- return $this->hasMany(AgentDomain::class);
- }
- public function token()
- {
- return $this->hasOne(AgentToken::class);
- }
- public function members()
- {
- return $this->hasMany(User::class, 'agent_id');
- }
- public function profitCommissionProfile()
- {
- return $this->belongsTo(AgentProfitCommissionProfile::class, 'profit_commission_profile_id');
- }
- public function profitCommissionAssignments()
- {
- return $this->hasMany(AgentProfitCommissionAssignment::class);
- }
- public function isJoint(): bool
- {
- return (int) $this->type === self::TYPE_JOINT;
- }
- public function isEquity(): bool
- {
- return (int) $this->type === self::TYPE_EQUITY;
- }
- public function getTypeTextAttribute(): string
- {
- return self::TYPE_NAMES[(int) ($this->type ?: self::TYPE_JOINT)] ?? '';
- }
- }
|