黄琪勇 8 місяців тому
батько
коміт
41c803dcf8

+ 95 - 13
src/student/trade/tradeOrder.ts

@@ -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)
         }
@@ -263,7 +330,9 @@ export const getAlbumDetail = async (id: any) => {
 // 获取畅学卡详情
 export const getDiscountDetail = async () => {
   try {
-    const {data} = await request.get(`${apiSuffix}/memberPriceSettings/getDiscount`)
+    const { data } = await request.get(
+      `${apiSuffix}/memberPriceSettings/getDiscount`
+    )
     return data
   } catch {
     throw new Error('获取畅学卡详情失败')
@@ -283,7 +352,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 +368,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()

+ 5 - 5
src/views/member-center/index.tsx

@@ -298,8 +298,7 @@ export default defineComponent({
         orderStatus.orderObject.orderDesc = `小酷Ai ${state.tabActive} ${member.title}`
         orderStatus.orderObject.actualPrice = calcSalePrice(member)
         orderStatus.orderObject.recomUserId = state.recomUserId
-        orderStatus.orderObject.activityId =
-          activitData.activityId || state.activityId
+        orderStatus.orderObject.activityId = state.activityId
         orderStatus.orderObject.orderNo = ''
 
         const orderData = {
@@ -328,6 +327,7 @@ export default defineComponent({
         if (member.id === activitData.vipCardId && canBuyNum > 0) {
           orderData.activityBuyCount = canBuyNum
           orderData.activityList = activitData.activityList
+          orderStatus.orderObject.activityId = activitData.activityId
         }
         orderStatus.orderObject.orderList = [orderData]
         router.push({
@@ -413,10 +413,10 @@ export default defineComponent({
         )
         const { list, ...more } = data
 
-        // 学生端 活动
-        if (baseState.platformType === 'STUDENT') {
+        // 学生端 活动 有分享活动的时候 就不支持折扣活动
+        if (baseState.platformType === 'STUDENT' && !state.activityId) {
           const activitRes = await request.post(
-            `api-student/memberPriceSettings/getMemberBuyGift`
+            `/api-student/memberPriceSettings/getMemberBuyGift`
           )
           if (activitRes.code === 200 && activitRes.data) {
             const {

+ 28 - 1
src/views/order-detail/order-vip/index.tsx

@@ -94,6 +94,33 @@ export default defineComponent({
           endTime: null
         }
       }
+    },
+    // vip 结束时间
+    vipEndTime() {
+      const vipVal = (this.item.activityList || []).find(item => {
+        return this.item.orderType === item.goodType
+      })
+      let endTime = this.item.endTime
+      if(vipVal){
+        if (vipVal.unit === 'MONTH') {
+          endTime = dayjs(endTime)
+            .add(1 * vipVal.goodsNum, 'month')
+            .toDate()
+        } else if (vipVal.unit === 'QUARTERLY') {
+          endTime = dayjs(endTime)
+            .add(3 * vipVal.goodsNum, 'month')
+            .toDate()
+        } else if (vipVal.unit === 'YEAR_HALF') {
+          endTime = dayjs(endTime)
+            .add(6 * vipVal.goodsNum, 'month')
+            .toDate()
+        } else if (vipVal.unit === 'YEAR') {
+          endTime = dayjs(endTime)
+            .add(1 * vipVal.goodsNum, 'year')
+            .toDate()
+        }
+      }
+      return dayjs(endTime).format('YYYY-MM-DD')
     }
   },
   watch: {
@@ -243,7 +270,7 @@ export default defineComponent({
                       <span>{item.orderType}会员生效时间</span>
                     </div>
                     <div class={styles.timer}>
-                      {this.startTime} 至 {item.endTime}
+                      {this.startTime} 至 {this.vipEndTime}
                     </div>
                   </div>
                 )