<!--#include file="../p_inc/Include_func.asp"-->
<!--#include file="../p_inc/openconn.asp"-->
<!--#include file="config.asp"-->
<!--#include file="function_u.asp"-->

<%
IF Not ChkPost() Then
	response.Redirect "../"
	response.End()
End IF
%>
<%
action=Request("action")

IF action="Pg310_save" Then
	Call Pg310_save() 'Pg310彩票保存	
ElseIF action="login" Then
	Call Loginf() '开始登陆		
End IF

Sub Pg310_save()
	oSMONEY=Trim(Request("SMONEY")) '投注
	oPid=Bint(Replace(Request("pid"),"'",""))
	oSMONEYSUM=Bint(Replace(Request("SMONEYSUM"),"'","")) '投注总金额
	oArrid=""
	oArrPv=""
	IF Request.Cookies(G_u_Cookies)("soojs_id")="" Then
		response.Write "<script>"
		response.Write "window.location='../Members/login.asp?p="&server.URLEncode("您还未登陆")&"';"
		response.Write "</script>"		
	End IF
	
	Set oRs=server.CreateObject(G_Rs)
	oRs.open "Select * From soojs_un Where Id="&Request.Cookies(G_u_Cookies)("soojs_id"),Conn,1,1
	IF Not oRs.Eof Then	
		zsoojs_jifen=Bint(oRs("soojs_jifen")) 
	End IF
	oRs.close
	IF Clng(oSMONEYSUM)>Clng(zsoojs_jifen) Then
		response.Write "<script>"
		response.Write "alert('积分不足');window.location='../Caipiao/Pg310.asp';"
		response.Write "</script>"		
		Response.End()
	End IF
	
	
	Set oRs4=Conn.Execute("Select * From qingtiandy_caipiao310 Where Id="&oPid&"")
	IF Not oRs4.Eof Then
		oPtimeEnd=oRs4("PtimeEnd")
	Else
		response.Write "<script>"
		response.Write "alert('无效投注');window.location='../Caipiao/Pg310.asp';"
		response.Write "</script>"		
		Response.End()		
	End IF
	IF DateDiff("s",oPtimeEnd,Now())>0 Then
		response.Write "<script>"
		response.Write "alert('已经关闭投注');window.location='../Caipiao/Pg310.asp';"
		response.Write "</script>"		
		Response.End()		
	End IF
	
	Set oRs3=Conn.Execute("Select * From qingtiandy_caipiao310_list Where Pid="&oPid&" order by id asc")
	IF Not oRs3.Eof Then
		Do While Not oRs3.Eof
			oid=oRs3("id")
			oPid=oRs3("Pid")
			oPtitle=oRs3("Ptitle")
			oPvalue=oRs3("Pvalue")
			oPv=oRs3("Pv")	
			oArrid=oArrid&oid&","
			oArrPv=oArrPv&oPv&","
			oRs3.MoveNext
		Loop
	End IF
	
	'======开始组合数组==========
	oSMONEY_a=Split(oSMONEY,",")
	oArrid_a=Split(oArrid,",")
	oArrPv_a=Split(oArrPv,",")
	oSum_x=0
	oTrue=False
	IF Ubound(oSMONEY_a)+1<>Ubound(oArrid_a) Then
		Response.Write "参数错误"
		Response.End()
	End IF
	For i=0 To Ubound(oSMONEY_a)
		oSMONEY_a_1=Trim(oSMONEY_a(i))
		oArrid_a_1=Trim(oArrid_a(i))
		oArrPv_a_1=Trim(oArrPv_a(i))
		IF oSMONEY_a_1<>"" Then
			oTrue=True
			kk_pid=oPid
			kk_pdid=oArrid_a_1
			kk_uid=Bint(Request.Cookies(G_u_Cookies)("soojs_id"))
			kk_kNumb=oSMONEY_a_1
			kk_kSum=oArrPv_a_1*kk_kNumb
			oSum_x=oSum_x+kk_kSum
			Set oRsu=Server.CreateObject(G_RS)
			oRsu.open "Select * From qingtiandy_caipiao310_list_user Where 1<>1",Conn,1,3
			oRsu.AddNew()
			oRsu("pid")=kk_pid
			oRsu("pdid")=kk_pdid
			oRsu("uid")=kk_uid
			oRsu("kNumb")=kk_kNumb
			oRsu("kSum")=kk_kSum
			oRsu("ks")=0
			oRsu("kstatus")=0
			oRsu.Update()
			oRsu.close()
		End IF
	Next
	IF oTrue Then
		Get_qingtiandy_jifen_ip Request.Cookies(G_u_Cookies)("soojs_id"),9,-oSMONEYSUM
		conn.Execute("Update qingtiandy_caipiao310 set Plirun=Plirun+"&oSMONEYSUM&",Ptotal=Ptotal+"&oSMONEYSUM&",Ptotalnumb=Ptotalnumb+1 Where id="&oPid&"")
		
	End IF
	response.Write "<script>"
	response.Write "alert('投注成功');window.location='../Caipiao/Pg310.asp?id="&oPid&"';"
	response.Write "</script>"		
End Sub
%>