| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667 |
- <?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 LEVEL_TWO = 2;
- public const MAX_LEVEL = self::LEVEL_TWO;
- protected $table = 'agents';
- protected $fillable = [
- 'parent_id', 'path', 'level', 'username', 'password', 'withdraw_password',
- 'real_name', 'invitation_code', 'balance', 'frozen_balance',
- 'deposit_fee_rate', 'withdraw_fee_rate', 'flow_commission_rate',
- 'profit_commission_rate', 'status', 'last_login_at', 'last_login_ip', 'created_by',
- ];
- protected $hidden = ['password', 'withdraw_password'];
- protected $appends = ['level_text', 'can_create_sub_agent'];
- protected $casts = [
- 'parent_id' => 'integer', 'level' => 'integer', 'status' => 'integer',
- 'balance' => 'decimal:4', 'frozen_balance' => 'decimal:4',
- 'deposit_fee_rate' => 'decimal:4', 'withdraw_fee_rate' => 'decimal:4',
- 'flow_commission_rate' => 'decimal:4', 'profit_commission_rate' => 'decimal:4',
- 'last_login_at' => 'datetime',
- ];
- public function parent()
- {
- return $this->belongsTo(self::class, 'parent_id');
- }
- public function domains()
- {
- return $this->hasMany(AgentDomain::class);
- }
- public function token()
- {
- return $this->hasOne(AgentToken::class);
- }
- public function children()
- {
- return $this->hasMany(self::class, 'parent_id');
- }
- public function members()
- {
- return $this->hasMany(User::class, 'agent_id');
- }
- public function getLevelTextAttribute(): string
- {
- return (int) $this->level === self::LEVEL_ONE ? '一级代理' : '二级代理';
- }
- public function getCanCreateSubAgentAttribute(): bool
- {
- return (int) $this->level === self::LEVEL_ONE;
- }
- }
|