|
@@ -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
|
}
|