shop.js 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. // 店铺相关接口
  2. import { get, post } from '@/core/http/http-client'
  3. import { buildRestPath } from '@/core/config/api-paths'
  4. import { buildOssUrl } from '@/core/media/oss-url'
  5. /**
  6. * 店铺详情
  7. * 对接 88live 的 /wanlshop/shop/getShopInfo 接口
  8. */
  9. export async function pullMallShopInfo(id) {
  10. const { data } = await get(buildRestPath('shop/getShopInfo'), { id })
  11. if (data.avatar) data.avatar = buildOssUrl(data.avatar)
  12. if (data.find_user && data.find_user.avatar) data.find_user.avatar = buildOssUrl(data.find_user.avatar)
  13. if (Array.isArray(data.category)) {
  14. data.category.forEach(item => {
  15. if (item.image) item.image = buildOssUrl(item.image)
  16. if (Array.isArray(item.childlist)) {
  17. item.childlist.forEach(child => {
  18. if (child.image) child.image = buildOssUrl(child.image)
  19. if (Array.isArray(child.childlist)) {
  20. child.childlist.forEach(sub => {
  21. if (sub.image) sub.image = buildOssUrl(sub.image)
  22. })
  23. }
  24. })
  25. }
  26. })
  27. }
  28. return data
  29. }
  30. /**
  31. * 店铺发现动态列表
  32. * 对接 88live 的 /wanlshop/find/find/getFindList 接口
  33. */
  34. export async function pullMallShopFindList({ user_no, page = 1 } = {}) {
  35. const { data } = await get(buildRestPath('find/find/getFindList'), { user_no, page })
  36. const list = data && data.data ? data.data : []
  37. if (Array.isArray(list)) {
  38. list.forEach(item => {
  39. if (Array.isArray(item.images)) {
  40. item.images = item.images.map(img => buildOssUrl(img))
  41. }
  42. })
  43. }
  44. return {
  45. list: list,
  46. total: data && data.total ? data.total : 0,
  47. currentPage: data && data.current_page ? data.current_page : 1,
  48. lastPage: data && data.last_page ? data.last_page : 1
  49. }
  50. }
  51. /**
  52. * 关注/取消关注店铺
  53. * 对接 88live 的 /wanlshop/find/user/setFindUser 接口
  54. */
  55. export async function postShopFollow(user_no) {
  56. const { data } = await post(buildRestPath('find/user/setFindUser'), {
  57. id: user_no,
  58. type: 'follow'
  59. })
  60. return data
  61. }
  62. /**
  63. * 获取通知列表
  64. * 对接 88live 的 /wanlshop/notice/getNoticeList 接口
  65. */
  66. export async function pullNoticeList({ type, page = 1 } = {}) {
  67. const { data } = await get(buildRestPath('notice/getNoticeList'), { type, page })
  68. return {
  69. data: data && data.data ? data.data : [],
  70. total: data && data.total ? data.total : 0,
  71. current_page: data && data.current_page ? data.current_page : 1,
  72. last_page: data && data.last_page ? data.last_page : 1
  73. }
  74. }
  75. /**
  76. * 获取收藏列表
  77. * 对接 88live 的 /wanlshop/product/collect 接口
  78. */
  79. export async function pullCollectList({ type, page = 1 } = {}) {
  80. const { data } = await get(buildRestPath('product/collect'), { type, page })
  81. return {
  82. data: data && data.data ? data.data : [],
  83. current_page: data && data.current_page ? data.current_page : 1,
  84. last_page: data && data.last_page ? data.last_page : 1
  85. }
  86. }
  87. /**
  88. * 收藏/取消收藏商品
  89. * 对接 88live 的 /wanlshop/product/follow 接口
  90. */
  91. export async function postCollectFollow({ type, id } = {}) {
  92. const apiUrl = type === 'groups' ? 'groups/product/follow' : 'product/follow'
  93. return await post(buildRestPath(apiUrl), { id })
  94. }
  95. /**
  96. * 获取关注店铺列表
  97. * 对接 88live 的 /wanlshop/find/user/getShopList 接口
  98. */
  99. export async function pullFollowShopList({ page = 1 } = {}) {
  100. const { data } = await post(buildRestPath('find/user/getShopList'), { page })
  101. return {
  102. data: data && data.data ? data.data : [],
  103. current_page: data && data.current_page ? data.current_page : 1,
  104. last_page: data && data.last_page ? data.last_page : 1,
  105. total: data && data.total ? data.total : 0
  106. }
  107. }
  108. /**
  109. * 关注/取消关注店铺
  110. * 对接 88live 的 /wanlshop/find/user/setFindUser 接口
  111. */
  112. export async function postFollowShop({ id, type = 'follow' } = {}) {
  113. const { data } = await post(buildRestPath('find/user/setFindUser'), { id, type })
  114. return { data: data && data.data !== undefined ? data.data : null }
  115. }
  116. /**
  117. * 获取我的足跡列表
  118. * 对接 88live 的 /wanlshop/product/footprint 接口
  119. */
  120. export async function pullFootprintList({ type, page = 1 } = {}) {
  121. const { data } = await get(buildRestPath('product/footprint'), { type, page })
  122. return {
  123. data: data && data.data ? data.data : [],
  124. current_page: data && data.current_page ? data.current_page : 1,
  125. last_page: data && data.last_page ? data.last_page : 1
  126. }
  127. }