feat:更改addFund,给邀请人加挖矿奖励

This commit is contained in:
chaosBreaking
2019-09-28 23:40:54 +08:00
parent 9b2fe61d84
commit ef1da0c6d6

View File

@@ -5,6 +5,7 @@ const ASSETTYPES = ['gin', 'vic', 'usdtBTC', 'usdtETH', 'usdtTRX'];
const { createAction } = require('../action/action.handler'); const { createAction } = require('../action/action.handler');
const { createNewFund } = require('./fund.handler'); const { createNewFund } = require('./fund.handler');
const { getNewDepositTx, getUSDTTxList } = require('../../common/deposit'); const { getNewDepositTx, getUSDTTxList } = require('../../common/deposit');
const User = require('../user/user.model');
const USDT2VIC_RATE = 100; const USDT2VIC_RATE = 100;
@@ -27,6 +28,7 @@ const FundSchema = new mongoose.Schema({
default: [] default: []
}, },
// fundSum, 用户充值的总usdt数 // fundSum, 用户充值的总usdt数
// fundSum 目前被用来记录邀请人奖励!!!
fundSum: { fundSum: {
type: Number, type: Number,
default: 0 default: 0
@@ -92,7 +94,7 @@ FundModel.prototype.hasNewDeposit = async function () {
• 如果直接上家不是金,就平分 3% 给上线所有银会员 • 如果直接上家不是金,就平分 3% 给上线所有银会员
• 2% 给上线所有金会员平分 • 2% 给上线所有金会员平分
*/ */
FundModel.prototype.addFund = async function (txlist = [], option) { FundModel.prototype.addFund = async (txlist = [], option) => {
let newSum = 0; let newSum = 0;
const actionPromiseList = []; const actionPromiseList = [];
const newFundList = txlist.map(txObj => { const newFundList = txlist.map(txObj => {
@@ -124,20 +126,30 @@ FundModel.prototype.addFund = async function (txlist = [], option) {
// 2.记录action // 2.记录action
Promise.all(actionPromiseList).catch(err => { Promise.all(actionPromiseList).catch(err => {
throw new Error('充值行为记录失败', err.errmsg); mylog.error('充值行为记录失败', err.errmsg);
}); });
// 3.增加上家团队总额 // 3.增加上家团队总额
FundModel.findOneAndUpdate({ userId: option.inviter }, { FundModel.findOneAndUpdate({ userId: option.inviter }, {
$inc: { $inc: {
groupFundSum: newSum 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; 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; if (!assetName || !amount || amount <= 0 || !Number.isFinite(amount) || !ASSETTYPES.includes(assetName)) return null;
const asset = 'asset.' + assetName; const asset = 'asset.' + assetName;
const res = await FundModel.findByIdAndUpdate(this.id, { 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'); if (res.asset[assetName] < 0) throw new Error('Insufficient funds');
return res; return res;
}; };
FundModel.prototype.decrease = async function (assetName, amount, option) { FundModel.prototype.decrease = async (assetName, amount, option) => {
// 传入的amount应该是大于0的正数 // 传入的amount应该是大于0的正数
if (!assetName || !amount || amount <= 0 || !Number.isFinite(amount) || !ASSETTYPES.includes(assetName)) return null; if (!assetName || !amount || amount <= 0 || !Number.isFinite(amount) || !ASSETTYPES.includes(assetName)) return null;
amount = 0 - amount; amount = 0 - amount;