<%@LANGUAGE="VBSCRIPT" CODEPAGE="936"%>
<!--#include file="UserSession.asp" -->
<!--#include file="../tgzcm.Scnn.asp" -->
<%
Call Chkhttp()
Dim Product,pid,sid,submit,shouji,dizhi,phow,pjf,Pzf
submit=Request.QueryString("submit")
Product=NoSqlHack(Request.QueryString("Product"))'奖品名称
pid=PE_CLng(Request.Form("pid"))'奖品ID
sid=Clng(PE_CLng(Request.Form("sid")))'剩余量
shouji=NoSqlHack(Request.Form("shouji"))'联系QQ
dizhi=Server.HTMLEncode(Request.Form("dizhi"))'用户支付宝
pjf=Clng(NoSqlHack(Request.Form("pjf")))'奖品所要积分
phow=Clng(NoSqlHack(Request.Form("phow")))'兑换数量

If sid<1 then
Call tgzcm_err_c("奖品已经兑换完毕,请选择其它奖品！！！")
response.End()
Elseif phow>sid Then
Call tgzcm_err_c("剩余奖品数量不够你的兑换数量！！！"&phow&sid&"")
response.End()
End IF		 

If len(submit)>10 then
    Set rs = Server.CreateObject("adodb.recordset")
    rs.Open"Select * from tgzcm_user where uid="&Uid&"",Conn,1,3
    If Not(rs.Eof And rs.Bof) then
	     If Product="" or Not isNumeric(shouji) or dizhi="" or Not isNumeric(phow) or pjf<0 or pid<0 Then
		 Call tgzcm_err_c("请认真填写兑换信息！！！")
         response.End()
		 Else
		 Pzf=phow*pjf '计算所要总分
		   If ujf<Clng(Pzf) Then
		     Call tgzcm_err_c("积分不够,不能兑换！！！")
             response.End()
		   Else
		   rs("ujf")=ujf-Pzf
		   End If
		 End If
	  rs.update
	  rs.Close
	  Call OrderAdd()'执行处理
	  Call tgzcm_err_b("兑换成功！！！","../product.asp?pid="&pid&"")
	  response.End()
    Else
      Call tgzcm_err_c("非法操作r！！！")
      response.End()
    End If
Else
Call tgzcm_err_c("非法操作！！！")
response.End()
End if

Sub OrderAdd()
  Set nrs=Conn.Execute("Select uqq,ujf From tgzcm_user Where uid="&Uid&"")
   If Not(nrs.eof and nrs.bof) Then
     Conn.Execute("Insert into tgzcm_order (opid,ouid,oname,ohow,oadd,otel,oqq) Values('"&pid&"','"&Uid&"','"&Product&"','"&phow&"','"&dizhi&"','"&shouji&"','"&nrs("uqq")&"')")
	 Conn.Execute("update tgzcm_product Set ps=ps-"&phow&" Where pid="&pid&"")
	 Session("Ujf")=Clng(nrs("ujf"))
   End If
  nrs.Close
  Call CloseConn
End Sub
%>
