<?php

namespace App\Exports;

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

class ActivityMemberLogExport 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);
            $res = aesDecryptCBC($member->user->mobile);
            if (empty($res)) {
                $mobile = $member->user->mobile;
            }else {
                $mobile = $res;
            }
            $items[] = [$member->user->id, $member->user->name, $mobile, $member->created_at->toDateTimeString(),$level];
        }
        return collect($items);
    }

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