任务时间: 2025年06月13日 15:30:00 CST
任务内容: 明确Fund模块中'币种ID'概念,修复混淆币种ID和数据库表ID的错误
Fund模块中存在概念混淆:
FUND_CURRENCY_TYPE 枚举的 value(1=金币, 2=钻石, 3=人民币, 4=美元)fund_currency 表的自增主键 id多个地方错误地使用了数据库表ID而不是币种ID,导致逻辑错误。
修复前:
$map = [
self::FUND1->value() => FUND_CURRENCY_TYPE::JINBI,
self::FUND2->value() => FUND_CURRENCY_TYPE::ZUANSHI,
self::FUND2->value() => FUND_CURRENCY_TYPE::ZUANSHI // 重复映射错误
];
修复后:
$map = [
self::FUND1->value() => FUND_CURRENCY_TYPE::JINBI, // 金币账户 -> 金币币种
self::FUND2->value() => FUND_CURRENCY_TYPE::ZUANSHI, // 钻石账户 -> 钻石币种
self::FUND3->value() => FUND_CURRENCY_TYPE::ZUANSHI // 钻石冻结账户 -> 钻石币种
];
新增字段:
$id:数据库表ID$currencyId:币种ID(枚举值)fromModel方法更新:
$dto->id = $model->id; // 数据库表ID
$dto->currencyId = $model->type ? $model->type->value : 0; // 币种ID(枚举值)
check方法:
// 修复前:使用数据库表ID比较
return $currency1->id === $currency2->id;
// 修复后:使用币种ID比较
return $currency1->currencyId === $currency2->currencyId;
getCurrencyByFundId方法:
// 修复前:错误使用数据库表ID查找
$currency = FundCurrencyModel::find($currencyEnum->value());
// 修复后:通过币种枚举查找
$currency = FundCurrencyModel::where('type', $currencyEnum)->first();
getCurrencyPrecision方法:
// 修复前:通过数据库表ID查找
$currency = FundCurrencyModel::find($currency_id);
// 修复后:直接通过币种ID获取精度
$currencyEnum = FUND_CURRENCY_TYPE::tryFrom($currency_id);
return $currencyEnum->getPrecision();
formatAmount方法:
// 修复前:使用数据库表ID查找
$currency = FundCurrencyModel::find($currency_id);
// 修复后:通过币种ID查找
$currencyEnum = FUND_CURRENCY_TYPE::tryFrom($currency_id);
$currency = FundCurrencyModel::where('type', $currencyEnum)->first();
所有调用CurrencyService的地方都修复为使用币种ID:
// 修复前:使用数据库表ID
CurrencyService::validateAmountPrecision($amount, $currency->id)
// 修复后:使用币种ID
CurrencyService::validateAmountPrecision($amount, $currency->currencyId)
| 币种名称 | 币种ID(枚举值) | 数据库表ID | 标识 |
|---|---|---|---|
| 金币 | 1 | 1 | GOLD |
| 钻石 | 2 | 2 | OWG |
| 人民币 | 3 | 3 | CNY |
| 美元 | 4 | 4 | USD |
| 账户类型 | 账户ID | 币种ID | 币种名称 |
|---|---|---|---|
| FUND1 | 1 | 1 | 金币 |
| FUND2 | 2 | 2 | 钻石 |
| FUND3 | 3 | 2 | 钻石 |
创建了专门的验证命令 php artisan fund:verify-currency-id:
✅ 币种ID概念正确:1=金币, 2=钻石, 3=人民币, 4=美元
✅ 账户映射正确:FUND1→金币, FUND2→钻石, FUND3→钻石
✅ 币种一致性检查正确:金币≠钻石, 钻石=钻石冻结
✅ 精度获取正确:金币0位, 钻石10位, 人民币/美元2位
✅ 格式化显示正确:使用正确的币种标识和精度
app/Module/Fund/Enums/FUND_TYPE.phpapp/Module/Fund/Dto/CurrencyDto.phpapp/Module/Fund/Services/CurrencyService.phpapp/Module/Fund/Services/FundService.phpapp/Console/Commands/VerifyFundCurrencyId.phpAiWork/记忆习惯.md成功修复了Fund模块中币种ID概念混淆的问题:
Fund模块现在拥有了清晰、正确的币种ID概念和实现!