<%@LANGUAGE="VBSCRIPT" CODEPAGE="936"%>
<!--#include file="UserSession.asp" -->
<!--#include file="UserConn.asp" -->
<%
Call Chkhttp()
Dim Product,pid,sid,submit,shouji,dizhi,phow,pjf,Pzf
submit=Request.QueryString("submit")
Product=NoSqlHack(Request.QueryString("Product"))'奖品名称
pid=QvodCms_CLng(Request.Form("pid"))'奖品ID
sid=QvodCms_CLng(Request.Form("sid"))'剩余量
shouji=NoSqlHack(Request.Form("shouji"))'联系手机
dizhi=Server.HTMLEncode(Request.Form("dizhi"))'用户地址
pjf=QvodCms_CLng(NoSqlHack(Request.Form("pjf")))'奖品所要积分
phow=QvodCms_CLng(NoSqlHack(Request.Form("phow")))'对换数量

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

If len(submit)>10 then
    Set rs = Server.CreateObject("adodb.recordset")
    rs.Open"Select * from qvodcms_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 QvodCms_Err("请认真填写兑换信息！！！")
         response.End()
		 Else
		 Pzf=phow*pjf '计算所要总分
		   If rs("ujf")<Pzf Then
		     Call QvodCms_Err("积分不够,不能兑换！！！")
             response.End()
		   Else
		   rs("ujf")=ujf-Pzf
		   End If
		 End If
		 'Response.End()
	  rs.update
	  rs.Close
	  Call OrderAdd()'执行处理
	  Call QvodCms_Err_Url("兑换成功！！！","../prod.asp?pid="&pid&"")
	  response.End()
    Else
      Call QvodCms_Err("非法操作r！！！")
      response.End()
    End If
Else
Call QvodCms_Err("非法操作！！！")
response.End()
End if

Sub OrderAdd()
  Set nrs=Conn.Execute("Select * From qvodcms_user Where uid="&Uid&"")
   If Not(nrs.eof and nrs.bof) Then
     Conn.Execute("Insert into qvodcms_order (opid,ouid,oname,ohow,oadd,otel,oqq) Values('"&pid&"','"&Uid&"','"&Product&"','"&phow&"','"&dizhi&"','"&shouji&"','"&nrs("uqq")&"')")
	 Conn.Execute("update qvodcms_product Set ps=ps-"&phow&" Where pid="&pid&"")
	 	Response.Cookies("qvodcms")("UserName") =Trim(nrs("uname"))
		Response.Cookies("qvodcms")("Uid") =QvodCms_Clng(nrs("Uid"))
        Response.Cookies("qvodcms")("Ujf") =QvodCms_Clng(nrs("ujf"))
        Response.Cookies("qvodcms")("Ulc") =Trim(nrs("ulc"))
        Response.Cookies("qvodcms")("Uvip") =nrs("uvip")
		Response.Cookies("qvodcms")("UPic") =QvodCms_Clng(nrs("upic"))
		Response.Cookies("qvodcms")("Utime") =Formatdatetime(nrs("utime"),2)
		Response.Cookies("qvodcms").Expires=dateadd("n",30,now())
   End If
  nrs.Close:Set nrs=Nothing
End Sub
Call CloseConn()
%>
