From 125902ad650b452f073280166b67f41e5f2e1ffc Mon Sep 17 00:00:00 2001 From: jysperm Date: Wed, 14 May 2014 18:58:57 +0800 Subject: [PATCH] =?UTF-8?q?=E5=9C=A8=E9=9D=A2=E6=9D=BF=E4=B8=8A=E6=98=BE?= =?UTF-8?q?=E7=A4=BA=E4=BD=99=E9=A2=9D=E5=92=8C=E5=89=A9=E4=BD=99=E6=97=B6?= =?UTF-8?q?=E9=95=BF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- core/api/panel.coffee | 19 ++++++++++++------- core/billing.coffee | 12 ++++++++++++ core/locale/zh_CN.json | 15 +++++++++++++-- core/view/panel.jade | 12 +++++++----- 4 files changed, 44 insertions(+), 14 deletions(-) diff --git a/core/api/panel.coffee b/core/api/panel.coffee index 71e3c0b..4cf07ed 100644 --- a/core/api/panel.coffee +++ b/core/api/panel.coffee @@ -2,6 +2,7 @@ _ = require 'underscore' config = require '../config' api = require './index' +billing = require '../billing' mAccount = require '../model/account' @@ -11,12 +12,16 @@ module.exports = res.redirect '/panel/' '/panel/': api.accountAuthenticateRender (req, res, account, renderer) -> - plans = [] + billing.calcBilling account, (account) -> + plans = [] - for name, info of config.plans - plans.push _.extend info, - name: name - isEnable: name in account.attribute.plans + for name, info of config.plans + plans.push _.extend info, + name: name + isEnable: name in account.attribute.plans - renderer 'panel', - plans: plans + account.attribute.remaining_time = Math.ceil(billing.calcRemainingTime(account) / 24) + + renderer 'panel', + account: account + plans: plans diff --git a/core/billing.coffee b/core/billing.coffee index eb53a3e..671cdea 100644 --- a/core/billing.coffee +++ b/core/billing.coffee @@ -25,3 +25,15 @@ exports.calcBilling = (account, callback) -> mAccount.update _id: account._id, modifier, {}, -> mAccount.findId account._id, (account) -> callback account + +exports.calcRemainingTime = (account) -> + price = 0 + + for planName in account.attribute.plans + plan = config.plans[planName] + + price += plan.price / 30 / 24 + + console.log price + + return account.attribute.balance / price diff --git a/core/locale/zh_CN.json b/core/locale/zh_CN.json index 449fdf4..0014c18 100644 --- a/core/locale/zh_CN.json +++ b/core/locale/zh_CN.json @@ -22,7 +22,8 @@ "logout": "注销" }, "panel": { - "": "管理面板" + "": "管理面板", + "overview": "概况" }, "ticket": { "": "工单", @@ -42,11 +43,21 @@ "members": "成员" }, "plan": { - "": "套餐" + "": "套餐", + "subscribe": "订购", + "unsubscribe": "退订", + "balance": "余额", + "remaining_time": "剩余时长", + "currency": { + "cny": "CNY" + } }, "admin": { "admin_panel": "管理员面板" }, + "time": { + "day": "天" + }, "view": { "layout": { "navigation": "展开导航" diff --git a/core/view/panel.jade b/core/view/panel.jade index c796719..b60c969 100644 --- a/core/view/panel.jade +++ b/core/view/panel.jade @@ -19,10 +19,13 @@ block content a(href='/ticket/list/') span.glyphicon.pull-right.glyphicon-edit | #{t('ticket.')} - + .col-md-9 .row - header 概况 + header= t('panel.overview') + p + | #{t('plan.balance')}: #{account.attribute.balance.toFixed(2)} #{t('plan.currency.cny')} + | #{t('plan.remaining_time')}: #{account.attribute.remaining_time} #{t('time.day')} .row header= t('plan.') @@ -35,7 +38,6 @@ block content td= plan.t_resources td if plan.isEnable - button.btn.btn-danger.btn-sm 退订 + button.btn.btn-danger.btn-sm= t('plan.unsubscribe') else - button.btn.btn-success.btn-sm 订购 - + button.btn.btn-success.btn-sm= t('plan.subscribe')