fix(admin): 兼容提现金额历史配置
This commit is contained in:
@@ -175,12 +175,7 @@ class SchemaProvider {
|
||||
continue;
|
||||
}
|
||||
if (($field['sanitize_type'] ?? '') === 'money_decimal') {
|
||||
try {
|
||||
if (!is_string($value)) {
|
||||
throw new \InvalidArgumentException('money_decimal_must_be_string');
|
||||
}
|
||||
\AKSRT\Ledger\AssetAmount::balance(trim($value));
|
||||
} catch (\InvalidArgumentException $e) {
|
||||
if ($this->normalize_money_decimal($value) === '') {
|
||||
$errors[] = sprintf('%s must be a decimal string with at most two fractional digits', $field['label'] ?? $key);
|
||||
continue;
|
||||
}
|
||||
@@ -543,6 +538,12 @@ class SchemaProvider {
|
||||
if (array_key_exists($field['key'], $stored)) {
|
||||
$data[$field['key']] = $stored[$field['key']];
|
||||
}
|
||||
if (($field['sanitize_type'] ?? '') === 'money_decimal' && array_key_exists($field['key'], $data)) {
|
||||
$normalized = $this->normalize_money_decimal($data[$field['key']]);
|
||||
if ($normalized !== '') {
|
||||
$data[$field['key']] = $normalized;
|
||||
}
|
||||
}
|
||||
|
||||
$stored_value = array_key_exists($field['key'], $stored) ? $stored[$field['key']] : ($data[$field['key']] ?? '');
|
||||
|
||||
@@ -748,7 +749,31 @@ class SchemaProvider {
|
||||
return $fields;
|
||||
}
|
||||
|
||||
private function sanitize_value($value, string $type) {
|
||||
/**
|
||||
* Normalize legacy numeric money settings without accepting lossy precision.
|
||||
*
|
||||
* @param mixed $value
|
||||
*/
|
||||
private function normalize_money_decimal($value): string {
|
||||
if (is_int($value)) {
|
||||
$value = (string) $value;
|
||||
} elseif (is_float($value)) {
|
||||
if (!is_finite($value)) {
|
||||
return '';
|
||||
}
|
||||
$value = (string) $value;
|
||||
} elseif (!is_string($value)) {
|
||||
return '';
|
||||
}
|
||||
|
||||
try {
|
||||
return \AKSRT\Ledger\AssetAmount::balance(trim($value))->decimal();
|
||||
} catch (\InvalidArgumentException $e) {
|
||||
return '';
|
||||
}
|
||||
}
|
||||
|
||||
private function sanitize_value($value, string $type) {
|
||||
switch ($type) {
|
||||
case 'attachment_ids':
|
||||
if (!is_array($value)) {
|
||||
@@ -771,14 +796,7 @@ class SchemaProvider {
|
||||
case 'float':
|
||||
return (float) $value;
|
||||
case 'money_decimal':
|
||||
if (!is_string($value)) {
|
||||
return '';
|
||||
}
|
||||
try {
|
||||
return \AKSRT\Ledger\AssetAmount::balance(trim($value))->decimal();
|
||||
} catch (\InvalidArgumentException $e) {
|
||||
return '';
|
||||
}
|
||||
return $this->normalize_money_decimal($value);
|
||||
case 'array':
|
||||
// 深层字符串净化,保留嵌套服务商配置(如 geetest.captcha_id)
|
||||
if (!is_array($value)) {
|
||||
|
||||
Reference in New Issue
Block a user