|
@@ -14,6 +14,7 @@ const apiSuffix =
|
|
|
interface IAmount {
|
|
|
couponAmount: number
|
|
|
discountPrice: number
|
|
|
+ expectPrice: number
|
|
|
}
|
|
|
export const formatOrderDetail = async (item: any, amount?: IAmount) => {
|
|
|
const type = item.goodType
|
|
@@ -87,27 +88,93 @@ export const formatOrderDetail = async (item: any, amount?: IAmount) => {
|
|
|
case 'SVIP':
|
|
|
{
|
|
|
try {
|
|
|
- const res = await getVipDetail(item.id)
|
|
|
-
|
|
|
// couponAmount 总的优惠金额
|
|
|
// discountPrice 优惠券金额
|
|
|
- let tempPrice = res.salePrice || item.actualPrice
|
|
|
- if (amount?.couponAmount) {
|
|
|
- tempPrice = Number(((res.salePrice - (amount.couponAmount -
|
|
|
- amount.discountPrice) / res.times)).toFixed(2))
|
|
|
+ let tempPrice = amount?.expectPrice || item.actualPrice
|
|
|
+ // 如果是赠送活动 就是一口价
|
|
|
+ if (item.activityType !== 'MEMBER') {
|
|
|
+ if (amount?.couponAmount) {
|
|
|
+ tempPrice = Number(
|
|
|
+ (
|
|
|
+ amount?.expectPrice -
|
|
|
+ (amount.couponAmount - amount.discountPrice) / item.goodNum
|
|
|
+ ).toFixed(2)
|
|
|
+ )
|
|
|
+ }
|
|
|
+ }
|
|
|
+ // 判断是否有会员
|
|
|
+ let startTime = new Date()
|
|
|
+ if (item.goodType === 'SVIP') {
|
|
|
+ startTime = dayjs(
|
|
|
+ state.user.data.userVip.svipEndDate || new Date()
|
|
|
+ ).toDate()
|
|
|
+ } else if (item.goodType === 'VIP') {
|
|
|
+ // 购买Vip时,先有vip的有效时间,如果没有则取SVIP有效时间,都没有默认当前
|
|
|
+ startTime = dayjs(
|
|
|
+ state.user.data.userVip.vipEndDate ||
|
|
|
+ state.user.data.userVip.svipEndDate ||
|
|
|
+ new Date()
|
|
|
+ ).toDate()
|
|
|
+ }
|
|
|
+ let endTime = new Date()
|
|
|
+ if (item.period === 'MONTH') {
|
|
|
+ endTime = dayjs(startTime)
|
|
|
+ .add(1 * item.goodNum, 'month')
|
|
|
+ .toDate()
|
|
|
+ } else if (item.period === 'QUARTERLY') {
|
|
|
+ endTime = dayjs(startTime)
|
|
|
+ .add(3 * item.goodNum, 'month')
|
|
|
+ .toDate()
|
|
|
+ } else if (item.period === 'YEAR_HALF') {
|
|
|
+ endTime = dayjs(startTime)
|
|
|
+ .add(6 * item.goodNum, 'month')
|
|
|
+ .toDate()
|
|
|
+ } else if (item.period === 'YEAR') {
|
|
|
+ endTime = dayjs(startTime)
|
|
|
+ .add(1 * item.goodNum, 'year')
|
|
|
+ .toDate()
|
|
|
}
|
|
|
tempList = {
|
|
|
orderType: item.goodType,
|
|
|
goodName: item.goodName,
|
|
|
num: item.goodNum,
|
|
|
id: item.id,
|
|
|
- title: memberType[res.period] || '',
|
|
|
+ title: item.goodName || '',
|
|
|
vipEndDays: item.vipEndDays,
|
|
|
// 判断是否有优惠金额
|
|
|
price: tempPrice,
|
|
|
- startTime: dayjs(res.startTime).format('YYYY-MM-DD'),
|
|
|
- endTime: dayjs(res.endTime).format('YYYY-MM-DD')
|
|
|
+ period: item.period,
|
|
|
+ startTime: dayjs(startTime).format('YYYY-MM-DD'),
|
|
|
+ endTime: dayjs(endTime).format('YYYY-MM-DD'),
|
|
|
+ activityList: [], // 活动赠送的东西
|
|
|
+ discountEndTime: state.user.data.discountEndTime, // 畅学卡结束时间
|
|
|
+ discountStartTime: state.user.data.discountStartTime // 畅学卡开始时间
|
|
|
}
|
|
|
+ tempList.activityList = (item.activityList || []).map(item => {
|
|
|
+ const { goodType, goodName, goodNum, giftFlag, bizId, period } = item
|
|
|
+ if (goodType === 'DISCOUNT') {
|
|
|
+ return {
|
|
|
+ goodType,
|
|
|
+ goodName,
|
|
|
+ goodNum,
|
|
|
+ bizContent: bizId,
|
|
|
+ giftFlag,
|
|
|
+ vipEndDays: null,
|
|
|
+ goodsNum: goodNum,
|
|
|
+ unit:period
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return {
|
|
|
+ goodType,
|
|
|
+ goodName,
|
|
|
+ goodNum,
|
|
|
+ bizContent: bizId,
|
|
|
+ giftFlag,
|
|
|
+ vipEndDays: null,
|
|
|
+ goodsNum: goodNum,
|
|
|
+ unit:period
|
|
|
+ }
|
|
|
+ })
|
|
|
} catch (e: any) {
|
|
|
throw new Error(e.message)
|
|
|
}
|
|
@@ -283,7 +350,8 @@ export const tradeOrder = (result: any, callBack?: any) => {
|
|
|
discountPrice,
|
|
|
paymentConfig,
|
|
|
paymentVendor,
|
|
|
- paymentVersion
|
|
|
+ paymentVersion,
|
|
|
+ expectPrice
|
|
|
} = result
|
|
|
orderStatus.orderObject.orderType = orderType
|
|
|
orderStatus.orderObject.orderName = orderName
|
|
@@ -298,10 +366,22 @@ export const tradeOrder = (result: any, callBack?: any) => {
|
|
|
}
|
|
|
orderStatus.orderObject.orderList = []
|
|
|
try {
|
|
|
- orderDetailList.forEach(async (item: any) => {
|
|
|
+ // 排除活动商品
|
|
|
+ const orderDetails: any[] = []
|
|
|
+ const orderDetailsActivity: any[] = []
|
|
|
+ orderDetailList.map(item => {
|
|
|
+ if (item.giftFlag) {
|
|
|
+ orderDetailsActivity.push(item)
|
|
|
+ } else {
|
|
|
+ orderDetails.push(item)
|
|
|
+ }
|
|
|
+ })
|
|
|
+ orderDetails[0] && (orderDetails[0].activityList = orderDetailsActivity)
|
|
|
+ orderDetails.forEach(async (item: any) => {
|
|
|
await formatOrderDetail(item, {
|
|
|
couponAmount,
|
|
|
- discountPrice
|
|
|
+ discountPrice,
|
|
|
+ expectPrice
|
|
|
})
|
|
|
})
|
|
|
callBack && callBack()
|