作者 何书鹏
1 个管道 的构建 通过 耗费 2 秒

业绩看板优化

... ... @@ -60,9 +60,9 @@ class Dashboard extends Backend
->alias('o')
->join('store s', 's.id = o.store_id')
->where($where1)
->field('o.store_saler_id,s.store_name,o.saler_realname,count(1) total')
->field('o.store_saler_id,s.store_name,o.saler_realname,count(1) total,sum(o.order_price) total_price')
->group('o.store_saler_id')
->order('total desc')
->order('total_price desc')
->limit(10)
->select();
// 销售额为0的销售代表
... ... @@ -72,15 +72,16 @@ class Dashboard extends Backend
// $saler_list = \app\admin\model\StoreSaler::alias('ss')
// ->join('store s', 's.id = ss.store_id')
// ->where('ss.id', 'not in', $store_saler_id_arr)
// ->field('ss.id store_saler_id,s.store_name,ss.realname saler_realname,0 total')
// ->field('ss.id store_saler_id,s.store_name,ss.realname saler_realname,0 total,0 total_price')
// ->limit(10 - $saler_count)
// ->select();
// $top10 = array_merge($top10, $saler_list);
// }
$data['top10'] = [];
$data['top_ten'] = [];
foreach ($top10 as $v) {
$data['top10']['name'][] = $v['store_name'] . ' ' . $v['saler_realname'];
$data['top10']['value'][] = $v['total'];
$data['top_ten']['name'][] = $v['store_name'] . ' ' . $v['saler_realname'];
$data['top_ten']['total'][] = $v['total'];
$data['top_ten']['total_price'][] = $v['total_price'];
}
// 延保套餐占比
$data['package_rate'] = $this->model
... ...
... ... @@ -400,25 +400,21 @@
<div class="row" style="margin-bottom:5px;">
<section class="col-lg-6 connectedSortable">
<!-- Map box -->
<div class="box box-solid">
<div class="box-header">
<!-- tools box -->
<div class="pull-right box-tools">
</div>
<!-- /. tools -->
<i class="fa fa-map-marker"></i>
<h3 class="box-title">
销售代表业绩排名(TOP10)
</h3>
</div>
<div class="box-body">
<div id="simplebar-chart" style="height: 500px; width: 100%;"></div>
<!-- Custom tabs (Charts with tabs)-->
<div class="nav-tabs-custom charts-custom">
<!-- Tabs within a box -->
<ul class="nav nav-tabs pull-right">
<li class="active"><a href="#top-ten-total-chart" data-toggle="tab">订单数量(个)</a></li>
<li><a href="#top-ten-total-price-chart" data-toggle="tab">订单金额(元)</a></li>
<li class="pull-left header"><i class="fa fa-inbox"></i> 销售代表业绩排名(TOP10)</li>
</ul>
<div class="tab-content no-padding">
<!-- Morris chart - Sales -->
<div class="chart tab-pane active" id="top-ten-total-chart" style="position: relative; height: 500px; width: 100%;"></div>
<div class="chart tab-pane" id="top-ten-total-price-chart" style="position: relative; height: 500px; width: 100%;"></div>
</div>
</div>
<!-- /.box -->
</section>
<!-- right col -->
... ... @@ -428,26 +424,26 @@
<div class="nav-tabs-custom charts-custom">
<!-- Tabs within a box -->
<ul class="nav nav-tabs pull-right">
<li class="active"><a href="#line-chart" data-toggle="tab">已付款订单总数量(个)</a></li>
<li><a href="#area-chart" data-toggle="tab">已付款订单总金额(元)</a></li>
<li class="active"><a href="#order-total-chart" data-toggle="tab">已付款订单总数量(个)</a></li>
<li><a href="#order-total-price-chart" data-toggle="tab">已付款订单总金额(元)</a></li>
<li class="pull-left header"><i class="fa fa-inbox"></i> 月度订单、营业额走势图</li>
</ul>
<div class="tab-content no-padding">
<!-- Morris chart - Sales -->
<div class="chart tab-pane active" id="line-chart" style="position: relative; height: 230px;"></div>
<div class="chart tab-pane" id="area-chart" style="position: relative; height: 230px;"></div>
<div class="chart tab-pane active" id="order-total-chart" style="position: relative; height: 230px;"></div>
<div class="chart tab-pane" id="order-total-price-chart" style="position: relative; height: 230px;"></div>
</div>
</div>
<div class="nav-tabs-custom charts-custom">
<!-- Tabs within a box -->
<ul class="nav nav-tabs pull-right">
<li class="active"><a href="#pie-chart" data-toggle="tab">饼图</a></li>
<li class="active"><a href="#package-rate-chart" data-toggle="tab">饼图</a></li>
<!-- <li><a href="#bar-chart" data-toggle="tab">柱状图</a></li>-->
<li class="pull-left header"><i class="fa fa-inbox"></i> 延保套餐销售占比图</li>
</ul>
<div class="tab-content no-padding">
<!-- Morris chart - Sales -->
<div class="chart tab-pane active" id="pie-chart" style="position: relative; height: 230px;"></div>
<div class="chart tab-pane active" id="package-rate-chart" style="position: relative; height: 230px;"></div>
<div class="chart tab-pane" id="bar-chart" style="position: relative; height: 230px;"></div>
</div>
</div>
... ... @@ -459,7 +455,7 @@
<!-- /.row (main row) -->
<!--@formatter:off-->
<script>
var top10 = {:json_encode($top10)};
var top_ten = {:json_encode($top_ten)};
var line = {:json_encode($line)};
var package_rate = {:json_encode($package_rate)};
var package_rate_name = {:json_encode(array_column($package_rate,'name'))};
... ...
... ... @@ -12,7 +12,8 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form', 'template', 'echarts'
$('#sum2').text(data.sum2);
$('#count3').text(data.count3);
$('#count4').text(data.count4);
lineChart.setOption(
// 已付款订单总数量
orderTotalChart.setOption(
{
xAxis: {
data: data.line.month
... ... @@ -22,7 +23,8 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form', 'template', 'echarts'
}]
}
);
areaChart.setOption(
// 已付款订单总金额
orderTotalPriceChart.setOption(
{
xAxis: {
data: data.line.month
... ... @@ -32,26 +34,53 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form', 'template', 'echarts'
}]
}
);
pieChart.setOption(
{
legend: {
data: data.package_rate_name
},
series: [{
data: data.package_rate,
}]
}
);
myChart.setOption(
// 延保套餐销售占比图
var packageRateChartOption = {
legend: {
data: data.package_rate_name,
formatter: function(name) {
var data = packageRateChartOption.series[0].data;
console.log(data);
var total = 0;
var tarValue;
for (var i = 0; i < data.length; i++) {
total += data[i].value;
if (data[i].name == name) {
tarValue = data[i].value;
}
}
var v = tarValue;
var p = Math.round(((tarValue / total) * 100));
return `${name} ${v}订单 ${p}%`;
},
},
series: [{
data: data.package_rate,
}]
};
packageRateChart.setOption(packageRateChartOption);
// 销售代表业绩排名(TOP10)(订单数量)
TopTenTotalChart.setOption(
{
yAxis: [{
data: data.top10.name,
data: data.top_ten.name,
}],
series: [{
data: data.top10.value,
data: data.top_ten.total,
}]
}
)
);
// 销售代表业绩排名(TOP10)(订单金额)
TopTenTotalPriceChart.setOption(
{
yAxis: [{
data: data.top_ten.name,
}],
series: [{
data: data.top_ten.total_price,
}]
}
)
}
});
console.log(Echarts.version);
... ... @@ -67,7 +96,7 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form', 'template', 'echarts'
/*---------------------已付款订单总数量-------------------------*/
// 基于准备好的dom,初始化echarts实例(订单数量)
var lineChart = Echarts.init(document.getElementById('line-chart'), 'walden');
var orderTotalChart = Echarts.init(document.getElementById('order-total-chart'), 'walden');
// 指定图表的配置项和数据
var option = {
... ... @@ -100,11 +129,11 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form', 'template', 'echarts'
};
// 使用刚指定的配置项和数据显示图表。
lineChart.setOption(option);
orderTotalChart.setOption(option);
/*---------------------已付款订单总金额-------------------------*/
// 基于准备好的dom,初始化echarts实例
var areaChart = Echarts.init(document.getElementById('area-chart'), 'walden');
var orderTotalPriceChart = Echarts.init(document.getElementById('order-total-price-chart'), 'walden');
// 指定图表的配置项和数据
var option = {
... ... @@ -137,34 +166,35 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form', 'template', 'echarts'
};
// 使用刚指定的配置项和数据显示图表。
areaChart.setOption(option);
orderTotalPriceChart.setOption(option);
/*---------------------延保套餐销售占比图-------------------------*/
var pieChart = Echarts.init(document.getElementById('pie-chart'), 'walden');
var option = {
var packageRateChart = Echarts.init(document.getElementById('package-rate-chart'), 'walden');
var packageRateChartOption = {
tooltip: {
trigger: 'item',
formatter: '{b} {c}订单 {d}%'
},
// legend: {
// orient: 'vertical',
// left: 10,
// data: package_rate_name,
// formatter: function(name) {
// var data = option.series[0].data;
// var total = 0;
// var tarValue;
// for (var i = 0; i < data.length; i++) {
// total += data[i].value;
// if (data[i].name == name) {
// tarValue = data[i].value;
// }
// }
// var v = tarValue;
// var p = Math.round(((tarValue / total) * 100));
// return `${name} ${v}订单 ${p}%`;
// },
// },
legend: {
orient: 'vertical',
left: 10,
data: package_rate_name,
formatter: function(name) {
var data = packageRateChartOption.series[0].data;
console.log(data);
var total = 0;
var tarValue;
for (var i = 0; i < data.length; i++) {
total += data[i].value;
if (data[i].name == name) {
tarValue = data[i].value;
}
}
var v = tarValue;
var p = Math.round(((tarValue / total) * 100));
return `${name} ${v}订单 ${p}%`;
},
},
series: [
{
name: '访问来源',
... ... @@ -173,8 +203,8 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form', 'template', 'echarts'
avoidLabelOverlap: false,
label: {
normal: {
show: true,
formatter: '{b} {c}订单 {d}%'
show: false,
position: 'center'
},
emphasis: {
show: true,
... ... @@ -194,57 +224,11 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form', 'template', 'echarts'
]
};
// 使用刚指定的配置项和数据显示图表。
pieChart.setOption(option);
// var barChart = Echarts.init(document.getElementById('simplebar-chart'));
// option = {
// grid: {
// // 间距是 根据x、y轴计算的;假如都是0,x、y轴的label汉字就隐藏掉了。
// left: '25%', // 默认10%,给24就挺合适的。
// top: '10%',
// },
// xAxis: {
// type: 'value',
// axisLine: {
// lineStyle: {
// color: "#fff"
// }
// }
// },
// yAxis: {
// type: 'category',
// axisLine: {
// lineStyle: {
// color: "#fff"
// }
// },
// data: top10.name
// },
// series: [{
// data: top10.value,
// type: 'bar',
// itemStyle: {
// normal: {
// color: "#fff",
// opacity: 0.6,
// label: {
// show: true, //开启显示
// position: 'right', //在上方显示
// textStyle: { //数值样式
// color: "#fff",
// }
// }
// }
// },
// }]
// };
// // 使用刚指定的配置项和数据显示图表。
// barChart.setOption(option);
packageRateChart.setOption(packageRateChartOption);
/*---------------------销售代表业绩排名(TOP10)-------------------------*/
/*---------------------销售代表业绩排名(TOP10)(订单数量)-------------------------*/
// 基于准备好的dom,初始化echarts实例
var myChart = Echarts.init(document.getElementById('simplebar-chart'));
var TopTenTotalChart = Echarts.init(document.getElementById('top-ten-total-chart'));
var option = {
tooltip: {
... ... @@ -267,7 +251,7 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form', 'template', 'echarts'
yAxis: [
{
type: 'category',
data: top10.name,
data: top_ten.name,
axisTick:{show:false}, //不显示刻度线
axisLabel:{
color:"#000"
... ... @@ -286,7 +270,7 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form', 'template', 'echarts'
{
yAxisIndex:0,
type: 'bar',
data: top10.value,
data: top_ten.total,
// 修改第一条柱子的圆角
itemStyle:{
normal:{
... ... @@ -311,7 +295,78 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form', 'template', 'echarts'
};
// 使用刚指定的配置项和数据显示图表。
myChart.setOption(option);
TopTenTotalChart.setOption(option);
/*---------------------销售代表业绩排名(TOP10)(订单金额)-------------------------*/
// 基于准备好的dom,初始化echarts实例
var TopTenTotalPriceChart = Echarts.init(document.getElementById('top-ten-total-price-chart'));
var option = {
tooltip: {
trigger: 'axis',
axisPointer: {
type: 'shadow'
},
formatter: '{b} <br> {c} 元'
},
grid: {
left: '1%',
top: '5%',
right: '10%',
bottom: '5%',
containLabel: true
},
xAxis: {
show:false, //不显示x轴相关信息
},
yAxis: [
{
type: 'category',
data: top_ten.name,
axisTick:{show:false}, //不显示刻度线
axisLabel:{
color:"#000"
},
axisTick:{
show:false
},
axisLine:{
show:false
},
inverse:true
},
],
series: [
{
yAxisIndex:0,
type: 'bar',
data: top_ten.total_price,
// 修改第一条柱子的圆角
itemStyle:{
normal:{
barBorderRadius:20,
color: '#0772E3'
},
// color 可以修改柱子的颜色
// color:"orange"
},
// 柱子之间的间距
barCategoryGap:5,
// 柱子之间的宽度
barWidth:20,
// 显示柱子内的文字
label:{
show:true,
position:"right",
// {c} 会自动解析为data中的数据
}
}
]
};
// 使用刚指定的配置项和数据显示图表。
TopTenTotalPriceChart.setOption(option);
}
};
return Controller;
... ...