mirror of
https://github.com/HackPlan/RootPanel.git
synced 2026-01-12 22:27:09 +08:00
实时显示 bitcoin 汇率
This commit is contained in:
@@ -13,6 +13,18 @@ exports.genAddress = (blockchain_secret, callback) ->
|
||||
|
||||
callback body.input_address
|
||||
|
||||
exports.getExchangeRate = (callback) ->
|
||||
app.redis.get 'rp:exchange_rate:cnybtc', (err, rate) ->
|
||||
if rate
|
||||
callback rate
|
||||
else
|
||||
request 'https://blockchain.info/ticker', (err, res, body) ->
|
||||
body = JSON.parse body
|
||||
rate = 1 / parseFloat(body['CNY']['15m'])
|
||||
|
||||
app.redis.setex 'rp:exchange_rate:cnybtc', 60, rate, ->
|
||||
callback parseFloat rate
|
||||
|
||||
exports.doCallback = (data, callback) ->
|
||||
mAccount.byDepositAddress data.input_address, (err, account) ->
|
||||
unless data.secret == account.blockchain_secret
|
||||
|
||||
@@ -3,6 +3,7 @@ path = require 'path'
|
||||
harp = require 'harp'
|
||||
fs = require 'fs'
|
||||
mongomin = require 'mongo-min'
|
||||
redis = require 'redis'
|
||||
|
||||
global._ = require 'underscore'
|
||||
global.ObjectID = require('mongodb').ObjectID
|
||||
@@ -30,11 +31,22 @@ bindRouters = (app) ->
|
||||
plugin = require './plugin'
|
||||
plugin.loadPlugins app
|
||||
|
||||
exports.connectDatabase = (callback) ->
|
||||
if global.app?.db
|
||||
return callback null, app.db
|
||||
|
||||
app.redis = redis.createClient()
|
||||
|
||||
mongomin config.mongodb, (err, db) ->
|
||||
global.app ?= {}
|
||||
app.db = db
|
||||
callback err, db
|
||||
|
||||
exports.runWebServer = ->
|
||||
global.app = exports.app = express()
|
||||
|
||||
mongomin config.mongodb, (db) ->
|
||||
app.db = db
|
||||
exports.connectDatabase (err) ->
|
||||
throw err if err
|
||||
|
||||
i18n.init
|
||||
default_language: 'zh_CN'
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
config = require '../config'
|
||||
billing = require '../billing'
|
||||
plugin = require '../plugin'
|
||||
bitcoin = require '../bitcoin'
|
||||
{requestAuthenticate, renderAccount} = require './middleware'
|
||||
|
||||
mAccount = require '../model/account'
|
||||
@@ -9,12 +10,14 @@ mBalance = require '../model/balance'
|
||||
module.exports = exports = express.Router()
|
||||
|
||||
exports.get '/pay', requestAuthenticate, renderAccount, (req, res) ->
|
||||
mBalance.find
|
||||
account_id: req.account._id
|
||||
.toArray (err, balance_log) ->
|
||||
res.render 'panel/pay',
|
||||
deposit_log: _.filter(balance_log, (i) -> i.type == 'deposit')
|
||||
billing_log: _.filter(balance_log, (i) -> i.type == 'billing')
|
||||
bitcoin.getExchangeRate (rate) ->
|
||||
mBalance.find
|
||||
account_id: req.account._id
|
||||
.toArray (err, balance_log) ->
|
||||
res.render 'panel/pay',
|
||||
exchange_rate: rate
|
||||
deposit_log: _.filter(balance_log, (i) -> i.type == 'deposit')
|
||||
billing_log: _.filter(balance_log, (i) -> i.type == 'billing')
|
||||
|
||||
exports.get '/', requestAuthenticate, (req, res) ->
|
||||
billing.checkBilling req.account, (account) ->
|
||||
|
||||
@@ -10,8 +10,8 @@ block main
|
||||
div
|
||||
h2 比特币
|
||||
p 你可以直接向该地址发送比特币。在经过一次确认后,系统会实时地,自动为你折算使用时间。
|
||||
p 实时汇率:10 CNY = 0.004 BTC
|
||||
pre.bg-success 13v2BTCMZMHg5v87susgg86HFZqXERuwUd
|
||||
p 实时汇率:10 CNY = #{(exchange_rate * 10).toFixed(4)} BTC
|
||||
pre.bg-success= account.attribute.bitcoin_deposit_address
|
||||
|
||||
div
|
||||
h2 淘宝
|
||||
|
||||
@@ -39,6 +39,7 @@
|
||||
"mysql": "*",
|
||||
"moment": "*",
|
||||
"request": "*",
|
||||
"mongo-min": "*"
|
||||
"mongo-min": "*",
|
||||
"redis": "*"
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user