goodsUrl=env('GOODS_URL'); } public string $goodsUrl ; /** * Execute the job. * @throws GuzzleException */ public function handle(): void { switch ($this->type) { case 1: $this->addGoods(); break; case 2: case 3: case 4: case 5: } } /** * @throws GuzzleException * @throws \Exception */ public function addGoods(): void { $goods = []; $this->client = new Client(); foreach ($this->data as $item) { $product = apiRequest::requests($this->client,$this->goodsUrl,[ 'itemId' =>$item['result']['itemId'], ],FormType::json); if($product['errCode']!='0000'){ throw new \Exception('request item '. $item['item_id'].' err:' .$product['desc'] ?? ''); } $product = $product['data']['product']; $product['itemid'] = $product['itemId']; $good = new Good(); $good->fill($product); $goods[]=$good->toArray(); } Good::insert($goods); } }