Authored by runner

dist update

Showing 35 changed files with 567 additions and 502 deletions
**/bundle/**/*.js
**/dist/**/*.js
coverage
... ...
... ... @@ -7,7 +7,6 @@
const config = require('./config/common');
// use one apm
if (config.useOneapm) {
require('oneapm');
... ... @@ -20,16 +19,12 @@ const cookieParser = require('cookie-parser');
const favicon = require('serve-favicon');
const session = require('express-session');
const memcached = require('connect-memcached');
const _ = require('lodash');
const hbs = require('express-handlebars');
const pkg = require('./package.json');
const cookie = require('./library/cookie');
const app = express();
const MemcachedStore = memcached(session);
const setChannel = require('./doraemon/middleware/set-channel');
// 向模板注入变量
app.locals.devEnv = app.get('env') === 'development';
app.locals.version = pkg.version;
... ... @@ -37,8 +32,15 @@ app.locals.version = pkg.version;
// 指定libray目录
global.library = path.resolve('./library/');
app.set('view engine', '.hbs');
app.set('views', './doraemon/views');
app.engine('.hbs', hbs({
extname: '.hbs',
defaultLayout: 'layout',
layoutsDir: './doraemon/views',
partialsDir: './doraemon/views/partial',
helpers: require(`${global.library}/helpers`)
}));
app.use(favicon(path.join(__dirname, '/public/favicon.ico')));
app.use(express.static(path.join(__dirname, 'public')));
... ... @@ -65,35 +67,35 @@ app.use(session({
})
}));
// req和res绑定yoho对象,用于传递全局数据, 如req.yoho.channel等
app.use((req, res, next) => {
req.yoho = {};
res.yoho = {};
next();
});
req.user = {}; // 全局的用户数据
req.yoho = {}; // req和res绑定yoho对象,用于传递全局数据, 如req.yoho.channel等
app.use((req, res, next) => {
req.user = {};
// 从 PHP 写的 SESSION 中获取到当前登录用户的 UID
if (req.session && _.isNumber(req.session._LOGIN_UID)) {
req.user.uid = req.session._LOGIN_UID;
}
// session 没有读取到的时候,从 cookie 读取 UID
if (!req.user.uid && req.cookies._UID) {
req.user.uid = cookie.getUid(req);
}
next();
});
const logger = require('./library/logger');
const user = require('./doraemon/middleware/user');
const setChannel = require('./doraemon/middleware/set-channel');
const errorHanlder = require('./doraemon/middleware/error-hanlder');
// YOHO 前置中间件
app.use(user());
app.use(setChannel());
// dispatcher
require('./dispatch')(app);
try {
require('./dispatch')(app);
app.all('*', errorHanlder.notFound()); // 404
// YOHO 后置中间件
app.use(errorHanlder.serverError());
} catch (err) {
logger.error(err);
}
// listener
app.listen(config.port, function() {
console.log('yohobuy start');
logger.info('yohobuy start');
});
... ...
... ... @@ -23,242 +23,246 @@ const contentCode = {
special: '89cc20483ee2cbc8a716dcfe2b6c7603'
};
class Star {
/**
* 获取资源位数据
* @param {[string]} page
* @return {[array]}
*/
static getResources(page) {
return serviceAPI.get('operations/api/v5/resource/get', sign.apiSign({
content_code: contentCode[page]
})).then((result) => {
if (result && result.code === 200) {
return resourcesProcess(result.data);
} else {
logger.error('星潮教室页面资源位返回 code 不是 200');
return [];
}
/**
* 获取资源位数据
* @param {[string]} page
* @return {[array]}
*/
const _getResources = (page) => {
return serviceAPI.get('operations/api/v5/resource/get', sign.apiSign({
content_code: contentCode[page]
})).then((result) => {
if (result && result.code === 200) {
return resourcesProcess(result.data);
} else {
logger.error('星潮教室页面资源位返回 code 不是 200');
return [];
}
});
};
/**
* 星潮教室首页数据处理
* @param {[array]} list
* @return {[array]}
*/
const _processIndexData = (list) => {
const formatData = {
ads: [],
starAvatar: [],
articles: []
};
list = list || {};
list = camelCase(list);
// 首页资源位数据处理
if (list.ads) {
_.forEach(list.ads.data, (data) => {
formatData.ads.push({
src: data.src,
url: data.url
});
});
}
/**
* 星潮教室首页数据处理
* @param {[array]} list
* @return {[array]}
*/
static processIndexData(list) {
const formatData = {
ads: [],
starAvatar: [],
articles: []
};
list = list || {};
list = camelCase(list);
// 首页资源位数据处理
if (list.ads) {
_.forEach(list.ads.data, (data) => {
formatData.ads.push({
src: data.src,
url: data.url
// 首页明星文章数据处理
if (list.list) {
_.forEach(list.list, (data) => {
const avatar = {
tags: []
};
if (data.ext.tags.length > 1) {
avatar.isSwiper = true;
}
_.forEach(data.ext.tags, (tags) => {
avatar.tags.push({
avatarUrl: `/guang/star/detail?tag=${tags.tagName}&openby:yohobuy{"action":"go.h5","params":{"id":"","share":"","shareparam":{},"islogin":"N","type":0,"updateflag":"N","url":"http:\/\/m.yohobuy.com\/guang\/star\/detail","param":{"tag":"${tags.tagName}"}}}`, // eslint-disable-line
cover: tags.cover,
tagName: tags.tagName
});
});
}
// 首页明星文章数据处理
if (list.list) {
_.forEach(list.list, (data) => {
const avatar = {
tags: []
};
if (data.ext.tags.length > 1) {
avatar.isSwiper = true;
}
_.forEach(data.ext.tags, (tags) => {
avatar.tags.push({
avatarUrl: `/guang/star/detail?tag=${tags.tagName}&openby:yohobuy{"action":"go.h5","params":{"id":"","share":"","shareparam":{},"islogin":"N","type":0,"updateflag":"N","url":"http:\/\/m.yohobuy.com\/guang\/star\/detail","param":{"tag":"${tags.tagName}"}}}`, // eslint-disable-line
cover: tags.cover,
tagName: tags.tagName
});
});
let urlObj = url.parse(data.url);
let appUrl = `&openby:yohobuy{"action":"go.h5","params":{"id":"","share":"","shareparam":{},"islogin":"N","type":0,"updateflag":"N","url":"${ urlObj.protocol + '//' + urlObj.host + urlObj.pathname}","param":${JSON.stringify(qs.parse(urlObj.query))}}}`.replace(/\//g, '\/'); // eslint-disable-line
formatData.articles.push(_.merge({
id: data.id,
url: data.url + appUrl,
title: data.title,
articeTxt: data.intro,
src: data.src,
publishTime: helpers.dateFormat('MM月DD日 hh:mm', data.publishTime),
viewsNum: data.viewsNum
}, avatar));
});
}
let urlObj = url.parse(data.url);
let appUrl = `&openby:yohobuy{"action":"go.h5","params":{"id":"","share":"","shareparam":{},"islogin":"N","type":0,"updateflag":"N","url":"${ urlObj.protocol + '//' + urlObj.host + urlObj.pathname}","param":${JSON.stringify(qs.parse(urlObj.query))}}}`.replace(/\//g, '\/'); // eslint-disable-line
formatData.articles.push(_.merge({
id: data.id,
url: data.url + appUrl,
title: data.title,
articeTxt: data.intro,
src: data.src,
publishTime: helpers.dateFormat('MM月DD日 hh:mm', data.publishTime),
viewsNum: data.viewsNum
}, avatar));
});
}
// 首页明星头像数据处理
if (list.tags) {
_.forEach(list.tags, (data) => {
let url = `/guang/star/detail?tag=${data.tagName}&openby:yohobuy{"action":"go.h5","params":{"id":"","share":"","shareparam":{},"islogin":"N","type":0,"updateflag":"N","url":"http:\/\/m.yohobuy.com\/guang\/star\/detail","param":{"tag":"${data.tagName}"}}}`; // eslint-disable-line
formatData.starAvatar.push({
url: url,
cover: data.cover
});
});
}
// 首页明星头像数据处理
if (list.tags) {
_.forEach(list.tags, (data) => {
let url = `/guang/star/detail?tag=${data.tagName}&openby:yohobuy{"action":"go.h5","params":{"id":"","share":"","shareparam":{},"islogin":"N","type":0,"updateflag":"N","url":"http:\/\/m.yohobuy.com\/guang\/star\/detail","param":{"tag":"${data.tagName}"}}}`; // eslint-disable-line
return formatData;
};
formatData.starAvatar.push({
url: url,
cover: data.cover
});
});
}
const _processShareUrl = (post) => {
return `${post.share.url}&openby:yohobuy={"action":"go.share","params":{"pic":"${helpers.image(post.src, 640, 640)}","title":"${post.title}","url":"${post.share.url}","content":"潮流资讯,新鲜贩售,YOHO!Buy有货【逛】不停"}}`; // eslint-disable-line
};
return formatData;
}
/**
* 明星专题列表数据处理
* @param {[array]} list
* @return {[array]}
*/
const _processDetailData = (list) => {
const formatData = [];
static processShareUrl(post) {
return `${post.share.url}&openby:yohobuy={"action":"go.share","params":{"pic":"${helpers.image(post.src, 640, 640)}","title":"${post.title}","url":"${post.share.url}","content":"潮流资讯,新鲜贩售,YOHO!Buy有货【逛】不停"}}`; // eslint-disable-line
}
list = list || [];
list = camelCase(list);
/**
* 明星专题列表数据处理
* @param {[array]} list
* @return {[array]}
*/
static processDetailData(list) {
const formatData = [];
list = list || [];
list = camelCase(list);
_.forEach(list, (data) => {
data.publishTime = helpers.dateFormat('MM月DD日 hh:mm', data.publishTime);
if (data.share && data.share.url) {
data.share.url = Star.processShareUrl(data);
}
formatData.push(data);
});
_.forEach(list, (data) => {
data.publishTime = helpers.dateFormat('MM月DD日 hh:mm', data.publishTime);
if (data.share && data.share.url) {
data.share.url = _processShareUrl(data);
}
formatData.push(data);
});
return formatData;
}
return formatData;
};
/**
* 星搭配文章列表数据处理
*/
static processCollocationData(list) {
const formatData = [];
/**
* 星搭配文章列表数据处理
*/
const _processCollocationData = (list) => {
const formatData = [];
list = list || [];
list = camelCase(list);
list = list || [];
list = camelCase(list);
_.forEach(list, (data) => {
if (data.isFavor === 'N') {
data.isCollected = false;
} else {
data.isCollected = true;
}
formatData.push(data);
});
_.forEach(list, (data) => {
if (data.isFavor === 'N') {
data.isCollected = false;
} else {
data.isCollected = true;
}
formatData.push(data);
});
return formatData;
}
return formatData;
};
/**
* 星潮首页
*/
static getIndexData() {
return api.get('', sign.apiSign({
method: 'app.starClass.index',
code: '8adc27fcf5676f356602889afcfd2a8e'
})).then((result) => {
if (result && result.code === 200) {
return Star.processIndexData(result.data);
} else {
logger.error('星潮教室首页数据返回 code 不是 200');
return {};
}
});
}
/**
* 星潮首页
*/
const getIndexData = () => {
return api.get('', sign.apiSign({
method: 'app.starClass.index',
code: '8adc27fcf5676f356602889afcfd2a8e'
})).then((result) => {
if (result && result.code === 200) {
return _processIndexData(result.data);
} else {
logger.error('星潮教室首页数据返回 code 不是 200');
return {};
}
});
};
/**
* 明星专题
*/
static getDetailData(params) {
return api.get('', sign.apiSign({
method: 'app.starClass.lastTagArticle',
tag: params.tag,
page: params.page || 1,
size: 10
})).then((result) => {
if (result && result.code === 200) {
if (params.page > result.data.totalPage) {
return '';
} else {
return Star.processDetailData(result.data.list);
}
/**
* 明星专题
*/
const getDetailData = (params) => {
return api.get('', sign.apiSign({
method: 'app.starClass.lastTagArticle',
tag: params.tag,
page: params.page || 1,
size: 10
})).then((result) => {
if (result && result.code === 200) {
if (params.page > result.data.totalPage) {
return '';
} else {
logger.error('明星专题文章数据返回 code 不是 200');
return [];
return _processDetailData(result.data.list);
}
});
}
} else {
logger.error('明星专题文章数据返回 code 不是 200');
return [];
}
});
};
/**
* 星专题
*/
static getSpecialData() {
return Star.getResources('special').then((result) => {
/**
* 星专题
*/
const getSpecialData = () => {
return _getResources('special').then((result) => {
// 数据结构嵌套太深
_.forEach(result, (data) => {
_.map(data.data, (item) => {
let urlObj = url.parse(item.url);
let appUrl = `&openby:yohobuy{"action":"go.h5","params":{"id":"","share":"","shareparam":{},"islogin":"N","type":0,"updateflag":"N","url":"${ urlObj.protocol + '//' + urlObj.host + urlObj.pathname}","param":${JSON.stringify(qs.parse(urlObj.query))}}}`.replace(/\//g, '\/'); // eslint-disable-line
// 数据结构嵌套太深
_.forEach(result, (data) => {
_.map(data.data, (item) => {
let urlObj = url.parse(item.url);
let appUrl = `&openby:yohobuy{"action":"go.h5","params":{"id":"","share":"","shareparam":{},"islogin":"N","type":0,"updateflag":"N","url":"${ urlObj.protocol + '//' + urlObj.host + urlObj.pathname}","param":${JSON.stringify(qs.parse(urlObj.query))}}}`.replace(/\//g, '\/'); // eslint-disable-line
item.url += appUrl;
return item;
});
item.url += appUrl;
return item;
});
return result;
});
}
/**
* 星搭配
*/
static getCollocationListData(params, uid) {
return serviceAPI.get('guang/api/v5/article/getStarClassroomArticleList', sign.apiSign(Object.assign({
limit: '20',
uid: uid
}, params))).then((result) => {
if (result && result.code === 200) {
return Star.processCollocationData(result.data.list.artList);
} else {
logger.error('获取星搭配文章列表返回 code 不是 200');
return [];
}
});
}
return result;
});
};
static setFavorite(params, uid) {
if (!uid) {
return Promise.resolve({
code: 401,
message: '未登录'
});
/**
* 星搭配
*/
const getCollocationListData = (params, uid) => {
return serviceAPI.get('guang/api/v5/article/getStarClassroomArticleList', sign.apiSign(Object.assign({
limit: '20',
uid: uid
}, params))).then((result) => {
if (result && result.code === 200) {
return _processCollocationData(result.data.list.artList);
} else {
logger.error('获取星搭配文章列表返回 code 不是 200');
return [];
}
});
};
return api.get('', sign.apiSign({
method: params.type === 'del' ? 'app.sns.cancelFavorBackCount' : 'app.sns.setFavorBackCount',
client_type: 'h5',
article_id: params.articleId,
uid: uid
}));
const setFavorite = (params, uid) => {
if (!uid) {
return Promise.resolve({
code: 401,
message: '未登录'
});
}
}
module.exports = Star;
return api.get('', sign.apiSign({
method: params.type === 'del' ? 'app.sns.cancelFavorBackCount' : 'app.sns.setFavorBackCount',
client_type: 'h5',
article_id: params.articleId,
uid: uid
}));
};
module.exports = {
getIndexData: getIndexData,
getSpecialData: getSpecialData,
getCollocationListData: getCollocationListData,
setFavorite: setFavorite,
getDetailData: getDetailData
};
... ...
... ... @@ -69,308 +69,313 @@ const contentCode = {
}
};
class Sale {
/**
* 折扣专场列表数据处理
* @param {[array]} list
* @return {[array]}
*/
static processDiscount(list, channel) {
const formatData = [];
let flag = true;
list = list || [];
list = camelCase(list);
if (list.length === 1) {
flag = false;
}
_.forEach(list, (data) => {
if (flag === true) {
data.specialUrl = `/product/sale/discount/detail?id=${data.id}&channel=${channel}`;
_.merge(data, processTime(data.leftTime));
}
/**
* 折扣专场列表数据处理
* @param {[array]} list
* @return {[array]}
*/
const _processDiscount = (list, channel) => {
const formatData = [];
let flag = true;
formatData.push(data);
});
list = list || [];
list = camelCase(list);
return formatData;
if (list.length === 1) {
flag = false;
}
/**
* 折扣专场接口调用
* @param {[object]} params
* @return {[array]}
*/
static discount(params) {
params = params || {};
return api.get('', sign.apiSign(Object.assign({
method: 'app.activity.get',
sort: 2,
plateform: 2
}, params)));
}
_.forEach(list, (data) => {
if (flag === true) {
data.specialUrl = `/product/sale/discount/detail?id=${data.id}&channel=${channel}`;
_.merge(data, processTime(data.leftTime));
}
/**
* 断码区分类数据处理
* @param {[array]} list
* @return {[array]}
*/
static processBreakingSort(list) {
const formatData = {};
const sort = [];
const sub = [];
formatData.push(data);
});
list = list || [];
list = camelCase(list);
return formatData;
};
_.forEach(list, (data, index) => {
const allSub = [];
/**
* 折扣专场接口调用
* @param {[object]} params
* @return {[array]}
*/
const _discount = (params) => {
params = params || {};
return api.get('', sign.apiSign(Object.assign({
method: 'app.activity.get',
sort: 2,
plateform: 2
}, params)));
};
data.sub.key = index;
sub.push(data.sub);
/**
* 断码区分类数据处理
* @param {[array]} list
* @return {[array]}
*/
const _processBreakingSort = (list) => {
const formatData = {};
const sort = [];
const sub = [];
_.forEach(data.sub, (dataSub) => {
allSub.push(dataSub.sizeId);
});
list = list || [];
list = camelCase(list);
sort.push({
sortName: data.sortName,
sortId: data.sortId,
allSub: allSub
});
_.forEach(list, (data, index) => {
const allSub = [];
data.sub.key = index;
sub.push(data.sub);
_.forEach(data.sub, (dataSub) => {
allSub.push(dataSub.sizeId);
});
formatData.sortData = sort;
formatData.sub = sub;
sort.push({
sortName: data.sortName,
sortId: data.sortId,
allSub: allSub
});
});
return formatData;
}
formatData.sortData = sort;
formatData.sub = sub;
return formatData;
};
/**
* 商品搜索接口请求
* @param {[object]} params
* @return {[array]}
*/
static searchSales(params) {
/**
* 商品搜索接口请求
* @param {[object]} params
* @return {[array]}
*/
const _searchSales = (params) => {
let method = 'app.search.sales';
let method = 'app.search.sales';
// 排除基本筛选项默认值为0的对象
for (let str in params) {
if (str !== 'order' && params[str] === '0' || params[str] === null) {
delete params[str];
}
// 排除基本筛选项默认值为0的对象
for (let str in params) {
if (str !== 'order' && params[str] === '0' || params[str] === null) {
delete params[str];
}
}
params.yh_channel = channelType[params.yh_channel];
params.yh_channel = channelType[params.yh_channel];
if (params.outlets) {
method = 'app.search.category';
}
if (params.outlets) {
method = 'app.search.category';
}
params = Object.assign({
limit: '50'
}, params);
params = Object.assign({
limit: '50'
}, params);
if (typeCont[params.type]) {
params.order = typeCont[params.type][params.order];
}
if (typeCont[params.type]) {
params.order = typeCont[params.type][params.order];
}
return api.get('', sign.apiSign(Object.assign({
method: method
}, params)), true);
};
return api.get('', sign.apiSign(Object.assign({
method: method
}, params)), true);
/**
* 获取用户数据信息
* @param {[string]} uid
* @return {[array]}
*/
const _getUserProfile = (uid) => {
if (!uid) {
return Promise.resolve({
code: 200,
data: {}
});
}
return api.get('', sign.apiSign({
method: 'app.passport.profile',
uid: uid
}), true);
};
/**
* 获取用户数据信息
* @param {[string]} uid
* @return {[array]}
*/
static getUserProfile(uid) {
if (!uid) {
return Promise.resolve({
code: 200,
data: {}
});
/**
* 获取资源位数据
* @param {[string]} page
* @return {[array]}
*/
const _getResources = (page, channel) => {
return serviceAPI.get('operations/api/v5/resource/get', sign.apiSign({
content_code: contentCode[channel][page]
})).then((result) => {
if (result && result.code === 200) {
return resourcesProcess(result.data);
} else {
logger.error('SALE 页面资源位返回 code 不是 200');
return [];
}
return api.get('', sign.apiSign({
method: 'app.passport.profile',
uid: uid
}), true);
}
});
};
/**
* 获取断码区分类数据
* @param {[string]} yhChannel
* @return {[object]}
*/
const _getBreakingSort = (yhChannel) => {
return api.get('', sign.apiSign({
method: 'app.sale.getBreakingSort',
yh_channel: channelType[yhChannel] || '1'
})).then((result) => {
if (result && result.code === 200) {
return _processBreakingSort(result.data);
} else {
logger.error('断码区分类接口返回 code 不是 200');
return {};
}
});
};
/**
* 获取资源位数据
* @param {[string]} page
* @return {[array]}
*/
static getResources(page, channel) {
return serviceAPI.get('operations/api/v5/resource/get', sign.apiSign({
content_code: contentCode[channel][page]
})).then((result) => {
/**
* 获取商品数据
*/
const getSearchData = (params, uid) => {
return Promise.all([
_searchSales(params).then((result) => {
if (result && result.code === 200) {
return resourcesProcess(result.data);
return productProcess.processProductList(result.data.product_list || [], {
yh_channel: params.yh_channel,
showSale: false
});
} else {
logger.error('SALE 页面资源位返回 code 不是 200');
logger.error('SALE 商品搜索返回 code 不是 200');
return [];
}
});
}
/**
* 获取断码区分类数据
* @param {[string]} yhChannel
* @return {[object]}
*/
static getBreakingSort(yhChannel) {
return api.get('', sign.apiSign({
method: 'app.sale.getBreakingSort',
yh_channel: channelType[yhChannel] || '1'
})).then((result) => {
}),
_getUserProfile(uid).then((result) => {
if (result && result.code === 200) {
return Sale.processBreakingSort(result.data);
return result.data.vip_info ? camelCase(result.data.vip_info) : {};
} else {
logger.error('断码区分类接口返回 code 不是 200');
logger.error('获取用户信息返回 code 不是 200');
return {};
}
});
}
})
]);
};
/**
* 获取商品数据
*/
static getSearchData(params, uid) {
return Promise.all([
Sale.searchSales(params).then((result) => {
if (result && result.code === 200) {
return productProcess.processProductList(result.data.product_list || [], {
yh_channel: params.yh_channel,
showSale: false
});
} else {
logger.error('SALE 商品搜索返回 code 不是 200');
return [];
}
}),
Sale.getUserProfile(uid).then((result) => {
if (result && result.code === 200) {
return result.data.vip_info ? camelCase(result.data.vip_info) : {};
} else {
logger.error('获取用户信息返回 code 不是 200');
return {};
}
})
]);
}
/**
* 获取筛选数据
* @param {[object]} params
* @return {[array]}
*/
const getFilterData = (params) => {
return _searchSales(params).then((result) => {
if (result && result.code === 200) {
return productProcess.processFilter(result.data.filter || [], {
hideSize: params.saleType === '1',
hideSort: params.saleType === '1'
});
} else {
logger.error('SALE 商品搜索返回 code 不是 200');
return [];
}
});
};
/**
* 获取筛选数据
* @param {[object]} params
* @return {[array]}
*/
static getFilterData(params) {
return Sale.searchSales(params).then((result) => {
if (result && result.code === 200) {
return productProcess.processFilter(result.data.filter || [], {
hideSize: params.saleType === '1',
hideSort: params.saleType === '1'
});
} else {
logger.error('SALE 商品搜索返回 code 不是 200');
return [];
}
});
}
/**
* 获取sale首页数据
* @return {[array]}
*/
const getSaleData = (channel) => {
return _getResources('sale', channel);
};
/**
* 获取sale首页数据
* @return {[array]}
*/
static getSaleData(channel) {
return Sale.getResources('sale', channel);
}
/**
* 获取会员享数据
* @return {[array]}
*/
const getVipData = (channel) => {
return _getResources('vip', channel);
};
/**
* 获取会员享数据
* @return {[array]}
*/
static getVipData(channel) {
return Sale.getResources('vip', channel);
}
/**
* 获取断码区数据
* @param {[object]} params
* @return {[object]}
*/
const getBreakCodeData = (params) => {
params = params || {};
return Promise.all([_getResources('breakCode', params.yhChannel), _getBreakingSort(params.yhChannel)])
.then((result) => {
return {
content: result[0],
nav: result[1]
};
});
};
/**
* 获取断码区数据
* @param {[object]} params
* @return {[object]}
*/
static getBreakCodeData(params) {
params = params || {};
return Promise.all([Sale.getResources('breakCode', params.yhChannel), Sale.getBreakingSort(params.yhChannel)])
.then((result) => {
return {
content: result[0],
nav: result[1]
};
});
}
/**
* 获取折扣专场专题列表数据
* @param {[object]} params
* @return {[object]}
*/
const getDiscountData = (yhChannel) => {
const discountData = {};
return _discount({
yh_channel: channelType[yhChannel] || '1'
}).then((result) => {
if (result && result.code === 200) {
discountData.data = _processDiscount(result.data, yhChannel);
return discountData;
} else {
logger.error('折扣专场专题列表返回 code 不是 200');
return {};
}
});
};
/**
* 获取折扣专场专题列表数据
* @param {[object]} params
* @return {[object]}
*/
static getDiscountData(yhChannel) {
const discountData = {};
return Sale.discount({
yh_channel: channelType[yhChannel] || '1'
}).then((result) => {
if (result && result.code === 200) {
discountData.data = Sale.processDiscount(result.data, yhChannel);
return discountData;
} else {
logger.error('折扣专场专题列表返回 code 不是 200');
return {};
}
});
}
/**
* 获取折扣专场专题详情数据
* @param {[string]} id
* @return {[object]}
*/
const getDiscountDetailData = (id, yhChannel) => {
let res = {};
let param = {
id: id,
yh_channel: channelType[yhChannel] || '1'
};
/**
* 获取折扣专场专题详情数据
* @param {[string]} id
* @return {[object]}
*/
static getDiscountDetailData(id, yhChannel) {
let res = {};
let param = {
id: id,
yh_channel: channelType[yhChannel] || '1'
};
return _discount(param).then((result) => {
if (result && result.code === 200) {
res = _processDiscount(result.data);
return Sale.discount(param).then((result) => {
if (result && result.code === 200) {
res = Sale.processDiscount(result.data);
return {
title: res[0].title,
productPool: res[0].productPool,
activity: {
coverUrl: res[0].coverUrl,
leftTime: res[0].leftTime
}
};
} else {
logger.error('折扣专场专题详情返回 code 不是 200');
return {};
}
});
}
}
return {
title: res[0].title,
productPool: res[0].productPool,
activity: {
coverUrl: res[0].coverUrl,
leftTime: res[0].leftTime
}
};
} else {
logger.error('折扣专场专题详情返回 code 不是 200');
return {};
}
});
};
module.exports = Sale;
module.exports = {
getSaleData: getSaleData,
getBreakCodeData: getBreakCodeData,
getDiscountData: getDiscountData,
getDiscountDetailData: getDiscountDetailData,
getVipData: getVipData,
getFilterData: getFilterData,
getSearchData: getSearchData
};
... ...
/**
* 404 错误
* @return {[type]}
*/
exports.notFound = () => {
return (req, res) => {
if (req.xhr) {
return res.status(404).json({
code: 404,
message: '页面不存在'
});
}
return res.render('error/404');
};
};
/**
* 服务器错误
* @return {[type]}
*/
exports.serverError = () => {
return (err, req, res, next) => {
if (!res.headersSent) {
if (req.xhr) {
return res.status(500).json({
code: 500,
message: '服务器错误'
});
}
return res.render('error/500', err);
}
next(err);
};
};
... ...
... ... @@ -19,7 +19,6 @@ module.exports = () => {
});
req.yoho.channel = channel;
res.yoho.channel = channel;
}
next();
... ...
const _ = require('lodash');
const cookie = require('../../library/cookie');
module.exports = () => {
return (req, res, next) => {
// 从 SESSION 中获取到当前登录用户的 UID
if (req.session && _.isNumber(req.session._LOGIN_UID)) {
req.user.uid = req.session._LOGIN_UID;
}
// session 没有读取到的时候,从 cookie 读取 UID
if (!req.user.uid && req.cookies._UID) {
req.user.uid = cookie.getUid(req);
}
next();
};
};
... ...
... ... @@ -9,14 +9,14 @@
},
"scripts": {
"start": "node app.js",
"dev": "node_modules/.bin/nodemon -e js,hbs -i public/ app.js",
"dev": "nodemon -e js,hbs -i public/ app.js",
"online": "NODE_ENV=\"production\" node app.js",
"debug": "DEBUG=\"express:*\" node_modules/.bin/nodemon -e js,hbs -i public/ app.js",
"lint-js": "./node_modules/.bin/eslint -c .eslintrc --cache --fix .",
"lint-css": "./node_modules/.bin/stylelint --config .stylelintrc public/scss/**/*.css",
"debug": "DEBUG=\"express:*\" nodemon -e js,hbs -i public/ app.js",
"lint-js": "eslint -c .eslintrc --cache --fix .",
"lint-css": "stylelint --config .stylelintrc public/scss/**/*.css",
"precommit": "node lint.js",
"test": "NODE_ENV=test ./node_modules/.bin/nyc ./node_modules/.bin/ava",
"posttest": "./node_modules/.bin/nyc report --reporter=html"
"test": "NODE_ENV=test nyc ./node_modules/.bin/ava",
"posttest": "nyc report --reporter=html"
},
"ava": {
"tap": true,
... ... @@ -68,14 +68,13 @@
"gulp-util": "^3.0.7",
"husky": "^0.11.4",
"nodemon": "1.9.2",
"nyc": "^6.4.4",
"nyc": "^6.6.1",
"postcss-assets": "^4.0.1",
"postcss-cachebuster": "^0.1.3",
"postcss-calc": "^5.2.1",
"postcss-center": "^1.0.0",
"postcss-clearfix": "^1.0.0",
"postcss-crip": "^2.0.0",
"postcss-opacity": "^3.0.0",
"postcss-position": "^0.5.0",
"postcss-pxtorem": "^3.3.1",
"postcss-short": "^1.4.0",
... ...
This diff could not be displayed because it is too large.
This diff could not be displayed because it is too large.
This diff could not be displayed because it is too large.
This diff could not be displayed because it is too large.
This diff could not be displayed because it is too large.
This diff could not be displayed because it is too large.
This diff could not be displayed because it is too large.
This diff could not be displayed because it is too large.
This diff could not be displayed because it is too large.
This diff could not be displayed because it is too large.
This diff could not be displayed because it is too large.
This diff could not be displayed because it is too large.
This diff could not be displayed because it is too large.
This diff could not be displayed because it is too large.
This diff could not be displayed because it is too large.
This diff could not be displayed because it is too large.
This diff could not be displayed because it is too large.
This diff could not be displayed because it is too large.
This diff could not be displayed because it is too large.
This diff could not be displayed because it is too large.
This diff could not be displayed because it is too large.
This diff could not be displayed because it is too large.
This diff could not be displayed because it is too large.
This diff could not be displayed because it is too large.
... ... @@ -9,7 +9,7 @@
&:link,
&:visited,
&:hover,
&:actived {
&:active {
color: #000;
}
}
... ... @@ -259,7 +259,7 @@
position: relative;
}
li:first {
li:first-child {
margin-left: 0;
}
... ...