cqp 5 dní pred
rodič
commit
57ae6c3045

+ 11 - 0
app/Http/Controllers/Api/TestController.php

@@ -54,6 +54,17 @@ class TestController extends BaseController
         }
     }
 
+    public function purchaseOrderGet(Request $request){
+        $common_array = $request->common_param;
+        list($bool, $data) = (new TestService())->purchaseOrderGet($request->all(),$common_array);
+
+        if($bool){
+            return $this->json_return(200,'',$data);
+        }else{
+            return $this->json_return(201,$data);
+        }
+    }
+
     public function materialAddU8(Request $request){
         $common_array = $request->common_param;
         list($bool, $data) = (new TestService())->materialAddU8($request->all(), $common_array);

+ 76 - 0
app/Service/TestService.php

@@ -285,6 +285,81 @@ class TestService extends Service
         return $return;
     }
 
+    public function purchaseOrderGet($data, $common_array){
+        list($status, $msg) = $this->getToken($common_array);
+        if(! $status) return [false, $msg];
+        list($host, $token) = $msg;
+
+        $today = (new \DateTime())->setTime(0, 0, 0)->format('Y-m-d H:i:s') . '.000';
+        $fourDaysAgo = (new \DateTime())->sub(new \DateInterval('P4D'))->setTime(0, 0, 0)->format('Y-m-d H:i:s') . '.000';
+
+        $page = $data['pageSize'] ?? 10;
+        $version = $data['version'] ?? 0;
+        $start_time = $data['start_time'] ?? $today;
+        $end_time = $data['end_time'] ?? $today;
+        $order_number = $data['order_number'] ?? '';
+
+        $header = ["Authorization: {$token}",'Content-Type:application/json'];
+        $url = $host . "/api/System/SqlQuery";
+        $json = [
+            'customSQLFileName' => "U8SQL",
+            'customSQLPath' => 'U8API/PurchaseOrderController/Get',
+            'paramObj' => [
+                "@pagesize" => $page,
+                "@where" => "AND m.dPODate >= '$start_time' AND m.dPODate <= '$end_time'",
+                "@code" => $order_number,
+                "@version" => $version,
+            ]
+        ];
+        $json = json_encode($json);
+
+        list($status, $result) = $this->post_helper($url,$json, $header, 60, $common_array['title'] . '获取采购订单');
+        if(! $status) return [false, $result];
+
+        if(! isset($result['code'])) return [false, '拉取采购订单失败,请重新拉取'];
+        if($result['code'] != 0) return [false, $result['msg']];
+        if(empty($result['data'])) return [true, []];
+
+        $r_data = $result['data'];
+        $return = $this->returnPurchaseOrders($common_array, $r_data, $msg);
+
+        return [true, $return];
+    }
+
+    private function returnPurchaseOrders($common_array, $r_data, $msg){
+        $site = $common_array['site'];
+        $title = $common_array['title'];
+        $return = [];
+        foreach ($r_data as $key => $value){
+            list($status, $detail) = $this->getPurchaseDetail($value, $msg, $title);
+            if(! $status) return [false, $detail];
+            $r_data[$key]['detail'] = $detail;
+        }
+
+        return $r_data;
+    }
+
+    private function getPurchaseDetail($sale_order, $msg, $title){
+        list($host, $token) = $msg;
+
+        $header = ["Authorization: {$token}",'Content-Type:application/json'];;
+        $url = $host . "/api/System/SqlQuery2";
+        $json = [
+            "selectSQL" => "",
+            "customSQLFileName"=> "U8SQL",
+            "customSQLPath"=> "U8API/PurchaseOrderController/GetVoucherData",
+            "paramObj"=> [
+                "@poid"=> $sale_order["poid"]
+            ]
+        ];
+        list($status, $result) = $this->post_helper($url, json_encode($json), $header, 30, $title . '获取采购订单详情');
+        if(! $status) return [false, $result];
+        if(! isset($result['code'])) return [false, '拉取采购订单详情失败,请重新拉取'];
+        if($result['code'] != 0) return [false, $result['msg']];
+
+        return [true, $result['data']['DataTable1']];
+    }
+
     private function SetU8($common_array){
 //        $api_host = env('API_HOST');
 //        if(empty($api_host)) return [false, '用友对外域名不存在'];
@@ -501,6 +576,7 @@ class TestService extends Service
         curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'POST');
         curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
         curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
+        curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
         curl_setopt($ch, CURLOPT_TIMEOUT, $timeout);
         curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 10);
 

+ 1 - 0
routes/api.php

@@ -68,6 +68,7 @@ Route::any('recordList', 'Api\TestController@recordList');
 Route::any('getInventoryStock', 'Api\TestController@getInventoryStock');
 Route::group(['middleware'=> ['CheckU8']],function ($route){
     $route->any('salesOrderGet', 'Api\TestController@salesOrderGet');
+    $route->any('purchaseOrderGet', 'Api\TestController@purchaseOrderGet');
     $route->any('materialAddU8', 'Api\TestController@materialAddU8')->middleware('U8Deal');
     $route->any('productInAddU8', 'Api\TestController@productInAddU8')->middleware('U8Deal');
     $route->any('dispatchAddU8', 'Api\TestController@dispatchAddU8')->middleware('U8Deal');