<?php
if(!defined('MOD'))  die("access die");
purviewCheck('sitemap', 'cheat');
if($_POST['myFormAc'] == 'update'){
	$channelid = intval($_POST['channelid']);
	$mod = qbase::getMod($channelid);
	if(!$mod) qbase::showmsg("bad request");
	$ids = array(intval($_POST['ids']['min']), intval($_POST['ids']['max']));
	$start = min($ids);
	$end = max($ids);
	$views = array(intval($_POST['views']['min']), intval($_POST['views']['max']));
	if($views[0] < 1 || $views[1] < 1) qbase::showmsg("日浏览基数不能为0");
	$type = $_POST['type'];
	$where = ' where 1= 1 ';
	if($start > 0) $where .= " and  id >= '{$start}' ";
	if($end > 0) $where .= " and  id <= '{$end}' ";
	$table = TABLEPRE . $mod .'_'. $channelid;
	$sql = " select id from {$table} {$where} ";
	$data = qdb::fetchAll($sql);
	$view_min = min($views);
	$view_max = max($views);

	foreach($data as $val){
		$param = array();
		$param['dview'] = rand($view_min, $view_max);
		$param['dview'] = $param['dview'] + rand(0, $param['dview']);
		$param['wview'] = $param['dview'] * 7 + rand($view_min, $view_max);
		$param['wview'] = $param['wview'] + rand(0, $param['wview']);
		$param['mview'] = $param['dview'] * 30 + rand($view_min, $view_max);
		$param['mview'] = $param['mview'] + rand(0, $param['mview']);
		$param['views'] = $param['dview'] * 90 + rand($view_min, $view_max);
		$param['views'] = $param['views'] + rand(0, $param['views']);
		$sql = qbase::createSql($table, $param, 'update') . " where id = '{$val['id']}' ";
		qdb::query($sql);
	}
	qbase::showmsg("操作成功，系统将自动更新缓存", "default", "system.php?sys=html&action=common&location=" . urlencode("plugin.php?plugin=cheat"));
}else{
	include qbase::template($path . 'plugin/cheat');
}
?>