<?php
	session_start();
	
	$strret = '0';
		
	header("Content-type: text/html; charset=gb2312"); 
	
	require_once("db/db.php");	
	require_once("common/common.php");
	
	//得到购物车号和会员号
	$strdefcartid = trim($_SESSION["main_defcarttempid"]);
	$strselvipno = trim($_SESSION["main_vipno"]);
	$strDListNo = trim($_SESSION["main_posChainDListNo"]);	//部门流水号
	$strDListNo = str_replace(',','',$strDListNo);
	$strwxid=trim($_SESSION["main_wxudid"]);
	//得到当前使用系统的关键字：会员号，微信号，临时购物号

	$sql = sprintf("EXECUTE WXG_CreateBillFromCart '%s','%s',%s,'%s'",$strselvipno,$strdefcartid,$strDListNo,$strwxid);
	
	if(executeSql($sql))
	{
		//得到创建成功的单号
		
		$sql = sprintf("SELECT MAX(Bill_No)AS Bill_No FROM WX_Bill_Inform WHERE TradeTime>dateadd(minute,-1,GetDate()) And CartTempID='%s' And (Sub_No='%s' Or wx_no='%s') And DListNo=%s",$strdefcartid,$strselvipno,$strwxid,$strDListNo);					
		$result = querySql($sql);
	
		if($row = fetch_array($result))
		{
			$strnewbillno = $row['Bill_No'];
			$strret='1'.$strnewbillno;
		}
		freeResult($result);	//释放数据库
		
	}

	echo $strret;
	closeDb();		
?>



