seam 8 年之前
父节点
当前提交
fc11926c16

+ 68 - 3
www/webapp/common/js/native.js

@@ -177,9 +177,74 @@ define(function (require) {
           var param_str = JSON.stringify(param);
           window.jsapi.sign(param_str);
         },
-        ios: function () {
-          var param_str = JSON.stringify(param);
-          window.location.href = 'http://callclient?method=sign&param=' + param_str + '&callback=' + _callback;
+        //支付
+        pay: function (params, callback) {
+            var that = this;
+            var param = {};
+            var _callback = 'NativeCallback.pay';
+            helper.osProxy({
+                android: function () {
+                    param['charge'] = params.charge;
+                    param['callback'] = _callback;
+                    var param_str = JSON.stringify(param);
+                    window.jsapi.pay(param_str);
+                },
+                // ios 的可以无视了,本项目暂时用不到
+                ios: function () {
+                    NativeDataAdapter.charge = JSON.stringify(params.charge);
+                    param['charge'] = 'NativeDataAdapter.charge';
+                    var param_str = JSON.stringify(param);
+                    window.location.href = 'http://callclient?method=pay&param=' + encodeURIComponent(param_str) + '&callback=' + _callback;
+                },
+                wx: function () {
+                  // 这个我就不知道说什么好了,判断当前环境为test的话,走ping++模拟支付
+                    if (config.test) {
+                        pingpp.createPayment(params.charge, function (result, err) {
+                            if (result == "success") {
+                                // 只有微信公众账号 wx_pub 支付成功的结果会在这里返回,其他的支付结果都会跳转到 extra 中对应的 URL。
+                                var res = {
+                                    success: true
+                                };
+                                callback(res);
+                            } else if (result == "fail") {
+                                // charge 不正确或者微信公众账号支付失败时会在此处返回
+                                console.log(err);
+                            } else if (result == "cancel") {
+                                // 微信公众账号支付取消支付
+                                console.log(err);
+                            }
+                        });
+                    }else {
+                      // 当前为正式环境,通过url传值到微信支付授权的url,然后在该url下面进行微信支付
+                      /*
+                      * 参数说明:带 * 号的为微信支付用到的
+                      * appId:* 公众号名称,由商户传入
+                      * nonceStr:* 随机串
+                      * prepay:预付款ID
+                      * signType:* 微信签名方式:
+                      * timeStamp:* 时间戳,自1970年以来的秒数
+                      * paySign:* 微信签名
+                      * amount:实付金额
+                      * created:建立
+                      * body:订单名字
+                      * bookingTime:预约时间
+                      * */
+                        var option = params['charge'].credential.wx_pub; // 支付凭据
+                        var prepay = option["package"].replace('prepay_id=', '');
+                        var bookingTime = params.orderInfo.booking_time_str;
+                        location.href = '/webapp/o2o/module/pay/index.html?appId='
+                            + option.appId + '&nonceStr=' + option.nonceStr
+                            + '&package=' + prepay + '&signType='
+                            + option.signType + '&timeStamp='
+                            + option.timeStamp + '&paySign='
+                            + option.paySign + '&amount=' + params['charge'].amount
+                            + '&created=' + params['charge'].created + '&body='
+                            + params['charge'].body + '&bookingTime=' + bookingTime;
+                    }
+                }
+            });
+            var callback = typeof (arguments[1]) == 'function' ? arguments[1] : null;
+            this.payCallback = callback;
         },
         wx: function () {
           //目前加上参数,绕过验证,后面再加上相关的验证

文件差异内容过多而无法显示
+ 201 - 203
www/webapp/moonclub/module/pay/index.html


文件差异内容过多而无法显示
+ 0 - 0
www/webapp/o2o/dist/js/main.js


文件差异内容过多而无法显示
+ 0 - 0
www/webapp/o2o/dist/js/native.js


文件差异内容过多而无法显示
+ 0 - 0
www/webapp/o2o/dist/js/page/pay.js


文件差异内容过多而无法显示
+ 3 - 3
www/webapp/o2o/js/build/template.js


+ 8 - 6
www/webapp/o2o/js/model/order.js

@@ -65,19 +65,21 @@ define(['base', '$', 'native', 'product', 'api'], function (base, $, native, pro
     //channel-渠道
     Order.prototype.addOrder = function (userID, channel, callback) {
         var that = this;
-
-        var productParam = [{//产品参数
-            product_id: this.productID,
-            count: this.productCount//产品数
+        // 产品参数
+        var productParam = [{
+            product_id: this.productID, // 产品ID
+            count: this.productCount // 产品数
         }];
-
-        var coupons = [];//优惠券
+       // 优惠券
+        var coupons = [];
         if (this.couponID != '') {
             coupons.push(this.couponID);
         }
 
+        // 添加额外的商品
         var extraJson = '';
         if (this.appendID) {
+          // 商品id && 商品价格
             extraJson = JSON.stringify([{type: this.appendID, price: this.price}]);
         }
 

+ 7 - 1
www/webapp/o2o/js/page/pay.js

@@ -25,7 +25,6 @@ define(['$', 'template', 'api', 'native', 'config', 'user'], function ($, templa
       var $doc = $(document);
       // 充值的回调
       function payResult(res) {
-        console.log(res.message);
         $doc.trigger('spa:closeloader');
         if (res.success) {
           var orderInfo = user.getOrderInfo(orderID);
@@ -33,6 +32,7 @@ define(['$', 'template', 'api', 'native', 'config', 'user'], function ($, templa
             orderInfo: orderInfo,
             charge: res.data
           };
+          // 调用native中pay方法,传值orderInfo,charge并做回调,返回充值结果
           native.pay(params, function (resA) {
             if (resA.success) {
               $doc.trigger('spa:navigate', {
@@ -57,19 +57,25 @@ define(['$', 'template', 'api', 'native', 'config', 'user'], function ($, templa
         $('.btn-pay', $view).attr('data-pay-channel', payChannel);
         $(this).addClass('checked').parent().siblings().find('a').removeClass('checked');
       }, $view);
+      // 真正的微信支付开始
       $.newTouch('.btn-pay', function (event) {
         event.preventDefault();
+        // 获取自定义的data-pay-channel的值,即支付方式
         var payChannel = $(this).attr('data-pay-channel');
+        // 判断当前客户端是否为微信公众号
         if (config.isWX) {
           payChannel = 'wx_pub';
         }
         if (!payChannel) return;
+        // 显示加载动画
         $doc.trigger('spa:openloader');
+        // 定义params对象,内置 用户id,订单id,支付方式
         var params = {
           user_id: user.id,
           order_id: orderID,
           pay_channel: payChannel
         };
+        // 判断是否是充值    PS:其实没啥用,都是走同一个支付入口的
         if (isRecharge) {
           api.payRecharge(params, function (res) {
             payResult(res)

+ 6 - 2
www/webapp/o2o/js/page/placeOrder.js

@@ -811,13 +811,16 @@ define(['$', 'template', 'order', 'native', 'helper', 'user', 'api', 'config', '
 
         /* 向服务器下订单 */
         $doc.trigger('spa:openloader');
+        // 判断用户余额大于等于订单金额,满足条件走余额支付
         if (user.balance >= order.payValue) {
           order.balance = order.payValue;
           order.payValue = 0;
         } else {
+          // 不满足条件走混合支付
           order.balance = user.balance;
           order.payValue = order.payValue - order.balance;
         }
+        // 在系统后台添加新增订单
         order.addOrder(user.id, payChannel, function (res) {
           $doc.trigger('spa:closeloader');
           if (res.success) {
@@ -835,14 +838,15 @@ define(['$', 'template', 'order', 'native', 'helper', 'user', 'api', 'config', '
             user.orderCoupons = newCouponList;
 
             var orderID = order.id;
-            order.reset();
-            console.log(order.reset());
+            order.reset(); //清空order内的值
             $('.booking-time', $view).html('请选择');
+            // status = 1 表示新增订单添加成功
             if (res.data.status == 1) {
               $doc.trigger('spa:navigate', {
                 hash: 'paySuccess'
               });
             } else {
+              // 跳转到pay调用微信支付
               $doc.trigger('spa:navigate', {
                 hash: 'pay',
                 pushData: {

+ 9 - 14
www/webapp/o2o/module/pay/index.html

@@ -185,7 +185,7 @@
     }
 
     .spa-page-pay-success .result-content {
-      background: #c7af34;
+      background: #8bc34a;
       padding-top: 38px;
     }
 
@@ -220,8 +220,8 @@
       font-size: 16px;
       padding: 10px 25px;
       margin-top: 0;
-      background: #c7af34;
-      border-color: #c7af34;
+      background: #8bc34a;
+      border-color: #8bc34a;
     }
 
     .spa-page-pay-success #icon-success {
@@ -291,6 +291,7 @@
 <script>
   if (location.search.length > 1) {
     var urlParam = {};
+    // 循环遍历WebApp通过url传过来的参数,赋值给urlParam
     for (var aItKey, nKeyId = 0, aCouples = location.search.substr(1).split("&"); nKeyId < aCouples.length; nKeyId++) {
       aItKey = aCouples[nKeyId].split("=");
       urlParam[decodeURIComponent(aItKey[0])] = aItKey.length > 1 ? decodeURIComponent(aItKey[1]) : "";
@@ -299,9 +300,8 @@
     var amount = urlParam.amount,
       created = urlParam.created,
       bookingTime = urlParam.bookingTime,
-      body = urlParam.body,
-      isSpecial = urlParam.isSpecial;
-
+      body = urlParam.body;
+    // 获取当前年月日时分
     function formatDate(now) {
       var d = new Date(now * 1000);
       var year = d.getFullYear();
@@ -314,7 +314,6 @@
 
     created = formatDate(created);
     amount = amount / 100;
-
     $('#order-name').text(body);
     if (bookingTime != 'undefined') {
       $('#order-time').text(bookingTime);
@@ -323,7 +322,7 @@
     }
 
     $('#order-result').text(amount + '元');
-
+    // 支付
     $('.btn-pay').click(function () {
       callpay();
     });
@@ -341,12 +340,8 @@
         }, function (res) {
           console.log(res);
           if (res.err_msg == "get_brand_wcpay_request:ok") {
-            if (isSpecial) {
-              location.href = '/o2o/web/index#bargain';
-            } else {
-              $('.j-pay-btn').hide();
-              $('.j-pay-result').show();
-            }
+            $('.j-pay-btn').hide();
+            $('.j-pay-result').show();
           } else if (res.err_msg == "get_brand_wcpay_request:cancel") {
             // alert('取消支付');
           } else {

部分文件因为文件数量过多而无法显示