YanaDH vor 7 Jahren
Ursprung
Commit
42f10b196a

+ 83 - 9
miaomiao/www/js/controllers/home.js

xqd xqd xqd xqd
@@ -172,22 +172,23 @@
         });
     }]);
 
-    app.controller('dreamDetailCtrl', ["$scope", "$state", "WechatService","$ionicModal","storage","msg", "common", "config", "homeService", "$ionicTabsDelegate", "$stateParams","$ionicBackdrop", "$timeout", "$ionicScrollDelegate", "$interval"
-        , function ($scope, $state,WechatService,$ionicModal, storage , msg, common, config, homeService, $ionicTabsDelegate, $stateParams,$ionicBackdrop, $timeout, $ionicScrollDelegate, $interval) {
-        var id = $stateParams.id;
-        var top3user = '';
+    app.controller('dreamDetailCtrl', ["$scope","$ionicHistory","$timeout", "$state", "WechatService","$ionicModal","storage","msg", "common", "config", "homeService", "$ionicTabsDelegate", "$stateParams","$ionicBackdrop", "$timeout", "$ionicScrollDelegate", "$interval"
+        , function ($scope, $ionicHistory,$timeout,$state,WechatService,$ionicModal, storage , msg, common, config, homeService, $ionicTabsDelegate, $stateParams,$ionicBackdrop, $timeout, $ionicScrollDelegate, $interval) {
+            var id = $stateParams.id;
+            var top3user = '';
             $scope.chosedIndex = 0;
-            $scope.clickAvatar = function(index){
+            $scope.clickAvatar = function (index) {
                 $scope.chosedIndex = index;
-                homeService.myInfo().then(function(result){
+                homeService.myInfo().then(function (result) {
                     $scope.user = result.data.data;
                 });
             };
-        // id=5;
+            // id=5;
             $scope.$on('$ionicView.beforeEnter', function () {
                 $ionicTabsDelegate.showBar(false);
                 $scope.load(id);
                 $scope.thisUser = storage.getObject('user');
+                $scope.vm.payType = 2;
                 homeService.myInfo().then(function(result){
                     $scope.user = result.data.data;
                 });
@@ -292,6 +293,7 @@
             $scope.toRecharge = function(){
                 $state.go("app.recharge")
             };
+
             $scope.share = function (type,$event) {
                 $scope.toshare = true;
                 if (type==0) {//分享给朋友
@@ -484,7 +486,80 @@
             }
 
         };
-      
+            $scope.testcharge = function(number){
+                if (!number) {
+                    msg.text('请输入充值金额');
+                    return;
+                }
+                homeService.testcharge(number,2).then(function (result) {
+                    msg.text("充值成功");
+                    $scope.vm.coin = parseInt($scope.vm.coin) + parseInt(number);
+                    $timeout(function () {
+                        $scope.closeRechargeModal();
+                    }, 500);
+                    homeService.myInfo().then(function (result) {
+                        $scope.user = result.data.data;
+                    });
+                })
+            }
+            //充值
+            $scope.charge = function(number){
+                if (!number) {
+                    msg.text('请输入充值金额');
+                    return;
+                }
+                homeService.charge(number,2).then(function (result) {
+                    //todo:result需要返回支付宝或者微信的签名信息
+                    console.log("result: " + JSON.stringify(result));
+                    var payInfo = result.data;
+                    if ($scope.vm.payType == 1) { //支付宝
+                        cordova.plugins.AliPay.pay(payInfo, function success(e) {
+                            //e.resultStatus  状态代码  e.result  本次操作返回的结果数据 e.memo 提示信息
+                            //e.resultStatus  9000  订单支付成功 ;8000 正在处理中  调用function success
+                            //e.resultStatus  4000  订单支付失败 ;6001  用户中途取消 ;6002 网络连接出错  调用function error
+                            //当e.resultStatus为9000时,请去服务端验证支付结果
+                            $scope.clicksub = false;
+                            if (e.resultStatus == '9000') {
+                                alert(orderID);
+                                //支付成功
+                                // $state.go('app.my');
+                            } else {
+                                msg.error("支付失败");
+                                // msg.error("支付失败:" + JSON.stringify(e));
+                            }
+                        }, function error(e) {
+                            $scope.clicksub = false;
+                            // msg.error("支付失败:" + JSON.stringify(e));
+                            msg.error("支付失败");
+                        });
+                    }
+                    if ($scope.vm.payType == 2) { //微信
+                        var obj = JSON.parse(payInfo);
+                        var params = {
+                            partnerid: obj.partnerid, // merchant id
+                            prepayid: obj.prepayid, // prepay id
+                            noncestr: obj.noncestr, // nonce
+                            timestamp: obj.timestamp, // timestamp
+                            sign: obj.sign, // signed string
+                        };
+                        Wechat.sendPaymentRequest(params, function (r) {
+                            $scope.clicksub = false;
+                            courseService.orderStatus(orderID, $scope.paytype).then(function (result) {
+                                //  alert(result);
+                                //支付成功
+                                //  $state.go('app.my');
+                            }, function (erro) {
+                                msg.alert("支付反馈失败:" + JSON.stringify(erro));
+                            });
+                        }, function (reason) {
+                            $scope.clicksub = false;
+                            msg.alert("支付失败:" + JSON.stringify(reason));
+                        });
+                    }
+                    // msg.text("充值成功");
+                    //   $state.go('app.my');
+                });
+            }
         $scope.submitComment = function (index) {
             var interaction = $scope.dream.interactions[index];
             var iid = interaction.id;
@@ -1337,7 +1412,6 @@
       $scope.toDetail = function (id) {
         $state.go('app.home_dreamdetail',{id:id});
       };
-
   }]);
     
 })(angular.module('app.controllers'));

+ 75 - 10
miaomiao/www/js/controllers/my.js

xqd xqd xqd xqd xqd
@@ -438,8 +438,8 @@
                 });
             });
         }]);
-    app.controller('rechargeCtrl', ["$scope","$ionicTabsDelegate", "$state", "myService", "msg"
-  , function ($scope, $ionicTabsDelegate,$state, myService, msg) {
+    app.controller('rechargeCtrl', ["$scope","$timeout","$ionicHistory","$ionicTabsDelegate", "$state", "myService", "msg"
+  , function ($scope,$timeout, $ionicHistory,$ionicTabsDelegate,$state, myService, msg) {
         $scope.$on('$ionicView.beforeEnter', function () {
             $ionicTabsDelegate.showBar(false);
             myService.myInfo().then(function(result){
@@ -454,7 +454,7 @@
         $scope.withdraw = function(){
             $state.go("app.withdraw")
         };
-           
+
       $scope.testcharge = function(number){
         if (!number) {
               msg.text('请输入充值金额');
@@ -462,8 +462,10 @@
         }
         myService.testcharge(number,2).then(function (result) {
              msg.text("充值成功");
-             $scope.vm.coin = parseInt($scope.vm.coin) + parseInt(number)
-            //   $state.go('app.my');
+             $scope.vm.coin = parseInt($scope.vm.coin) + parseInt(number);
+            $timeout(function(){
+                $ionicHistory.goBack();
+            },500)
         });
       }
       //充值
@@ -526,8 +528,8 @@
       }
 
   }]);
-    app.controller('payCtrl', ["$scope","$ionicTabsDelegate", "$timeout","$ionicHistory","$state", "myService", "msg"
-        , function ($scope,$ionicTabsDelegate, $timeout,$ionicHistory,$state, myService, msg) {
+    app.controller('payCtrl', ["$scope","$timeout","$ionicHistory","$ionicTabsDelegate", "$timeout","$ionicHistory","$state", "myService", "msg"
+        , function ($scope,$timeout,$ionicHistory,$ionicTabsDelegate, $timeout,$ionicHistory,$state, myService, msg) {
             $scope.$on('$ionicView.beforeEnter', function () {
                 myService.myInfo().then(function(result){
                     $scope.vm = result.data.data;
@@ -542,12 +544,75 @@
                 $state.go("app.payout")
             };
             //充值
-            $scope.recharge = function(money){
-                myService.recharge(money).then(function(result){
+            $scope.testcharge = function(number){
+                if (!number) {
+                    msg.text('请输入充值金额');
+                    return;
+                }
+                myService.testcharge(number,2).then(function (result) {
                     msg.text("充值成功");
+                    $scope.vm.coin = parseInt($scope.vm.coin) + parseInt(number);
                     $timeout(function(){
                         $ionicHistory.goBack();
-                    },1000)
+                    },500)
+                });
+            }
+            //充值
+            $scope.charge = function(number){
+                if (!number) {
+                    msg.text('请输入充值金额');
+                    return;
+                }
+                myService.charge(number,2).then(function (result) {
+                    //todo:result需要返回支付宝或者微信的签名信息
+                    console.log("result: " + JSON.stringify(result));
+                    var payInfo = result.data;
+                    if ($scope.vm.payType == 1) { //支付宝
+                        cordova.plugins.AliPay.pay(payInfo, function success(e) {
+                            //e.resultStatus  状态代码  e.result  本次操作返回的结果数据 e.memo 提示信息
+                            //e.resultStatus  9000  订单支付成功 ;8000 正在处理中  调用function success
+                            //e.resultStatus  4000  订单支付失败 ;6001  用户中途取消 ;6002 网络连接出错  调用function error
+                            //当e.resultStatus为9000时,请去服务端验证支付结果
+                            $scope.clicksub = false;
+                            if (e.resultStatus == '9000') {
+                                alert(orderID);
+                                //支付成功
+                                // $state.go('app.my');
+                            } else {
+                                msg.error("支付失败");
+                                // msg.error("支付失败:" + JSON.stringify(e));
+                            }
+                        }, function error(e) {
+                            $scope.clicksub = false;
+                            // msg.error("支付失败:" + JSON.stringify(e));
+                            msg.error("支付失败");
+                        });
+                    }
+                    if ($scope.vm.payType == 2) { //微信
+                        var obj = JSON.parse(payInfo);
+                        var params = {
+                            partnerid: obj.partnerid, // merchant id
+                            prepayid: obj.prepayid, // prepay id
+                            noncestr: obj.noncestr, // nonce
+                            timestamp: obj.timestamp, // timestamp
+                            sign: obj.sign, // signed string
+                        };
+                        Wechat.sendPaymentRequest(params, function (r) {
+                            $scope.clicksub = false;
+                            courseService.orderStatus(orderID, $scope.paytype).then(function (result) {
+                                //  alert(result);
+                                //支付成功
+                                //  $state.go('app.my');
+                            }, function (erro) {
+                                msg.alert("支付反馈失败:" + JSON.stringify(erro));
+                            });
+                        }, function (reason) {
+                            $scope.clicksub = false;
+                            msg.alert("支付失败:" + JSON.stringify(reason));
+                        });
+                    }
+                    // msg.text("充值成功");
+                    //   $state.go('app.my');
                 });
             }
 

+ 13 - 0
miaomiao/www/js/services/homeservice.js

xqd
@@ -100,6 +100,19 @@
                     url:config.server + "api/dream/share?id=" + id,
                     method:"get"
                 })
+            },
+            testcharge:function(number,type){
+                return $http({
+                    url:config.server + "api/my/recharge?coin="+number,
+                    method:"post"
+                })
+            },
+            charge:function(number,type){
+                return $http({
+                    url:config.server + "api/pay/charge",
+                    method:"post",
+                    data: { number:number,goods:1,type:type}
+                })
             }
         };
     }]);

+ 12 - 16
miaomiao/www/templates/home/dream-detail.html

xqd xqd
@@ -318,46 +318,42 @@
     <script id="recharge-modal.html" type="text/ng-template">
       <div class="modal">
         <ion-header-bar class="bar-calm bar bar-header has-tabs-top">
-            <button class="button button-clear" ng-click="closeRechargeModal()">关闭</button>
             <h1 class="title">充值</h1>
-            <button class="button button-clear" ui-sref="app.pay">支付说明</button>
+            <button class="button button-clear" ng-click="closeRechargeModal()">关闭</button>
         </ion-header-bar>
         <ion-content>
             <div class="list recharge padding">
                 <div class="item" style="padding:20px">
                     <div class="row">
                         <div class="col col-20">
-                            <img ng-src="img/icon_gold.svg" style="height: 100%; width: 100%">
+                            <img src="img/icon_gold.svg" style="height: 100%; width: 100%">
                         </div>
                         <div class="col">
                             <div>剩余梦想币</div>
-                            <div class="re-num">{{vm.coin}}</div>
-                        </div>
-                        <div class="col col-33" style="padding: 30px 0 0 20px">
-                            <a ui-sref="app.withdraw" style="border: 1px solid #00C3DA; color: #00C3DA; padding: 5px 25px; border-radius: 30px;">提现</a>
+                            <div class="re-num">{{user.coin}}</div>
                         </div>
                     </div>
                 </div>
                 <div class="item item-input" style="padding-top: 20px; padding-bottom: 20px">
-                    <span class="input-label" style="width: 60px">金额</span>
-                    <input type="number" placeholder="请输入充值金额" ng-model="vm.money">
+                    <span class="input-label" style="width: 60px">梦想币</span>
+                    <input type="tel" placeholder="请输入数量" ng-model="vm.number">
                 </div>
                 <div class="item" style="color: #969696; padding-top: 40px">
                     选择支付方式
                 </div>
                 <ion-list class="re-radio">
-                    <ion-radio ng-model="choice" ng-value="'A'">
-                        <img ng-src="img/icon_ Alipay.svg" />
-                        <span>支付宝支付</span>
-                    </ion-radio>
-                    <ion-radio ng-model="choice" ng-value="'B'">
+                    <ion-radio ng-model="vm.payType" ng-value="2">
                         <img ng-src="img/icon_ WeChat Pay.svg" />
                         <span>微信支付</span>
                     </ion-radio>
+                    <!-- <ion-radio ng-model="vm.payType" ng-value="1">
+                        <img ng-src="img/icon_ Alipay.svg" />
+                        <span>支付宝支付</span>
+                    </ion-radio> -->
                 </ion-list>
             </div>
             <div class="padding">
-                <button  class="button button-block button-calm" ng-click="recharge(vm.money)">
+                <button  class="button button-block button-calm" ng-click="testcharge(vm.number)">
                     支付
                 </button>
             </div>
@@ -451,7 +447,7 @@
                         </div>
                         <em>{{user.coin}}&nbsp;</em>
                     </div>
-                    <div class="calm" ng-click="toRecharge()" style="float: left;">
+                    <div class="calm" ng-click="openRechargeModal()" style="float: left;">
                         <div style="float:left; padding-top: 4px;height: 45px;">
                             <img ng-src="img/icon_ recharge.png">
                         </div>