<?php

namespace App\Exports;

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

class RegularActivityOrdersExport implements FromCollection, WithHeadings
{

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

    /**
    * @return \Illuminate\Support\Collection
    */
    public function collection()
    {
        $orders = $this->orders;
        $items = [];
        foreach ($orders as $order) {
            $level = $order->agentUser?$order->agentUser->level:0;
            if ($level == 2) {
                $name = "准批发商";
            }elseif ($level == 1) {
                $name = "批发商";
            }else {
                $name = "非批发商";
            }
            $items[] = [
                $order->name,
                $order->mobile,
                $name,
                $order->is_apply_food?"已报餐":"未报餐",
                $order->sign_in?"已签到":"未签到",
                $order->created_at->toDateTimeString(),
            ];
        }
        return collect($items);
    }

    public function headings(): array
    {
        return ["名称","手机号","批发商资格","是否报餐","是否签到","报名时间"];
    }
}
