Shop.php 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. <?php
  2. namespace common\components\delivery\platform\shunfeng;
  3. /**
  4. * Class Shop
  5. * 门店接口实现
  6. */
  7. class Shop extends Shunfeng
  8. {
  9. /**
  10. * 获取店铺账户余额
  11. *
  12. * 获取当前店铺储值卡/预付费余额
  13. *
  14. * 文档参考:https://openic.sf-express.com/open/api/external/getshopaccountbalance
  15. *
  16. * @return array 返回格式:['success' => true/false, 'balance' => 0, 'reserved_amount' => 0,
  17. * 'withdraw_amount' => 0, 'supplier_balance' => 0, 'message' => '']
  18. * balance: 店铺账户余额,单位:分
  19. * reserved_amount: 预留余额,单位:分
  20. * withdraw_amount: 实际可提现余额,单位:分
  21. * supplier_balance: 商家账户余额,单位:分(仅当传入为链店铺ID时返回)
  22. */
  23. public function getShopAccountBalance()
  24. {
  25. // 构建请求参数
  26. $businessData = [
  27. 'push_time' => time(),
  28. ];
  29. // 调用httpRequest方法发送请求
  30. $response = $this->httpRequest('getshopaccountbalance', $businessData);
  31. // 检查API响应
  32. if (isset($response['error_code']) && $response['error_code'] == 0) {
  33. return [
  34. 'success' => true,
  35. 'balance' => $response['result']['balance'],
  36. 'reserved_amount' => $response['result']['reserved_amount'],
  37. 'withdraw_amount' => $response['result']['withdraw_amount'],
  38. 'pay_amount' => $response['result']['pay_amount'],
  39. 'message' => '查询余额成功',
  40. ];
  41. }
  42. return [
  43. 'success' => false,
  44. 'balance' => 0,
  45. 'reserved_amount' => 0,
  46. 'withdraw_amount' => 0,
  47. 'supplier_balance' => 0,
  48. 'message' => $response['error_msg'] ?? '查询余额失败',
  49. ];
  50. }
  51. /**
  52. * 获取店铺信息
  53. *
  54. * 2025/2/17更新,返回参数更新,支持返回物流产品,详见logistic_type_list
  55. * 开发者可通过该接⼝获取到店铺的基础信息(非连锁店铺可以额外获得等级信息和补贴信息)
  56. *
  57. * @param string $shopId 店铺ID
  58. * @param int $shopType 店铺ID类型 1:顺丰店铺ID 2:接⼊⽅店铺ID
  59. * @return mixed
  60. */
  61. public function getShopInfo($shopId, $shopType = 1)
  62. {
  63. $params = [
  64. 'shop_id' => $shopId,
  65. 'shop_type' => $shopType,
  66. 'push_time' => time()
  67. ];
  68. $response = $this->httpRequest('getshopinfo', $params);
  69. // 检查API响应
  70. if (isset($response['error_code']) && $response['error_code'] == 0) {
  71. return [
  72. 'success' => true,
  73. 'shop_info' => $response['result']['shop_info'] ?? [],
  74. 'message' => '获取店铺信息成功',
  75. ];
  76. }
  77. return [
  78. 'success' => false,
  79. 'shop_info' => [],
  80. 'message' => $response['error_msg'] ?? '获取店铺信息失败',
  81. ];
  82. }
  83. }