Commit bbd14bd7 authored by shajiaming's avatar shajiaming

h5平行链

parent 818a227d
<?php
namespace api\controllers;
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')
->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'] : '',
'hash' => isset($post['hash']) ? $post['hash'] : '',
'fee' => isset($post['fee']) ? $post['fee'] : ''
];
if ($model->load($params, '') && $model->save()) {
goto doEnd;
}
$this->msg = $model->errors;
$this->code = -1;
goto doEnd;
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')->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';
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' => '钱包地址',
'hash' => '申请费用hash'
];
}
public function rules()
{
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', 'hash'], 'string'],
[['platform'], 'string', 'length' => [1, 30]],
[['token'], 'string', 'length' => [1, 10]],
[['port'], 'integer']
];
}
public function scenarios()
{
$scenarios = [
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'],
];
return array_merge(parent:: scenarios(), $scenarios);
}
}
\ 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