123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119 |
- <?php
- namespace app\common\model;
- use app\hander\HelpHander;
- use think\Db;
- use think\Model;
- class Action extends Model
- {
- public function lists(){
- $lists = Db::name('action')
- ->order('id asc')
- ->select();
- return $lists?$lists:[];
- }
- public function logInfo($id){
- $info = Db::name('action_log')
- ->alias('al')
- ->join('action a','a.id = al.action_id')
- ->join('user_info ui','ui.user_id = al.user_id')
- ->join('user u','u.id = al.user_id')
- ->where('al.id',$id)
- ->field('al.id,al.create_time,al.content,al.device,al.data,a.name as module,u.code,ui.name')
- ->find();
- if(!$info){
- HelpHander::error('记录不存在');
- }
- if($info['data']){
- $info['data'] = json_decode($info['data'],true);
- }
- return $info;
- }
- // 日志列表
- public function selectActionLog($page,$size,$name,$code,$actionId,$startTime,$endTime){
- if($name){
- $map[] = ['ui.name','like','%'.$name.'%'];
- }
- if($code){
- $map[] = ['u.code','like','%'.$code.'%'];
- }
- if($actionId){
- $map[] = ['al.action_id','=',$actionId];
- }
- if($startTime&&$endTime){
- $map[] = ['al.create_time','>=',$startTime];
- $map[] = ['al.create_time','<=',$endTime];
- }
- $map = !empty($map)?$map:true;
- $lists = Db::name('action_log')
- ->alias('al')
- ->join('action a','a.id = al.action_id')
- ->join('user_info ui','ui.user_id = al.user_id')
- ->join('user u','u.id = al.user_id')
- ->where($map)
- ->page($page,$size)
- ->field('al.id,al.create_time,al.content,al.device,a.name as module,u.code,ui.name')
- ->order('al.id desc')
- ->select();
- $total = Db::name('action_log')
- ->alias('al')
- ->join('action a','a.id = al.action_id')
- ->join('user_info ui','ui.user_id = al.user_id')
- ->join('user u','u.id = al.user_id')
- ->where($map)->count();
- $data = [
- 'total' => $total,
- 'list' => $lists?$lists:[]
- ];
- return $data;
- }
- // 日志导出
- public function selectOperationLog($name,$code,$actionId,$startTime,$endTime){
- if($name){
- $map[] = ['ui.name','like','%'.$name.'%'];
- }
- if($code){
- $map[] = ['u.code','like','%'.$code.'%'];
- }
- if($actionId){
- $map[] = ['al.action_id','=',$actionId];
- }
- if($startTime&&$endTime){
- $map[] = ['al.create_time','>=',$startTime];
- $map[] = ['al.create_time','<=',$endTime];
- }
- $map = !empty($map)?$map:true;
- $lists = Db::name('action_log')
- ->alias('al')
- ->join('action a','a.id = al.action_id')
- ->join('user_info ui','ui.user_id = al.user_id')
- ->join('user u','u.id = al.user_id')
- ->where($map)
- ->field('al.id,al.create_time,al.content,al.device,a.name as module,u.code,ui.name')
- ->order('al.id desc')
- ->select();
- $columns = [
- ["title" => "序号","key" => "id"],
- ["title" => "日志行为","key" => "module"],
- ["title" => "操作人","key" => "name"],
- ["title" => "操作人工号","key" => "code"],
- ["title" => "操作说明","key" => "createTime"],
- ["title" => "操作动作","key" => "content"],
- ];
- $data = [
- 'columns' => $columns,
- 'list' => $lists?$lists:[]
- ];
- return $data;
- }
- }
|