Browse Source

每日数据汇总统计

sunhao 5 years ago
parent
commit
f324e3751d

+ 93 - 1
app/Http/Controllers/Admin/StatisticsController.php

@@ -4552,10 +4552,102 @@ class StatisticsController extends Controller
4552 4552
         $filename = 'xiaoshoufugou_'.date('Y-m-d_H').'.xlsx';
4553 4553
         return Order::export_excel($result, $filename, $indexKey, $title);  
4554 4554
     }
4555
+
4556
+    /**
4557
+     * 每日累计汇总数据
4558
+     */
4559
+    public function dayGrandTotal(Request $request){
4560
+        $page = (int)$request->input('page');
4561
+        $pageSize = 20;
4562
+        if($page<=0){
4563
+            $page = 1;
4564
+        }
4565
+
4566
+        $data = array();
4567
+        if($page == 1){
4568
+            $pageSize = $pageSize - 1;
4569
+            $offset = ($page-1) * $pageSize;
4570
+            //今日数据实时计算
4571
+            $idate = date('Y-m-d');
4572
+            $data['idate'] = $idate;
4573
+            //总投入
4574
+            $data['throw_cost'] = CustTotal::where('is_del',0)->sum('total_cost');
4575
+            //订单信息
4576
+            $order = Order::select(DB::raw('sum(cost) as goods_cost, sum(freight_cost) as freight_cost, sum(aftersale_fee) as aftersale_cost, count(1) as order_count, sum(receivedAmount) as order_amount, count(distinct(receiverMobile)) as cust_count'))->where('is_del',0)->where('cost', '>', 0)->first();
4577
+            $data['goods_cost'] = $order->goods_cost;
4578
+            $data['freight_cost'] = $order->freight_cost;
4579
+            $data['aftersale_cost'] = $order->aftersale_cost;
4580
+            $data['order_count'] = $order->order_count;
4581
+            $data['order_amount'] = $order->order_amount;
4582
+            $data['cust_count'] = $order->cust_count;
4583
+            //加粉
4584
+            $data['fan_count'] = CustDetail::where('is_del',0)->sum('fan_add');    
4585
+            //毛利 = 总销售额-总商品成本-总运费-总售后
4586
+            $data['profit'] = $order->order_amount - $order->goods_cost - $order->freight_cost - $order->aftersale_cost;
4587
+        }else{
4588
+            $offset = ($page-1) * $pageSize - 1;
4589
+        }
4590
+        //查询历史数据
4591
+        $count = DB::table('day_grand_total')->count();
4592
+        $count = $count + 1;
4593
+        $result = DB::table('day_grand_total')->orderBy('idate', 'desc')->offset($offset)->limit($pageSize)->get();
4594
+        $result = json_decode(json_encode($result), true);
4595
+        if($page == 1){
4596
+            $result  = array_merge([$data], $result);
4597
+        }
4598
+
4599
+        if ($count > 1) {
4600
+            // 总页数
4601
+            $pages = ceil($count/$pageSize);
4602
+        }else{
4603
+            // 总页数
4604
+            $pages = 1;
4605
+        }
4606
+
4607
+        return view('statistics/dayGrandTotal', ['result' =>$result,
4608
+            'page'              =>$page,
4609
+            'count'             =>$count,
4610
+            'pages'             =>$pages,                                                                                                   
4611
+            ]);
4612
+    }
4613
+
4614
+    /**
4615
+     * 每日累计汇总数据导出
4616
+     */
4617
+    public function dayGrandTotal_export(Request $request){
4618
+        
4619
+        $data = array();
4620
+        //今日数据实时计算
4621
+        $idate = date('Y-m-d');
4622
+        $data['idate'] = $idate;
4623
+        //总投入
4624
+        $data['throw_cost'] = CustTotal::where('is_del',0)->sum('total_cost');
4625
+        //订单信息
4626
+        $order = Order::select(DB::raw('sum(cost) as goods_cost, sum(freight_cost) as freight_cost, sum(aftersale_fee) as aftersale_cost, count(1) as order_count, sum(receivedAmount) as order_amount, count(distinct(receiverMobile)) as cust_count'))->where('is_del',0)->where('cost', '>', 0)->first();
4627
+        $data['goods_cost'] = $order->goods_cost;
4628
+        $data['freight_cost'] = $order->freight_cost;
4629
+        $data['aftersale_cost'] = $order->aftersale_cost;
4630
+        $data['order_count'] = $order->order_count;
4631
+        $data['order_amount'] = $order->order_amount;
4632
+        $data['cust_count'] = $order->cust_count;
4633
+        //加粉
4634
+        $data['fan_count'] = CustDetail::where('is_del',0)->sum('fan_add');    
4635
+        //毛利 = 总销售额-总商品成本-总运费-总售后
4636
+        $data['profit'] = $order->order_amount - $order->goods_cost - $order->freight_cost - $order->aftersale_cost;
4637
+       
4638
+        $result = DB::table('day_grand_total')->orderBy('idate', 'desc')->get();
4639
+        $result = json_decode(json_encode($result), true);   
4640
+        $result  = array_merge([$data], $result);
4641
+
4642
+        $indexKey = ['idate','throw_cost','cust_count','order_count','order_amount','goods_cost', 'freight_cost', 'aftersale_cost', 'profit'];
4643
+        $title = ['汇总日期', '总投放', '总客户数', '总下单数', '总销售额', '总货品成本', '总运费成本', '总售后', '总毛利'];
4644
+        $filename = 'huizongshuj_'.date('Y-m-d_H').'.xlsx';
4645
+        return Order::export_excel($result, $filename, $indexKey, $title); 
4646
+    }
4555 4647
                                                                                 
4556 4648
 }
4557 4649
                                                                         
4558
-  
4650
+                                          
4559 4651
   
4560 4652
 
4561 4653
 

+ 3 - 0
app/Http/routes.php

@@ -222,6 +222,9 @@ Route::group(['prefix' => 'admin'], function(){
222 222
         Route::get('template/sourcedelete/{id}',   'Admin\TemplateController@sourcedel');
223 223
         Route::post('template/uploadBack/',   'Admin\TemplateController@uploadBack');
224 224
         Route::get('template/getTempback/{id}',   'Admin\TemplateController@getTempback');
225
+        //每日汇总数据
226
+        Route::get('statistics/dayGrandTotal',   'Admin\StatisticsController@dayGrandTotal');
227
+        Route::get('statistics/dayGrandTotal_export',   'Admin\StatisticsController@dayGrandTotal_export');
225 228
 
226 229
     });
227 230
     

+ 2 - 1
resources/views/admin/index.blade.php

@@ -129,7 +129,8 @@
129 129
                     <ul>                       
130 130
                         <li @if(!isset($res['statistics/districtRoi'])) style="display:none;list-style-type:none;" @endif><a data-href="{{url('admin/statistics/districtRoi7day')}}" data-title="滚动地域ROI" href="javascript:void(0)">滚动地域ROI</a></li> 
131 131
                         <li @if(!isset($res['template/manage'])) style="display:none;list-style-type:none;" @endif><a data-href="{{url('admin/template/templateLogReport')}}" data-title="销售模板导粉报表" href="javascript:void(0)">销售模板导粉报表</a></li> 
132
-                        <li @if(!isset($res['statistics/salerOrderFugou'])) style="display:none;list-style-type:none;" @endif><a data-href="{{url('admin/statistics/salerOrderFugou')}}" data-title="销售粉丝复购报表" href="javascript:void(0)">销售粉丝复购报表</a></li>                        
132
+                        <li @if(!isset($res['statistics/salerOrderFugou'])) style="display:none;list-style-type:none;" @endif><a data-href="{{url('admin/statistics/salerOrderFugou')}}" data-title="销售粉丝复购报表" href="javascript:void(0)">销售粉丝复购报表</a></li> 
133
+                        <li @if(!isset($res['statistics/dayGrandTotal'])) style="display:none;list-style-type:none;" @endif><a data-href="{{url('admin/statistics/dayGrandTotal')}}" data-title="每日数据累计汇总报表" href="javascript:void(0)">每日数据累计汇总报表</a></li>                        
133 134
                     </ul>
134 135
                    
135 136
                 </dd>

+ 87 - 0
resources/views/statistics/dayGrandTotal.blade.php

@@ -0,0 +1,87 @@
1
+@extends('admin/master')
2
+@section('content')
3
+    <body>
4
+    <div class="page-container">
5
+        <div>
6
+            <div>
7
+                                                   
8
+                <!--a class="btn btn-primary radius"  style="margin-left: 5px" onclick="user_search()" href="javascript:;">搜索</a-->   
9
+                <a class="btn btn-primary radius" onclick="statistics_export()" href="javascript:;"><i class="Hui-iconfont"></i> 导出数据</a>
10
+                
11
+            </div>
12
+        </div>
13
+      
14
+        <div class="mt-20">
15
+            <table class="table table-border table-bordered table-bg table-hover table-sort">
16
+                <thead>
17
+                <tr class="text-c">
18
+                    <th width="5%">汇总日期</th>
19
+                    <th width="5%">总投放</th>
20
+                    <th width="5%">总客户数</th>
21
+                    <th width="5%">总下单数</th>                  
22
+                    <th width="5%">总销售额</th>
23
+                    <th width="5%">总货品成本</th>                                                
24
+                    <th width="5%">总运费成本</th>                                                
25
+                    <th width="5%">总售后</th>  
26
+                    <th width="5%">总毛利</th>                                                                                            
27
+                                             
28
+                </tr>
29
+                </thead>
30
+                <tbody>
31
+                @if($result)
32
+                    @foreach($result as $a)
33
+                        <tr class="text-c" style=" text-align:center;">                                               
34
+                            <td>{{$a['idate']}}</td>                                                                                   
35
+                            <td>{{$a['throw_cost']}}</td>                                                                                   
36
+                            <td>{{$a['cust_count']}}</td>                                                                                   
37
+                            <td>{{$a['order_count']}}</td>                                                                                   
38
+                            <td>{{$a['order_amount']}}</td>                                                                                   
39
+                            <td>{{$a['goods_cost']}}</td>                                                                                   
40
+                            <td>{{$a['freight_cost']}}</td>  
41
+                            <td>{{$a['aftersale_cost']}}</td>                                                                                 
42
+                            <td>{{$a['profit']}}</td>                                                                                   
43
+                           
44
+                        </tr>
45
+                    @endforeach
46
+                @endif
47
+                </tbody>
48
+            </table>
49
+        </div>
50
+        <div id="page" class="page_div"></div>
51
+    </div>
52
+    
53
+    <!--_footer 作为公共模版分离出去-->
54
+    <script type="text/javascript" src="/admin/lib/jquery/1.9.1/jquery.min.js"></script>
55
+    <script type="text/javascript" src="/admin/lib/layer/2.4/layer.js"></script>
56
+    <script type="text/javascript" src="/admin/static/h-ui/js/H-ui.min.js"></script>
57
+    <script type="text/javascript" src="/admin/static/h-ui.admin/js/H-ui.admin.js"></script>
58
+    <script type="text/javascript" src="/admin/lib/page/paging.js"></script>
59
+    <script type="text/javascript" src="/admin/lib/My97DatePicker/4.8/WdatePicker.js"></script>
60
+    <!--/_footer 作为公共模版分离出去-->
61
+    <!--/_footer 作为公共模版分离出去-->
62
+     <script type="text/javascript">
63
+        function user_search(){
64
+  
65
+            location.href = 'dayGrandTotal';
66
+        }
67
+        //导出
68
+        function statistics_export(){
69
+            location.href = 'dayGrandTotal_export';
70
+        }
71
+       
72
+        /*分页*/
73
+            
74
+        $("#page").paging({
75
+            pageNo:{{$page}},
76
+            totalPage: {{$pages}},
77
+            totalSize: {{$count}},
78
+            callback: function(num) {              
79
+                location.href='dayGrandTotal?page='+num;
80
+            }
81
+        })
82
+        
83
+    </script>
84
+   
85
+    </body>
86
+
87
+@endsection