Authored by 郭成尧

ctx-another

... ... @@ -276,7 +276,7 @@ class BuyNowController {
let userData = yield req.ctx(userModel).queryProfile(uid);
let mobile = _.get(userData, 'data.mobile', '');
let addresslist = yield req.ctx(userModel).addressTextData(uid);
let returnData = orderModel.processInvoiceData(orderInfo, mobile, addresslist);
let returnData = req.ctx(orderModel).processInvoiceData(orderInfo, mobile, addresslist);
let headerData = headerModel.setNav({
invoiceNotice: '发票须知',
navTitle: '发票信息',
... ...
... ... @@ -82,7 +82,7 @@ exports.orderEnsure = (req, res, next) => {
];
if (_.isUndefined(req.cookies._isNewUser)) {
allPromise.push(orderModel.isNewUser(uid));
allPromise.push(req.ctx(orderModel).isNewUser(uid));
}
return Promise.all(allPromise).then(result => {
... ... @@ -427,7 +427,7 @@ exports.invoiceInfo = (req, res, next) => {
let userData = yield req.ctx(userModel).queryProfile(uid);
let mobile = _.get(userData, 'data.mobile', '');
let addresslist = yield req.ctx(userModel).addressTextData(uid);
let returnData = orderModel.processInvoiceData(orderInfo, mobile, addresslist);
let returnData = req.ctx(orderModel).processInvoiceData(orderInfo, mobile, addresslist);
let headerData = headerModel.setNav({
invoiceNotice: '发票须知',
navTitle: '发票信息',
... ...
'use strict';
// doc: http://git.yoho.cn/yoho-documents/api-interfaces/blob/master/个人中心/地址管理.md';
const api = global.yoho.API;
const crypto = global.yoho.crypto;
class AddressModel extends global.yoho.BaseModel {
... ... @@ -16,32 +14,26 @@ class AddressModel extends global.yoho.BaseModel {
* @return
*/
addressData(uid) {
let params = {
method: 'app.address.gethidden',
uid
};
let options = {
cache: false
};
return api.get('', params, options)
.then(
result => {
if (result.code === 200) {
// 加密address_id
result.data.forEach(address => {
address.address_id = encodeURIComponent(crypto.encryption(null, address.address_id));
});
}
return result;
}
,
() => {
return {code: 500, data: [], message: '地址获取失败'};
}
);
return this.get({
data: {
method: 'app.address.gethidden',
uid
},
param: {
cache: false
}
}).then(result => {
if (result.code === 200) {
// 加密address_id
result.data.forEach(address => {
address.address_id = encodeURIComponent(crypto.encryption(null, address.address_id));
});
}
return result;
}, () => {
return {code: 500, data: [], message: '地址获取失败'};
});
}
}
... ...
'use strict';
const api = global.yoho.API;
const _ = require('lodash');
const crypto = global.yoho.crypto;
const processInvoiceData = (orderInfo, mobile, addresslist) => {
let invoices_title = false;
let invoices_title_personal = false;
let invoices_type = '2';
let addressId = orderInfo.addressId &&
parseInt(crypto.encryption('', orderInfo.addressId), 10) || 0;
// 用户手机号处理
if (orderInfo.receiverMobile && orderInfo.isModifyTel) {
mobile = orderInfo.receiverMobile;
} else {
_.forEach(addresslist, addressValue => {
if (addressValue.address_id === addressId) {
mobile = addressValue.mobile;
return false;
}
});
class orderModel extends global.yoho.BaseModel {
constructor(ctx) {
super(ctx);
}
// 发票信息处理
if (orderInfo.invoices_type && orderInfo.invoices_title) {
invoices_title = orderInfo.invoices_title;
invoices_type = orderInfo.invoices_type * 1;
}
processInvoiceData(orderInfo, mobile, addresslist) {
let invoices_title = false;
let invoices_title_personal = false;
let invoices_type = '2';
let addressId = orderInfo.addressId &&
parseInt(crypto.encryption('', orderInfo.addressId), 10) || 0;
invoices_title_personal = orderInfo.invoices_title_personal || '个人(可修改)';
// 用户手机号处理
if (orderInfo.receiverMobile && orderInfo.isModifyTel) {
mobile = orderInfo.receiverMobile;
} else {
_.forEach(addresslist, addressValue => {
if (addressValue.address_id === addressId) {
mobile = addressValue.mobile;
return false;
}
});
}
let isCompany = invoices_title && invoices_title !== '个人';
// 发票信息处理
if (orderInfo.invoices_type && orderInfo.invoices_title) {
invoices_title = orderInfo.invoices_title;
invoices_type = orderInfo.invoices_type * 1;
}
return {
phone: mobile ? mobile : '',
completeTel: mobile,
isCompany: isCompany,
companyName: isCompany ? invoices_title : invoices_title_personal,
buyerTaxNumber: orderInfo.buyerTaxNumber,
isPaper: invoices_type === 1,
invoicesType: [
{
id: '2',
type: '电子发票'
}
],
invoiceTitle: [
{
type: '个人',
choosed: !isCompany
},
{
type: '单位',
choosed: isCompany
}
]
};
invoices_title_personal = orderInfo.invoices_title_personal || '个人(可修改)';
};
let isCompany = invoices_title && invoices_title !== '个人';
/**
* 判断用户是否是老用户
*/
const isNewUser = (uid) => {
return api.get('', {
method: 'app.SpaceOrders.get',
type: '5',
page: '1',
limit: '1',
uid: uid
}, {code: 200}).then(result => {
let order = _.get(result, 'data.order_list', []);
return {
phone: mobile ? mobile : '',
completeTel: mobile,
isCompany: isCompany,
companyName: isCompany ? invoices_title : invoices_title_personal,
buyerTaxNumber: orderInfo.buyerTaxNumber,
isPaper: invoices_type === 1,
invoicesType: [
{
id: '2',
type: '电子发票'
}
],
invoiceTitle: [
{
type: '个人',
choosed: !isCompany
},
{
type: '单位',
choosed: isCompany
}
]
};
if (order.length > 0) {
return false;
} else {
return true;
}
});
};
}
/**
* 判断用户是否是老用户
*/
isNewUser(uid) {
return this.get({
data: {
method: 'app.SpaceOrders.get',
type: '5',
page: '1',
limit: '1',
uid: uid
},
param: {code: 200}
}).then(result => {
let order = _.get(result, 'data.order_list', []);
module.exports = {
processInvoiceData,
isNewUser
};
if (order.length > 0) {
return false;
} else {
return true;
}
});
}
}
module.exports = orderModel;
... ...
... ... @@ -6,8 +6,6 @@
'use strict';
const api = global.yoho.API;
class payApiModel extends global.yoho.BaseModel {
constructor(ctx) {
super(ctx);
... ... @@ -15,64 +13,67 @@ class payApiModel extends global.yoho.BaseModel {
// 获取支付宝等平台支付方式列表
getPayProvider() {
return api.get('', {
method: 'web.SpaceOrders.getPaymentList'
}, {cache: true});
return this.get({
data: {
method: 'web.SpaceOrders.getPaymentList'
},
param: {cache: true}
});
}
// 获取单个支付方式相关详细信息
getPaymentInfo(id) {
return api.get('', {
return this.get({data: {
method: 'web.SpaceOrders.getPaymentById',
id: id
}, {cache: true});
}, param: {cache: true}});
}
/* 获取上次使用的支付方式*/
getBankByOrder(code) {
return api.get('', {
return this.get({data: {
method: 'web.SpaceOrders.getOrderPayBank',
orderCode: code
});
}});
}
/* 记录支付方式*/
setOrderPayBank(code, payment, bankCode) {
return api.get('', {
return this.get({data: {
method: 'web.SpaceOrders.addOrderPayBank',
orderCode: code,
payment: payment,
bankCode: bankCode
});
}});
}
/* 更改支付方式*/
updateOrderPayBank(code, payment, bankCode) {
return api.get('', {
return this.get({data: {
method: 'web.SpaceOrders.modifyOrderPayBank',
orderCode: code,
payment: payment,
bankCode: bankCode
});
}});
}
/* 发送支付确认*/
sendPayConfirm(code, payment, uid) {
return api.get('', {
return this.get({data: {
method: 'app.SpaceOrders.payConfirm',
order_code: code,
payment_id: payment,
uid: uid
});
}});
}
sendMessage(mobile, template, codes) {
return api.get('', {
return this.get({data: {
method: 'app.message.sendMsg',
mobile: mobile,
template: template,
codes: codes
});
}});
}
}
... ...
'use strict';
const _ = require('lodash');
const api = global.yoho.API;
class shoppingModel extends global.yoho.BaseModel {
constructor(ctx) {
... ... @@ -35,7 +34,7 @@ class shoppingModel extends global.yoho.BaseModel {
param.product_sku_list = JSON.stringify(params.activityInfo.product_sku_list);
}
return api.get('', param, {cache: false});
return this.get({data: param, param: {cache: false}});
}
/**
... ... @@ -69,7 +68,7 @@ class shoppingModel extends global.yoho.BaseModel {
finalParams.product_sku_list = JSON.stringify(params.activityInfo.product_sku_list);
}
return api.get('', finalParams, {code: 200});
return this.get({data: finalParams, param: {code: 200}});
}
/**
... ... @@ -105,7 +104,7 @@ class shoppingModel extends global.yoho.BaseModel {
});
}
return api.get('', params, {code: 200});
return this.get({data: params, param: {code: 200}});
}
/**
... ... @@ -192,12 +191,12 @@ class shoppingModel extends global.yoho.BaseModel {
finalParams.client_type = 'wechat';
}
return api.post('', finalParams, {
return this.post({data: finalParams, param: {
headers: {
'X-Forwarded-For': params.ip || '',
'User-Agent': params.userAgent
}
});
}});
}
... ... @@ -213,7 +212,7 @@ class shoppingModel extends global.yoho.BaseModel {
uid
};
return api.get('', param);
return this.get({data: param});
}
... ... @@ -231,7 +230,7 @@ class shoppingModel extends global.yoho.BaseModel {
is_group_frees: params.is_group_frees
};
return api.get('', param);
return this.get({data: param});
}
/**
... ... @@ -247,7 +246,7 @@ class shoppingModel extends global.yoho.BaseModel {
uid
};
return api.get('', param);
return this.get({data: param});
}
}
... ...