fix: deposit award

This commit is contained in:
chaosBreaking
2019-09-29 21:53:39 +08:00
parent a31f095699
commit 624f34e1ed
2 changed files with 31 additions and 2 deletions

View File

@@ -13,6 +13,7 @@ function createAction (actCode, data) {
case 1: return createMineRewardAction(data); case 1: return createMineRewardAction(data);
case 2: return createGroupRewardAction(data); case 2: return createGroupRewardAction(data);
case 3: return createWithdrawAction(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 = { module.exports = {
createAction, createAction,
}; };

View File

@@ -143,14 +143,28 @@ FundModel.prototype.addFund = async function (txlist = [], option) {
const myId = this.userId; const myId = this.userId;
User.findById(myId).then(async user => { User.findById(myId).then(async user => {
if (!user && !user.inviter) return 0; if (!user && !user.inviter) return 0;
const award = +newSum * 0.1;
const inviteFund = createNewFund({ const inviteFund = createNewFund({
amount: +newSum * 0.1, amount: award,
blockNumber: 'followerReward', blockNumber: 'followerReward',
hash: myId hash: myId
}); });
User.findByIdAndUpdate(user.inviter, { 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; return res;
}; };