<?php

namespace App\Exports;

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

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


    public function headings(): array
    {
        return [
            ['用户ID','商品名称','商品图片', '提现类型', '收货人姓名', '收货人手机号', '收货人地址','提取数量','提取时间', '状态','快递公司', '快递单号']
        ];
    }

    public function array():array
    {
        $rows =[];
        $stocks = $this->data;
        foreach ($stocks as $stock)
        {
            $rows[] = ['id'=>$stock["id"], 'title'=>$stock['shop']['title'], 'pic'=>$stock['shop']['icon'], 'sku_name'=>$stock['type'] == 'ONLINE'?"线上提取":"线下提取",
                'name'=>$stock['name'], 'mobile'=>$stock['mobile'], 'address'=>$stock['address'], 'num'=>$stock['num'], 'created_at'=>$stock['created_at'],
                'status'=>$stock['status'] == 'AUDIT'?"待发货":"已发货", 'express'=>$stock['express'], 'express_no'=>$stock['express_no']];
        }
        return $rows;
    }
}
