Explorar o código

优化购买优惠券支付流程,增加购买超级会员验证微信支付是否成功

zhengjinyi %!s(int64=3) %!d(string=hai) anos
pai
achega
84e47c65e4

+ 24 - 0
src/main/resources/static/js/common/serviceapi/pay.service.js

@@ -76,6 +76,30 @@ var PayApi = {
                 callback(res);
             });
         },
+        PayOrderPayCouponCheck: function (params, callback) {//查询微信支付优惠券是否已完成支付
+            Http.AjaxService({
+                url:'/order/pay/coupon/check',
+                type:'GET',
+                data:params,
+                json:true,
+                isHost:true
+            })
+            .then(function(res){
+                callback(res);
+            });
+        },
+        PayOrderPayVipCheck: function (params, callback) {//查询微信支付超级会员是否已完成支付
+            Http.AjaxService({
+                url:'/order/pay/vip/check',
+                type:'GET',
+                data:params,
+                json:true,
+                isHost:true
+            })
+            .then(function(res){
+                callback(res);
+            });
+        },
         PayOrderFindOrderStatus: function (params, callback) {//查询判断是否已完成支付
             Http.AjaxService({
                 url:'/order/pay/result/json',

+ 17 - 0
src/main/resources/static/js/common/serviceapi/product.service.js

@@ -311,6 +311,23 @@ var ProductApi = {
                 callback(res);
             });
         },
+        /**
+         * @优惠券-生成购买优惠券记录Id
+         * @param:userId 用户userId
+         * @param:couponId 优惠券Id
+         */
+        createCouponRecord:function (params, callback) {//获取促销活动详情
+            Http.AjaxService({
+                url:'/order/pay/coupon/record',
+                type:'post',
+                data:params,
+                json:false,
+                isHost:true
+            })
+            .then(function(res){
+                callback(res);
+            });
+        },
         /**
          * @优惠券-兑换优惠券
          * @param:userId 用户userId

+ 10 - 4
src/main/resources/static/js/pay/caimei-paycash.js

@@ -53,6 +53,7 @@ var payContainer = new Vue({
         is_Wechat_bowcr:false,
         comboInfo: null, //选中的svip套餐信息
         vipRecordId: undefined,
+        couponRecordId:undefined,
         couponId:undefined,
         userId:0
     },
@@ -522,7 +523,7 @@ var payContainer = new Vue({
         RefreshBody:function(){//刷新页面
             var _self = this;
             // 验证支付(支付会员)
-            if(_self.pageType == 2 || _self.pageType == 3){
+            if( _self.pageType == 2 ){
                 PayApi.PayOrderFindOrderStatus({mbOrderId:_self.mbOrderId},function(response){
                     _self.isPayAlert = false;
                     var data = response.data.data;
@@ -683,6 +684,7 @@ var payContainer = new Vue({
                 returnUrl: 'https://www.caimei365.com/pay/success.html?pageType=www&type=success&payAmount='+_self.couponInfo.moneyCouponPrice,
                 userType: _self.payInfo.payUserType,
                 couponId: _self.couponId,
+                couponRecordId:_self.couponRecordId,
                 userId:_self.userId,
                 source:2 //支付来源 1 小程序 2 WWW
             };
@@ -713,9 +715,10 @@ var payContainer = new Vue({
             if (!isPC) {
                 var orderInfo = {//普通订单微信二维码参数
                     pageType: 3,
-                    vipId: this.comboInfo.id,
-                    vipRecordId: this.vipRecordId,
-                    payAmount: this.payAmount
+                    payAmount: this.couponInfo.moneyCouponPrice,
+                    couponRecordId:this.couponRecordId,
+                    couponId: this.couponId,
+                    userId : this.userId
                 };
                 this.payInfo.payMobileUrl = "https://open.weixin.qq.com/connect/oauth2/authorize?appid=wx91c4152b60ca91a3&redirect_uri=https://www.caimei365.com/pay/wechatpay.html&response_type=code&scope=snsapi_base&state=" + JSON.stringify(orderInfo) + "#wechat_redirect";
                 location.href = this.payInfo.payMobileUrl;
@@ -725,6 +728,7 @@ var payContainer = new Vue({
                     amount: this.couponInfo.moneyCouponPrice,
                     url: this.payInfo.payMobileUrl,
                     couponId:this.couponId,
+                    couponRecordId:this.couponRecordId,
                     userId:this.userId
                 };
                 CAIMEI.Storage.setItem('payData', JSON.stringify(this.payInfo.payData));
@@ -740,6 +744,7 @@ var payContainer = new Vue({
                 returnUrl: 'https://www.caimei365.com/',
                 couponId: _self.couponInfo.couponId,
                 userId:_self.userId,
+                couponRecordId:_self.couponRecordId,
                 source:2 //支付来源 1 小程序 2 WWW
             };
             PayApi.PayCouponMiniAliPay(params, function(response){
@@ -790,6 +795,7 @@ var payContainer = new Vue({
             this.getBankList();
         } else if(this.pageType === '3') {// 支付优惠券
             this.couponId = parseInt(CAIMEI.getUrlParam('couponId'));
+            this.couponRecordId = parseInt(CAIMEI.getUrlParam('couponRecordId'));
             this.initCouponDetail(this.couponId);
             this.PayOrderOnLineSwitch();
             this.getBankList();

+ 52 - 20
src/main/resources/static/js/pay/caimei-paymobile.js

@@ -28,6 +28,8 @@ var payContainer = new Vue({
         pageType:'',//页面跳转类型
         productID:'',//商品ID
         duration: 0, // 购买的会员期限
+        mbOrderId:0,
+        couponRecordId:0,
         vipId: null, // vip套餐id
         vipRecordId: undefined,
         couponId:0,
@@ -134,6 +136,7 @@ var payContainer = new Vue({
                     pageType: 3,
                     payAmount: _self.payAmount,
                     couponId: _self.couponId,
+                    couponRecordId:_self.couponRecordId,
                     userId : _self.userId
                 };
             } else {
@@ -163,30 +166,59 @@ var payContainer = new Vue({
                     _self.isRefresh = true;
                 }
             },1000);
-            if(_self.pageType === '3'){
-                _self.setTimerAliPay();
-            }else{
-                _self.setTimerWechatPay();
-            }
+            _self.setTimerWechatPay();
         },
         setTimerWechatPay:function () {//定时任务查询微信支付结果
             var _self = this;
             var timer;
-            PayApi.PayOrderPayWhetherSuccess({orderId: _self.payInfo.payOrderId, paySuccessCounter:_self.paySuccessCounter},function(response){
-                // console.log(response);
-                if(response.code === 0){
-                    CAIMEI.dialog('支付成功');
-                    clearTimeout(timer); //清理定时任务
-                    setTimeout(function(){
-                        window.location.href = '/index.html';
-                    },2000);
+            if(_self.pageType === '2'){//超级会员支付结果
+                PayApi.PayOrderPayVipCheck({recordId : _self.vipRecordId},function(response){
+                    // console.log(response);
+                    if(response.code === 0){
+                        CAIMEI.dialog('支付成功');
+                        clearTimeout(timer); //清理定时任务
+                        setTimeout(function(){
+                            window.location.href = '/index.html';
+                        },2000);
 
-                }else{
-                    timer = setTimeout(function(){
-                        _self.setTimerWechatPay()
-                    }, 1000*10);
-                }
-            });
+                    }else{
+                        timer = setTimeout(function(){
+                            _self.setTimerWechatPay()
+                        }, 1000*10);
+                    }
+                });
+            }else if(_self.pageType === '3'){//优惠券支付结果
+                PayApi.PayOrderPayCouponCheck({ couponRecordId: _self.couponRecordId },function(response){
+                    // console.log(response);
+                    if(response.code === 0){
+                        CAIMEI.dialog('支付成功');
+                        clearTimeout(timer); //清理定时任务
+                        setTimeout(function(){
+                            window.location.href = '/index.html';
+                        },2000);
+                    }else{
+                        timer = setTimeout(function(){
+                            _self.setTimerWechatPay()
+                        }, 1000*10);
+                    }
+                });
+            }else{
+                PayApi.PayOrderPayWhetherSuccess({orderId: _self.payInfo.payOrderId, paySuccessCounter:_self.paySuccessCounter},function(response){
+                    // console.log(response);
+                    if(response.code === 0){
+                        CAIMEI.dialog('支付成功');
+                        clearTimeout(timer); //清理定时任务
+                        setTimeout(function(){
+                            window.location.href = '/index.html';
+                        },2000);
+
+                    }else{
+                        timer = setTimeout(function(){
+                            _self.setTimerWechatPay()
+                        }, 1000*10);
+                    }
+                });
+            }
         },
         setTimerAliPay:function () {//定时任务查询支付宝支付结果
             var _self = this;
@@ -238,7 +270,7 @@ var payContainer = new Vue({
         }else if(_self.pageType === '3'){
             _self.payInfo.payType = payData.type;
             _self.payAmount = _self.payableAmount = payData.amount;
-            _self.mbOrderId = payData.mbOrderId;
+            _self.couponRecordId = payData.couponRecordId;
             _self.payInfo.payMobileUrl = payData.url;
             _self.couponId = payData.couponId;
             _self.userId = payData.userId;

+ 2 - 0
src/main/resources/static/js/pay/caimei-wechatpay.js

@@ -14,6 +14,7 @@ var payContainer = new Vue({
         vipId: null, // vip套餐id
         vipRecordId: undefined,
         couponId: undefined,//优惠券Id
+        couponRecordId:undefined,//优惠券记录Id
         userId : undefined //购买优惠券的用户Id
     },
     computed: {
@@ -89,6 +90,7 @@ var payContainer = new Vue({
                 state: _this.rand(1000, 9999),
                 userId: _this.userId,
                 couponId: _this.couponId,
+                couponRecordId:_this.couponRecordId,
                 returnUrl: 'https://www.caimei365.com/',
                 source:2 //支付来源 1 小程序 2 WWW
             };

+ 9 - 1
src/main/resources/static/js/product/detail.js

@@ -681,7 +681,15 @@ var productDetail = new Vue({
             window.location.href = '/shopping/confirm.html?type=3';
         },
         toBuyCoupon:function (coupon) {// 点击购买按钮事件处理
-            window.location.href = '/pay/caimei-paycash.html?pageType=3&couponId='+coupon.couponId;
+            var _self = this;
+            ProductApi.createCouponRecord({userId:_self.listQuery.userId, couponId:coupon.couponId}, function (response) {
+                if(response.code == 0){
+                    let couponRecordId = response.data.couponRecordId
+                    window.location.href = '/pay/caimei-paycash.html?pageType=3&couponId='+coupon.couponId+'&couponRecordId='+couponRecordId;
+                }else{
+                    CAIMEI.Alert(response.msg, '确定', false);
+                }
+            })
         },
         showSupportingMore:function () {
             var _self = this;

+ 9 - 1
src/main/resources/static/js/shopping/cart.js

@@ -533,7 +533,15 @@ var shoppingCart = new Vue({
             })
         },
         toBuyCoupon:function (coupon) {// 点击购买按钮事件处理
-            window.location.href = '/pay/caimei-paycash.html?pageType=3&couponId='+coupon.couponId;
+            var _self = this;
+            ProductApi.createCouponRecord({userId:_self.userId, couponId:coupon.couponId}, function (response) {
+                if(response.code == 0){
+                    let couponRecordId = response.data.couponRecordId
+                    window.location.href = '/pay/caimei-paycash.html?pageType=3&couponId='+coupon.couponId+'&couponRecordId='+couponRecordId;
+                }else{
+                    CAIMEI.Alert(response.msg, '确定', false);
+                }
+            })
         },
         queryCouponTabs:function (value){
             var _self = this;

+ 9 - 1
src/main/resources/static/js/user-center/account/coupon-collection.js

@@ -103,10 +103,18 @@ var orderPage = new Vue({
             })
         },
         toBuyCoupon:function (coupon) {// 点击购买按钮事件处理
+            var  _self = this;
             if(this.listQuery.userId == 0){
                 window.location.href='/login.html';
             }else{
-                window.location.href = '/pay/caimei-paycash.html?pageType=3&couponId='+coupon.couponId;
+                ProductApi.createCouponRecord({userId:_self.listQuery.userId, couponId:coupon.couponId}, function (response) {
+                    if(response.code == 0){
+                        let couponRecordId = response.data.couponRecordId
+                        window.location.href = '/pay/caimei-paycash.html?pageType=3&couponId='+coupon.couponId+'&couponRecordId='+couponRecordId;
+                    }else{
+                        CAIMEI.Alert(response.msg, '确定', false);
+                    }
+                })
             }
         },
         receiveCoupon:function(coupon){// 点击领取按钮事件处理