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;