<%@LANGUAGE="VBSCRIPT" CODEPAGE="936"%>
<%option explicit%>
<!--#include file="../Conn.asp"-->
<!--#include file="../Task/TaskConfig.asp"-->
<!--#include file="../HSK_Cls/HSK.MemberCls.asp"-->
<!--#include file="../HSK_Cls/HSK.Label.CommonCls.asp"-->
<!--#include file="../Plus/md5.asp"-->
<%
Dim KSCls
Set KSCls = New User_Money2Money
KSCls.HSK_Run()
Set KSCls = Nothing

Class User_Money2Money
        Private KS,KSUser,RS
		Private Action,ID,LoginTF
		Private Sub Class_Initialize()
		  Set KS=New PublicCls
		  Set KSUser = New UserCls
		  Session(KS.SiteSN & "UserInfo") = Empty
		End Sub
        Private Sub Class_Terminate()
		 Set KS=Nothing
		 Set KSUser=Nothing
		End Sub
		%>
		<!--#include file="../HSK_Cls/UserFunction.asp"-->
		<%
       Public Sub loadMain()
		Call KSUser.Head()
		Call KSUser.InnerLocation("账号资金转移")
		LoginTF = Cbool(KSUser.UserLoginChecked)
		IF LoginTF = False  Then
			GCls.ComeUrl = GCls.GetUrl()
			KS.Die "<script>top.location.href='Login/';</script>"
			Exit Sub
		End If
		If KS.S("Action")="OK" And KS.CheckOuterUrl() = False Then 
		 	Call DoTransfer()
		Else
		%>
        <script language = "JavaScript">
			function CheckForm()
			{
			if ($("#Money").val()=="")
			  {
				alert("请输入转移金额！");
				$("#Money").focus();
				return false;
			  }
			if ($("#AcceptUserName").val()=="")
			  {
				alert("请输入接收用户名！");
				$("#AcceptUserName").focus();
				return false;
			  }
			if (document.myform.SecurityCode.value =="")
				{
				alert("请填写安全密码！");
				document.myform.SecurityCode.focus();
				return false;
				}
			if (document.myform.VerifyCode.value =="")
				{
				alert("请填写手机验证码！");
				document.myform.VerifyCode.focus();
				return false;
				}
			  return confirm("确定要转移吗?");
			}
		  
			function SendSMS(){
			var ajaxchk;
			var ajaxstr;
			if (document.myform.SecurityCode.value =="")
				{
				alert("请先填写安全密码再获取短信！");
				document.myform.SecurityCode.focus();
				return false;
			}
			document.myform.Send_bt.disabled=true;
			$.ajax({type:"post",url:"/Plus/Ajax_SMS.asp",data:"Action=SendSMS&Mobile=<%=KSUser.GetUserInfo("Mobile")%>&N=2&M=1&Flag=Money2Money&C="+ document.myform.SecurityCode.value +"&CC=1&anticache=" + Math.floor(Math.random()*1000),cache:false,dataType:"html",success:function(d){
			var s=unescape(d);
			ajaxchk=s.split('|')[0];
			ajaxstr=s.split('|')[1];
			if (ajaxstr!=null){
				if (ajaxchk=='ok'){CheckTime();alert(ajaxstr);}
				else{alert(ajaxstr);document.myform.Send_bt.disabled=false;}
			}
		} });
		}
		
		var t = 180;
		function CheckTime() {
		if (t <0 ) t = 0;
		document.myform.Send_bt.disabled=true;
		document.myform.Send_bt.value= "（" + t + "秒后）重新获取短信"
			var uptime = function() {
				t = t - 1;
				if (t <= 0) {
					window.clearInterval(tt_0);
					t = 0;
					document.myform.Send_bt.value= " 重新获取短信 ";
					document.myform.Send_bt.disabled=false;
				}else{
				document.myform.Send_bt.value= "（" + t + "秒后）重新获取短信"
				}
			}
			var tt_0 = window.setInterval(uptime, 1000);
		}
		
		function SetMoneyRatio(n){
			if (n>0)
				$('#Ratio').html(n + '元 — (' + n + ' X <%=KS.GetN(MemberCenter_Money2Money_Ratio,3)%>) = <span class="red">' + parseFloat(n - n * <%=KS.GetN(MemberCenter_Money2Money_Ratio,3)%>).toFixed(2) + '</span> 元');
			else
				$('#Ratio').html('0 元');
		}
		</script>
            	<div class="tabs">	
                <ul>
                    <li class="select"><a href="?">资金转移</a></li>
                    <li><a href="User_LogMoney.asp">财务明细</a></li>
                </ul>
                </div>
				  <table width="100%"  border="0" align="center" cellpadding="0" cellspacing="1" class="border">
                    <form name="myform" method="post" action="?" onSubmit="return CheckForm();">
                    <input name="Action" type="hidden" value="OK" />
                    <tr class="title">
                        <td height="30" colspan=2 align="center"><strong>用户账号之间资金转移</strong></td>
                    </tr>
                    <tr class="tdbg">
                      <td colspan=2 height="10" align="center"></td>
                    </tr>
                    <tr class="tdbg">
                      <td width="40%" height="35" align="right">您当前余额：</td>
                      <td width="60%" class="red"><%=KSUser.GetUserInfo("Money")%> 元</td>
                    </tr>
                    <tr class="tdbg">
                      <td width="40%" height="35" align="right">转移金额：</td>
                      <td width="60%"><input class="textbox" style="width:80px;" type="text" id="Money" maxlength="8" name="Money" value="<%=KSUser.GetUserInfo("Money")%>" title="请输入需要转移给对方的金额" onKeyUp="this.value=this.value.replace(/[^0123456789.]/g,'');SetMoneyRatio(this.value)" onafterpaste="this.value=this.value.replace(/[^0123456789.]/g,'')" /> 
                      元 &nbsp; <span class="red">注：转移资金需收取<%=MemberCenter_Money2Money_Ratio * 100%>%手续费</span></td>
                    </tr>
                    <tr class="tdbg">
                      <td width="40%" height="35" align="right">实际到账金额：</td>
                      <td width="60%" id="Ratio"><%
					If KSUser.GetUserInfo("Money") > 0 Then%><%=KSUser.GetUserInfo("Money")%>元 — (<%=KSUser.GetUserInfo("Money")%> X <%=KS.GetN(MemberCenter_Money2Money_Ratio,3)%>) = <span class="red"><%=KS.GetN(KSUser.GetUserInfo("Money") - KSUser.GetUserInfo("Money") * MemberCenter_Money2Money_Ratio, 2)%></span> 元<%
					Else
					   KS.Echo "0 元"
					End If%></td>
                    </tr>
                    <tr class="tdbg">
                      <td width="40%" height="35" align="right">接收方用户名：</td>
                      <td width="60%"><input class="textbox" style="width:150px;" type="text" id="AcceptUserName" maxlength="30" name="AcceptUserName" value="" title="请输入资金接收方用户名" /></td>
                    </tr>
                    <tr class="tdbg">
                      <td width="40%" height="35" align="right">安全密码：</td>
                      <td width="60%"><input class="textbox" style="width:100px;" type="password" id="SecurityCode" maxlength="16" name="SecurityCode" value="" title="安全密码主要用于资金流转、账户安全二层保护作用。&#13;&#10;注：安全密码不是登录密码，只需第一次输入。" /></td>
                    </tr>
                    <tr class="tdbg">
                      <td width="40%" height="35" align="right">手机验证码：</td>
                      <td width="60%"><input class="textbox" style="width:100px;" type="text" name="VerifyCode" id="VerifyCode" size="30" maxlength="6" onKeyUp="this.value=this.value.replace(/\D/g,'')" onafterpaste="this.value=this.value.replace(/\D/g,'')" value="" />&nbsp; <input class="button" name="Send_bt" id="Send_bt" type="button" value="获取手机短信验证码(<%=KS.GetN(SMS_Price,2)%>元/条)" title="从您账户余额中扣取<%=KS.GetN(SMS_Price,2)%>元/条" onclick="SendSMS()" /></td>
                    </tr>       
                    <tr class="tdbg">
                      <td colspan=2 height="80" align="center"><input class="button" name="Submit2" type="submit" value=" 确定提交 "<%If KSUser.GetUserInfo("Money") <= 0 Then KS.Echo " disabled"%> /></td>
                    </tr>
                    <tr class="tdbg">
                      <td colspan=2 height="20" align="center">&nbsp;</td>
                    </tr>
                    <tr class="tdbg">
                      <td colspan=2 height="100" align="center">
                      <div  style="color:red; width:96%; padding:8px; text-align:left; border: 1px #F96 solid; background-color:#FFFEEE"><strong>温馨提示：</strong>本功能主要是为用户账号之间资金转移，例如账号A想把账号下的资金转移到账号B，可在“接收方用户名”输入B的账号名，提交即可。但请慎用本功能，如果不明白如何使用，请别乱操作，否则资金一旦成功转移到对方账号，将不可挽回。</div></td>
                    </tr>
                    </form>
                </table>
		<%
		End If
       End Sub
	   
	   Sub DoTransfer()
		IF Md5(Trim(KS.F("SecurityCode")),16) <> KSUser.GetUserInfo("KS_SecurityCode") Then
			KS.AlertHistory "系统提示：\n\n您输入的安全密码不对!","-1"
		End IF
		IF Trim(KS.F("VerifyCode")) <> KSUser.GetUserInfo("CheckNum") Then
			KS.AlertHistory "系统提示：\n\n您输入的手机验证码不对!","-1"
		End IF
		Dim Money: Money = Left(Trim(KS.F("Money")),8)
		IF Money = "" Then
			KS.AlertHistory "系统提示：\n\n转移金额不能为空!","-1"
		ElseIf Not IsNumeric(Money) Then
			KS.AlertHistory "系统提示：\n\n请输入有效的金额数字!","-1"
		End IF
		IF Round(Money,2) > Round(KSUser.GetUserInfo("Money"),2) Then
			KS.AlertHistory "系统提示：\n\n您账号余额不足!","-1"
		End IF
		Dim AcceptUserName: AcceptUserName = KS.CheckXSS(KS.F("AcceptUserName"))
		IF AcceptUserName = KSUser.UserName Then
			KS.AlertHistory "系统提示：\n\n不能转给自己!","-1"
		End IF
		If Not KS.IsNul(AcceptUserName) Then
			If Not Conn.Execute("Select Top 1 UserID From KS_User Where UserName = '" & AcceptUserName & "'").Eof Then
				Call KS.MoneyInOrOut(KSUser.UserName,KSUser.GetUserInfo("RealName"),Round(Money,2),4,2,Now,0,"系统","转移资金" & Money & "元到账号:" & AcceptUserName,0,0,1)
				Money = Round(Money - Money * MemberCenter_Money2Money_Ratio, 2)
				Call KS.MoneyInOrOut(AcceptUserName,Conn.Execute("SELECT TOP 1 RealName FROM KS_User WHERE UserName = '" & AcceptUserName & "'")(0),Money,4,1,Now,0,"系统","会员:" & KSUser.UserName & "给您转入" & Money & "元",0,0,1)
				Call KSUser.AddLog(KSUser.UserName,"转移资金" & Money & "元给账号:" & Left(AcceptUserName,1) & "***" & Right(AcceptUserName,1),1)	
				Conn.Execute("Update KS_User Set CheckNum = '" & KS.MakeRandom(6) & "' Where UserName = '" & KSUser.UserName & "'")
				KS.Alert "恭喜，资金转移成功，请通知对方查收！","User_LogMoney.asp"
			Else
				KS.AlertHistory "系统提示：\n\n接收方用户名不存在，请返回核实再试!","-1"
			End If
		Else
			KS.AlertHistory "系统提示：\n\n接收方用户名不能为空!","-1"
		End If
		
	 End Sub
End Class
%> 
