Showing 82 changed files with 992 additions and 701 deletions
{
"sourceMapPath": "/nfs-ops/Data/app/node-ci/data",
"buildDistPath": "./public/dist",
"targetKeyPrefix": ""
}
... ...
... ... @@ -2,11 +2,14 @@
const robotCheckService = require('../models/robot-check-service');
const captchaService = require('../../passport/controllers/captcha');
const headerModel = require('../../../doraemon/models/header');
const logger = global.yoho.logger;
const index = (req, res, next) => {
let channel = req.yoho.channel || 'boys';
robotCheckService.index(channel).then((result) => {
req.ctx(headerModel).requestHeaderData(channel).then((result) => {
return res.render('robot-check', Object.assign({
module: '3party',
page: 'robot-check'
... ...
... ... @@ -5,13 +5,10 @@ const Promise = require('bluebird');
const _ = require('lodash');
const sm = require('sitemap');
const staticUrls = require('../../../config/staticUrls');
const api = global.yoho.API;
const Service = global.yoho.ServiceAPI;
const headerModel = require('../../../doraemon/models/header');
const siteMapService = require('../models/site-map-service');
const redis = global.yoho.redis;
const getStaticUrls = (currentStatics) => {
let urls = [];
... ... @@ -57,10 +54,10 @@ const keywordsPage = (page) => {
};
// 逛详情
const getArticleUrls = () => {
const getArticleUrls = (req) => {
let urls = [];
return Service.get('/guang/api/v2/article/getLastArticleList', {limit: 1000}, {cache: 86400}).then(res => {
return req.ctx(siteMapService).guangArticles().then(res => {
_.forEach(_.get(res, 'data.artList', ''), val => {
urls.push({
... ... @@ -75,27 +72,28 @@ const getArticleUrls = () => {
};
// www 地图数据
const wwwXmlData = (page) => {// eslint-disable-line
const wwwXmlData = (req, page) => {// eslint-disable-line
if (page > 1) {
return keywordsPage(page);
} else {
return Promise.all([keywordsPage(page),
getStaticUrls(_.get(staticUrls, 'www')),
getArticleUrls()]).then(result => {
getArticleUrls(req)]).then(result => {
return _.concat(result[1], result[0], result[2]);
});
}
};
// list 地图数据
const listXmlData = () => {// eslint-disable-line
return Promise.all([getStaticUrls(_.get(staticUrls, 'list')), headerModel.requestHeaderData()]).then(result => {
const listXmlData = (req) => {// eslint-disable-line
return Promise.all([getStaticUrls(_.get(staticUrls, 'list')),
req.ctx(headerModel).getSubNavGroupData()]).then(result => {
// 获取导航中的列表链接
let listNav = [],
listPatten = /list\.yohobuy\.com/;
_.forEach(_.get(result[1], 'headerData.subNavGroup'), val => {
_.forEach(result[1] || [], val => {
_.forEach(val.subNav, sub => {
if (listPatten.test(sub.link)) {
listNav.push({url: sub.link, changefreq: 'daily', priority: 0.3});
... ... @@ -113,10 +111,10 @@ const listXmlData = () => {// eslint-disable-line
};
// item 地图数据
const itemXmlData = () => {// eslint-disable-line
const itemXmlData = (req) => {// eslint-disable-line
let urls = [];
return api.get('', {method: 'web.product.bdPromotion'}, {cache: 86400}).then(res => {
return req.ctx(siteMapService).itemList().then(res => {
_.forEach(_.get(res, 'data', ''), val => {
urls.push({
url: `https:${helpers.getUrlBySkc(val.erpProductId)}`,
... ... @@ -142,7 +140,7 @@ const siteMap = (req, res, next) => {
let page = req.params[0] || 1;
eval(subdomain + 'XmlData')(page).then(urls => {// eslint-disable-line
eval(subdomain + 'XmlData')(req, page).then(urls => {// eslint-disable-line
sm.createSitemap({
hostname: `https://${subdomain}.yohobuy.com`,
xmlNs: ' ',
... ...
... ... @@ -3,21 +3,10 @@
const url = require('url');
const cache = global.yoho.cache.master;
const Promise = require('bluebird');
const co = Promise.coroutine;
const config = global.yoho.config;
const _ = require('lodash');
const humanExpire = 3600;
const HeaderModel = require('../../../doraemon/models/header');
const index = co(function* (channel) {
const header = yield HeaderModel.requestHeaderData(channel);
return {
headerData: header.headerData
};
});
const removeBlack = (remoteIp, apiLimitValidate, referer) => {
let operations = [];
... ... @@ -44,6 +33,5 @@ const removeBlack = (remoteIp, apiLimitValidate, referer) => {
};
module.exports = {
index,
removeBlack
};
... ...
... ... @@ -57,6 +57,30 @@ module.exports = class extends global.yoho.BaseModel {
});
}
guangArticles() {
return this.get({
url: '/guang/api/v2/article/getLastArticleList',
data: {
limit: 1000
},
param: {
cache: 86400
},
api: global.yoho.ServiceAPI
});
}
itemList() {
return this.get({
data: {
method: 'web.product.bdPromotion'
},
param: {
cache: 86400
}
});
}
};
... ...
... ... @@ -15,7 +15,7 @@ let responseData = {
const yohobuy = (req, res, next) => {
let channel = req.yoho.channel || 'boys';
headerModel.requestHeaderData(channel).then(result => {
req.ctx(headerModel).requestHeaderData(channel).then(result => {
responseData.headerData = result.headerData;
res.render('yohobuy', responseData);
... ... @@ -28,7 +28,7 @@ const yohobuy = (req, res, next) => {
const newpower = (req, res, next) => {
let channel = req.yoho.channel || 'boys';
headerModel.requestHeaderData(channel).then(result => {
req.ctx(headerModel).requestHeaderData(channel).then(result => {
responseData.headerData = result.headerData;
res.render('newpower', responseData);
... ... @@ -41,7 +41,7 @@ const newpower = (req, res, next) => {
const contact = (req, res, next) => {
let channel = req.yoho.channel || 'boys';
headerModel.requestHeaderData(channel).then(result => {
req.ctx(headerModel).requestHeaderData(channel).then(result => {
responseData.headerData = result.headerData;
res.render('contact', responseData);
... ... @@ -54,7 +54,7 @@ const contact = (req, res, next) => {
const privacy = (req, res, next) => {
let channel = req.yoho.channel || 'boys';
headerModel.requestHeaderData(channel).then(result => {
req.ctx(headerModel).requestHeaderData(channel).then(result => {
responseData.headerData = result.headerData;
res.render('privacy', responseData);
... ... @@ -68,7 +68,7 @@ const link = (req, res, next) => {
let channel = req.yoho.channel || 'boys';
Promise.all([
headerModel.requestHeaderData(channel),
req.ctx(headerModel).requestHeaderData(channel),
req.ctx(aboutModel).link(),
]).then(result => {
responseData.headerData = _.get(result, '[0].headerData');
... ... @@ -84,7 +84,7 @@ const category = (req, res, next) => {
let channel = req.yoho.channel || 'boys';
return Promise.all([
headerModel.requestHeaderData(channel, true),
req.ctx(headerModel).requestHeaderData(channel, true),
req.ctx(aboutModel).getCategoryDataWithCache(channel)
]).then(result => {
res.render('category', Object.assign(result[1], responseData, result[0]));
... ... @@ -98,7 +98,7 @@ const chanpin = (req, res, next) => {
let channel = req.yoho.channel || 'boys';
return Promise.all([
headerModel.requestHeaderData(channel, true),
req.ctx(headerModel).requestHeaderData(channel, true),
req.ctx(aboutModel).getChanpinData(channel)
]).then(result => {
res.render('chanpin', Object.assign(result[1], responseData, result[0]));
... ...
... ... @@ -5,7 +5,7 @@
<h1 class="main-title">产品大全</h1>
<ul class="list-block clearfix">
{{# chanpinList}}
<li><a href="//www.yohobuy.com/chanpin/{{id}}.html" title="{{keyword}}" target="_blank">{{keyword}}</a></li>
<li><a href="//www.yohobuy.com/{{#if is_hot}}hot{{^}}chanpin{{/if}}/{{id}}.html" title="{{keyword}}" target="_blank">{{keyword}}</a></li>
{{/ chanpinList}}
</ul>
</div>
... ...
... ... @@ -13,7 +13,7 @@ const contentCode = 'bb7268bd46dd46d304c2917309814681';
exports.index = (req, res, next) => {
const channel = req.cookies._Channel || 'boys';
couponModel.getCouponData(channel, {
req.ctx(couponModel).getCouponData(channel, {
uid: req.user.uid,
contentCode: req.query.contentCode || contentCode
}).then(result => {
... ... @@ -31,7 +31,7 @@ exports.index = (req, res, next) => {
};
exports.getCouponStatus = (req, res, next) => {
couponModel.getCouponStatus({
req.ctx(couponModel).getCouponStatus({
uid: req.user.uid,
contentCode: req.query.contentCode || contentCode
}).then(result => {
... ... @@ -40,7 +40,7 @@ exports.getCouponStatus = (req, res, next) => {
};
exports.sendcoupon = (req, res, next) => {
couponModel.sendcoupon(req.query.id, req.user.uid).then(result => {
req.ctx(couponModel).sendcoupon(req.query.id, req.user.uid).then(result => {
res.json(result);
}).catch(next);
};
... ...
... ... @@ -13,7 +13,7 @@ exports.special = (req, res) => {
let id = req.params[0] || 0;
let channel = req.query.channel ? req.query.channel : 'boys';
specialModel.getSpecialData(id, channel).then((result) => {
req.ctx(specialModel).getSpecialData(id, channel).then((result) => {
let headerData = result[0];
result[1].content = result[1].content.replace(/http:/ig, '');
... ...
... ... @@ -7,14 +7,15 @@
const _ = require('lodash');
const Promise = require('bluebird');
const api = global.yoho.API;
const crypto = global.yoho.crypto;
const helpers = global.yoho.helpers;
const HeaderModel = require('../../../doraemon/models/header');
const homeService = require('../../product/models/home-service');
const config = global.yoho.config;
exports.getCouponData = (channel, params) => {
function getCouponData(channel, params) {
let that = this;
return Promise.coroutine(function*() {
const result = {
pathNav: [homeService.getHomeChannelNav(channel), {
... ... @@ -27,11 +28,16 @@ exports.getCouponData = (channel, params) => {
categories: []
};
const headerModelCtx = new HeaderModel(that.ctx);
const requestData = yield Promise.all([
api.get('', Object.assign(params, {
method: 'app.promotion.queryCouponCenter'
}), config.apiCache),
HeaderModel.requestHeaderData(channel)
that.get({
data: Object.assign(params, {
method: 'app.promotion.queryCouponCenter'
}),
param: config.apiCache
}),
headerModelCtx.requestHeaderData(channel)
]);
const coupon = requestData[0];
... ... @@ -78,13 +84,17 @@ exports.getCouponData = (channel, params) => {
while (false); // eslint-disable-line
return result;
})();
};
}
function getCouponStatus(params) {
const that = this;
exports.getCouponStatus = (params) => {
return Promise.coroutine(function*() {
const coupon = yield api.get('', Object.assign(params, {
method: 'app.promotion.couponStatus'
}));
const coupon = yield that.get({
data: Object.assign(params, {
method: 'app.promotion.couponStatus'
})
});
const result = {
code: coupon.code,
categories: []
... ... @@ -116,18 +126,20 @@ exports.getCouponStatus = (params) => {
while (false); // eslint-disable-line
return result;
})();
};
}
exports.sendcoupon = (couponId, uid) => {
function sendcoupon(couponId, uid) {
let returnData = {};
couponId = crypto.decrypt('yoho9646abcdefgh', couponId);
// 领取优惠券
return api.get('', {
method: 'app.promotion.getCoupon',
couponId: couponId,
uid: uid
return this.get({
data: {
method: 'app.promotion.getCoupon',
couponId: couponId,
uid: uid
}
}).then(result => {
switch (result.code) {
case 200:
... ... @@ -164,4 +176,15 @@ exports.sendcoupon = (couponId, uid) => {
}
return returnData;
});
}
module.exports = class extends global.yoho.BaseModel {
constructor(ctx) {
super(ctx);
this.getCouponData = getCouponData.bind(this);
this.getCouponStatus = getCouponStatus.bind(this);
this.sendcoupon = sendcoupon.bind(this);
}
};
... ...
... ... @@ -6,28 +6,42 @@
'use strict';
const logger = global.yoho.logger;
const headerModel = require('../../../doraemon/models/header');
const HeaderModel = require('../../../doraemon/models/header');
var api = global.yoho.ServiceAPI;
module.exports = class extends global.yoho.BaseModel {
constructor(ctx) {
super(ctx);
}
const _getstaticFile = (id) => {
return api.get('activity/staticFileManage/queryById', {
id: id
}, {
cache: true
}).then(result => {
if (result && result.code === 200) {
result.data.title = result.data.pageTitle;
result.data.keywords = result.data.keyWord;
result.data.description = result.data.pageDesc;
return result.data;
} else {
logger.error(`专题活动ID: ${id} 接口返回数据错误`);
return {};
}
});
};
getSpecialData(id, type) {
const headerModelCtx = new HeaderModel(this.ctx);
return Promise.all([
headerModelCtx.requestHeaderData(type),
this._getstaticFile(id)
]);
}
exports.getSpecialData = (id, type) => {
return Promise.all([headerModel.requestHeaderData(type), _getstaticFile(id)]);
_getstaticFile(id) {
return this.get({
url: 'activity/staticFileManage/queryById',
data: {
id: id
},
param: {
cache: true
},
api: global.yoho.ServiceAPI
}).then(result => {
if (result && result.code === 200) {
result.data.title = result.data.pageTitle;
result.data.keywords = result.data.keyWord;
result.data.description = result.data.pageDesc;
return result.data;
} else {
logger.error(`专题活动ID: ${id} 接口返回数据错误`);
return {};
}
});
}
};
... ...
... ... @@ -7,8 +7,7 @@
const Promise = require('bluebird');
const co = Promise.coroutine;
const api = global.yoho.API;
const headerModel = require('../../../doraemon/models/header');
const HeaderModel = require('../../../doraemon/models/header');
const BrandsModel = require('./brands-model');
const _ = require('lodash');
const helpers = global.yoho.helpers;
... ... @@ -150,14 +149,15 @@ module.exports = class extends global.yoho.BaseModel {
getBrandViewList(channel) {
let that = this;
let brandsModelCtx = new BrandsModel(that.ctx);
let headerModelCtx = new HeaderModel(that.ctx);
let apiMethod = [
headerModel.requestHeaderData(channel),
headerModelCtx.requestHeaderData(channel),
brandsModelCtx.getBrandViewTop(channel),
brandsModelCtx.getBrandViewList(channel) // 分屏加载
];
return api.all(apiMethod).then(result => {
return Promise.all(apiMethod).then(result => {
let responseData = {
module: 'brands',
page: 'brands',
... ... @@ -208,7 +208,7 @@ module.exports = class extends global.yoho.BaseModel {
brandsModelCtx.getBrandViewList(channel, start)
];
return api.all(apiMethod).then(result => {
return Promise.all(apiMethod).then(result => {
let responseData = {};
// 品牌一览列表
... ... @@ -231,7 +231,7 @@ module.exports = class extends global.yoho.BaseModel {
brandsModelCtx.getBrandInfo(brandId, uid)
];
return api.all(apiMethod).then(result => {
return Promise.all(apiMethod).then(result => {
let responseData = {
code: _.isEmpty(result[0]) ? 400 : 200,
brand: _.isEmpty(result[0]) ? '' : result[0],
... ... @@ -257,7 +257,8 @@ module.exports = class extends global.yoho.BaseModel {
let brandsModelCtx = new BrandsModel(that.ctx);
return co(function*() {
let headerData = yield headerModel.requestHeaderData(channel, true);
let headerModelCtx = new HeaderModel(that.ctx);
let headerData = yield headerModelCtx.requestHeaderData(channel, true);
let responseData = {
module: 'brands',
... ...
... ... @@ -14,7 +14,7 @@ const config = global.yoho.config;
const processProduct = require(`${global.utils}/product-process`).processProduct;
const SearchApi = require('./search-api');
const headerModel = require('../../../doraemon/models/header');
const HeaderModel = require('../../../doraemon/models/header');
const needQuery = {
'GIRL KIDS': true,
... ... @@ -1198,11 +1198,11 @@ module.exports = class extends global.yoho.BaseModel {
* @return {Object}
*/
getContent(type, isJKChannel, poolId) {
let params = {new_device: 'Y'};
const headerModelCtx = new HeaderModel(this.ctx);
return Promise.all([
headerModel.requestHeaderData(type),
headerModelCtx.requestHeaderData(type),
this._requestContent(type, params),
this.getNewArrival(type, isJKChannel, poolId)
]).then(res => {
... ... @@ -1271,9 +1271,10 @@ module.exports = class extends global.yoho.BaseModel {
getJKContent(req) {
let channel = req.query.channel || req.yoho.channel || 'boys',
contentCode = req.query.content_code;
const headerModelCtx = new HeaderModel(this.ctx);
return Promise.all([
headerModel.requestHeaderData(channel),
headerModelCtx.requestHeaderData(channel),
this._requestContent(channel, {}, contentCode),
this.getNewArrival(channel, true, req.query.template_id)
]).then(res => {
... ...
... ... @@ -7,7 +7,7 @@ const find = (req, res, next) => {
let skn = req.query.skn || '';
let sku = req.query.sku || '';
service.find({
req.ctx(service).find({
skn: skn,
sku: sku
}).then((result) => {
... ...
... ... @@ -15,7 +15,7 @@ const index = (req, res, next) => {
let width = req.query.width || '';
let height = req.query.height || '';
getBannerModel.getResource(contentCode).then(data => {
req.ctx(getBannerModel).getResource(contentCode).then(data => {
let banner = '';
... ...
... ... @@ -27,14 +27,14 @@ const index = (req, res, next) => {
if (uid) {
// 获取个人信息VIP资料
let profile = yield passportModel.getUserProfile(uid).then(ret => {
let profile = yield req.ctx(passportModel).getUserProfile(uid).then(ret => {
if (ret && ret.code === 200) {
return ret.data;
}
return null;
});
let userNum = yield passportModel.getUserInfoNum(uid).then(ret => {
let userNum = yield req.ctx(passportModel).getUserInfoNum(uid).then(ret => {
if (ret && ret.code === 200) {
return ret.data;
}
... ...
... ... @@ -31,7 +31,7 @@ const index = (req, res, next) => {
});
} else {
skn = _.slice(_.uniq(skn.split(',')), 0, limit).join(','); // 去重+截取
rvModel.index(skn, limit).then(data => {
req.ctx(rvModel).index(skn, limit).then(data => {
res.jsonp(data);
}).catch(next);
}
... ... @@ -42,7 +42,7 @@ const getRecommend = (req, res, next) => {
let uid = req.user.uid;
let udid = req.user.uid + req.yoho.udid;
rvModel.recommend({
req.ctx(rvModel).recommend({
yh_channel: req.yoho.channelNum,
uid: uid,
udid: udid,
... ...
... ... @@ -4,7 +4,6 @@
'use strict';
const api = global.yoho.API;
const config = global.yoho.config;
/**
... ... @@ -12,25 +11,35 @@ const config = global.yoho.config;
* @param pid
* @returns {Promise.<type>}
*/
const getProductBySknAsync = (skn) => {
function getProductBySknAsync(skn) {
let params = {
method: 'app.product.data',
product_skn: skn
};
return api.get('', params, config.apiCache);
};
return this.get({
data: params,
param: config.apiCache
});
}
const getProductBySkuAsync = (sku) => {
function getProductBySkuAsync(sku) {
let params = {
method: 'app.shops.productListByskus',
skus: sku
};
return api.get('', params, config.apiCache);
};
return this.get({
data: params,
param: config.apiCache
});
}
module.exports = class extends global.yoho.BaseModel {
constructor(ctx) {
super(ctx);
module.exports = {
getProductBySknAsync,
getProductBySkuAsync
this.getProductBySknAsync = getProductBySknAsync.bind(this);
this.getProductBySkuAsync = getProductBySkuAsync.bind(this);
}
};
... ...
... ... @@ -4,50 +4,54 @@
'use strict';
const api = require('./erp2goods-api');
const Erp2GoodsApi = require('./erp2goods-api');
const _ = require('lodash');
const helpers = global.yoho.helpers;
const findBySkn = (skn) => {
return api.getProductBySknAsync(skn).then((result) => {
if (result && result.code && result.code === 200 && result.data.product_url) {
return {
url: helpers.getUrlBySkc(result.data.product_skn)
};
} else {
return {};
}
});
};
const findBySku = (sku) => {
return api.getProductBySkuAsync(`[${sku}]`).then((result) => {
if (result && result.code && result.code === 200 && !_.isEmpty(result.data)) {
let product = _.head(result.data) || {};
let skn = product.erpProductId || '';
module.exports = class extends global.yoho.BaseModel {
constructor(ctx) {
super(ctx);
if (skn) {
return findBySkn(skn);
}
this.erp2GoodsApi = new Erp2GoodsApi(ctx);
}
return {};
find(q) {
if (q.sku) {
return this._findBySku(q.sku);
} else if (q.skn) {
return this._findBySkn(q.skn);
} else {
return {};
return Promise.reject();
}
});
};
}
_findBySku(sku) {
return this.erp2GoodsApi.getProductBySkuAsync(`[${sku}]`).then((result) => {
if (result && result.code && result.code === 200 && !_.isEmpty(result.data)) {
let product = _.head(result.data) || {};
let skn = product.erpProductId || '';
const find = (q) => {
if (q.sku) {
return findBySku(q.sku);
} else if (q.skn) {
return findBySkn(q.skn);
} else {
return Promise.reject();
if (skn) {
return this._findBySkn(skn);
}
return {};
} else {
return {};
}
});
}
};
module.exports = {
find
_findBySkn(skn) {
return this.erp2GoodsApi.getProductBySknAsync(skn).then((result) => {
if (result && result.code && result.code === 200 && result.data.product_url) {
return {
url: helpers.getUrlBySkc(result.data.product_skn)
};
} else {
return {};
}
});
}
};
... ...
... ... @@ -6,23 +6,29 @@
'use strict';
const serviceApi = global.yoho.ServiceAPI;
const URL_OPERATIONS_RESOURCE_GET = 'operations/api/v5/resource/get';
/**
* 获取资源数据
*
* @string content_code
* @return array
*/
const getResource = content_code => { //eslint-disable-line
return serviceApi.get(URL_OPERATIONS_RESOURCE_GET, {
content_code: content_code
}, {cache: true});
};
module.exports = class extends global.yoho.BaseModel {
constructor(ctx) {
super(ctx);
}
module.exports = {
getResource
/**
* 获取资源数据
*
* @string content_code
* @return array
*/
getResource(content_code) { //eslint-disable-line
return this.get({
url: URL_OPERATIONS_RESOURCE_GET,
data: {
content_code: content_code
},
param: {
cache: true
},
api: global.yoho.ServiceAPI
});
}
};
... ...
... ... @@ -6,7 +6,6 @@
'use strict';
const api = global.yoho.API;
const config = global.yoho.config;
/**
... ... @@ -14,30 +13,40 @@ const config = global.yoho.config;
* @param uid
* @return string
*/
const getUserProfile = uid => {
function getUserProfile(uid) {
let params = {
method: 'app.passport.profile',
uid: uid
};
return api.get('', params, config.apiCache);
};
return this.get({
data: params,
param: config.apiCache
});
}
/**
* 获取用户信息
* @param uid
* @return string
*/
const getUserInfoNum = uid => {
function getUserInfoNum(uid) {
let params = {
method: 'app.home.getInfoNum',
uid: uid
};
return api.get('', params, config.apiCache);
};
return this.get({
data: params,
param: config.apiCache
});
}
module.exports = class extends global.yoho.BaseModel {
constructor(ctx) {
super(ctx);
module.exports = {
getUserProfile,
getUserInfoNum
this.getUserProfile = getUserProfile.bind(this);
this.getUserInfoNum = getUserInfoNum.bind(this);
}
};
... ...
... ... @@ -7,13 +7,12 @@
'use strict';
const _ = require('lodash');
const api = global.yoho.API;
const helper = global.yoho.helpers;
/**
* 处理商品
*/
const _handleProduct = (products) => {
function _handleProduct(products) {
return products.map((product) => {
return {
href: helper.getUrlBySkc(product.product_skn),
... ... @@ -23,14 +22,16 @@ const _handleProduct = (products) => {
productId: product.product_id
};
});
};
}
const index = (skn, limit) => {
function index(skn, limit) {
return api.get('', {
method: 'h5.product.batch',
productSkn: skn,
limit: limit
return this.get({
data: {
method: 'h5.product.batch',
productSkn: skn,
limit: limit
}
}).then(result => {
if (result.code === 200) {
... ... @@ -76,24 +77,30 @@ const index = (skn, limit) => {
};
}
});
};
}
/**
* [为你优选]
* @param {[type]} params [(yh_channel、uid、udid、rec_pos、limit)]
* @return {[type]} [{}]
*/
const recommend = (params) => {
function recommend(params) {
params.limit = params.limit || 30;
return api.get('', Object.assign({
method: 'app.home.newPreference'
}, params)).then(d => {
return this.get({
data: Object.assign({
method: 'app.home.newPreference'
}, params)
}).then(d => {
return _handleProduct(_.get(d, 'data.product_list', []));
});
};
}
module.exports = class extends global.yoho.BaseModel {
constructor(ctx) {
super(ctx);
module.exports = {
index,
recommend
this.index = index.bind(this);
this.recommend = recommend.bind(this);
}
};
... ...
... ... @@ -5,30 +5,34 @@
*/
'use strict';
const api = require('./getBanner');
const GetBanner = require('./getBanner');
const _ = require('lodash');
const QUESTION_CODE = '1337a9f26f3972060bb2a2ca3aba81fd';
const suggestFeedBack = () => {
return api.getResource(QUESTION_CODE).then(result => {
if (result.code === 200) {
let data = _.dropWhile(_.get(result, 'data', []), o => {
return o.template_name !== 'single_image'; // 取一张图资源位
});
let list = [];
module.exports = class extends global.yoho.BaseModel {
constructor(ctx) {
super(ctx);
_.forEach(data, value => {
list.push(_.get(value, 'data[0]', ''));
});
this.getBanner = new GetBanner(ctx);
}
result.data = _.compact(list);
}
suggestFeedBack() {
return this.getBanner.getResource(QUESTION_CODE).then(result => {
if (result.code === 200) {
let data = _.dropWhile(_.get(result, 'data', []), o => {
return o.template_name !== 'single_image'; // 取一张图资源位
});
let list = [];
return result;
});
};
_.forEach(data, value => {
list.push(_.get(value, 'data[0]', ''));
});
result.data = _.compact(list);
}
module.exports = {
suggestFeedBack
return result;
});
}
};
... ...
... ... @@ -10,7 +10,7 @@ const headerModel = require('../../../doraemon/models/header');
const index = (req, res, next) => {
let channel = req.cookies._Channel || 'boys';
headerModel.requestHeaderData(channel).then(result => {
req.ctx(headerModel).requestHeaderData(channel).then(result => {
res.render('app', result);
}).catch(next);
};
... ...
... ... @@ -40,7 +40,7 @@ exports.index = (req, res, next) => {
reqCtx.getHotTags(page, pageSize, channel, isHotDegrade),
reqCtx.getAds(channel, isAdDegrade),
reqCtx.getRecoArticles(gender, 1, 10),
headerModel.requestHeaderData(channel),
req.ctx(headerModel).requestHeaderData(channel),
reqCtx.getTopList(gender, uid, udid, page, true)
]).then(ret => {
... ... @@ -102,7 +102,7 @@ exports.tags = (req, res, next) => {
reqCtx.getHotTags(1, 20, channel, isHotDegrade),
reqCtx.getAds(channel, isAdDegrade),
reqCtx.getRecoArticles(gender, 1, 10),
headerModel.requestHeaderData(channel)
req.ctx(headerModel).requestHeaderData(channel)
]).then(ret => {
if (_.isEmpty(ret[1]) || _.isEmpty(ret[1].msgs)) {
... ... @@ -162,7 +162,7 @@ exports.editor = (req, res, next) => {
reqCtx.getHotTags(1, 20, channel, isHotDegrade),
reqCtx.getAds(channel, isAdDegrade),
reqCtx.getRecoArticles(gender, 1, 10),
headerModel.requestHeaderData(channel)
req.ctx(headerModel).requestHeaderData(channel)
]).then(ret => {
if (_.isEmpty(ret[1]) || _.isEmpty(ret[1].msgs)) {
... ... @@ -247,7 +247,7 @@ exports.detail = (req, res, next) => {
}
let promises = [
headerModel.requestHeaderData(channel, true),
req.ctx(headerModel).requestHeaderData(channel, true),
reqCtx.getArticleContent(id, info.title),
reqCtx.getHotTags(1, 20, channel, isHotDegrade),
reqCtx.getArticleComments(udid, uid, id, page, pageSize),
... ...
... ... @@ -7,7 +7,7 @@
'use strict';
const _ = require('lodash');
const HelpApi = require('./help-api');
const headerModel = require('../../../doraemon/models/header');
const HeaderModel = require('../../../doraemon/models/header');
const pager = require(`${global.utils}/pager`).setPager;
module.exports = class extends global.yoho.BaseModel {
... ... @@ -324,10 +324,11 @@ module.exports = class extends global.yoho.BaseModel {
// 首页
helpData(channel) {
let helpDataModel = new HelpApi(this.ctx);
let headerModelCtx = new HeaderModel(this.ctx);
let _this = this;
return Promise.all([
headerModel.requestHeaderData(channel),
headerModelCtx.requestHeaderData(channel),
helpDataModel.getHotSearch(),
helpDataModel.gethomeCategoryFaq(),
helpDataModel.getSelfService()
... ... @@ -349,8 +350,9 @@ module.exports = class extends global.yoho.BaseModel {
detailData(params) {
let helpDataModel = new HelpApi(this.ctx);
let headerModelCtx = new HeaderModel(this.ctx);
let promiseData = [
headerModel.requestHeaderData(params.channel),
headerModelCtx.requestHeaderData(params.channel),
helpDataModel.getHotSearch(),
helpDataModel.gethomeCategoryFaq()
];
... ...
... ... @@ -23,7 +23,7 @@ exports.index = (req, res, next) => {
// uid = '20000318';
// uid: 20000318 test1
commentModel.getCommentList(uid, isComment, page)
req.ctx(commentModel).getCommentList(uid, isComment, page)
.then(data => {
let localData = _.merge(data, {
module: 'home',
... ... @@ -40,7 +40,7 @@ exports.commentList4Order = (req, res, next) => {
let orderId = req.query.orderId;
// console.log(uid + '===' + orderId);
commentModel.getCommentList4Order(uid, orderId)
req.ctx(commentModel).getCommentList4Order(uid, orderId)
.then(data => {
let result = _.merge({
module: 'home',
... ... @@ -78,7 +78,7 @@ exports.saveComment = (req, res, next) => {
// console.log(JSON.stringify(data));
commentModel.saveShareOrder(data)
req.ctx(commentModel).saveShareOrder(data)
.then(result => {
let ret = result;
... ... @@ -91,7 +91,7 @@ exports.saveComment = (req, res, next) => {
createTime: moment(new Date()).format('YYYY-MM-DD HH:mm:ss'),
satisfied: data.satisfied,
size: data.size,
sizeLabel: commentModel.sizeLabelMap[data.size],
sizeLabel: req.ctx(commentModel).sizeLabelMap[data.size],
url: uutils.getUploadImgAbsoluteUrl(data.url, 'sns'),
sourceUrl: uutils.getUploadImgAbsoluteUrl(data.url, 'sns'),
height: data.height,
... ...
... ... @@ -17,7 +17,7 @@ const index = (req, res, next) => {
let uid = req.user.uid;
let page = req.query.page || 1;
complaints.getComplaintsList(uid, page).then(result => {
req.ctx(complaints).getComplaintsList(uid, page).then(result => {
res.render('complaints', result);
}).catch(next);
};
... ... @@ -36,7 +36,7 @@ const submit = (req, res, next) => {
return next();
}
complaints.addComplaints(uid, params).then(result => {
req.ctx(complaints).addComplaints(uid, params).then(result => {
res.json(result);
}).catch(next);
};
... ... @@ -55,7 +55,7 @@ const cancel = (req, res, next) => {
return next();
}
complaints.cancelComplaints(uid, id).then(result => {
req.ctx(complaints).cancelComplaints(uid, id).then(result => {
res.json(result);
}).catch(next);
};
... ...
... ... @@ -12,7 +12,7 @@ exports.index = (req, res, next) => {
const uid = req.user.uid;
const page = req.query.page || 1;
consultModel.consultList(uid, page /* ,limit=10*/)
req.ctx(consultModel).consultList(uid, page /* ,limit=10*/)
.then(result => {
let renderData = Object.assign({
module: 'home',
... ...
... ... @@ -18,7 +18,7 @@ const check = (req, res, next) => {
});
}
newUserService.check(uid).then((result) => {
req.ctx(newUserService).check(uid).then((result) => {
if (_.isEmpty(result)) {
return res.json({
code: 500,
... ...
/**
* @author: weiqingting<qingting.wei@yoho.cn>
*/
'use strict';
const api = global.yoho.API;
const getByNodeContent = (node, mode)=>{
mode = mode || 'release';
let options = {
method: 'web.html.content',
mode: mode,
node: node
};
return api.get('', options);
};
module.exports = {
getByNodeContent
};
... ... @@ -16,7 +16,6 @@ const pagerPath = path.join(global.appRoot, '/apps/product/models/public-handler
const pager = require(pagerPath).handlePagerData;
const co = Promise.coroutine;
const api = global.yoho.API;
const helpers = global.yoho.helpers;
... ... @@ -29,23 +28,26 @@ const sizeLabelMap = {
BIG: '偏大'
};
exports.sizeLabelMap = sizeLabelMap;
exports.getCommentList = (uid, isComment, page, limit) => {
function getCommentList(uid, isComment, page, limit) {
limit = limit || 10;
let that = this;
const process = function*() {
let resData = {};
// 临时解决个人中心-评论-用户头像缺失问题,待个人中心整体重构调整头像获取机制
let proInfo = yield Promise.all([
api.post('', {
method: 'web.show.queryOrderProductCommentList',
uid: uid
that.post({
data: {
method: 'web.show.queryOrderProductCommentList',
uid: uid
}
}),
api.get('', {
method: 'app.passport.profile',
uid: uid
that.get({
data: {
method: 'app.passport.profile',
uid: uid
}
})
]);
... ... @@ -149,17 +151,20 @@ exports.getCommentList = (uid, isComment, page, limit) => {
};
return co(process)();
};
}
exports.getCommentList4Order = (uid, orderCode) => {
function getCommentList4Order(uid, orderCode) {
let that = this;
const process = function*() {
let result = yield api.post('', {
// method: 'show.toShareOrderList',
method: 'web.show.queryCommentListByOrderCode',
uid: uid,
orderCode: orderCode
let result = yield that.post({
data: {
// method: 'show.toShareOrderList',
method: 'web.show.queryCommentListByOrderCode',
uid: uid,
orderCode: orderCode
}
});
let commentList = {
... ... @@ -259,11 +264,26 @@ exports.getCommentList4Order = (uid, orderCode) => {
};
return co(process)();
};
}
exports.saveShareOrder = data => {
return api.post('', {
method: 'show.saveShareOrder',
parameters: JSON.stringify(data)
function saveShareOrder(data) {
return this.post({
data: {
method: 'show.saveShareOrder',
parameters: JSON.stringify(data)
}
});
}
module.exports = class extends global.yoho.BaseModel {
constructor(ctx) {
super(ctx);
this.sizeLabelMap = sizeLabelMap;
this.getCommentList = getCommentList.bind(this);
this.getCommentList4Order = getCommentList4Order.bind(this);
this.saveShareOrder = saveShareOrder.bind(this);
}
};
... ...
... ... @@ -5,8 +5,6 @@
*/
'use strict';
const api = global.yoho.API;
const _ = require('lodash');
const Promise = require('bluebird');
... ... @@ -20,106 +18,116 @@ const complaintType = {
2: '物流相关'
};
/**
* 获取投诉列表
* @function getComplaintsList
* @param { Number } uid 用户uid
* @param { Number } page 页码
* @param { Number } limit 每页数目
* @return { Object } 投诉列表数据
*/
const getComplaintsList = (uid, page, limit) => {
page = page || 1;
limit = limit || 10;
const process = function*() {
let resData = {};
let result = yield api.get('', {
method: 'web.complaints.getList',
uid: uid,
page: page,
limit: limit
}, {code: 200});
if (!_.isEmpty(result.data)) {
let list = [];
_.forEach(_.get(result, 'data.complaintList', []), value => {
list.push({
id: value.id,
title: value.title,
target: value.customer,
type: complaintType[value.complaintsType],
order: value.orderCode,
time: value.createTime,
question: value.content,
reply: value.reply,
replyTime: value.replyTime,
revoke: value.status === -1
});
});
if (_.isEmpty(list)) {
resData.complaints = {empty: '您尚未投诉任何内容'};
} else {
resData.complaints = list;
}
module.exports = class extends global.yoho.BaseModel {
constructor(ctx) {
super(ctx);
}
/**
* 获取投诉列表
* @function getComplaintsList
* @param { Number } uid 用户uid
* @param { Number } page 页码
* @param { Number } limit 每页数目
* @return { Object } 投诉列表数据
*/
getComplaintsList(uid, page, limit) {
page = page || 1;
limit = limit || 10;
const process = function*() {
let resData = {};
let result = yield this.get({
data: {
method: 'web.complaints.getList',
uid: uid,
page: page,
limit: limit
},
param: {
cache: 200
}
});
resData.pager = Object.assign({
count: _.get(result, 'data.total', 0),
curPage: page,
totalPages: _.get(result, 'data.page_total', 0)
}, setPager(_.get(result, 'data.page_total', 0), {
page: page
}));
if (!_.isEmpty(result.data)) {
let list = [];
_.forEach(_.get(result, 'data.complaintList', []), value => {
list.push({
id: value.id,
title: value.title,
target: value.customer,
type: complaintType[value.complaintsType],
order: value.orderCode,
time: value.createTime,
question: value.content,
reply: value.reply,
replyTime: value.replyTime,
revoke: value.status === -1
});
});
if (!_.get(resData, 'pager.pages[1]')) {
_.unset(resData, 'pager.pages');
if (_.isEmpty(list)) {
resData.complaints = {empty: '您尚未投诉任何内容'};
} else {
resData.complaints = list;
}
resData.pager = Object.assign({
count: _.get(result, 'data.total', 0),
curPage: page,
totalPages: _.get(result, 'data.page_total', 0)
}, setPager(_.get(result, 'data.page_total', 0), {
page: page
}));
if (!_.get(resData, 'pager.pages[1]')) {
_.unset(resData, 'pager.pages');
}
}
}
return resData;
};
return co(process)();
};
/**
* 添加投诉
* @function addComplaints
* @param { Number } uid 用户uid
* @param { Object } params 投诉内容信息
* @return { Object } 添加投诉结果
*/
const addComplaints = (uid, params) => {
return api.post('', {
method: 'web.complaints.add',
uid: uid,
title: _.trim(params.title),
customer: _.trim(params.customer),
complaintsType: _.trim(params.complaintsType),
orderCode: _.trim(params.orderCode),
content: _.trim(params.content)
});
};
/**
* 撤销投诉
* @function addComplaints
* @param { Number } uid 用户uid
* @param { Number } id 投诉id
* @return { Object } 撤销投诉结果
*/
const cancelComplaints = (uid, id) => {
return api.post('', {
method: 'web.complaints.cancel',
uid: uid,
id: id
});
};
module.exports = {
getComplaintsList,
addComplaints,
cancelComplaints
return resData;
};
return co(process)();
}
/**
* 添加投诉
* @function addComplaints
* @param { Number } uid 用户uid
* @param { Object } params 投诉内容信息
* @return { Object } 添加投诉结果
*/
addComplaints(uid, params) {
return this.post({
data: {
method: 'web.complaints.add',
uid: uid,
title: _.trim(params.title),
customer: _.trim(params.customer),
complaintsType: _.trim(params.complaintsType),
orderCode: _.trim(params.orderCode),
content: _.trim(params.content)
}
});
}
/**
* 撤销投诉
* @function addComplaints
* @param { Number } uid 用户uid
* @param { Number } id 投诉id
* @return { Object } 撤销投诉结果
*/
cancelComplaints(uid, id) {
return this.post({
data: {
method: 'web.complaints.cancel',
uid: uid,
id: id
}
});
}
};
... ...
... ... @@ -8,7 +8,6 @@ const Promise = require('bluebird');
const moment = require('moment');
const _ = require('lodash');
const api = global.yoho.API;
const helpers = global.yoho.helpers;
const co = Promise.coroutine;
... ... @@ -27,11 +26,13 @@ const NO_CONSULT = '您尚未咨询任何内容';
function getProductGoodsInfo(skns) {
const query = _.join(_.uniq(skns), ',');
return api.get('', {
method: 'h5.product.batch',
limit: skns.length,
productSkn: query,
contain_all: 'Y'
return this.get({
data: {
method: 'h5.product.batch',
limit: skns.length,
productSkn: query,
contain_all: 'Y'
}
}).then(result => {
let resData = {};
... ... @@ -46,7 +47,7 @@ function getProductGoodsInfo(skns) {
/**
* 获取咨询列表
*/
exports.consultList = (uid, page, limit) => {
function consultList(uid, page, limit) {
page = Number.parseInt(page, 10) || 1;
limit = Number.parseInt(limit, 10) || 10;
... ... @@ -56,10 +57,14 @@ exports.consultList = (uid, page, limit) => {
limit: limit
};
let that = this;
const fetchConsults = co(function*(params) {
let res = yield api.get('', Object.assign({
method: 'web.personCen.buyConsult'
}, params));
let res = yield that.get({
data: Object.assign({
method: 'web.personCen.buyConsult'
}, params)
});
return res;
});
... ... @@ -80,7 +85,7 @@ exports.consultList = (uid, page, limit) => {
skns.push(consult.skn);
});
let goodInfos = yield getProductGoodsInfo(skns);
let goodInfos = yield that.getProductGoodsInfo(skns);
origin.consult_list.forEach(consult => {
let info = {
... ... @@ -117,4 +122,14 @@ exports.consultList = (uid, page, limit) => {
});
return fetchConsults(data).then(processData);
}
module.exports = class extends global.yoho.BaseModel {
constructor(ctx) {
super(ctx);
this.getProductGoodsInfo = getProductGoodsInfo.bind(this);
this.consultList = consultList.bind(this);
}
};
... ...
... ... @@ -3,7 +3,7 @@
const _ = require('lodash');
const UserApi = require('./user-api');
const headerModel = require('../../../doraemon/models/header');
const HeaderModel = require('../../../doraemon/models/header');
const MsgApi = require('./message');
const helpers = global.yoho.helpers;
... ... @@ -140,10 +140,11 @@ module.exports = class extends global.yoho.BaseModel {
_getTabsData(uid, channel) {
let that = this;
let headerModelCtx = new HeaderModel(this.ctx);
return Promise.props({
msg: that._msgCount(uid),
header: headerModel.requestHeaderData(channel),
header: headerModelCtx.requestHeaderData(channel),
avatar: that._getAvatar(uid)
});
}
... ...
... ... @@ -11,7 +11,7 @@ const OrderService = require('./orders-service');
const IndexApi = require('./index-api');
const UserApi = require('./user-api');
const MsgApi = require('./message');
const headerModel = require('../../../doraemon/models/header');
const HeaderModel = require('../../../doraemon/models/header');
const cache = global.yoho.cache;
const cachePreKey = 'HOME_INDEX_';
const defaultAvatar = '//img10.static.yhbimg.com/headimg/' +
... ... @@ -290,8 +290,9 @@ module.exports = class extends global.yoho.BaseModel {
// 个人中心首页同步数据
async indexNew(uid, udid, channel, isStudent) {
let headerModelCtx = new HeaderModel(this.ctx);
let indexData = await Promise.props({
header: headerModel.requestHeaderData(channel),
header: headerModelCtx.requestHeaderData(channel),
recentOrder: this._recentOrder(uid),
footerBanner: this._footerBanner(),
reason: this._cancelReason(uid)
... ...
'use strict';
const api = global.yoho.API;
exports.getUserSuccessfulOrders = (uid)=>{
return api.get('', {
method: 'app.resources.isNewUser',
uid: uid
function getUserSuccessfulOrders(uid) {
return this.get({
data: {
method: 'app.resources.isNewUser',
uid: uid
}
});
};
}
module.exports = class extends global.yoho.BaseModel {
constructor(ctx) {
super(ctx);
this.getUserSuccessfulOrders = getUserSuccessfulOrders.bind(this);
}
};
... ...
'use strict';
const _ = require('lodash');
const api = require('../models/new-user-api');
const NewUserApi = require('../models/new-user-api');
const check = (uid) => {
return api.getUserSuccessfulOrders(uid).then((result) => {
function check(uid) {
return this.newUserApi.getUserSuccessfulOrders(uid).then((result) => {
if (result.code !== 200) {
return {};
}
... ... @@ -20,8 +20,15 @@ const check = (uid) => {
}
});
};
}
module.exports = class extends global.yoho.BaseModel {
constructor(ctx) {
super(ctx);
module.exports = {
check
this.newUserApi = new NewUserApi(ctx);
this.check = check.bind(this);
}
};
... ...
... ... @@ -12,7 +12,6 @@ const OrdersAPI = require('./orders-api');
const pager = require(`${global.utils}/pager`).setPager;
const co = Promise.coroutine;
const api = global.yoho.API;
const helpers = global.yoho.helpers;
// 常量
... ... @@ -122,11 +121,13 @@ module.exports = class extends global.yoho.BaseModel {
orders: [],
pager: {}
};
let response = yield api.post('', {
method: 'app.refund.getList',
uid: uid,
page: page,
limit: limit
let response = yield that.post({
data: {
method: 'app.refund.getList',
uid: uid,
page: page,
limit: limit
}
});
let repData = response.data;
... ...
... ... @@ -7,7 +7,6 @@
'use strict';
const Promise = require('bluebird');
const co = Promise.coroutine;
const api = global.yoho.API;
const _ = require('lodash');
const UserApi = require('./user-api');
const helpers = global.yoho.helpers;
... ... @@ -272,7 +271,7 @@ module.exports = class extends global.yoho.BaseModel {
return co(function*() {
let userDataModel = new UserApi(that.ctx);
let result = yield api.all([
let result = yield Promise.all([
userDataModel.getUserInfo(uid),
userDataModel.getTipConfig(uid),
userDataModel.getUserContactInfo(uid),
... ...
... ... @@ -2,7 +2,7 @@
const _ = require('lodash');
const helpers = global.yoho.helpers;
const headerModel = require('../../../doraemon/models/header');
const HeaderModel = require('../../../doraemon/models/header');
const NewsAPi = require('./news-api');
const utils = require('./utils');
const moment = require('moment');
... ... @@ -123,12 +123,13 @@ module.exports = class extends global.yoho.BaseModel {
getIndexList(channel, param) {
let newsAPi = new NewsAPi(this.ctx);
let headerModelCtx = new HeaderModel(this.ctx);
let params = {
page: param.page || 1
};
let apiMethod = [
headerModel.requestHeaderData(channel),
headerModelCtx.requestHeaderData(channel),
newsAPi.getRecoArticles({
gender: _.get(this.ctx, 'req.yoho.gender', '1,3'),
page: 1,
... ... @@ -216,8 +217,9 @@ module.exports = class extends global.yoho.BaseModel {
app: param.app,
};
let newsAPi = new NewsAPi(this.ctx);
let headerModelCtx = new HeaderModel(this.ctx);
let apiMethod = [
headerModel.requestHeaderData(channel, true),
headerModelCtx.requestHeaderData(channel, true),
newsAPi.getRecoArticles({
gender: _.get(this.ctx, 'req.yoho.gender', '1,3'),
page: 1,
... ...
... ... @@ -176,7 +176,7 @@ const validateMobileAPI = (req, res, next) => {
return res.json(ERR);
}
if (!passportHelper.validator.isMobile(mobile)) {
if (!req.ctx(passportHelper).validator.isMobile(mobile)) {
return res.json(ERR);
}
... ... @@ -206,7 +206,7 @@ const sendEmailPage = (req, res, next) => {
req.session.type = 'back-step3';
passportHelper.getLeftBannerAsync()
req.ctx(passportHelper).getLeftBannerAsync()
.then(result => {
res.render('back/send-email', Object.assign({
module: 'passport',
... ... @@ -245,7 +245,7 @@ const validateCodeByEmailPage = (req, res, next) => {
const resetPasswordPage = (req, res, next) => {
let code = req.query.code || '';
passportHelper.getLeftBannerAsync()
req.ctx(passportHelper).getLeftBannerAsync()
.then(result => {
res.render('back/reset-pwd', Object.assign({
module: 'passport',
... ... @@ -270,7 +270,7 @@ const verifyCodeByMobilePage = (req, res, next) => {
req.session.type = 'back-step3';
passportHelper.getLeftBannerAsync()
req.ctx(passportHelper).getLeftBannerAsync()
.then(result => {
res.render('back/verification', Object.assign({
module: 'passport',
... ... @@ -302,7 +302,7 @@ const validateSuccessStatusPage = (req, res, next) => {
};
const resetPwdSuccessPage = (req, res, next) => {
passportHelper.getLeftBannerAsync()
req.ctx(passportHelper).getLeftBannerAsync()
.then(result => {
res.render('back/reset-success', Object.assign({
module: 'passport',
... ... @@ -386,7 +386,7 @@ const validateCodeByMobilePage = (req, res, next) => {
const validatePwdPage = (req, res, next) => {
let pwd = req.body.pwd || '';
if (!passportHelper.validator.isPassword(pwd)) {
if (!req.ctx(passportHelper).validator.isPassword(pwd)) {
return res.redirect(helpers.urlFormat('/passport/back/index'));
}
... ... @@ -428,7 +428,7 @@ const weakPasswordPage = (req, res, next) => {
return res.redirect(refer);
}
passportHelper.getLeftBannerAsync().then(result => {
req.ctx(passportHelper).getLeftBannerAsync().then(result => {
res.render('back/weak-pwd', Object.assign({
module: 'passport',
page: 'back-weak-pwd',
... ... @@ -448,7 +448,7 @@ const weakPasswordPage = (req, res, next) => {
const weakPwdSuccessPage = (req, res, next) => {
let refer = req.query.refer || helpers.urlFormat('/');
passportHelper.getLeftBannerAsync()
req.ctx(passportHelper).getLeftBannerAsync()
.then(result => {
res.render('back/weak-success', Object.assign({
module: 'passport',
... ...
... ... @@ -35,7 +35,7 @@ const bind = {
openId: openId,
sourceType: sourceType,
nickName: nickName,
region: passportHelper.getCountry(),
region: req.ctx(passportHelper).getCountry(),
serviceUrl: helpers.urlFormat('/help', {
category_id: 9
}),
... ...
... ... @@ -15,7 +15,7 @@ const isGeetest = (req) => {
};
function required(req, res, next) {
img.trySwitch(req).then(() => {
img.trySwitch(req, res).then(() => {
if (req.session.captcha.type === CAPTCHA_TYPE.image && req.session.captcha.value === CAPTCHA_SWITCH.off) {
const captcha = {
type: CAPTCHA_TYPE.geetest,
... ... @@ -23,7 +23,7 @@ function required(req, res, next) {
};
req.session.captcha = captcha;
res.app.locals.captcha = captcha;
res.locals.captcha = captcha;
}
next();
}).catch(next);
... ... @@ -62,7 +62,7 @@ const geeOnly = function(req, res, next) {
};
req.session.captcha = captcha;
res.app.locals.captcha = captcha;
res.locals.captcha = captcha;
next();
};
... ...
... ... @@ -19,7 +19,7 @@ const cert = {
let refer = req.query.refer || `${config.siteUrl}`;
res.render('cert/index', {
region: passportHelper.getCountry(),
region: req.ctx(passportHelper).getCountry(),
refer: refer,
serviceUrl: helpers.urlFormat('/help', {
category_id: 9
... ...
... ... @@ -56,7 +56,7 @@ const checkAPI = (req, res, next) => {
}).catch(next);
};
const trySwitch = (req) => {
const trySwitch = (req, res) => {
return req.ctx(CaptchaServiceModel).try().then((result) => {
const captcha = {
type: CAPTCHA_TYPE.image,
... ... @@ -64,7 +64,7 @@ const trySwitch = (req) => {
};
req.session.captcha = captcha;
req.app.locals.captcha = captcha;
res.locals.captcha = captcha;
});
};
... ...
... ... @@ -107,7 +107,7 @@ const local = {
let bindMobile = _.trim(req.query.bindMobile || '');
let bindArea = '+' + _.trim(req.query.bindArea || '86');
let areaArr = PassportHelper.getCountry();
let areaArr = req.ctx(PassportHelper).getCountry();
let areaName = '';
if (bindArea) {
... ... @@ -120,7 +120,7 @@ const local = {
let refer = req.query.refer || req.cookies.refer || req.get('Referer');
PassportHelper.getLeftBannerAsync(SIGNIN_LEFT_BANNER_CODE).then(cover => {
req.ctx(PassportHelper).getLeftBannerAsync(SIGNIN_LEFT_BANNER_CODE).then(cover => {
res.render('login', {
loginPage: true,
simpleHeader: simpleHeaderModel.setSimpleHeaderData(),
... ...
... ... @@ -80,7 +80,7 @@ let index = (req, res, next) => {
simpleHeader: simpleHeaderModel.setSimpleHeaderData(),
title: '新用户注册',
passport: {
region: passportHelper.getCountry(),
region: req.ctx(passportHelper).getCountry(),
location: area || '+86',
defaultMobile: mobile,
captchaUrl: helpers.urlFormat('/passport/imagesNode', {t: Date.now()}),
... ...
... ... @@ -14,7 +14,7 @@ const Api = require('./back-api');
const UserService = require('./user-service');
const CaptchaImgService = require('./captcha-img-service');
const passportHelper = require('./passport-helper');
const PassportHelper = require('./passport-helper');
const backHelper = require('./back-helper');
const BACK_LEFT_BANNER_CODE = '3bbaf502c447a2ddad60879042e286d8'; // 找回密码左边的banner
... ... @@ -26,6 +26,7 @@ module.exports = class extends global.yoho.BaseModel {
this.api = new Api(ctx);
this.userService = new UserService(ctx);
this.captchaService = new CaptchaImgService(ctx);
this.passportHelper = new PassportHelper(ctx);
/**
* 验证邮件验证码
... ... @@ -40,16 +41,18 @@ module.exports = class extends global.yoho.BaseModel {
* 验证手机和邮箱输入正确性
*/
validateEmailOrMobileAsync(userInput, areaCode) {
let that = this;
return new Promise(function(resolve, rejected) {
let result = {type: 'email', area: '', phone: ''};
if (passportHelper.validator.isEmail(userInput)) {
if (that.passportHelper.validator.isEmail(userInput)) {
result.type = 'email';
result.area = '';
result.phone = userInput;
resolve(result);
} else if (passportHelper.validator.isMobile(userInput)) {
} else if (that.passportHelper.validator.isMobile(userInput)) {
result.type = 'mobile';
result.area = areaCode;
result.phone = userInput;
... ... @@ -128,9 +131,11 @@ module.exports = class extends global.yoho.BaseModel {
* 获得首页的数据
*/
indexPageDataAsync() {
let that = this;
return co(function* () {
let banner = yield passportHelper.getLeftBannerAsync(BACK_LEFT_BANNER_CODE);
let countryList = passportHelper.getCountry();
let banner = yield that.passportHelper.getLeftBannerAsync(BACK_LEFT_BANNER_CODE);
let countryList = that.passportHelper.getCountry();
return {
back: {
... ...
... ... @@ -4,19 +4,24 @@
'use strict';
const serviceAPI = global.yoho.ServiceAPI;
const config = global.yoho.config;
/**
* 资源码找资源
*/
const getResourceAsync = resourceCode => {
return serviceAPI.get('/operations/api/v5/resource/get', {
content_code: resourceCode
}, config.apiCache);
};
module.exports = class extends global.yoho.BaseModel {
constructor(ctx) {
super(ctx);
}
module.exports = {
getResourceAsync
/**
* 资源码找资源
*/
getResourceAsync(resourceCode) {
return this.get({
url: '/operations/api/v5/resource/get',
data: {
content_code: resourceCode
},
param: config.apiCache,
api: global.yoho.ServiceAPI
});
}
};
... ...
... ... @@ -3,13 +3,20 @@
*/
'use strict';
const api = require('./index-api');
const IndexApi = require('./index-api');
/**
* 获得资源
*/
const getResourceAsync = (resourceCode) => {
return api.getResourceAsync(resourceCode)
module.exports = class extends global.yoho.BaseModel {
constructor(ctx) {
super(ctx);
this.indexApi = new IndexApi(ctx);
}
/**
* 获得资源
*/
getResourceAsync(resourceCode) {
return this.indexApi.getResourceAsync(resourceCode)
.then(result => {
if (result.code === 200) {
return result.data;
... ... @@ -20,8 +27,5 @@ const getResourceAsync = (resourceCode) => {
.catch(() => {
return {};
});
};
module.exports = {
getResourceAsync
}
};
... ...
... ... @@ -8,7 +8,7 @@ const co = Promise.coroutine;
const _ = require('lodash');
const helpers = global.yoho.helpers;
const indexService = require('./index-service');
const IndexService = require('./index-service');
/**
* 获得图片
... ... @@ -19,9 +19,10 @@ function getLeftBannerAsync(resourceCode) {
'yhb-img01/2015/12/01/07/020a0b6e7ff908d0c2bc4045b4fef42b9f.png?imageView/2/w/252/h/190',
url: ''
};
let that = this;
return co(function* () {
let resource = yield indexService.getResourceAsync(resourceCode);
let resource = yield that.indexService.getResourceAsync(resourceCode);
if (_.isEmpty(resource)) {
return DEFAULT_VALUE;
... ... @@ -128,13 +129,17 @@ const isPassword = pwd => {
return pwdRegexp.test(_.trim(pwd));
};
module.exports = {
validator: {
isMobile,
isEmail,
isPassword
},
getCountry,
getLeftBannerAsync
module.exports = class extends global.yoho.BaseModel {
constructor(ctx) {
super(ctx);
this.indexService = new IndexService(ctx);
this.getLeftBannerAsync = getLeftBannerAsync.bind(this);
this.getCountry = getCountry;
this.validator = {
isMobile,
isEmail,
isPassword
};
}
};
... ...
... ... @@ -2,7 +2,7 @@
* 注册 model
*/
'use strict';
const passportHelper = require('./passport-helper');
const PassportHelper = require('./passport-helper');
const Api = require('./reg-api');
const CaptchaServiceModel = require('./captcha-img-service');
... ... @@ -14,6 +14,7 @@ module.exports = class extends global.yoho.BaseModel {
super(ctx);
this.api = new Api(ctx);
this.captchaService = new CaptchaServiceModel(ctx);
this.passportHelper = new PassportHelper(ctx);
this.sendCodeToMobile = this.api.sendCodeToMobile.bind(this.api);
this.regMobileAes = this.api.regMobileAes.bind(this.api);
... ... @@ -21,6 +22,6 @@ module.exports = class extends global.yoho.BaseModel {
}
getRegData() {
return passportHelper.getLeftBannerAsync(REGISTER_LEFT_BANNER_CODE);
return this.passportHelper.getLeftBannerAsync(REGISTER_LEFT_BANNER_CODE);
}
};
... ...
... ... @@ -40,7 +40,7 @@ exports.index = (req, res, next) => {
let headerData = {};
headerModel.requestHeaderData(channel).then(result => {
req.ctx(headerModel).requestHeaderData(channel).then(result => {
headerData = result.headerData;
});
... ...
... ... @@ -157,6 +157,7 @@ const searchHistory = (req, res) => {
history = _.filter(history.split(','), old => old && old !== q);
if (q) {
sear;
history.unshift(q);
res.cookie('_History', _.take(history, 9).join(','), {
path: '/',
... ...
... ... @@ -9,6 +9,10 @@ const seoModel = require('../models/seo-service'); // seo 页 model
const hot = (req, res, next) => {
return req.ctx(seoModel).getHotKeywordDate(req.params.id, req.query, req.yoho.channel).then(result => {
if (!result) {
return next();
}
res.render('seo/hot', result);
}).catch(next);
};
... ...
... ... @@ -65,6 +65,7 @@ module.exports = class extends global.yoho.BaseModel {
this.getNewProduct = _cached(this._getNewProduct, this);
this.getGuangArticles = _cached(this._getGuangArticles, this);
this.getRecommendHotKeywords = _cached(this._getRecommendHotKeywords, this);
this.getRecommendKeywords = _cached(this._getRecommendKeywords, this);
this.getShopRecommendAsync = _cached(this._getShopRecommendAsync, this, ONE_DAY);
}
... ... @@ -235,6 +236,17 @@ module.exports = class extends global.yoho.BaseModel {
});
}
// 根据mid_sort从redis获取分类下的hot关键词
_getRecommendHotKeywords(midSort, skn) { // eslint-disable-line
return redis.all([['get', `global:yoho:seo:hot:keywords:${midSort}:page`]]).then(res => {
return redis.all([
['get', `global:yoho:seo:hot:keywords:${midSort}:page:${ _.random(1, res[0]) || 1}`]
]);
}).then(res => {
return this._getKeywordsInfo(JSON.parse(res[0] || '[]'));
});
}
// 根据small_sort从redis获取分类下的关键词
_getRecommendKeywords(smallSort, skn) { // eslint-disable-line
return redis.all([['get', `global:yoho:seo:keywords:sortId:${smallSort}:page`]]).then(res => {
... ... @@ -252,7 +264,7 @@ module.exports = class extends global.yoho.BaseModel {
_.forEach(_.slice(_.shuffle(keywords), 0, 18), val => {
res.push({
url: helpers.urlFormat(`/chanpin/${val.id}.html`),
url: helpers.urlFormat(`/${val.is_hot ? 'hot' : 'chanpin'}/${val.id}.html`),
keyword: val.keyword
});
});
... ...
... ... @@ -1032,6 +1032,7 @@ function _detailDataPkg(origin, uid, vipLevel, cookies) {
result.maxSortId = propOrigin('maxSortId', '');
result.smallSortId = propOrigin('smallSortId', '');
result.middleSortId = propOrigin('middleSortId', '');
result.goCartUrl = helpers.urlFormat('/cart/cart');
... ... @@ -1073,7 +1074,7 @@ function _detailDataPkg(origin, uid, vipLevel, cookies) {
}
// 相关推荐词
requestApi.recommendKeywords = this.productAPI.getRecommendKeywords(result.smallSortId, result.skn);
requestApi.recommendKeywords = this.productAPI.getRecommendHotKeywords(result.middleSortId, result.skn);
// 店铺推荐直出(seo需要)
requestApi.shopRecommend = this.productAPI.getShopRecommendAsync(result.skn);
... ... @@ -1484,6 +1485,8 @@ function _removeSalePrice(productInfo) {
* 获取某一个商品详情主页面
*/
function showMainAsync(req, data) {
let headerModelCtx = new HeaderModel(this.ctx);
return co(function* () {
// 获取商品基本信息
let productData = yield this.productAPI.getProductAsync(
... ... @@ -1506,7 +1509,7 @@ function showMainAsync(req, data) {
);
let requestData = yield Promise.all([
HeaderModel.requestHeaderData(data.channel), // 通用头部数据
headerModelCtx.requestHeaderData(data.channel), // 通用头部数据
_getProductIntroAsync.call(this, productId, productSkn), // 商品详细介绍
curUserProduct.call(this, productData), // 商品详细价格
tdk('skn', data.skn, req) // seo
... ...
... ... @@ -12,7 +12,7 @@ const cheerio = require('cheerio');
const helpers = global.yoho.helpers;
const homeService = require('./home-service');
const headerModel = require('../../../doraemon/models/header');
const HeaderModel = require('../../../doraemon/models/header');
const listHandler = require('./list-handler');
const searchHandler = require('./search-handler');
const seoHandler = require('./seo-handler');
... ... @@ -182,8 +182,10 @@ function getGlobalProductListData(params, yoho) {
dps.brand = params.brand;
}
let headerModelCtx = new HeaderModel(this.ctx);
return Promise.props({
header: headerModel.requestHeaderData(yoho.channel, true),
header: headerModelCtx.requestHeaderData(yoho.channel, true),
fullList: this.globalApi.getGlobalProductListAsync(Object.assign({
physical_channel: yoho.channelNum,
limit: 1
... ... @@ -266,8 +268,10 @@ function getGlobalProductListData(params, yoho) {
}
function getGlobalProductDetailData(skn, channelNum, channel) {
let headerModelCtx = new HeaderModel(this.ctx);
return Promise.props({
header: headerModel.requestHeaderData(channel),
header: headerModelCtx.requestHeaderData(channel),
detail: this.globalApi.getGlobalProductDetailAsync(skn, channelNum),
html: this.globalApi.getGlobalProductHtmlAsync(skn, channelNum)
}).then(result => {
... ...
... ... @@ -7,7 +7,7 @@
const utils = '../../../utils';
const SearchApiModel = require('./search-api');
const ShopApiModel = require('./shop-api');
const headerModel = require('../../../doraemon/models/header');
const HeaderModel = require('../../../doraemon/models/header');
const productProcess = require(`${utils}/product-process-simple`);
const searchHandler = require('./search-handler');
const listHandler = require('./list-handler');
... ... @@ -18,6 +18,7 @@ const crypto = global.yoho.crypto;
const _ = require('lodash');
const md5 = require('md5');
const redis = global.yoho.redis;
const cache = global.yoho.cache;
// const limitNum = 60; // 商品每页显示数目
const needParams = ['query', 'msort', 'misort', 'category_id', 'gender', 'shelveTime'];
... ... @@ -33,6 +34,20 @@ const positionId = 10;
// 获取分类左侧广告id
const sortAdsId = 79;
const sortCache = {
key: 'global:yoho:category:name:',
get(categoryId) {
if (!categoryId) {
return Promise.resolve(false);
}
return cache.get(this.key + categoryId);
},
set(categoryId, sortName) {
return cache.set(this.key + categoryId, sortName);
}
};
/**
* 获取商品分类列表数据
*/
... ... @@ -56,9 +71,10 @@ function getListData(params, channel) {
// 调用接口
let apiMethod = [
headerModel.requestHeaderData(channel, true),
this.headerModel.requestHeaderData(channel, true),
this.searchApi.getSortList({}, channel),
this.searchApi.getProductList(searchParams, 'categoryList')
this.searchApi.getProductList(searchParams, 'categoryList'),
sortCache.get(searchParams.category_id)
];
// 搜索分类介绍和广告
... ... @@ -125,13 +141,13 @@ function getListData(params, channel) {
}
// 分类介绍
if (result[3] && result[3].code === 200) {
finalResult.list.sortIntro = searchHandler.handleSortIntro(result[3].data);
if (result[4] && result[4].code === 200) {
finalResult.list.sortIntro = searchHandler.handleSortIntro(result[4].data);
}
// 分类广告
if (result[4] && result[4].code === 200) {
Object.assign(finalResult.list.leftContent, searchHandler.handleSortAds(result[4].data));
if (result[5] && result[5].code === 200) {
Object.assign(finalResult.list.leftContent, searchHandler.handleSortAds(result[5].data));
}
let sortName;
... ... @@ -150,7 +166,20 @@ function getListData(params, channel) {
}
});
const seo = seoHandler.getListSeo(sortList, checkedList);
let extendParam = {};
if (searchParams.category_id) {
let cacheSortName = result[3];
if (!sortName && cacheSortName) {
sortName = cacheSortName;
extendParam.sort = cacheSortName;
} else if (sortName && sortName !== cacheSortName) {
sortCache.set(searchParams.category_id, sortName);
}
}
const seo = seoHandler.getListSeo(sortList, checkedList, extendParam);
if (sortName) {
return redis.all([
... ... @@ -181,7 +210,7 @@ function getListNewData(params, channel) {
// 调用接口
let apiMethod = [
headerModel.requestHeaderData(channel, true),
this.headerModel.requestHeaderData(channel, true),
this.searchApi.getSortList({}, channel),
this.searchApi.getProductList(Object.assign(searchParams), 'newProduct'),
this.searchApi.getWeekNew(params)
... ... @@ -313,7 +342,7 @@ function getBrandData(params, extra, channel) {
// 调用接口
let apiMethod = [
headerModel.requestHeaderData(channel),
this.headerModel.requestHeaderData(channel),
this.searchApi.getSortList(queryBase),
this.searchApi.getProductList(Object.assign(searchParams, queryBase), 'brand')
];
... ... @@ -398,7 +427,7 @@ function getBrandAbout(domain, uid, channel) {
channel = channel || 'boys';
return Promise.all([
headerModel.requestHeaderData(channel),
this.headerModel.requestHeaderData(channel),
this.searchApi.getBrandData({domain: domain})
]).then(result => {
let home;
... ... @@ -478,7 +507,7 @@ function getShopAbout(shopId, uid, channel) {
let resData = {};
return Promise.all([
headerModel.requestHeaderData(channel),
this.headerModel.requestHeaderData(channel),
this.searchApi.getShopDecorator(shopId), // 店铺装修数据
this.searchApi.getShopInfo(shopId, uid)
]).then(result => {
... ... @@ -633,6 +662,7 @@ module.exports = class extends global.yoho.BaseModel {
this.searchApi = new SearchApiModel(ctx);
this.shopApi = new ShopApiModel(ctx);
this.headerModel = new HeaderModel(ctx);
this.getListData = getListData.bind(this);
this.getListNewData = getListNewData.bind(this);
... ...
... ... @@ -4,7 +4,7 @@
*/
'use strict';
const headerModel = require('../../../doraemon/models/header');
const HeaderModel = require('../../../doraemon/models/header');
const NewArriveApiModel = require('./newArrive-api');
const _ = require('lodash');
... ... @@ -164,8 +164,9 @@ function index(req) {
let cateId = req.query.cateId || '';
let headerModelCtx = new HeaderModel(this.ctx);
let apiMethod = [
headerModel.requestHeaderData(channel),
headerModelCtx.requestHeaderData(channel),
this.api.recShop(shopParams),
this.api.recBrand(params),
this.api.recList(Object.assign({}, params)), // 获取品类
... ...
... ... @@ -14,7 +14,7 @@ const List = require('./list');
const outletsProcess = require('./outlets-handler');
const OutletsApiModel = require('./outlets-api');
const productProcess = require(`${utils}/product-process`);
const headerModel = require('../../../doraemon/models/header');
const HeaderModel = require('../../../doraemon/models/header');
const _ = require('lodash');
const publicHandler = require('./public-handler');
... ... @@ -37,7 +37,7 @@ const channelCode = {
function getOutletsIndexData(params, channel) {
return Promise.all([
headerModel.requestHeaderData('outlets'),
this.headerModel.requestHeaderData('outlets'),
this.outletsApi.getChannelResouceData({content_code: channelCode.index}),
this.outletsApi.getOutletsActivityOrigin({type: '1', channel: channel}), // 获取限时活动列表
this.outletsApi.getOutletsActivityOrigin({type: '2', channel: channel}), // 获取即将结束列表
... ... @@ -141,7 +141,7 @@ function getOutletsChannelData(params, channel) {
let apiArr = [
// 获取头部数据
headerModel.requestHeaderData('outlets'),
this.headerModel.requestHeaderData('outlets'),
// 获取频道资源位
this.outletsApi.getChannelResouceData({content_code: channelCode[channel]}),
... ... @@ -230,7 +230,7 @@ function getOutletsChannelData(params, channel) {
*/
function getOutletsSpecialData(params, channel) {
return Promise.all([
headerModel.requestHeaderData('outlets'),
this.headerModel.requestHeaderData('outlets'),
this.outletsApi.getOutletsActivityOrigin({ // 获取活动信息
id: params.id
})
... ... @@ -269,7 +269,7 @@ function getOutletsSpecialData(params, channel) {
*/
function getOutletsCategoryData(params, channel) {
return Promise.all([
headerModel.requestHeaderData('outlets')
this.headerModel.requestHeaderData('outlets')
]).then(result => {
let finalResult = {
headerData: Object.assign(result[0].headerData, {
... ... @@ -303,6 +303,7 @@ module.exports = class extends global.yoho.BaseModel {
this.list = new List(ctx);
this.outletsApi = new OutletsApiModel(ctx);
this.headerModel = new HeaderModel(ctx);
this.getOutletsIndexData = getOutletsIndexData.bind(this);
this.getOutletsChannelData = getOutletsChannelData.bind(this);
... ...
... ... @@ -6,7 +6,6 @@
*/
'use strict';
const api = global.yoho.API;
const Promise = require('bluebird');
const querystring = require('querystring');
... ... @@ -20,7 +19,7 @@ const seoHandler = require('./seo-handler');
const productProcess = require(`${global.utils}/product-process`);
const imageHandler = require(`${global.utils}/images`).getImageUrl;
const _ = require('lodash');
const headerModel = require('../../../doraemon/models/header');
const HeaderModel = require('../../../doraemon/models/header');
const handleStaticUrl = require(`${global.utils}/parameter`).fullParamToMinPath;
... ... @@ -145,8 +144,8 @@ function getSaleGoodsData(params, vipLevel) {
* @return {[type]} [description]
*/
function getSaleIndexData(channel) {
return api.all([
headerModel.requestHeaderData(channel),
return Promise.all([
this.headerModel.requestHeaderData(channel),
this.saleApi.getSaleActivityList('', channel),
this.saleApi.getSaleBannerList(contentCode[channel].sale),
this.saleApi.getSaleGoodsList({channel: channel, saleType: '2', limit: '1'}), // 会员专享分类
... ... @@ -238,7 +237,7 @@ function getSaleOthersData(params, channel) {
if (params.saleType === '2') { // 会员专区
promiseObject = [
headerModel.requestHeaderData(channel, true),
this.headerModel.requestHeaderData(channel, true),
this.saleApi.getSaleGoodsList(params),
this.saleApi.getSaleBannerList(contentCode[channel].vip),
this.saleApi.getSaleGoodsList({saleType: '2', limit: '1', channel: channel}),
... ... @@ -247,7 +246,7 @@ function getSaleOthersData(params, channel) {
baseUrl += '/vip';
} else { // 最新降价
promiseObject = [
headerModel.requestHeaderData(channel, true),
this.headerModel.requestHeaderData(channel, true),
this.saleApi.getSaleGoodsList(params),
this.saleApi.getSaleBannerList(contentCode[channel].newSale),
this.saleApi.getSaleGoodsList({limit: '1', channel: channel})
... ... @@ -255,7 +254,7 @@ function getSaleOthersData(params, channel) {
baseUrl += '/newSale';
}
return api.all(promiseObject).then(result => {
return Promise.all(promiseObject).then(result => {
let finalResult = result[0];
// 获取商品数据
... ... @@ -380,8 +379,8 @@ function _setSaleDiscountData(info) {
* @return {[type]} [description]
*/
function getSaleDiscountData(params, channel) {
return api.all([
headerModel.requestHeaderData(channel),
return Promise.all([
this.headerModel.requestHeaderData(channel),
this.saleApi.getSaleActivityList(params, channel)
]).then(result => {
let finalResult = result[0];
... ... @@ -408,7 +407,7 @@ function getSaleDiscountData(params, channel) {
}
// 这里把 channel 全都处理掉,因为根据channel查小分类,而传入商品池时,不需要
return api.all([
return Promise.all([
this.saleApi.getSaleGoodsList({
channel: null,
saleType: '3',
... ... @@ -473,8 +472,8 @@ function getSaleDiscountData(params, channel) {
function getSalebreakingYardsData(params, channel) {
const baseUrl = `/${_.toLower(channel)}-sale/breakingYards`;
return api.all([
headerModel.requestHeaderData(channel, true),
return Promise.all([
this.headerModel.requestHeaderData(channel, true),
this.saleApi.getSaleBannerList(contentCode[channel].breakCode),
this.saleApi.getSalebreakingYardsSortList(params)
]).then(result => {
... ... @@ -502,7 +501,7 @@ function getSalebreakingYardsData(params, channel) {
});
}
return api.all([
return Promise.all([
this.saleApi.getSaleGoodsList({
channel: channel,
saleType: '5', // app 与 pc 有冲突,为 PC 加一个 5 的选项
... ... @@ -593,7 +592,7 @@ function getSaleSpecialData(id, params, channel) {
latestWalk: 6
},
apiList = [
headerModel.requestHeaderData(channel),
this.headerModel.requestHeaderData(channel),
this.searchApi.getSortList(defaultParam)
];
... ... @@ -685,6 +684,7 @@ module.exports = class extends global.yoho.BaseModel {
this.saleApi = new SaleApiModel(ctx);
this.searchApi = new SearchApiModel(ctx);
this.headerModel = new HeaderModel(ctx);
this.getSaleGoodsData = getSaleGoodsData.bind(this);
this.getSaleIndexData = getSaleIndexData.bind(this);
... ...
... ... @@ -5,8 +5,6 @@
'use strict';
const utils = '../../../utils';
const api = global.yoho.API;
const Promise = require('bluebird');
const co = Promise.coroutine;
const helpers = global.yoho.helpers;
... ... @@ -15,7 +13,7 @@ const redis = global.yoho.redis;
const SaleApiModel = require('./sale-api');
const SearchApiModel = require('./search-api');
const headerModel = require('../../../doraemon/models/header');
const HeaderModel = require('../../../doraemon/models/header');
const productProcess = require(`${utils}/product-process-simple`);
const searchHandler = require('./search-handler');
const hotBrandsModel = require('../../../doraemon/models/hot-brands');
... ... @@ -152,13 +150,13 @@ function getSearchData(params, channel) {
// 调用接口
let apiMethod = [
headerModel.requestHeaderData(channel),
this.headerModel.requestHeaderData(channel),
this.searchApi.getSortList(Object.assign({}, searchParams, {msort: '', misort: '', sort: ''})),
this.searchApi.getProductList(searchParams, 'fuzzySearch'),
this.searchApi.getShopList(params)
];
return api.all(apiMethod).then(result => {
return Promise.all(apiMethod).then(result => {
if (_.get(result, '[2].data.isChangedQuery', '') === 'Y') {
return this.searchApi.getSortList(Object.assign({}, searchParams, {
msort: '',
... ... @@ -457,12 +455,12 @@ function getSearchKeywordData(params, channel) {
// 调用接口
let apiMethod = [
headerModel.requestHeaderData(channel),
this.headerModel.requestHeaderData(channel),
this.searchApi.getSuggest({keyword: searchParams.query.substring(0, 2)}),
this.searchApi.getSeoProductList(searchParams, 'fuzzySearch')
];
return api.all(apiMethod).then(result => {
return Promise.all(apiMethod).then(result => {
return _setSearchKeywordData(result, params, channel);
});
... ... @@ -533,6 +531,7 @@ module.exports = class extends global.yoho.BaseModel {
this.searchApi = new SearchApiModel(ctx);
this.saleApi = new SaleApiModel(ctx);
this.headerModel = new HeaderModel(ctx);
this.getKeyActivity = getKeyActivity.bind(this);
this.getSearchData = getSearchData.bind(this);
... ...
... ... @@ -85,8 +85,8 @@ const listDefaultTdk = {
* @param checked
* @returns {{title: string, keywords: string, description: string}}
*/
const getListSeo = (sorts, checked) => {
let {brand, channel, color, style, sort} = getSeoCheckedParamsName(sorts, checked);
const getListSeo = (sorts, checked, extend = {}) => {
let {brand, channel, color, style, sort} = Object.assign(getSeoCheckedParamsName(sorts, checked), extend);
if (brand && _.indexOf(brand, '、') > -1) {
brand = '';
... ...
... ... @@ -5,7 +5,7 @@ const helpers = global.yoho.helpers;
const logger = global.yoho.logger;
const _ = require('lodash');
const headerModel = require('../../../doraemon/models/header');
const HeaderModel = require('../../../doraemon/models/header');
const SearchApi = require('./search-api');
const searchHandler = require('./search-handler');
... ... @@ -13,6 +13,17 @@ const seoHandler = require('./seo-handler');
const utils = '../../../utils';
const productProcess = require(`${utils}/product-process-simple`);
const _handleImageUrl = (url) => {
if (url) {
let imgArr = _.split(url, '?', 1);
imgArr.push('imageView2/1/w/{width}/h/{height}/q/90');
url = imgArr.join('?');
}
return url;
};
const _setHotKeywordData = (result, params, channel) => {
let changeQuery = Object.assign({}, params);
let finalResult = {
... ... @@ -105,8 +116,10 @@ module.exports = class extends global.yoho.BaseModel {
searchParams.need_filter = 'yes';
let headerModelCtx = new HeaderModel(this.ctx);
return Promise.all([
headerModel.requestHeaderData(channel, true),
headerModelCtx.requestHeaderData(channel, true),
this.searchApi.getSeoProductList(searchParams, 'fuzzySearch'),
this.searchApi.getSeoProductList(Object.assign(searchParams, {
order: 's_n_desc',
... ... @@ -130,23 +143,26 @@ module.exports = class extends global.yoho.BaseModel {
}
if (!_.get(keyword, 'name')) {
return Promise.reject(`cannot find hot keywords by id(${id})`);
logger.error(`cannot find hot keywords by id(${id})`);
return false;
}
params.query = keyword.name;
return this.getSearchProduct(params, channel).then(result => {
const keyNum = 10;
let hotKeys = (keyword.data || []).map(val => {
val.href = helpers.urlFormat(`/hot/${val.id}.html`);
return val;
});
let seoTDK = seoHandler.getHotKeywordsSeo(keyword.name, _.get(result, 'product.totalCount', '多'));
keyword.list = _.take(hotKeys, 6);
keyword.goods_img = _handleImageUrl(keyword.goods_img);
keyword.list = _.take(hotKeys, keyNum);
keyword.describe = keyword.describe || seoTDK.description;
Object.assign(result, {
hotKeys: _.drop(hotKeys, 6),
hotKeys: _.drop(hotKeys, keyNum),
keyword: keyword
}, seoTDK);
... ...
... ... @@ -14,7 +14,7 @@ const shopHandler = require('./shop-handler');
const searchHandler = require('./search-handler');
const listHandler = require('./list-handler');
const seoHandler = require('./seo-handler');
const headerModel = require('../../../doraemon/models/header');
const HeaderModel = require('../../../doraemon/models/header');
const productProcess = require('../../../utils/product-process-simple');
const handleStaticUrl = require(`${global.utils}/parameter`).fullParamToMinPath;
... ... @@ -63,7 +63,7 @@ function _getShopData(channel, params, shopInfo) {
return co(function* () {
let result = yield Promise.props({
header: headerModel.requestHeaderData(channel), // 头部数据
header: this.headerModel.requestHeaderData(channel), // 头部数据
sort: this.searchApi.getSortList({shop_id: shopId}),
decorator: this.searchApi.getShopDecorator(shopId), // 店铺装修数据
product: this.searchApi.getProductList(Object.assign({
... ... @@ -225,7 +225,7 @@ function _getBaseShopData(channel, params, shopInfo) {
return co(function* () {
let result = yield Promise.props({
header: headerModel.requestHeaderData(channel, true), // 头部数据
header: this.headerModel.requestHeaderData(channel, true), // 头部数据
sort: this.searchApi.getSortList({shop_id: shopId}),
decorator: this.searchApi.getShopDecorator(shopId), // 店铺装修数据
product: this.searchApi.getProductList(Object.assign(searchParams,
... ... @@ -425,7 +425,7 @@ function _getShopListData(channel, params, shopInfo) {
return co(function* () {
let result = yield Promise.props({
header: headerModel.requestHeaderData(channel, true), // 头部数据
header: this.headerModel.requestHeaderData(channel, true), // 头部数据
shopInfo: shopInfo ? shopInfo : this.api.getShopInfo(shopId), // 店铺介绍
decorator: this.searchApi.getShopDecorator(shopId), // 店铺装修数据
sort: this.searchApi.getSortList({shop_id: shopId}),
... ... @@ -610,6 +610,7 @@ module.exports = class extends global.yoho.BaseModel {
super(ctx);
this.api = new Api(ctx);
this.searchApi = new SearchApi(ctx);
this.headerModel = new HeaderModel(ctx);
this._getShopData = _getShopData.bind(this);
this._getBaseShopData = _getBaseShopData.bind(this);
... ...
... ... @@ -16,8 +16,7 @@ const SearchApiModel = require('./search-api');
const stuHandler = require('./students-handler');
const helpers = global.yoho.helpers;
const crypto = global.yoho.crypto;
const headerModel = require('../../../doraemon/models/header');
const serviceApi = global.yoho.ServiceAPI;
const HeaderModel = require('../../../doraemon/models/header');
const productProcess = require(`${utils}/product-process`);
const searchHandler = require('./search-handler');
... ... @@ -34,10 +33,16 @@ const studentsCode = '989396a17443bf61e3e269702e51ef04'; // h5 a83b7d55324fb65f9
*/
function getStudentsData(channel, req) {
let apiMethod = [
headerModel.requestHeaderData(channel),
this.headerModel.requestHeaderData(channel),
// 资源位数据
serviceApi.get('operations/api/v5/resource/get', {content_code: studentsCode}),
this.get({
url: 'operations/api/v5/resource/get',
data: {
content_code: studentsCode
},
api: global.yoho.ServiceAPI
}),
// 认证总数
this.studentsApi.getVerifiedTotal(),
... ... @@ -187,7 +192,7 @@ function getStudentsList(params, channel) {
// 调用接口
let apiMethod = [
headerModel.requestHeaderData(channel),
this.headerModel.requestHeaderData(channel),
this.searchApi.getSortList(Object.assign({}, {msort: '', misort: ''})),
this.studentsApi.getStudentsProduct(searchParams)
];
... ... @@ -253,7 +258,7 @@ module.exports = class extends global.yoho.BaseModel {
this.studentsApi = new StudentsApiModel(ctx);
this.searchApi = new SearchApiModel(ctx);
this.headerModel = new HeaderModel(ctx);
/**
* 获取学校地区数据
... ...
... ... @@ -22,7 +22,7 @@
{{/if}}
</div>
</div>
<img class="thumb" src="{{image2 goods_img}}" alt="{{name}}">
<img class="thumb" src="{{image2 goods_img w=300 h=300}}" alt="{{name}}">
{{/ keyword}}
</div>
... ...
... ... @@ -21,7 +21,7 @@ const index = (req, res, next) => {
footerTop: true
};
headerModel.requestHeaderData(channel).then(result => {
req.ctx(headerModel).requestHeaderData(channel).then(result => {
responseData.headerData = result.headerData;
res.render('settled', responseData);
... ... @@ -52,7 +52,8 @@ const apply = (req, res, next) => {
footerTop: true
};
Promise.all([headerModel.requestHeaderData(channel), shopService.applyAction()]).then(result => {
Promise.all([req.ctx(headerModel).requestHeaderData(channel),
req.ctx(shopService).applyAction()]).then(result => {
responseData.headerData = result[0].headerData;
responseData.oneCategory = result[1];
responseData.uploadKey = base64StrEncode(authcode(JSON.stringify(adpic),
... ... @@ -75,7 +76,7 @@ const getTwoCategoryAction = (req, res, next) => {
return data;
}
shopService.getTwoCategory(id).then(result => {
req.ctx(shopService).getTwoCategory(id).then(result => {
res.json(result);
}).catch(next);
};
... ... @@ -174,7 +175,7 @@ const applysave = (req, res, next) => {
param.storeInfo = JSON.stringify(storeInfo);
param.uid = uid;
shopService.insertApply(param).then(result => {
req.ctx(shopService).insertApply(param).then(result => {
res.json(result);
}).catch(next);
};
... ...
'use strict';
const _ = require('lodash');
const api = global.yoho.API;
/**
* 获取一级品类
* @return type []
*/
const applyAction = () => {
return api.get('', {
method: 'app.category.queryMax'
function applyAction() {
return this.get({
data: {
method: 'app.category.queryMax'
}
}).then((result) => {
if (result.code && result.code === 200) {
let list = [];
... ... @@ -25,17 +24,19 @@ const applyAction = () => {
return list;
}
});
};
}
/**
* 获取二级品类
* @return type []
*/
const getTwoCategory = (id) => {
function getTwoCategory(id) {
return api.get('', {
method: 'app.category.queryMin',
parent_id: id
return this.get({
data: {
method: 'app.category.queryMin',
parent_id: id
}
}).then((result) => {
if (result.code && result.code === 200) {
let list = [];
... ... @@ -52,50 +53,56 @@ const getTwoCategory = (id) => {
return result;
}
});
};
}
/**
* 添加入驻申请保存
* @return type []
*/
const insertApply = (param) => {
function insertApply(param) {
return api.get('', {
method: 'app.shops.insertApply',
brandName: param.brandName,
registerStatus: param.registerStatus,
sellerName: param.sellerName,
sellerAddress: param.sellerAddress,
zipCode: param.zipCode,
contacts: param.contacts,
contactPhone: param.contactPhone,
contactEmail: param.contactEmail,
sellerRole: param.sellerRole,
brandWebsite: param.brandWebsite,
onlineShopWebsite: param.onlineShopWebsite,
categoryInfo: param.categoryInfo,
billingCycle: param.billingCycle,
warehouseAddress: param.warehouseAddress,
producer: param.producer,
invoiceType: param.invoiceType,
newCycle: param.newCycle,
quarterNum: param.quarterNum,
supplyCycle: param.supplyCycle,
haveStore: param.haveStore,
storeInfo: param.storeInfo,
brandMaterial: param.brandMaterial,
goodsMaterial: param.goodsMaterial,
uid: param.uid
return this.get({
data: {
method: 'app.shops.insertApply',
brandName: param.brandName,
registerStatus: param.registerStatus,
sellerName: param.sellerName,
sellerAddress: param.sellerAddress,
zipCode: param.zipCode,
contacts: param.contacts,
contactPhone: param.contactPhone,
contactEmail: param.contactEmail,
sellerRole: param.sellerRole,
brandWebsite: param.brandWebsite,
onlineShopWebsite: param.onlineShopWebsite,
categoryInfo: param.categoryInfo,
billingCycle: param.billingCycle,
warehouseAddress: param.warehouseAddress,
producer: param.producer,
invoiceType: param.invoiceType,
newCycle: param.newCycle,
quarterNum: param.quarterNum,
supplyCycle: param.supplyCycle,
haveStore: param.haveStore,
storeInfo: param.storeInfo,
brandMaterial: param.brandMaterial,
goodsMaterial: param.goodsMaterial,
uid: param.uid
}
}).then((result) => {
if (result.code && result.code === 200) {
return result;
}
});
};
}
module.exports = class extends global.yoho.BaseModel {
constructor(ctx) {
super(ctx);
module.exports = {
applyAction,
getTwoCategory,
insertApply
this.applyAction = applyAction.bind(this);
this.getTwoCategory = getTwoCategory.bind(this);
this.insertApply = insertApply.bind(this);
}
};
... ...
... ... @@ -21,10 +21,10 @@ module.exports = {
cookieDomain: '.yohobuy.com',
domains: {
// test3
singleApi: 'http://api-test3.yohops.com:9999/',
api: 'http://api-test3.yohops.com:9999/',
service: 'http://api-test3.yohops.com:9999/',
serviceNotify: 'http://api-test3.yohops.com:9999/',
singleApi: 'http://api-test3.dev.yohocorp.com/',
api: 'http://api-test3.dev.yohocorp.com/',
service: 'http://api-test3.dev.yohocorp.com/',
serviceNotify: 'http://api-test3.dev.yohocorp.com/',
global: 'http://global-test-soa.yohops.com:9999/',
platformApi: 'http://192.168.102.48:8088/',
yohoNowApi: 'http://yohonow-test.yohops.com:9999/',
... ... @@ -81,9 +81,6 @@ module.exports = {
},
useOneapm: false,
useCache: true,
interfaceShunt: {
open: false
},
loggers: {
infoFile: {
name: 'info',
... ... @@ -218,10 +215,6 @@ if (isProduction) {
},
useOneapm: true,
useCache: true,
interfaceShunt: {
open: false,
url: 'http://123.206.2.55/strategy'
},
zookeeperServer: 'web.zookeeper.yohoops.org:2181',
redis: {
connect: {
... ...
... ... @@ -2,15 +2,36 @@
wordir=$2
cd $wordir
rm -rf yohobuy-node.tar.gz
yarn --production=false
if [[ $1 == "TEST1" ]] || [[ $1 == "TEST2" ]] || [[ $1 == "TEST3" ]]
if [[ $1 == "yoho-gray" ]]
then
yarn build
yarn --production=false
else
yarn
fi
if [[ $1 == "yoho-gray" ]]
then
rm -rf public/dist
yarn build
yarn upload -f
rm -rf public/dist
yarn build
if [[ $? == 1 ]]
then
echo "build failed"
exit 1
fi
yarn yo-cli upload -f
if [[ $? == 1 ]]
then
echo "file upload failed"
exit 1
fi
fi
if [[ $1 == "TEST1" ]] || [[ $1 == "TEST2" ]] || [[ $1 == "TEST3" ]]
then
yarn build
fi
tar -czvf yohobuy-node.tar.gz *
... ...
... ... @@ -34,7 +34,7 @@ exports.notFound = () => {
});
}
headerModel.requestHeaderData(req.yoho.channel).then((result) => {
req.ctx(headerModel).requestHeaderData(req.yoho.channel).then((result) => {
return res.status(404).render('error/404', {
module: 'common',
page: 'error',
... ... @@ -148,7 +148,7 @@ exports.serverError = () => {
});
};
return headerModel.requestHeaderData(req.yoho.channel).then(renderErrPage).catch(() => {
return req.ctx(headerModel).requestHeaderData(req.yoho.channel).then(renderErrPage).catch(() => {
renderErrPage();
});
}
... ...
... ... @@ -123,6 +123,8 @@ module.exports = (req, res, next) => {
if (exclusion) {
return next();
} else if (!allPass && policy) {
logger.info(`limit remote ip: ${remoteIp}; ua: ${req.header('User-Agent')}; uid: ${req.user.uid}`);
policy(req, res, next);
} else {
return next();
... ...
... ... @@ -43,6 +43,7 @@ module.exports = () => {
return (req, res, next) => {
let domain = 'm.yohobuy.com';
let proRegNew = /^\/product\/([\d]+).html(.*)/;
let hotReg = /^\/hot\/([\d]+).html(.*)/;
if (!req.xhr) {
let url = _.head(_.split(req.url, '?'));
... ... @@ -56,6 +57,8 @@ module.exports = () => {
data.mobileRefer = `//${domain}/guang?${queryString.stringify(req.query)}`;
} else if (proRegNew.test(url)) {
data.mobileRefer = url.replace(proRegNew, `//${domain}/product/$1.html$2`);
} else if (hotReg) {
data.mobileRefer = `//${domain}/mip${url}`;
}
// 设置不需要跳转页面
... ...
... ... @@ -8,7 +8,6 @@
const _ = require('lodash');
const api = global.yoho.API;
const serviceApi = global.yoho.ServiceAPI;
const helpers = global.yoho.helpers;
const Handlebars = require('handlebars');
... ... @@ -196,24 +195,6 @@ const setHeaderData = (resData, type) => (
}
);
const getHotSearchAsync = (channel) => {
return api.get('', {method: 'app.search.getTerms', yh_channel: channel}, {
cache: 600,
code: 200
});
};
const getHeaderNavAsync = () => {
return serviceApi.get('operations/api/v6/category/getCategory', {}, {
cache: true,
code: 200
});
};
/**
* 请求头部数据
* @param {String} 频道类型
... ... @@ -222,81 +203,120 @@ const getHeaderNavAsync = () => {
const cacheHeaderHtml = {};
const THIRTY_MINUTES = 1000 * 60 * 10;
async function requestHeaderData(type, noH1) {
const usableType = ['boys', 'girls', 'kids', 'lifestyle'];
let resData = {disHeaderH1: noH1};
let _html;
if (usableType.indexOf(type) < 0) {
type = usableType[0];
module.exports = class extends global.yoho.BaseModel {
constructor(ctx) {
super(ctx);
}
let cacheKey = noH1 ? `${type}_noh1` : type;
let cacheData = cacheHeaderHtml[cacheKey];
getHotSearchAsync(channel) {
return this.get({
data: {
method: 'app.search.getTerms',
yh_channel: channel
},
param: {
cache: 600,
code: 200
}
});
}
if (!cacheData) {
cacheHeaderHtml[cacheKey] = [];
cacheData = [];
getHeaderNavAsync() {
return this.get({
url: 'operations/api/v6/category/getCategory',
data: {},
param: {
cache: true,
code: 200
},
api: serviceApi
});
}
async requestHeaderData(type, noH1) {
const usableType = ['boys', 'girls', 'kids', 'lifestyle'];
let resData = {disHeaderH1: noH1};
let _html;
if (_.isEmpty(cacheData[0]) || ((new Date() - cacheData[1]) > THIRTY_MINUTES)) {
let channelNum = (function() {
switch (type) {
case 'boys':
return 1;
case 'girls':
return 2;
case 'kids':
return 3;
case 'lifestyle':
return 4;
default:
return 1;
}
}());
if (usableType.indexOf(type) < 0) {
type = usableType[0];
}
let res = await Promise.all([
getHeaderNavAsync(),
getHotSearchAsync(channelNum)
]);
let cacheKey = noH1 ? `${type}_noh1` : type;
resData.headerData = {};
let cacheData = cacheHeaderHtml[cacheKey];
if (res[0] && res[0].data) {
Object.assign(resData.headerData, setHeaderData(res[0].data, type));
} else {
logger.error('header api data empty');
if (!cacheData) {
cacheHeaderHtml[cacheKey] = [];
cacheData = [];
}
if (res[1] && res[1].data) {
resData.headerData.defaultSearch = _.get(res[1], 'data.defaultTerms[0].content', '');
resData.headerData.hotTerms = _.map(_.get(res[1], 'data.hotTerms', []), (value) => {
return {
href: helpers.urlFormat('', {query: value.content}, 'search'),
content: value.content,
sort: value.sort,
status: value.status,
type: value.type
};
});
} else {
logger.error('search terms api data empty');
}
if (_.isEmpty(cacheData[0]) || ((new Date() - cacheData[1]) > THIRTY_MINUTES)) {
let channelNum = (function() {
switch (type) {
case 'boys':
return 1;
case 'girls':
return 2;
case 'kids':
return 3;
case 'lifestyle':
return 4;
default:
return 1;
}
}());
let res = await Promise.all([
this.getHeaderNavAsync(),
this.getHotSearchAsync(channelNum)
]);
resData.headerData = {};
if (res[0] && res[0].data) {
Object.assign(resData.headerData, setHeaderData(res[0].data, type));
} else {
logger.error('header api data empty');
}
if (_.isEmpty(_.get(resData, 'headerData.navbars')) && cacheData[0]) {
_html = cacheData[0];
if (res[1] && res[1].data) {
resData.headerData.defaultSearch = _.get(res[1], 'data.defaultTerms[0].content', '');
resData.headerData.hotTerms = _.map(_.get(res[1], 'data.hotTerms', []), (value) => {
return {
href: helpers.urlFormat('', {query: value.content}, 'search'),
content: value.content,
sort: value.sort,
status: value.status,
type: value.type
};
});
} else {
logger.error('search terms api data empty');
}
if (_.isEmpty(_.get(resData, 'headerData.navbars')) && cacheData[0]) {
_html = cacheData[0];
} else {
_html = template(resData);
cacheHeaderHtml[cacheKey] = [_html, new Date()];
}
} else {
_html = template(resData);
cacheHeaderHtml[cacheKey] = [_html, new Date()];
_html = cacheData[0];
}
} else {
_html = cacheData[0];
return Promise.resolve({headerData: _html});
}
return Promise.resolve({headerData: _html});
}
getSubNavGroupData(type) {
const usableType = ['boys', 'girls', 'kids', 'lifestyle'];
module.exports = {
requestHeaderData
if (usableType.indexOf(type) < 0) {
type = usableType[0];
}
return this.getHeaderNavAsync().then(result => {
return getSubNavGroup(result.data, type) || [];
});
}
};
... ...
... ... @@ -33,6 +33,14 @@
{{/ifand}}
</script>
<script>
{{#ifand isProduction pc.open.webperf}}
!function(t){function n(r){if(e[r])return e[r].exports;var i=e[r]={exports:{},id:r,loaded:!1};return t[r].call(i.exports,i,i.exports,n),i.loaded=!0,i.exports}var e={};n.m=t,n.c=e,n.p="",n(0)}({0:function(t,n,e){var r=e(1),i=e(2),o="_perfLog",a=e(16),c=e(17);({init:function(t){this.debug=t,this.dataList=[],this.isRunning=!1,a.init(this.debug),c.init(this.debug),this.report();var n=this;window.addEventListener&&window.addEventListener("load",function(){setTimeout(function(){n.collect()},0)})},collect:function(){try{var t=c.collect(),n=a.collect();this.chunkWrite(t);for(var e=0;e<n.length;e++)this.chunkWrite(n[e])}catch(t){this.debug&&console.log(t)}},getMeta:function(){return{pt:encodeURIComponent(window.location.href),u:i.getUid(),ud:i.getUdid(),rid:i.getReqId(),r:i.getRoute()}},jsonConcat:function(t,n){for(var e in n)t[e]=n[e];return t},write:function(t){this.jsonConcat(t,this.getMeta());var n=JSON.parse(r(o)||"[]");n.push(t),r(o,JSON.stringify(n)),n.length>=5&&this.report()},report:function(){var t=this,n=JSON.parse(r(o)||"[]"),e=i.stringify(n);i.report(e,function(){t.clear()})},clear:function(){r(o,"[]")},chunkWrite:function(t){function n(){if(0!==e.dataList.length){var t=e.dataList.shift();e.write(t),setTimeout(n,10)}}var e=this;this.dataList.push(t),this.isRunning||(this.isRunning=!0,n())}}).init()},1:function(t,n){t.exports=function(t,n,e){if(void 0===n){var r=null;if(document.cookie)for(var i=document.cookie.split(";"),o=0;o<i.length;o++){var a=(i[o]||"").trim();if(a.substring(0,t.length+1)==t+"="){r=decodeURIComponent(a.substring(t.length+1));break}}return r}e=e||{},null===n&&(n="",e.expires=-1);var c="";if(e.expires&&("number"==typeof e.expires||e.expires.toUTCString)){var s;"number"==typeof e.expires?(s=new Date,s.setTime(s.getTime()+24*e.expires*60*60*1e3)):s=e.expires,c="; expires="+s.toUTCString()}var u=e.path?"; path="+e.path:"",f=e.domain?"; domain="+e.domain:"",d=e.secure?"; secure":"";document.cookie=[t,"=",encodeURIComponent(n),c,u,f,d].join("")}},2:function(t,n,e){var r=e(1),i=window._yohoAppName||"unknown",o={config:{reportUrl:"//badjs.yoho.cn/apm/yas2.gif"},stringify:function(t){for(var n=[],e=0;e<t.length;e++){var r=t[e],i=[];for(var o in r)r.hasOwnProperty(o)&&i.push(o+"::"+r[o]);n.push(i.join("$$"))}return n.join("**")},report:function(t,n){if(t){(new Image).src=this.config.reportUrl+"?s="+i+"&l="+t+"&t="+(new Date).getTime(),n&&n()}},getUdid:function(){return r("udid")||""||0},getUid:function(){return(r("_UID")||"").split("::")[1]||0},getReqId:function(){return r("docreqid")||0},getRoute:function(){return window._router||""}};t.exports=o},16:function(t,n){var e={init:function(t){if(this.enable=!0,this.debug=t,!("performance"in window&&"getEntriesByType"in window.performance&&window.performance.getEntriesByType("resource")instanceof Array))return void(this.enable=!1);this.whiteList=[/\/\/img\d*.static.yhbimg.com/,/\/\/cdn.yoho.cn/]},print:function(){var t=document.getElementById("debug"),n=this.formatDebugInfo();if(t)t.innerHTML+=n;else{var e=document.createElement("div");e.id="debug",e.innerHTML=n,document.body.appendChild(e)}},formatDebugInfo:function(){for(var t="<p>resource object: <br/>",n=this.getData(),e=0;e<n.length;e++)t+=JSON.stringify(n[e],null,2)+"<br/>";return t+="</p>"},filter:function(t){for(var n=0;n<this.whiteList.length;n++)if(this.whiteList[n].test(t))return!0;return!1},getData:function(){var t=window.performance.getEntriesByType("resource"),n=[],e={};for(var r in t){var i=t[r];if(this.filter(i.name)){var o={tp:"resource",mtp:i.initiatorType||"unknown",id:i.name||"unknown",dt:Math.floor(i.domainLookupEnd-i.domainLookupStart||0),tt:Math.floor(i.connectEnd-i.connectStart||0),rt:Math.floor(i.responseEnd-i.responseStart||0),rrt:Math.floor(i.responseEnd-i.fetchStart||0)};i.initiatorType in e?e[i.initiatorType].push(o):e[i.initiatorType]=[o]}}for(var a in e){for(var c=e[a],s=c.length,u={tp:"rs",mtp:a,dt:0,tt:0,rt:0,rrt:0},f=0;f<c.length;f++){var d=c[f];u.dt+=d.dt,u.tt+=d.tt,u.rt+=d.rt,u.rrt+=d.rrt}u.dt=Math.floor(u.dt/s),u.tt=Math.floor(u.tt/s),u.rt=Math.floor(u.rt/s),u.rrt=Math.floor(u.rrt/s),n.push(u)}return n},collect:function(){return this.enable?(this.debug&&this.print(),this.getData()):[]}};t.exports=e},17:function(t,n){var e=function(){function t(){return{tp:"tm",mtp:"html",dt:Math.floor(n),tt:Math.floor(e),rt:Math.floor(r),domt:Math.floor(o),et:Math.floor(i),ot:Math.floor(a),rtt:Math.floor(c),sw:screen.width||1,sh:screen.height||1,pf:navigator.platform||"unknown"}}var n=performance.timing.domainLookupEnd-(performance.timing.domainLookupStart||0),e=performance.timing.connectEnd-(performance.timing.connectStart||0),r=performance.timing.responseEnd-(performance.timing.responseStart||0),i=performance.timing.responseStart-(performance.timing.navigationStart||0),o=performance.timing.domContentLoadedEventEnd-(performance.timing.domLoading||0),a=performance.timing.domContentLoadedEventEnd-(performance.timing.navigationStart||0),c=(performance.timing.loadEventEnd||performance.timing.domComplete)-(performance.timing.navigationStart||0);return{collect:function(){return t()},print:function(){var t=document.getElementById("debug"),n=this.formatDebugInfo();if(t)t.innerHTML+=n;else{var e=document.createElement("div");e.id="debug",e.innerHTML=n,document.body.appendChild(e)}},formatDebugInfo:function(){var t="<p>";return t+="timing object : "+JSON.stringify(this.collect(),null,2)+"<br/>",t+="url: "+decodeURIComponent(window.location.href)+"<br/>",t+="</p>"}}},r={init:function(t){if(this.enable=!0,this.debug=t,!("performance"in window))return void(this.enable=!1)},collect:function(){if(this.enable){var t=e(),n=t.collect();return this.debug&&t.print(),n}}};t.exports=r}});
{{/ifand}}
</script>
{{#if devEnv}}
<link rel="stylesheet" href="//{{devHost}}:5002/base.css">
<link rel="stylesheet" href="//{{devHost}}:5002/{{#if cssModule}}{{cssModule}}.css{{^}}{{module}}.css{{/if}}">
... ...
{
"name": "yohobuy-node",
"version": "6.6.0",
"version": "6.6.2",
"private": true,
"description": "A New Yohobuy Project With Express",
"repository": {
... ... @@ -12,7 +12,6 @@
"dev": "nodemon -e js,hbs -i public/ app.js",
"static": "webpack-dev-server --config ./public/build/webpack.dev.config.js",
"build": "webpack --config ./public/build/webpack.prod.config.js",
"upload": "yo-cli upload",
"online": "NODE_ENV=\"production\" node app.js",
"debug": "DEBUG=\"express:*\" nodemon -e js,hbs -i public/ app.js",
"lint-js": "eslint -c .eslintrc --cache --fix .",
... ... @@ -57,7 +56,7 @@
"sitemap": "^1.12.1",
"urlencode": "^1.1.0",
"uuid": "^2.0.2",
"yo-cli": "^1.0.5",
"yo-cli": "=1.0.7",
"yoho-express-session": "^2.0.0",
"yoho-node-lib": "=0.6.11",
"yoho-zookeeper": "^1.0.8"
... ...
... ... @@ -299,7 +299,7 @@ function goBind(area, mobile, smsCode) {
code: smsCode
}).then(function(result) {
if (result.code !== 200) {
new Alert(result.mesage).show();
new Alert(result.message).show();
return false;
}
... ...
... ... @@ -12,7 +12,7 @@
position: relative;
.sort-intro {
width: 488px;
width: 650px;
height: 300px;
line-height: 300px;
border: 1px solid #eaeceb;
... ... @@ -21,7 +21,7 @@
.inline {
width: 100%;
padding: 0 50px;
padding: 0 30px;
line-height: 1;
text-align: center;
display: inline-block;
... ... @@ -53,7 +53,7 @@
margin-top: 30px;
> li {
width: 33.33%;
width: 20%;
text-align: center;
float: left;
font-size: 12px;
... ... @@ -67,7 +67,7 @@
}
.thumb {
width: 480px;
width: 300px;
height: 300px;
position: absolute;
top: 0;
... ...
... ... @@ -118,8 +118,8 @@
resolved "http://npm.yohops.com/@sindresorhus%2fis/-/is-0.7.0.tgz#9a06f4f137ee84d7df0460c1fdb1135ffa6c50fd"
"@types/node@^8.0.20":
version "8.10.14"
resolved "http://npm.yohops.com/@types%2fnode/-/node-8.10.14.tgz#a24767cfa22023f1bf7e751c0ead56a14c07ed45"
version "8.10.17"
resolved "http://npm.yohops.com/@types%2fnode/-/node-8.10.17.tgz#d48cf10f0dc6dcf59f827f5a3fc7a4a6004318d3"
abbrev@1:
version "1.1.1"
... ... @@ -421,10 +421,14 @@ ast-types@0.10.1:
version "0.10.1"
resolved "http://npm.yohops.com/ast-types/-/ast-types-0.10.1.tgz#f52fca9715579a14f841d67d7f8d25432ab6a3dd"
ast-types@0.11.3, ast-types@0.x.x:
ast-types@0.11.3:
version "0.11.3"
resolved "http://npm.yohops.com/ast-types/-/ast-types-0.11.3.tgz#c20757fe72ee71278ea0ff3d87e5c2ca30d9edf8"
ast-types@0.x.x:
version "0.11.4"
resolved "http://npm.yohops.com/ast-types/-/ast-types-0.11.4.tgz#76f930930e9571851ba282a9a0f6923f29f6be2f"
async-each@^1.0.0:
version "1.0.1"
resolved "http://npm.yohops.com/async-each/-/async-each-1.0.1.tgz#19d386a1d9edc6e7c1c85d388aedbcc56d33602d"
... ... @@ -433,7 +437,13 @@ async@^1.4.0, async@^1.5.0, async@^1.5.2:
version "1.5.2"
resolved "http://npm.yohops.com/async/-/async-1.5.2.tgz#ec6a61ae56480c0c3cb241c95618e20892f9672a"
async@^2.1.2, async@^2.4.1, async@^2.5.0, async@^2.6.0:
async@^2.1.2:
version "2.6.1"
resolved "http://npm.yohops.com/async/-/async-2.6.1.tgz#b245a23ca71930044ec53fa46aa00a3e87c6a610"
dependencies:
lodash "^4.17.10"
async@^2.4.1, async@^2.5.0, async@^2.6.0:
version "2.6.0"
resolved "http://npm.yohops.com/async/-/async-2.6.0.tgz#61a29abb6fcc026fea77e56d1c6ec53a795951f4"
dependencies:
... ... @@ -3010,7 +3020,7 @@ escope@^3.6.0:
esrecurse "^4.1.0"
estraverse "^4.1.1"
eslint-config-yoho@^1.0.9:
eslint-config-yoho@1.0.9:
version "1.0.9"
resolved "http://npm.yohops.com/eslint-config-yoho/-/eslint-config-yoho-1.0.9.tgz#973f7810b1e0e09b66061defd477e2144d2fdcbb"
... ... @@ -3706,8 +3716,8 @@ get-stream@3.0.0, get-stream@^3.0.0:
resolved "http://npm.yohops.com/get-stream/-/get-stream-3.0.0.tgz#8e943d1358dc37555054ecbe2edb05aa174ede14"
get-uri@^2.0.0:
version "2.0.1"
resolved "http://npm.yohops.com/get-uri/-/get-uri-2.0.1.tgz#dbdcacacd8c608a38316869368117697a1631c59"
version "2.0.2"
resolved "http://npm.yohops.com/get-uri/-/get-uri-2.0.2.tgz#5c795e71326f6ca1286f2fc82575cd2bab2af578"
dependencies:
data-uri-to-buffer "1"
debug "2"
... ... @@ -4129,8 +4139,8 @@ html-entities@^1.2.0:
resolved "http://npm.yohops.com/html-entities/-/html-entities-1.2.1.tgz#0df29351f0721163515dfb9e5543e5f6eed5162f"
html-minifier@^3.2.3:
version "3.5.15"
resolved "http://npm.yohops.com/html-minifier/-/html-minifier-3.5.15.tgz#f869848d4543cbfd84f26d5514a2a87cbf9a05e0"
version "3.5.16"
resolved "http://npm.yohops.com/html-minifier/-/html-minifier-3.5.16.tgz#39f5aabaf78bdfc057fe67334226efd7f3851175"
dependencies:
camel-case "3.0.x"
clean-css "4.1.x"
... ... @@ -5327,7 +5337,7 @@ lodash@^4.0.0, lodash@^4.13.1, lodash@^4.17.4, lodash@^4.3.0, lodash@^4.6.1:
version "4.17.5"
resolved "http://npm.yohops.com/lodash/-/lodash-4.17.5.tgz#99a92d65c0272debe8c96b6057bc8fbfa3bed511"
lodash@^4.14.0, lodash@^4.15.0, lodash@^4.17.2, lodash@^4.17.3, lodash@^4.17.5, lodash@^4.2.0:
lodash@^4.14.0, lodash@^4.15.0, lodash@^4.17.10, lodash@^4.17.2, lodash@^4.17.3, lodash@^4.17.5, lodash@^4.2.0:
version "4.17.10"
resolved "http://npm.yohops.com/lodash/-/lodash-4.17.10.tgz#1b7793cf7259ea38fb3661d4d38b3260af8ae4e7"
... ... @@ -5605,22 +5615,18 @@ mime-types@^2.0.1, mime-types@^2.1.12, mime-types@~2.1.17, mime-types@~2.1.18, m
dependencies:
mime-db "~1.33.0"
mime@1.3.6:
version "1.3.6"
resolved "http://npm.yohops.com/mime/-/mime-1.3.6.tgz#591d84d3653a6b0b4a3b9df8de5aa8108e72e5e0"
mime@1.4.1:
version "1.4.1"
resolved "http://npm.yohops.com/mime/-/mime-1.4.1.tgz#121f9ebc49e3766f311a76e1fa1c8003c4b03aa6"
mime@2.3.1, mime@^2.1.0:
version "2.3.1"
resolved "http://npm.yohops.com/mime/-/mime-2.3.1.tgz#b1621c54d63b97c47d3cfe7f7215f7d64517c369"
mime@^1.3.4, mime@^1.4.0:
version "1.6.0"
resolved "http://npm.yohops.com/mime/-/mime-1.6.0.tgz#32cd9e5c64553bd58d19a568af452acff04981b1"
mime@^2.1.0:
version "2.3.1"
resolved "http://npm.yohops.com/mime/-/mime-2.3.1.tgz#b1621c54d63b97c47d3cfe7f7215f7d64517c369"
mimic-fn@^1.0.0:
version "1.2.0"
resolved "http://npm.yohops.com/mimic-fn/-/mimic-fn-1.2.0.tgz#820c86a39334640e99516928bd03fca88057d022"
... ... @@ -7491,14 +7497,14 @@ q@^1.1.2:
resolved "http://npm.yohops.com/q/-/q-1.5.1.tgz#7e32f75b41381291d04611f1bf14109ac00651d7"
qiniu@^7.1.3:
version "7.1.5"
resolved "http://npm.yohops.com/qiniu/-/qiniu-7.1.5.tgz#bcdf7f60398b5af97001a2eae32b11da0ea4095a"
version "7.1.7"
resolved "http://npm.yohops.com/qiniu/-/qiniu-7.1.7.tgz#708048e181176f1662fbaf700ece2bb2abc3e10d"
dependencies:
agentkeepalive "3.3.0"
crc32 "0.2.2"
encodeurl "^1.0.1"
formstream "1.1.0"
mime "1.3.6"
mime "2.3.1"
tunnel-agent "0.6.0"
urllib "2.22.0"
... ... @@ -8859,7 +8865,7 @@ stylelint-config-standard@^18.2.0:
dependencies:
stylelint-config-recommended "^2.1.0"
stylelint-config-yoho@^1.3.0:
stylelint-config-yoho@1.3.0:
version "1.3.0"
resolved "http://npm.yohops.com/stylelint-config-yoho/-/stylelint-config-yoho-1.3.0.tgz#2af6d1d4c388921a0c6dd53b27abf44601463eba"
dependencies:
... ... @@ -9242,8 +9248,8 @@ uglify-es@^3.3.4:
source-map "~0.6.1"
uglify-js@3.3.x:
version "3.3.25"
resolved "http://npm.yohops.com/uglify-js/-/uglify-js-3.3.25.tgz#3266ccb87c5bea229f69041a0296010d6477d539"
version "3.3.27"
resolved "http://npm.yohops.com/uglify-js/-/uglify-js-3.3.27.tgz#eb8c3c9429969f86ff5b0a2422ffc78c3cea8cc0"
dependencies:
commander "~2.15.0"
source-map "~0.6.1"
... ... @@ -10192,9 +10198,9 @@ yeoman-generator@^2.0.3:
through2 "^2.0.0"
yeoman-environment "^2.0.5"
yo-cli@^1.0.5:
version "1.0.5"
resolved "http://npm.yohops.com/yo-cli/-/yo-cli-1.0.5.tgz#a5e00c6b4a041ab2acca35017074d58c0cc60ffd"
yo-cli@=1.0.7:
version "1.0.7"
resolved "http://npm.yohops.com/yo-cli/-/yo-cli-1.0.7.tgz#c431d1b4aff574b7a251008bd5531c82b754313e"
dependencies:
chalk "^2.3.0"
extract-text-webpack-plugin "^3.0.2"
... ...