From ef1da0c6d60dc79b7b3fe2d1f068ac5947a63876 Mon Sep 17 00:00:00 2001 From: chaosBreaking Date: Sat, 28 Sep 2019 23:40:54 +0800 Subject: [PATCH] =?UTF-8?q?feat:=E6=9B=B4=E6=94=B9addFund=EF=BC=8C?= =?UTF-8?q?=E7=BB=99=E9=82=80=E8=AF=B7=E4=BA=BA=E5=8A=A0=E6=8C=96=E7=9F=BF?= =?UTF-8?q?=E5=A5=96=E5=8A=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/modules/fund/fund.model.js | 26 +++++++++++++++++++------- 1 file changed, 19 insertions(+), 7 deletions(-) diff --git a/src/modules/fund/fund.model.js b/src/modules/fund/fund.model.js index 0585fb8..8670949 100644 --- a/src/modules/fund/fund.model.js +++ b/src/modules/fund/fund.model.js @@ -5,6 +5,7 @@ const ASSETTYPES = ['gin', 'vic', 'usdtBTC', 'usdtETH', 'usdtTRX']; const { createAction } = require('../action/action.handler'); const { createNewFund } = require('./fund.handler'); const { getNewDepositTx, getUSDTTxList } = require('../../common/deposit'); +const User = require('../user/user.model'); const USDT2VIC_RATE = 100; @@ -27,6 +28,7 @@ const FundSchema = new mongoose.Schema({ default: [] }, // fundSum, 用户充值的总usdt数 + // fundSum 目前被用来记录邀请人奖励!!! fundSum: { type: Number, default: 0 @@ -92,7 +94,7 @@ FundModel.prototype.hasNewDeposit = async function () { • 如果直接上家不是金,就平分 3% 给上线所有银会员 • 2% 给上线所有金会员平分 */ -FundModel.prototype.addFund = async function (txlist = [], option) { +FundModel.prototype.addFund = async (txlist = [], option) => { let newSum = 0; const actionPromiseList = []; const newFundList = txlist.map(txObj => { @@ -124,20 +126,30 @@ FundModel.prototype.addFund = async function (txlist = [], option) { // 2.记录action Promise.all(actionPromiseList).catch(err => { - throw new Error('充值行为记录失败', err.errmsg); + mylog.error('充值行为记录失败', err.errmsg); }); - // 3.增加上家团队总额 FundModel.findOneAndUpdate({ userId: option.inviter }, { $inc: { groupFundSum: newSum } + }).exec(); + // 3.对于自己的邀请者进行奖励,按照自己充值金额的十分之一,累加到邀请人的fundList里,类型为1 + const myId = this.userId; + User.findById(myId).then(async user => { + if (!user && !user.inviter) return 0; + const inviteFund = createNewFund({ + amount: +newSum * 0.1, + blockNumber: 'followerReward', + hash: myId + }); + User.findByIdAndUpdate(user.inviter, { + $push: inviteFund + }); }); - // 4.奖励团队 - // todo return res; }; -FundModel.prototype.increase = async function (assetName, amount, option = {}) { +FundModel.prototype.increase = async (assetName, amount, option = {}) => { if (!assetName || !amount || amount <= 0 || !Number.isFinite(amount) || !ASSETTYPES.includes(assetName)) return null; const asset = 'asset.' + assetName; const res = await FundModel.findByIdAndUpdate(this.id, { @@ -150,7 +162,7 @@ FundModel.prototype.increase = async function (assetName, amount, option = {}) { if (res.asset[assetName] < 0) throw new Error('Insufficient funds'); return res; }; -FundModel.prototype.decrease = async function (assetName, amount, option) { +FundModel.prototype.decrease = async (assetName, amount, option) => { // 传入的amount应该是大于0的正数 if (!assetName || !amount || amount <= 0 || !Number.isFinite(amount) || !ASSETTYPES.includes(assetName)) return null; amount = 0 - amount;