<?php
/*error_reporting(E_ALL);
ini_set('display_errors', '1');*/
date_default_timezone_set('Asia/Tokyo');
include_once('../system/lib/config.php');

$system = new System();

//根据内置方法取番号
$transaction_number = $system-> getTransactionNumberCommon(VAR_TRANSACTION_DEPOSIT);
//$transaction_number = trim(trim(date('YmdHis',time())).mt_rand(10000,99999));
$sqlObject = new mysql($system->getConfigValue(SECTION_DB,HOST_NAME),$system->getConfigValue(SECTION_DB,USER_NAME),$system->getConfigValue(SECTION_DB,LOGIN_PASS),$system->getConfigValue(SECTION_DB,TARGET_DB_NAME),'','UTF8');


//获取账号信息
$system -> account = $system -> getRowData($system -> getAccountCommon($system -> getUserData(PARAM_USER_ACCOUNT)));
$accountType = $system -> getColumnData($system -> account,'account_type');


//格式化要发送的数据
$system->gateway 									= $system -> getColumnData($CUP,'Merchant_gateWay');
$system->arrSysRegister['version'] 					= $system -> getColumnData($CUP['Post'],'version');
$system->arrSysRegister['action'] 					= $system -> getColumnData($CUP['Post'],'action');
$system->arrSysRegister['merch_id'] 				= $system -> getColumnData($CUP['Post'],'merch_id');
$system->arrSysRegister['term_id']		 			= $system -> getColumnData($CUP['Post'],'term_id');
$system->arrSysRegister['access_id'] 				= $system -> getColumnData($CUP['Post'],'access_id');
$system->arrSysRegister['locale'] 					= $system -> getColumnData($CUP['Post'],'locale');
$system->arrSysRegister['pay_type'] 				= $system -> getColumnData($CUP['Post'],'pay_type');
$system->arrSysRegister['currency'] 				= $system -> getColumnData($CUP['Post'],'currency');
$system->arrSysRegister['pay_item'] 				= $system -> getColumnData($CUP['Post'],'pay_item');
$system->arrSysRegister['bill_to_street'] 			= $system -> getColumnData($_SESSION['CUP_Data'],'address');
$system->arrSysRegister['bill_to_city'] 			= $system -> getColumnData($_SESSION['CUP_Data'],'city');
$system->arrSysRegister['bill_to_postal_code'] 		= $system -> getColumnData($_SESSION['CUP_Data'],'zip');
$system->arrSysRegister['bill_to_country_code'] 	= $system -> getColumnData($_SESSION['CUP_Data'],'Country');
$system->arrSysRegister['phone_no'] 				= $system -> getColumnData($_SESSION['CUP_Data'],'tel');
$system->arrSysRegister['return_url'] 				= str_replace('{lang}', $system -> getColumnData($_SESSION['CUP_Data'],'lang'), $CUP['ReturnURL']);
$system->arrSysRegister['amount'] 					= $system -> getColumnData($_SESSION['CUP_Data'],'Actual') * 100;
$system->arrSysRegister['merch_order_id'] 			= $transaction_number;
$system->arrSysRegister['bill_to_first_name'] 		= $system -> getColumnData($_SESSION['CUP_Data'],'firstName');
$system->arrSysRegister['bill_to_last_name'] 		= $system -> getColumnData($_SESSION['CUP_Data'],'lastName');
$system->arrSysRegister['bill_to_email_address']	= $system -> getColumnData($_SESSION['CUP_Data'],'mail');
$system->arrSysRegister['remark']					= $system -> getColumnData($_SESSION['CUP_Data'],'lang');
$system->arrSysRegister['pay_item']					= $system -> getColumnData($_SESSION['CUP_Data'],'lang');

error_log(date("[Y-m-d H:i:s]")."订单".$transaction_number."发送的request变量为\r\n" . print_r($system->arrSysRegister,true)."\r\n", 3, 'Logs'.DIRECTORY_SEPARATOR.'CUP'.DIRECTORY_SEPARATOR.'request'.DIRECTORY_SEPARATOR.'Log_'.date("Y-m-d").'.log');
/*echo $system->gateway;
echo "<br>";
foreach($system->arrSysRegister as $key=>$value){
	echo $key."----".$value;
	echo "<br>";
}
exit();*/



//模型化入数据库
$CUP['Model']['transaction_number'] = $transaction_number;
$CUP['Model']['user_account'] = $system -> getColumnData($_SESSION['CUP_Data'],'user_account');
$CUP['Model']['amount'] = $system -> getColumnData($_SESSION['CUP_Data'],'amount')*100;
$CUP['Model']['currency'] = $system -> getColumnData($_SESSION['CUP_Data'],'currency');
$CUP['Model']['method'] = $system -> getColumnData($_SESSION['CUP_Data'],'method');
$CUP['Model']['deposit_bank'] = $system -> getColumnData($_SESSION['CUP_Data'],'method');
$CUP['Model']['deposit_date'] = date("Y-m-d H:i:s");
$CUP['Model']['fee'] = '0';
$CUP['Model']['message'] = $system -> getColumnData($_SESSION['CUP_Data'],'message');
$CUP['Model']['comment'] = '';
$CUP['Model']['create_time'] = date("Y-m-d H:i:s");
$CUP['Model']['process_user'] = '9999';
$CUP['Model']['type'] = '0';
$CUP['Model']['err_flg'] = '0';
$sql = "insert into t_deposit_cup_temporary ";


//进deposit表的sql方法
$strsql = $sqlObject->Insertsql($CUP['Model']);
$sql .= $strsql;
$sqlObject->query($sql);

//echo $sql;

error_log(date("[Y-m-d H:i:s]")."订单".SITE_SHORT_NAME.$transaction_number."的数据库CUP临时表插入记录为\r\n" . "$sql\r\n", 3, 'Logs'.DIRECTORY_SEPARATOR.'CUP'.DIRECTORY_SEPARATOR.'DB'.DIRECTORY_SEPARATOR.'Log_'.date("Y-m-d").'.log');
$response = $system -> curl();




?>
<body onload='document.CUPForm.submit();'>
	<?php echo $response; ?>
</body>