<?
include("../../config/conn.php");
include("../../config/function.php");
sesCheck_m();

$sqluser="select * from yjcode_user where uid='".$_SESSION[SHOPUSER]."'";mysql_query("SET NAMES 'GBK'");$resuser=mysql_query($sqluser);
if(!$rowuser=mysql_fetch_array($resuser)){php_toheader("../reg/");}
$sj=date("Y-m-d H:i:s");
include("../../user/buycheck.php");

//B
if(sqlzhuru($_POST[jvs])=="carpay" && sqlzhuru($_POST[R1])=="alipay"){
if($needmoney<=$usermoney){Audit_alert("您的可用余额充足，请用余额直接支付。","carpay.php?carid=".$carid);}
zwzr();
updatetable("yjcode_user","uqq='".sqlzhuru($_POST[tuqq])."' where uid='".$_SESSION[SHOPUSER]."'");
$bh=time();
$uip=$_SERVER["REMOTE_ADDR"];
$ddbh=time()."|".$rowuser[id];	
$money1=sprintf("%.2f",($needmoney-$usermoney));
$buyformarr=sqlzhuru($_POST[buyformv]);
$shdzarr=sqlzhuru($_POST[shdzv]);
intotable("yjcode_dingdang","bh,ddbh,userid,sj,uip,money1,ddzt,alipayzt,bz,ifok,probh,pronum,tcid,buyform,shdz","'".$bh."','".$ddbh."',".$rowuser[id].",'".$sj."','".$uip."',".$money1.",'等待买家付款','','',0,'".$bharr."','".$numarr."','".$tcidarr."','".$buyformarr."','".$shdzarr."'");

require_once("../../user/alipay.config.php");
$payment_type = "1";
$notify_url = weburl."user/notify_carpay.php"; //服务器异步通知页面路径
$return_url = weburl."m/user/order.php";//页面跳转同步通知页面路径
$seller_email = $rowcontrol[seller_email];//卖家支付宝帐户
$out_trade_no = $ddbh;//商户订单号
$subject = webname."收银台结算";//订单名称
$body =  webname."收银台结算";
$show_url = weburl;//商品展示地址

//开始即时到帐
if(0==$rowcontrol[zftype]){ 
$alipay_config['cacert']    = getcwd().'\\cacert.pem';
require_once("../../user/lib/alipay_submit.class.php");
$total_fee = $money1;//付款金额
$anti_phishing_key = "";//防钓鱼时间戳
$exter_invoke_ip = "";//客户端的IP地址
$parameter = array(
		"service" => "create_direct_pay_by_user",
		"partner" => trim($alipay_config['partner']),
		"payment_type"	=> $payment_type,
		"notify_url"	=> $notify_url,
		"return_url"	=> $return_url,
		"seller_email"	=> $seller_email,
		"out_trade_no"	=> $out_trade_no,
		"subject"	=> $subject,
		"total_fee"	=> $total_fee,
		"body"	=> $body,
		"show_url"	=> $show_url,
		"anti_phishing_key"	=> $anti_phishing_key,
		"exter_invoke_ip"	=> $exter_invoke_ip,
		"_input_charset"	=> trim(strtolower($alipay_config['input_charset'])));
//结束即时到帐


}

//建立请求
$alipaySubmit = new AlipaySubmit($alipay_config);
$html_text = $alipaySubmit->buildRequestForm($parameter,"get", "正在跳转，请稍候");
echo $html_text;exit;


}elseif(sqlzhuru($_POST[jvs])=="carmypay"){//余额支付
 if($needmoney>$usermoney){Audit_alert("您的可用余额不足，返回重试。","carpay.php?carid=".$carid);}
 zwzr();
 updatetable("yjcode_user","uqq='".sqlzhuru($_POST[tuqq])."' where uid='".$_SESSION[SHOPUSER]."'");
 $buyuserid=$rowuser[id];
 $buyformarr=sqlzhuru($_POST[buyformv]);
 $shdzarr=sqlzhuru($_POST[shdzv]);
 include("../../user/buy.php");
 php_toheader("../tishi/index.php?admin=4");

}
//E
?>
<html>
<html>
<head>
<meta http-equiv="x-ua-compatible" content="ie=7" />
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<meta name="viewport" content="width=device-width,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no"/>
<title>会员中心 <?=webname?></title>
<link rel="stylesheet" href="../css/basic.css">
<link rel="stylesheet" href="index.css">
<script src="../js/jquery-1.9.1.min.js" type="text/javascript"></script>
<script language="javascript" src="../js/basic.js"></script>
<script language="javascript" src="index.js"></script>
<script language="javascript">
function xz(x){
document.getElementById(x).checked=true;	
}

function carpaytj(x){
 if((document.f1.tuqq.value).replace("/\s/","")==""){alert("请输入您的常用QQ");document.f1.tuqq.focus();return false;}
 r=document.getElementsByName("R1");
 rv="";
 for(i=0;i<r.length;i++){
 if(r[i].checked==true){rv=r[i].value;}
 }
 <? if($usermoney<$needmoney){?>if(rv==""){alert("请选择支付方式");return false;}<? }?>
 if(rv=="alipay" || rv==""){fu="carpay.php?carid="+x;}
 else if(rv=="tenpay"){fu="../../user/tenpay/buy_index.php?carid="+x;}
 else if(rv=="ips"){fu="../../user/ips/buy_OrderPay.php?carid="+x;}
 else if(rv=="bank"){fu="../../user/bank/buy_Send.php?carid="+x;}
 
 else if(rv=="wxpay"){f1.action="../../user/wxpay/buy_index.php?m=yes&carid="+x;}
 <? if ( strpos($_SERVER['HTTP_USER_AGENT'], 'MicroMessenger') == false ) {?>
 //else if(rv=="wxpay"){f1.action="../../user/wxpay/buy_index.php?m=yes&carid="+x;}
 <? }else{?>
 //else if(rv=="wxpay"){f1.action="wxpay_gz/example/jsapi.php?carid="+x;}
 <? }?>
 
 else if(rv=="yunpay"){f1.action="../../user/yunpay/buy_yunpay.php?carid="+x;}
 a=parseInt(document.getElementById("biga").innerHTML);
 buystr="";
 rshdz="";
 for(i=1;i<=a;i++){
  buystrs="";
  if(document.getElementById("smalla"+i)){
   b=parseInt(document.getElementById("smalla"+i).innerHTML);
   for(j=1;j<=b;j++){buystrs=buystrs+document.getElementById("buyt"+i+"_"+j).value+document.getElementById("buyv"+i+"_"+j).value+"<br>";}
  }
  buystr=buystr+buystrs+"yj99yjcode";
  
  rr="";
  if(document.getElementById("Rdz"+i)){
   r=document.getElementsByName("Rdz"+i);
   rr="";
   for(i=0;i<r.length;i++){if(r[i].checked==true){rr=r[i].value;}}
  }
  rshdz=rshdz+rr+"xcf";

 }
 document.f1.buyformv.value=buystr;
 document.f1.shdzv.value=rshdz;
 f1.action=fu;
}

function yunfeicha(){
yunfeiv=0;
a=parseInt(document.getElementById("biga").innerHTML);
for(i=1;i<=a;i++){
 rr="";
 if(document.getElementById("Rdz"+i)){
 r=document.getElementsByName("Rdz"+i);
 rr="";
 for(j=0;j<r.length;j++)
  if(r[j].checked==true){rr=r[j].value;yunfeiv=addNum(yunfeiv,document.getElementById("yunfei"+rr).value);}
 }
}

document.f1.yunfeifv.value=yunfeiv;
document.getElementById("yunfeii").innerHTML="(含运费："+yunfeiv+"元)";
yepayv=parseFloat(document.getElementById("yepay").innerHTML);
yepay1v=parseFloat(document.getElementById("yepay1").innerHTML);
if((yunfeiv+yepay1v)<=yepayv){ //余额充足
 document.f1.jvs.value="carmypay";
 document.getElementById("dsf").style.display="none";
 document.getElementById("yepay2").innerHTML=addNum(yunfeiv,yepay1v);
}else{
 document.f1.jvs.value="carpay";
 document.getElementById("dsf").style.display="";
 document.getElementById("yepay2").innerHTML=yepayv;
 document.getElementById("yepay4").innerHTML=addNum(yunfeiv,parseFloat(document.getElementById("yepay3").innerHTML));
}
}

function tjonc(){
 tjwait();
}
</script>
</head>
<body>
<? include("top.php");?>

<div class="boxcap box">
 <div class="d1"><a href="../">用户中心</a> - 收银台结算</div>
</div>

  <form name="f1" method="post" onSubmit="return carpaytj('<?=$carid?>')">
  <input type="hidden" value="" name="buyformv">
  <input type="hidden" value="" name="shdzv">
  <input type="hidden" value="0" name="yunfeifv">
  <div class="listcap box"><div class="d2">结算统计：</div></div>
  <div class="syt box">
  <div class="d1">商品数量：<?=$pnum?></div>
  <div class="d2"><strong><?=$needmoney?></strong> 元</div>
  </div>
  
  <div class="listcap box"><div class="d2">信息输入：</div></div>
  <div class="uk box">
  <div class="d11">常用QQ：</div>
  <div class="d2"><input type="text" name="tuqq" value="<?=$rowuser[uqq]?>" placeholder="请填写您的常用QQ，网站工作人员可能会需要与您联系" /></div>
  </div>
  
  <?
  $biga=0;
  $b=preg_split("/xcf/",$bharr);
  for($i=0;$i<=count($b);$i++){
  if(!empty($b[$i])){
  $biga++;
  while1("id,bh,tit,ty2id,userid,fhxs","yjcode_pro where bh='".$b[$i]."'");$row1=mysql_fetch_array($res1);$prouserid=$row1[userid];
  while2("*","yjcode_type where admin=2 and id=".$row1[ty2id]);if($row2=mysql_fetch_array($res2)){
  if(!empty($row2[buyform])){
  ?>
  <ul class="ukbuy">
  <li class="cap">您购买的<span class="green"> <?=returntitdian($row1[tit],60)?> </span>建议填入以下内容，以便我们更好地为您发货</li>
  <?
  $av=str_replace("\r","",$row2[buyform]);
  $a=preg_split("/\n/",$av);
  $smalla=0;
  for($j=0;$j<=count($a);$j++){
  if(!empty($a[$j])){
  $smalla++;
  ?>
  <li class="l1"><input type="text" style="display:none;" value="<?=$a[$j]?>" id="buyt<?=$biga?>_<?=$smalla?>" /><?=$a[$j]?></li>
  <li class="l2"><input type="text" class="inp" id="buyv<?=$biga?>_<?=$smalla?>" /></li>
  <? }}?>
  </ul>
  <div id="smalla<?=$biga?>" style="display:none;"><?=$smalla?></div>
  <?
  }}
  ?>
  
  <? if(5==$row1[fhxs]){?>
  <div class="listcap box"><div class="d2">请选择收货地址 [<a href="shdzlx.php" class="blue">+增加收货地址</a>]</div></div>
  <div class="uk box">
  <? while1("*","yjcode_shdz where zt=0 and userid=".$rowuser[id]." order by sj desc");while($row1=mysql_fetch_array($res1)){?>
  <div class="d3">
  <label>
  <input type="hidden" value="<?=returnyunfei($row1[add1],$row1[add2],$row1[add3],$prouserid);?>" name="yunfei<?=$row1[id]?>" id="yunfei<?=$row1[id]?>" />
  <input name="Rdz<?=$biga?>" id="Rdz<?=$biga?>" onClick="yunfeicha()" type="radio" value="<?=$row1[id]?>"<? if($row1[ifmr]==1){?> checked<? }?> />&nbsp;
  <?=$row1[lxr]." ".returnarea($row1[add1]).returnarea($row1[add2]).returnarea($row1[add3]).$row1[addr]." (手机:".$row1[mot]?>)  &nbsp;&nbsp;&nbsp;&nbsp;[<a href="shdz.php?bh=<?=$row1[bh]?>" class="blue">修改</a>]
  </label>
  </div>
  <? }?>
  </div>
  <? }?>
  
  <? }}?>
  <div id="biga" style="display:none;"><?=$biga?></div>

  <div class="listcap box"><div class="d2">余额：<strong id="yepay"><?=$usermoney?></strong> 元</div></div>

  <div class="pay box">
   <div class="paym">
   <ul class="pu1">
   <li class="l1">&nbsp;&nbsp;<? if($usermoney<$needmoney){$p=$usermoney;}else{$p=$needmoney;}?><span id="yepay1" style="display:none;"><?=$needmoney?></span><strong id="yepay2"><?=$p?></strong> 元<span id="yunfeii"></span><? if(!empty($userdj)){?>，<?=$userdj?>(已减<span class="red"><?=$yhmoney?></span>元)<? }?></li>
   </ul>
   
   <div id="dsf">
   <ul class="pay1">
   <li class="l1">&nbsp;&nbsp;采用第三方平台支付<span id="yepay3" style="display:none;"><?=sprintf("%.2f",($needmoney-$usermoney))?></span><strong id="yepay4"><?=$yepay3?></strong> 元：</li>
  
   <? if(!empty($rowcontrol[partner]) && !empty($rowcontrol[security_code]) && !empty($rowcontrol[seller_email]) && 3!=$rowcontrol[zftype]){?>
   <li class="l2"><input name="R1" id="alipay" checked="checked" type="radio" value="alipay" /><img onClick="xz('alipay')" src="../../user/img/pay/alipay.gif" /></li>
   <? }?>
  
   <? if(!empty($rowcontrol[tenpay1]) && !empty($rowcontrol[tenpay2])){?>
   <li class="l2">
   <input name="R1" id="tenpay" type="radio" value="tenpay" /><img src="../../user/img/pay/tenpay.gif" onClick="xz('tenpay')" />
   </li>
   <? }?>

   <? if(!empty($rowcontrol[ipsshh]) && !empty($rowcontrol[ipszs])){?>
   <li class="l2">
   <input name="R1" id="ips" type="radio" value="ips" /><img src="../../user/img/pay/ips.gif" onClick="xz('ips')" />
   </li>
   <? }?>
  
   <? if(!empty($rowcontrol[bankbh]) && !empty($rowcontrol[bankkey])){?>
   <li class="l2">
   <input name="R1" id="bank" type="radio" value="bank" /><img src="../../user/img/pay/bank.gif" onClick="xz('bank')" />
   </li>
   <? }?>

   <? if(!empty($rowcontrol[wxpay]) && $rowcontrol[wxpay]!=",,,"){?>
   <li class="l2">
   <input name="R1" id="wxpay" type="radio" value="wxpay" /><img src="../../user/img/pay/wxpay.gif" onClick="xz('wxpay')" />
   </li>
   <? }?> 

   <? if(!empty($rowcontrol[yunpay]) && $rowcontrol[yunpay]!=",,"){?>
   <li class="l2">
   <input name="R1" id="yunpay" type="radio" value="yunpay" /><img src="../../user/img/pay/yunpay.png" width="150" height="50" onClick="xz('yunpay')" />
   </li>
   <? }?>

   </ul>
   </div>
  
   </div>
  </div>

  <div class="carbtn" onClick="tjonc()">
   <div id="tjbtn"><input type="submit" class="tjinput" value="确认付款" /></div>
   <div class="tjing" id="tjing" style="display:none;">
   <img style="margin:0 0 6px 0;" src="../img/ajax_loader.gif" width="208" height="13" /><br />正在处理数据，请不要刷新页面，也不要关闭页面 ^_^
   </div>
  </div>
  <input type="hidden" value="carpay" name="jvs" />

  </form>

<script language="javascript">
yunfeicha();
</script>
</body>
</html>