<?php
include("require.php");
if(!isset($_COOKIE["core_user_name"]))
  jump("login.php?action=login&last=pay.php");
if($_GET['action']=="pays")
{
  require_once("api/alipay/alipay.config.php");
  require_once("api/alipay/lib/alipay_submit.class.php");
  submitfilter($_POST['money']);
  /**************************请求参数**************************/
  //商户订单号,商户网站订单系统中唯一订单号，必填
  $out_trade_no = (strtotime(date('Y-m-d H:i:s'))+$core_time*3600).rand(1000,9999);
  //订单名称,必填
  $subject = $core_barname."在线充值";
  //付款金额，必填
  $price = trim($_POST['money']);
  //商品数量，必填，建议默认为1，不改变值，把一次交易看成是一次下订单而非购买一件商品
  $quantity = "1";
  //物流费用，必填，即运费
  $logistics_fee = "0.00";
  //物流类型，必填，三个值可选：EXPRESS（快递）、POST（平邮）、EMS（EMS）
  $logistics_type = "EXPRESS";
  //物流支付方式，必填，两个值可选：SELLER_PAY（卖家承担运费）、BUYER_PAY（买家承担运费）
  $logistics_payment = "SELLER_PAY";
  //订单描述
  $body = "";
  //商品展示地址,需以http://开头的完整路径，如：http://www.xxx.com/myorder.html
  $show_url = "";
  //收货人姓名，如：张三
  $receive_name = "";
  //收货人地址，如：XX省XXX市XXX区XXX路XXX小区XXX栋XXX单元XXX号
  $receive_address = "";
  //收货人邮编，如：123456
  $receive_zip = "";
  //收货人电话号码，如：0571-88158090
  $receive_phone = "";
  //收货人手机号码，如：13312341234
  $receive_mobile = "";
  /************************************************************/
  //构造要请求的参数数组，无需改动
  $parameter = array(
		"service" => "trade_create_by_buyer",
		"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,
		"price"	=> $price,
		"quantity"	=> $quantity,
		"logistics_fee"	=> $logistics_fee,
		"logistics_type"	=> $logistics_type,
		"logistics_payment"	=> $logistics_payment,
		"body"	=> $body,
		"show_url"	=> $show_url,
		"receive_name"	=> $receive_name,
		"receive_address"	=> $receive_address,
		"receive_zip"	=> $receive_zip,
		"receive_phone"	=> $receive_phone,
		"receive_mobile"	=> $receive_mobile,
		"_input_charset"	=> trim(strtolower($alipay_config['input_charset']))
  );
  //建立请求
  $alipaySubmit = new AlipaySubmit($alipay_config);
  $html_text = $alipaySubmit->buildRequestForm($parameter,"get", "系统处理中，请稍候，如长时间无反应请点击本链接");
  $time=date('Y-m-d H:i:s',strtotime(date('Y-m-d H:i:s'))+$core_time*3600);
  $phpcolor->table="pay";
  $phpcolor->field="sid ,username, money, status, type, operatetime, ip";
  $phpcolor->where="'".$out_trade_no."','".$_COOKIE['core_user_name']."','".$price."','1','1','".$time."','".$_SERVER['REMOTE_ADDR']."'";
  $phpcolor->write();
  echo $html_text;
  exit();
}
if($_GET['action']=="paytx")
{
  echo "您好，本功能尚未开通，如您需提现请直接联系管理员。";
  exit();
}
$phpcolor->table="user";
$phpcolor->field="money";
$phpcolor->where="username='".$_COOKIE['core_user_name']."'";
$user=$phpcolor->exist(1);
$phpcolor->table="pay";
$phpcolor->field="sum(money)";
$phpcolor->where="username = '".$_COOKIE["core_user_name"]."' and status=2";
$paysum=$phpcolor->exist(1);
if($paysum[0]!="")
  $user['paysum']=$paysum[0];
else
  $user['paysum']=0;
$phpcolor->field="*";
$phpcolor->where="username = '".$_COOKIE["core_user_name"]."'";
$count=$phpcolor->exist(2);
$phpcolor->where="username = '".$_COOKIE["core_user_name"]."' order by operatetime desc limit ".($_GET['page']*15).",15";
$pay=$phpcolor->assignment();
for ($count=0;$count<count($pay);$count++)
{
  if($pay[$count]['status']=="0")
	$pay[$count]['statusn']="交易成功";
  $sbtime=date('Y-m-d H:i:s',strtotime(date('Y-m-d H:i:s'))+$core_time*3600-36000);
  if($pay[$count]['status']=="1" and $pay[$count]['operatetime']<$sbtime)
    $pay[$count]['statusn']="交易失败";
  elseif($pay[$count]['status']=="1")
    $pay[$count]['statusn']="等待付款";
  if($pay[$count]['status']=="2")
    $pay[$count]['statusn']="等待付款";
  $pays[$count]=$phpcolor->payso($pay[$count]['type'],$pay[$count]['money']);
  $pay[$count]['moneys']=$pays[$count]['moneys'];
  $pay[$count]['types']=$pays[$count]['types'];
}
$page=pages($count,15,$_GET['page'],'page','','','0');
$tpl -> assign("action", $_GET['action']);
$tpl -> assign("pay", $pay); 
$tpl -> assign("user", $user); 
$tpl -> assign("page", $page);
$tpl -> assign("core_header_title", "充值记录 - ");
$tpl -> display("$core_style/pay.htm");
?>