<?php
include(dirname(__FILE__)."/require.php");
if($ppurview[39]!=1)
  jump("jump.php?id=25&jump=main.php");
$phpcolor->table="pay";
if(isset($_GET['action']) and isset($_GET['id']) and $_GET['action'] == "define")
{
  $phpcolor->field="money,username";
  $phpcolor->where="id = '".$_GET['id']."'";
  $pay=$phpcolor->exist(1);
  $phpcolor->field="status='0'";
  $phpcolor->upgrade();
  $time=date('Y-m-d H:i:s',strtotime(date('Y-m-d H:i:s'))+$core_time*3600);
  $phpcolor->table="user";
  $phpcolor->field="money=money+".$pay['money'];
  $phpcolor->where="username = '".$pay['username']."'";
  $phpcolor->upgrade();
  jump("jump.php?id=24&jump=pay.php");
}
if(isset($_GET['action']) and $_GET['action'] == "adddo")
{
  submitfilter($_POST['money']);
  $phpcolor->table="user";
  $phpcolor->field="*";
  $phpcolor->where="username = '".$_POST['username']."'";
  if(!$phpcolor->exist(2))
    jump("jump.php?id=1&jump=pay.php?action=add");
  $phpcolor->table="pay";
  $tradeno=(strtotime(date('Y-m-d H:i:s'))+$core_time*3600).rand(1000,9999);
  $time=date('Y-m-d H:i:s',strtotime(date('Y-m-d H:i:s'))+$core_time*3600);
  $phpcolor->field="sid ,username, money, status, type, operatetime, ip";
  $phpcolor->where="'".$tradeno."','".$_POST['username']."','".$_POST['money']."','0','".$_POST['type']."','".$time."','管理员操作'";
  $phpcolor->write();
  $phpcolor->table="user";
  if($_POST['type']=="2")
    $phpcolor->field="money=money+".$_POST['money'];
  if($_POST['type']=="3")
    $phpcolor->field="money=money-".$_POST['money'];
  $phpcolor->where="username = '".$_POST['username']."'";
  $phpcolor->upgrade();
  jump("jump.php?id=24&jump=pay.php");
}
if(isset($_GET['action']) and $_GET['action'] == "add")
  $tpl -> display("pay_add.htm");
else
{
  if(!isset($_GET['page']))
    $_GET['page']=0;
  $phpcolor->field="*";
  if(isset($_GET['username']))
  {
    $phpcolor->where="username like '%".$_GET['username']."%'";
    $count=$phpcolor->exist(2);
    $phpcolor->where="username like '%".$_GET['username']."%' order by operatetime desc limit ".($_GET['page']*20).",20";
	$page=pages($count,20,$_GET['page'],'pay','&username='.$_GET['username'].'','0');
  }
  else
  {
	$phpcolor->where="1=1";
    $count=$phpcolor->exist(2);
    $phpcolor->where="1=1 order by operatetime desc limit ".($_GET['page']*20).",20"; 
    $page=pages($count,20,$_GET['page'],'pay','','','0');
  }
  $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'];
  }
  $tpl -> assign("pay", $pay);
  $tpl -> assign("page", $page);
  $tpl -> display("pay.htm");
}
?>