tradeOrder.ts 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. import { memberType } from '@/constant'
  2. import request from '@/helpers/request'
  3. import { orderStatus } from '@/views/order-detail/orderStatus'
  4. import dayjs from 'dayjs'
  5. // LIVE: '直播课',
  6. // PRACTICE: '陪练课',
  7. // VIDEO: '视频课',
  8. // VIP: '开通会员',
  9. // MUSIC: '单曲点播'
  10. interface IAmount {
  11. couponAmount: number
  12. discountPrice: number
  13. }
  14. export const formatOrderDetail = async (item: any, amount?: IAmount) => {
  15. const type = item.goodType
  16. let tempList: any = {}
  17. switch (type) {
  18. case 'PINAO_ROOM':
  19. {
  20. try {
  21. const res = await getPinaoDetail(item.bizId)
  22. console.log('res', res)
  23. tempList = {
  24. orderType: item.goodType,
  25. goodsName: item.goodName,
  26. ...res
  27. }
  28. } catch (e: any) {
  29. throw new Error(e.message)
  30. }
  31. }
  32. break
  33. case 'VIP':
  34. try {
  35. const res = await getVipDetail(item.id)
  36. tempList = {
  37. orderType: item.goodType,
  38. goodName: item.goodName,
  39. id: item.id,
  40. title: memberType[res.period] || '',
  41. // price: res.salePrice || item.actualPrice,
  42. // 判断是否有优惠金额
  43. price: amount?.couponAmount
  44. ? Number(
  45. (
  46. res.salePrice -
  47. amount.couponAmount +
  48. amount.discountPrice
  49. ).toFixed(2)
  50. )
  51. : res.salePrice || item.actualPrice,
  52. startTime: dayjs(res.startTime).format('YYYY-MM-DD'),
  53. endTime: dayjs(res.endTime).format('YYYY-MM-DD')
  54. }
  55. } catch (e: any) {
  56. throw new Error(e.message)
  57. }
  58. break
  59. }
  60. tempList.orderType = type
  61. tempList.goodName = item.goodName
  62. orderStatus.orderObject.orderList.push(tempList)
  63. }
  64. // 获取时长详情失败
  65. export const getPinaoDetail = async (id: any) => {
  66. try {
  67. const res = await request.get(`/api-teacher/pianoRoomSettings/detail/${id}`)
  68. return res.data
  69. } catch {
  70. throw new Error('获取时长详情失败')
  71. }
  72. }
  73. // 获取会员详情
  74. export const getVipDetail = async (id: any) => {
  75. try {
  76. const setting = await request.get('/api-teacher/vipCardRecord/detail/' + id)
  77. return setting.data || []
  78. } catch {
  79. throw new Error('获取会员详情失败')
  80. }
  81. }
  82. export const tradeOrder = (result: any, callBack?: any) => {
  83. const {
  84. orderNo,
  85. actualPrice,
  86. orderDesc,
  87. orderName,
  88. orderType,
  89. orderDetailList,
  90. couponAmount,
  91. discountPrice
  92. } = result
  93. orderStatus.orderObject.orderType = orderType
  94. orderStatus.orderObject.orderName = orderName
  95. orderStatus.orderObject.orderDesc = orderDesc
  96. orderStatus.orderObject.orderNo = orderNo
  97. orderStatus.orderObject.actualPrice = actualPrice
  98. orderStatus.orderObject.discountPrice = discountPrice
  99. orderStatus.orderObject.orderList = []
  100. console.log(result)
  101. try {
  102. orderDetailList.forEach(async (item: any) => {
  103. await formatOrderDetail(item, {
  104. couponAmount,
  105. discountPrice
  106. })
  107. })
  108. callBack && callBack()
  109. } catch {
  110. //
  111. }
  112. }