<?php

namespace App\Exports;

use App\Models\AgentUser;
use Maatwebsite\Excel\Concerns\FromCollection;
use Maatwebsite\Excel\Concerns\WithHeadings;

class ActivityMemberExport implements FromCollection, WithHeadings
{

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

    /**
    * @return \Illuminate\Support\Collection
    */
    public function collection()
    {
        $items = [];
        foreach ($this->members as $member) {
            $level = AgentUser::agentName($member->level);

            $items[] = [$member->user->id, $member->user->name, $member->user->mobile, $member->status?"成功":"失败", $member->updated_at->toDateTimeString(), $level];
        }
        return collect($items);
    }

    public function headings(): array
    {
        return [
            ['用户id','姓名', '手机号','状态','签到时间','身份']
        ];
    }
}
