<?php

namespace App\Imports;

use App\Facades\HttpService;
use App\Models\OperateStockLog;
use App\Models\User;
use GuzzleHttp\Client;
use Illuminate\Support\Facades\Cache;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Log;
use Maatwebsite\Excel\Concerns\ToModel;

class AgentUsersImport implements \Maatwebsite\Excel\Concerns\ToArray
{
    /**
    * @param array $row
     *
    */
    public function array(array $rows)
    {
        $url = config('app.shop_url') . "admin/group/user/agent/orders";
        $res = HttpService::getData($url);
        $members = $res['data'];
//        dd($members);
        $index = 0;
        foreach ($rows as $row) {

            if ($index <= 2) {
                $index++;
                continue;
            }
            if(!$row[0]) break;
            $num = $row[2];
            $mobile = $row[15];
            $member = collect($members)->first(function ($member) use($mobile) {
                return $member['user']['mobile'] == $mobile;
            });
            if(empty($member)) {
                Log::info("用户手机号：$mobile, 未查到信息");
                continue;
            }
            if ($member['count'] != $num) {
                Log::info("用户手机号：$mobile, 订购数：$num, 记录数：{$member['count']}");
            }
            $index++;
        }
    }


}
