...
|
...
|
@@ -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);
|
|
|
}
|
|
|
}; |
...
|
...
|
|