Forráskód Böngészése

余额支付完全调通。微信支付还需要调试

赵启卫 2 éve
szülő
commit
e0cb6c765c

+ 1 - 1
application/wap/controller/Callback.php

xqd
@@ -17,7 +17,7 @@ use think\Request;
 class Callback extends AuthController
 {
     /**
-     * @param $type 1=专题 2=商品 3=报名 4=金币充值 5=会员 6=考试 7=轻专题 8=资料
+     * @param $type 1=专题 2=商品 3=报名 4=金币充值 5=会员 6=考试 7=轻专题 8=资料 9=学习计划
      * @return mixed
      */
     public function pay_success_synchro($type = 0, $id = 0)

+ 13 - 0
application/wap/controller/Studyplan.php

xqd
@@ -190,4 +190,17 @@ class Studyplan extends AuthController{
         $specialWatchList = SpecialWatch::where('special_id', 'in', $spids)->where('uid', $this->uid)->group('special_id')->order('add_time desc')->select();
         print_r($specialWatchList);
     }
+
+    /**
+     * 购买失败删除订单
+     * @param string $orderId 订单id
+     * @return json
+     * */
+    public function del_order($orderId = '') {
+        if (StoreOrder::where('order_id', $orderId)->update(['is_del' => 1]))
+            return JsonService::successful();
+        else
+            return JsonService::fail();
+    }
+
 }

+ 3 - 0
application/wap/view/first/callback/pay_success_synchro.html

xqd
@@ -64,6 +64,9 @@
                         case '8':
                             window.location = $h.U({ c: 'special', a: 'data_details', q: { id: this.id } });
                             break;
+                        case '9':
+                            window.location = $h.U({ c: 'studyplan', a: 'details', q: { id: this.id } });
+                            break;
                         default:
                             window.location = $h.U({ c: 'index', a: 'index'});
                             break;

+ 1 - 1
application/wap/view/first/special/details.html

xqd
@@ -2598,11 +2598,11 @@
                                         id: 0
                                     }
                                 };
+                                var task = this.otherTaskList[0];
                                 if (!task) {
                                     $h.pushMsg('课程信息错误,无法购买。');
                                     return true;
                                 }
-                                var task = this.otherTaskList[0];
                                 if (task.special_task) {
                                     task = task.special_task[0];
                                 }

+ 71 - 9
application/wap/view/first/studyplan/details.html

xqd xqd xqd
@@ -168,6 +168,7 @@
         var wxpayH5 = {$is_h5_wechat_payment_switch? 'true': 'false'};
         var now_money = {$now_money};
         var isMember = {$is_member};
+        var callback_url = '{$callback_url}';
         // 站点名称
         var site_name = '{$Auth_site_name}';
         var app = new Vue({
@@ -196,6 +197,7 @@
                 wxpayH5:wxpayH5,
                 isMember:isMember,
                 site_name:site_name,
+                orderId:'',
             },
             mounted: function () {
                 this.$nextTick(function () {
@@ -249,21 +251,81 @@
                     var value = opt.value || '';
                     this[action] && this[action](value);
                 },
+                pay_order: function (data) {
+                    this.orderId = data.data.result.orderId || '';
+                    switch (data.data.status) {
+                        case "PAY_ERROR":
+                        case 'ORDER_EXIST':
+                        case 'ORDER_ERROR':
+                            this.extendOrder(data.msg);
+                            break;
+                        case 'WECHAT_PAY':
+                            this.wechatPay(data.data.result.jsConfig);
+                            break;
+                        case 'WECHAT_H5_PAY':
+                            this.payDialogOpen = false;
+                            var callbackUrl = callback_url + '?type=9&id=' + this.planinfo.id;
+                            var mwebUrl = data.data.result.jsConfig.mweb_url + '&redirect_url=' + encodeURIComponent(callbackUrl);
+                            window.location.href = mwebUrl;
+                            break;
+                        case 'SUCCESS':
+                            this.successOrder(data.msg);
+                            break;
+                        case 'ZHIFUBAO_PAY':
+                            window.location.href = $h.U({
+                                m: 'wap',
+                                c: 'alipay',
+                                a: 'index',
+                                q: {info: data.data.result, params: 'plan'}
+                            });
+                            break;
+                    }
+                },
+                successOrder: function (msg) {
+                    var that = this;
+                    $h.showMsg({
+                        title: msg ? msg : '支付成功',
+                        icon: 'success',
+                        success: function () {
+                            that.paid = true;
+                            that.is_pay = true;
+                            that.payDialogOpen = false;
+                            var opt = {
+                                c: 'studyplan',
+                                a: 'details',
+                                q: {
+                                    id: that.planinfo.id
+                                }
+                            };
+                            window.location.assign($h.U(opt));
+                        }
+                    });
+                    
+                },
+                extendOrder: function (msg) {
+                    var that = this;
+                    if (typeof msg === 'object') {
+                        if (msg.errMsg === 'chooseWXPay:cancel') {
+                            msg = '微信支付取消';
+                        } else {
+                            msg = '支付失败';
+                        }
+                    } else {
+                        msg = '支付失败';
+                    }
+                    $h.pushMsg(msg, function () {
+                        that.payDialogOpen = false;
+                        if (that.orderId) {
+                            app.baseGet($h.U({c: 'plan', a: 'del_order', q: {orderId: that.orderId}}));
+                        }
+                    });
+                },
                 //打开支付插件,并检测登录状态,没有登录,打开登录插件
                 OpenPay: function () {
                     var vm = this;
                     store.baseGet($h.U({c: 'index', a: 'user_login'}), function (res) {
                         this.money = this.money;
                         this.payDialogOpen = true;
-                        // $h.pushMsg('支付成功');
-                        // var opt = {
-                        //     c: 'studyplan',
-                        //     a: 'details',
-                        //     q: {
-                        //         id: this.planinfo.id
-                        //     }
-                        // };
-                        // window.location.assign($h.U(opt));
                     }.bind(this), function () {
                         vm.loginShow = true;
                     });

+ 77 - 8
application/wap/view/first/studyplan/index.html

xqd xqd
@@ -174,6 +174,75 @@
                     var value = opt.value || '';
                     this[action] && this[action](value);
                 },
+                pay_order: function (data) {
+                    this.orderId = data.data.result.orderId || '';
+                    switch (data.data.status) {
+                        case "PAY_ERROR":
+                        case 'ORDER_EXIST':
+                        case 'ORDER_ERROR':
+                            this.extendOrder(data.msg);
+                            break;
+                        case 'WECHAT_PAY':
+                            this.wechatPay(data.data.result.jsConfig);
+                            break;
+                        case 'WECHAT_H5_PAY':
+                            this.payDialogOpen = false;
+                            var callbackUrl = callback_url + '?type=9&id=' + this.planinfo.id;
+                            var mwebUrl = data.data.result.jsConfig.mweb_url + '&redirect_url=' + encodeURIComponent(callbackUrl);
+                            window.location.href = mwebUrl;
+                            break;
+                        case 'SUCCESS':
+                            this.successOrder(data.msg);
+                            break;
+                        case 'ZHIFUBAO_PAY':
+                            window.location.href = $h.U({
+                                m: 'wap',
+                                c: 'alipay',
+                                a: 'index',
+                                q: {info: data.data.result, params: 'plan'}
+                            });
+                            break;
+                    }
+                },
+                successOrder: function (msg) {
+                    var that = this;
+                    $h.showMsg({
+                        title: msg ? msg : '支付成功',
+                        icon: 'success',
+                        success: function () {
+                            that.paid = true;
+                            that.is_pay = true;
+                            that.payDialogOpen = false;
+                            var opt = {
+                                c: 'studyplan',
+                                a: 'details',
+                                q: {
+                                    id: that.planinfo.id
+                                }
+                            };
+                            window.location.assign($h.U(opt));
+                        }
+                    });
+                    
+                },
+                extendOrder: function (msg) {
+                    var that = this;
+                    if (typeof msg === 'object') {
+                        if (msg.errMsg === 'chooseWXPay:cancel') {
+                            msg = '微信支付取消';
+                        } else {
+                            msg = '支付失败';
+                        }
+                    } else {
+                        msg = '支付失败';
+                    }
+                    $h.pushMsg(msg, function () {
+                        that.payDialogOpen = false;
+                        if (that.orderId) {
+                            app.baseGet($h.U({c: 'plan', a: 'del_order', q: {orderId: that.orderId}}));
+                        }
+                    });
+                },
                 //打开支付插件,并检测登录状态,没有登录,打开登录插件
                 OpenPay: function (plan) {
                     this.planinfo = plan;
@@ -181,14 +250,14 @@
                     var vm = this;
                     store.baseGet($h.U({c: 'index', a: 'user_login'}), function (res) {
                         this.payDialogOpen = true;
-                        var opt = {
-                            c: 'studyplan',
-                            a: 'details',
-                            q: {
-                                id: this.planinfo.id
-                            }
-                        };
-                        window.location.assign($h.U(opt));
+                        // var opt = {
+                        //     c: 'studyplan',
+                        //     a: 'details',
+                        //     q: {
+                        //         id: this.planinfo.id
+                        //     }
+                        // };
+                        // window.location.assign($h.U(opt));
                     }.bind(this), function () {
                         vm.loginShow = true;
                     });