'float', 'total_income' => 'float', 'commission_rate' => 'float', 'last_login_time' => 'datetime', 'created_at' => 'datetime', 'updated_at' => 'datetime', ]; // 获取父级代理 public function parent() { return $this->belongsTo(Agent::class, 'parent_id'); } // 获取子级代理 public function children() { return $this->hasMany(Agent::class, 'parent_id'); } // 获取代理的激活码 public function codes() { return $this->hasMany('app\manager\model\AgentCode', 'agent_id'); } // 更新余额 public function updateBalance($amount) { $this->balance += $amount; $this->total_income += max(0, $amount); return $this->save(); } }