Commit 328f11e3 authored by ZhuChunYang's avatar ZhuChunYang

批量添加币种配置

parent 1ccfcbf9
......@@ -359,4 +359,66 @@ class CoinController extends BaseController
return ['coin' => -1, 'msg' => '币种不存在'];
}
}
public function actionPackageCopy()
{
if (Yii::$app->request->isAjax) {
Yii::$app->response->format = Response::FORMAT_JSON;
$get = Yii::$app->request->get();
$platform_id = $get['platform_id'] ?? '';
$coin_ids = $get['coin_ids'] ?? '';
foreach (['platform_id' => '钱包', 'coin_ids' => '币种'] as $key => $value) {
if (empty($$key)) {
return ['code' => -1, 'msg' => $value . '不能为空'];
}
}
$user_platform_id = Yii::$app->user->identity->platform_id;
if ($user_platform_id == Yii::$app->params['admin']) {
$coin_id_items = explode(',',$coin_ids);
foreach($coin_id_items as $id) {
$coin = Coin::getOneById($id);
if($coin){
$platform_ids = explode(',',$coin->platform_id);
$platform_ids = implode(',', array_unique(array_merge($platform_ids, [$platform_id])));
$coin->platform_id = $platform_ids;
$coin->save();
}
}
return ['code' => 0, 'msg' => '复制成功'];
}
return ['code' => -1, 'msg' => '没有权限修改'];
}
}
public function actionPackageBatchDel()
{
if (Yii::$app->request->isAjax) {
/* Yii::$app->response->format = Response::FORMAT_JSON;
$get = Yii::$app->request->get();
$platform_id = $get['platform_id'] ?? '';
$coin_ids = $get['coin_ids'] ?? '';
foreach (['platform_id' => '钱包', 'coin_ids' => '币种'] as $key => $value) {
if (empty($$key)) {
return ['code' => -1, 'msg' => $value . '不能为空'];
}
}
$user_platform_id = Yii::$app->user->identity->platform_id;
if ($user_platform_id == Yii::$app->params['admin']) {
$coin_id_items = explode(',',$coin_ids);
foreach($coin_id_items as $id) {
$coin = Coin::getOneById($id);
if($coin){
$platform_ids = explode(',',$coin->platform_id);
$platform_ids = implode(',', array_unique(array_merge($platform_ids, [$platform_id])));
$coin->platform_id = $platform_ids;
$coin->save();
}
}
return ['code' => 0, 'msg' => '复制成功'];
}
return ['code' => -1, 'msg' => '没有权限修改'];*/
}
}
}
......@@ -12,6 +12,9 @@
.layui-form-label{
width: 100px;
}
.myselect .layui-input{
height: 25px;
}
</style>
<div class="layui-row">
<form class="layui-form" lay-filter="form2">
......@@ -87,8 +90,18 @@
</script>
<script type="text/html" id="toolBarTop">
<div class="layui-btn-container">
<button class="layui-btn layui-btn-sm" lay-event="recommend_add">添加</button>
<button class="layui-btn layui-btn-xs" lay-event="recommend_add">添加</button>
<button class="layui-btn layui-btn-xs layui-btn-danger" lay-event="batch_del">批量删除</button>
<div class="layui-inline" style="padding-left:100px">
<button class="layui-btn layui-btn-xs layui-btn-normal" lay-event="copy">复制到</button>
<div class="layui-input-inline myselect">
<select class="layui-select" name="copy_platform_id" id="copy_platform_id">
<option value="">选择一个钱包</option>
<?php foreach($platforms as $key => $value): ?>
<option value="<?= $value['id'] ?>"><?= $value['name'] ?></option>
<?php endforeach; ?>
</select>
</div>
</div>
</script>
......@@ -103,6 +116,10 @@ table.render({
url: '/admin/coin/package',
cols: [[
{
type: 'checkbox',
fixed: 'left'
},
{
field: 'id',
title: 'ID'
},
......@@ -176,6 +193,52 @@ table.on('toolbar(table1)', function(obj) {
$("#_form").css('display', 'none');
}
});
}else if(event == 'copy'){
var checkStatus = table.checkStatus('table1')
,data = checkStatus.data;
var coin_ids = "";
$.each(data,function(index,value){
if(coin_ids){
coin_ids +=","+value.id ;
}else{
coin_ids = value.id;
}
});
var platform_id = $("select[name='copy_platform_id']").val();
$.get('/admin/coin/package-copy', {coin_ids:coin_ids,platform_id:platform_id}, function(rev) {
layer.msg(rev.msg);
if (0 == rev.code) {
layer.close(index);
table.reload('table1', {
page: {
curr: 1
}
});
}
});
}else if(event == 'batch_del'){
var checkStatus = table.checkStatus('table1')
,data = checkStatus.data;
var coin_ids = "";
$.each(data,function(index,value){
if(coin_ids){
coin_ids +=","+value.id ;
}else{
coin_ids = value.id;
}
});
var platform_id = $("select[name='platform_id']").val();
$.get('/admin/coin/package-batch-del', {coin_ids:coin_ids,platform_id:platform_id}, function(rev) {
layer.msg(rev.msg);
if (0 == rev.code) {
layer.close(index);
table.reload('table1', {
page: {
curr: 1
}
});
}
});
}
});
......
......@@ -252,4 +252,12 @@ class Coin extends BaseActiveRecord
}
return $data ? $data : [];
}
/**
* 获取币种
*/
public static function getOneById($id)
{
return self::find()->where(['id' => $id])->one();
}
}
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