wxPayReturn.js 2.14 KB
angular.module('myApp')
    .controller('wxPayReturnController',['$scope','$rootScope','dingdaService','$state','globalService',function($scope,$rootScope,dingdaService,$state,globalService, $stateParams){

        var type = $stateParams.type

        var init = function() {
            switch(type){
                case 'order':
                    dingdaService.getUnfinishedOrder().success(function(data , status){
                        if(data.meta.code == 200) {
                            if(!data.data.unfinishedOrder.id) {
                                layer.open({
                                    content: '支付成功',
                                    time: 2
                                });
                                $state.go('main')
                                return
                            }else {
                                $scope.unfinishOrder = data.data.unfinishedOrder;
                                $state.go('tripDetail' , { orderId : $scope.unfinishOrder.id});
                                return
                            }
                            $state.go('main')
                        }


                    }).error(function(data , status) {
                        console.log(JSON.stringify(data))
                    })
                    break
                case 'bond':
                    var longitude = $rootScope.currentPoint.longitude;
                    var latitude = $rootScope.currentPoint.latitude;
                    dingdaService.getBond(longitude,latitude)
                        .success(function(data){
                            if(data.meta.code == 200){
                                if(data.data.isActive){
                                    $rootScope.toPaid = data.data.toPaid;
                                    $state.go('bondSuccess');
                                    return
                                }
                            }
                            $state.go('bond')
                        }).error(function(data){

                        })
                    break
                default:
            }

        }
        init()

    }]);