<!--#include file="conn.asp"-->
<!--#include file="adminset.asp"-->
<%if session("admin")="" then
response.Write "<script language='javascript'>alert('网络超时或您还没有登陆！');window.location.href='login.asp';</script>"
response.End
end if
if session("flag")>1 then
response.Write "<div align=center><font size=80 color=red><b>您没有此项目管理权限！</b></font></div>"
response.End
end if
if qx2<>1 then
response.Write "<div align=center><font size=80 color=red><b>您没有此项目管理权限！</b></font></div>"
response.End
end if

day1=trim(Request.Form("year1fx"))&"-"&trim(Request.Form("month1fx"))&"-"&trim(Request.Form("day1fx"))
day2=trim(Request.Form("year2fx"))&"-"&trim(Request.Form("month2fx"))&"-"&trim(Request.Form("day2fx"))

year1=trim(Request.Form("year1fx"))
month1=trim(Request.Form("month1fx"))
year2=trim(Request.Form("year2fx"))
month2=trim(Request.Form("month2fx"))
'day1="#"&trim(Request.Form("month1"))&"-"&trim(Request.Form("day1"))&"-"&trim(Request.Form("year1"))&"#"
'day2="#"&trim(Request.Form("month2"))&"-"&trim(Request.Form("day2"))&"-"&trim(Request.Form("year2"))&"#"
%>
<html>
<head>
<title>网软志成在线购物系统</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<link href="../css.css" rel="stylesheet" type="text/css">
<style type="text/css">
<!--
.STYLE1 {color: #FF0000}
body {
	margin-left: 0px;
	margin-top: 0px;
	margin-right: 0px;
}
-->
</style>
</head>

<body>
<table width="100%" border="0" cellpadding="0" cellspacing="0">
  <tr>
    <td width="1%" height="28">&nbsp;</td>
    <td width="99%"><table width="100%" border="0" cellspacing="0" cellpadding="5">
      <tr>
        <td width="77%" height="27" style="font-size:14px;color:#ffffff">&nbsp;<strong><font color="#000000">网软志成购物后台管理系统 &gt;&gt; 订单管理 &gt;&gt; 会员分析报表</font></strong></td>
        <td width="23%" style="font-size:14px;color:#ffffff"><span class="STYLE1">* 为必添项目</span></td>
      </tr>
    </table></td>
  </tr>
</table>
<br>
<table width="95%" border="0" align="center" cellpadding="0" cellspacing="0">
  <tr> 
<%
    ddzhl=0
	pjddl=0
	pjddje=0
    ddl=0
	dde=0
	ddqrl=0
	
    set rs=server.createobject("adodb.recordset")
	sql="select datediff(d,'"&day1&"','"&day2&"')"
	rs.open sql,conn,1,1
	daynum=rs(0)+1  '取得两时间段之间的天数
	sql="SELECT sum(1),sum(isnull(zonger,0)),sum(CASE WHEN zhuangtai<4 THEN 0 ELSE 1 END) FROM shop_action WHERE (datediff(d,fhsj,'"&day2&"')>=0) AND (datediff(d,'"&day1&"',fhsj)>=0)"
	if rs.state=1 then rs.close
	rs.open sql,conn,1,1
	if not rs.eof then
	    ddl=rs(0)      '定单量
		dde=rs(1)      '定单金额
	    pjddl=rs(0)/daynum   '客户平均定单量
		pjddje=rs(1)/daynum  '客户平均定单金额
		if rs(0)=0 then ddzhl=0 else ddzhl=rs(2)*100/rs(0) end if '定单转化率
        ddqrl=rs(2)         '定单确认量
	end if
    
    sql="select count(userid) from shop_user"
	if rs.state=1 then rs.close
	rs.open sql,conn,1,1
	hyl=rs(0)  '会员总数

	sql="SELECT count(distinct username) FROM shop_action WHERE (datediff(d,fhsj,'"&day2&"')>=0) AND (datediff(d,'"&day1&"',fhsj)>=0) and zhuangtai>=4"
	if rs.state=1 then rs.close
	rs.open sql,conn,1,1
	gmhyl=rs(0)  '购买的会员总数

	if hyl=0 then hygml=0 else hygml=gmhyl*100/hyl end if '会员购买率
	if hyl=0 then pjhyddl=0 else pjhyddl=ddl/hyl end if    '平均会员定单量
	if hyl=0 then pjhydde=0 else pjhydde=dde/hyl end if    '平均会员定单额
	if gmhyl=0 then pjhyddlgm=0 else pjhyddlgm=ddl/gmhyl end if    '平均会员定单量(参加购买的)
	if gmhyl=0 then pjhyddegm=0 else pjhyddegm=dde/gmhyl end if    '平均会员定单额(参加购买的)


	



%>
    <td height="32" bgcolor="#FFFFFF"><div align="center"><span id="title"><span class="STYLE1">统计分析 日期范围：<%=day1&"至"&day2%>
            </span>
      </span><font color="#000000"><span>
      <input type="button" class="go-wenbenkuang" name="Submit4" value="打 印" onClick="javascript:window.print()">
      </span></font> </div></td>
  </tr>
</table>
<table width="95%" border="0" align="center" cellpadding="3" cellspacing="1" bgcolor="#999999">
  <tr align="center" bgcolor="#F3F3F3" >
    <td width="20%">客户平均订单数量</td>
    <td width="30%"><%=pjddl%></td>
    <td width="20%">客户平均订单金额</td>
    <td width="30%"><%=pjddje%></td>
  </tr>
  <tr align="center" bgcolor="#F3F3F3" >
    <td width="20%">订单转化率</td>
    <td width="30%"><%=ddzhl%>%</td>
    <td width="20%">注册会员购买率</td>
    <td width="30%"><%=hygml%>%</td>
  </tr>
  <tr align="center" bgcolor="#F3F3F3" >
    <td width="20%">平均所有会员订单量</td>
    <td width="30%"><%=pjhyddl%></td>
    <td width="20%">平均所有会员订单金额</td>
    <td width="30%"><%=pjhydde%></td>
  </tr>
  <tr align="center" bgcolor="#F3F3F3" >
    <td width="20%">平均购买会员订单量</td>
    <td width="30%"><%=pjhyddlgm%></td>
    <td width="20%">平均购买会员订单金额</td>
    <td width="30%"><%=pjhyddegm%></td>
  </tr>
  <tr align="center" bgcolor="#F3F3F3" >
    <td colspan="4" align="right"><span id="xsfx" ></span>&nbsp;
        <input type="button" name="Submit" class="go-wenbenkuang" value="导入EXCEL" onClick="javascript:openexcel('<%=pjddl&","&pjddje&","&ddzhl&","&hygml&","&pjhyddl&","&pjhydde&","&pjhyddlgm&","&pjhyddegm&","%>');"></td>
  </tr>
</table>
<%
recordshow=Request.Form("recordcountfx")
pmfx=Request.Form("pmfx")
%>
<%
if pmfx="0" or pmfx="1" then
    sqlhydd="SELECT top "&recordshow&" username,count(*) num FROM shop_action WHERE (datediff(d,fhsj,'"&day2&"')>=0) AND (datediff(d,'"&day1&"',fhsj)>=0) GROUP BY username ORDER BY num DESC"
	if rs.state=1 then rs.close
	rs.open sqlhydd,conn,1,1
%>
<table width="95%" border="0" align="center" cellpadding="0" cellspacing="0">
  <tr>
    <td height="22" align="center"><span class="STYLE1">会员订单量排名</span></td>
  </tr>
</table>
<table width="95%" border="0" align="center" cellpadding="3" cellspacing="1" bgcolor="#999999">
  <tr align="center" bgcolor="#cccccc">
    <td width="50%">用户名</td>
    <td width="50%">订单量</td>
  </tr>
  <%
    while not rs.eof
%>
  <tr align="center" bgcolor="#F3F3F3">
    <td width="50%"><a href="listuser.asp?username=<%=rs(0)%>"><%=rs(0)%></a></td>
    <td width="50%"><%=rs(1)%></td>
  </tr>
  <%
	    rs.movenext
	wend
%>
  <tr align="center" bgcolor="#F3F3F3" >
    <td colspan="2" align="right"><span id="hydd" ></span>&nbsp;
        <input type="button" name="Submit" class="go-wenbenkuang" value="导入EXCEL" onClick="javascript:openhydd();"></td>
  </tr>
</table>
<%
end if
%>
<%
if pmfx="0" or pmfx="2" then
    sqlhygwe="SELECT top "&recordshow&" username,sum(isnull(zonger,0)) num FROM shop_action WHERE (datediff(d,fhsj,'"&day2&"')>=0) AND (datediff(d,'"&day1&"',fhsj)>=0) GROUP BY username ORDER BY num DESC"
	if rs.state=1 then rs.close
	rs.open sqlhygwe,conn,1,1
%>
<table width="95%" border="0" align="center" cellpadding="0" cellspacing="0">
  <tr>
    <td height="22" align="center"><span class="STYLE1">会员购物额排名</span></td>
  </tr>
</table>
<table width="95%" border="0" align="center" cellpadding="3" cellspacing="1" bgcolor="#999999">
  <tr align="center" bgcolor="#cccccc">
    <td width="50%">用户名</td>
    <td width="50%">购物额</td>
  </tr>
  <%
    while not rs.eof
%>
  <tr align="center" bgcolor="#F3F3F3">
    <td width="50%"><a href="listuser.asp?username=<%=rs(0)%>"><%=rs(0)%></a></td>
    <td width="50%"><%=round(rs(1),2)%></td>
  </tr>
  <%
	    rs.movenext
	wend
%>
  <tr align="center" bgcolor="#F3F3F3" >
    <td colspan="2" align="right"><span id="hygwe" ></span>&nbsp;
        <input type="button" name="Submit" class="go-wenbenkuang" value="导入EXCEL" onClick="javascript:openhygwe();"></td>
  </tr>
</table>
<%
end if
%>
<%
if pmfx="0" or pmfx="3" then
    sqlfwcs="SELECT top "&recordshow&" shopname, isnull(liulancount,0) num FROM wygkcn_shop  ORDER BY num DESC"
	if rs.state=1 then rs.close
	rs.open sqlfwcs,conn,1,1
%>
<table width="95%" border="0" align="center" cellpadding="0" cellspacing="0">
  <tr>
    <td height="22" align="center"><span class="STYLE1">商品访问次数排名</span></td>
  </tr>
</table>
<table width="95%" border="0" align="center" cellpadding="3" cellspacing="1" bgcolor="#999999">
  <tr align="center" bgcolor="#cccccc">
    <td width="50%">商品名称</td>
    <td width="50%">访问次数</td>
  </tr>
  <%
    while not rs.eof
%>
  <tr align="center" bgcolor="#F3F3F3">
    <td width="50%"><%=rs(0)%></td>
    <td width="50%"><%=round(rs(1),2)%></td>
  </tr>
  <%
	    rs.movenext
	wend
%>
  <tr align="center" bgcolor="#F3F3F3" >
    <td colspan="2" align="right"><span id="fwcs" ></span>&nbsp;
        <input type="button" name="Submit" class="go-wenbenkuang" value="导入EXCEL" onClick="javascript:openfwcs();"></td>
  </tr>
</table>
<%
end if
%>
<%
if pmfx="0" or pmfx="4" then
'    sqlfwcs="SELECT top "&recordshow&" shopname, isnull(liulancount,0) num FROM wygkcn_shop  ORDER BY num DESC"
	sqlcsdb="SELECT top "&recordshow&" wygkcn_shop.shopname, isnull(liulancount,0) num,sum(isnull(zonger,0)) sumnum FROM wygkcn_shop Left Outer Join  shop_action on shop_action.shopid=wygkcn_shop.shopid and (datediff(d,fhsj,'"&day2&"')>=0) AND (datediff(d,'"&day1&"',fhsj)>=0) group by wygkcn_shop.shopname,wygkcn_shop.liulancount ORDER BY num DESC"
	sqljedb="SELECT top "&recordshow&" wygkcn_shop.shopname, isnull(liulancount,0) num,sum(isnull(zonger,0)) sumnum FROM wygkcn_shop Left Outer Join  shop_action on shop_action.shopid=wygkcn_shop.shopid and (datediff(d,fhsj,'"&day2&"')>=0) AND (datediff(d,'"&day1&"',fhsj)>=0) group by wygkcn_shop.shopname,wygkcn_shop.liulancount ORDER BY sumnum DESC"
	set rsxs=server.createobject("adodb.recordset")

	if rs.state=1 then rs.close
	rs.open sqlcsdb,conn,1,1
	rsxs.open sqljedb,conn,1,1
%>
<table width="95%" border="0" align="center" cellpadding="0" cellspacing="0">
  <tr>
    <td height="22" align="center"><span class="STYLE1">商品访问次数与购买次数排名对比</span></td>
  </tr>
</table>
<table width="95%" border="0" align="center" cellpadding="3" cellspacing="1" bgcolor="#999999">
  <tr align="center" bgcolor="#f1f1f1">
    <td width="25%" bgcolor="#cccccc">商品名称(按访问次数排名)</td>
    <td width="25%" bgcolor="#cccccc">访问次数/销售额</td>
    <td width="25%" bgcolor="#cccccc">商品名称(按销售额排名)</td>
    <td width="25%" bgcolor="#cccccc">销售额/访问次数</td>
  </tr>
  <%
    while not rs.eof
%>
  <tr align="center" bgcolor="#F3F3F3">
    <td width="25%"><%=rs(0)%></td>
    <td width="25%" bgcolor="#F3F3F3"><%=rs(1)%> / <%=round(rs(2),2)%></td>
    <%
		  if not rsxs.eof then
		  %>
    <td width="25%" bgcolor="#F3F3F3"><%=rsxs(0)%></td>
    <td width="25%" bgcolor="#F3F3F3"><%=round(rsxs(2),2)%> / <%=rsxs(1)%></td>
    <%
		      rsxs.movenext   
		  else
		  %>
    <td width="25%" bgcolor="#F3F3F3"></td>
    <td width="25%" bgcolor="#F3F3F3"></td>
    <%
		  end if
		  %>
  </tr>
  <%
	    rs.movenext
	wend
%>
  <tr align="center" >
    <td bgcolor="#F3F3F3" colspan="4" align="right"><span id="csdb" ></span>&nbsp;
        <input type="button" name="Submit" class="go-wenbenkuang" value="导入EXCEL" onClick="javascript:opencsdb();"></td>
  </tr>
</table>
<%
end if
%>
<table width="95%" border="0" align="center" cellpadding="0" cellspacing="0">
  <tr bgcolor="#FFFFFF">
    <td height="22" colspan="5">
      <div align="center">
        <input type="button" name="Submit" class="go-wenbenkuang" value="返回" onClick="javascript:history.go(-1)">
        <font color="red"><span id="excelfile" ></span></font> </div></td>
  </tr>
</table>
<br>
<!--#include file="copyright.asp"-->
<p>&nbsp;</p>
<p>&nbsp;</p>
</body>
</html>
<script>
function openexcel(avalue){
    window.open("tjbb_result2_excel.asp?flag=XSFX&sql="+avalue);
}

function openhydd(){
    window.open("tjbb_result2_excel.asp?flag=HYDD&sql=<%=sqlhydd%>");
}
function openhygwe(){
    window.open("tjbb_result2_excel.asp?flag=HYGWE&sql=<%=sqlhygwe%>");
}
function openfwcs(){
    window.open("tjbb_result2_excel.asp?flag=FWCS&sql=<%=sqlfwcs%>");
}
function opencsdb(){
    window.open("tjbb_result2_excel.asp?flag=CSDB&sql=<%=sqlcsdb%>&sql1=<%=sqljedb%>");
}





</script>