feat: 充值查询+刷新

This commit is contained in:
chaosBreaking
2019-09-08 17:24:36 +08:00
parent 8edcc85903
commit 383e24fbfa
9 changed files with 173 additions and 40 deletions

View File

@@ -10,6 +10,8 @@ const actionFilter = 'id type amount detail op createdAt';
const { inject } = require('../../common/Provider');
const ETH = require('../../utils/erc20').ERC20;
const { USDTAddr } = require('../../common/constant');
const { calRevenueLastday, getActiveFund } = require('./fund.handler');
const { getDate } = require('../../utils/date');
const depositCoinsList = [{
id: 'usdtBTC',
@@ -191,14 +193,40 @@ module.exports = {
async refreshFund (req, res) {
// todo: 要求刷新程序去刷新
const { userId } = res.locals.user;
const { inviter } = req.query;
const fund = await Fund.findOne({ userId }).exec();
const tokenAddress = fund && fund.tokenAddress;
if(!tokenAddress || !tokenAddress['usdtETH']) return res.json({
code: 0,
data: fund.fundList
});
const txActions = await ETH.getActions(tokenAddress['usdtETH'], USDTAddr);
return this.getFundList(req, res);
const { hasNew, list } = fund.hasNewDeposit();
if (!hasNew) return res.json({
code: 0,
msg: '刷新成功',
data: {}
});
const [ start, end ] = getDate(1);
const [newFund, actions] = await Promise.all([
fund.addFund(list, { inviter }),
Action.find({ userId, type: 1, createdAt: { $gt: start, $lt: end } })
]);
// 计算昨日收益
let revenueLastday = calRevenueLastday(actions);
// 筛选有效矿晶
let activeFund = getActiveFund(fund.fundList);
return res.json({
code: 0,
msg: '刷新成功',
data: {
list: newFund.fundList,
basic: {
activeFund,
revenueLastday,
revenueAll: newFund.fundSum
}
}
});
},
async getFundList (req, res) {
const { userId } = res.locals.user;
@@ -218,22 +246,12 @@ module.exports = {
async getBasicInfo (req, res) {
const { userId } = res.locals.user;
return Fund.findOne({userId}).then(async fund => {
const start = ''; // 前天
const end = ''; // 昨天
const [ start, end ] = getDate(1);
const actions = await Action.find({ userId, type: 1, createdAt: { $gt: start, $lt: end } }).exec();
// 计算昨日收益
let revenueLastday = 0;
if (actions && actions.length > 0) {
for (let i = actions.length; i >= 0; i--) {
actions[i] && (revenueLastday += actions[i] && +actions[i].amount || 0);
}
}
// 筛选有效矿晶
let activeFund = 0;
for (let i = fund.fundList.length; i >= 0; i--) {
const fundItem = fund.fundList[i];
fundItem && (activeFund += fundItem.status === 1 ? +fundItem.amount : 0);
}
let revenueLastday = calRevenueLastday(actions);
// 筛选有效矿晶
let activeFund = getActiveFund(fund.fundList);
return res.json({
code: 0,
data: {