<!--#include file="conn.asp"-->
<!--#include file="INC/md5.asp"-->
<%
	'检查访问的来源是否合法
	call checkPrePage()
	
	'检查用户访问的权限
	call checkuser(1)


strM_ID=GetQueryString("id")
if GetQueryString("action")="save" then

	'1、计算使用月数
	Dim intMonths		'月数
	oldexpire=GetFormVariable("oldexpire")
	newexpire=GetFormVariable("year") & "-" & GetFormVariable("month") & "-" & GetFormVariable("day")
	intMonths=DateDiff("m",oldexpire,newexpire)
	intDays=DateDiff("d",oldexpire,newexpire)
	if intMonths=0 and intDays>0 then intMonths=1
	'if intMonths<0 then
		'ShowMsg "对不起，期限不能设置比原来的小，如果对此有问题请向总部反映，谢谢！"
	'end if

	if intMonths>0 then			'如果设置了使用期限，则要进行扣加款计算
		'++++++++++++++++++++++++++++扣加款开始+++++++++++++++++++++++++++++++++++
		'2、逐级扣加款
		'先扣除当事人钱
		intPay=Cdbl(GetFormVariable("txtWebPrice"))	'该扣用户的金额
		intMoney=Cdbl(GetFormVariable("hidMoney"))		'用户账号余额
		
		if intMoney<intPay then 
			ShowMsg "该用户账号没有足够的余额，设置使用期限失败！<br>提示：至少还需要缴 ￥" & (intPay-intMoney)
		end if
		
		
		'准备工作：取其代理价格
		strAgentID=GetFormVariable("hidAgent")

		'开始逐级扣加款
		Dim myAgent,myM_ID,myPay,strLC
		myAgent=strAgentID		'我的代理商
		myM_ID=strM_ID			'我的ID号
		myPay=intPay			'我要上缴的款额
		strLC="<-" & GetName(myM_ID)		'记录扣款流程
				
		Do While myAgent<>0
			'1、先扣我的款，并把款加到代理账上
			Call AutoBank(myM_ID,myAgent,(0-myPay),"扣款","自动：" & GetName(myAgent) & strLC)				'扣用户的款
			'Call AutoBank(myAgent,myM_ID,myPay,"付费","自动：" & GetName(myAgent) & strLC)				'将款打到代理商账号上
			strLC ="<-" & GetName(myAgent) & strLC			
			
			'准备下回循环
			myM_ID=myAgent
			myAgent=GetAgent(myM_ID)
			'如果代理商ID号为0，结束
			if myAgent=0 then
				exit Do
			end if
			
			AgentPrice=GetPrice(myM_ID)
			myPay=intMonths * AgentPrice
			
		Loop
		'++++++++++++++++++++++++++++扣加款结束+++++++++++++++++++++++++++++++++++
	end if
	strDLPrice=GetFormVariable("txtPrice")
	if strDLPrice="" then strDLPrice="0"	
	strSQL="Update member Set m_webprice=" & strDLPrice & ", m_expire='" & newexpire & "'  Where id=" & strM_ID
	conn.execute strSQL,0,1
end if

'---------------------------------------------------------------------------------------------
'---------------------------------------------------------------------------------------------
'获取代理价格
Function GetAgent(strID)
	set rsAgent=Server.CreateObject("ADODB.RecordSet")
	rsAgent.open "Select m_AgentName From member Where id=" & strID,conn,1,1
	GetAgent=rsAgent("m_AgentName")
End Function

'获取代理商的代理价格
Function GetPrice(strID)
	set rsPrice=Server.CreateObject("ADODB.RecordSet")
	rsPrice.open "Select m_webprice From member Where id=" & strID,conn,1,1
	GetPrice=rsPrice("m_webprice")
End Function

'获取用户名称
Function GetName(strID)
	set rsName=Server.CreateObject("ADODB.RecordSet")
	rsName.open "Select m_name From member Where id=" & strID,conn,1,1
	GetName=rsName("m_name")
End Function


'自动银行
Sub AutoBank(strM_ID,strAdminID,money,strType,strNote)

	'添加记录
	strSQL="Insert Into bank(m_id,b_adminid,b_money,b_type,b_note) Values("
	strSQL=strSQL & "" & strM_ID & ","
	strSQL=strSQL & "" & strAdminID & ","
	strSQL=strSQL & "" & money & ","
	strSQL=strSQL & "'" & strType & "',"
	strSQL=strSQL & "'" & strNote & "')"
	conn.execute strSQL,0,1
	
	'更新目标者余额
	strSQL="Update member Set m_money=m_money+" & Trim(money) & " Where id=" & strM_ID
	conn.execute strSQL,0,1
	
end Sub
%>
<%
strSQL="Select * from v_member_agent Where id=" & strM_ID
rs.open strSQL,conn,1,1
%>

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>电子商务自助建站--您理想的助手</title>
<link href="common/styleMain.css" rel="stylesheet" type="text/css">
<script language="JavaScript" src="common/JS_CheckForm.js"></script>
<script language="JavaScript">

function checksearch(theform){
	if (theform.txtkey.value==""){
		alert("请输入搜索关键字 ");
		return false;
	}
}


function checkform(theform){
	if (!CheckEmpty(theform.txtWebPrice, "续费金额"))	return false;
	if (!CheckReal(theform.txtWebPrice, "续费金额"))	return false;
	if (theform.txtPrice!=null){
		if (!CheckEmpty(theform.txtPrice, "代理价格"))		return false;
		if (!CheckReal(theform.txtPrice, "代理价格"))	return false;
	}
	
}

function init(){
	SelectValue(form1.year,"<%=year(rs("m_expire"))%>");
	SelectValue(form1.month,"<%=month(rs("m_expire"))%>");
	SelectValue(form1.day,"<%=day(rs("m_expire"))%>");
}
</script>
</head>
<body leftmargin="0" topmargin="0" onLoad="init()">
<table width="100%" height="100%" border="0" cellpadding="0" cellspacing="0">
  <tr>
    <td align="center"><table width="100%" height="100%" border="0" cellpadding="0" cellspacing="0">
        <tr> 
          <td height="0" align="center">
		  <!--#include file="common/top.asp"-->
          </td>
        </tr>
        <tr> 
          <td height="100%" align="center" valign="top">
<TABLE class=table002 cellSpacing=0 cellPadding=0 border=0>
              <TBODY>
                <TR> 
                  <!--左边开始-->
                  <TD width="20%" align=right vAlign=top> <!--#include file="common/adminleft.asp"--> </TD>
                  <!--左边结束-->
                  <TD width="2%" background="images/rowline.gif">&nbsp;</TD>
                  <!--右边开始-->
                  <TD vAlign=top align=center width="78%">
<table width="100%" border="0" cellspacing="0" cellpadding="0">
                      <tr> 
                        <td><form name="form1" method="post" action="?action=save&id=<%=strM_ID%>" onSubmit="return checkform(this)">
                            <TABLE width="100%" height="100%" border=0 cellPadding=6 cellSpacing=0>
                              <TBODY>
                                <TR> 
                                  <TD vAlign=top align=left bgColor=#ffffff><strong><font color="#FF0000">用户管理：<%=trim(rs("m_name"))%></font></strong><BR> <HR SIZE=1>
                                    <table width="98%" border="0" cellspacing="0" cellpadding="0">
                                      <tr> 
                                        <td height="25" align="center" valign="bottom"> 
                                          <table width="551" height="23" border="0" cellpadding="0" cellspacing="0">
                                            <tr align="center"> 
                                              <td width="30" valign="bottom">&nbsp;</td>
                                              <td width="88" bgcolor="#EEEEEE"><strong><a href="Admin_UserInfo.asp?id=<%=GetVariable("id")%>">基本资料</a></strong></td>
                                              <td width="17">&nbsp;</td>
                                              <td width="88" bgcolor="#5F8AC5"><strong><font color="#FFFFFF">财务相关</font></strong></td>
                                              <td width="17">&nbsp;</td>
                                              <td width="88" bgcolor="#EEEEEE"><a href="Admin_UserInfo2.asp?id=<%=GetVariable("id")%>"><strong>权限管理</strong></a></td>
                                              <td width="210">&nbsp;</td>
                                            </tr>
                                          </table></td>
                                      </tr>
                                      <tr> 
                                        <td height="1" bgcolor="#5F8AC5"></td>
                                      </tr>
                                      <tr> 
                                        <td><table width="100%" border="0" cellpadding="2" cellspacing="1" bgcolor="#5F8AC5">
                                            <tr> 
                                              <td height="30" align="center" bgcolor="#FFFFFF"> 
                                                <table width="98%" border="0" cellspacing="0" cellpadding="3">
                                                  <tr> 
                                                    <td height="30" colspan="2" align="center"><strong>与财务相关设置</strong>                                                    </td>
                                                  </tr>
                                                  <tr> 
                                                    <td width="25%" align="right" bgcolor="#F9F9F9">用户ID号：</td>
                                                    <td width="75%" bgcolor="#F9F9F9"><font color=#5E5E5E face=verdana><%=rs("id")%> 
                                                      <input name="hidCode" type="hidden" id="hidCode" value="<%=rs("m_Code")%>">
                                                      <input name="hidAgent" type="hidden" id="hidAgent" value="<%=rs("m_AgentName")%>">
                                                      <input name="hidMoney" type="hidden" id="hidMoney" value="<%=rs("m_money")%>">
                                                      </font></td>
                                                  </tr>
                                                  <tr> 
                                                    <td align="right">用户账号：</td>
                                                    <td><%=rs("m_name")%></td>
                                                  </tr>
                                                  <tr> 
                                                    <td align="right" valign="top" bgcolor="#F9F9F9"><strong><font color="#FF0000">使用期限：</font></strong></td>
                                                    <td valign="top" bgcolor="#F9F9F9"> 
                                                      截止 
                                                      <select name="year" id="year">
                                                        <%
														for i=year(date)-3 to year(date) + 5
														%>
                                                        <option value="<%=i%>"><%=i%></option>
                                                        <%next%>
                                                      </select>
                                                      年 
                                                      <select name="month" id="month">
                                                        <option value="1">1</option>
                                                        <option value="2">2</option>
                                                        <option value="3">3</option>
                                                        <option value="4">4</option>
                                                        <option value="5">5</option>
                                                        <option value="6">6</option>
                                                        <option value="7">7</option>
                                                        <option value="8">8</option>
                                                        <option value="9">9</option>
                                                        <option value="10">10</option>
                                                        <option value="11">11</option>
                                                        <option value="12">12</option>
                                                      </select>
                                                      月 
                                                      <select name="day" id="day">
                                                        <option value="1">1</option>
                                                        <option value="2">2</option>
                                                        <option value="3">3</option>
                                                        <option value="4">4</option>
                                                        <option value="5">5</option>
                                                        <option value="6">6</option>
                                                        <option value="7">7</option>
                                                        <option value="8">8</option>
                                                        <option value="9">9</option>
                                                        <option value="10">10</option>
                                                        <option value="11">11</option>
                                                        <option value="12">12</option>
                                                        <option value="13">13</option>
                                                        <option value="14">14</option>
                                                        <option value="15">15</option>
                                                        <option value="16">16</option>
                                                        <option value="17">17</option>
                                                        <option value="18">18</option>
                                                        <option value="19">19</option>
                                                        <option value="20">20</option>
                                                        <option value="21">21</option>
                                                        <option value="22">22</option>
                                                        <option value="23">23</option>
                                                        <option value="24">24</option>
                                                        <option value="25">25</option>
                                                        <option value="26">26</option>
                                                        <option value="27">27</option>
                                                        <option value="28">28</option>
                                                        <option value="29">29</option>
                                                        <option value="30">30</option>
                                                        <option value="31">31</option>
                                                      </select>
                                                      日 <font color="#FF0000"> 
                                                      <input name="oldexpire" type="hidden" id="oldexpire" value="<%=rs("m_expire")%>">
                                                      </font></td>
                                                  </tr>
                                                  <tr bgcolor="#F9F9F9"> 
                                                    <td align="right">续费金额：</td>
                                                    <td> 
                                                      <input name="txtWebPrice" type="text" id="txtWebPrice" value="0" size="10" maxlength="10">
                                                      <font color="#FF0000">[单位：￥]</font>                                                    </td>
                                                  </tr>
												  <%
												  if rs("m_code")>0 then
												  %>
                                                  <tr style="display:none"> 
                                                    <td align="right">代理价格：</td>
                                                    <td><input name="txtPrice" type="text" id="txtPrice" value="<%=rs("m_webprice")%>" size="10" maxlength="10">
                                                      <font color="#FF0000">[以月为单位，对代理商才设置此项]</font></td>
                                                  </tr>
												  <%end if%>
                                                  <tr bgcolor="#F9F9F9"> 
                                                    <td height="60" align="right">&nbsp;</td>
                                                    <td height="60"> <input type="submit" name="Submit" value="确 定">
                                                      　 
                                                      <input type="button" name="reset" value="放 弃" onClick="location='?id=<%=strM_ID%>'"></td>
                                                  </tr>
                                                  <tr bgcolor="#CCCCCC"> 
                                                    <td colspan="2">&nbsp;<strong>财务总账</strong></td>
                                                  </tr>
                                                  <%
												  '财务总账
												  '总付款
												  Dim AllPay
												  strSQL="Select Sum(b_money) as allpay From bank Where b_adminid=" & strM_ID & " And b_type='付费'"
												  Set rsBank=Server.CreateObject("ADODB.RecordSet")
												  rsBank.open strSQL,conn,1,1
												  AllPay=rsBank("allpay")
												  rsBank.close
												  
												  '总入帐款
												  Dim AllGet
												  strSQL="Select Sum(b_money) as AllGet From bank Where m_id=" & strM_ID & " And b_type='入账'"
												  Set rsBank=Server.CreateObject("ADODB.RecordSet")
												  rsBank.open strSQL,conn,1,1
												  AllGet=rsBank("AllGet")
												  rsBank.close
												  
												  '总退还款
												  Dim AllBack
												  strSQL="Select Sum(b_money) as AllBack From bank Where m_id=" & strM_ID & " And b_type='退款'"
												  Set rsBank=Server.CreateObject("ADODB.RecordSet")
												  rsBank.open strSQL,conn,1,1
												  AllBack=rsBank("AllBack")
												  rsBank.close
												  
												  '总扣款
												  Dim AllDeduct
												  strSQL="Select Sum(b_money) as AllDeduct From bank Where m_id=" & strM_ID & " And b_type='扣款'"
												  Set rsBank=Server.CreateObject("ADODB.RecordSet")
												  rsBank.open strSQL,conn,1,1
												  AllDeduct=rsBank("AllDeduct")
												  rsBank.close
												  
												  '最后付款时间
												  Dim LastTime
												  strSQL="Select Top 1 B_CreateTime From bank Where m_id=" & strM_ID & " And b_type='扣款' order by id desc"
												  Set rsBank=Server.CreateObject("ADODB.RecordSet")
												  rsBank.open strSQL,conn,1,1
												  if rsBank.recordcount>0 then
												  	LastTime=rsBank("B_CreateTime")
												   else
												  	LastTime="无记录"
												   end if
												  rsBank.close
												  
												  
												  %>
                                                  <tr> 
                                                    <td align="right" bgcolor="#F9F9F9">账号余款：</td>
                                                    <td bgcolor="#F9F9F9"><font color="#FF0000">&nbsp;￥ 
                                                      <%=rs("m_money")%></font></td>
                                                  </tr>
                                                  <tr>
                                                    <td align="right" bgcolor="#FFFFFF">入帐总额：</td>
                                                    <td bgcolor="#FFFFFF">&nbsp; <%=AllGet%></td>
                                                  </tr>
                                                  <tr bgcolor="#F9F9F9"> 
                                                    <td align="right">扣款总额：</td>
                                                    <td>&nbsp; <%=AllDeduct%></td>
                                                  </tr>
                                                  <tr>
                                                    <td align="right" bgcolor="#FFFFFF">退还总额：</td>
                                                    <td bgcolor="#FFFFFF">&nbsp; <%=AllBack%></td>
                                                  </tr>
                                                  <tr> 
                                                    <td align="right" bgcolor="#FFFFFF">最后付款时间：</td>
                                                    <td bgcolor="#FFFFFF">&nbsp;<%=LastTime%></td>
                                                  </tr>
                                                  <tr bgcolor="#F9F9F9"> 
                                                    <td height="28" align="right">&nbsp;</td>
                                                    <td height="28"> <a href="Admin_BankList1.asp?id=<%=strM_ID%>"><strong>[查看明细账] 
                                                      </strong></a> <a href="Admin_BankAdd.asp?id=<%=strM_ID%>&type=%CD%CB%BF%EE"><strong>[退还款]</strong></a></td>
                                                  </tr>
                                                </table></td>
                                            </tr>
                                          </table></td>
                                      </tr>
                                    </table> </TD>
                                </TR>
                              </TBODY>
                            </TABLE>
                          </form>
						 </td>
                      </tr>
                      <tr>
                        <td align="center"> 
                          <form action="Admin_User.asp?state=用户搜索：搜索结果" method="post" name="search" id="search" onSubmit="return checksearch(this)">
                            <table width="98%" border="0" cellpadding="2" cellspacing="1" bgcolor="#5F8AC5">
                              <tr> 
                                <td bgcolor="#5F8AC5">&nbsp<strong><font color="#FFFFFF">用户搜索</font></strong></td>
                              </tr>
                              <tr> 
                                <td height="40" align="center" bgcolor="F9F9F9"> 
                                  关键字： 
                                  <input name="txtkey" type=text id="txtkey" value="" size=30> 
                                  <select name="SchType">
                                    <option value="" selected>模糊查询</option>
                                    <option value="id" >用户ID</option>
                                    <option value="name" >单位域名</option>
                                    <option value="email" >email</option>
                                    <option value="oicq" >oicq</option>
                                  </select> <input type=submit name="submit" value="搜 索">
                                </td>
                              </tr>
                            </table>
                          </form></td>
                      </tr>
                    </table> 
                  </TD>
                </TR>
              </TBODY>
            </TABLE></td>
        </tr>
        <tr> 
          <td height="0" align="center">
		  <!--#include file="common/bottom.asp"-->
		  </td>
        </tr>
      </table></td>
  </tr>
</table>
</body>
</html>
