<?php
	session_start();
	
	require_once("db/db.php");	
	require_once("common/common.php");
	
	//设置统一语言格式
	header("Content-type: text/html; charset=gb2312"); 
	
	$price = trim($_REQUEST['price']);
	$strblistno = trim($_REQUEST['blid']);
	$intxzdays = trim($_REQUEST['xzday']);
	
	$strchainno = $_SESSION["main_order_chainno"];
	$main_vipno = $_SESSION["main_vipno"];
		
	$strpayforxz=trim($_SESSION["main_wxpayforxz"]);
	if($strpayforxz==1)
	{	
		//1.得到单号和房号
		$strorderno="";
		$strroomno="";
		$sql = sprintf("SELECT Order_No,Room_No FROM TR_Order_Room_List Where ListNo=%s", $strblistno);
		$result = querySql($sql);
		$row = fetch_array($result);
		$strorderno=$row['Order_No'];
		$strroomno=$row['Room_No'];
		freeResult($result);
		
		//2.判断余额
		$sql = sprintf("SELECT a.VIP_LiftSum,a.VIP_IntegVal,a.VIP_UsedSum,b.Sub_State,a.VIP_State FROM VIP_Main a,VIP_Item b WHERE a.VIP_NO=b.VIP_NO AND b.Sub_No='%s'", $_SESSION["main_vipno"]);
		$result = querySql($sql);
		$row = fetch_array($result);
		$VIP_LiftSum = $row['VIP_LiftSum']; //预订房型
		freeResult($result);
		
		if($VIP_LiftSum<$price)
		{
			closeDb();
			$strtemp='会员账户余额不足';
			echo "<script>window.location.href='xzpaysel.php?price=".$price."&blid=".$strblistno."&xzday=".$intxzdays."&payer=会员账户余额不足';</script>";
			exit;
		}
	
		//3.开始会员入账
		$strRemarks = "客房".$strroomno."续住";
		$sql = sprintf("EXECUTE VIP_ScoreSaveValWeb '%s','%s','预付款',%f,0,'%s','%s'", $strchainno, $main_vipno, $price, $strorderno,$strRemarks);
		$result1 = querySql($sql);
		$row1 = fetch_array($result1);
		$retval = $row1['RetVal'];
		freeResult($result1);
		
		if($retval>0)
		{	
			$strtemp='未知'.trim($retval);
			if($retval==1)
			{
				$strtemp='会员账户不存在';
			}
			elseif($retval==2)
			{
				$strtemp='会员账户停用';
			}
			elseif($retval==3)
			{
				$strtemp='会员账户余额不足';
			}
			echo "<script>window.location.href='xzpaysel.php?price=".$price."&blid=".$strblistno."&xzday=".$intxzdays."&payer=支付失败:".$strtemp."';</script>";
			exit;
		}
		
		//4.续住		
		$sql = sprintf("EXECUTE TRS_OrderRoomAddDays %s,%s,'会员卡',%s,'会员续住'", $strblistno,$intxzdays,$price);
		$result = querySql($sql);
	
	}
	$_SESSION["main_wxpayforxz"]="";
	//关闭数据库
	closeDb();	
?>
<html>
<head>
	<meta charset="gb2312">	
	<meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0"/>
	<meta name="apple-mobile-web-app-capable" content="1">
	<meta name="apple-mobile-web-app-status-bar-style" content="black">
	<meta name="format-detection" content="telephone=0">
	<meta name="apple-touch-fullscreen" content="1">
	<title>在线支付</title>
	<script src="jsp4/jquery.js"></script>
	<link rel="stylesheet" href="css/mycss.css"> 
	
	<script>
		setTimeout("window.location='roomlist.php'",1000);
	</script>

	<script language="JavaScript"> 
		//不允许进行后退
		javascript:window.history.forward(0); 
	</script>
</head>

<body leftmargin="0" rightmargin="0" topmargin="0" bottommargin="0">
&nbsp;<br>
<center><span style='color:green;font-size:22px'><b>付款成功</b></span></center>
<p>
</body>

</html>


