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({
class individuationModel extends global.yoho.BaseModel {
constructor(ctx) {
super(ctx);
}
productLst(params) {
return this.get({
data: Object.assign({
method: 'app.search.newPromotion'
}, params), {
cache: true
}, params),
param: {cache: true}
}).then(res => {
var data = [],
lst = (res && res.data && res.data.product_list) || [];
... ... @@ -45,9 +47,10 @@ module.exports = {
});
return data;
});
},
maybeLikeList: function(params) {
return api.get('', {
}
maybeLikeList(params) {
return this.get({
data: {
method: 'app.home.newPreference',
uid: params.uid || 0,
udid: params.udid || 0,
... ... @@ -56,8 +59,8 @@ module.exports = {
need_filter: 'null',
rec_pos: '100053',
gender: params.gender || gender[params.yh_channel]
}, {
cache: true
},
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({
}
getCoupon(params) {
return this.get({
data: Object.assign({
method: 'app.coupons.personalCoupons'
}, params), {
cache: true
}, params),
param: {cache: true}
});
}
};
}
module.exports = individuationModel;
... ...
/**
* Created by yoho on 2016/10/19.
*/
'use strict';
const serviceApi = global.yoho.ServiceAPI;
/**
class shareModel extends global.yoho.BaseModel {
constructor(ctx) {
super(ctx);
}
/**
* 从接口获取 share 内容
* @returns {*|Promise.<TResult>}
*/
const getShareContent = (params) => {
return serviceApi.get('operations/api/v5/webshare/getShare', {
share_id: params.shareId
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 = {
getShareContent
};
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,36 +4,43 @@
'use strict';
const utils = '../../../utils';
const _ = require('lodash');
const api = global.yoho.API;
const helpers = global.yoho.helpers;
const productProcess = require(`${utils}/product-process`);
/**
class bundleModel extends global.yoho.BaseModel {
constructor(ctx) {
super(ctx);
}
/**
* 从接口获取套装数据
* @private
*/
const getBundleBySkn = (productSkn) => {
return api.get('', {
getBundleBySkn(productSkn) {
return this.get({
data: {
method: 'app.query.bundleSkn',
product_skn: productSkn
}, {cache: false}).then(result => {
},
param: {cache: false}
}).then(result => {
return result;
});
};
}
/**
/**
* 套装详情页数据
* @param params
* @returns {*}
*/
const detail = (params, isApp) => {
detail(params, isApp) {
if (!params.skn && !params.bundle_skn) {
return Promise.resolve({});
}
let bundleIndex = (params.index || 1);
--bundleIndex;
return getBundleBySkn(params.skn || params.bundle_skn).then(result => {
return this.getBundleBySkn(params.skn || params.bundle_skn).then(result => {
if (_.has(result, `data[${bundleIndex}]`)) {
let shareInfo = _.get(result, 'data[0].shareInfo', {});
... ... @@ -58,18 +65,19 @@ const detail = (params, isApp) => {
url: shareInfo.url
},
bundleInfo: _.get(result, `data[${bundleIndex}].bundleInfo`, {}),
productList: productProcess.processProductList(_.get(result, `data[${bundleIndex}].productList`, []))
productList: productProcess.processProductList(
_.get(result, `data[${bundleIndex}].productList`, []))
};
}
return {};
});
};
}
/**
/**
* 套餐加入购物车
* @param {*} params
*/
const addToCart = (params) => {
addToCart(params) {
let skuList = params.product_sku_list;
let finalParams = {
method: 'app.Shopping.addBundle',
... ... @@ -84,15 +92,15 @@ const addToCart = (params) => {
});
}
return api.post('', finalParams, {
return this.post({
data: finalParams,
param: {
headers: {
'User-Agent': params.userAgent
}
}
});
};
}
}
module.exports = {
getBundleBySkn,
detail,
addToCart
};
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];
... ... @@ -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) => {
... ...
... ... @@ -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 => {
... ...