Commit fc75a94f authored by shajiaiming's avatar shajiaiming

solve conflict

parents 53dec005 d61efc09
...@@ -6,27 +6,90 @@ use api\base\BaseController; ...@@ -6,27 +6,90 @@ use api\base\BaseController;
use common\models\psources\CoinAirDropTrade; use common\models\psources\CoinAirDropTrade;
use common\models\psources\CoinSupportedSymbol; use common\models\psources\CoinSupportedSymbol;
use common\service\chain33\Chain33Service; use common\service\chain33\Chain33Service;
use linslin\yii2\curl\Curl;
use Yii; use Yii;
use yii\helpers\ArrayHelper;
class SupportedSymbolController extends BaseController class SupportedSymbolController extends BaseController
{ {
public function actionSearch() public function actionIndex()
{ {
$platform_withhold_id = Yii::$app->request->get('id', ''); $platform_id = Yii::$app->request->get('platform_id', '');
if (empty($platform_withhold_id)) { if (empty($platform_id)) {
$msg = '参数不能为空'; $msg = '参数不能为空';
$code = -1; $code = -1;
$data = null; $data = null;
goto doEnd; goto doEnd;
} }
$coinSupportedSymbol = CoinSupportedSymbol::find()->select('symbol')->where(['platform_withhold_id' => $platform_withhold_id])->asArray()->all(); $parentSupportedSymbol = CoinSupportedSymbol::find()->where(['platform_id' => $platform_id])->groupBy('currency')->all();
$data = array_column($coinSupportedSymbol, 'symbol'); $market = [];
foreach ($parentSupportedSymbol as $val) {
$coin_name[] = $val->coinInfo->name;
}
$curl = new Curl();
$data = [
"names" => $coin_name
];
$params = json_encode($data);
$curl->setHeader('Content-Type', 'application/json');
$curl->setRawPostData($params);
$res = $curl->post(\Yii::$app->params['biqianbao'].'/interface/coin/coin-index', true);
$res = json_decode($res, true);
$res = array_column($res['data'],NULL,'id');;
foreach ($parentSupportedSymbol as &$val) {
$temp = [];
$temp['id'] = (int)$val->currency;
$temp['name'] = $val->coinInfo->name;
$temp['icon'] = $val->coinInfo->icon;
$temp['isToken'] = (1 == $val->coinInfo->treaty) ? true : false;
$temp['isParacross'] = ('BTY' == strtoupper($val->coinInfo->platform)) ? false : true;
$temp['url'] = 'http://www.huifen.com';
$temp['platfrom'] = $val->coinInfo->platform;
$temp['rmb'] = isset($res[$val->currency]['rmb']) ? $res[$val->currency]['rmb'] : 0.00;
$temp['usd'] = isset($res[$val->currency]['usd']) ? $res[$val->currency]['usd'] : 0.00;
array_push($market, $temp);
}
$coin_name = [];
foreach ($market as &$val) {
$childSupportedSymbol = CoinSupportedSymbol::find()->where(['platform_id' => $platform_id, 'currency' => $val['id']])->all();
$tokens = [];
foreach ($childSupportedSymbol as $child) {
$coin_name[] = $child->baseCurrencyInfo->name;
}
$data_child = [
"names" => $coin_name
];
$params = json_encode($data_child);
$curl = new Curl();
$curl->setHeader('Content-Type', 'application/json');
$curl->setRawPostData($params);
$res = $curl->post(\Yii::$app->params['biqianbao'].'/interface/coin/coin-index', true);
$res = json_decode($res, true);
$res = array_column($res['data'],NULL,'id');;
foreach ($childSupportedSymbol as $child) {
$temp = [];
$temp['id'] = (int)$child->base_currency;
$temp['name'] = $child->baseCurrencyInfo->name;
$temp['icon'] = $child->baseCurrencyInfo->icon;
$temp['isToken'] = (1 == $child->baseCurrencyInfo->treaty) ? true : false;
$temp['isParacross'] = ('BTY' == strtoupper($child->baseCurrencyInfo->platform)) ? false : true;
$temp['url'] = 'http://www.huifen.com';
$temp['platfrom'] = $child->baseCurrencyInfo->platform;
$temp['rmb'] = isset($res[$child->base_currency]['rmb']) ? $res[$child->base_currency]['rmb'] : 0.00;
$temp['usd'] = isset($res[$child->base_currency]['usd']) ? $res[$child->base_currency]['usd'] : 0.00;
array_push($tokens, $temp);
}
$val['tokens'] = $tokens;
}
$code = 0; $code = 0;
$msg = 'success'; $msg = 'success';
doEnd : doEnd :
return ['code' => $code, 'msg' => $msg, 'data' => $data]; return ['code' => $code, 'msg' => $msg, 'data' => $market];
} }
} }
\ No newline at end of file
...@@ -3,6 +3,7 @@ ...@@ -3,6 +3,7 @@
namespace backend\controllers; namespace backend\controllers;
use backend\models\coin\CoinSupportedSymbolForm; use backend\models\coin\CoinSupportedSymbolForm;
use common\models\psources\Coin;
use common\models\psources\CoinSupportedSymbol; use common\models\psources\CoinSupportedSymbol;
use Yii; use Yii;
...@@ -11,7 +12,7 @@ class CoinSupportedSymbolController extends BaseController ...@@ -11,7 +12,7 @@ class CoinSupportedSymbolController extends BaseController
{ {
public function actionList() public function actionList()
{ {
$platform_withhold_id = Yii::$app->request->get('id'); $platform_id = Yii::$app->request->get('id');
if (Yii::$app->request->isAjax) { if (Yii::$app->request->isAjax) {
Yii::$app->response->format = 'json'; Yii::$app->response->format = 'json';
$request = Yii::$app->request; $request = Yii::$app->request;
...@@ -20,47 +21,45 @@ class CoinSupportedSymbolController extends BaseController ...@@ -20,47 +21,45 @@ class CoinSupportedSymbolController extends BaseController
$id = $request->get('id', ''); $id = $request->get('id', '');
$where = []; $where = [];
if ($id) { if ($id) {
$where[] = ['platform_withhold_id' => $id]; $where[] = ['platform_id' => $id];
} }
$data = CoinSupportedSymbol::getList($page, $limit, $where); $data = CoinSupportedSymbol::getList($page, $limit, $where);
$data['code'] = 0; foreach ($data['data'] as &$val) {
$val->currency = $val->coinInfo->name;
$val->base_currency = $val->baseCurrencyInfo->name;
}
Yii::$app->response->format = 'json'; Yii::$app->response->format = 'json';
return $data; return $data;
} }
return $this->render('index', ['platform_withhold_id' => $platform_withhold_id]); return $this->render('index', ['platform_id' => $platform_id]);
} }
public function actionAdd() public function actionAdd()
{ {
$this->layout = false;
$model = new CoinSupportedSymbolForm(); $model = new CoinSupportedSymbolForm();
$model->scenario = 'add'; $model->scenario = 'add';
if (Yii::$app->request->isPost) { if (Yii::$app->request->isPost) {
Yii::$app->response->format = 'json';
$data = Yii::$app->request->post(); $data = Yii::$app->request->post();
if ($model->load($data, '') && $model->validate()) { if ($model->load($data, '') && $model->validate()) {
$currency = Coin::find()->select('id')->where(['name' => $data['currency']])->asArray()->one();
$base_currency = Coin::find()->select('id')->where(['name' => $data['base_currency']])->asArray()->one();
$coinSupportedSymbol = new CoinSupportedSymbol(); $coinSupportedSymbol = new CoinSupportedSymbol();
$coinSupportedSymbol->platform_withhold_id = $data['platform_withhold_id']; $coinSupportedSymbol->platform_id = $data['platform_id'];
$coinSupportedSymbol->symbol = $data['symbol']; $coinSupportedSymbol->currency = $currency['id'];
$coinSupportedSymbol->base_currency = $base_currency['id'];
$result = $coinSupportedSymbol->save(); $result = $coinSupportedSymbol->save();
if ($result === true) { if ($result != true) {
$this->success('添加成功', '/admin/coin-supported-symbol/list?id=' . $data['platform_withhold_id']); return ['code' => -1, 'msg' => current($model->firstErrors)];
}
}
//表单验证失败
$errors = $model->errors;
if ($errors) {
foreach ($errors as $key => $item) {
$errors = $item[0];
break;
} }
} elseif (isset($result) && $result['code'] != 0) {
$errors = $result['message'];
} }
$this->error($errors, Yii::$app->request->getReferrer()); return ['code' => 0, 'msg' => 'succeed'];
} }
$platform_withhold_id = Yii::$app->request->get('platform_withhold_id'); $platform_id = Yii::$app->request->get('platform_id');
return $this->render('add', ['model' => $model, 'platform_withhold_id' => $platform_withhold_id]); return $this->render('add', ['model' => $model, 'platform_id' => $platform_id]);
} }
public function actionDelete() public function actionDelete()
......
...@@ -2,13 +2,15 @@ ...@@ -2,13 +2,15 @@
namespace backend\models\coin; namespace backend\models\coin;
use common\models\psources\Coin;
use yii\base\Model; use yii\base\Model;
class CoinSupportedSymbolForm extends Model class CoinSupportedSymbolForm extends Model
{ {
public $id; public $id;
public $platform_withhold_id; public $platform_id;
public $symbol; public $currency;
public $base_currency;
public function formName() public function formName()
{ {
...@@ -18,34 +20,26 @@ class CoinSupportedSymbolForm extends Model ...@@ -18,34 +20,26 @@ class CoinSupportedSymbolForm extends Model
public function rules() public function rules()
{ {
return [ return [
[['platform_withhold_id', 'symbol'], 'required', 'on' => 'add'], [['platform_id', 'currency', 'base_currency'], 'required', 'on' => 'add'],
[['id', 'platform_withhold_id', 'symbol'], 'required', 'on' => 'update'], [['id', 'platform_id', 'currency', 'base_currency'], 'required', 'on' => 'update'],
[['currency', 'base_currency'], 'isExist']
]; ];
} }
public function attributeLabels() public function scenarios()
{ {
return [ return [
'id' => 'ID', 'add' => ['platform_id', 'currency', 'base_currency'],
'platform_withhold_id' => '对应链', 'update' => ['id', 'platform_id', 'currency', 'base_currency'],
'symbol' => '货币对',
]; ];
} }
public function scenarios() public function isExist($attribute, $params)
{ {
return [ $coin_model = Coin::find()->where(['name' => $this->currency])->one();
'add' => [ if (false == $coin_model) {
'platform_withhold_id', $this->addError($attribute, '币种不存在');
'symbol' return false;
], }
'update' => [
'id',
'platform_withhold_id',
'symbol'
],
];
} }
} }
\ No newline at end of file
<h4>添加货币对</h4> <div style="padding: 5px 20px;">
<style> <br>
.layui-form-label { <form id="addData">
width: 100px; <input name="_csrf" type="hidden" value="<?= Yii::$app->request->getCsrfToken() ?>">
} <div class="input-group my-group">
</style> <span class="input-group-addon">交易货币</span>
<div class="layui-row" style="padding: 5px;"> <input name="currency" type="text" class="form-control" lay-verify="required">
<div class="layui-col-md6"> </div>
<form class="layui-form" method="post" action=""> <div class="input-group my-group">
<input name="_csrf" type="hidden" value="<?= Yii::$app->request->getCsrfToken() ?>"> <span class="input-group-addon">基础货币</span>
<div class="layui-inline"> <input name="base_currency" type="text" class="form-control" lay-verify="required">
<label class="layui-form-label">货币对</label> </div>
<div class="layui-input-block"> <input class="layui-input" name="platform_id" type="hidden" value="<?= $platform_id ?>"
<input class="layui-input" name="symbol" lay-verify="required"> lay-verify="required">
</div> </form>
</div> </div>
<div class="layui-form-item">
<button class="layui-btn">提交</button>
</div>
<input class="layui-input" name="platform_withhold_id" type="hidden" value="<?= $platform_withhold_id ?>"
lay-verify="required">
</form>
</div>
</div>
<?php
/**
* Created by PhpStorm.
* User: rlgyzhcn
* Date: 18-5-31
* Time: 下午6:23
*/
?>
<style>
.layui-form-label {
width: 100px;
}
</style>
<div class="layui-row" style="padding: 5px;">
<div class="layui-col-md12">
<form class="layui-form" method="post" action="" id="walletEdit">
<input name="_csrf" type="hidden" value="<?= Yii::$app->request->getCsrfToken() ?>">
<input name="id" type="hidden" value="<?= $model->id ?>">
<div class="layui-inline">
<label class="layui-form-label">简称</label>
<div class="layui-input-block">
<input class="layui-input" name="name" value="<?= $model->name ?>" lay-verify="required">
</div>
</div>
<div class="layui-form-item">
<label class="layui-form-label">下载地址</label>
<div class="layui-input-block">
<input class="layui-input" name="download_url" value="<?= $model->download_url ?>">
</div>
</div>
<div class="layui-form-item">
<label class="layui-form-label">介绍</label>
<div class="layui-input-block">
<textarea class="layui-textarea" name="introduce"><?= $model->introduce?></textarea>
</div>
</div>
</form>
</div>
</div>
<script>
var laydate = layui.laydate;
laydate.render({
elem: "#time1"
});
//图片上传
var uploader = layui.upload;
$_csrf = $("input[name='_csrf']").val();
uploader.render({
elem: "#upload1",
url: '/admin/coin/upload',
data: {_csrf: $_csrf},
done: function (res) {
console.log(res.data.src);
$("input[name='icon']").val(res.data.src);
$("#icon1").attr('src', res.data.src);
},
error: function (res) {
}
});
//form render
var form = layui.form;
form.render();
</script>
...@@ -16,15 +16,13 @@ IndexAsset::register($this); ...@@ -16,15 +16,13 @@ IndexAsset::register($this);
padding: 0px; padding: 0px;
} }
</style> </style>
<h4>货币列表</h4> <h4>货币列表</h4>
<div class="layui-row"> <div class="layui-row">
<div class="layui-col-md1"> <div class="layui-col-md1">
<a href="/admin/coin-supported-symbol/add?platform_withhold_id=<?= $platform_withhold_id ?>""> <button class="layui-btn layui-btn-sm" lay-event="add" id="add">单笔添加</button>
<button class="layui-btn layui-btn-default" id="add">添加货币对</button>
</a>
</div> </div>
</div> </div>
<input id="platform_withhold_id" type="hidden" value="<?= $platform_withhold_id ?>"> <input id="platform_id" type="hidden" value="<?= $platform_id ?>">
<div class="layui-row"> <div class="layui-row">
<table class="layui-table" id="table1" lay-filter="table1"></table> <table class="layui-table" id="table1" lay-filter="table1"></table>
</div> </div>
......
...@@ -44,5 +44,5 @@ IndexAsset::register($this); ...@@ -44,5 +44,5 @@ IndexAsset::register($this);
<script type="text/html" id="operationTpl"> <script type="text/html" id="operationTpl">
<a class="layui-btn layui-btn-xs" lay-event="edit">编辑</a> <a class="layui-btn layui-btn-xs" lay-event="edit">编辑</a>
<a class="layui-btn layui-btn-xs" lay-event="delete">删除</a> <a class="layui-btn layui-btn-xs" lay-event="delete">删除</a>
<a class="layui-btn layui-btn-primary layui-btn-xs" href="/admin/coin-supported-coin/list?id={{d.id}}" >支持发行货币种类</a> <a class="layui-btn layui-btn-primary layui-btn-xs" href="/admin/coin-supported-symbol/list?id={{d.id}}" >支持发行货币种类</a>
</script> </script>
...@@ -5,16 +5,33 @@ var table = layui.table; ...@@ -5,16 +5,33 @@ var table = layui.table;
var form = layui.form; var form = layui.form;
var layer = layui.layer; var layer = layui.layer;
form.render(); form.render();
var platform_withhold_id = $("#platform_withhold_id").val(); var platform_id = $("#platform_id").val();
var tableIns = table.render({ var tableIns = table.render({
elem: "#table1", elem: "#table1",
url: '/admin/coin-supported-symbol/list?id=' + platform_withhold_id, url: '/admin/coin-supported-symbol/list?id=' + platform_id,
limit: 10, limit: 10,
page: 1, page: 1,
loading: true, loading: true,
cols: [[ cols: [[
{field: 'id', title: 'ID'}, {field: 'id', title: 'ID'},
{field: 'symbol', title: '货币对'}, {
field: 'currency',
title: '交易货币',
//templet: function (data) {
//var name = JSON.parse(data.name);
//console.log(typeof (data.name), name.zh);
//return name.zh
//}
},
{
field: 'base_currency',
title: '基础货币',
//templet: function (data) {
//var name = JSON.parse(data.name);
//console.log(typeof (data.name), name.zh);
//return name.zh
//}
},
{field: 'create_time', title: '创建时间'}, {field: 'create_time', title: '创建时间'},
{field: 'id', title: '操作', templet: '#operationTpl'} {field: 'id', title: '操作', templet: '#operationTpl'}
]], ]],
...@@ -30,7 +47,7 @@ form.on('submit(form1)', function (data) { ...@@ -30,7 +47,7 @@ form.on('submit(form1)', function (data) {
table.on('tool(table1)', function (obj) { table.on('tool(table1)', function (obj) {
var data = obj.data; var data = obj.data;
if (obj.event == 'delete') { if (obj.event == 'delete') {
layer.confirm('真的要删除' + data.symbol + '吗?', {icon: 3, title: '删除'}, function (index) { layer.confirm('真的要删除' + data.coin_name + '吗?', {icon: 3, title: '删除'}, function (index) {
layer.close(index); layer.close(index);
//向服务端发送删除指令 //向服务端发送删除指令
$.get('/admin/coin-supported-symbol/delete?id=' + obj.data.id, function (data, status) { $.get('/admin/coin-supported-symbol/delete?id=' + obj.data.id, function (data, status) {
...@@ -41,4 +58,32 @@ table.on('tool(table1)', function (obj) { ...@@ -41,4 +58,32 @@ table.on('tool(table1)', function (obj) {
}); });
}); });
} }
});
$('#add').click(function () {
//打开弹窗
$.get('/admin/coin-supported-symbol/add?platform_id=' + platform_id, {}, function (str) {
var index = layer.open({
type: 1,
title: '添加数据',
id: 'add-one',
skin: 'layui-layer-lan',
area: ['320px', 'auto'],
content: str,
btn: ['确认', '取消'],
btn1: function () {
$.post('/admin/coin-supported-symbol/add', $("#addData").serialize(), function (rev) {
layer.msg(rev.msg);
//if (rev.code == 0) {
layer.close(index);
table.reload("table1", {});
//}
});
}
});
layui.form.render();
});
return false;
}); });
\ No newline at end of file
...@@ -16,9 +16,9 @@ class CoinSupportedSymbol extends BaseActiveRecord ...@@ -16,9 +16,9 @@ class CoinSupportedSymbol extends BaseActiveRecord
$query = $query->andWhere($item); $query = $query->andWhere($item);
} }
$count = $query->count(); $count = $query->count();
$data = $query->offset(($page - 1) * 10)->limit($limit)->asArray()->all(); $data = $query->offset(($page - 1) * 10)->limit($limit)->all();
return ['count' => $count, 'data' => $data]; return ['count' => $count, 'data' => $data, 'code' => 0];
} }
public function addOne($params) public function addOne($params)
...@@ -36,4 +36,20 @@ class CoinSupportedSymbol extends BaseActiveRecord ...@@ -36,4 +36,20 @@ class CoinSupportedSymbol extends BaseActiveRecord
return ['code' => $exception->getCode(), 'message' => $exception->getMessage()]; return ['code' => $exception->getCode(), 'message' => $exception->getMessage()];
} }
} }
// public function attributes()
// {
// return array_merge(parent::attributes(), ['code']);
// }
public function getCoinInfo()
{
return $this->hasOne(Coin::class, ['id' => 'currency']);
}
public function getBaseCurrencyInfo()
{
return $this->hasOne(Coin::class, ['id' => 'base_currency']);
}
} }
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