Authored by htoooth

list

... ... @@ -6,15 +6,14 @@
'use strict';
// TODO: ctx
const mRoot = '../models';
const list = require(`${mRoot}/list`);
const listSeoMap = require(`${global.middleware}/seo/listSeoMap`);
const helpers = global.yoho.helpers;
const _ = require('lodash');
const tdk = require('../../../utils/getTDK');
// 搜索相关接口
const searchApi = require(`${mRoot}/search-api`);
const searchApi = require('../models/ctx-search-api');
const list = require('../models/list');
// 店铺页
const shop = (shopId, req, res, next, brandInfo) => {
... ... @@ -33,7 +32,7 @@ const shop = (shopId, req, res, next, brandInfo) => {
description: TDKObj[3]
};
}
return list.getShopInfo(shopId, req.user.uid).then(shopInfo => {
return req.ctx(list).getShopInfo(shopId, req.user.uid).then(shopInfo => {
let pjax = params._pjax;
// 获取不到店铺信息跳转至首页
... ... @@ -50,7 +49,7 @@ const shop = (shopId, req, res, next, brandInfo) => {
if (+shopInfo.shopTemplateType === 2) { // 经典模板
if (pjax) {
list.getShopGoodsData(shopId, req.yoho.channel, params, shopInfo).then(result => {
req.ctx(list).getShopGoodsData(shopId, req.yoho.channel, params, shopInfo).then(result => {
Object.assign(result, {
shopId: shopId,
layout: false
... ... @@ -60,7 +59,7 @@ const shop = (shopId, req, res, next, brandInfo) => {
return;
}
list.getShopData(shopId, req.yoho.channel, params, shopInfo).then(result => {
req.ctx(list).getShopData(shopId, req.yoho.channel, params, shopInfo).then(result => {
Object.assign(result, {
page: 'shop',
shopId: shopId
... ... @@ -74,7 +73,7 @@ const shop = (shopId, req, res, next, brandInfo) => {
res.render('list/shop-index', result);
}).catch(next);
} else { // 基础模板
list.getBaseShopData(params, Object.assign({uid: req.user.uid}, brandInfo),
req.ctx(list).getBaseShopData(params, Object.assign({uid: req.user.uid}, brandInfo),
req.yoho.channel, shopId).then(result => {
Object.assign(result, {page: 'list'});
... ... @@ -102,7 +101,7 @@ exports.index = (req, res, next) => {
let resData = {};
let qs = decodeURIComponent(req._parsedOriginalUrl.query || '');
list.getListData(Object.assign(req.query, {uid: req.user.uid, prid: req.user.prid}),
req.ctx(list).getListData(Object.assign(req.query, {uid: req.user.uid, prid: req.user.prid}),
req.yoho.channel).then(result => {
Object.assign(resData, result);
... ... @@ -137,7 +136,7 @@ exports.index = (req, res, next) => {
exports.new = (req, res, next) => {
let resData = {};
list.getListNewData(Object.assign({order: 's_t_desc'}, req.query), req.yoho.channel).then(result => {
req.ctx(list).getListNewData(Object.assign({order: 's_t_desc'}, req.query), req.yoho.channel).then(result => {
Object.assign(resData, result, {
hideInfo: {from: 'newProduct'}
});
... ... @@ -207,7 +206,7 @@ exports.brand = (req, res, next) => {
}
// 获取品牌信息
list.getBrandInfo({domain: brandDomain}).then(brandInfo => {
req.ctx(list).getBrandInfo({domain: brandDomain}).then(brandInfo => {
if (!brandInfo.hasOwnProperty('type')) {
return res.redirect(helpers.urlFormat(''));
}
... ... @@ -243,11 +242,11 @@ exports.brandAbout = (req, res, next) => {
}
if (shopId) {
list.getShopAbout(shopId, req.user.uid).then(result => {
req.ctx(list).getShopAbout(shopId, req.user.uid).then(result => {
res.render('list/brand', Object.assign(result, {page: 'list'}));
}).catch(next);
} else {
list.getBrandAbout(brandDomain, req.user.uid, req.yoho.channel).then(result => {
req.ctx(list).getBrandAbout(brandDomain, req.user.uid, req.yoho.channel).then(result => {
res.render('list/brand', Object.assign(result, {page: 'list'}));
}).catch(next);
}
... ... @@ -266,7 +265,7 @@ exports.shopList = (req, res, next) => {
return next();
}
list.getShopListData(req.yoho.channel, req.query, req.user.uid).then(result => {
req.ctx(list).getShopListData(req.yoho.channel, req.query, req.user.uid).then(result => {
Object.assign(result, {
page: 'shop',
shopId: shopId
... ... @@ -295,7 +294,7 @@ exports.getNodeContent = (req, res, next) => {
return next();
}
list.getNodeContentData(req.body).then(result => {
req.ctx(list).getNodeContentData(req.body).then(result => {
res.json(result);
}).catch(next);
};
... ... @@ -312,7 +311,7 @@ exports.getAdnav = (req, res, next) => {
return next();
}
list.getAdnav(req.body).then(result => {
req.ctx(list).getAdnav(req.body).then(result => {
res.json(result);
}).catch(next);
};
... ... @@ -337,7 +336,7 @@ exports.isFavoriteBrand = (req, res, next) => {
return res.json({code: 400, message: '用户未登录或缺少参数'});
}
searchApi.isFavoriteBrand(uid, brandId).then(result => {
req.ctx(searchApi).isFavoriteBrand(uid, brandId).then(result => {
res.json(result);
}).catch(next);
};
... ... @@ -361,7 +360,7 @@ exports.shopCouponSync = (req, res, next) => {
return res.json({code: 400, message: '用户未登录或缺少参数'});
}
list.getUserCoupunStatus(id, uid, 'shop').then(result => {
req.ctx(list).getUserCoupunStatus(id, uid, 'shop').then(result => {
res.json(result);
});
};
... ... @@ -384,7 +383,7 @@ exports.brandCouponSync = (req, res, next) => {
return res.json({code: 400, message: '用户未登录或缺少参数'});
}
list.getUserCoupunStatus(id, uid, 'brand').then(result => {
req.ctx(list).getUserCoupunStatus(id, uid, 'brand').then(result => {
res.json(result);
});
... ...
/**
* Created by TaoHuang on 2016/6/14.
*/
'use strict';
const _ = require('lodash');
const Fn = require('lodash/fp');
const md5 = require('md5');
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;
function getSearchCacheKey(params) {
let removeUnusedKey = Fn.omit(['page', 'limit', 'need_filter', 'order']);
let sortByKey = Fn.pipe(Fn.toPairs, Fn.sortBy(0), Fn.flatten);
let genKey = Fn.pipe(Fn.cloneDeep, removeUnusedKey, sortByKey, Fn.join('_'));
return 'search_custom_' + md5(genKey(params));
}
function _saveCache(key, kv, cacheTime) {
cache.set(key, kv, cacheTime)
.catch(err => logger.debug(`product query save cache data fail:${err.toString()}`));
}
function getProductListOrig(finalParams) {
return this.get({data: finalParams});
}
function getKeyActivityAsync(query) {
return this.get({
data: {
method: 'app.search.word',
query: query
}, params: {
catch: true,
code: 200
}
});
}
/**
* 获取商品列表
* @return
*/
function getProductList(params, from) {
let finalParams = {
method: 'web.search.search',
sales: 'Y',
outlets: 2,
stocknumber: 1,
need_filter: 'yes',
limit: 60
};
Object.assign(finalParams, params);
// 店铺默认排序s_w_desc
if (params.shopId || params.shop_id || params.shop) {
finalParams.order = params.order || 's_w_desc';
}
if (from) {
finalParams.from = from;
}
if (!config.useCache) {
return this.getProductListOrig(finalParams);
} else {
let cKey = this.getSearchCacheKey(finalParams);
return cache.get(cKey)
.catch(err => logger.debug(`product query save cache data fail:${err.toString()}`))
.then(cdata => {
let hasCache = false;
if (cdata) {
try {
cdata = JSON.parse(cdata);
} catch (e) {
logger.debug('getProductList cache data parse fail.');
}
if (cdata.filter && cdata.standard) {
hasCache = true;
finalParams.need_filter = 'no';
}
}
return this.getProductListOrig(finalParams).then(result => {
if (hasCache && result && result.data) {
Object.assign(result.data, cdata);
} else {
if (result && result.data && result.data.filter) {
_saveCache(cKey, Object.assign({}, {
filter: result.data.filter,
standard: result.data.standard
}), CACHE_TIME_S);
}
}
return result;
});
});
}
}
/**
* 获取seo商品列表
* @return
*/
function 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);
}
function getSortListOrig(finalParams) {
return this.get({data: finalParams, params: {cache: config.apiCache}});
}
/**
* 获取分类列表
* @return
*/
function 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 this.getSortListOrig(finalParams);
} else {
let cKey = this.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 this.getSortListOrig(finalParams).then(ret => {
if (ret && ret.code === 200) {
_saveCache(cKey, ret, CACHE_TIME_S);
}
return ret;
});
}
});
}
}
/**
* 获取分类图文介绍
* @return
*/
function getSortIntro(params) {
let finalParams = {
method: 'web.search.banner'
};
Object.assign(finalParams, params);
return this.get({data: finalParams, params: {cache: config.apiCache}});
}
/**
* 获取分类广告
* @return
*/
function getSortAds(params) {
let finalParams = {
method: 'app.ads.list'
};
Object.assign(finalParams, params);
return this.get({data: finalParams, params: {cache: config.apiCache}});
}
/**
* 获取品牌系列
* @return
*/
function 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 this.get({data: finalParams, params: {cache: config.apiCache}});
}
/**
* 获取品牌folder
* @return
*/
function 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 this.get({data: finalParams, params: {cache: config.apiCache}});
}
/**
* 获取品牌水牌
* @return
*/
function getNodeContent(params) {
let finalParams = {
method: 'web.html.content',
mode: params.mode || 'release',
node: params.node || ''
};
return this.get({data: finalParams, params: {cache: config.apiCache}});
}
/**
* 一周新品上架
* @return
*/
function getWeekNew(params) {
let finalParams = {
method: 'web.regular.recent'
};
Object.assign(finalParams, params);
return this.get({data: finalParams, params: {cache: config.apiCache}});
}
function getBrandCouponAsync(brandId, uid) {
let extra = {code: 200};
if (!uid) {
extra.cache = true;
}
return this.get({
data: {
method: 'app.brand.getBrandIntro',
brand_id: brandId,
uid: uid
}, params: extra
});
}
/**
* 根据关键词搜索品牌店铺信息
* @return
*/
function getBrandShop(query) {
let finalParams = {
method: 'web.search.shopListInfo'
};
return this.get({data: Object.assign(finalParams, {keyword: query}), params: {cache: config.apiCache}});
}
/**
* 根据搜索得到店铺/品牌
*/
function getShopList(params) {
if (!params || !params.query) {
return;
}
return this.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
*/
function getSuggest(params) {
let finalParams = {
method: 'app.search.fuzzy',
keyword: params.keyword || ''
};
return this.get({data: finalParams, params: {cache: config.apiCache}});
}
/**
* 根据品牌域名获取品牌信息
* @return
*/
function getBrandData(params) {
let finalParams = {
method: 'web.brand.byDomain',
domain: params.domain || ''
};
return this.get({data: finalParams, params: {cache: config.apiCache}});
}
/**
* 根据uid和品牌id判断品牌是否收藏
* @return
*/
function isFavoriteBrand(uid, brandId) {
return this.get({
url: isFavoriteBrandUrl,
data: {
uid: uid,
brandId: brandId
},
api: global.yoho.serviceApi
});
}
/**
* 根据shopId获取店铺基本信息
* @return
*/
function getShopInfo(shopId, uid) {
let finalParams = {
method: 'app.shops.getIntro',
shop_id: shopId || 0,
uid: uid || 0
};
return this.get({data: finalParams, params: {cache: config.apiCache}});
}
/**
* 查询店铺下面的所有品牌
*/
function getShopBrands(shopId) {
return this.get({
data: {method: 'app.shops.getShopsBrands', shop_id: shopId || 0},
params: {cache: config.apiCache}
});
}
/**
* 查询店铺装修
*/
function getShopDecorator(shopId) {
return this.get({
data: {method: 'app.shopsdecorator.getList', shop_id: shopId || 0},
params: {cache: config.apiCache}
});
}
/**
* 通过品牌获取相关文章
*/
function getArticleByBrand(brand, udid, limit) {
let params = {
brand_id: brand || 0,
udid: udid,
limit: limit || 6
};
return this.get({
url: relateArticleUrl,
data: params,
api: global.yoho.ServiceAPI
});
}
function getBrands4Filter(params) {
return this.get({
data: 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 接口返回的数据
* */
function 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 this.get({data: param});
}
module.exports = class extends global.yoho.BaseModel {
constructor(ctx) {
super(ctx);
this.getKeyActivityAsync = getKeyActivityAsync.bind(this);
this.getProductList = getProductList.bind(this);
this.getSeoProductList = getSeoProductList.bind(this);
this.getSortList = getSortList.bind(this);
this.getSortIntro = getSortIntro.bind(this);
this.getSortAds = getSortAds.bind(this);
this.getBrandShopFolder = getBrandShopFolder.bind(this);
this.getBrandShopSeries = getBrandShopSeries.bind(this);
this.getWeekNew = getWeekNew.bind(this);
this.getBrandCouponAsync = getBrandCouponAsync.bind(this);
this.getBrandShop = getBrandShop.bind(this);
this.getSuggest = getSuggest.bind(this);
this.getBrandData = getBrandData.bind(this);
this.getNodeContent = getNodeContent.bind(this);
this.isFavoriteBrand = isFavoriteBrand.bind(this);
this.getShopInfo = getShopInfo.bind(this);
this.getShopBrands = getShopBrands.bind(this);
this.getShopDecorator = getShopDecorator.bind(this);
this.getArticleByBrand = getArticleByBrand.bind(this);
this.getShopList = getShopList.bind(this);
this.getBrands4Filter = getBrands4Filter.bind(this);
this.getProductListOrig = getProductListOrig.bind(this);
this.getSearchCacheKey = getSearchCacheKey.bind(this);
this.lessRecommend = lessRecommend.bind(this);
this.getSortListOrig = getSortListOrig.bind(this);
}
};
... ...
... ... @@ -3,23 +3,62 @@
*/
'use strict';
const config = global.yoho.config;
module.exports = class extends global.yoho.BaseModel {
constructor(ctx) {
super(ctx);
}
/**
* 获取店铺装修的所有资源接口
*/
shopsDecoratorListAsync(shopId) {
return this.get({
data: {
method: 'app.shopsdecorator.getList',
shop_id: shopId
}, params: {cache: config.apiCache}
});
}
/**
* 获取店铺优惠券接口
*/
shopCouponListAsync(shopId, uid) {
let extra = {
code: 200
};
if (!uid) {
extra.cache = true;
}
return this.get({
data: {
method: 'shop.coupons.list',
shop_id: shopId,
uid: uid
}, params: extra
});
}
shopBannerAsync(shopId) {
return this.get({data: {
method: 'app.shop.banner',
shop_id: shopId
}});
return this.get({
data: {
method: 'app.shop.banner',
shop_id: shopId
}
});
}
queryShopsByBrandId(sid, bid) {
return this.get({data: {
method: 'app.product.queryShopsInfoById',
brand_id: bid,
shop_id: sid
}});
return this.get({
data: {
method: 'app.product.queryShopsInfoById',
brand_id: bid,
shop_id: sid
}
});
}
};
... ...
... ... @@ -6,8 +6,8 @@
// TODO: ctx
'use strict';
const utils = '../../../utils';
const searchApi = require('./search-api');
const shopApi = require('./shop-api');
const SearchApiModel = require('./ctx-search-api');
const ShopApiModel = require('./ctx-shop-api');
const headerModel = require('../../../doraemon/models/header');
const productProcess = require(`${utils}/product-process`);
const searchHandler = require('./search-handler');
... ... @@ -55,7 +55,7 @@ const _getGender = (channel) => {
/**
* 获取商品分类列表数据
*/
const getListData = (params, channel) => {
function getListData(params, channel) {
let standard = [];
_.forEach(params, (value, key) => {
... ... @@ -76,8 +76,8 @@ const getListData = (params, channel) => {
// 调用接口
let apiMethod = [
headerModel.requestHeaderData(channel),
searchApi.getSortList({}, channel),
searchApi.getProductList(searchParams, 'categoryList')
this.searchApi.getSortList({}, channel),
this.searchApi.getProductList(searchParams, 'categoryList')
];
// 搜索分类介绍和广告
... ... @@ -88,8 +88,8 @@ const getListData = (params, channel) => {
gender: params.gender || '1,3'
};
apiMethod.push(searchApi.getSortIntro(Object.assign(IntroParams, {position_id: positionId})));
apiMethod.push(searchApi.getSortAds(Object.assign(IntroParams, {position_id: sortAdsId})));
apiMethod.push(this.searchApi.getSortIntro(Object.assign(IntroParams, {position_id: positionId})));
apiMethod.push(this.searchApi.getSortAds(Object.assign(IntroParams, {position_id: sortAdsId})));
}
return Promise.all(apiMethod).then(result => {
... ... @@ -158,21 +158,21 @@ const getListData = (params, channel) => {
return Object.assign({}, seo, finalResult);
});
};
}
/**
* 获取新品到着数据
*/
const getListNewData = (params, channel) => {
function getListNewData(params, channel) {
let searchParams = searchHandler.getSearchParams(params);
// 调用接口
let apiMethod = [
headerModel.requestHeaderData(channel),
searchApi.getSortList({}, channel),
searchApi.getProductList(Object.assign(searchParams), 'newProduct'),
searchApi.getWeekNew(params)
this.searchApi.getSortList({}, channel),
this.searchApi.getProductList(Object.assign(searchParams), 'newProduct'),
this.searchApi.getWeekNew(params)
];
return Promise.all(apiMethod).then(result => {
... ... @@ -214,8 +214,10 @@ const getListNewData = (params, channel) => {
totalCount: result[2].data.total,
footPager: searchHandler.handlePagerData(result[2].data.total, params),
goods: productProcess.processProductList(result[2].data.product_list,
Object.assign({showDiscount: false, showNew: false,
from: {type: 'listNew', params: params}}, params)),
Object.assign({
showDiscount: false, showNew: false,
from: {type: 'listNew', params: params}
}, params)),
hasNextPage: searchHandler.handleNextPage(params, result[2].data.total),
// 最近浏览记录
... ... @@ -234,13 +236,13 @@ const getListNewData = (params, channel) => {
return Object.assign({}, seo, finalResult);
});
};
}
/**
* 根据品牌域名查询品牌信息
*/
const getBrandInfo = (params) => {
return searchApi.getBrandData(params).then(result => {
function getBrandInfo(params) {
return this.searchApi.getBrandData(params).then(result => {
if (result.code !== 200 || !result.data) {
return {};
... ... @@ -262,12 +264,12 @@ const getBrandInfo = (params) => {
};
});
};
}
/**
* 获取品牌页面数据
*/
const getBrandData = (params, extra, channel) => {
function getBrandData(params, extra, channel) {
let queryBase = {};
let searchParams = searchHandler.getSearchParams(params);
... ... @@ -288,12 +290,12 @@ const getBrandData = (params, extra, channel) => {
// 调用接口
let apiMethod = [
headerModel.requestHeaderData(channel),
searchApi.getSortList(queryBase),
searchApi.getProductList(Object.assign(searchParams, queryBase), 'brand')
this.searchApi.getSortList(queryBase),
this.searchApi.getProductList(Object.assign(searchParams, queryBase), 'brand')
];
if (queryBase.brand) {
apiMethod.push(searchApi.getBrandCouponAsync(queryBase.brand));
apiMethod.push(this.searchApi.getBrandCouponAsync(queryBase.brand));
}
return Promise.all(apiMethod).then(result => {
... ... @@ -363,17 +365,17 @@ const getBrandData = (params, extra, channel) => {
return Object.assign({}, seo, finalResult);
});
};
}
/**
* 获取品牌介绍页面数据
*/
const getBrandAbout = (domain, uid, channel) => {
function getBrandAbout(domain, uid, channel) {
channel = channel || 'boys';
return Promise.all([
headerModel.requestHeaderData(channel),
searchApi.getBrandData({domain: domain})
this.searchApi.getBrandData({domain: domain})
]).then(result => {
let home;
let finalResult = {
... ... @@ -442,19 +444,19 @@ const getBrandAbout = (domain, uid, channel) => {
return finalResult;
});
};
}
/**
* 获取店铺介绍页面数据
*/
const getShopAbout = (shopId, uid, channel) => {
function getShopAbout(shopId, uid, channel) {
let resData = {};
return Promise.all([
headerModel.requestHeaderData(channel),
searchApi.getShopDecorator(shopId), // 店铺装修数据
searchApi.getShopInfo(shopId, uid)
this.searchApi.getShopDecorator(shopId), // 店铺装修数据
this.searchApi.getShopInfo(shopId, uid)
]).then(result => {
resData.headerData = Object.assign(result[0].headerData, {
header: true
... ... @@ -485,27 +487,30 @@ const getShopAbout = (shopId, uid, channel) => {
return resData;
});
};
}
/**
* 获取品牌页面水牌
*/
const getNodeContentData = (params) => {
return searchApi.getNodeContent(params).then(result => {
function getNodeContentData(params) {
return this.searchApi.getNodeContent(params).then(result => {
if (result.code === 200 && result.data) {
return result.data;
}
});
};
}
/**
* 获取品牌页面系列
*/
const getAdnav = (params) => {
function getAdnav(params) {
let resData = {};
return Promise.all([searchApi.getBrandShopFolder(params), searchApi.getBrandShopSeries(params)]).then(result => {
return Promise.all([
this.searchApi.getBrandShopFolder(params),
this.searchApi.getBrandShopSeries(params)
]).then(result => {
let flist = [];
let slist = [];
... ... @@ -540,15 +545,15 @@ const getAdnav = (params) => {
return resData;
});
};
}
/**
* 获取店铺基本信息
*/
const getShopInfo = (shopId, uid) => {
function getShopInfo(shopId, uid) {
return searchApi.getShopInfo(shopId, uid).then(result => {
return this.searchApi.getShopInfo(shopId, uid).then(result => {
if (result.code === 200) {
return {
brandName: result.data.shop_name,
... ... @@ -565,7 +570,7 @@ const getShopInfo = (shopId, uid) => {
return {};
}
});
};
}
/**
* 获取经典模板店铺数据
... ... @@ -574,7 +579,7 @@ const getShopInfo = (shopId, uid) => {
* @param params
* @param shopInfo 店铺介绍
*/
const getShopData = (shopId, channel, params, shopInfo) => {
function getShopData(shopId, channel, params, shopInfo) {
let gender = _getGender(channel);
params = params || {};
... ... @@ -582,12 +587,12 @@ const getShopData = (shopId, channel, params, shopInfo) => {
return Promise.all([
headerModel.requestHeaderData(channel), // 头部数据
searchApi.getShopDecorator(shopId), // 店铺装修数据
searchApi.getProductList(Object.assign({
this.searchApi.getShopDecorator(shopId), // 店铺装修数据
this.searchApi.getProductList(Object.assign({
shop_id: shopId
}, params), 'shop'), // 搜索店铺商品
searchApi.getShopBrands(shopId), // 店铺品牌数据
shopApi.shopCouponListAsync(shopId) // 店铺优惠券数据
this.searchApi.getShopBrands(shopId), // 店铺品牌数据
this.shopApi.shopCouponListAsync(shopId) // 店铺优惠券数据
]).then(result => {
let finalResult = {};
... ... @@ -641,7 +646,7 @@ const getShopData = (shopId, channel, params, shopInfo) => {
let articleApiMethod = [], // 通过品牌获取相关文章接口
apiMethod = [
searchApi.getProductList({
this.searchApi.getProductList({
viewNum: sknList.length,
query: _.join(_.uniq(sknList), ',')
}, 'shop')
... ... @@ -650,7 +655,7 @@ const getShopData = (shopId, channel, params, shopInfo) => {
if (result[3].code === 200 && result[3].data) {
_.forEach(result[3].data, value => {
articleApiMethod.push(
searchApi.getArticleByBrand(value.brand_id, 'udid') // 品牌推荐文章
this.searchApi.getArticleByBrand(value.brand_id, 'udid') // 品牌推荐文章
);
});
}
... ... @@ -660,7 +665,7 @@ const getShopData = (shopId, channel, params, shopInfo) => {
}
// 根据店铺id获取分类
apiMethod.push(searchApi.getSortList({shop_id: shopId}));
apiMethod.push(this.searchApi.getSortList({shop_id: shopId}));
apiMethod = _.concat(apiMethod, articleApiMethod);
return Promise.all(apiMethod).then(subRes => {
... ... @@ -725,7 +730,7 @@ const getShopData = (shopId, channel, params, shopInfo) => {
trendList.push({
href: helpers.urlFormat(`/guang/${articleList[i].id}.html`, null),
src: helpers.getForceSourceUrl(articleList[i].src) +
'?imageView2/1/w/{width}/h/{height}',
'?imageView2/1/w/{width}/h/{height}',
mainTitle: articleList[i].title,
Subtitle: articleList[i].intro
});
... ... @@ -741,21 +746,21 @@ const getShopData = (shopId, channel, params, shopInfo) => {
return finalResult;
});
});
};
}
/**
* 获取店铺商品数据
*/
const getShopGoodsData = (shopId, channel, params) => {
function getShopGoodsData(shopId, channel, params) {
let gender = _getGender(channel);
let resData = {};
_.unset(params, '_pjax');
return Promise.all([
searchApi.getProductList(Object.assign({
this.searchApi.getProductList(Object.assign({
shop_id: shopId
}, params), 'shop'), // 搜索店铺商品
searchApi.getSortList({shop_id: shopId}) // 根据店铺id获取分类
this.searchApi.getSortList({shop_id: shopId}) // 根据店铺id获取分类
]).then(result => {
// 获取商品数据和顶部筛选条件
if (result[0].code === 200) {
... ... @@ -779,24 +784,24 @@ const getShopGoodsData = (shopId, channel, params) => {
return resData;
});
};
}
const getShopListData = (channel, params, uid) => {
function getShopListData(channel, params, uid) {
let gender = _getGender(channel),
shopId = params.shopId,
navBar = params.navBar || 1;
let apiArr = [
headerModel.requestHeaderData(channel), // 头部数据
searchApi.getShopDecorator(shopId), // 店铺装修数据
searchApi.getShopInfo(shopId, uid), // 店铺介绍
searchApi.getProductList(Object.assign({shop_id: shopId}, params,
this.searchApi.getShopDecorator(shopId), // 店铺装修数据
this.searchApi.getShopInfo(shopId, uid), // 店铺介绍
this.searchApi.getProductList(Object.assign({shop_id: shopId}, params,
{limit: (params.limit || 60) - 1}), 'shop'), // 搜索店铺商品
searchApi.getSortList({shop_id: shopId}) // 店铺分类
this.searchApi.getSortList({shop_id: shopId}) // 店铺分类
];
if (_.has(params, 'query')) {
// 如果有店内搜索,则并行查询店铺所有商品,搜索不到商品则显示所有商品
apiArr.push(searchApi.getProductList(Object.assign({shop_id: shopId},
apiArr.push(this.searchApi.getProductList(Object.assign({shop_id: shopId},
params, {query: ''}), 'shop')); // 搜索店铺所有商品
}
... ... @@ -897,21 +902,21 @@ const getShopListData = (channel, params, uid) => {
return finalResult;
});
};
}
/**
* 获取基础模板店铺数据
*/
const getBaseShopData = (params, extra, channel, shopId) => {
function getBaseShopData(params, extra, channel, shopId) {
let resData = {};
params.shopId = shopId;
return Promise.all([
getBrandData(params, extra, channel),
searchApi.getShopDecorator(shopId), // 店铺装修数据
searchApi.getShopInfo(shopId, extra.uid),
shopApi.shopCouponListAsync(shopId) // 店铺优惠券数据
this.searchApi.getShopDecorator(shopId), // 店铺装修数据
this.searchApi.getShopInfo(shopId, extra.uid),
this.shopApi.shopCouponListAsync(shopId) // 店铺优惠券数据
]).then(result => {
let brand = result[0] || {};
... ... @@ -961,11 +966,11 @@ const getBaseShopData = (params, extra, channel, shopId) => {
return resData;
});
};
}
const getUserCoupunStatus = (id, uid, type) => {
function getUserCoupunStatus(id, uid, type) {
if (type === 'shop') {
return shopApi.shopCouponListAsync(id, uid).then(result => {
return this.shopApi.shopCouponListAsync(id, uid).then(result => {
if (result.data) {
_.forEach(result.data, value => {
Object.assign(value, {
... ... @@ -978,7 +983,7 @@ const getUserCoupunStatus = (id, uid, type) => {
return result;
});
} else {
return searchApi.getBrandCouponAsync(id, uid).then(result => {
return this.searchApi.getBrandCouponAsync(id, uid).then(result => {
if (result.data) {
result.data = _.get(result, 'data.coupons', []);
_.forEach(result.data, value => {
... ... @@ -992,22 +997,28 @@ const getUserCoupunStatus = (id, uid, type) => {
return result;
});
}
};
module.exports = {
getListData,
getListNewData,
getBrandInfo,
getBrandData,
getBrandAbout,
getShopAbout,
getNodeContentData,
getAdnav,
getShopInfo,
getShopData,
getShopGoodsData,
getShopListData,
getBaseShopData,
getUserCoupunStatus
}
module.exports = class extends global.yoho.BaseModel {
constructor(ctx) {
super(ctx);
this.searchApi = new SearchApiModel(ctx);
this.shopApi = new ShopApiModel(ctx);
this.getListData = getListData.bind(this);
this.getListNewData = getListNewData.bind(this);
this.getBrandInfo = getBrandInfo.bind(this);
this.getBrandData = getBrandData.bind(this);
this.getBrandAbout = getBrandAbout.bind(this);
this.getShopAbout = getShopAbout.bind(this);
this.getNodeContentData = getNodeContentData.bind(this);
this.getAdnav = getAdnav.bind(this);
this.getShopInfo = getShopInfo.bind(this);
this.getShopData = getShopData.bind(this);
this.getShopGoodsData = getShopGoodsData.bind(this);
this.getShopListData = getShopListData.bind(this);
this.getBaseShopData = getBaseShopData.bind(this);
this.getUserCoupunStatus = getUserCoupunStatus.bind(this);
}
};
... ...