123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134 |
- <?php
- namespace app\admin\controller\base;
- /**
- * @title: 系统日志
- * @Description:
- * @Author: goldenrock 112049337@qq.com
- * @Date: 2024-08-24 09:40:45
- * @LastEditTime: 2024-11-29 17:48:58
- * @LastEditors: goldenrock
- * @FilePath: \OA_hbdrwhe:\HBDRWHCODE\JindDongFang_platform\app\admin\controller\base\Systemlog.php
- */
- use app\admin\controller\Base;
- use app\common\model\base\org\Org;
- use app\common\model\base\Systemlog as Syslog;
- use app\common\model\base\user\User;
- use app\common\model\base\user\UserRole;
- class Systemlog extends Base
- {
- protected $model = null;
- public function initialize()
- {
- parent::initialize();
- $this->model = new Syslog;
- }
- //创建列表查询语句
- public function createWhere()
- {
- $data = $this->request->param();
- if(empty($data['org_id'])){
- $org_ids = Org::getChildrenIds($this->userinfo['org_id']);
- }else{
- $org_ids = Org::getChildrenIds($data['org_id']);
- }
- $user_ids = UserRole::where('org_id','in',$org_ids)->column('user_id');
- $where = [['create_uid','in',$user_ids]];
- if(!empty($data['username'])){
- $where[] = ['username','LIKE',"%{$data['username']}%"];
- }
- if(!empty($data['username'])){
- $where[] = ['username','LIKE',"%{$data['username']}%"];
- }
- if(!empty($data['daterange']) && 2==count($data['daterange'])){
- $data['daterange'][1].=' 23:59:59';
- $where[] = ['createtime','between',$data['daterange']];
- }
- return $where;
- }
- /**
- * @title: 系统日志列表
- * @param {int} {pageNo} {非必填,默认值为1} {页码}
- * @param {int} {pageSize} {非必填,默认值为10} {每页数量}
- * @param {string} {username} {非必填} {账户搜索}
- * @param {array} {daterange} {非必填} {时间区间}
- * @param {int} {org_id} {非必填} {组织id}
- * @return mixed
- * @Author: wangkewei
- * @Date: 2021/5/18 10:08
- */
- public function getList($pageNo=1,$pageSize=20)
- {
- $list = $this->model
- ->where($this->createWhere())
- ->with(['request','menu','createUser'=>function($query){
- $query->with(['org'=>function($query_){
- $query_->field('org_id,name')->append(['status_txt']);
- }])->field('user_id,name,org_id,status')->append(['status_txt']);
- }])
- ->order("createtime DESC")
- ->paginate(['page'=>$pageNo,'list_rows'=>$pageSize]);
- return pageRes(1,"获取成功",$list->total(),$list->items());
- }
- /**
- * @title: 系统日志导出
- * @param {string} {username} {非必填} {账户搜索}
- * @param {array} {daterange} {非必填} {时间区间}
- * @param {int} {org_id} {非必填} {组织id}
- * @return mixed
- * @Author: wangkewei
- * @Date: 2022/2/28 17:18
- * @throws \Exception
- */
- public function doExport()
- {
- $list = $this->model->where($this->createWhere())
- ->with(['request','menu','createUser'=>function($query){
- $query->with(['org'=>function($query_){
- $query_->field('org_id,name')->append(['status_txt']);
- }])->field('user_id,name,org_id,status')->append(['status_txt']);
- }])
- ->order("createtime DESC")
- ->select();
- if($list->isEmpty()){
- return res(2,'没有数据导出');
- }
- $head = ['序号','操作用户','用户组织','访问路径','操作代码','操作内容','操作结果','IP地址','操作时间'];
- $body = [];
- foreach($list as $key=>$item){
- $index = $key + 1;
- $body[$index][] = $item->id;
- $body[$index][] = $item->username;
- $body[$index][] = $item->createUser->org->name;
- $body[$index][] = $item->path;
- $body[$index][] = $item->code;
- $body[$index][] = $item->remark;
- $body[$index][] = $item->result_txt;
- $body[$index][] = $item->ip;
- $body[$index][] = $item->createtime;
- }
- //创建文件夹
- $basepath = "uploads".DS."download".DS.date('Ymd');
- $savepath = public_path().$basepath;
- if(!is_dir($savepath)){
- mkdir($savepath,0777,true);
- }
- //保存文件
- $filename = date('Ymd')."系统日志导出.xls";
- $path = $savepath."/".$filename;
- $export_help = new \excel\MultiHeadExcel();
- $export_help->export_help($body,$head,$path);
- //返回路径
- $returnpath = WEBURL.DS.$basepath.DS.$filename;
- slog(1,"导出了系统日志");
- return res(1,"获取成功",['url'=>$returnpath,'name'=>$filename]);
- }
- }
|