<?php
session_start();
include_once("inc/conn.php");
include_once("inc/function.php");
$zf=false;

$query=$db->query("Select * FROM {$web_dbtop}payset Order by id desc");
if($rs=$db->fetch_array($query)){
	$reg_userid=$rs["paysetid"];
	$reg_key=$rs["paysetpassword"];
}
	
$v_orderid=$_REQUEST['v_orderid'];   //贺喜支付平台反馈的定单号
if (!empty($v_orderid)){
	$v_orderdate=$_REQUEST['v_orderdate'];   //定单成交时间
	$v_price=$_REQUEST['v_price'];   //定单成交价格，以分为单位
	$v_billno=$_REQUEST['v_billno'];   //商户订单号
	$v_custom1=$_REQUEST['v_custom1'];   //自定义字段1
	$v_custom2=$_REQUEST['v_custom2'];   //自定义字段2
	$v_mobileno=$_REQUEST['v_mobileno'];   //用户支付的手机号码,仅手机短信注册时有效
	$v_servicename=$_REQUEST['v_servicename'];   //支付订单的服务名称
	$v_payvia=$_REQUEST['v_payvia'];   //用户选择的支付途径，1：银行卡在线支付；2：声讯电话支付；3：互联星空支付；4：手机短信注册；5：腾讯财付通支付；6：腾讯Q币支付；7：神州行充值卡支付；8，盛大游戏点卡支付；9，支付宝支付；10，手机银行支付；11，北京宽带支付；12，联通充值卡支付
	$v_payviastr=$_REQUEST['v_payviastr'];   //用户选择的支付途径中文名称
	$v_md5=$_REQUEST['v_md5'];   //返回的加密字符串
	$v_pstatus=$_REQUEST['v_pstatus'];   //定单成功反馈的字符串，有1和0两种情况。主要用于验证是否属正常反馈。1为成功。
	$v_pstring=$_REQUEST['v_pstring'];   //定单支付状态说明。
	$v_paymode=$_REQUEST['v_paymode'];   //当前定单运行模式，仅启用测试模式时有效，值为testmode。
	$v_server=$_REQUEST['v_server'];   //当前定单通知的模式，1为服务器端通知。
	
	$discount=showcontent("business","discount",$v_custom2);

	if(($v_pstatus=="1")){
		$encrypt_string=strtoupper(md5($v_orderid.$v_billno.$v_custom1.$v_custom2.$v_price.$v_payvia.$reg_userid.$v_pstatus.$reg_key.$v_paymode));
		if(($v_md5==$encrypt_string)){
			if($_SESSION["reg168_orderid"]){
				if($_SESSION["reg168_orderid"]==$v_orderid){
					echo"<script language=javascript>alert('错误：同一定单成交页面不允许多次刷新或提交！');location.href = 'businesscardback.php'</script>";
					exit;
				}else{
					$_SESSION["reg168_orderid"]=$v_orderid;
				}
			}else{
				$_SESSION["reg168_orderid"]=$v_orderid;
			}
			$custom=explode("$|$",$v_custom1);
			$cardid=explode(",",$custom[0]);
			$num=explode(",",$custom[1]);
			for($i=0;$i<count($cardid);$i++){
				if($num[$i]>0){
					$query=$db->query("Select cardname,cardtop,cardlen,cardtype,cardprice from {$web_dbtop}cardtype where id=$cardid[$i]");
					if($rs=$db->fetch_array($query)){
						$cardname=$rs["cardname"];
						$cardtop=$rs["cardtop"];
						$cardlen=$rs["cardlen"];
						$cardtype=$rs["cardtype"];
						$cardprice=$rs["cardprice"];
					}
					for($y=0;$y<$num[$i];$y++){
						$db->query("INSERT INTO {$web_dbtop}card (cardtype,cardid,cardpaw,time,businessid) VALUES ($cardid[$i],'".$cardtop.createrandstring($cardlen,$cardtype)."','".createrandstring($cardlen,$cardtype)."','".date("Y-m-d H:i:s")."',$v_custom2)");
					}
					$db->query("INSERT INTO {$web_dbtop}paylogc (cardname,cardnum,price,orderid) VALUES ('$cardname',$num[$i],".($cardprice*$discount/10*$num[$i]).",'$v_orderid')");
				}
			}
			$db->query("update {$web_dbtop}business set sales=sales+$v_price where id=$v_custom2");
			$db->query("insert into {$web_dbtop}paylog (orderid,price,businessid,time,type) values('$v_orderid',".($v_price/100).",$v_custom2,'$v_orderdate',1)");
			$zf=true;
		}
	}
}
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3c.org/TR/1999/REC-html401-19991224/loose.dtd">
<HTML xmlns="http://www.w3.org/1999/xhtml"><HEAD>
<TITLE>商户中心--<?=$web_name;?></TITLE>
<META http-equiv=Content-Type content="text/html; charset=gb2312">
<META content="<?=$web_description;?>" name="cescription">
<META content="<?=$web_keywords;?>" name="keywords">
<META content="MSHTML 6.00.3790.4426" name=GENERATOR>
<LINK href="style/base.css" type=text/css rel=stylesheet>
<LINK href="style/user.css" type=text/css rel=stylesheet>
</HEAD>
<BODY>
<?php include_once("top.php");?>
<DIV id=main>
	<!-- sub_left -->
	<?php include_once("businessLeft.php");?>
	<!-- sub_right -->
<DIV id=right_main>
<DIV><IMG src="images/hyzx_t2.jpg"></DIV>
<DIV class=right_background>
<DIV class=right_banner><IMG src="images/hyzx_gg.jpg"></DIV>
<!--right_Content-->
<div id="right_Content">
<div class="right_title"><img src="images/shzx_wyjh.jpg" width="102" height="18" /></div>
<div class="right_mainContent">
<ul class="bgk">
<? 
if($zf){
?>
	<li class="g1" style="padding-left:5px">支付成功,定单号：<?=$v_orderid;?></li>
	<?
	$query=$db->query("Select * FROM {$web_dbtop}cardtype where id in ($custom[0]) Order by id desc");
	$i=0;
	while($rs=$db->fetch_array($query)){
	?>
		<li class="b22"><span style="padding-left:10px"><?=$rs["cardname"]?> / 每张 <?=number_format($rs["cardprice"]*$discount/10,1);?> 元</span></li>
		<li class="b21a"><span style="padding-left:5px"> <?=$num[$i];?>张</span></li>
	<?
		$i++;
	}
	?>
	<li class="g1" style="padding-left:5px">合计：<?=$v_price/100;?> 元</li>
<? 
}else{
?>
	<li class="g1" style="padding-left:5px">支付失败,<?=$v_pstring;?></li>
<?
}
?>
  </ul>
  </div>
</div>
<DIV><IMG src="images/hyzx_b.jpg"></DIV></DIV></DIV></DIV>
<?php include_once("foot.php");?>
</body>
</html>