Authored by 邱骏

channel与editorial相关接口上下文修改

... ... @@ -26,7 +26,7 @@ module.exports = {
/* 获取品牌列表数据 */
getBrandList: (req, res, next) => {
brandModel.getBrandListData({
req.ctx(brandModel).getBrandListData({
channel: req.query.channel
}).then(result => {
res.json(result);
... ... @@ -44,7 +44,7 @@ module.exports = {
// 全部分类api
getCateList: (req, res, next) => {
brandModel.getCateListData({
req.ctx(brandModel).getCateListData({
app_type: 1
}).then(result => {
res.json(result);
... ...
... ... @@ -19,7 +19,7 @@ module.exports = {
index(req, res, next) {
let channel = req.path.split('/')[1] || req.yoho.channel;
channelModel.getResourcesData({
req.ctx(channelModel).getResourcesData({
contentCode: channelMap[channel]
}).then(result => {
const resources = result.slice(0, 3);
... ... @@ -41,17 +41,17 @@ module.exports = {
}).catch(next);
},
channel(req, res, next) {
channelModel.getChannelData().then(result => {
req.ctx(channelModel).getChannelData().then(result => {
return res.json(result);
}).catch(next);
},
resources(req, res, next) {
channelModel.getResourcesData(req.query).then(result => {
req.ctx(channelModel).getResourcesData(req.query).then(result => {
return res.json(result);
}).catch(next);
},
goods(req, res, next) {
channelModel.getGoodsData(req.query).then(result => {
req.ctx(channelModel).getGoodsData(req.query).then(result => {
return res.json(result);
}).catch(next);
},
... ... @@ -62,7 +62,7 @@ module.exports = {
page: 'sidebar'
});
}
channelModel.getSidebarData(req.query).then(result => {
req.ctx(channelModel).getSidebarData(req.query).then(result => {
return res.json(result);
}).catch(next);
}
... ...
... ... @@ -5,7 +5,8 @@
* Time: 14:02
*/
'use strict';
const api = global.yoho.API;
// const api = global.yoho.API;
const yhChannel = {
men: {
... ... @@ -19,32 +20,42 @@ const yhChannel = {
}
};
module.exports = {
module.exports = class extends global.yoho.BaseModel{
constructor(ctx) {
super(ctx);
}
/**
* 从接口获取品牌列表页数据
* @returns {*}
*/
getBrandListOriginData(params) {
return api.get('', {
method: 'app.brand.allBrandList',
yh_channel: params.channel ? yhChannel[params.channel].channel : ''
}, {
return this.get({
data: {
yh_channel: params.channel ? yhChannel[params.channel].channel : '',
method: 'app.brand.allBrandList'
},
param: {
code: 200,
cache: true
}
});
},
}
/**
* 从接口获取全部分类数据
* @returns {*}
*/
getCateListData(params) {
return api.get('', Object.assign(params, {
return this.get({
data: Object.assign(params, {
method: 'app.sort.get'
}, {
}),
param: {
code: 200,
cache: true
}));
}
});
}
};
... ...
... ... @@ -6,15 +6,20 @@
*/
'use strict';
const brandApi = require('./brand-api');
const BrandApi = require('./brand-api');
const _ = require('lodash');
/**
module.exports = class extends global.yoho.BaseModel {
constructor(ctx) {
super(ctx);
}
/**
* 处理品牌一览品牌列表数据
* @param origin
* @returns {Array}
*/
const handleBrandList = origin => {
handleBrandList(origin) {
let dest = {
brandList: [],
indexList: []
... ... @@ -97,34 +102,40 @@ const handleBrandList = origin => {
}
return dest;
};
}
/**
/**
* 获取品牌列表页数据
* @param params
*/
const getBrandListData = params => {
getBrandListData(params) {
let finalResult = {};
let brandData = new BrandApi(this.ctx);
let that = this;
return brandApi.getBrandListOriginData(params).then(result => {
return brandData.getBrandListOriginData(params).then(result => {
if (result && result.data) {
Object.assign(finalResult, handleBrandList(result.data.all_list));
Object.assign(finalResult, that.handleBrandList(result.data.all_list));
}
return finalResult;
});
};
}
/**
/**
* 获取全部分类数据
* @param params
* @returns {*|Promise.<TResult>}
*/
const getCateListData = params => {
return brandApi.getCateListData(params);
getCateListData(params) {
let brandData = new BrandApi(this.ctx);
return brandData.getCateListData(params);
}
};
module.exports = {
/* module.exports = {
getBrandListData,
getCateListData
};
}; */
... ...
'use strict';
// const api = global.yoho.API;
const service = global.yoho.ServiceAPI;
const api = global.yoho.API;
const processResources = require(`${global.utils}/beautify/resources`);
const processProductList = require(`${global.utils}/beautify/product`);
let channel = {
let channel = class extends global.yoho.BaseModel {
constructor(ctx) {
super(ctx);
}
getResourcesData(params) {
if (!params.contentCode) {
return Promise.resolve([]);
}
return service.get('operations/api/v5/resource/get', {
return this.get({
api: service,
url: 'operations/api/v5/resource/get',
data: {
content_code: params.contentCode
}, {
},
param: {
cache: true,
code: 200
}
}).then(result => {
return result && result.data ? processResources(result.data) : [];
});
},
}
getSidebarData() {
return service.get('operations/api/v6/category/getCategory', {}, {
return this.get({
api: service,
url: 'operations/api/v6/category/getCategory',
data: {},
param: {
cache: true,
code: 200
}
});
},
}
getGoodsData(params) {
if (!params.productSkn || !params.productSkn.length) {
return Promise.resolve([]);
}
return api.get('', {
method: 'h5.product.batch',
productSkn: params.productSkn
}, {
return this.get({
data: {
productSkn: params.productSkn,
method: 'h5.product.batch'
},
param: {
cache: true,
code: 200
}
}).then(result => {
return result && result.data ? processProductList(result.data.product_list) : [];
});
},
}
getChannelData() {
return api.get('', {
return this.get({
data: {
method: 'app.blk.getAllChannels'
}, {
},
param: {
cache: true,
code: 200
}
});
}
};
... ...
... ... @@ -5,7 +5,7 @@
*/
'use strict';
const model = require('../models/detail');
const DetailModel = require('../models/detail');
/**
* 商品详情
... ... @@ -29,7 +29,7 @@ const component = {
client_type: 'h5'
};
model.index(params).then(result => {
req.ctx(DetailModel).index(params).then(result => {
res.json(result);
}).catch(next);
},
... ... @@ -49,7 +49,7 @@ const component = {
// uid: req.user.uid || 8050378
};
model.like(params, req.query.flag === 'true').then(result => {
req.ctx(DetailModel).like(params, req.query.flag === 'true').then(result => {
res.json(result);
}).catch(next);
},
... ... @@ -75,7 +75,7 @@ const component = {
return;
}
model.favorite(params, req.query.flag === 'true').then(result => {
req.ctx(DetailModel).favorite(params, req.query.flag === 'true').then(result => {
res.json(result);
}).catch(next);
},
... ... @@ -94,7 +94,7 @@ const component = {
udid: req.sessionID
};
model.misc(params).then(result => {
req.ctx(DetailModel).misc(params).then(result => {
res.json(result);
}).catch(next);
}
... ...
... ... @@ -27,7 +27,7 @@ module.exports = {
uid: req.user.uid
};
listModel.editorialList(params).then(result => {
req.ctx(listModel).editorialList(params).then(result => {
res.json(result);
}).catch(next);
}
... ...
... ... @@ -10,27 +10,47 @@ const Promise = require('bluebird');
/**
* 资讯详情
*/
const model = {
const model = class extends global.yoho.BaseModel{
constructor(ctx) {
super(ctx);
}
index(params) {
const URI_PACKAGE_ARTICLE = 'guang/service/v2/article/';
return serviceAPI.all([
serviceAPI.get(URI_PACKAGE_ARTICLE + 'getArticle', params),
serviceAPI.get(URI_PACKAGE_ARTICLE + 'getArticleContent', params),
serviceAPI.get(URI_PACKAGE_ARTICLE + 'getBrand', params),
return Promise.all([
this.get({
api: serviceAPI,
url: URI_PACKAGE_ARTICLE + 'getArticle',
data: params
}),
this.get({
api: serviceAPI,
url: URI_PACKAGE_ARTICLE + 'getArticleContent',
data: params
}),
this.get({
api: serviceAPI,
url: URI_PACKAGE_ARTICLE + 'getBrand',
data: params
})
]).then(res => {
const article = res[0];
return serviceAPI.get(URI_PACKAGE_ARTICLE + 'getOtherArticle', Object.assign({
return this.get({
api: serviceAPI,
url: URI_PACKAGE_ARTICLE + 'getOtherArticle',
data: Object.assign({
tags: article.data ? article.data.tag : {},
offset: 0,
limit: 3
}, params)).then(other => {
}, params)
}).then(other => {
res.push(other);
return res;
});
});
},
}
/**
* 点赞
... ... @@ -40,22 +60,36 @@ const model = {
* @returns {*}
*/
like(params, flag) {
let that = this;
return Promise.coroutine(function*() {
let ret = null;
if (flag) {
ret = yield serviceAPI.get('guang/api/v2/praise/setPraise', params);
ret = yield that.get({
api: serviceAPI,
url: 'guang/api/v2/praise/setPraise',
data: params
});
} else {
ret = yield serviceAPI.get('guang/api/v2/praise/cancel', params);
ret = yield that.get({
api: serviceAPI,
url: 'guang/api/v2/praise/cancel',
data: params
});
}
const misc = yield serviceAPI.get('guang/api/v2/article/getArticleBaseInfo', Object.assign({
const misc = yield that.get({
api: serviceAPI,
url: 'guang/api/v2/article/getArticleBaseInfo',
data: Object.assign({
id: params.article_id
}, params));
}, params)
});
return [ret, misc];
})();
},
}
/**
* 收藏
... ... @@ -65,22 +99,36 @@ const model = {
* @returns {*}
*/
favorite(params, flag) {
let that = this;
return Promise.coroutine(function*() {
let ret = null;
if (flag) {
ret = yield serviceAPI.get('guang/api/v1/favorite/setFavorite', params);
ret = yield that.get({
api: serviceAPI,
url: 'guang/api/v1/favorite/setFavorite',
data: params
});
} else {
ret = yield serviceAPI.get('guang/api/v1/favorite/cancelFavorite', params);
ret = yield that.get({
api: serviceAPI,
url: 'guang/api/v1/favorite/cancelFavorite',
data: params
});
}
const misc = yield serviceAPI.get('guang/api/v2/article/getArticleBaseInfo', Object.assign({
const misc = yield that.get({
api: serviceAPI,
url: 'guang/api/v2/article/getArticleBaseInfo',
data: Object.assign({
id: params.article_id
}, params));
}, params)
});
return [ret, misc];
})();
},
}
/**
* 其它信息
... ... @@ -88,9 +136,13 @@ const model = {
* @param params
*/
misc(params) {
return serviceAPI.get('guang/api/v2/article/getArticleBaseInfo', Object.assign({
return this.get({
api: serviceAPI,
url: 'guang/api/v2/article/getArticleBaseInfo',
data: Object.assign({
id: params.article_id
}, params));
}, params)
});
}
};
... ...
... ... @@ -20,16 +20,27 @@ const yhChannel = {
}
};
module.exports = {
module.exports = class extends global.yoho.BaseModel{
constructor(ctx) {
super(ctx);
}
/* 资讯列表页数据获取 */
getEditorialListData(params) {
return serviceAPI.get('guang/api/v2/article/getList', {
return this.get({
api: serviceAPI,
url: 'guang/api/v2/article/getList',
data: {
sort_id: '',
gender: yhChannel[params.channel || 'all'].channel,
uid: params.uid || '0',
page: params.page,
limit: '10'
}, {code: 200, cache: true});
},
param: {
code: 200,
cache: true
}
});
}
};
... ...
... ... @@ -6,17 +6,24 @@
*/
'use strict';
const editorialListApi = require('./list-api');
const EditorialListApi = require('./list-api');
/**
* 资讯列表数据
* @param params
* @returns {*|Promise.<TResult>}
*/
const editorialList = params => {
module.exports = class extends global.yoho.BaseModel {
constructor(ctx) {
super(ctx);
}
editorialList(params) {
let finalResult = {};
let editorialListData = new EditorialListApi(this.ctx);
return editorialListApi.getEditorialListData(params).then(result => {
return editorialListData.getEditorialListData(params).then(result => {
if (result && result.data) {
Object.assign(finalResult, {
data: {
... ... @@ -29,8 +36,5 @@ const editorialList = params => {
return finalResult;
});
};
module.exports = {
editorialList
}
};
... ...
... ... @@ -12,7 +12,7 @@ const config = require('./config/common');
// require('oneapm');
// }
const heapdump = require('heapdump');
// const heapdump = require('heapdump');
const express = require('express');
const path = require('path');
const bodyParser = require('body-parser');
... ...
... ... @@ -37,7 +37,6 @@
"express-session": "^1.14.1",
"global": "^4.3.2",
"happypack": "^3.1.0",
"heapdump": "^0.3.9",
"influxdb-winston": "^1.0.1",
"lodash": "^4.15.0",
"lodash-cli": "^4.17.4",
... ...
... ... @@ -4022,10 +4022,6 @@ header-case@^1.0.0:
no-case "^2.2.0"
upper-case "^1.1.3"
heapdump@^0.3.9:
version "0.3.9"
resolved "http://npm.yohops.com/heapdump/-/heapdump-0.3.9.tgz#03c74eb0df5d67be0982e83429ba9c9d2b3b7f78"
hmac-drbg@^1.0.0:
version "1.0.1"
resolved "http://npm.yohops.com/hmac-drbg/-/hmac-drbg-1.0.1.tgz#d2745701025a6c775a6c545793ed502fc0c649a1"
... ...