<?php

namespace App\Exports;

use Maatwebsite\Excel\Concerns\FromArray;
use Maatwebsite\Excel\Concerns\FromCollection;
use Maatwebsite\Excel\Concerns\WithEvents;
use Maatwebsite\Excel\Concerns\WithHeadings;
use Maatwebsite\Excel\Concerns\WithStyles;

class ActivityRefundExport implements FromArray,WithHeadings
{

    protected $logs;

    public function __construct($logs)
    {
        $this->logs = $logs;
    }

    public function array():array
    {
        $items = [];
        foreach ($this->logs as $log){
            $type = $log->type == 'ADMIN'?"用户申请退款":"介绍人退款";
            $items[] = [
                $log->order->activity->title,
                $log->order->trade_no,
                $log->order->name,
                $log->order->mobile,
                $log->targetOrder && $log->target_order_id != $log->order_id?$log->targetOrder->name:"",
                $log->targetOrder && $log->target_order_id != $log->order_id?$log->targetOrder->mobile:"",
                $log->amount,
                $type,
                $log->reason,
                $log->created_at->toDateTimeString(),
            ];
        }
        return $items;
    }


    public function headings(): array
    {
        return [
            ['活动名称','订单号', '姓名', '手机号', "推荐订单-姓名", "推荐订单-手机号",'退款金额','退款类型','拒绝原因','操作时间']
        ];
    }
}
