Commit f555604a authored by shajiaming's avatar shajiaming

fix

parent 84d0571c
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
namespace api\controllers; namespace api\controllers;
use common\service\chain33\Chain33Service;
use Yii; use Yii;
use api\base\BaseController; use api\base\BaseController;
use common\models\psources\WalletChain; use common\models\psources\WalletChain;
...@@ -35,7 +36,7 @@ class WalletChainController extends BaseController ...@@ -35,7 +36,7 @@ class WalletChainController extends BaseController
$size = Yii::$app->request->get('size', 10); $size = Yii::$app->request->get('size', 10);
$query = WalletChain::find() $query = WalletChain::find()
->select('id, token, platform') ->select('id, token, platform, status')
->where(['wallet_address' => $wallet_address]) ->where(['wallet_address' => $wallet_address])
->orderBy('id'); ->orderBy('id');
...@@ -92,14 +93,37 @@ class WalletChainController extends BaseController ...@@ -92,14 +93,37 @@ class WalletChainController extends BaseController
'wallet_address' => isset($post['wallet_address']) ? $post['wallet_address'] : '', 'wallet_address' => isset($post['wallet_address']) ? $post['wallet_address'] : '',
'status' => WalletChain::STATUS_NO, 'status' => WalletChain::STATUS_NO,
'origin' => WalletChain::ORIGIN_MANAGE, 'origin' => WalletChain::ORIGIN_MANAGE,
'fee' => isset($post['fee']) ? $post['fee'] : '' 'fee' => isset($post['fee']) ? $post['fee'] : '',
'hash' => isset($post['hash']) ? $post['hash'] : ''
]; ];
if ($model->load($params, '') && !$model->save()) { if ($model->load($params, '') && !$model->save()) {
$this->msg = $model->errors; $this->msg = $model->errors;
$this->code = -1; $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 : doEnd :
return ['code' => $this->code, 'data' => $this->data, 'msg' => $this->msg]; return ['code' => $this->code, 'data' => $this->data, 'msg' => $this->msg];
...@@ -128,7 +152,7 @@ class WalletChainController extends BaseController ...@@ -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)) { if (empty($model)) {
goto doEnd; goto doEnd;
} }
......
...@@ -42,15 +42,16 @@ class WalletChain extends BaseActiveRecord ...@@ -42,15 +42,16 @@ class WalletChain extends BaseActiveRecord
'port' => '钱包服务端口', 'port' => '钱包服务端口',
'wallet_address' => '钱包地址', 'wallet_address' => '钱包地址',
'status' => '申请状态', 'status' => '申请状态',
'origin' => '创建人' 'origin' => '创建人',
'hash' => '申请费用hash'
]; ];
} }
public function rules() public function rules()
{ {
return [ return [
[['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', 'status', 'port', 'fee', 'origin', 'hash'], 'required'],
[['platform', 'address', 'private_key', 'execer', 'brower_url', 'token', 'host', 'wallet_address'], 'string'], [['platform', 'address', 'private_key', 'execer', 'brower_url', 'token', 'host', 'wallet_address', 'hash'], 'string'],
[['platform'], 'string', 'length' => [1, 30]], [['platform'], 'string', 'length' => [1, 30]],
[['token'], 'string', 'length' => [1, 10]], [['token'], 'string', 'length' => [1, 10]],
[['port', 'status', 'origin'], 'integer'] [['port', 'status', 'origin'], 'integer']
...@@ -60,8 +61,8 @@ class WalletChain extends BaseActiveRecord ...@@ -60,8 +61,8 @@ class WalletChain extends BaseActiveRecord
public function scenarios() public function scenarios()
{ {
$scenarios = [ $scenarios = [
self:: SCENARIOS_CREATE => ['platform', 'token', 'address', 'private_key', 'fee', 'host', 'port', 'wallet_address', 'status', 'origin'], self:: SCENARIOS_CREATE => ['platform', 'token', 'address', 'private_key', 'fee', 'host', 'port', 'wallet_address', 'status', 'origin', 'hash'],
self:: SCENARIOS_UPDATE => ['platform', 'token', 'address', 'private_key', 'fee', 'host', 'port', 'wallet_address', 'status', 'origin'], self:: SCENARIOS_UPDATE => ['status'],
]; ];
return array_merge(parent:: scenarios(), $scenarios); return array_merge(parent:: scenarios(), $scenarios);
} }
......
...@@ -54,12 +54,8 @@ class Chain33Service ...@@ -54,12 +54,8 @@ class Chain33Service
return json_encode($data); 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); $ch = new Curl($timeout);
$jsonrpc = self::jsonRpcBuild($params, $method); $jsonrpc = self::jsonRpcBuild($params, $method);
$ch->setHeader('Content-Type', 'application/json'); $ch->setHeader('Content-Type', 'application/json');
...@@ -449,4 +445,23 @@ class Chain33Service ...@@ -449,4 +445,23 @@ class Chain33Service
]; ];
return $this->send($params, 'Chain33.UnLock'); 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);
}
} }
<?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