'use strict'; const dayjs = require('dayjs'); const balanceUtil = require('./util.js'); module.exports = { /** * 查询余额 * @url admin/finance/balance/sys/getInfo 前端调用的url参数地址 * @param {String} accNo 账号 */ main: async (event) => { let { data = {}, util } = event; let { vk } = util; let { accNo } = data; accNo = String(accNo || '').trim(); if (!accNo) { return { code: -1, msg: 'accNo不能为空' }; } let res = await balanceUtil.requestMerchantBalance({ vk, accNo }); if (res && typeof res === 'object' && typeof res.code === 'undefined') { res.code = 0; } const merchantBalance = balanceUtil.getRemoteMerchantBalance(res); if (merchantBalance !== null) { const updateTime = dayjs().format('YYYY-MM-DD HH:mm:ss'); const syncRes = await balanceUtil.syncMerchantBalance({ vk, accNo, merchantBalance, updateTime }); const nextMerchantBalance = syncRes.merchantBalance; if (res.data && typeof res.data === 'object') { res.data.balance = nextMerchantBalance; res.data.updateTime = updateTime; } else if (res.info && typeof res.info === 'object') { res.info.balance = nextMerchantBalance; res.info.updateTime = updateTime; } else if (res.content && typeof res.content === 'object') { res.content.balance = nextMerchantBalance; res.content.updateTime = updateTime; } else { res.data = { balance: nextMerchantBalance, updateTime }; } } return res; } };