Explorar o código

后台用户权限一键禁用/解禁

zhangxiaobin hai 1 ano
pai
achega
1e495f6954

+ 82 - 1
application/admin/controller/UserPower.php

@@ -3,6 +3,7 @@
 namespace app\admin\controller;
 
 use app\common\controller\Backend;
+use think\Exception;
 
 /**
  * 会员权限管理
@@ -148,9 +149,13 @@ class UserPower extends Backend
                 }
                 if (isset($params['private_messages_time']) && !empty($params['private_messages_time'])) {
                     $params['private_messages_time'] = strtotime($params['private_messages_time']);
+                } else {
+                    $params['private_messages_time'] = 0;
                 }
                 if (isset($params['speak_time']) && !empty($params['speak_time'])) {
                     $params['speak_time'] = strtotime($params['speak_time']);
+                } else {
+                    $params['speak_time'] = 0;
                 }
                 $result = $row->allowField(true)->save($params);
             } catch (ValidateException|PDOException|Exception $e) {
@@ -159,9 +164,85 @@ class UserPower extends Backend
             if ($result == false) {
                 $this->error(__('No rows were updated'));
             }
-            $this->success();
+            $this->success('操作成功');
         }
         $this->view->assign("row", $row);
         return $this->view->fetch();
     }
+
+    /**
+     * 一键禁用
+     */
+    public function powerBan($ids = null)
+    {
+        try {
+            $row = $this->model->get($ids);
+            if (!$row) {
+                throw new Exception(__('No Results were found'));
+            }
+            $adminIds = $this->getDataLimitAdminIds();
+            if (is_array($adminIds)) {
+                if (!in_array($row[$this->dataLimitField], $adminIds)) {
+                    throw new Exception(__('You have no permission'));
+                }
+            }
+            $data = [
+                'private_messages'      => 2,//禁止私聊:0=正常,1=禁止.2=禁止(永久)
+                'private_messages_time' => 0,//禁止私聊时间
+                'speak'                 => 2,//禁言弹幕:0=正常,1=禁止.2=禁止(永久)
+                'speak_time'            => 0,//禁言时间
+                'recharge'              => 1,//充值:0=正常,1=禁止
+                'raffle'                => 1,//抽奖:0=正常,1=禁止
+                'give_gift'             => 1,//赠送礼物:0=正常,1=禁止
+                'transfer'              => 1,//转账:0=正常,1=禁止
+                'payorder'              => 1,//下单:0=正常,1=禁止
+                'attire'                => 1,//购买装扮:0=正常,1=禁止
+                'noble'                 => 1,//开通贵族:0=正常,1=禁止
+                'withdraw'              => 1,//提现:0=允许,1=禁止
+            ];
+            $where['id'] = $ids;
+            $res = $this->model->update($data,$where);
+            $this->success('操作成功');
+        } catch (Exception $e) {
+            $this->error($e->getMessage());
+        }
+    }
+
+    /**
+     * 一键解禁
+     */
+    public function powerUnban($ids = null)
+    {
+        try {
+            $row = $this->model->get($ids);
+            if (!$row) {
+                throw new Exception(__('No Results were found'));
+            }
+            $adminIds = $this->getDataLimitAdminIds();
+            if (is_array($adminIds)) {
+                if (!in_array($row[$this->dataLimitField], $adminIds)) {
+                    throw new Exception(__('You have no permission'));
+                }
+            }
+            $data = [
+                'private_messages'      => 0,//禁止私聊:0=正常,1=禁止.2=禁止(永久)
+                'private_messages_time' => 0,//禁止私聊时间
+                'speak'                 => 0,//禁言弹幕:0=正常,1=禁止.2=禁止(永久)
+                'speak_time'            => 0,//禁言时间
+                'recharge'              => 0,//充值:0=正常,1=禁止
+                'raffle'                => 0,//抽奖:0=正常,1=禁止
+                'give_gift'             => 0,//赠送礼物:0=正常,1=禁止
+                'transfer'              => 0,//转账:0=正常,1=禁止
+                'payorder'              => 0,//下单:0=正常,1=禁止
+                'attire'                => 0,//购买装扮:0=正常,1=禁止
+                'noble'                 => 0,//开通贵族:0=正常,1=禁止
+                'withdraw'              => 0,//提现:0=允许,1=禁止
+            ];
+            $where['id'] = $ids;
+            $res = $this->model->update($data,$where);
+            $this->success('操作成功');
+        } catch (Exception $e) {
+            $this->error($e->getMessage());
+        }
+    }
 }

+ 1 - 1
application/admin/model/UserPower.php

@@ -47,7 +47,7 @@ class UserPower extends Model
 
     public function getSpeakList()
     {
-        return ['0' => __('Speak 0'),'1' => __('Speak 1'),'2' => __('Speak 3')];
+        return ['0' => __('Speak 0'),'1' => __('Speak 1'),'2' => __('Speak 2')];
     }
 
     public function getRechargeList()

+ 1 - 1
application/admin/view/gift/back/add.html

@@ -1,7 +1,7 @@
 <form id="add-form" class="form-horizontal" role="form" data-toggle="validator" method="POST" action="">
 
     <div class="form-group">
-        <label class="control-label col-xs-12 col-sm-2">{:__('User_id')}:</label>
+        <label class="control-label col-xs-12 col-sm-2">{:__('用户昵称')}:</label>
         <div class="col-xs-12 col-sm-8">
             <input id="c-user_id" data-rule="required" data-source="user/user/index" data-field="nickname" class="form-control selectpage" name="row[user_id]" type="text" value="">
         </div>

+ 1 - 1
application/admin/view/gift/back/edit.html

@@ -1,7 +1,7 @@
 <form id="edit-form" class="form-horizontal" role="form" data-toggle="validator" method="POST" action="">
 
     <div class="form-group">
-        <label class="control-label col-xs-12 col-sm-2">{:__('User_id')}:</label>
+        <label class="control-label col-xs-12 col-sm-2">{:__('用户昵称')}:</label>
         <div class="col-xs-12 col-sm-8">
             <input id="c-user_id" data-rule="required" data-source="user/user/index" data-field="nickname" class="form-control selectpage" name="row[user_id]" type="text" value="{$row.user_id|htmlentities}">
         </div>

+ 2 - 2
application/admin/view/gift/back/index.html

@@ -7,7 +7,7 @@
                 <div class="widget-body no-padding">
                     <div id="toolbar" class="toolbar">
                         <a href="javascript:;" class="btn btn-primary btn-refresh" title="{:__('Refresh')}" ><i class="fa fa-refresh"></i> </a>
-                        <a href="javascript:;" class="btn btn-success btn-add {:$auth->check('gift/back/add')?'':'hide'}" title="{:__('Add')}" ><i class="fa fa-plus"></i> {:__('Add')}</a>
+                        <!--<a href="javascript:;" class="btn btn-success btn-add {:$auth->check('gift/back/add')?'':'hide'}" title="{:__('Add')}" ><i class="fa fa-plus"></i> {:__('Add')}</a>
                         <a href="javascript:;" class="btn btn-success btn-edit btn-disabled disabled {:$auth->check('gift/back/edit')?'':'hide'}" title="{:__('Edit')}" ><i class="fa fa-pencil"></i> {:__('Edit')}</a>
                         <a href="javascript:;" class="btn btn-danger btn-del btn-disabled disabled {:$auth->check('gift/back/del')?'':'hide'}" title="{:__('Delete')}" ><i class="fa fa-trash"></i> {:__('Delete')}</a>
                         <a href="javascript:;" class="btn btn-danger btn-import {:$auth->check('gift/back/import')?'':'hide'}" title="{:__('Import')}" id="btn-import-file" data-url="ajax/upload" data-mimetype="csv,xls,xlsx" data-multiple="false"><i class="fa fa-upload"></i> {:__('Import')}</a>
@@ -18,7 +18,7 @@
                                 <li><a class="btn btn-link btn-multi btn-disabled disabled" href="javascript:;" data-params="status=normal"><i class="fa fa-eye"></i> {:__('Set to normal')}</a></li>
                                 <li><a class="btn btn-link btn-multi btn-disabled disabled" href="javascript:;" data-params="status=hidden"><i class="fa fa-eye-slash"></i> {:__('Set to hidden')}</a></li>
                             </ul>
-                        </div>
+                        </div>-->
 
                         
                     </div>

+ 1 - 1
public/assets/js/backend/gift/back.js

@@ -34,7 +34,7 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefin
                         {field: 'use_time', title: __('Use_time'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                         {field: 'get_way', title: __('Get_way'), searchList: {"1":__('Get_way 1'),"2":__('Get_way 2'),"3":__('Get_way 3')}, formatter: Table.api.formatter.normal},
                         {field: 'createtime', title: __('Createtime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
-                        {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
+                        //{field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
                     ]
                 ]
             });

+ 44 - 1
public/assets/js/backend/user_power.js

@@ -42,7 +42,50 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefin
                         {field: 'attire', title: __('Attire'), searchList: {"0":__('Attire 0'),"1":__('Attire 1')}, formatter: Table.api.formatter.normal},
                         {field: 'noble', title: __('Noble'), searchList: {"0":__('Noble 0'),"1":__('Noble 1')}, formatter: Table.api.formatter.normal},
                         {field: 'withdraw', title: __('Withdraw'), searchList: {"0":__('Withdraw 0'),"1":__('Withdraw 1')}, formatter: Table.api.formatter.normal},
-                        {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
+                        {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate,
+                            buttons:[
+                                {
+                                    name: 'ban',
+                                    title: __('一键禁用'),
+                                    classname: 'btn btn-xs btn-warning btn-magic btn-ajax',
+                                    icon: 'fa fa-times-circle',
+                                    confirm: '确认一键禁用?',
+                                    url: 'user_power/powerBan',
+                                    success: function (data, ret) {
+                                        //Layer.alert(ret.msg);
+                                        //如果需要阻止成功提示,则必须使用return false;
+                                        if (ret.code == 0) {
+                                            return false;
+                                        }
+                                        table.bootstrapTable('refresh');
+                                    },
+                                    error: function (data, ret) {
+                                        Layer.alert(ret.msg);
+                                        return false;
+                                    }
+                                },
+                                {
+                                    name: 'unban',
+                                    title: __('一键解禁'),
+                                    classname: 'btn btn-xs btn-info btn-magic btn-ajax',
+                                    icon: 'fa fa-check-circle',
+                                    confirm: '确认一键解禁?',
+                                    url: 'user_power/powerUnban',
+                                    success: function (data, ret) {
+                                        //Layer.alert(ret.msg);
+                                        //如果需要阻止成功提示,则必须使用return false;
+                                        if (ret.code == 0) {
+                                            return false;
+                                        }
+                                        table.bootstrapTable('refresh');
+                                    },
+                                    error: function (data, ret) {
+                                        Layer.alert(ret.msg);
+                                        return false;
+                                    }
+                                },
+                            ]
+                        }
                     ]
                 ]
             });