<?php

namespace App\Exports;

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

class TestActivityMembersExport implements  FromArray,WithHeadings
{

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

    /**
    * @return \Illuminate\Support\Collection
    */
    public function array():array
    {
        $members = $this->members;
        $rows = [];
        foreach ($members as $member)
        {
            if(empty($member->agentUser)) {
                $level = "客户";
            }else {
                $level = "";
                switch ($member->agentUser->level)  {
                    case 0:
                        $level = "客户";
                        break;
                    case 1:
                        $level = "批发商";
                        break;
                    case 2:
                        $level = "准批发商";
                        break;
                    case 3:
                        $level = "员工";
                        break;
                    case 4:
                        $level = "VIP";
                        break;
                }
            }

            $rows[] = [
                $member->user_id,
                $member->user->name,
                $member->user->mobile,
                $member->status?"成功":"失败",
                $level,
                $member->amount?:"0",
            ];
        }
        return $rows;
    }

    public function headings(): array
    {
        return [
            ["用户id",'姓名','手机号', '签到状态', '角色',"余额"]
        ];
    }
}
