对搜索返回的消息做中英双版本

This commit is contained in:
2026-04-28 15:22:50 +08:00
parent 85133ee92b
commit 9bc439ea5e
32 changed files with 575 additions and 183 deletions

View File

@@ -334,19 +334,19 @@ final class DepositChannel
$out = [];
foreach ($items as $idx => $row) {
if (!is_array($row)) {
throw new InvalidArgumentException('第 ' . ($idx + 1) . ' 行格式错误');
throw new InvalidArgumentException('Row format error');
}
$code = isset($row['code']) && is_string($row['code']) ? strtolower(trim($row['code'])) : '';
if ($code === '' || !isset($registry[$code])) {
throw new InvalidArgumentException('第 ' . ($idx + 1) . ' 行渠道 code 未注册');
throw new InvalidArgumentException('Channel code is not registered');
}
if (isset($seen[$code])) {
throw new InvalidArgumentException('渠道 code 重复:' . $code);
throw new InvalidArgumentException('Duplicate channel code');
}
$seen[$code] = true;
$norm = self::normalizeOverrides([array_merge($row, ['code' => $code])]);
if ($norm === []) {
throw new InvalidArgumentException('第 ' . ($idx + 1) . ' 行渠道数据无效');
throw new InvalidArgumentException('Invalid channel row data');
}
$out[] = $norm[0];
}
@@ -369,7 +369,7 @@ final class DepositChannel
$wrapped = ['channels' => $items];
$encoded = json_encode($wrapped, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES);
if ($encoded === false) {
throw new InvalidArgumentException('JSON 编码失败');
throw new InvalidArgumentException('JSON encode failed');
}
return $encoded;

View File

@@ -149,7 +149,7 @@ final class DepositTier
foreach ($items as $idx => $row) {
$no = $idx + 1;
if (!is_array($row)) {
throw new InvalidArgumentException('第 ' . $no . ' 行格式错误');
throw new InvalidArgumentException('Row format error');
}
$id = isset($row['id']) && is_string($row['id']) ? trim($row['id']) : '';
@@ -157,10 +157,10 @@ final class DepositTier
$id = self::generateId();
}
if (!preg_match('/^[a-zA-Z0-9_\-]{1,32}$/', $id)) {
throw new InvalidArgumentException('第 ' . $no . ' 行 ID 非法');
throw new InvalidArgumentException('Tier id is invalid');
}
if (isset($seenId[$id])) {
throw new InvalidArgumentException('档位 ID 重复:' . $id);
throw new InvalidArgumentException('Duplicate tier id');
}
$seenId[$id] = true;
@@ -170,45 +170,45 @@ final class DepositTier
$title = self::stringField($row, 'name');
}
if ($title === '') {
throw new InvalidArgumentException('第 ' . $no . ' 行中文充值名称不能为空');
throw new InvalidArgumentException('Tier title (zh) is required');
}
if (mb_strlen($title) > 64) {
throw new InvalidArgumentException('第 ' . $no . ' 行中文充值名称过长');
throw new InvalidArgumentException('Tier title (zh) is too long');
}
$titleEn = self::stringField($row, 'title_en');
if (mb_strlen($titleEn) > 64) {
throw new InvalidArgumentException('第 ' . $no . ' 行英文充值名称过长');
throw new InvalidArgumentException('Tier title (en) is too long');
}
$currency = self::normalizeCurrency($row['currency'] ?? '');
if ($currency === '') {
throw new InvalidArgumentException('第 ' . $no . ' 行支付货币不能为空');
throw new InvalidArgumentException('Currency is required');
}
$payAmount = self::normalizeAmount($row['pay_amount'] ?? '');
if (bccomp($payAmount, '0', 2) <= 0) {
throw new InvalidArgumentException('第 ' . $no . ' 行支付货币额度必须大于 0');
throw new InvalidArgumentException('Pay amount must be greater than 0');
}
$amount = self::normalizeAmount($row['amount'] ?? '');
if (bccomp($amount, '0', 2) <= 0) {
throw new InvalidArgumentException('第 ' . $no . ' 行基础平台币到账必须大于 0');
throw new InvalidArgumentException('Base credit amount must be greater than 0');
}
$bonus = self::normalizeAmount($row['bonus_amount'] ?? '0');
if (bccomp($bonus, '0', 2) < 0) {
throw new InvalidArgumentException('第 ' . $no . ' 行赠送金额不能为负数');
throw new InvalidArgumentException('Bonus amount cannot be negative');
}
$desc = self::stringField($row, 'desc');
if (mb_strlen($desc) > 255) {
throw new InvalidArgumentException('第 ' . $no . ' 行中文描述过长');
throw new InvalidArgumentException('Description (zh) is too long');
}
$descEn = self::stringField($row, 'desc_en');
if (mb_strlen($descEn) > 255) {
throw new InvalidArgumentException('第 ' . $no . ' 行英文描述过长');
throw new InvalidArgumentException('Description (en) is too long');
}
$sort = isset($row['sort']) && is_numeric($row['sort']) ? intval($row['sort']) : 0;
@@ -248,7 +248,7 @@ final class DepositTier
{
$encoded = json_encode($items, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES);
if ($encoded === false) {
throw new InvalidArgumentException('JSON 编码失败');
throw new InvalidArgumentException('JSON encode failed');
}
return $encoded;
}

View File

@@ -328,50 +328,50 @@ final class FinanceCashierConfig
private static function validate(array $p): void
{
if (!isset($p['platform_coin']) || !is_array($p['platform_coin'])) {
throw new InvalidArgumentException('platform_coin 格式错误');
throw new InvalidArgumentException('platform_coin format error');
}
$lz = $p['platform_coin']['label_zh'] ?? '';
$le = $p['platform_coin']['label_en'] ?? '';
if (!is_string($lz) || trim($lz) === '' || !is_string($le) || trim($le) === '') {
throw new InvalidArgumentException('请填写平台币中英文名称');
throw new InvalidArgumentException('Platform coin labels (zh/en) are required');
}
if (!isset($p['currencies']) || !is_array($p['currencies']) || $p['currencies'] === []) {
throw new InvalidArgumentException('至少保留一条货币');
throw new InvalidArgumentException('At least one currency is required');
}
$seenCodes = [];
foreach ($p['currencies'] as $idx => $row) {
if (!is_array($row)) {
throw new InvalidArgumentException('货币列表第 ' . ($idx + 1) . ' 行格式错误');
throw new InvalidArgumentException('Currency row format error');
}
$code = $row['code'] ?? '';
if (!is_string($code) || !preg_match('/^[A-Z0-9]{2,12}$/', $code)) {
throw new InvalidArgumentException('货币代码非法:' . (is_string($code) ? $code : ''));
throw new InvalidArgumentException('Currency code is invalid');
}
if (isset($seenCodes[$code])) {
throw new InvalidArgumentException('货币代码不能重复:' . $code);
throw new InvalidArgumentException('Duplicate currency code');
}
$seenCodes[$code] = true;
$dep = $row['deposit_coins_per_fiat'] ?? '';
$wdr = $row['withdraw_coins_per_fiat'] ?? '';
if (!is_string($dep) || $dep === '' || !is_numeric($dep) || bccomp($dep, '0', 2) <= 0) {
throw new InvalidArgumentException('第 ' . ($idx + 1) . ' 行:充值汇率须为大于 0 的数字');
throw new InvalidArgumentException('Deposit rate must be a number greater than 0');
}
if (!is_string($wdr) || $wdr === '' || !is_numeric($wdr) || bccomp($wdr, '0', 2) <= 0) {
throw new InvalidArgumentException('第 ' . ($idx + 1) . ' 行:提现汇率须为大于 0 的数字');
throw new InvalidArgumentException('Withdraw rate must be a number greater than 0');
}
}
if (isset($p['withdraw_banks']) && is_array($p['withdraw_banks'])) {
$seen = [];
foreach ($p['withdraw_banks'] as $idx => $row) {
if (!is_array($row)) {
throw new InvalidArgumentException('银行第 ' . ($idx + 1) . ' 行格式错误');
throw new InvalidArgumentException('Bank row format error');
}
$code = $row['code'] ?? '';
if (!is_string($code) || !preg_match('/^[a-z0-9][a-z0-9_\-]{0,31}$/', $code)) {
throw new InvalidArgumentException('银行代码非法');
throw new InvalidArgumentException('Bank code is invalid');
}
if (isset($seen[$code])) {
throw new InvalidArgumentException('银行代码重复:' . $code);
throw new InvalidArgumentException('Duplicate bank code');
}
$seen[$code] = true;
}
@@ -380,13 +380,13 @@ final class FinanceCashierConfig
foreach (['min_ewallet', 'min_bank'] as $k) {
$v = $p['withdraw_limits'][$k] ?? '0';
if (!is_string($v) || !is_numeric($v) || bccomp($v, '0', 2) < 0) {
throw new InvalidArgumentException('提现最低限额须为不小于 0 的数字');
throw new InvalidArgumentException('Withdraw min limit must be a number not less than 0');
}
}
}
$reg = DepositChannel::codeRegistry();
if ($reg !== [] && (!isset($p['channels']) || !is_array($p['channels']) || $p['channels'] === [])) {
throw new InvalidArgumentException('请配置充值渠道');
throw new InvalidArgumentException('Please configure deposit channels');
}
}
}

View File

@@ -168,43 +168,43 @@ final class ZiHuaDictionary
public static function prepareItemsForSave(array $items): array
{
if (count($items) !== 36) {
throw new InvalidArgumentException('必须恰好 36 条');
throw new InvalidArgumentException('Must be exactly 36 items');
}
$nos = [];
$out = [];
foreach ($items as $idx => $row) {
if (!is_array($row)) {
throw new InvalidArgumentException('第 ' . ($idx + 1) . ' 行格式错误');
throw new InvalidArgumentException('Row format error');
}
$no = $row['no'] ?? null;
if (!is_numeric($no)) {
throw new InvalidArgumentException('编号必须为数字');
throw new InvalidArgumentException('No must be numeric');
}
$n = intval($no, 10);
if ($n < 1 || $n > 36) {
throw new InvalidArgumentException('编号必须在 136');
throw new InvalidArgumentException('No must be between 1 and 36');
}
if (isset($nos[$n])) {
throw new InvalidArgumentException('编号重复:' . $n);
throw new InvalidArgumentException('Duplicate no');
}
$nos[$n] = true;
$name = $row['name'] ?? '';
if (!is_string($name) || trim($name) === '') {
throw new InvalidArgumentException('编号 ' . $n . ' 名称不能为空');
throw new InvalidArgumentException('Name is required');
}
$cat = $row['category'] ?? '';
$catTrim = is_string($cat) ? trim($cat) : '';
if (!in_array($catTrim, self::CATEGORIES, true)) {
throw new InvalidArgumentException('编号 ' . $n . ' 类型无效');
throw new InvalidArgumentException('Category is invalid');
}
$out[] = ['no' => $n, 'name' => trim($name), 'category' => $catTrim];
}
for ($i = 1; $i <= 36; $i++) {
if (!isset($nos[$i])) {
throw new InvalidArgumentException('缺少编号:' . $i);
throw new InvalidArgumentException('Missing no');
}
}
usort($out, static fn (array $a, array $b): int => $a['no'] <=> $b['no']);
@@ -219,7 +219,7 @@ final class ZiHuaDictionary
usort($items, static fn (array $a, array $b): int => $a['no'] <=> $b['no']);
$encoded = json_encode($items, JSON_UNESCAPED_UNICODE);
if ($encoded === false) {
throw new InvalidArgumentException('JSON 编码失败');
throw new InvalidArgumentException('JSON encode failed');
}
return $encoded;
}