<?
	include("config/connect.php");
	include("functions.php");
	$userid  = $_SESSION["userid"];
	$aucid = $_POST["aucid"];  
	$priceCount=$_POST["pc"];
	$OrdersId = $_POST["oid"];
	$dprice=$_POST["dprice"];
  $pay_interface = $_POST["paytype"];
  
	$postname = $_POST["postname"];
	$address = $_POST["address"];
	$zip = $_POST["zip"];
	$tel = $_POST["tel"];
	$email = $_POST["email"];
	$des = $_POST["des"];

	$ip = GetIP();	
  $stime=date("Y-m-d H:i:s");
  $lastpriceCount =$priceCount+$dprice; 
  //echo "商品费用=".$lastpriceCount."<br>";
  //echo "订单编号=".$OrdersId."<br>";
  //echo "快递费用=".$dprice."<br>";

	$qrysel = "SELECT `oid` FROM shops_orders WHERE userid='$userid' and aid='$aucid' LIMIT 0,1";
	$ressel = mysql_query($qrysel);
	$total = mysql_num_rows($ressel);
	
	if($total<1){  
		$OrdersId = 'S-P'.time().'RN'.mt_rand(100,999);		
		$sql = "INSERT INTO `shops_orders` (`aid`,`oid`,`userid`,`state`,`ip`,`stime`,`dprice`,`priceCount`) VALUES ('$aucid','$OrdersId','$userid','0','$ip','$stime','$dprice','$lastpriceCount');";
		//echo $sql;
 
  	mysql_query($sql);

		$sql = "INSERT INTO `shops_userinfo` (`userid`,`oid`,`consignee`,`address`,`zip`,`tel`,`email`,`des`) VALUES ('$userid','$OrdersId','$postname','$address','$zip','$tel','$email','$des')";
		
  	mysql_query($sql);
  	
  }else{
  	$objbid2 = mysql_fetch_object($ressel);
		$OrdersId = $objbid2->oid; 
		$sql = "UPDATE `shops_orders`
		SET `ip`='$ip',`stime`='$stime',dprice='$dprice',priceCount='$lastpriceCount'
		WHERE oid='$OrdersId' AND userid='$userid' ;";
		if(mysql_query($sql))
		{
			$sql = "UPDATE `shops_userinfo`
			SET `consignee`='$postname',`address`='$address',`zip`='$zip',`tel`='$tel',`email`='$email',`des`='$des'
			WHERE oid='$OrdersId';";
			mysql_query($sql);
		}	
  }  
  //$lastpriceCount='0.01';
?>

</head>

<body onload="frmnew();">

<form name="_xclick" action="payment.php" method="post">				
<input type="hidden" name="famount" value="<?=$lastpriceCount;?>">
<input type="hidden" name="winid" value="<?=$OrdersId;?>">
<input type="hidden" name="paytype" value="BUYNOW"><!-- BUYNOW 购买商品-->
<input type="hidden" name="pay_interface" value="<?=$pay_interface;?>">
</form>

<script language='javascript'>
function frmnew()
{ 
	document._xclick.submit();
}
</script>

</body>
</html>
