<?php
define('CURSCRIPT','payrecord');
require dirname(__FILE__)."/global.php";
require MYMPS_INC."/db.class.php";
require MYMPS_INC."/pay.fun.php";
require MYMPS_DATA."/moneytype.inc.php";

$part = $part ? $part : 'list';

(!defined('IN_ADMIN') || !defined('IN_MYMPS')) && exit('Access Denied');

if($orderid){
	$orderid=intval($orderid);
	UpdatePayRecord($orderid,'支付成功');
	write_msg('','?page='.$page);
}

if(!submit_check(CURSCRIPT.'_submit')) {
	!chk_adm_purview("purview_支付接口")&& write_msg("很抱歉，您所在会员组没有当前菜单的操作权限！");
	$here     = '管理支付记录';
	$where    = "WHERE 1 ";
	
	$rstarttime = $starttime ? strtotime($starttime) : 0;
	$rendtime = $endtime ? strtotime($endtime) : 0;
	$status = $status ? intval($status) : 1;
	
	if($keywords != ''){
		switch($action){
			case 1:
				$where .= $keywords ? " AND a.orderid LIKE '%".$keywords."%'" : "";
			break;
			case 2:
				$where .= $keywords ? " AND a.userid LIKE '%".$keywords."%'" : "";
			break;
			case 3:
				$where .= $keywords ? " AND a.payip LIKE '%".$keywords."%'" : "";
			break;
			case 4:
				$where .= $keywords ? " AND a.paybz LIKE '%".$keywords."%'" : "";
			break;
			case 5:
				$cityid = $db->getOne("SELECT cityid FROM `{$db_mymps}city` WHERE cityname = '$keywords'");
				$where .= $keywords ? " AND b.cityid = '$cityid'" : "";
			break;
		}
	}
	
	$where .= $rstarttime ? " AND a.posttime > '$rstarttime'" : "" ; 
	$where .= $rendtime ? " AND a.posttime < '$rendtime'" : "" ;
	$where .= $cityid ? " AND b.cityid = '$cityid'" : "" ; 
	$where .= $ifadd ? " AND a.ifadd = '1'" : "";
	
	if($status == 2){
		$where .= " AND a.ifadd = 1 AND (a.paybz = '支付完成' OR a.paybz = '支付成功')";
	} elseif($status == 3){
		$where .= " AND a.ifadd = 0 AND a.paybz = '等待支付'";
	}
	$sql	  = "SELECT a.*,b.cityid FROM `{$db_mymps}payrecord` AS a LEFT JOIN `{$db_mymps}member` AS b ON a.userid=b.userid $where ORDER BY a.id DESC";
	$totals_num = $db->getOne("SELECT SUM(a.money) FROM `{$db_mymps}payrecord` AS a LEFT JOIN `{$db_mymps}member` AS b ON a.userid=b.userid {$where} AND a.ifadd = '1'");
	$rows_num = $db->getOne("SELECT COUNT(a.id) FROM `{$db_mymps}payrecord` AS a LEFT JOIN `{$db_mymps}member` AS b ON a.userid=b.userid {$where}");
	$param	  = setParam(array('starttime','endtime','keywords','action','status'));
	$list	  = page1($sql);
	$starttime  =  $starttime ? date('Y-m-d',$rstarttime) : '';
	$endtime 	=  $endtime   ? date('Y-m-d',$rendtime)	 : '';
	include(mayi_tpl(CURSCRIPT));
} else {
	if(is_array($delids)){
		$i=1;
		foreach ($delids as $kids => $vids){
			mymps_delete(CURSCRIPT,"WHERE id = ".$vids);
		}
	}
	write_msg('会员充值记录更新成功！',$url,'MympsRecord');
}

is_object($db) && $db->Close();
$mymps_global = $db = $db_mymps = $part = NULL;
?>