Commit f507a8ca authored by shajiaming's avatar shajiaming

列表加入时间

parents dfd28bfe f79117ee
......@@ -45,25 +45,32 @@ class MarketController extends BaseController
goto doEnd;
}
if (!in_array($exchange, Yii::$app->params['exchange'])) {
$this->msg = 'invalid exchange';
$exchange = ExchangeFactory::createExchange($exchange);
$currency_ticker = $exchange->getTicker($currency, 'USDT');
$base_currency_ticker = $exchange->getTicker($base_currency, 'USDT');
if (empty($currency_ticker) || empty($base_currency_ticker)) {
$this->code = -1;
$this->msg = '此交易所暂不支持所选币种!';
goto doEnd;
}
$currency_quotation = [
'low' => (float)sprintf("%0.4f", $currency_ticker['low']),
'high' => (float)sprintf("%0.4f", $currency_ticker['high']),
'last' => (float)sprintf("%0.4f", $currency_ticker['last']),
'rmb' => (float)sprintf("%0.2f", $currency_ticker['last']),
];
$exchange = ExchangeFactory::createExchange($exchange);
$quotation = $exchange->getTicker($currency, 'USDT');
$quotation = [
'low' => (float)sprintf("%0.4f", $quotation['low'] / 100),
'high' => (float)sprintf("%0.4f", $quotation['high'] / 100),
'last' => (float)sprintf("%0.4f", $quotation['last'] / 100),
'rmb' => (float)sprintf("%0.2f", $quotation['last'] / 100),
$base_currency_quotation = [
'low' => (float)sprintf("%0.4f", $base_currency_ticker['low']),
'high' => (float)sprintf("%0.4f", $base_currency_ticker['high']),
'last' => (float)sprintf("%0.4f", $base_currency_ticker['last']),
'rmb' => (float)sprintf("%0.2f", $base_currency_ticker['last']),
];
echo json_encode($quotation);exit;
$this->data = (float)sprintf("%0.4f",$currency_quotation['last'] / $base_currency_quotation['last']);
doEnd :
return ['code' => $this->code, 'msg' => $this->msg, 'tick' => $this->data ];
return ['code' => $this->code, 'msg' => $this->msg, 'data' => $this->data];
}
}
\ No newline at end of file
<?php
namespace api\controllers;
use common\service\chain33\Chain33Service;
use Yii;
use api\base\BaseController;
use common\models\psources\WalletChain;
use yii\data\Pagination;
class WalletChainController extends BaseController
{
/**
* h5发行链列表
* @param string wallet_address
* @return array
*/
public function actionChains()
{
if (!Yii::$app->request->isGet) {
$this->code = -1;
$this->msg = '请求方式错误!';
goto doEnd;
}
$params = Yii::$app->request->get();
$wallet_address = isset($params['wallet_address']) ? $params['wallet_address'] : '';
if (false == $wallet_address) {
$this->code = -1;
$this->msg = '参数错误';
goto doEnd;
}
$page = Yii::$app->request->get('page', 1);
$size = Yii::$app->request->get('size', 10);
$query = WalletChain::find()
->select('id, token, platform, create_time, status')
->where(['wallet_address' => $wallet_address])
->orderBy('id');
$model = $query->offset(($page - 1) * $size)->orderBy('create_time desc')->limit($size)->asArray()->all();
$countQuery = clone $query;
$pages = new Pagination(['totalCount' => $countQuery->count(), 'pageSize' => $size]);
$this->data = [
'list' => $model,
'page' => [
'pageCount' => $pages->pageCount,
'pageSize' => $size,
'currentPage' => $page,
]
];
doEnd :
return ['code' => $this->code, 'data' => $this->data, 'msg' => $this->msg];
}
/**
* h5发行链
* @param string platform
* @param string address
* @param string private_key
* @param string fee
* @param string token
* @param string host
* @param string port
* @param string wallet_address
* @param string hash
* @return array
*/
public function actionChain()
{
$request = Yii::$app->request;
if (!$request->isPost) {
$this->code = -1;
$this->msg = '请求方式错误!';
goto doEnd;
}
$post = $request->post();
$model = new WalletChain();
$model->setScenario(WalletChain::SCENARIOS_CREATE);
$params = [
'platform' => isset($post['platform']) ? $post['platform'] : '',
'address' => isset($post['address']) ? $post['address'] : '',
'private_key' => isset($post['private_key']) ? $post['private_key'] : '',
'token' => isset($post['token']) ? strtoupper($post['token']) : '',
'host' => isset($post['host']) ? $post['host'] : '',
'port' => isset($post['port']) ? $post['port'] : '',
'wallet_address' => isset($post['wallet_address']) ? $post['wallet_address'] : '',
'status' => WalletChain::STATUS_NO,
'origin' => WalletChain::ORIGIN_MANAGE,
'fee' => isset($post['fee']) ? $post['fee'] : '',
'hash' => isset($post['hash']) ? $post['hash'] : ''
];
if ($model->load($params, '') && !$model->save()) {
$this->msg = $model->errors;
$this->code = -1;
goto doEnd;
}
$id = Yii::$app->p_sources->getLastInsertID();
// $params = [
// 'platform' => 'BZCHAIN',
// 'host' => '112.74.59.221',
// 'port' => 1235,
// ];
$node_params = Yii::$app->params['para'];
$service = new Chain33Service($node_params);
$result = $service->addPara($params['platform'], $params['host'] . ':' . $params['port']);
if (0 != $result['code']) {
$this->code = $result['code'];
$this->msg = $result['msg'];
goto doEnd;
}
$chain_update = WalletChain::find()->where(['id' => $id])->one();
$chain_update->setScenario(WalletChain::SCENARIOS_UPDATE);
$chain_update->status = WalletChain::STATUS_YES;
$chain_update->save();
doEnd :
return ['code' => $this->code, 'data' => $this->data, 'msg' => $this->msg];
}
/**
* h5发行链
* @param string wallet_address
* @return array
*/
public function actionDetail()
{
if (!Yii::$app->request->isGet) {
$this->code = -1;
$this->msg = '请求方式错误!';
goto doEnd;
}
$params = Yii::$app->request->get();
$id = isset($params['id']) ? $params['id'] : '';
if (false == $id) {
$this->code = -1;
$this->msg = '参数错误';
goto doEnd;
}
$model = WalletChain::find()->select('platform, token, address, private_key, fee, host, port, hash, status')->where(['id' => (int)$id])->asArray()->one();
if (empty($model)) {
goto doEnd;
}
$model['fee'] = $model['fee'] . $model['token'];
$model['charge'] = '10BTY';
$this->data = $model;
goto doEnd;
doEnd :
return ['code' => $this->code, 'data' => $this->data, 'msg' => $this->msg];
}
}
\ No newline at end of file
<?php
namespace common\models\psources;
use Yii;
use common\core\BaseActiveRecord;
class WalletChain extends BaseActiveRecord
{
//定义场景
const SCENARIOS_CREATE = 'create';
const SCENARIOS_UPDATE = 'update';
const STATUS_NO = 0; //创建失败
const STATUS_YES = 1; //创建成功
const ORIGIN_MANAGE = 1; //管理员创建
const ORIGIN_USER = 2; //h5用户创建
public static function getDb()
{
return Yii::$app->get('p_sources');
}
public static function tableName()
{
return '{{wallet_chain}}';
}
public function attributeLabels()
{
return [
'id' => 'ID',
'platform' => '平行链名称',
'address' => '代扣地址',
'private_key' => '代扣私钥',
'execer' => '执行器',
'fee' => '手续费',
'brower_url' => '浏览器链接',
'token' => '手续费(基础代币)',
'host' => '钱包服务IP',
'port' => '钱包服务端口',
'wallet_address' => '钱包地址',
'status' => '申请状态',
'origin' => '创建人',
'hash' => '申请费用hash'
];
}
public function rules()
{
return [
[['platform', 'address', 'private_key', 'execer', 'brower_url', 'token', 'host', 'wallet_address', 'status', 'port', 'fee', 'origin', 'hash'], 'required'],
[['platform', 'address', 'private_key', 'execer', 'brower_url', 'token', 'host', 'wallet_address', 'hash'], 'string'],
[['platform'], 'string', 'length' => [1, 30]],
[['token'], 'string', 'length' => [1, 10]],
[['port', 'status', 'origin'], 'integer']
];
}
public function scenarios()
{
$scenarios = [
self:: SCENARIOS_CREATE => ['platform', 'token', 'address', 'private_key', 'fee', 'host', 'port', 'wallet_address', 'status', 'origin', 'hash'],
self:: SCENARIOS_UPDATE => ['status'],
];
return array_merge(parent:: scenarios(), $scenarios);
}
}
\ No newline at end of file
......@@ -54,12 +54,8 @@ class Chain33Service
return json_encode($data);
}
public function send($params = [], $method = 'Chain33.Query')
public function send($params = [], $method = 'Chain33.Query', $timeout = [])
{
$timeout = [
'connect_timeout' => 50000,
'timeout_ms' => 40000
];
$ch = new Curl($timeout);
$jsonrpc = self::jsonRpcBuild($params, $method);
$ch->setHeader('Content-Type', 'application/json');
......@@ -449,4 +445,23 @@ class Chain33Service
];
return $this->send($params, 'Chain33.UnLock');
}
/**
* @param ParaName
* @param ParaSerAddr
* @return array|mixed
* 解锁钱包
*/
public function addPara($paraName, $paraSerAddr)
{
$params = [
'ParaName' => $paraName,
'ParaSerAddr' => $paraSerAddr,
];
$timeout = [
'connect_timeout' => 50000,
'timeout_ms' => 50000
];
return $this->send($params, 'CoinsControl.AddParaCoinsInfo', $timeout);
}
}
......@@ -8,7 +8,7 @@ class Bilaxy extends Exchange implements ExchangeInterface
{
protected $supported_symbol = 'supported_symbol_bilaxy';
protected $quotation_prefix = 'quotation_bilaxy_';
protected $base_url = 'https://api.bilaxy.com/v1/tickers';
protected $base_url = 'https://newapi.bilaxy.com/';
public function symbolExists($tag = 'BVA', $aim = "USDT")
......@@ -38,7 +38,15 @@ class Bilaxy extends Exchange implements ExchangeInterface
*/
public function setSupportedSymbol()
{
$this->redis->sadd($this->supported_symbol, 'BVA_USDT');
$curl = new Curl();
$api = $this->base_url . '/v1/ticker/24hr';
$content = $curl->get($api, false);//json
if (is_array($content)) {
foreach ($content as $key => $item) {
$this->redis->sadd($this->supported_symbol, strtoupper($key));
}
}
}
/**
......@@ -49,14 +57,13 @@ class Bilaxy extends Exchange implements ExchangeInterface
public function setQuotation()
{
$curl = new Curl();
$content = $curl->get($this->base_url, false);
if (is_array($content) && isset($content['data'])) {
$data = $content['data'];
$key = $this->quotation_prefix . 'BVA_USDT';
foreach ($data as $item) {
if ( 260 == $item['symbol']) {
$this->redis->hmset($key, 'low', $item['low'], 'high', $item['high'], 'last', $item['last']);
$this->redis->sadd($this->supported_symbol, 'KPC8_USDT');
$api = $this->base_url . '/v1/ticker/24hr';
$content = $curl->get($api, false);
if (is_array($content)) {
foreach ($content as $key => $item) {
$this->redis->hmset($this->quotation_prefix . strtoupper($key), 'low', $item['low'], 'high', $item['height'], 'last', $item['close']);
if (!$this->redis->sismember($this->supported_symbol, strtoupper($key))){
$this->redis->sadd($this->supported_symbol, strtoupper($key));
}
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment