瀏覽代碼

达达平台相关代码修改

shizhongqi 8 月之前
父節點
當前提交
6064feb406

+ 2 - 1
app-ghs/controllers/DeliveryController.php

@@ -87,7 +87,7 @@ class DeliveryController extends BaseController
                 $Auth->didiAuth($mainId, $this->shopId);
                 break;
             case 'dada':
-                $Auth->dadaAuth($mainId);
+                $Auth->dadaAuth($mainId, $this->shopId);
                 break;
             default:
                 util::error(-1, $platform . '不存在');
@@ -760,6 +760,7 @@ class DeliveryController extends BaseController
         $get = Yii::$app->request->get();
         $getData = json_encode($get, JSON_UNESCAPED_UNICODE);
         Yii::info($getData);
+        // // 用merchanId 来保存 sourceId
 
         $callbackData = Yii::$app->request->post();
         if (empty($callbackData)) {

+ 2 - 2
common/components/delivery/platform/dada/Auth.php

@@ -37,7 +37,7 @@ class Auth
      * 初始化授权类
      * 根据环境获取配置信息
      */
-    public function __construct()
+    public function __construct($mainId)
     {
         $isProduction = getenv('YII_ENV') == 'production';
         
@@ -46,7 +46,7 @@ class Auth
             $this->appKey = 'dadaf2279d901a5ba40';
             $this->appSecret = '828a03677a1c00a3a5b3c59209c4433d';
             // TODO
-            $this->redirectUri = 'https://api.shop.hzghd.com' . '/delivery/dada-auth-callback'; // TODO Yii::$app->params['ghsHost'].'/delivery/dada-auth-callback';
+            $this->redirectUri = 'https://api.shop.hzghd.com' . '/delivery/dada-auth-callback?mainId='.$mainId; // TODO Yii::$app->params['ghsHost'].'/delivery/dada-auth-callback?mainId='.$mainId;
             $this->authorizeUrl = self::AUTHORIZE_URL_PROD;
             $this->tokenUrl = self::TOKEN_URL_PROD;
         } else {

+ 1 - 2
common/components/delivery/platform/dada/Dada.php

@@ -31,13 +31,12 @@ class Dada
             $this->baseUrl = self::PROD_BASE_URL;
             $this->appKey = 'dadaf2279d901a5ba40';
             $this->appSecret = '828a03677a1c00a3a5b3c59209c4433d';
-            $this->sourceId = '499021274';
         } else {
             // 测试环境配置(需要替换为实际的测试环境凭证)
             $this->baseUrl = self::TEST_BASE_URL;
             $this->appKey = 'dadaf2279d901a5ba40';
             $this->appSecret = '828a03677a1c00a3a5b3c59209c4433d';
-            $this->sourceId = '499021274';
+            //$this->sourceId = '499021274';
         }
 
         $this->isSandbox = !$isProduction;

+ 7 - 10
common/components/delivery/services/AuthService.php

@@ -30,9 +30,9 @@ Class AuthService{
     public function huolalaAuth($mainId)
     {
         $huoLalaAuth = new \common\components\delivery\platform\huolala\Auth();
-        // $apiHost = Yii::$app->params['ghsHost'];
-        // TODO 暂时修改为测试环境
         $apiHost = Yii::$app->params['ghsHost'];
+        // TODO 暂时修改为测试环境
+        //$apiHost = 'https://api.shop.hzghd.com';
         $redirectUrl = $apiHost . '/delivery/huolala-auth-callback' . '?mainId=' . $mainId;
         $authUrl = $huoLalaAuth->generateAuthUrl($redirectUrl);
 
@@ -43,24 +43,21 @@ Class AuthService{
     public function fengniaoAuth($mainId)
     {
         $fengnaioAuth = new \common\components\delivery\platform\fengniao\Auth();
-        // $apiHost = Yii::$app->params['ghsHost'];
-        // TODO 暂时修改为测试环境
         $apiHost = Yii::$app->params['ghsHost'];
+        // TODO 暂时修改为测试环境
+        //$apiHost = 'https://api.shop.hzghd.com';
         $redirectUrl = $apiHost . '/delivery/fengniao-auth-callback' . '?main_id=' . $mainId;
         $authUrl = $fengnaioAuth->generateAuthUrl($redirectUrl);
 
         util::success(['url'=>$authUrl]);
     }
 
-    public function dadaAuth($mainId)
+    public function dadaAuth($mainId, $shopId)
     {
-        $dadaAuth = new \common\components\delivery\platform\dada\Auth();
+        $dadaAuth = new \common\components\delivery\platform\dada\Auth($mainId);
         $ticket = $dadaAuth->getTicket();
-
-        $redirectUrl = Yii::$app->params['ghsHost'] . '/delivery/dada-auth-callback' . '?mainId=' . $mainId;
-        $shopNumber = '40d8391f9b05477b';
         $state = 'huidiao_biaoshi';
-        $authUrl = $dadaAuth->generateAuthUrl($ticket, $state, $shopNumber);
+        $authUrl = $dadaAuth->generateAuthUrl($ticket, $state, $shopId);
         //header('Location: ' . $authUrl);
         util::success(['url'=>$authUrl]);
     }

+ 6 - 3
common/components/delivery/services/DispatchService.php

@@ -7,12 +7,13 @@ use bizGhs\express\classes\GhsDeliveryOrderClass;
 use bizGhs\order\classes\OrderItemClass;
 use bizHd\express\classes\HdDeliveryOrderClass;
 use common\components\delivery\helpers\HttpClient;
-use common\components\delivery\services\adapter\{DadaAdapter,
+use common\components\delivery\services\adapter\{
+    DadaAdapter,
     Functions,
     ShansongAdapter,
     HuolalaAdapter,
     FengniaoAdapter,
-    ShunfengAdapter}; // MeituanAdapter, DadaAdapter, UUAdapter,
+    ShunfengAdapter}; // MeituanAdapter, UUAdapter,
 use common\components\util;
 use Yii;
 
@@ -51,6 +52,7 @@ class DispatchService
                     case 'dada':
                         $this->adapters['dada'] = new DadaAdapter($pt['accessToken']);
                         $this->adapters['dada']->setShopNo($pt['shopId']);
+                        $this->adapters['dada']->setSourceId($pt['merchantId']); // 用 merchanId 来保存 sourceId
                         break;
                 }
 
@@ -846,7 +848,8 @@ class DispatchService
                         'en_name' => 'dada',
                         'price' => $item['deliver_fee'],
                         'distance' => $item['distance'],
-                        'type' => 'dada',
+                        'type' => '',
+                        'isAble' => true
                     ];
                     break;
             }

+ 11 - 2
common/components/delivery/services/adapter/DadaAdapter.php

@@ -257,6 +257,16 @@ class DadaAdapter extends Dada implements Adapter
         return $this->shopNo;
     }
 
+    public function setSourceId($sourceId)
+    {
+        $this->sourceId = $sourceId;
+    }
+
+    public function getSourceId($sourceId)
+    {
+        return $this->sourceId;
+    }
+
     /**
      * 构建运费报价请求信息
      *
@@ -327,9 +337,8 @@ class DadaAdapter extends Dada implements Adapter
             $result = $resp['result'];
             return [
                 'platform' => 'dada',
-                'deliver_fee' => $result['deliver_fee'],
+                'deliver_fee' => $result['deliverFee'] * 100, // *100 把单位:元 变为 分
                 'distance' => $result['distance'],
-                'duration' => $result['duration'],
                 'tips' => $result['tips'],
             ];
         }