Browse Source

充值消费月报

sunhao 5 years ago
parent
commit
ce5f3df667

+ 76 - 0
app/Http/Controllers/Admin/StatisticsController.php

@@ -5378,5 +5378,81 @@ class StatisticsController extends Controller
5378 5378
         return Order::export_excel($result, $filename, $indexKey, $title); 
5379 5379
 
5380 5380
     }
5381
+
5382
+    /**
5383
+     * 客户充值月报
5384
+     */
5385
+    public function customerMonthAccount(Request $request){
5386
+
5387
+        $page = (int)$request->input('page');
5388
+        $pageSize = 20;
5389
+        if($page<=0){
5390
+            $page = 1;
5391
+        }
5392
+        $offset = ($page-1) * $pageSize;
5393
+        $_data = $this->depositCtimePage($offset, $pageSize);
5394
+
5395
+        $count = $_data['count'];
5396
+        if ($count > 1) {
5397
+            // 总页数
5398
+            $pages = ceil($count/20);
5399
+        }else{
5400
+            // 总页数
5401
+            $pages = 1;
5402
+        }
5403
+
5404
+        $result = $_data['data'];
5405
+        
5406
+        foreach($result as $k=>&$v){
5407
+            $m_consum = CustomerConsum::select(DB::raw('sum(money) as money'))->whereRaw('left(create_time, 7)="'.$v['date'].'"')->where('phone', $v['phone'])->where('is_del', 0)->first();
5408
+            $v['money'] = $m_consum->money;
5409
+            $v['month'] = $v['date'];
5410
+            //用户
5411
+            $v['cust_name'] = CustomerInfo::where('phone', $v['phone'])->pluck('name');
5412
+            //累计数据
5413
+            $end = date('Y-m-1', strtotime($v['month'].' +1 month'));
5414
+            //充值
5415
+            $deposit = CustomerDeposit::select(DB::raw('sum(pay_amount) as pay_amount_total, sum(discount) as discount_total, sum(deposit_amount) as deposit_amount_total'))->where('phone', $v['phone'])->where('is_del', 0)->where('pay_time', '<', $end)->first();
5416
+            $v['pay_amount_total'] = $deposit->pay_amount_total;
5417
+            $v['discount_total'] = $deposit->discount_total;
5418
+            $v['deposit_amount_total'] = $deposit->deposit_amount_total;
5419
+            //消费
5420
+            $consum = CustomerConsum::select(DB::raw('sum(money) as money'))->where('phone', $v['phone'])->where('is_del', 0)->where('create_time', '<', $end)->first();
5421
+            $v['consum_total'] = $consum->money;
5422
+            $v['balance'] = $v['deposit_amount_total'] - $v['consum_total'];
5423
+        }
5424
+
5425
+         return view('statistics/customerMonthAccount', ['result' =>$result,
5426
+            'page'              =>$page,
5427
+            'count'             =>$count,
5428
+            'pages'             =>$pages,                                                                                                                                                                                                                 
5429
+            ]);
5430
+    }
5431
+
5432
+    /**
5433
+     * 充值客户财务月报时间格式处理  
5434
+     */
5435
+    public function depositCtimePage($offset, $pageSize){
5436
+        $result = array();
5437
+        $sdate = '2019-11';
5438
+        $edate = date('Y-m');
5439
+
5440
+        $custs = CustomerInfo::lists('phone');
5441
+        for($i=0;$i<36;$i++){
5442
+            $d = $sdate. ' +'.$i.' month';
5443
+            $date = date('Y-m', strtotime($d));
5444
+            foreach($custs as $phone){
5445
+                $result[] = ['date'=>$date, 'phone'=>$phone];
5446
+            }
5447
+            if($date == $edate){
5448
+                break;
5449
+            }
5450
+        }
5451
+
5452
+        $count = count($result);
5453
+        $ret['data'] = array_slice($result, $offset, $pageSize);
5454
+        $ret['count'] = $count;
5455
+        return $ret;
5456
+    }
5381 5457
                                                                                 
5382 5458
 }

+ 3 - 0
app/Http/routes.php

@@ -252,6 +252,9 @@ Route::group(['prefix' => 'admin'], function(){
252 252
         
253 253
         Route::get('statistics/consumDetail',   'Admin\StatisticsController@consumDetail');
254 254
         Route::get('statistics/consumDetail_export',   'Admin\StatisticsController@consumDetail_export');
255
+        
256
+        Route::get('statistics/customerMonthAccount',   'Admin\StatisticsController@customerMonthAccount');
257
+        Route::get('statistics/customerMonthAccount_export',   'Admin\StatisticsController@customerMonthAccount_export');
255 258
 
256 259
         //充值
257 260
         Route::get('deposit/index', 'Admin\CustomerDepositController@index');  //充值记录

+ 3 - 0
resources/views/admin/index.blade.php

@@ -195,6 +195,9 @@
195 195
                     <ul>                       
196 196
                         <li @if(!isset($res['statistics/depositDayReport'])) style="display:none;list-style-type:none;" @endif><a data-href="{{url('admin/statistics/consumDetail')}}" data-title="充值卡消费明细" href="javascript:void(0)">充值卡消费明细</a></li>                        
197 197
                     </ul>
198
+                    <ul>                       
199
+                        <li @if(!isset($res['statistics/depositDayReport'])) style="display:none;list-style-type:none;" @endif><a data-href="{{url('admin/statistics/customerMonthAccount')}}" data-title="充值卡消费明细" href="javascript:void(0)">客户充值消费月报</a></li>                        
200
+                    </ul>
198 201
                     
199 202
                 </dd>
200 203
             </dl>

+ 85 - 0
resources/views/statistics/customerMonthAccount.blade.php

@@ -0,0 +1,85 @@
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" onclick="statistics_export()" href="javascript:;"><i class="Hui-iconfont"></i> 导出数据</a>
9
+                
10
+            </div>
11
+        </div>
12
+        
13
+        <div class="mt-20">
14
+            <table class="table table-border table-bordered table-bg table-hover table-sort">
15
+                <thead>
16
+                <tr class="text-c">
17
+                    <th width="5%">月份</th>
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
+                </tr>
26
+                </thead>
27
+                <tbody>
28
+                @if($result)
29
+                    @foreach($result as $a)
30
+                        <tr class="text-c" style=" text-align:center;">                           
31
+                            <td>{{$a['month']}}</td>                            
32
+                            <td>{{$a['cust_name']}}</td>
33
+                            <td>{{$a['pay_amount_total']}}</td>
34
+                            <td>{{$a['discount_total']}}</td>
35
+                            <td>{{$a['deposit_amount_total']}}</td>
36
+                            <td>{{$a['money']}}</td>
37
+                            <td>{{$a['consum_total']}}</td>
38
+                            <td>{{$a['balance']}}</td>
39
+                           
40
+                        </tr>
41
+                    @endforeach
42
+                @endif
43
+                </tbody>
44
+            </table>
45
+        </div>
46
+        <div id="page" class="page_div"></div>
47
+    </div>
48
+    
49
+    <!--_footer 作为公共模版分离出去-->
50
+    <script type="text/javascript" src="/admin/lib/jquery/1.9.1/jquery.min.js"></script>
51
+    <script type="text/javascript" src="/admin/lib/layer/2.4/layer.js"></script>
52
+    <script type="text/javascript" src="/admin/static/h-ui/js/H-ui.min.js"></script>
53
+    <script type="text/javascript" src="/admin/static/h-ui.admin/js/H-ui.admin.js"></script>
54
+    <script type="text/javascript" src="/admin/lib/page/paging.js"></script>
55
+    <script type="text/javascript" src="/admin/lib/My97DatePicker/4.8/WdatePicker.js"></script>
56
+    <!--/_footer 作为公共模版分离出去-->
57
+    <!--/_footer 作为公共模版分离出去-->
58
+     <script type="text/javascript">
59
+        function user_search(){
60
+        
61
+            location.href = 'customerMonthAccount';
62
+        }
63
+        //导出
64
+        function statistics_export(){
65
+          
66
+            location.href = '/admin/statistics/customerMonthAccount_export';
67
+        }
68
+       
69
+        /*分页*/
70
+            
71
+        $("#page").paging({
72
+            pageNo:{{$page}},
73
+            totalPage: {{$pages}},
74
+            totalSize: {{$count}},
75
+            callback: function(num) {
76
+            
77
+                location.href='customerMonthAccount?page='+num;
78
+            }
79
+        })
80
+        
81
+    </script>
82
+   
83
+    </body>
84
+
85
+@endsection