<?php
	session_start();
	require_once("../Wx.Config.php");	//只加载一次

	require_once("db/db.php");	
	require_once("common/common.php");

	$orderno = trim($_REQUEST['selbillno']);	
	$payerror= trim($_REQUEST['payer']);
	
	$_SESSION["temp_wxbill_billno"] = $orderno;
	
	//1.得到订单金额
	$price = '0';
	$sql = sprintf("Select ItemValue from WX_Bill_Inform Where Bill_No='%s' And BillState=0",$orderno);
	$result = querySql($sql);
	if($row = fetch_array($result))
	{		
		$fltBillVal = $row['ItemValue']; //预订房型
		$price = number_format($fltBillVal,1);
	}
	freeResult($result);
	
	$price=str_replace(',','',$price);
	
	//测试模式
	$pricewx = $price;
	$intIsDubgeModle = WxMainConfig::NowIsDubgeModle;
	if($intIsDubgeModle=='1')
	{
		$pricewx = '0.01';
	}
		
	//2.得到积分兑换系数
	$fltintegralcashrate = '1';
	$sql=sprintf("SELECT IntegralCashRate from VIP_Config");
	$result = querySql($sql);
	if($row = fetch_array($result))
	{
		$fltintegralcashrate = $row['IntegralCashRate']; //预订房型
	}
	freeResult($result);	//释放数据库
	
	//生成应收积分金额
	$fltBillVal= round($price * $fltintegralcashrate,0);
	$PriceIntegVal = number_format($fltBillVal,0);
	$PriceIntegVal=str_replace(',','',$PriceIntegVal);
	
	//3.得到会员卡账户余额
	$VIP_LiftSum = '0';
	$VIP_IntegSum = '0';
	$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);
	if($row = fetch_array($result))
	{
		$fltBillVal = $row['VIP_LiftSum']; //预订房型
		$VIP_LiftSum = number_format($fltBillVal,1);
		$VIP_LiftSum=str_replace(',','',$VIP_LiftSum);
		
		$fltBillVal = $row['VIP_IntegVal']; //预订房型
		$VIP_IntegSum = number_format($fltBillVal,0);
		$VIP_IntegSum=str_replace(',','',$VIP_IntegSum);
	}
	freeResult($result);
	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"> 
	
	<!--<link rel="stylesheet" href="jsp5/jquery.mobile-1.4.5.min.css">-->
	<script src="jsp4/jquery.mobile-1.4.3.min.js"></script>
	<!--<script src="jsp5/jquery.mobile-1.4.5.min.js"></script>-->
	<link rel="stylesheet" href="jsp5/jquery.mobile-1.4.5.min.css">

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

<body leftmargin="0" rightmargin="0" topmargin="0" bottommargin="0">

    <header data-role="header" data-position="fixed" data-tap-toggle="false" style="border-top-width:0px;border-bottom-width:0px;">
        <table width="100%" height="52" border="0" cellpadding="0" cellspacing="0" bgcolor="<?php echo WxMainConfig::colHeadBkColor;?>">
            <tr>
                <td height="52" width="20"></td>
                <td height="52" align="center">
                    <span style="color:<?php echo WxMainConfig::colHeadTextColor;?>;font: 12px/1.5 '微软雅黑',tahoma, Srial, helvetica, sans-serif; font-size:19px;text-shadow:none;">应付金额:￥<?php echo $price;?></span>
                </td>
                <td height="52" width="20"></td>
            </tr>
        </table>
    </header>
    <form name="f">
    <table width="100%" border=0 cellSpacing=0 cellPadding=0>
        <tr height="50px">
            <td width="10"></td>
            <Td align="center" valign="center" width="50px" style="padding-bottom:7px"><input type="radio" name="paytype" value="1" checked></td>
            <Td>会员余额支付</td>
            <Td align="right">
				<?php if(strlen($strSubNo)>0) { ?>
					￥<?php echo $VIP_LiftSum;?>&nbsp;&nbsp;
				<?php } else {?>
					<div data-rel="back" onClick="bmtGoToLogin()" style="border-radius:5px;width:95%; height:30px; background-color:#D7AA28;">
                        <table width="100%" height="100%" border="0" cellpadding="0" cellspacing="0">
							<tr><td width="100%" height="100%" align="center">
								<span style="color:#fff ;font: 12px/1.5 '微软雅黑',tahoma, Srial, helvetica, sans-serif; font-size:14px;text-shadow:none;">会员登录</span>                            	
                            </td></tr>
                        </table>
                    </div>
				<?php } ?>
			</td>
            <td width="10"></td>
        </tr>
        <tr height="1px">
            <td width="10"></td>
            <Td colspan="3" style="background:#ccc"></td>
            <td width="10"></td>
        </tr>
        <tr height="50px">
            <td width="10"></td>
            <td align="center" valign="center" width="50px" style="padding-bottom:7px">
            	<?php if($VIP_IntegSum>$PriceIntegVal) {?>
	            	<input type="radio" name="paytype" value="2">
                <?php } else { ?>
                	<input type="radio" name="paytype" value="2" disabled>
                <?php } ?>
            </td>
            <td>会员积分支付</td>
            <td align="right">
            	<table width="100%" border=0 cellSpacing=0 cellPadding=0>
                	<tr>
                        <td height="100%" align="right" valign="middle">
                        	<?php echo $VIP_IntegSum;?>&nbsp;&nbsp;
                        </td>
                    	<td width="15" height="100%" valign="middle">
                        	<img src="images\jfimg.png" width="12" height="15" border="0" style="margin-top:3px;">
                        </td>
                    </tr>
                </table>
            </td>
            <td width="10"></td>
        </tr>
        <tr height="1px">
            <td width="10"></td>
            <Td colspan="3" style="background:#ccc"></td>
            <td width="10"></td>
        </tr>
        <tr height="50px">
            <td width="10"></td>
            <Td align="center" valign="center" width="50px" style="padding-bottom:7px"><input type="radio" name="paytype" value="3"></td>
            <Td>微信支付</td>
            <Td align="right"></Td>
            <td width="10"></td>
        </tr>
        <tr height="1px">
            <Td colspan="5" style="background:#ccc"></td>
        </tr>
        
        <tr height="20px">
            <Td colspan="5" ></td>
        </tr>
    </table>
    
    <table width="100%" border=0 cellSpacing=0 cellPadding=0>
    	
        <tr width="100%">
            <td height="10" width="20"></td>
            <td height="10" align="center">
            	<span style="color:#D12023 ;font: 12px/1.5 '微软雅黑',tahoma, Srial, helvetica, sans-serif; font-size:16px;text-shadow:none;">如使用积分支付，应付积分为 <?php echo $PriceIntegVal;?></span> 
            </td>
            <td height="10" width="20"></td>
        </tr>
        
        <tr width="100%">
            <td height="30" colspan="3"></td>
        </tr>
        
        <tr height="30" width="100%">
            <td width="20"></td>
            <td>
            	<table width="100%" border="0" cellpadding="0" cellspacing="0">
                    <tr>
                        <td width="50%" align="center">
                            <div data-rel="back" onClick="bmtReturnBill()" style="border-radius:5px;width:80%; height:38px; background-color:#D7AA28;">
                                <table width="100%" height="100%" border="0" cellpadding="0" cellspacing="0">
                                    <tr><td width="100%" height="100%" align="center">
                                        <span style="color:#fff ;font: 12px/1.5 '微软雅黑',tahoma, Srial, helvetica, sans-serif; font-size:16px;text-shadow:none;">返 回</span>                            	
                                    </td></tr>
                                </table>
                            </div>
                        </td>
                        <td width="50%" align="center">
                            <div data-rel="back" onClick="bmtToPayFor()" style="border-radius:5px;width:80%; height:38px; background-color:<?php echo WxMainConfig::colHeadBkColor;?>;">
                                <table width="100%" height="100%" border="0" cellpadding="0" cellspacing="0">
                                    <tr><td width="100%" height="100%" align="center">
                                        <span style="color:#fff ;font: 12px/1.5 '微软雅黑',tahoma, Srial, helvetica, sans-serif; font-size:16px;text-shadow:none;">支 付</span>                            	
                                    </td></tr>
                                </table>
                            </div>
                        </td>
                    </tr>
                </table>
            
            </td>
            <td width="20"></td>
        </tr>
        
		<?php if($intIsDubgeModle=='1') { ?>
		 <tr width="100%">
            <td height="30" colspan="3"></td>
        </tr>
		
         <tr width="100%">
            <td height="10" width="20"></td>
            <td height="10" align="center">
            	<span style="color:#D12023 ;font: 12px/1.5 '微软雅黑',tahoma, Srial, helvetica, sans-serif; font-size:13px;text-shadow:none;">演示模式，在微信支付页面时自动按0.01支付</span> 
            </td>
            <td height="10" width="20"></td>
        </tr>
        <?php } ?>
       
    </table>
    
    </form>
    
    <?php 
        if(strlen($payerror)>0)
        {
    ?>
        <span style="color: #666666;font: 12px/1.5 '微软雅黑',tahoma, Srial, helvetica, sans-serif; font-size:14px;">
            <table width="100%" border=0 cellSpacing=0 cellPadding=0>
                <tr height="50px">
                    <Td align="center" valign="center" width="50px" style="padding-bottom:7px"><?php echo $payerror;?></td>
                </tr>
                <tr height="1px">
                    <Td style="background:#ccc"></td>
                </tr>
            </table>
        </span>
    <?php
        }
    ?>


 	<script type="text/javascript">
	 	
		//返回到订单页面
		function bmtReturnBill()
		{
			var strBillNo = <?php echo $orderno;?>;
			window.location="ordermodify.php?selbillno=" + strBillNo;
		};

		function bmtGoToLogin()
		{
			window.location="login.php?pgid=5" ;
		};
		
		//进入到相应的支付操作
		function bmtToPayFor()
		{	
			var VIP_LiftSum = <?php echo $VIP_LiftSum;?>;
			var VIP_IntegSum = <?php echo $VIP_IntegSum;?>;
			var priceInte = <?php echo $PriceIntegVal;?>;
			var price = <?php echo $price;?>;
		
			var paytype = $("input[name='paytype']:checked").val();
			if(paytype == 1)//余额
			{
				if(VIP_LiftSum < price)
				{
					alert("余额不足!");
				}
				else
				{
					//进入会员支付界面
					window.location = "orderpayvip.php?payid=1&price=<?php echo $price;?>&orderno=<?php echo $orderno;?>";
				}
			}
			else if(paytype == 2)//积分支付
			{
				if(VIP_IntegSum < priceInte)
				{
					alert("积分余额不足!");
				}
				else
				{
					//进入会员积分支付界面
					window.location = "orderpayvip.php?payid=2&price=<?php echo $price;?>&orderno=<?php echo $orderno;?>";
				}	
			}
			else if(paytype == 3)//微信
			{
				//进入微信支付界面
				//window.location = "orderwxpay.php?price=<?php echo $price;?>&orderno=<?php echo $orderno;?>";
				window.location = "orderwxpay.php?price=<?php echo $pricewx;?>&orderno=<?php echo $orderno;?>";
			}
		}
		
	</script>

		
	<script>
		//禁止页面上下滑动,整个页面都不能滑动了
		document.addEventListener('touchmove', function(e) 
		{
			e.preventDefault();
		});
	</script>
</body>
</html>



