Commit 4977e47e authored by ml's avatar ml

资管后台-钱包流入流出详细数据

parent 3b6a2bc3
......@@ -179,4 +179,26 @@ export const autoCheckList = async (req: any, commonParam: CommonParam) => {
/**
* 钱包流入流出列表
* @param req
* @param commonParam
*/
export const walletInOutList = async (req: any, commonParam: CommonParam) => {
let func_name = "assetCheck.control.walletInOutList";
try {
setPageAndSize(commonParam);
beforeQueryCheckTime(commonParam);
let res = await assetCheckService.walletInOutList(commonParam);
return Res3Utils.result(res);
}
catch (e) {
logger.error(`${func_name} error:${e}`);
return Res3Utils.getErrorResult(e);
}
};
......@@ -2,12 +2,12 @@ import {
madAdminOrmDB, coinAddress, coinType, mainUserAsset, dwdSpotAssetsApi,
ormDB, coinTx, coinWithdraw, walletAssets,
financeAccountCategory, financeAccount,
financeAccountDailyRecord
financeAccountDailyRecord, abkWalletDailySnap
} from "@madex/ex-ts-dao";
import BigNumber from "bignumber.js";
import { CommonParam } from "./abkCommonService";
let { logger, apiAssertUtils: ApiAssert, BigNumberUtils } = require('@madex/ex-js-public');
let { logger, apiAssertUtils: ApiAssert, BigNumberUtils, datetimeUtils } = require('@madex/ex-js-public');
let { authCommon: AuthCommon, redisUtilsCommon: RedisClient, financeAccountDataUtils, tickerUtils } = require('@madex/ex-js-common');
let _ = require('lodash');
......@@ -615,4 +615,87 @@ async function getSiteWalletAssetsGroupBy(conditions: any[], group_by_field: str
}
export async function walletInOutList(commonParam: CommonParam) {
let from_time = commonParam.from_time;
let to_time = commonParam.to_time;
let page = Number(commonParam.page);
let size = Number(commonParam.size);
//查询昨日流入流出 和 总计流入流出
let opAnd = {
createdAt: {
[ormDB.Op.gte]: from_time,
[ormDB.Op.lt]: to_time
}
};
let walletTask = abkWalletDailySnap.prototype.findAll({
attributes: ['snap_date',
ormDB.literal('sum(case when change_amount >= 0 then ABS(`change_eq_usdt`) else 0 end) as in_amount'),
ormDB.literal('sum(case when change_amount < 0 then ABS(`change_eq_usdt`) else 0 end) as out_amount')],
where: {
[ormDB.Op.and]: opAnd,
},
group: ['snap_date'],
order: [['snap_date', 'desc']],
raw: true
});
//按正常来说 snap_date 倒序 第一个就是昨天的数据
//比较一下日期 如果没有 就先置为 0
let pageTask = abkWalletDailySnap.prototype.findAndCount({
where: {
[ormDB.Op.and]: opAnd,
},
limit: size,
offset: (page - 1) * size,
order: [["snap_date", "desc"]],
raw: true
})
let [walletDataList, pageData] = await Promise.all([walletTask, pageTask]);
let yesterday_in = new BigNumber(0);
let yesterday_out = new BigNumber(0);
let total_in = new BigNumber(0);
let total_out = new BigNumber(0);
let today = datetimeUtils.trim(new Date(), 'd');
let yesterday = datetimeUtils.sub(today, datetimeUtils.DAY);
for (let item of walletDataList) {
let inAmount = item.in_amount;
let outAmount = item.out_amount;
total_in = total_in.add(new BigNumber(inAmount));
total_out = total_out.add(new BigNumber(outAmount));
}
if (walletDataList.length && walletDataList[0]) {
let snapDate = walletDataList[0].snap_date;
let inAmount = walletDataList[0].in_amount;
let outAmount = walletDataList[0].out_amount;
let yts = new Date(yesterday).getTime();
let sts = new Date(snapDate).getTime();
//库里的最新纪录是昨天的 ,任务定时在跑, 如果不是昨天的 定时任务可能出问题了
if (yts == sts) {
yesterday_in = new BigNumber(inAmount);
yesterday_out = new BigNumber(outAmount);
}
}
let gather_data = {
yesterday_in,
yesterday_out,
yesterday_in_out: yesterday_in.sub(yesterday_out),
total_in,
total_out,
total_in_out: total_in.sub(total_out),
}
pageData['gather_data'] = gather_data;
return pageData;
}
......@@ -37,6 +37,7 @@ const postFunc = {
'assetCheck/funding/monitor/totalRecords': assetCheckCtrl.fundingTotalRecords,//资金监控-总记录
'assetCheck/funding/monitor/dailyRecords': assetCheckCtrl.fundingDailyRecords,//资金监控-每日记录
'assetCheck/auto/checkList': assetCheckCtrl.autoCheckList,//自动对账列表
'assetCheck/walletInOutList': assetCheckCtrl.walletInOutList,//钱包流入流出
//收入分析
'abkFeeStatistics/home/gatherData': feeStatisticsCtrl.gatherData,//首页数据概览
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment