<%@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"-->
<%
Dim KSCls
Set KSCls = New User_ExChange
KSCls.HSK_Run()
Set KSCls = Nothing

Class User_ExChange
        Private KS,KSUser
		Private Sub Class_Initialize()
		  Set KS=New PublicCls
		  Set KSUser = New UserCls
		End Sub
        Private Sub Class_Terminate()
		 Set KS=Nothing
		 Set KSUser=Nothing
		End Sub
		%>
		<!--#include file="../HSK_Cls/UserFunction.asp"-->
		<%
		Public Sub loadMain()
		IF Cbool(KSUser.UserLoginChecked)=false Then
		  GCls.ComeUrl = "/user/user_exchange.asp?Action=Money"
		  Response.Write "<script>top.location.href='Login';</script>"
		  Exit Sub
		End If
		Call KSUser.Head()
		Response.Write "<div class=""tabs"">"
		Response.Write " <ul class="""">"
		Response.Write " <li><a href=""User_Transfer.asp"" style='color:red;'>支付宝自动充值</a></li>"
		Response.Write " <li><a href=""User_PayOnline.asp"">在线支付充值</a></li>"
		Response.Write " <li><a href=""user_recharge.asp"">充值卡充值</a></li>"
		Response.Write " <li><a href=""user_card.asp"" style='color:red;'>购买点卡</a></li>"
		If Mid(KS.Setting(170),1,1)="1" or Mid(KS.Setting(170),2,1)="1" Then
			If KS.S("Action")="Point" Then
			Response.Write " <li class='select'><a href=""user_exchange.asp?Action=Point"">兑换" & KS.Setting(45) & "</a></li>"
			Else
			Response.Write " <li><a href=""user_exchange.asp?Action=Point"">兑换" & KS.Setting(45) & "</a></li>"
			End IF
		End If
		If Mid(KS.Setting(170),3,1)="1" or Mid(KS.Setting(170),4,1)="1" Then
			If KS.S("Action")="Edays" Then
			Response.Write " <li class='select'><a href=""user_exchange.asp?Action=Edays"">兑换有效期</a></li>"
			Else
			Response.Write " <li><a href=""user_exchange.asp?Action=Edays"">兑换有效期</a></li>"
			End If
		End If
		If Mid(KS.Setting(170),5,1)="1" Then
			If KS.S("Action")="Money" Then
			Response.Write " <li class='select'><a href=""user_exchange.asp?Action=Money"">兑换资金</a></li>"
			Else
			Response.Write " <li><a href=""user_exchange.asp?Action=Money"">兑换资金</a></li>"
			End If
		End If
		Response.Write "</ul>"
		Response.Write "</div>"
		Select Case KS.S("Action")
		 Case "Point"
		   Call KSUser.InnerLocation("兑换" & KS.Setting(45))
		   Call ExchangePoint()
		 Case "Money" 
		   Call KSUser.InnerLocation("兑换账户资金")
		   Call ExchangeMoney()
		 Case "SaveExchangeMoney"
		   Call SaveExchangeMoney()
		 Case "SaveExchangePoint"
		   Call SaveExchangePoint()
		 Case "Edays"
		 	Call KSUser.InnerLocation("兑换有效天数")
		    Call ExchangeEdays()
		 Case "SaveExchangeEdays"
		    Call SaveExchangeEdays()
		End Select
       End Sub
	   
	   Sub ExchangePoint()
	   %>
	   <script>
		//* 名　　称：IsInteger
		//* 功    能：判断是否为正整数
		//*****************************************************************
		function IsInteger(fData)
		{
		if ((fData==null) || (fData.length==0) || (isNaN(fData)) || (fData.indexOf("-")!=-1)){
		return false   
		}
		return true   
		}
		
	     function Confirm()
		 {
		   var str='友情提醒:\n\n';
		   if (document.myform.ChangeType[0].checked==true){
		     if (IsInteger(document.myform.Money.value)==false){
				alert('请输入有效数字！');
				document.myform.Money.focus();
			    return false;
			 }
		     if (parseFloat(document.myform.Premoney.value)<parseFloat(document.myform.Money.value)){
			   alert('您目前资金余额不足，请充值后再来兑换！');
			   return false;
			   }
		    str+='兑换前资金：'+document.myform.Premoney.value+' 元\n\n';
			str+='兑换后资金：'+(document.myform.Premoney.value-document.myform.Money.value).toFixed(2)+' 元\n\n';
			str+='一旦兑换成功即不可逆，确定兑换吗？';
		   }else{
		   if (IsInteger(document.myform.Score.value)==false || (document.myform.Score.value.indexOf(".")!=-1)){
				alert('请输入整数！');
				document.myform.Score.focus();
			    return false;
			}
		   if (parseInt(document.myform.PreScore.value)<parseInt(document.myform.Score.value)){
			   alert('您目前可用积分不足，不能兑换！');
			   return false;
			   }
		    str+='兑换前积分：'+document.myform.PreScore.value+' 分\n\n';
			str+='兑换后积分：'+(document.myform.PreScore.value-document.myform.Score.value)+' 分\n\n';
			str+='一旦兑换成功即不可逆，确定兑换吗？';
		   }
		   if (confirm(str)){
		    return true}
		   else{ return false}
		 }
	   </script>
		<FORM name=myform action="User_Exchange.asp" method="post">
		  <table class=border cellSpacing=1 cellPadding=2 width="100%" align=center border=0>
			<tr class=title>
			  <td align=middle colSpan=2 height=22><B> 兑 换 发 布 点 </B></td>
			</tr> 
			<tr class=tdbg>
			  <td align=right width=120>用户名：</td>
			  <td><%=KSUser.UserName%></td>
			</tr>
			<tr class=tdbg>
			  <td align=right width=120>资金余额：</td>
			  <td><input type='hidden' value='<%=KSUser.GetUserInfo("Money")%>' name='Premoney'><%=KS.GetN(KSUser.GetUserInfo("Money"),2)%> 元</td>
			</tr>
			<tr class=tdbg>
			  <td align=right width=120>可用积分：</td>
			  <td><input type='hidden' value='<%=KSUser.GetUserInfo("Score")%>' name='PreScore'><%=KSUser.GetUserInfo("Score")%> 分</td>
			</tr>
			<tr class=tdbg>
			  <td align=right width=120>可用<%=KS.Setting(45)%>：</td>
			  <td><%=KS.GetN(KSUser.GetUserInfo("Point"),2)%>&nbsp;<%=KS.Setting(46)%><input type='hidden' value='<%=KSUser.GetUserInfo("Point")%>' name='Prepoint'></td>
			</tr>
			<tr class=tdbg>
			  <td align=right width=120>可用收藏点：</td>
			  <td><%=KS.GetN(KSUser.GetUserInfo("KS_CollectPoint"),3)%>&nbsp;点<input type='hidden' value='<%=KSUser.GetUserInfo("KS_CollectPoint")%>' name='PreCollectPoint'></td>
			</tr>
			<tr class=tdbg>
			  <td align=right width=120>可用流量点：</td>
			  <td><%=KS.GetN(KSUser.GetUserInfo("KS_FlowPoint"),4)%>&nbsp;点<input type='hidden' value='<%=KSUser.GetUserInfo("KS_FlowPoint")%>' name='PreFlowPoint'></td>
			</tr>
			<tr class=tdbg>
			  <td align=right width=120>兑换<%=KS.Setting(45)%>：</td>
			  <td>
			  <%if Mid(KS.Setting(170),1,1)="1" then%>
		  <label><Input type=radio CHECKED value="1" name="ChangeType">使用资金余额： 将 
		  <Input style="TEXT-ALIGN: center" maxLength=8 size=6 value="10" name="Money" onKeyUp="this.value=this.value.replace(/[^0123456789.]/g,'')"  onafterpaste="this.value=this.value.replace(/[^0123456789.]/g,'')"> 元兑换成<%=KS.Setting(45)%> &nbsp;&nbsp;&nbsp;&nbsp;<Font color=red>兑换比率：<%=KS.Setting(43)%>元 = 1<%=KS.Setting(46)%></Font> </label>
		     <br>
			 <%End If%>
		     <%if Mid(KS.Setting(170),2,1)="1" then%>
		  <label><Input type=radio value="2" name="ChangeType"<%IF Mid(KS.Setting(170),1,1)="0" then Response.Write " checked"%>>使用经验积分： 将 
				<Input style="TEXT-ALIGN: center" maxLength=8 size=6 value="<%=KS.Setting(41)%>" name="Score" onKeyUp="this.value=this.value.replace(/\D/g,'')"  onafterpaste="this.value=this.value.replace(/\D/g,'')"> 分兑换成<%=KS.Setting(45)%> &nbsp;&nbsp;&nbsp;&nbsp;<Font color=red>兑换比率：<%=KS.Setting(41)%>分 = 1<%=KS.Setting(46)%> </Font></label>
				
			 <%End IF%>	
				</td>
			</tr>
			<tr class=tdbg>
			  <td align=middle colSpan=2 height=40>
		        <Input id=Action type=hidden value="SaveExchangePoint" name="Action"> 
				<Input class="button" id=Submit type=submit value="执行兑换" onClick="return(Confirm())" name=Submit> </td>
			</tr>
		  </table>
		</FORM>
	   <%
	   End Sub
	   
	   Sub SaveExchangePoint()
	     Dim ChangeType:ChangeType=KS.ChkCLng(KS.S("ChangeType"))
		 
		  If ChangeType=1 And Mid(KS.Setting(170),1,1)="0" Then
			   Response.Write "<script>alert('对不起,没有开启资金兑换" & KS.Setting(45) &"服务!');history.back();</script>"
			   Exit Sub
		  ElseIf ChangeType=2 And Mid(KS.Setting(170),2,1)="0" Then
			   Response.Write "<script>alert('对不起,没有开启经验积分兑换" & KS.Setting(45) &"服务!');history.back();</script>"
			   Exit Sub
		  End If
		 
		 Dim Money:Money=KS.S("Money")
		 Dim Score:Score=KS.ChkClng(KS.S("Score"))
		 Dim RS:Set RS=Server.CreateObject("ADODB.RECORDSET")
		 RS.Open "Select top 1 * From KS_User Where UserName='" & KSUser.UserName & "'",conn,1,1
		 If RS.Eof  Then
		   Rs.Close:Set RS=Nothing
		   Response.Write "<script>alert('出错啦!请检查是否登录已超时!');history.back();</script>"
		   Exit Sub
		 End If
		 If ChangeType=1 Then	'资金兑换发布点
		    If KS.ChkClng(Money)=0 Then
			   Rs.Close:Set RS=Nothing
			   Response.Write "<script>alert('你输入的资金不正确,资金必须大于0!');history.back();</script>"
			   Exit Sub
			End iF
			If KS.ChkClng(Money)<KS.ChkClng(KS.Setting(43)) Then
			   Rs.Close:Set RS=Nothing
			   Response.Write "<script>alert('你输入的资金不正确,资金必须大于等于" & KS.Setting(43) &"!');history.back();</script>"
			   Exit Sub
			End If
		    IF Round(RS("Money"),2)<Round(Money,2) Then
			   Rs.Close:Set RS=Nothing
			   Response.Write "<script>alert('你可用资金不足，请充值后再来兑换!');history.back();</script>"
			   Exit Sub
		    End If

		'  ChannelID,InfoID,UserName,InOrOutFlag,Point,User,Descript
		Call KS.PointInOrOut(0,0,rs("UserName"),1,Round(Money/KS.Setting(43),2),"系统","账户资金兑换所得",0)
		Call KS.MoneyInOrOut(rs("UserName"),rs("RealName"),Money,4,2,now,0,"系统","用于兑换"& KS.Setting(45),0,0,1)
	
		 Else
		    If Score=0 Then
			   Rs.Close:Set RS=Nothing
			   Response.Write "<script>alert('你输入的积分不正确,积分必须大于0!');history.back();</script>"
			   Exit Sub
			End If
			If KS.ChkClng(Score)<KS.ChkClng(KS.Setting(41)) Then
			   Rs.Close:Set RS=Nothing
			   Response.Write "<script>alert('你输入的积分不正确,积分必须大于等于" & KS.Setting(41) &"!');history.back();</script>"
			   Exit Sub
			End If
		   IF KS.ChkClng(RS("Score"))<KS.ChkClng(Score) Then
			   Rs.Close:Set RS=Nothing
			   Response.Write "<script>alert('你可用积分不足，不能兑换!');history.back();</script>"
			   Exit Sub
		   End If
		   
		     Call KS.ScoreInOrOut(rs("UserName"),2,Score,"系统","兑换"& KS.Setting(45) &"消耗!",0,0)
			'ChannelID,InfoID,UserName,InOrOutFlag,Point,User,Descript
			 Call KS.PointInOrOut(0,0,rs("UserName"),1,Round(Score/KS.Setting(41),2),"系统","积分兑换所得",0)
		 End IF
		 Response.Write "<script>alert('恭喜您，"& KS.Setting(45) &"兑换成功!');location.href='User_ExChange.asp?Action=Point';</script>"
		 RS.Close:Set RS=Nothing
 	   End Sub
	   
	   
	   Sub ExchangeMoney()
	   %>
	   		<script>
		//* 名　　称：IsInteger
		//* 功    能：判断是否为正整数
		//*****************************************************************
		function IsInteger(fData)
		{
		if ((fData==null) || (fData.length==0) || (isNaN(fData)) || (fData.indexOf(".")!=-1) || (fData.indexOf("-")!=-1)){
		return false   
		}
		return true   
		}
		 
	     function checkform()
		 {
		   var str='友情提醒:\n\n';
		   var n=$("input:radio[checked]").val();
		   if(n==1){
			   	 var Name = "发布点";
				 var Num = 10;		//默认10点起兑换，可自行修改此数值
				 var Point = document.myforms.Point.value;
				 var PrePoint = document.myforms.Prepoint.value;
			}
			 if(n==2){
			   	 var Name = "收藏点";
				 var Num = 100;
				 var Point = document.myforms.Point2.value;
				 var PrePoint = document.myforms.PreCollectPoint.value;
			 }
			 if(n==3){
			   	 var Name = "流量点";
				 var Num = 500;
				 var Point = document.myforms.Point3.value;
				 var PrePoint = document.myforms.PreFlowPoint.value;
			 }
		    if (Point<1 || IsInteger(Point)==false){
				alert('请输入整数！');
			    return false;
			}
			 if (parseFloat(Point)<parseFloat(Num)){
			   alert('抱歉！最低' + Num + '个' + Name + '起才可以兑换！');
			   return false;
			   }
		     if (parseFloat(PrePoint)<parseFloat(Point)){
			   alert('抱歉，你的' + Name + '不足！');
			   return false;
			   }
		    str+='兑换前' + Name + '：' + PrePoint + ' 点\n\n';
			str+='兑换后' + Name + '：' + (PrePoint - Point).toFixed(2) + ' 点\n\n';
			str+='一旦兑换成功即不可逆，确定兑换吗？';

		   if (confirm(str)){
		    return true; }
		   else{ return false; }
		 }
	   </script>
		<FORM name=myforms action="User_Exchange.asp" method="post">
		  <table class=border cellSpacing=1 cellPadding=2 width="100%" align=center border=0>
			<tr class=title>
			  <td align=middle colSpan=2 height=22><B> 兑 换 资 金 </B></td>
			</tr> 
			<tr class=tdbg>
			  <td align=right width=120>用户名：</td>
			  <td><%=KSUser.UserName%></td>
			</tr>
			<tr class=tdbg>
			  <td align=right width=120>资金余额：</td>
			  <td><input type='hidden' value='<%=KSUser.GetUserInfo("Money")%>' name='Premoney'><%=KS.GetN(KSUser.GetUserInfo("Money"),2)%> 元</td>
			</tr>
			<tr class=tdbg>
			  <td align=right width=120>可用积分：</td>
			  <td><input type='hidden' value='<%=KSUser.GetUserInfo("Score")%>' name='PreScore'><%=KSUser.GetUserInfo("Score")%> 分</td>
			</tr>
			<tr class=tdbg>
			  <td align=right width=120>可用<%=KS.Setting(45)%>：</td>
			  <td><%=KS.GetN(KSUser.GetUserInfo("Point"),2)%>&nbsp;<%=KS.Setting(46)%><input type='hidden' value='<%=KSUser.GetUserInfo("Point")%>' name='Prepoint'></td>
			</tr>
			<tr class=tdbg>
			  <td align=right width=120>可用收藏点：</td>
			  <td><%=KS.GetN(KSUser.GetUserInfo("KS_CollectPoint"),3)%>&nbsp;点<input type='hidden' value='<%=KSUser.GetUserInfo("KS_CollectPoint")%>' name='PreCollectPoint'></td>
			</tr>
			<tr class=tdbg>
			  <td align=right width=120>可用流量点：</td>
			  <td><%=KS.GetN(KSUser.GetUserInfo("KS_FlowPoint"),4)%>&nbsp;点<input type='hidden' value='<%=KSUser.GetUserInfo("KS_FlowPoint")%>' name='PreFlowPoint'></td>
			</tr>
			<tr class=tdbg>
			  <td align=right width=120>兑换方式：</td>
			  <td><%
		If KS.ChkClng(KSUser.GetUserInfo("KS_JinzhiExchangeMoney")) = 1 Then
			KS.Echo "<font color=red>抱歉！您当前不支持兑换资金！如需兑换，请联系客服！</font>"
		Else
			  %><Input type=radio value="1" name="ChangeType" checked="checked" />
			    <%=KS.Setting(45)%>： 将 <Input style="TEXT-ALIGN: center" maxLength="8" size="6" value="<%=Int(KSUser.GetUserInfo("Point"))%>" name="Point" onKeyUp="this.value=this.value.replace(/\D/g,'')"  onafterpaste="this.value=this.value.replace(/\D/g,'')" /> 
		  <%=KS.Setting(46)%><%=KS.Setting(45)%>兑换成账户资金 &nbsp;&nbsp;&nbsp;<font color=red>兑换比率：1 <%=KS.Setting(46)%> = <%
			IF KS.ChkClng(KSUser.GroupID) = UserGroupVipID Then
				KS.Echo KS.GetN(TaskPointExchangeMoneyVIP,2) & " 元</font> <font color=blue>(普通会员是：" & KS.GetN(TaskPointExchangeMoneyCommon,2) & " 元)</font>"
			Else
				KS.Echo KS.GetN(TaskPointExchangeMoneyCommon,2) & " 元</font> <font color=blue>(VIP会员是：" & KS.GetN(TaskPointExchangeMoneyVIP,2) & " 元)</font>"
			End If%><br />
	<input type="radio" value="2" name="ChangeType" />
	收藏点： 将
	<input style="TEXT-ALIGN: center" maxlength="8" size="6" value="<%=Int(KSUser.GetUserInfo("KS_CollectPoint"))%>" name="Point2" onkeyup="this.value=this.value.replace(/\D/g,'')"  onafterpaste="this.value=this.value.replace(/\D/g,'')" />
	点收藏点兑换成账户资金 &nbsp;&nbsp;&nbsp;<font color="red">兑换比率：1 点 = <%
			IF KS.ChkClng(KSUser.GroupID) = UserGroupVipID Then
				KS.Echo KS.GetN(CollectPointExchangeMoneyVIP,3) & " 元</font> <font color=blue>(普通会员是：" & KS.GetN(CollectPointExchangeMoneyCommon,3) & " 元)</font>"
			Else
				KS.Echo KS.GetN(CollectPointExchangeMoneyCommon,3) & " 元</font> <font color=blue>(VIP会员是：" & KS.GetN(CollectPointExchangeMoneyVIP,3) & " 元)</font>"
			End If%><br />
	<input type="radio" value="3" name="ChangeType" />
	流量点： 将
	<input style="TEXT-ALIGN: center" maxlength="8" size="6" value="<%=Int(KSUser.GetUserInfo("KS_FlowPoint"))%>" name="Point3" onkeyup="this.value=this.value.replace(/\D/g,'')"  onafterpaste="this.value=this.value.replace(/\D/g,'')" />
	点流量点兑换成账户资金 &nbsp;&nbsp;&nbsp;<font color="red">兑换比率：1 点 = <%
			IF KS.ChkClng(KSUser.GroupID) = UserGroupVipID Then
				KS.Echo KS.GetN(FlowPointExchangeMoneyVIP,4) & " 元</font> <font color=blue>(普通会员是：" & KS.GetN(FlowPointExchangeMoneyCommon,4) & " 元)</font>"
			Else
				KS.Echo KS.GetN(FlowPointExchangeMoneyCommon,4) & " 元</font> <font color=blue>(VIP会员是：" & KS.GetN(FlowPointExchangeMoneyVIP,4) & " 元)</font>"
			End If
		End If
		%></td>
			</tr>
			<tr class=tdbg>
			  <td align=middle colSpan=2 height=40>
		        <Input id=Action type=hidden value="SaveExchangeMoney" name="Action"> 
				<Input class="button" id=Submit type=submit value="执行兑换" onClick="return(checkform())" name=Submit<%If KS.ChkClng(KSUser.GetUserInfo("KS_JinzhiExchangeMoney")) = 1 Then KS.Echo " disabled"%>> </td>
			</tr>
		  </table>
		</FORM>

		
	   <%
	   End Sub
	   
	   Sub SaveExchangeMoney()
		Dim Point
		Dim ChangeType:ChangeType=KS.ChkClng(KS.S("ChangeType"))

		If Mid(KS.Setting(170),5,1)="0" Then
		   Response.Write "<script>alert('对不起,没有开启" & KS.Setting(45) & "兑换资金服务!');history.back();</script>"
		   Exit Sub
		End If
			
		DIM RS:Set RS=Server.CreateObject("ADODB.RECORDSET")
		RS.Open "Select top 1 * From KS_User Where UserName='" & KSUser.UserName & "'",conn,1,1
		If RS.Eof  Then
			Rs.Close:Set RS=Nothing
			Response.Write "<script>alert('出错啦!请检查是否登录已超时！');history.back();</script>"
			Exit Sub
		End If
		Select Case ChangeType
			Case 1
				Point=KS.ChkCLng(KS.S("Point"))
				If Int(Point)<=0 Then
				   Response.Write "<script>alert('你输入的" & KS.Setting(45) & "不正确,必须大于0!');history.back();</script>"
				   Exit Sub
				End iF
				IF Int(RS("Point"))<Int(Point) Then
				   Rs.Close:Set RS=Nothing
				   Response.Write "<script>alert('你可用" & KS.Setting(45) & "不足!');history.back();</script>"
				   Exit Sub
				End If
				 Call KS.PointInOrOut(0,0,rs("UserName"),2,Int(Point),"系统",KS.Setting(45) & "兑换账户资金",0)
				 IF KS.ChkClng(rs("GroupID")) = UserGroupVipID Then	'是VIP会员
					 Call KS.MoneyInOrOut(rs("UserName"),rs("RealName"),Round(point*TaskPointExchangeMoneyVIP,2),4,1,now,0,"系统",KS.Setting(45) & "兑换所得",0,0,0)
				 Else
					 Call KS.MoneyInOrOut(rs("UserName"),rs("RealName"),Round(point*TaskPointExchangeMoneyCommon,2),4,1,now,0,"系统",KS.Setting(45) & "兑换所得",0,0,0)
				 End IF
			Case 2
				Point=KS.ChkCLng(KS.S("Point2"))
				If Int(Point)<=0 Then
				   Response.Write "<script>alert('你输入的收藏点不正确,必须大于0!');history.back();</script>"
				   Exit Sub
				End iF
				IF Int(RS("KS_CollectPoint"))<Int(Point) Then
				   Rs.Close:Set RS=Nothing
				   Response.Write "<script>alert('你可用收藏点不足!');history.back();</script>"
				   Exit Sub
				End If
				 Call KS.CollectPointInOrOut(0,0,rs("UserName"),"",2,Int(Point),"系统","收藏点兑换账户资金",0)
				 IF KS.ChkClng(rs("GroupID")) = UserGroupVipID Then	'是VIP会员
					 Call KS.MoneyInOrOut(rs("UserName"),rs("RealName"),Round(point*CollectPointExchangeMoneyVIP,3),4,1,now,0,"系统","收藏点兑换所得",0,0,0)
				 Else
					 Call KS.MoneyInOrOut(rs("UserName"),rs("RealName"),Round(point*CollectPointExchangeMoneyCommon,3),4,1,now,0,"系统","收藏点兑换所得",0,0,0)
				 End IF
			Case 3
				Point=KS.ChkCLng(KS.S("Point3"))
				If Int(Point)<=0 Then
				   Response.Write "<script>alert('你输入的流量点不正确,必须大于0!');history.back();</script>"
				   Exit Sub
				End iF
				IF Int(RS("KS_FlowPoint"))<Int(Point) Then
				   Rs.Close:Set RS=Nothing
				   Response.Write "<script>alert('你可用流量点不足!');history.back();</script>"
				   Exit Sub
				End If
				 Call KS.FlowPointInOrOut(0,0,rs("UserName"),2,Int(Point),"系统","流量点兑换账户资金",0)
				 IF KS.ChkClng(rs("GroupID")) = UserGroupVipID Then	'是VIP会员
					 Call KS.MoneyInOrOut(rs("UserName"),rs("RealName"),Round(point*FlowPointExchangeMoneyVIP,3),4,1,now,0,"系统","流量点兑换所得",0,0,0)
				 Else
					 Call KS.MoneyInOrOut(rs("UserName"),rs("RealName"),Round(point*FlowPointExchangeMoneyCommon,3),4,1,now,0,"系统","流量点兑换所得",0,0,0)
				 End IF
		End Select
		RS.Close:Set RS=Nothing
		Response.Write "<script>alert('恭喜您，账户资金兑换成功!');location.href='User_ExChange.asp?Action=Money';</script>"
	   End Sub
	   
	   	   
	   Sub ExchangeEdays()
	    %>
	   <script>
	     function Confirm()
		 {
		   var str='友情提醒:\n';
		   if (document.myform.ChangeType[0].checked==true){
		     if (parseFloat(document.myform.Premoney.value)<parseFloat(document.myform.Money.value)){
			   alert('您目前资金余额不足，请充值后再来兑换！');
			   return false;
			   }
		    str+='兑换前资金：'+document.myform.Premoney.value+' 元\n';
			str+='兑换后资金：'+(document.myform.Premoney.value-document.myform.Money.value)+' 元\n';
			str+='一旦兑换成功即不可逆，确定兑换吗？';
		   }else{
		   if (parseInt(document.myform.PreScore.value)<parseInt(document.myform.Score.value)){
			   alert('您目前可用积分不足，不能兑换！');
			   return false;
			   }
		    str+='兑换前积分：'+document.myform.PreScore.value+' 分\n';
			str+='兑换后积分：'+(document.myform.PreScore.value-document.myform.Score.value)+' 分\n';
			str+='一旦兑换成功即不可逆，确定兑换吗？';
		   }
		   if (confirm(str)){
		    return true}
		   else{ return false}
		 }
	   </script>
		<FORM name=myform action="User_Exchange.asp" method="post">
		  <table class=border cellSpacing=1 cellPadding=2 width="100%" align=center border=0>
			<tr class=title>
			  <td align=middle colSpan=2 height=22><B> 兑 换 VIP 有 效 期</B></td>
			</tr>
			<tr class=tdbg>
			  <td align=right width=120>用户名：</td>
			  <td><%=KSUser.UserName%></td>
			</tr>
			<tr class=tdbg>
			  <td align=right width=120>资金余额：</td>
			  <td><input type='hidden' value='<%=KSUser.GetUserInfo("Money")%>' name='Premoney'><%=Formatnumber(KSUser.GetUserInfo("Money"),2,-1,0,-1)%> 元</td>
			</tr>
			<tr class=tdbg>
			  <td align=right width=120>可用积分：</td>
			  <td><input type='hidden' value='<%=KSUser.GetUserInfo("Score")%>' name='PreScore'><%=KSUser.GetUserInfo("Score")%> 分</td>
			</tr>
			<tr class=tdbg>
			  <td align=right width=120>剩余天数：</td>
			  <td>
			  <%if KSUser.ChargeType=3 Then%>
			  无限期
			  <%else%>
			  <%=KSUser.GetEdays%>&nbsp;天
			  <%end if%></td>
			</tr>
			<tr class=tdbg>
			  <td align=right width=120>兑换点券：</td>
			  <td>
			  <%If Mid(KS.Setting(170),3,1)="1" Then%>
		  <Input type=radio CHECKED value="1" name="ChangeType">使用资金余额： 将 
		  <Input style="TEXT-ALIGN: center" maxLength=8 size=6 value=100 name="Money"> 元兑换成有效天数 &nbsp;&nbsp;&nbsp;&nbsp;<Font color=red>兑换比率：<%=KS.Setting(44)%>元 = 1天</Font> <br>
		  <%End If%>
		  <%If Mid(KS.Setting(170),4,1)="1" Then%>
		  <Input type=radio value="2" name="ChangeType"<%If Mid(KS.Setting(170),3,1)="0" Then response.write " checked"%>>使用经验积分： 将 
				<Input style="TEXT-ALIGN: center" maxLength=8 size=6 value=100 name="Score"> 分兑换成有效天数 &nbsp;&nbsp;&nbsp;&nbsp;<Font color=red>兑换比率：<%=KS.Setting(42)%>分 = 1天 </Font>
		  <%End If%>		
				</td>
			</tr>
			<tr class=tdbg>
			  <td align=middle colSpan=2 height=40>
		        <Input id=Action type=hidden value="SaveExchangeEdays" name="Action"> 
				<Input class="button" id=Submit type=submit value="执行兑换" onClick="return(Confirm())" name=Submit> </td>
			</tr>
		  </table>
		</FORM>
	   <%
	   End Sub
		
	   Sub SaveExchangeEdays()
	   	 Dim ChangeType:ChangeType=KS.ChkClng(KS.S("ChangeType"))
		  If ChangeType=1 And Mid(KS.Setting(170),3,1)="0" Then
			   Response.Write "<script>alert('对不起,没有开启资金换有效天数服务!');history.back();</script>"
			   Exit Sub
		  ElseIf ChangeType=1 And Mid(KS.Setting(170),4,1)="0" Then
			   Response.Write "<script>alert('对不起,没有开启经验积分换有效天数服务!');history.back();</script>"
			   Exit Sub
		  End If

		 Dim Money:Money=KS.S("Money")
		 Dim Score:Score=KS.ChkClng(KS.S("Score"))
		 Dim tmpDays,ValidDays,RS:Set RS=Server.CreateObject("ADODB.RECORDSET")
		 RS.Open "Select top 1 * From KS_User Where UserName='" & KSUser.UserName & "'",conn,1,3
		 If RS.Eof  Then
		   Rs.Close:Set RS=Nothing
		   Response.Write "<script>alert('出错啦!');history.back();</script>"
		   Exit Sub
		 End If
		 If ChangeType=1 Then
		    If KS.ChkClng(Money)=0 Then
			   Rs.Close:Set RS=Nothing
			   Response.Write "<script>alert('你输入的资金不正确,资金必须大于0!');history.back();</script>"
			   Exit Sub
			End iF
			If KS.ChkClng(Money)<KS.ChkClng(KS.Setting(44)) Then
			   Rs.Close:Set RS=Nothing
			   Response.Write "<script>alert('你输入的资金不正确,资金必须大于等于" & KS.Setting(44) &"!');history.back();</script>"
			   Exit Sub
			End If
		   IF Round(RS("Money"))<Round(Money) Then
			   Rs.Close:Set RS=Nothing
			   Response.Write "<script>alert('你可用资金不足，请充值后再来兑换!');history.back();</script>"
			   Exit Sub
		   End If
			    ValidDays=rs("Edays")
				tmpDays=ValidDays-DateDiff("D",rs("BeginDate"),now())
				if tmpDays>0 then
					rs("Edays")=rs("Edays")+Money/KS.Setting(44)
				else
					rs("BeginDate")=now
					rs("Edays")=Money/KS.Setting(44)
				end if
			RS.Update
			'  UserName,InOrOutFlag,Edays,User,Descript
			Call KS.EdaysInOrOut(rs("UserName"),1,Money/KS.Setting(44),"System","账户资金兑换所得")
			Call KS.MoneyInOrOut(rs("UserName"),rs("RealName"),Money,4,2,now,0,"System","用于兑换有效天数",0,0,0)
			

		 Else
		    If Score=0 Then
			   Rs.Close:Set RS=Nothing
			   Response.Write "<script>alert('你输入的积分不正确,积分必须大于0!');history.back();</script>"
			   Exit Sub
			End If
			If KS.ChkClng(Score)<KS.ChkClng(KS.Setting(42)) Then
			   Rs.Close:Set RS=Nothing
			   Response.Write "<script>alert('你输入的积分不正确,积分必须大于等于" & KS.Setting(42) &"!');history.back();</script>"
			   Exit Sub
			End If
		   IF KS.ChkClng(RS("Score"))<KS.ChkClng(Score) Then
			   Rs.Close:Set RS=Nothing
			   Response.Write "<script>alert('你可用积分不足，不能兑换!');history.back();</script>"
			   Exit Sub
		   End If
		    RS("Score")=RS("Score")-Score
			   ValidDays=rs("Edays")
				tmpDays=ValidDays-DateDiff("D",rs("BeginDate"),now())
				if tmpDays>0 then
					rs("Edays")=rs("Edays")+Score/KS.Setting(42)
				else
					rs("BeginDate")=now
					rs("Edays")=Score/KS.Setting(42)
				end if
			RS.Update
			'  UserName,InOrOutFlag,Edays,User,Descript
			Call KS.EdaysInOrOut(rs("UserName"),1,Score/KS.Setting(42),"System","积分兑换所得")
		 End IF
		 Response.Write "<script>alert('恭喜您，有效天数兑换成功!');location.href='User_ExChange.asp?Action=Edays';</script>"
		 RS.Close:Set RS=Nothing
	   End Sub
End Class
%> 
