Commit d2c4f160 authored by ml's avatar ml

费率、现货数据折线图

parent 0e5fee07
...@@ -10,10 +10,11 @@ import { ...@@ -10,10 +10,11 @@ import {
feeRateSpotLog, feeRateSpotLog,
feeRateContractLog, feeRateContractLog,
commonUserFeeSetting, commonUserFeeSetting,
feeRateBaseCoinContractLog, spotPairs, contractPairs feeRateBaseCoinContractLog, spotPairs, contractPairs,
userProductFee
} from "@madex/ex-ts-dao"; } from "@madex/ex-ts-dao";
import { FEE_RATE_LOG_STATUS } from "../../src/constant/feeRateLogConst"; import { FEE_RATE_LOG_STATUS } from "../../src/constant/feeRateLogConst";
import { changeTradingFee, getPairFromCore } from "../../src/utils/coreSystemUtils"; import { changeTradingFee, getPairFromCore, getUserAccountFromCore } from "../../src/utils/coreSystemUtils";
let BigNumber = require('bignumber.js'); let BigNumber = require('bignumber.js');
...@@ -113,10 +114,16 @@ let checkFeeRate = async function (fee_rate) { ...@@ -113,10 +114,16 @@ let checkFeeRate = async function (fee_rate) {
}; };
export const changeUserSpotFee = async function (user_id, symbol, fee_model, maker_fee, taker_fee, logId) { export const changeUserSpotFee = async function (user_id, symbol, fee_model, maker_fee, taker_fee, logId) {
let pair = symbol === 'all' ? '' : symbol;
let is_success = true; let is_success = true;
await checkFeeModel(fee_model); await checkFeeModel(fee_model);
let product_type = pair == 'all' ? 'spot' : 'single';
//生效的费率 与要设置的费率 比对做校验 现在分不开 现货 合约 先不校验 之后分开了 再校验
/* let feeExist = await cancelIfFeeExist(user_id, product_type, symbol, maker_fee, taker_fee);
if (feeExist) {
return is_success;
}*/
let asset = await mainUserAsset.prototype.findOne({ let asset = await mainUserAsset.prototype.findOne({
where: { where: {
user_id user_id
...@@ -134,28 +141,43 @@ export const changeUserSpotFee = async function (user_id, symbol, fee_model, mak ...@@ -134,28 +141,43 @@ export const changeUserSpotFee = async function (user_id, symbol, fee_model, mak
logger.warn(' task.fee.rate.log.model.changeUserSpotFee ', ` taker_fee fee_rate error ${taker_fee}`); logger.warn(' task.fee.rate.log.model.changeUserSpotFee ', ` taker_fee fee_rate error ${taker_fee}`);
throw '3000'; throw '3000';
} }
await checkPair(symbol, 1); if (pair) {
await checkPair(symbol, 1);
}
await checkUser(user_id); await checkUser(user_id);
await sleep(1000); await sleep(1000);
//请求撮合 修改费率 //请求撮合 修改费率
let res = await changeTradingFee(symbol, user_id, maker_fee, taker_fee);
let res = await changeTradingFee(pair, user_id, maker_fee, taker_fee);
return res.is_success; return res.is_success;
}; };
export const changeUserContractFee = async function (user_id, symbol, fee_model, maker_fee, taker_fee, logId) { export const changeUserContractFee = async function (user_id, symbol, fee_model, maker_fee, taker_fee, logId) {
let _func_name_ = 'task.fee.rate.log.model.changeUserContractFee'; let _func_name_ = 'task.fee.rate.log.model.changeUserContractFee';
let pair = symbol === 'all' ? '' : symbol;
let is_success = true; let is_success = true;
await checkPair(symbol, 2); let product_type = pair == 'all' ? 'lpc' : 'single';
let asset = await mainUserAsset.prototype.findOne({ //生效的费率 与要设置的费率 比对做校验 现在分不开 现货 合约 先不校验 之后分开了 再校验
where: { /*let feeExist = await cancelIfFeeExist(user_id, product_type, symbol, maker_fee, taker_fee);
user_id if (feeExist) {
}, return is_success;
raw: true }*/
}) if (pair) {
if (!asset) { await checkPair(symbol, 2);
}
//查询交易账户资产
let asset: any;
try {
asset = await getUserAccountFromCore(user_id);
}
catch (e) {
logger.error('changeUserContractFee.getUserAccountFromCore.error:' + e);
}
if (!asset || !asset.length) {
return is_success; return is_success;
} }
if (maker_fee < -0.0003) { // 最大返0.0003 if (maker_fee < -0.0003) { // 最大返0.0003
...@@ -172,7 +194,7 @@ export const changeUserContractFee = async function (user_id, symbol, fee_model, ...@@ -172,7 +194,7 @@ export const changeUserContractFee = async function (user_id, symbol, fee_model,
await sleep(1000); await sleep(1000);
//请求撮合 修改费率 //请求撮合 修改费率
let res = await changeTradingFee(symbol, user_id, maker_fee, taker_fee); let res = await changeTradingFee(pair, user_id, maker_fee, taker_fee);
return res.is_success; return res.is_success;
}; };
...@@ -194,3 +216,30 @@ async function getMainAccountUserId(user_id: number) { ...@@ -194,3 +216,30 @@ async function getMainAccountUserId(user_id: number) {
let father_id = dbSon ? dbSon.father_id : user_id; let father_id = dbSon ? dbSon.father_id : user_id;
return father_id; return father_id;
} }
async function cancelIfFeeExist(user_id, product_type, pair, maker_fee, taker_fee) {
let condition = {
user_id,
product: pair == 'all' ? '' : pair,
product_type
}
let dbFee = await userProductFee.prototype.findOne({
where: condition,
raw: true
});
if (dbFee && dbFee.maker_fee == maker_fee && dbFee.taker_fee == taker_fee) {
return true;
}
//现货默认费率
if (product_type == 'spot' && maker_fee == 0.001 && taker_fee == 0.002) {
return true;
}
//合约默认费率
if (product_type == 'lpc' && maker_fee == 0.0004 && taker_fee == 0.0006) {
return true;
}
return false;
}
...@@ -21,15 +21,7 @@ const oneMonth = oneDay * 30; ...@@ -21,15 +21,7 @@ const oneMonth = oneDay * 30;
let inJob = false; let inJob = false;
let limit = 3000; let limit = 3000;
/**
* 注意:
* fee_rate_spot_log
* fee_rate_contract_log
* fee_rate_base_coin_contract_log
* 相关表中不支持 all 或 ALL 交易对
* 管理后台配置用户费率的 all 交易对也是分多个交易对来处理的
* 即(common_user_fee_setting 中的 all 分多个交易对 设置到 fee_rate_log 表中)
*/
let setFeeRateJob = schedule.scheduleJob('*/30 * * * * *', function () { let setFeeRateJob = schedule.scheduleJob('*/30 * * * * *', function () {
if (inJob) { if (inJob) {
......
...@@ -23,15 +23,7 @@ const oneMonth = oneDay * 30; ...@@ -23,15 +23,7 @@ const oneMonth = oneDay * 30;
let inJob = false; let inJob = false;
let limit = 3000; let limit = 3000;
/**
* 注意:
* fee_rate_spot_log
* fee_rate_contract_log
* fee_rate_base_coin_contract_log
* 相关表中不支持 all 或 ALL 交易对
* 管理后台配置用户费率的 all 交易对也是分多个交易对来处理的
* 即(common_user_fee_setting 中的 all 分多个交易对 设置到 fee_rate_log 表中)
*/
let setFeeRateJob = schedule.scheduleJob('*/30 * * * * *', function () { let setFeeRateJob = schedule.scheduleJob('*/30 * * * * *', function () {
if (inJob) { if (inJob) {
......
...@@ -22,15 +22,7 @@ const oneMonth = oneDay * 30; ...@@ -22,15 +22,7 @@ const oneMonth = oneDay * 30;
let inJob = false; let inJob = false;
let limit = 3000; let limit = 3000;
/**
* 注意:
* fee_rate_spot_log
* fee_rate_contract_log
* fee_rate_base_coin_contract_log
* 相关表中不支持all 或 ALL 交易对
* 管理后台配置用户费率的 all 交易对也是分多个交易对来处理的
* 即(common_user_fee_setting 中的 all 分多个交易对 设置到 fee_rate_log 表中)
*/
let setFeeRateJob = schedule.scheduleJob('*/30 * * * * *', function () { let setFeeRateJob = schedule.scheduleJob('*/30 * * * * *', function () {
if (inJob) { if (inJob) {
...@@ -240,7 +232,7 @@ async function setExpiredDefault() { ...@@ -240,7 +232,7 @@ async function setExpiredDefault() {
raw: true, raw: true,
}); });
let defaultFeeObj = {}, max_maker_rate = 0.001, max_taker_rate = 0.002; // 2020.5.9 let defaultFeeObj = {}, max_maker_rate = 0.001, max_taker_rate = 0.002; // 2020.5.9
let activePairs: any = []; let activePairs: any = ['all'];
for (let i = 0; i < defaultPairFee.length; i++) { for (let i = 0; i < defaultPairFee.length; i++) {
let { symbol, maker_fee, taker_fee } = defaultPairFee[i]; let { symbol, maker_fee, taker_fee } = defaultPairFee[i];
......
...@@ -77,4 +77,5 @@ export const ErrorCode = { ...@@ -77,4 +77,5 @@ export const ErrorCode = {
FEE_EX_OR_DEL:'30073',//费率设置已过期或已删除,不可以修改 FEE_EX_OR_DEL:'30073',//费率设置已过期或已删除,不可以修改
PAIR_FORMAT_ERR:'30074',//交易对格式错误 PAIR_FORMAT_ERR:'30074',//交易对格式错误
PAIR_NOT_SUPPORT:'30075',//暂不支持此交易对 PAIR_NOT_SUPPORT:'30075',//暂不支持此交易对
FEE_TOO_LOW_OR_HIGH:'30076',//设置的费率过高/过低
} }
...@@ -140,6 +140,16 @@ async function addParamValid(commonUserFeeVO: CommonUserFeeVO) { ...@@ -140,6 +140,16 @@ async function addParamValid(commonUserFeeVO: CommonUserFeeVO) {
if (pair != 'all'){ if (pair != 'all'){
throw ErrorCode.PAIR_NOT_SUPPORT; throw ErrorCode.PAIR_NOT_SUPPORT;
} }
//校验费率范围
if (type == FEE_TYPE.FEE_TYPE_SPOT){
if (Number(makerFee) < 0.0002 || Number(takerFee) < 0.0005){
throw ErrorCode.FEE_TOO_LOW_OR_HIGH;
}
}else {
if (Number(makerFee) < -0.00015 || Number(takerFee) < 0.00035){
throw ErrorCode.FEE_TOO_LOW_OR_HIGH;
}
}
await checkMaker(commonUserFeeVO); await checkMaker(commonUserFeeVO);
await paramCheck(beginTime, expireTime, Number(type), userId); await paramCheck(beginTime, expireTime, Number(type), userId);
......
...@@ -108,7 +108,7 @@ export async function dealReturnData(resList: any) { ...@@ -108,7 +108,7 @@ export async function dealReturnData(resList: any) {
for (let item of resList.rows) { for (let item of resList.rows) {
let symbol = item.coin_symbol; let symbol = item.coin_symbol;
let amount = item.amount; let amount = item.amount;
let usdt = usdtTickerMap[symbol] ? usdtTickerMap[symbol] : await tickerUtils._rateCoin2USDT(symbol); let usdt = usdtTickerMap[symbol] ? usdtTickerMap[symbol] : await tickerUtils.rateCoin2USDT(symbol);
usdtTickerMap[symbol] = usdt; usdtTickerMap[symbol] = usdt;
item.equal_usdt = new BigNumber(usdt).mul(amount); item.equal_usdt = new BigNumber(usdt).mul(amount);
} }
......
...@@ -13,6 +13,7 @@ import BigNumber from "bignumber.js"; ...@@ -13,6 +13,7 @@ import BigNumber from "bignumber.js";
let _ = require('lodash'); let _ = require('lodash');
let { tickerUtils } = require('@madex/ex-js-common'); let { tickerUtils } = require('@madex/ex-js-common');
let { datetimeUtils } = require('@madex/ex-js-public');
export interface QueryVO { export interface QueryVO {
...@@ -65,9 +66,9 @@ export async function increaseUserList(pageVO: QueryVO) { ...@@ -65,9 +66,9 @@ export async function increaseUserList(pageVO: QueryVO) {
export async function tradeUserList(pageVO: QueryVO) { export async function tradeUserList(pageVO: QueryVO) {
let where:any = { let where: any = {
type:0,//UTC 0 type: 0,//UTC 0
category:1,//现货 category: 1,//现货
[dwsMadOrmDB.Op.and]: [ [dwsMadOrmDB.Op.and]: [
{ {
trade_date: { [dwsMadOrmDB.Op.gte]: pageVO.from_time } trade_date: { [dwsMadOrmDB.Op.gte]: pageVO.from_time }
...@@ -79,7 +80,7 @@ export async function tradeUserList(pageVO: QueryVO) { ...@@ -79,7 +80,7 @@ export async function tradeUserList(pageVO: QueryVO) {
let resList: any = []; let resList: any = [];
if (!pageVO.is_export) { if (!pageVO.is_export) {
resList = await dwsUserDailyTrade.prototype.findAndCount({ resList = await dwsUserDailyTrade.prototype.findAndCount({
attributes:['user_id',dwsMadOrmDB.literal('sum(equal_usdt + equal_usdt_free) as trade_amount')], attributes: ['user_id', dwsMadOrmDB.literal('sum(equal_usdt + equal_usdt_free) as trade_amount')],
where: where, where: where,
limit: pageVO.size, limit: pageVO.size,
offset: (Number(pageVO.page) - 1) * Number(pageVO.size), offset: (Number(pageVO.page) - 1) * Number(pageVO.size),
...@@ -89,23 +90,23 @@ export async function tradeUserList(pageVO: QueryVO) { ...@@ -89,23 +90,23 @@ export async function tradeUserList(pageVO: QueryVO) {
}); });
resList.count = resList.count.length; resList.count = resList.count.length;
let uids = resList.rows.map(item => item.user_id); let uids = resList.rows.map(item => item.user_id);
if (uids){ if (uids) {
where["user_id"] = uids where["user_id"] = uids
await dealFeeData(where,resList.rows); await dealFeeData(where, resList.rows);
} }
} }
else {//导出不分页 else {//导出不分页
resList = await dwsUserDailyTrade.prototype.findAll({ resList = await dwsUserDailyTrade.prototype.findAll({
attributes:['user_id',dwsMadOrmDB.literal('sum(equal_usdt + equal_usdt_free) as trade_amount')], attributes: ['user_id', dwsMadOrmDB.literal('sum(equal_usdt + equal_usdt_free) as trade_amount')],
where: where, where: where,
order: [["trade_amount", "desc"]], order: [["trade_amount", "desc"]],
group: ['user_id'], group: ['user_id'],
raw: true raw: true
}); });
let uids = resList.map(item => item.user_id); let uids = resList.map(item => item.user_id);
if (uids){ if (uids) {
where["user_id"] = uids where["user_id"] = uids
await dealFeeData(where,resList); await dealFeeData(where, resList);
} }
} }
return resList; return resList;
...@@ -288,15 +289,63 @@ export async function userDepositAndWithdrawList(pageVO: QueryVO) { ...@@ -288,15 +289,63 @@ export async function userDepositAndWithdrawList(pageVO: QueryVO) {
export async function gatherData(pageVO: QueryVO) { export async function gatherData(pageVO: QueryVO) {
let [increaseCount, tradeCount, activeCount, depositAndWithdraw] = let [increaseObj, tradeObj, activeObj, depositAndWithdrawObj] =
await Promise.all([increaseUserCount(pageVO), tradeUserCount(pageVO), activeUserCount(pageVO), depositAndWithdrawCount(pageVO)]); await Promise.all([increaseUserCount(pageVO), tradeUserCount(pageVO), activeUserCount(pageVO), depositAndWithdrawCount(pageVO)]);
//处理日期
let daysArr = getAllDay(pageVO.from_time, pageVO.to_time);
let increase_data: any = [];
let trade_data: any = [];
let active_data: any = [];
let deposit_data: any = [];
let withdraw_data: any = [];
let deposit_withdraw_data: any = [];
for (let item of daysArr) {
increase_data.push({
time: item,
data: increaseObj.increaseDataMap[item] || 0
})
trade_data.push({
time: item,
data: tradeObj.tradeDataMap[item] || 0
})
active_data.push({
time: item,
data: activeObj.activeDataMap[item] || 0
})
deposit_data.push({
time: item,
data: depositAndWithdrawObj.depositDataMap[item] || 0
})
withdraw_data.push({
time: item,
data: depositAndWithdrawObj.withdrawDataMap[item] || 0
})
deposit_withdraw_data.push({
time: item,
data: depositAndWithdrawObj.depositWithdrawDataMap[item] || 0
})
}
return { return {
increase: increaseCount, increase: increaseObj.increaseCount,
trade: tradeCount, increase_data,
active: activeCount, trade: tradeObj.tradeCount,
deposit: depositAndWithdraw.deposit, trade_data,
withdraw: depositAndWithdraw.withdraw, active: activeObj.activeCount,
deposit_withdraw: depositAndWithdraw.deposit_withdraw, active_data,
deposit: depositAndWithdrawObj.deposit,
deposit_data,
withdraw: depositAndWithdrawObj.withdraw,
withdraw_data,
deposit_withdraw: depositAndWithdrawObj.deposit_withdraw,
deposit_withdraw_data
} }
} }
...@@ -311,18 +360,32 @@ async function increaseUserCount(pageVO: QueryVO) { ...@@ -311,18 +360,32 @@ async function increaseUserCount(pageVO: QueryVO) {
createdAt: { [ormDB.Op.lt]: pageVO.to_time }, createdAt: { [ormDB.Op.lt]: pageVO.to_time },
}] }]
} }
let count = await userLog.prototype.count({ let dbDataList = await userLog.prototype.findAll({
attributes: [
ormDB.literal(`DATE_FORMAT(createdAt,'%Y-%m-%d') AS dt`),
ormDB.literal('COUNT(1) AS count')
],
where: where, where: where,
group: [`dt`],
raw: true raw: true
}); });
return count; let dataMap: any = {};
let count = 0;
for (let item of dbDataList) {
count += item.count;
dataMap[item.dt] = item.count;
}
return { increaseCount: count, increaseDataMap: dataMap };
} }
async function tradeUserCount(pageVO: QueryVO) { async function tradeUserCount(pageVO: QueryVO) {
let where:any = { let where: any = {
type:0,//UTC 0 type: 0,//UTC 0
category:1,//现货 category: 1,//现货
[dwsMadOrmDB.Op.and]: [ [dwsMadOrmDB.Op.and]: [
{ {
trade_date: { [dwsMadOrmDB.Op.gte]: pageVO.from_time } trade_date: { [dwsMadOrmDB.Op.gte]: pageVO.from_time }
...@@ -331,18 +394,36 @@ async function tradeUserCount(pageVO: QueryVO) { ...@@ -331,18 +394,36 @@ async function tradeUserCount(pageVO: QueryVO) {
trade_date: { [dwsMadOrmDB.Op.lt]: pageVO.to_time }, trade_date: { [dwsMadOrmDB.Op.lt]: pageVO.to_time },
}] }]
}; };
let dbList = await dwsUserDailyTrade.prototype.findAll({
attributes:[dwsMadOrmDB.literal('distinct(user_id) as user_id')], let dbDataList = await dwsUserDailyTrade.prototype.findAll({
where:where, attributes: ['user_id',
raw:true dwsMadOrmDB.literal(`DATE_FORMAT(trade_date,'%Y-%m-%d') AS dt`),
dwsMadOrmDB.literal('sum(equal_usdt + equal_usdt_free) AS amount')],
where: where,
group: [`dt`, 'user_id'],
raw: true
}); });
return dbList.length;
let uidList: any = [];
let dataMap: any = [];
for (let item of dbDataList) {
if (!uidList.includes) {
uidList.push(item.user_id)
}
dataMap[item.dt] = dataMap[item.dt] ? Number(dataMap[item.dt]) + Number(item.amount) : Number(item.amount)
}
return {
tradeCount: uidList.length, tradeDataMap: dataMap
};
} }
async function activeUserCount(pageVO: QueryVO) { async function activeUserCount(pageVO: QueryVO) {
let count_sql = `SELECT COUNT(*) AS num let count_sql = `SELECT DATE_FORMAT(t2.createdAt, '%Y-%m-%d') AS dt, COUNT(t2.user_id) AS num
FROM user_log AS t1 FROM user_log AS t1
INNER JOIN INNER JOIN
(SELECT user_id, MAX(createdAt) AS createdAt (SELECT user_id, MAX(createdAt) AS createdAt
...@@ -350,11 +431,20 @@ async function activeUserCount(pageVO: QueryVO) { ...@@ -350,11 +431,20 @@ async function activeUserCount(pageVO: QueryVO) {
WHERE type = 0 WHERE type = 0
AND createdAt >= '${pageVO.from_time}' AND createdAt >= '${pageVO.from_time}'
AND createdAt < '${pageVO.to_time}' AND createdAt < '${pageVO.to_time}'
GROUP BY user_id) AS t2 ON t1.user_id = t2.user_id AND t1.createdAt = t2.createdAt`; GROUP BY user_id) AS t2 ON t1.user_id = t2.user_id AND t1.createdAt = t2.createdAt
GROUP BY dt`;
let dbDataList = await ormDB.query(count_sql, { raw: true, type: ormDB.QueryTypes.SELECT });
let dbCount = await ormDB.query(count_sql, { raw: true, type: ormDB.QueryTypes.SELECT }); let count = 0;
let count = dbCount[0].num; let dataMap: any = {}
return count; for (let item of dbDataList) {
count += item.num;
dataMap[item.dt] = item.num;
}
return {
activeCount: count, activeDataMap: dataMap
};
} }
async function depositAndWithdrawCount(pageVO: QueryVO) { async function depositAndWithdrawCount(pageVO: QueryVO) {
...@@ -362,6 +452,9 @@ async function depositAndWithdrawCount(pageVO: QueryVO) { ...@@ -362,6 +452,9 @@ async function depositAndWithdrawCount(pageVO: QueryVO) {
deposit: new BigNumber(0), deposit: new BigNumber(0),
withdraw: new BigNumber(0), withdraw: new BigNumber(0),
deposit_withdraw: new BigNumber(0), deposit_withdraw: new BigNumber(0),
depositDataMap: {},
withdrawDataMap: {},
depositWithdrawDataMap: {},
} }
let where = { let where = {
type: { [ormDB.Op.in]: [100, 102] },//充值、提现 type: { [ormDB.Op.in]: [100, 102] },//充值、提现
...@@ -375,13 +468,17 @@ async function depositAndWithdrawCount(pageVO: QueryVO) { ...@@ -375,13 +468,17 @@ async function depositAndWithdrawCount(pageVO: QueryVO) {
}]; }];
let amountList = await mainUserBills.prototype.findAll({ let amountList = await mainUserBills.prototype.findAll({
attributes: ['symbol', attributes: ['symbol',
ormDB.literal(`DATE_FORMAT(createdAt,'%Y-%m-%d') AS dt`),
ormDB.literal('sum(case when type = 100 then ABS(`change`) else 0 end) as deposit_amount'), ormDB.literal('sum(case when type = 100 then ABS(`change`) else 0 end) as deposit_amount'),
ormDB.literal('sum(case when type = 102 then ABS(`change`) else 0 end) as withdraw_amount'), ormDB.literal('sum(case when type = 102 then ABS(`change`) else 0 end) as withdraw_amount'),
], ],
where: where, where: where,
group: ['symbol'], group: [`dt`, 'symbol'],
raw: true raw: true
}); });
let depositDataMap: any = {};
let withdrawDataMap: any = {};
let depositWithdrawDataMap: any = {};
if (amountList.length) { if (amountList.length) {
let deposit_usdt = new BigNumber(0); let deposit_usdt = new BigNumber(0);
let withdraw_usdt = new BigNumber(0); let withdraw_usdt = new BigNumber(0);
...@@ -389,18 +486,31 @@ async function depositAndWithdrawCount(pageVO: QueryVO) { ...@@ -389,18 +486,31 @@ async function depositAndWithdrawCount(pageVO: QueryVO) {
let symbol = item.symbol; let symbol = item.symbol;
let deposit_amount = item.deposit_amount; let deposit_amount = item.deposit_amount;
let withdraw_amount = item.withdraw_amount; let withdraw_amount = item.withdraw_amount;
let usdt = await tickerUtils._rateCoin2USDT(symbol); let usdt = await tickerUtils.rateCoin2USDT(symbol);
let deposit_amount_usdt = new BigNumber(deposit_amount).mul(new BigNumber(usdt)); let deposit_amount_usdt = new BigNumber(deposit_amount).mul(new BigNumber(usdt));
deposit_usdt = deposit_usdt.add(deposit_amount_usdt); deposit_usdt = deposit_usdt.add(deposit_amount_usdt);
depositDataMap[item.dt] = depositDataMap[item.dt] ? depositDataMap[item.dt].add(deposit_amount_usdt) : deposit_amount_usdt;
let withdraw_amount_usdt = new BigNumber(withdraw_amount).mul(new BigNumber(usdt)); let withdraw_amount_usdt = new BigNumber(withdraw_amount).mul(new BigNumber(usdt));
withdraw_usdt = withdraw_usdt.add(withdraw_amount_usdt); withdraw_usdt = withdraw_usdt.add(withdraw_amount_usdt);
withdrawDataMap[item.dt] = withdrawDataMap[item.dt] ? withdrawDataMap[item.dt].add(withdraw_amount_usdt) : withdraw_amount_usdt;
let d_w_usdt = deposit_amount_usdt.sub(withdraw_amount_usdt);
depositWithdrawDataMap[item.dt] = depositWithdrawDataMap[item.dt] ? depositWithdrawDataMap[item.dt].add(d_w_usdt) : d_w_usdt;
} }
let deposit_withdraw_usdt = deposit_usdt.sub(withdraw_usdt); let deposit_withdraw_usdt = deposit_usdt.sub(withdraw_usdt);
res.deposit = deposit_usdt; res.deposit = deposit_usdt;
res.withdraw = withdraw_usdt; res.withdraw = withdraw_usdt;
res.deposit_withdraw = deposit_withdraw_usdt; res.deposit_withdraw = deposit_withdraw_usdt;
res.depositDataMap = depositDataMap;
res.withdrawDataMap = withdrawDataMap;
res.depositWithdrawDataMap = depositWithdrawDataMap;
} }
return res; return res;
} }
...@@ -451,7 +561,7 @@ async function dealDepositOrWithdrawReturnData(resList: any) { ...@@ -451,7 +561,7 @@ async function dealDepositOrWithdrawReturnData(resList: any) {
for (let item of resList) { for (let item of resList) {
let symbol = item.symbol; let symbol = item.symbol;
let change = item.change; let change = item.change;
let usdt = usdtTickerMap[symbol] ? usdtTickerMap[symbol] : await tickerUtils._rateCoin2USDT(symbol); let usdt = usdtTickerMap[symbol] ? usdtTickerMap[symbol] : await tickerUtils.rateCoin2USDT(symbol);
usdtTickerMap[symbol] = usdt; usdtTickerMap[symbol] = usdt;
item.equal_usdt = new BigNumber(usdt).mul(change); item.equal_usdt = new BigNumber(usdt).mul(change);
} }
...@@ -465,7 +575,7 @@ async function dealDepositAndWithdrawReturnData(resList: any) { ...@@ -465,7 +575,7 @@ async function dealDepositAndWithdrawReturnData(resList: any) {
let symbol = item.symbol; let symbol = item.symbol;
let deposit_amount = item.deposit_amount; let deposit_amount = item.deposit_amount;
let withdraw_amount = item.withdraw_amount; let withdraw_amount = item.withdraw_amount;
let usdt = usdtTickerMap[symbol] ? usdtTickerMap[symbol] : await tickerUtils._rateCoin2USDT(symbol); let usdt = usdtTickerMap[symbol] ? usdtTickerMap[symbol] : await tickerUtils.rateCoin2USDT(symbol);
usdtTickerMap[symbol] = usdt; usdtTickerMap[symbol] = usdt;
item.deposit_usdt = new BigNumber(usdt).mul(deposit_amount); item.deposit_usdt = new BigNumber(usdt).mul(deposit_amount);
item.withdraw_usdt = new BigNumber(usdt).mul(withdraw_amount); item.withdraw_usdt = new BigNumber(usdt).mul(withdraw_amount);
...@@ -474,14 +584,14 @@ async function dealDepositAndWithdrawReturnData(resList: any) { ...@@ -474,14 +584,14 @@ async function dealDepositAndWithdrawReturnData(resList: any) {
} }
} }
async function dealFeeData(where:any,dbList:any){ async function dealFeeData(where: any, dbList: any) {
let dbFeeList = await dwsUserDailyFee.prototype.findAll({ let dbFeeList = await dwsUserDailyFee.prototype.findAll({
attributes:['user_id',dwsMadOrmDB.literal('sum(equalusdt_amount) as fee_amount')], attributes: ['user_id', dwsMadOrmDB.literal('sum(equalusdt_amount) as fee_amount')],
where: where, where: where,
group:['user_id'], group: ['user_id'],
raw: true raw: true
}); });
let fee_map:any = {}; let fee_map: any = {};
for (let item of dbFeeList) { for (let item of dbFeeList) {
fee_map[item.user_id] = item.fee_amount; fee_map[item.user_id] = item.fee_amount;
} }
...@@ -490,6 +600,27 @@ async function dealFeeData(where:any,dbList:any){ ...@@ -490,6 +600,27 @@ async function dealFeeData(where:any,dbList:any){
} }
} }
/**
* 获取开始到结束每一天
* @param start
* @param end
*/
function getAllDay(start: any, end: any) {
let startTime = datetimeUtils.trim(start, 'd');
let endTime = datetimeUtils.trim(end, 'd');
let dateArr: any = [];
while ((endTime.getTime() - startTime.getTime()) > 0) {
let year = startTime.getFullYear();
let month = (startTime.getMonth() + 1).toString().length === 1 ? "0" + (parseInt(startTime.getMonth().toString(), 10) + 1) : (startTime.getMonth() + 1);
let day = startTime.getDate().toString().length === 1 ? "0" + startTime.getDate() : startTime.getDate();
dateArr.push(year + "-" + month + "-" + day);
startTime.setDate(startTime.getDate() + 1);
}
return dateArr;
}
//let allDay = getAllDay("2024-11-11T00:00:00.000Z","2024-11-11T23:59:59.999Z");
......
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