get(); foreach ($details as $key => $detail) { $this->createByOrderDetail($detail, $orderPackage); } } public function basedOnActAllocationDetailsStoreByOrderNo($orderNo,$orderPackage){ $details = OracleActAllocationDetails::where('orderno', $orderNo)->get(); foreach ($details as $key => $detail) { $this->createByActAllocationDetails($detail, $orderPackage); } } public function basedOnActAllocationDetailsStore($orderPackage) { $details = OracleActAllocationDetails::where('picktotraceid', $orderPackage->logistic_number)->get(); foreach ($details as $key => $detail) { $this->createByActAllocationDetails($detail, $orderPackage); } } private function createByActAllocationDetails($detail, OrderPackage $orderPackage) { $owner = Owner::where(['code' => $detail->customerid])->first(); // 货主 $sku = $detail->sku; $owner_id = $owner['id']; $commodity = Commodity::where(['sku' => $sku, 'owner_id' => $owner_id])->first(); if ($commodity == null) { $basSku = OracleBasSKU::where(['sku' => $sku, 'customerid' => $detail->customerid])->first(); $commodity = Commodity::create(['sku' => $sku, 'owner_id' => $owner_id, 'name' => $basSku->descr_c]); } return OrderPackageCommodities::create(['order_package_id' => $orderPackage['id'], 'commodity_id' => $commodity['id'], 'amount' => $detail['qty']]); } public function getOrderPackageCommoditiesByOrderId($orderId) { $order = Order::where('id', $orderId)->first(); if (!$order) { return null; } $orderPackageIds = OrderPackage::select('id')->where('order_id', $order['id'])->get(); if (!$orderPackageIds) { return null; } return OrderPackageCommodities::with('commodity')->whereIn('order_package_id', $orderPackageIds)->get(); } public function createByOrderDetail(OracleDOCOrderDetail $detail, OrderPackage $orderPackage) { $owner = Owner::where(['code' => $detail['customerid']])->first(); // 货主 $sku = $detail->sku; // sku $owner_id = $owner->id; // 货主id $commodity = Commodity::where(['sku' => $sku, 'owner_id' => $owner_id])->first(); // 商品 if ($commodity == null) { $basSku = OracleBasSKU::where(['sku' => $sku, 'customerid' => $detail->customerid])->first(); // 没有找到对应的商品信息 $commodity = Commodity::create(['sku' => $sku, 'owner_id' => $owner_id, 'name' => $basSku->descr_c]); } return OrderPackageCommodities::create(['order_package_id' => $orderPackage['id'], 'commodity_id' => $commodity['id'], 'amount' => $detail['qtyordered']]); } }