feat: 补齐客户端/管理端服务模块与数据库 schema,完善登录短信、法大大签署及公共函数
This commit is contained in:
+104
@@ -0,0 +1,104 @@
|
||||
'use strict';
|
||||
const dayjs = require('dayjs');
|
||||
const balanceUtil = require('../../../admin/finance/balance/sys/util.js');
|
||||
|
||||
module.exports = {
|
||||
/**
|
||||
* 定时同步余额流水状态
|
||||
* @url client/timedTask/pub/syncBalanceActionStatus 前端调用的url参数地址
|
||||
*/
|
||||
main: async (event) => {
|
||||
let { data = {}, util } = event;
|
||||
let { vk, _ } = util;
|
||||
let res = { code: 0, msg: '', data: [] };
|
||||
|
||||
if (data.key !== 'lsgjoksdjf') return { code: 1, msg: '非法请求' };
|
||||
|
||||
const result = await vk.baseDao.selects({
|
||||
dbName: 'jjx-balance-log',
|
||||
whereJson: {
|
||||
srcReqId: _.and(_.exists(true), _.neq('')),
|
||||
status: 1
|
||||
},
|
||||
sortArr: [{ name: '_add_time', type: 'asc' }],
|
||||
pageIndex: 1,
|
||||
pageSize: 5000,
|
||||
getCount: true
|
||||
});
|
||||
|
||||
for (const row of result.rows || []) {
|
||||
try {
|
||||
const reqDate = formatReqDate(row._add_time);
|
||||
if (!reqDate) {
|
||||
throw new Error('流水日期格式不正确');
|
||||
}
|
||||
const requestRes = await balanceUtil.requestActionLog({
|
||||
vk,
|
||||
accNo: row.merchantId || '',
|
||||
reqDate,
|
||||
reqJournalNo: row.srcReqId
|
||||
});
|
||||
const status = balanceUtil.getActionStatus(requestRes);
|
||||
if (status === null) {
|
||||
res.data.push({
|
||||
_id: row._id,
|
||||
srcReqId: row.srcReqId,
|
||||
success: false,
|
||||
msg: '未获取到可更新状态'
|
||||
});
|
||||
continue;
|
||||
}
|
||||
if (status === 1) {
|
||||
res.data.push({
|
||||
_id: row._id,
|
||||
srcReqId: row.srcReqId,
|
||||
success: true,
|
||||
msg: '状态仍处理中'
|
||||
});
|
||||
continue;
|
||||
}
|
||||
await vk.baseDao.updateById({
|
||||
dbName: 'jjx-balance-log',
|
||||
id: row._id,
|
||||
dataJson: {
|
||||
status,
|
||||
actionStatusUpdateTime: dayjs().format('YYYY-MM-DD HH:mm:ss'),
|
||||
actionStatusRaw: JSON.stringify(requestRes || {})
|
||||
}
|
||||
});
|
||||
res.data.push({
|
||||
_id: row._id,
|
||||
srcReqId: row.srcReqId,
|
||||
success: true,
|
||||
status
|
||||
});
|
||||
} catch (err) {
|
||||
console.error('syncBalanceActionStatus error:', row._id, err);
|
||||
res.data.push({
|
||||
_id: row._id,
|
||||
srcReqId: row.srcReqId,
|
||||
success: false,
|
||||
msg: err.message || '更新失败'
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
const failList = res.data.filter(item => !item.success);
|
||||
if (failList.length) {
|
||||
res.code = -1;
|
||||
res.msg = `部分流水状态更新失败:${failList.map(item => item.srcReqId).join(',')}`;
|
||||
}
|
||||
|
||||
return res;
|
||||
}
|
||||
};
|
||||
|
||||
function formatReqDate(value) {
|
||||
const date = typeof value === 'number'
|
||||
? new Date(value)
|
||||
: new Date(String(value || '').replace(/-/g, '/'));
|
||||
if (Number.isNaN(date.getTime())) {
|
||||
return '';
|
||||
}
|
||||
return dayjs(date).format('YYYYMMDD');
|
||||
}
|
||||
Reference in New Issue
Block a user