Commit 1b40a616 authored by shajiaiming's avatar shajiaiming

增加托管费添加

parent ad418f78
......@@ -12,6 +12,7 @@ use common\service\trusteeship\Trusteeship;
use Yii;
use common\models\psources\MinerFee;
use backend\models\coin\MinerFeeForm;
use common\models\psources\Coin;
use \Exception;
class MinerFeeController extends BaseController
......@@ -23,18 +24,18 @@ class MinerFeeController extends BaseController
{
if (Yii::$app->request->isAjax) {
$request = Yii::$app->request;
$type = $request->get('type',1);
$page = $request->get('page', 1);
$limit = $request->get('limit', 10);
$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 {
$data['code'] = 1;
$data['msg'] = '数据为空';
$data['msg'] = '数据为空';
}
Yii::$app->response->format = 'json';
Yii::$app->response->data = $data;
Yii::$app->response->data = $data;
Yii::$app->response->send();
}
return $this->render('index');
......@@ -45,27 +46,32 @@ class MinerFeeController extends BaseController
*/
public function actionAdd()
{
$model = new MinerFeeForm();
$model->scenario = 'add';
$type = Yii::$app->request->get('type',1);
$model = new MinerFeeForm();
$type = Yii::$app->request->get('type', 1);
if (MinerFeeForm::TYPE_WALLET == $type) {
$model->setScenario(MinerFeeForm::SCENARIOS_WALLET_CREATE);
} else {
$model->setScenario(MinerFeeForm::SCENARIOS_TRUSTEESHIP_CREATE);
}
$platforms = Coin::getChainList();
if (Yii::$app->request->isPost) {
$request = Yii::$app->request;
if ($model->load($request->post()) && $model->validate()) {
$minerFee = new MinerFee();
$minerFee->platform = $model->platform;
$minerFee->min = $model->min;
$minerFee->max = $model->max;
$minerFee->level = $model->level;
$minerFee->type = $type;
$minerFee = new MinerFee();
$minerFee->platform = $model->platform;
if (MinerFeeForm::TYPE_WALLET == $type) {
$minerFee->min = $model->min;
$minerFee->max = $model->max;
$minerFee->level = $model->level;
} else {
$minerFee->fee = $model->fee;
}
$minerFee->type = $type;
$minerFee->create_at = date('Y-m-d H:i:s');
$minerFee->update_at = date('Y-m-d H:i:s');
try {
$minerFee->save();
$this->success('添加成功', '/admin/miner-fee/cost');
} catch (Exception $exception) {
$this->error($exception->getMessage(), '/admin/miner-fee/add');
}
$minerFee->save();
$this->success('添加成功', '/admin/miner-fee/cost');
}
//表单验证失败
$errors = $model->errors;
......@@ -77,7 +83,7 @@ class MinerFeeController extends BaseController
}
$this->error($errors, Yii::$app->request->getReferrer());
}
return $this->render('add', ['model' => $model]);
return $this->render('add', ['model' => $model, 'platforms' => $platforms, 'type' => $type]);
}
/**
......@@ -86,24 +92,30 @@ class MinerFeeController extends BaseController
*/
public function actionEdit()
{
$model = new MinerFeeForm();
$model->scenario = 'edit';
$id = Yii::$app->request->get('id', null);
$model = new MinerFeeForm();
$id = Yii::$app->request->get('id', null);
$type = Yii::$app->request->get('type', 1);
if (MinerFeeForm::TYPE_WALLET == $type) {
$model->setScenario(MinerFeeForm::SCENARIOS_WALLET_UPDATE);
} else {
$model->setScenario(MinerFeeForm::SCENARIOS_TRUSTEESHIP_UPDATE);
}
if ($id) {
$minerFee = MinerFee::findOne(['id' => $id]);
$platforms = Coin::getChainList();
if ($minerFee) {
if (Yii::$app->request->isPost) {
if ($model->load(Yii::$app->request->post()) && $model->validate()) {
$minerFee->min = $model->min;
$minerFee->max = $model->max;
$minerFee->level = $model->level;
$minerFee->update_at = date('Y-m-d H:i:s');
try {
$minerFee->save();
$this->success('更新成功', '/admin/miner-fee/cost');
} catch (Exception $exception) {
$this->error($exception->getMessage(), Yii::$app->request->getReferrer());
if (MinerFeeForm::TYPE_WALLET == $type) {
$minerFee->min = $model->min;
$minerFee->max = $model->max;
$minerFee->level = $model->level;
} else {
$minerFee->fee = $model->fee;
}
$minerFee->update_at = date('Y-m-d H:i:s');
$minerFee->save();
$this->success('更新成功', '/admin/miner-fee/cost');
}
$errors = $model->errors;
if ($errors) {
......@@ -114,7 +126,7 @@ class MinerFeeController extends BaseController
}
$this->error($errors, Yii::$app->request->getReferrer());
}
return $this->render('edit', ['model' => $minerFee]);
return $this->render('edit', ['model' => $minerFee, 'platforms' => $platforms, 'type' => $type]);
}
}
$this->error('公告不存在', Yii::$app->request->getReferrer());
......@@ -149,24 +161,24 @@ class MinerFeeController extends BaseController
Yii::$app->response->format = 'json';
$trusteeship = new Trusteeship();
$data = $trusteeship->getSupportCoin();
if($data['code'] != 0){
if ($data['code'] != 0) {
return ['code' => -1, 'msg' => $data['msg']];
}else{
$trusteeship_coins = array_column($data['data'],'currency');
} 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{
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' => '币种库已经最新'];
$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;
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();
......@@ -184,19 +196,19 @@ class MinerFeeController extends BaseController
if (Yii::$app->request->isAjax) {
Yii::$app->response->format = 'json';
$request = Yii::$app->request;
$id = $request->get('id', '');
$fee = $request->get('fee',0);
if($id){
$id = $request->get('id', '');
$fee = $request->get('fee', 0);
if ($id) {
$minerFee = MinerFee::find()->where(['id' => $id])->one();
if(!$minerFee){
return ['code' => 1,'msg' =>'币种旷工费异常'];
if (!$minerFee) {
return ['code' => 1, 'msg' => '币种旷工费异常'];
}
$minerFee->fee = $fee;
$minerFee->update_at = date('Y-m-d H:i:s');
$minerFee->save();
return ['code' => 0,'msg' => '旷工费设置成功'];
}else{
return ['code' => 1 ,'msg' => '旷工费设置失败'];
return ['code' => 0, 'msg' => '旷工费设置成功'];
} else {
return ['code' => 1, 'msg' => '旷工费设置失败'];
}
}
}
......
......@@ -8,6 +8,7 @@
namespace backend\models\coin;
use common\models\psources\MinerFee;
use yii\base\Model;
class MinerFeeForm extends Model
......@@ -18,6 +19,17 @@ class MinerFeeForm extends Model
public $min;
public $level;
public $type;
public $fee;
//定义场景
const SCENARIOS_WALLET_CREATE = 'wallet_create';
const SCENARIOS_WALLET_UPDATE = 'wallet_update';
const SCENARIOS_TRUSTEESHIP_CREATE = 'trusteeship_create';
const SCENARIOS_TRUSTEESHIP_UPDATE = 'trusteeship_update';
const TYPE_WALLET = 1; //币钱包
const TYPE_TRUSTEESHIP = 2; //托管钱包
public function formName()
{
......@@ -27,27 +39,39 @@ class MinerFeeForm extends Model
public function rules()
{
return [
[['id', 'min', 'max', 'level'], 'required', 'on' => 'edit'],
[['platform', 'min', 'max', 'level'], 'required', 'on' => 'add'],
[['platform', 'min', 'max', 'level', 'fee'], 'required'],
[['id', 'max', 'min', 'level'], 'number'],
['platform', 'isExist','on' => [self:: SCENARIOS_TRUSTEESHIP_CREATE]]
];
}
public function isExist($attribute, $params)
{
$count = MinerFee::find()->where(['platform' => $this->platform, 'type' => self::TYPE_TRUSTEESHIP])->count();
if($count > 0) {
$this->addError('platform', '该平台已存在');
}
}
public function scenarios()
{
return [
'add' => ['platform', 'min', 'max', 'level'],
'edit' => ['id', 'min', 'max', 'level'],
$scenarios = [
self:: SCENARIOS_WALLET_CREATE => ['platform', 'min', 'max', 'level'],
self:: SCENARIOS_WALLET_UPDATE => ['platform', 'min', 'max', 'level'],
self:: SCENARIOS_TRUSTEESHIP_CREATE => ['platform', 'type', 'fee'],
self:: SCENARIOS_TRUSTEESHIP_UPDATE => ['platform', 'type', 'fee'],
];
return array_merge(parent:: scenarios(), $scenarios);
}
public function attributeLabels()
{
return [
'platform' => '平台',
'min' => '最小值',
'max' => '最大值',
'level' => '分档',
'min' => '最小值',
'max' => '最大值',
'level' => '分档',
'fee' => '手续费'
];
}
}
\ No newline at end of file
......@@ -8,4 +8,4 @@
?>
<h4>添加币种</h4>
<?= $this->render('form', ['model' => $model]) ?>
\ No newline at end of file
<?= $this->render('form', ['model' => $model, 'platforms' => $platforms, 'type' => $type]) ?>
\ No newline at end of file
......@@ -8,4 +8,4 @@
?>
<h4>修改信息</h4>
<?= $this->render('form', ['model' => $model]) ?>
<?= $this->render('form', ['model' => $model, 'platforms' => $platforms, 'type' => $type]) ?>
<?php
/**
* Created by PhpStorm.
* User: rlgyzhcn
* Date: 18-5-31
* Time: 下午3:28
*/
/**
* @var $model backend\models\coin\CoinForm;
*/
use common\models\psources\Coin;
$platforms = Coin::getChainList();
?>
<style>
.layui-form-label {
width: 100px;
......@@ -24,46 +8,51 @@ $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 ?>">
<?php if ($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>
</div>
<?php else :?>
<div class="layui-form-item">
<label class="layui-form-label">平台</label>
<div class="layui-input-block">
<select name="platform">
<?php foreach ($platforms as $platform): ?>
<option value="<?= $platform ?>" <?php if ($model->platform == $platform) {
echo "selected";
} ?>><?= $platform ?></option>
<?php endforeach; ?>
</select>
<div class="layui-form-item">
<label class="layui-form-label">手续费</label>
<div class="layui-input-block">
<input class="layui-input" name="fee" value="<?= $model->fee ?>">
</div>
</div>
</div>
<?php endif;?>
<div class="layui-form-item">
<label class="layui-form-label">最小值</label>
<div class="layui-input-block">
<input class="layui-input" name="min" value="<?= $model->min ?>">
<?php else : ?>
<div class="layui-form-item">
<label class="layui-form-label">平台</label>
<div class="layui-input-block">
<select name="platform">
<?php foreach ($platforms as $platform): ?>
<option value="<?= $platform ?>" <?php if ($model->platform == $platform) {
echo "selected";
} ?>><?= $platform ?></option>
<?php endforeach; ?>
</select>
</div>
</div>
</div>
<div class="layui-form-item">
<label class="layui-form-label">最大值</label>
<div class="layui-input-block">
<input class="layui-input" name="max" value="<?= $model->max ?>">
<div class="layui-form-item">
<label class="layui-form-label">最小值</label>
<div class="layui-input-block">
<input class="layui-input" name="min" value="<?= $model->min ?>">
</div>
</div>
</div>
<div class="layui-form-item">
<label class="layui-form-label">分档</label>
<div class="layui-input-block">
<input class="layui-input" name="level" value="<?= $model->level ?>">
<div class="layui-form-item">
<label class="layui-form-label">最大值</label>
<div class="layui-input-block">
<input class="layui-input" name="max" value="<?= $model->max ?>">
</div>
</div>
</div>
<div class="layui-form-item">
<label class="layui-form-label">分档</label>
<div class="layui-input-block">
<input class="layui-input" name="level" value="<?= $model->level ?>">
</div>
</div>
<?php endif; ?>
<div class="layui-form-item">
<button class="layui-btn">提交</button>
</div>
......
......@@ -25,8 +25,12 @@
</div>
<div class="layui-tab-item">
<button class="layui-btn layui-btn-default" id="update-coin">更新币种库</button>
<table class="layui-table" id="table2" lay-filter="table2" ></table>
<a href="/admin/miner-fee/add?type=2">
<button class="layui-btn">添加矿工费</button>
</a>
<div class="layui-row">
<table class="layui-table" id="table2" lay-filter="table2"></table>
</div>
</div>
</div>
......@@ -56,9 +60,10 @@
cols: [[
{field: 'id', title: 'ID'},
{field: 'platform', title: '币种'},
{field: 'fee', title: '旷工费' ,edit: 'text'},
{field: 'fee', title: '旷工费', edit: 'text'},
{field: 'create_at', title: '创建时间'},
{field: 'update_at', title: '更新时间'},
{field: 'id', title: '操作', templet: "#operatorTpl"}
]],
url: '/admin/miner-fee/cost?type=2'
});
......@@ -66,7 +71,7 @@
$('#update-coin').click(function () {
$.get('/admin/miner-fee/update-coin', {}, function (rev) {
layer.msg(rev.msg);
if (0==rev.code) {
if (0 == rev.code) {
table.reload('table2', {
page: {
curr: 1
......@@ -76,14 +81,14 @@
});
});
//监听单元格编辑
table.on('edit(table2)', function(obj){
table.on('edit(table2)', function (obj) {
var value = obj.value; //得到修改后的值
var data = obj.data; //得到所在行所有键值
$.get('/admin/miner-fee/set-fee', {id:data.id,fee:value}, function(rev) {
$.get('/admin/miner-fee/set-fee', {id: data.id, fee: value}, function (rev) {
layer.msg(rev.msg);
if (0 == rev.code) {
table.reload('table2',{});
}else{
table.reload('table2', {});
} else {
}
});
......
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