<!--#include file="conn.asp"-->
<!--#include file="baofu_md5.asp"-->
<!--#include file="../include/Lebi_config.asp"-->
<!--#include file="../union/config.asp"-->
<%
  MARKReturn = "~|~"
  '商户充值流水号
  TransID=Request("TransID")
  
  '支付结果
  Result=Request("Result")
  
  '支付结果描述
  resultDesc=Request("resultDesc")  
  
  '成功金额
  factMoney=Request("factMoney")
  
  '订单附加消息
  additionalInfo=Request("additionalInfo")  
If InStr(additionalInfo,"|") > 0 Then 
	LangTxt = Split(additionalInfo,"|")(0)
	user_id = Split(additionalInfo,"|")(1)
Else
	user_id = ""
End If 
  '交易成功时间
  SuccTime=Request("SuccTime") 
  
  'md5签名
  Md5Sign=Request("Md5Sign")   
  
  '通知方式
  NoticeType=Request("NoticeType")   
  
  '生成加密信息
  Md5Data="MemberID=" & Trim(Pay_baofu(1)) & MARKReturn & "TerminalID=" & Trim(Pay_baofu(12)) & MARKReturn & "TransID=" & TransID & MARKReturn & "Result=" & Result & MARKReturn & "ResultDesc=" & ResultDesc & MARKReturn & "FactMoney=" & FactMoney & MARKReturn & "AdditionalInfo=" & AdditionalInfo & MARKReturn & "SuccTime=" & SuccTime & MARKReturn & "Md5Sign=" & Trim(Pay_baofu(2))
  
  '进行信息校验
  if Md5Sign<>Baofu_MD5(Md5Data) then
    response.Write("校验信息不符")
    response.End
  End if
  
  '实际面额转到以元为单位
  factMoney=factMoney/100
  '返回接口信息，表示已收到  
  response.Write("ok")
  
  '支付失败
  if Result="0" then
     response.redirect Eshop_url & LangTxt
     response.End
  end if  
  
  '支付成功
  if Result="1" Then
    factMoney=factMoney
	If user_id = "" Then 
			conn.execute("UPDATE [Lebi_pay_log] SET l_state=1 where l_ordernum='"&TransID&"'")
			Set rs = server.CreateObject("adodb.recordset")
			rs.open "select orderzt,paymenttype,paidmoney,id from [Lebi_orders] where order_number='"& TransID &"'",conn,1,3
			If Not rs.eof Then
					orderzt = orderzt & rs(0) &",2,"
					rs(0) = orderzt
					rs(1) = Pay_baofu(8)
					rs(2) = rs(2) + factMoney
					rs.update 
					conn.execute("insert into [Lebi_Orders_Paylog](p_price,p_type,p_content,p_time,oid)values("& factMoney &",1,'"& Pay_baofu(8) &"',"& sqlnowstring &","& rs(3) &")")
					If Config_Lebi_Eshop(23) = 1 Then '付款后扣除库存 by 56770.kingdge 2012-05-14
						Set rsbasket = conn.execute("select cpid,basket_count,spvalue from [lebi_basket] where order_number = "& rs(3) &"")
						Do While Not rsbasket.eof 
							conn.execute("update [Lebi_product] set buys = buys + "& rsbasket("basket_count")&",kucun = kucun - "& rsbasket("basket_count") &",html = 0 where id = " & rsbasket("cpid") &"")
							conn.execute("update [Lebi_Product_Stock] set p_buys = p_buys + "& rsbasket("basket_count") &",p_stock = p_stock - "& rsbasket("basket_count") &" where p_id = " & rsbasket("cpid") &" and s_value"& LangTxt &" = '"& rsbasket("spvalue") &"'")
						rsbasket.movenext 
						Loop
						rsbasket.close : Set rsbasket = Nothing 
					End If 
			End If
			rs.close : Set rs = Nothing
			response.redirect Eshop_url & LangTxt
	Else
			rem 增加防刷新 2006-7-25 by 56770.kingdge
			set Rs = conn.execute("select * from [Lebi_money_log] where m_order_num='"& TransID &"' and m_zt=0")
			If not rs.eof Then
					conn.execute("UPDATE [Lebi_money_log] SET m_zt=1 where m_order_num='"& TransID &"'")
					conn.execute("UPDATE [Lebi_buy] SET orderzt=1 where order_num='"& TransID &"'")
					conn.execute("UPDATE [Lebi_User] SET usermoney = usermoney + "& factMoney &" where user_id = '"& rs("m_user_id") &"'")
			End If
			rs.close : Set rs = Nothing
			response.redirect Eshop_url & LangTxt &"user/pay.asp?action=update"
	End If 
  end if  

%>