<!--#include file="../fy_inc/fy.User.asp"-->
 <!--#include file="../fy_inc/cls_pageview.asp"-->
<% 
	 dim  UserHS
    	Set UserHS = New ACT_User
	IF Cbool(UserHS.UserLoginChecked)=false then
	  echo "<script>top.location.href ='login.asp' ;</script>"
	  Response.end
	End If	
 
  %><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>会员中心</title>
<script language="JavaScript" src="main.js"></script>
 <link href="images/css.css" rel="stylesheet" type="text/css" />
 </head>
<body style="background-color:#fff">
<div id="head">
  <div id="logo"><a href="index.asp" alt=""><img src="images/logo_member.gif" alt="fycms"></a></div><div id="banner"></div>
</div>
<div id="membermenu">
<!--#include file="menu.asp"-->

</div>

<div id="main">
<div id="left">
  <div id="treemenu">
    <h5>信息管理</h5>
    <ul>
        <li><a href="logmoney.asp">资金明细</a></li>
		<li><a href="logpoint.asp">点券明细</a></li>
		<li><a href="logedays.asp">有效期明细</a></li>
 		<li><a href="card.asp">充值卡充值 </a></li>
		<li><a href="exchange.asp?Action=Point">兑换<%=fycms.fycms_Sys(24)%></a></li>
		<li><a href="exchange.asp?Action=Edays">兑换有效期</a></li>
		<li><a href="exchange.asp?Action=Money"><%=fycms.fycms_Sys(24)%>兑换账户资金</a></li>
     </ul>
  </div>
  <ol>
    <li class="local"><a href="<%= fycms.Domain%>">返回网站首页</a></li>
    <li class="exit"><a href="Checklogin.asp?Action=LoginOut">退出登录</a></li>
  </ol>
</div>
  <div id="right">

<p id="position"><strong>当前位置：</strong><a href="index.asp">会员中心</a> 充 值 卡 充 值  </p>
<div class="clear"></div>
<div class="clear"></div>

<table cellpadding="0" cellspacing="1" class="table_list">
<tr>
  <td bgcolor="#F7FCFF"><a href="card.asp">充值卡充值 </a>
				<a href="exchange.asp?Action=Point">兑换<%=fycms.fycms_Sys(24)%></a>
				<a href="exchange.asp?Action=Edays">兑换有效期</a>
                <a href="exchange.asp?Action=Money"><%=fycms.fycms_Sys(24)%>兑换账户资金</a>
				 </td>
</tr>
</table>
    <% 	
	Select Case fycms.S("Action")
		 Case "Point"
 		   Call ExchangePoint()
		 Case "Money" 
 		   Call ExchangeMoney()
		 Case "SaveMoney"
		   Call SaveMoney()
		 Case "SavePoint"
		   Call SavePoint()
		 Case "Edays"
 		    Call ExchangeEdays()
		 Case "SaveEdays"
		    Call SaveEdays()
	End Select
     
	
	   Sub SaveMoney()
		 Dim Point:Point=fycms.S("Point")

		    If Round(Point)<=0 Then
			   echo "<script>alert('你输入的" & fycms.fycms_Sys(24) & "不正确,必须大于0!');history.back();</script>"
			   Exit Sub
			End iF
			
			
		DIM RS:Set RS=Server.CreateObject("ADODB.RECORDSET")
		 RS.Open "Select top 1 * From User_fy Where UserID=" & UserHS.UserID & "",conn,1,1
		 If RS.Eof  Then
		   Rs.Close:Set RS=Nothing
		   echo "<script>alert('出错啦!');history.back();</script>"
		   Exit Sub
		 End If
		   IF Round(RS("Point"))<Round(Point) Then
			   Rs.Close:Set RS=Nothing
			   echo "<script>alert('你可用" & fycms.fycms_Sys(24) & "不足!');history.back();</script>"
			   Exit Sub
		   End If
 			 Call fycms.PointInOrOut(0,0,rs("UserID"),2,Round(Point),"System","用户兑换账户资金",0)
			 Call fycms.MoneyInOrOut(rs("UserID"),rs("RealName"),(point*fycms.fycms_Sys(22)),4,1,now,0,"System","点券兑换所得",0,0)
		 echo "<script>alert('恭喜您，账户资金兑换成功!');location.href='?Action=Money';</script>"
		 RS.Close:Set RS=Nothing
	   End Sub
	   


	   Sub SaveEdays()
	   	 Dim ChangeType:ChangeType=fycms.S("ChangeType")
		 Dim Money:Money=fycms.S("Money")
		 Dim Score:Score=ChkNumeric(fycms.S("Score"))
		 Dim tmpDays,ValidDays,RS:Set RS=Server.CreateObject("ADODB.RECORDSET")
		 RS.Open "Select * From User_fy Where UserID=" & UserHS.UserID & "",conn,1,3
		 If RS.Eof  Then
		   Rs.Close:Set RS=Nothing
		   echo "<script>alert('出错啦!');history.back();</script>"
		   Exit Sub
		 End If
		 If ChangeType=1 Then
		    If ChkNumeric(Money)=0 Then
			   Rs.Close:Set RS=Nothing
			   echo "<script>alert('你输入的资金不正确,资金必须大于0!');history.back();</script>"
			   Exit Sub
			End iF
			If ChkNumeric(Money)<ChkNumeric(fycms.fycms_Sys(23)) Then
			   Rs.Close:Set RS=Nothing
			   echo "<script>alert('你输入的资金不正确,资金必须大于等于" & fycms.fycms_Sys(23) &"!');history.back();</script>"
			   Exit Sub
			End If
		   IF Round(RS("Money"))<Round(Money) Then
			   Rs.Close:Set RS=Nothing
			   echo "<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/fycms.fycms_Sys(23)
				else
					rs("BeginDate")=now
					rs("Edays")=Money/fycms.fycms_Sys(23)
				end if
			RS.Update
 			Call fycms.EdaysInOrOut(rs("UserID"),1,Money/fycms.fycms_Sys(23),"System","账户资金兑换所得")
			Call fycms.MoneyInOrOut(rs("UserID"),rs("RealName"),Money,4,2,now,0,"System","用于兑换有效天数",0,0)
 		 Else
		    If Score=0 Then
			   Rs.Close:Set RS=Nothing
			   echo "<script>alert('你输入的积分不正确,积分必须大于0!');history.back();</script>"
			   Exit Sub
			End If
			If ChkNumeric(Score)<ChkNumeric(fycms.fycms_Sys(21)) Then
			   Rs.Close:Set RS=Nothing
			   echo "<script>alert('你输入的积分不正确,积分必须大于等于" & fycms.fycms_Sys(21) &"!');history.back();</script>"
			   Exit Sub
			End If
		   IF ChkNumeric(RS("Score"))<ChkNumeric(Score) Then
			   Rs.Close:Set RS=Nothing
			   echo "<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/fycms.fycms_Sys(21)
				else
					rs("BeginDate")=now
					rs("Edays")=Score/fycms.fycms_Sys(21)
				end if
			RS.Update
 			Call fycms.EdaysInOrOut(rs("UserID"),1,Score/fycms.fycms_Sys(21),"System","积分兑换所得")
		 End IF
		 echo "<script>alert('恭喜您，有效天数兑换成功!');location.href='?Action=Edays';</script>"
		 RS.Close:Set RS=Nothing
	   End Sub
	
	   Sub SavePoint()
	   
 	     Dim ChangeType:ChangeType=fycms.S("ChangeType")
		 Dim Money:Money=fycms.S("Money")
		 Dim Score:Score=ChkNumeric(fycms.S("Score"))
		 Dim RS:Set RS=Server.CreateObject("ADODB.RECORDSET")
		 RS.Open "Select * From User_fy Where UserID=" & UserHS.UserID & "",conn,1,1
		 If RS.Eof  Then
		   Rs.Close:Set RS=Nothing
		   echo "<script>alert('没有找到这个用户!');history.back();</script>"
		   Exit Sub
		 End If
		 If ChangeType=1 Then
		    If ChkNumeric(Money)=0 Then
			   Rs.Close:Set RS=Nothing
			   echo "<script>alert('你输入的资金不正确,资金必须大于0!');history.back();</script>"
			   Exit Sub
			End iF
			If ChkNumeric(Money)<ChkNumeric(fycms.fycms_Sys(22)) Then
			   Rs.Close:Set RS=Nothing
			   echo "<script>alert('你输入的资金不正确,资金必须大于等于" & fycms.fycms_Sys(22) &"!');history.back();</script>"
			   Exit Sub
			End If
		   IF Round(RS("Money"))<Round(Money) Then
			   Rs.Close:Set RS=Nothing
			   echo "<script>alert('你可用资金不足，请充值后再来兑换!');history.back();</script>"
			   Exit Sub
		   End If
 			Call fycms.PointInOrOut(0,0,rs("UserID"),1,Money/fycms.fycms_Sys(22),"System","账户资金兑换所得",0)
			Call fycms.MoneyInOrOut(rs("UserID"),rs("RealName"),Money,4,2,now,0,"System","用于兑换点券",0,0)
	
		 Else
		    If Score=0 Then
			   Rs.Close:Set RS=Nothing
			   echo "<script>alert('你输入的积分不正确,积分必须大于0!');history.back();</script>"
			   Exit Sub
			End If
			If ChkNumeric(Score)<ChkNumeric(fycms.fycms_Sys(20)) Then
			   Rs.Close:Set RS=Nothing
			   echo "<script>alert('你输入的积分不正确,积分必须大于等于" & fycms.fycms_Sys(20) &"!');history.back();</script>"
			   Exit Sub
			End If
		   IF ChkNumeric(RS("Score"))<ChkNumeric(Score) Then
			   Rs.Close:Set RS=Nothing
			   echo "<script>alert('你可用积分不足，不能兑换!');history.back();</script>"
			   Exit Sub
		   End If
		    RS("Score")=RS("Score")-Score
 			RS.Update
 			 Call fycms.PointInOrOut(0,0,rs("UserID"),1,Score/fycms.fycms_Sys(20),"System","积分兑换所得",0)
		 End IF
		 echo "<script>alert('恭喜您，点券兑换成功!');location.href='?Action=Point';</script>"
		 RS.Close:Set RS=Nothing
 	   End Sub
	   
	 
	    
 %>
			 
<% 		 
Sub ExchangePoint()
	   %>
	   <script>
	     function Confirm()
		 {
		   var str='友情提醒:\n';
		   if (document.myform.ChangeType[0].checked==true){
		     if (parseInt(document.myform.Premoney.value)<parseInt(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="?" method="post">
		  <table cellpadding="0" cellspacing="1" class="table_list">
			 <caption>兑 换 点 券 </caption>
			<tr>
			  <td align=right width=120>用户名：</td>
			  <td><%=UserHS.UserName%></td>
			</tr>
			<tr>
			  <td align=right width=120>资金余额：</td>
			  <td><input type='hidden' value='<%=UserHS.Money%>' name='Premoney'><%=UserHS.Money%> 元</td>
			</tr>
			<tr>
			  <td align=right width=120>可用积分：</td>
			  <td><input type='hidden' value='<%=UserHS.Score%>' name='PreScore'><%=UserHS.Score%> 分</td>
			</tr>
			<tr>
			  <td align=right width=120>可用<%=fycms.fycms_Sys(24)%>：</td>
			  <td><%=UserHS.Point%>&nbsp;<%=fycms.fycms_Sys(25)%></td>
			</tr>
			<tr>
			  <td align=right width=120>兑换点券：</td>
			  <td>
		  <label for="ChangeType1"><Input type=radio CHECKED value="1" id="ChangeType1" name="ChangeType">使用资金余额： 将 
		  <Input maxLength=8 size=6 value=100 name="Money"> 元兑换成<%=fycms.fycms_Sys(24)%> &nbsp;&nbsp;&nbsp;&nbsp;<Font color=red>兑换比率：<%=fycms.fycms_Sys(22)%>元:1<%=fycms.fycms_Sys(25)%></Font></label> <br>
		 <label for="ChangeType2"> <Input type=radio value="2" id="ChangeType2" name="ChangeType">使用经验积分： 将 
				 <Input   maxLength=8 size=6 value=100 name="Score"> 分兑换成<%=fycms.fycms_Sys(24)%> &nbsp;&nbsp;&nbsp;&nbsp;<Font color=red>兑换比率：<%=fycms.fycms_Sys(20)%>分:1<%=fycms.fycms_Sys(25)%> </Font></label> </td>
			</tr>
			<tr>
			  <td align=middle colSpan=2 height=40>
		        <Input id=Action type=hidden value="SavePoint" name="Action"> 
				<Input class="button_style" id=Submit type=submit value="执行兑换" onClick="return(Confirm())" name=Submit>
                 </td>
			</tr>
		  </table>
		</FORM>
	   <%
	   End Sub%>
	   
 	   
	  <% Sub ExchangeEdays()
	    %>
	   <script>
	     function Confirm()
		 {
		   var str='友情提醒:\n';
		   if (document.myform.ChangeType[0].checked==true){
		     if (parseInt(document.myform.Premoney.value)<parseInt(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="?" method="post">
		 <table cellpadding="0" cellspacing="1" class="table_list">
         <caption>兑 换 有 效 期</caption>
			 
			<tr >
			  <td align=right width=120>用户名：</td>
			  <td><%=UserHS.UserName%></td>
			</tr>
			<tr >
			  <td align=right width=120>资金余额：</td>
			  <td><input type='hidden' value='<%=UserHS.Money%>' name='Premoney'><%=UserHS.Money%> 元</td>
			</tr>
			<tr >
			  <td align=right width=120>可用积分：</td>
			  <td><input type='hidden' value='<%=UserHS.Score%>' name='PreScore'><%=UserHS.Score%> 分</td>
			</tr>
			<tr >
			  <td align=right width=120>剩余天数：</td>
			  <td>
			  <%if UserHS.ChargeType=3 Then%>
			  无限期
			  <%else%>
			  <%=UserHS.GetEdays%>&nbsp;天
			  <%end if%></td>
			</tr>
			<tr >
			  <td align=right width=120>兑换点券：</td>
			  <td>
		 <label for="ChangeType11"> <Input type=radio CHECKED value="1" name="ChangeType" id="ChangeType11">使用资金余额： 将 
		  <Input style="TEXT-ALIGN: center" maxLength=8 size=6 value=100 name="Money"> 元兑换成有效天数 &nbsp;&nbsp;&nbsp;&nbsp;<Font color=red>兑换比率：<%=fycms.fycms_Sys(23)%>元:1天</Font></label> <br>
		  <label for="ChangeType22"><Input type=radio value="2" name="ChangeType" id="ChangeType22">使用经验积分： 将 
				<Input style="TEXT-ALIGN: center" maxLength=8 size=6 value=100 name="Score"> 分兑换成有效天数 &nbsp;&nbsp;&nbsp;&nbsp;<Font color=red>兑换比率：<%=fycms.fycms_Sys(21)%>分:1天 </Font></label></td>
			</tr>
			<tr >
			  <td align=middle colSpan=2 height=40>
		        <Input id=Action type=hidden value="SaveEdays" name="Action"> 
				<Input class="button_style" id=Submit type=submit value="执行兑换" onClick="return(Confirm())" name=Submit> </td>
			</tr>
		  </table>
		</FORM>
	   <%
	   End Sub
		
   Sub ExchangeMoney()
	   %>
	   		<script>
	     function checkform()
		 {
		   var str='友情提醒:\n';
		     if (parseInt(document.myforms.Prepoint.value)<parseInt(document.myforms.Point.value)){
			   alert('对不起，你的<%=fycms.fycms_Sys(24)%>不足！');
			   return false;
			   }
		    str+='兑换前<%=fycms.fycms_Sys(24)%>：'+document.myforms.Prepoint.value+' <%=fycms.fycms_Sys(25)%>\n';
			str+='兑换后<%=fycms.fycms_Sys(24)%>：'+(document.myforms.Prepoint.value-document.myforms.Point.value)+' <%=fycms.fycms_Sys(25)%>\n';
			str+='一旦兑换成功即不可逆，确定兑换吗？';

		   if (confirm(str)){
		    return true}
		   else{ return false}
		 }
	   </script>
		<FORM name=myforms action="?" method="post">
		  <table cellpadding="0" cellspacing="1" class="table_list">
         <caption>兑 换 资 金</caption>
			<tr>
			  <td align=right width=120>用户名：</td>
			  <td><%=UserHS.UserName%></td>
			</tr>
			<tr>
			  <td align=right width=120>资金余额：</td>
			  <td><%=UserHS.Money%> 元</td>
			</tr>
			<tr>
			  <td align=right width=120>可用积分：</td>
			  <td><%=UserHS.Score%> 分</td>
			</tr>
			<tr>
			  <td align=right width=120>可用<%=fycms.fycms_Sys(24)%>：</td>
			  <td><%=formatnumber(UserHS.Point,2)%>&nbsp;<%=fycms.fycms_Sys(25)%><input type='hidden' value='<%=UserHS.Point%>' name='Prepoint'></td>
			</tr>
			<tr>
			  <td align=right width=120>兑换资金：</td>
			  <td>
		   将
		  <Input style="TEXT-ALIGN: center" maxLength=8 size=6 value=<%=ChkNumeric(UserHS.Point)%> name="Point"> <%=fycms.fycms_Sys(25)%><%=fycms.fycms_Sys(24)%>兑换成账户资金 &nbsp;&nbsp;&nbsp;&nbsp;<Font color=red>兑换比率：1<%=fycms.fycms_Sys(25)%>:<%=fycms.fycms_Sys(22)%>元</Font> <br>
		  </td>
			</tr>
			<tr>
			  <td align=middle colSpan=2 height=30>
		        <Input id=Action type=hidden value="SaveMoney" name="Action"> 
				<Input class="button_style" id=Submit type=submit value="执行兑换" onClick="return(checkform())" name=Submit> </td>
			</tr>
		  </table>
		</FORM>
	 
		
	   <%
	   End Sub
	   %>


 
   <script language="JavaScript" type="text/javascript">
function CheckForm()
{ var form=document.fycmsform;
  
	 if (form.CardNum.value=='')
    { alert("请输入充值卡卡号!!");   
	  form.CardNum.focus();    
	   return false;
    }

 if (form.CardPass.value=='')
    { alert("请输入充值卡密码!!!");   
	  form.CardPass.focus();    
	   return false;
    }
 		form.Submit1.value="正在提交数据,请稍等...";
		form.Submit1.disabled=true;	
 	    form.submit();
        return true;
	}

 
 
  </script>
 <span id="toggle_pannel" style="display:none;"></span>
<div class="clear"></div>
</div>
  </div> 
<!--#include file="foot.asp"-->
 
</body>
</html>