Showing
4 changed files
with
152 additions
and
10 deletions
@@ -2,9 +2,20 @@ | @@ -2,9 +2,20 @@ | ||
2 | const _ = require('lodash'); | 2 | const _ = require('lodash'); |
3 | const helpers = global.yoho.helpers; | 3 | const helpers = global.yoho.helpers; |
4 | const cartModel = require('../models/cart'); | 4 | const cartModel = require('../models/cart'); |
5 | +const headerModel = require('../../../doraemon/models/header'); | ||
6 | +const userModel = require('../../serverAPI/user'); | ||
7 | +const addressModel = require('../../serverAPI/user/address'); | ||
5 | 8 | ||
6 | 9 | ||
7 | exports.orderEnsure = (req, res, next) => { | 10 | exports.orderEnsure = (req, res, next) => { |
11 | + req.locals.width750 = true; | ||
12 | + req.locals.title = '确认订单'; | ||
13 | + | ||
14 | + let headerData = headerModel.setNav({ | ||
15 | + navTitle: '确认订单', | ||
16 | + navBtn: false | ||
17 | + }); | ||
18 | + | ||
8 | let uid = req.user.uid; | 19 | let uid = req.user.uid; |
9 | let returnUrl = helpers.urlFormat('/cart/index/new'); | 20 | let returnUrl = helpers.urlFormat('/cart/index/new'); |
10 | let cartType = req.query.cartType || 'ordinary'; | 21 | let cartType = req.query.cartType || 'ordinary'; |
@@ -16,6 +27,12 @@ exports.orderEnsure = (req, res, next) => { | @@ -16,6 +27,12 @@ exports.orderEnsure = (req, res, next) => { | ||
16 | orderInfo = {}; | 27 | orderInfo = {}; |
17 | } | 28 | } |
18 | 29 | ||
30 | + let cookieCartType = _.get(orderInfo, 'cartType'); | ||
31 | + | ||
32 | + if (cookieCartType) { | ||
33 | + cartType = cookieCartType; | ||
34 | + } | ||
35 | + | ||
19 | // 如果传递了code, skn, sku, buy_number 就代表限购商品 | 36 | // 如果传递了code, skn, sku, buy_number 就代表限购商品 |
20 | let limitProductCode = req.query.limitproductcode || ''; | 37 | let limitProductCode = req.query.limitproductcode || ''; |
21 | let sku = req.query.sku || ''; | 38 | let sku = req.query.sku || ''; |
@@ -23,14 +40,52 @@ exports.orderEnsure = (req, res, next) => { | @@ -23,14 +40,52 @@ exports.orderEnsure = (req, res, next) => { | ||
23 | let buyNumber = req.query.buy_number || 1; | 40 | let buyNumber = req.query.buy_number || 1; |
24 | 41 | ||
25 | if (limitProductCode) { | 42 | if (limitProductCode) { |
26 | - returnUrl = req.get('Referer') || returnUrl; | 43 | + headerData.backUrl = req.get('Referer') || returnUrl; |
27 | } | 44 | } |
28 | 45 | ||
29 | - cartModel.cartPay(uid, cartType, orderInfo, sku, skn, buyNumber, req.xhr) | ||
30 | - .then(order => { | 46 | + let order = cartModel.cartPay(uid, cartType, orderInfo, sku, skn, buyNumber, req.xhr); |
47 | + let userProfile = userModel.queryProfile(uid); | ||
48 | + let address = addressModel.addressData(uid); | ||
49 | + | ||
50 | + return Promise.all([order, userProfile, address]) | ||
51 | + .then( | ||
52 | + result => { | ||
53 | + order = result[0]; | ||
54 | + userProfile = result[1]; | ||
55 | + address = result[2]; | ||
56 | + | ||
57 | + if (order.cartUrl) { // TODO? 普通或者预售商品为空时, BUT WHEN AJAX? | ||
58 | + return res.redirect(order.cartUrl); | ||
59 | + } | ||
60 | + | ||
61 | + if (req.xhr) { | ||
62 | + return res.json(order); | ||
63 | + } | ||
64 | + | ||
65 | + // 获取用户完整手机号 | ||
66 | + let mobile = _.get(userProfile, 'data.mobile', ''); | ||
67 | + let orderAddress = _.get(order, 'address', []); | ||
68 | + let addressList = _.get(address, 'data', []); | ||
69 | + | ||
70 | + orderAddress.length && addressList.forEach(address => { //eslint-disable-line | ||
71 | + if (address.address_id === orderAddress.address_id) { | ||
72 | + mobile = address.mobile; | ||
73 | + } | ||
74 | + }); | ||
75 | + | ||
76 | + let viewData = { | ||
77 | + orderEnsurePage: true, | ||
78 | + isOrdinaryCart: cartType !== 'advance', | ||
79 | + orderEnsure: order, | ||
80 | + userMobile: mobile | ||
81 | + }; | ||
82 | + | ||
83 | + viewData.pageHader = headerData; | ||
84 | + viewData.pageFooter = true; | ||
31 | 85 | ||
32 | - }) | 86 | + res.render('order-ensure', viewData); |
87 | + } | ||
88 | + ) | ||
33 | .catch(next); | 89 | .catch(next); |
34 | 90 | ||
35 | - res.send('todo: orderEnsure'); | ||
36 | }; | 91 | }; |
apps/serverAPI/user/address.js
0 → 100644
1 | +'use stict'; | ||
2 | + | ||
3 | +// doc: http://git.yoho.cn/yoho-documents/api-interfaces/blob/master/个人中心/地址管理.md'; | ||
4 | + | ||
5 | +const api = global.yoho.API; | ||
6 | +const crypto = global.yoho.crypto; | ||
7 | + | ||
8 | +/** | ||
9 | + * 地址数据 | ||
10 | + * @param uid | ||
11 | + * @return | ||
12 | + * { | ||
13 | + * "code":200, | ||
14 | + * "data":[ | ||
15 | + * { | ||
16 | + * "area":"江苏省 南京市 浦口区", | ||
17 | + * "address":"沿江街道******, | ||
18 | + * "consignee":"孟令阶", | ||
19 | + * "is_support":"Y", | ||
20 | + * "area_code":"320111", | ||
21 | + * "mobile":"180****2255", | ||
22 | + * "address_id":"6117354", // 会被加密 | ||
23 | + * "is_default":"N", | ||
24 | + * "is_delivery":"Y", | ||
25 | + * "zip_code":"", | ||
26 | + * "uid":"14616040", | ||
27 | + * "phone":"", | ||
28 | + * "email":""} | ||
29 | + * ], | ||
30 | + * "md5":"c35872955397cd0aabff4583cd41ac4b", | ||
31 | + * "message":"Address List" | ||
32 | + * } | ||
33 | + */ | ||
34 | +exports.addressData = (uid) => { | ||
35 | + let params = { | ||
36 | + method: 'app.address.gethidden', | ||
37 | + uid | ||
38 | + }; | ||
39 | + | ||
40 | + let options = { | ||
41 | + cache: true | ||
42 | + }; | ||
43 | + | ||
44 | + return api.get('', params, options) | ||
45 | + .then( | ||
46 | + result => { | ||
47 | + if (result.code === 200) { | ||
48 | + // 加密address_id | ||
49 | + result.data.forEach(address => { | ||
50 | + address.address_id = crypto.encryption(null, address.address_id); | ||
51 | + }); | ||
52 | + } | ||
53 | + | ||
54 | + return result; | ||
55 | + } | ||
56 | + , | ||
57 | + () => { | ||
58 | + return {code: 500, data: [], message: '地址获取失败'}; | ||
59 | + } | ||
60 | + ); | ||
61 | +}; |
apps/serverAPI/user/index.js
0 → 100644
1 | +'use strict'; | ||
2 | +const api = global.yoho.API; | ||
3 | + | ||
4 | + | ||
5 | + | ||
6 | +/** | ||
7 | + * 获取用户信息 | ||
8 | + * doc: http://git.yoho.cn/yoho-documents/api-interfaces/blob/master/个人中心/addUserprofile.md | ||
9 | + * @param uid 用户id | ||
10 | + * @return | ||
11 | + */ | ||
12 | +exports.queryProfile = (uid) => { | ||
13 | + let params = { | ||
14 | + method: 'app.passport.profile', | ||
15 | + uid | ||
16 | + }; | ||
17 | + | ||
18 | + let options = { | ||
19 | + cache: true | ||
20 | + }; | ||
21 | + | ||
22 | + return api.get('', params, options); | ||
23 | +}; |
@@ -21,10 +21,13 @@ module.exports = { | @@ -21,10 +21,13 @@ module.exports = { | ||
21 | // liveApi: 'http://testapi.live.yohops.com:9999/', | 21 | // liveApi: 'http://testapi.live.yohops.com:9999/', |
22 | // singleApi: 'http://api-test3.yohops.com:9999/' | 22 | // singleApi: 'http://api-test3.yohops.com:9999/' |
23 | 23 | ||
24 | - api: 'http://api.yoho.cn/', | ||
25 | - service: 'http://service.yoho.cn/', | ||
26 | - liveApi: 'http://api.live.yoho.cn/', | ||
27 | - singleApi: 'http://single.yoho.cn/' | 24 | + api: 'http://api.gray.yohops.com', |
25 | + service: 'service.gray.yohops.com' | ||
26 | + | ||
27 | + // api: 'http://api.yoho.cn/', | ||
28 | + // service: 'http://service.yoho.cn/', | ||
29 | + // liveApi: 'http://api.live.yoho.cn/', | ||
30 | + // singleApi: 'http://single.yoho.cn/' | ||
28 | }, | 31 | }, |
29 | subDomains: { | 32 | subDomains: { |
30 | host: '.m.yohobuy.com', | 33 | host: '.m.yohobuy.com', |
@@ -69,7 +72,7 @@ module.exports = { | @@ -69,7 +72,7 @@ module.exports = { | ||
69 | port: '4444' // influxdb port | 72 | port: '4444' // influxdb port |
70 | }, | 73 | }, |
71 | console: { | 74 | console: { |
72 | - level: 'error', | 75 | + level: 'info', |
73 | colorize: 'all', | 76 | colorize: 'all', |
74 | prettyPrint: true | 77 | prettyPrint: true |
75 | } | 78 | } |
-
Please register or login to post a comment