后台数据统计优化

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';
MyViewAssign('default_day', $default_day);
// 收入统计权限
$is_income = AdminIsPower('index', 'income');
MyViewAssign('is_income', $is_income);
// 时间
$time_data = StatisticalService::DateTimeList();
MyViewAssign('time_data', $time_data);
@ -118,8 +122,11 @@ class Index extends Common
MyViewAssign('order_complete_number', $order_complete_number['data']);
// 订单收入总计
$order_complete_money = StatisticalService::OrderCompleteMoneyYesterdayTodayTotal();
MyViewAssign('order_complete_money', $order_complete_money['data']);
if($is_income == 1)
{
$order_complete_money = StatisticalService::OrderCompleteMoneyYesterdayTodayTotal();
MyViewAssign('order_complete_money', $order_complete_money['data']);
}
}
return MyView();

View File

@ -60,9 +60,19 @@
<span class="icon"></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>
{{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">
<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>
<div class="li-content">
<p class="name">用户总量</p>
@ -132,29 +142,32 @@
<i class="am-icon-gg am-icon-lg bg-icon"></i>
</div>
</li>
<li>
<div class="li-content">
<p class="name">收入总计</p>
<p class="total animation-count-to base-order-complete-total" data-to="{{$base_count.order_complete_total}}" data-speed="1500" data-decimals="2">0.00</p>
<div class="item am-margin-bottom-xs">
<span>上月</span>
<span class="animation-count-to" data-to="{{$order_complete_money.last_month_count}}" data-speed="1500">0</span>
<!-- 收入统计权限判断 -->
{{if isset($is_income) and $is_income eq true}}
<li>
<div class="li-content">
<p class="name">收入总计</p>
<p class="total animation-count-to base-order-complete-total" data-to="{{$base_count.order_complete_total}}" data-speed="1500" data-decimals="2">0.00</p>
<div class="item am-margin-bottom-xs">
<span>上月</span>
<span class="animation-count-to" data-to="{{$order_complete_money.last_month_count}}" data-speed="1500">0</span>
</div>
<div class="item am-margin-bottom-xs">
<span>当月</span>
<span class="animation-count-to" data-to="{{$order_complete_money.same_month_count}}" data-speed="1500">0</span>
</div>
<div class="item am-margin-bottom-xs">
<span>昨日</span>
<span class="animation-count-to" data-to="{{$order_complete_money.yesterday_count}}" data-speed="1500" data-decimals="2">0.00</span>
</div>
<div class="item">
<span>今日</span>
<span class="animation-count-to" data-to="{{$order_complete_money.today_count}}" data-speed="1500" data-decimals="2">0.00</span>
</div>
<i class="am-icon-line-chart am-icon-lg bg-icon"></i>
</div>
<div class="item am-margin-bottom-xs">
<span>当月</span>
<span class="animation-count-to" data-to="{{$order_complete_money.same_month_count}}" data-speed="1500">0</span>
</div>
<div class="item am-margin-bottom-xs">
<span>昨日</span>
<span class="animation-count-to" data-to="{{$order_complete_money.yesterday_count}}" data-speed="1500" data-decimals="2">0.00</span>
</div>
<div class="item">
<span>今日</span>
<span class="animation-count-to" data-to="{{$order_complete_money.today_count}}" data-speed="1500" data-decimals="2">0.00</span>
</div>
<i class="am-icon-line-chart am-icon-lg bg-icon"></i>
</div>
</li>
</li>
{{/if}}
</ul>
</div>
@ -163,7 +176,16 @@
<div class="block-title echarts-title">
<span class="icon"></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 id="echarts-order-profit"></div>
</div>
@ -173,7 +195,16 @@
<div class="block-title echarts-title">
<span class="icon"></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 id="echarts-order-trading"></div>
</div>
@ -185,7 +216,17 @@
<div class="block-title echarts-title">
<span class="icon"></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 id="echarts-goods-hot"></div>
</li>
@ -195,7 +236,16 @@
<div class="block-title echarts-title">
<span class="icon"></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 id="echarts-pay-type"></div>
</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,37 +393,46 @@ class StatisticalService
// 订单状态
// 0待确认, 1已确认/待支付, 2已支付/待发货, 3已发货/待收货, 4已完成, 5已取消, 6已关闭
// 上月
$where = [
['status', 'in', [2,3,4]],
['add_time', '>=', self::$last_month_time_start],
['add_time', '<=', self::$last_month_time_end],
];
$last_month_count = Db::name('Order')->where($where)->sum('total_price');
// 是否有收入统计权限
if(AdminIsPower('index', 'income'))
{
// 上月
$where = [
['status', 'in', [2,3,4]],
['add_time', '>=', self::$last_month_time_start],
['add_time', '<=', self::$last_month_time_end],
];
$last_month_count = Db::name('Order')->where($where)->sum('total_price');
// 当月
$where = [
['status', 'in', [2,3,4]],
['add_time', '>=', self::$this_month_time_start],
['add_time', '<=', self::$this_month_time_end],
];
$same_month_count = Db::name('Order')->where($where)->sum('total_price');
// 当月
$where = [
['status', 'in', [2,3,4]],
['add_time', '>=', self::$this_month_time_start],
['add_time', '<=', self::$this_month_time_end],
];
$same_month_count = Db::name('Order')->where($where)->sum('total_price');
// 昨天
$where = [
['status', 'in', [2,3,4]],
['add_time', '>=', self::$yesterday_time_start],
['add_time', '<=', self::$yesterday_time_end],
];
$yesterday_count = Db::name('Order')->where($where)->sum('total_price');
// 昨天
$where = [
['status', 'in', [2,3,4]],
['add_time', '>=', self::$yesterday_time_start],
['add_time', '<=', self::$yesterday_time_end],
];
$yesterday_count = Db::name('Order')->where($where)->sum('total_price');
// 今天
$where = [
['status', 'in', [2,3,4]],
['add_time', '>=', self::$today_time_start],
['add_time', '<=', self::$today_time_end],
];
$today_count = Db::name('Order')->where($where)->sum('total_price');
// 今天
$where = [
['status', 'in', [2,3,4]],
['add_time', '>=', self::$today_time_start],
['add_time', '<=', self::$today_time_end],
];
$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 = [
@ -466,14 +475,20 @@ class StatisticalService
// 订单成交总量
$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 = [
'user_count' => $user_count,
'order_count' => $order_count,
'order_sale_count' => $order_sale_count,
'order_complete_total' => $order_complete_total,
'order_complete_total' => PriceNumberFormat($order_complete_total),
];
return DataReturn('处理成功', 0, $result);
}
@ -719,9 +734,15 @@ class StatisticalService
// 获取订单id
$where = [
['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');
// 获取订单详情热销商品
@ -772,17 +793,20 @@ class StatisticalService
'key_name' => 'type',
'error_msg' => '类型为空',
],
[
];
if(isset($params['type']) && in_array($params['type'], ['order-profit', 'order-trading', 'pay-type']))
{
$p[] = [
'checked_type' => 'empty',
'key_name' => 'start',
'error_msg' => '开始时间为空',
],
[
'error_msg' => '开始时间不能为空',
];
$p[] = [
'checked_type' => 'empty',
'key_name' => 'end',
'error_msg' => '结束时间为空',
],
];
'error_msg' => '结束时间不能为空',
];
}
$ret = ParamsChecked($params, $p);
if($ret !== true)
{

View File

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

View File

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