getCellAtIndex(0)?->getValue(); if (empty($orderSn)) { throw new ImportException('未输入订单编号'); } //获取商品ID; $skuId = $row->getCellAtIndex(2)?->getValue(); if (empty($skuId)) { throw new ImportException('未输入商品编号'); } //获取快递公司#8 $shippingCompany = $row->getCellAtIndex(9)?->getValue(); if (empty($shippingCompany)) { throw new ImportException('未输入快递公司'); } if (!(OrderPackageModel::$shippingCompanyTexts[$shippingCompany] ?? '')) { throw new ImportException('未找到快递公司:'.$shippingCompany); } //获取运单号#9 $shippingNumber = $row->getCellAtIndex(10)?->getValue(); if (empty($shippingNumber)) { throw new ImportException('未输入快递单号'); } //获取发货数量#10 $quantity = $row->getCellAtIndex(11)?->getValue(); if (empty($quantity)) { throw new ImportException('发货数量不能为0'); } //找到对应订单 $order = Order::where('sn', $orderSn)->first(); if ($order) { $orderPackageService = new OrderPackageService(); $orderPackage = OrderPackageModel::where([ 'order_id' =>$order->id, 'shipping_code'=>Arr::get(Kuaidi100Service::$codeArr, $shippingCompany, ''), 'shipping_number'=>$shippingNumber, ])->first(); $orderProduct = $order->load('products')->products->where('sku_id', $skuId)->first(); if (!$orderProduct) { throw new ImportException('未找到订单商品'); } $orderPackageService->createPackage($order, [ 'shipping_company'=>$shippingCompany, 'shipping_number'=>$shippingNumber, 'packages'=>[ [ 'order_product_id'=>$orderProduct->id, 'quantity' =>$quantity, ], ], ], $orderPackage); } else { throw new ImportException('未找到订单:'.$orderSn); } } }