比例字段。 */ public const CATEGORY_RATE_FIELDS = [ 'self:lottery' => 'f1_lottery_rate', 'self:sport' => 'f1_sport_rate', 'third:1' => 'live_rate', 'third:2' => 'slot_rate', 'third:4' => 'sport_rate', 'third:5' => 'esports_rate', 'third:6' => 'fishing_rate', 'third:7' => 'chess_rate', ]; public const RATE_FIELDS = [ 'f1_lottery_rate', 'f1_sport_rate', 'live_rate', 'slot_rate', 'sport_rate', 'esports_rate', 'fishing_rate', 'chess_rate', ]; protected $table = 'agent_profit_commission_profiles'; protected $hidden = ['owner_agent_id']; protected $fillable = [ 'name', 'margin_amount', 'f1_lottery_rate', 'f1_sport_rate', 'live_rate', 'slot_rate', 'sport_rate', 'esports_rate', 'fishing_rate', 'chess_rate', 'is_default', ]; protected $casts = [ 'margin_amount' => 'decimal:4', 'f1_lottery_rate' => 'decimal:4', 'f1_sport_rate' => 'decimal:4', 'live_rate' => 'decimal:4', 'slot_rate' => 'decimal:4', 'sport_rate' => 'decimal:4', 'esports_rate' => 'decimal:4', 'fishing_rate' => 'decimal:4', 'chess_rate' => 'decimal:4', 'is_default' => 'integer', ]; public function agents() { return $this->hasMany(Agent::class, 'profit_commission_profile_id'); } public static function officialDefaultId(): ?int { $id = static::query()->whereNull('owner_agent_id')->where('is_default', 1)->value('id'); return $id ? (int) $id : null; } public static function rateForCategory(object $source, string $category): string { $field = self::CATEGORY_RATE_FIELDS[$category] ?? null; return $field ? bcadd((string) ($source->{$field} ?? 0), '0', 4) : '0.0000'; } public function rateSnapshot(): array { $snapshot = []; foreach (self::RATE_FIELDS as $field) { $snapshot[$field] = (string) $this->{$field}; } return $snapshot; } }