<?php

namespace App\Exports;

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

class AgentUsersSimpleExport implements FromArray,WithHeadings
{
    protected $data;
    public function __construct($data)
    {
        $this->data = $data;
    }


    public function headings(): array
    {
        return [
            ['openid', 'level', 'remark']
        ];
    }
    public function array():array
    {
        $rows =[];
        $users = $this->data;
        foreach ($users as $user)
        {
            if ($user->level == 1) {
                $remark = "经销商";
            }elseif ($user->level == 2) {
                $remark = "准经销商";
            }
            $rows[] = [
                $user->officialWechat->openid,
                $user->level,
                $remark
            ];
        }
        return $rows;
    }
}
