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 : ''
}, {
code: 200,
cache: true
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, {
method: 'app.sort.get'
}, {
code: 200,
cache: true
}));
return this.get({
data: Object.assign(params, {
method: 'app.sort.get'
}),
param: {
code: 200,
cache: true
}
});
}
};
... ...
... ... @@ -6,36 +6,80 @@
*/
'use strict';
const brandApi = require('./brand-api');
const BrandApi = require('./brand-api');
const _ = require('lodash');
/**
* 处理品牌一览品牌列表数据
* @param origin
* @returns {Array}
*/
const handleBrandList = origin => {
let dest = {
brandList: [],
indexList: []
};
module.exports = class extends global.yoho.BaseModel {
constructor(ctx) {
super(ctx);
}
// 标记是否有数字,有数字先暂存
let hasNum = false;
let numTemp = {};
/**
* 处理品牌一览品牌列表数据
* @param origin
* @returns {Array}
*/
handleBrandList(origin) {
let dest = {
brandList: [],
indexList: []
};
// 标记是否有数字,有数字先暂存
let hasNum = false;
let numTemp = {};
_.forEach(origin, (value, key) => {
let brands = [];
if (_.size(value) <= 0) {
return;
}
if (key === '0~9') {
hasNum = true;
numTemp = origin[key];
} else {
_.forEach(value, (subValue) => {
brands.push({
name: subValue.brand_name_en || subValue.brand_name_cn || subValue.brand_name,
logo: subValue.brand_ico,
domain: subValue.brand_domain,
shopId: subValue.shop_id,
shopName: subValue.brand_name_en || subValue.brand_name_cn || subValue.brand_name,
isRedShop: subValue.is_red_shop,
shopTemplateType: subValue.shop_template_type
});
});
_.forEach(origin, (value, key) => {
let brands = [];
dest.brandList.push({
index: key,
brands: brands
});
if (_.size(value) <= 0) {
return;
}
dest.indexList.push({
index: key,
name: key === '0~9' ? '0' : key
});
}
if (key === '0~9') {
hasNum = true;
numTemp = origin[key];
} else {
_.forEach(value, (subValue) => {
});
// 商品列表排序一次
_.sortBy(dest.brandList, o => {
return o.index.charCodeAt();
});
// 字母列表排序一次
_.sortBy(dest.indexList, o => {
return o.index.charCodeAt();
});
// 如果有数字,单独处理
if (hasNum) {
let brands = [];
_.forEach(numTemp, (subValue) => {
brands.push({
name: subValue.brand_name_en || subValue.brand_name_cn || subValue.brand_name,
logo: subValue.brand_ico,
... ... @@ -46,85 +90,52 @@ const handleBrandList = origin => {
shopTemplateType: subValue.shop_template_type
});
});
dest.brandList.push({
index: key,
index: '0~9',
brands: brands
});
dest.indexList.push({
index: key,
name: key === '0~9' ? '0' : key
index: '0_9',
name: '0'
});
}
});
// 商品列表排序一次
_.sortBy(dest.brandList, o => {
return o.index.charCodeAt();
});
// 字母列表排序一次
_.sortBy(dest.indexList, o => {
return o.index.charCodeAt();
});
// 如果有数字,单独处理
if (hasNum) {
let brands = [];
_.forEach(numTemp, (subValue) => {
brands.push({
name: subValue.brand_name_en || subValue.brand_name_cn || subValue.brand_name,
logo: subValue.brand_ico,
domain: subValue.brand_domain,
shopId: subValue.shop_id,
shopName: subValue.brand_name_en || subValue.brand_name_cn || subValue.brand_name,
isRedShop: subValue.is_red_shop,
shopTemplateType: subValue.shop_template_type
});
});
dest.brandList.push({
index: '0~9',
brands: brands
});
return dest;
}
dest.indexList.push({
index: '0_9',
name: '0'
/**
* 获取品牌列表页数据
* @param params
*/
getBrandListData(params) {
let finalResult = {};
let brandData = new BrandApi(this.ctx);
let that = this;
return brandData.getBrandListOriginData(params).then(result => {
if (result && result.data) {
Object.assign(finalResult, that.handleBrandList(result.data.all_list));
}
return finalResult;
});
}
return dest;
};
/**
* 获取品牌列表页数据
* @param params
*/
const getBrandListData = params => {
let finalResult = {};
/**
* 获取全部分类数据
* @param params
* @returns {*|Promise.<TResult>}
*/
getCateListData(params) {
let brandData = new BrandApi(this.ctx);
return brandApi.getBrandListOriginData(params).then(result => {
if (result && result.data) {
Object.assign(finalResult, handleBrandList(result.data.all_list));
}
return finalResult;
});
};
/**
* 获取全部分类数据
* @param params
* @returns {*|Promise.<TResult>}
*/
const getCateListData = params => {
return brandApi.getCateListData(params);
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', {
content_code: params.contentCode
}, {
cache: true,
code: 200
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', {}, {
cache: true,
code: 200
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
}, {
cache: true,
code: 200
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('', {
method: 'app.blk.getAllChannels'
}, {
cache: true,
code: 200
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({
tags: article.data ? article.data.tag : {},
offset: 0,
limit: 3
}, params)).then(other => {
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 => {
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({
id: params.article_id
}, params));
const misc = yield that.get({
api: serviceAPI,
url: 'guang/api/v2/article/getArticleBaseInfo',
data: Object.assign({
id: params.article_id
}, 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({
id: params.article_id
}, params));
const misc = yield that.get({
api: serviceAPI,
url: 'guang/api/v2/article/getArticleBaseInfo',
data: Object.assign({
id: params.article_id
}, params)
});
return [ret, misc];
})();
},
}
/**
* 其它信息
... ... @@ -88,9 +136,13 @@ const model = {
* @param params
*/
misc(params) {
return serviceAPI.get('guang/api/v2/article/getArticleBaseInfo', Object.assign({
id: params.article_id
}, params));
return this.get({
api: serviceAPI,
url: 'guang/api/v2/article/getArticleBaseInfo',
data: Object.assign({
id: params.article_id
}, 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', {
sort_id: '',
gender: yhChannel[params.channel || 'all'].channel,
uid: params.uid || '0',
page: params.page,
limit: '10'
}, {code: 200, cache: true});
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'
},
param: {
code: 200,
cache: true
}
});
}
};
... ...
... ... @@ -6,31 +6,35 @@
*/
'use strict';
const editorialListApi = require('./list-api');
const EditorialListApi = require('./list-api');
/**
* 资讯列表数据
* @param params
* @returns {*|Promise.<TResult>}
*/
const editorialList = params => {
let finalResult = {};
return editorialListApi.getEditorialListData(params).then(result => {
if (result && result.data) {
Object.assign(finalResult, {
data: {
list: result.data.list ? result.data.list.artList : [],
totalPage: result.data.totalPage
},
code: 200
});
}
module.exports = class extends global.yoho.BaseModel {
constructor(ctx) {
super(ctx);
}
return finalResult;
});
};
editorialList(params) {
let finalResult = {};
let editorialListData = new EditorialListApi(this.ctx);
return editorialListData.getEditorialListData(params).then(result => {
if (result && result.data) {
Object.assign(finalResult, {
data: {
list: result.data.list ? result.data.list.artList : [],
totalPage: result.data.totalPage
},
code: 200
});
}
module.exports = {
editorialList
return finalResult;
});
}
};
... ...
... ... @@ -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"
... ...