quanwei
18 hours ago c441dea81bd86bdfb12dff35821fed51f4cc91c2
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
<?php
 
namespace app\operations\service\order;
 
use PhpOffice\PhpSpreadsheet\IOFactory;
use PhpOffice\PhpSpreadsheet\Spreadsheet;
use PhpOffice\PhpSpreadsheet\Writer\Xlsx;
 
/**
 * 订单导出服务类
 */
class ExportService
{
    /**
     * 订单导出
     */
    public function orderList($list)
    {
        $spreadsheet = new Spreadsheet();
        $sheet = $spreadsheet->getActiveSheet();
 
        //列宽
        $sheet->getColumnDimension('B')->setWidth(30);
        $sheet->getColumnDimension('P')->setWidth(30);
 
        //设置工作表标题名称
        $sheet->setTitle('订单明细');
 
        $sheet->setCellValue('A1', '订单号');
        $sheet->setCellValue('B1', '商品信息');
        $sheet->setCellValue('C1', '订单总额');
        $sheet->setCellValue('D1', '优惠券抵扣');
        $sheet->setCellValue('E1', '积分抵扣');
        $sheet->setCellValue('F1', '运费金额');
        $sheet->setCellValue('G1', '后台改价');
        $sheet->setCellValue('H1', '实付款金额');
        $sheet->setCellValue('I1', '支付方式');
        $sheet->setCellValue('J1', '下单时间');
        $sheet->setCellValue('K1', '买家');
        $sheet->setCellValue('L1', '买家留言');
        $sheet->setCellValue('M1', '配送方式');
        $sheet->setCellValue('N1', '自提门店名称');
        $sheet->setCellValue('O1', '自提联系人');
        $sheet->setCellValue('P1', '自提联系电话');
        $sheet->setCellValue('Q1', '收货人姓名');
        $sheet->setCellValue('R1', '联系电话');
        $sheet->setCellValue('S1', '收货人地址');
        $sheet->setCellValue('T1', '物流公司');
        $sheet->setCellValue('U1', '物流单号');
        $sheet->setCellValue('V1', '付款状态');
        $sheet->setCellValue('W1', '付款时间');
        $sheet->setCellValue('X1', '发货状态');
        $sheet->setCellValue('Y1', '发货时间');
        $sheet->setCellValue('Z1', '收货状态');
        $sheet->setCellValue('AA1', '收货时间');
        $sheet->setCellValue('AB1', '订单状态');
        $sheet->setCellValue('AC1', '微信支付交易号');
        $sheet->setCellValue('AD1', '是否已评价');
 
        //填充数据
        $index = 0;
        foreach ($list as $order) {
            $address = $order['address'];
            $sheet->setCellValue('A' . ($index + 2), "\t" . $order['order_no'] . "\t");
            $sheet->setCellValue('B' . ($index + 2), $this->filterProductInfo($order));
            $sheet->setCellValue('C' . ($index + 2), $order['total_price']);
            $sheet->setCellValue('D' . ($index + 2), $order['coupon_money']);
            $sheet->setCellValue('E' . ($index + 2), $order['points_money']);
            $sheet->setCellValue('F' . ($index + 2), $order['express_price']);
            $sheet->setCellValue('G' . ($index + 2), "{$order['update_price']['symbol']}{$order['update_price']['value']}");
            $sheet->setCellValue('H' . ($index + 2), $order['order_source'] == 70 ? round($order['pay_price'] + $order['advance']['pay_price'], 2) : $order['pay_price']);
            $sheet->setCellValue('I' . ($index + 2), $order['pay_type']['text']);
            $sheet->setCellValue('J' . ($index + 2), $order['create_time']);
            $sheet->setCellValue('K' . ($index + 2), $order['user']['nickName']);
            $sheet->setCellValue('L' . ($index + 2), $order['buyer_remark']);
            $sheet->setCellValue('M' . ($index + 2), $order['delivery_type']['text']);
            $sheet->setCellValue('N' . ($index + 2), !empty($order['extract_store']) ? $order['extract_store']['shop_name'] : '');
            $sheet->setCellValue('O' . ($index + 2), !empty($order['extract']) ? $order['extract']['linkman'] : '');
            $sheet->setCellValue('P' . ($index + 2), !empty($order['extract']) ? $order['extract']['phone'] : '');
            $sheet->setCellValue('Q' . ($index + 2), !empty($order['address']) ? $order['address']['name']:'');
            $sheet->setCellValue('R' . ($index + 2), !empty($order['address']) ? $order['address']['phone']: '');
            $sheet->setCellValue('S' . ($index + 2), $address ? $address->getFullAddress() : '');
            $sheet->setCellValue('T' . ($index + 2),  !empty($order['express']) ? $order['express']['express_name']:'');
            $sheet->setCellValue('U' . ($index + 2), $order['express_no']);
            $sheet->setCellValue('V' . ($index + 2), $order['pay_status']['text']);
            $sheet->setCellValue('W' . ($index + 2), $this->filterTime($order['pay_time']));
            $sheet->setCellValue('X' . ($index + 2), $order['delivery_status']['text']);
            $sheet->setCellValue('Y' . ($index + 2), $this->filterTime($order['delivery_time']));
            $sheet->setCellValue('Z' . ($index + 2), $order['receipt_status']['text']);
            $sheet->setCellValue('AA' . ($index + 2), $this->filterTime($order['receipt_time']));
            $sheet->setCellValue('AB' . ($index + 2), $order['order_status']['text']);
            $sheet->setCellValue('AC' . ($index + 2), $order['transaction_id']);
            $sheet->setCellValue('AD' . ($index + 2), $order['is_comment'] ? '是' : '否');
            $index++;
        }
 
        //保存文件
        $writer = new Xlsx($spreadsheet);
        $filename = iconv("UTF-8", "GB2312//IGNORE", '订单') . '-' . date('YmdHis') . '.xlsx';
 
 
        header('Content-Type: application/vnd.ms-excel');
        header('Content-Disposition: attachment;filename="' . $filename . '"');
        header('Cache-Control: max-age=0');
        $writer = IOFactory::createWriter($spreadsheet, 'Xlsx');
        $writer->save('php://output');
    }
 
    /**
     * 分销订单导出
     */
    public function agentOrderList($list)
    {
        $spreadsheet = new Spreadsheet();
        $sheet = $spreadsheet->getActiveSheet();
 
        //列宽
        $sheet->getColumnDimension('B')->setWidth(30);
 
        //设置工作表标题名称
        $sheet->setTitle('分销订单明细');
 
        $sheet->setCellValue('A1', '订单号');
        $sheet->setCellValue('B1', '商品信息');
        $sheet->setCellValue('C1', '订单总额');
        $sheet->setCellValue('D1', '实付款金额');
        $sheet->setCellValue('E1', '支付方式');
        $sheet->setCellValue('F1', '下单时间');
        $sheet->setCellValue('G1', '一级分销商');
        $sheet->setCellValue('H1', '一级分销佣金');
        $sheet->setCellValue('I1', '二级分销商');
        $sheet->setCellValue('J1', '二级分销佣金');
        $sheet->setCellValue('K1', '三级分销商');
        $sheet->setCellValue('L1', '三级分销佣金');
        $sheet->setCellValue('M1', '买家');
        $sheet->setCellValue('N1', '付款状态');
        $sheet->setCellValue('O1', '付款时间');
        $sheet->setCellValue('P1', '发货状态');
        $sheet->setCellValue('Q1', '发货时间');
        $sheet->setCellValue('R1', '收货状态');
        $sheet->setCellValue('S1', '收货时间');
        $sheet->setCellValue('T1', '订单状态');
        $sheet->setCellValue('U1', '佣金结算');
        $sheet->setCellValue('V1', '结算时间');
        //填充数据
        $index = 0;
        foreach ($list as $agent) {
            $order = $agent['order_master'];
            $sheet->setCellValue('A' . ($index + 2), "\t" . $order['order_no'] . "\t");
            $sheet->setCellValue('B' . ($index + 2), $this->filterProductInfo($order));
            $sheet->setCellValue('C' . ($index + 2), $order['total_price']);
            $sheet->setCellValue('D' . ($index + 2), $order['pay_price']);
            $sheet->setCellValue('E' . ($index + 2), $order['pay_type']['text']);
            $sheet->setCellValue('F' . ($index + 2), $order['create_time']);
            $sheet->setCellValue('G' . ($index + 2), isset($agent['agent_first'])?$agent['agent_first']['nickName']:'');
            $sheet->setCellValue('H' . ($index + 2), $agent['first_money']);
            $sheet->setCellValue('I' . ($index + 2), isset($agent['agent_second'])?$agent['agent_second']['nickName']:'');
            $sheet->setCellValue('J' . ($index + 2), $agent['second_money']);
            $sheet->setCellValue('K' . ($index + 2), isset($agent['agent_third'])?$agent['agent_third']['nickName']:'');
            $sheet->setCellValue('L' . ($index + 2), $agent['third_money']);
            $sheet->setCellValue('M' . ($index + 2), $order['user']['nickName']);
            $sheet->setCellValue('N' . ($index + 2), $order['pay_status']['text']);
            $sheet->setCellValue('O' . ($index + 2), $this->filterTime($order['pay_time']));
            $sheet->setCellValue('P' . ($index + 2), $order['delivery_status']['text']);
            $sheet->setCellValue('Q' . ($index + 2), $this->filterTime($order['delivery_time']));
            $sheet->setCellValue('R' . ($index + 2), $order['receipt_status']['text']);
            $sheet->setCellValue('S' . ($index + 2), $this->filterTime($order['receipt_time']));
            $sheet->setCellValue('T' . ($index + 2), $order['order_status']['text']);
            $sheet->setCellValue('U' . ($index + 2), $agent['is_settled'] == 1 ? '已结算' : '未结算');
            $sheet->setCellValue('V' . ($index + 2), $this->filterTime($agent['settle_time']));
            $index++;
        }
 
        //保存文件
        $filename = iconv("UTF-8", "GB2312//IGNORE", '分销订单') . '-' . date('YmdHis') . '.xlsx';
        header('Content-Type: application/vnd.ms-excel');
        header('Content-Disposition: attachment;filename="' . $filename . '"');
        header('Cache-Control: max-age=0');
        $writer = IOFactory::createWriter($spreadsheet, 'Xlsx');
        $writer->save('php://output');
    }
 
    /**
     * 提现订单导出
     */
    public function cashList($list)
    {
        $spreadsheet = new Spreadsheet();
        $sheet = $spreadsheet->getActiveSheet();
 
        //列宽
        $sheet->getColumnDimension('H')->setWidth(50);
 
        //设置工作表标题名称
        $sheet->setTitle('提现明细');
 
        $sheet->setCellValue('A1', 'ID');
        $sheet->setCellValue('B1', '分销商id');
        $sheet->setCellValue('C1', '分销商姓名');
        $sheet->setCellValue('D1', '微信昵称');
        $sheet->setCellValue('E1', '手机号');
        $sheet->setCellValue('F1', '提现金额');
        $sheet->setCellValue('G1', '提现方式');
        $sheet->setCellValue('H1', '提现信息');
        $sheet->setCellValue('I1', '审核状态');
        $sheet->setCellValue('J1', '申请时间');
        $sheet->setCellValue('K1', '审核时间');
        //填充数据
        $index = 0;
        foreach ($list as $cash) {
            $sheet->setCellValue('A' . ($index + 2), $cash['id']);
            $sheet->setCellValue('B' . ($index + 2), $cash['user_id']);
            $sheet->setCellValue('C' . ($index + 2), $cash['real_name']);
            $sheet->setCellValue('D' . ($index + 2), $cash['nickName']);
            $sheet->setCellValue('E' . ($index + 2), "\t" . $cash['mobile'] . "\t");
            $sheet->setCellValue('F' . ($index + 2), $cash['money']);
            $sheet->setCellValue('G' . ($index + 2), $cash['pay_type']['text']);
            $sheet->setCellValue('H' . ($index + 2), $this->cashInfo($cash));
            $sheet->setCellValue('I' . ($index + 2), $cash['apply_status']['text']);
            $sheet->setCellValue('J' . ($index + 2), $cash['create_time']);
            $sheet->setCellValue('K' . ($index + 2), $cash['audit_time']);
            $index++;
        }
        //保存文件
        $filename = iconv("UTF-8", "GB2312//IGNORE", '提现明细') . '-' . date('YmdHis') . '.xlsx';
        header('Content-Type: application/vnd.ms-excel');
        header('Content-Disposition: attachment;filename="' . $filename . '"');
        header('Cache-Control: max-age=0');
        $writer = IOFactory::createWriter($spreadsheet, 'Xlsx');
        $writer->save('php://output');
    }
    
    /**
     * 余额提现订单导出
     */
    public function userCashList($list)
    {
        $spreadsheet = new Spreadsheet();
        $sheet = $spreadsheet->getActiveSheet();
 
        //列宽
        $sheet->getColumnDimension('I')->setWidth(50);
 
        //设置工作表标题名称
        $sheet->setTitle('余额提现明细');
 
        $sheet->setCellValue('A1', 'ID');
        $sheet->setCellValue('B1', '用户ID');
        $sheet->setCellValue('C1', '微信昵称');
        $sheet->setCellValue('D1', '手机号');
        $sheet->setCellValue('E1', '提现金额');
        $sheet->setCellValue('F1', '实际到账');
        $sheet->setCellValue('G1', '提现比例');
        $sheet->setCellValue('H1', '提现方式');
        $sheet->setCellValue('I1', '提现信息');
        $sheet->setCellValue('J1', '审核状态');
        $sheet->setCellValue('K1', '申请时间');
        $sheet->setCellValue('L1', '审核时间');
        //填充数据
        $index = 0;
        foreach ($list as $cash) {
            $sheet->setCellValue('A' . ($index + 2), $cash['id']);
            $sheet->setCellValue('B' . ($index + 2), $cash['user_id']);
            $sheet->setCellValue('C' . ($index + 2), $cash['nickName']);
            $sheet->setCellValue('D' . ($index + 2), "\t" . $cash['mobile'] . "\t");
            $sheet->setCellValue('E' . ($index + 2), $cash['money']);
            $sheet->setCellValue('F' . ($index + 2), $cash['real_money']);
            $sheet->setCellValue('G' . ($index + 2), $cash['cash_ratio'] . '%');
            $sheet->setCellValue('H' . ($index + 2), $cash['pay_type']['text']);
            $sheet->setCellValue('I' . ($index + 2), $this->cashInfo($cash));
            $sheet->setCellValue('J' . ($index + 2), $cash['apply_status']['text']);
            $sheet->setCellValue('K' . ($index + 2), $cash['create_time']);
            $sheet->setCellValue('L' . ($index + 2), $cash['audit_time']);
            $index++;
        }
        //保存文件
        $filename = iconv("UTF-8", "GB2312//IGNORE", '余额提现明细') . '-' . date('YmdHis') . '.xlsx';
        header('Content-Type: application/vnd.ms-excel');
        header('Content-Disposition: attachment;filename="' . $filename . '"');
        header('Cache-Control: max-age=0');
        $writer = IOFactory::createWriter($spreadsheet, 'Xlsx');
        $writer->save('php://output');
    }
 
    /**
     * 核销订单导出
     */
    public function orderStoreList($list)
    {
        $spreadsheet = new Spreadsheet();
        $sheet = $spreadsheet->getActiveSheet();
 
        //列宽
        $sheet->getColumnDimension('B')->setWidth(30);
        $sheet->getColumnDimension('D')->setWidth(30);
        $sheet->getColumnDimension('E')->setWidth(20);
        $sheet->getColumnDimension('F')->setWidth(20);
        $sheet->getColumnDimension('G')->setWidth(20);
 
        //设置工作表标题名称
        $sheet->setTitle('核销订单明细');
 
        $sheet->setCellValue('A1', '门店ID');
        $sheet->setCellValue('B1', '核销门店');
        $sheet->setCellValue('C1', '核销员');
        $sheet->setCellValue('D1', '订单号');
        $sheet->setCellValue('E1', '订单类型');
        $sheet->setCellValue('F1', '配送类型');
        $sheet->setCellValue('G1', '核销时间');
        $sheet->setCellValue('H1', '订单金额');
        $sheet->setCellValue('I1', '门店提成');
        $sheet->setCellValue('J1', '配送费');
        $sheet->setCellValue('K1', '实付金额');
 
        //填充数据
        $index = 0;
        foreach ($list as $order) {
            $sheet->setCellValue('A' . ($index + 2), $order['store_id']);
            $sheet->setCellValue('B' . ($index + 2), $order["store"]['store_name']);
            $sheet->setCellValue('C' . ($index + 2), $order["clerk"]['real_name']);
            $sheet->setCellValue('D' . ($index + 2), "\t" . $order["order"]['order_no'] . "\t");
            $sheet->setCellValue('E' . ($index + 2), $order['order_type']['text']);
            $sheet->setCellValue('F' . ($index + 2), $order['order']['delivery_type']['text']);
            $sheet->setCellValue('G' . ($index + 2), $order['create_time']);
            $sheet->setCellValue('H' . ($index + 2), $order['order']['order_price']);
            $sheet->setCellValue('I' . ($index + 2), $order['commission']);
            $sheet->setCellValue('J' . ($index + 2), $order['delivery_fee']);
            $sheet->setCellValue('K' . ($index + 2), $order['order']['pay_price']);
            $index++;
        }
 
        //保存文件
        $writer = new Xlsx($spreadsheet);
        $filename = iconv("UTF-8", "GB2312//IGNORE", '核销订单') . '-' . date('YmdHis') . '.xlsx';
 
        header('Content-Type: application/vnd.ms-excel');
        header('Content-Disposition: attachment;filename="' . $filename . '"');
        header('Cache-Control: max-age=0');
        $writer = IOFactory::createWriter($spreadsheet, 'Xlsx');
        $writer->save('php://output');
    }
 
    /**
     * 商户数据统计
     */
    public function supplierStatisticsList($list)
    {
        $spreadsheet = new Spreadsheet();
        $sheet = $spreadsheet->getActiveSheet();
 
        //设置工作表标题名称
        $sheet->setTitle('商户券数据统计');
 
        $sheet->setCellValue('A1', '商户ID');
        $sheet->setCellValue('B1', '商户名称');
        $sheet->setCellValue('C1', '线上券金额');
        $sheet->setCellValue('D1', '线上券数量');
        $sheet->setCellValue('E1', '线下券金额');
        $sheet->setCellValue('F1', '线下券数量');
        $sheet->setCellValue('G1', '总金额');
        //填充数据
        $index = 0;
        foreach ($list as $cash) {
            $sheet->setCellValue('A' . ($index + 2), $cash['shop_supplier_id']);
            $sheet->setCellValue('B' . ($index + 2), $cash['name']);
            $sheet->setCellValue('C' . ($index + 2), $cash['coupon_money']);
            $sheet->setCellValue('D' . ($index + 2), $cash['coupon_num']);
            $sheet->setCellValue('E' . ($index + 2), $cash['store_coupon_money']);
            $sheet->setCellValue('F' . ($index + 2), $cash['store_coupon_num']);
            $sheet->setCellValue('G' . ($index + 2), $cash['total_coupon_money']);
            $index++;
        }
        //保存文件
        $filename = iconv("UTF-8", "GB2312//IGNORE", '商户券数据统计') . '-' . date('YmdHis') . '.xlsx';
        header('Content-Type: application/vnd.ms-excel');
        header('Content-Disposition: attachment;filename="' . $filename . '"');
        header('Cache-Control: max-age=0');
        $writer = IOFactory::createWriter($spreadsheet, 'Xlsx');
        $writer->save('php://output');
    }
 
    /**
     * 商家收入明细导出
     */
    public function supplierCapitalList($data)
    {
        $list = $data["list"];
        $total_money = $data["total_money"];
        $spreadsheet = new Spreadsheet();
        $sheet = $spreadsheet->getActiveSheet();
 
        //设置工作表标题名称
        $sheet->setTitle('商家收支记录');
 
        $sheet->setCellValue('A1', '所属商户');
        $sheet->setCellValue('B1', '收支类型');
        $sheet->setCellValue('C1', '金额');
        $sheet->setCellValue('D1', '时间');
        $sheet->setCellValue('E1', '说明');
        $sheet->setCellValue('F1', '总金额');
 
        //填充数据
        $index = 0;
        foreach ($list as $cash) {
            $sheet->setCellValue('A' . ($index + 2), $cash['supplier']['name']);
            $sheet->setCellValue('B' . ($index + 2), $cash['flow_type'] == 10 ? '收入' : '支出');
            $sheet->setCellValue('C' . ($index + 2), $cash['money']);
            $sheet->setCellValue('D' . ($index + 2), $cash['create_time']);
            $sheet->setCellValue('E' . ($index + 2), $cash['describe']);
            $index++;
        }
        $sheet->setCellValue('F2', $total_money);
        //保存文件
        $filename = iconv("UTF-8", "GB2312//IGNORE", '商家收支记录') . '-' . date('YmdHis') . '.xlsx';
        header('Content-Type: application/vnd.ms-excel');
        header('Content-Disposition: attachment;filename="' . $filename . '"');
        header('Cache-Control: max-age=0');
        $writer = IOFactory::createWriter($spreadsheet, 'Xlsx');
        $writer->save('php://output');
    }
 
    /**
     * 商家收入提现记录导出
     */
    public function supplierCashList($data)
    {
        $list = $data["list"];
        $spreadsheet = new Spreadsheet();
        $sheet = $spreadsheet->getActiveSheet();
 
        //设置工作表标题名称
        $sheet->setTitle('商家收支提现记录');
 
        $sheet->setCellValue('A1', '所属商户');
        $sheet->setCellValue('B1', '金额');
        $sheet->setCellValue('C1', '时间');
        $sheet->setCellValue('D1', '说明');
        $sheet->setCellValue('E1', '状态');
 
        //填充数据
        $index = 0;
        foreach ($list as $cash) {
            if($cash["is_settled"] == 1){
                $status = "提现中";
            }elseif($cash["is_settled"] == 2){
                $status = "已提现";
            }else{
                $status = "未提现";
            }
            $sheet->setCellValue('A' . ($index + 2), $cash['supplier']['name']);
            $sheet->setCellValue('B' . ($index + 2), $cash['money']);
            $sheet->setCellValue('C' . ($index + 2), $cash['create_time']);
            $sheet->setCellValue('D' . ($index + 2), $cash['describe']);
            $sheet->setCellValue('E' . ($index + 2), $status);
            $index++;
        }
 
        //保存文件
        $filename = iconv("UTF-8", "GB2312//IGNORE", '商家收支提现记录') . '-' . date('YmdHis') . '.xlsx';
        header('Content-Type: application/vnd.ms-excel');
        header('Content-Disposition: attachment;filename="' . $filename . '"');
        header('Cache-Control: max-age=0');
        $writer = IOFactory::createWriter($spreadsheet, 'Xlsx');
        $writer->save('php://output');
    }
 
    /**
     * 收入统计导出
     */
    public function incomeList($list)
    {
        $spreadsheet = new Spreadsheet();
        $sheet = $spreadsheet->getActiveSheet();
 
        //设置工作表标题名称
        $sheet->setTitle('收入统计');
 
        $sheet->setCellValue('A1', '日期');
        $sheet->setCellValue('B1', '余额支付');
        $sheet->setCellValue('C1', '付呗支付');
        $sheet->setCellValue('D1', '线下支付');
        $sheet->setCellValue('E1', '其他支付');
        $sheet->setCellValue('F1', '优惠券');
        $sheet->setCellValue('G1', '满减金额');
        $sheet->setCellValue('H1', '积分金额');
        $sheet->setCellValue('I1', '退款金额');
 
        //填充数据
        $index = 0;
        foreach ($list as $item) {
            $sheet->setCellValue('A' . ($index + 2), $item['day']);
            $sheet->setCellValue('B' . ($index + 2), $item['pay_balance']);
            $sheet->setCellValue('C' . ($index + 2), $item['pay_wx']);
            $sheet->setCellValue('D' . ($index + 2), $item['pay_cash']);
            $sheet->setCellValue('E' . ($index + 2), $item['pay_other']);
            $sheet->setCellValue('F' . ($index + 2), $item['coupon']);
            $sheet->setCellValue('G' . ($index + 2), $item['fullreduce']);
            $sheet->setCellValue('H' . ($index + 2), $item['points']);
            $sheet->setCellValue('I' . ($index + 2), $item['refund_money']);
            $index++;
        }
 
        //保存文件
        $writer = new Xlsx($spreadsheet);
        $filename = iconv("UTF-8", "GB2312//IGNORE", '收入统计') . '-' . date('YmdHis') . '.xlsx';
 
        header('Content-Type: application/vnd.ms-excel');
        header('Content-Disposition: attachment;filename="' . $filename . '"');
        header('Cache-Control: max-age=0');
        $writer = IOFactory::createWriter($spreadsheet, 'Xlsx');
        $writer->save('php://output');
    }
 
    /**
     * 用户导出
     */
    public function userList($list)
    {
        $spreadsheet = new Spreadsheet();
        $sheet = $spreadsheet->getActiveSheet();
 
        //设置工作表标题名称
        $sheet->setTitle('会员列表');
 
        $sheet->setCellValue('A1', '用户id');
        $sheet->setCellValue('B1', '昵称');
        $sheet->setCellValue('C1', '姓名');
        $sheet->setCellValue('D1', '会员等级');
        $sheet->setCellValue('E1', '来源');
        $sheet->setCellValue('F1', '积分');
        $sheet->setCellValue('G1', '余额');
        $sheet->setCellValue('H1', '推荐人');
        $sheet->setCellValue('I1', '手机号');
        $sheet->setCellValue('J1', '注册时间');
 
        //填充数据
        $index = 0;
        foreach ($list as $item) {
            $reg_source = '小程序';
            if($item["reg_source"] == 'mp'){
                $reg_source = '公众号';
            }
            $nickName = $item['nickName'];
            if(!empty($nickName)){
                $nickName = $this->cutStr($nickName,10);
            }
            $sheet->setCellValue('A' . ($index + 2), $item['user_id']);
            $sheet->setCellValue('B' . ($index + 2), $nickName);
            $sheet->setCellValue('C' . ($index + 2), $item['real_name']);
            $sheet->setCellValue('D' . ($index + 2), empty($item['grade_id']) ? '无' : $item['grade']['name']);
            $sheet->setCellValue('E' . ($index + 2), $reg_source);
            $sheet->setCellValue('F' . ($index + 2), $item['points']);
            $sheet->setCellValue('G' . ($index + 2), $item['balance']);
            $sheet->setCellValue('H' . ($index + 2), $item['referee_name']);
            $sheet->setCellValue('I' . ($index + 2), $item['mobile']);
            $sheet->setCellValue('J' . ($index + 2), $item['create_time']);
            $index++;
        }
 
        //保存文件
        $writer = new Xlsx($spreadsheet);
        $filename = iconv("UTF-8", "GB2312//IGNORE", '会员') . '-' . date('YmdHis') . '.xlsx';
 
 
        header('Content-Type: application/vnd.ms-excel');
        header('Content-Disposition: attachment;filename="' . $filename . '"');
        header('Cache-Control: max-age=0');
        $writer = IOFactory::createWriter($spreadsheet, 'Xlsx');
        $writer->save('php://output');
    }
 
    /**
     * 连盟活动报名列表导出
     */
    public function activityUserList($list)
    {
        $spreadsheet = new Spreadsheet();
        $sheet = $spreadsheet->getActiveSheet();
        $title = $list[0]['activity']['branch']['name'] . '-' . $list[0]['activity']['name'] . '-' . '活动报名记录表';
        //设置工作表标题名称
        $sheet->setTitle('活动报名记录表');
 
        /*$sheet->setCellValue('A1', '用户id');
        $sheet->setCellValue('B1', '昵称');*/
        $sheet->setCellValue('A1', '姓名');
        $sheet->setCellValue('B1', '手机号');
        $sheet->setCellValue('C1', '邀请人');
        $sheet->setCellValue('D1', '邀请人手机号');
        $sheet->setCellValue('E1', '所属分会');
        /*$sheet->setCellValue('F1', '微信支付交易号');
        $sheet->setCellValue('G1', '积分抵扣金额');
        $sheet->setCellValue('H1', '余额抵扣金额');
        $sheet->setCellValue('I1', '在线支付金额');*//*
        $sheet->setCellValue('F1', '报名状态');
        $sheet->setCellValue('G1', '报名时间');
        $sheet->setCellValue('H1', '活动ID');
        $sheet->setCellValue('I1', '活动标题');*/
        foreach(range('A','E') as $columnID) {
            $sheet->getColumnDimension($columnID)->setAutoSize(true);
        }
        //填充数据
        $index = 0;
        foreach ($list as $item) {
            $sheet->setCellValue('A' . ($index + 2), $item['real_name']);
            $sheet->setCellValueExplicit('B' . ($index + 2), $item['mobile'] , \PhpOffice\PhpSpreadsheet\Cell\DataType::TYPE_STRING);
            $sheet->setCellValue('C' . ($index + 2), $item['recommend_name']);
            $sheet->setCellValueExplicit('D' . ($index + 2), $item['recommend_mobile'] , \PhpOffice\PhpSpreadsheet\Cell\DataType::TYPE_STRING);
 
            $sheet->setCellValue('E' . ($index + 2), empty($item['branch']) ? '无' : $item['branch']['name']);
           /* $sheet->setCellValue('F' . ($index + 2), $item['transaction_id']);
            $sheet->setCellValue('G' . ($index + 2), $item['points_money']);
            $sheet->setCellValue('H' . ($index + 2), $item['balance']);
            $sheet->setCellValue('I' . ($index + 2), $item['online_money']);*//*
            $sheet->setCellValue('F' . ($index + 2), $item['status_text']);
            $sheet->setCellValue('G' . ($index + 2), $item['create_time']);
            $sheet->setCellValue('H' . ($index + 2), $item['activity_id']);
            $sheet->setCellValue('I' . ($index + 2), $item['activity']['name']);*/
            $index++;
        }
 
        //保存文件
        $writer = new Xlsx($spreadsheet);
        $filename = iconv("UTF-8", "GB2312//IGNORE", $title) . '-' . date('YmdHis') . '.xlsx';
 
 
        header('Content-Type: application/vnd.ms-excel');
        header('Content-Disposition: attachment;filename="' . $filename . '"');
        header('Cache-Control: max-age=0');
        $writer = IOFactory::createWriter($spreadsheet, 'Xlsx');
        $writer->save('php://output');
    }
 
   public function cutStr($str, $maxLength) {
       $str=$this->filterEmoji($str);
       if(preg_match('/[\x{4e00}-\x{9fa5}]/u', $str)){
           return $str;
       };
 
        $pattern = '/[\x{4e00}-\x{9fa5}]+|[a-zA-Z]+/u';
        preg_match($pattern, $str, $matches, PREG_OFFSET_CAPTURE);
        if(empty($matches[0])){
            return '';
        }
        $start = $matches[0][1]; // 起始位置
        if(empty($matches[0][0])){
            return '';
        }
        $matchLength = strlen($matches[0][0]); // 匹配到的字符长度
 
 
        $end = $start + $matchLength - 1;
        $cutLength = 0;
 
        for ($i = $start; $i <= $end; $i++) {
            if (($maxLength - $cutLength) >= 2) {
                // 对于非英文字符,长度为2(UTF-8下)
                $cutLength += 2;
            } else if (($maxLength - $cutLength) == 1) {
                // 对于英文字符,长度为1
                $cutLength += 1;
            } else {
                break;
            }
        }
        $nickname = substr($str, 0, $i);
        return $nickname;
    }
 
    public function filterEmoji($str)
    {
        $str = preg_replace_callback(
            '/./u',
            function (array $match) {
                return strlen($match[0]) >= 4 ? '' : $match[0];
            },
            $str);
        return $str;
    }
 
 
    /**
     * 格式化提现信息
     */
    private function cashInfo($cash)
    {
        $content = '';
        if ($cash['pay_type']['value'] == 20) {
            $content .= "支付宝姓名:{$cash['alipay_name']}\n";
            $content .= "  支付宝账号:{$cash['alipay_account']}\n";
        } elseif ($cash['pay_type']['value'] == 30) {
            $content .= "开户行:{$cash['bank_name']}\n";
            $content .= "  姓名:{$cash['bank_account']}\n";
            $content .= "  卡号:{$cash['bank_account']}\n";
        }
        return $content;
    }
 
    /**
     * 格式化商品信息
     */
    private function filterProductInfo($order)
    {
        $content = '';
        foreach ($order['product'] as $key => $product) {
            $content .= ($key + 1) . ".商品名称:{$product['product_name']}\n";
            !empty($product['product_attr']) && $content .= " 商品规格:{$product['product_attr']}\n";
            $content .= " 购买数量:{$product['total_num']}\n";
            $content .= " 商品总价:{$product['total_price']}元\n\n";
        }
        return $content;
    }
 
 
    /**
     * 日期值过滤
     */
    private function filterTime($value)
    {
        if (!$value) return '';
        return date('Y-m-d H:i:s', $value);
    }
 
}