后台数据统计优化

This commit is contained in:
Devil 2021-08-31 18:08:12 +08:00
parent a7b45d4f47
commit 4ffe6e67a2
7 changed files with 166 additions and 98 deletions

View File

@ -91,6 +91,10 @@ class Index extends Common
$default_day = '30-day'; $default_day = '30-day';
MyViewAssign('default_day', $default_day); MyViewAssign('default_day', $default_day);
// 收入统计权限
$is_income = AdminIsPower('index', 'income');
MyViewAssign('is_income', $is_income);
// 时间 // 时间
$time_data = StatisticalService::DateTimeList(); $time_data = StatisticalService::DateTimeList();
MyViewAssign('time_data', $time_data); MyViewAssign('time_data', $time_data);
@ -118,9 +122,12 @@ class Index extends Common
MyViewAssign('order_complete_number', $order_complete_number['data']); MyViewAssign('order_complete_number', $order_complete_number['data']);
// 订单收入总计 // 订单收入总计
if($is_income == 1)
{
$order_complete_money = StatisticalService::OrderCompleteMoneyYesterdayTodayTotal(); $order_complete_money = StatisticalService::OrderCompleteMoneyYesterdayTodayTotal();
MyViewAssign('order_complete_money', $order_complete_money['data']); MyViewAssign('order_complete_money', $order_complete_money['data']);
} }
}
return MyView(); return MyView();
} }

View File

@ -60,9 +60,19 @@
<span class="icon"></span> <span class="icon"></span>
<span class="title">商城统计</span> <span class="title">商城统计</span>
<a href="javascript:;" class="am-icon-question-circle am-text-warning" data-am-popover="{content: '时间筛选仅对总数有效', trigger: 'hover focus', theme: 'sm'}"></a> <a href="javascript:;" class="am-icon-question-circle am-text-warning" data-am-popover="{content: '时间筛选仅对总数有效', trigger: 'hover focus', theme: 'sm'}"></a>
{{include file="/index/stats_where" type="base-count" init="0" /}} <div class="am-fr right-operate" data-type="base-count" data-empty-time="1">
{{if !empty($time_data)}}
<span class="quick-time">
{{foreach $time_data as $k=>$v}}
<a href="javascript:;" data-start="{{$v.start}}" data-end="{{$v.end}}">{{$v.name}}</a>
{{/foreach}}
<a href="javascript:;" data-start="" data-end="">全部</a>
</span>
{{/if}}
{{include file="/index/stats_time" /}}
</div> </div>
<ul class="am-avg-sm-2 am-avg-lg-4"> </div>
<ul class="{{if isset($is_income) and $is_income eq true}}am-avg-sm-2 am-avg-lg-4{{else /}}am-avg-sm-1 am-avg-lg-3{{/if}}">
<li> <li>
<div class="li-content"> <div class="li-content">
<p class="name">用户总量</p> <p class="name">用户总量</p>
@ -132,6 +142,8 @@
<i class="am-icon-gg am-icon-lg bg-icon"></i> <i class="am-icon-gg am-icon-lg bg-icon"></i>
</div> </div>
</li> </li>
<!-- 收入统计权限判断 -->
{{if isset($is_income) and $is_income eq true}}
<li> <li>
<div class="li-content"> <div class="li-content">
<p class="name">收入总计</p> <p class="name">收入总计</p>
@ -155,6 +167,7 @@
<i class="am-icon-line-chart am-icon-lg bg-icon"></i> <i class="am-icon-line-chart am-icon-lg bg-icon"></i>
</div> </div>
</li> </li>
{{/if}}
</ul> </ul>
</div> </div>
@ -163,7 +176,16 @@
<div class="block-title echarts-title"> <div class="block-title echarts-title">
<span class="icon"></span> <span class="icon"></span>
<span class="title">订单成交金额走势</span> <span class="title">订单成交金额走势</span>
{{include file="/index/stats_where" type="order-profit" init="1" /}} <div class="am-fr right-operate" data-type="order-profit" data-init="1">
{{if !empty($time_data)}}
<span class="quick-time">
{{foreach $time_data as $k=>$v}}
<a href="javascript:;" data-start="{{$v.start}}" data-end="{{$v.end}}">{{$v.name}}</a>
{{/foreach}}
</span>
{{/if}}
{{include file="/index/stats_time" /}}
</div>
</div> </div>
<div id="echarts-order-profit"></div> <div id="echarts-order-profit"></div>
</div> </div>
@ -173,7 +195,16 @@
<div class="block-title echarts-title"> <div class="block-title echarts-title">
<span class="icon"></span> <span class="icon"></span>
<span class="title">订单交易走势</span> <span class="title">订单交易走势</span>
{{include file="/index/stats_where" type="order-trading" init="1" /}} <div class="am-fr right-operate" data-type="order-trading" data-init="1">
{{if !empty($time_data)}}
<span class="quick-time">
{{foreach $time_data as $k=>$v}}
<a href="javascript:;" data-start="{{$v.start}}" data-end="{{$v.end}}">{{$v.name}}</a>
{{/foreach}}
</span>
{{/if}}
{{include file="/index/stats_time" /}}
</div>
</div> </div>
<div id="echarts-order-trading"></div> <div id="echarts-order-trading"></div>
</div> </div>
@ -185,7 +216,17 @@
<div class="block-title echarts-title"> <div class="block-title echarts-title">
<span class="icon"></span> <span class="icon"></span>
<span class="title">热销商品</span> <span class="title">热销商品</span>
{{include file="/index/stats_where" type="goods-hot" init="1" /}} <div class="am-fr right-operate" data-type="goods-hot" data-init="1" data-empty-time="1">
{{if !empty($time_data)}}
<span class="quick-time">
{{foreach $time_data as $k=>$v}}
<a href="javascript:;" data-start="{{$v.start}}" data-end="{{$v.end}}">{{$v.name}}</a>
{{/foreach}}
<a href="javascript:;" data-start="" data-end="">全部</a>
</span>
{{/if}}
{{include file="/index/stats_time" /}}
</div>
</div> </div>
<div id="echarts-goods-hot"></div> <div id="echarts-goods-hot"></div>
</li> </li>
@ -195,7 +236,16 @@
<div class="block-title echarts-title"> <div class="block-title echarts-title">
<span class="icon"></span> <span class="icon"></span>
<span class="title">支付方式</span> <span class="title">支付方式</span>
{{include file="/index/stats_where" type="pay-type" init="1" /}} <div class="am-fr right-operate" data-type="pay-type" data-init="1">
{{if !empty($time_data)}}
<span class="quick-time">
{{foreach $time_data as $k=>$v}}
<a href="javascript:;" data-start="{{$v.start}}" data-end="{{$v.end}}">{{$v.name}}</a>
{{/foreach}}
</span>
{{/if}}
{{include file="/index/stats_time" /}}
</div>
</div> </div>
<div id="echarts-pay-type"></div> <div id="echarts-pay-type"></div>
</li> </li>

View File

@ -0,0 +1,6 @@
<span class="am-form echarts-where-time">
<input type="text" autocomplete="off" name="time_start" class="Wdate am-radius" placeholder="开始时间" onclick="WdatePicker({firstDayOfWeek:1,dateFmt:'yyyy-MM-dd HH:mm:ss'})" value="{{if !empty($time_data) and !empty($default_day) and isset($time_data[$default_day])}}{{$time_data[$default_day]['start']}}{{/if}}" />
<span class="join">-</span>
<input type="text" autocomplete="off" class="Wdate am-radius" placeholder="结束时间" name="time_end" onclick="WdatePicker({firstDayOfWeek:1,dateFmt:'yyyy-MM-dd HH:mm:ss'})" value="{{if !empty($time_data) and !empty($default_day) and isset($time_data[$default_day])}}{{$time_data[$default_day]['end']}}{{/if}}" />
<button type="button" class="am-btn am-btn-secondary am-radius am-btn-xs am-icon-line-chart btn-loading-example echarts-where-submit" data-am-loading="{loadingText:' 加载'}"> 确认</button>
</span>

View File

@ -1,15 +0,0 @@
<div class="am-fr right-operate" data-type="[type]" data-init="[init]">
{{if !empty($time_data)}}
<span class="quick-time">
{{foreach $time_data as $k=>$v}}
<a href="javascript:;" data-start="{{$v.start}}" data-end="{{$v.end}}">{{$v.name}}</a>
{{/foreach}}
</span>
{{/if}}
<span class="am-form echarts-where-time">
<input type="text" autocomplete="off" name="time_start" class="Wdate am-radius" placeholder="开始时间" onclick="WdatePicker({firstDayOfWeek:1,dateFmt:'yyyy-MM-dd HH:mm:ss'})" value="{{if !empty($time_data) and !empty($default_day) and isset($time_data[$default_day])}}{{$time_data[$default_day]['start']}}{{/if}}" />
<span class="join">-</span>
<input type="text" autocomplete="off" class="Wdate am-radius" placeholder="结束时间" name="time_end" onclick="WdatePicker({firstDayOfWeek:1,dateFmt:'yyyy-MM-dd HH:mm:ss'})" value="{{if !empty($time_data) and !empty($default_day) and isset($time_data[$default_day])}}{{$time_data[$default_day]['end']}}{{/if}}" />
<button type="button" class="am-btn am-btn-secondary am-radius am-btn-xs am-icon-line-chart btn-loading-example echarts-where-submit" data-am-loading="{loadingText:' 加载'}"> 确认</button>
</span>
</div>

View File

@ -393,6 +393,9 @@ class StatisticalService
// 订单状态 // 订单状态
// 0待确认, 1已确认/待支付, 2已支付/待发货, 3已发货/待收货, 4已完成, 5已取消, 6已关闭 // 0待确认, 1已确认/待支付, 2已支付/待发货, 3已发货/待收货, 4已完成, 5已取消, 6已关闭
// 是否有收入统计权限
if(AdminIsPower('index', 'income'))
{
// 上月 // 上月
$where = [ $where = [
['status', 'in', [2,3,4]], ['status', 'in', [2,3,4]],
@ -424,6 +427,12 @@ class StatisticalService
['add_time', '<=', self::$today_time_end], ['add_time', '<=', self::$today_time_end],
]; ];
$today_count = Db::name('Order')->where($where)->sum('total_price'); $today_count = Db::name('Order')->where($where)->sum('total_price');
} else {
$last_month_count = 0.00;
$same_month_count = 0.00;
$yesterday_count = 0.00;
$today_count = 0.00;
}
// 数据组装 // 数据组装
$result = [ $result = [
@ -466,14 +475,20 @@ class StatisticalService
// 订单成交总量 // 订单成交总量
$order_sale_count = Db::name('Order')->where(array_merge($where, [['status', '=', 4]]))->count(); $order_sale_count = Db::name('Order')->where(array_merge($where, [['status', '=', 4]]))->count();
// 订单收入总计 // 订单收入总计、是否有收入统计权限
$order_complete_total = PriceNumberFormat(Db::name('Order')->where(array_merge($where, [['status', 'in', [2,3,4]]]))->sum('total_price')); if(AdminIsPower('index', 'income'))
{
$order_complete_total = Db::name('Order')->where(array_merge($where, [['status', 'in', [2,3,4]]]))->sum('total_price');
} else {
$order_complete_total = 0.00;
}
$result = [ $result = [
'user_count' => $user_count, 'user_count' => $user_count,
'order_count' => $order_count, 'order_count' => $order_count,
'order_sale_count' => $order_sale_count, 'order_sale_count' => $order_sale_count,
'order_complete_total' => $order_complete_total, 'order_complete_total' => PriceNumberFormat($order_complete_total),
]; ];
return DataReturn('处理成功', 0, $result); return DataReturn('处理成功', 0, $result);
} }
@ -719,9 +734,15 @@ class StatisticalService
// 获取订单id // 获取订单id
$where = [ $where = [
['status', '<=', 4], ['status', '<=', 4],
['add_time', '>=', $params['start']],
['add_time', '<=', $params['end']],
]; ];
if(!empty($params['start']))
{
$where[] = ['add_time', '>=', $params['start']];
}
if(!empty($params['end']))
{
$where[] = ['add_time', '<=', $params['end']];
}
$order_ids = Db::name('Order')->where($where)->column('id'); $order_ids = Db::name('Order')->where($where)->column('id');
// 获取订单详情热销商品 // 获取订单详情热销商品
@ -772,17 +793,20 @@ class StatisticalService
'key_name' => 'type', 'key_name' => 'type',
'error_msg' => '类型为空', 'error_msg' => '类型为空',
], ],
[ ];
if(isset($params['type']) && in_array($params['type'], ['order-profit', 'order-trading', 'pay-type']))
{
$p[] = [
'checked_type' => 'empty', 'checked_type' => 'empty',
'key_name' => 'start', 'key_name' => 'start',
'error_msg' => '开始时间为空', 'error_msg' => '开始时间不能为空',
], ];
[ $p[] = [
'checked_type' => 'empty', 'checked_type' => 'empty',
'key_name' => 'end', 'key_name' => 'end',
'error_msg' => '结束时间为空', 'error_msg' => '结束时间不能为空',
],
]; ];
}
$ret = ParamsChecked($params, $p); $ret = ParamsChecked($params, $p);
if($ret !== true) if($ret !== true)
{ {

View File

@ -181,17 +181,12 @@ html, body {
color: rgba(255, 255, 255, 0.12); color: rgba(255, 255, 255, 0.12);
} }
@media only screen and (max-width: 641px) { @media only screen and (max-width: 641px) {
.shopxo-base li:nth-child(1){ .shopxo-base li {
padding: 10px 5px 5px 0; padding: 10px 5px;
} }
.shopxo-base li:nth-child(2){ .shopxo-base ul.am-avg-lg-4 li:nth-child(3),
padding: 10px 0 5px 5px; .shopxo-base ul.am-avg-lg-4 li:nth-child(4) {
} padding-top: 0;
.shopxo-base li:nth-child(3){
padding: 5px 5px 0 0;
}
.shopxo-base li:nth-child(4){
padding: 5px 0 0 5px;
} }
} }

View File

@ -529,9 +529,10 @@ $(function()
$('.quick-time a').on('click', function() $('.quick-time a').on('click', function()
{ {
// 参数判断 // 参数判断
var start = $(this).data('start') || null; var start = $(this).data('start') || '';
var end = $(this).data('end') || null; var end = $(this).data('end') || '';
if(start == null || end == null) var is_empty_time = parseInt($(this).parents('.right-operate').data('empty-time')) || 0;
if(is_empty_time == 0 && (start == '' || end == ''))
{ {
Prompt('快捷时间配置有误'); Prompt('快捷时间配置有误');
return false; return false;