行为日志完成

master
zhengyongxing 5 years ago
parent 80f8eb431c
commit d2867b4635

@ -60,19 +60,20 @@ class AdminController extends Controller {
if ($rule == "admin/index/index"){
//如果首页没有访问权限 自动检测有访问权限的页面然后跳转过去
$qx = M("Auth_group")->table("__AUTH_GROUP__ as ag")
->join("__AUTH_GROUP_ACCESS__ as aga on(ag.id=aga.group_id and aga.uid=".UID.")",'right')
->where("ag.status=1")->limit(1)->select();
if (empty($qx)){
//如果没有任何权限 直接登出
D('Member')->logout();
session('[destroy]');
}
$where['id'] = substr($qx[0]['rules'],0,strpos($qx[0]['rules'], ','));
//$where['id'] = substr($qx[0]['rules'],0,1)
$dz = M("auth_rule")->field('name')->where($where)->find();
$red = substr($dz['name'],6);
redirect(U("$red"));
// $qx = M("Auth_group")->table("__AUTH_GROUP__ as ag")
// ->join("__AUTH_GROUP_ACCESS__ as aga on(ag.id=aga.group_id and aga.uid=".UID.")",'right')
// ->where("ag.status=1")->limit(1)->select();
// if (empty($qx)){
// //如果没有任何权限 直接登出
// D('Member')->logout();
// session('[destroy]');
// }
// $where['id'] = substr($qx[0]['rules'],0,strpos($qx[0]['rules'], ','));
// //$where['id'] = substr($qx[0]['rules'],0,1)
// $dz = M("auth_rule")->field('name')->where($where)->find();
// $red = substr($dz['name'],6);
// redirect(U("$red"));
redirect(U("Admin/Member/user_info"));
}else{
$this->error('未授权访问!');
}

@ -0,0 +1,299 @@
<?php
// +----------------------------------------------------------------------
// | OneThink [ WE CAN DO IT JUST THINK IT ]
// +----------------------------------------------------------------------
// | Copyright (c) 2013 http://www.onethink.cn All rights reserved.
// +----------------------------------------------------------------------
// | Author: 麦当苗儿 <zuojiazi@vip.qq.com> <http://www.zjzit.cn>
// +----------------------------------------------------------------------
namespace Admin\Controller;
use User\Api\UserApi;
use Com\Wechat;
use Com\WechatAuth;
/**
* 后台用户控制器
* @author 麦当苗儿 <zuojiazi@vip.qq.com>
*/
class UserActionLogController extends AdminController
{
public function index($p = 0) {
$page = intval($p);
$page = $page ? $page : 1; //默认显示第一页数据
$arraypage = $page;
if (isset($_REQUEST['row'])) {
$row = $_REQUEST['row'];
} else {
$row = 10;
}
$map = [];
if ($_REQUEST['time_start']&&!$_REQUEST['time_end']) {
$map['create_time'] = ['egt',strtotime($_REQUEST['time_start'])];
}
if (!$_REQUEST['time_start']&&$_REQUEST['time_end']) {
$map['create_time'] = ['elt',strtotime($_REQUEST['time_end'])];
}
if ($_REQUEST['time_start']&&$_REQUEST['time_end']) {
$map['create_time'] = ['egt',strtotime($_REQUEST['time_start'])];
$map['create_time'] = ['elt',strtotime($_REQUEST['time_end'])];
}
if ($_REQUEST['action']) {
$map['action'] = ['like',"%{$_REQUEST['action']}%"];
}
$data = M('user_action_log','tab_')->where($map)->page($page,$row)->order('create_time DESC')->select();
$count = M('user_action_log','tab_')->where($map)->order('create_time DESC')->count();
$page = set_pagination($count, $row);
if ($page) {
$this->assign('_page', $page);//分页
}
$this->assign('data',$data);
$this->display();
}
public function del() {
if (!$_REQUEST['id']) {
$this->ajaxReturn(['status'=>1001]);
}
$map['id'] = $_REQUEST['id'];
$is_del = M('user_action_log','tab_')->where($map)->delete();
if ($is_del) {
$this->ajaxReturn(['status'=>1]);
} else {
$this->ajaxReturn(['status'=>0]);
}
}
public function export() {
$xlsName = $_REQUEST['xlsname'];
$xlsCell = array(
'编号','行为','游戏','玩家','操作时间','操作IP地址'
);
$map = [];
if ($_REQUEST['time_start']&&!$_REQUEST['time_end']) {
$map['create_time'] = ['egt',strtotime($_REQUEST['time_start'])];
}
if (!$_REQUEST['time_start']&&$_REQUEST['time_end']) {
$map['create_time'] = ['elt',strtotime($_REQUEST['time_end'])];
}
if ($_REQUEST['time_start']&&$_REQUEST['time_end']) {
$map['create_time'] = ['egt',strtotime($_REQUEST['time_start'])];
$map['create_time'] = ['elt',strtotime($_REQUEST['time_end'])];
}
if ($_REQUEST['action']) {
$map['action'] = ['like',"%{$_REQUEST['action']}%"];
}
$csvFileName = $xlsName.'.csv';
//设置好告诉浏览器要下载excel文件的headers
header('Content-Description: File Transfer');
header('Content-Type: application/vnd.ms-excel');
header('Content-Disposition: attachment; filename="'. $csvFileName .'"');
header('Expires: 0');
header('Cache-Control: must-revalidate');
header('Pragma: public');
$fp = fopen('php://output', 'a');//打开output流
mb_convert_variables('GBK', 'UTF-8', $xlsCell);
fputcsv($fp, $xlsCell);//将数据格式化为CSV格式并写入到output流中
$accessNum=M('user_action_log','tab_')->where($map)->order('create_time DESC')->count();
$perSize = 5000;//每次查询的条数
$pages = ceil($accessNum / $perSize);
for($i = 1; $i <= $pages; $i++) {
/* 获取频道列表 */
$xlsData = M('user_action_log','tab_')
->field("id,action,game_name,account,create_time,ip")
->where($map)
->limit(($i-1)*$perSize ,$perSize)
->order('create_time DESC')->select();
foreach($xlsData as $key => $value) {
$value['create_time'] = date("Y-m-d H:i:s", $value['create_time']);
mb_convert_variables('GBK', 'UTF-8', $value);
fputcsv($fp, $value);
}
unset($xlsData);//释放变量的内存
//刷新输出缓冲到浏览器
ob_flush();
flush();//必须同时使用 ob_flush() 和flush() 函数来刷新输出缓冲。
}
fclose($fp);
exit();
}
public function operateLog($p = 0) {
$page = intval($p);
$page = $page ? $page : 1; //默认显示第一页数据
$arraypage = $page;
if (isset($_REQUEST['row'])) {
$row = $_REQUEST['row'];
} else {
$row = 10;
}
$map = [];
if ($_REQUEST['time_start']&&!$_REQUEST['time_end']) {
$map['create_time'] = ['egt',strtotime($_REQUEST['time_start'])];
}
if (!$_REQUEST['time_start']&&$_REQUEST['time_end']) {
$map['create_time'] = ['elt',strtotime($_REQUEST['time_end'])];
}
if ($_REQUEST['time_start']&&$_REQUEST['time_end']) {
$map['create_time'] = ['egt',strtotime($_REQUEST['time_start'])];
$map['create_time'] = ['elt',strtotime($_REQUEST['time_end'])];
}
if ($_REQUEST['action']) {
$map['op_name'] = ['like',"%{$_REQUEST['action']}%"];
}
$data = M('operation_log','tab_')
->where($map)
->page($page,$row)
->order('create_time DESC')
->select();
$count = M('operation_log','tab_')->where($map)->order('create_time DESC')->count();
$page = set_pagination($count, $row);
if ($page) {
$this->assign('_page', $page);//分页
}
$this->assign('data',$data);
$this->display();
}
public function operateLogDel() {
if (!$_REQUEST['id']) {
$this->ajaxReturn(['status'=>1001]);
}
$map['id'] = $_REQUEST['id'];
$is_del = M('operation_log','tab_')->where($map)->delete();
if ($is_del) {
$this->ajaxReturn(['status'=>1]);
} else {
$this->ajaxReturn(['status'=>0]);
}
}
public function operateLoExport() {
$xlsName = $_REQUEST['xlsname'];
$xlsCell = array(
'编号','位置','类型','操作人','操作时间','操作IP地址'
);
$map = [];
if ($_REQUEST['time_start']&&!$_REQUEST['time_end']) {
$map['create_time'] = ['egt',strtotime($_REQUEST['time_start'])];
}
if (!$_REQUEST['time_start']&&$_REQUEST['time_end']) {
$map['create_time'] = ['elt',strtotime($_REQUEST['time_end'])];
}
if ($_REQUEST['time_start']&&$_REQUEST['time_end']) {
$map['create_time'] = ['egt',strtotime($_REQUEST['time_start'])];
$map['create_time'] = ['elt',strtotime($_REQUEST['time_end'])];
}
if ($_REQUEST['action']) {
$map['op_name'] = ['like',"%{$_REQUEST['action']}%"];
}
$csvFileName = $xlsName.'.csv';
//设置好告诉浏览器要下载excel文件的headers
header('Content-Description: File Transfer');
header('Content-Type: application/vnd.ms-excel');
header('Content-Disposition: attachment; filename="'. $csvFileName .'"');
header('Expires: 0');
header('Cache-Control: must-revalidate');
header('Pragma: public');
$fp = fopen('php://output', 'a');//打开output流
mb_convert_variables('GBK', 'UTF-8', $xlsCell);
fputcsv($fp, $xlsCell);//将数据格式化为CSV格式并写入到output流中
$accessNum=M('operation_log','tab_')->where($map)->order('create_time DESC')->count();
$perSize = 5000;//每次查询的条数
$pages = ceil($accessNum / $perSize);
for($i = 1; $i <= $pages; $i++) {
/* 获取频道列表 */
$xlsData = M('operation_log','tab_')
->field("id,menu,key,op_name,admin_account,create_time,op_ip")
->where($map)
->limit(($i-1)*$perSize ,$perSize)
->order('create_time DESC')->select();
foreach($xlsData as $key => $value) {
$value['menu'] = $value['menu'].'-'.$value['key'];
$value['create_time'] = date("Y-m-d H:i:s", $value['create_time']);
unset($value['key']);
mb_convert_variables('GBK', 'UTF-8', $value);
fputcsv($fp, $value);
}
unset($xlsData);//释放变量的内存
//刷新输出缓冲到浏览器
ob_flush();
flush();//必须同时使用 ob_flush() 和flush() 函数来刷新输出缓冲。
}
fclose($fp);
exit();
}
}

@ -0,0 +1,239 @@
<extend name="Public/base"/>
<block name="body">
<link rel="stylesheet" href="__CSS__/select2.min.css" type="text/css" />
<script type="text/javascript" src="__JS__/bootstrap.min.js"></script>
<script type="text/javascript" src="__JS__/select2.min.js"></script>
<script type="text/javascript" src="__STATIC__/layer3/layer.js"></script>
<style>
.select2-container--default .select2-selection--single {
color: #000;
resize: none;
border-width: 1px;
border-style: solid;
border-color: #a7b5bc #ced9df #ced9df #a7b5bc;
box-shadow: 0px 3px 3px #F7F8F9 inset;height:35px;
height:28px;border-radius:3px;font-size:12px;
}
.select2-container--default .select2-selection--single .select2-selection__rendered {
line-height:35px;
line-height:28px;
}
.select2-container--default .select2-selection--single .select2-selection__arrow {
height:26px;
}
.select2-container--default .select2-search--dropdown .select2-search__field {
height:26px;line-height:26px;font-size:12px;
}
.select2-results__option[aria-selected] {font-size:12px;}
</style>
<div class="cf main-place top_nav_list navtab_list">
<h3 class="page_title">行为日志</h3>
<p class="description_text"></p>
</div>
<div class="cf top_nav_list">
<!-- 高级搜索 -->
<div class="jssearch fl cf search_list" style="margin: 0 30%">
<!--游戏类型搜索END-->
<div class="input-list">
<input type="text" id="time-start" name="time_start" class="" value="{:I('time_end')}" placeholder="操作开始时间" autocomplete="off"/>
-
<div class="input-append date" id="datetimepicker" style="display:inline-block">
<input type="text" id="time-end" name="time_end" class="" value="{:I('time_end')}" placeholder="操作结束时间" autocomplete="off"/>
<span class="add-on"><i class="icon-th"></i></span>
</div>
</div>
<div class="input-list">
<input type="text" name="action" placeholder="关键字" class="" value="{:I('action')}" style="width: 180px"/>&nbsp;
</div>
<div class="input-list">
<a class="sch-btn" href="javascript:;" id="search" url="{:U('UserActionLog/index','model='.$model['name'].'&row='.I('row'),false)}" style="">搜索</a>
</div>
</div>
</div>
<!-- 数据列表 -->
<div class="data_list">
<div class="">
<table>
<!-- 表头 -->
<thead>
<tr>
<th >编号</th>
<th >行为</th>
<th >游戏</th>
<th>玩家</th>
<th >操作时间</th>
<th >操作IP地址</th>
<th >操作</th>
</tr>
</thead>
<!-- 列表 -->
<tbody>
<style>
.data-table thead th, .data-table tbody td{text-align:center}
.data-table tbody td{border-right:1px solid #DDDDDD;}
.d_list .drop-down ul {z-index:999;}
</style>
<if condition = "empty($data)">
<tr>
<td colspan="14" class="text-center">aOh! 暂时还没有内容!</td>
</tr>
</if>
<notemtpy name = "data">
<volist name="data" id="data" key="$key">
<tr>
<td >{$data.id}</td>
<td >{$data.action}</td>
<td >{$data.game_name}</td>
<td >{$data.account}</td>
<td >{$data.create_time|date='Y-m-d H:i:s',###}</td>
<td >{$data.ip}</td>
<td ><a class="confirm del" data-id="{$data.id}">删除</a></td>
</tr>
</volist>
</notemtpy>
</tbody>
</table>
</div>
</div>
<div class="page">
<a class="sch-btn export-btn" href="{:U('UserActionLog/export',array_merge(['xlsname'=>'行为日志'],I('get.')))}" target="_blank">导出</a>
{$_page|default=''}
</div>
</block>
<block name="script">
<link href="__STATIC__/datetimepicker/css/datetimepicker.css" rel="stylesheet" type="text/css">
<php>if(C('COLOR_STYLE')=='blue_color') echo '<link href="__STATIC__/datetimepicker/css/datetimepicker_blue.css" rel="stylesheet" type="text/css">';</php>
<link href="__STATIC__/datetimepicker/css/dropdown.css" rel="stylesheet" type="text/css">
<script type="text/javascript" src="__STATIC__/datetimepicker/js/bootstrap-datetimepicker.min.js"></script>
<script type="text/javascript" src="__STATIC__/datetimepicker/js/locales/bootstrap-datetimepicker.zh-CN.js" charset="UTF-8"></script>
<script type="text/javascript">
//导航高亮
highlight_subnav('{:U("UserActionLog/index")}');
$(function () {
<volist name=":I('get.')" id="vo">
Think.setValue('{$key}',"{$vo}");
</volist>
});
</script>
<script type="text/javascript">
$(".select_gallery").select2();
function reload() {
window.location.reload();
}
$(function(){
$('#time-start').datetimepicker({
format: 'yyyy-mm-dd',
language: "zh-CN",
showMeridian:true,
pickDate:true,
minView: 2,
autoclose: true,
pickTime:true,
todayBtn:true,
}).on('change',function(ev){
var val = new Date($.trim($(this).val())).getTime();
var end = new Date($.trim($('#time-end').val())).getTime();
if (val>end) {
layer.msg('开始时间大于结束时间!');$(this).val('');
}
return false;
});
$("#time-end").datetimepicker({
format:"yyyy-mm-dd",
language: "zh-CN",
showMeridian:true,
minView:2,
autoclose:true,
todayBtn:true,
}).on('change',function(ev){
var val = new Date($.trim($(this).val())).getTime();
var start = new Date($.trim($('#time-start').val())).getTime();
if (val<start) {
layer.msg('开始时间大于结束时间!');$(this).val('');
}
return false;
});
//搜索功能
$("#search").click(function(){
var starttime = $.trim($('#time-start').val());
var endtime = $.trim($('#time-end').val());
if (starttime && endtime && starttime > endtime) {layer.msg('开始时间必须小于等于结束时间');return false;}
var url = $(this).attr('url');
var query = $('.jssearch').find('input').serialize();
query += "&" + $('.jssearch').find('select').serialize();
query = query.replace(/(&|^)(\w*?\d*?\-*?_*?)*?=?((?=&)|(?=$))/g,'');
query = query.replace(/^&/g,'');
if( url.indexOf('?')>0 ){
url += '&' + query;
}else{
url += '?' + query;
}
window.location.replace(url);
});
//回车自动提交
$('.jssearch').find('input').keyup(function(event){
if(event.keyCode===13){
$("#search").click();
}
});
})
$(".del").click(function () {
var del = $(this).data();
layer.confirm('【警告】撤销后将不可回退,如需继续请点击确认', {
btn: ['确认','取消'],
title:false
}, function(){
var url = "/admin.php?s=/UserActionLog/del/id/"+del.id;
layer.load(2);
$.ajax({
url: url,
type: "get",
dataType: "json",
success: function (data) {
if(data.status == 1){
layer.closeAll('loading');
layer.msg("<font style='color: red'>删除成功</font>");
setTimeout(function(){
window.location.reload();
},350);
}else{
alert("删除失败")
}
}
})
}, function(){
});
});
</script>
</block>

@ -0,0 +1,239 @@
<extend name="Public/base"/>
<block name="body">
<link rel="stylesheet" href="__CSS__/select2.min.css" type="text/css" />
<script type="text/javascript" src="__JS__/bootstrap.min.js"></script>
<script type="text/javascript" src="__JS__/select2.min.js"></script>
<script type="text/javascript" src="__STATIC__/layer3/layer.js"></script>
<style>
.select2-container--default .select2-selection--single {
color: #000;
resize: none;
border-width: 1px;
border-style: solid;
border-color: #a7b5bc #ced9df #ced9df #a7b5bc;
box-shadow: 0px 3px 3px #F7F8F9 inset;height:35px;
height:28px;border-radius:3px;font-size:12px;
}
.select2-container--default .select2-selection--single .select2-selection__rendered {
line-height:35px;
line-height:28px;
}
.select2-container--default .select2-selection--single .select2-selection__arrow {
height:26px;
}
.select2-container--default .select2-search--dropdown .select2-search__field {
height:26px;line-height:26px;font-size:12px;
}
.select2-results__option[aria-selected] {font-size:12px;}
</style>
<div class="cf main-place top_nav_list navtab_list">
<h3 class="page_title">操作日志</h3>
<p class="description_text"></p>
</div>
<div class="cf top_nav_list">
<!-- 高级搜索 -->
<div class="jssearch fl cf search_list" style="margin: 0 30%">
<!--游戏类型搜索END-->
<div class="input-list">
<input type="text" id="time-start" name="time_start" class="" value="{:I('time_end')}" placeholder="操作开始时间" autocomplete="off"/>
-
<div class="input-append date" id="datetimepicker" style="display:inline-block">
<input type="text" id="time-end" name="time_end" class="" value="{:I('time_end')}" placeholder="操作结束时间" autocomplete="off"/>
<span class="add-on"><i class="icon-th"></i></span>
</div>
</div>
<div class="input-list">
<input type="text" name="action" placeholder="关键字" class="" value="{:I('action')}" style="width: 180px"/>&nbsp;
</div>
<div class="input-list">
<a class="sch-btn" href="javascript:;" id="search" url="{:U('UserActionLog/operateLog','model='.$model['name'].'&row='.I('row'),false)}" style="">搜索</a>
</div>
</div>
</div>
<!-- 数据列表 -->
<div class="data_list">
<div class="">
<table>
<!-- 表头 -->
<thead>
<tr>
<th >编号</th>
<th >位置</th>
<th >类型</th>
<th>操作人</th>
<th >操作时间</th>
<th >操作IP地址</th>
<th >操作</th>
</tr>
</thead>
<!-- 列表 -->
<tbody>
<style>
.data-table thead th, .data-table tbody td{text-align:center}
.data-table tbody td{border-right:1px solid #DDDDDD;}
.d_list .drop-down ul {z-index:999;}
</style>
<if condition = "empty($data)">
<tr>
<td colspan="14" class="text-center">aOh! 暂时还没有内容!</td>
</tr>
</if>
<notemtpy name = "data">
<volist name="data" id="data" key="$key">
<tr>
<td >{$data.id}</td>
<td ><if condition="$data['op_type'] neq 2"><a href="{$data.url}" target="_blank">{$data.menu}-{$data.key}</a><else/>{$data.menu}-{$data.key}</if></td>
<td >{$data.op_name}</td>
<td >{$data.admin_account}</td>
<td >{$data.create_time|date='Y-m-d H:i:s',###}</td>
<td >{$data.op_ip}</td>
<td ><a class="confirm del" data-id="{$data.id}">删除</a></td>
</tr>
</volist>
</notemtpy>
</tbody>
</table>
</div>
</div>
<div class="page">
<a class="sch-btn export-btn" href="{:U('UserActionLog/operateLoExport',array_merge(['xlsname'=>'操作日志'],I('get.')))}" target="_blank">导出</a>
{$_page|default=''}
</div>
</block>
<block name="script">
<link href="__STATIC__/datetimepicker/css/datetimepicker.css" rel="stylesheet" type="text/css">
<php>if(C('COLOR_STYLE')=='blue_color') echo '<link href="__STATIC__/datetimepicker/css/datetimepicker_blue.css" rel="stylesheet" type="text/css">';</php>
<link href="__STATIC__/datetimepicker/css/dropdown.css" rel="stylesheet" type="text/css">
<script type="text/javascript" src="__STATIC__/datetimepicker/js/bootstrap-datetimepicker.min.js"></script>
<script type="text/javascript" src="__STATIC__/datetimepicker/js/locales/bootstrap-datetimepicker.zh-CN.js" charset="UTF-8"></script>
<script type="text/javascript">
//导航高亮
highlight_subnav('{:U("UserActionLog/operateLog")}');
$(function () {
<volist name=":I('get.')" id="vo">
Think.setValue('{$key}',"{$vo}");
</volist>
});
</script>
<script type="text/javascript">
$(".select_gallery").select2();
function reload() {
window.location.reload();
}
$(function(){
$('#time-start').datetimepicker({
format: 'yyyy-mm-dd',
language: "zh-CN",
showMeridian:true,
pickDate:true,
minView: 2,
autoclose: true,
pickTime:true,
todayBtn:true,
}).on('change',function(ev){
var val = new Date($.trim($(this).val())).getTime();
var end = new Date($.trim($('#time-end').val())).getTime();
if (val>end) {
layer.msg('开始时间大于结束时间!');$(this).val('');
}
return false;
});
$("#time-end").datetimepicker({
format:"yyyy-mm-dd",
language: "zh-CN",
showMeridian:true,
minView:2,
autoclose:true,
todayBtn:true,
}).on('change',function(ev){
var val = new Date($.trim($(this).val())).getTime();
var start = new Date($.trim($('#time-start').val())).getTime();
if (val<start) {
layer.msg('开始时间大于结束时间!');$(this).val('');
}
return false;
});
//搜索功能
$("#search").click(function(){
var starttime = $.trim($('#time-start').val());
var endtime = $.trim($('#time-end').val());
if (starttime && endtime && starttime > endtime) {layer.msg('开始时间必须小于等于结束时间');return false;}
var url = $(this).attr('url');
var query = $('.jssearch').find('input').serialize();
query += "&" + $('.jssearch').find('select').serialize();
query = query.replace(/(&|^)(\w*?\d*?\-*?_*?)*?=?((?=&)|(?=$))/g,'');
query = query.replace(/^&/g,'');
if( url.indexOf('?')>0 ){
url += '&' + query;
}else{
url += '?' + query;
}
window.location.replace(url);
});
//回车自动提交
$('.jssearch').find('input').keyup(function(event){
if(event.keyCode===13){
$("#search").click();
}
});
})
$(".del").click(function () {
var del = $(this).data();
layer.confirm('【警告】撤销后将不可回退,如需继续请点击确认', {
btn: ['确认','取消'],
title:false
}, function(){
var url = "/admin.php?s=/UserActionLog/operateLogDel/id/"+del.id;
layer.load(2);
$.ajax({
url: url,
type: "get",
dataType: "json",
success: function (data) {
if(data.status == 1){
layer.closeAll('loading');
layer.msg("<font style='color: red'>删除成功</font>");
setTimeout(function(){
window.location.reload();
},350);
}else{
alert("删除失败")
}
}
})
}, function(){
});
});
</script>
</block>
Loading…
Cancel
Save