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,104 +5,122 @@
*/
'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('', {
method: 'app.address.gethidden',
uid: uid
}, {code: 200});
/**
* 获取用户收货地址列表
* @param uid [number] uid
*/
getAddressListAsync(uid) {
let options = {
method: 'app.address.gethidden',
uid: uid
};
/**
* 省市区列表
* @param id [number] 省市区id
*/
const getAreaListAsync = (id) => {
return api.get('', {
method: 'app.address.provinces',
id: id || 0
});
};
return this.get({data: options, param: {
code: 200
}});
}
/**
* 地址删除
* @param uid [number] uid
* @param id [string] address id
*/
const delAddressAsync = (uid, id) => api.get('', {
method: 'app.address.del',
uid: uid,
id: id
});
/**
* 省市区列表
* @param id [number] 省市区id
*/
getAreaListAsync(id) {
let options = {
method: 'app.address.provinces',
id: id || 0
};
/**
* 新增地址api
* @param uid [Number]
* @param consignee [String] 收货人
* @param areaCode [Number] 区号
* @param address [String] 地址
* @param mobile [String] 手机号
* @param phone [String] 电话号码
* @param zipCode [String] 邮编
* @param email [String] 邮箱
*/
const addAddressAsync = (uid, consignee, areaCode, address, mobile, phone, zipCode, email) => api.get('', {
method: 'app.address.add',
uid: uid,
consignee: consignee,
area_code: areaCode,
address: address,
mobile: mobile,
phone: phone,
zip_code: zipCode,
email: email
});
return this.get({data: options});
}
/**
* 更新地址地址api
* @param uid [Number]
* @param id [Number] 地址id
* @param consignee [String] 收货人
* @param areaCode [Number] 区号
* @param address [String] 地址
* @param mobile [String] 手机号
* @param phone [String] 电话号码
* @param zipCode [String] 邮编
* @param email [String] 邮箱
*/
const updateAddressAsync = (uid, id, consignee, areaCode, address, mobile, phone, zipCode, email) => api.get('', {
method: 'app.address.update',
uid: uid,
id: id,
consignee: consignee,
area_code: areaCode,
address: address,
mobile: mobile,
phone: phone,
zip_code: zipCode,
email: email
});
/**
* 地址删除
* @param uid [number] uid
* @param id [string] address id
*/
delAddressAsync(uid, id) {
let options = {
method: 'app.address.del',
uid: uid,
id: id
};
/**
* 设置默认地址
* @param uid [Number]
* @param id [Number] 地址id
*/
const setDefaultAddressAsync = (uid, id) => api.get('', {
method: 'app.address.setdefault',
uid: uid,
id: id
});
return this.get({data: options});
}
/**
* 新增地址api
* @param uid [Number]
* @param consignee [String] 收货人
* @param areaCode [Number] 区号
* @param address [String] 地址
* @param mobile [String] 手机号
* @param phone [String] 电话号码
* @param zipCode [String] 邮编
* @param email [String] 邮箱
*/
addAddressAsync(uid, consignee, areaCode, address, mobile, phone, zipCode, email) {
let options = {
method: 'app.address.add',
uid: uid,
consignee: consignee,
area_code: areaCode,
address: address,
mobile: mobile,
phone: phone,
zip_code: zipCode,
email: email
};
return this.get({data: options});
}
/**
* 更新地址地址api
* @param uid [Number]
* @param id [Number] 地址id
* @param consignee [String] 收货人
* @param areaCode [Number] 区号
* @param address [String] 地址
* @param mobile [String] 手机号
* @param phone [String] 电话号码
* @param zipCode [String] 邮编
* @param email [String] 邮箱
*/
updateAddressAsync(uid, id, consignee, areaCode, address, mobile, phone, zipCode, email) {
let options = {
method: 'app.address.update',
uid: uid,
id: id,
consignee: consignee,
area_code: areaCode,
address: address,
mobile: mobile,
phone: phone,
zip_code: zipCode,
email: email
};
return this.get({data: options});
}
/**
* 设置默认地址
* @param uid [Number]
* @param id [Number] 地址id
*/
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,89 +10,88 @@ 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 => {
let list = _.get(result, 'data', []);
module.exports = class extends global.yoho.BaseModel {
constructor(ctx) {
super(ctx);
}
if (id * 1 === 0 && list.length) {
_.forEach(list, value => {
value.initial = pinyin[value.caption] || 'z';
value.pySort = _.indexOf(worldSort, value.initial);
});
result.data = list;
}
return result;
});
};
getAreaListData(id) {
return new AddressApi(this.ctx).getAreaListAsync(id).then(result => {
let list = _.get(result, 'data', []);
const getAddressListData = (uid) => {
return addressApi.getAddressListAsync(uid).then(result => {
if (result.code !== 200) {
if (id * 1 === 0 && list.length) {
_.forEach(list, value => {
value.initial = pinyin[value.caption] || 'z';
value.pySort = _.indexOf(worldSort, value.initial);
});
result.data = list;
}
return result;
}
let d = result.data;
});
}
_.forEach(d, dd => {
if (dd.is_default === 'Y') {
dd.default = true;
getAddressListData(uid) {
return new AddressApi(this.ctx).getAddressListAsync(uid).then(result => {
if (result.code !== 200) {
return result;
}
// 地址加密
let id = dd.address_id;
let d = result.data;
_.forEach(d, dd => {
if (dd.is_default === 'Y') {
dd.default = true;
}
// 地址加密
let id = dd.address_id;
dd.id = crypto.encryption('', `${id}`);
delete dd.address_id;
delete dd.uid; // 删除uid,用户数据保密
});
dd.id = crypto.encryption('', `${id}`);
delete dd.address_id;
delete dd.uid; // 删除uid,用户数据保密
return result;
});
}
return result;
});
};
delAddressById(uid, id) {
id = crypto.decrypt('', `${id}`);
return new AddressApi(this.ctx).delAddressAsync(uid, id);
}
const delAddressById = (uid, id) => {
id = crypto.decrypt('', `${id}`);
saveAddressData(uid, info) {
let addressApiModel = new AddressApi(this.ctx);
return addressApi.delAddressAsync(uid, id);
};
if (info.id) {
let id = crypto.decrypt('', `${info.id}`);
const saveAddressData = (uid, info) => {
if (info.id) {
let id = crypto.decrypt('', `${info.id}`);
return addressApi.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,
info.phone, info.zipCode, info.email).then(result => {
if (result.code === 200) {
let d = result.data;
d.id = crypto.encryption('', `${d.address_id}`);
delete d.address_id;
delete d.uid;
}
return addressApiModel.updateAddressAsync(uid, id, info.consignee, info.areaCode, info.address,
info.mobile, info.phone, info.zipCode, info.email);
} else {
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;
return result;
});
}
d.id = crypto.encryption('', `${d.address_id}`);
delete d.address_id;
delete d.uid;
}
};
return result;
});
}
const setDefaultAddress = (uid, id) => {
id = crypto.decrypt('', `${id}`);
}
return addressApi.setDefaultAddressAsync(uid, id);
};
setDefaultAddress(uid, id) {
id = crypto.decrypt('', `${id}`);
module.exports = {
getAreaListData,
getAddressListData,
delAddressById,
saveAddressData,
setDefaultAddress
return new AddressApi(this.ctx).setDefaultAddressAsync(uid, id);
}
};
... ...
... ... @@ -5,71 +5,158 @@
*/
'use strict';
const api = global.yoho.API;
const getEasyPaymentAsync = (uid, goods, activity) => {
let param = {
method: 'app.Shopping.easyPayment',
uid: uid,
cart_type: 'ordinary',
product_sku_list: goods,
yoho_coin_mode: 0,
is_support_apple_pay: 'N'
};
if (activity) {
param.activity_id = activity;
module.exports = class extends global.yoho.BaseModel {
constructor(ctx) {
super(ctx);
}
return api.get('', param, {code: 200});
};
getEasyPaymentAsync(uid, goods, activity) {
let param = {
method: 'app.Shopping.easyPayment',
uid: uid,
cart_type: 'ordinary',
product_sku_list: goods,
yoho_coin_mode: 0,
is_support_apple_pay: 'N'
};
if (activity) {
param.activity_id = activity;
}
return this.get({data: param});
}
/**
* 订单计算API
* @param uid [number] uid
* @param cartType [string] 购物车类型,ordinary表示普通, advance表示预售
* @param paymentType [number] 支付方式,1表示在线支付,2表示货到付款
* @param deliveryWay [number] 配送方式,1表示普通快递,2表示顺丰速运
* @param coin [number] 使用的有货币
* @param useRedEnvelops [number] 红包
* @param couponCode [string] 优惠券码
* @param promotionCode [string] 优惠码
* @param productSkuList [string] 限购商品
/**
* 订单计算API
* @param uid [number] uid
* @param cartType [string] 购物车类型,ordinary表示普通, advance表示预售
* @param paymentType [number] 支付方式,1表示在线支付,2表示货到付款
* @param deliveryWay [number] 配送方式,1表示普通快递,2表示顺丰速运
* @param coin [number] 使用的有货币
* @param useRedEnvelops [number] 红包
* @param couponCode [string] 优惠券码
* @param promotionCode [string] 优惠码
* @param productSkuList [string] 限购商品
*/
getEasypayComputeAsync(uid, cartType, paymentType, deliveryWay, other) {
let param = {
method: 'app.Shopping.easyCompute',
uid: uid,
cart_type: cartType || 'ordinary',
payment_type: paymentType,
delivery_way: deliveryWay
};
// 其他可选参数
if (other) {
if (other.coin) {
Object.assign(param, {
use_yoho_coin: other.coin / 100
});
}
*/
const getEasypayComputeAsync = (uid, cartType, paymentType, deliveryWay, other) => {
let param = {
method: 'app.Shopping.easyCompute',
uid: uid,
cart_type: cartType || 'ordinary',
payment_type: paymentType,
delivery_way: deliveryWay
};
// 其他可选参数
if (other) {
if (other.useRedEnvelops) {
Object.assign(param, {
use_red_envelopes: other.useRedEnvelops
});
}
if (other.couponCode) {
Object.assign(param, {
coupon_code: other.couponCode
});
}
if (other.promotionCode) {
Object.assign(param, {
promotion_code: other.promotionCode
});
}
if (other.productSkuList) {
Object.assign(param, {
product_sku_list: other.productSkuList
});
if (other.bundle) {
Object.assign(param, {
activity_id: other.bundle
});
}
}
}
return this.get({data: param});
}
/**
* 订单提交API
* @param uid [number] uid
* @param cartType [String] 购物车类型,ordinary表示普通, advance表示预售
* @param addressId [String] 地址
* @param deliveryTime [number] 寄送时间类型
* @param deliveryWay [number] 配送方式,1表示普通快递,2表示顺丰速运
* @param invoicesType [number] 发票类型
* @param invoicesTitle [string] 发票抬头
* @param invoicesContent [int] 发票类型
* @param receiverMobile [string] 发票收人电话
* @param coin [number] 使用的有货币金额
* @param redEnvelopes [number] 使用的红包
* @param paymentId [number] 支付id
* @param paymentType [number] 支付类型
* @param remark [string] 备注
* @param couponCode [string] 优惠券码
* @param printPrice [string] 是否打印价格
*/
easypayOrderSubmitAsync(uid, cartType, addressId, deliveryTime, deliveryWay, paymentType, paymentId, printPrice, other, remoteIp) { // eslint-disable-line
let param = {
method: 'app.Shopping.easySubmit',
uid: uid,
cart_type: cartType || 'ordinary',
address_id: addressId,
delivery_time: deliveryTime,
delivery_way: deliveryWay,
payment_type: paymentType,
payment_id: paymentId,
is_print_price: printPrice
};
// 发票
if (other.invoicesType) {
Object.assign(param, {
invoices_type: other.invoicesType,
invoices_title: other.invoicesTitle,
invoice_content: other.invoicesContent,
receiverMobile: other.receiver
});
}
// 有货币
if (other.coin) {
Object.assign(param, {
use_yoho_coin: other.coin / 100
use_yoho_coin: other.coin / 100 // 有货币稀释
});
}
if (other.useRedEnvelops) {
// 红包
if (other.redEnvelopes) {
Object.assign(param, {
use_red_envelopes: other.useRedEnvelops
use_red_envelopes: other.redEnvelopes
});
}
if (other.couponCode) {
// 备注
if (other.remark) {
Object.assign(param, {
coupon_code: other.couponCode
remark: other.remark
});
}
if (other.promotionCode) {
// 优惠券码
if (other.couponCode) {
Object.assign(param, {
promotion_code: other.promotionCode
coupon_code: other.couponCode
});
}
... ... @@ -85,106 +172,16 @@ const getEasypayComputeAsync = (uid, cartType, paymentType, deliveryWay, other)
}
}
}
return api.get('', param);
};
/**
* 订单提交API
* @param uid [number] uid
* @param cartType [String] 购物车类型,ordinary表示普通, advance表示预售
* @param addressId [String] 地址
* @param deliveryTime [number] 寄送时间类型
* @param deliveryWay [number] 配送方式,1表示普通快递,2表示顺丰速运
* @param invoicesType [number] 发票类型
* @param invoicesTitle [string] 发票抬头
* @param invoicesContent [int] 发票类型
* @param receiverMobile [string] 发票收人电话
* @param coin [number] 使用的有货币金额
* @param redEnvelopes [number] 使用的红包
* @param paymentId [number] 支付id
* @param paymentType [number] 支付类型
* @param remark [string] 备注
* @param couponCode [string] 优惠券码
* @param printPrice [string] 是否打印价格
*/
const easypayOrderSubmitAsync = (uid, cartType, addressId, deliveryTime, deliveryWay, paymentType, paymentId, printPrice, other, remoteIp) => { // eslint-disable-line
let param = {
method: 'app.Shopping.easySubmit',
uid: uid,
cart_type: cartType || 'ordinary',
address_id: addressId,
delivery_time: deliveryTime,
delivery_way: deliveryWay,
payment_type: paymentType,
payment_id: paymentId,
is_print_price: printPrice
};
// 发票
if (other.invoicesType) {
Object.assign(param, {
invoices_type: other.invoicesType,
invoices_title: other.invoicesTitle,
invoice_content: other.invoicesContent,
receiverMobile: other.receiver
});
}
// 有货币
if (other.coin) {
Object.assign(param, {
use_yoho_coin: other.coin / 100 // 有货币稀释
});
}
// 红包
if (other.redEnvelopes) {
Object.assign(param, {
use_red_envelopes: other.redEnvelopes
});
}
// 备注
if (other.remark) {
Object.assign(param, {
remark: other.remark
});
}
// 优惠券码
if (other.couponCode) {
Object.assign(param, {
coupon_code: other.couponCode
});
}
if (other.productSkuList) {
Object.assign(param, {
product_sku_list: other.productSkuList
});
if (other.bundle) {
if (other.udid) {
Object.assign(param, {
activity_id: other.bundle
udid: other.udid
});
}
}
if (other.udid) {
Object.assign(param, {
udid: other.udid
});
return this.get({data: param, param: {
headers: {
'X-Forwarded-For': remoteIp || ''
}
}});
}
return api.get('', param, {
headers: {'X-Forwarded-For': remoteIp || ''}
});
};
module.exports = {
getEasyPaymentAsync,
getEasypayComputeAsync,
easypayOrderSubmitAsync
};
... ...
... ... @@ -10,91 +10,101 @@ 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 ensureHandle = require('./order-ensure-handle');
const _getLimitProductData = (params) => {
let resList = [];
if (params.limitcode && params.sku && params.skn) {
resList.push({
type: 'limitcode',
buy_number: 1,
sku: params.sku,
skn: params.skn,
limitproductcode: params.limitcode
});
} else if (params.bundle && params.sku) {
resList = [];
const EasypayApi = require('./easypay-api');
const AddressApi = require('./address-api');
const EnsureApi = require('./order-ensure-api');
_.forEach(_.split(params.sku, ',', 10), val => {
resList.push({
type: 'bundle',
sku: parseInt(val, 10),
buy_number: 1
});
});
const EnsureHandle = require('./order-ensure-handle');
module.exports = class extends global.yoho.BaseModel {
constructor(ctx) {
super(ctx);
}
return resList.length ? JSON.stringify(resList) : false;
};
_getLimitProductData(params) {
let resList = [];
// 获取结算信息
const getEasypayOrderData = (params, uid) => {
let resData = {};
let strInfo = _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)
]).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), {
receiverMobile: receiver,
hideReceiverMobile: _.replace(receiver, /(\d{3})\d{4}(\d{4,9})/, '$1****$2')
if (params.limitcode && params.sku && params.skn) {
resList.push({
type: 'limitcode',
buy_number: 1,
sku: params.sku,
skn: params.skn,
limitproductcode: params.limitcode
});
} else if (params.bundle && params.sku) {
resList = [];
_.forEach(_.split(params.sku, ',', 10), val => {
resList.push({
type: 'bundle',
sku: parseInt(val, 10),
buy_number: 1
});
});
}
return resData;
});
};
// 价格计算
const getOrderComputeData = (uid, cartType, params) => {
params.productSkuList = _getLimitProductData(params);
return resList.length ? JSON.stringify(resList) : false;
}
return easypayApi.getEasypayComputeAsync(uid, cartType, params.paymentType, params.deliveryWay, params).then(result => { // eslint-disable-line
if (result.code === 200) {
if (_.has(result, 'data.last_order_amount')) {
result.data.last_order_amount = (result.data.last_order_amount).toFixed(2);
// 获取结算信息
getEasypayOrderData(params, uid) {
let resData = {};
let strInfo = this._getLimitProductData(params);
let bundle = params.bundle ? parseInt(params.bundle, 10) : false;
return Promise.all([
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, new EnsureHandle(this.ctx).handlePaymentInfo(data, address), {
receiverMobile: receiver,
hideReceiverMobile: _.replace(receiver, /(\d{3})\d{4}(\d{4,9})/, '$1****$2')
});
}
if (_.has(result, 'data.promotion_formula_list')) {
ensureHandle.handleViewPrice(result.data.promotion_formula_list);
}
return resData;
});
}
result.data = Object.assign(result.data, ensureHandle.handleUseYohoCoin(result.data));
}
return result;
});
};
// 价格计算
getOrderComputeData(uid, cartType, params) {
params.productSkuList = this._getLimitProductData(params);
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')) {
ensureHandleModel.handleViewPrice(result.data.promotion_formula_list);
}
result.data = Object.assign(result.data, ensureHandleModel.handleUseYohoCoin(result.data));
}
return result;
});
}
// 订单提交
const easypayOrderSubmit = (uid, cartType, params, remoteIp) => {
params.addressId = crypto.decrypt('', params.addressId);
params.productSkuList = _getLimitProductData(params);
// 订单提交
easypayOrderSubmit(uid, cartType, params, remoteIp) {
params.addressId = crypto.decrypt('', params.addressId);
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,85 +5,185 @@
*/
'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('', {
method: 'app.passport.profile',
uid: uid
});
/**
* 获取用户信息API
* @param uid [number] uid
*/
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('', {
method: 'app.Shopping.payment',
cart_type: cartType,
yoho_coin_mode: yohoCoinMode,
uid: uid
});
/**
* 购物车结算API
* @param uid [number] uid
* @param cartType [string] 购物车类型,ordinary表示普通, advance表示预售
* @param yohoCoinMode [number] 是否使用yoho币,1使用,0不使用
*/
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('', {
method: 'app.Shopping.listCoupon',
uid: uid,
is_group_frees: 'Y'
});
/**
* 获取用户优惠券信息API
* @param uid [number] uid
*/
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('', {
method: 'app.Shopping.useCoupon',
uid: uid,
coupon_code: code
});
/**
* 优惠码兑换优惠券API
* @param uid [number] uid
* @param code [number] code
*/
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表示预售
* @param paymentType [number] 支付方式,1表示在线支付,2表示货到付款
* @param deliveryWay [number] 配送方式,1表示普通快递,2表示顺丰速运
* @param coin [number] 使用的有货币
* @param useRedEnvelops [number] 红包
* @param couponCode [string] 优惠券码
* @param promotionCode [string] 优惠码
*/
const getOrderComputeAsync = (uid, cartType, paymentType, deliveryWay, other) => {
let param = {
method: 'app.Shopping.compute',
uid: uid,
cart_type: cartType,
payment_type: paymentType,
delivery_way: deliveryWay
};
// 其他可选参数
if (other) {
/**
* 订单计算API
* @param uid [number] uid
* @param cartType [string] 购物车类型,ordinary表示普通, advance表示预售
* @param paymentType [number] 支付方式,1表示在线支付,2表示货到付款
* @param deliveryWay [number] 配送方式,1表示普通快递,2表示顺丰速运
* @param coin [number] 使用的有货币
* @param useRedEnvelops [number] 红包
* @param couponCode [string] 优惠券码
* @param promotionCode [string] 优惠码
*/
getOrderComputeAsync(uid, cartType, paymentType, deliveryWay, other) {
let param = {
method: 'app.Shopping.compute',
uid: uid,
cart_type: cartType,
payment_type: paymentType,
delivery_way: deliveryWay
};
// 其他可选参数
if (other) {
if (other.coin) {
Object.assign(param, {
use_yoho_coin: other.coin
});
}
if (other.redEnvelopes) {
Object.assign(param, {
use_red_envelopes: other.redEnvelopes
});
}
if (other.couponCode) {
Object.assign(param, {
coupon_code: other.couponCode
});
} else if (other.promotionCode) {
Object.assign(param, {
promotion_code: other.promotionCode
});
}
}
return this.get({data: param});
}
/**
* 订单提交API
* @param uid [number] uid
* @param cartType [String] 购物车类型,ordinary表示普通, advance表示预售
* @param addressId [String] 地址
* @param deliveryTime [number] 寄送时间类型
* @param deliveryWay [number] 配送方式,1表示普通快递,2表示顺丰速运
* @param invoicesType [number] 发票类型
* @param invoicesTitle [string] 发票抬头
* @param invoicesContent [int] 发票类型
* @param receiverMobile [string] 发票收人电话
* @param coin [number] 使用的有货币金额
* @param redEnvelopes [number] 使用的红包
* @param paymentId [number] 支付id
* @param paymentType [number] 支付类型
* @param remark [string] 备注
* @param couponCode [string] 优惠券码
* @param printPrice [string] 是否打印价格
*/
orderSubmitAsync(uid, cartType, addressId, deliveryTime, deliveryWay, paymentType, paymentId, printPrice, other, remoteIp) { // eslint-disable-line
let param = {
method: 'app.Shopping.submit',
uid: uid,
cart_type: cartType,
address_id: addressId,
delivery_time: deliveryTime,
delivery_way: deliveryWay,
payment_type: paymentType,
payment_id: paymentId,
is_print_price: printPrice,
is_continue_buy: other.continueBuy ? 'Y' : 'N'
};
// 发票
if (other.invoicesType) {
Object.assign(param, {
invoices_type: other.invoicesType,
invoices_title: other.invoicesTitle,
invoice_content: other.invoicesContent,
receiverMobile: other.receiverMobile,
buyerTaxNumber: other.taxNumber,
invoice_payable_type: other.taxNumber ? 2 : 1
});
}
// 有货币
if (other.coin) {
Object.assign(param, {
use_yoho_coin: other.coin
use_yoho_coin: other.coin / 100 // 有货币稀释
});
}
// 红包
if (other.redEnvelopes) {
Object.assign(param, {
use_red_envelopes: other.redEnvelopes
});
}
// 备注
if (other.remark) {
Object.assign(param, {
remark: other.remark
});
}
// 优惠券码
if (other.couponCode) {
Object.assign(param, {
coupon_code: other.couponCode
... ... @@ -93,120 +193,32 @@ const getOrderComputeAsync = (uid, cartType, paymentType, deliveryWay, other) =>
promotion_code: other.promotionCode
});
}
}
return api.get('', param);
};
/**
* 订单提交API
* @param uid [number] uid
* @param cartType [String] 购物车类型,ordinary表示普通, advance表示预售
* @param addressId [String] 地址
* @param deliveryTime [number] 寄送时间类型
* @param deliveryWay [number] 配送方式,1表示普通快递,2表示顺丰速运
* @param invoicesType [number] 发票类型
* @param invoicesTitle [string] 发票抬头
* @param invoicesContent [int] 发票类型
* @param receiverMobile [string] 发票收人电话
* @param coin [number] 使用的有货币金额
* @param redEnvelopes [number] 使用的红包
* @param paymentId [number] 支付id
* @param paymentType [number] 支付类型
* @param remark [string] 备注
* @param couponCode [string] 优惠券码
* @param printPrice [string] 是否打印价格
*/
const orderSubmitAsync = (uid, cartType, addressId, deliveryTime, deliveryWay, paymentType, paymentId, printPrice, other, remoteIp) => { // eslint-disable-line
let param = {
method: 'app.Shopping.submit',
uid: uid,
cart_type: cartType,
address_id: addressId,
delivery_time: deliveryTime,
delivery_way: deliveryWay,
payment_type: paymentType,
payment_id: paymentId,
is_print_price: printPrice,
is_continue_buy: other.continueBuy ? 'Y' : 'N'
};
// 发票
if (other.invoicesType) {
Object.assign(param, {
invoices_type: other.invoicesType,
invoices_title: other.invoicesTitle,
invoice_content: other.invoicesContent,
receiverMobile: other.receiverMobile,
buyerTaxNumber: other.taxNumber,
invoice_payable_type: other.taxNumber ? 2 : 1
});
}
// 有货币
if (other.coin) {
Object.assign(param, {
use_yoho_coin: other.coin / 100 // 有货币稀释
});
}
// 红包
if (other.redEnvelopes) {
Object.assign(param, {
use_red_envelopes: other.redEnvelopes
});
}
// 备注
if (other.remark) {
Object.assign(param, {
remark: other.remark
});
}
// 优惠券码
if (other.couponCode) {
Object.assign(param, {
coupon_code: other.couponCode
});
} else if (other.promotionCode) {
Object.assign(param, {
promotion_code: other.promotionCode
});
}
if (other.continueBuy) {
Object.assign(param, {
is_continue_buy: 'Y'
});
}
if (other.continueBuy) {
Object.assign(param, {
is_continue_buy: 'Y'
});
}
if (other.udid) {
Object.assign(param, {
udid: other.udid
});
}
if (other.udid) {
Object.assign(param, {
udid: other.udid
});
}
// 友盟有关信息的传递
if (other.qhyUnion) {
Object.assign(param, {
qhy_union: other.qhyUnion
});
}
// 友盟有关信息的传递
if (other.qhyUnion) {
Object.assign(param, {
qhy_union: other.qhyUnion
});
return this.get({data: param, param: {
headers: {
'X-Forwarded-For': remoteIp || '',
'User-Agent': other.userAgent || ''
}
}});
}
return api.get('', param, {
headers: {
'X-Forwarded-For': remoteIp || '',
'User-Agent': other.userAgent || ''
}
});
};
module.exports = {
getUserProfileAsync,
getOrderPaymentAsync,
getUesrCouponAsync,
getCouponByCodeAsync,
getOrderComputeAsync,
orderSubmitAsync
};
... ...
... ... @@ -6,121 +6,119 @@
'use strict';
const _ = require('lodash');
const helper = global.yoho.helpers;
const crypto = global.yoho.crypto;
const handleViewPrice = list => {
if (list) {
_.forEach(list, val => {
if (val.promotion === '商品金额') {
val.promotion = '商品总价';
val.promotion_amount = `+ ${val.promotion_amount}`;
} else {
val.promotion_amount = _.replace(val.promotion_amount, '+', '+ ');
val.promotion_amount = _.replace(val.promotion_amount, '-', '- ');
}
});
module.exports = class extends global.yoho.BaseModel {
constructor(ctx) {
super(ctx);
}
};
const handleUseYohoCoin = (info) => {
let resData = {};
let limitCoin = _.get(info, 'yoho_coin_pay_rule.num_limit', 0);
if (info) {
Object.assign(resData, {
yoho_coin: info.yoho_coin.toFixed(2),
use_yoho_coin: info.use_yoho_coin,
total_yoho_coin_num: info.total_yoho_coin_num,
yoho_coin_pay_rule: info.yoho_coin_pay_rule,
canUseCoinNum: _.round(info.yoho_coin * 100),
usedCoinNum: _.round(info.use_yoho_coin * 100)
});
if (!resData.canUseCoinNum) {
let coinErrorTip = '';
handleViewPrice(list) {
if (list) {
_.forEach(list, val => {
if (val.promotion === '商品金额') {
val.promotion = '商品总价';
val.promotion_amount = `+ ${val.promotion_amount}`;
} else {
val.promotion_amount = _.replace(val.promotion_amount, '+', '+ ');
val.promotion_amount = _.replace(val.promotion_amount, '-', '- ');
}
});
}
}
if (info.total_yoho_coin_num > limitCoin) {
coinErrorTip = '抱歉,您的订单实付款不满足有货币使用条件';
} else {
coinErrorTip = `抱歉,您的有货币不足,有货币满${limitCoin}个方可使用`;
handleUseYohoCoin(info) {
let resData = {};
let limitCoin = _.get(info, 'yoho_coin_pay_rule.num_limit', 0);
if (info) {
Object.assign(resData, {
yoho_coin: info.yoho_coin.toFixed(2),
use_yoho_coin: info.use_yoho_coin,
total_yoho_coin_num: info.total_yoho_coin_num,
yoho_coin_pay_rule: info.yoho_coin_pay_rule,
canUseCoinNum: _.round(info.yoho_coin * 100),
usedCoinNum: _.round(info.use_yoho_coin * 100)
});
if (!resData.canUseCoinNum) {
let coinErrorTip = '';
if (info.total_yoho_coin_num > limitCoin) {
coinErrorTip = '抱歉,您的订单实付款不满足有货币使用条件';
} else {
coinErrorTip = `抱歉,您的有货币不足,有货币满${limitCoin}个方可使用`;
}
resData.coinErrorTip = coinErrorTip;
}
resData.coinErrorTip = coinErrorTip;
}
return resData;
}
return resData;
};
handlePaymentInfo(d, address) {
let resData = {};
let defAddrId = _.get(d, 'delivery_address.address_id', 0);
const handlePaymentInfo = (d, address) => {
let resData = {};
let defAddrId = _.get(d, 'delivery_address.address_id', 0);
_.forEach(address, dd => {
if (dd.is_default === 'Y') {
dd.default = true;
}
_.forEach(address, dd => {
if (dd.is_default === 'Y') {
dd.default = true;
}
// 地址加密
let id = dd.address_id;
// 地址加密
let id = dd.address_id;
dd.id = crypto.encryption('', `${id}`);
dd.id = crypto.encryption('', `${id}`);
// 设置默认选中地址
if (id === defAddrId) {
dd.selected = true;
}
// 设置默认选中地址
if (id === defAddrId) {
dd.selected = true;
}
// 删除uid,用户数据保密
_.unset(dd, 'address_id');
_.unset(dd, 'uid');
});
// 删除uid,用户数据保密
_.unset(dd, 'address_id');
_.unset(dd, 'uid');
});
resData.deliveryAddress = address;
resData.deliveryAddress = address;
d.shopping_cart_data.hasCoin = _.round(d.yoho_coin * 100); // 有货币稀释
d.shopping_cart_data.hasCoin = _.round(d.yoho_coin * 100); // 有货币稀释
_.forEach(d.goods_list, g => {
g.last_vip_price = g.last_vip_price && Number(g.last_vip_price).toFixed(2) || '';
g.sales_price = g.sales_price && Number(g.sales_price).toFixed(2) || '';
_.forEach(d.goods_list, g => {
g.last_vip_price = g.last_vip_price && Number(g.last_vip_price).toFixed(2) || '';
g.sales_price = g.sales_price && Number(g.sales_price).toFixed(2) || '';
// link to goods
g.linkToGoods = helper.urlFormat(`/product/pro_${g.product_id}_${g.goods_id}/${g.cn_alphabet}.html`,
'', 'item');
g.productPrice = g.sales_price;
g.isVipPrice = g.discount_tag === 'V';
g.isStuPrice = g.discount_tag === 'S';
// link to goods
g.linkToGoods = helper.urlFormat(`/product/pro_${g.product_id}_${g.goods_id}/${g.cn_alphabet}.html`,
'', 'item');
g.productPrice = g.sales_price;
g.isVipPrice = g.discount_tag === 'V';
g.isStuPrice = g.discount_tag === 'S';
// 赠品、加价购
if (g.goods_type === 'gift' || g.goods_type === 'price_gift') {
g.productPrice = g.last_price;
}
});
resData.goodsList = d.goods_list;
// 赠品、加价购
if (g.goods_type === 'gift' || g.goods_type === 'price_gift') {
g.productPrice = g.last_price;
if (d.shopping_cart_data && d.shopping_cart_data.promotion_formula_list) {
this.handleViewPrice(d.shopping_cart_data.promotion_formula_list);
}
});
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);
}
Object.assign(resData, {
paymentWay: d.payment_way,
deliveryTime: d.delivery_time,
deliveryWay: d.delivery_way,
shoppingCartData: Object.assign(d.shopping_cart_data, handleUseYohoCoin(d), {
redEnvelopes: d.red_envelopes,
useRedEnvelopes: d.use_red_envelopes
}),
invoices: d.invoices
});
return resData;
};
Object.assign(resData, {
paymentWay: d.payment_way,
deliveryTime: d.delivery_time,
deliveryWay: d.delivery_way,
shoppingCartData: Object.assign(d.shopping_cart_data, this.handleUseYohoCoin(d), {
redEnvelopes: d.red_envelopes,
useRedEnvelopes: d.use_red_envelopes
}),
invoices: d.invoices
});
module.exports = {
handleViewPrice,
handleUseYohoCoin,
handlePaymentInfo
return resData;
}
};
... ...
... ... @@ -6,109 +6,110 @@
'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');
const index = (uid, cartType) => {
let resData = {};
module.exports = class extends global.yoho.BaseModel {
constructor(ctx) {
super(ctx);
}
return Promise.all([
ensureApi.getOrderPaymentAsync(uid, cartType, 0),
addressApi.getAddressListAsync(uid),
ensureApi.getUserProfileAsync(uid)
]).then(result => {
let data = _.get(result, '[0].data', false);
let address = _.get(result, '[1].data', []);
let receiver = _.get(result, '[2].data.mobile', '');
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([
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, ensureHandleModel.handlePaymentInfo(data, address), {
receiverMobile: receiver,
hideReceiverMobile: _.replace(receiver, /(\d{3})\d{4}(\d{4,9})/, '$1****$2')
});
}
if (data) {
Object.assign(resData, ensureHandle.handlePaymentInfo(data, address), {
receiverMobile: receiver,
hideReceiverMobile: _.replace(receiver, /(\d{3})\d{4}(\d{4,9})/, '$1****$2')
});
}
return resData;
});
}
return resData;
});
};
// 获取优惠券列表
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 getCoupons = (uid) => ensureApi.getUesrCouponAsync(uid).then(result => {
if (_.isEmpty(_.get(result, 'data.usable_coupons', [])) &&
_.isEmpty(_.get(result, 'data.usable_frees_coupons', []))) {
_.set(result, 'data.emptyUsable', true);
// 兑换优惠券
convertCoupons(uid, code) {
return new EnsureApi(this.ctx).getCouponByCodeAsync(uid, code);
}
return 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);
// 兑换优惠券
const convertCoupons = (uid, code) => ensureApi.getCouponByCodeAsync(uid, code);
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')) {
ensureHandleModel.handleViewPrice(result.data.promotion_formula_list);
}
// 订单计算
const compute = (uid, cartType, pa) => {
return ensureApi.getOrderComputeAsync(uid, cartType, pa.paymentType, pa.deliveryWay, pa).then(result => {
if (result.code === 200) {
if (_.has(result, 'data.last_order_amount')) {
result.data.last_order_amount = (result.data.last_order_amount).toFixed(2);
result.data = Object.assign(result.data, ensureHandleModel.handleUseYohoCoin(result.data));
}
if (_.has(result, 'data.promotion_formula_list')) {
ensureHandle.handleViewPrice(result.data.promotion_formula_list);
}
return result;
});
}
result.data = Object.assign(result.data, ensureHandle.handleUseYohoCoin(result.data));
// 订单提交
submit(uid, cartType, p, remoteIp) {
if (p.addressId) {
p.addressId = crypto.decrypt('', `${p.addressId}`);
}
return result;
});
};
// 订单提交
const submit = (uid, cartType, p, remoteIp) => {
if (p.addressId) {
p.addressId = crypto.decrypt('', `${p.addressId}`);
}
// 5.8.1 发票优化需求
// 只接受电子发票(1 纸质 2 电子),发票内容为明细(id 12:明细)
if (p.invoicesType) {
Object.assign(p, {
invoicesType: 2,
invoicesContent: 12
});
}
// 5.8.1 发票优化需求
// 只接受电子发票(1 纸质 2 电子),发票内容为明细(id 12:明细)
if (p.invoicesType) {
Object.assign(p, {
invoicesType: 2,
invoicesContent: 12
});
}
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;
return ensureApi.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;
d.url = helper.urlFormat('/shopping/newpay', {
ordercode: d.order_code
});
}
d.url = helper.urlFormat('/shopping/newpay', {
ordercode: d.order_code
});
return result;
}
return result;
}
);
};
module.exports = {
index,
getCoupons,
convertCoupons,
compute,
submit
);
}
};
... ...
... ... @@ -2,55 +2,54 @@
* Created by TaoHuang on 2017/6/22.
*/
const api = global.yoho.API;
/**
* 电子票下单
* @param uid 用户id
* @param sku 商品sku
* @param count 购买数量 1-4
* @param mobile 手机号码
* @param yohoCoin 有货币
*/
function submit(uid, sku, count, mobile, yohoCoin) {
let params = {
method: 'app.shopping.submitTicket',
uid,
product_sku: sku,
buy_number: count,
mobile: mobile
};
if (yohoCoin) {
params.use_yoho_coin = yohoCoin / 100;
module.exports = class extends global.yoho.BaseModel {
constructor(ctx) {
super(ctx);
}
return api.get('', params);
}
/**
* 电子票添加和查询
* @param uid 用户 id
* @param sku 商品sku
* @param count 购买数量 1-4
* @param yohoCoin 有货币
*/
function add(uid, sku, count, yohoCoin) {
let params = {
method: 'app.shopping.ticket',
uid,
product_sku: sku,
buy_number: count
};
if (yohoCoin) {
params.use_yoho_coin = yohoCoin / 100;
/**
* 电子票下单
* @param uid 用户id
* @param sku 商品sku
* @param count 购买数量 1-4
* @param mobile 手机号码
* @param yohoCoin 有货币
*/
submit(uid, sku, count, mobile, yohoCoin) {
let params = {
method: 'app.shopping.submitTicket',
uid,
product_sku: sku,
buy_number: count,
mobile: mobile
};
if (yohoCoin) {
params.use_yoho_coin = yohoCoin / 100;
}
return this.get({data: params});
}
return api.get('', params);
}
module.exports = {
submit,
add
/**
* 电子票添加和查询
* @param uid 用户 id
* @param sku 商品sku
* @param count 购买数量 1-4
* @param yohoCoin 有货币
*/
add(uid, sku, count, yohoCoin) {
let params = {
method: 'app.shopping.ticket',
uid,
product_sku: sku,
buy_number: count
};
if (yohoCoin) {
params.use_yoho_coin = yohoCoin / 100;
}
return this.get({data: params});
}
};
... ...
... ... @@ -2,80 +2,83 @@
* 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) {
return list.map((i) => {
i.linkToGoods = helpers.getUrlBySkc(i.product_skn);
i.productPrice = i.sales_price;
return i;
});
}
function _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);
let result = {};
module.exports = class extends global.yoho.BaseModel {
constructor(ctx) {
super(ctx);
}
if (_.isEmpty(ticketInfo)) {
return {
last_order_amount: 0,
error: '人太多啦,稍后再试!'
};
_handleGoodsList(list) {
return list.map((i) => {
i.linkToGoods = helpers.getUrlBySkc(i.product_skn);
i.productPrice = i.sales_price;
return i;
});
}
if (ticketInfo.code !== 200) {
return {
last_order_amount: 0,
error: ticketInfo.message
};
_handleAmount(info) {
return _.get(info, 'data.shopping_cart_data.last_order_amount', 0);
}
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', {})));
addTicket(uid, sku, count, yohoCoin) {
return new TicketApi(this.ctx).add(uid, sku, count, yohoCoin).then(ticketInfo => {
let result = {};
return result;
});
if (_.isEmpty(ticketInfo)) {
return {
last_order_amount: 0,
error: '人太多啦,稍后再试!'
};
}
const submitTicket = co(function * (uid, sku, count, mobile, yohoCoin) {
let result = yield api.submit(uid, sku, count, mobile, yohoCoin);
if (ticketInfo.code !== 200) {
return {
last_order_amount: 0,
error: ticketInfo.message
};
}
if (_.isEmpty(result)) {
return {
code: 500,
message: '人太多啦,稍后再试!'
};
}
result.virtualGood = true;
result.goodsList = this._handleGoodsList(_.get(ticketInfo, 'data.goods_list', []));
result.last_order_amount = this._handleAmount(ticketInfo);
if (result.code !== 200) {
return {
code: result.code,
message: result.message
};
Object.assign(result, new OrderEnsureHandle(this.ctx).handleUseYohoCoin(
_.get(ticketInfo, 'data.shopping_cart_data', {}
)));
return result;
});
}
return {
code: 200,
message: '提交成功',
data: {
refer: helpers.urlFormat('/shopping/newpay', {
ordercode: result.data.order_code
})
}
};
});
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,
message: '人太多啦,稍后再试!'
};
}
if (result.code !== 200) {
return {
code: result.code,
message: result.message
};
}
module.exports = {
addTicket,
submitTicket
return {
code: 200,
message: '提交成功',
data: {
refer: helpers.urlFormat('/shopping/newpay', {
ordercode: result.data.order_code
})
}
};
});
}
};
... ...
... ... @@ -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,19 +6,26 @@
'use strict';
const logger = global.yoho.logger;
var api = global.yoho.API;
exports.getQRcodeData = (id, uid) => {
return api.get('', {
method: 'app.SpaceOrders.getQrByOrderCode',
order_code: id,
uid: uid
}).then(result => {
if (result && result.code === 200) {
return result.data;
} else {
logger.error(`查看二维码ID: ${id} 接口返回数据错误`);
return false;
}
});
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
};
return this.get({data: options}).then(result => {
if (result && result.code === 200) {
return result.data;
} else {
logger.error(`查看二维码ID: ${id} 接口返回数据错误`);
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>
<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,14 +105,14 @@
{{> 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>
</textarea>
<textarea class="lazy-load-object-2" style="visibility: hidden;">
<script>getSearchRecommend();</script>
</textarea>
</div>
<div class="bottom-tab-line">
... ... @@ -125,13 +122,17 @@
<div class="goods-slide">
<div data-role="recommend-slide" class="slide-panel recommend-slider"></div>
</div>
{{/if_cond}}
{{/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}}
<div class="recommend-keywords">
<h3>相关推荐</h3>
<p>
{{# goodsInfo.recommendKeywords}}
<a href="{{url}}" title="{{keyword}}" target="_blank" class="keyword">{{keyword}}</a>
{{/ goodsInfo.recommendKeywords}}
</p>
</div>
{{/if}}
{{# goodsInfo}}
{{#if recommendKeywords}}
<div class="recommend-keywords">
<h3>{{#if recommendKeywordsTitle}}{{recommendKeywordsTitle}}{{^}}相关推荐{{/if}}</h3>
<p>
{{# recommendKeywords}}
<a href="{{url}}" title="{{keyword}}" target="_blank" class="keyword">{{keyword}}</a>
{{/ recommendKeywords}}
</p>
</div>
{{/if}}
{{#if goodsInfo.recommendNewProducts}}
<div class="recommend-keywords">
<h3>新品推荐</h3>
<p>
{{# goodsInfo.recommendNewProducts}}
<a href="{{url}}" title="{{name}}" target="_blank" class="common">{{name}}</a>
{{/ goodsInfo.recommendNewProducts}}
</p>
</div>
{{/if}}
{{#if recommendNewProducts}}
<div class="recommend-keywords">
<h3>新品推荐</h3>
<p>
{{# recommendNewProducts}}
<a href="{{url}}" title="{{name}}" target="_blank" class="common">{{name}}</a>
{{/ recommendNewProducts}}
</p>
</div>
{{/if}}
{{#if goodsInfo.recommendArticles}}
<div class="recommend-keywords">
<h3>文章推荐</h3>
<p>
{{# goodsInfo.recommendArticles}}
<a href="{{url}}" title="{{name}}" target="_blank" class="common">{{name}}</a>
{{/ goodsInfo.recommendArticles}}
</p>
</div>
{{/if}}
{{#if recommendArticles}}
<div class="recommend-keywords">
<h3>文章推荐</h3>
<p>
{{# recommendArticles}}
<a href="{{url}}" title="{{name}}" target="_blank" class="common">{{name}}</a>
{{/ recommendArticles}}
</p>
</div>
{{/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,18 +137,18 @@ function syncCouponStatus() {
for (i = 0; i < info.length; i++) {
asyncObj[info[i].coupon_id] = info[i];
}
}
for (i in couponObj) {
if (couponObj.hasOwnProperty(i)) {
coup = asyncObj[i];
if (coup && (coup.status === 1 || coup.status === 3)) {
couponObj[i].status = coup.status;
coup.status === 3 ? setPicked(couponObj[i]) : false;
} else {
couponObj[i].status = 2; // 券不存在设置领取状态为已抢光
couponObj[i].dom.text('已抢光');
for (i in couponObj) {
if (couponObj.hasOwnProperty(i)) {
coup = asyncObj[i];
if (coup && (coup.status === 1 || coup.status === 3)) {
couponObj[i].status = coup.status;
coup.status === 3 ? setPicked(couponObj[i]) : false;
} else {
couponObj[i].status = 2; // 券不存在设置领取状态为已抢光
couponObj[i].dom.text('已抢光');
}
}
}
}
... ...
... ... @@ -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 {
... ...