ajun 4 лет назад
Родитель
Сommit
f385d44b60
1 измененных файлов с 32 добавлено и 1 удалено
  1. 32 1
      app/Services/OrderCommodityService.php

+ 32 - 1
app/Services/OrderCommodityService.php

@@ -6,10 +6,12 @@ use App\Batch;
 use App\OracleActAllocationDetails;
 use App\Order;
 use App\OrderCommodity;
+use App\OrderPackage;
 use App\Services\common\BatchUpdateService;
 use App\Services\common\DataHandlerService;
 use Carbon\Carbon;
 use App\Traits\ServiceAppAop;
+use Illuminate\Support\Collection;
 
 
 class OrderCommodityService
@@ -89,7 +91,8 @@ class OrderCommodityService
         }
         $orders = Order::query()->with('packages.commodities')->whereIn('code',$orderNos)->get();
         if($orders->count()==0)return;
-        $orderCommodities = OrderCommodity::query()->with(['order','commodity'])->whereIn('order_id',data_get($orders,'*.id'))->get();
+        $orderCommodities = $this->getCommoditiesByOrderIds(data_get($orders,'*.id'));
+        // OrderCommodity::query()->with(['order','commodity'])->whereIn('order_id',data_get($orders,'*.id'))->get();
         $order_code_map = $dataHandlerService->dataHeader(['code'],$orders);
         $ActAllocationDetail_maps =  $this->getRegroupActAllocationDetails($orderHeaders);
         $orderCommodity_maps = $this->getRegroupOrderCommodities($orderCommodities,$owner_id_maps);
@@ -113,6 +116,34 @@ class OrderCommodityService
         unset($delete_ids);
     }
 
+    public function getCommoditiesByOrderNos($orderNos)
+    {
+        $orderIds = [];
+        $order_chunks = array_chunk($orderNos,150);
+        foreach ($order_chunks as $order_chunk) {
+            $ids = Order::query()->select('id')->whereIn('code',$order_chunk)->get()->map(function($order){
+                return $order->id;
+            })->toArray();
+            $orderIds = array_merge($orderIds,$ids);
+        }
+       return $this->getCommoditiesByOrderIds($orderIds);
+    }
+
+    public function getCommoditiesByOrderIds($orderIds)
+    {
+        $orderCommodities = null;
+        $orderId_chunks = array_chunk($orderIds,150);
+        foreach ($orderId_chunks as $orderId_chunk){
+            $items = OrderCommodity::query()->with(['order','commodity'])->whereIn('order_id',$orderId_chunk)->get();
+            if ($orderCommodities == null){
+                $orderCommodities = $items;
+            }else{
+                $orderCommodities = $orderCommodities->concat($items);
+            }
+        }
+        return $orderCommodities ?? new Collection();
+    }
+
     public function getRegroupActAllocationDetails(&$orderHeaders)
     {
         $map = [];