|
|
@@ -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'] ?? '查询余额失败',
|
|
|
+ ];
|
|
|
}
|
|
|
|
|
|
/**
|