控制器内容
/**
* 订单分析,数据统计
* author:咔咔
* time:2018.7.4
* @access public
*/
public function goodsanalysis(){
//获得展示类型
if($_GET['time_type']){
$time_type = $_GET['time_type'];
}else{
$time_type = 'day';
}
//获得月份
if($_GET['month']){
$month = $_GET['month'];
}else{
$month = date("m",time());
}
// 获取到当前的年份 2018
$years_time =date("Y",time()) ;
// 视图传过来的月份,跟当前年份拼接 string(7) "2018-07"
$oldtime = $years_time."-".$month;
/*
array(3) {
//当月第一天的时间戳
[0] => int(1530374400)
//当月最后一天的时间戳
[1] => int(1532966400)
//当月的天数
[2] => int(30)
}
*/
$time_interval = $this->getMonth($oldtime);
$data = array();
if($time_type=='day'){
// 循环每月的天数
for ($x=0; $x<=$time_interval['2']; $x++) {
// 从第一天到最后一天的时间戳
$time = $time_interval['0']+(86400*$x);
// 将第一天到最后一天的时间戳格式化 在视图底部输出日期
$data['time'][$x]=date("m/d",$time);
// 统计订单的查询条件
$where['is_pay'] = 1;
// $where['refund'] = 1;
$where['ctime'] = array(array('EGT',$time),array('ELT',($time+86400)),'AND');
// 订单的所有数量
$data['sales_sum'][$x]=M('goodsorder')->where($where)->count();
// 订单的总价
$data['saleroom'][$x]=M('goodsorder')->where($where)->sum('price');
// 当没有订单的时候总价为0
if($data['saleroom'][$x]==NULL){
$data['saleroom'][$x]=0;
}
}
}else{
for ($x=1; $x<=12; $x++) {
$time = $years_time."-".$x;
$time_interval = $this->getMonth($time);
$data['time'][$x]=$x."月";
$where['is_pay'] = 1;
// $where['refund'] = 1;
$where['ctime'] = array(array('EGT',$time_interval[0]),array('ELT',$time_interval[1]),'AND');
$data['sales_sum'][$x]=M('goodsorder')->where($where)->count();
$data['saleroom'][$x]=M('goodsorder')->where($where)->sum('price');
if($data['saleroom'][$x]==NULL){
$data['saleroom'][$x]=0;
}
}
}
//将time 拼接字符串
// 将当月的所有天数转换为字符串
$time_str ="";
foreach($data['time'] as $k=>$v){
$time_str=$time_str."_".$v ;
}
// 截取第一个-
$time_str = substr($time_str,1);
//将销量拼接字符串
$sales_sum_str ="";
foreach($data['sales_sum'] as $k=>$v){
$sales_sum_str=$sales_sum_str."_".$v ;
}
$sales_sum_str = substr($sales_sum_str,1);
//将销售额拼接数组
$saleroom_str ="";
foreach($data['saleroom'] as $k=>$v){
$saleroom_str=$saleroom_str."_".$v ;
}
$saleroom_str = substr($saleroom_str,1);
$data['max_count'] =max($data['sales_sum']);
$data['max_salessum'] =max($data['saleroom']);
$data['saleroom'] = $saleroom_str;
$data['time'] =$time_str;
$data['sales_sum'] = $sales_sum_str;
$this->assign('data',$data);
$this->display();
}
/**
* 时间
* author:咔咔
* time:2018.7.4
* param string $data 当前的年份跟月份
*/
//获取月初和月末的时间戳
function getMonth($date){
// 获取到当月的第一天时间戳
$firstday = date("Y-m-01",strtotime($date));
// string(10) "2018-07-31" 获取到当月的最后天
$lastday = date("Y-m-d",strtotime("$firstday +1 month -1 day"));
// 将第一天转为时间戳
$firstday = strtotime($date);
// 最后一天转为时间戳
$lastday = strtotime($lastday);
// 获取当月天数
$day_sum = (($lastday - $firstday)/86400);
return array($firstday,$lastday,$day_sum);
}
修改过得html内容
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
</head>
<body>
<style type="text/css">
.pagination{
padding: 10px 0;
}
.pagination *{
margin-right:3px;
padding: 5px 10px;
}
.pagination a{
border:1px solid #337ab7;
border-radius: 3px;
}
.sousuo {
width: 263px;
}
.nr {
font-size: 10px;
color: #3F3F3F;
}
.tabledown{
width:10%;
margin-bottom:25px;
display:inline-block;
}
.tabletype{
display:inline-block;
margin-right:5px;
}
.tabletypeleft{
margin-left:20px;
}
</style>
<div class="mod">
<!-- 数据分析select -->
<div class="tabletype">报表类型</div>
<div class="tabledown">
<select name="" class="form-control" id="styleselect">
<option value="day" select>日报表</option>
<option value="years">月报表</option>
</select>
</div>
<div class="tabletype tabletypeleft">时间</div>
<div class="tabledown" id="month_div">
<select name="" class="form-control" id="month">
<for start="1" end="13" name="i">
<option value="{$i}">{$i}月</option>
</for>
</select>
</div>
<div class="tabledown" style="display:none" id="years_div">
<select name="" class="form-control" id="years_sum">
<option value="2018" select >2018年</option>
</select>
</div>
<!-- Bootstrap 的搜索按钮 -->
<button class="btn btn-primary" id="sales_report"><i class="icon-search"></i></button>
<!-- !!数据分析select -->
<br class="table-responsive">
<input type="hidden" name="field_name" id="max_count" value={$data['max_count']}>
<input type="hidden" name="field_name" id="max_salessum" value={$data['max_salessum']}>
<input type="hidden" name="field_name" id="saleroom" value={$data['saleroom']}>
<input type="hidden" name="field_name" id="time" value={$data['time']}>
<input type="hidden" name="field_name" id="sales_sum" value={$data['sales_sum']}>
<div id="container" style="height: 500px"></div>
<script type="text/javascript" src="http://echarts.baidu.com/gallery/vendors/echarts/echarts.min.js"></script>
<script type="text/javascript" src="http://echarts.baidu.com/gallery/vendors/echarts-gl/echarts-gl.min.js"></script>
<script type="text/javascript" src="http://echarts.baidu.com/gallery/vendors/echarts-stat/ecStat.min.js"></script>
<script type="text/javascript" src="http://echarts.baidu.com/gallery/vendors/echarts/extension/dataTool.min.js"></script>
<script type="text/javascript" src="http://echarts.baidu.com/gallery/vendors/echarts/map/js/china.js"></script>
<script type="text/javascript" src="http://echarts.baidu.com/gallery/vendors/echarts/map/js/world.js"></script>
<script type="text/javascript" src="http://api.map.baidu.com/api?v=2.0&ak=ZUONbpqGBsYGXNIYHicvbAbM"></script>
<script type="text/javascript" src="http://echarts.baidu.com/gallery/vendors/echarts/extension/bmap.min.js"></script>
<script type="text/javascript" src="http://echarts.baidu.com/gallery/vendors/simplex.js"></script>
<script type="text/javascript">
var dom = document.getElementById("container");
var myChart = echarts.init(dom);
var app = {};
//定义参数
var max_count=parseInt(document.getElementById("max_count").value)+parseInt(20);
var max_salessum=parseInt(document.getElementById("max_salessum").value)+parseInt(50);
var saleroom=document.getElementById("saleroom").value;
var time=document.getElementById("time").value;
var sales_sum=document.getElementById("sales_sum").value;
option = null;
var data_time = time.split("_");
var data_sales_sum = sales_sum.split("_");
var data_saleroom = saleroom.split("_");
app.title = '折柱混合';
option = {
tooltip: {
trigger: 'axis',
axisPointer: {
type: 'cross',
crossStyle: {
color: '#999'
}
}
},
toolbox: {
feature: {
dataView: {show: true, readOnly: false},
magicType: {show: true, type: ['line', 'bar']},
restore: {show: true},
saveAsImage: {show: true}
}
},
legend: {
data:[,'销售数量','销售总额']
},
xAxis: [
{
type: 'category',
data: data_time,
axisPointer: {
type: 'shadow'
}
}
],
yAxis: [
{
type: 'value',
name: '数量',
min: 0,
max: max_count,
interval: Math.ceil(max_count/5),
axisLabel: {
formatter: '{value} 件'
}
},
{
type: 'value',
name: '总额',
min: 0,
max: max_salessum,
interval: Math.ceil(max_salessum/5),
axisLabel: {
formatter: '{value} 元'
}
}
],
series: [
{
name:'销售数量',
type:'bar',
data:data_sales_sum
},
{
name:'销售总额',
type:'line',
yAxisIndex: 1,
data:data_saleroom
}
]
};
;
if (option && typeof option === "object") {
myChart.setOption(option, true);
}
$("#styleselect").change(function(){
var opt=$("#styleselect").val();
if(opt=="day"){
$("#years_div").attr("style","display:none;");
$("#month_div").attr("style","display:inline-block;");
}else{
$("#years_div").attr("style","display:inline-block;");
$("#month_div").attr("style","display:none;");
}
});
$("#sales_report").click(function(){
var time_type = $("#styleselect").val();
if(time_type =="day"){
var month = $("#month").val();
}
window.location.href="index.php?s=/addon/WeiuidStore/web/analysis/time_type/"+time_type+"/month/"+month;
})
</script>
</div>
</div>
</div>
</body>
</html>
本身自带的html文件
<extend name="./App/Common/View/default/Base/common.html" />
<block name="main_content">
<include file="./App/Common/View/default/Public/crumb.html" />
<style type="text/css">
.pagination{
padding: 10px 0;
}
.pagination *{
margin-right:3px;
padding: 5px 10px;
}
.pagination a{
border:1px solid #337ab7;
border-radius: 3px;
}
.sousuo {
width: 263px;
}
.nr {
font-size: 10px;
color: #3F3F3F;
}
.tabledown{
width:10%;
margin-bottom:25px;
display:inline-block;
}
.tabletype{
display:inline-block;
margin-right:5px;
}
.tabletypeleft{
margin-left:20px;
}
</style>
<div class="mod">
<div class="mod-head">
<h3>
<include file="./App/Common/View/default/Public/nav.html" />
</h3>
</div>
<div class="mod-body tab-content">
<if condition="$tip">
<div class="alert alert-info tip" role="alert">{$tip}</div>
</if>
<include file="./App/Common/View/default/Public/search.html" />
<div class="tab-pane active" id="list">
<if condition="$subnav">
<ul class="nav nav-tabs">
<volist name="subnav" id="vo">
<li role="presentation" class="{$vo.class}"><a href="{$vo.url}">{$vo.title}</a></li>
</volist>
</ul>
<br>
</if>
<br>
<!-- 数据分析select -->
<div class="tabletype">报表类型</div>
<div class="tabledown">
<select name="" class="form-control" id="styleselect">
<option value="day" select>日报表</option>
<option value="years">月报表</option>
</select>
</div>
<div class="tabletype tabletypeleft">时间</div>
<div class="tabledown" id="month_div">
<select name="" class="form-control" id="month">
<for start="1" end="13" name="i">
<option value="{$i}">{$i}月</option>
</for>
</select>
</div>
<div class="tabledown" style="display:none" id="years_div">
<select name="" class="form-control" id="years_sum">
<option value="2018" select >2018年</option>
</select>
</div>
<button class="btn btn-primary" id="sales_report"><i class="icon-search"></i></button>
<!-- !!数据分析select -->
<br class="table-responsive">
<input type="hidden" name="field_name" id="max_count" value={$data['max_count']}>
<input type="hidden" name="field_name" id="max_salessum" value={$data['max_salessum']}>
<input type="hidden" name="field_name" id="saleroom" value={$data['saleroom']}>
<input type="hidden" name="field_name" id="time" value={$data['time']}>
<input type="hidden" name="field_name" id="sales_sum" value={$data['sales_sum']}>
<div id="container" style="height: 500px"></div>
<script type="text/javascript" src="http://echarts.baidu.com/gallery/vendors/echarts/echarts.min.js"></script>
<script type="text/javascript" src="http://echarts.baidu.com/gallery/vendors/echarts-gl/echarts-gl.min.js"></script>
<script type="text/javascript" src="http://echarts.baidu.com/gallery/vendors/echarts-stat/ecStat.min.js"></script>
<script type="text/javascript" src="http://echarts.baidu.com/gallery/vendors/echarts/extension/dataTool.min.js"></script>
<script type="text/javascript" src="http://echarts.baidu.com/gallery/vendors/echarts/map/js/china.js"></script>
<script type="text/javascript" src="http://echarts.baidu.com/gallery/vendors/echarts/map/js/world.js"></script>
<script type="text/javascript" src="http://api.map.baidu.com/api?v=2.0&ak=ZUONbpqGBsYGXNIYHicvbAbM"></script>
<script type="text/javascript" src="http://echarts.baidu.com/gallery/vendors/echarts/extension/bmap.min.js"></script>
<script type="text/javascript" src="http://echarts.baidu.com/gallery/vendors/simplex.js"></script>
<script type="text/javascript">
var dom = document.getElementById("container");
var myChart = echarts.init(dom);
var app = {};
//定义参数
var max_count=parseInt(document.getElementById("max_count").value)+parseInt(20);
var max_salessum=parseInt(document.getElementById("max_salessum").value)+parseInt(50);
var saleroom=document.getElementById("saleroom").value;
var time=document.getElementById("time").value;
var sales_sum=document.getElementById("sales_sum").value;
option = null;
var data_time = time.split("_");
var data_sales_sum = sales_sum.split("_");
var data_saleroom = saleroom.split("_");
app.title = '折柱混合';
option = {
tooltip: {
trigger: 'axis',
axisPointer: {
type: 'cross',
crossStyle: {
color: '#999'
}
}
},
toolbox: {
feature: {
dataView: {show: true, readOnly: false},
magicType: {show: true, type: ['line', 'bar']},
restore: {show: true},
saveAsImage: {show: true}
}
},
legend: {
data:[,'销售数量','销售总额']
},
xAxis: [
{
type: 'category',
data: data_time,
axisPointer: {
type: 'shadow'
}
}
],
yAxis: [
{
type: 'value',
name: '数量',
min: 0,
max: max_count,
interval: Math.ceil(max_count/5),
axisLabel: {
formatter: '{value} 件'
}
},
{
type: 'value',
name: '总额',
min: 0,
max: max_salessum,
interval: Math.ceil(max_salessum/5),
axisLabel: {
formatter: '{value} 元'
}
}
],
series: [
{
name:'销售数量',
type:'bar',
data:data_sales_sum
},
{
name:'销售总额',
type:'line',
yAxisIndex: 1,
data:data_saleroom
}
]
};
;
if (option && typeof option === "object") {
myChart.setOption(option, true);
}
$("#styleselect").change(function(){
var opt=$("#styleselect").val();
if(opt=="day"){
$("#years_div").attr("style","display:none;");
$("#month_div").attr("style","display:inline-block;");
}else{
$("#years_div").attr("style","display:inline-block;");
$("#month_div").attr("style","display:none;");
}
});
$("#sales_report").click(function(){
var time_type = $("#styleselect").val();
if(time_type =="day"){
var month = $("#month").val();
}
window.location.href="index.php?s=/addon/WeiuidStore/web/analysis/time_type/"+time_type+"/month/"+month;
})
</script>
</div>
</div>
</div>
</block>