Authored by 毕凯

Merge branch 'hotfix/alipay' into 'gray'

支付宝改用AJAX跳转



See merge request !401
@@ -3,7 +3,7 @@ @@ -3,7 +3,7 @@
3 * @Author: Targaryen 3 * @Author: Targaryen
4 * @Date: 2017-01-04 15:17:51 4 * @Date: 2017-01-04 15:17:51
5 * @Last Modified by: Targaryen 5 * @Last Modified by: Targaryen
6 - * @Last Modified time: 2017-02-20 18:16:09 6 + * @Last Modified time: 2017-03-20 14:03:48
7 */ 7 */
8 8
9 'use strict'; 9 'use strict';
@@ -127,7 +127,11 @@ const pay = (req, res, next) => { @@ -127,7 +127,11 @@ const pay = (req, res, next) => {
127 } 127 }
128 128
129 if (!orderCode || !uid) { 129 if (!orderCode || !uid) {
130 - return res.redirect('/'); 130 + return res.json({
  131 + code: 400,
  132 + message: '订单或用户信息不存在!',
  133 + url: '/'
  134 + });
131 } 135 }
132 136
133 co(function* () { 137 co(function* () {
@@ -140,7 +144,7 @@ const pay = (req, res, next) => { @@ -140,7 +144,7 @@ const pay = (req, res, next) => {
140 if (!orderDetail || !orderDetail.data) { 144 if (!orderDetail || !orderDetail.data) {
141 return res.json({ 145 return res.json({
142 code: 400, 146 code: 400,
143 - msg: '没有找到该订单!' 147 + message: '没有找到该订单!'
144 }); 148 });
145 } 149 }
146 150
@@ -149,8 +153,9 @@ const pay = (req, res, next) => { @@ -149,8 +153,9 @@ const pay = (req, res, next) => {
149 153
150 return res.json({ 154 return res.json({
151 code: 400, 155 code: 400,
152 - msg: '订单已经取消'  
153 - }).redirect(url); 156 + message: '订单已经取消',
  157 + url: url
  158 + });
154 } 159 }
155 160
156 Payment.pay(user, orderDetail.data, payment, { 161 Payment.pay(user, orderDetail.data, payment, {
@@ -162,9 +167,17 @@ const pay = (req, res, next) => { @@ -162,9 +167,17 @@ const pay = (req, res, next) => {
162 return res.json(result); 167 return res.json(result);
163 } 168 }
164 if (result && result.data && result.data.href && paymentCode === payModel.payments.alipay) { 169 if (result && result.data && result.data.href && paymentCode === payModel.payments.alipay) {
165 - return res.redirect(result.data.href); 170 + return res.json({
  171 + code: 200,
  172 + message: '校验成功',
  173 + url: result.data.href
  174 + });
166 } else { 175 } else {
167 - return res.redirect('/'); 176 + return res.json({
  177 + code: 400,
  178 + message: '系统错误!',
  179 + url: '/'
  180 + });
168 } 181 }
169 }); 182 });
170 })().catch(next); 183 })().catch(next);
@@ -4,10 +4,7 @@ @@ -4,10 +4,7 @@
4 {{/if}} 4 {{/if}}
5 <div class="payapp-list"> 5 <div class="payapp-list">
6 {{# payAppInfo}} 6 {{# payAppInfo}}
7 - {{#if payLink}}  
8 - <a href="{{payLink}}">  
9 - {{/if}}  
10 - <div class="box" id="{{appId}}"> 7 + <div class="box" id="{{appId}}" data-href="{{payLink}}">
11 <div class="icon"> 8 <div class="icon">
12 {{#if appIcon}} 9 {{#if appIcon}}
13 <img src="{{appIcon}}" alt="app图标"> 10 <img src="{{appIcon}}" alt="app图标">
@@ -25,9 +22,6 @@ @@ -25,9 +22,6 @@
25 </div> 22 </div>
26 <div class="iconfont">&#xe604</div> 23 <div class="iconfont">&#xe604</div>
27 </div> 24 </div>
28 - {{#if payLink}}  
29 - </a>  
30 - {{/if}}  
31 {{/ payAppInfo}} 25 {{/ payAppInfo}}
32 </div> 26 </div>
33 <div class="loading-toast hide"></div> 27 <div class="loading-toast hide"></div>
@@ -23,10 +23,10 @@ var richTip = require('../plugin/rich-tip'); @@ -23,10 +23,10 @@ var richTip = require('../plugin/rich-tip');
23 // 点击微信显示加载 23 // 点击微信显示加载
24 var $loadingToast = $('.loading-toast'); 24 var $loadingToast = $('.loading-toast');
25 25
26 -/* TODO 影响加载此段 JS */  
27 var theOrderCode = document.getElementById('ordercode') ? document.getElementById('ordercode').value : ''; 26 var theOrderCode = document.getElementById('ordercode') ? document.getElementById('ordercode').value : '';
28 27
29 var wxPayEl = document.getElementById('weixin'), 28 var wxPayEl = document.getElementById('weixin'),
  29 + $aliPayEL = $('#alipay'),
30 wxHammer = wxPayEl && new Hammer(wxPayEl); 30 wxHammer = wxPayEl && new Hammer(wxPayEl);
31 31
32 var appIconPosition = { 32 var appIconPosition = {
@@ -133,6 +133,19 @@ function jsApiCall(orderCode, jsApiParameters) { @@ -133,6 +133,19 @@ function jsApiCall(orderCode, jsApiParameters) {
133 ); 133 );
134 } 134 }
135 135
  136 +// 支付宝支付
  137 +if ($aliPayEL && $aliPayEL.length > 0 && $aliPayEL.data('href')) {
  138 + $aliPayEL.on('click', function() {
  139 + $.get($aliPayEL.data('href'), function(result) {
  140 + if (result && result.code === 200 && result.url) {
  141 + window.location.href = result.url;
  142 + } else {
  143 + tip.show(result && result.message || '系统错误!');
  144 + }
  145 + });
  146 + });
  147 +}
  148 +
136 // 微信支付 149 // 微信支付
137 function callpay(orderCode) { 150 function callpay(orderCode) {
138 var jsApiParameters; 151 var jsApiParameters;
@@ -195,7 +208,7 @@ function hideAliPay() { @@ -195,7 +208,7 @@ function hideAliPay() {
195 208
196 $payApps.each(function(idx, app) { 209 $payApps.each(function(idx, app) {
197 if ($(app).parent().attr('id') === 'alipay') { 210 if ($(app).parent().attr('id') === 'alipay') {
198 - $(app).closest('a').css('display', 'none'); 211 + $(app).parent().css('display', 'none');
199 return false; 212 return false;
200 } 213 }
201 }); 214 });