<?php
	session_start();
	
	require_once("db/db.php");	
	require_once("common/common.php");
	
	//设置统一语言格式
	header("Content-type: text/html; charset=gb2312"); 

	$strChainNo=trim($_REQUEST['chainno']);	
	$strBListNo=trim($_REQUEST['rblistno']);
		
	if(strlen($strBListNo)<1)
	{
		$strBListNo='0';
	}

	$strTradeMan=trim($_SESSION['username']);
		
	//1.判断该房间是否是在住状态，如果不是在住则不继续
	$intBillState=0;
	$strNewRoomNo='';
	$strOrderNo='';
	$sql=sprintf("SELECT Room_BillState,Room_No,Order_No FROM TR_Order_Room_List WHERE ListNo=%s",$strBListNo);
	$result = querySql($sql);		
	if($row = fetch_array($result))
	{	
		$intBillState=$row['Room_BillState'];
		$strNewRoomNo=$row['Room_No'];
		$strOrderNo=$row['Order_No'];
	}
	freeResult($result);
	
	if($intBillState<>2)	//0预排,1预订,2入住,3退房,4取消
	{
		//客房不是在住状态，不能退房！
		echo "*2*";
		exit;
	}
	
	/* 2025- 11-30 暂时不处理此部分功能*/
	//2.是否有出租未归还的信息
	//sqlstr = "SELECT * FROM TR_LendOut_List WHERE Order_No='" & Trim(m_strOrderNo) & "' AND BListNo=" & strSelBListNo & " AND LendOutState=0"
	
	
	//3.生成房费相关内容
	//将生成房费放在存储过程里
	//$sql=sprintf("EXECUTE TRS_App_CancelRoomAddScore %s",$strBListNo);
	//$result = querySql($sql);	
	
	
	//4.执行退房操作
	$sql=sprintf("EXECUTE TR_CancelOrderRoom '%s',%s,'%s','%s',1",$strOrderNo,$strBListNo,$strTradeMan,$strChainNo);
    $result = querySql($sql);
	
	echo '*1*';	//成功

?>


