<%@LANGUAGE="VBSCRIPT" CODEPAGE="936"%>
<%option explicit%>
<!--#include file="../Conn.asp"-->
<!--#include file="../HSK_Cls/HSK.CommonCls.asp"-->
<!--#include file="../HSK_Cls/HSK.AdministratorCls.asp"-->
<!--#include file="Include/Session.asp"-->
<%

Dim KSCls
Set KSCls = New Admin_MaiMaiUser
KSCls.HSK_Run()
Set KSCls = Nothing

Class Admin_MaiMaiUser
        Private KS,Param,KSCls
		Private Action,i,strClass,sFileName,RS,SQL,maxperpage,CurrentPage,totalPut,TotalPageNum
        Private Sub Class_Initialize()
		  Set KS=New PublicCls
		  Set KSCls=New ManageCls
  		  maxperpage = 20 '###每页显示数
		End Sub
        Private Sub Class_Terminate()
		 Call CloseConn()
		 Set KS=Nothing
		End Sub

		Public Sub HSK_Run()
		 With KS
					If Not KS.ReturnPowerResult(0, "KSMS20000") Then          '检查是权限
					 Call KS.ReturnErr(1, "")
					 Response.End()
					 End If
              .echo "<!DOCTYPE html PUBLIC ""-//W3C//DTD XHTML 1.0 Strict//EN"" ""http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"">" & vbcrlf
			  .echo "<html xmlns=""http://www.w3.org/1999/xhtml"">"
			  .echo"<head>"
			  .echo"<meta http-equiv=""Content-Type"" content=""text/html; charset=gb2312"">"
			  .echo"<link href=""Include/Admin_Style.CSS"" rel=""stylesheet"" type=""text/css"">"
			  .echo "<script src=""../HSK_JS/common.js"" language=""JavaScript""></script>"
			  .echo "<script src=""../HSK_JS/jquery.js"" language=""JavaScript""></script>"
			  .echo "<script type=""text/javascript"" src=""../editor/ckeditor.js"" mce_src=""../editor/ckeditor.js""></script>"
			  .echo"</head>"
			  .echo"<body leftmargin=""0"" topmargin=""0"" marginwidth=""0"" marginheight=""0"">"
			  .echo "<ul id='menu_top'>"
			  .echo "<li style='margin-left:30px;margin-top:10px'><strong>查看方式:</strong><a href=""MaiMaiManage.asp?flag=1"">所有掌柜号</a>  <a href=""MaiMaiManage.asp?flag=2"">所有买号</a> <a href=""MaiMaiManage.asp?flag=3"">正常买号</a> <a href=""MaiMaiManage.asp?flag=4"">危险买号</a> <a href=""MaiMaiManage.asp?flag=5"">失效买号</a> <a href=""MaiMaiManage.asp?flag=6"">锁定买号</a> <a href=""MaiMaiManage.asp?flag=7"">暂停买号</a> <a href=""MaiMaiManage.asp?flag=8"">暂停掌柜号</a> <a href=""MaiMaiManage.asp?flag=9"">待激活掌柜号</a></li>"
			  .echo "</ul>"
		
		If Not IsNumeric(Request("page")) And Len(Request("page")) <> 0 Then
			.echo ("错误的系统参数!请输入整数")
			Response.End
		End If
		If Not IsEmpty(Request("page")) And Len(Request("page")) <> 0 Then
			CurrentPage = CInt(Request("page"))
		Else
			CurrentPage = 1
		End If
		If CInt(CurrentPage) = 0 Then CurrentPage = 1
		
		Param=" where 1=1"
		If KS.G("KeyWord")<>"" Then
		  If KS.G("condition")="1" Then
		   Param= Param & " And AccountType=1 And ShopName like '%" & KS.G("KeyWord") & "%'"
		  ElseIf KS.G("condition")="2" Then
		   Param= Param & " And AccountType=2 And ShopName like '%" & KS.G("KeyWord") & "%'"
		  ElseIf KS.G("condition")="3" Then
		   Param= Param & " And UserName like '%" & KS.G("KeyWord") & "%'"
		  End If
		End If
		If KS.G("Flag")<>"" Then
		  If KS.G("Flag")="1" Then Param=Param & " and AccountType=2"
		  If KS.G("Flag")="2" Then Param=Param & " and AccountType=1"
		  If KS.G("Flag")="3" Then Param=Param & " and AccountType=1 And Status=0"
		  If KS.G("Flag")="4" Then Param=Param & " and AccountType=1 And Status=1"
		  If KS.G("Flag")="5" Then Param=Param & " and AccountType=1 And Status=2"
		  If KS.G("Flag")="6" Then Param=Param & " and AccountType=1 And Status=3"
		  If KS.G("Flag")="7" Then Param=Param & " and AccountType=1 And Status=4"
		  If KS.G("Flag")="8" Then Param=Param & " and AccountType=2 And Status=4"
		  If KS.G("Flag")="9" Then Param=Param & " and AccountType=2 And IsActivate=0"
		Else
			If KS.G("KeyWord")="" Then
				Param=Param & " and AccountType=2"	'默认时显示卖家号
			End If
		End If

		totalPut = Conn.Execute("Select Count(id) From MaiMaiUser " & Param)(0)
		TotalPageNum = CInt(totalPut / maxperpage)  '得到总页数
		If TotalPageNum < totalPut / maxperpage Then TotalPageNum = TotalPageNum + 1
		If CurrentPage < 1 Then CurrentPage = 1
		If CurrentPage > TotalPageNum Then CurrentPage = TotalPageNum
		Select Case KS.S("action")
		 Case "Del"  		Call DoDel()
		 Case "NoIsDel"		Call DoNoIsDel()
		 Case "Mod"  		Call DoMod()
		 Case "Activate"	Call DoActivate()
		 Case Else
				 If (KS.G("Flag")="" And KS.G("KeyWord")="") Or (KS.G("Flag")="" And KS.G("condition")="2") Or KS.G("Flag")="1" Or KS.G("Flag")="8" Or KS.G("Flag")="9" Then
					Call ShowShopName()
				 Else
					Call ShowMaiName()
				 End If
		End Select
	End With	
End Sub

Private Sub ShowShopName()
%>
<table width="100%" border="0" align="center" cellspacing="0" cellpadding="0">
<tr height="25" align="center" class='sort'>
	<td width='5%' nowrap>选择</th>
	<td nowrap>用户号</th>
	<td nowrap>绑定的掌柜号</th>
	<td nowrap>所属任务区</th>
	<td nowrap>绑定时间</th>
	<td nowrap>状态/管理操作</th>
</tr>
<%
	sFileName = "MaiMaiManage.asp?"
	Set Rs = Server.CreateObject("ADODB.Recordset")
	SQL = "select * from MaiMaiUser " & Param & " order by id desc"
	If DataBaseType = 1 Then
		If CurrentPage > 100 Then
			Rs.Open SQL, Conn, 1, 1
		Else
			Set Rs = Conn.Execute(SQL)
		End If
	Else
		Rs.Open SQL, Conn, 1, 1
	End If
	If Rs.bof And Rs.EOF Then
		Response.Write "<tr><td height=""25"" align=center bgcolor=""#ffffff"" colspan=6>还没有任何掌柜号！</td></tr>"
	Else
		If TotalPageNum > 1 then Rs.Move (CurrentPage - 1) * maxperpage
		i = 0
%>
<form name=selform method=post action=?action=Del>
<%
	Do While Not Rs.EOF And i < CInt(maxperpage)
		If Not Response.IsClientConnected Then Response.End
		
%>
<tr height="25" class='list' onMouseOver="this.className='listmouseover'" onMouseOut="this.className='list'">
	<td align="center" class="splittd"><input type=checkbox name=ID value='<%=rs("id")%>'></td>
	<td align="center" class="splittd"><%=Rs("UserName")%></td>
	<td align="center" class="splittd"><%=Rs("ShopName")%></td>
	<td align="center" class="splittd"><%=KS.C_C(Rs("tid"),1)%></td>
    <td align="center" class="splittd"><%=KS.GetTimeFormat(Rs("AddDate"))%></td>
    <td align="center" class="splittd"><%
	if KS.ChkClng(Rs("IsDel"))=1 then KS.Echo "<span style=""color:red"" title=""指会员在前台删除，但并不是彻底删除，只是隐藏做个删除标记，目的避免频繁添加删除操作。"">虚删</span>|<a href=""?Action=NoIsDel&ID=" & KS.ChkClng(Rs("id")) & """ onclick=""return(confirm('确定要恢复为正常状态吗？'));""><span class=""orange"">恢复</span></a> "
    '3 为锁定ID  4为暂停ID
	if KS.ChkClng(Rs("IsActivate")) = 0 Then
		KS.Echo "<span style=""color:red"">尚未激活</span>|<a href=""?Action=Activate&Status=1&ID=" & KS.ChkClng(Rs("id")) & """ onclick=""return(confirm('确定要激活该掌柜号吗？'));""><span style=""color:#0000FF"">激活</span></a>"
	else
		if KS.ChkClng(Rs("Status"))=0 Or (KS.ChkClng(Rs("Status"))<>4 And KS.ChkClng(Rs("Status"))<>3) then
		KS.Echo "<span style=""color:#999"">启用</span>|<a href=""?Action=Mod&Status=4&ID=" & KS.ChkClng(Rs("id")) & """ onclick=""return(confirm('确定要停用吗？'));"">停用</a>|<a href=""?Action=Mod&Status=3&ID=" & KS.ChkClng(Rs("id")) & """ onclick=""return(confirm('确定要锁定吗？'));""><span class=""orange"">锁定</span></a>|<a href=""?Action=Activate&Status=0&ID=" & KS.ChkClng(Rs("id")) & """ onclick=""return(confirm('确定要把该掌柜号设为未激活状态吗？'));"">反激活</a>"
		elseif KS.ChkClng(Rs("Status"))=4 then
		KS.Echo "<span style=""color:#FF0000"">暂停</span>|<a href=""?Action=Mod&Status=0&ID=" & KS.ChkClng(Rs("id")) & """><span class=""orange"" onclick=""return(confirm('确定要启用吗？'));"">启用</span></a>|<a href=""javascript:void(0);"" onclick=""alert('暂时状态下需要先启用，才可以锁定！');""><span class=""orange"">锁定</span></a>|<a href=""?Action=Activate&Status=0&ID=" & KS.ChkClng(Rs("id")) & """ onclick=""return(confirm('确定要把该掌柜号设为未激活状态吗？'));"">反激活</a>"
		elseif KS.ChkClng(Rs("Status"))=3 then
		KS.Echo "<span style=""color:#FF0000"">锁定</span>|<a href=""?Action=Mod&Status=0&ID=" & KS.ChkClng(Rs("id")) & """ onclick=""return(confirm('确定要解锁吗？'));""><span class=""orange"">解锁</span></a>|<a href=""?Action=Activate&Status=0&ID=" & KS.ChkClng(Rs("id")) & """ onclick=""return(confirm('确定要把该掌柜号设为未激活状态吗？'));"">反激活</a>"
		end if
	end if
	%>|<a href="?Action=Del&ID=<%=rs("id")%>" onclick="return(confirm('确定要彻底删除吗？'));">删除</a>
    </td>
</tr>
<%
		Rs.movenext
			i = i + 1
			If i >= maxperpage Then Exit Do
		Loop
	End If
	Rs.Close:Set Rs = Nothing
%>
<tr>
	<td class='list' onMouseOver="this.className='listmouseover'" onMouseOut="this.className='list'" height='25' colspan=6>
	&nbsp;&nbsp;<input id="chkAll" onClick="CheckAll(this.form)" type="checkbox" value="checkbox"  name="chkAll">全选
	<input class="button" type="submit" name="Submit2" value=" 删除选中的绑定账号 " onclick="{if(confirm('此操作不可逆，确定要删除选中的记录吗?')){this.document.selform.submit();return true;}return false;}"></td>
</tr>
</form>
<tr>
	<td  colspan=6 align=right>
	<%
	 Call KSCLS.ShowPage(totalPut, MaxPerPage, "MaiMaiManage.asp", True, "个", CurrentPage, KS.QueryParam("page"))
	%></td>
</tr>
</table>
<div>
<form action="MaiMaiManage.asp" name="myform" method="get">
   <div style="border:1px dashed #cccccc;margin:3px;padding:4px">
      &nbsp;<strong>快速搜索=></strong>
	 &nbsp;绑定的账号名:<input type="text" class='textbox' name="keyword">&nbsp;类型:
	 <select name="condition">
	  <option value=1>按绑定的买号搜索</option>
	  <option value=2>按绑定的卖号搜索</option>
	  <option value=3>按用户名搜索</option>
	 </select>
	  &nbsp;<input type="submit" value="开始搜索" class="button" name="s1">
    </div>
</form>
</div>
</body>
</head>
</html>
<%
End Sub

Private Sub ShowMaiName()
%>
<table width="100%" border="0" align="center" cellspacing="0" cellpadding="0">
<tr height="25" align="center" class='sort'>
	<td width='5%' nowrap>选择</th>
	<td nowrap>用户号</th>
	<td nowrap>绑定的买号</th>
	<td nowrap>所属任务区</th>
	<td nowrap>目前信誉</th>
	<td nowrap>当日接手</th>
	<td nowrap>本周接手</th>
	<td nowrap>绑定时间</th>
	<td nowrap>状态/管理操作</th>
</tr>
<%
	sFileName = "MaiMaiManage.asp?"
	Set Rs = Server.CreateObject("ADODB.Recordset")
	SQL = "select * from MaiMaiUser " & Param & " order by id desc"
	If DataBaseType = 1 Then
		If CurrentPage > 100 Then
			Rs.Open SQL, Conn, 1, 1
		Else
			Set Rs = Conn.Execute(SQL)
		End If
	Else
		Rs.Open SQL, Conn, 1, 1
	End If
	If Rs.bof And Rs.EOF Then
		Response.Write "<tr><td height=""25"" align=center bgcolor=""#ffffff"" colspan=10>还没有任何买/卖家！</td></tr>"
	Else
		If TotalPageNum > 1 then Rs.Move (CurrentPage - 1) * maxperpage
		i = 0
%>
<form name=selform method=post action=?action=Del>
<%
	Do While Not Rs.EOF And i < CInt(maxperpage)
		If Not Response.IsClientConnected Then Response.End
		
%>
<tr height="25" class='list' onMouseOver="this.className='listmouseover'" onMouseOut="this.className='list'">
	<td align="center" class="splittd"><input type=checkbox name=ID value='<%=rs("id")%>'></td>
	<td align="center" class="splittd"><%=Rs("UserName")%></td>
	<td align="center" class="splittd"><%=Rs("ShopName")%></td>
	<td align="center" class="splittd"><%=KS.C_C(Rs("tid"),1)%></td>
	<td align="center" class="splittd"><%=RS("CurrentXinYu")%></td>
	<td align="center" class="splittd"><%
	KS.Echo KS.ChkClng(Conn.Execute("select Count(ID) from KS_U_sxyrw where year(KS_Buydate)=year(" & SQLNowString & ") and month(KS_BuyDate)=month(" & SQLNowString & ") and day(KS_BuyDate)=day(" & SQLNowString & ") and KS_BuyUserName='" & Rs("UserName") & "' and KS_BuyShopName='" & Rs("ShopName") & "' And Tid='" & Rs("tid") & "' And KS_Status>=1")(0))
	%>
	</td>
   	<td align="center" class="splittd"><%
	KS.echo KS.ChkClng(Conn.Execute("select Count(ID) from KS_U_sxyrw where year(KS_Buydate)=year(" & SQLNowString & ") and month(KS_Buydate)=month(" & SQLNowString & ") and DATENAME(WEEK, KS_Buydate) = DATENAME(WEEK, " & SQLNowString & ") and KS_BuyUserName='" & Rs("UserName") & "' and KS_BuyShopName='" & Rs("ShopName") & "' And Tid='" & Rs("tid") & "' And KS_Status>=1")(0))
	%></td>
    <td align="center" class="splittd"><%=KS.GetTimeFormat(Rs("AddDate"))%></td>
    <td align="center" class="splittd"><%
	if KS.ChkClng(Rs("IsDel"))=1 then KS.Echo "<span style=""color:red"" title=""指会员在前台删除，但并不是彻底删除，只是隐藏做个删除标记，目的避免频繁添加删除操作。"">虚删</span>|<a href=""?Action=NoIsDel&ID=" & KS.ChkClng(Rs("id")) & """ onclick=""return(confirm('确定要恢复为正常状态吗？'));""><span class=""orange"">恢复</span></a> "
    '3 为锁定ID  4为暂停ID
	if KS.ChkClng(Rs("Status"))=0 Or (KS.ChkClng(Rs("Status"))<>4 And KS.ChkClng(Rs("Status"))<>3) then
	KS.Echo "<span style=""color:#999"">启用</span>|<a href=""?Action=Mod&Status=4&ID=" & KS.ChkClng(Rs("id")) & """ onclick=""return(confirm('确定要停用吗？'));"">停用</a>|<a href=""?Action=Mod&Status=3&ID=" & KS.ChkClng(Rs("id")) & """ onclick=""return(confirm('确定要锁定吗？'));""><span class=""orange"">锁定</span></a>"
	elseif KS.ChkClng(Rs("Status"))=4 then
	KS.Echo "<span style=""color:#FF0000"">暂停</span>|<a href=""?Action=Mod&Status=0&ID=" & KS.ChkClng(Rs("id")) & """><span class=""orange"" onclick=""return(confirm('确定要启用吗？'));"">启用</span></a>|<a href=""javascript:void(0);"" onclick=""alert('暂时状态下需要先启用，才可以锁定！');""><span class=""orange"">锁定</span></a>"
	elseif KS.ChkClng(Rs("Status"))=3 then
	KS.Echo "<span style=""color:#FF0000"">锁定</span>|<a href=""?Action=Mod&Status=0&ID=" & KS.ChkClng(Rs("id")) & """ onclick=""return(confirm('确定要解锁吗？'));""><span class=""orange"">解锁</span></a>"
	end if
	%>|<a href="?Action=Del&ID=<%=rs("id")%>" onclick="return(confirm('确定要彻底删除吗？'));">删除</a>
    </td>
</tr>
<%
		Rs.movenext
			i = i + 1
			If i >= maxperpage Then Exit Do
		Loop
	End If
	Rs.Close:Set Rs = Nothing
%>
<tr>
	<td class='list' onMouseOver="this.className='listmouseover'" onMouseOut="this.className='list'" height='25' colspan=9>
	&nbsp;&nbsp;<input id="chkAll" onClick="CheckAll(this.form)" type="checkbox" value="checkbox"  name="chkAll">全选
	<input class="button" type="submit" name="Submit2" value=" 删除选中的绑定账号 " onclick="{if(confirm('此操作不可逆，确定要删除选中的记录吗?')){this.document.selform.submit();return true;}return false;}"></td>
</tr>
</form>
<tr>
	<td  colspan=9 align=right>
	<%
	 Call KSCLS.ShowPage(totalPut, MaxPerPage, "MaiMaiManage.asp", True, "个", CurrentPage, KS.QueryParam("page"))
	%></td>
</tr>
</table>
<div>
<form action="MaiMaiManage.asp" name="myform" method="get">
   <div style="border:1px dashed #cccccc;margin:3px;padding:4px">
      &nbsp;<strong>快速搜索=></strong>
	 &nbsp;绑定的账号名:<input type="text" class='textbox' name="keyword">&nbsp;类型:
	 <select name="condition">
	  <option value=1>按绑定的买号搜索</option>
	  <option value=2>按绑定的卖号搜索</option>
	  <option value=3>按用户名搜索</option>
	 </select>
	  &nbsp;<input type="submit" value="开始搜索" class="button" name="s1">
    </div>
</form>
</div>
</body>
</head>
</html>
<%
End Sub

Sub DoDel()
	Dim ID: ID=KS.G("ID")
	IF KS.CheckOuterUrl()=False Then
		If ID <> "" Then
			Conn.Execute("Delete From MaiMaiUser Where id In("& id & ")")
			KS.AlertHintScript("删除成功！")
		End If
	End If
End Sub

Sub DoNoIsDel()
	Dim ID: ID=KS.ChkClng(KS.G("ID"))
	IF KS.CheckOuterUrl()=False Then
		If ID <> 0 Then
			Conn.Execute("Update MaiMaiUser Set IsDel=0 Where ID="&ID)
			KS.AlertHintScript("恢复成功！")
		End If
	End If
End Sub

Sub DoMod()
	Dim ID: ID=KS.ChkClng(KS.G("ID"))
	IF KS.CheckOuterUrl()=False Then
		Dim StatusID : StatusID = KS.ChkClng(KS.S("Status"))
		If ID <> 0 And StatusID <> 0 Then
			Conn.Execute("Update MaiMaiUser Set LastUPdateID=Status, Status=" & StatusID & " Where ID=" & ID)
			IF StatusID = 3 Then
				Dim UserName,ShopName
				Set RS = Conn.Execute("Select Top 1 UserName,ShopName From MaiMaiUser Where ID=" & ID)
				UserName = RS("UserName")
				ShopName = RS("ShopName")
				Set RS = Nothing
				Call KS.ScoreInOrOut(UserName,2,100,"系统","买号("& ShopName &")被管理员锁定！",0,0)	'买号被挂起锁定一次扣100积分
			End IF
			KS.AlertHintScript("设置成功！")
		ElseIf ID <> 0 And StatusID = 0 Then
			Conn.Execute("Update MaiMaiUser Set Status=LastUPdateID Where ID="&ID)
			KS.AlertHintScript("设置成功！")
		End If
	End If
End Sub

Sub DoActivate()
Dim ID: ID=KS.ChkClng(KS.G("ID"))
	IF KS.CheckOuterUrl()=False Then
		Dim StatusID : StatusID = KS.ChkClng(KS.S("Status"))
		If ID <> 0 Then
			Conn.Execute("Update MaiMaiUser Set IsActivate=" & StatusID & " Where ID=" & ID)
			KS.AlertHintScript("设置成功！")
		End If
	End If
End Sub
End Class
%> 
