<?php
/**
* @author 龙虾 <15108148@qq.com>
* @version 2.0 2020-08-12
* @copyright 睿谷信息 <www.rgxx.com>
*/
namespace app\admin\controller;
use think\Controller;
use app\admin\model\Adminlog as AdminlogModel;
use Request;

class Adminlog extends Base
{
	// 记录列表
	public function index()
	{
		if(Request::isPost())
		{
			$type = Request::post('type');
			$data = AdminlogModel::when(!$this->admininfo['isboss'],function($query){
				$query->whereAdminId(session('adminid'));
			})->when($type,function($query)use($type){
				$query->whereType($type);
			})->order('create_time desc')->with('admin')->paginate(Request::post('limit/d'))->toArray();
			return json(['code'=>0,'msg'=>lang('getdatatrue'),'data'=>$data['data'],'count'=>$data['total']]);
		}
		return $this->fetch();
	}

	// 删除
	public function del()
	{
		if(Request::isPost() && $this->admininfo['isboss']) {
			$data = Request::post();
			if(isset($data['id'])) {
				$result = AdminlogModel::destroy($data['id']);
			} else {
				$result = AdminlogModel::where('id > 0')->delete();
			}
			adminlog(2,'删除('.AdminlogModel::getLastsql().')',$result?1:0);
			if ($result) {
				$this->success(lang('deltrue'));
			} else {
				$this->error(lang('delfalse'));
			}
		} else {
			$this->error(lang('delfalse'));
		}
	}
}