<?php

namespace App\Imports;

use App\Models\ShopCode;
use App\Models\User;
use Illuminate\Support\Facades\Hash;

class ImportPackCode implements \Maatwebsite\Excel\Concerns\ToArray
{

    /**
     * @inheritDoc
     */
    public function array(array $array)
    {
        $count = ShopCode::count();
        if ($count) return;
        $list = [];
        $index = 1;
        foreach ($array as $arr)
        {
            for ($i = 0; $i<6; $i++) {
                $code_arr = explode('/', $arr[0]);
                $pack_code = $code_arr[count($code_arr)-1];
                $verify_code = $arr[1];
                $pack_number = "P".time().$index;
                $list[] = ['goods_id'=>1, 'sku_id'=>1, 'code'=>'', 'pack_code'=>$pack_code, 'verify_code'=>$verify_code, 'pack_number'=>$pack_number];
            }
            $index++;

        }
        ShopCode::insert($list);
    }
}
