优化免费套餐的计费

This commit is contained in:
jysperm
2014-08-20 17:12:14 +08:00
parent 2b68bd33f1
commit 78ab92148e
6 changed files with 14 additions and 12 deletions

View File

@@ -17,8 +17,7 @@ module.exports =
available_services: ['shadowsocks']
plans:
all:
price: 0
shadowsocks:
t_name: 'ShadowSocks 按量付费'
t_service: 'ShadowSocks'
t_resources: '0.6 CNY / G'

View File

@@ -49,7 +49,7 @@ exports.calcBilling = (account, isForce, callback) ->
exports.checkExpired account, ->
amount = 0
for planName in account.attribute.plans
for planName in _.filter(account.attribute.plans, (i) -> config.plans[i].price)
plan_info = config.plans[planName]
price = plan_info.price / 30 / 24
@@ -96,7 +96,7 @@ exports.forceUnsubscribe = (account, callback) ->
exports.calcRemainingTime = (account) ->
price = 0
for planName in account.attribute.plans
for planName in _.filter(account.attribute.plans, (i) -> config.plans[i].price)
plan_info = config.plans[planName]
price += plan_info.price / 30 / 24

View File

@@ -47,7 +47,7 @@ exports.post '/signup', errorHandling, (req, res) ->
res.json
id: account._id
if 'linux' in config.plugin.availablePlugin
if 'linux' in config.plugin.available_services
require('../../plugin/linux/monitor').loadPasswd (passwd_cache) ->
if req.body.username in _.values(passwd_cache)
return res.error 'username_exist'

View File

@@ -15,8 +15,10 @@ exports.post '/subscribe', requireAuthenticate, (req, res) ->
if req.body.plan in req.account.attribute.plans
return res.error 'already_in_plan'
plan_info = config.plans[req.body.plan]
billing.calcBilling req.account, true, (account) ->
if account.attribute.balance <= 0
if plan_info.price and account.attribute.balance <= 0
return res.error 'insufficient_balance'
plan.joinPlan account, req.body.plan, ->

View File

@@ -2,6 +2,6 @@
module.exports = exports = express.Router()
if config.plugin.rpvhost.index_page
if config.plugins.rpvhost.index_page
app.get '/', renderAccount, (req, res) ->
res.render path.join(__dirname, './view/index')

View File

@@ -81,12 +81,13 @@ module.exports =
config_content = _.template (fs.readFileSync path.join(__dirname, 'template/config.conf')).toString(), account.attribute.plugin.shadowsocks
plugin.writeConfig "/etc/shadowsocks/#{account.username}.json", config_content, ->
config_content = _.template (fs.readFileSync path.join(__dirname, 'template/supervisor.conf')).toString(),
account: account
child_process.exec "sudo chmod +r /etc/shadowsocks/#{account.username}.json", ->
config_content = _.template (fs.readFileSync path.join(__dirname, 'template/supervisor.conf')).toString(),
account: account
plugin.writeConfig "/etc/supervisor/conf.d/#{account.username}.conf", config_content, ->
child_process.exec 'sudo supervisorctl reload', ->
callback()
plugin.writeConfig "/etc/supervisor/conf.d/#{account.username}.conf", config_content, ->
child_process.exec 'sudo supervisorctl reload', ->
callback()
widget: (account, callback) ->
jade.renderFile path.join(__dirname, 'view/widget.jade'),