forked from OpenWF/SpaceNinjaServer
Remove Chinese comments from currency validation code
This commit is contained in:
parent
0b6f9bb026
commit
39cd484036
@ -13,7 +13,6 @@ export const purchaseController: RequestHandler = async (req, res) => {
|
|||||||
try {
|
try {
|
||||||
const inventory = await getInventory(accountId);
|
const inventory = await getInventory(accountId);
|
||||||
|
|
||||||
// 记录购买前的货币状态
|
|
||||||
const beforePurchase = {
|
const beforePurchase = {
|
||||||
RegularCredits: inventory.RegularCredits,
|
RegularCredits: inventory.RegularCredits,
|
||||||
PremiumCredits: inventory.PremiumCredits,
|
PremiumCredits: inventory.PremiumCredits,
|
||||||
@ -26,7 +25,6 @@ export const purchaseController: RequestHandler = async (req, res) => {
|
|||||||
const response = await handlePurchase(purchaseRequest, inventory);
|
const response = await handlePurchase(purchaseRequest, inventory);
|
||||||
await inventory.save();
|
await inventory.save();
|
||||||
|
|
||||||
// 记录购买后的货币状态
|
|
||||||
const afterPurchase = {
|
const afterPurchase = {
|
||||||
RegularCredits: inventory.RegularCredits,
|
RegularCredits: inventory.RegularCredits,
|
||||||
PremiumCredits: inventory.PremiumCredits,
|
PremiumCredits: inventory.PremiumCredits,
|
||||||
@ -37,7 +35,6 @@ export const purchaseController: RequestHandler = async (req, res) => {
|
|||||||
|
|
||||||
res.json(response);
|
res.json(response);
|
||||||
|
|
||||||
// 立即发送货币更新广播,确保客户端实时同步
|
|
||||||
sendWsBroadcastTo(accountId, {
|
sendWsBroadcastTo(accountId, {
|
||||||
update_inventory: true,
|
update_inventory: true,
|
||||||
currency_update: {
|
currency_update: {
|
||||||
@ -50,7 +47,6 @@ export const purchaseController: RequestHandler = async (req, res) => {
|
|||||||
} catch (error) {
|
} catch (error) {
|
||||||
logger.error(`Purchase failed for account ${accountId}:`, error);
|
logger.error(`Purchase failed for account ${accountId}:`, error);
|
||||||
|
|
||||||
// 返回详细的错误信息给客户端
|
|
||||||
if (error instanceof Error && error.message.includes('Insufficient')) {
|
if (error instanceof Error && error.message.includes('Insufficient')) {
|
||||||
res.status(400).json({
|
res.status(400).json({
|
||||||
error: 'INSUFFICIENT_CURRENCY',
|
error: 'INSUFFICIENT_CURRENCY',
|
||||||
|
|||||||
@ -1259,7 +1259,6 @@ export const updateCurrency = (
|
|||||||
): IInventoryChanges => {
|
): IInventoryChanges => {
|
||||||
if (price != 0 && isCurrencyTracked(inventory, usePremium)) {
|
if (price != 0 && isCurrencyTracked(inventory, usePremium)) {
|
||||||
if (usePremium) {
|
if (usePremium) {
|
||||||
// 验证白金余额是否足够
|
|
||||||
if (validateBalance) {
|
if (validateBalance) {
|
||||||
const totalPlatinum = inventory.PremiumCredits + inventory.PremiumCreditsFree;
|
const totalPlatinum = inventory.PremiumCredits + inventory.PremiumCreditsFree;
|
||||||
if (totalPlatinum < price) {
|
if (totalPlatinum < price) {
|
||||||
@ -1278,7 +1277,6 @@ export const updateCurrency = (
|
|||||||
inventory.PremiumCredits -= price;
|
inventory.PremiumCredits -= price;
|
||||||
logger.debug(`currency changes `, { PremiumCredits: -price });
|
logger.debug(`currency changes `, { PremiumCredits: -price });
|
||||||
} else {
|
} else {
|
||||||
// 验证现金余额是否足够
|
|
||||||
if (validateBalance && inventory.RegularCredits < price) {
|
if (validateBalance && inventory.RegularCredits < price) {
|
||||||
throw new Error(`Insufficient credits balance. Required: ${price}, Available: ${inventory.RegularCredits}`);
|
throw new Error(`Insufficient credits balance. Required: ${price}, Available: ${inventory.RegularCredits}`);
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user