From 68b56e26f109804b25954e33e29a717ef454701b Mon Sep 17 00:00:00 2001 From: chaosBreaking Date: Mon, 30 Sep 2019 13:20:08 +0800 Subject: [PATCH] right reduce --- src/modules/fund/fund.controller.js | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/modules/fund/fund.controller.js b/src/modules/fund/fund.controller.js index 4884464..687f475 100644 --- a/src/modules/fund/fund.controller.js +++ b/src/modules/fund/fund.controller.js @@ -233,6 +233,7 @@ module.exports = { const { hasNew, list } = await fund.hasNewDeposit(); const [ start, end ] = getDate(1); let now = new Date(); + const allAction = await Action.find({ userId, type: 1 }).exec(); if (!hasNew) { // const [ start, end ] = getDate(1); const actions = await Action.find({ userId, type: 1, createdAt: { $gt: start, $lt: now } }); @@ -240,7 +241,8 @@ module.exports = { let revenueLastday = calRevenueLastday(actions); // 筛选有效矿晶 let activeFund = getActiveFund(fund.fundList); - const revenueAll = fund.asset && +fund.asset['vic'] || 0; + let revenueAll = Array.isArray(allAction) && allAction.reduce((pre, cur) => pre + (+cur.amount || 0), 0) || 0; + revenueAll = revenueAll.toFixed(4); return res.json({ code: 0, msg: '刷新成功', @@ -263,7 +265,8 @@ module.exports = { // 筛选有效矿晶 let activeFund = getActiveFund(fund.fundList); if (!newFund || !newFund.fundList) newFund = fund; - const revenueAll = fund.asset && +fund.asset['vic'] || 0; + let revenueAll = Array.isArray(allAction) && allAction.reduce((pre, cur) => pre + (+cur.amount || 0), 0) || 0; + revenueAll = revenueAll.toFixed(4); return res.json({ code: 0, msg: '刷新成功', @@ -303,8 +306,8 @@ module.exports = { const allAction = await Action.find({ userId, type: 1 }).exec(); // 计算昨日收益 let revenueLastday = calRevenueLastday(actions); - const revenueAll = Array.isArray(allAction) && allAction.reduce((pre, cur) => (pre.amount && +pre.amount || 0) + (pre.amount && +cur.amount || 0), 0) || 0; - // const revenueAll = fund.asset && +fund.asset['vic'] || 0; + let revenueAll = Array.isArray(allAction) && allAction.reduce((pre, cur) => pre + (+cur.amount || 0), 0) || 0; + revenueAll = revenueAll.toFixed(4); return res.json({ code: 0, data: {