kevin_zhangl 2 жил өмнө
parent
commit
7e1df0285d

+ 24 - 15
common/helpers/Logistics.php

@@ -7,32 +7,35 @@ use Yii;
 
 class Logistics
 {
+    const prodDomain = 'http://warehouse.taoplus.com.my';
+    const testDomain = 'http://warehouse.worldsyntech.com';
+
     // 1.获取bearer token,此token是其他api调用时的必传参数.
-    const authenticationUrl = 'http://warehouse.worldsyntech.com/index.php?route=rest/admin_security/api_login&grant_type=client_credentials';
+    const authenticationUrl = '/index.php?route=rest/admin_security/api_login&grant_type=client_credentials';
     // 2.创建订单和产品(以前不存在/已提交的产品).
-    const createOrderUrl = 'http://warehouse.worldsyntech.com/index.php?route=rest/warehouse_api/add_order';
+    const createOrderUrl = '/index.php?route=rest/warehouse_api/add_order';
     // 3.获取产品/包裹的重量和状态.
-    const getProductUrl = 'http://warehouse.worldsyntech.com/index.php?route=rest/warehouse_api/get_order_product';
+    const getProductUrl = '/index.php?route=rest/warehouse_api/get_order_product';
     // 4.获取订单重量,m3,包装的包裹数量,费用跟踪号码和状态.
-    const getOrderUrl = 'http://warehouse.worldsyntech.com/index.php?route=rest/warehouse_api/get_order';
+    const getOrderUrl = '/index.php?route=rest/warehouse_api/get_order';
     // 5.通知仓库已经付款,包裹可以投递.
-    const notifyDeliveryUrl = 'http://warehouse.worldsyntech.com/index.php?route=rest/ warehouse_api/notify_delivery';
+    const notifyDeliveryUrl = '/index.php?route=rest/ warehouse_api/notify_delivery';
     // 6.创建产品/包裹.
-    const addProductUrl = 'http://warehouse.worldsyntech.com/index.php?route=rest/warehouse_api/add_order_product';
+    const addProductUrl = '/index.php?route=rest/warehouse_api/add_order_product';
     // 7.创建交付订单并将现有产品绑定到订单.需要先调用接口6创建商品.
-    const createOrderSimpleUrl = 'http://warehouse.worldsyntech.com/index.php?route=rest/warehouse_api/add_order_simple';
+    const createOrderSimpleUrl = '/index.php?route=rest/warehouse_api/add_order_simple';
     // 8.计算订单费用,并将订单状态改为待付款.
-    const stockOutUrl = 'http://warehouse.worldsyntech.com/index.php?route=rest/warehouse_api/stock_out';
+    const stockOutUrl = '/index.php?route=rest/warehouse_api/stock_out';
     // 9.通知物流系统订单不可删除.error包含错误的订单ID.
-    const notifyOrderUndeletableUrl = 'http://warehouse.worldsyntech.com/index.php?route=rest/warehouse_api/notify_order_undeletable';
+    const notifyOrderUndeletableUrl = '/index.php?route=rest/warehouse_api/notify_order_undeletable';
     // 10.取消订单产品/包裹。它将状态更改为无效,并保留订单产品/包裹.
-    const cancelOrderProductUrl = ' http://warehouse.worldsyntech.com/index.php?route=rest/warehouse_api/cancel_order_product';
+    const cancelOrderProductUrl = ' /index.php?route=rest/warehouse_api/cancel_order_product';
     // 11.从数据库中删除订购产品/包裹.
-    const deleteOrderProductUrl = 'http://warehouse.worldsyntech.com/index.php?route=rest/warehouse_api/delete_order_product';
+    const deleteOrderProductUrl = '/index.php?route=rest/warehouse_api/delete_order_product';
     // 12.取消订单,状态改为无效,保留订单不删除.
-    const cancelOrderUrl = 'http://warehouse.worldsyntech.com/index.php?route=rest/warehouse_api/cancel_order';
+    const cancelOrderUrl = '/index.php?route=rest/warehouse_api/cancel_order';
     // 13.从数据库中删除订单.
-    const deleteOrderUrl = 'http://warehouse.worldsyntech.com/index.php?route=rest/warehouse_api/delete_order';
+    const deleteOrderUrl = '/index.php?route=rest/warehouse_api/delete_order';
     // 14.运单追踪.
     const trackOrderUrl = 'https://taoplus.com.my/index.php?route=information/order_tracking/json&order_tracking_search=';
 
@@ -49,6 +52,12 @@ class Logistics
         // }
     }
 
+    function getDomain()
+    {
+        $env = 'prod';
+        return $env === 'prod' ? self::prodDomain : self::testDomain;
+    }
+
     /**
      * 通用curl接口.
      * @param string $url api接口url
@@ -82,7 +91,7 @@ class Logistics
             'agent_id' => Yii::$app->params['wst']['agentId'],
         ];
 
-        $ch = curl_init(self::authenticationUrl);
+        $ch = curl_init($this->getDomain() . self::authenticationUrl);
         header('Content-Type: application/json');
         $authorization = "Authorization: Basic " . Yii::$app->params['wst']['baseToken'];
         curl_setopt($ch, CURLOPT_HTTPHEADER, ['Content-Type: application/json', $authorization]);
@@ -131,7 +140,7 @@ class Logistics
 
         LoggerTool::info(['actionLogisticsOrder', $order, $request]);
 
-        return $this->curl(self::createOrderUrl, $request);
+        return $this->curl($this->getDomain() . self::createOrderUrl, $request);
     }
 
     // 3.获取产品/包裹的重量和状态.