Shop.php 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  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. * @param int $shopId 店铺id(新增店铺接⼝返回)
  54. * @param array $post 更新的数据
  55. */
  56. public function updateShop($shopId, $post)
  57. {
  58. // 构建请求参数
  59. $params = [
  60. 'dev_id' => $this->devId,
  61. 'shop_id' => $shopId,
  62. 'push_time' => time(),
  63. ];
  64. // 可选参数列表
  65. $optionalFields = [
  66. 'out_shop_id',
  67. 'shop_name',
  68. 'shop_address',
  69. 'longitude',
  70. 'latitude',
  71. 'shop_contact_name',
  72. 'shop_contact_phone'
  73. ];
  74. foreach ($optionalFields as $field) {
  75. if (isset($post[$field])) {
  76. $params[$field] = $post[$field];
  77. }
  78. }
  79. // 调用httpRequest方法发送请求
  80. $response = $this->httpRequest('updateshop', $params);
  81. // 检查API响应
  82. if (isset($response['error_code']) && $response['error_code'] == 0) {
  83. return [
  84. 'success' => true,
  85. 'message' => '店铺信息更新成功',
  86. 'result' => $response['result'] ?? null,
  87. ];
  88. }
  89. return [
  90. 'success' => false,
  91. 'message' => $response['error_msg'] ?? '店铺信息更新失败',
  92. 'error_code' => $response['error_code'] ?? -1,
  93. ];
  94. }
  95. }