效果
很简单
1.获取数据
/**
* 获取每月统计金额
*/
public function get_all_total()
{
$now_time = time();
$now_year = date("Y");
$now_month = date("m");
$data = [];
//循环月份
for($i=1;$i<=12;$i++)
{
//如果大于当前月直接填0
if($i>$now_month)
{
$data[$i]['ms_total'] = 0;
$data[$i]['task_total'] = 0;
$data[$i]['deal_total'] = 0;
}
else
{
//获取这一月数据
$data[$i] = $this->get_current_total($now_year.'-'.$i);
}
}
//重新分配结果
$result = [];
foreach($data as $k => $v)
{
$result['data']['ms_total'][] = $v['ms_total']/1000;
$result['data']['task_total'][] = $v['task_total']/1000;
$result['data']['deal_total'][] = $v['deal_total']/1000;
}
$result['code'] = '00';
$this->ajaxReturn($result);
}
/**
* 获取当前月数据
* @param $ym 当前年月
*/
public function get_current_total($ym)
{
//获取当前月天数
$day_num = date('t',strtotime($ym));
//获取开始时间
$begin_time = strtotime($ym.'-'.'01');
//获取结束时间
$end_time = strtotime($ym.'-'.$day_num);
//获取3种交易统计数据
$ms_total = $this->get_ms_sale_total($begin_time,$end_time);//获取盈利
$task_total = $this->get_task_total($begin_time,$end_time);//获取任务盈利
$deal_total = $this->get_deal_total($begin_time,$end_time);//获取交易平台盈利
$result['ms_total'] = $ms_total;
$result['task_total'] = $task_total;
$result['deal_total'] = $deal_total;
return $result;
}
/**
* 获取妙手盈利
*/
private function get_ms_sale_total($begin_time,$end_time)
{
$model = D('DepositSale');
$where['status'] = 14;//系统自动完成
$where['sale_type'] = 6; //自营(会员月卡)
$where['order_mem_id'] = 0;
$where['create_time'] = array(array('gt',$begin_time),array('lt',$end_time));
$count = $model->where($where)->sum('order_total');
return $count;
}
/**
* 获取任务盈利
*/
private function get_task_total($begin_time,$end_time)
{
return 0;
}
/**
* 获取交易平台盈利
*/
private function get_deal_total($begin_time,$end_time){
return 0;
}
2.配置到本地即可
贴上前端代码
<script>
window.οnlοad=function () {
var url = '{:U("Statistics/get_all_total")}';
var callback = function (res) {
if(res.code=='00')
{
set_canvas(res.data);
}
};
$.get(url,callback);//获取当前年数据
}
</script>
<script>
//设置图标
function set_canvas(res) {
<!-- json数据格式配置统计图 -->
var json = {};
var title = {
text: '收入统计'
};
var subtitle = {
text: '统计当前月收入单位1000=1k'
};
var xAxis = {
categories: ['一月', '二月', '三月', '四月', '五月', '六月'
,'七月', '八月', '九月', '十月', '十一月', '十二月']
};
var yAxis = {
title: {
text: '收入金额'
},
plotLines: [{
value: 0,
width: 1,
color: '#808080'
}],
categories: [1,2,3,4],
};
var tooltip = {
valueSuffix: 'k'
}
var legend = {
layout: 'vertical',
align: 'right',
verticalAlign: 'middle',
borderWidth: 0
};
var series = [
{
name: 'xxxxxxx收入',
data: res.ms_total
},
{
name: '交易平台收入',
data: res.deal_total
},
{
name: '任务平台收入',
data: res.task_total
}
];
json.title = title;
json.subtitle = subtitle;
json.xAxis = xAxis;
json.yAxis = yAxis;
json.tooltip = tooltip;
json.legend = legend;
json.series = series;
$('#content').highcharts(json);
}
</script>
highcharts 教程文档点击打开链接