Quellcode durchsuchen

Merge pull request #445 from John-Hong/KIP-14429

feat(KIP-14429):  前端补充 order-and-prepay 接口的校验
Tron vor 1 Jahr
Ursprung
Commit
063dce17e5

+ 51 - 8
src/pages/parkingFee/mixins/parkingFeeDetail.js

@@ -10,7 +10,8 @@ import {
   getPlatform,
   getsTheCurrentTopic,
   isAlipay,
-  theCommunicationBetweenWechatAndH5IsNormal
+  theCommunicationBetweenWechatAndH5IsNormal,
+  waitByTime
 } from '@/utils';
 import { Dialog, Toast } from 'vant';
 import { ordersAndPrepay } from '@/api/parking';
@@ -213,6 +214,8 @@ export default {
       const { parkingRecord, discountInfo = {}, parkingRule = {}, parkInfo = {}} = this.orderDetail;
       const { coupons = [], points = [], memberGrade = [], paperCoupons = [], consume = [], newMemberPoints = {} } = discountInfo
       const { hourPrice } = parkingRule
+      /* 校验 */
+      let usingTotalDiscount = 0;
       try {
         const params = {
           // vehicleNo: '', // 车牌号
@@ -246,6 +249,7 @@ export default {
             "discountFee": discountFee,
             "memberGrade": memberGrade[0].memberGrade
           }
+          usingTotalDiscount = usingTotalDiscount + discountFee
         }
         // 消费减免
         if ( consume?.length && consume[0].discountFee > 0 && consume[0].hasOwnProperty('selected')? consume[0]?.selected : consume[0]?.defaultSelected) {
@@ -265,6 +269,7 @@ export default {
             // 杭州,沈阳,天津,福州,重新计算 redeemSalesAmount
             "redeemSalesAmount": ([2,4,6,8].indexOf(this.parkMallCode) > -1) ? (redeemSalesAmount / defaultDiscountTime) * ( discountFee / hourPrice) : redeemSalesAmount
           }
+          usingTotalDiscount = usingTotalDiscount + discountFee
         }
         
         // 积分
@@ -276,6 +281,7 @@ export default {
             "discountFee": discountFee,
             "discountPoints": discountFee / hourPrice * pointsPerUnit
           }
+          usingTotalDiscount = usingTotalDiscount + discountFee
         }
         // 新会员积分
         if (newMemberPoints?.discountFee && newMemberPoints?.discountFee) {
@@ -285,6 +291,7 @@ export default {
             "discountFee": discountFee,
             "discountPoints": discountFee / hourPrice * pointsPerUnit
           }
+          usingTotalDiscount = usingTotalDiscount + discountFee
         }
         // 优惠券
         if (coupons?.length) {
@@ -293,6 +300,7 @@ export default {
             return selected
           }).map(elm => {
             elm.discountTime = elm.discountFee / hourPrice * 60
+            usingTotalDiscount = usingTotalDiscount + elm.discountFee
             return elm
           })
           if (selectedCoupons.length) {
@@ -305,6 +313,7 @@ export default {
               if ( !elm.discountFee ) {
                 return false
               }
+              usingTotalDiscount = usingTotalDiscount + elm.discountFee
               return {
                 ...elm,
                 "discountFee": elm.discountFee,
@@ -313,6 +322,14 @@ export default {
             })
          }
         console.log('下单时的参数', params);
+         /* 优惠金额的校验 */
+        // console.log('优惠金额的校验', usingTotalDiscount, params.use);
+        // 优惠总金额 + 实际支付 >= 停车订单总金额 否则 刷新订单数据
+        if (usingTotalDiscount + parkingRecord.actualPayFee < parkingRecord.totalFeeInYuan) {
+          // 如果接口返回异常,重置当前页面数据
+          this.reCreateParkOrder('当前优惠信息异常,已重新刷新!', 'now')
+          return
+        }
         const unlicensed = parkingRecord.vehicleNo.indexOf('临') > -1; // true: 临时车牌;false:燃油车牌
         const res = await ordersAndPrepay({
           params, 
@@ -375,8 +392,18 @@ export default {
           console.log('err::::', err)
           if (err.code !=='NO_FEE_NEED_TO_PAY') {
             this.reCreateParkOrder(err.langMessage)
-          } else if(['ETCP_RECORD_COUPON_FAILED', 'ETCP_COUPON_CONFIG_EXCEPTION', 'ETCP_COUPON_INSUFFICIENT_STOCK', 'ETCP_RECORD_COUPON_FAILED', 'ETCP_PUSH_DISCOUNT_FAILED', 'WRONG_AMOUNT'].indexOf(err.code) > -1) {
+          } else if(['ETCP_RECORD_COUPON_FAILED', 'ETCP_COUPON_CONFIG_EXCEPTION', 'ETCP_COUPON_INSUFFICIENT_STOCK', 'ETCP_RECORD_COUPON_FAILED', 'ETCP_PUSH_DISCOUNT_FAILED', 'WRONG_AMOUNT', 'POINTS_VALIDATION_FAILED'].indexOf(err.code) > -1) {
             this.reCreateParkOrder(err.langMessage)
+          } else if(['REMOTE_CALL_FAIL'].indexOf(err.code) > -1) {
+            Toast.clear()
+            setTimeout(() => {
+              Toast.clear()
+              Toast.loading({
+                message: '车场连接有问题,请联系服务台!',
+                duration: 0,
+                icon: 'none'
+              });
+            }, 100)
           } else {
             Dialog.alert({
               title: '提示',
@@ -560,13 +587,9 @@ export default {
         });
     },
     // 支付失败弹框 重新创建订单
-    reCreateParkOrder(msg = '支付失败') {
+    async reCreateParkOrder(msg = '支付失败', type = '') {
       // console.log('支付失败弹框 重新创建订单');
-      Dialog.alert({
-        title: '提示',
-        message: msg || '支付失败',
-        confirmButtonColor: kipTheme[this.theme].primaryColor,
-      }).then(() => {
+      const orderInit = () => {
         this.$refs.countDown.reset(); // 停车场重置费用倒计时3分钟
         this.$store.dispatch('order/orderInit', {
           gateId: this.$route.query?.gateId,
@@ -578,6 +601,26 @@ export default {
         })
         this.btnLoading = false;
         this.isPay = false
+      }
+      if(type == 'now') {
+        Toast.clear()
+        await waitByTime(100)
+        Toast({
+          message: msg,
+          className: "white-space",
+          icon: 'none',
+        });
+        await waitByTime(2500)
+        orderInit()
+        return
+      }
+      Dialog.alert({
+        title: '提示',
+        message: msg || '支付失败',
+        // confirmButtonColor: '#333',
+        confirmButtonColor: kipTheme[this.theme].primaryColor,
+      }).then(() => {
+        orderInit()
         // this.createParkOrder();
       });
       // uni.showModal({

+ 51 - 8
src/pages/parkingFeeV2/mixins/parkingFeeDetail.js

@@ -5,6 +5,7 @@ import {
   backLbsHome,
   getPlatform,
   isAlipay,
+  waitByTime,
 } from '@/utils';
 import {debounce, } from 'lodash'
 import { Dialog, Toast } from 'vant';
@@ -278,6 +279,8 @@ export default {
       const { parkingRecord, discountInfo = {}, parkingRule = {}, parkInfo = {}} = this.orderDetail;
       const { coupons = [], points = [], memberGrade = [], paperCoupons = [], consume = [], newMemberPoints= {} } = discountInfo
       const { hourPrice } = parkingRule
+      /* 校验 */
+      let usingTotalDiscount = 0;
       try {
         const params = {
           // vehicleNo: '', // 车牌号
@@ -311,6 +314,7 @@ export default {
             "discountFee": discountFee,
             "memberGrade": memberGrade[0].memberGrade
           }
+          usingTotalDiscount = usingTotalDiscount + discountFee
         }
         // 消费减免
         if ( consume?.length && consume[0].discountFee > 0 && consume[0].hasOwnProperty('selected')? consume[0]?.selected : consume[0]?.defaultSelected) {
@@ -334,6 +338,7 @@ export default {
           if( this.parkMallCode == 1 && couponCodes) {
             params.discountInfo.consume.couponCodes = couponCodes.split('#').slice(0,discountFee / hourPrice).toString().replace(/,/g, '#')
           }
+          usingTotalDiscount = usingTotalDiscount + discountFee
         }
         
         // 积分
@@ -345,6 +350,7 @@ export default {
             "discountFee": discountFee,
             "discountPoints": discountFee / hourPrice * pointsPerUnit
           }
+          usingTotalDiscount = usingTotalDiscount + discountFee
         }
         // 新会员积分
         if (newMemberPoints?.discountFee && newMemberPoints?.discountFee) {
@@ -354,6 +360,7 @@ export default {
             "discountFee": discountFee,
             "discountPoints": discountFee / hourPrice * pointsPerUnit
           }
+          usingTotalDiscount = usingTotalDiscount + discountFee
         }
         // 优惠券
         if (coupons?.length) {
@@ -362,6 +369,7 @@ export default {
             return selected
           }).map(elm => {
             elm.discountTime = elm.discountFee / hourPrice * 60
+            usingTotalDiscount = usingTotalDiscount + elm.discountFee
             return elm
           })
           if (selectedCoupons.length) {
@@ -374,6 +382,7 @@ export default {
               if ( !elm.discountFee ) {
                 return false
               }
+              usingTotalDiscount = usingTotalDiscount + elm.discountFee
               return {
                 ...elm,
                 "discountFee": elm.discountFee,
@@ -382,6 +391,15 @@ export default {
             })
          }
         console.log('下单时的参数', params);
+        /* 优惠金额的校验 */
+        // console.log('优惠金额的校验', usingTotalDiscount, params.use);
+        // 优惠总金额 + 实际支付 >= 停车订单总金额 否则 刷新订单数据
+        if (usingTotalDiscount + parkingRecord.actualPayFee < parkingRecord.totalFeeInYuan) {
+          console.log(398);
+          // 如果接口返回异常,重置当前页面数据
+          this.reCreateParkOrder('当前优惠信息异常,已重新刷新!', 'now')
+          return
+        }
         const unlicensed = parkingRecord.vehicleNo.indexOf('临') > -1; // true: 临时车牌;false:燃油车牌
         const res = await ordersAndPrepay({
           params, unlicensed,
@@ -440,8 +458,18 @@ export default {
           console.log('err::::', err)
           if (err.code !=='NO_FEE_NEED_TO_PAY') {
             this.reCreateParkOrder(err.langMessage)
-          } else if(['ETCP_RECORD_COUPON_FAILED', 'ETCP_COUPON_CONFIG_EXCEPTION', 'ETCP_COUPON_INSUFFICIENT_STOCK', 'ETCP_RECORD_COUPON_FAILED', 'ETCP_PUSH_DISCOUNT_FAILED', 'WRONG_AMOUNT'].indexOf(err.code) > -1) {
+          } else if(['ETCP_RECORD_COUPON_FAILED', 'ETCP_COUPON_CONFIG_EXCEPTION', 'ETCP_COUPON_INSUFFICIENT_STOCK', 'ETCP_RECORD_COUPON_FAILED', 'ETCP_PUSH_DISCOUNT_FAILED', 'WRONG_AMOUNT', 'POINTS_VALIDATION_FAILED'].indexOf(err.code) > -1) {
             this.reCreateParkOrder(err.langMessage)
+          } else if(['REMOTE_CALL_FAIL'].indexOf(err.code) > -1) {
+            Toast.clear()
+            setTimeout(() => {
+              Toast.clear()
+              Toast.loading({
+                message: '车场连接有问题,请联系服务台!',
+                duration: 0,
+                icon: 'none'
+              });
+            }, 100)
           } else {
             Dialog.alert({
               title: '提示',
@@ -664,14 +692,9 @@ export default {
         });
     },
     // 支付失败弹框 重新创建订单
-    reCreateParkOrder(msg = '支付失败') {
+    async reCreateParkOrder(msg = '支付失败', type = '') {
       // console.log('支付失败弹框 重新创建订单');
-      Dialog.alert({
-        title: '提示',
-        message: msg || '支付失败',
-        // confirmButtonColor: '#333',
-        confirmButtonColor: kipTheme[this.theme].primaryColor,
-      }).then(() => {
+      const orderInit = () => {
         this.$refs.countDown.reset(); // 停车场重置费用倒计时3分钟
         this.$store.dispatch('order/orderInit', {
           gateId: this.$route.query?.gateId,
@@ -683,6 +706,26 @@ export default {
         })
         this.btnLoading = false;
         this.isPay = false
+      }
+      if(type == 'now') {
+        Toast.clear()
+        await waitByTime(100)
+        Toast({
+          message: msg,
+          className: "white-space",
+          icon: 'none',
+        });
+        await waitByTime(2500)
+        orderInit()
+        return
+      }
+      Dialog.alert({
+        title: '提示',
+        message: msg || '支付失败',
+        // confirmButtonColor: '#333',
+        confirmButtonColor: kipTheme[this.theme].primaryColor,
+      }).then(() => {
+        orderInit()
         // this.createParkOrder();
       });
       // uni.showModal({