<!--#include file=../conn.asp-->
<!-- #include file="inc/const.asp" -->
<%Head()
	dim admin_flag
	admin_flag=",15,"
	if not master or instr(","&session("flag")&",",admin_flag)=0 then
		Errmsg=ErrMsg + "<BR><li>本页面为管理员专用，请<a href=../"&LoginUrl&" target=_top>登录</a>后进入。<br><li>您没有管理本页面的权限。"
		Call Ms_error()
	End If
		Main(1)
		Select Case Request("action")
		Case "Vsearch"''读取数据列表
		call Vsearch()
		Case "edit"
		call edit()
		Case "ToVip"''Vip操作
		call ToVip()
		Case "savevipinfo"''保存VIP数据
		call savevipinfo()
		Case "fix"
		call per()
		Case Else
		call VipIndex()''搜索表单
		End Select
		Main(0)
		Footer()

sub main(Str)
if Str=1 then%>
<table width="95%" border="0" cellspacing="1" cellpadding="3"  align=center class="tableBorder">
  <tr> 
    <th height="23" colspan="8" class="tableHeaderText">Vip贵宾管理</th>
  </tr>
  <tr> 
    <td width="16%" height="24" align="right" class="forumrow">说明：</td>
    <td width="84%" height="24" class="forumrow" colspan=7><li>会员申请VIP记录删除此操作是不可逆的；</li>
	<li>VIP会员管理可进行审核、撤消、删除操作；</li>
	<li>VIP会员期限限制，系统检测是否到期；</li>
	<li>点击支付方式进入修改VIP记录信息；</li>
	<li><font color=red>审核成功即对VIP推荐换算结束</font></li></td>
  </tr>
  <tr> 
    <td height="30" colspan=8 class="forumrow">快捷方式：<a href="vip.asp">管理首页</a> 
      | <a href=?action=Vsearch&Vsearch=1>所有贵宾</a> | <a href=?action=Vsearch&Vsearch=2>未 
      审 核</a> | <a href=?action=Vsearch&Vsearch=3>未 付 款</a> | <a href=?action=Vsearch&Vsearch=4>15天到期</a> 
      | <a href=?action=Vsearch&Vsearch=5>7天到期</a> | <a href="?action=Vsearch&Vsearch=6">3天到期</a><br>
      　　　　　<a href="?action=Vsearch&Vsearch=7">铜级贵宾</a> | <a href="?action=Vsearch&Vsearch=8">白银贵宾</a> 
      | <a href="?action=Vsearch&Vsearch=9">黄金贵宾</a> | <a href="?action=Vsearch&Vsearch=10">水晶贵宾</a> 
      | <a href="?action=Vsearch&Vsearch=11">已 过 期</a></td>
  </tr>
<%
	Else
%>
</table>
<p></p>
<%end if
end sub

'Vip管理首页，搜索项
Sub VipIndex()%>
<form action="?action=Vsearch" method=post>
<input type=hidden name="VSearch" value="12"> 
<tr>
<th align=left colspan=8 height=23>高级VIP查询</th>
</tr>
<tr>
<td width=20% class=forumrow>注意事项</td>
<td width=80% class=forumrow colspan=7>在记录很多的情况下搜索条件越多查询越慢，请尽量减少查询条件</td>
</tr>
<tr>
<td width=20% class=forumrow>会员姓名</td>
<td width=80% class=forumrow colspan=7><input name="username" type="text" size="20">&nbsp;<input type=checkbox name="like" value="1" checked>
      完整匹配</td>
</tr>
<tr>
<td width=20% class=forumrow>VIP等级</td>
<td width=80% class=forumrow colspan=7>
<select name="Vipclass">
<option value=""></option>
      <option value="1">铜级VIP</option>
	  <option value="2">白银VIP</option>
	  <option value="3">黄金VIP</option>
	  <option value="4">水晶VIP</option>
    </select></td>
</tr>
<tr>
<td width=20% class=forumrow>支付方式</td>
<td width=80% class=forumrow colspan=7>
<select name="Postclass">
<option value=""></option>
      <option value="1">盛大游戏卡</option>
	  <option value="2">168声讯</option>
	  <option value="3">短信套餐</option>
	  <option value="4">小灵通支付</option>
	  <option value="5">网银支付</option>
	  <option value="6">国外支付</option>
    </select></td>
</tr>
<tr> 
   <td class=forumrow>申请天数 </td>
	<td width=80% class=forumrow colspan=7><input type=radio value=more name="Addtime" checked> &nbsp;多于&nbsp; <input type=radio value=less name="Addtime"> 
            &nbsp;少于&nbsp;&nbsp; <input size=5 name="AddtimeT" type=text>
            天</td>
</tr>
<tr>
<td width=100% class=forumrow align=center colspan=8><input name="submit" type=submit value="   搜  索   "></td>
</tr>
</form>
<%
End Sub

sub Vsearch()''搜索列表
strFileName="vip.asp?VSearch=" & Request("VSearch") & "&action="&Request("action") & "&username="&request("username")&"&Vipclass="&request("Vipclass")&"&Postclass="&request("Postclass")&"&Addtime="&request("Addtime")&"&AddtimeT="&request("AddtimeT")&""
call tumppages()
dim sqlt
sqlt = " Vid,Username,Vipclass,Postclass,Posttime,Payok,StarTime,EndTime,Checked,Addtime "
%>
<tr>
<th colspan=8 align=left height=23>搜索结果</th>
</tr>
<FORM METHOD=POST ACTION="?action=ToVip">
<tr align=center height=23>
<td class=forumRowHighlight width="16%"><B>用户名</B></td>
<td class=forumRowHighlight width="7%"><B>Vip等级</B></td>
<td class=forumRowHighlight width="11%"><B>支付方式</B></td>
<td class=forumRowHighlight width="15%"><B>支付时间</B></td>
<td class=forumRowHighlight width="7%"><B>状态</B></td>
<td class=forumRowHighlight width="15%"><B>申请时间</B></td>
<td class=forumRowHighlight width="22%"><B>登记/终止日期</B></td>
<td class=forumRowHighlight><B>操作</B></td>
</tr>
<%dim sqlstr,Tsqlstr
set rs=server.createobject("adodb.recordset")
Select Case Request("VSearch")
	Case 1
		Sql = "SELECT " & sqlt & " from Ms_Uservip ORDER BY VID DESC"
	Case 2
		Sql = "SELECT " & sqlt & " from Ms_Uservip where Checked=0 ORDER BY VID DESC"
	case 3
		sql="select " & sqlt & " from Ms_Uservip  where Payok=0  order by VID desc"
	case 4
		If IsSqlDataBase=1 Then
		sql="select " & sqlt & " from Ms_Uservip where datediff(day,"&SqlNowString&",EndTime)<=15 and datediff(day,"&SqlNowString&",EndTime)>7 order by VID desc"
		else
		sql="select " & sqlt & " from Ms_Uservip where datediff('d',"&SqlNowString&",EndTime)<=15 and datediff('d',"&SqlNowString&",EndTime)>7 order by VID desc"
		end if
	case 5
		If IsSqlDataBase=1 Then
		sql="select " & sqlt & " from Ms_Uservip where datediff(day,"&SqlNowString&",EndTime)<=7 and datediff(day,"&SqlNowString&",EndTime)>3 order by VID desc"
		else
		sql="select " & sqlt & " from Ms_Uservip where datediff('d',"&SqlNowString&",EndTime)<=7 and datediff('d',"&SqlNowString&",EndTime)>3 order by VID desc"
		end if
	case 6
		If IsSqlDataBase=1 Then
		sql="select " & sqlt & " from Ms_Uservip where datediff(day,"&SqlNowString&",EndTime)<=3 and datediff(day,"&SqlNowString&",EndTime)>0 order by VID desc"
		else
		sql="select " & sqlt & " from Ms_Uservip where datediff('d',"&SqlNowString&",EndTime)<=3 and datediff('d',"&SqlNowString&",EndTime)>0 order by VID desc"
		end if
	case 7
		sql="select " & sqlt & " from Ms_Uservip  where Vipclass=1  order by VID desc"
	case 8
		sql="select " & sqlt & " from Ms_Uservip  where Vipclass=2  order by VID desc"
	case 9
		sql="select " & sqlt & " from Ms_Uservip  where Vipclass=3  order by VID desc"
	case 10
		sql="select " & sqlt & " from Ms_Uservip  where Vipclass=4  order by VID desc"
	case 11
		If IsSqlDataBase=1 Then
		sql="select " & sqlt & " from Ms_Uservip where datediff(day,EndTime,"&SqlNowString&")>=0 order by VID desc"
		else
		sql="select " & sqlt & " from Ms_Uservip where datediff('d',EndTime,"&SqlNowString&")>=0 order by VID desc"
		end if
	case 12
		sqlstr=""''搜索开始
		if request("username")<>"" then
			if request("like")=1 then
			sqlstr=" username='"&request("username")&"'"
			else
			sqlstr=" username like '%"&request("username")&"%'"
			end if
		end if
		if request("Vipclass")<>"" then
			if sqlstr<>"" then
			sqlstr=sqlstr & " and Vipclass="&request("Vipclass")&""
			else
			sqlstr=" Vipclass="&request("Vipclass")&""
			end if
		end if
		if request("Postclass")<>"" then
			if sqlstr<>"" then
			sqlstr=sqlstr & " and Postclass="&request("Postclass")&""
			else
			sqlstr=" Postclass="&request("Postclass")&""
			end if
		end if
		if request("AddtimeT")<>"" then
		   	if request("Addtime")="more" then
				If IsSqlDataBase=1 Then
					Tsqlstr=" datediff(d,Addtime,"&SqlNowString&") >= "&request("AddtimeT")
				Else
					Tsqlstr=" datediff('d',Addtime,"&SqlNowString&") >= "&request("AddtimeT")
				End If
			else
				If IsSqlDataBase=1 Then
					Tsqlstr=" datediff(d,Addtime,"&SqlNowString&") <= "&request("AddtimeT")
				Else
					Tsqlstr=" datediff('d',Addtime,"&SqlNowString&") <= "&request("AddtimeT")
				End If
			end if 	
			if sqlstr="" then 
			  sqlstr=Tsqlstr
			else
			  sqlstr=sqlstr & " and " & Tsqlstr
			end if 
		end if
		if sqlstr<>"" then
		Sql = "SELECT " & sqlt & " FROM [Ms_UserVip] WHERE " & Sqlstr & " ORDER BY VID DESC"
		else
		Response.Write "<tr><td colspan=8 class=forumrow>搜索条件不能都为空。</td></tr>"
		Response.End
		end if			
	case else
		Response.Write "<tr><td colspan=8 class=forumrow>错误的参数。</td></tr>"
		Response.End
	End Select
rs.Open sql,conn,1,1
if not (rs.eof and rs.bof) then
call rspages()
do while not rs.eof and page_count<Cint(MaxPerPage)%>
<tr>
<td class=forumrow><a href="admin_user.asp?action=modify&username=<%=rs("username")%>"><%=rs("username")%></a></td>
<td class=forumrow align="center">
<%if rs(2)=1 then
response.Write("铜级")
elseif rs(2)=2 then
response.Write("白银")
elseif rs(2)=3 then
response.Write("黄金")
else
response.Write("水晶")
end if%></td>
<td class=forumrow align=center>
<%Select Case rs(3)
Case 1
response.Write("<a href=?action=edit&id="&rs(0)&">盛大游戏卡</a>")
Case 2
response.Write("<a href=?action=edit&id="&rs(0)&">168声讯</a>")
Case 3
response.Write("<a href=?action=edit&id="&rs(0)&">短讯套餐</a>")
Case 4
response.Write("<a href=?action=edit&id="&rs(0)&">小灵通支付</a>")
Case 5
response.Write("<a href=?action=edit&id="&rs(0)&">网银支付</a>")
Case 6
response.Write("<a href=?action=edit&id="&rs(0)&">国外用户</a>")
Case else
response.Write("<a href=?action=edit&id="&rs(0)&">其它方式</a>")
end Select%></td>
<td class=forumrow align=center><%=rs(4)%></td>
<td class=forumrow align=center>
<%if rs(8)=1 then
response.write("<font color=red>审核</font>")
else
response.write("<font color=blue>未审</font>")
end if%></td>
<td class=forumrow ><%=rs(9)%></td>
<td class=forumrow align=center>
<%=rs("StarTime")%>/
<%=rs("EndTime")%>
</td>
<td class=forumrow align=center><input type="checkbox" name="id" value="<%=rs("Vid")%>"></td>
</tr>
<%page_count=page_count+1
  rs.movenext
  loop
  end if
  %>
    <tr align="center"> 
      <td height="24" colspan="8" class=forumrow> <%if totalrec>0 then
		  	call showpage(strFileName)
		  end if%></td>
    </tr>
<tr align="center"> 
      <td height="24" colspan="8" class=forumrow><input type="radio" name="Vipaction" value=1>删除记录
	  <input type="radio" name="Vipaction" value=3>VIP操作
	  <select name="VIPset">
	  <option value=1>审核VIP</option>
	  <option value=0>解除VIP</option>
	  </select>
全部选定<input type=checkbox value="on" name="chkall" onclick="CheckAll(this.form)"></td>
    </tr>
	<tr align="center"> 
      <td height="24" colspan="8" class=forumRowHighlight><input type=submit name=submit value="执行操作"  onclick="{if(confirm('确定执行操作吗?')){return true;}return false;}"></td>
    </tr>
</form>
<%end sub

sub ToVip()''VIP操作
dim delid,fixid,Usertj,Vipname,Vipmon,rsv
response.write "<tr><th colspan=8 height=23 align=left>执行结果</th></tr>"
	if request("Vipaction")="" then
		response.write "<tr><td colspan=8 class=forumrow>请指定相关参数。</td></tr>"
		founderr=true
	end if
	delid=replace(request.form("id"),"'","")
	delid=replace(delid,";","")
	delid=replace(delid,"--","")
	delid=replace(delid,")","")
	fixid=replace(delid,",","")
	fixid=Trim(replace(fixid," ",""))
	If Not IsNumeric(fixid) Then
		response.write "<tr><td colspan=8 class=forumrow>请选择相关用户。</td></tr>"
		founderr=true
	End If
	if not founderr then
		if request("Vipaction")=1 then''删除操作
				Conn.Execute("delete from Ms_UserVip where Vid in ("&delid&")")
				response.write "<tr><td colspan=8 class=forumrow>删除VIP记录成功。</td></tr>"
		elseif request("Vipaction")=3 then''审核操作
			Conn.Execute("update Ms_UserVip set Checked="&Cint(request("VIPset"))&" where  Vid in ("&delid&")")''审核VIp表记录
			set rs=Conn.Execute("select Username,StarTime,EndTime,Vipclass,Usertj,Vipmoney from Ms_userVip where Vid in ("&delid&")")
				if not (rs.eof and rs.bof) then
					do while not rs.eof
					Vipname=rs(0)
					Usertj=rs(4)
					if Vipname<>Usertj then''VIP推荐换算
						Vipmon=(rs(5)*Vipgive)''计算抽成率
							set rsv=Conn.Execute("select Vipset from [Ms_user] where Username='"&Usertj&"'")''取出VIP推荐数据
							if not (rsv.eof and rsv.bof) then
								dim Vipsets
								Vipsets=rsv(0)
							end if
							rsv.close
							dim Vipsetin
							Vipsetin=""&(split(Vipsets,"|")(0)+Vipmon)&"|"&split(Vipsets,"|")(1)&""
						Conn.Execute("update [Ms_user] set Vipset='"&Vipsetin&"' where Username='"&Usertj&"'")''
					end if''推荐换算结束
					dim userclass,usertitlepic,Usergid,Usergrid,rsg
					''计算出VIP等级
					set rsg=Conn.Execute("select top 1 UserGroupID from Ms_usergroups where ParentGID=5 order by UserGroupID asc")
						if not (rsg.eof and rsg.bof) then
							Usergid=rsg(0)
						end if
						rsg.close
					Usergrid=(Usergid+(rs(3)-1))
					''获得VIP等级信息
				set rsg=Conn.Execute("select usertitle,grouppic from Ms_usergroups where UserGroupID="&Usergrid&"")
						if not (rsg.eof and rsg.bof) then
							userclass=rsg(0)
							usertitlepic=rsg(1)
						end if
						rsg.close
						Conn.Execute("update [Ms_user] set UserVip="&rs(3)&",Vip_StarTime='"&rs(1)&"',Vip_EndTime='"&rs(2)&"',UserGroupID="&Usergrid&",userclass='"&userclass&"',titlepic='"&usertitlepic&"' where Username='"&Vipname&"'")
					Conn.Execute("update [Ms_usergroups] set Useradd=Useradd+1 where UserGroupID="&Usergrid&"")
					rs.movenext
					loop
				response.write "<tr><td colspan=8 class=forumrow>操作成功。</td></tr>"
				end if
		else
			response.write "<tr><td colspan=8 class=forumrow>错误的参数。</td></tr>"
		end if
	end if
end sub

sub edit()''修改VIP记录
sql="select * from [Ms_UserVip] where Vid="&request("id")&""
		set rs=conn.execute(Sql)
		if not (rs.eof and rs.bof) then
		%>
<FORM METHOD=POST ACTION="?action=savevipinfo">
<tr><th colspan=8 height=23 align=center>VIP记录修改</th></tr>
<tr>
<td width=20% class=forumrow>申请会员</td>
<td width=80% class=forumrow colspan=7><input size=20 name="Username" type=text value="<%=rs("username")%>" readonly></td>
</tr>
<input name="Vid" type=hidden value="<%=request("id")%>">
<tr>
<td width=20% class=forumrow>推荐会员</td>
<td width=80% class=forumrow colspan=7><input size=20 name="Usertj" type=text value="<%=rs("usertj")%>" readonly></td>
</tr>
<tr>
<td width=20% class=forumrow>VIP等级</td>
<td width=80% class=forumrow colspan=7>
<select name="Vipclass">
      <option value="1" <%if rs("Vipclass")=1 then%>selected<%end if%>>铜级VIP</option>
	  <option value="2" <%if rs("Vipclass")=2 then%>selected<%end if%>>白银VIP</option>
	  <option value="3" <%if rs("Vipclass")=3 then%>selected<%end if%>>黄金VIP</option>
	  <option value="4" <%if rs("Vipclass")=4 then%>selected<%end if%>>水晶VIP</option>
    </select></td>
</tr>
<tr>
<td width=20% class=forumrow>预付金额</td>
<td width=80% class=forumrow colspan=7><input size=20 name="Vipmoney" type=text value="<%=rs("Vipmoney")%>"></td>
</tr>
<tr>
<tr>
<td width=20% class=forumrow>支付方式</td>
<td width=80% class=forumrow colspan=7>
<select name="Postclass">
      <option value="1" <%if rs("Postclass")=1 then%>selected<%end if%>>盛大游戏卡</option>
	  <option value="2" <%if rs("Postclass")=2 then%>selected<%end if%>>168声讯</option>
	  <option value="3" <%if rs("Postclass")=3 then%>selected<%end if%>>短信套餐</option>
	  <option value="4" <%if rs("Postclass")=4 then%>selected<%end if%>>小灵通支付</option>
	  <option value="5" <%if rs("Postclass")=5 then%>selected<%end if%>>网银支付</option>
	  <option value="6" <%if rs("Postclass")=6 then%>selected<%end if%>>国外支付</option>
    </select></td>
</tr>
<tr>
<td width=20% class=forumrow>对帐单号</td>
<td width=80% class=forumrow colspan=7><input size=20 name="Postcode" type=text value="<%=rs("Postcode")%>"></td>
</tr>
<tr>
<td width=20% class=forumrow>支付时间</td>
<td width=80% class=forumrow colspan=7><input size=20 name="Posttime" type=text value="<%=rs("Posttime")%>"></td>
</tr>
<tr>
<td width=20% class=forumrow>支付与否</td>
<td width=80% class=forumrow colspan=7><input name="Payok" type="radio" value="1" <%if rs("Payok")=1 then%>checked<%end if%>>是<input name="Payok" type="radio" value="0" <%if rs("Payok")=0 then%>checked<%end if%>>否</td>
</tr>
<tr>
<td width=20% class=forumrow>开始时间</td>
<td width=80% class=forumrow colspan=7><input size=20 name="StarTime" type=text value="<%=rs("StarTime")%>"></td>
</tr>
<tr>
<td width=20% class=forumrow>结束时间</td>
<td width=80% class=forumrow colspan=7><input size=20 name="EndTime" type=text value="<%=rs("EndTime")%>"></td>
</tr>
<tr>
<td width=100% class=forumrow align=center colspan=8><input name="submit" type=submit value="   更  新   "></td>
</tr>
</FORM>
<%end if
rs.close
end sub

sub savevipinfo()''保存VIp数据
	If Request.Form("StarTime")="" and isdate(Request.Form("StarTime"))=false Then
		Response.Write "<tr><td colspan=8 class=forumrow>开始时间不能为空</td></tr>"
		Founderr = True
	End If
	If Request.Form("EndTime")="" and isdate(Request.Form("EndTime"))=false Then
		Response.Write "<tr><td colspan=8 class=forumrow>结束时间不能为空</td></tr>"
		Founderr = True
	End If
	If Request.Form("Posttime")<>"" and isdate(Request.Form("Posttime"))=false Then
		Response.Write "<tr><td colspan=8 class=forumrow>支付时间不能为空</td></tr>"
		Founderr = True
	End If
	if not founderr then
		Set rs= Server.CreateObject("ADODB.Recordset")
		sql="select * from [Ms_UserVip] where Vid="&request("Vid")
		rs.open sql,conn,1,3
			if not (rs.eof and rs.bof) then
			rs("Postclass")=request.form("Postclass")
			if request.form("Vipmoney")<>"" then
			rs("Vipmoney")=request.form("Vipmoney")
			end if
			rs("Vipclass")=request.form("Vipclass")
			if request.form("Postcode")<>"" then
			rs("Postcode")=request.form("Postcode")
			end if
			if request.form("Posttime")<>"" then
			rs("Posttime")=Cdate(request.form("Posttime"))
			end if
			rs("Payok")=request.form("Payok")
			if request.form("StarTime")<>"" then
			rs("StarTime")=Cdate(request.form("StarTime"))
			end if
			if request.form("EndTime")<>"" then
			rs("EndTime")=Cdate(request.form("EndTime"))
			end if
			rs.update()
			rs.close
			end if
			Ms_suc("更新数据成功。")
	else
		response.write "<tr><td colspan=8 class=forumrow>更新失败。</td></tr>"
	end if
end sub%>