Authored by 毕凯

Merge branch 'feature/context-api' into 'release/6.6'

Feature/context api

以下接口上下文调用修改
/operations/api/v5/webshare/getShare
app.coupons.couponsSend
app.search.newPromotion
app.query.bundleSkn

See merge request !1366
... ... @@ -22,7 +22,7 @@ const _getPname = (req) => {
};
exports.index = function(req, res, next) {
model.index({
req.ctx(model).index({
code: req.params.code,
type: stringProcess.paramsFilter(req.query.type),
from_page_name: _getPname(req),
... ... @@ -53,7 +53,7 @@ exports.index = function(req, res, next) {
};
exports.sidebar = function(req, res, next) {
model.index({
req.ctx(model).index({
code: req.params.code
}).then((result) => {
if (!result) {
... ... @@ -68,7 +68,7 @@ exports.sidebar = function(req, res, next) {
exports.bottombar = function(req, res, next) {
model.index({
req.ctx(model).index({
code: req.params.code
}).then((result) => {
if (!result) {
... ... @@ -117,7 +117,7 @@ exports.couponSend = (req, res, next) => {
return res.jsonp(resultData);
}
model.couponSend(uid, token).then(result => {
req.ctx(model).couponSend(uid, token).then(result => {
res.set({
'Cache-Control': 'no-cache',
Pragma: 'no-cache',
... ...
... ... @@ -15,7 +15,7 @@ exports.productLst = function(req, res, next) {
let getProductList;
if (req.query.maybeLike) {
getProductList = model.maybeLikeList(Object.assign({
getProductList = req.ctx(model).maybeLikeList(Object.assign({
uid: uid,
udid: udid,
yh_channel: req.query.yh_channel || (req.cookies._Channel && channels[req.cookies._Channel]) || 1,
... ... @@ -58,7 +58,7 @@ exports.productLst = function(req, res, next) {
}
}
getProductList = model.productLst(params);
getProductList = req.ctx(model).productLst(params);
}
getProductList.then((result) => {
... ... @@ -93,7 +93,7 @@ exports.coupon = function(req, res, next) {
});
}
model.getCoupon({
req.ctx(model).getCoupon({
activity_template_id,
uid
}).then((result) => {
... ...
... ... @@ -3,9 +3,8 @@
* Created by yoho on 2016/10/19.
*/
'use strict';
const mRoot = '../models';
const share = require(`${mRoot}/share`);
const _ = require('lodash');
const shareModel = require('../models/share');
exports.getShareContent = (req, res, next) => {
if (!req.query.shareId) {
... ... @@ -22,7 +21,7 @@ exports.getShareContent = (req, res, next) => {
});
}
share.getShareContent({
req.ctx(shareModel).getShareContent({
shareId: req.query.shareId
}).then(result => {
res.jsonp(result);
... ...
... ... @@ -57,8 +57,11 @@ const _getShopGroup = (shopRawData) => {
});
};
module.exports = {
index: function(params) {
class featureModel extends global.yoho.BaseModel {
constructor(ctx) {
super(ctx);
}
index(params) {
return Promise.coroutine(function*() {
if (!params.code) {
return Promise.resolve({});
... ... @@ -134,7 +137,7 @@ module.exports = {
return data;
})();
},
}
/**
* 领取优惠券
... ... @@ -157,7 +160,7 @@ module.exports = {
};
}
return api.get('', data).then(result => {
return this.get({data}).then(result => {
if (!result) {
result.code = 404;
... ... @@ -167,4 +170,7 @@ module.exports = {
return result;
});
}
};
}
module.exports = featureModel;
... ...
'use strict';
const api = global.yoho.API;
let _getProduct = function(o) {
return {
small_sort_id: o.small_sort_id,
... ... @@ -30,12 +28,16 @@ const gender = {
2: '2,3'
};
module.exports = {
productLst: function(params) {
return api.get('', Object.assign({
method: 'app.search.newPromotion'
}, params), {
cache: true
class individuationModel extends global.yoho.BaseModel {
constructor(ctx) {
super(ctx);
}
productLst(params) {
return this.get({
data: Object.assign({
method: 'app.search.newPromotion'
}, params),
param: {cache: true}
}).then(res => {
var data = [],
lst = (res && res.data && res.data.product_list) || [];
... ... @@ -45,19 +47,20 @@ module.exports = {
});
return data;
});
},
maybeLikeList: function(params) {
return api.get('', {
method: 'app.home.newPreference',
uid: params.uid || 0,
udid: params.udid || 0,
yh_channel: params.yh_channel,
limit: params.limit || 60,
need_filter: 'null',
rec_pos: '100053',
gender: params.gender || gender[params.yh_channel]
}, {
cache: true
}
maybeLikeList(params) {
return this.get({
data: {
method: 'app.home.newPreference',
uid: params.uid || 0,
udid: params.udid || 0,
yh_channel: params.yh_channel,
limit: params.limit || 60,
need_filter: 'null',
rec_pos: '100053',
gender: params.gender || gender[params.yh_channel]
},
param: {cache: true}
}).then(res => {
var data = [],
lst = (res && res.data && res.data.product_list) || [];
... ... @@ -67,12 +70,16 @@ module.exports = {
});
return data;
});
},
getCoupon: function(params) {
return api.get('', Object.assign({
method: 'app.coupons.personalCoupons'
}, params), {
cache: true
}
getCoupon(params) {
return this.get({
data: Object.assign({
method: 'app.coupons.personalCoupons'
}, params),
param: {cache: true}
});
}
};
}
module.exports = individuationModel;
... ...
/**
* Created by yoho on 2016/10/19.
*/
'use strict';
const serviceApi = global.yoho.ServiceAPI;
/**
* 从接口获取 share 内容
* @returns {*|Promise.<TResult>}
*/
const getShareContent = (params) => {
return serviceApi.get('operations/api/v5/webshare/getShare', {
share_id: params.shareId
}).then(result => {
return result;
});
};
class shareModel extends global.yoho.BaseModel {
constructor(ctx) {
super(ctx);
}
module.exports = {
getShareContent
};
/**
* 从接口获取 share 内容
* @returns {*|Promise.<TResult>}
*/
getShareContent(params) {
return this.get({
url: 'operations/api/v5/webshare/getShare',
data: {share_id: params.shareId},
api: global.yoho.ServiceAPI,
}).then(result => {
return result;
});
}
}
module.exports = shareModel;
... ...
... ... @@ -15,7 +15,7 @@ const bundleModel = require(`${mRoot}/bundle`);
* @param next
*/
exports.detail = (req, res, next) => {
bundleModel.detail(req.query, req.yoho.isApp).then(result => {
req.ctx(bundleModel).detail(req.query, req.yoho.isApp).then(result => {
if (!result.bundleDatas) {
return next();
}
... ... @@ -40,7 +40,7 @@ exports.detail = (req, res, next) => {
exports.addToCart = (req, res, next) => {
let shoppingKey = req.cookies._SPK || '';
bundleModel.addToCart({
req.ctx(bundleModel).addToCart({
uid: req.user.uid,
activity_id: req.body.activity_id,
product_sku_list: req.body.product_sku_list,
... ...
... ... @@ -4,95 +4,103 @@
'use strict';
const utils = '../../../utils';
const _ = require('lodash');
const api = global.yoho.API;
const helpers = global.yoho.helpers;
const productProcess = require(`${utils}/product-process`);
/**
* 从接口获取套装数据
* @private
*/
const getBundleBySkn = (productSkn) => {
return api.get('', {
method: 'app.query.bundleSkn',
product_skn: productSkn
}, {cache: false}).then(result => {
return result;
});
};
/**
* 套装详情页数据
* @param params
* @returns {*}
*/
const detail = (params, isApp) => {
if (!params.skn && !params.bundle_skn) {
return Promise.resolve({});
class bundleModel extends global.yoho.BaseModel {
constructor(ctx) {
super(ctx);
}
let bundleIndex = (params.index || 1);
--bundleIndex;
return getBundleBySkn(params.skn || params.bundle_skn).then(result => {
if (_.has(result, `data[${bundleIndex}]`)) {
let shareInfo = _.get(result, 'data[0].shareInfo', {});
return {
bundleDatas: _.map(result.data, (bundle, index) => {
let query = {bundle_skn: params.skn ||
params.bundle_skn, productId: params.productId, index: index + 1};
/**
* 从接口获取套装数据
* @private
*/
getBundleBySkn(productSkn) {
return this.get({
data: {
method: 'app.query.bundleSkn',
product_skn: productSkn
},
param: {cache: false}
}).then(result => {
return result;
});
}
if (isApp) {
query.app_version = isApp;
}
return {
selected: index === bundleIndex,
title: _.get(bundle, 'bundleInfo.tabName') || '',
href: helpers.urlFormat('/product/bundle/detail', query),
};
}),
shareInfo: {
imgUrl: `http:${helpers.image(shareInfo.imgUrl, 300, 300)}`,
subTitle: encodeURIComponent(shareInfo.subTitle),
title: encodeURIComponent(shareInfo.title),
url: shareInfo.url
},
bundleInfo: _.get(result, `data[${bundleIndex}].bundleInfo`, {}),
productList: productProcess.processProductList(_.get(result, `data[${bundleIndex}].productList`, []))
};
/**
* 套装详情页数据
* @param params
* @returns {*}
*/
detail(params, isApp) {
if (!params.skn && !params.bundle_skn) {
return Promise.resolve({});
}
return {};
});
};
let bundleIndex = (params.index || 1);
/**
* 套餐加入购物车
* @param {*} params
*/
const addToCart = (params) => {
let skuList = params.product_sku_list;
let finalParams = {
method: 'app.Shopping.addBundle',
shopping_key: params.shopping_key,
activity_id: params.activity_id,
product_sku_list: skuList
};
--bundleIndex;
return this.getBundleBySkn(params.skn || params.bundle_skn).then(result => {
if (_.has(result, `data[${bundleIndex}]`)) {
let shareInfo = _.get(result, 'data[0].shareInfo', {});
if (params.uid) {
Object.assign(finalParams, {
uid: params.uid
return {
bundleDatas: _.map(result.data, (bundle, index) => {
let query = {bundle_skn: params.skn ||
params.bundle_skn, productId: params.productId, index: index + 1};
if (isApp) {
query.app_version = isApp;
}
return {
selected: index === bundleIndex,
title: _.get(bundle, 'bundleInfo.tabName') || '',
href: helpers.urlFormat('/product/bundle/detail', query),
};
}),
shareInfo: {
imgUrl: `http:${helpers.image(shareInfo.imgUrl, 300, 300)}`,
subTitle: encodeURIComponent(shareInfo.subTitle),
title: encodeURIComponent(shareInfo.title),
url: shareInfo.url
},
bundleInfo: _.get(result, `data[${bundleIndex}].bundleInfo`, {}),
productList: productProcess.processProductList(
_.get(result, `data[${bundleIndex}].productList`, []))
};
}
return {};
});
}
return api.post('', finalParams, {
headers: {
'User-Agent': params.userAgent
/**
* 套餐加入购物车
* @param {*} params
*/
addToCart(params) {
let skuList = params.product_sku_list;
let finalParams = {
method: 'app.Shopping.addBundle',
shopping_key: params.shopping_key,
activity_id: params.activity_id,
product_sku_list: skuList
};
if (params.uid) {
Object.assign(finalParams, {
uid: params.uid
});
}
});
};
module.exports = {
getBundleBySkn,
detail,
addToCart
};
return this.post({
data: finalParams,
param: {
headers: {
'User-Agent': params.userAgent
}
}
});
}
}
module.exports = bundleModel;
... ...
... ... @@ -241,7 +241,7 @@ module.exports = class extends global.yoho.BaseModel {
}),
this._getCommonConsult(), // eslint-disable-line
comment.getConsults(result.product_id, 1, 2),
bundle.getBundleBySkn(result.product_skn)
this.ctx.req.ctx(bundle).getBundleBySkn(result.product_skn)
]).then((info) => {
finalResult = _detailDataPkg(result, data.ua); // eslint-disable-line
finalResult.enterStore = info[0];
... ... @@ -256,7 +256,7 @@ module.exports = class extends global.yoho.BaseModel {
href: helpers.urlFormat('/product/bundle/detail',
{skn: result.product_skn, id: result.product_id}),
description: '立省¥' + (parseInt(_.get(bundleData, 'bundleInfo.salesPrice', 0), 10) -
parseInt(_.get(bundleData, 'bundleInfo.discountPrice', 0), 10)) + '元',
parseInt(_.get(bundleData, 'bundleInfo.discountPrice', 0), 10)) + '元',
productList: productProcess.processProductList(bundleData && bundleData.productList)
};
}
... ... @@ -631,14 +631,14 @@ module.exports = class extends global.yoho.BaseModel {
});
dest.showBuyNow = true;
dest.cartInfo.addToCartUrl = helpers.urlFormat('/product/buy_' + origin.product_id + '_' +
origin.goods_id + '.html');
origin.goods_id + '.html');
} else { // 除了上面商品之外的普通商品
Object.assign(dest.cartInfo, cartInfo, {
price: dest.goodsPrice.previousPrice ? dest.goodsPrice.previousPrice : '',
salePrice: dest.goodsPrice.currentPrice ? dest.goodsPrice.currentPrice : '',
});
dest.cartInfo.addToCartUrl = helpers.urlFormat('/product/buy_' + origin.product_id + '_' +
origin.goods_id + '.html');
origin.goods_id + '.html');
}
return resolve(dest);
}).then(result => {
... ... @@ -728,7 +728,7 @@ module.exports = class extends global.yoho.BaseModel {
];
if (data.bundleType) {
apiArray.push(bundle.getBundleBySkn(data.productSkn));
apiArray.push(this.ctx.req.ctx(bundle).getBundleBySkn(data.productSkn));
}
return Promise.all(apiArray).then((res) => {
... ...
... ... @@ -93,8 +93,8 @@ module.exports = class extends global.yoho.BaseModel {
}
/*
获取 促销,评论,咨询,品牌信息
*/
获取 促销,评论,咨询,品牌信息
*/
querySknData(params) {
let brandId = params.brandId;
let shopId = params.shopId;
... ... @@ -112,7 +112,7 @@ module.exports = class extends global.yoho.BaseModel {
];
if (params.bundleType) {
apiArray.push(bundle.getBundleBySkn(skn));
apiArray.push(this.ctx.req.ctx(bundle).getBundleBySkn(skn));
}
return Promise.all(apiArray).then(info => {
... ... @@ -153,8 +153,8 @@ module.exports = class extends global.yoho.BaseModel {
// ------------------------------接口
/*
接口: 根据BrandID, 查询品牌信息
*/
接口: 根据BrandID, 查询品牌信息
*/
queryShopsByBrandId(brandId, shopId) {
let params = {
method: 'app.product.queryShopsInfoById',
... ...