feat(score): transfer users score with fixed ratio to inviter per month first day

This commit is contained in:
OldHawk
2018-05-24 18:55:07 +08:00
parent 9931c82626
commit 00e15a6757
2 changed files with 67 additions and 7 deletions

View File

@@ -428,21 +428,31 @@ module.exports = {
*
* score system settings
*
* @levelStep: value of each level step, default 500
* @scoreLogDays: setting of days to write score detail log to db, because the data is too more too big, do not to set a big value
* @action: score change action list
* @name: action name
* @value: action score value
* @enable: action enable status, if false, system will not change user`s score at this action
* NOTE: ENABLE VALUE OF DEFAULTACTION MUST BE TRUE
* @levelStep: value of each level step, default 500
* @scoreLogDays: setting of days to write score detail log to db, because the data is too more too big, do not to set a big value
* @transfer: setting of transfer score to inviter per month
* @enable: setting whether to enable transfer
* @transRatio: setting transfer ratio, the user`s score of this ratio will be subtract and add into the inviter`s account
* @action: score change action list
* @name: action name
* @value: action score value
* @enable: action enable status, if false, system will not change user`s score at this action
* NOTE: ENABLE VALUE OF DEFAULTACTION MUST BE TRUE
*/
score: {
levelStep: 1000,
scoreLogDays: 10,
transfer: {
enable: true,
transRatio: 0.05
},
action: {
defaultAction: {name: 'defaultAction', value: 0, enable: true},
adminModify: {name: 'adminModify', value: 0, enable: true},
transferScoreIntoInviterFrom: {name: 'transferScoreIntoInviterFrom', value: 0, enable: true},
transferScoreIntoInviterTo: {name: 'transferScoreIntoInviterTo', value: 0, enable: true},
uploadTorrent: {name: 'uploadTorrent', value: 50, enable: true},
uploadTorrentBeDeleted: {name: 'uploadTorrentBeDeleted', value: -50, enable: true},
uploadTorrentBeRecommend: {name: 'uploadTorrentBeRecommend', value: 10, enable: true},

View File

@@ -20,6 +20,7 @@ var path = require('path'),
UserMonthsLog = mongoose.model('UserMonthsLog'),
ScoreLog = mongoose.model('ScoreLog'),
Trace = mongoose.model('Trace'),
scoreUpdate = require(path.resolve('./config/lib/score')).update,
backup = require('mongodb-backup');
var mtDebug = require(path.resolve('./config/lib/debug'));
@@ -89,6 +90,10 @@ module.exports = function (app) {
cronJobs.push(countUsersHnrWarning());
}
if (scoreConfig.transfer.enable) {
cronJobs.push(transferUserScoreToInviter());
}
if (supportConfig.mailTicketSupportService) {
cronJobs.push(listenServiceEmail());
}
@@ -339,6 +344,51 @@ function countUsersHnrWarning() {
return cronJob;
}
/**
* transferUserScoreToInviter
*/
function transferUserScoreToInviter() {
var cronJob = new CronJob({
cronTime: '00 00 2 1 * *',
onTick: function () {
logger.info(chalk.green('transferUserScoreToInviter: process!'));
var mom = moment().utcOffset(appConfig.dbTimeZone);
var y = mom.get('year');
var m = mom.get('month') + 1;
UserMonthsLog.find({
year: y,
month: m - 1
}).populate({
path: 'user',
select: 'username displayName profileImageURL isVip score uploaded downloaded invited_by',
populate: {
path: 'invited_by',
select: 'username displayName profileImageURL isVip score uploaded downloaded'
}
}).exec(function (err, logs) {
if (logs) {
logs.forEach(function (l) {
if (l.score > 0 && l.user.invited_by) {
var transValue = Math.round(l.score * scoreConfig.transfer.transRatio * 100) / 100;
scoreUpdate(undefined, l.user, scoreConfig.action.transferScoreIntoInviterFrom, -(transValue));
scoreUpdate(undefined, l.user.invited_by, scoreConfig.action.transferScoreIntoInviterTo, transValue);
}
});
}
});
},
start: false,
timeZone: appConfig.cronTimeZone
});
cronJob.start();
return cronJob;
}
/**
* listenServiceEmail
*/