feat: 修改job

This commit is contained in:
chaosBreaking
2019-09-29 10:32:14 +08:00
parent a1be616abc
commit b4b70bcc92

View File

@@ -23,7 +23,24 @@ const { createAction } = require('../modules/action/action.handler');
const { createNewFund } = require('../modules/fund/fund.handler'); const { createNewFund } = require('../modules/fund/fund.handler');
const tokenReleaseRate = 0.2; const tokenReleaseRate = 0.2;
async function awardMine(user, fund, i) {
const released = fund.releasedAmout || 0;
if (released === fund.releasedAmout) {
await Fund.findByIdAndUpdate(fund.id, {
$set: {
[`fundList.${i}.status`]: 2 //标记失效
}
});
return 0;
}
const rewardMine = +fund.amount * tokenReleaseRate;
return rewardMine;
}
function awardInvite(user, fund, allInviteReward) {
const rewardInvite = allInviteReward - (fund.option.usedGroupReward || 0); // 求增量: 总额 - 已领取总额(fundSum)
// 挖矿奖励 = 充值金额奖励 + 社区奖励
return rewardInvite;
}
// fund.option.usedGroupReward : 已领取的社群奖励总额 // fund.option.usedGroupReward : 已领取的社群奖励总额
const doReward = async (user, fund) => { const doReward = async (user, fund) => {
// 1.对于充值的fundList的每一项按照2%进行发放累加到asset.vic添加action类型为1 // 1.对于充值的fundList的每一项按照2%进行发放累加到asset.vic添加action类型为1
@@ -32,19 +49,9 @@ const doReward = async (user, fund) => {
const fundlist = fund.fundList; const fundlist = fund.fundList;
for (let i = 0, len = fundlist.length; i < len; ++i) { for (let i = 0, len = fundlist.length; i < len; ++i) {
const fund = fundlist[i]; const fund = fundlist[i];
const released = fund.releasedAmout || 0; const allInviteReward = (+user.group.length || 0) * 10;
if (released === fund.releasedAmout) { const rewardMine = awardMine(user, fund, i);
await Fund.findByIdAndUpdate(fund.id, { const rewardInvite = awardInvite(user, fund, allInviteReward);
$set: {
[`fundList.${i}.status`]: 2 //标记失效
}
});
continue;
}
const allInviteReward = (+user.group.length || 0) * 10; // 计算出从开始到现在邀请奖励总额
const rewardInvite = allInviteReward - (fund.option.usedGroupReward || 0); // 求增量: 总额 - 已领取总额(fundSum)
// 挖矿奖励 = 充值金额奖励 + 社区奖励
const rewardMine = +fund.amount * tokenReleaseRate;
const reward = rewardMine + rewardInvite; const reward = rewardMine + rewardInvite;
await Fund.findByIdAndUpdate(fund.id, { await Fund.findByIdAndUpdate(fund.id, {
$inc: { $inc: {
@@ -55,7 +62,7 @@ const doReward = async (user, fund) => {
'asset.usdt': allInviteReward // 用来记录所有社群奖励总额 'asset.usdt': allInviteReward // 用来记录所有社群奖励总额
} }
}).then(() => { }).then(() => {
createAction(1, { rewardMine > 0 && createAction(1, {
userId: fund.userId, userId: fund.userId,
tokenType: 'vic', tokenType: 'vic',
amount: rewardMine, amount: rewardMine,
@@ -83,7 +90,8 @@ const jobs = [
if (typeof currentIndex !== 'number') { if (typeof currentIndex !== 'number') {
currentIndex = 0; currentIndex = 0;
await new system({ await new system({
key: currentIndex key: 'userIndex4job',
value: currentIndex
}).save(); }).save();
} }