<%@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 User_LogAutoCZ
KSCls.HSK_Run()
Set KSCls = Nothing

Class User_LogAutoCZ
		Private KS,KSCls
		Private MaxPerPage,RS,TotalPut,TotalPages,I,Page,SQL,ComeUrl
		Private Sub Class_Initialize()
		  MaxPerPage=20
		  Set KS=New PublicCls
		  Set KSCls=New ManageCls
		End Sub
        Private Sub Class_Terminate()
		 Call CloseConn()
		 Set KS=Nothing
		 Set KSCls=Nothing
		End Sub
       Sub HSK_Run()
          Response.Write "<html>"
			Response.Write"<head>"
			Response.Write"<meta http-equiv=""Content-Type"" content=""text/html; charset=gb2312"">"
			Response.Write"<link href=""Include/Admin_Style.CSS"" rel=""stylesheet"" type=""text/css"">"
			Response.Write"<script src=""../HSK_JS/jquery.js""></script><script type=""text/javascript"" src=""../HSK_JS/HSK.box.js""></script>"
			Response.Write"</head>"
			Response.Write"<body leftmargin=""0"" topmargin=""0"" marginwidth=""0"" marginheight=""0"">"
	        If Not KS.ReturnPowerResult(0, "KMUA10005") Then
				Response.Write ("<script>$(parent.document).find('#BottomFrame')[0].src='javascript:history.back();';</script>")
				Call KS.ReturnErr(1, "")
			End If
			%>
            <ul id='menu_top'>
            <li class='parent' onClick="UserFormAdd();"><span class=child onmouseover="this.parentNode.className='parent_border'" onMouseOut="this.parentNode.className='parent'" onclick='javascript:new KesionPopup("#fff",4,true,"font-size:12px;background:url(/style/images/w_b_2.gif) #1B76B7 0 -4px;color:#20537A;line-height:30px;").mousepopup("添加充值交易号","<div style=\"padding-top:16px;width:304px;text-align:right;\"><FORM name=czform action=\"?Action=AddNo\" method=post><b>充值会员账号：</b><input name=UserName id=UserName type=text class=textbox size=20 maxlength=30 /><br><br><b>支付交易号：</b><input name=TradeNo id=TradeNo type=text class=textbox size=20 maxlength=30 /><br><br><b>充值金额：</b><input name=Money id=Money type=text class=textbox size=20 maxlength=8 /><br><div style=\"padding:10px 0 0 82px;text-align:center;\"><br><Input class=button id=Submit type=Submit value=确定提交 name=Submit /></div></form></div>",400);'><img src='images/ico/a.gif' border='0' align='absmiddle'>添加充值交易号</span></li>
            <li class='parent' onClick="UserFormAdd();"><span class=child onmouseover="this.parentNode.className='parent_border'" onMouseOut="this.parentNode.className='parent'" onclick='javascript:new KesionPopup("#fff",4,true,"font-size:12px;background:url(/style/images/w_b_2.gif) #1B76B7 0 -4px;color:#20537A;line-height:30px;").mousepopup("添加禁止充值交易号","<div style=\"margin:20px 10px;\"><b>添加禁止充值交易号主要目的避免如下类似例子恶意充值：</b><br><br>1、你的淘宝店绑定了某支付宝号，平台支付宝充值也是该支付宝号的话，会员在你的淘宝店购买了商品后，把支付宝交易单和金额填写到平台进行充值，会得到相应资金；<br><br>2、某客户通过其他途径与你交易或是收款，向你支付宝支付了一笔资金，过后发现平台有支付宝充值功能，于是输入交易号和金额进去充值。<br><br>所以建议使用软件自动充值的朋友，注册个新的支付宝账号再关联到之前已经认证的支付宝，使用新支付宝账号。<br><br><FORM name=czform action=\"?Action=SetNo\" method=post><b>请输入禁止充值的交易号：</b><input name=TradeNo id=TradeNo type=text class=textbox size=20 maxlength=30 /> &nbsp; <Input class=button id=Submit type=Submit value=确定提交 name=Submit /></form></div>",630);'><img src='images/ico/as.gif' border='0' align='absmiddle'>添加禁止充值交易号</span></li>
            </ul>
            <%
		ComeUrl=Cstr(Request.ServerVariables("HTTP_REFERER"))
		Select Case Request("Action")
			Case "del"
				Conn.Execute ("DELETE FROM AutoCZ Where ID = " & KS.ChkClng(KS.G("ID")))
				Call KS.AlertHintScript("删除成功！")
			Case "AddNo"
				Call DoSaveAlipPayCZ()
			Case "SetNo"
				Dim TradeNo: TradeNo=Left(Trim(KS.S("TradeNo")),30)
				If TradeNo="" Then 
					Call KS.AlertHistory("请输入交易号！",-1)
					Exit Sub
				end if
				If Len(TradeNo) < 16 Then 
					Call KS.AlertHistory("您输入的交易号长度不对，标准交易号为16位或28位!",-1)
					Exit Sub
				end if
				Dim RS: Set Rs = Server.CreateObject("ADODB.Recordset")
				Rs.Open "SELECT * FROM AutoCZ WHERE TradeNo = '" & TradeNo & "'", Conn, 1, 3
				If Not Rs.EOF Then
					Rs.Close: Set Rs = Nothing
					Call KS.AlertHistory("该交易号已经存在！",-1)
					KS.Die ""
				Else
					Rs.AddNew
					Rs("UserName") =  KS.DelSql(KS.C("AdminName"))
					RS("RealName") = "管理员后台操作"
					RS("TradeNo") = TradeNo
					Rs("Money") = 0
					Rs("Status") = 3
					Rs("AddDate") = Now
					Rs("EndDate") = Now
					Rs("IP") = KS.GetIP()
					Rs.Update
					Rs.Close
					Set Rs = Nothing
					Call KS.AlertHintScript("添加成功！")
					KS.Die ""
				End If
			Case "deldate"
				Dim Param
				Select Case KS.ChkClng(KS.G("DelType"))
					Case 1 Param="datediff(" & DataPart_D & ",adddate," & SqlNowString & ")>11"
					Case 2 Param="datediff(" & DataPart_D & ",adddate," & SqlNowString & ")>31"
					Case 3 Param="datediff(" & DataPart_D & ",adddate," & SqlNowString & ")>61"
					Case 4 Param="datediff(" & DataPart_D & ",adddate," & SqlNowString & ")>91"
					Case 5 Param="datediff(" & DataPart_D & ",adddate," & SqlNowString & ")>181"
					Case 6 Param="datediff(" & DataPart_D & ",adddate," & SqlNowString & ")>366"
				End Select
				If Param<>"" Then Conn.Execute("Delete From AutoCZ Where 1=1 and " & Param)
				Call KS.AlertHintScript("删除成功！")
		End Select
		%>
<table width="100%" border="0" align="center" cellspacing="0" cellpadding="0">
  <tr class="sort">
    <td nowrap="nowrap" width="4%" align="center"><strong>ID</strong></td>
    <td nowrap="nowrap" width="10%" align="center"><strong>用户名</strong></td>
    <td nowrap="nowrap" width="10%" align="center"><strong>真实姓名</strong></td>
    <td nowrap="nowrap" width="17%" align="center"><strong>交易号</strong></td>
    <td nowrap="nowrap" width="7%" align="center"><strong>支付金额</strong></td>
    <td width="12%"  align="center"><strong>提交时间</strong></td>
    <td width="12%"  align="center"><strong>完成时间</strong></td>
    <td width="12%" align="center"><strong>IP</strong></td>
    <td width="8%" align="center"><strong>状态</strong></td>
    <td nowrap="nowrap" width="" align="center"><strong>操作</strong></td>
  </tr>
  <%
  Page	= KS.ChkClng(request("page"))
  If Page<=0 Then Page=1
	if Trim(request("keyword"))<>"" then
		if KS.ChkClng(KS.S("Field"))=1 Then
			Param=" TradeNo='" & Trim(request("keyword")) & "'"
		else
			Param=" username='" & Trim(request("keyword")) & "'"	
		end if
	else
		Param=" 1=1"
	end if
  Dim SQLStr,FieldStr:FieldStr="*"
  If DataBaseType=1 Then
					Dim Cmd : Set Cmd = Server.CreateObject("ADODB.Command")
					Set Cmd.ActiveConnection=conn
					Cmd.CommandText="KS_GetPageRecords"
					Cmd.CommandType=4	
					CMD.Prepared = true 
					Cmd.Parameters.Append cmd.CreateParameter("@tblName",202,1,200)
					Cmd.Parameters.Append cmd.CreateParameter("@fldName",202,1,200)
					Cmd.Parameters.Append cmd.CreateParameter("@pagesize",3)
					Cmd.Parameters.Append cmd.CreateParameter("@pageindex",3)
					Cmd.Parameters.Append cmd.CreateParameter("@ordertype",3)
					Cmd.Parameters.Append cmd.CreateParameter("@strWhere",202,1,1000)
					Cmd.Parameters.Append cmd.CreateParameter("@fieldIds",202,1,1000)
					Cmd("@tblName")="AutoCZ"
					Cmd("@fldName")= "ID"
					Cmd("@pagesize")=MaxPerPage
					Cmd("@pageindex")=page
					Cmd("@ordertype")=1
					Cmd("@strWhere")=Param
					Cmd("@fieldIds")=FieldStr
					Set Rs=Cmd.Execute
	 Else
			SQLStr=KS.GetPageSQL("AutoCZ","ID",MaxPerPage,Page,1,Param,FieldStr)
			Set RS = Server.CreateObject("AdoDb.RecordSet")
			RS.Open SQLStr, conn, 1, 1
	 End If
  
	If RS.Eof And RS.Bof Then
	 Response.Write "<tr><td colspan=10 align=center height=25 class='splittd'>没找到转账自动充值提交的记录！</td></tr>"
	Else
        TotalPut=Conn.Execute("Select count(1) From AutoCZ")(0)
		SQL = rs.GetRows(MaxPerPage)
		rs.Close:set rs=Nothing
		ShowContent
   End If
%>		
</table>

<div>
		<form action="?" name="myform" method="post">
		   <div style="border:1px dashed #cccccc;margin:3px;padding:4px">
			  &nbsp;<strong>查询类型</strong>
			 &nbsp;<Select id=Field name=Field class='textbox'> 
              		<Option value=1 selected>交易号</Option> 
              		<Option value=2<%if KS.ChkClng(KS.S("Field"))=2 then KS.Echo " selected"%>>用户名</Option>
					</Select> 输入关键字：<input type="text" class='textbox' name="keyword" value="<%=Trim(request("keyword"))%>" maxlength="30">
			  &nbsp;<input type="submit" value="开始搜索" class="button" name="s1">
			  </div>
		</form>
		</div>


<div class="attention">
  <iframe src='about:blank' style='display:none' name='_hiddenframe' id='_hiddenframe'></iframe>
<form action="?action=deldate" target="_hiddenframe" method=post onsubmit="return(confirm('确定要删除吗？'))">
删除范围：<input name="deltype" type="radio" value=1>
10天前 
    <input name="deltype" type="radio" value="2" />
    1个月前
    <input name="deltype" type="radio" value="3" />
    2个月前
    <input name="deltype" type="radio" value="4" />
    3个月前
    <input name="deltype" type="radio" value="5" />
    6个月前
    <input name="deltype" type="radio" value="6" checked="checked" />
    1年前
    <input type="submit" value="执行删除" class="button">
	</form>
</div>
<%End Sub
Sub ShowContent
For i=0 To Ubound(SQL,2)
	%>
  <tr height="25" class='list' onMouseOver="this.className='listmouseover'" onMouseOut="this.className='list'">
    <td class="splittd" align="center"><%=SQL(0,i)%></td>
    <td class="splittd" align="center"><a href="?Field=2&keyword=<%=SQL(1,i)%>"><%=SQL(1,i)%></a></td>
    <td class="splittd" align="center"><%If KS.IsNul(SQL(2,i)) Then KS.Echo "&nbsp;" Else KS.Echo SQL(2,i)%></td>
    <td class="splittd" align="center"><%=SQL(3,i)%></td>
    <td class="splittd" align="center"><%=SQL(4,I)%> 元</td>
    <td class="splittd" align="center"><%=SQL(6,i)%></td>
    <td class="splittd" align="center"><%If KS.IsNul(SQL(7,i)) Then KS.Echo "&nbsp;" Else KS.Echo SQL(7,i)%></td>
    <td class="splittd" align="center"><%=SQL(8,i)%></td>
	<td class="splittd" align="center"><%
	If SQL(5,i)=0 Then
		KS.Echo "<span style=""color:green"">等待充值</span>"
	ElseIf SQL(5,i)=1 Then
		KS.Echo "充值成功"
	ElseIf SQL(5,i)=2 Then
		KS.Echo "<span style=""color:red"">充值失败</span>"
	ElseIf SQL(5,i)=3 Then
		KS.Echo "<span style=""color:blue"">禁止充值</span>"
	End If
	%></td>
    <td class="splittd" align="center"><a href="?Action=del&ID=<%=SQL(0,i)%>" onClick="return confirm('您确定要删除吗？')">删除</a></td>
  </tr>
<%Next%>
  <%  
  Response.Write "<tr><td colspan=10 align=right class='list' onMouseOver=""this.className='listmouseover'"" onMouseOut=""this.className='list'"">"
    Call KS.ShowPage(totalput, MaxPerPage, "", Page,true,true)
  Response.Write "</td></tr>"
End Sub
			
Sub DoSaveAlipPayCZ()
			Dim TradeNo: TradeNo=Left(Trim(KS.S("TradeNo")),30)
			Dim Money:Money=Left(Trim(KS.S("Money")),8)
			If TradeNo="" Or Money="" Then 
				Call KS.AlertHistory("请输入支付宝的交易号或支付金额！",-1)
				Exit Sub
			end if
			If Len(TradeNo) < 16 Then 
				Call KS.AlertHistory("您输入的支付宝交易号长度不对，标准交易号为16位或28位!",-1)
				Exit Sub
			end if
			If Not IsNumeric(Money) Then
				Call KS.AlertHistory("支付的金额输入有误！",-1)
				Exit Sub
			End if
			If Round(Money,2) <= 0 Then
				Call KS.AlertHistory("支付的金额必需是大于0",-1)
				Exit Sub
			End if
			If KS.IsNul(KS.S("UserName")) Then
				Call KS.AlertHistory("请填写要充值的会员名！",-1)
				Exit Sub
			End if
			IF Conn.Execute("SELECT UserID FROM KS_User WHERE UserName='" & Trim(KS.S("UserName")) & "'").Eof Then
				Call KS.AlertHistory("你输入的充值会员账号不存在！",-1)
				Exit Sub
			End IF
			Dim RS: Set Rs = Server.CreateObject("ADODB.Recordset")
			Rs.Open "SELECT * FROM AutoCZ WHERE TradeNo = '" & TradeNo & "'", Conn, 1, 3
			If Not Rs.EOF Then
				If Rs.RecordCount >= 2 then
					Rs.Close: Set Rs = Nothing
					Call KS.AlertHistory("抱歉！系统限制同一交易号不能提交超过2条！请先删除再重新添加！谢谢！",-1)
					KS.Die ""
				ElseIf Rs("Status") = 0 Then
					Rs.Close: Set Rs = Nothing
					Call KS.AlertHistory("该交易号已经存在，请不要重复提交！谢谢！",-1)
					KS.Die ""
				ElseIf Rs("Status") = 1 Then
					Rs.Close: Set Rs = Nothing
					Call KS.AlertHistory("该交易号已经充值成功，请不要重复提交！谢谢！",-1)
					KS.Die ""
				ElseIf Rs("Status") = 3 Then
					Rs.Close: Set Rs = Nothing
					Call KS.AlertHistory("该交易号系统已禁止充值，请先删除再重新添加！谢谢！",-1)
					KS.Die ""
				End IF
			End If
			'不存在相同交易号的 和 第一次充值失败(Status=2)的允许再提交一次
			Rs.AddNew
			Rs("UserName") = Trim(KS.S("UserName"))
			RS("RealName") = Conn.Execute("SELECT RealName FROM KS_User WHERE UserName='" & Trim(KS.S("UserName")) & "'")(0)
			RS("TradeNo") = TradeNo
			Rs("Money") = Round(Money,2)
			Rs("Status") = 0
			Rs("AddDate") = Now
			Rs("IP") = KS.GetIP()
			Rs.Update
			Rs.Close
			Set Rs = Nothing
			KS.AlertHintScript "提交成功！\n\n系统将会在1分钟左右充值完毕！"		
	   End Sub
	   	
End Class
%> 
