50 lines
1.4 KiB
PHP
50 lines
1.4 KiB
PHP
|
|
<?php
|
||
|
|
|
||
|
|
namespace App\Exports;
|
||
|
|
|
||
|
|
use Maatwebsite\Excel\Concerns\FromCollection;
|
||
|
|
use Maatwebsite\Excel\Concerns\ShouldAutoSize;
|
||
|
|
use Maatwebsite\Excel\Concerns\WithColumnFormatting;
|
||
|
|
use Maatwebsite\Excel\Concerns\WithHeadings;
|
||
|
|
use Maatwebsite\Excel\Concerns\WithStrictNullComparison;
|
||
|
|
use PhpOffice\PhpSpreadsheet\Style\NumberFormat;
|
||
|
|
|
||
|
|
class MerchantEarningExport implements FromCollection ,WithHeadings,WithStrictNullComparison,WithColumnFormatting,ShouldAutoSize
|
||
|
|
{
|
||
|
|
private $data;
|
||
|
|
public function __construct($data)
|
||
|
|
{
|
||
|
|
$this->data = $data;
|
||
|
|
}
|
||
|
|
public function headings(): array
|
||
|
|
{
|
||
|
|
return [
|
||
|
|
"ID",
|
||
|
|
"订单号",
|
||
|
|
"来源商家",
|
||
|
|
'订单金额',
|
||
|
|
'订单退款金额',
|
||
|
|
'微信手续费',
|
||
|
|
'提现手续费',
|
||
|
|
'订单时间',
|
||
|
|
'月份'
|
||
|
|
];
|
||
|
|
}
|
||
|
|
//设置列格式
|
||
|
|
public function columnFormats(): array
|
||
|
|
{
|
||
|
|
return [
|
||
|
|
'A' => NumberFormat::FORMAT_TEXT,
|
||
|
|
];
|
||
|
|
}
|
||
|
|
public function collection()
|
||
|
|
{
|
||
|
|
$arr = [];
|
||
|
|
foreach ($this->data as $data) {
|
||
|
|
$arr[] = ['id'=>$data->id, '订单号'=>$data->trade_no.' ','name'=>$data->goods, 'amount'=>$data->price, 'refund'=>0, 'ratio'=>0.006, 'w_ratio'=>0, 'date'=>$data->created_at->toDateTimeString(), 'month'=> date('m', strtotime($data->created_at->toDateTimeString()))];
|
||
|
|
}
|
||
|
|
$arr = collect($arr);
|
||
|
|
return $arr;
|
||
|
|
}
|
||
|
|
}
|