Commit 84d0571c authored by shajiaming's avatar shajiaming

fix

parent fa321d80
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
namespace api\controllers; namespace api\controllers;
use common\service\exchange\ExchangeFactory;
use Yii; use Yii;
use api\base\BaseController; use api\base\BaseController;
use common\service\exchange\ExchangeBuilderFactory; use common\service\exchange\ExchangeBuilderFactory;
...@@ -32,4 +33,53 @@ class MarketController extends BaseController ...@@ -32,4 +33,53 @@ class MarketController extends BaseController
return ['code' => $code, 'msg' => $msg, 'tick' => $ticker ?? []]; return ['code' => $code, 'msg' => $msg, 'tick' => $ticker ?? []];
} }
public function actionIndex()
{
$currency = Yii::$app->request->post('currency', '');
$base_currency = Yii::$app->request->post('base_currency', '');
$exchange = Yii::$app->request->post("exchange", 'Zhaobi');
$base_exchange = Yii::$app->request->post("base_exchange", 'Zhaobi');
if (false == $currency || false == $base_currency) {
$msg = 'invalid symbol';
$code = -1;
goto doEnd;
}
$exchange = ExchangeFactory::createExchange($exchange);
$quotation = $exchange->getTicker($currency);
$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),
];
echo json_encode($quotation);exit;
$base_exchange = ExchangeFactory::createExchange($base_exchange);
$base_quotation = $base_exchange->getTicker($base_currency);
$base_quotation = [
'low' => (float)sprintf("%0.4f", $base_quotation['low'] / 100),
'high' => (float)sprintf("%0.4f", $base_quotation['high'] / 100),
'last' => (float)sprintf("%0.4f", $base_quotation['last'] / 100),
'rmb' => (float)sprintf("%0.2f", $base_quotation['last'] / 100),
];
$builder = ExchangeBuilderFactory::create('Zhaobi');
$result = $builder->getDetail(strtoupper($currency), strtoupper($base_currency));
if (-1 == $result['code']) {
$msg = 'invalid symbol';
$code = -1;
goto doEnd;
}
$code = 0;
$msg = 'ok';
$ticker = $result['ticker'];
doEnd :
return ['code' => $code, 'msg' => $msg, 'tick' => $ticker ?? []];
}
} }
\ No newline at end of file
...@@ -90,16 +90,16 @@ class WalletChainController extends BaseController ...@@ -90,16 +90,16 @@ class WalletChainController extends BaseController
'host' => isset($post['host']) ? $post['host'] : '', 'host' => isset($post['host']) ? $post['host'] : '',
'port' => isset($post['port']) ? $post['port'] : '', 'port' => isset($post['port']) ? $post['port'] : '',
'wallet_address' => isset($post['wallet_address']) ? $post['wallet_address'] : '', 'wallet_address' => isset($post['wallet_address']) ? $post['wallet_address'] : '',
'hash' => isset($post['hash']) ? $post['hash'] : '', 'status' => WalletChain::STATUS_NO,
'origin' => WalletChain::ORIGIN_MANAGE,
'fee' => isset($post['fee']) ? $post['fee'] : '' 'fee' => isset($post['fee']) ? $post['fee'] : ''
]; ];
if ($model->load($params, '') && $model->save()) { if ($model->load($params, '') && !$model->save()) {
goto doEnd; $this->msg = $model->errors;
$this->code = -1;
} }
$this->msg = $model->errors;
$this->code = -1;
goto doEnd;
doEnd : doEnd :
return ['code' => $this->code, 'data' => $this->data, 'msg' => $this->msg]; return ['code' => $this->code, 'data' => $this->data, 'msg' => $this->msg];
......
...@@ -11,6 +11,12 @@ class WalletChain extends BaseActiveRecord ...@@ -11,6 +11,12 @@ class WalletChain extends BaseActiveRecord
const SCENARIOS_CREATE = 'create'; const SCENARIOS_CREATE = 'create';
const SCENARIOS_UPDATE = 'update'; 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() public static function getDb()
{ {
return Yii::$app->get('p_sources'); return Yii::$app->get('p_sources');
...@@ -35,26 +41,27 @@ class WalletChain extends BaseActiveRecord ...@@ -35,26 +41,27 @@ class WalletChain extends BaseActiveRecord
'host' => '钱包服务IP', 'host' => '钱包服务IP',
'port' => '钱包服务端口', 'port' => '钱包服务端口',
'wallet_address' => '钱包地址', 'wallet_address' => '钱包地址',
'hash' => '申请费用hash' 'status' => '申请状态',
'origin' => '创建人'
]; ];
} }
public function rules() public function rules()
{ {
return [ return [
[['platform', 'address', 'private_key', 'execer', 'brower_url', 'token', 'host', 'wallet_address', 'hash', 'port', 'fee'], 'required'], [['platform', 'address', 'private_key', 'execer', 'brower_url', 'token', 'host', 'wallet_address', 'status', 'port', 'fee', 'origin'], 'required'],
[['platform', 'address', 'private_key', 'execer', 'brower_url', 'token', 'host', 'wallet_address', 'hash'], 'string'], [['platform', 'address', 'private_key', 'execer', 'brower_url', 'token', 'host', 'wallet_address'], 'string'],
[['platform'], 'string', 'length' => [1, 30]], [['platform'], 'string', 'length' => [1, 30]],
[['token'], 'string', 'length' => [1, 10]], [['token'], 'string', 'length' => [1, 10]],
[['port'], 'integer'] [['port', 'status', 'origin'], 'integer']
]; ];
} }
public function scenarios() public function scenarios()
{ {
$scenarios = [ $scenarios = [
self:: SCENARIOS_CREATE => ['platform', 'token', 'address', 'private_key', 'fee', 'host', 'port', 'wallet_address', 'hash'], self:: SCENARIOS_CREATE => ['platform', 'token', 'address', 'private_key', 'fee', 'host', 'port', 'wallet_address', 'status', 'origin'],
self:: SCENARIOS_UPDATE => ['platform', 'token', 'address', 'private_key', 'fee', 'host', 'port', 'wallet_address', 'hash'], self:: SCENARIOS_UPDATE => ['platform', 'token', 'address', 'private_key', 'fee', 'host', 'port', 'wallet_address', 'status', 'origin'],
]; ];
return array_merge(parent:: scenarios(), $scenarios); return array_merge(parent:: scenarios(), $scenarios);
} }
......
<?php
/**
* Created by PhpStorm.
* User: rlgyzhcn
* Date: 18-6-5
* Time: 上午11:17
*/
namespace common\service\coin;
use Yii;
use common\helpers\Curl;
/**
* 币种服务类
* Class CoinService
* @package common\service
*/
class CoinsControl
{
protected $url;
public function __construct()
{
$this->url = Yii::$app->params['para']['scheme'] . '/' . Yii::$app->params['para']['host'] . '/' . Yii::$app->params['para']['port'];
}
public function init()
{
$url = Yii::$app->params['feixiaohao_domain'] . Yii::$app->params['feixiaohao_page']['currencies'] . $this->sid . '/';
$ch = new Curl();
$content = $ch->get($url, true);
$this->content = str_replace(['&nbsp;', '&nbsp;'], '', $content);
}
/**
* Gets the Article List ,Without Content field.
*
* @param number $page
* @param number $page_size
* @param string $language
* @return mixed
*/
public function getArticleList($page = 1, $page_size = 20, $language = BISHIJIE_LANGUAGE_CN)
{
$params = array('language' => $language, 'page' => $page, 'size' => $page_size);
return $this->get('article/list', $params);
}
}
\ No newline at end of file
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