50 lines
1.5 KiB
PHP
50 lines
1.5 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 EvalOrdersExprt implements FromCollection ,WithHeadings,WithStrictNullComparison,WithColumnFormatting,ShouldAutoSize
|
||
|
|
{
|
||
|
|
private $data;
|
||
|
|
public function __construct($data)
|
||
|
|
{
|
||
|
|
$this->data = $data;
|
||
|
|
}
|
||
|
|
public function headings(): array
|
||
|
|
{
|
||
|
|
return [
|
||
|
|
'名称',
|
||
|
|
'金额',
|
||
|
|
'姓名',
|
||
|
|
'支付状态',
|
||
|
|
'支付类型',
|
||
|
|
'是否使用',
|
||
|
|
'订单号',
|
||
|
|
'时间'
|
||
|
|
];
|
||
|
|
}
|
||
|
|
//设置列格式
|
||
|
|
public function columnFormats(): array
|
||
|
|
{
|
||
|
|
return [
|
||
|
|
'A' => NumberFormat::FORMAT_TEXT,
|
||
|
|
];
|
||
|
|
}
|
||
|
|
public function collection()
|
||
|
|
{
|
||
|
|
$arr = [];
|
||
|
|
foreach ($this->data as $data) {
|
||
|
|
$arr[] = ['title'=>$data->goods, 'amount'=>$data->price, 'name'=>$data->name, 'pay_status'=>$data->pay_status?"已支付":"未支付",
|
||
|
|
'pay_type'=>($data->pay_type == 'free')?'优惠券':"微信", ''=>($data->user_evaluate&&$data->user_evaluate->evaluate_report)?"已使用":"未使用", 'trade_no'=>$data->trade_no.' ', 'time'=>$data->created_at->toDateTimeString()];
|
||
|
|
}
|
||
|
|
$arr = collect($arr);
|
||
|
|
return $arr;
|
||
|
|
}
|
||
|
|
}
|