memberPrepaid.js 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  1. import { http } from '@/common/service/service.js'
  2. import { USER_INFO } from '@/common/util/constants.js'
  3. const BASE = '/memberPrepaidMerchant'
  4. /** 当前登录门店 ID */
  5. export function getMerchantId() {
  6. const info = uni.getStorageSync(USER_INFO) || {}
  7. return info.merchantId || ''
  8. }
  9. /** 获取本商户经纬度(共享门店列表按门店坐标算距离) */
  10. export function getMerchantLocation(merchantId = getMerchantId()) {
  11. if (!merchantId) {
  12. return Promise.reject(new Error('未获取到门店信息'))
  13. }
  14. return http
  15. .get('/merchant/localMerchantInfo/queryById', {
  16. params: { id: merchantId }
  17. })
  18. .then((res) => {
  19. if (res.data.code !== 200 || !res.data.result) {
  20. return Promise.reject(new Error(res.data.message || '获取门店信息失败'))
  21. }
  22. const { longitude, latitude } = res.data.result
  23. if (
  24. longitude === undefined ||
  25. longitude === null ||
  26. longitude === '' ||
  27. latitude === undefined ||
  28. latitude === null ||
  29. latitude === ''
  30. ) {
  31. return Promise.reject(new Error('门店未配置经纬度'))
  32. }
  33. return {
  34. longitude: Number(longitude),
  35. latitude: Number(latitude)
  36. }
  37. })
  38. }
  39. /** 格式化门店距离展示,如 746.00m / 3.24km */
  40. export function formatStoreDistance(item = {}) {
  41. if (item.distance == null || item.distance === '') {
  42. return item.distanceText || ''
  43. }
  44. const num = Number(item.distance)
  45. if (Number.isNaN(num)) {
  46. return String(item.distanceText || item.distance)
  47. }
  48. const text = Number.isInteger(num) ? String(num) : num.toFixed(2)
  49. const unit = item.distanceUnit || ''
  50. return unit ? `${text}${unit}` : text
  51. }
  52. /**
  53. * auditStatus: 0未申请 / 1待审核 / 2已通过 / 3已驳回
  54. * operationStatus: 0关闭 / 1开启
  55. * reapplyStatus: 0不适用 / 1禁止重新申请 / 2允许重新申请
  56. */
  57. const api = {
  58. /** 查询商户行业是否支持储值(true 时显示储值管理入口) */
  59. checkIndustryEligibility(merchantId = getMerchantId()) {
  60. return http.get(`${BASE}/industry/eligibility`, { params: { merchantId } })
  61. },
  62. /** 查询储值功能状态 */
  63. getFeatureStatus(merchantId = getMerchantId()) {
  64. return http.get(`${BASE}/feature/status`, { params: { merchantId } })
  65. },
  66. /** 当前生效协议 */
  67. getCurrentAgreement() {
  68. return http.get(`${BASE}/agreement/current`)
  69. },
  70. /** 当前或最近申请详情 */
  71. getApplication(merchantId = getMerchantId()) {
  72. return http.get(`${BASE}/feature/application`, { params: { merchantId } })
  73. },
  74. /** 提交开通申请 */
  75. applyFeature(data, merchantId = getMerchantId()) {
  76. return http.post(`${BASE}/feature/apply`, data, { params: { merchantId } })
  77. },
  78. /** 开启储值功能 */
  79. openFeature(merchantId = getMerchantId()) {
  80. return http.post(`${BASE}/feature/open`, {}, { params: { merchantId } })
  81. },
  82. /** 关闭储值功能 */
  83. closeFeature(data, merchantId = getMerchantId()) {
  84. return http.post(`${BASE}/feature/close`, data || {}, { params: { merchantId } })
  85. },
  86. /** 当前门店详情 */
  87. getCurrentStore(merchantId = getMerchantId()) {
  88. return http.get(`${BASE}/store/current`, { params: { merchantId } })
  89. },
  90. /**
  91. * 可添加共享门店分页
  92. * 必传 longitude / latitude,按距离由近到远
  93. */
  94. getShareableStores(params = {}) {
  95. return http.get(`${BASE}/store/shareable/page`, {
  96. params: {
  97. merchantId: getMerchantId(),
  98. pageNo: 1,
  99. pageSize: 10,
  100. ...params
  101. }
  102. })
  103. },
  104. /**
  105. * 已共享门店分页
  106. * 必传 longitude / latitude,按距离由近到远
  107. */
  108. getSharedStores(params = {}) {
  109. return http.get(`${BASE}/store/shared/page`, {
  110. params: {
  111. merchantId: getMerchantId(),
  112. pageNo: 1,
  113. pageSize: 10,
  114. ...params
  115. }
  116. })
  117. },
  118. /** 批量添加共享门店 */
  119. addSharedStores(sharedStoreIds, merchantId = getMerchantId()) {
  120. return http.post(
  121. `${BASE}/store/shared`,
  122. { sharedStoreIds },
  123. { params: { merchantId } }
  124. )
  125. },
  126. /** 移除共享门店 */
  127. removeSharedStore(sharedStoreId, merchantId = getMerchantId()) {
  128. return http.delete(`${BASE}/store/shared/${sharedStoreId}`, {}, { params: { merchantId } })
  129. },
  130. /** 首页概览 */
  131. getOverview(merchantId = getMerchantId()) {
  132. return http.get(`${BASE}/overview`, { params: { merchantId } })
  133. },
  134. /** 账户明细分页 */
  135. getLedgerPage(params = {}) {
  136. return http.get(`${BASE}/account/ledger/page`, {
  137. params: { merchantId: getMerchantId(), pageNo: 1, pageSize: 10, ...params }
  138. })
  139. },
  140. /** 账户明细详情 */
  141. getLedgerDetail(ledgerId, merchantId = getMerchantId()) {
  142. return http.get(`${BASE}/account/ledger/${ledgerId}/detail`, {
  143. params: { merchantId }
  144. })
  145. },
  146. /** 查询储值设置 */
  147. getRechargeConfig(merchantId = getMerchantId()) {
  148. return http.get(`${BASE}/recharge/config`, { params: { merchantId } })
  149. },
  150. /** 保存储值设置 */
  151. saveRechargeConfig(data, merchantId = getMerchantId()) {
  152. return http.put(`${BASE}/recharge/config`, data, { params: { merchantId } })
  153. },
  154. /** 可赠送优惠券分页 */
  155. getCouponPage(params = {}) {
  156. return http.get(`${BASE}/recharge/coupon/page`, {
  157. params: { merchantId: getMerchantId(), pageNo: 1, pageSize: 50, ...params }
  158. })
  159. }
  160. }
  161. export default api