/** * 后台提现展示逻辑与数据获取器单元模拟测试 * 模拟验证 application/admin/model/shopro/Withdraw.php 中的: * 1. getIsMadowWithdrawAttr 判断逻辑 * 2. getWithdrawInfoDisplayAttr 字段清洗、市值汇率与换算市值格式化逻辑 */ const assert = require('assert'); function simulateGetIsMadowWithdraw(withdraw_info) { let info = withdraw_info; if (typeof info === 'string') { try { info = JSON.parse(info); } catch (e) { info = {}; } } if (!info || typeof info !== 'object') return false; return Boolean( (info.wallet_type === 'madow') || (info['提现资产'] && info['提现资产'].toLowerCase() === 'dmepa') ); } function simulateGetWithdrawInfoDisplay(withdraw_info, amount) { let info = withdraw_info; if (typeof info === 'string') { try { info = JSON.parse(info); } catch (e) { info = {}; } } if (!info || typeof info !== 'object') return {}; const display = {}; const isMadow = simulateGetIsMadowWithdraw(info); if (isMadow) { display['提现资产'] = 'DMEPA'; // 扣除 DMEPA const madowAmount = info['madow_amount'] || info['扣除DMEPA'] || info['扣除dmepa'] || null; if (madowAmount !== null) { const madowClean = String(madowAmount).replace(/dmepa/gi, '').trim(); display['扣除DMEPA'] = `${madowClean} DMEPA`; } // 市值汇率 const rate = info['rate'] !== undefined ? info['rate'] : (info['市值汇率'] || info['折算汇率'] || null); if (rate !== null) { if (typeof rate === 'number') { const rateClean = rate.toFixed(12).replace(/\.?0+$/, ''); display['市值汇率'] = `1 DMEPA ≈ ${rateClean} 元`; } else { const rateClean = String(rate).replace(/1\s*DMEPA\s*≈|元\/dmepa|元\/DMEPA|元|\s/g, '').trim(); display['市值汇率'] = `1 DMEPA ≈ ${rateClean} 元`; } } // 换算市值 const marketValue = info['换算市值'] || amount || null; if (marketValue !== null) { const valClean = String(marketValue).replace(/元|\s/g, '').trim(); display['换算市值'] = `${Number(valClean).toFixed(2)} 元`; } } const excludeKeys = ['wallet_type', 'madow_amount', 'rate', '提现资产', '扣除DMEPA', '扣除dmepa', '市值汇率', '折算汇率', '换算市值']; for (const [k, v] of Object.entries(info)) { if (!excludeKeys.includes(k)) { display[k] = v; } } return display; } console.log('--- 开始执行后台模型获取器逻辑模拟单元测试 ---'); // 场景 1: 普通佣金提现单 const normalWithdraw = { amount: '50.00', withdraw_info: { '真实姓名': '张三', '开户银行': '工商银行', '银行卡号': '6222021234567890' } }; assert.strictEqual(simulateGetIsMadowWithdraw(normalWithdraw.withdraw_info), false, '普通提现单识别为非 DMEPA'); const normalDisplay = simulateGetWithdrawInfoDisplay(normalWithdraw.withdraw_info, normalWithdraw.amount); assert.strictEqual(normalDisplay['提现资产'], undefined); assert.strictEqual(normalDisplay['市值汇率'], undefined); assert.strictEqual(normalDisplay['真实姓名'], '张三'); console.log('✓ 场景 1 (普通佣金提现单) 通过'); // 场景 2: 新版 DMEPA 银行卡提现单 const newMadowWithdraw = { amount: '100.00', withdraw_info: { '真实姓名': '李四', '开户银行': '建设银行', '银行卡号': '6217001234567890', '提现资产': 'DMEPA', '扣除DMEPA': '133333333.3333 DMEPA', '市值汇率': '1 DMEPA ≈ 0.00000075 元', '换算市值': '100.00 元', 'wallet_type': 'madow', 'madow_amount': '133333333.3333', 'rate': 0.00000075 } }; assert.strictEqual(simulateGetIsMadowWithdraw(newMadowWithdraw.withdraw_info), true, '新版 DMEPA 单据成功识别'); const newDisplay = simulateGetWithdrawInfoDisplay(newMadowWithdraw.withdraw_info, newMadowWithdraw.amount); assert.strictEqual(newDisplay['提现资产'], 'DMEPA'); assert.strictEqual(newDisplay['扣除DMEPA'], '133333333.3333 DMEPA'); assert.strictEqual(newDisplay['市值汇率'], '1 DMEPA ≈ 0.00000075 元'); assert.strictEqual(newDisplay['换算市值'], '100.00 元'); assert.strictEqual(newDisplay['真实姓名'], '李四'); assert.strictEqual(newDisplay['开户银行'], '建设银行'); assert.strictEqual(newDisplay['wallet_type'], undefined, '成功过滤底层英文键 wallet_type'); assert.strictEqual(newDisplay['madow_amount'], undefined, '成功过滤底层英文键 madow_amount'); assert.strictEqual(newDisplay['rate'], undefined, '成功过滤底层英文键 rate'); console.log('✓ 场景 2 (新版 DMEPA 银行卡提现单) 通过'); // 场景 3: 旧版兼容 DMEPA 记录 (历史数据兼容) const legacyMadowWithdraw = { amount: '200.00', withdraw_info: { '真实姓名': '王五', '开户银行': '招商银行', '银行卡号': '6225881234567890', '提现资产': 'dmepa', '扣除dmepa': '266666666.6667', '折算汇率': '0.00000075 元/dmepa', 'wallet_type': 'madow', 'madow_amount': '266666666.6667', 'rate': 0.00000075 } }; assert.strictEqual(simulateGetIsMadowWithdraw(legacyMadowWithdraw.withdraw_info), true, '旧版小写 dmepa 成功识别'); const legacyDisplay = simulateGetWithdrawInfoDisplay(legacyMadowWithdraw.withdraw_info, legacyMadowWithdraw.amount); assert.strictEqual(legacyDisplay['提现资产'], 'DMEPA', '小写 dmepa 规范大写'); assert.strictEqual(legacyDisplay['扣除DMEPA'], '266666666.6667 DMEPA', '自动补齐 DMEPA 单位后缀'); assert.strictEqual(legacyDisplay['市值汇率'], '1 DMEPA ≈ 0.00000075 元', '历史「折算汇率」自动规范为「市值汇率」'); assert.strictEqual(legacyDisplay['换算市值'], '200.00 元', '历史数据自动根据金额补全「换算市值」'); assert.strictEqual(legacyDisplay['折算汇率'], undefined, '历史旧键被清理'); assert.strictEqual(legacyDisplay['扣除dmepa'], undefined, '历史小写键被清理'); console.log('✓ 场景 3 (旧版兼容 DMEPA 记录) 通过'); console.log('-------------------------------------------'); console.log('所有单元行为模拟测试全部通过!');