<?php
/**
 * @author william-fan
 * @todo  向招宝提交出区单数据(调用招宝webservice)
 */
//发送出区报文
set_time_limit(7200);
require_once ('config.php');
$flagFile = APPLICATION_PATH . '/../data/log/shipBatchSubmitZ.lock';
if (@file_exists($flagFile)) {
	echo 'Anather process is running.'."\r\n\r\n";
	echo $flagFile."\r\n";
	exit();
}
$link = fopen($flagFile, 'wb');
fclose($link);
define('RUNTIME', '[' . date('Y-m-d H:i:s') . '] ');
echo RUNTIME . "Starting.\r\n";
try {
	$ftProcess = new Service_FtpReceiveProcess();
	//$receivingList = Service_Receiving::getByCondition(array('receiving_status'=>3));	
	$receivingCondition = array('fmt_code'=>'ZCCQ', 'fml_status'=>1);
	$counts = Service_FtpMessageSendlist::getByCondition($receivingCondition,"count(*)");
	$pageSize = 20;
	if($counts>0){
		$ftProcess = new Service_FtpReceiveProcess();
		
		$cmblApi=new Service_CMBLApiProcess();
		
		$pages = ceil($counts/$pageSize);
		for($page=1;$page<=$pages;$page++){
			$sendList = Service_FtpMessageSendlist::getByCondition($receivingCondition,'*',$pageSize,$page,'fml_id desc');
			print_r($sendList);
			foreach($sendList as $sendRow){
				//print_r($sendList);
				//uploadRCustomerOrder($sendRow);
				$cmblApi->UploadCCustomOrder($sendRow);
			}
		}

	}
	echo "[发送出区报文]全部处理完成\r\n";
} catch (Exception $e) {
	@unlink($flagFile);
	echo '[' . date('Y-m-d H:i:s') . '] Fail Exception:' . $e->getMessage() ."\r\n";
}
echo "[" . date('Y-m-d H:i:s') . "] End run\r\n\r\n";
@unlink($flagFile);