<%@ Language=VBScript %>
<!--#include virtual="/inc-freehost-function/FreeHostFunctionMain.asp"-->
<%
If session("admau")="" Then
	ef=True
	ec="授权非法，有可能是超时造成的。"
ElseIf Request.Form ("username")="" or RegExpTest("[^A-Za-z0-9]",Request.Form ("username")) Then
	ef=True
	ec="用户名没填或非法字符！"
ElseIf Request.Form ("usermoney")="" Then
	ef=True
	ec="金额没填！"
ElseIf Request.Form ("add")="" Then
	ef=True
	ec="必须选择款项操作分类！"
ElseIf not IsNumeric(Request.Form ("usermoney"))  Then
	ef=True
	ec="金额应该是数字！"
ElseIf Request.Form ("forwhat")="" Then
	ef=True
	ec="必须填写原因！"
end if

if not ef then
if Request.Form ("add")="入款" then
If session("canmoneyA")="" Then
	ef=True
	ec="您没有此操作的权限。"
end if
elseif Request.Form ("add")="直接扣款" then
If session("canmoneyB")="" Then
	ef=True
	ec="您没有此操作的权限。"
end if
elseif Request.Form ("add")="消费扣款" then
If session("canmoneyC")="" Then
	ef=True
	ec="您没有此操作的权限。"
end if
elseif Request.Form ("add")="退款回帐" then
If session("canmoneyD")="" Then
	ef=True
	ec="您没有此操作的权限。"
end if
elseif Request.Form ("add")="退款" then
If session("canmoneyE")="" Then
	ef=True
	ec="您没有此操作的权限。"
end if
elseif Request.Form ("add")="代理返款" then
If session("canmoneyF")="" Then
	ef=True
	ec="您没有此操作的权限。"
end if
elseif Request.Form ("add")="优惠虚增" then
If session("canmoneyG")="" Then
	ef=True
	ec="您没有此操作的权限。"
end if
end if
end if 
 

if not ef then
if Request.Form ("usermoney")<0 then
	ef=True
	ec="金额不能小于零！"
end if
end if

if not ef then
isagn=false
Set conn=Server.CreateObject("ADODB.Connection")
	conn.Open Application("FreeHostDBlink")
	if Request.Form ("usertype")="用户名" then
	Set ds = Server.CreateObject("ADODB.Recordset")	
		Sql="Select * from FreeHost.FreeHost_USER where username='"&Request.Form ("username")&"'"
		ds.Open Sql,conn,1,3
if ds.Eof then
		ef=True
		ec="用户不存在！"
end if
end if
end if

if not ef then
if Request.Form ("usertype")="代理名" then
		Set ds = Server.CreateObject("ADODB.Recordset")	
		Sql="Select * from FreeHost.FreeHost_AGENT where username='"&Request.Form ("username")&"'"
		ds.Open Sql,conn,1,3
	if ds.Eof then
		ef=True
		ec="代理用户不存在！"
	else
		isagn=true
	end if
end if
end if

if not ef then
if Request.Form ("usertype")="用户或代理名" then
isagn=false
Set conn=Server.CreateObject("ADODB.Connection")
	conn.Open Application("FreeHostDBlink")
		Set ds = Server.CreateObject("ADODB.Recordset")	
		Sql="Select * from FreeHost.FreeHost_AGENT where username='"&Request.Form ("username")&"'"
		ds.Open Sql,conn,1,3
	if ds.Eof then
	Set ds = Server.CreateObject("ADODB.Recordset")	
		Sql="Select * from FreeHost.FreeHost_USER where username='"&Request.Form ("username")&"'"
		ds.Open Sql,conn,1,3
if ds.Eof then
		ef=True
		ec="用户或代理不存在！"
end if
	else
		isagn=true
	end if
end if
end if

if not ef then
if DateDiff("s", Application("domainoptime"),NOW )<Application("domainopmax") and Application("domainoplock")=true then
'	ef=True
	ec="系统繁忙，前一个操作尚未处理完，请您稍等两分钟后再试，谢谢您的支持。"
else
Application.lock
Application("domainoptime")=now
Application("domainoplock")=true
Application.unlock
end if
end if

if not ef then
stmoney=ds("usermoney")
moneych=0
if Request.Form ("add")="入款" or Request.Form ("add")="退款" or Request.Form ("add")="优惠虚增" then
isadd="y"
ds("usermoney")=ds("usermoney")+request.Form ("usermoney")
moneych=request.Form ("usermoney")

if request("kefuget")="是" and not isnull(ds("kefunow")) and Request.Form ("add")="入款" then
Set dskefu = Server.CreateObject("ADODB.Recordset")	
	Sql="Select finishmoney from FreeHost.FreeHost_KeFu where kefumd5='"&md5(trim(ds("kefunow")))&"'"
	dskefu.Open Sql,conn,1,3
if not dskefu.Eof then
dskefu("finishmoney")=dskefu("finishmoney")+moneych
dim kefu
kefu=ds("kefunow")
dskefu.update
end if
dskefu.close
end if

else
isadd="n"
ds("usermoney")=ds("usermoney")-request.Form ("usermoney")
moneych=request.Form ("usermoney")
end if
endmoney=ds("usermoney")
ds.Update

issubagn="n"
isuser="n"
if isagn then
isagn="y"
else
isagn="n"
isuser="y"
end if
'log

'log to user or agn
'connmoney=conn
isuser=isuser
isagn=isagn
issup="y"
ishand="y"
isadd=isadd
isAgnHostSer=false
moneyX=moneych
if isuser="y" then
norusername=Request.Form ("username")
norStmoney=stmoney
norEndmoney=endmoney
end if
if isagn="y" then
agnusername=Request.Form ("username")
agnStmoney=stmoney
agnEndmoney=endmoney
end if
supusername=session("admusername")
forwhat=Request.Form ("forwhat")
corewhat=Request.Form ("corewhat")
whichProduct=Request.Form ("whichProduct")
pdid=0
attime=NOW
pingzheng=Request.Form ("pingzheng")
type1=Request.Form ("add")
bank=Request.Form ("bank")
haveget=Request.Form ("haveget")
havecheck="否"
'pdtype=pdtype
'pdsttime=pdsttime
'pdendtime=pdendtime
username=Request.Form ("username")
opusername=session("admusername")

FreeHost_moneyNewlog conn,isuser,isagn,issup,ishand,isadd,isAgnHostSer,moneyX,username,opusername,norusername,norStmoney,norEndmoney,agnusername,agnStmoney,agnEndmoney,supusername,forwhat,corewhat,whichProduct,pdid,pingzheng,type1,bank,haveget,havecheck



ds.Close
set ds=nothing
conn.Close 
set conn=nothing

Application.lock
Application("domainoplock")=false
Application.unlock
%>
<br>
<br>
操作成功：
<%if isagn="y" then%>
<font color=red>操作代理：</font>
<%else%>
操作用户：
<%end if%>
<%=Request.Form ("username")&" 原金额是："&stmoney&"元　现在的可用金额是："&endmoney&"元。"%>
<%if isadd="y" then%>
增加：
<%else%>
减少：
<%end if%>
<%=moneych%> 元
<%end if

if ef then%>
<%=ec%>
<%end if%>
<script>
var partable=parent.document.getElementById("table0");
if (partable!=null)
partable.style.display='';

partable=parent.document.getElementById("outconM");
if (partable!=null)
partable.innerHTML = document.body.innerHTML;
</script>