Przeglądaj źródła

1. 闪送授权回调地址,暂时修改为测试环境 -- 要修改回线上的
2. 蜂鸟门店查询与门店绑定-解绑

shizhongqi 8 miesięcy temu
rodzic
commit
e4d60f89f0

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

@@ -94,7 +94,9 @@ class DeliveryController extends BaseController
         //闪送授权(商户授权:授权后能为商户下所有门店发单)
         $auth = new \common\components\delivery\platform\shansong\Auth();
         if(getenv('YII_ENV') == 'production') {
-            $apiHost = Yii::$app->params['ghsHost'];
+            //$apiHost = Yii::$app->params['ghsHost'];
+            // TODO 暂时修改为测试环境
+            $apiHost = 'https://api.shop.hzghd.com';
         } else {
             $apiHost = Yii::$app->params['ghsHost'];
         }

+ 27 - 1
app-ghs/controllers/DeliveryShopController.php

@@ -62,11 +62,37 @@ class DeliveryShopController extends BaseController
         util::success(['balance'=>$balance]);
     }
 
-    public function actionStore()
+    public function actionStoreList()
     {
         $get = Yii::$app->request->get();
         $platform = $get['platform'];
 
         $ShopService = new ShopService($this->mainId, $platform);
+        $stores = $ShopService->getMerchantStores($platform);
+        util::success($stores);
+    }
+
+    public function actionBindStore(){
+        $post = Yii::$app->request->post();
+        $platform = $post['platform'];
+        $storeId = $post['shopId'];
+        $ShopService = new ShopService($this->mainId, $platform);
+        $re = $ShopService->bindStore($this->mainId, $platform, $storeId);
+        if(!$re){
+            util::fail('绑定门店失败');
+        }
+        util::success('绑定成功');
+    }
+
+    public function actionUnbindStore(){
+        $post = Yii::$app->request->post();
+        $platform = $post['platform'];
+        $storeId = $post['shopId'];
+        $ShopService = new ShopService($this->mainId, $platform);
+        $re = $ShopService->unbindStore($this->mainId, $platform, $storeId);
+        if(!$re){
+            util::fail('解绑门店失败');
+        }
+        util::success('解绑门店成功');
     }
 }

+ 29 - 5
common/components/delivery/platform/fengniao/Shop.php

@@ -1,8 +1,9 @@
 <?php
 namespace common\components\delivery\platform\fengniao;
 
-
+use Yii;
 use common\components\delivery\helpers\HttpClient;
+use bizGhs\express\classes\DeliveryAuthTokenClass;
 
 /**
  * Class Shop
@@ -37,7 +38,7 @@ class Shop extends Fengniao
     public function chainstoreQueryList($data = [])
     {
         // 验证 merchant_id 必填
-        $merchantId = $data['merchant_id'] ?? null;
+        $merchantId = $data['merchant_id'] ?? $this->merchantId;
 
         if (empty($merchantId)) {
             Yii::warning("[FengniaoAdapter] chainstoreQueryList failed: merchant_id is required");
@@ -47,7 +48,7 @@ class Shop extends Fengniao
                 'data' => null
             ];
         }
-        $this->setMerchantId($merchantId);
+        //$this->setMerchantId($merchantId);
 
         // 构建业务数据
         $businessData = [];
@@ -56,6 +57,7 @@ class Shop extends Fengniao
         if (isset($data['page_no']) && $data['page_no'] !== null) {
             $businessData['page_no'] = (int)$data['page_no'];
         }
+        $businessData['page_size'] = 1000; // 设置每页获取数为 1000
         if (isset($data['page_size']) && $data['page_size'] !== null) {
             $businessData['page_size'] = (int)$data['page_size'];
         }
@@ -69,8 +71,6 @@ class Shop extends Fengniao
             'Content-Type' => 'application/json',
         ]);
 
-        Yii::info("[FengniaoAdapter] chainstoreQueryList Response: " . json_encode($resp));
-
         // 处理响应
         if (isset($resp['code']) && $resp['code'] == '200' && isset($resp['business_data'])) {
             // business_data 是 JSON 字符串,需要解析
@@ -128,4 +128,28 @@ class Shop extends Fengniao
             'data' => null
         ];
     }
+
+    public function bindStore($mainId, $storeId)
+    {
+        $deliveryAuthToken = DeliveryAuthTokenClass::getByCondition(['platform'=>'fengniao', 'mainId'=>$mainId], true);
+        if(!$deliveryAuthToken){
+            Yii::error('蜂鸟平台未授权');
+            return false;
+        }
+        $deliveryAuthToken->shopId = $storeId;
+        $deliveryAuthToken->save();
+        return true;
+    }
+
+    public function unbindStore($mainId, $storeId)
+    {
+        $deliveryAuthToken = DeliveryAuthTokenClass::getByCondition(['platform'=>'fengniao', 'mainId'=>$mainId], true);
+        if(!$deliveryAuthToken){
+            Yii::error('蜂鸟平台未授权');
+            return false;
+        }
+        $deliveryAuthToken->shopId = '';
+        $deliveryAuthToken->save();
+        return true;
+    }
 }

+ 67 - 2
common/components/delivery/services/ShopService.php

@@ -2,11 +2,13 @@
 namespace common\components\delivery\services;
 
 //商户账号绑定管理
+use Yii;
 use bizGhs\express\classes\DeliveryAuthTokenClass;
 use common\components\delivery\platform\fengniao\Shop as FengniaoShop;
 use common\components\delivery\platform\huolala\Shop as HuolalaShop;
 use common\components\delivery\platform\shansong\Shop as ShansongShop;
 use common\components\delivery\platform\shunfeng\Shop as ShunfengShop;
+use common\components\delivery\services\adapter\FengniaoAdapter;
 
 /**
  * 聚合调度逻辑(平台选择/优先级)
@@ -98,8 +100,71 @@ class ShopService
     /**
      * 获取商家的所有门店
      */
-    public function getMerchantStores()
+    public function getMerchantStores($platform)
     {
-        
+        $storeDatas = [];
+        switch($platform) {
+            case 'fengniao':
+                /** @var FengniaoShop $shop */
+                $shop = $this->adapters[$platform];
+                $ret = $shop->chainstoreQueryList();
+                $stores = $ret['data']['list'];
+                break;
+        }
+
+        if($platform == 'fengniao') {
+            $bindShopId = $shop->getShopId();
+            foreach($stores as $store) {
+                $storeDatas[] = [
+                    'id' => $store['chain_store_id'],
+                    'merchant_id' => $store['merchant_id'],
+                    'out_shop_code' => $store['out_shop_code'],
+                    'name' => $store['name'],
+                    'address' => $store['address'],
+                    'status' => $store['status'],
+                    'status_desc' => $store['status'],
+                    'latitude' => $store['latitude'],
+                    'longitude' => $store['longitude'],
+                    'bindStatus' => $bindShopId == $store['chain_store_id'] ? true : false,
+                ];
+            }
+        }
+        return $storeDatas;
+    }
+
+    public function bindStore($mainId, $platform, $storeId)
+    {
+        try {
+            switch($platform) {
+                case 'fengniao':
+                    /** @var FengniaoShop $shop */
+                    $shop = $this->adapters[$platform];
+                    $shop->bindStore($mainId, $storeId);
+                    break;
+            }
+            return true;
+        } catch(\Exception $e) {
+            Yii::error('绑定门店失败: ' . $e->getMessage());
+            return false;
+        }
+        return true;
+    }
+
+    public function unbindStore($mainId, $platform, $storeId)
+    {
+        try {
+        switch($platform) {
+            case 'fengniao':
+                /** @var FengniaoShop $shop */
+                $shop = $this->adapters[$platform];
+                $shop->unbindStore($mainId, $storeId);
+                break;
+            }
+            return true;
+        } catch(\Exception $e) {
+            Yii::error('解绑门店失败: ' . $e->getMessage());
+            return false;
+        }
+        return true;
     }
 }