fix(score): change score transfer logic

This commit is contained in:
OldHawk
2018-05-26 15:07:36 +08:00
parent 8a2acb1f1e
commit 13914b2e36
2 changed files with 22 additions and 16 deletions

View File

@@ -434,23 +434,25 @@ 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
* @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
* @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
* @deductFromUser: setting whether deduct the score from user
* @transRatio: setting transfer ratio, the user`s score of this ratio will be subtract and add into the inviter`s account if the @deductFromUser is true
* @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: {
transferToInviter: {
enable: true,
transRatio: 0.05
deductFromUser: false,
transRatio: 0.001
},
action: {
defaultAction: {name: 'defaultAction', value: 0, enable: true},

View File

@@ -92,7 +92,7 @@ module.exports = function (app) {
cronJobs.push(countUsersHnrWarning());
}
if (scoreConfig.transfer.enable) {
if (scoreConfig.transferToInviter.enable) {
cronJobs.push(transferUserScoreToInviter());
}
@@ -401,10 +401,14 @@ function transferUserScoreToInviter() {
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;
var transValue = Math.round(l.score * scoreConfig.transferToInviter.transRatio * 100) / 100;
scoreUpdate(undefined, l.user, scoreConfig.action.transferScoreIntoInviterFrom, -(transValue));
scoreUpdate(undefined, l.user.invited_by, scoreConfig.action.transferScoreIntoInviterTo, transValue);
if (transValue > 0) {
if (scoreConfig.transferToInviter.deductFromUser) {
scoreUpdate(undefined, l.user, scoreConfig.action.transferScoreIntoInviterFrom, -(transValue));
}
scoreUpdate(undefined, l.user.invited_by, scoreConfig.action.transferScoreIntoInviterTo, transValue);
}
}
});
}