<?php
/*
ÐüÉÍÌùµÄ×î¼Ñ´ð°¸
pre_forum_thread
pre_forum_post
*/

$maxpid = $xc->db['source']->result(
		$xc->db['source']->query("SELECT MAX(pid) AS MAXPID FROM {$source_tablepre}bonuslog")
		, 0, 'MAXPID');

if($start < $maxpid) {
	$converted = 1;
}

$query = $xc->db['source']->query("SELECT * FROM {$source_tablepre}bonuslog WHERE pid>=$start AND pid<=$end");
while($b = $xc->db['source']->fetch_array($query)) {
	$b		= daddslashes(array_change_key_case($b));

	if($b['bonus'] && $b['isbest'] == 2) {
		
		$thread = $xc->db['discuz']->fetch_array(
			$xc->db['discuz']->query("SELECT * FROM {$discuz_tablepre}forum_thread WHERE tid={$b[tid]}")	
		);
		if(!$thread) {
			continue;
		}
		$xc->db['discuz']->query("UPDATE {$discuz_tablepre}forum_thread SET price='".(0-abs($thread['price']))."' WHERE tid='{$b[tid]}'");
		$xc->db['discuz']->query("UPDATE {$discuz_tablepre}forum_post SET dateline={$thread[dateline]}+1 WHERE pid='{$b[pid]}'");
		$totalrows ++;
		$convertedrows ++;
	} else {
		continue;
	}
	$url = 'index.php?mod=dealdata&step='.$step.'&start='.($b['pid']+1).'&stay='.$stay.'&totalrows='.$totalrows.'&convertedrows='.$convertedrows.'&sqlfilenum='.$sqlfilenum;
	file_put_contents(XCONVERT_ROOT.'./cache/lock/progress_'.$step.".txt", $url);
}
?>