Authored by 杨延青

Merge branch 'feature/modifyApi' into 'release/0529'

Feature/modify api



See merge request !289
Showing 65 changed files with 825 additions and 628 deletions
... ... @@ -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]));
... ...
... ... @@ -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;
});
... ... @@ -117,4 +122,13 @@ exports.consultList = (uid, page, limit) => {
});
return fetchConsults(data).then(processData);
}
module.exports = class extends global.yoho.BaseModel {
constructor(ctx) {
super(ctx);
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
}),
... ...
... ... @@ -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
... ...
... ... @@ -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: '/',
... ...
... ... @@ -1485,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(
... ... @@ -1507,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');
... ... @@ -56,7 +56,7 @@ function getListData(params, channel) {
// 调用接口
let apiMethod = [
headerModel.requestHeaderData(channel, true),
this.headerModel.requestHeaderData(channel, true),
this.searchApi.getSortList({}, channel),
this.searchApi.getProductList(searchParams, 'categoryList')
];
... ... @@ -181,7 +181,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 +313,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 +398,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 +478,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 +633,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);
... ...
... ... @@ -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');
... ... @@ -105,8 +105,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',
... ...
... ... @@ -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);
/**
* 获取学校地区数据
... ...
... ... @@ -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);
}
};
... ...
... ... @@ -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();
});
}
... ...
... ... @@ -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) || [];
});
}
};
... ...