Authored by 周少峰

Merge branch 'feature/channel-op' into gray

... ... @@ -8,14 +8,14 @@
const _ = require('lodash');
const channelModel = require('../models/index');
const ChannelModel = require('../models/index');
exports.index = (req, res, next) => {
let channelType = req.path.split('/')[1] || 'boys';
let poolId = req.query.template_id;
let isJKChannel = req.query.mChannel === 'japanKorean';
channelModel.getContent(channelType, isJKChannel, poolId).then(data => {
req.ctx(ChannelModel).getContent(channelType, isJKChannel, poolId).then(data => {
// channel为空不缓存
if (_.isEmpty(data.channel)) {
... ... @@ -28,7 +28,7 @@ exports.index = (req, res, next) => {
// 日韩馆频道页
exports.japanKorean = (req, res, next) => {
channelModel.getJKContent(req).then(data => {
req.ctx(ChannelModel).getJKContent(req).then(data => {
// channel为空不缓存
if (_.isEmpty(data.channel)) {
... ... @@ -55,7 +55,7 @@ exports.getNewArrival = (req, res, next) => {
pageCount = 20;
}
channelModel.getNewArrival(channel, isJKChannel, poolId).then(data => {
req.ctx(ChannelModel).getNewArrival(channel, isJKChannel, poolId).then(data => {
goods = _.slice(data, pageIndex, pageIndex + pageCount);
if (goods.length !== 0) {
... ... @@ -69,15 +69,15 @@ exports.getNewArrival = (req, res, next) => {
};
exports.getIndexGuide = (req, res, next) => {
channelModel.getIndexGuideData().then(data => {
req.ctx(ChannelModel).getIndexGuideData().then(data => {
if (data.code !== 200) {
const err = new Error('异常');
throw err;
}
return channelModel.formatIndexGuideData(data.data);
return req.ctx(ChannelModel).formatIndexGuideData(data.data);
}).then(data => {
return channelModel.getResourceData(data);
return req.ctx(ChannelModel).getResourceData(data);
}).then(data => {
let result = {list: data, layout: false};
... ... @@ -87,7 +87,7 @@ exports.getIndexGuide = (req, res, next) => {
exports.hasNewUserFloor = (req, res, next) => {
channelModel.hasNewUserFloor(req.yoho.channel, req.user.uid).then(data => {
req.ctx(ChannelModel).hasNewUserFloor(req.yoho.channel, req.user.uid).then(data => {
res.send(data);
}).catch(next);
};
... ...
... ... @@ -13,16 +13,49 @@ const helpers = global.yoho.helpers;
const config = global.yoho.config;
const processProduct = require(`${global.utils}/product-process`).processProduct;
const searchApi = require('./search-api');
const SearchApi = require('./search-api');
const headerModel = require('../../../doraemon/models/header');
const needQuery = {
'GIRL KIDS': true,
'BOY KIDS': true,
人气单品: true,
ACCESSORIES: true
};
const api = global.yoho.API;
const serviceApi = global.yoho.ServiceAPI;
const channelMap = dataMap.channel;
const headerModel = require('../../../doraemon/models/header');
const sortMap = dataMap.sort;
module.exports = class extends global.yoho.BaseModel {
constructor(ctx) {
super(ctx);
this.searchApi = new SearchApi(ctx);
this.floorMap = {
slide: this._getSlideData.bind(this),
hot: this._getHotGoodsFloorData.bind(this),
最新速报: this._getNewReportFloorData.bind(this),
人气单品: this._getSingleHotFloorData.bind(this),
'GIRL KIDS': this._getSingleHotFloorData.bind(this),
'BOY KIDS': this._getSingleHotFloorData.bind(this),
ACCESSORIES: this._getSingleHotFloorData.bind(this),
优选品牌: this._getPreBrandTopData.bind(this),
最新上架: this._getNewGoodsFloorData.bind(this),
ad: this._getadbannerData.bind(this),
category: this._getCategoryFloorData.bind(this),
accordion: this._getAccordionFloorData.bind(this),
debrisSlide: this._getDebrisSlide.bind(this),
jacket: this._getJacketData.bind(this),
sevenCategory: this._getClothesCategory.bind(this),
floorTitle: this._getFloorTitleData.bind(this),
newuser: this._getNewUserFloorData.bind(this)
};
}
// 获取可用的标题
const _getText = data => {
_getText(data) {
let text = data.split(' ')[0];
const regResult = /\w+/.exec(text);
const titleWithoutChinese = /^(?=.*[A-Za-z0-9])[A-Za-z0-9 _]*$/;
... ... @@ -39,21 +72,17 @@ const _getText = data => {
}
return text;
};
const channelMap = dataMap.channel;
const sortMap = dataMap.sort;
}
/**
/**
* 新人专享
* @param {[Object]} data 原始数据
* @return {[Object]} 转换后的数据
*/
const _getNewUserFloorData = data => {
_getNewUserFloorData(data) {
let floorData = {
newUserFloor: {
name: _getText(data.title.name),
name: this._getText(data.title.name),
navs: {},
bannerImage: {
url: data.banner_image[0].url,
... ... @@ -87,14 +116,14 @@ const _getNewUserFloorData = data => {
}
return floorData;
};
}
/**
/**
* 获取带小图的banner
* @param {[Object]} data 原始数据
* @return {[Object]} 转换后的数据
*/
const _getDebrisSlide = data => {
_getDebrisSlide(data) {
let floorData = {
debrisSlider: {
left: [],
... ... @@ -110,27 +139,27 @@ const _getDebrisSlide = data => {
});
return floorData;
};
}
/**
/**
* 获取广告位
* @param {Object} data 原始数据
* @return {Object} 转换后的数据
*/
const _getadbannerData = data => {
_getadbannerData(data) {
return {
adbanner: data
};
};
}
/**
/**
* 生成banner模板数据
* @param {Object} srcData 原始数据
* @return {Object} 转换后的数据
*/
const _getSlideData = srcData => {
_getSlideData(srcData) {
const slideData = {
slide: {
list: [],
... ... @@ -151,15 +180,15 @@ const _getSlideData = srcData => {
}
return slideData;
};
}
/**
/**
* 获取品牌列表数据
* @param {[Object]} args 参数列表
* @param {String} type 频道类型
* @return {Object}
*/
const _getBrandLogosData = (args, showNum) => {
_getBrandLogosData(args, showNum) {
let items = [],
brandLogos = [],
i = 0,
... ... @@ -214,14 +243,14 @@ const _getBrandLogosData = (args, showNum) => {
isMore: true
});
return brandLogos;
};
}
/**
/**
* 获取最新速报模板数据 : 大图+小图+大图+single_image(广告位)/+floor(logo列表)
* @param {Object} srcData 原始数据
* @return {Object} 转换后的数据
*/
const _getNewReportFloorData = (args) => {
_getNewReportFloorData(args) {
const title = args[0].data.text;
let floorId = args[0].template_id;
let item = args[1].data;
... ... @@ -258,7 +287,7 @@ const _getNewReportFloorData = (args) => {
// 广告位
if (forthItem.template_name && forthItem.template_name === 'single_image') {
adData = _getadbannerData(forthItem.data[0]);
adData = this._getadbannerData(forthItem.data[0]);
floorDatas.push(adData);
}
... ... @@ -269,30 +298,30 @@ const _getNewReportFloorData = (args) => {
brandLogoObj.moreBrand = args[5].data[0].url || '';
}
brandLogoObj.brandLogos = _getBrandLogosData(forthItem.data, brandLogoObj.showNum);
brandLogoObj.brandLogos = this._getBrandLogosData(forthItem.data, brandLogoObj.showNum);
data.newReport.brandLogoObj = brandLogoObj;
}
return floorDatas;
};
}
/**
/**
* 给目标对象绑定频道属性
* @param {Object} obj 需要绑定频道属性的对象
* @param {String} type 需要设置的频道类型
* @return undefined
*/
const _setChannelType = (obj, type) => {
_setChannelType(obj, type) {
obj[type + 'Channel'] = true;
};
}
/**
/**
* 获取优选品牌模板数据
* @param {[Object]} args 参数列表
* @param {String} type 频道类型
* @return {Object}
*/
const _getPreBrandTopData = (args, type) => {
_getPreBrandTopData(args, type) {
const title = args[0].data.text;
let item = args[1].data,
logoItems = args[2] || {},
... ... @@ -314,25 +343,25 @@ const _getPreBrandTopData = (args, type) => {
if (_.get(args[3], 'data[0].url', '')) {
brandLogoObj.moreBrand = args[3].data[0].url;
}
brandLogoObj.brandLogos = _getBrandLogosData(args[2].data, showNum);
brandLogoObj.brandLogos = this._getBrandLogosData(args[2].data, showNum);
data.preferenceBrands.brandLogoObj = brandLogoObj;
}
data.preferenceBrands.imgBrand = item;
if (type === 'kids') {
data.preferenceBrands.sliderColor = '#7AD3F8';
}
_setChannelType(data.preferenceBrands, type);
this._setChannelType(data.preferenceBrands, type);
return data;
};
}
/**
/**
* 获取热门分类模板数据
* @param {[Object]} args 参数列表
* @param {String} type 频道类型
* @return {Object}
*/
const _getHotGoodsFloorData = (args, type) => {
_getHotGoodsFloorData(args, type) {
let item = args[0];
let nextItem = args[1];
... ... @@ -376,19 +405,19 @@ const _getHotGoodsFloorData = (args, type) => {
list.push(object);
data.recommend.tplrecommend = list;
_setChannelType(data.recommend, type);
this._setChannelType(data.recommend, type);
return data;
};
}
/**
/**
* 获取japanKorean潮流上装Jacket,title+左大图+右6小图模板数据
* @param {[Object]} args 参数列表
* @param {String} type 频道类型
* @return {Object}
*/
const _getJacketData = (arg) => {
_getJacketData(arg) {
let resData = {
tpltopic: {
bigPic: arg.big_image[0],
... ... @@ -401,29 +430,29 @@ const _getJacketData = (arg) => {
}
return resData;
};
}
/**
/**
* 获取7个品类图
* @param {[Object]} args 参数列表
* @param {String} type 频道类型
* @return {Object}
*/
const _getClothesCategory = (arg) => {
_getClothesCategory(arg) {
return {
sevenCategory: {
categorys: arg.list
}
};
};
}
/**
/**
* 获取boys人气单品模版数据
* @param {[Object]} args 参数列表
* @param {String} type 频道类型
* @return {Object}
*/
const _getBoysSingleHot = (args, type) => {
_getBoysSingleHot(args, type) {
const len = 10;
const data = {
singlehot: {
... ... @@ -460,24 +489,24 @@ const _getBoysSingleHot = (args, type) => {
});
data.singlehot.imgHot = list;
_setChannelType(data.singlehot, type);
this._setChannelType(data.singlehot, type);
floorDatas.push(data);
if (args[3].template_name === 'single_image') {
adData = _getadbannerData(args[3].data[0]);
adData = this._getadbannerData(args[3].data[0]);
floorDatas.push(adData);
}
return floorDatas;
};
}
/**
/**
* 获取girls人气单品模版数据
* @param {[Object]} args 参数列表
* @param {String} type 频道类型
* @return {Object}
*/
const _getGirlsSingleHot = (args, type) => {
_getGirlsSingleHot(args, type) {
let goods = args[2] && args[2].data;
let skns = '';
... ... @@ -489,7 +518,7 @@ const _getGirlsSingleHot = (args, type) => {
return;
}
return searchApi.getProductList({
return this.searchApi.getProductList({
client_type: 'web',
query: skns,
order: 'shelve_time:desc',
... ... @@ -501,30 +530,30 @@ const _getGirlsSingleHot = (args, type) => {
gender: channelMap[type].gender,
limit: 60
}, config.apiCache);
};
}
/**
/**
* 人气单品入口
* @param {[Object]} args 参数列表
* @param {String} type 频道类型
* @return {Object}
*/
const _getSingleHotFloorData = (args, type) => {
_getSingleHotFloorData(args, type) {
if (type === 'boys') {
return _getBoysSingleHot(args, type);
return this._getBoysSingleHot(args, type);
} else {
return _getGirlsSingleHot(args, type);
return this._getGirlsSingleHot(args, type);
}
}
};
/**
/**
* 组装最新上架楼层数据
*
* @param string data
* return obj
*/
const _getNewGoodsFloorData = args => {
_getNewGoodsFloorData(args) {
const data = {};
if (!_.isEmpty(args)) {
... ... @@ -537,15 +566,15 @@ const _getNewGoodsFloorData = args => {
data.newArrivls.navs = args[1] ? args[1].data : {};
}
return data;
};
}
/**
/**
* 文本标题
* @param {[Object]} args 参数列表
* @param {String} type 频道类型
* @return {Object}
*/
const _getFloorTitleData = (args) => {
_getFloorTitleData(args) {
let resData = {
floorHeader: {}
};
... ... @@ -560,12 +589,12 @@ const _getFloorTitleData = (args) => {
}
if (resData.floorHeader.name.indexOf('最新上架') >= 0) {
resData = _getNewGoodsFloorData(args);
resData = this._getNewGoodsFloorData(args);
}
return resData;
};
}
/**
/**
* 处理异步获取的人气单品数据
* @param {[Object]} args 参数列表
* @param {String} originQuery 原始skns
... ... @@ -573,7 +602,7 @@ const _getFloorTitleData = (args) => {
* @param {String} type 频道类型
* @return {Object}
*/
const _getSingehotViaResult = (args, originQuery, queryResult, type) => {
_getSingehotViaResult(args, originQuery, queryResult, type) {
let data = {
singlehot: {
name: args[0].data.text,
... ... @@ -643,11 +672,11 @@ const _getSingehotViaResult = (args, originQuery, queryResult, type) => {
}
});
data.singlehot.navs = args[1].data;
_setChannelType(data.singlehot, type);
this._setChannelType(data.singlehot, type);
return data;
};
}
/**
/**
* 异步获取人气单品
* @param {[Object]} rawData 接口返回的原始数据
* @param {[Object]} floorData 已经经过处理的楼层数据
... ... @@ -657,27 +686,25 @@ const _getSingehotViaResult = (args, originQuery, queryResult, type) => {
* @param {Type} type 人气单品楼层的类型
* @return {Object}
*/
const _processFloorDataWithQueryReusult = (rawData, originQuery, queryResult, title, type) => {
_processFloorDataWithQueryReusult(rawData, originQuery, queryResult, title, type) {
let data = {};
_.forEach(rawData, (subData, index) => {
if (subData && subData.data && subData.data.text) {
const text = subData.data.text && _getText(subData.data.text);
const text = subData.data.text && this._getText(subData.data.text);
if (text === title) {
data = _getSingehotViaResult(rawData.slice(index, index + 4), originQuery, queryResult, type);
data = this._getSingehotViaResult(rawData.slice(index, index + 4), originQuery, queryResult, type);
}
}
});
return data;
};
}
const _getCategoryFloorData = args => {
_getCategoryFloorData(args) {
const data = {
category: {
name: args[0].data.text,
... ... @@ -701,9 +728,9 @@ const _getCategoryFloorData = args => {
});
return data;
};
}
const _getAccordionFloorData = args => {
_getAccordionFloorData(args) {
let data = {
accordion: {
name: args[0].data.text,
... ... @@ -715,9 +742,9 @@ const _getAccordionFloorData = args => {
data.accordion.slide = args[2].data;
return data;
};
}
const _requestContent = (type, params, code) => {
_requestContent(type, params, code) {
let data = {
client_type: 'web',
content_code: code || channelMap[type || 'boys'].code,
... ... @@ -727,43 +754,22 @@ const _requestContent = (type, params, code) => {
};
Object.assign(data, params);
return serviceApi.get('operations/api/v5/resource/home', data, {
return this.get({
url: 'operations/api/v5/resource/home',
data,
param: {
cache: true,
code: 200
},
api: global.yoho.ServiceAPI
}).then(result => {
return result;
});
};
const floorMap = {
slide: _getSlideData,
hot: _getHotGoodsFloorData,
最新速报: _getNewReportFloorData,
人气单品: _getSingleHotFloorData,
'GIRL KIDS': _getSingleHotFloorData,
'BOY KIDS': _getSingleHotFloorData,
ACCESSORIES: _getSingleHotFloorData,
优选品牌: _getPreBrandTopData,
最新上架: _getNewGoodsFloorData,
ad: _getadbannerData,
category: _getCategoryFloorData,
accordion: _getAccordionFloorData,
debrisSlide: _getDebrisSlide,
jacket: _getJacketData,
sevenCategory: _getClothesCategory,
floorTitle: _getFloorTitleData,
newuser: _getNewUserFloorData
};
}
const needQuery = {
'GIRL KIDS': true,
'BOY KIDS': true,
人气单品: true,
ACCESSORIES: true
};
const getQuery = args => {
getQuery(args) {
let goods = args[2] && args[2].data;
let skns = '';
... ... @@ -774,10 +780,9 @@ const getQuery = args => {
}
return skns;
};
}
const _processFloorData = (rawData, type) => {
_processFloorData(rawData, type) {
let floorList = [];
let searchPromise = [];
let singlehotFloorIndex = [];
... ... @@ -796,29 +801,29 @@ const _processFloorData = (rawData, type) => {
if (data && data.template_name === 'recommend_content_three' ||
(data.template_intro === '焦点图' && index === 0)) { // 处理banner
floorData = floorMap.slide.call(null, data.data);
floorData = this.floorMap.slide(data.data);
} else if (data && data.template_intro === '热门品类') { // 处理热门品类
floorData = floorMap.hot.call(null, rawData.slice(index, index + hotCategoryLength), type);
floorData = this.floorMap.hot(rawData.slice(index, index + hotCategoryLength), type);
} else if (data && data.data && data.data.text) { // 处理一般楼层
let text = _getText(data.data.text);
let text = this._getText(data.data.text);
let lastIndex = index + bigFloorLength < rawData.length ?
index + bigFloorLength : index + (rawData.length - index - 1);
floorData = floorMap[text] &&
floorMap[text].call(null, rawData.slice(index, lastIndex), type);
floorData = this.floorMap[text] &&
this.floorMap[text](rawData.slice(index, lastIndex), type);
if (needQuery[text]) {
queryParam = getQuery(rawData.slice(index, lastIndex));
queryParam = this.getQuery(rawData.slice(index, lastIndex));
if (queryParam.length > 0) {
params.push(queryParam);
}
}
} else if (data && data.template_name === 'debrisSlider') { // 处理girls的banner
floorData = floorMap.debrisSlide.call(null, data.data);
floorData = this.floorMap.debrisSlide(data.data);
} else if (data.template_name === 'new_user_floor' || data.template_intro === '新人专享') {
if (!hasNewUser) {
floorData = floorMap.newuser.call(null, data.data);
floorData = this.floorMap.newuser(data.data);
hasNewUser = true;
}
... ... @@ -828,14 +833,14 @@ const _processFloorData = (rawData, type) => {
if (!floorData && index + normalFloorLength < rawData.length &&
rawData[index + 1].template_name === 'textNav' &&
rawData[index + 2].template_name === 'floor') {
floorData = floorMap.category.call(null, rawData.slice(index, index + normalFloorLength));
floorData = this.floorMap.category(rawData.slice(index, index + normalFloorLength));
}
// 处理手风琴楼层
if (!floorData && index + normalFloorLength < rawData.length &&
rawData[index + 1].template_name === 'textNav' &&
rawData[index + 2].template_name === 'focus') {
floorData = floorMap.accordion.call(null, rawData.slice(index, index + normalFloorLength));
floorData = this.floorMap.accordion(rawData.slice(index, index + normalFloorLength));
}
... ... @@ -847,7 +852,7 @@ const _processFloorData = (rawData, type) => {
singlehotFloorIndex.push(floorList.length);
// 记住楼层标题, 以便后面promise获取数据后插入楼层数据
singlehotFloorTitle.push(_getText(data.data.text));
singlehotFloorTitle.push(this._getText(data.data.text));
} else if (!_.isNil(floorData)) {
_.isArray(floorData) ?
floorList = floorList.concat(floorData) :
... ... @@ -862,9 +867,9 @@ const _processFloorData = (rawData, type) => {
singlehotFloorTitle: _.reverse(singlehotFloorTitle),
singlehotFloorIndex: _.reverse(singlehotFloorIndex)
};
};
}
const _processJKFloorData = (rawData) => {
_processJKFloorData(rawData) {
let floorList = [];
let searchPromise = [];
let singlehotFloorIndex = [];
... ... @@ -877,14 +882,14 @@ const _processJKFloorData = (rawData) => {
if (data && data.template_name === 'recommend_content_three' ||
(data.template_intro === '焦点图' && index === 0)) { // 处理banner
floorData = floorMap.slide.call(null, data.data);
floorData = this.floorMap.slide.call(null, data.data);
floorData.slide.floorId = data.template_id;
} else if (data && data.data && data.data.text) { // 处理一般楼层
let text = _getText(data.data.text);
let text = this._getText(data.data.text);
// 最新速报
if (text.indexOf('最新速报') >= 0) {
floorData = _getNewReportFloorData(rawData.slice(index, index + 6));
floorData = this._getNewReportFloorData(rawData.slice(index, index + 6));
// 单个图作为最新速报模块用过的,标识一下,不作为广告位了
_.filter(rawData.slice(index, index + 5), function(o) {
... ... @@ -897,19 +902,19 @@ const _processJKFloorData = (rawData) => {
let href = rawData[index + 1].template_name === 'textNav' ?
rawData.slice(index, index + 2) : data;
floorData = floorMap.floorTitle.call(null, href);
floorData = this.floorMap.floorTitle.call(null, href);
}
} else if (data && data.template_name === 'jk_floor') { // 左1大图,右6小图,title
floorData = floorMap.jacket.call(null, data.data);
floorData = this.floorMap.jacket.call(null, data.data);
} else if (data && data.template_name === 'recommend_content_five') {
// 1标题12图,在日韩馆频道页,作为7个品类显示
floorData = floorMap.sevenCategory.call(null, data.data);
floorData = this.floorMap.sevenCategory.call(null, data.data);
floorData.sevenCategory.floorId = data.template_id;
} else if (data && data.template_name === 'single_image') {
if (!data.hasUser) {
// 一张图,在日韩馆频道页,做广告位
floorData = floorMap.ad.call(null, data.data);
floorData = this.floorMap.ad.call(null, data.data);
}
}
... ... @@ -921,7 +926,7 @@ const _processJKFloorData = (rawData) => {
singlehotFloorIndex.push(floorList.length);
// 记住楼层标题, 以便后面promise获取数据后插入楼层数据
singlehotFloorTitle.push(_getText(data.data.text));
singlehotFloorTitle.push(this._getText(data.data.text));
} else if (!_.isNil(floorData)) {
_.isArray(floorData) ?
floorList = floorList.concat(floorData) :
... ... @@ -938,10 +943,15 @@ const _processJKFloorData = (rawData) => {
singlehotFloorTitle: _.reverse(singlehotFloorTitle),
singlehotFloorIndex: _.reverse(singlehotFloorIndex)
};
};
}
const _formatResourceParams = (channel, code) => {
return serviceApi.get('operations/api/v5/resource/get', {content_code: code}, config.apiCache).then(data => {
_formatResourceParams(channel, code) {
return this.get({
url: 'operations/api/v5/resource/get',
data: { content_code: code },
param: config.apiCache,
api: global.yoho.ServiceAPI
}).then(data => {
let result = data && data.data[0] && data.data[0].data[0];
if (result) {
... ... @@ -950,14 +960,14 @@ const _formatResourceParams = (channel, code) => {
return result || {};
});
};
}
/**
/**
* 频道页首次登陆导航并行调接口数据
* @param {Object} data
* @return {Object} formatData
*/
const _formatParams = (channel, data) => {
_formatParams(channel, data) {
let params = {};
// 排序数据映射表
... ... @@ -1005,7 +1015,7 @@ const _formatParams = (channel, data) => {
params = Object.assign(data);
}
return searchApi.getProductList(params).then(result => {
return this.searchApi.getProductList(params).then(result => {
let ret = result.data;
if (ret) {
... ... @@ -1014,14 +1024,14 @@ const _formatParams = (channel, data) => {
return ret;
});
};
}
/**
/**
* 格式化频道页首次登陆导航数据
* @param {Object} data
* @return {Object} formatData
*/
const formatIndexGuideData = data => {
formatIndexGuideData(data) {
let channels = {
boys: {gender: '1,3', limit: 1},
girls: {gender: '2,3', limit: 1},
... ... @@ -1045,7 +1055,7 @@ const formatIndexGuideData = data => {
});
if (channels[channel]) {
promiseArr.push(_formatParams(channel, channels[channel]));
promiseArr.push(this._formatParams(channel, channels[channel]));
}
});
... ... @@ -1060,22 +1070,21 @@ const formatIndexGuideData = data => {
return formatData;
});
};
}
/**
/**
* 获取最新上架商品数据
*
* @param string $channel
* @return array
*/
const getNewArrival = (channel, isJKChannel, poolId)=> {
getNewArrival(channel, isJKChannel, poolId) {
let rel = [],
sortList = sortMap[channel],
params = {},
method = '';
if (isJKChannel) {
method = 'app.search.sales';
params = {
... ... @@ -1104,9 +1113,12 @@ const getNewArrival = (channel, isJKChannel, poolId)=> {
_.forEach(sortList, (item) => {
let data = Object.assign(item, params, {limit: item.viewNum});
rel.push(api.get('', Object.assign({
rel.push(this.get({
data: Object.assign({
method: method
}, data), {cache: true}));
}, data),
param: {cache: true}
}));
});
return Promise.all(rel).then(res => {
... ... @@ -1130,22 +1142,22 @@ const getNewArrival = (channel, isJKChannel, poolId)=> {
});
return result;
});
};
}
/**
/**
* 获取频道页数据
* @param {String} type 传入频道页类型,值可以是: boys, girls, kids, lifestyle
* @return {Object}
*/
const getContent = (type, isJKChannel, poolId) => {
getContent(type, isJKChannel, poolId) {
let params = {new_device: 'Y'};
return Promise.all([
headerModel.requestHeaderData(type),
_requestContent(type, params),
getNewArrival(type, isJKChannel, poolId)
this._requestContent(type, params),
this.getNewArrival(type, isJKChannel, poolId)
]).then(res => {
let headerData = res[0].data || res[0],
... ... @@ -1153,7 +1165,7 @@ const getContent = (type, isJKChannel, poolId) => {
let data = {};
const processResult = _processFloorData(contentData, type);
const processResult = this._processFloorData(contentData, type);
data = headerData;
data.module = 'channel';
... ... @@ -1187,7 +1199,7 @@ const getContent = (type, isJKChannel, poolId) => {
_.forEach(res, (data, index) => {
result.floorData.channel
.splice(result.singlehotFloorIndex[index], 0,
_processFloorDataWithQueryReusult(
this._processFloorDataWithQueryReusult(
result.rawData,
result.queryParams[index],
data,
... ... @@ -1202,21 +1214,21 @@ const getContent = (type, isJKChannel, poolId) => {
return result.floorData || result;
});
};
}
/**
/**
* 获取日韩馆频道页数据
* @param {String} type 传入频道页类型,值可以是: boys, girls, kids, lifestyle
* @return {Object}
*/
const getJKContent = (req) => {
getJKContent(req) {
let channel = req.query.channel || req.yoho.channel || 'boys',
contentCode = req.query.content_code;
return Promise.all([
headerModel.requestHeaderData(channel),
_requestContent(channel, {}, contentCode),
getNewArrival(channel, true, req.query.template_id)
this._requestContent(channel, {}, contentCode),
this.getNewArrival(channel, true, req.query.template_id)
]).then(res => {
let headerData = res[0].data || res[0],
... ... @@ -1224,7 +1236,7 @@ const getJKContent = (req) => {
let data = {};
const processResult = _processJKFloorData(contentData);
const processResult = this._processJKFloorData(contentData);
data = headerData;
data.module = 'channel';
... ... @@ -1259,7 +1271,7 @@ const getJKContent = (req) => {
_.forEach(res, (data, index) => {
result.floorData.channel
.splice(result.singlehotFloorIndex[index], 0,
_processFloorDataWithQueryReusult(
this._processFloorDataWithQueryReusult(
result.rawData,
result.queryParams[index],
data,
... ... @@ -1274,14 +1286,14 @@ const getJKContent = (req) => {
return result.floorData || result;
});
};
}
const getResourceData = (formatData) => {
getResourceData(formatData) {
let promiseArr = [];
_.forEach(formatData, item => {
if (item.content_code) {
promiseArr.push(_formatResourceParams(item.channel, item.content_code));
promiseArr.push(this._formatResourceParams(item.channel, item.content_code));
}
});
return Promise.all(promiseArr).then(data => {
... ... @@ -1295,26 +1307,31 @@ const getResourceData = (formatData) => {
return formatData;
});
};
}
/**
/**
* 获取频道页首次登陆导航数据
* @param {String} type 传入频道页类型,值可以是: boys, girls, kids, lifestyle
* @return {Object}
*/
const getIndexGuideData = () => {
getIndexGuideData() {
let params = {
client_type: 'web',
private_key: '0ed29744ed318fd28d2c07985d3ba633'
};
return serviceApi.get('operations/api/v6/category/getCategory', params, config.apiCache);
};
return this.get({
url: 'operations/api/v6/category/getCategory',
data: params,
param: config.apiCache,
api: global.yoho.ServiceAPI
});
}
const hasNewUserFloor = (channelType, uid) => {
hasNewUserFloor(channelType, uid) {
let params = {uid: uid};
return _requestContent(channelType, params).then(res => {
return this._requestContent(channelType, params).then(res => {
let isNewUser = false,
contentData = res.data ? res.data.list : res;
... ... @@ -1329,16 +1346,5 @@ const hasNewUserFloor = (channelType, uid) => {
isNewUser: isNewUser
};
});
};
module.exports = {
getNewArrival: getNewArrival,
getContent: getContent,
getJKContent: getJKContent,
getIndexGuideData: getIndexGuideData,
formatIndexGuideData: formatIndexGuideData,
getResourceData: getResourceData,
hasNewUserFloor: hasNewUserFloor
}
};
... ...
/**
* Created by TaoHuang on 2016/6/14.
*/
'use strict';
const _ = require('lodash');
const Fn = require('lodash/fp');
const md5 = require('md5');
const api = global.yoho.API;
const serviceApi = global.yoho.ServiceAPI;
const config = global.yoho.config;
const helpers = global.yoho.helpers;
const cache = global.yoho.cache;
const logger = global.yoho.logger;
// 判断用户是否收藏品牌
const isFavoriteBrandUrl = '/shops/service/v1/favorite/getUidBrandFav';
// 根据品牌查询相关文章
const relateArticleUrl = 'guang/service/v2/article/getArticleByBrand';
const GLOBAL_BASE_URI = '/product/global/list';
// 缓存生效时间
const CACHE_TIME_S = 60;
... ... @@ -38,23 +25,20 @@ const saveCache = (key, kv, cacheTime) => {
.catch(err => logger.debug(`product query save cache data fail:${err.toString()}`));
};
const getProductListOrig = finalParams => api.get('', finalParams);
module.exports = class extends global.yoho.BaseModel {
constructor(ctx) {
super(ctx);
}
const getKeyActivityAsync = (query) => {
return api.get('', {
method: 'app.search.word',
query: query
}, {
catch: true,
code: 200
});
};
getProductListOrig(finalParams) {
return this.get({data: finalParams});
}
/**
/**
* 获取商品列表
* @return
*/
const getProductList = (params, from) => {
getProductList(params, from) {
let finalParams = {
method: 'web.search.search',
sales: 'Y',
... ... @@ -76,7 +60,7 @@ const getProductList = (params, from) => {
}
if (!config.useCache) {
return getProductListOrig(finalParams);
return this.getProductListOrig(finalParams);
} else {
let cKey = getSearchCacheKey(finalParams);
... ... @@ -99,7 +83,7 @@ const getProductList = (params, from) => {
}
}
return getProductListOrig(finalParams).then(result => {
return this.getProductListOrig(finalParams).then(result => {
if (hasCache && result && result.data) {
Object.assign(result.data, cdata);
} else {
... ... @@ -115,412 +99,6 @@ const getProductList = (params, from) => {
});
});
}
};
/**
* 获取seo商品列表
* @return
*/
const getSeoProductList = (params, from) => {
let finalParams = {
method: 'web.search.forseo',
sales: 'Y',
outlets: 2,
stocknumber: 1,
need_filter: 'no',
limit: 60
};
Object.assign(finalParams, params);
if (from) {
finalParams.from = from;
}
return getProductListOrig(finalParams);
};
const getSortListOrig = (finalParams) => api.get('', finalParams, config.apiCache);
/**
* 获取分类列表
* @return
*/
const getSortList = (params, channel) => {
let finalParams = {
method: 'web.regular.groupsort.sale',
sales: 'Y', // 在销售商品分类
status: 1, // 上架商品分类
stocknumber: 1 // 过滤掉已售罄
};
Object.assign(finalParams, params);
if (channel) {
switch (channel) {
case 'boys':
finalParams.yh_channel = 1;
break;
case 'girls':
finalParams.yh_channel = 2;
break;
case 'kids':
finalParams.yh_channel = 3;
break;
case 'lifestyle':
finalParams.yh_channel = 4;
break;
default:
break;
}
}
if (!config.useCache) {
return getSortListOrig(finalParams);
} else {
let cKey = getSearchCacheKey(finalParams);
return cache.get(cKey)
.catch(err => logger.debug(`product query save cache data fail:${err.toString()}`))
.then(cdata => {
let cdataObj;
if (cdata) {
try {
cdataObj = JSON.parse(cdata);
} catch (e) {
logger.debug('getSortList cache data parse fail.');
}
}
if (cdataObj) {
return cdataObj;
} else {
return getSortListOrig(finalParams).then(ret => {
if (ret && ret.code === 200) {
saveCache(cKey, ret, CACHE_TIME_S);
}
return ret;
});
}
});
}
};
/**
* 获取分类图文介绍
* @return
*/
const getSortIntro = (params) => {
let finalParams = {
method: 'web.search.banner'
};
Object.assign(finalParams, params);
return api.get('', finalParams, config.apiCache);
};
/**
* 获取分类广告
* @return
*/
const getSortAds = (params) => {
let finalParams = {
method: 'app.ads.list'
};
Object.assign(finalParams, params);
return api.get('', finalParams, config.apiCache);
};
/**
* 获取品牌系列
* @return
*/
const getBrandShopSeries = (params) => {
let finalParams = {
method: 'web.brand.series',
status: params.status || 1
};
if (params.brandId) {
finalParams.brand_id = params.brandId;
} else if (params.shopId) {
Object.assign(finalParams, {
method: 'web.shop.series',
shop_id: params.shopId
});
}
return api.get('', finalParams, config.apiCache);
};
/**
* 获取品牌folder
* @return
*/
const getBrandShopFolder = (params) => {
let finalParams = {
method: 'web.brand.folder',
status: params.status || 1
};
if (params.brandId) {
finalParams.brand_id = params.brandId;
} else if (params.shopId) {
Object.assign(finalParams, {
method: 'web.shop.folder',
shop_id: params.shopId
});
}
return api.get('', finalParams, config.apiCache);
};
/**
* 获取品牌水牌
* @return
*/
const getNodeContent = (params) => {
let finalParams = {
method: 'web.html.content',
mode: params.mode || 'release',
node: params.node || ''
};
return api.get('', finalParams, config.apiCache);
};
/**
* 一周新品上架
* @return
*/
const getWeekNew = (params) => {
let finalParams = {
method: 'web.regular.recent'
};
Object.assign(finalParams, params);
return api.get('', finalParams, config.apiCache);
};
const getBrandCouponAsync = (brandId, uid) => {
let extra = {code: 200};
if (!uid) {
extra.cache = true;
}
return api.get('', {
method: 'app.brand.getBrandIntro',
brand_id: brandId,
uid: uid
}, extra);
};
/**
* 根据关键词搜索品牌店铺信息
* @return
*/
const getBrandShop = (query) => {
let finalParams = {
method: 'web.search.shopListInfo'
};
return api.get('', Object.assign(finalParams, {keyword: query}), config.apiCache);
};
/**
* 根据搜索得到店铺/品牌
*/
const getShopList = params => {
if (!params || !params.query) {
return;
}
return getBrandShop(params.query).then(shops => {
let shopEntry = [];
_.forEach(_.get(shops, 'data.shopList', []), value => {
let shopInfo = {
home: helpers.urlFormat('', null, value.shop_domain || value.brand_domain),
logo: value.shop_logo || value.brand_ico,
shopName: value.shop_name || value.brand_name,
shopType: '',
sort: []
};
if (value.is_global === 'Y') {
shopInfo.home = helpers.urlFormat(GLOBAL_BASE_URI, {brand: value.global_brand_id});
shopInfo.shopType = 'global-brand';
}
// 店铺/品牌的小分类
_.forEach(_.get(value, 'sortInfo.sort', []), sortInfo => {
_.forEach(_.get(sortInfo, 'sub', []), subSort => {
let sortHref;
if (value.is_global !== 'Y') {
sortHref = helpers.urlFormat('', {misort: subSort.sort_id},
value.shop_domain || value.brand_domain);
} else {
sortHref = helpers.urlFormat(GLOBAL_BASE_URI, {
misort: subSort.sort_id,
brand: value.global_brand_id
});
}
shopInfo.sort.push({
href: sortHref,
name: subSort.sort_name
});
});
});
shopEntry.push(shopInfo);
});
return shopEntry;
});
};
/**
* 搜索提示
* @return
*/
const getSuggest = (params) => {
let finalParams = {
method: 'app.search.fuzzy',
keyword: params.keyword || ''
};
return api.get('', finalParams, config.apiCache);
};
/**
* 根据品牌域名获取品牌信息
* @return
*/
const getBrandData = (params) => {
let finalParams = {
method: 'web.brand.byDomain',
domain: params.domain || ''
};
return api.get('', finalParams, config.apiCache);
};
/**
* 根据uid和品牌id判断品牌是否收藏
* @return
*/
const isFavoriteBrand = (uid, brandId) => {
return serviceApi.get(isFavoriteBrandUrl, {
uid: uid,
brandId: brandId
});
};
/**
* 根据shopId获取店铺基本信息
* @return
*/
const getShopInfo = (shopId, uid) => {
let finalParams = {
method: 'app.shops.getIntro',
shop_id: shopId || 0,
uid: uid || 0
};
return api.get('', finalParams, config.apiCache);
};
/**
* 查询店铺下面的所有品牌
*/
const getShopBrands = (shopId) => {
return api.get('', {method: 'app.shops.getShopsBrands', shop_id: shopId || 0}, config.apiCache);
};
/**
* 查询店铺装修
*/
const getShopDecorator = (shopId) => {
return api.get('', {method: 'app.shopsdecorator.getList', shop_id: shopId || 0}, config.apiCache);
};
/**
* 通过品牌获取相关文章
*/
const getArticleByBrand = (brand, udid, limit) => {
let params = {
brand_id: brand || 0,
udid: udid,
limit: limit || 6
};
return serviceApi.get(relateArticleUrl, params);
};
const getBrands4Filter = (params) => {
return api.get('', Object.assign({
method: 'web.regular.aggBrand'
}, params));
};
/**
* 有可能喜欢的商品
* @param int $channel 频道,1代表男生,2代表女生,3代表潮童,4代表创意生活
* @param $uid 用户ID
* @param $udid 设备ID
* @param $rec_pos 位置码
* @param $limit 数量限制
* @return array 接口返回的数据
* */
const lessRecommend = (channelNum, uid, udid, recPos, limit) => {
let param = {
method: 'app.search.newLast7day',
yh_channel: channelNum,
udid: udid,
rec_pos: recPos,
limit: limit
};
if (uid) {
param.uid = uid;
}
return api.get('', param);
};
module.exports = {
getKeyActivityAsync,
getProductList,
getSeoProductList,
getSortList,
getSortIntro,
getSortAds,
getBrandShopFolder,
getBrandShopSeries,
getWeekNew,
getBrandCouponAsync,
getBrandShop,
getSuggest,
getBrandData,
getNodeContent,
isFavoriteBrand,
getShopInfo,
getShopBrands,
getShopDecorator,
getArticleByBrand,
getShopList,
getBrands4Filter,
getProductListOrig,
getSearchCacheKey,
lessRecommend
};
... ...
... ... @@ -58,7 +58,7 @@ passport.use('local', new LocalStrategy({
getLoginStat(clientIp).then((times) => {
let errLoginTimes = _.parseInt(times) || 0;
return LoginApi.signin(type, area, username, password, shoppingKey, clientIp, close).then((result) => {
return req.ctx(LoginApi).signin(type, area, username, password, shoppingKey, close).then((result) => {
if (result.code && (result.code === 200 || result.code === 510) && result.data.uid) {
cache.del(errorLoginKey).catch(() => {});
req.session.type = '';
... ...
... ... @@ -7,7 +7,7 @@
const helpers = global.yoho.helpers;
const config = global.yoho.config;
const service = require('../models/back-service');
const BackService = require('../models/back-service');
const passportHelper = require('../models/passport-helper');
const simpleHeaderModel = require('../../../doraemon/models/simple-header');
const _ = require('lodash');
... ... @@ -24,7 +24,7 @@ const index = (req, res, next) => {
domain: config.cookieDomain
});
service.indexPageDataAsync()
req.ctx(BackService).indexPageDataAsync()
.then(result => {
res.render('back/index', Object.assign({
module: 'passport',
... ... @@ -43,7 +43,7 @@ const validateInputAPI = (req, res, next) => {
let userInput = req.body.phoneNum || '';
let areaCode = (req.body.area || '86').replace('+', '');
service.validateEmailOrMobileAsync(userInput, areaCode)
req.ctx(BackService).validateEmailOrMobileAsync(userInput, areaCode)
.then(result => {
req.inputInfo = result;
next();
... ... @@ -63,7 +63,7 @@ const validateInputPage = (req, res, next) => {
let userInput = req.body.phoneNum || '';
let areaCode = (req.body.area || '86').replace('+', '');
service.validateEmailOrMobileAsync(userInput, areaCode)
req.ctx(BackService).validateEmailOrMobileAsync(userInput, areaCode)
.then(result => {
req.inputInfo = result;
next();
... ... @@ -81,7 +81,7 @@ const getUserInfoAPI = (req, res, next) => {
req.session.type = 'back-step1';
service.findUserAsync(inputInfo.type, inputInfo.phone, inputInfo.area)
req.ctx(BackService).findUserAsync(inputInfo.type, inputInfo.phone, inputInfo.area)
.then(result => {
res.json(result);
})
... ... @@ -96,7 +96,7 @@ const sendCodePage = (req, res, next) => {
let inputInfo = req.inputInfo;
req.session.type = 'back-step1';
service.sendCodeToUserAsync(inputInfo.type, inputInfo.phone, inputInfo.area)
req.ctx(BackService).sendCodeToUserAsync(inputInfo.type, inputInfo.phone, inputInfo.area)
.then(result => {
if (!(result.code && result.code === 200)) {
return res.json({
... ... @@ -160,7 +160,7 @@ const sendBackMobileAPI = (req, res, next) => {
let mobile = req.body.mobile || '';
let area = req.body.area || '86';
service.sendCodeToMobileAsync(area, mobile)
req.ctx(BackService).sendCodeToMobileAsync(area, mobile)
.then(result => {
res.json(result);
})
... ... @@ -230,7 +230,7 @@ const validateCodeByEmailPage = (req, res, next) => {
return next();
}
service.checkEmailCodeAsync(code)
req.ctx(BackService).checkEmailCodeAsync(code)
.then(result => {
if (!result) {
return res.redirect(helpers.urlFormat('/passport/back/index'));
... ... @@ -338,7 +338,7 @@ const verifyCodeByMobileAPI = (req, res) => {
return res.json(ERR);
}
service.verifyCodyByMobileAsync(area, mobile, mobileCode)
req.ctx(BackService).verifyCodyByMobileAsync(area, mobile, mobileCode)
.then(result => {
res.json(result);
})
... ... @@ -377,7 +377,7 @@ const validateCodeByMobilePage = (req, res, next) => {
};
code = new Buffer(code, 'base64').toString();
req.mobileAuth = service.authRequest(data, code);
req.mobileAuth = req.ctx(BackService).authRequest(data, code);
next();
};
... ... @@ -397,7 +397,7 @@ const updatePwdAPI = (req, res, next) => {
let mobileAuth = req.mobileAuth || {};
let newPassword = req.body.pwd || '';
service.updatePwdAsync(code, mobileAuth, newPassword)
req.ctx(BackService).updatePwdAsync(code, mobileAuth, newPassword)
.then(result => {
if (result.status) {
req.session.successType = result.type;
... ... @@ -470,7 +470,7 @@ const weakPwdSuccessPage = (req, res, next) => {
const modPwdByCodeAPI = (req, res, next) => {
let body = req.body;
service.modPwdByCodeAsync({
req.ctx(BackService).modPwdByCodeAsync({
uid: req.user.uid,
oldPwd: body.oldPwd,
newPwd: body.newPwd,
... ...
... ... @@ -9,9 +9,9 @@
const _ = require('lodash');
const helpers = global.yoho.helpers;
const passportHelper = require('../models/passport-helper');
const bindService = require('../models/bind-service');
const loginService = require('../models/login-service');
const userService = require('../models/user-service');
const BindService = require('../models/bind-service');
const LoginService = require('../models/login-service');
const UserService = require('../models/user-service');
// const UserService = require('../models/user-service');
const simpleHeaderModel = require('../../../doraemon/models/simple-header');
... ... @@ -77,19 +77,7 @@ const bind = {
return next();
}
// UserService.findByMobileAsync(area, mobile).then(user => {
// if (user) {
// return {
// thumb: user.headImg,
// userName: user.username,
// loginHref: user.bindLogin
// };
// } else {
// return {};
// }
// })
userService.getUserInfo(area, mobile).then(user => {
req.ctx(UserService).getUserInfo(area, mobile).then(user => {
let data = _.assign(user, {
phoneNum: mobile,
areaCode: area,
... ... @@ -125,8 +113,8 @@ const bind = {
res.render('bind/success', data);
},
_bindCheck: (mobile, openId, area, sourceType) => {
return bindService.bindCheck(mobile, openId, sourceType, area).then(result => {
_bindCheck: (req, mobile, openId, area, sourceType) => {
return req.ctx(BindService).bindCheck(mobile, openId, sourceType, area).then(result => {
if (!result || !result.code) {
return {code: 400, message: '', data: ''};
} else if (result.code === 200 && result.data.is_register === 0) {
... ... @@ -135,17 +123,17 @@ const bind = {
// 绑定流程:code=200 未注册,可绑定
return {code: 200, message: result.message, data: {next: nextUrl}};
} else if (result.code === 200 && result.data.is_register === 1) {
return userService.getUserInfo(area, mobile).then(user => {
return req.ctx(UserService).getUserInfo(area, mobile).then(user => {
// 绑定流程:code=201 已注册 绑定过其他第三方
return {code: 201, message: result.message, data: {user: user}};
});
} else if (result.code === 200 && result.data.is_register === 3) {
// 关联流程
return userService.getUserInfo(area, mobile).then(user => {
return req.ctx(UserService).getUserInfo(area, mobile).then(user => {
return {code: 203, message: result.message, data: {user: user}};
});
} else if (result.code === 506 || result.code === 505) {
return userService.getUserInfo(area, mobile).then(user => {
return req.ctx(UserService).getUserInfo(area, mobile).then(user => {
// 绑定流程:code=506 手机号码注册过,而且该手机号码也已经绑定过该类型第三方
// code=505 手机号码注册过,而且该第三方也已经绑定过手机号
return {code: 205, message: result.message, data: {user: user}};
... ... @@ -176,7 +164,7 @@ const bind = {
* code:506 // 手机号码注册过,而且该手机号码也已经绑定过该类型第三方
*/
bind._bindCheck(mobile, openId, area, sourceType).then(result => {
bind._bindCheck(req, mobile, openId, area, sourceType).then(result => {
return res.json(result);
}).catch(next);
} else {
... ... @@ -207,7 +195,7 @@ const bind = {
*/
bind._bindCheck(mobile, openId, area, sourceType).then(result => {
if (result.code === 201) {
bindService.sendBindMsg(area, mobile).then(d => {
req.ctx(BindService).sendBindMsg(area, mobile).then(d => {
if (d && d.code) {
return res.json(result);
} else {
... ... @@ -230,7 +218,7 @@ const bind = {
return res.json({code: 400, message: '非法请求'});
}
bindService.sendBindMsg(area, mobile).then(result => {
req.ctx(BindService).sendBindMsg(area, mobile).then(result => {
if (result && result.code) {
return res.json(result);
} else {
... ... @@ -243,7 +231,7 @@ const bind = {
let area = req.body.area;
let code = req.body.code;
bindService.checkBindCode(area, mobile, code).then(result => {
req.ctx(BindService).checkBindCode(area, mobile, code).then(result => {
if (result && result.code) {
return res.json(result);
} else {
... ... @@ -259,11 +247,11 @@ const bind = {
let code = _.trim(req.body.code);
let password = _.trim(req.body.password) || '';
bindService.checkBindCode(area, mobile, code).then(result => {
req.ctx(BindService).checkBindCode(area, mobile, code).then(result => {
if (result && result.code !== 200) {
return {code: 402, message: '短信验证码不正确', data: ''};
} else {
return bindService.bindMobile(openId, sourceType, mobile, area, password);
return req.ctx(BindService).bindMobile(openId, sourceType, mobile, area, password);
}
}).then(result => {
if (result && result.code) {
... ... @@ -272,7 +260,7 @@ const bind = {
sourceType: sourceType + '_bind'
});
return loginService.syncUserSession(result.data, req, res).then(() => {
return req.ctx(LoginService).syncUserSession(result.data, req, res).then(() => {
return {code: 200, message: result.message, data: {refer: refer}};
});
} else {
... ... @@ -293,9 +281,9 @@ const bind = {
let code = req.body.code;
if (_.toNumber(mobile) && openId && areaCode && sourceType && code) {
bindService.checkBindCode(areaCode, mobile, code).then(result => {
req.ctx(BindService).checkBindCode(areaCode, mobile, code).then(result => {
if (result && result.code && result.code === 200) {
return bindService.relateMobile(openId, sourceType, mobile, areaCode);
return req.ctx(BindService).relateMobile(openId, sourceType, mobile, areaCode);
} else {
return {code: 402, message: '短信验证码错误', data: ''};
}
... ... @@ -306,7 +294,7 @@ const bind = {
sourceType: sourceType + '_relate'
});
return loginService.syncUserSession(
return req.ctx(LoginService).syncUserSession(
result.data,
req,
res
... ...
... ... @@ -9,8 +9,8 @@
const _ = require('lodash');
const helpers = global.yoho.helpers;
const passportHelper = require('../models/passport-helper');
const certService = require('../models/cert-service');
const userService = require('../models/user-service');
const CertService = require('../models/cert-service');
const UserService = require('../models/user-service');
const simpleHeaderModel = require('../../../doraemon/models/simple-header');
const config = global.yoho.config;
... ... @@ -28,7 +28,7 @@ const cert = {
return res.send(req.query.callback + '(' + JSON.stringify(dest) + ')');
}
certService.checkEmailCertTip(uid)
req.ctx(CertService).checkEmailCertTip(uid)
.then(ret => {
dest.data = _.get(ret, 'data.isBindedOrRelated') === 'N' ? 'Y' : 'N';
res.type('text/javascript');
... ... @@ -87,7 +87,7 @@ const cert = {
let area = req.body.area;
let refer = req.body.refer;
userService.getUserInfo(area, mobile).then(user => {
req.ctx(UserService).getUserInfo(area, mobile).then(user => {
let data = _.assign(user, {
phoneNum: mobile,
areaCode: area,
... ... @@ -131,7 +131,7 @@ const cert = {
* code:200,isCanBind=Y // 不可绑定
*/
certService.certCheck(mobile, area).then(result => {
req.ctx(CertService).certCheck(mobile, area).then(result => {
if (!result || !result.code) {
return {code: 400, message: '', data: ''};
} else if (result.code === 200) {
... ... @@ -158,7 +158,7 @@ const cert = {
let mobile = req.body.mobile;
let area = req.body.area;
certService.sendCertMsg(mobile, area).then(result => {
req.ctx(CertService).sendCertMsg(mobile, area).then(result => {
if (result && result.code) {
return res.json(result);
} else {
... ... @@ -174,7 +174,7 @@ const cert = {
let code = _.trim(req.body.code);
let refer = req.body.refer;
certService.certMobile(uid, mobile, code, area).then(result => {
req.ctx(CertService).certMobile(uid, mobile, code, area).then(result => {
if (result && result.code === 200) {
let url = helpers.urlFormat('/passport/cert/success', {
... ... @@ -207,7 +207,7 @@ const cert = {
let refer = req.body.refer;
let email;
userService.profile(uid).then(info => {
req.ctx(UserService).profile(uid).then(info => {
if (info && info.code === 200) {
email = _.get(info, 'data.email');
} else {
... ... @@ -217,7 +217,7 @@ const cert = {
});
}
certService.relateMobile(uid, email, code, mobile, area).then(result => {
req.ctx(CertService).relateMobile(uid, email, code, mobile, area).then(result => {
if (result && result.code === 200) {
let url = helpers.urlFormat('/passport/cert/success', {
type: 'relate',
... ...
... ... @@ -17,7 +17,7 @@ const helpers = global.yoho.helpers;
const log = global.yoho.logger;
const config = global.yoho.config;
const cache = global.yoho.cache;
const loginService = require('../models/login-service');
const LoginService = require('../models/login-service');
const referWhiteListService = require('../models/refer-service');
const PassportHelper = require('../models/passport-helper');
const simpleHeaderModel = require('../../../doraemon/models/simple-header');
... ... @@ -54,7 +54,7 @@ function doPassportCallback(req, res, user) {
user.openId = user.unionId;
}
return loginService.signinByOpenID(user.nickname, user.openId, user.sourceType, shoppingKey)
return req.ctx(LoginService).signinByOpenID(user.nickname, user.openId, user.sourceType, shoppingKey)
.then((result) => {
if (result.code !== 200) {
return res.redirect(config.siteUrl);
... ... @@ -67,7 +67,7 @@ function doPassportCallback(req, res, user) {
});
} else if (result.data['is_bind'] === 'Y' && result.data.uid) {//eslint-disable-line
return loginService.syncUserSession(result.data, req, res).then(() => {
return req.ctx(LoginService).syncUserSession(result.data, req, res).then(() => {
return refer;
});
}
... ... @@ -178,7 +178,7 @@ const local = {
}
if (_.get(req.body, 'isRemember', 'false') === 'true') {
loginService.rememberAccount({
req.ctx(LoginService).rememberAccount({
area: req.body.areaCode || '86',
account: req.body.account,
password: req.body.password
... ... @@ -199,7 +199,7 @@ const local = {
}
}());
loginService.syncUserSession(user, req, res).then((noCertTip) => {
req.ctx(LoginService).syncUserSession(user, req, res).then((noCertTip) => {
// 弱密码
if (user.code === 510) {
refer = `${config.siteUrl}/passport/back/weak?refer=${refer}`;
... ... @@ -268,7 +268,7 @@ const local = {
});
}
loginService.sendPasswordBySMS(area, mobile).then((result) => {
req.ctx(LoginService).sendPasswordBySMS(area, mobile).then((result) => {
return res.json(result);
}).then(() => {
req.session.captcha = 'yoho4946abcdef#$%&!@';
... ... @@ -286,7 +286,7 @@ const local = {
});
}
loginService.verifyPasswordBySMS(area, mobile, code).then((result) => {
req.ctx(LoginService).verifyPasswordBySMS(area, mobile, code).then((result) => {
if (_.get(result, 'code', 200) !== 200) {
return res.json(result);
}
... ... @@ -316,7 +316,7 @@ const local = {
});
}
loginService.checkUserExitBySMS(area, mobile).then((result) => {
req.ctx(LoginService).checkUserExitBySMS(area, mobile).then((result) => {
if (_.get(result, 'code') !== 200) {
return Promise.reject('check user by sms error');
}
... ... @@ -336,7 +336,7 @@ const local = {
},
qrcode: {
refresh: (req, res, next) => {
loginService.fetchByQrCode().then((result) => {
req.ctx(LoginService).fetchByQrCode().then((result) => {
if (result.code === 200) {
return res.json({
code: 200,
... ... @@ -371,7 +371,7 @@ const local = {
let token = decodeURIComponent(qrcode.substring(qrcode.indexOf('=') + 1));
loginService.checkByQrCode(token).then((result) => {
req.ctx(LoginService).checkByQrCode(token).then((result) => {
if (_.isEmpty(result)) {
return res.json({
code: 400,
... ...
... ... @@ -5,9 +5,9 @@
const _ = require('lodash');
const Promise = require('bluebird');
const passportHelper = require('../models/passport-helper');
const regService = require('../models/reg-service');
const userService = require('../models/user-service');
const loginService = require('../models/login-service');
const RegService = require('../models/reg-service');
const UserService = require('../models/user-service');
const LoginService = require('../models/login-service');
const config = require('../../../config/common');
const simpleHeaderModel = require('../../../doraemon/models/simple-header');
let helpers = global.yoho.helpers;
... ... @@ -76,7 +76,7 @@ let index = (req, res, next) => {
domain: config.cookieDomain
});
regService.getRegData().then((result) => {
req.ctx(RegService).getRegData().then((result) => {
res.render('reg/index', {
simpleHeader: simpleHeaderModel.setSimpleHeaderData(),
title: '新用户注册',
... ... @@ -125,7 +125,7 @@ let checkMobile = (req, res, next) => {
}
// 判断用户是否存在
return userService.findByMobileAsync(area, mobile).then((user) => {
return req.ctx(UserService).findByMobileAsync(area, mobile).then((user) => {
if (!_.isEmpty(user)) {
data.message = '手机号码已经存在';
return res.json(data);
... ... @@ -182,7 +182,7 @@ let sendBindMsg = (req, res, next) => {
}
/* 向手机发送注册验证码 */
let result = yield regService.sendCodeToMobile(area, mobile);
let result = yield req.ctx(RegService).sendCodeToMobile(area, mobile);
req.session.type = 'register-step1';
... ... @@ -210,7 +210,7 @@ let msgCaptcha = (req, res, next) => {
let mobile = req.body.mobile;
let code = req.body.code; // 短信验证码
regService.validMobileCode(area, mobile, code).then((result) => {
req.ctx(RegService).validMobileCode(area, mobile, code).then((result) => {
if (result.code) {
return res.json(result);
} else {
... ... @@ -266,7 +266,7 @@ let mobileRegister = (req, res, next) => {
let password = req.body.password;
let inviteCode = req.body.inviteCode;
let clientIp = req.yoho.clientIp;
let result = yield regService.validMobileCode(area, mobile, code); // 验证注册的标识码是否有效
let result = yield req.ctx(RegService).validMobileCode(area, mobile, code); // 验证注册的标识码是否有效
if (!result.code || result.code !== 200) {
data.message = '验证码错误';
... ... @@ -274,7 +274,7 @@ let mobileRegister = (req, res, next) => {
}
/* 手机注册: 调用注册接口*/
let regResult = yield regService.regMobileAes(
let regResult = yield req.ctx(RegService).regMobileAes(
area, mobile, password, code, cookie.getShoppingKey(req), inviteCode, clientIp
);
... ... @@ -286,7 +286,7 @@ let mobileRegister = (req, res, next) => {
// 清除 session type
req.session.type = '';
return loginService.syncUserSession(regResult.data, req, res).then(() => {
return req.ctx(LoginService).syncUserSession(regResult.data, req, res).then(() => {
return res.json({
code: 200,
message: '注册成功',
... ... @@ -305,7 +305,7 @@ let success = (req, res, next) => {
let goUrl = req.query.next || config.siteUrl;
let goShoppingUrl = req.query.goShoppingUrl || config.siteUrl;
regService.getRegData().then((result) => {
req.ctx(RegService).getRegData().then((result) => {
res.render('reg/success', {
title: '注册成功',
module: 'passport',
... ...
... ... @@ -4,16 +4,22 @@
'use strict';
const api = global.yoho.API;
const aes = require('./aes-pwd');
const YOHOBUY_URL = 'https//www.yohobuy.com/';
/**
module.exports = class extends global.yoho.BaseModel {
constructor(ctx) {
super(ctx);
}
/**
* 获取地区数据
*/
const getAreaDataAsync = () => {
return api.get('', {
getAreaDataAsync() {
return this.get({
data: {
method: 'app.passport.getArea'
}
}).then(result => {
result.data = result.data.map(value => {
value.areaCode = `+${value.area}`;
... ... @@ -30,27 +36,29 @@ const getAreaDataAsync = () => {
return result;
});
};
}
/**
/**
* 通过邮箱找回密码
*
* @param string mail 邮箱地址
*/
const sendCodeToEmailAsync = (email) => {
return api.get('', {
sendCodeToEmailAsync(email) {
return this.get({
data: {
method: 'app.register.backpwdByEmail',
email: email
}
});
};
}
/**
/**
* 根据邮箱验证码修改密码(调用www.yohobuy.com接口)
*
* @param string pwd 新密码
* @param string code 邮箱验证码
*/
const modifyPasswordByEmailAsync = (pwd, code) => {
modifyPasswordByEmailAsync(pwd, code) {
const options = {
url: `${YOHOBUY_URL}passport/back/update`,
form: {
... ... @@ -61,124 +69,127 @@ const modifyPasswordByEmailAsync = (pwd, code) => {
timeout: 3000
};
return api._requestFromAPI(options);
};
return this._requestFromAPI(options);
}
/**
/**
* 通过手机找回密码
*
* @param string mobile 手机号
* @param integer area 地区码ID
*/
const sendCodeToMobileAsync = (mobile, area) => {
return api.get('', {
sendCodeToMobileAsync(mobile, area) {
return this.get({
data: {
mobile: mobile,
area: area,
method: 'app.register.sendBackpwdCodeToMobile'
}
});
};
}
/**
/**
* 校验密码修改手机验证码
*
* @param string mobile 手机号
* @param string code 验证码
* @param integer area 地区码ID
*/
const validateMobileCodeAsync = (mobile, code, area) => {
validateMobileCodeAsync(mobile, code, area) {
area = area || 86;
return api.get('', {
return this.get({
data: {
mobile: mobile,
code: code,
area: area,
method: 'app.register.validBackpwdCode'
}
});
};
}
/**
/**
* 根据手机验证码修改密码
*
* @param string mobile 手机号
* @param string token 验证手机验证码返回的token
* @param integer area 地区码ID
*/
const modifyPasswordByMobileAsync = (mobile, token, newpwd, area)=> {
return api.get('', {
modifyPasswordByMobileAsync(mobile, token, newpwd, area) {
return this.get({
data: {
mobile: mobile,
token: token,
newpwd: newpwd,
area: area,
method: 'app.register.changepwdByMobileCode'
}
});
};
}
/**
/**
* 根据手机验证码修改密码(密码AES加密)
*
* @param string mobile 手机号
* @param string token 验证手机验证码返回的token
* @param integer area 地区码ID
*/
const modifyPasswordByMobileAsyncAes = (mobile, token, newpwd, area)=> {
return api.get('', {
modifyPasswordByMobileAsyncAes(mobile, token, newpwd, area) {
return this.get({
data: {
mobile: mobile,
token: token,
newpwd: aes.aesPwd(newpwd),
area: area,
method: 'app.register.changepwdByMobileCodeAES'
}
});
};
}
/**
/**
* 验证找回邮件code
*/
const checkEmailCodeAsync = (code) => {
return api.get('', {
checkEmailCodeAsync(code) {
return this.get({
data: {
code: code,
method: 'web.passport.checkCodeValid'
}
});
};
}
/**
/**
* 根据邮箱code修改密码
*/
const modifyPasswordByEmailCodeAsync = (code, password) => {
return api.get('', {
modifyPasswordByEmailCodeAsync(code, password) {
return this.get({
data: {
code: code,
newPwd: password,
method: 'app.register.resetPwdByCode'
}
});
};
}
/**
/**
* 根据邮箱code修改密码(AES密码加密)
*/
const modifyPasswordByEmailCodeAsyncAes = (code, password) => {
return api.get('', {
modifyPasswordByEmailCodeAsyncAes(code, password) {
return this.get({
data: {
code: code,
newPwd: aes.aesPwd(password),
method: 'app.register.resetPwdByCodeAES'
}
});
};
}
const modPwdByCodeAsync = (params) => {
return api.get('', Object.assign(params, {
modPwdByCodeAsync(params) {
return this.get({
data: Object.assign(params, {
method: 'app.password.modPwdByCode',
oldPwd: aes.aesPwd(params.oldPwd),
newPwd: aes.aesPwd(params.newPwd)
}));
};
module.exports = {
getAreaDataAsync,
sendCodeToEmailAsync,
modifyPasswordByEmailAsync,
sendCodeToMobileAsync,
validateMobileCodeAsync,
modifyPasswordByMobileAsync,
modifyPasswordByMobileAsyncAes,
checkEmailCodeAsync,
modifyPasswordByEmailCodeAsync,
modifyPasswordByEmailCodeAsyncAes,
modPwdByCodeAsync
})
});
}
};
... ...
... ... @@ -10,17 +10,33 @@ const _ = require('lodash');
const moment = require('moment');
const helpers = global.yoho.helpers;
const api = require('./back-api');
const userService = require('./user-service');
const Api = require('./back-api');
const UserService = require('./user-service');
const passportHelper = require('./passport-helper');
const backHelper = require('./back-helper');
const BACK_LEFT_BANNER_CODE = '3bbaf502c447a2ddad60879042e286d8'; // 找回密码左边的banner
/**
module.exports = class extends global.yoho.BaseModel {
constructor(ctx) {
super(ctx);
this.api = new Api(ctx);
this.userService = new UserService(ctx);
/**
* 验证邮件验证码
*/
this.checkEmailCodeAsync = this.api.checkEmailCodeAsync.bind(this.api);
// 弱密码重置
this.modPwdByCodeAsync = this.api.modPwdByCodeAsync.bind(this.api);
}
/**
* 验证手机和邮箱输入正确性
*/
const validateEmailOrMobileAsync = (userInput, areaCode) => {
validateEmailOrMobileAsync(userInput, areaCode) {
return new Promise(function(resolve, rejected) {
let result = {type: 'email', area: '', phone: ''};
... ... @@ -42,13 +58,13 @@ const validateEmailOrMobileAsync = (userInput, areaCode) => {
});
};
}
/**
/**
* 查找用户
*/
const findUserAsync = (type, phone, area) => {
return co(function * () {
findUserAsync(type, phone, area) {
return co(function* () {
const MESSAGE = {
mobile: '您输入的手机号码尚未注册!',
email: '您输入的邮件账户尚未注册!',
... ... @@ -56,8 +72,8 @@ const findUserAsync = (type, phone, area) => {
};
const findBy = {
email: userService.findByEmailAsync,
mobile: _.rearg(userService.findByMobileAsync, [1, 0]) // 交换参数
email: this.userService.findByEmailAsync.bind(this.userService),
mobile: _.rearg(this.userService.findByMobileAsync.bind(this.userService), [1, 0]) // 交换参数
};
const OK = {code: 200, message: MESSAGE.ok};
... ... @@ -72,33 +88,33 @@ const findUserAsync = (type, phone, area) => {
}
return OK;
})();
};
}).bind(this)();
}
/**
/**
* 发送验证码到用户
*/
const sendCodeToUserAsync = (type, mobile, areaCode) => {
sendCodeToUserAsync(type, mobile, areaCode) {
let sendTo = {
email: api.sendCodeToEmailAsync,
mobile: api.sendCodeToMobileAsync
email: this.api.sendCodeToEmailAsync.bind(this.api),
mobile: this.api.sendCodeToMobileAsync.bind(this.api)
};
return sendTo[type](mobile, areaCode);
};
}
/**
/**
* 发送找回手机号短信
*/
const sendCodeToMobileAsync = (areaCode, mobile) => {
return api.sendCodeToMobileAsync(mobile, areaCode);
};
sendCodeToMobileAsync(areaCode, mobile) {
return this.api.sendCodeToMobileAsync(mobile, areaCode);
}
/**
/**
* 获得首页的数据
*/
const indexPageDataAsync = () => {
return co(function *() {
indexPageDataAsync() {
return co(function* () {
let banner = yield passportHelper.getLeftBannerAsync(BACK_LEFT_BANNER_CODE);
let countryList = passportHelper.getCountry();
... ... @@ -113,19 +129,19 @@ const indexPageDataAsync = () => {
}
};
})();
};
}
/**
/**
* 验证手机验证码
*/
const verifyCodyByMobileAsync = (area, mobile, mobileCode) => {
verifyCodyByMobileAsync(area, mobile, mobileCode) {
const ERR = {
code: 400,
message: '验证码错误!',
data: helpers.urlFormat('/passport/back/index')
};
return api.validateMobileCodeAsync(mobile, mobileCode, area)
return this.api.validateMobileCodeAsync(mobile, mobileCode, area)
.then(result => {
if (!(result.code && result.code === 200)) {
return ERR;
... ... @@ -147,12 +163,12 @@ const verifyCodyByMobileAsync = (area, mobile, mobileCode) => {
};
});
};
}
/**
/**
* 手机 token 合法性验证
*/
const authRequest = (data, token) => {
authRequest(data, token) {
if (!backHelper.validateToken(data, token)) {
return {};
}
... ... @@ -165,13 +181,13 @@ const authRequest = (data, token) => {
} else {
return data;
}
};
}
/**
/**
* 更新密码接口
*/
const updatePwdAsync = (emailToken, mobileToken, newPassword) => {
return co(function * () {
updatePwdAsync(emailToken, mobileToken, newPassword) {
return co(function* () {
let result = {type: 'mobile', status: false};
const ERR = {type: 'unknown', status: false};
... ... @@ -183,7 +199,7 @@ const updatePwdAsync = (emailToken, mobileToken, newPassword) => {
let mobile = mobileToken.mobile;
let area = mobileToken.area;
let token = mobileToken.token;
let modifyStatus = yield api.modifyPasswordByMobileAsyncAes(mobile, token, newPassword, area);
let modifyStatus = yield this.api.modifyPasswordByMobileAsyncAes(mobile, token, newPassword, area);
if (!modifyStatus.code || modifyStatus.code !== 200) {
return ERR;
... ... @@ -192,7 +208,7 @@ const updatePwdAsync = (emailToken, mobileToken, newPassword) => {
result.type = 'mobile';
result.status = true;
} else {
let modifyStatus = yield api.modifyPasswordByEmailCodeAsyncAes(emailToken, newPassword);
let modifyStatus = yield this.api.modifyPasswordByEmailCodeAsyncAes(emailToken, newPassword);
if (!modifyStatus.code || modifyStatus.code !== 200) {
return ERR;
... ... @@ -203,26 +219,6 @@ const updatePwdAsync = (emailToken, mobileToken, newPassword) => {
}
return result;
})();
};
/**
* 验证邮件验证码
*/
const checkEmailCodeAsync = api.checkEmailCodeAsync;
// 弱密码重置
const modPwdByCodeAsync = api.modPwdByCodeAsync;
module.exports = {
validateEmailOrMobileAsync,
findUserAsync,
sendCodeToUserAsync,
sendCodeToMobileAsync,
indexPageDataAsync,
verifyCodyByMobileAsync,
authRequest,
updatePwdAsync,
checkEmailCodeAsync,
modPwdByCodeAsync
}).bind(this)();
}
};
... ...
... ... @@ -5,11 +5,12 @@
* @date 2016/06/21
*/
'use strict';
const api = global.yoho.API;
module.exports = class extends global.yoho.BaseModel {
constructor(ctx) {
super(ctx);
}
const bindCheck = (mobile, openId, sourceType, area) => {
bindCheck(mobile, openId, sourceType, area) {
let params = {
method: 'app.passport.signCheck',
area: area,
... ... @@ -18,29 +19,29 @@ const bindCheck = (mobile, openId, sourceType, area) => {
source_type: sourceType
};
return api.get('', params);
};
return this.get({data: params});
}
const sendBindMsg = (area, mobile) => {
sendBindMsg(area, mobile) {
let params = {
method: 'app.passport.smsbind',
mobile: mobile,
area: area
};
return api.get('', params);
};
return this.get({data: params});
}
const checkBindCode = (area, mobile, code) => {
return api.get('', {
checkBindCode(area, mobile, code) {
return this.get({data: {
method: 'app.register.validRegCode',
mobile: mobile,
area: area,
code: code
});
};
}});
}
const bindMobile = (openId, sourceType, mobile, area, password, nickname) => {
bindMobile(openId, sourceType, mobile, area, password, nickname) {
let params = {
method: 'app.passport.bind',
mobile: mobile,
... ... @@ -57,43 +58,34 @@ const bindMobile = (openId, sourceType, mobile, area, password, nickname) => {
params.nickname = nickname;
}
return api.get('', params);
};
return this.get({data: params});
}
const relateMobile = (openId, sourceType, mobile, area) => {
return api.get('', {
relateMobile(openId, sourceType, mobile, area) {
return this.get({data: {
method: 'app.passport.relatedMobile',
mobile: mobile,
openId: openId,
source_type: sourceType,
area: area
});
};
}});
}
const changeCheck = (mobile, area) => {
return api.get('', {
changeCheck(mobile, area) {
return this.get({data: {
method: 'app.passport.changeCheck',
mobile: mobile,
area: area
});
};
}});
}
const changeMobile = (uid, mobile, area, code) => {
return api.get('', {
changeMobile(uid, mobile, area, code) {
return this.get({data: {
method: 'app.passport.changeMobile',
mobile: mobile,
uid: uid,
code: code,
area: area
});
};
module.exports = {
bindCheck,
sendBindMsg,
checkBindCode,
bindMobile,
relateMobile,
changeCheck,
changeMobile
}});
}
};
... ...
... ... @@ -7,6 +7,10 @@
'use strict';
const api = require('./bind-api');
const BindApi = require('./bind-api');
module.exports = api;
module.exports = class extends BindApi {
constructor(ctx) {
super(ctx);
}
};
... ...
... ... @@ -4,9 +4,12 @@
'use strict';
const api = global.yoho.API;
module.exports = class extends global.yoho.BaseModel {
constructor(ctx) {
super(ctx);
}
const goodsCount = (uid, shoppingKey) => {
goodsCount(uid, shoppingKey) {
let params = {
method: 'app.Shopping.count'
};
... ... @@ -19,9 +22,6 @@ const goodsCount = (uid, shoppingKey) => {
params.shopping_key = shoppingKey;
}
return api.get('', params);
};
module.exports = {
goodsCount
return this.get({data: params});
}
};
... ...
... ... @@ -5,15 +5,19 @@
'use strict';
const api = require('./cart-api');
const Api = require('./cart-api');
const _ = require('lodash');
const goodsCount = (uid, shoppingKey) => {
return api.goodsCount(uid, shoppingKey).then(result => _.get(result, 'data.cart_goods_count', 0));
};
module.exports = class extends global.yoho.BaseModel {
constructor(ctx) {
super(ctx);
this.api = new Api(ctx);
}
module.exports = {
goodsCount
goodsCount(uid, shoppingKey) {
return this.api.goodsCount(uid, shoppingKey).then(result => _.get(result, 'data.cart_goods_count', 0));
}
};
... ...
... ... @@ -4,38 +4,32 @@
'use strict';
const api = global.yoho.API;
module.exports = class extends global.yoho.BaseModel {
constructor(ctx) {
super(ctx);
}
const certCheck = (mobile, area) => {
certCheck(mobile, area) {
let params = {
method: 'app.passport.checkIsCanBind',
area: area,
mobile: mobile
};
return api.get('', params);
};
return this.get({data: params});
}
const sendCertMsg = (mobile, area) => {
sendCertMsg(mobile, area) {
let params = {
method: 'app.passport.smsbind',
mobile: mobile,
area: area
};
return api.get('', params);
};
/* const checkCertCode = (area, mobile, code) => {
return api.get('', {
method: 'app.register.validRegCode',
mobile: mobile,
area: area,
code: code
});
};*/
return this.get({data: params});
}
const certMobile = (uid, mobile, code, area) => {
certMobile(uid, mobile, code, area) {
let params = {
method: 'app.passport.changeMobile',
uid: uid,
... ... @@ -44,52 +38,27 @@ const certMobile = (uid, mobile, code, area) => {
code: code
};
return api.get('', params);
};
return this.get({data: params});
}
const relateMobile = (uid, email, code, mobile, area) => {
return api.get('', {
relateMobile(uid, email, code, mobile, area) {
return this.get({data: {
method: 'app.passport.relatedMobileAndEmail',
uid: uid,
email: email,
mobile: mobile,
code: code,
area: area
});
};
/* const changeCheck = (mobile, area) => {
return api.get('', {
method: 'app.passport.changeCheck',
mobile: mobile,
area: area
});
};*/
/* const changeMobile = (uid, mobile, area, code) => {
return api.get('', {
method: 'app.passport.changeMobile',
mobile: mobile,
uid: uid,
code: code,
area: area
});
};*/
const checkEmailCertTip = (uid) => {
}});
}
checkEmailCertTip(uid) {
let param = {
method: 'app.passport.checkIsBindedOrRelated',
uid: uid
};
return api.get('', param);
return this.get({data: param});
}
};
module.exports = {
certCheck,
sendCertMsg,
certMobile,
relateMobile,
checkEmailCertTip
};
... ...
'use strict';
const api = require('./cert-api');
const CertApi = require('./cert-api');
module.exports = api;
module.exports = class extends CertApi {
constructor(ctx) {
super(ctx);
}
};
... ...
... ... @@ -5,10 +5,13 @@
'use strict';
const aes = require('./aes-pwd');
const api = global.yoho.API;
const logger = global.yoho.logger;
const signinByPasswordWithAes = (area, profile, password, shoppingKey, clientIp) => {
module.exports = class extends global.yoho.BaseModel {
constructor(ctx) {
super(ctx);
}
signinByPasswordWithAes(area, profile, password, shoppingKey) {
let param = {
method: 'sesame.flowering.higher',
area: area,
... ... @@ -20,17 +23,10 @@ const signinByPasswordWithAes = (area, profile, password, shoppingKey, clientIp)
param.shopping_key = shoppingKey;
}
logger.info('login successfully by password from', clientIp);
return api.post('', param, {
headers: {
'user-agent': 'yoho/nodejs',
'X-YOHO-IP': clientIp
return this.post({data: param});
}
});
};
const signinBySMS = (area, mobile, token, shoppingKey) => {
signinBySMS(area, mobile, token, shoppingKey) {
let param = {
method: 'app.passport.autoSignin',
area: area,
... ... @@ -42,10 +38,10 @@ const signinBySMS = (area, mobile, token, shoppingKey) => {
param.shopping_key = shoppingKey;
}
return api.post('', param);
};
return this.post({data: param});
}
const signinByQrCode = (__1, __2, code, shoppingKey) => { // eslint-disable-line
signinByQrCode(__1, __2, code, shoppingKey) { // eslint-disable-line
let param = {
method: 'app.twoDimen.qrCodeLogin',
code: code.substring(code.indexOf('=') + 1)
... ... @@ -55,19 +51,19 @@ const signinByQrCode = (__1, __2, code, shoppingKey) => { // eslint-disable-line
param.shopping_key = shoppingKey;
}
return api.post('', param);
};
return this.post({data: param});
}
const checkByQrCode = (code) => {
checkByQrCode(code) {
let param = {
method: 'app.twoDimen.loginCheck',
code: code
};
return api.post('', param);
};
return this.post({data: param});
}
const sendPasswordBySMS = (area, mobile) => {
sendPasswordBySMS(area, mobile) {
let param = {
method: 'app.message.sendSms',
area: area,
... ... @@ -75,28 +71,28 @@ const sendPasswordBySMS = (area, mobile) => {
type: 1 // 手机快捷登录短信验证码
};
return api.get('', param);
};
return this.get({data: param});
}
const checkUserExitBySMS = (area, mobile) => {
return api.get('', {
checkUserExitBySMS(area, mobile) {
return this.get({data: {
method: 'app.passport.checkUserExist',
area: area,
mobile: mobile
});
};
}});
}
const verifyPasswordBySMS = (area, mobile, code) => {
return api.get('', {
verifyPasswordBySMS(area, mobile, code) {
return this.get({data: {
method: 'app.message.verifySmsCode',
area: area,
mobile: mobile,
code: code,
type: 1 // 手机快捷登录短信验证码
});
};
}});
}
const signinByOpenID = (nickname, openId, sourceType, shoppingKey) => {
signinByOpenID(nickname, openId, sourceType, shoppingKey) {
let param = {
nickname: nickname,
openId: openId,
... ... @@ -108,16 +104,6 @@ const signinByOpenID = (nickname, openId, sourceType, shoppingKey) => {
param.shopping_key = shoppingKey;
}
return api.get('', param);
};
module.exports = {
signinByPasswordWithAes,
signinBySMS,
signinByQrCode,
checkByQrCode,
sendPasswordBySMS,
checkUserExitBySMS,
verifyPasswordBySMS,
signinByOpenID
return this.get({data: param});
}
};
... ...
... ... @@ -15,26 +15,40 @@ const AUTH_TIME = 2592000000;
const Promise = require('bluebird');
const cartService = require('./cart-service');
const userService = require('./user-service');
const api = require('./login-api');
const CartService = require('./cart-service');
const UserService = require('./user-service');
const LoginApi = require('./login-api');
const logger = global.yoho.logger;
const signin = (type, area, profile, password, shoppingKey, clientIp, closePasswordLogin) => {
module.exports = class extends global.yoho.BaseModel {
constructor(ctx) {
super(ctx);
this.api = new LoginApi(ctx);
this.cartService = new CartService(ctx);
this.userService = new UserService(ctx);
this.checkByQrCode = this.api.checkByQrCode.bind(this.api);
this.sendPasswordBySMS = this.api.sendPasswordBySMS.bind(this.api);
this.checkUserExitBySMS = this.api.checkUserExitBySMS.bind(this.api);
this.verifyPasswordBySMS = this.api.verifyPasswordBySMS.bind(this.api);
this.signinByOpenID = this.api.signinByOpenID.bind(this.api);
}
signin(type, area, profile, password, shoppingKey, close) {
let loginBy = {
password: api.signinByPasswordWithAes,
sms: api.signinBySMS,
qrcode: api.signinByQrCode
password: this.api.signinByPasswordWithAes.bind(this.api),
sms: this.api.signinBySMS.bind(this.api),
qrcode: this.api.signinByQrCode.bind(this.api)
};
if (closePasswordLogin) {
if (close) {
delete loginBy.password;
}
return loginBy[type](area, profile, password, shoppingKey, clientIp);
};
return loginBy[type](area, profile, password, shoppingKey);
}
const syncUserSession = (user, req, res) => {
syncUserSession(user, req, res) {
let uid = user.uid;
let sessionKey = user.session_key;
... ... @@ -56,9 +70,10 @@ const syncUserSession = (user, req, res) => {
};
return Promise.all([
userService.profile(uidObj),
cartService.goodsCount(uidObj),
userService.checkNoCertEmailUser(uidObj).catch(err => logger(`checkNoCertEmailUser${uid}err: ${err}`))
this.userService.profile(uidObj),
this.cartService.goodsCount(uidObj),
this.userService.checkNoCertEmailUser(uidObj)
.catch(err => logger(`checkNoCertEmailUser${uid}err: ${err}`))
]).spread((userInfo, count, isTipCert) => {
let salt = uuid.v4().substr(0, 8);
let saltedUid = uid + salt;
... ... @@ -130,9 +145,9 @@ const syncUserSession = (user, req, res) => {
}
});
};
}
const rememberAccount = (accountInfo, req, res) => {
rememberAccount(accountInfo, req, res) {
let aWeek = (new Date()).getTime() / 1000 + 504000; // 504000-一周
let rememKey = md5(md5(accountInfo.account + accountInfo.password + accountInfo.area));
... ... @@ -148,9 +163,9 @@ const rememberAccount = (accountInfo, req, res) => {
// if (!cache.get(rememKey)) {
// cache.set(rememKey, accountInfo, aWeek);
// }
};
}
const fetchByQrCode = () => {
fetchByQrCode() {
let code = {
qrcode: uuid.v4(),
time: new Date().getTime()
... ... @@ -164,16 +179,5 @@ const fetchByQrCode = () => {
},
code: 200
});
};
module.exports = {
signin,
syncUserSession,
rememberAccount,
fetchByQrCode,
checkByQrCode: api.checkByQrCode,
sendPasswordBySMS: api.sendPasswordBySMS,
checkUserExitBySMS: api.checkUserExitBySMS,
verifyPasswordBySMS: api.verifyPasswordBySMS,
signinByOpenID: api.signinByOpenID
}
};
... ...
... ... @@ -13,7 +13,7 @@ const indexService = require('./index-service');
/**
* 获得图片
*/
const getLeftBannerAsync = (resourceCode) => {
function getLeftBannerAsync(resourceCode) {
const DEFAULT_VALUE = {
img: 'https://img12.static.yhbimg.com/' +
'yhb-img01/2015/12/01/07/020a0b6e7ff908d0c2bc4045b4fef42b9f.png?imageView/2/w/252/h/190',
... ... @@ -35,7 +35,7 @@ const getLeftBannerAsync = (resourceCode) => {
return value;
})();
};
}
/**
* 国家数据
... ...
... ... @@ -8,19 +8,23 @@
'use strict';
const aes = require('./aes-pwd');
const api = global.yoho.API;
let sendCodeToMobile = (area, mobile) => {
module.exports = class extends global.yoho.BaseModel {
constructor(ctx) {
super(ctx);
}
sendCodeToMobile(area, mobile) {
let params = {
method: 'app.register.sendRegCodeToMobile',
area: area,
mobile: mobile
};
return api.post('', params);
};
return this.post({data: params});
}
let validMobileCode = (area, mobile, code) => {
validMobileCode(area, mobile, code) {
let params = {
method: 'app.register.validRegCode',
area: area,
... ... @@ -28,10 +32,10 @@ let validMobileCode = (area, mobile, code) => {
code: code
};
return api.post('', params);
};
return this.post({data: params});
}
let regMobileAes = (area, mobile, password, code, shoppingKey, inviteCode, clientIp)=> {
regMobileAes(area, mobile, password, code, shoppingKey, inviteCode) {
let params = {
method: 'app.passport.registerAES',
area: area,
... ... @@ -48,16 +52,6 @@ let regMobileAes = (area, mobile, password, code, shoppingKey, inviteCode, clien
params.inviteCode = inviteCode;
}
return api.post('', params, {
headers: {
'user-agent': 'yoho/nodejs',
'X-YOHO-IP': clientIp
return this.post({data: params});
}
});
};
module.exports = {
sendCodeToMobile,
validMobileCode,
regMobileAes
};
... ...
... ... @@ -3,14 +3,22 @@
*/
'use strict';
const passportHelper = require('./passport-helper');
const api = require('./reg-api');
const Api = require('./reg-api');
const REGISTER_LEFT_BANNER_CODE = 'c479ec90120cae7f96e52922b4917064'; // 注册左边的banner
let getRegData = () => {
module.exports = class extends global.yoho.BaseModel {
constructor(ctx) {
super(ctx);
this.api = new Api();
this.sendCodeToMobile = this.api.sendCodeToMobile.bind(this.api);
this.validMobileCode = this.api.validMobileCode.bind(this.api);
this.regMobileAes = this.api.regMobileAes.bind(this.api);
}
getRegData() {
return passportHelper.getLeftBannerAsync(REGISTER_LEFT_BANNER_CODE);
}
};
module.exports = Object.assign(api, {
getRegData
});
... ...
... ... @@ -4,18 +4,23 @@
'use strict';
const _ = require('lodash');
const api = global.yoho.API;
const EMPTY = {};
/**
module.exports = class extends global.yoho.BaseModel {
constructor(ctx) {
super(ctx);
}
/**
* 根据手机号获取用户信息
*/
const findByMobileAsync = (area, mobile) => {
return api.get('', {
findByMobileAsync(area, mobile) {
return this.get({
data: {
mobile: mobile,
area: area,
method: 'app.passport.getProfileByMobile'
}
}).then(result => {
if (!result.code || result.code !== 200 || !result.data || _.isEmpty(result.data)) {
return EMPTY;
... ... @@ -25,15 +30,17 @@ const findByMobileAsync = (area, mobile) => {
}).catch(() => {
return EMPTY;
});
};
}
/**
/**
* 根据邮箱获取用户信息
*/
const findByEmailAsync = (email) => {
return api.get('', {
findByEmailAsync(email) {
return this.get({
data: {
email: email,
method: 'app.passport.getProfileByEmail'
}
}).then(result => {
if (!result.code || result.code !== 200 || !result.data || _.isEmpty(result.data)) {
return EMPTY;
... ... @@ -44,32 +51,25 @@ const findByEmailAsync = (email) => {
}).catch(() => {
return EMPTY;
});
};
}
const profile = (uid) => {
profile(uid) {
let param = {
uid: uid,
method: 'app.passport.profile'
};
return api.get('', param);
};
return this.get({data: param});
}
const checkNoCertEmailUser = (uid) => {
checkNoCertEmailUser(uid) {
let param = {
method: 'app.passport.checkIsNeedPopupRelated',
uid: uid
};
return api.get('', param);
return this.get({data: param});
}
};
module.exports = {
findByMobileAsync,
findByEmailAsync,
profile,
checkNoCertEmailUser
};
... ...
... ... @@ -3,17 +3,29 @@
*/
'use strict';
const api = require('./user-api');
const Api = require('./user-api');
const helpers = global.yoho.helpers;
const DEFAULT_HEAD_IMG_ICO = 'https://img10.static.yhbimg.com/headimg/2013/11/28/09/01cae078abe5fe320c88cdf4c220212688.gif?imageView/2/w/100/h/100';
/**
module.exports = class extends global.yoho.BaseModel {
constructor(ctx) {
super(ctx);
this.api = new Api(ctx);
this.findByMobileAsync = this.api.findByMobileAsync.bind(this.api);
this.findByEmailAsync = this.api.findByEmailAsync.bind(this.api);
this.profile = this.api.profile.bind(this.api);
this.checkNoCertEmailUser = this.api.checkNoCertEmailUser.bind(this.api);
}
/**
* 第三方登录 根据手机号获取用户相关信息
*/
const getUserInfo = (area, mobile) => {
return api.findByMobileAsync(area, mobile).then(user => {
getUserInfo(area, mobile) {
return this.api.findByMobileAsync(area, mobile).then(user => {
let profile = (user.profile_name || mobile).toString();
if ((profile.length === 11 && profile.indexOf('*') < 0) || (profile.indexOf('-') >= 0 &&
... ... @@ -27,8 +39,5 @@ const getUserInfo = (area, mobile) => {
bindLogin: helpers.urlFormat('/signin.html', {bindMobile: mobile, bindArea: area})
};
});
}
};
module.exports = Object.assign(api, {
getUserInfo
});
... ...
... ... @@ -12,12 +12,12 @@ module.exports = class extends global.yoho.BaseModel {
}
getBannerInfoAsync(bid) {
return this.get({data: {
return this.get({
data: {
method: 'web.brand.banner',
brand_id: bid
}, params: {
cache: config.apiCache
}});
}, param: config.apiCache
});
}
};
... ...
... ... @@ -17,8 +17,6 @@ module.exports = class extends global.yoho.BaseModel {
product_id: pid
};
return this.get({data, params: {
cache: config.apiCache
}});
return this.get({data, param: config.apiCache });
}
};
... ...
... ... @@ -71,9 +71,8 @@ module.exports = class extends global.yoho.BaseModel {
data: {
method: 'web.productBanner.data',
product_id: pid
}, params: {
cache: config.apiCache
}
}, param: config.apiCache
});
}
... ... @@ -85,9 +84,7 @@ module.exports = class extends global.yoho.BaseModel {
data: {
method: 'h5.product.intro',
productskn: skn
}, params: {
cache: config.apiCache
}
}, param: config.apiCache
});
}
... ... @@ -99,9 +96,7 @@ module.exports = class extends global.yoho.BaseModel {
data: {
method: 'web.product.refundExchange',
product_skn: skn
}, params: {
cache: config.apiCache
}
}, param: config.apiCache
});
}
... ... @@ -113,9 +108,7 @@ module.exports = class extends global.yoho.BaseModel {
data: {
method: 'web.productComfort.data',
product_id: pid
}, params: {
cache: config.apiCache
}
}, param: config.apiCache
});
}
... ... @@ -127,9 +120,7 @@ module.exports = class extends global.yoho.BaseModel {
data: {
method: 'web.productModelTry.data',
product_skn: skn
}, params: {
cache: config.apiCache
}
}, param: config.apiCache
});
}
... ... @@ -162,11 +153,7 @@ module.exports = class extends global.yoho.BaseModel {
data.current_vip_level = vipLevel;
}
return this.get({
data, params: {
cache: config.apiCache
}
});
return this.get({ data, param: config.apiCache });
}
/**
... ... @@ -178,11 +165,7 @@ module.exports = class extends global.yoho.BaseModel {
product_skn: skn
};
return this.get({
data, params: {
cache: config.apiCache
}
});
return this.get({ data, param: config.apiCache });
}
/**
... ... @@ -202,11 +185,7 @@ module.exports = class extends global.yoho.BaseModel {
data.product_skn = skn;
}
return this.get({
data, params: {
cache: config.apiCache
}
});
return this.get({ data, param: config.apiCache });
}
/**
... ... @@ -244,7 +223,7 @@ module.exports = class extends global.yoho.BaseModel {
method: 'web.search.findLike',
limit: limit || 10,
product_skn: skn
}, params: {
}, param: {
cache: 86400
}
});
... ...
... ... @@ -27,7 +27,7 @@ module.exports = class extends global.yoho.BaseModel {
return this.get({
url: 'product/api/v2/detail/getlist',
data: finalParams,
params: {cache: config.apiCache},
param: config.apiCache,
api: global.yoho.GlobalAPI
});
}
... ... @@ -39,7 +39,7 @@ module.exports = class extends global.yoho.BaseModel {
physical_channel: channelNum,
product_skn: skn
},
params: { cache: config.apiCache },
param: config.apiCache,
api: global.yoho.GlobalAPI
});
}
... ... @@ -52,7 +52,7 @@ module.exports = class extends global.yoho.BaseModel {
product_skn: skn,
return_type: 'html'
},
params: {cache: config.apiCache},
param: config.apiCache,
api: global.yoho.GlobalAPI
});
}
... ... @@ -61,7 +61,7 @@ module.exports = class extends global.yoho.BaseModel {
return this.get({
url: 'editor/api/v1/brand/get',
data: { brandId: brand },
params: {cache: config.apiCache},
param: config.apiCache,
api: global.yoho.GlobalAPI
});
}
... ...
... ... @@ -54,7 +54,7 @@ module.exports = class extends global.yoho.BaseModel {
size: params.size || 0,
yh_channel: yhChannel[tempChannel].channel,
type: params.type || 0
}, params: {cache: config.apiCache}
}, param: config.apiCache
});
}
... ... @@ -67,7 +67,7 @@ module.exports = class extends global.yoho.BaseModel {
return this.get({
url: 'operations/api/v5/resource/home',
data: params,
params: {cache: config.apiCache},
param: config.apiCache,
api: global.yoho.ServiceAPI
});
}
... ... @@ -89,7 +89,7 @@ module.exports = class extends global.yoho.BaseModel {
stocknumber: 1, // 过滤出库存 > 1的商品
limit: params.limit || 5,
outlets: params.outlets || 1 // 默认取奥莱商品
}, params: {cache: config.apiCache}
}, param: config.apiCache
});
}
... ... @@ -123,6 +123,6 @@ module.exports = class extends global.yoho.BaseModel {
tempParams[paramsName] = params[paramsName];
}
});
return this.get({data: tempParams, params: {cache: config.apiCache}});
return this.get({data: tempParams, param: config.apiCache});
}
};
... ...
... ... @@ -47,7 +47,7 @@ module.exports = class extends global.yoho.BaseModel {
finalParams.yh_channel = yhChannel[params.channel].channel;
}
return this.get({data: Object.assign(finalParams, params), params: {cache: config.apiCache}});
return this.get({data: Object.assign(finalParams, params), param: config.apiCache});
}
/**
... ... @@ -61,7 +61,7 @@ module.exports = class extends global.yoho.BaseModel {
data: {
method: 'app.sale.getBreakingSort',
yh_channel: yhChannel[tempChannel].channel
}, params: {cache: config.apiCache}
}, param: config.apiCache
});
}
... ... @@ -79,7 +79,7 @@ module.exports = class extends global.yoho.BaseModel {
sort: '2',
plateform: '1',
yh_channel: tempChannel.channel
}, params: {cache: config.apiCache}
}, param: config.apiCache
});
}
... ... @@ -93,7 +93,7 @@ module.exports = class extends global.yoho.BaseModel {
data: {
content_code: cCode
},
params: {cache: config.apiCache},
param: config.apiCache,
api: global.yoho.ServiceAPI
});
}
... ... @@ -106,7 +106,7 @@ module.exports = class extends global.yoho.BaseModel {
return this.get({
data: {
method: 'app.sort.get'
}, params: {cache: config.apiCache}
}, param: config.apiCache
});
}
... ... @@ -126,7 +126,7 @@ module.exports = class extends global.yoho.BaseModel {
data: {
method: 'app.passport.profile',
uid: uid
}, params: {cache: true}
}, param: {cache: true}
});
}
... ... @@ -141,7 +141,7 @@ module.exports = class extends global.yoho.BaseModel {
method: 'app.resources.getOneSpecial',
special_id: specialId
},
params: {
param: {
code: 200,
cache: true
}
... ...
... ... @@ -45,7 +45,7 @@ function getKeyActivityAsync(query) {
data: {
method: 'app.search.word',
query: query
}, params: {
}, param: {
catch: true,
code: 200
}
... ... @@ -143,7 +143,7 @@ function getSeoProductList(params, from) {
}
function getSortListOrig(finalParams) {
return this.get({data: finalParams, params: {cache: config.apiCache}});
return this.get({data: finalParams, param: config.apiCache});
}
/**
... ... @@ -221,7 +221,7 @@ function getSortIntro(params) {
};
Object.assign(finalParams, params);
return this.get({data: finalParams, params: {cache: config.apiCache}});
return this.get({data: finalParams, param: config.apiCache});
}
/**
... ... @@ -234,7 +234,7 @@ function getSortAds(params) {
};
Object.assign(finalParams, params);
return this.get({data: finalParams, params: {cache: config.apiCache}});
return this.get({data: finalParams, param: config.apiCache});
}
/**
... ... @@ -256,7 +256,7 @@ function getBrandShopSeries(params) {
});
}
return this.get({data: finalParams, params: {cache: config.apiCache}});
return this.get({data: finalParams, param: config.apiCache});
}
/**
... ... @@ -278,7 +278,7 @@ function getBrandShopFolder(params) {
});
}
return this.get({data: finalParams, params: {cache: config.apiCache}});
return this.get({data: finalParams, param: config.apiCache});
}
/**
... ... @@ -292,7 +292,7 @@ function getNodeContent(params) {
node: params.node || ''
};
return this.get({data: finalParams, params: {cache: config.apiCache}});
return this.get({data: finalParams, param: config.apiCache});
}
/**
... ... @@ -306,7 +306,7 @@ function getWeekNew(params) {
};
Object.assign(finalParams, params);
return this.get({data: finalParams, params: {cache: config.apiCache}});
return this.get({data: finalParams, param: {cache: config.apiCache}});
}
function getBrandCouponAsync(brandId, uid) {
... ... @@ -321,7 +321,7 @@ function getBrandCouponAsync(brandId, uid) {
method: 'app.brand.getBrandIntro',
brand_id: brandId,
uid: uid
}, params: extra
}, param: extra
});
}
... ... @@ -334,7 +334,7 @@ function getBrandShop(query) {
method: 'web.search.shopListInfo'
};
return this.get({data: Object.assign(finalParams, {keyword: query}), params: {cache: config.apiCache}});
return this.get({data: Object.assign(finalParams, {keyword: query}), param: config.apiCache});
}
/**
... ... @@ -401,7 +401,7 @@ function getSuggest(params) {
keyword: params.keyword || ''
};
return this.get({data: finalParams, params: {cache: config.apiCache}});
return this.get({data: finalParams, param: config.apiCache});
}
... ... @@ -415,7 +415,7 @@ function getBrandData(params) {
domain: params.domain || ''
};
return this.get({data: finalParams, params: {cache: config.apiCache}});
return this.get({data: finalParams, param: config.apiCache});
}
/**
... ... @@ -444,7 +444,7 @@ function getShopInfo(shopId, uid) {
uid: uid || 0
};
return this.get({data: finalParams, params: {cache: config.apiCache}});
return this.get({data: finalParams, param: config.apiCache});
}
... ... @@ -454,7 +454,7 @@ function getShopInfo(shopId, uid) {
function getShopBrands(shopId) {
return this.get({
data: {method: 'app.shops.getShopsBrands', shop_id: shopId || 0},
params: {cache: config.apiCache}
param: config.apiCache
});
}
... ... @@ -464,7 +464,7 @@ function getShopBrands(shopId) {
function getShopDecorator(shopId) {
return this.get({
data: {method: 'app.shopsdecorator.getList', shop_id: shopId || 0},
params: {cache: config.apiCache}
param: config.apiCache
});
}
... ...
... ... @@ -18,7 +18,7 @@ module.exports = class extends global.yoho.BaseModel {
data: {
method: 'app.shopsdecorator.getList',
shop_id: shopId
}, params: {cache: config.apiCache}
}, param: config.apiCache
});
}
... ... @@ -39,7 +39,7 @@ module.exports = class extends global.yoho.BaseModel {
method: 'shop.coupons.list',
shop_id: shopId,
uid: uid
}, params: extra
}, param: extra
});
}
... ... @@ -75,7 +75,7 @@ module.exports = class extends global.yoho.BaseModel {
return this.get({
data: finalParams,
params: {cache: config.apiCache}
param: config.apiCache
});
}
};
... ...
... ... @@ -22,7 +22,7 @@ module.exports = class extends global.yoho.BaseModel {
*/
getVerifiedTotal() {
return this.get({data: {method: 'app.student.verifiedStudentTotal'}, params: {cache: config.apiCache}});
return this.get({data: {method: 'app.student.verifiedStudentTotal'}, param: config.apiCache});
}
/**
... ... @@ -31,7 +31,7 @@ module.exports = class extends global.yoho.BaseModel {
*/
getEduLevelList() {
return this.get({data: {method: 'app.studentMarket.getEducationLevelList'}, params: {cache: config.apiCache}});
return this.get({data: {method: 'app.studentMarket.getEducationLevelList'}, param: config.apiCache});
}
/**
... ... @@ -43,7 +43,7 @@ module.exports = class extends global.yoho.BaseModel {
method: 'app.studentMarket.getAddressList'
};
return this.get({data: finalParams, params: {cache: config.apiCache}});
return this.get({data: finalParams, param: config.apiCache});
}
/**
... ... @@ -56,7 +56,7 @@ module.exports = class extends global.yoho.BaseModel {
areaCode: areaCode
};
return this.get({data: finalParams, params: {cache: config.apiCache}});
return this.get({data: finalParams, param: config.apiCache});
}
/**
... ... @@ -71,7 +71,7 @@ module.exports = class extends global.yoho.BaseModel {
};
Object.assign(finalParams, params);
return this.get({data: finalParams, params: {cache: config.apiCache}});
return this.get({data: finalParams, param: config.apiCache});
}
/**
... ... @@ -87,7 +87,7 @@ module.exports = class extends global.yoho.BaseModel {
page_url: pageUrl
};
return this.get({data: finalParams, params: {cache: config.apiCache}});
return this.get({data: finalParams, param: config.apiCache});
}
/**
... ... @@ -104,7 +104,7 @@ module.exports = class extends global.yoho.BaseModel {
enrollment_year: enrollmentYear
};
return this.get({data: finalParams, params: {cache: config.apiCache}});
return this.get({data: finalParams, param: config.apiCache});
}
/**
... ... @@ -122,7 +122,7 @@ module.exports = class extends global.yoho.BaseModel {
finalParams.uid = uid;
}
return this.get({data: finalParams, params: {cache: config.apiCache}});
return this.get({data: finalParams, param: config.apiCache});
}
... ...
... ... @@ -41,10 +41,10 @@ module.exports = {
// platformApi: 'http://172.16.6.210:8088/',
// gray
// singleApi: 'http://single.gray.yohops.com/',
// api: 'http://api.gray.yohops.com/',
// service: 'http://service.gray.yohops.com/',
// platformApi: 'http://172.16.6.210:8088/',
singleApi: 'http://single.gray.yohops.com/',
api: 'http://api.gray.yohops.com/',
service: 'http://service.gray.yohops.com/',
platformApi: 'http://172.16.6.210:8088/',
// dev
// api: 'http://dev-api.yohops.com:9999/',
... ...