<?php

namespace App\Exports;

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

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


    public function headings(): array
    {
        return [
            ['用户id','用户昵称','用户头像', '用户手机', '提现金额','提现时间']
        ];
    }

    public function array():array
    {
        $rows =[];
        $orders = $this->data;
        foreach ($orders as $order)
        {
            $rows[] = ['id'=>$order["user_id"], 'nickname'=>$order['user']['name'], 'pic'=>$order['user']['avatar'], 'mobile'=>$order['user']['mobile'],
                'amount'=>$order['amount'], 'time'=>$order['created_at']];
        }
        return $rows;
    }
}
