<?php
error_reporting(0); 
include("../conn.php");
include("../common.php");


session_start();
if(!isset($_SESSION['username'])){
echo "<script>alert('管理身份已失效请重新登录!')</script><script>top.location.href='index.php'</script>";
exit;
}
$username=ubo($_SESSION['username']);
$type="WHERE uid='$username'";
$duqu=queryall(admin,$type);
$uid=ubo($_GET["uid"]);
$btime=ubo($_GET["btime"]);
$sql1 = mysql_query("SELECT * FROM zhucema WHERE  recommend='$username'");
$row=mysql_fetch_array($sql1);
if($row[zdsl]!=""){echo "<script>location.href='index.php'</script>";}
?>
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="gb2312">
<title>订单列表</title>
<meta name="renderer" content="webkit">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="format-detection" content="telephone=no">
<link rel="stylesheet" href="css/layui.css" media="all">
<link rel="stylesheet" href="css/peizhi.css">
<script src='newui/js/jquery.min.js' type="text/javascript"></script>
<script src="newui/layui/layui.js"></script>
<script src='newui/js/myc.js' type="text/javascript"></script>
<script src="newui/js/bootstrap.min.js"></script>
</head>
<body>
<div class="layui-layout layui-layout-admin">
<div class="layui-body">
<!--tab标签-->
<div class="layui-tab layui-tab-brief">
<ul class="layui-tab-title">
<li class="layui-this"><a href="dingdan.php">订单列表[补偿不记入流水记录]</a></li>
</ul>
<div class="layui-tab-content">
<form class="layui-form layui-form-pane" action="" method="get">
<div class="layui-inline">
<label class="layui-form-label">代理</label>
<div class="layui-input-inline">
<input type="text" name="uid" value="<?php if($uid==null){ }else{ echo $uid;}?>" placeholder="请输入代理" class="layui-input">
</div>
</div>
<SCRIPT language=javascript src="../app/laydate/laydate.js" charset="utf-8"></SCRIPT>
<script>
!function(){
laydate.skin('molv');//切换皮肤，请查看skins下面皮肤库
laydate({elem: '#btime'});//绑定元素
}();
</script>
<div class="layui-inline">
<button class="layui-btn">搜索</button>
</div>
</form>
<hr>
<div class="layui-tab-item layui-show">
<table class="layui-table" lay-even="" lay-skin="row">
<?php 
$day=strtotime(date("Y-m-d"),time());
$jinri=$day + 86400;
$jinri=date("Y-m-d H:i:s",$jinri);
$zuori=$day - 86400;
$zuori=date("Y-m-d H:i:s",$zuori);
$day=date("Y-m-d H:i:s",$day);
if($uid){
$sql = "WHERE 1=1  and shijian>='$day' and shijian<'$jinri'";
$sql .=" and   recommend='$uid' ";
$sql2 = "WHERE 1=1  and shijian>='$zuori' and shijian<'$day'";
$sql2 .=" and   recommend='$uid' ";
$sql3 = "WHERE 1=1 ";
$sql3 .=" and   recommend='$uid' ";

}else{
$sql = "WHERE 1=1  and shijian>='$day' and shijian<'$jinri'";
$sql .=" and   recommend!='buchang' ";
$sql2 = "WHERE 1=1  and shijian>='$zuori' and shijian<'$day'";
$sql2 .=" and   recommend!='buchang' ";
$sql3 = "WHERE 1=1 ";
$sql3 .=" and   recommend!='buchang' ";
}

//今日订单总金额
$sqlt="select sum(rmb) from chongzhi   ".$sql." ";
if ($res=mysql_query($sqlt)){
list($money1)=mysql_fetch_row($res);
mysql_free_result($res);
} 
//昨日订单总金额
$sqlb="select sum(rmb) from chongzhi  ".$sql2." ";
if ($res=mysql_query($sqlb)){
list($money2)=mysql_fetch_row($res);
mysql_free_result($res);
} 
//今日订单
$sqlq = mysql_query("SELECT * FROM chongzhi  ".$sql."  ");
$daydd = mysql_num_rows($sqlq);
//昨日订单
$sqlx = mysql_query("SELECT * FROM chongzhi  ".$sql2." ");
$zdd = mysql_num_rows($sqlx);
//历史总订单
$sqle = mysql_query("SELECT * FROM chongzhi   ".$sql3."");
$z = mysql_num_rows($sqle);
//历史总金额
$sqlc="select sum(rmb) from chongzhi  ".$sql3." ";
if ($res=mysql_query($sqlc)){
list($money5)=mysql_fetch_row($res);
mysql_free_result($res);
} 
?>
<thead>
<tr>
<th align="center">今日总笔数</th>
<th align="center">昨日总笔数</th>
<th align="center">今日总金额</th>
<th align="center">昨日总金额</th>
<th align="center">历史总笔数</th>
<th align="center">历史总金额</th>
</tr>
</thead>
<tbody>
<tr>
<td align="center"><?php echo $daydd?> 笔</td>
<td align="center"><?php echo $zdd?> 笔</td>
<td align="center"><?php if($money1 == null){ ?>￥0元<?php }else{  ?>￥<?php $xs1=round($money1,2);echo $xs1;?> 元<?php } ?></td>
<td align="center"><?php if($money2 == null){ ?>￥0元<?php }else{  ?>￥<?php $xs1=round($money2,2);echo $xs1;?> 元<?php } ?></td>
<td align="center"><?php echo $z?> 笔</td>
<td align="center"><?php if($money5 == null){ ?>￥0元<?php }else{  ?>￥<?php $xs1=round($money5,2);echo $xs1;?> 元<?php } ?></td>
</tr>
</tbody>
</table>
<hr>
<table class="layui-table" lay-even="" lay-skin="row">
<thead>
<tr>
<th align="center" >订单号</th>
<th align="center" >所属代理</th>
<th align="center" >区服</th>
<th align="center" >角色名</th>
<th align="center" >充值金额</th>
<th align="center" >订单日期</th>
<th align="center" >状态</th>
<th align="center">操作</th>
</tr>
</thead>
<tbody>
<?php 
$Page_size=10; 
$sql = "WHERE recommend!='buchang' ";
if($uid){
$sql .=" and   recommend='$uid' ";
}else{
if($btime){
$sql .="   and shijian  like '%".$btime."%'";
}
}
$result = mysql_query("select count(1) from chongzhi   ".$sql."");
$count =mysql_fetch_array($result)[0];
if($count == 0){echo '<tr class="color2"><td colspan=10 align="center">查询不到数据</td></tr>';}
$Page_count = ceil($count/$Page_size); 
$init=1; 
$Page_len=7; 
$max_p=$Page_count; 
$Pages=$Page_count; 

//判断当前页码
if(empty($_GET['page'])||$_GET['page']<0){ 
$Page=1; 
}else { 
$Page=$_GET['page']; 
} 
$offset=$Page_size*($Page-1); 
$query = mysql_query("select * from chongzhi ".$sql." order by id desc   limit $offset, $Page_size");
while ($a=mysql_fetch_array($query)) { 
?> 
<tr>
<td align="center"><?php echo $a[orderid];?></td>
<td align="center"><?php echo $a[recommend]?></td>
<td align="center"><?php echo $a[server] ?> </td>
<td align="center"><?php echo $a[uid]?></td>
<td align="center"><?php echo $a[rmb]?></td>
<td align="center"><?php echo $a[shijian]?></td>
<td align="center"><?php echo $a[status];?></td>
<td align="center"></td>
<?php
//date("Y-m-d H:i:s",$a[orderid]);
} 
$Page_len = ($Page_len%2)?$Page_len:$Pagelen+1;//页码个数 
$Pageoffset = ($Page_len-1)/2;//页码个数左右偏移量 
$key.="<li><a class='number' >当前第 $Page 页/共 $Pages 页</a></li>"; //第几页,共几页 
if($Page!=1){ 
if($uid){
$key.="<li><a href=\"".$_SERVER['PHP_SELF']."?page=1&uid=$uid&btime=$btime\">&laquo;</a></li>"; //首页 
$key.="<li><a href=\"".$_SERVER['PHP_SELF']."?page=".($Page-1)."&uid=$uid&btime=$btime\">&lt;</a></li>"; //上一页 
}elseif($btime){
$key.="<li><a href=\"".$_SERVER['PHP_SELF']."?page=1&uid=$uid&btime=$btime\">&laquo;</a></li>"; //首页 
$key.="<li><a href=\"".$_SERVER['PHP_SELF']."?page=".($Page-1)."&uid=$uid&btime=$btime\">&lt;</a></li>"; //上一页 
}else {
$key.="<li><a href=\"".$_SERVER['PHP_SELF']."?page=1\">&laquo;</a></li>"; //首页 
$key.="<li><a href=\"".$_SERVER['PHP_SELF']."?page=".($Page-1)."\">&lt;</a></li>"; //上一页 
}
}else { 
$key.="<li><a>&laquo;</a> "; //首页 
$key.="<li><a >&lt;</a>"; //上一页  
} 
if($Pages>$Page_len){ 
//如果当前页小于等于左偏移 
if($Page<=$Pageoffset){ 
$init=1; 
$max_p = $Page_len; 
}else{//如果当前页大于左偏移 
//如果当前页码右偏移超出最大分页数 
if($Page+$Pageoffset>=$Pages+1){ 
$init = $Pages-$Page_len+1; 
}else{ 
//左右偏移都存在时的计算 
$init = $Page-$Pageoffset; 
$max_p = $Page+$Pageoffset; 
} 
} 
} 
for($i=$init;$i<=$max_p;$i++){ 
if($i==$Page){ 
$key.='<li class="active"><span>'.$i.'</span></li>'; 
} else { 
if($uid){
$key.="<li><a href=\"".$_SERVER['PHP_SELF']."?page=".$i."&uid=$uid&btime=$btime\">".$i."</a></li>"; 
}elseif($btime){
$key.="<li><a href=\"".$_SERVER['PHP_SELF']."?page=".$i."&uid=$uid&btime=$btime\">".$i."</a></li>"; 
} else { 
$key.="<li><a href=\"".$_SERVER['PHP_SELF']."?page=".$i."\">".$i."</a></li>"; 
}
} 
} 
if($Page!=$Pages){ 
if($uid){
$key.="<li><a href=\"".$_SERVER['PHP_SELF']."?page=".($Page+1)."&uid=$uid&btime=$btime\">&gt;</a></li> ";//下一页 
$key.="<li><a href=\"".$_SERVER['PHP_SELF']."?page={$Pages}&uid=$uid&btime=$btime\">&raquo;</a></li> "; //最后一页 
}elseif($btime){
$key.="<li><a href=\"".$_SERVER['PHP_SELF']."?page=".($Page+1)."&uid=$uid&btime=$btime\">&gt;</a></li> ";//下一页 
$key.="<li><a href=\"".$_SERVER['PHP_SELF']."?page={$Pages}&uid=$uid&btime=$btime\">&raquo;</a></li> "; //最后一页 
}else { 
$key.="<li><a href=\"".$_SERVER['PHP_SELF']."?page=".($Page+1)."\">&gt;</a></li> ";//下一页 
$key.="<li><a href=\"".$_SERVER['PHP_SELF']."?page={$Pages}\">&raquo;</a></li> "; //最后一页 
}
}else { 
$key.="<li>&gt;</li>";//下一页 
$key.="<li>&raquo;</li>"; //最后一页 
} 
$key.=''; 
?> 
</tbody>
</table>
<!--分页-->
<ul class="pagination">
<?php if($count =="0"){?><?php }else{?><?php echo $key?><?php }?>
</ul>
</div>
</div>
<?php include_once('footer.php');?>
</div>
</div>
   
</body>
</html>