coupon.js 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. // 优惠券相关的API接口
  2. import { get, post } from '@/core/http/http-client'
  3. import { buildRestPath } from '@/core/config/api-paths'
  4. /**
  5. * 获取我的优惠券列表(我的卡包)
  6. * state: 1=未使用 2=已使用 3=已过期
  7. * page: 分页页码
  8. */
  9. export async function pullCouponMyList({ state, page = 1 } = {}) {
  10. const { data } = await get(buildRestPath('coupon/getMyList'), { state, page })
  11. return {
  12. rows: Array.isArray(data.data) ? data.data : [],
  13. currentPage: data.current_page || 1,
  14. lastPage: data.last_page || 1,
  15. total: data.total || 0
  16. }
  17. }
  18. /**
  19. * 获取优惠券领取中心列表
  20. * type: 'reduction'=满减券 'discount'=折扣券 'shipping'=包邮券
  21. * page: 分页页码
  22. */
  23. export async function pullCouponList({ type, page = 1 } = {}) {
  24. const { data } = await get(buildRestPath('coupon/getList'), { type, page })
  25. return {
  26. rows: Array.isArray(data.data) ? data.data : [],
  27. currentPage: data.current_page || 1,
  28. lastPage: data.last_page || 1,
  29. total: data.total || 0
  30. }
  31. }
  32. /**
  33. * 获取优惠券详情及可用商品列表
  34. * id: 优惠券ID
  35. * page: 商品分页页码
  36. */
  37. export async function pullCouponApply({ id, page = 1 } = {}) {
  38. const { data } = await get(buildRestPath('coupon/apply'), { id, page })
  39. return data
  40. }
  41. /**
  42. * 领取优惠券
  43. * id: 优惠券ID
  44. */
  45. export async function postCouponReceive({ id } = {}) {
  46. const { data } = await post(buildRestPath('coupon/receive'), { id })
  47. return data
  48. }