<!-- #include file="include/config.asp" -->
<!-- #include file="INCLUDE/skin.asp" -->
<!-- #include file="include/conn.asp" -->
<%
' 请修改以下参数
dim MinJiang,JiaGe,AMaxJiang
index_url="games"
tit_fir=format_menu(index_url)
' 奖池最小奖金数量，低于此数量自动补足(需要新一期才可生效)
MinJiang	=	1000
' 单注价格
JiaGe		=	5
' 单注最高奖金
AMaxJiang	=	1000

' 以下无需修改
sub KiaJiang(ID)
	dim ZongJiTouZhu,ZongJinE,ZhongJiangHaoMa,ZhongJiangZhuShu,JiangJin,Content,ShengY
	dim ZhongJiangUser  '中奖名单   
	' 获得总金额
	rs.open "select * from CP_Record where ID="&id,conncaipiao,1,3
	ZongJinE=rs("YuE")
	ZhongJiangHaoMa=rs("Number")
	rs.close
	rs.open "select count(id) from CP_User where Qi="&ID,conncaipiao,1,3
	ZongJiTouZhu=rs(0)
	rs.close
	ZongJinE=ZongJinE+ZongJiTouZhu*5

	' 获得中奖注数
	rs.open "select count(ID) from CP_User where Qi="&id&" and HaoMa='"&ZhongJiangHaoMa&"'",conncaipiao,1,3    
	ZhongJiangZhuShu=rs(0)  
	' 每注奖金
	if ZhongJiangZhuShu>0 then
		JiangJin=Int(ZongJinE/ZhongJiangZhuShu)
	else
		JiangJin=0
	End if
	if JiangJin>AMaxJiang then
		JiangJin=AMaxJiang
	end if
	ShengY=ZongJinE-(JiangJin*ZhongJiangZhuShu)
	rs.close
	rs.open "select * from CP_Record where ID="&id,conncaipiao,1,3
	rs("YuE")=ShengY
	rs.update
	rs.close
	rs.open "select UserName,user from CP_User where Qi="&id&" and HaoMa='"&ZhongJiangHaoMa&"'",conncaipiao,1,3
	if rs.eof and rs.bof then
		ZhongJiangUser="本期无人中奖"
	else
		ZhongJiangUser="本期中奖者："
		do while not rs.eof
			conn.execute("Update user_data set emoney=emoney+"&JiangJin&" where Userid="&rs(1))
			ZhongJiangUser=ZhongJiangUser&rs(0)&"  "
			rs.movenext
		loop
	end if
	rs.close
	
	dim rs2
	set rs2=server.createobject("adodb.recordset")
	rs2.open "select username from cp_user where Qi="&id&" group by username",conncaipiao,1,3
	rs.open "select * from user_mail where id is null",conn,3,3
	do while not rs2.eof
		rs.addnew
		rs("Send_u")="彩票中心"
		rs("accept_u")=rs2("UserName")
		rs("topic")="第"&ID&"期彩票开奖公告"
		word="本期中奖号码为"& ZhongJiangHaoMa &"。总计投注"&ZongJiTouZhu&"注，奖池总额"&ZongJinE&"元。其中中奖"& ZhongJiangZhuShu &"注,每注得奖金"& JiangJin &"元。"&chr(13)&"本期剩余奖金"&ShengY&"元滚入下期奖池。"
		word=word&" "&ZhongJiangUser
		rs("word")=word
		rs("isread")=0
		rs("types")=1
		rs("tim")=now()
		rs.update
		rs2.movenext
	loop
	rs.close
	rs2.close
	set rs2=nothing
	
	'写中奖情况表  冰语修改制作
	rs.open "select * from qingkuang where id is null",conncaipiao,3,3
	rs.addnew
	rs("ZhongJiangHaoMa")=ZhongJiangHaoMa
	rs("ZongJiTouZhu")=ZongJiTouZhu
	rs("ZongJiTouZhujine")=ZongJiTouZhu*JiaGe
	rs("ZongJinE")=ZongJinE
	rs("ZhongJiangZhuShu")=ZhongJiangZhuShu
	rs("JiangJin")=JiangJin
	rs("ShengY")=ShengY
	rs.update
	rs.close	
end sub

sub savepiao
	dim cp1,cp2,cp3,cp4
	cp1=request("CP1")
	cp2=request("CP2")
	cp3=request("CP3")
	cp4=request("CP4")
	if cp1="" or cp2="" or cp3="" or cp4="" then
		ts="你至少有一个号码没有购买，请重新选择。"
	end if
	if usermoney<JiaGe then
		ts="对不起，您的社区货币不够购买一注。"
	end if
	if cp1<0 or cp1>9 then
		ts="你至少有一个号码没有购买，请重新选择。"
	end if
	if cp2<0 or cp2>9 then
		ts="你至少有一个号码没有购买，请重新选择。"
	end if
	if cp3<0 or cp3>9 then
		ts="你至少有一个号码没有购买，请重新选择。"
	end if
	if cp4<0 or cp4>9 then
		ts="你至少有一个号码没有购买，请重新选择。"
	end if
	if ts="" then
		rs.open "select * from CP_User where ID is null",conncaipiao,1,3
		rs.addnew
		rs("Username")=username
		rs("User")=UserID
		rs("Haoma")=cp1&cp2&cp3&cp4
		rs("Qi")=CP_Qi
		rs.update
		rs.close
		conn.execute("update user_data set emoney=emoney-"&JiaGe&" where id="&userid)
		ts=cp1&cp2&cp3&cp4&"购买成功，您可以继续选择购买。"
	end if
end sub


tit="彩票中心"
call web_head(1,0,2,0,0)
set rs=server.createobject("adodb.recordset")
dim CP_Qi,CP_MaxJiang,CP_TouZhuRenShu,CP_TouZhuE,CP_OpenDateTime,UserMoney,ts,username,userid,word
sql="select * from user_data where username='"&login_username&"'"
set rs=conn.execute(sql)
usermoney=rs("emoney")
username=rs("username")
userid=rs("id")
rs.close

dim rs3,rs1
set rs3=server.createobject("adodb.recordset")
rs3.open "select Top 1 * From CP_Record where OpenDateTime>=#"&now&"# order by id desc",conncaipiao,1,3
if rs3.eof or rs3.bof then
	set rs1=server.createobject("adodb.recordset")
	rs1.open "select Top 1 * From CP_Record order by id desc",conncaipiao,1,3
	if rs1.eof or rs1.bof then
		CP_MaxJiang=500
	Else
		call KiaJiang(RS1("ID"))
		CP_MaxJiang=RS1("YuE")
	End if
	if CP_MaxJiang<MinJiang then
		CP_MaxJiang=CP_MaxJiang+MinJiang
	end if
	Rs1.close
	set rs1=nothing
	rs3.addnew
	Randomize
	rs3("Number")=int((8999*rnd)+1000)
	rs3("OpenDateTime")=date()+1&" 20:00:00"
	rs3("YuE")=CP_MaxJiang
	rs3.update
else
	set rs1=server.createobject("adodb.recordset")
	rs1.open "select Top 1 * From CP_user order by id desc",conncaipiao,1,3
	if not( rs1.bof and rs1.eof )then
		if rs1("Qi")<rs3("ID") then
			Randomize
			rs3("Number")=int((8999*rnd)+1000)
			rs3("OpenDateTime")=date()+1&" 20:00:00"
			rs3.update
		end if 
	end if			
end if
CP_Qi=rs3("id")
CP_MaxJiang=500
CP_OpenDateTime=rs3("OpenDateTime")
CP_MaxJiang=rs3("YuE")
rs3.close
set rs3=nothing
if request("job")<>"" then 
	call savepiao
	response.Redirect "caipiao.asp"
end if
CP_TouZhuRenShu=0
CP_TouZhuE=0

rs.open "select count(id) From CP_User Where Qi="&CP_Qi,conncaipiao,1,3
CP_TouZhuRenShu=rs(0)
rs.close
CP_MaxJiang=CP_MaxJiang+CP_TouZhuRenShu*5
CP_TouZhuE=CP_TouZhuRenShu*5

%>
<table align=center cellspacing=1 cellpadding="3" border=0 class=tf>
<tr bgcolor=<% response.write web_var(web_color,4) %> class=td><th><%=username%>,欢迎光临彩票中心</th></tr>
<tr><td class=tablebody2>
<br>
<div align="center">
  <center>
          <table cellpadding=5 cellspacing=1 style="word-break:break-all; border-collapse:collapse" border="1" bordercolor=<%response.write web_var(web_color,3)%> width="98%">
            <tr>
<TD width="76%" vAlign=top >
　<%=ts%><br>
　您现在就可以购买第 <font color=#FF0000><b><%=CP_Qi%></b></font> 期彩票，本期总共累计奖额 <font color=#FF0000><b><%=CP_MaxJiang%></b></font> 元，单注最高奖额 <font color=#FF0000><b><%=AMaxJiang%></b></font> 元。<br>
　本期共有投注 <font color=#FF0000><b><%=CP_TouZhuRenShu%></b></font> 注，总投注额 <font color=#FF0000><b><%=CP_TouZhuE%></b></font> 元，于 <font color=#FF0000><b><%=CP_OpenDateTime%></b></font> 开奖。<br>
</td>
<td width="24%" rowspan=2 vAlign=top class=tablebody1>
<B>历史投注:</b><br>
<%
	rs.open "select top 10 * from cp_user where user="&userid&" order by qi desc",conncaipiao,1,3
	i=0
	do while ( not rs.eof ) and i<10 
%>
第<%=rs("Qi")%>期:<%=rs("Haoma")%><br>
<%
	 	rs.movenext
		i=i+1
	loop
	rs.close
%>
</td>
</tr>
<tr>
<TD vAlign=top class=tablebody1 align="center">
每注彩票 <font color=red><%=JiaGe%></font> 元，您现在共有 <font color=red><%=UserMoney%></font> 元。<br>您需要购买什么号码？
<br><br>
<form action="CaiPiao.asp" method=Get name=BuyCaiPiao>
<input type="hidden" name="job" value="save">
<select name="CP1">
  <option selected>1</option>
  <option>2</option>
  <option>3</option>
  <option>4</option>
  <option>5</option>
  <option>6</option>
  <option>7</option>
  <option>8</option>
  <option>9</option>
  <option>0</option>
</select>
<select name="CP2">
  <option selected>1</option>
  <option>2</option>
  <option>3</option>
  <option>4</option>
  <option>5</option>
  <option>6</option>
  <option>7</option>
  <option>8</option>
  <option>9</option>
  <option>0</option>
</select>
<select name="CP3">
  <option selected>1</option>
  <option>2</option>
  <option>3</option>
  <option>4</option>
  <option>5</option>
  <option>6</option>
  <option>7</option>
  <option>8</option>
  <option>9</option>
  <option>0</option>
</select>
<select name="CP4">
  <option selected>1</option>
  <option>2</option>
  <option>3</option>
  <option>4</option>
  <option>5</option>
  <option>6</option>
  <option>7</option>
  <option>8</option>
  <option>9</option>
  <option>0</option>
</select>
<input type=submit value="投注">
<input type="button" value="机选" onclick="SelRandom()">
<script>
function SelRandom() {
	BuyCaiPiao.CP1.options[Math.random()*10].selected=true;
	BuyCaiPiao.CP2.options[Math.random()*10].selected=true;
	BuyCaiPiao.CP3.options[Math.random()*10].selected=true;
	BuyCaiPiao.CP4.options[Math.random()*10].selected=true;

}
SelRandom()
</script>
</form>
</td></tr>
</table>
  </center>
</div>
<br>
</td></tr></table>
<br>
<div align="center">
  <center>
<table cellspacing=1 cellpadding="3" border=0 class=tf>
<tr bgcolor=<% response.write web_var(web_color,4) %> class=td><th bordercolor="#3D62A0">彩票中心---本期投注情况</th></tr>
<tr><td class=tablebody2 bordercolor="#3D62A0">
<br>
	<div align="center">
      <center>
	<table cellpadding=5 cellspacing=0 class=tableborder1 style="word-break:break-all; border-collapse:collapse" border="1" bordercolor=<%response.write web_var(web_color,3)%> width="98%">
		<tr>
			<TD class=tablebody2 align=center height=20>用户名</td>
			<TD class=tablebody2 align=center>投注数</td>
			<TD class=tablebody2 align=center>投注金额</td>  
		</tr>
<%
	rs.open "SELECT Count(UserName) AS UserNameOfCount,UserName FROM CP_User where qi="&CP_Qi&" GROUP BY UserName ORDER BY Count(UserName) DESC ",conncaipiao,1,3
	if rs.eof and rs.bof then
	%>
		<tr><td colspan=3 class=tablebody1 align=center height=20>本期还没有人投注</td></tr>
	<%
	else
		do while not rs.eof
	%>		
			<tr>
				<TD class=tablebody1 align=center height=20><%=rs(1)%></td>
				<TD class=tablebody1 align=center><%=rs(0)%>　</td>
				<TD class=tablebody1 align=center><%=rs(0)*JiaGe%>　</td>
			</tr>
	<%
			rs.movenext
		loop
	end if
	rs.close
%>			
	</table>
      </center>
</div>
<br>
</td></tr></table>
  </center>
</div>
<br>
<table align=center cellspacing=1 cellpadding="3" border=0 class=tf>
<tr bgcolor=<% response.write web_var(web_color,4) %> class=td><th>彩票中心---最近10期中奖情况</th></tr>
<tr><td class=tablebody2>
<br>
	<div align="center">
      <center>
	<table cellpadding=5 cellspacing=0 class=tableborder1 style="word-break:break-all; border-collapse:collapse" width="98%" border="1" bordercolor=<%response.write web_var(web_color,3)%>>
		<tr>
			<TD class=tablebody2 align=center height=20>期  数</td>
			<TD class=tablebody2 align=center>中奖号码</td>
			<TD class=tablebody2 align=center>总投注数</td>
			<TD class=tablebody2 align=center>总投注金额</td>			
			<TD class=tablebody2 align=center>奖池总金额</td>  
			<TD class=tablebody2 align=center>中奖注数</td> 
			<TD class=tablebody2 align=center>单注奖金</td>
			<TD class=tablebody2 align=center>奖池剩余奖金</td> 			
		</tr>
<%
    set	rs=conncaipiao.execute("SELECT top 10 id,ZhongJiangHaoMa,ZongJiTouZhu,ZongJiTouZhujine,ZongJinE,ZhongJiangZhuShu,JiangJin,ShengY FROM qingkuang order by id DESC")
	if rs.eof and rs.bof then
	%>
		<tr><td colspan=3 class=tablebody1 align=center height=20>还没有历史中奖情况</td></tr>
	<%
	else
		do while not rs.eof
	%>		
			<tr>
			<TD class=tablebody1 align=center height=20><%=rs(0)%></td>
			<TD class=tablebody1 align=center><%=rs(1)%>　</td> 
			<TD class=tablebody1 align=center><%=rs(2)%>　</td>  
			<TD class=tablebody1 align=center><%=rs(3)%>　</td> 
			<TD class=tablebody1 align=center><%=rs(4)%>　</td> 
			<TD class=tablebody1 align=center><%=rs(5)%>　</td>
			<TD class=tablebody1 align=center><%=rs(6)%>　</td> 
			<TD class=tablebody1 align=center><%=rs(7)%>　</td> 
			</tr>
	<%
			rs.movenext
		loop
	end if
	rs.close
%>			
	</table>
      </center>
</div>
<br>
</td></tr></table>
<%
call web_end(0)
%>