From 624f34e1ed2e300c8cce38652667237b624eaa07 Mon Sep 17 00:00:00 2001 From: chaosBreaking Date: Sun, 29 Sep 2019 21:53:39 +0800 Subject: [PATCH] fix: deposit award --- src/modules/action/action.handler.js | 15 +++++++++++++++ src/modules/fund/fund.model.js | 18 ++++++++++++++++-- 2 files changed, 31 insertions(+), 2 deletions(-) diff --git a/src/modules/action/action.handler.js b/src/modules/action/action.handler.js index 5188f59..34932f0 100644 --- a/src/modules/action/action.handler.js +++ b/src/modules/action/action.handler.js @@ -13,6 +13,7 @@ function createAction (actCode, data) { case 1: return createMineRewardAction(data); case 2: return createGroupRewardAction(data); case 3: return createWithdrawAction(data); + case 4: return createFollerDepositAward(data); } } @@ -70,6 +71,20 @@ function createWithdrawAction(data = {}) { }); } +function createFollerDepositAward(data = {}) { + // 充值奖励推荐人 + const { userId, amount, remain, tokenType, detail = {} } = data; + return new Action({ + userId, + type: 4, + op: 1, + amount, + remain, + tokenType, + detail + }); +} + module.exports = { createAction, }; diff --git a/src/modules/fund/fund.model.js b/src/modules/fund/fund.model.js index 6c57c28..95728b0 100644 --- a/src/modules/fund/fund.model.js +++ b/src/modules/fund/fund.model.js @@ -143,14 +143,28 @@ FundModel.prototype.addFund = async function (txlist = [], option) { const myId = this.userId; User.findById(myId).then(async user => { if (!user && !user.inviter) return 0; + const award = +newSum * 0.1; const inviteFund = createNewFund({ - amount: +newSum * 0.1, + amount: award, blockNumber: 'followerReward', hash: myId }); User.findByIdAndUpdate(user.inviter, { - $push: inviteFund + $push: { + fundList: inviteFund + } }); + createAction(4, { + userId: myId, + amount: award, // 充值记录的数值仍然是区块链的数值 + tokenType: 'vic', // 目前设定只能挖出矿晶vic + remain: this.asset, + detail: { + desc: `${user.id}挖矿充值奖励其推荐人${user.inviter}` + } + }).save(); + }).catch(err => { + mylog.error(`${myId}充值奖励其推荐人时出错 `, JSON.stringify(err)); }); return res; };