Commit 281e9f71 authored by ZhuChunYang's avatar ZhuChunYang

添加托管币种旷工费

parent 74fc1f52
......@@ -15,6 +15,7 @@ use common\business\CoinBusiness;
use common\business\ExchangeBusiness;
use common\models\psources\Coin;
use common\models\psources\CoinRecommend;
use common\models\psources\MinerFee;
use Yii;
/**
......@@ -178,10 +179,11 @@ class CoinController extends BaseController
$names = Yii::$app->request->post('name');
$coin = Coin::findOne(['name' => $names]);
if ($coin) {
$miner_fee = $coin->minerFee;
if (empty($miner_fee)) {
return [];
}
$chain = $coin->chain;
$miner_fee = MinerFee::find()->where(['platform' => $chain,'type' => 1])->one();
if(!$miner_fee){
throw new Exception('8', '旷工费未设置');
}
} else {
//如果coin为null,$coin->minerFee会抛出Trying to get property 'minerFee' of non-object",code=>8
throw new Exception('8', '币种不存在');
......
......@@ -12,6 +12,7 @@ use api\base\BaseController;
use common\business\ExchangeBusiness;
use common\models\psources\Coin;
use common\models\psources\CoinRecommend;
use common\models\psources\MinerFee;
use common\service\coin\CoinFactory;
use Yii;
......@@ -94,4 +95,22 @@ class ServiceController extends BaseController
}
return [];
}
/**
* @return array
* 获取旷工费
*/
public function actionFee()
{
$request = Yii::$app->request;
$coin = $request->post('name');
if(!$coin){
return ['code' => 1,'data' => [],'msg' => '币种不能为空'];
}
$fee = MinerFee::find()->where(['platform' => $coin,'type' => 2])->asArray()->one();
if(!$fee){
return ['code' => 1,'data' => [],'msg' => '旷工费未设置'];
}
return ['code' => 0,'data' => $fee,'msg' => '旷工费获取成功'];
}
}
......@@ -215,7 +215,7 @@ class BaseController extends Controller
$this->ajaxReturn($data);
}
// 成功操作后默认停留1秒
$waitSecond = 3;
$waitSecond = 2;
if ($status) {
//发送成功信息
......
......@@ -8,6 +8,7 @@
namespace backend\controllers;
use common\service\trusteeship\Trusteeship;
use Yii;
use common\models\psources\MinerFee;
use backend\models\coin\MinerFeeForm;
......@@ -21,7 +22,11 @@ class MinerFeeController extends BaseController
public function actionCost()
{
if (Yii::$app->request->isAjax) {
$data = MinerFee::getList(1, 999, []);//数据不多
$request = Yii::$app->request;
$type = $request->get('type',1);
$page = $request->get('page', 1);
$limit = $request->get('limit', 10);
$data = MinerFee::getList($page, $limit, [['type' => $type]]);//数据不多
if ($data['count'] > 0) {
$data['code'] = 0;
} else {
......@@ -42,6 +47,7 @@ class MinerFeeController extends BaseController
{
$model = new MinerFeeForm();
$model->scenario = 'add';
$type = Yii::$app->request->get('type',1);
if (Yii::$app->request->isPost) {
$request = Yii::$app->request;
if ($model->load($request->post()) && $model->validate()) {
......@@ -50,6 +56,7 @@ class MinerFeeController extends BaseController
$minerFee->min = $model->min;
$minerFee->max = $model->max;
$minerFee->level = $model->level;
$minerFee->type = $type;
$minerFee->create_at = date('Y-m-d H:i:s');
$minerFee->update_at = date('Y-m-d H:i:s');
......@@ -87,7 +94,6 @@ class MinerFeeController extends BaseController
if ($minerFee) {
if (Yii::$app->request->isPost) {
if ($model->load(Yii::$app->request->post()) && $model->validate()) {
$minerFee->platform = $model->platform;
$minerFee->min = $model->min;
$minerFee->max = $model->max;
$minerFee->level = $model->level;
......@@ -133,4 +139,35 @@ class MinerFeeController extends BaseController
}
$this->error('删除失败', Yii::$app->request->getReferrer());
}
public function actionUpdateCoin()
{
Yii::$app->response->format = 'json';
$trusteeship = new Trusteeship();
$data = $trusteeship->getSupportCoin();
if($data['code'] != 0){
return ['code' => -1, 'msg' => '获取托管钱包币种失败'];
}else{
$trusteeship_coins = array_column($data['data'],'currency');
$list = MinerFee::getList(1, 999, [['type' => 2]]);
if($list){
$local_coins = array_column($list['data'],'platform');
}else{
$local_coins = [];
}
$need_add_coins = array_diff($trusteeship_coins,$local_coins);
if(!$need_add_coins){
return ['code' => 0,'msg' => '币种库已经最新'];
}
foreach($need_add_coins as $item){
$minerFee = new MinerFee();
$minerFee->platform = $item;
$minerFee->type = 2;
$minerFee->create_at = date('Y-m-d H:i:s');
$minerFee->update_at = date('Y-m-d H:i:s');
$minerFee->save();
}
return ['code' => 0, 'msg' => '币种库更新成功'];
}
}
}
\ No newline at end of file
......@@ -17,6 +17,7 @@ class MinerFeeForm extends Model
public $max;
public $min;
public $level;
public $type;
public function formName()
{
......@@ -26,10 +27,9 @@ class MinerFeeForm extends Model
public function rules()
{
return [
[['id', 'platform', 'min', 'max', 'level'], 'required', 'on' => 'edit'],
[['id', 'min', 'max', 'level'], 'required', 'on' => 'edit'],
[['platform', 'min', 'max', 'level'], 'required', 'on' => 'add'],
[['id', 'max', 'min', 'level'], 'number'],
[['platform'], 'string', 'max' => 255],
];
}
......@@ -37,7 +37,7 @@ class MinerFeeForm extends Model
{
return [
'add' => ['platform', 'min', 'max', 'level'],
'edit' => ['id', 'platform', 'min', 'max', 'level'],
'edit' => ['id', 'min', 'max', 'level'],
];
}
......
......@@ -24,6 +24,14 @@ $platforms = Coin::getChainList();
<form class="layui-form" method="post" action="">
<input name="_csrf" type="hidden" value="<?= Yii::$app->request->getCsrfToken() ?>">
<input name="id" type="hidden" value="<?= $model->id ?>">
<?php if($model->type == 2) :?>
<div class="layui-form-item">
<label class="layui-form-label">币种</label>
<div class="layui-input-block">
<input class="layui-input" name="platform" value="<?= $model->platform ?>">
</div>
</div>
<?php else :?>
<div class="layui-form-item">
<label class="layui-form-label">平台</label>
<div class="layui-input-block">
......@@ -36,6 +44,7 @@ $platforms = Coin::getChainList();
</select>
</div>
</div>
<?php endif;?>
<div class="layui-form-item">
<label class="layui-form-label">最小值</label>
......
......@@ -9,17 +9,30 @@
<h4>矿工费</h4>
<div class="layui-row">
<div class="layui-col-md1">
<a href="/admin/miner-fee/add">
<button class="layui-btn">添加矿工费</button>
</a>
</div>
<div class="layui-col-md8">
<div class="layui-tab layui-tab-card">
<ul class="layui-tab-title">
<li class="layui-this">币钱包</li>
<li>托管钱包</li>
</ul>
<div class="layui-tab-content">
<div class="layui-tab-item layui-show">
<a href="/admin/miner-fee/add?type=1">
<button class="layui-btn">添加矿工费</button>
</a>
<div class="layui-row">
<table id="table1" class="layui-table"></table>
</div>
</div>
<div class="layui-tab-item">
<button class="layui-btn layui-btn-default" id="update-coin">更新币种库</button>
<table class="layui-table" id="table2" ></table>
</div>
</div>
</div>
</div>
<div class="layui-row">
<table id="table1" class="layui-table"></table>
</div>
<script>
var table = layui.table;
table.render({
......@@ -34,11 +47,40 @@
{field: 'update_at', title: '更新时间'},
{field: 'id', title: '操作', templet: "#operatorTpl"}
]],
url: '/admin/miner-fee/cost'
url: '/admin/miner-fee/cost?type=1'
});
table.render({
elem: "#table2",
page: true,
limit: 10,
cols: [[
{field: 'id', title: 'ID'},
{field: 'platform', title: '币种'},
{field: 'min', title: '最小值'},
{field: 'max', title: '最大值'},
{field: 'level', title: '分档'},
{field: 'create_at', title: '创建时间'},
{field: 'update_at', title: '更新时间'},
{field: 'id', title: '操作', templet: "#operatorTpl"}
]],
url: '/admin/miner-fee/cost?type=2'
});
$('#update-coin').click(function () {
$.get('/admin/miner-fee/update-coin', {}, function (rev) {
layer.msg(rev.msg);
if (0==rev.code) {
table.reload('table2', {
page: {
curr: 1
}
});
}
});
})
</script>
<script type="text/html" id="operatorTpl">
<a href="/admin/miner-fee/edit?id={{d.id}}">
<a href="/admin/miner-fee/edit?id={{d.id}}&type={{d.type}}">
<button class="layui-btn layui-btn-sm">编辑</button>
</a>
<a href="/admin/miner-fee/del?id={{d.id}}">
......
<?php
/**
* Created by PhpStorm.
* User: ZCY
* Date: 2019/1/10
* Time: 10:53
*/
namespace common\service\trusteeship;
use Yii;
use common\helpers\Curl;
/**
* Lottery平行链 区块链接口
*/
class Trusteeship
{
/**
* @return string
* 平行链上操作彩票
*/
public static function urlTrusteeshipBuild()
{
$config = Yii::$app->params['trusteeship'];
$service = $config['service'];
$scheme = $service['scheme'] ?? 'http';
$host = $service['host'] ?? '127.0.0.1';
$port = (string)$service['port'] ?? '';
if ($port) {
return $scheme . '://' . $host . ':' . $port;
} else {
return $scheme . '://' . $host;
}
}
/**
* @return array|mixed
* 获取支持的币种
*/
public function getSupportCoin()
{
$ch = new Curl();
$config = Yii::$app->params['trusteeship'];
$url = self::urlTrusteeshipBuild().$config['coin_getsupport'];
$result = $ch->get($url, false);
if (!$result) {
return ['code' => -1, 'msg' => $ch->errorText];
}
if (200 == $result['code']) {
$result['code'] = 0;
$result['msg'] = $result['message'];
unset($result['message']);
return $result;
} else {
return ['code' => -1, 'msg' => $result['message']];
}
}
}
\ 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