-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* 재충전 통화 정의 테이블 추가 * 통화 정의 테이블 수정 * later.js 모듈 추가
- Loading branch information
Showing
9 changed files
with
215 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
'use strict' | ||
|
||
const later = require('later'); | ||
|
||
function GetOffSetTime(time, offsetTime) { | ||
return new Date(time + (offsetTime*3600000)).getTime(); | ||
} | ||
|
||
|
||
/** | ||
* 재충전 가능한 통화의 충전 처리 | ||
* 최대치 충전 주기나 재충전 주기를 고려한다. | ||
* @param OwnCurrencyData {Object} | ||
* @param GameUser {Object} | ||
* @param RechargeInfo {Object} | ||
* @param NowDate {Date} | ||
*/ | ||
exports.CheckForRecharge = (OwnCurrencyData, GameUser, RechargeInfo, NowDate)=>{ | ||
|
||
//재충전 가능한 통화인가? | ||
if(OwnCurrencyData.RechargeCurrencyID === null | ||
|| OwnCurrencyData.CurrentQNTY >= OwnCurrencyData.TotalQNTY) //혹은 최대치만큼 보유했는가? | ||
return {code:false}; | ||
|
||
let nowTime = NowDate.getTime(); | ||
let oldTime = new Date(OwnCurrencyData.UpdateTimeStamp).getTime(); | ||
let oldOffTime = GetOffSetTime(oldTime, GameUser.OffsetTime); | ||
let updateValue = {CurrentQNTY:null, UpdateTimeStamp:null}; | ||
|
||
//최대치 충전 주기가 있는가? | ||
if(RechargeInfo.SetMaxSwitch === true) { | ||
let convertLater = later.parse.cron(RechargeInfo.SetMaxPattern); | ||
let prevTime = later.schedule(convertLater).prev(); | ||
let prevOffsetTime = GetOffSetTime(prevTime.getTime(), GameUser.OffsetTime ); | ||
//UpdateTimeStamp가 prevTime보다 뒤에있는가? | ||
if(oldOffTime < prevOffsetTime) { | ||
updateValue.CurrentQNTY = OwnCurrencyData.TotalQNTY; | ||
updateValue.UpdateTimeStamp = NowDate; | ||
return {code:true, update:updateValue} | ||
} | ||
} | ||
|
||
//시간경과에 따른 업데이트 항목만 작동. | ||
let spendTime = (nowTime - oldTime)/1000; | ||
let rechargeAmount = Math.floor(spendTime / RechargeInfo.IntervalTime); | ||
|
||
let totalAmount = OwnCurrencyData.CurrentQNTY + rechargeAmount; | ||
|
||
|
||
//현재 보유할 수 있는 최대수량을넘어가는가? | ||
if(totalAmount >= OwnCurrencyData.TotalQNTY) { | ||
updateValue.CurrentQNTY = OwnCurrencyData.TotalQNTY; | ||
updateValue.UpdateTimeStamp = NowDate; | ||
return {code:true, update:updateValue} | ||
} | ||
//최대 수량에 미치지 못하나 충전할만한 량이 있을때 | ||
else if( rechargeAmount > 0) { | ||
updateValue.CurrentQNTY = totalAmount; | ||
updateValue.UpdateTimeStamp = | ||
new Date( | ||
oldTime + | ||
(rechargeAmount * RechargeInfo.IntervalTime)*1000 | ||
); | ||
return {code:true, update:updateValue} | ||
} | ||
|
||
return {code:false}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
'use strict'; | ||
|
||
module.exports = function(sequelize, DataTypes) { | ||
let DefineRechargeCurrency= sequelize.define('DefineRechargeCurrency', { | ||
RechargeCurrencyID : { type : DataTypes.INTEGER, primaryKey: true}, | ||
IntervalTime : { type : DataTypes.INTEGER, defaultValue : 3600 }, | ||
IntervalChargeAmount : { type : DataTypes.INTEGER, defaultValue:1 }, | ||
SetMaxSwitch : { type : DataTypes.BOOLEAN, defaultValue:false }, | ||
SetMaxPattern : { //cron 표현식을 통해 최대치 충전 주기를설정한다. | ||
type : DataTypes.STRING(32), | ||
validate : { //반드시 올바른 형태의 입력인지 체크한다. | ||
is: /^\s*($|#|\w+\s*=|(\?|\*|(?:[0-5]?\d)(?:(?:-|\/|\,)(?:[0-5]?\d))?(?:,(?:[0-5]?\d)(?:(?:-|\/|\,)(?:[0-5]?\d))?)*)\s+(\?|\*|(?:[0-5]?\d)(?:(?:-|\/|\,)(?:[0-5]?\d))?(?:,(?:[0-5]?\d)(?:(?:-|\/|\,)(?:[0-5]?\d))?)*)\s+(\?|\*|(?:[01]?\d|2[0-3])(?:(?:-|\/|\,)(?:[01]?\d|2[0-3]))?(?:,(?:[01]?\d|2[0-3])(?:(?:-|\/|\,)(?:[01]?\d|2[0-3]))?)*)\s+(\?|\*|(?:0?[1-9]|[12]\d|3[01])(?:(?:-|\/|\,)(?:0?[1-9]|[12]\d|3[01]))?(?:,(?:0?[1-9]|[12]\d|3[01])(?:(?:-|\/|\,)(?:0?[1-9]|[12]\d|3[01]))?)*)\s+(\?|\*|(?:[1-9]|1[012])(?:(?:-|\/|\,)(?:[1-9]|1[012]))?(?:L|W)?(?:,(?:[1-9]|1[012])(?:(?:-|\/|\,)(?:[1-9]|1[012]))?(?:L|W)?)*|\?|\*|(?:JAN|FEB|MAR|APR|MAY|JUN|JUL|AUG|SEP|OCT|NOV|DEC)(?:(?:-)(?:JAN|FEB|MAR|APR|MAY|JUN|JUL|AUG|SEP|OCT|NOV|DEC))?(?:,(?:JAN|FEB|MAR|APR|MAY|JUN|JUL|AUG|SEP|OCT|NOV|DEC)(?:(?:-)(?:JAN|FEB|MAR|APR|MAY|JUN|JUL|AUG|SEP|OCT|NOV|DEC))?)*)\s+(\?|\*|(?:[0-6])(?:(?:-|\/|\,|#)(?:[0-6]))?(?:L)?(?:,(?:[0-6])(?:(?:-|\/|\,|#)(?:[0-6]))?(?:L)?)*|\?|\*|(?:MON|TUE|WED|THU|FRI|SAT|SUN)(?:(?:-)(?:MON|TUE|WED|THU|FRI|SAT|SUN))?(?:,(?:MON|TUE|WED|THU|FRI|SAT|SUN)(?:(?:-)(?:MON|TUE|WED|THU|FRI|SAT|SUN))?)*)(|\s)+(\?|\*|(?:|\d{4})(?:(?:-|\/|\,)(?:|\d{4}))?(?:,(?:|\d{4})(?:(?:-|\/|\,)(?:|\d{4}))?)*))$/ | ||
}, | ||
defaultValue : '0 0 12 * * ?' //기본값(매일 낮 12시) | ||
} | ||
|
||
}, { | ||
timestamps: false, | ||
tableName: 'DefineRechargeCurrency' | ||
}); | ||
return DefineRechargeCurrency; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters