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

class Spider extends Base
{
	
	// 记录列表
	public function index($bot='')
	{
		if(Request::isPost())
		{
			$data = SpiderModel::when($bot,function($query)use($bot){
				$query->whereBot($bot);
			})->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('bot'));
	}

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