Pārlūkot izejas kodu

查询跑腿平台的帐户余额

shizhongqi 7 mēneši atpakaļ
vecāks
revīzija
fdec2d6819

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

@@ -16,12 +16,13 @@ class Dada
     protected $appKey;
     protected $appSecret;
     protected $sourceId;
+    protected $shopNo;
 
     /**
      * 初始化达达适配器
      * 根据运行环境加载对应的配置信息
      */
-    public function __construct($token='')
+    public function __construct($token='', $shopId=0, $sourceId=0)
     {
         $isProduction = getenv('YII_ENV') == 'production';
 
@@ -37,6 +38,45 @@ class Dada
             $this->appSecret = '828a03677a1c00a3a5b3c59209c4433d';
             //$this->sourceId = '499021274';
         }
+        $shopId != 0 ? $this->shopNo = $shopId : '';
+        $sourceId != 0 ? $this->sourceId = $sourceId : '';
+    }
+
+    public function setShopNo($shopNo)
+    {
+        $this->shopNo = $shopNo;
+    }
+
+    public function getShopNo()
+    {
+        return $this->shopNo;
+    }
+
+    public function balance()
+    {
+        $api = 'api/balance/query';
+        $params = [
+            'category' => 1, //查询运费账户类型(1:运费账户;2:红包账户,3:所有),默认查询运费账户余额
+            'shop_no' => $this->shopNo,
+        ];
+        
+        $body = json_encode($params);
+        $requestParams = $this->buildRequestPayload($api, $body);
+        $result = $this->getHttpRequestWithPost($api, json_encode($requestParams));
+        $resp = json_decode($result, true);
+        if(isset($resp['code']) && $resp['code']==0){
+            return [
+                'success' => true,
+                'balance' => $resp['deliverBalance'],
+                'message' => '查询余额成功',
+            ];
+        }
+
+        return [
+            'success' => false,
+            'balance' => 0,
+            'message' => $resp['msg'] ?? '查询余额失败',
+        ];
     }
 
     /**

+ 26 - 3
common/components/delivery/platform/didi/Didi.php

@@ -74,6 +74,32 @@ class Didi
         return [];
     }
 
+    /**
+     * 查询钱包余额
+     * @return array
+     */
+    public function walletBalance()
+    {
+        $payload = $this->buildRequestPayload([]);
+        $url = $this->getApiUrl('freight.open.platform.channel.standard.walletBalance');
+        $headers = ["Content-Type" => "application/x-www-form-urlencoded"];
+
+        $resp = HttpClient::post($url, $payload, $headers);
+        if ($resp['code'] == 200 && isset($resp['data']['balance'])) {
+            return [
+                'success' => true,
+                'balance' => round($resp['data']['balance'], 2),
+                'message' => $resp['msg'] ?? '查询余额成功',
+            ];
+        }
+
+        return [
+            'success' => false,
+            'balance' => 0,
+            'message' => $resp['msg'] ?? '查询余额失败',
+        ];
+    }
+
     /**
      * 构建API请求参数
      *
@@ -84,13 +110,10 @@ class Didi
     {
         // 1. 准备公共参数
         $timestamp = (int)(microtime(true) * 1000); // 毫秒级时间戳
-
         // 2. 处理业务参数 logisticsParam (JSON字符串)
         $logisticsParam = json_encode($businessParams, JSON_UNESCAPED_UNICODE); // 注意:根据文档,logisticsParam 是 json 字符串
-
         // 3. 生成签名
         $sign = $this->generateSignature($logisticsParam, $timestamp);
-
         // 4. 构建最终请求体
         $payload = [
             'appId' => $this->appId,

+ 6 - 4
common/components/delivery/platform/fengniao/Shop.php

@@ -166,14 +166,16 @@ class Shop extends Fengniao
         if(isset($resp['code'])&&$resp['code']==200){
             $data = json_decode($resp['business_data'], true);
             return [
-                'code' => 1,
-                'balance' => $data['balance_amount_cent']
+                'success' => true,
+                'balance' => $data['balance_amount_cent'],
+                'message' => '查询余额成功',
             ];
         }
 
         return [
-            'code' => 0,
-            'balance' => 0
+            'success' => false,
+            'balance' => 0,
+            'message' => '查询余额失败',
         ];
     }
 }

+ 0 - 12
common/components/delivery/services/adapter/DadaAdapter.php

@@ -18,7 +18,6 @@ use Yii;
  */
 class DadaAdapter extends Dada implements Adapter
 {
-    protected $shopNo;
 
     /**
      * 获取已开通城市列表
@@ -588,17 +587,6 @@ class DadaAdapter extends Dada implements Adapter
         return $resp;
     }
 
-
-    public function setShopNo($shopNo)
-    {
-        $this->shopNo = $shopNo;
-    }
-
-    public function getShopNo()
-    {
-        return $this->shopNo;
-    }
-
     public function setSourceId($sourceId)
     {
         $this->sourceId = $sourceId;