<!--#include file="config.asp"-->
<!--#include file="check.asp"-->
<!--#include file="../inc/cls_payment.asp"-->
<%
Dim m_orderid,addmoney,m_oamount,m_ocomment
Dim wp,strChinaeBank
strChinaeBank = Split(Newasp.ChinaeBank, "|||")
Set wp = New WebPayment_Cls
wp.PayPlatform = CInt(Newasp.StopBankPay)
wp.Paymentid = Trim(strChinaeBank(0))
wp.Paymentkey = Trim(strChinaeBank(1))
wp.Percent = Newasp.CheckNumeric(strChinaeBank(2))
wp.Comment = "会员充值"
wp.ReceivePage
m_orderid = Newasp.CheckInfuse(wp.Orderid,30)
addmoney = wp.Buymoney
m_oamount = wp.Paymoney
m_ocomment = wp.Comment

Select Case CInt(wp.ErrNumber)
Case 0
	SaveUserInfo m_orderid,addmoney,m_oamount,m_ocomment
Case 3
	ErrMsg = wp.Description
	Founderr = True
Case 4
	ErrMsg = wp.Description
	Founderr = True
Case 5
	ErrMsg = wp.Description
	Founderr = True
Case 6
	ErrMsg = wp.Description
	Founderr = True
Case 8
	ErrMsg = wp.Description
	Founderr = True
End Select
Set wp = Nothing
If Founderr = True Then
	Call Returnerr(ErrMsg)
End If
CloseConn

Function SaveUserInfo(OrderForm,addmoney,realmoney,readme)
	Dim Rs,SQL
	Dim carid,UserName,CardType
	Dim UseDayNum,addPoint,UserGroup
	UserName = MemberName
	carid = Split(OrderForm & "-0", "-")(1)
	carid = CLng(carid)
	Set Rs = Newasp.Execute("SELECT CardID,CardType,UseDayNum,addPoint,UserName FROM NC_Card WHERE IsConsume=2 And CardID=" & carid)
	If Rs.BOF And Rs.EOF Then
		ErrMsg = ErrMsg + "<li>认证信息出错，请不要重复提交数据,此次交易失败！！！</li><li>如有问题，请联系本站管理人员</li>"
		Founderr = True
		Set Rs = Nothing
		Exit Function
	Else
		If Rs("UserName") <> UserName Then
			ErrMsg = ErrMsg + "<li>认证信息出错，本次交易失败！！！</li><li>如有问题，请联系本站管理人员</li>"
			Founderr = True
			Set Rs = Nothing
			Exit Function
		End If
		CardType = Rs("CardType")
		UseDayNum = Rs("UseDayNum")
		addPoint = Rs("addPoint")
	End If
	Set Rs = Nothing
	If Founderr = True Then Exit Function
	
	'--开始更新用户帐号信息
	Set Rs = Server.CreateObject("ADODB.Recordset")
	SQL = "SELECT * FROM NC_User WHERE username='" & UserName & "'"
	Rs.Open SQL,Conn,1,3
	If Rs.BOF And Rs.EOF Then
		FoundErr = True
		ErrMsg = ErrMsg + "<li>会员充值失败！</li>"
		Set Rs = Nothing
		Exit Function
	Else
		Rs("userpoint").value = Rs("userpoint").value + addPoint
		If CardType = 1 Then
			Rs("ExpireTime").value = DateAdd("d",UseDayNum,Now())
			Rs("UserClass").value = 1
		End If
		Rs.update
	End If
	Rs.Close:Set Rs = Nothing
	Newasp.Execute ("UPDATE NC_Card SET IsConsume=1 WHERE CardID=" & carid)
	
	Set Rs = Server.CreateObject("ADODB.Recordset")
	SQL = "SELECT * FROM NC_Account WHERE (AccountID is null)"
	Rs.Open SQL,Conn,1,3
	Rs.addnew
		Rs("payer").Value = Newasp.membername
		Rs("payee").Value = Newasp.SiteName
		Rs("product").Value = Newasp.ChkFormStr(readme)
		Rs("Amount").Value = 1
		Rs("unit").Value = "次"
		Rs("price").Value = CCur(addmoney)
		Rs("TotalPrices").Value = CCur(realmoney)
		Rs("DateAndTime").Value = Now()
		Rs("Accountype").Value = 0
		Rs("Explain").Value = Newasp.ChkFormStr(readme)
		Rs("Reclaim").Value = 0
	Rs.update
	Rs.Close:Set Rs = Nothing
	Call Returnsuc("<li>恭喜您！会员充值完成。</li><li>消费金额："& FormatCurrency(realmoney,2,-1) &" 元</li><li>此次所用手续费："& FormatCurrency(realmoney-addmoney,2,-1) &" 元</li>")
End Function
%>