Commit b9594ab6 authored by shajiaming's avatar shajiaming

solve conflict

parents f58a5430 f555604a
......@@ -2,6 +2,7 @@
namespace api\controllers;
use common\service\exchange\ExchangeFactory;
use Yii;
use api\base\BaseController;
use common\service\exchange\ExchangeBuilderFactory;
......@@ -32,4 +33,53 @@ class MarketController extends BaseController
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
......@@ -2,6 +2,7 @@
namespace api\controllers;
use common\service\chain33\Chain33Service;
use Yii;
use api\base\BaseController;
use common\models\psources\WalletChain;
......@@ -35,7 +36,7 @@ class WalletChainController extends BaseController
$size = Yii::$app->request->get('size', 10);
$query = WalletChain::find()
->select('id, token, platform')
->select('id, token, platform, status')
->where(['wallet_address' => $wallet_address])
->orderBy('id');
......@@ -90,16 +91,39 @@ class WalletChainController extends BaseController
'host' => isset($post['host']) ? $post['host'] : '',
'port' => isset($post['port']) ? $post['port'] : '',
'wallet_address' => isset($post['wallet_address']) ? $post['wallet_address'] : '',
'hash' => isset($post['hash']) ? $post['hash'] : '',
'fee' => isset($post['fee']) ? $post['fee'] : ''
'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()) {
goto doEnd;
}
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];
......@@ -128,7 +152,7 @@ class WalletChainController extends BaseController
}
$model = WalletChain::find()->select('platform, token, address, private_key, fee, host, port, hash')->where(['id' => (int)$id])->asArray()->one();
$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;
}
......
......@@ -11,6 +11,15 @@ class WalletChain extends BaseActiveRecord
const SCENARIOS_CREATE = 'create';
const SCENARIOS_UPDATE = 'update';
<<<<<<< HEAD
=======
const STATUS_NO = 0; //创建失败
const STATUS_YES = 1; //创建成功
const ORIGIN_MANAGE = 1; //管理员创建
const ORIGIN_USER = 2; //h5用户创建
>>>>>>> feature/ticker
public static function getDb()
{
return Yii::$app->get('p_sources');
......@@ -35,6 +44,11 @@ class WalletChain extends BaseActiveRecord
'host' => '钱包服务IP',
'port' => '钱包服务端口',
'wallet_address' => '钱包地址',
<<<<<<< HEAD
=======
'status' => '申请状态',
'origin' => '创建人',
>>>>>>> feature/ticker
'hash' => '申请费用hash'
];
}
......@@ -42,19 +56,32 @@ class WalletChain extends BaseActiveRecord
public function rules()
{
return [
<<<<<<< HEAD
[['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', 'hash'], 'string'],
[['platform'], 'string', 'length' => [1, 30]],
[['token'], 'string', 'length' => [1, 10]],
[['port'], 'integer']
=======
[['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']
>>>>>>> feature/ticker
];
}
public function scenarios()
{
$scenarios = [
<<<<<<< HEAD
self:: SCENARIOS_CREATE => ['platform', 'token', 'address', 'private_key', 'fee', 'host', 'port', 'wallet_address', 'hash'],
self:: SCENARIOS_UPDATE => ['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', 'hash'],
self:: SCENARIOS_UPDATE => ['status'],
>>>>>>> feature/ticker
];
return array_merge(parent:: scenarios(), $scenarios);
}
......
......@@ -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);
}
}
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