<!--#include virtual="/inc/conn.asp"-->
<!--#include virtual="/inc/sitecon.asp"-->
<%
On error resume next 

Function randarr()
Const stringmodarr = "0123456789"
strlength = Len(stringmodarr)
Randomize timer
For i = 1 To 5 
randarr2 = randarr2&Mid(stringmodarr,Int(Rnd * strlength + 1),1)  
Next 
randarr=randarr2 
End Function



'新版 后台排序发卡Function payokbuy
Function payokbuy(out_trade_no,trade_no,total_fee,isre)
	sql="select top 1 aydingdansum,aydingdanzt,aydingdanzj,ayddyouhuiquan,ayddyouhuiquanzhi,ddrebiaoshi from "&getddku(out_trade_no)&" where aydingdansum='"&out_trade_no&"' and aydingdanzt=0" 
	rs.open sql,conn,1,3	
	if not(rs.bof and rs.eof) then 
		if isnull(trim(rs("ayddyouhuiquan")))=false and trim(rs("ayddyouhuiquan"))<>"" then
			kouyouhui=ccur(rs("aydingdanzj"))-ccur(rs("ayddyouhuiquanzhi"))
			if ccur(total_fee)<ccur(kouyouhui) then 
			conn.execute "update "&getddku(out_trade_no)&" set aydingdanzt=0,ayddbody='"&now()&"sign金额篡改"&total_fee&"-"&kouyouhui&"' where aydingdansum='"&out_trade_no&"'"
			rs.close
			response.End()
			end if
		else
			if ccur(total_fee)<ccur(rs("aydingdanzj")) then 
			conn.execute "update "&getddku(out_trade_no)&" set aydingdanzt=0,ayddbody='"&now()&"sign金额篡改"&total_fee&"-"&rs("aydingdanzj")&"' where aydingdansum='"&out_trade_no&"'"
			rs.close
			response.End()
			end if
		end if
	rs("ddrebiaoshi")=rejiami
	rs.update
	conn.execute "update aybuylx set aydddzt=1,aydddj='"&trade_no&"' where aydddsum='"&out_trade_no&"' and aydddzt=0"
	end if
	rs.close
End Function



'充值
Function payokchong(out_trade_no,trade_no,total_fee,isre)

		cwku=getcwku(out_trade_no)
		sql="select aycailiushui,aycaiwuzt,aycwfsjin from "&cwku&" where aycailiushui='"&out_trade_no&"' and aycaiwuzt=0" 
		rs.open sql,conn,1,1	
		if not(rs.bof and rs.eof) then 
			if ccur(total_fee)<ccur(rs("aycwfsjin")) then 
			response.End()
			end if
		else
		response.End()
		end if 
		rs.close
		 
		sql="select aycaiwujine,aycaiwuuser,aycaiwuzt,aycailiushui,aycwfsjin from "&cwku&" where aycailiushui='"&out_trade_no&"' and aycaiwuzt=0" 
		rs.open sql,conn,1,3
		if not(rs.bof and rs.eof) then 
			if ccur(total_fee)<ccur(rs("aycwfsjin")) then 
			response.End()
			end if
		aycaiwujine=rs("aycaiwujine")    '发生金额
		aycaiwuuser=rs("aycaiwuuser")    '所属会员
		rs("aycaiwuzt")=1
		rs.update
		rs.close
		'充值入账
		sql="select aynameid,ayyue from ayname where aynameid="&clng(aycaiwuuser)&"" 
		rs.open sql,conn,1,3
		useryu=ccur(rs("ayyue"))+ccur(aycaiwujine)
		rs("ayyue")=ccur(rs("ayyue"))+ccur(aycaiwujine)
		rs.update
		rs.close
		'财务发送余额更新
		sql="select aycailiushui,aycaiwuyue from "&cwku&" where aycailiushui='"&out_trade_no&"'" 
		rs.open sql,conn,1,3
		rs("aycaiwuyue")=useryu
		rs.update
		rs.close
		end if
		
		if isre="re" then
		response.Redirect(weburl&"pay/payok.asp?c=ok")
		end if
		
	'if err.number<>0 then 
	'errstr=replace(Err.Description,"'"," ")  
	'conn.Execute("Insert Into ayerr(errcon,errlu,errbei) values('"&errstr&"','"&Request.ServerVariables("HTTP_URL")&"','payokchong')")
	'if isre="re" then response.Redirect(weburl&"pay/payok.asp?c=ok")
	'end if
End Function



%>