Commit 1b40a616 authored by shajiaiming's avatar shajiaiming

增加托管费添加

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