<?php

namespace App\Exports;

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

class AgentEarningsExport 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["order_id"], 'total'=>$order['total'], 'amount'=>$order['amount'], 'wechat_fee'=>$order['wechat_fee'], 'ufutx_fee'=>$order['ufutx_fee'], 'time'=>$order['created_at']];
        }
        return $rows;
    }
}
