<?php

namespace App\Exports;

use Maatwebsite\Excel\Concerns\FromCollection;
use Maatwebsite\Excel\Concerns\WithHeadings;

class OrderSharesExport implements FromCollection, WithHeadings
{

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

    /**
    * @return \Illuminate\Support\Collection
    */
    public function collection()
    {
        $logs = $this->logs;

        $items = [];
        foreach ($logs as $log) {
            $items[] = [
                $log->user->name,
                $log->user->mobile,
                $log->trade_no,
                $log->amount,
                $log->created_at->toDateTimeString(),
            ];
        }
        return collect($items);
    }

    public function headings(): array
    {
        return [
            ['用戶姓名','手机号', '订单号', '分润金额',"申请时间"]
        ];
    }
}
