(string) $value, 'exchange_rate' => (float) $value, default => $value, }; } /** * 转换成将要进行存储的值 */ public function set(Model $model, string $key, mixed $value, array $attributes): mixed { if (is_null($value)) { return null; } // 根据字段类型进行转换 return match ($key) { 'out_amount', 'amount' => (string) $value, 'exchange_rate' => number_format((float) $value, 4, '.', ''), default => $value, }; } }