20261008
This commit is contained in:
+65
@@ -0,0 +1,65 @@
|
||||
'use strict';
|
||||
const notaryPay = require('../../order/kh/util/notaryPay');
|
||||
|
||||
module.exports = {
|
||||
/**
|
||||
* 自动划付到期付款单
|
||||
* @url client/timedTask/pub/autoTransferPayList 前端调用的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 payList = await vk.baseDao.select({
|
||||
dbName: 'jjx-order-pay-list',
|
||||
whereJson: {
|
||||
isNotaryPay: true,
|
||||
isNotaryApply: true,
|
||||
hasPaid: true,
|
||||
buyerRefuse: false,
|
||||
sellerConfirm: false,
|
||||
autoTransferTimestamp: _.lte(Date.now())
|
||||
},
|
||||
sortArr: [{name: 'autoTransferTimestamp', type: 'asc'}],
|
||||
pageIndex: 1,
|
||||
pageSize: 200
|
||||
});
|
||||
|
||||
for (const payRecord of payList.rows || []) {
|
||||
try {
|
||||
const transferRes = await notaryPay.executeTransfer({
|
||||
vk,
|
||||
payRecord,
|
||||
operator: 'auto'
|
||||
});
|
||||
res.data.push({
|
||||
_id: payRecord._id,
|
||||
orderId: payRecord.orderId,
|
||||
sourcePayOrderNo: payRecord.fullPayOrderNo || payRecord.sourcePayOrderNo || '',
|
||||
success: transferRes.code === 0,
|
||||
msg: transferRes.msg
|
||||
});
|
||||
} catch (err) {
|
||||
console.error('autoTransferPayList error:', payRecord._id, err);
|
||||
res.data.push({
|
||||
_id: payRecord._id,
|
||||
orderId: payRecord.orderId,
|
||||
sourcePayOrderNo: payRecord.fullPayOrderNo || payRecord.sourcePayOrderNo || '',
|
||||
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._id).join(',')}`;
|
||||
}
|
||||
|
||||
return res;
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,41 @@
|
||||
'use strict';
|
||||
const dayjs = require("dayjs");
|
||||
module.exports = {
|
||||
/**
|
||||
* XXXnameXXX
|
||||
* @url client/timedTask/pub/task 前端调用的url参数地址
|
||||
* data 请求参数
|
||||
* @param {String} params1 参数1
|
||||
*/
|
||||
main: async (event) => {
|
||||
let {data = {}, userInfo, util, filterResponse, originalParam} = event;
|
||||
let {customUtil, uniID, config, pubFun, vk, db, _} = util;
|
||||
let {uid} = data;
|
||||
let res = {code: 0, msg: ""};
|
||||
// 业务逻辑开始-----------------------------------------------------------
|
||||
|
||||
if (data.key !== 'lsgjoksdjf') return {code: 1, msg: '非法请求'}
|
||||
|
||||
// 取消超时未支付订单
|
||||
res = await vk.baseDao.select({
|
||||
dbName: "jjx-old",
|
||||
whereJson: {
|
||||
status: 0,
|
||||
},
|
||||
})
|
||||
for (const row of res.rows) {
|
||||
if (dayjs(row.expiredTime).isBefore(dayjs())) {
|
||||
await vk.baseDao.updateById({
|
||||
dbName: "jjx-old",
|
||||
id: row._id,
|
||||
dataJson: {
|
||||
status: -1,
|
||||
},
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
// 业务逻辑结束-----------------------------------------------------------
|
||||
return res;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
'use strict';
|
||||
module.exports = {
|
||||
/**
|
||||
* XXXnameXXX
|
||||
* @url client/timedTask/pub/task 前端调用的url参数地址
|
||||
* data 请求参数
|
||||
* @param {String} params1 参数1
|
||||
*/
|
||||
main: async (event) => {
|
||||
let {data = {}, userInfo, util, filterResponse, originalParam} = event;
|
||||
let {customUtil, uniID, config, pubFun, vk, db, _} = util;
|
||||
let {uid} = data;
|
||||
let res = {code: 0, msg: ""};
|
||||
// 业务逻辑开始-----------------------------------------------------------
|
||||
|
||||
if (data.key !== 'lsgjoksdjf') return {code: 1, msg: '非法请求'}
|
||||
|
||||
// 取消超时未支付订单
|
||||
await vk.baseDao.update({
|
||||
dbName: "jjx-order",
|
||||
whereJson: {
|
||||
orderStatus: 0,
|
||||
type: _.in([0 , 1, 2, 3, 7]),
|
||||
_add_time: _.lte(
|
||||
vk.pubfn.getOffsetTime(new Date(), {
|
||||
minutes: 30,
|
||||
mode: "before",
|
||||
}))
|
||||
},
|
||||
dataJson: {
|
||||
orderStatus: -1
|
||||
}
|
||||
})
|
||||
|
||||
// 业务逻辑结束-----------------------------------------------------------
|
||||
return res;
|
||||
}
|
||||
}
|
||||
+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');
|
||||
}
|
||||
+63
@@ -0,0 +1,63 @@
|
||||
'use strict';
|
||||
const dayjs = require('dayjs');
|
||||
const balanceUtil = require('../../../admin/finance/balance/sys/util.js');
|
||||
|
||||
module.exports = {
|
||||
/**
|
||||
* 定时同步企业余额
|
||||
* @url client/timedTask/pub/syncMerchantBalance 前端调用的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 updateTime = dayjs().format('YYYY-MM-DD HH:mm:ss');
|
||||
|
||||
for (const merchant of balanceUtil.MERCHANT_OPTIONS) {
|
||||
try {
|
||||
const requestRes = await balanceUtil.requestMerchantBalance({
|
||||
vk,
|
||||
accNo: merchant.accNo
|
||||
});
|
||||
const merchantBalance = balanceUtil.getRemoteMerchantBalance(requestRes);
|
||||
if (merchantBalance === null) {
|
||||
throw new Error('未获取到余额字段');
|
||||
}
|
||||
|
||||
const syncRes = await balanceUtil.syncMerchantBalance({
|
||||
vk,
|
||||
accNo: merchant.accNo,
|
||||
merchantBalance,
|
||||
updateTime
|
||||
});
|
||||
|
||||
res.data.push({
|
||||
accNo: merchant.accNo,
|
||||
merchantName: merchant.label,
|
||||
balance: syncRes.merchantBalance,
|
||||
updateTime,
|
||||
success: true
|
||||
});
|
||||
} catch (err) {
|
||||
console.error(`syncMerchantBalance error: ${merchant.accNo}`, err);
|
||||
res.data.push({
|
||||
accNo: merchant.accNo,
|
||||
merchantName: merchant.label,
|
||||
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.accNo).join(',')}`;
|
||||
}
|
||||
|
||||
return res;
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user