Authored by htoooth

Merge branch 'master' into feature/channel-op

... ... @@ -17,7 +17,7 @@ const getArea = (req, res, next) => {
});
}
address.getAreaListData(id).then(result => {
req.ctx(address).getAreaListData(id).then(result => {
res.send(result);
}).catch(next);
};
... ... @@ -32,7 +32,7 @@ const getList = (req, res, next) => {
});
}
address.getAddressListData(uid).then(result => {
req.ctx(address).getAddressListData(uid).then(result => {
res.send(result);
}).catch(next);
};
... ... @@ -45,7 +45,7 @@ const delAddress = (req, res, next) => {
return next();
}
address.delAddressById(uid, id).then(result => {
req.ctx(address).delAddressById(uid, id).then(result => {
res.send(result);
}).catch(next);
};
... ... @@ -58,7 +58,7 @@ const saveAddress = (req, res, next) => {
return next();
}
address.saveAddressData(uid, params).then(result => {
req.ctx(address).saveAddressData(uid, params).then(result => {
res.send(result);
}).catch(next);
};
... ... @@ -71,7 +71,7 @@ const setDefault = (req, res, next) => {
return next();
}
address.setDefaultAddress(uid, id).then(result => {
req.ctx(address).setDefaultAddress(uid, id).then(result => {
res.send(result);
}).catch(next);
};
... ...
... ... @@ -17,7 +17,7 @@ const index = (req, res, next) => {
let uid = req.user.uid;
let params = req.query;
easypay.getEasypayOrderData(params, uid).then(result => {
req.ctx(easypay).getEasypayOrderData(params, uid).then(result => {
let header = headerModel.setSimpleHeaderData() || {};
result.stepper = stepper;
... ... @@ -39,7 +39,7 @@ const compute = (req, res, next) => {
let uid = req.user.uid;
let params = req.body;
easypay.getOrderComputeData(uid, 'ordinary', params).then(result => {
req.ctx(easypay).getOrderComputeData(uid, 'ordinary', params).then(result => {
res.json(result);
}).catch(next);
};
... ... @@ -53,7 +53,7 @@ const submit = (req, res, next) => {
return next();
}
easypay.easypayOrderSubmit(uid, 'ordinary', params, remoteIp).then(result => {
req.ctx(easypay).easypayOrderSubmit(uid, 'ordinary', params, remoteIp).then(result => {
res.json(result);
}).catch(next);
};
... ...
... ... @@ -23,7 +23,7 @@ const stepper = [
const index = (req, res, next) => {
let cartType = req.query.type === '2' ? 'advance' : 'ordinary';
oeModel.index(req.user.uid, cartType).then(result => {
req.ctx(oeModel).index(req.user.uid, cartType).then(result => {
let header = headerModel.setSimpleHeaderData() || {};
Object.assign(result, {
... ... @@ -46,14 +46,14 @@ const index = (req, res, next) => {
// 获取优惠券列表
const getCoupons = (req, res, next) => {
oeModel.getCoupons(req.user.uid).then(data => {
req.ctx(oeModel).getCoupons(req.user.uid).then(data => {
res.send(data);
}).catch(next);
};
// 获取优惠券列表
const convertCoupons = (req, res, next) => {
oeModel.convertCoupons(req.user.uid, req.query.code).then(data => {
req.ctx(oeModel).convertCoupons(req.user.uid, req.query.code).then(data => {
res.send(data);
}).catch(next);
};
... ... @@ -64,11 +64,11 @@ const compute = (req, res, next) => {
let cartType = params.cartType === '2' ? 'advance' : 'ordinary';
if (params.sku) { // 快捷结算
easypayModel.getOrderComputeData(req.user.uid, 'ordinary', params).then(result => {
req.ctx(easypayModel).getOrderComputeData(req.user.uid, 'ordinary', params).then(result => {
res.json(result);
}).catch(next);
} else {
oeModel.compute(req.user.uid, cartType, params).then(data => {
req.ctx(oeModel).compute(req.user.uid, cartType, params).then(data => {
res.send(data);
}).catch(next);
}
... ... @@ -153,11 +153,11 @@ const submit = (req, res, next) => {
params.udid = req.cookies._yasvd || 'yoho_pc';
if (params.sku) { // 快捷结算
easypayModel.easypayOrderSubmit(uid, 'ordinary', params, remoteIp).then(result => {
req.ctx(easypayModel).easypayOrderSubmit(uid, 'ordinary', params, remoteIp).then(result => {
res.json(result);
}).catch(next);
} else {
oeModel.submit(uid, cartType, params, remoteIp).then(data => {
req.ctx(oeModel).submit(uid, cartType, params, remoteIp).then(data => {
if (data && data.code === 200 && unionKey) {
data.data.unionKey = {
client_id: clientId
... ...
... ... @@ -21,7 +21,7 @@ const ticketEnsure = (req, res, next) => {
let buyNumber = req.query.buyNumber || 0;
let skn = req.query.productSkn || 0;
ticketService.addTicket(uid, sku, buyNumber).then(result => {
req.ctx(ticketService).addTicket(uid, sku, buyNumber).then(result => {
let header = headerModel.setSimpleHeaderData() || {};
result.stepper = stepper;
... ... @@ -51,7 +51,7 @@ const ticketSubmit = (req, res, next) => {
});
}
ticketService.submitTicket(uid, sku, count, mobile, yohoCoin).then(result => {
req.ctx(ticketService).submitTicket(uid, sku, count, mobile, yohoCoin).then(result => {
return res.json(result);
}).catch(next);
};
... ... @@ -62,7 +62,7 @@ const ticketCompute = (req, res, next) => {
let buyNumber = req.body.count || 0;
let yohoCoin = req.body.coin || 0;
ticketService.addTicket(uid, sku, buyNumber, yohoCoin).then(result => {
req.ctx(ticketService).addTicket(uid, sku, buyNumber, yohoCoin).then(result => {
if (_.isEmpty(result)) {
return res.json({
code: 401,
... ...
... ... @@ -5,40 +5,55 @@
*/
'use strict';
const api = global.yoho.API;
module.exports = class extends global.yoho.BaseModel {
constructor(ctx) {
super(ctx);
}
/**
/**
* 获取用户收货地址列表
* @param uid [number] uid
*/
const getAddressListAsync = (uid) => api.get('', {
getAddressListAsync(uid) {
let options = {
method: 'app.address.gethidden',
uid: uid
}, {code: 200});
};
/**
return this.get({data: options, param: {
code: 200
}});
}
/**
* 省市区列表
* @param id [number] 省市区id
*/
const getAreaListAsync = (id) => {
return api.get('', {
getAreaListAsync(id) {
let options = {
method: 'app.address.provinces',
id: id || 0
});
};
};
/**
return this.get({data: options});
}
/**
* 地址删除
* @param uid [number] uid
* @param id [string] address id
*/
const delAddressAsync = (uid, id) => api.get('', {
delAddressAsync(uid, id) {
let options = {
method: 'app.address.del',
uid: uid,
id: id
});
};
/**
return this.get({data: options});
}
/**
* 新增地址api
* @param uid [Number]
* @param consignee [String] 收货人
... ... @@ -49,7 +64,8 @@ const delAddressAsync = (uid, id) => api.get('', {
* @param zipCode [String] 邮编
* @param email [String] 邮箱
*/
const addAddressAsync = (uid, consignee, areaCode, address, mobile, phone, zipCode, email) => api.get('', {
addAddressAsync(uid, consignee, areaCode, address, mobile, phone, zipCode, email) {
let options = {
method: 'app.address.add',
uid: uid,
consignee: consignee,
... ... @@ -59,9 +75,12 @@ const addAddressAsync = (uid, consignee, areaCode, address, mobile, phone, zipCo
phone: phone,
zip_code: zipCode,
email: email
});
};
/**
return this.get({data: options});
}
/**
* 更新地址地址api
* @param uid [Number]
* @param id [Number] 地址id
... ... @@ -73,7 +92,8 @@ const addAddressAsync = (uid, consignee, areaCode, address, mobile, phone, zipCo
* @param zipCode [String] 邮编
* @param email [String] 邮箱
*/
const updateAddressAsync = (uid, id, consignee, areaCode, address, mobile, phone, zipCode, email) => api.get('', {
updateAddressAsync(uid, id, consignee, areaCode, address, mobile, phone, zipCode, email) {
let options = {
method: 'app.address.update',
uid: uid,
id: id,
... ... @@ -84,25 +104,23 @@ const updateAddressAsync = (uid, id, consignee, areaCode, address, mobile, phone
phone: phone,
zip_code: zipCode,
email: email
});
};
/**
return this.get({data: options});
}
/**
* 设置默认地址
* @param uid [Number]
* @param id [Number] 地址id
*/
const setDefaultAddressAsync = (uid, id) => api.get('', {
setDefaultAddressAsync(uid, id) {
let options = {
method: 'app.address.setdefault',
uid: uid,
id: id
});
};
module.exports = {
getAddressListAsync,
getAreaListAsync,
delAddressAsync,
addAddressAsync,
updateAddressAsync,
setDefaultAddressAsync
return this.get({data: options});
}
};
... ...
... ... @@ -10,12 +10,17 @@ const _ = require('lodash');
const crypto = global.yoho.crypto;
const pinyin = require('../models/province-pinyin');
const addressApi = require('../models/address-api');
const AddressApi = require('../models/address-api');
const worldSort = 'abcdefghijklmnopqrstuvwxyz';
const getAreaListData = (id) => {
return addressApi.getAreaListAsync(id).then(result => {
module.exports = class extends global.yoho.BaseModel {
constructor(ctx) {
super(ctx);
}
getAreaListData(id) {
return new AddressApi(this.ctx).getAreaListAsync(id).then(result => {
let list = _.get(result, 'data', []);
if (id * 1 === 0 && list.length) {
... ... @@ -27,10 +32,10 @@ const getAreaListData = (id) => {
}
return result;
});
};
}
const getAddressListData = (uid) => {
return addressApi.getAddressListAsync(uid).then(result => {
getAddressListData(uid) {
return new AddressApi(this.ctx).getAddressListAsync(uid).then(result => {
if (result.code !== 200) {
return result;
}
... ... @@ -52,22 +57,23 @@ const getAddressListData = (uid) => {
return result;
});
};
}
const delAddressById = (uid, id) => {
delAddressById(uid, id) {
id = crypto.decrypt('', `${id}`);
return new AddressApi(this.ctx).delAddressAsync(uid, id);
}
return addressApi.delAddressAsync(uid, id);
};
saveAddressData(uid, info) {
let addressApiModel = new AddressApi(this.ctx);
const saveAddressData = (uid, info) => {
if (info.id) {
let id = crypto.decrypt('', `${info.id}`);
return addressApi.updateAddressAsync(uid, id, info.consignee, info.areaCode, info.address,
return addressApiModel.updateAddressAsync(uid, id, info.consignee, info.areaCode, info.address,
info.mobile, info.phone, info.zipCode, info.email);
} else {
return addressApi.addAddressAsync(uid, info.consignee, info.areaCode, info.address, info.mobile,
return addressApiModel.addAddressAsync(uid, info.consignee, info.areaCode, info.address, info.mobile,
info.phone, info.zipCode, info.email).then(result => {
if (result.code === 200) {
let d = result.data;
... ... @@ -81,18 +87,11 @@ const saveAddressData = (uid, info) => {
});
}
};
}
const setDefaultAddress = (uid, id) => {
setDefaultAddress(uid, id) {
id = crypto.decrypt('', `${id}`);
return addressApi.setDefaultAddressAsync(uid, id);
};
module.exports = {
getAreaListData,
getAddressListData,
delAddressById,
saveAddressData,
setDefaultAddress
return new AddressApi(this.ctx).setDefaultAddressAsync(uid, id);
}
};
... ...
... ... @@ -5,9 +5,12 @@
*/
'use strict';
const api = global.yoho.API;
module.exports = class extends global.yoho.BaseModel {
constructor(ctx) {
super(ctx);
}
const getEasyPaymentAsync = (uid, goods, activity) => {
getEasyPaymentAsync(uid, goods, activity) {
let param = {
method: 'app.Shopping.easyPayment',
uid: uid,
... ... @@ -21,11 +24,10 @@ const getEasyPaymentAsync = (uid, goods, activity) => {
param.activity_id = activity;
}
return api.get('', param, {code: 200});
};
return this.get({data: param});
}
/**
/**
* 订单计算API
* @param uid [number] uid
* @param cartType [string] 购物车类型,ordinary表示普通, advance表示预售
... ... @@ -36,9 +38,8 @@ const getEasyPaymentAsync = (uid, goods, activity) => {
* @param couponCode [string] 优惠券码
* @param promotionCode [string] 优惠码
* @param productSkuList [string] 限购商品
*/
const getEasypayComputeAsync = (uid, cartType, paymentType, deliveryWay, other) => {
getEasypayComputeAsync(uid, cartType, paymentType, deliveryWay, other) {
let param = {
method: 'app.Shopping.easyCompute',
uid: uid,
... ... @@ -84,13 +85,12 @@ const getEasypayComputeAsync = (uid, cartType, paymentType, deliveryWay, other)
});
}
}
}
return api.get('', param);
};
return this.get({data: param});
}
/**
/**
* 订单提交API
* @param uid [number] uid
* @param cartType [String] 购物车类型,ordinary表示普通, advance表示预售
... ... @@ -109,7 +109,7 @@ const getEasypayComputeAsync = (uid, cartType, paymentType, deliveryWay, other)
* @param couponCode [string] 优惠券码
* @param printPrice [string] 是否打印价格
*/
const easypayOrderSubmitAsync = (uid, cartType, addressId, deliveryTime, deliveryWay, paymentType, paymentId, printPrice, other, remoteIp) => { // eslint-disable-line
easypayOrderSubmitAsync(uid, cartType, addressId, deliveryTime, deliveryWay, paymentType, paymentId, printPrice, other, remoteIp) { // eslint-disable-line
let param = {
method: 'app.Shopping.easySubmit',
uid: uid,
... ... @@ -178,13 +178,10 @@ const easypayOrderSubmitAsync = (uid, cartType, addressId, deliveryTime, deliver
});
}
return api.get('', param, {
headers: {'X-Forwarded-For': remoteIp || ''}
});
};
module.exports = {
getEasyPaymentAsync,
getEasypayComputeAsync,
easypayOrderSubmitAsync
return this.get({data: param, param: {
headers: {
'X-Forwarded-For': remoteIp || ''
}
}});
}
};
... ...
... ... @@ -10,13 +10,18 @@ const _ = require('lodash');
const helper = global.yoho.helpers;
const crypto = global.yoho.crypto;
const easypayApi = require('./easypay-api');
const addressApi = require('./address-api');
const ensureApi = require('./order-ensure-api');
const EasypayApi = require('./easypay-api');
const AddressApi = require('./address-api');
const EnsureApi = require('./order-ensure-api');
const ensureHandle = require('./order-ensure-handle');
const EnsureHandle = require('./order-ensure-handle');
const _getLimitProductData = (params) => {
module.exports = class extends global.yoho.BaseModel {
constructor(ctx) {
super(ctx);
}
_getLimitProductData(params) {
let resList = [];
if (params.limitcode && params.sku && params.skn) {
... ... @@ -40,25 +45,25 @@ const _getLimitProductData = (params) => {
}
return resList.length ? JSON.stringify(resList) : false;
};
}
// 获取结算信息
const getEasypayOrderData = (params, uid) => {
// 获取结算信息
getEasypayOrderData(params, uid) {
let resData = {};
let strInfo = _getLimitProductData(params);
let strInfo = this._getLimitProductData(params);
let bundle = params.bundle ? parseInt(params.bundle, 10) : false;
return Promise.all([
easypayApi.getEasyPaymentAsync(uid, strInfo, bundle),
addressApi.getAddressListAsync(uid),
ensureApi.getUserProfileAsync(uid)
new EasypayApi(this.ctx).getEasyPaymentAsync(uid, strInfo, bundle),
new AddressApi(this.ctx).getAddressListAsync(uid),
new EnsureApi(this.ctx).getUserProfileAsync(uid)
]).then(result => {
let data = _.get(result, '[0].data', false);
let address = _.get(result, '[1].data', []);
let receiver = _.get(result, '[2].data.mobile', '');
if (data) {
Object.assign(resData, ensureHandle.handlePaymentInfo(data, address), {
Object.assign(resData, new EnsureHandle(this.ctx).handlePaymentInfo(data, address), {
receiverMobile: receiver,
hideReceiverMobile: _.replace(receiver, /(\d{3})\d{4}(\d{4,9})/, '$1****$2')
});
... ... @@ -66,35 +71,40 @@ const getEasypayOrderData = (params, uid) => {
return resData;
});
};
}
// 价格计算
const getOrderComputeData = (uid, cartType, params) => {
params.productSkuList = _getLimitProductData(params);
// 价格计算
getOrderComputeData(uid, cartType, params) {
params.productSkuList = this._getLimitProductData(params);
return easypayApi.getEasypayComputeAsync(uid, cartType, params.paymentType, params.deliveryWay, params).then(result => { // eslint-disable-line
return new EasypayApi(this.ctx).getEasypayComputeAsync(uid, cartType, params.paymentType, params.deliveryWay, params).then(result => { // eslint-disable-line
if (result.code === 200) {
let ensureHandleModel = new EnsureHandle(this.ctx);
if (_.has(result, 'data.last_order_amount')) {
result.data.last_order_amount = (result.data.last_order_amount).toFixed(2);
}
if (_.has(result, 'data.promotion_formula_list')) {
ensureHandle.handleViewPrice(result.data.promotion_formula_list);
ensureHandleModel.handleViewPrice(result.data.promotion_formula_list);
}
result.data = Object.assign(result.data, ensureHandle.handleUseYohoCoin(result.data));
result.data = Object.assign(result.data, ensureHandleModel.handleUseYohoCoin(result.data));
}
return result;
});
};
}
// 订单提交
const easypayOrderSubmit = (uid, cartType, params, remoteIp) => {
// 订单提交
easypayOrderSubmit(uid, cartType, params, remoteIp) {
params.addressId = crypto.decrypt('', params.addressId);
params.productSkuList = _getLimitProductData(params);
params.productSkuList = this._getLimitProductData(params);
return easypayApi.easypayOrderSubmitAsync(uid, cartType, params.addressId, params.deliveryTime,
params.deliveryWay, params.paymentType, params.paymentId, params.printPrice, params, remoteIp).then(result => {
return new EasypayApi(this.ctx).easypayOrderSubmitAsync(
uid, cartType, params.addressId, params.deliveryTime,
params.deliveryWay, params.paymentType, params.paymentId,
params.printPrice, params, remoteIp
).then(result => {
if (result.code === 200) {
let d = result.data;
... ... @@ -103,12 +113,6 @@ const easypayOrderSubmit = (uid, cartType, params, remoteIp) => {
});
}
return result;
});
}
);
};
module.exports = {
getEasypayOrderData,
getOrderComputeData,
easypayOrderSubmit
};
... ...
... ... @@ -5,52 +5,71 @@
*/
'use strict';
const api = global.yoho.API;
module.exports = class extends global.yoho.BaseModel {
constructor(ctx) {
super(ctx);
}
/**
/**
* 获取用户信息API
* @param uid [number] uid
*/
const getUserProfileAsync = (uid) => api.get('', {
getUserProfileAsync(uid) {
let options = {
method: 'app.passport.profile',
uid: uid
});
};
/**
return this.get({data: options});
}
/**
* 购物车结算API
* @param uid [number] uid
* @param cartType [string] 购物车类型,ordinary表示普通, advance表示预售
* @param yohoCoinMode [number] 是否使用yoho币,1使用,0不使用
*/
const getOrderPaymentAsync = (uid, cartType, yohoCoinMode) => api.get('', {
getOrderPaymentAsync(uid, cartType, yohoCoinMode) {
let options = {
method: 'app.Shopping.payment',
cart_type: cartType,
yoho_coin_mode: yohoCoinMode,
uid: uid
});
};
/**
return this.get({data: options});
}
/**
* 获取用户优惠券信息API
* @param uid [number] uid
*/
const getUesrCouponAsync = (uid) => api.get('', {
getUesrCouponAsync(uid) {
let options = {
method: 'app.Shopping.listCoupon',
uid: uid,
is_group_frees: 'Y'
});
};
/**
return this.get({data: options});
}
/**
* 优惠码兑换优惠券API
* @param uid [number] uid
* @param code [number] code
*/
const getCouponByCodeAsync = (uid, code) => api.get('', {
getCouponByCodeAsync(uid, code) {
let options = {
method: 'app.Shopping.useCoupon',
uid: uid,
coupon_code: code
});
};
/**
return this.get({data: options});
}
/**
* 订单计算API
* @param uid [number] uid
* @param cartType [string] 购物车类型,ordinary表示普通, advance表示预售
... ... @@ -61,7 +80,7 @@ const getCouponByCodeAsync = (uid, code) => api.get('', {
* @param couponCode [string] 优惠券码
* @param promotionCode [string] 优惠码
*/
const getOrderComputeAsync = (uid, cartType, paymentType, deliveryWay, other) => {
getOrderComputeAsync(uid, cartType, paymentType, deliveryWay, other) {
let param = {
method: 'app.Shopping.compute',
uid: uid,
... ... @@ -95,10 +114,10 @@ const getOrderComputeAsync = (uid, cartType, paymentType, deliveryWay, other) =>
}
}
return api.get('', param);
};
return this.get({data: param});
}
/**
/**
* 订单提交API
* @param uid [number] uid
* @param cartType [String] 购物车类型,ordinary表示普通, advance表示预售
... ... @@ -117,7 +136,7 @@ const getOrderComputeAsync = (uid, cartType, paymentType, deliveryWay, other) =>
* @param couponCode [string] 优惠券码
* @param printPrice [string] 是否打印价格
*/
const orderSubmitAsync = (uid, cartType, addressId, deliveryTime, deliveryWay, paymentType, paymentId, printPrice, other, remoteIp) => { // eslint-disable-line
orderSubmitAsync(uid, cartType, addressId, deliveryTime, deliveryWay, paymentType, paymentId, printPrice, other, remoteIp) { // eslint-disable-line
let param = {
method: 'app.Shopping.submit',
uid: uid,
... ... @@ -194,19 +213,12 @@ const orderSubmitAsync = (uid, cartType, addressId, deliveryTime, deliveryWay, p
});
}
return api.get('', param, {
return this.get({data: param, param: {
headers: {
'X-Forwarded-For': remoteIp || '',
'User-Agent': other.userAgent || ''
}
});
}});
}
};
module.exports = {
getUserProfileAsync,
getOrderPaymentAsync,
getUesrCouponAsync,
getCouponByCodeAsync,
getOrderComputeAsync,
orderSubmitAsync
};
... ...
... ... @@ -6,11 +6,15 @@
'use strict';
const _ = require('lodash');
const helper = global.yoho.helpers;
const crypto = global.yoho.crypto;
const handleViewPrice = list => {
module.exports = class extends global.yoho.BaseModel {
constructor(ctx) {
super(ctx);
}
handleViewPrice(list) {
if (list) {
_.forEach(list, val => {
if (val.promotion === '商品金额') {
... ... @@ -22,9 +26,9 @@ const handleViewPrice = list => {
}
});
}
};
}
const handleUseYohoCoin = (info) => {
handleUseYohoCoin(info) {
let resData = {};
let limitCoin = _.get(info, 'yoho_coin_pay_rule.num_limit', 0);
... ... @@ -52,9 +56,9 @@ const handleUseYohoCoin = (info) => {
}
return resData;
};
}
const handlePaymentInfo = (d, address) => {
handlePaymentInfo(d, address) {
let resData = {};
let defAddrId = _.get(d, 'delivery_address.address_id', 0);
... ... @@ -101,14 +105,14 @@ const handlePaymentInfo = (d, address) => {
resData.goodsList = d.goods_list;
if (d.shopping_cart_data && d.shopping_cart_data.promotion_formula_list) {
handleViewPrice(d.shopping_cart_data.promotion_formula_list);
this.handleViewPrice(d.shopping_cart_data.promotion_formula_list);
}
Object.assign(resData, {
paymentWay: d.payment_way,
deliveryTime: d.delivery_time,
deliveryWay: d.delivery_way,
shoppingCartData: Object.assign(d.shopping_cart_data, handleUseYohoCoin(d), {
shoppingCartData: Object.assign(d.shopping_cart_data, this.handleUseYohoCoin(d), {
redEnvelopes: d.red_envelopes,
useRedEnvelopes: d.use_red_envelopes
}),
... ... @@ -116,11 +120,5 @@ const handlePaymentInfo = (d, address) => {
});
return resData;
};
module.exports = {
handleViewPrice,
handleUseYohoCoin,
handlePaymentInfo
}
};
... ...
... ... @@ -6,33 +6,35 @@
'use strict';
const _ = require('lodash');
// const api = global.yoho.API;
const helper = global.yoho.helpers;
const crypto = global.yoho.crypto;
// const config = global.yoho.config;
const ensureApi = require('./order-ensure-api');
const addressApi = require('./address-api');
const EnsureApi = require('./order-ensure-api');
const AddressApi = require('./address-api');
const EnsureHandle = require('./order-ensure-handle');
const ensureHandle = require('./order-ensure-handle');
module.exports = class extends global.yoho.BaseModel {
constructor(ctx) {
super(ctx);
}
const index = (uid, cartType) => {
index(uid, cartType) {
let resData = {};
let addressApiModel = new AddressApi(this.ctx);
let ensureApiModel = new EnsureApi(this.ctx);
let ensureHandleModel = new EnsureHandle(this.ctx);
return Promise.all([
ensureApi.getOrderPaymentAsync(uid, cartType, 0),
addressApi.getAddressListAsync(uid),
ensureApi.getUserProfileAsync(uid)
ensureApiModel.getOrderPaymentAsync(uid, cartType, 0),
addressApiModel.getAddressListAsync(uid),
ensureApiModel.getUserProfileAsync(uid)
]).then(result => {
let data = _.get(result, '[0].data', false);
let address = _.get(result, '[1].data', []);
let receiver = _.get(result, '[2].data.mobile', '');
if (data) {
Object.assign(resData, ensureHandle.handlePaymentInfo(data, address), {
Object.assign(resData, ensureHandleModel.handlePaymentInfo(data, address), {
receiverMobile: receiver,
hideReceiverMobile: _.replace(receiver, /(\d{3})\d{4}(\d{4,9})/, '$1****$2')
});
... ... @@ -40,43 +42,49 @@ const index = (uid, cartType) => {
return resData;
});
};
}
// 获取优惠券列表
const getCoupons = (uid) => ensureApi.getUesrCouponAsync(uid).then(result => {
// 获取优惠券列表
getCoupons(uid) {
return new EnsureApi(this.ctx).getUesrCouponAsync(uid).then(result => {
if (_.isEmpty(_.get(result, 'data.usable_coupons', [])) &&
_.isEmpty(_.get(result, 'data.usable_frees_coupons', []))) {
_.set(result, 'data.emptyUsable', true);
}
return result;
});
// 兑换优惠券
const convertCoupons = (uid, code) => ensureApi.getCouponByCodeAsync(uid, code);
});
}
// 兑换优惠券
convertCoupons(uid, code) {
return new EnsureApi(this.ctx).getCouponByCodeAsync(uid, code);
}
// 订单计算
const compute = (uid, cartType, pa) => {
return ensureApi.getOrderComputeAsync(uid, cartType, pa.paymentType, pa.deliveryWay, pa).then(result => {
// 订单计算
compute(uid, cartType, pa) {
return new EnsureApi(this.ctx).getOrderComputeAsync(
uid, cartType, pa.paymentType, pa.deliveryWay, pa
).then(result => {
if (result.code === 200) {
let ensureHandleModel = new EnsureHandle(this.ctx);
if (_.has(result, 'data.last_order_amount')) {
result.data.last_order_amount = (result.data.last_order_amount).toFixed(2);
}
if (_.has(result, 'data.promotion_formula_list')) {
ensureHandle.handleViewPrice(result.data.promotion_formula_list);
ensureHandleModel.handleViewPrice(result.data.promotion_formula_list);
}
result.data = Object.assign(result.data, ensureHandle.handleUseYohoCoin(result.data));
result.data = Object.assign(result.data, ensureHandleModel.handleUseYohoCoin(result.data));
}
return result;
});
};
}
// 订单提交
const submit = (uid, cartType, p, remoteIp) => {
// 订单提交
submit(uid, cartType, p, remoteIp) {
if (p.addressId) {
p.addressId = crypto.decrypt('', `${p.addressId}`);
}
... ... @@ -90,7 +98,7 @@ const submit = (uid, cartType, p, remoteIp) => {
});
}
return ensureApi.orderSubmitAsync(uid, cartType, p.addressId, p.deliveryTime,
return new EnsureApi(this.ctx).orderSubmitAsync(uid, cartType, p.addressId, p.deliveryTime,
p.deliveryWay, p.paymentType, p.paymentId, p.printPrice, p, remoteIp).then(result => {
if (result.code === 200) {
let d = result.data;
... ... @@ -103,12 +111,5 @@ const submit = (uid, cartType, p, remoteIp) => {
return result;
}
);
};
module.exports = {
index,
getCoupons,
convertCoupons,
compute,
submit
}
};
... ...
... ... @@ -2,9 +2,12 @@
* Created by TaoHuang on 2017/6/22.
*/
const api = global.yoho.API;
module.exports = class extends global.yoho.BaseModel {
constructor(ctx) {
super(ctx);
}
/**
/**
* 电子票下单
* @param uid 用户id
* @param sku 商品sku
... ... @@ -12,7 +15,7 @@ const api = global.yoho.API;
* @param mobile 手机号码
* @param yohoCoin 有货币
*/
function submit(uid, sku, count, mobile, yohoCoin) {
submit(uid, sku, count, mobile, yohoCoin) {
let params = {
method: 'app.shopping.submitTicket',
uid,
... ... @@ -25,17 +28,17 @@ function submit(uid, sku, count, mobile, yohoCoin) {
params.use_yoho_coin = yohoCoin / 100;
}
return api.get('', params);
}
return this.get({data: params});
}
/**
/**
* 电子票添加和查询
* @param uid 用户 id
* @param sku 商品sku
* @param count 购买数量 1-4
* @param yohoCoin 有货币
*/
function add(uid, sku, count, yohoCoin) {
add(uid, sku, count, yohoCoin) {
let params = {
method: 'app.shopping.ticket',
uid,
... ... @@ -47,10 +50,6 @@ function add(uid, sku, count, yohoCoin) {
params.use_yoho_coin = yohoCoin / 100;
}
return api.get('', params);
}
module.exports = {
submit,
add
return this.get({data: params});
}
};
... ...
... ... @@ -2,27 +2,30 @@
* Created by TaoHuang on 2017/6/22.
*/
const api = require('./ticket-api');
const Promise = require('bluebird');
const co = Promise.coroutine;
const TicketApi = require('./ticket-api');
const _ = require('lodash');
const helpers = global.yoho.helpers;
const _handleUseYhoCoin = require('./order-ensure-handle').handleUseYohoCoin;
const OrderEnsureHandle = require('./order-ensure-handle');
function _handleGoodsList(list) {
module.exports = class extends global.yoho.BaseModel {
constructor(ctx) {
super(ctx);
}
_handleGoodsList(list) {
return list.map((i) => {
i.linkToGoods = helpers.getUrlBySkc(i.product_skn);
i.productPrice = i.sales_price;
return i;
});
}
}
function _handleAmount(info) {
_handleAmount(info) {
return _.get(info, 'data.shopping_cart_data.last_order_amount', 0);
}
}
const addTicket = co(function * (uid, sku, count, yohoCoin) {
let ticketInfo = yield api.add(uid, sku, count, yohoCoin);
addTicket(uid, sku, count, yohoCoin) {
return new TicketApi(this.ctx).add(uid, sku, count, yohoCoin).then(ticketInfo => {
let result = {};
if (_.isEmpty(ticketInfo)) {
... ... @@ -40,16 +43,19 @@ const addTicket = co(function * (uid, sku, count, yohoCoin) {
}
result.virtualGood = true;
result.goodsList = _handleGoodsList(_.get(ticketInfo, 'data.goods_list', []));
result.last_order_amount = _handleAmount(ticketInfo);
Object.assign(result, _handleUseYhoCoin(_.get(ticketInfo, 'data.shopping_cart_data', {})));
result.goodsList = this._handleGoodsList(_.get(ticketInfo, 'data.goods_list', []));
result.last_order_amount = this._handleAmount(ticketInfo);
return result;
});
Object.assign(result, new OrderEnsureHandle(this.ctx).handleUseYohoCoin(
_.get(ticketInfo, 'data.shopping_cart_data', {}
)));
const submitTicket = co(function * (uid, sku, count, mobile, yohoCoin) {
let result = yield api.submit(uid, sku, count, mobile, yohoCoin);
return result;
});
}
submitTicket(uid, sku, count, mobile, yohoCoin) {
return new TicketApi(this.ctx).submit(uid, sku, count, mobile, yohoCoin).then(result => {
if (_.isEmpty(result)) {
return {
code: 500,
... ... @@ -73,9 +79,6 @@ const submitTicket = co(function * (uid, sku, count, mobile, yohoCoin) {
})
}
};
});
module.exports = {
addTicket,
submitTicket
});
}
};
... ...
... ... @@ -12,7 +12,7 @@ const helpers = global.yoho.helpers;
exports.QRcode = (req, res, next) => {
let id = req.query.orderCode || 0;
QRcodeModel.getQRcodeData(id, req.user.uid).then((result)=>{
req.ctx(QRcodeModel).getQRcodeData(id, req.user.uid).then((result)=>{
if (!result) {
return next();
}
... ...
... ... @@ -6,14 +6,20 @@
'use strict';
const logger = global.yoho.logger;
var api = global.yoho.API;
exports.getQRcodeData = (id, uid) => {
return api.get('', {
module.exports = class extends global.yoho.BaseModel {
constructor(ctx) {
super(ctx);
}
getQRcodeData(id, uid) {
let options = {
method: 'app.SpaceOrders.getQrByOrderCode',
order_code: id,
uid: uid
}).then(result => {
};
return this.get({data: options}).then(result => {
if (result && result.code === 200) {
return result.data;
} else {
... ... @@ -21,4 +27,5 @@ exports.getQRcodeData = (id, uid) => {
return false;
}
});
}
};
... ...
... ... @@ -183,8 +183,8 @@ exports.isFavoriteBrand = (req, res, next) => {
return next();
}
if (!req.body.brandId || !uid) {
return res.json({code: 400, message: '用户未登录或缺少参数'});
if (!req.body.brandId) {
return res.json({code: 400, message: '缺少参数'});
}
req.ctx(searchApi).isFavoriteBrand(uid, brandId).then(result => {
... ... @@ -207,8 +207,8 @@ exports.shopCouponSync = (req, res, next) => {
return next();
}
if (!id || !uid) {
return res.json({code: 400, message: '用户未登录或缺少参数'});
if (!id) {
return res.json({code: 400, message: '缺少参数'});
}
req.ctx(list).getUserCoupunStatus(id, uid, 'shop').then(result => {
... ...
... ... @@ -225,7 +225,14 @@ const keyId = (req, res, next) => {
title: `${query}价格_图片_品牌_怎么样-YOHO!BUY有货`,
keywords: `${query},${query}价格,${query}图片,${query}怎么样,${query}品牌,YOHO!BUY有货`,
description: `YOHO!BUY有货网yohobuy.com是国内专业的${query}网上潮流购物商城,为您找到${_.get(result,
'search.totalCount', 0)}${query}、产品的详细参数,实时报价,价格行情,图片、评价、品牌等信息。买${query},就上YOHO!BUY有货`
'search.totalCount', 0)}${query}、产品的详细参数,实时报价,价格行情,图片、评价、品牌等信息。买${query},就上YOHO!BUY有货`,
pageFooterSeo: {
description: `YOHO!BUY有货网yohobuy.com是国内专业的<b>${query}</b>网上潮流购物商城,为您找到<b>${_.get(result,
'search.totalCount', 0)}</b>条<b>${query}</b>、产品的详细参数,实时报价,价格行情,图片、评价、品牌等信息。买<b>` +
`${query}</b>,就上YOHO!BUY有货!`,
queryKey: query,
wapUrl: helpers.urlFormat(`/chanpin/${id}.html`, null, 'm')
}
});
if (!_.get(result, 'search.goods') || !_.get(result, 'search.goods').length) {
... ...
... ... @@ -444,7 +444,15 @@ function getSearchKeywordDataById(id, params, channel) {
});
});
_.set(resData, 'search.leftContent.allSuggest.list', redisData.data);
let rarr = _.chunk(redisData.data, 12);
if (rarr.length) {
_.set(resData, 'search.leftContent.allSuggest.list', rarr.shift());
_.set(resData, 'recommendKeywordsInfo', {
recommendKeywordsTitle: '更多推荐',
recommendKeywords: _.concat(...rarr)
});
}
}
return resData;
... ...
<div class="product-list-page search-page product-page yoho-page">
<div class="product-list-page product-search-page product-page yoho-page">
{{# search}}
{{> list/list}}
... ...
... ... @@ -65,17 +65,14 @@
{{> product/left-content}}
</div>
<div class="list-right pull-right">
{{#if_cond goods.length '<' 20 }}
{{#if suggest}}
{{#unless changedQuery}}
<div class="search-suggest-less">
<em>"{{name}}"</em>&nbsp;搜索结果太少了,试试{{#suggest}}&nbsp;"<a href="/?query={{.}}&is_rec=Y">{{.}}</a>"&nbsp;{{/suggest}}关键词搜索
</div>
{{/unless}}
{{/if}}
{{/if}}
{{/if_cond}}
{{#if changedQuery}}
... ... @@ -108,10 +105,10 @@
{{> product/standard-content}}
{{#if @root.search.isSearch}}
{{#if_cond goods.length '<' 20 }}
{{> product/recommend-keywords goodsInfo=@root.recommendKeywordsInfo}}
{{#if @root.search.isSearch}}
{{#if_cond goods.length '<' 20}}
<div>
<textarea class="lazy-load-object-2" style="visibility: hidden;">
<script>getSearchRecommend();</script>
... ... @@ -125,13 +122,17 @@
<div class="goods-slide">
<div data-role="recommend-slide" class="slide-panel recommend-slider"></div>
</div>
{{/if_cond}}
{{/if}}
{{> product/latest-walk}}
{{# @root.pageFooterSeo}}
<div class="page-footer-seo">
<div>{{{description}}}</div>
<p class="wap-page-href">移动版:<a href="{{wapUrl}}">{{queryKey}}</a></p>
</div>
{{/ @root.pageFooterSeo}}
</div>
{{/ brandAbout}}
</div>
... ...
{{#if goodsInfo.recommendKeywords}}
{{# goodsInfo}}
{{#if recommendKeywords}}
<div class="recommend-keywords">
<h3>相关推荐</h3>
<h3>{{#if recommendKeywordsTitle}}{{recommendKeywordsTitle}}{{^}}相关推荐{{/if}}</h3>
<p>
{{# goodsInfo.recommendKeywords}}
{{# recommendKeywords}}
<a href="{{url}}" title="{{keyword}}" target="_blank" class="keyword">{{keyword}}</a>
{{/ goodsInfo.recommendKeywords}}
{{/ recommendKeywords}}
</p>
</div>
{{/if}}
{{/if}}
{{#if goodsInfo.recommendNewProducts}}
{{#if recommendNewProducts}}
<div class="recommend-keywords">
<h3>新品推荐</h3>
<p>
{{# goodsInfo.recommendNewProducts}}
{{# recommendNewProducts}}
<a href="{{url}}" title="{{name}}" target="_blank" class="common">{{name}}</a>
{{/ goodsInfo.recommendNewProducts}}
{{/ recommendNewProducts}}
</p>
</div>
{{/if}}
{{/if}}
{{#if goodsInfo.recommendArticles}}
{{#if recommendArticles}}
<div class="recommend-keywords">
<h3>文章推荐</h3>
<p>
{{# goodsInfo.recommendArticles}}
{{# recommendArticles}}
<a href="{{url}}" title="{{name}}" target="_blank" class="common">{{name}}</a>
{{/ goodsInfo.recommendArticles}}
{{/ recommendArticles}}
</p>
</div>
{{/if}}
{{/if}}
{{/ goodsInfo}}
... ...
... ... @@ -168,7 +168,7 @@ module.exports = class extends global.yoho.BaseModel {
if (orderInfo.order_code) {
// 订单处理
if (orderInfo.attribute === 3) {
if (+orderInfo.attribute === 3) {
orderInfo.deliveryTimes = '自动发货 - 在您支付成功后,系统将立即为您发放二维码,您可以在您的订单中查看。';
} else {
orderInfo.deliveryTimes = orderInfo.delivery_time || '';
... ...
... ... @@ -17,12 +17,12 @@ module.exports = {
cookieDomain: '.yohobuy.com',
domains: {
// test3
// singleApi: 'http://api-test3.yohops.com:9999/',
// api: 'http://api-test3.yohops.com:9999/',
// service: 'http://service-test3.yohops.com:9999/',
// serviceNotify: 'http://service-test3.yohops.com:9999/',
// global: 'http://global-test-soa.yohops.com:9999/',
// platformApi: 'http://192.168.102.48:8088/',
singleApi: 'http://api-test3.yohops.com:9999/',
api: 'http://api-test3.yohops.com:9999/',
service: 'http://service-test3.yohops.com:9999/',
serviceNotify: 'http://service-test3.yohops.com:9999/',
global: 'http://global-test-soa.yohops.com:9999/',
platformApi: 'http://192.168.102.48:8088/',
// test2
// singleApi: 'http://api-test2.yohops.com:9999/',
... ...
{
"name": "yohobuy-node",
"version": "6.0.18",
"version": "6.0.20",
"private": true,
"description": "A New Yohobuy Project With Express",
"repository": {
... ...
... ... @@ -137,7 +137,6 @@ function syncCouponStatus() {
for (i = 0; i < info.length; i++) {
asyncObj[info[i].coupon_id] = info[i];
}
}
for (i in couponObj) {
if (couponObj.hasOwnProperty(i)) {
... ... @@ -152,6 +151,7 @@ function syncCouponStatus() {
}
}
}
}
});
}
... ...
... ... @@ -17,6 +17,60 @@
font-weight: bold;
}
}
.recommend-keywords {
margin-top: 30px;
margin-bottom: 20px;
border: 1px #e0e0e0 solid;
h3 {
height: 46px;
border-bottom: 1px #e0e0e0 solid;
line-height: 44px;
background: #f5f5f5;
text-align: center;
font-size: 15px;
}
p {
padding: 10px;
.keyword {
display: inline-block;
margin: 5px 15px;
font-size: 12px;
width: 150px;
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
}
.common {
display: inline-block;
margin: 5px 15px;
font-size: 12px;
width: 190px;
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
}
}
}
.page-footer-seo {
font-size: 13px;
margin: 30px 0;
b {
font-weight: bold;
line-height: 2;
}
.wap-page-href {
text-align: right;
font-weight: bold;
}
}
}
.min-screen .product-search-page {
... ...