<?php
	!defined('DIRCMS_MANAGE') && exit('Access Denied!');
	$r=cache_read('module.cache.php',DIRCMS_ROOT.'data/cache_module/');
	$r=$r['order']['roleid']; 
	if(!in_array($_roleid,$r) && $_userid!=ADMIN_FOUNDERS)showmsg_nourl('您没有该操作的权限!');
	$action=empty($action)?'manage':trim($action);
	require_once(DIRCMS_ROOT.'include/list.class.php');
	$l=new dircmslist();
	switch($action)
	{
		case 'manage':
			$where=1;
			$where=isset($ispay)?$where." AND `ispay`=".intval($ispay):$where;
			$field=$field?$field:'username';
			if(!in_array($field,array('username','sn','inputer')))showmsg('错误的请求!');
			$k=trim(preg_replace('/[!@#\$%\^&\*\(\):\'\"\{\}\[\]\.\?\,\/`\;]+/i','',$k));
			$where=!empty($k)?$where." AND `{$field}` like '%".$k."%'":$where;
			$orderby="id DESC";
			$page=max(isset($page)?intval($page):1,1);
			$result=$l->getlist(DB_PRE.'pay_user_account',$where,$orderby,$page,15);
			$pages=$l->pages;
			include admin_tlp('paylog_manage');
			break;
		case 'delete':
			if(!$id)showmsg('请选择需要删除的记录!');
			$id=array_map('intval',!is_array($id)?array($id):$id);
			$db->mysql_delete(DB_PRE.'pay_user_account',$id);
			showmsg($LANG['MANAGE_SUCEESS'],ADMIN_FILE.'?file=paylog&action=manage');
			break;
		case 'pay':
			$id=intval($id);
			$r=$db->fetch_one('SELECT * FROM `'.DB_PRE.'pay_user_account` WHERE `'.DB_PRE.'pay_user_account`.`id`='.$id);
			if(!$r)showmsg('该充值记录不存在!',ADMIN_FILE.'?file=paylog&action=manage');
			if($r['ispay'])showmsg('无效的操作!',ADMIN_FILE.'?file=paylog&action=manage');
			$db->update(DB_PRE.'pay_user_account',array('inputer'=>$_username,'inputerid'=>$_userid,'paytime'=>TIME,'ispay'=>1,'ip'=>IP),'id='.$id);
			$db->query("UPDATE `".DB_PRE."member` SET `".DB_PRE."member`.`amount`=`".DB_PRE."member`.`amount`+".floatval($r['quantity'])." WHERE `".DB_PRE."member`.`id`='{$r[userid]}'",true);
			$db->query("UPDATE `".DB_PRE."member_cache` SET `".DB_PRE."member_cache`.`amount`=`".DB_PRE."member_cache`.`amount`+".floatval($r['quantity'])." WHERE `".DB_PRE."member_cache`.`id`='{$r[userid]}'",true);
			showmsg($LANG['MANAGE_SUCEESS'],ADMIN_FILE.'?file=paylog&action=manage');
			break;
	}
?>
