| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105 |
- <?php
- namespace common\components\delivery\platform\shunfeng;
- /**
- * Class Shop
- * 门店接口实现
- */
- class Shop extends Shunfeng
- {
- /**
- * 获取店铺账户余额
- *
- * 获取当前店铺储值卡/预付费余额
- *
- * 文档参考:https://openic.sf-express.com/open/api/external/getshopaccountbalance
- *
- * @return array 返回格式:['success' => true/false, 'balance' => 0, 'reserved_amount' => 0,
- * 'withdraw_amount' => 0, 'supplier_balance' => 0, 'message' => '']
- * balance: 店铺账户余额,单位:分
- * reserved_amount: 预留余额,单位:分
- * withdraw_amount: 实际可提现余额,单位:分
- * supplier_balance: 商家账户余额,单位:分(仅当传入为链店铺ID时返回)
- */
- public function getShopAccountBalance()
- {
- // 构建请求参数
- $businessData = [
- 'push_time' => time(),
- ];
-
- // 调用httpRequest方法发送请求
- $response = $this->httpRequest('getshopaccountbalance', $businessData);
-
- // 检查API响应
- if (isset($response['error_code']) && $response['error_code'] == 0) {
- return [
- 'success' => true,
- 'balance' => $response['result']['balance'],
- 'reserved_amount' => $response['result']['reserved_amount'],
- 'withdraw_amount' => $response['result']['withdraw_amount'],
- 'pay_amount' => $response['result']['pay_amount'],
- 'message' => '查询余额成功',
- ];
- }
-
- return [
- 'success' => false,
- 'balance' => 0,
- 'reserved_amount' => 0,
- 'withdraw_amount' => 0,
- 'supplier_balance' => 0,
- 'message' => $response['error_msg'] ?? '查询余额失败',
- ];
- }
- /**
- * 更新店铺信息
- * @param int $shopId 店铺id(新增店铺接⼝返回)
- * @param array $post 更新的数据
- */
- public function updateShop($shopId, $post)
- {
- // 构建请求参数
- $params = [
- 'dev_id' => $this->devId,
- 'shop_id' => $shopId,
- 'push_time' => time(),
- ];
- // 可选参数列表
- $optionalFields = [
- 'out_shop_id',
- 'shop_name',
- 'shop_address',
- 'longitude',
- 'latitude',
- 'shop_contact_name',
- 'shop_contact_phone'
- ];
- foreach ($optionalFields as $field) {
- if (isset($post[$field])) {
- $params[$field] = $post[$field];
- }
- }
- // 调用httpRequest方法发送请求
- $response = $this->httpRequest('updateshop', $params);
- // 检查API响应
- if (isset($response['error_code']) && $response['error_code'] == 0) {
- return [
- 'success' => true,
- 'message' => '店铺信息更新成功',
- 'result' => $response['result'] ?? null,
- ];
- }
- return [
- 'success' => false,
- 'message' => $response['error_msg'] ?? '店铺信息更新失败',
- 'error_code' => $response['error_code'] ?? -1,
- ];
- }
- }
|