mirror of
https://github.com/HackPlan/RootPanel.git
synced 2026-04-28 19:45:45 +08:00
测试欠费自动删除
This commit is contained in:
@@ -40,4 +40,4 @@ RP 主机价格固定 10 元每月,25 元每季度,一个月即 30 天,一
|
||||
你可以向客服创建一个工单来申请免费试用,你需要用 100 字来介绍一下你的个人信息,然后客服会酌情为你赠送一些余额。
|
||||
|
||||
### 什么情况下账户会被强制删除?
|
||||
欠费超过 5 元人民币,或者欠费超过三十天,服务将被强行停止,相关数据会被删除。
|
||||
欠费超过 5 元人民币,或者欠费超过 15 天,服务将被强行停止,相关数据会被删除。
|
||||
|
||||
@@ -21,59 +21,75 @@ exports.checkBilling = (account, callback) ->
|
||||
else
|
||||
callback account
|
||||
|
||||
exports.calcBilling = (account, isForce, callback) ->
|
||||
amount = 0
|
||||
|
||||
for planName in account.attribute.plans
|
||||
plan = config.plans[planName]
|
||||
|
||||
price = plan.price / 30 / 24
|
||||
time = (Date.now() - account.attribute.last_billing_at.getTime()) / 1000 / 3600
|
||||
|
||||
if isForce
|
||||
billing_time = Math.ceil time
|
||||
else
|
||||
billing_time = Math.floor time
|
||||
|
||||
amount += price * billing_time
|
||||
|
||||
if amount <= 0
|
||||
return callback account
|
||||
|
||||
if isForce
|
||||
new_last_billing_at = new Date()
|
||||
else
|
||||
new_last_billing_at = new Date account.attribute.last_billing_at.getTime() + billing_time * 3600 * 1000
|
||||
|
||||
exports.checkExpired = (account, callback) ->
|
||||
modifier =
|
||||
$set:
|
||||
'attribute.last_billing_at': new_last_billing_at
|
||||
$inc:
|
||||
'attribute.balance': -amount
|
||||
$set: {}
|
||||
|
||||
if account.attribute.balance < 0
|
||||
unless account.attribute.arrears_at
|
||||
modifier.$set['attribute.arrears_at'] = new Date()
|
||||
|
||||
exports.forceUnsubscribe account, ->
|
||||
callcallback = ->
|
||||
mAccount.update _id: account._id, modifier, ->
|
||||
mAccount.findId account._id, (err, account) ->
|
||||
callback account
|
||||
|
||||
if account.attribute.balance > 0
|
||||
modifier.$set['attribute.arrears_at'] = null
|
||||
|
||||
mAccount.update _id: account._id, modifier, ->
|
||||
mBalance.create account, 'billing', -amount,
|
||||
plans: account.attribute.plans
|
||||
billing_time: billing_time
|
||||
is_force: isForce
|
||||
last_billing_at: account.attribute.last_billing_at
|
||||
, ->
|
||||
mAccount.findId account._id, (err, account) ->
|
||||
callback account
|
||||
if account.attribute.balance < 0
|
||||
unless account.attribute.arrears_at
|
||||
modifier.$set['attribute.arrears_at'] = new Date()
|
||||
else
|
||||
if account.attribute.balance < -5
|
||||
return exports.forceUnsubscribe account, callcallback
|
||||
|
||||
if Date.now() - account.attribute.arrears_at.getTime() > 15 * 24 * 3600 * 1000
|
||||
return exports.forceUnsubscribe account, callcallback
|
||||
|
||||
callcallback()
|
||||
|
||||
exports.calcBilling = (account, isForce, callback) ->
|
||||
exports.checkExpired account, ->
|
||||
amount = 0
|
||||
|
||||
for planName in account.attribute.plans
|
||||
plan_info = config.plans[planName]
|
||||
|
||||
price = plan_info.price / 30 / 24
|
||||
time = (Date.now() - account.attribute.last_billing_at.getTime()) / 1000 / 3600
|
||||
|
||||
if isForce
|
||||
billing_time = Math.ceil time
|
||||
else
|
||||
billing_time = Math.floor time
|
||||
|
||||
amount += price * billing_time
|
||||
|
||||
if amount <= 0
|
||||
return callback account
|
||||
|
||||
if isForce
|
||||
new_last_billing_at = new Date()
|
||||
else
|
||||
new_last_billing_at = new Date account.attribute.last_billing_at.getTime() + billing_time * 3600 * 1000
|
||||
|
||||
modifier =
|
||||
$set:
|
||||
'attribute.last_billing_at': new_last_billing_at
|
||||
$inc:
|
||||
'attribute.balance': -amount
|
||||
|
||||
mAccount.update _id: account._id, modifier, ->
|
||||
mBalance.create account, 'billing', -amount,
|
||||
plans: account.attribute.plans
|
||||
billing_time: billing_time
|
||||
is_force: isForce
|
||||
last_billing_at: account.attribute.last_billing_at
|
||||
, ->
|
||||
mAccount.findId account._id, (err, account) ->
|
||||
callback account
|
||||
|
||||
exports.forceUnsubscribe = (account, callback) ->
|
||||
async.mapSeries account.attribute.plans, (plan, callback) ->
|
||||
async.mapSeries account.attribute.plans, (plan_name, callback) ->
|
||||
mAccount.findId account._id, (err, account) ->
|
||||
plan.leavePlan account, plan, callback
|
||||
plan.leavePlan account, plan_name, callback
|
||||
, ->
|
||||
callback()
|
||||
|
||||
@@ -81,8 +97,8 @@ exports.calcRemainingTime = (account) ->
|
||||
price = 0
|
||||
|
||||
for planName in account.attribute.plans
|
||||
plan = config.plans[planName]
|
||||
plan_info = config.plans[planName]
|
||||
|
||||
price += plan.price / 30 / 24
|
||||
price += plan_info.price / 30 / 24
|
||||
|
||||
return account.attribute.balance / price
|
||||
|
||||
Reference in New Issue
Block a user