reloadnike 2 years ago
parent
commit
4cce7dec2f
1 changed files with 25 additions and 12 deletions
  1. 25 12
      App/HttpController/Index.php

+ 25 - 12
App/HttpController/Index.php

@@ -5,6 +5,7 @@ namespace App\HttpController;
 
 
 use EasySwoole\Http\AbstractInterface\Controller;
+use Swoole\Coroutine\Channel;
 use App\Com\JdSdk;
 
 // 或者使用如下:
@@ -74,8 +75,9 @@ class Index extends Controller
      */
     public function skuState()
     {
-
-
+        $channel = new Channel(1);
+        // 或者使用如下:
+        go(function() use($channel){
             // 获取 `POST` 或者 `GET` 提交的所有参数
             $data = $this->request()->getRequestParam();
 
@@ -83,19 +85,19 @@ class Index extends Controller
 
             $this->JdSdk = new JdSdk();
 
-            $responseState = $this->JdSdk->api_product_sku_state($skuArr);
-
+            $response = $this->JdSdk->api_product_sku_state($skuArr);
 
+            $channel->push($response);
 
             //$response = json_decode($response, true);
-//        =====$response=====
-//        { "success": true, "resultMessage": "操作成功", "resultCode": "0000", "result": [ { "state": 0, "sku": 5729524 } ], "code": 200 }
-
-            //return $response;
+            //        =====$response=====
+            //        { "success": true, "resultMessage": "操作成功", "resultCode": "0000", "result": [ { "state": 0, "sku": 5729524 } ], "code": 200 }
 
+            //return $responseState;
+        });
+        $responseState = $channel->pop();
 
         $this->response()->write($responseState . PHP_EOL);
-
     }
 
     /**
@@ -108,7 +110,9 @@ class Index extends Controller
      */
     public function skuStock()
     {
+        $channel = new Channel(1);
 
+        go(function() use($channel){
             // 获取 `POST` 或者 `GET` 提交的所有参数
             $data = $this->request()->getRequestParam();
 
@@ -118,10 +122,14 @@ class Index extends Controller
 
             $this->JdSdk = new JdSdk();
 
-            $responseStock = $this->JdSdk->api_stock_get_new_stock_by_id($skuNums, $area);
+            $response = $this->JdSdk->api_stock_get_new_stock_by_id($skuNums, $area);
+
+            $channel->push($response);
 
             //return $response;
+        });
 
+        $responseStock = $channel->pop();
 
         $this->response()->write($responseStock . PHP_EOL);
     }
@@ -134,7 +142,9 @@ class Index extends Controller
      */
     function skuPrice()
     {
+        $channel = new Channel(1);
 
+        go(function() use($channel){
             // 获取 `POST` 或者 `GET` 提交的所有参数
             $data = $this->request()->getRequestParam();
 
@@ -142,11 +152,14 @@ class Index extends Controller
 
             $this->JdSdk = new JdSdk();
 
-            $responsePrice = $this->JdSdk->api_price_get_price($skuStr);
+            $response = $this->JdSdk->api_price_get_price($skuStr);
 
             //$this->response()->write($response . PHP_EOL);
-
+            $channel->push($response);
         //return $response;
+        });
+
+        $responsePrice = $channel->pop();
 
         $this->response()->write($responsePrice . PHP_EOL);
     }