Kaynağa Gözat

更新原来请求workapi的东西

cqp 2 ay önce
ebeveyn
işleme
6872eb4b88

+ 1 - 1
app/Service/ConstructionService.php

@@ -1925,7 +1925,7 @@ class ConstructionService extends Service
         if(! $status) return [false, $msg];
 
         //sn码map
-        $sn_list = $msg['data'];
+        $sn_list = $msg;
         $sn_map = [];
         foreach ($sn_list as $value){
             $key = $value['code'] . $value['sn'];

+ 33 - 3
app/Service/DataSyncToU8Service.php

@@ -94,10 +94,17 @@ class DataSyncToU8Service extends Service
     public function getSnFromU8($data, $user){
         if(empty($data['sn_type'])) return [false, 'sn码来源依据不能为空'];
         if(empty($data['code'])) return [false, '产品编码不能为空'];
-        list($status,$return) = $this->getSnList($data, $user);
+        $data['depart_title'] = $this->getMyTopDepart($user,true);
+
+        $service = new U8ServerService(true);
+        if(! empty($service->error)) return [false, $service->error];
+
+        list($status,$return) = $service->getSnList($data, $user);
+//        list($status,$return) = $this->getSnList($data, $user);
         return [$status, $return];
     }
 
+    //todo 废弃一
     public function getSnList($data, $user){
         $header = ['Content-Type:application/json'];
         $construction_id = $data['construction_id'] ?? 0;
@@ -176,7 +183,7 @@ class DataSyncToU8Service extends Service
         if(! $status) return [false, $msg];
 
         //sn码map
-        $sn_list = $msg['data'];
+        $sn_list = $msg;
         $sn_map = [];
         foreach ($sn_list as $value){
             $key = $value['code'] . $value['sn'];
@@ -272,6 +279,13 @@ class DataSyncToU8Service extends Service
 
     //获取在库的sn码信息通过sn码和产品编码
     public function getSnForMap($code, $sn){
+        $service = new U8ServerService(true);
+        if(! empty($service->error)) return [false, $service->error];
+
+        list($status, $msg) = $service->getSnListFormU8ForMap(['code' => $code, 'sn' => $sn]);
+        return [$status, $msg];
+
+        // todo 废弃二
         $header = ['Content-Type:application/json'];
         $post = [
             'urlFromT9' => 'getSnMap',
@@ -284,7 +298,7 @@ class DataSyncToU8Service extends Service
 
         if($msg['code'] != 200) return [false, $msg['msg']];
 
-        return [true, $msg];
+        return [true, $msg['data'] ?? []];
     }
 
     //获取在库的sn码信息通过sn码 客户手动创建质保
@@ -308,6 +322,13 @@ class DataSyncToU8Service extends Service
 
     //更新sn信息
     public function updateSnInfo($sn_type, $sn_for_u8,$data_id){
+        $service = new U8ServerService(true);
+        if(! empty($service->error)) return [false, $service->error];
+
+        list($status, $msg) = $service->saveSnUseDataDetail($sn_type, $sn_for_u8, $data_id);
+        return [$status, $msg];
+
+        //todo 废弃三
         $header = ['Content-Type:application/json'];
         $post = [
             'urlFromT9' => 'saveSnUseData',
@@ -325,6 +346,15 @@ class DataSyncToU8Service extends Service
     }
 
     public function snForWarranty($data){
+        $service = new U8ServerService(true);
+        if(! empty($service->error)) return [false, $service->error];
+
+        list($status, $msg) = $service->getSnForWarrantyData($data);
+        if(! $status) return [false, $msg];
+        if(empty($msg)) return [false, '产品序列码不存在'];
+        return [$status, $msg];
+
+        //todo 废弃四
         $header = ['Content-Type:application/json'];
         $post = [
             'urlFromT9' => 'getSnForWarranty',

+ 29 - 22
app/Service/ProductService.php

@@ -1570,13 +1570,16 @@ class ProductService extends Service
         $head = $user['head']['id'] ?? 0;
         $storehouse_id = Storehouse::where('top_depart_id', $head)->where('del_time',0)->value('id') ?? 0;
 
+        $service = new U8ServerService(true);
+        if(! empty($service->error)) return [false, $service->error];
+
         $time = time();
         DB::table('product')
             ->where('del_time', 0)
             ->where('top_depart_id', $head)
             ->select('id','code')
             ->orderBy('id')
-            ->chunk(200, function ($data) use($head,$storehouse_id,$time){
+            ->chunk(200, function ($data) use($head,$storehouse_id,$time,$service){
                 $data = Collect($data)->map(function ($object) {
                     return (array)$object;
                 })->toArray();
@@ -1584,16 +1587,18 @@ class ProductService extends Service
                 $map = array_column($data,'id','code');
                 $id = array_unique(array_column($data,'id'));
                 $code = array_unique(array_column($data,'code'));
-                $post = [
-                    'urlFromT9' => 'getStock',
-                    'code' => $code,
-                    'warehouse' => '001',
-                ];
-                $post = json_encode($post);
-                $header = ['Content-Type:application/json'];
-                list($status, $msg) = $this->post_helper("https://workapi.qingyaokeji.com/api/updateTopStock",$post, $header);
-                if($msg['code'] != 200) return [false, $msg['msg']];
-                $msg = $msg['data'] ?? [];
+                list($status, $msg) = $service->getStock($code, "001");
+                if(! $status) return [false, $msg];
+//                $post = [
+//                    'urlFromT9' => 'getStock',
+//                    'code' => $code,
+//                    'warehouse' => '001',
+//                ];
+//                $post = json_encode($post);
+//                $header = ['Content-Type:application/json'];
+//                list($status, $msg) = $this->post_helper("https://workapi.qingyaokeji.com/api/updateTopStock",$post, $header);
+//                if($msg['code'] != 200) return [false, $msg['msg']];
+//                $msg = $msg['data'] ?? [];
 
                 $insert = [];
                 foreach ($msg as $value){
@@ -1663,7 +1668,7 @@ class ProductService extends Service
                 ->where('top_depart_id', $head)
                 ->select('id','code')
                 ->orderBy('id')
-                ->chunk(200, function ($data) use($head,$storehouse_id,$time){
+                ->chunk(200, function ($data) use($head,$storehouse_id,$time,$service){
                     $data = Collect($data)->map(function ($object) {
                         return (array)$object;
                     })->toArray();
@@ -1671,16 +1676,18 @@ class ProductService extends Service
                     $map = array_column($data,'id','code');
                     $id = array_unique(array_column($data,'id'));
                     $code = array_unique(array_column($data,'code'));
-                    $post = [
-                        'urlFromT9' => 'getStock',
-                        'code' => $code,
-                        'warehouse' => '001',
-                    ];
-                    $post = json_encode($post);
-                    $header = ['Content-Type:application/json'];
-                    list($status, $msg) = $this->post_helper("https://workapi.qingyaokeji.com/api/updateTopStock",$post, $header);
-                    if($msg['code'] != 200) return [false, $msg['msg']];
-                    $msg = $msg['data'] ?? [];
+                    list($status, $msg) = $service->getStock($code, "001");
+                    if(! $status) return [false, $msg];
+//                    $post = [
+//                        'urlFromT9' => 'getStock',
+//                        'code' => $code,
+//                        'warehouse' => '001',
+//                    ];
+//                    $post = json_encode($post);
+//                    $header = ['Content-Type:application/json'];
+//                    list($status, $msg) = $this->post_helper("https://workapi.qingyaokeji.com/api/updateTopStock",$post, $header);
+//                    if($msg['code'] != 200) return [false, $msg['msg']];
+//                    $msg = $msg['data'] ?? [];
 
                     $insert = [];
                     foreach ($msg as $value){