Browse Source

祯仓接口数据调整

haozi 4 năm trước cách đây
mục cha
commit
11aebc6f1f

+ 6 - 12
app/Http/Controllers/TestController.php

@@ -727,18 +727,12 @@ sql;
 
     public function testZhenCang()
     {
-//        $batches=Batch::query()->where('id',161071)->get();
-//        BroadcastBatchToZhengCangJob::dispatch($batches);
-//        $sql = <<<sql
-//select department_id,obligation_id,owner_id,max(valid_time) from department_obligation_owner group by obligation_id,owner_id,department_id
-//sql;
-//        $info = DB::select(DB::raw($sql));
-//        dd($info);
-//        $owner=Owner::query()->with(['departmentObligationOwner'])->find(403);
-//        dd($owner);
-//        $a=app('ObligationService')->recombineCodeIdArr();
-        $now=Carbon::now()->subMonths(-1)->startOfMonth()->startOfDay()->toDateTimeString();
-        dd($now);
+        $batches=Batch::query()->where('id',255673)->get();
+//        dd($batches);
+        BroadcastBatchToZhengCangJob::dispatch($batches);
+
+
+
     }
 
     public function syncOrderIssue()

+ 40 - 13
app/Services/ForeignZhenCangService.php

@@ -13,26 +13,53 @@ class ForeignZhenCangService
 
     public function broadcastBatch($batches)
     {
+//        $body=[];
+//        $body['id']=$batches->code;
+//        $body['orders'] = [];
+//        foreach ($batches->orders as $order){
+//            $orderArr = [];
+//            $orderArr['id']=$order->code??'';
+//            $orderArr['createdAt']=Carbon::parse($order->created_at)->toDateTimeString()??'';
+//            $orderArr['barcodes'] = [];
+//            foreach ($order->orderCommodities as $orderCommodity){
+//                $barcode=[];
+//                $barcode['id']=$orderCommodity->id;
+//                $barcode['barcode']=$orderCommodity->commodity ? ($orderCommodity->commodity->barcodes?$orderCommodity->commodity->barcodes->first()['code']:'') : '';
+//                $barcode['name']=$orderCommodity->commodity->name??'';
+//                $barcode['sku']=$orderCommodity->commodity->sku??'';
+//                $barcode['amount']=$orderCommodity->amount??'';
+//                $barcode['location']=$orderCommodity->location??'';
+//                $orderArr['barcodes'][]=$barcode;
+//            }
+//            $body['orders'][] = $orderArr;
+//        }
+
+        //12.13
         $body=[];
         $body['id']=$batches->code;
-        $body['orders'] = [];
+        $body['slots'] = [];
         foreach ($batches->orders as $order){
             $orderArr = [];
-            $orderArr['id']=$order->code??'';
-            $orderArr['createdAt']=Carbon::parse($order->created_at)->toDateTimeString()??'';
-            $orderArr['barcodes'] = [];
             foreach ($order->orderCommodities as $orderCommodity){
-                $barcode=[];
-                $barcode['id']=$orderCommodity->id;
-                $barcode['barcode']=$orderCommodity->commodity ? ($orderCommodity->commodity->barcodes?$orderCommodity->commodity->barcodes->first()['code']:'') : '';
-                $barcode['name']=$orderCommodity->commodity->name??'';
-                $barcode['sku']=$orderCommodity->commodity->sku??'';
-                $barcode['amount']=$orderCommodity->amount??'';
-                $barcode['location']=$orderCommodity->location??'';
-                $orderArr['barcodes'][]=$barcode;
+                $orderArr['id']=$orderCommodity->location??'';
+                $orderArr['sku']=$orderCommodity->commodity->sku??'';
+                $orderArr['barcode']=$orderCommodity->commodity ? ($orderCommodity->commodity->barcodes?$orderCommodity->commodity->barcodes->first()['code']:'') : '';
+                $orderArr['name']=$orderCommodity->commodity->name??'';
+                $orderArr['amount']=$orderCommodity->amount??'';
+            }
+            $body['slots'][] = $orderArr;
+
+        }
+        $result=array();
+        foreach($body['slots'] as $val){
+            $key = $val['id'].'_'.$val['barcode'];
+            if(!isset($result[$key])){
+                $result[$key] = $val;
+            }else{
+                $result[$key]['amount'] += $val['amount'];
             }
-            $body['orders'][] = $orderArr;
         }
+        $body['slots']=array_values($result);
         dd($body);
         $response = Http::withHeaders([
             'Host' => 'zc-it.com',