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

class Visits extends Base
{
	// 记录列表
	public function index($ip = '')
	{
		if(Request::isPost())
		{
			$data = VisitsModel::when($ip,function($query)use($ip){
				$query->whereIp($ip);
			})->with('site')->order('create_time desc')->paginate(input('post.limit/d'))->toArray();
			return json(['code'=>0,'msg'=>lang('getdatatrue'),'data'=>$data['data'],'count'=>$data['total']]);
		}
		return $this->fetch('',compact('ip'));
	}

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