From 13914b2e36d70f9ab210141be2bb222736b2fb60 Mon Sep 17 00:00:00 2001 From: OldHawk Date: Sat, 26 May 2018 15:07:36 +0800 Subject: [PATCH] fix(score): change score transfer logic --- config/env/torrents.js | 26 ++++++++++++++------------ config/lib/cron-job.js | 12 ++++++++---- 2 files changed, 22 insertions(+), 16 deletions(-) diff --git a/config/env/torrents.js b/config/env/torrents.js index 84c44640..adb6a0fa 100644 --- a/config/env/torrents.js +++ b/config/env/torrents.js @@ -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}, diff --git a/config/lib/cron-job.js b/config/lib/cron-job.js index 74c1e1c5..77efa00c 100644 --- a/config/lib/cron-job.js +++ b/config/lib/cron-job.js @@ -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); + } } }); }