Browse Source

累计充值月报

sunhao 5 years ago
parent
commit
702ef04c99

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

@@ -5430,9 +5430,41 @@ class StatisticsController extends Controller
5430 5430
     }
5431 5431
 
5432 5432
     /**
5433
+     * 客户充值月报
5434
+     */
5435
+    public function customerMonthAccount_export(Request $request){
5436
+
5437
+        $result = $this->depositCtimePage(0, 0, 1);
5438
+       
5439
+        foreach($result as $k=>&$v){
5440
+            $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();
5441
+            $v['money'] = $m_consum->money;
5442
+            $v['month'] = $v['date'];
5443
+            //用户
5444
+            $v['cust_name'] = CustomerInfo::where('phone', $v['phone'])->pluck('name');
5445
+            //累计数据
5446
+            $end = date('Y-m-1', strtotime($v['month'].' +1 month'));
5447
+            //充值
5448
+            $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();
5449
+            $v['pay_amount_total'] = $deposit->pay_amount_total;
5450
+            $v['discount_total'] = $deposit->discount_total;
5451
+            $v['deposit_amount_total'] = $deposit->deposit_amount_total;
5452
+            //消费
5453
+            $consum = CustomerConsum::select(DB::raw('sum(money) as money'))->where('phone', $v['phone'])->where('is_del', 0)->where('create_time', '<', $end)->first();
5454
+            $v['consum_total'] = $consum->money;
5455
+            $v['balance'] = $v['deposit_amount_total'] - $v['consum_total'];
5456
+        }
5457
+
5458
+        $indexKey = ['month', 'cust_name', 'pay_amount_total','discount_total','deposit_amount_total','money','consum_total','balance'];
5459
+        $title = ['月份', '充值用户', '累计充值', '累计赠送', '累计实得', '当月消费', '累计消费', '剩余实得'];
5460
+        $filename = 'chongzhiyuebao_'.date('Y-m-d_H').'.xlsx';
5461
+        return Order::export_excel($result, $filename, $indexKey, $title);   
5462
+    }
5463
+                                                 
5464
+    /**
5433 5465
      * 充值客户财务月报时间格式处理  
5434 5466
      */
5435
-    public function depositCtimePage($offset, $pageSize){
5467
+    public function depositCtimePage($offset, $pageSize, $is_export=0){
5436 5468
         $result = array();
5437 5469
         $sdate = '2019-11';
5438 5470
         $edate = date('Y-m');
@@ -5449,6 +5481,9 @@ class StatisticsController extends Controller
5449 5481
             }
5450 5482
         }
5451 5483
 
5484
+        if($is_export == 1){
5485
+            return $result;
5486
+        }
5452 5487
         $count = count($result);
5453 5488
         $ret['data'] = array_slice($result, $offset, $pageSize);
5454 5489
         $ret['count'] = $count;

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

@@ -196,7 +196,7 @@
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 198
                     <ul>                       
199
-                        <li @if(!isset($res['statistics/depositDayReport2'])) style="display:none;list-style-type:none;" @endif><a data-href="{{url('admin/statistics/customerMonthAccount')}}" data-title="客户充值消费月报" href="javascript:void(0)">客户充值消费月报</a></li>                        
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 200
                     </ul>
201 201
                     
202 202
                 </dd>