<?php
require '../conn/conn.php';
require '../conn/function.php';
require 'admin_check.php';

$t1=getrs("select count(S_id) as S_count from sl_short","S_count");
$t2=getrs("select sum(O_money) as O_sum from sl_orders where O_state=1 and not O_title like '%账户充值%'","O_sum");
$t3=getrs("select count(M_id) as M_count from sl_member","M_count");
$t4=getrs("select sum(S_times) as S_sum from sl_short","S_sum");


for ($j=0;$j<=15;$j++){
  $sql="select sum(O_money) as money_total from sl_orders where O_state>0 and  DATE_FORMAT( O_time, '%Y-%m-%d' )='".date('Y-m-d', strtotime ("-".(15-$j)." day", time()))."'";
  $result = mysqli_query($conn, $sql);
  $row = mysqli_fetch_assoc($result);
  $m_all1=round($row["money_total"],2);
  if ($m_all1==""){
    $m_all1=0;
  }
    $info1=$info1.$m_all1.",";
  }

for ($j=0;$j<=15;$j++){
  $sql="select count(S_id) as S_count from sl_short where DATE_FORMAT( S_time, '%Y-%m-%d' )<='".date('Y-m-d', strtotime ("-".(15-$j)." day", time()))."'";
  $result = mysqli_query($conn, $sql);
  $row = mysqli_fetch_assoc($result);
  $m_all2=intval($row["S_count"]);
  if ($m_all2==""){
    $m_all2=0;
  }
    $info2=$info2.$m_all2.",";
  }

for ($j=0;$j<=15;$j++){
  $sql="select count(S_id) as S_count from sl_short where DATE_FORMAT( S_time, '%Y-%m-%d' )='".date('Y-m-d', strtotime ("-".(15-$j)." day", time()))."'";
  $result = mysqli_query($conn, $sql);
  $row = mysqli_fetch_assoc($result);
  $m_all3=intval($row["S_count"]);
  if ($m_all3==""){
    $m_all3=0;
  }
    $info3=$info3.$m_all3.",";
  }
?>
<!DOCTYPE html>
<html lang="zh">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no" />
<title>首页 - 后台管理</title>
<link rel="icon" href="../media/<?php echo $C_ico?>" type="image/ico">
<link href="../css/bootstrap.min.css" rel="stylesheet">
<link href="../css/materialdesignicons.min.css" rel="stylesheet">
<link href="../css/style.min.css" rel="stylesheet">
</head>
  
<body>
<div class="lyear-layout-web">
  <div class="lyear-layout-container">
	<?php require 'nav.php';?>
    <main class="lyear-layout-content">
      
      <div class="container-fluid">
        
        <div class="row">
          <div class="col-sm-6 col-lg-3">
            <div class="card bg-primary">
              <div class="card-body clearfix">
                <div class="pull-right">
                  <p class="h6 text-white m-t-0">短网址个数</p>
                  <p class="h3 text-white m-b-0"><?php echo $t1?>个</p>
                </div>
                <div class="pull-left"> <span class="img-avatar img-avatar-48 bg-translucent"><i class="mdi mdi-currency-cny fa-1-5x"></i></span> </div>
              </div>
            </div>
          </div>
          
          <div class="col-sm-6 col-lg-3">
            <div class="card bg-danger">
              <div class="card-body clearfix">
                <div class="pull-right">
                  <p class="h6 text-white m-t-0">订单总额</p>
                  <p class="h3 text-white m-b-0"><?php echo $t2?>元</p>
                </div>
                <div class="pull-left"> <span class="img-avatar img-avatar-48 bg-translucent"><i class="mdi mdi-account fa-1-5x"></i></span> </div>
              </div>
            </div>
          </div>
          
          <div class="col-sm-6 col-lg-3">
            <div class="card bg-success">
              <div class="card-body clearfix">
                <div class="pull-right">
                  <p class="h6 text-white m-t-0">会员数量</p>
                  <p class="h3 text-white m-b-0"><?php echo $t3?>个</p>
                </div>
                <div class="pull-left"> <span class="img-avatar img-avatar-48 bg-translucent"><i class="mdi mdi-arrow-down-bold fa-1-5x"></i></span> </div>
              </div>
            </div>
          </div>
          
          <div class="col-sm-6 col-lg-3">
            <div class="card bg-purple">
              <div class="card-body clearfix">
                <div class="pull-right">
                  <p class="h6 text-white m-t-0">访问次数</p>
                  <p class="h3 text-white m-b-0"><?php echo $t4?>次</p>
                </div>
                <div class="pull-left"> <span class="img-avatar img-avatar-48 bg-translucent"><i class="mdi mdi-comment-outline fa-1-5x"></i></span> </div>
              </div>
            </div>
          </div>
        </div>
        
        <div class="row">
          
          <div class="col-lg-6"> 
            <div class="card">
              <div class="card-header">
                <h4>订单统计</h4>
              </div>
              <div class="card-body">
                <canvas class="js-chartjs-bars"></canvas>
              </div>
            </div>
          </div>
          
          <div class="col-lg-6"> 
            <div class="card">
              <div class="card-header">
                <h4>短网址统计</h4>
              </div>
              <div class="card-body">
                <canvas class="js-chartjs-lines"></canvas>
              </div>
            </div>
          </div>
           
        </div>
<?php if(!checkauth()){?>
        <div class="row">
        	<div class="col-lg-12"><div class="card">
              <div class="card-header">
                <h4>授权提醒</h4>
              </div>
              <div class="card-body">
                当前版本为免费测试版，如果购买授权版，请联系QQ：450245869 微信：shanling1706
              </div>
            </div></div>
        </div>
<?php }?>
        
        
      </div>
      
    </main>
    <!--End 页面主要内容-->
  </div>
</div>


<script type="text/javascript" src="../js/jquery.min.js"></script>
<script type="text/javascript" src="../js/bootstrap.min.js"></script>
<script type="text/javascript" src="../js/perfect-scrollbar.min.js"></script>
<script type="text/javascript" src="../js/main.min.js"></script>

<script src="../js/bootstrap-notify.min.js"></script>
<script type="text/javascript" src="../js/lightyear.js"></script>
<script src="../js/jqPaginator.min.js" type="text/javascript"></script>
<script src="../js/help.js" type="text/javascript"></script>
<script src="../js/jconfirm/jquery-confirm.min.js"></script>

<!--图表插件-->
<script type="text/javascript" src="../js/Chart.js"></script>
<script type="text/javascript">
$(document).ready(function(e) {
    var $dashChartBarsCnt  = jQuery( '.js-chartjs-bars' )[0].getContext( '2d' ),
        $dashChartLinesCnt = jQuery( '.js-chartjs-lines' )[0].getContext( '2d' );
    
    var $dashChartBarsData = {
    labels: [<?php
            for($i=0;$i<=15;$i++){
              echo "'".date('m-d', strtotime ("-".(15-$i)." day", time()))."',";
            }
            ?>],
    datasets: [
      {
        label: '订单金额',
                borderWidth: 1,
                borderColor: 'rgba(0,0,0,0)',
        backgroundColor: 'rgba(51,202,185,0.5)',
                hoverBackgroundColor: "rgba(51,202,185,0.7)",
                hoverBorderColor: "rgba(0,0,0,0)",
        data: [<?php echo $info1?>]
      }
    ]
  };


    var $dashChartLinesData = {
    labels: [<?php
            for($i=0;$i<=15;$i++){
              echo "'".date('m-d', strtotime ("-".(15-$i)." day", time()))."',";
            }
            ?>],
    datasets: [
      {
        label: '短网址每日',
        data: [<?php echo $info3?>],
                    fill: false,
            borderWidth: 3,
            pointRadius: 4,
            borderColor: "#36a2eb",
            backgroundColor: "#36a2eb",
            pointBackgroundColor: "#36a2eb",
            pointBorderColor: "#36a2eb",
            pointHoverBackgroundColor: "#fff",
            pointHoverBorderColor: "#36a2eb",
      },{
        label: '短网址累积',
        data: [<?php echo $info2?>],
        fill: false,
            borderWidth: 3,
            pointRadius: 4,
            borderColor: "#ff6384",
            backgroundColor: "#ff6384",
            pointBackgroundColor: "#ff6384",
            pointBorderColor: "#ff6384",
            pointHoverBackgroundColor: "#fff",
            pointHoverBorderColor: "#ff6384",
      }
    ]
  };
    
    new Chart($dashChartBarsCnt, {
        type: 'bar',
        data: $dashChartBarsData
    });
    
    var myLineChart = new Chart($dashChartLinesCnt, {
        type: 'line',
        data: $dashChartLinesData,
    });
});
  var path=window.location.pathname;
  $("a").each(function(){
    if(path.indexOf($(this).attr("href"))!=-1){
      console.log($(this).attr("href"));
      $(this).parent("li").addClass("active");
      $(this).parent("li").parent("ul").parent("li").addClass("open active");
    }
  });
    </script>
</body>
</html>