orderConfirm.js 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. import { mockIp, mockReqId } from '../../utils/mock';
  2. export const transformGoodsDataToConfirmData = (goodsDataList) => {
  3. const list = [];
  4. goodsDataList.forEach((goodsData) => {
  5. list.push({
  6. storeId: goodsData.storeId,
  7. spuId: goodsData.spuId,
  8. skuId: goodsData.skuId,
  9. goodsName: goodsData.title,
  10. image: goodsData.primaryImage,
  11. reminderStock: 119,
  12. quantity: goodsData.quantity,
  13. payPrice: goodsData.price,
  14. totalSkuPrice: goodsData.price,
  15. discountSettlePrice: goodsData.price,
  16. realSettlePrice: goodsData.price,
  17. settlePrice: goodsData.price,
  18. oriPrice: goodsData.originPrice,
  19. tagPrice: null,
  20. tagText: null,
  21. skuSpecLst: goodsData.specInfo,
  22. promotionIds: null,
  23. weight: 0.0,
  24. unit: 'KG',
  25. volume: null,
  26. masterGoodsType: 0,
  27. viceGoodsType: 0,
  28. roomId: goodsData.roomId,
  29. egoodsName: null,
  30. });
  31. });
  32. return list;
  33. };
  34. /** 生成结算数据 */
  35. export function genSettleDetail(params) {
  36. const { userAddressReq, couponList, goodsRequestList } = params;
  37. const resp = {
  38. data: {
  39. settleType: 0,
  40. userAddress: null,
  41. totalGoodsCount: 3,
  42. packageCount: 1,
  43. totalAmount: '289997',
  44. totalPayAmount: '',
  45. totalDiscountAmount: '110000',
  46. totalPromotionAmount: '1100',
  47. totalCouponAmount: '0',
  48. totalSalePrice: '289997',
  49. totalGoodsAmount: '289997',
  50. totalDeliveryFee: '0',
  51. invoiceRequest: null,
  52. skuImages: null,
  53. deliveryFeeList: null,
  54. storeGoodsList: [
  55. {
  56. storeId: '1000',
  57. storeName: '云Mall深圳旗舰店',
  58. remark: null,
  59. goodsCount: 1,
  60. deliveryFee: '0',
  61. deliveryWords: null,
  62. storeTotalAmount: '0',
  63. storeTotalPayAmount: '179997',
  64. storeTotalDiscountAmount: '110000',
  65. storeTotalCouponAmount: '0',
  66. skuDetailVos: [],
  67. couponList: [
  68. {
  69. couponId: 11,
  70. storeId: '1000',
  71. },
  72. ],
  73. },
  74. ],
  75. inValidGoodsList: null,
  76. outOfStockGoodsList: null,
  77. limitGoodsList: null,
  78. abnormalDeliveryGoodsList: null,
  79. invoiceSupport: 1,
  80. },
  81. code: 'Success',
  82. msg: null,
  83. requestId: mockReqId(),
  84. clientIp: mockIp(),
  85. rt: 244,
  86. success: true,
  87. };
  88. const list = transformGoodsDataToConfirmData(goodsRequestList);
  89. // 获取购物车传递的商品数据
  90. resp.data.storeGoodsList[0].skuDetailVos = list;
  91. // 判断是否携带优惠券数据
  92. const discountPrice = [];
  93. if (couponList && couponList.length > 0) {
  94. couponList.forEach((coupon) => {
  95. if (coupon.status === 'default') {
  96. discountPrice.push({
  97. type: coupon.type,
  98. value: coupon.value,
  99. });
  100. }
  101. });
  102. }
  103. // 模拟计算场景
  104. // 计算总价
  105. const totalPrice = list.reduce((pre, cur) => {
  106. return pre + cur.quantity * Number(cur.settlePrice);
  107. }, 0);
  108. // 计算折扣
  109. const totalDiscountPrice =
  110. discountPrice.length > 0
  111. ? discountPrice.reduce((pre, cur) => {
  112. if (cur.type === 1) {
  113. return pre + cur.value;
  114. }
  115. if (cur.type === 2) {
  116. return pre + (Number(totalPrice) * cur.value) / 10;
  117. }
  118. return pre + cur;
  119. }, 0)
  120. : 0;
  121. resp.data.totalSalePrice = totalPrice;
  122. resp.data.totalCouponAmount = totalDiscountPrice;
  123. resp.data.totalPayAmount =
  124. totalPrice - totalDiscountPrice - Number(resp.data.totalPromotionAmount);
  125. if (userAddressReq) {
  126. resp.data.settleType = 1;
  127. resp.data.userAddress = userAddressReq;
  128. }
  129. return resp;
  130. }