Authored by 陈轩

save

... ... @@ -2,9 +2,20 @@
const _ = require('lodash');
const helpers = global.yoho.helpers;
const cartModel = require('../models/cart');
const headerModel = require('../../../doraemon/models/header');
const userModel = require('../../serverAPI/user');
const addressModel = require('../../serverAPI/user/address');
exports.orderEnsure = (req, res, next) => {
req.locals.width750 = true;
req.locals.title = '确认订单';
let headerData = headerModel.setNav({
navTitle: '确认订单',
navBtn: false
});
let uid = req.user.uid;
let returnUrl = helpers.urlFormat('/cart/index/new');
let cartType = req.query.cartType || 'ordinary';
... ... @@ -16,6 +27,12 @@ exports.orderEnsure = (req, res, next) => {
orderInfo = {};
}
let cookieCartType = _.get(orderInfo, 'cartType');
if (cookieCartType) {
cartType = cookieCartType;
}
// 如果传递了code, skn, sku, buy_number 就代表限购商品
let limitProductCode = req.query.limitproductcode || '';
let sku = req.query.sku || '';
... ... @@ -23,14 +40,52 @@ exports.orderEnsure = (req, res, next) => {
let buyNumber = req.query.buy_number || 1;
if (limitProductCode) {
returnUrl = req.get('Referer') || returnUrl;
headerData.backUrl = req.get('Referer') || returnUrl;
}
cartModel.cartPay(uid, cartType, orderInfo, sku, skn, buyNumber, req.xhr)
.then(order => {
let order = cartModel.cartPay(uid, cartType, orderInfo, sku, skn, buyNumber, req.xhr);
let userProfile = userModel.queryProfile(uid);
let address = addressModel.addressData(uid);
return Promise.all([order, userProfile, address])
.then(
result => {
order = result[0];
userProfile = result[1];
address = result[2];
if (order.cartUrl) { // TODO? 普通或者预售商品为空时, BUT WHEN AJAX?
return res.redirect(order.cartUrl);
}
if (req.xhr) {
return res.json(order);
}
// 获取用户完整手机号
let mobile = _.get(userProfile, 'data.mobile', '');
let orderAddress = _.get(order, 'address', []);
let addressList = _.get(address, 'data', []);
orderAddress.length && addressList.forEach(address => { //eslint-disable-line
if (address.address_id === orderAddress.address_id) {
mobile = address.mobile;
}
});
let viewData = {
orderEnsurePage: true,
isOrdinaryCart: cartType !== 'advance',
orderEnsure: order,
userMobile: mobile
};
viewData.pageHader = headerData;
viewData.pageFooter = true;
})
res.render('order-ensure', viewData);
}
)
.catch(next);
res.send('todo: orderEnsure');
};
... ...
'use stict';
// doc: http://git.yoho.cn/yoho-documents/api-interfaces/blob/master/个人中心/地址管理.md';
const api = global.yoho.API;
const crypto = global.yoho.crypto;
/**
* 地址数据
* @param uid
* @return
* {
* "code":200,
* "data":[
* {
* "area":"江苏省 南京市 浦口区",
* "address":"沿江街道******,
* "consignee":"孟令阶",
* "is_support":"Y",
* "area_code":"320111",
* "mobile":"180****2255",
* "address_id":"6117354", // 会被加密
* "is_default":"N",
* "is_delivery":"Y",
* "zip_code":"",
* "uid":"14616040",
* "phone":"",
* "email":""}
* ],
* "md5":"c35872955397cd0aabff4583cd41ac4b",
* "message":"Address List"
* }
*/
exports.addressData = (uid) => {
let params = {
method: 'app.address.gethidden',
uid
};
let options = {
cache: true
};
return api.get('', params, options)
.then(
result => {
if (result.code === 200) {
// 加密address_id
result.data.forEach(address => {
address.address_id = crypto.encryption(null, address.address_id);
});
}
return result;
}
,
() => {
return {code: 500, data: [], message: '地址获取失败'};
}
);
};
... ...
'use strict';
const api = global.yoho.API;
/**
* 获取用户信息
* doc: http://git.yoho.cn/yoho-documents/api-interfaces/blob/master/个人中心/addUserprofile.md
* @param uid 用户id
* @return
*/
exports.queryProfile = (uid) => {
let params = {
method: 'app.passport.profile',
uid
};
let options = {
cache: true
};
return api.get('', params, options);
};
... ...
... ... @@ -21,10 +21,13 @@ module.exports = {
// liveApi: 'http://testapi.live.yohops.com:9999/',
// singleApi: 'http://api-test3.yohops.com:9999/'
api: 'http://api.yoho.cn/',
service: 'http://service.yoho.cn/',
liveApi: 'http://api.live.yoho.cn/',
singleApi: 'http://single.yoho.cn/'
api: 'http://api.gray.yohops.com',
service: 'service.gray.yohops.com'
// api: 'http://api.yoho.cn/',
// service: 'http://service.yoho.cn/',
// liveApi: 'http://api.live.yoho.cn/',
// singleApi: 'http://single.yoho.cn/'
},
subDomains: {
host: '.m.yohobuy.com',
... ... @@ -69,7 +72,7 @@ module.exports = {
port: '4444' // influxdb port
},
console: {
level: 'error',
level: 'info',
colorize: 'all',
prettyPrint: true
}
... ...