<?php
/*
银行存款转化为金钱：pre_common_member_count
*/
if($xc->config['info']['convert_type'] == 'sql') {
	$query = $xc->db['source']->query("SELECT hk_name, hk_value FROM {$source_tablepre}hack WHERE hk_name IN ('bk_drate', 'bk_rate', 'bk_ddate')") or dexit();

	while($hk = $xc->db['source']->fetch_array($query)) {
		$hack[$hk['hk_name']] = $hk['hk_value'];
	}

	$maxuserid = $xc->db['source']->result($xc->db['source']->query("SELECT max(uid) FROM {$source_tablepre}memberinfo"), 0);
	if($start < $maxuserid){
		$converted = 1;
	}

	$query = $xc->db['source']->query("SELECT uid, deposit, startdate, ddeposit, dstartdate FROM {$source_tablepre}memberinfo WHERE uid >= $start AND uid < $start + $rpp") or dexit();
	while($user	=	$xc->db['source']->fetch_array($query)) {
		//日利息
		if($user['startdate'] && $timestamp > $user['startdate']){
			$accrual = round((floor(($timestamp - $user['startdate']) / 86400)) * $user['deposit'] * $hack['bk_rate'] / 100);
		} else {
			$accrual = 0;
		}
		//月利息
		$ddates = floor(($timestamp - $user['dstartdate']) / ($hack['bk_ddate'] * 30 * 86400));
		if($user['dstartdate'] && $ddates){
			$daccrual = round($ddates * $hack['bk_ddate'] * 30 * $user['ddeposit'] * $hack['bk_drat'] / 100);
		} else {
			$daccrual = 0;
		}

		$deposit = $user['deposit'] + $accrual + $user['ddeposit'] + $daccrual;		//银行存款总数

		$query1 = "UPDATE {$discuz_tablepre}common_member_count SET extcredits2=extcredits2+'$deposit' WHERE uid='$user[uid]'";

		if ($xc->db['discuz']->query($query1)) {
			$convertedrows ++;
		} else {
			reportlog();
		}
		$converted = 1;
		$totalrows ++;
		$url = 'index.php?mod=dealdata&step='.$step.'&start='.($user['uid']+1).'&stay='.$stay.'&totalrows='.$totalrows.'&convertedrows='.$convertedrows.'&sqlfilenum='.$sqlfilenum;
		file_put_contents(XCONVERT_ROOT.'./cache/lock/progress_'.$step.".txt", $url);
	}
}

?>