Authored by htoooth

refactor

... ... @@ -6,22 +6,23 @@
'use strict';
const moment = require('moment');
const library = '../../../library';
const helpers = require(`${library}/helpers`);
const mRoot = '../models';
const service = require(`${mRoot}/detail-service`);
const detailHelper = require(`${mRoot}/detail-helper`);
const detailHelper = require('../models/detail-helper');
/**
* 单个商品详情
*/
module.exports.showMain = (req, res, next) => {
// TODO: 需要修改为正式取 UID 的方式
// TODO: vipLevel = 0; // 用户等级
let pid = 204503;
let pid = 373057;
let uid = req.user.uid || '';
let channel = detailHelper.COOKIE_NAME_BOYS;
... ... @@ -38,10 +39,10 @@ module.exports.showMain = (req, res, next) => {
ua: req.get('user-agent') || '',
channel: channel,
gender: gender,
uid: '',
uid: uid,
vipLevel: 0
}).then((result) => {
res.render('detail', Object.assign({
res.render('product/detail', Object.assign({
module: 'product',
page: 'detail'
}, result));
... ... @@ -55,9 +56,9 @@ module.exports.indexHotArea = (req, res, next) => {
let pid = req.params.productId || 0;
service.indexHotAreaAsync(pid).then(result => {
res.render('hotarea', {
res.render('product/hotarea', {
hotArea: result,
layout:false
layout: false
});
}).catch(next);
};
... ... @@ -68,11 +69,13 @@ module.exports.indexHotArea = (req, res, next) => {
*/
module.exports.indexComment = (req, res, next) => {
let pid = req.params.productId || 0;
let page = req.params.page || 1;
let size = req.params.size || 10;
service.indexCommentAsync(pid, page, size).then(result => {
res.json(result)
res.json(result);
}).catch(next);
};
... ... @@ -81,10 +84,12 @@ module.exports.indexComment = (req, res, next) => {
* json
*/
module.exports.indexConsult = (req, res, next) => {
// TODO: uid
let uid = '';
let uid = req.user.uid || '';
let pid = req.params.productId || 0;
let page = req.params.page || 1;
let size = req.params.size || 10;
service.indexConsultAsync(uid, pid, page, size).then(result => {
... ... @@ -97,10 +102,10 @@ module.exports.indexConsult = (req, res, next) => {
* json
*/
module.exports.createConsult = (req, res, next) => {
let uid = req.user.uid || '';
//TODO: uid
let uid = '';
let pid = req.body.productId || 0;
let content = req.body.content;
if (content && uid) {
... ... @@ -117,9 +122,9 @@ module.exports.createConsult = (req, res, next) => {
} else if (!uid) {
res.json({
code: 403,
message: "用户没有登录",
message: '用户没有登录',
data: {
url: helpers.urlFormat('/signin.html')
url: helpers.urlFormat('signin.html')
}
});
... ...
... ... @@ -3,6 +3,7 @@
*/
'use strict';
const library = '../../../library';
const helpers = require(`${library}/helpers`);
const brandService = require('../models/favorite-brand-service');
... ... @@ -12,21 +13,20 @@ const productService = require('../models/favorite-product-service');
* 收藏品牌ajax请求
*/
module.exports.changeFavoriteBrand = (req, res, next) => {
// TODO: uid get
let uid = '';
let uid = req.user.uid || '';
let brandId = req.body.brandId;
if (uid && brandId) {
brandService.changeAsync(uid, brandId).then(result => {
res.json(result)
res.json(result);
}).catch(next);
} else if (!uid) {
res.json({
code: 403,
message: '用户ID不存在',
data: {
url: helpers.urlFormat('/signin.html')
url: helpers.urlFormat('signin.html')
}
});
} else {
... ... @@ -38,8 +38,7 @@ module.exports.changeFavoriteBrand = (req, res, next) => {
};
module.exports.collectProduct = (req, res, next) => {
// TODO: uid get
let uid = '';
let uid = req.user.uid || '';
let pid = req.body.productId;
... ... @@ -48,43 +47,43 @@ module.exports.collectProduct = (req, res, next) => {
if (uid && pid) {
switch (type) {
case 'add':
{
productService.createAsync(uid, pid).then(result => {
if (result.code === 413) {
result.message = '该商品已经收藏';
}
{
productService.createAsync(uid, pid).then(result => {
if (result.code === 413) {
result.message = '该商品已经收藏';
}
res.json(result);
}).catch(next);
break;
}
res.json(result);
}).catch(next);
break;
}
case 'cancel':
{
productService.deleteAsync(uid, pid)
{
productService.deleteAsync(uid, pid)
.then(result => res.json(result))
.catch(next);
break;
}
break;
}
default:
{
res.json({
code: 400,
message: '错误类型'
});
}
{
res.json({
code: 400,
message: '错误类型'
});
}
}
} else if (!uid) {
res.json({
code: 403,
message: '用户没有登录',
data: {
url: helpers.urlFormat('/signin.html')
url: helpers.urlFormat('signin.html')
}
})
});
} else {
res.json({
code: 400,
message: '收藏失败'
})
});
}
};
... ...
... ... @@ -4,9 +4,11 @@
'use strict';
const moment = require('moment');
/* COOKIE标识访问的是男生频道 */
const COOKIE_NAME_BOYS = 'boys';
module.exports.COOKIE_DOMAIN = '.yohobuy.com';
const COOKIE_NAME_BOYS = module.exports.COOKIE_NAME_BOYS = 'boys';
const COOKIE_DOMAIN = module.exports.COOKIE_DOMAIN = '.yohobuy.com';
module.exports.setSwitchToCookie = (res) => {
res.cookie('_Channel', COOKIE_NAME_BOYS, {
... ... @@ -22,19 +24,19 @@ module.exports.getGenderByCookie = (req) => {
switch (channel) {
case 'boys':
{
gender = '1,3';
break;
}
{
gender = '1,3';
break;
}
case 'girls':
{
gender = '2,3';
break;
}
{
gender = '2,3';
break;
}
default:
{
gender = '1,2,3';
}
{
gender = '1,2,3';
}
}
return gender;
... ...
... ... @@ -5,7 +5,6 @@
const library = '../../../library';
const API = require(`${library}/api`).API;
const sign = require(`${library}/sign`);
const Promise = require('bluebird');
const api = new API();
... ... @@ -13,7 +12,7 @@ const api = new API();
* 获取商品的热区
*/
module.exports.indexAsync = (pid) => {
return api.get('', api.apiSign({
return api.get('', sign.apiSign({
method: 'web.productCollocation.list',
product_id: pid
})).catch(console.log);
... ...
... ... @@ -12,8 +12,6 @@ const moment = require('moment');
const _ = require('lodash');
const library = '../../../library';
const API = require(`${library}/api`).API;
const sign = require(`${library}/sign`);
const helpers = require(`${library}/helpers`);
const detailAPI = require('./detail-main-api');
... ... @@ -27,17 +25,16 @@ const favoriteProductService = require('./favorite-product-service');
const shopAPI = require('./shop-api');
const searchAPI = require('./search-api');
const homeHandle = require('./home-handle');
const homeService = require('./home-service');
const HeaderModel = require('../../../doraemon/models/header');
const BLANK_STR = ' ';
//商品详情页的默认头像
// 商品详情页的默认头像
const DEFAULT_AVATAR_ICO = 'http://static.yohobuy.com/images/v3/boy.jpg';
const IMAGE_SERVICE_URL = "http://head.static.yhbimg.com/yhb-head/";
const IMAGE_SERVICE_URL = 'http://head.static.yhbimg.com/yhb-head/';
var api = new API();
const multiResourcesUrl = {};
const setMultiResourceByProductBaseInfo = (data) => {
... ... @@ -1373,6 +1370,7 @@ module.exports.indexCommentAsync = (pid, page, size) => {
module.exports.indexConsultAsync = (uid, pid, page, size) => {
return co(function *() {
let consultList = yield consultAPI.indexAsync(uid, pid, page, size);
if (consultList.code && consultList.code === 200) {
return consultList.data.list.map(value => {
return {
... ... @@ -1386,11 +1384,11 @@ module.exports.indexConsultAsync = (uid, pid, page, size) => {
isUseful: value.is_useful === 'Y',
useful: parseInt(value.useful, 10),
total: value.total
}
};
});
}
return []
return [];
})();
};
... ... @@ -1399,7 +1397,7 @@ module.exports.indexConsultAsync = (uid, pid, page, size) => {
*/
module.exports.createConsultAsync = (uid, pid, content) => {
return consultAPI.createAsync(uid, pid, content);
}
};
/**
* 获取某一个商品详情主页面
... ... @@ -1425,7 +1423,7 @@ module.exports.showMainAsync = (data) => {
};
// 导航
result.detail.pathNav = _.concat(homeHandle.getHomeChannelNav(data.channel),
result.detail.pathNav = _.concat(homeService.getHomeChannelNav(data.channel),
navs,
[{name: productInfo.goodsInfo.name}]);
result.detail.lastWalk = 5;
... ... @@ -1475,10 +1473,12 @@ module.exports.indexHotAreaAsync = (pid) => {
marketPrice: cur.product.productPriceBo.formatMarketPrice,
productName: cur.product.productName,
href: helpers.getUrlBySkc(_.head(goods.goodsImagesList).productId,
_.head(goods.goodsImagesList).goodsId,
cur.product.cnAlphabet)
_.head(goods.goodsImagesList).goodsId,
cur.product.cnAlphabet)
};
acc.push(point);
return acc;
}, []);
if (_.isEmpty(item)) {
... ... @@ -1493,4 +1493,4 @@ module.exports.indexHotAreaAsync = (pid) => {
return [];
})();
}
};
... ...