Authored by htoooth

list

@@ -6,15 +6,14 @@ @@ -6,15 +6,14 @@
6 'use strict'; 6 'use strict';
7 7
8 // TODO: ctx 8 // TODO: ctx
9 -const mRoot = '../models';  
10 -const list = require(`${mRoot}/list`);  
11 const listSeoMap = require(`${global.middleware}/seo/listSeoMap`); 9 const listSeoMap = require(`${global.middleware}/seo/listSeoMap`);
12 const helpers = global.yoho.helpers; 10 const helpers = global.yoho.helpers;
13 const _ = require('lodash'); 11 const _ = require('lodash');
14 const tdk = require('../../../utils/getTDK'); 12 const tdk = require('../../../utils/getTDK');
15 13
16 // 搜索相关接口 14 // 搜索相关接口
17 -const searchApi = require(`${mRoot}/search-api`); 15 +const searchApi = require('../models/ctx-search-api');
  16 +const list = require('../models/list');
18 17
19 // 店铺页 18 // 店铺页
20 const shop = (shopId, req, res, next, brandInfo) => { 19 const shop = (shopId, req, res, next, brandInfo) => {
@@ -33,7 +32,7 @@ const shop = (shopId, req, res, next, brandInfo) => { @@ -33,7 +32,7 @@ const shop = (shopId, req, res, next, brandInfo) => {
33 description: TDKObj[3] 32 description: TDKObj[3]
34 }; 33 };
35 } 34 }
36 - return list.getShopInfo(shopId, req.user.uid).then(shopInfo => { 35 + return req.ctx(list).getShopInfo(shopId, req.user.uid).then(shopInfo => {
37 let pjax = params._pjax; 36 let pjax = params._pjax;
38 37
39 // 获取不到店铺信息跳转至首页 38 // 获取不到店铺信息跳转至首页
@@ -50,7 +49,7 @@ const shop = (shopId, req, res, next, brandInfo) => { @@ -50,7 +49,7 @@ const shop = (shopId, req, res, next, brandInfo) => {
50 if (+shopInfo.shopTemplateType === 2) { // 经典模板 49 if (+shopInfo.shopTemplateType === 2) { // 经典模板
51 50
52 if (pjax) { 51 if (pjax) {
53 - list.getShopGoodsData(shopId, req.yoho.channel, params, shopInfo).then(result => { 52 + req.ctx(list).getShopGoodsData(shopId, req.yoho.channel, params, shopInfo).then(result => {
54 Object.assign(result, { 53 Object.assign(result, {
55 shopId: shopId, 54 shopId: shopId,
56 layout: false 55 layout: false
@@ -60,7 +59,7 @@ const shop = (shopId, req, res, next, brandInfo) => { @@ -60,7 +59,7 @@ const shop = (shopId, req, res, next, brandInfo) => {
60 return; 59 return;
61 } 60 }
62 61
63 - list.getShopData(shopId, req.yoho.channel, params, shopInfo).then(result => { 62 + req.ctx(list).getShopData(shopId, req.yoho.channel, params, shopInfo).then(result => {
64 Object.assign(result, { 63 Object.assign(result, {
65 page: 'shop', 64 page: 'shop',
66 shopId: shopId 65 shopId: shopId
@@ -74,7 +73,7 @@ const shop = (shopId, req, res, next, brandInfo) => { @@ -74,7 +73,7 @@ const shop = (shopId, req, res, next, brandInfo) => {
74 res.render('list/shop-index', result); 73 res.render('list/shop-index', result);
75 }).catch(next); 74 }).catch(next);
76 } else { // 基础模板 75 } else { // 基础模板
77 - list.getBaseShopData(params, Object.assign({uid: req.user.uid}, brandInfo), 76 + req.ctx(list).getBaseShopData(params, Object.assign({uid: req.user.uid}, brandInfo),
78 req.yoho.channel, shopId).then(result => { 77 req.yoho.channel, shopId).then(result => {
79 Object.assign(result, {page: 'list'}); 78 Object.assign(result, {page: 'list'});
80 79
@@ -102,7 +101,7 @@ exports.index = (req, res, next) => { @@ -102,7 +101,7 @@ exports.index = (req, res, next) => {
102 let resData = {}; 101 let resData = {};
103 let qs = decodeURIComponent(req._parsedOriginalUrl.query || ''); 102 let qs = decodeURIComponent(req._parsedOriginalUrl.query || '');
104 103
105 - list.getListData(Object.assign(req.query, {uid: req.user.uid, prid: req.user.prid}), 104 + req.ctx(list).getListData(Object.assign(req.query, {uid: req.user.uid, prid: req.user.prid}),
106 req.yoho.channel).then(result => { 105 req.yoho.channel).then(result => {
107 Object.assign(resData, result); 106 Object.assign(resData, result);
108 107
@@ -137,7 +136,7 @@ exports.index = (req, res, next) => { @@ -137,7 +136,7 @@ exports.index = (req, res, next) => {
137 exports.new = (req, res, next) => { 136 exports.new = (req, res, next) => {
138 let resData = {}; 137 let resData = {};
139 138
140 - list.getListNewData(Object.assign({order: 's_t_desc'}, req.query), req.yoho.channel).then(result => { 139 + req.ctx(list).getListNewData(Object.assign({order: 's_t_desc'}, req.query), req.yoho.channel).then(result => {
141 Object.assign(resData, result, { 140 Object.assign(resData, result, {
142 hideInfo: {from: 'newProduct'} 141 hideInfo: {from: 'newProduct'}
143 }); 142 });
@@ -207,7 +206,7 @@ exports.brand = (req, res, next) => { @@ -207,7 +206,7 @@ exports.brand = (req, res, next) => {
207 } 206 }
208 207
209 // 获取品牌信息 208 // 获取品牌信息
210 - list.getBrandInfo({domain: brandDomain}).then(brandInfo => { 209 + req.ctx(list).getBrandInfo({domain: brandDomain}).then(brandInfo => {
211 if (!brandInfo.hasOwnProperty('type')) { 210 if (!brandInfo.hasOwnProperty('type')) {
212 return res.redirect(helpers.urlFormat('')); 211 return res.redirect(helpers.urlFormat(''));
213 } 212 }
@@ -243,11 +242,11 @@ exports.brandAbout = (req, res, next) => { @@ -243,11 +242,11 @@ exports.brandAbout = (req, res, next) => {
243 } 242 }
244 243
245 if (shopId) { 244 if (shopId) {
246 - list.getShopAbout(shopId, req.user.uid).then(result => { 245 + req.ctx(list).getShopAbout(shopId, req.user.uid).then(result => {
247 res.render('list/brand', Object.assign(result, {page: 'list'})); 246 res.render('list/brand', Object.assign(result, {page: 'list'}));
248 }).catch(next); 247 }).catch(next);
249 } else { 248 } else {
250 - list.getBrandAbout(brandDomain, req.user.uid, req.yoho.channel).then(result => { 249 + req.ctx(list).getBrandAbout(brandDomain, req.user.uid, req.yoho.channel).then(result => {
251 res.render('list/brand', Object.assign(result, {page: 'list'})); 250 res.render('list/brand', Object.assign(result, {page: 'list'}));
252 }).catch(next); 251 }).catch(next);
253 } 252 }
@@ -266,7 +265,7 @@ exports.shopList = (req, res, next) => { @@ -266,7 +265,7 @@ exports.shopList = (req, res, next) => {
266 return next(); 265 return next();
267 } 266 }
268 267
269 - list.getShopListData(req.yoho.channel, req.query, req.user.uid).then(result => { 268 + req.ctx(list).getShopListData(req.yoho.channel, req.query, req.user.uid).then(result => {
270 Object.assign(result, { 269 Object.assign(result, {
271 page: 'shop', 270 page: 'shop',
272 shopId: shopId 271 shopId: shopId
@@ -295,7 +294,7 @@ exports.getNodeContent = (req, res, next) => { @@ -295,7 +294,7 @@ exports.getNodeContent = (req, res, next) => {
295 return next(); 294 return next();
296 } 295 }
297 296
298 - list.getNodeContentData(req.body).then(result => { 297 + req.ctx(list).getNodeContentData(req.body).then(result => {
299 res.json(result); 298 res.json(result);
300 }).catch(next); 299 }).catch(next);
301 }; 300 };
@@ -312,7 +311,7 @@ exports.getAdnav = (req, res, next) => { @@ -312,7 +311,7 @@ exports.getAdnav = (req, res, next) => {
312 return next(); 311 return next();
313 } 312 }
314 313
315 - list.getAdnav(req.body).then(result => { 314 + req.ctx(list).getAdnav(req.body).then(result => {
316 res.json(result); 315 res.json(result);
317 }).catch(next); 316 }).catch(next);
318 }; 317 };
@@ -337,7 +336,7 @@ exports.isFavoriteBrand = (req, res, next) => { @@ -337,7 +336,7 @@ exports.isFavoriteBrand = (req, res, next) => {
337 return res.json({code: 400, message: '用户未登录或缺少参数'}); 336 return res.json({code: 400, message: '用户未登录或缺少参数'});
338 } 337 }
339 338
340 - searchApi.isFavoriteBrand(uid, brandId).then(result => { 339 + req.ctx(searchApi).isFavoriteBrand(uid, brandId).then(result => {
341 res.json(result); 340 res.json(result);
342 }).catch(next); 341 }).catch(next);
343 }; 342 };
@@ -361,7 +360,7 @@ exports.shopCouponSync = (req, res, next) => { @@ -361,7 +360,7 @@ exports.shopCouponSync = (req, res, next) => {
361 return res.json({code: 400, message: '用户未登录或缺少参数'}); 360 return res.json({code: 400, message: '用户未登录或缺少参数'});
362 } 361 }
363 362
364 - list.getUserCoupunStatus(id, uid, 'shop').then(result => { 363 + req.ctx(list).getUserCoupunStatus(id, uid, 'shop').then(result => {
365 res.json(result); 364 res.json(result);
366 }); 365 });
367 }; 366 };
@@ -384,7 +383,7 @@ exports.brandCouponSync = (req, res, next) => { @@ -384,7 +383,7 @@ exports.brandCouponSync = (req, res, next) => {
384 return res.json({code: 400, message: '用户未登录或缺少参数'}); 383 return res.json({code: 400, message: '用户未登录或缺少参数'});
385 } 384 }
386 385
387 - list.getUserCoupunStatus(id, uid, 'brand').then(result => { 386 + req.ctx(list).getUserCoupunStatus(id, uid, 'brand').then(result => {
388 res.json(result); 387 res.json(result);
389 }); 388 });
390 389
  1 +/**
  2 + * Created by TaoHuang on 2016/6/14.
  3 + */
  4 +'use strict';
  5 +const _ = require('lodash');
  6 +const Fn = require('lodash/fp');
  7 +const md5 = require('md5');
  8 +
  9 +const config = global.yoho.config;
  10 +
  11 +const helpers = global.yoho.helpers;
  12 +const cache = global.yoho.cache;
  13 +const logger = global.yoho.logger;
  14 +
  15 +// 判断用户是否收藏品牌
  16 +const isFavoriteBrandUrl = '/shops/service/v1/favorite/getUidBrandFav';
  17 +
  18 +// 根据品牌查询相关文章
  19 +const relateArticleUrl = 'guang/service/v2/article/getArticleByBrand';
  20 +
  21 +const GLOBAL_BASE_URI = '/product/global/list';
  22 +
  23 +// 缓存生效时间
  24 +const CACHE_TIME_S = 60;
  25 +
  26 +function getSearchCacheKey(params) {
  27 + let removeUnusedKey = Fn.omit(['page', 'limit', 'need_filter', 'order']);
  28 + let sortByKey = Fn.pipe(Fn.toPairs, Fn.sortBy(0), Fn.flatten);
  29 + let genKey = Fn.pipe(Fn.cloneDeep, removeUnusedKey, sortByKey, Fn.join('_'));
  30 +
  31 + return 'search_custom_' + md5(genKey(params));
  32 +}
  33 +
  34 +function _saveCache(key, kv, cacheTime) {
  35 + cache.set(key, kv, cacheTime)
  36 + .catch(err => logger.debug(`product query save cache data fail:${err.toString()}`));
  37 +}
  38 +
  39 +function getProductListOrig(finalParams) {
  40 + return this.get({data: finalParams});
  41 +}
  42 +
  43 +function getKeyActivityAsync(query) {
  44 + return this.get({
  45 + data: {
  46 + method: 'app.search.word',
  47 + query: query
  48 + }, params: {
  49 + catch: true,
  50 + code: 200
  51 + }
  52 + });
  53 +}
  54 +
  55 +/**
  56 + * 获取商品列表
  57 + * @return
  58 + */
  59 +function getProductList(params, from) {
  60 + let finalParams = {
  61 + method: 'web.search.search',
  62 + sales: 'Y',
  63 + outlets: 2,
  64 + stocknumber: 1,
  65 + need_filter: 'yes',
  66 + limit: 60
  67 + };
  68 +
  69 + Object.assign(finalParams, params);
  70 +
  71 + // 店铺默认排序s_w_desc
  72 + if (params.shopId || params.shop_id || params.shop) {
  73 + finalParams.order = params.order || 's_w_desc';
  74 + }
  75 +
  76 + if (from) {
  77 + finalParams.from = from;
  78 + }
  79 +
  80 + if (!config.useCache) {
  81 + return this.getProductListOrig(finalParams);
  82 + } else {
  83 + let cKey = this.getSearchCacheKey(finalParams);
  84 +
  85 + return cache.get(cKey)
  86 + .catch(err => logger.debug(`product query save cache data fail:${err.toString()}`))
  87 + .then(cdata => {
  88 + let hasCache = false;
  89 +
  90 + if (cdata) {
  91 +
  92 + try {
  93 + cdata = JSON.parse(cdata);
  94 + } catch (e) {
  95 + logger.debug('getProductList cache data parse fail.');
  96 + }
  97 +
  98 + if (cdata.filter && cdata.standard) {
  99 + hasCache = true;
  100 + finalParams.need_filter = 'no';
  101 + }
  102 + }
  103 +
  104 + return this.getProductListOrig(finalParams).then(result => {
  105 + if (hasCache && result && result.data) {
  106 + Object.assign(result.data, cdata);
  107 + } else {
  108 + if (result && result.data && result.data.filter) {
  109 + _saveCache(cKey, Object.assign({}, {
  110 + filter: result.data.filter,
  111 + standard: result.data.standard
  112 + }), CACHE_TIME_S);
  113 + }
  114 + }
  115 +
  116 + return result;
  117 + });
  118 + });
  119 + }
  120 +}
  121 +
  122 +/**
  123 + * 获取seo商品列表
  124 + * @return
  125 + */
  126 +function getSeoProductList(params, from) {
  127 + let finalParams = {
  128 + method: 'web.search.forseo',
  129 + sales: 'Y',
  130 + outlets: 2,
  131 + stocknumber: 1,
  132 + need_filter: 'no',
  133 + limit: 60
  134 + };
  135 +
  136 + Object.assign(finalParams, params);
  137 +
  138 + if (from) {
  139 + finalParams.from = from;
  140 + }
  141 +
  142 + return getProductListOrig(finalParams);
  143 +}
  144 +
  145 +function getSortListOrig(finalParams) {
  146 + return this.get({data: finalParams, params: {cache: config.apiCache}});
  147 +}
  148 +
  149 +/**
  150 + * 获取分类列表
  151 + * @return
  152 + */
  153 +function getSortList(params, channel) {
  154 + let finalParams = {
  155 + method: 'web.regular.groupsort.sale',
  156 + sales: 'Y', // 在销售商品分类
  157 + status: 1, // 上架商品分类
  158 + stocknumber: 1 // 过滤掉已售罄
  159 + };
  160 +
  161 + Object.assign(finalParams, params);
  162 +
  163 + if (channel) {
  164 + switch (channel) {
  165 + case 'boys':
  166 + finalParams.yh_channel = 1;
  167 + break;
  168 + case 'girls':
  169 + finalParams.yh_channel = 2;
  170 + break;
  171 + case 'kids':
  172 + finalParams.yh_channel = 3;
  173 + break;
  174 + case 'lifestyle':
  175 + finalParams.yh_channel = 4;
  176 + break;
  177 + default:
  178 + break;
  179 + }
  180 + }
  181 +
  182 + if (!config.useCache) {
  183 + return this.getSortListOrig(finalParams);
  184 + } else {
  185 + let cKey = this.getSearchCacheKey(finalParams);
  186 +
  187 + return cache.get(cKey)
  188 + .catch(err => logger.debug(`product query save cache data fail:${err.toString()}`))
  189 + .then(cdata => {
  190 + let cdataObj;
  191 +
  192 + if (cdata) {
  193 + try {
  194 + cdataObj = JSON.parse(cdata);
  195 + } catch (e) {
  196 + logger.debug('getSortList cache data parse fail.');
  197 + }
  198 + }
  199 +
  200 + if (cdataObj) {
  201 + return cdataObj;
  202 + } else {
  203 + return this.getSortListOrig(finalParams).then(ret => {
  204 + if (ret && ret.code === 200) {
  205 + _saveCache(cKey, ret, CACHE_TIME_S);
  206 + }
  207 + return ret;
  208 + });
  209 + }
  210 + });
  211 + }
  212 +}
  213 +
  214 +/**
  215 + * 获取分类图文介绍
  216 + * @return
  217 + */
  218 +function getSortIntro(params) {
  219 + let finalParams = {
  220 + method: 'web.search.banner'
  221 + };
  222 +
  223 + Object.assign(finalParams, params);
  224 + return this.get({data: finalParams, params: {cache: config.apiCache}});
  225 +}
  226 +
  227 +/**
  228 + * 获取分类广告
  229 + * @return
  230 + */
  231 +function getSortAds(params) {
  232 + let finalParams = {
  233 + method: 'app.ads.list'
  234 + };
  235 +
  236 + Object.assign(finalParams, params);
  237 + return this.get({data: finalParams, params: {cache: config.apiCache}});
  238 +}
  239 +
  240 +/**
  241 + * 获取品牌系列
  242 + * @return
  243 + */
  244 +function getBrandShopSeries(params) {
  245 + let finalParams = {
  246 + method: 'web.brand.series',
  247 + status: params.status || 1
  248 + };
  249 +
  250 + if (params.brandId) {
  251 + finalParams.brand_id = params.brandId;
  252 + } else if (params.shopId) {
  253 + Object.assign(finalParams, {
  254 + method: 'web.shop.series',
  255 + shop_id: params.shopId
  256 + });
  257 + }
  258 +
  259 + return this.get({data: finalParams, params: {cache: config.apiCache}});
  260 +}
  261 +
  262 +/**
  263 + * 获取品牌folder
  264 + * @return
  265 + */
  266 +function getBrandShopFolder(params) {
  267 + let finalParams = {
  268 + method: 'web.brand.folder',
  269 + status: params.status || 1
  270 + };
  271 +
  272 + if (params.brandId) {
  273 + finalParams.brand_id = params.brandId;
  274 + } else if (params.shopId) {
  275 + Object.assign(finalParams, {
  276 + method: 'web.shop.folder',
  277 + shop_id: params.shopId
  278 + });
  279 + }
  280 +
  281 + return this.get({data: finalParams, params: {cache: config.apiCache}});
  282 +}
  283 +
  284 +/**
  285 + * 获取品牌水牌
  286 + * @return
  287 + */
  288 +function getNodeContent(params) {
  289 + let finalParams = {
  290 + method: 'web.html.content',
  291 + mode: params.mode || 'release',
  292 + node: params.node || ''
  293 + };
  294 +
  295 + return this.get({data: finalParams, params: {cache: config.apiCache}});
  296 +}
  297 +
  298 +/**
  299 + * 一周新品上架
  300 + * @return
  301 + */
  302 +function getWeekNew(params) {
  303 +
  304 + let finalParams = {
  305 + method: 'web.regular.recent'
  306 + };
  307 +
  308 + Object.assign(finalParams, params);
  309 + return this.get({data: finalParams, params: {cache: config.apiCache}});
  310 +}
  311 +
  312 +function getBrandCouponAsync(brandId, uid) {
  313 + let extra = {code: 200};
  314 +
  315 + if (!uid) {
  316 + extra.cache = true;
  317 + }
  318 +
  319 + return this.get({
  320 + data: {
  321 + method: 'app.brand.getBrandIntro',
  322 + brand_id: brandId,
  323 + uid: uid
  324 + }, params: extra
  325 + });
  326 +}
  327 +
  328 +/**
  329 + * 根据关键词搜索品牌店铺信息
  330 + * @return
  331 + */
  332 +function getBrandShop(query) {
  333 + let finalParams = {
  334 + method: 'web.search.shopListInfo'
  335 + };
  336 +
  337 + return this.get({data: Object.assign(finalParams, {keyword: query}), params: {cache: config.apiCache}});
  338 +}
  339 +
  340 +/**
  341 + * 根据搜索得到店铺/品牌
  342 + */
  343 +function getShopList(params) {
  344 + if (!params || !params.query) {
  345 + return;
  346 + }
  347 +
  348 + return this.getBrandShop(params.query).then(shops => {
  349 + let shopEntry = [];
  350 +
  351 + _.forEach(_.get(shops, 'data.shopList', []), value => {
  352 + let shopInfo = {
  353 + home: helpers.urlFormat('', null, value.shop_domain || value.brand_domain),
  354 + logo: value.shop_logo || value.brand_ico,
  355 + shopName: value.shop_name || value.brand_name,
  356 + shopType: '',
  357 + sort: []
  358 + };
  359 +
  360 + if (value.is_global === 'Y') {
  361 + shopInfo.home = helpers.urlFormat(GLOBAL_BASE_URI, {brand: value.global_brand_id});
  362 + shopInfo.shopType = 'global-brand';
  363 + }
  364 +
  365 + // 店铺/品牌的小分类
  366 + _.forEach(_.get(value, 'sortInfo.sort', []), sortInfo => {
  367 + _.forEach(_.get(sortInfo, 'sub', []), subSort => {
  368 + let sortHref;
  369 +
  370 + if (value.is_global !== 'Y') {
  371 + sortHref = helpers.urlFormat('', {misort: subSort.sort_id},
  372 + value.shop_domain || value.brand_domain);
  373 + } else {
  374 + sortHref = helpers.urlFormat(GLOBAL_BASE_URI, {
  375 + misort: subSort.sort_id,
  376 + brand: value.global_brand_id
  377 + });
  378 + }
  379 + shopInfo.sort.push({
  380 + href: sortHref,
  381 + name: subSort.sort_name
  382 + });
  383 + });
  384 + });
  385 +
  386 + shopEntry.push(shopInfo);
  387 + });
  388 +
  389 + return shopEntry;
  390 + });
  391 +}
  392 +
  393 +/**
  394 + * 搜索提示
  395 + * @return
  396 + */
  397 +function getSuggest(params) {
  398 +
  399 + let finalParams = {
  400 + method: 'app.search.fuzzy',
  401 + keyword: params.keyword || ''
  402 + };
  403 +
  404 + return this.get({data: finalParams, params: {cache: config.apiCache}});
  405 +}
  406 +
  407 +
  408 +/**
  409 + * 根据品牌域名获取品牌信息
  410 + * @return
  411 + */
  412 +function getBrandData(params) {
  413 + let finalParams = {
  414 + method: 'web.brand.byDomain',
  415 + domain: params.domain || ''
  416 + };
  417 +
  418 + return this.get({data: finalParams, params: {cache: config.apiCache}});
  419 +}
  420 +
  421 +/**
  422 + * 根据uid和品牌id判断品牌是否收藏
  423 + * @return
  424 + */
  425 +function isFavoriteBrand(uid, brandId) {
  426 + return this.get({
  427 + url: isFavoriteBrandUrl,
  428 + data: {
  429 + uid: uid,
  430 + brandId: brandId
  431 + },
  432 + api: global.yoho.serviceApi
  433 + });
  434 +}
  435 +
  436 +/**
  437 + * 根据shopId获取店铺基本信息
  438 + * @return
  439 + */
  440 +function getShopInfo(shopId, uid) {
  441 + let finalParams = {
  442 + method: 'app.shops.getIntro',
  443 + shop_id: shopId || 0,
  444 + uid: uid || 0
  445 + };
  446 +
  447 + return this.get({data: finalParams, params: {cache: config.apiCache}});
  448 +
  449 +}
  450 +
  451 +/**
  452 + * 查询店铺下面的所有品牌
  453 + */
  454 +function getShopBrands(shopId) {
  455 + return this.get({
  456 + data: {method: 'app.shops.getShopsBrands', shop_id: shopId || 0},
  457 + params: {cache: config.apiCache}
  458 + });
  459 +}
  460 +
  461 +/**
  462 + * 查询店铺装修
  463 + */
  464 +function getShopDecorator(shopId) {
  465 + return this.get({
  466 + data: {method: 'app.shopsdecorator.getList', shop_id: shopId || 0},
  467 + params: {cache: config.apiCache}
  468 + });
  469 +}
  470 +
  471 +/**
  472 + * 通过品牌获取相关文章
  473 + */
  474 +function getArticleByBrand(brand, udid, limit) {
  475 + let params = {
  476 + brand_id: brand || 0,
  477 + udid: udid,
  478 + limit: limit || 6
  479 + };
  480 +
  481 + return this.get({
  482 + url: relateArticleUrl,
  483 + data: params,
  484 + api: global.yoho.ServiceAPI
  485 + });
  486 +}
  487 +
  488 +function getBrands4Filter(params) {
  489 + return this.get({
  490 + data: Object.assign({
  491 + method: 'web.regular.aggBrand'
  492 + }, params)
  493 + });
  494 +}
  495 +
  496 +/**
  497 + * 有可能喜欢的商品
  498 +
  499 + * @param int $channel 频道,1代表男生,2代表女生,3代表潮童,4代表创意生活
  500 + * @param $uid 用户ID
  501 + * @param $udid 设备ID
  502 + * @param $rec_pos 位置码
  503 + * @param $limit 数量限制
  504 + * @return array 接口返回的数据
  505 + * */
  506 +
  507 +function lessRecommend(channelNum, uid, udid, recPos, limit) {
  508 + let param = {
  509 + method: 'app.search.newLast7day',
  510 + yh_channel: channelNum,
  511 + udid: udid,
  512 + rec_pos: recPos,
  513 + limit: limit
  514 + };
  515 +
  516 + if (uid) {
  517 + param.uid = uid;
  518 + }
  519 +
  520 + return this.get({data: param});
  521 +}
  522 +
  523 +module.exports = class extends global.yoho.BaseModel {
  524 + constructor(ctx) {
  525 + super(ctx);
  526 +
  527 + this.getKeyActivityAsync = getKeyActivityAsync.bind(this);
  528 + this.getProductList = getProductList.bind(this);
  529 + this.getSeoProductList = getSeoProductList.bind(this);
  530 + this.getSortList = getSortList.bind(this);
  531 + this.getSortIntro = getSortIntro.bind(this);
  532 + this.getSortAds = getSortAds.bind(this);
  533 + this.getBrandShopFolder = getBrandShopFolder.bind(this);
  534 + this.getBrandShopSeries = getBrandShopSeries.bind(this);
  535 + this.getWeekNew = getWeekNew.bind(this);
  536 + this.getBrandCouponAsync = getBrandCouponAsync.bind(this);
  537 + this.getBrandShop = getBrandShop.bind(this);
  538 + this.getSuggest = getSuggest.bind(this);
  539 + this.getBrandData = getBrandData.bind(this);
  540 + this.getNodeContent = getNodeContent.bind(this);
  541 + this.isFavoriteBrand = isFavoriteBrand.bind(this);
  542 + this.getShopInfo = getShopInfo.bind(this);
  543 + this.getShopBrands = getShopBrands.bind(this);
  544 + this.getShopDecorator = getShopDecorator.bind(this);
  545 + this.getArticleByBrand = getArticleByBrand.bind(this);
  546 + this.getShopList = getShopList.bind(this);
  547 + this.getBrands4Filter = getBrands4Filter.bind(this);
  548 + this.getProductListOrig = getProductListOrig.bind(this);
  549 + this.getSearchCacheKey = getSearchCacheKey.bind(this);
  550 + this.lessRecommend = lessRecommend.bind(this);
  551 + this.getSortListOrig = getSortListOrig.bind(this);
  552 + }
  553 +};
@@ -3,23 +3,62 @@ @@ -3,23 +3,62 @@
3 */ 3 */
4 'use strict'; 4 'use strict';
5 5
  6 +const config = global.yoho.config;
  7 +
6 module.exports = class extends global.yoho.BaseModel { 8 module.exports = class extends global.yoho.BaseModel {
7 constructor(ctx) { 9 constructor(ctx) {
8 super(ctx); 10 super(ctx);
9 } 11 }
10 12
  13 + /**
  14 + * 获取店铺装修的所有资源接口
  15 + */
  16 + shopsDecoratorListAsync(shopId) {
  17 + return this.get({
  18 + data: {
  19 + method: 'app.shopsdecorator.getList',
  20 + shop_id: shopId
  21 + }, params: {cache: config.apiCache}
  22 + });
  23 + }
  24 +
  25 + /**
  26 + * 获取店铺优惠券接口
  27 + */
  28 + shopCouponListAsync(shopId, uid) {
  29 + let extra = {
  30 + code: 200
  31 + };
  32 +
  33 + if (!uid) {
  34 + extra.cache = true;
  35 + }
  36 +
  37 + return this.get({
  38 + data: {
  39 + method: 'shop.coupons.list',
  40 + shop_id: shopId,
  41 + uid: uid
  42 + }, params: extra
  43 + });
  44 + }
  45 +
11 shopBannerAsync(shopId) { 46 shopBannerAsync(shopId) {
12 - return this.get({data: {  
13 - method: 'app.shop.banner',  
14 - shop_id: shopId  
15 - }}); 47 + return this.get({
  48 + data: {
  49 + method: 'app.shop.banner',
  50 + shop_id: shopId
  51 + }
  52 + });
16 } 53 }
17 54
18 queryShopsByBrandId(sid, bid) { 55 queryShopsByBrandId(sid, bid) {
19 - return this.get({data: {  
20 - method: 'app.product.queryShopsInfoById',  
21 - brand_id: bid,  
22 - shop_id: sid  
23 - }}); 56 + return this.get({
  57 + data: {
  58 + method: 'app.product.queryShopsInfoById',
  59 + brand_id: bid,
  60 + shop_id: sid
  61 + }
  62 + });
24 } 63 }
25 }; 64 };
@@ -6,8 +6,8 @@ @@ -6,8 +6,8 @@
6 // TODO: ctx 6 // TODO: ctx
7 'use strict'; 7 'use strict';
8 const utils = '../../../utils'; 8 const utils = '../../../utils';
9 -const searchApi = require('./search-api');  
10 -const shopApi = require('./shop-api'); 9 +const SearchApiModel = require('./ctx-search-api');
  10 +const ShopApiModel = require('./ctx-shop-api');
11 const headerModel = require('../../../doraemon/models/header'); 11 const headerModel = require('../../../doraemon/models/header');
12 const productProcess = require(`${utils}/product-process`); 12 const productProcess = require(`${utils}/product-process`);
13 const searchHandler = require('./search-handler'); 13 const searchHandler = require('./search-handler');
@@ -55,7 +55,7 @@ const _getGender = (channel) => { @@ -55,7 +55,7 @@ const _getGender = (channel) => {
55 /** 55 /**
56 * 获取商品分类列表数据 56 * 获取商品分类列表数据
57 */ 57 */
58 -const getListData = (params, channel) => { 58 +function getListData(params, channel) {
59 let standard = []; 59 let standard = [];
60 60
61 _.forEach(params, (value, key) => { 61 _.forEach(params, (value, key) => {
@@ -76,8 +76,8 @@ const getListData = (params, channel) => { @@ -76,8 +76,8 @@ const getListData = (params, channel) => {
76 // 调用接口 76 // 调用接口
77 let apiMethod = [ 77 let apiMethod = [
78 headerModel.requestHeaderData(channel), 78 headerModel.requestHeaderData(channel),
79 - searchApi.getSortList({}, channel),  
80 - searchApi.getProductList(searchParams, 'categoryList') 79 + this.searchApi.getSortList({}, channel),
  80 + this.searchApi.getProductList(searchParams, 'categoryList')
81 ]; 81 ];
82 82
83 // 搜索分类介绍和广告 83 // 搜索分类介绍和广告
@@ -88,8 +88,8 @@ const getListData = (params, channel) => { @@ -88,8 +88,8 @@ const getListData = (params, channel) => {
88 gender: params.gender || '1,3' 88 gender: params.gender || '1,3'
89 }; 89 };
90 90
91 - apiMethod.push(searchApi.getSortIntro(Object.assign(IntroParams, {position_id: positionId})));  
92 - apiMethod.push(searchApi.getSortAds(Object.assign(IntroParams, {position_id: sortAdsId}))); 91 + apiMethod.push(this.searchApi.getSortIntro(Object.assign(IntroParams, {position_id: positionId})));
  92 + apiMethod.push(this.searchApi.getSortAds(Object.assign(IntroParams, {position_id: sortAdsId})));
93 } 93 }
94 94
95 return Promise.all(apiMethod).then(result => { 95 return Promise.all(apiMethod).then(result => {
@@ -158,21 +158,21 @@ const getListData = (params, channel) => { @@ -158,21 +158,21 @@ const getListData = (params, channel) => {
158 158
159 return Object.assign({}, seo, finalResult); 159 return Object.assign({}, seo, finalResult);
160 }); 160 });
161 -}; 161 +}
162 162
163 /** 163 /**
164 * 获取新品到着数据 164 * 获取新品到着数据
165 */ 165 */
166 -const getListNewData = (params, channel) => { 166 +function getListNewData(params, channel) {
167 167
168 let searchParams = searchHandler.getSearchParams(params); 168 let searchParams = searchHandler.getSearchParams(params);
169 169
170 // 调用接口 170 // 调用接口
171 let apiMethod = [ 171 let apiMethod = [
172 headerModel.requestHeaderData(channel), 172 headerModel.requestHeaderData(channel),
173 - searchApi.getSortList({}, channel),  
174 - searchApi.getProductList(Object.assign(searchParams), 'newProduct'),  
175 - searchApi.getWeekNew(params) 173 + this.searchApi.getSortList({}, channel),
  174 + this.searchApi.getProductList(Object.assign(searchParams), 'newProduct'),
  175 + this.searchApi.getWeekNew(params)
176 ]; 176 ];
177 177
178 return Promise.all(apiMethod).then(result => { 178 return Promise.all(apiMethod).then(result => {
@@ -214,8 +214,10 @@ const getListNewData = (params, channel) => { @@ -214,8 +214,10 @@ const getListNewData = (params, channel) => {
214 totalCount: result[2].data.total, 214 totalCount: result[2].data.total,
215 footPager: searchHandler.handlePagerData(result[2].data.total, params), 215 footPager: searchHandler.handlePagerData(result[2].data.total, params),
216 goods: productProcess.processProductList(result[2].data.product_list, 216 goods: productProcess.processProductList(result[2].data.product_list,
217 - Object.assign({showDiscount: false, showNew: false,  
218 - from: {type: 'listNew', params: params}}, params)), 217 + Object.assign({
  218 + showDiscount: false, showNew: false,
  219 + from: {type: 'listNew', params: params}
  220 + }, params)),
219 hasNextPage: searchHandler.handleNextPage(params, result[2].data.total), 221 hasNextPage: searchHandler.handleNextPage(params, result[2].data.total),
220 222
221 // 最近浏览记录 223 // 最近浏览记录
@@ -234,13 +236,13 @@ const getListNewData = (params, channel) => { @@ -234,13 +236,13 @@ const getListNewData = (params, channel) => {
234 236
235 return Object.assign({}, seo, finalResult); 237 return Object.assign({}, seo, finalResult);
236 }); 238 });
237 -}; 239 +}
238 240
239 /** 241 /**
240 * 根据品牌域名查询品牌信息 242 * 根据品牌域名查询品牌信息
241 */ 243 */
242 -const getBrandInfo = (params) => {  
243 - return searchApi.getBrandData(params).then(result => { 244 +function getBrandInfo(params) {
  245 + return this.searchApi.getBrandData(params).then(result => {
244 246
245 if (result.code !== 200 || !result.data) { 247 if (result.code !== 200 || !result.data) {
246 return {}; 248 return {};
@@ -262,12 +264,12 @@ const getBrandInfo = (params) => { @@ -262,12 +264,12 @@ const getBrandInfo = (params) => {
262 }; 264 };
263 265
264 }); 266 });
265 -}; 267 +}
266 268
267 /** 269 /**
268 * 获取品牌页面数据 270 * 获取品牌页面数据
269 */ 271 */
270 -const getBrandData = (params, extra, channel) => { 272 +function getBrandData(params, extra, channel) {
271 let queryBase = {}; 273 let queryBase = {};
272 let searchParams = searchHandler.getSearchParams(params); 274 let searchParams = searchHandler.getSearchParams(params);
273 275
@@ -288,12 +290,12 @@ const getBrandData = (params, extra, channel) => { @@ -288,12 +290,12 @@ const getBrandData = (params, extra, channel) => {
288 // 调用接口 290 // 调用接口
289 let apiMethod = [ 291 let apiMethod = [
290 headerModel.requestHeaderData(channel), 292 headerModel.requestHeaderData(channel),
291 - searchApi.getSortList(queryBase),  
292 - searchApi.getProductList(Object.assign(searchParams, queryBase), 'brand') 293 + this.searchApi.getSortList(queryBase),
  294 + this.searchApi.getProductList(Object.assign(searchParams, queryBase), 'brand')
293 ]; 295 ];
294 296
295 if (queryBase.brand) { 297 if (queryBase.brand) {
296 - apiMethod.push(searchApi.getBrandCouponAsync(queryBase.brand)); 298 + apiMethod.push(this.searchApi.getBrandCouponAsync(queryBase.brand));
297 } 299 }
298 300
299 return Promise.all(apiMethod).then(result => { 301 return Promise.all(apiMethod).then(result => {
@@ -363,17 +365,17 @@ const getBrandData = (params, extra, channel) => { @@ -363,17 +365,17 @@ const getBrandData = (params, extra, channel) => {
363 365
364 return Object.assign({}, seo, finalResult); 366 return Object.assign({}, seo, finalResult);
365 }); 367 });
366 -}; 368 +}
367 369
368 /** 370 /**
369 * 获取品牌介绍页面数据 371 * 获取品牌介绍页面数据
370 */ 372 */
371 -const getBrandAbout = (domain, uid, channel) => { 373 +function getBrandAbout(domain, uid, channel) {
372 channel = channel || 'boys'; 374 channel = channel || 'boys';
373 375
374 return Promise.all([ 376 return Promise.all([
375 headerModel.requestHeaderData(channel), 377 headerModel.requestHeaderData(channel),
376 - searchApi.getBrandData({domain: domain}) 378 + this.searchApi.getBrandData({domain: domain})
377 ]).then(result => { 379 ]).then(result => {
378 let home; 380 let home;
379 let finalResult = { 381 let finalResult = {
@@ -442,19 +444,19 @@ const getBrandAbout = (domain, uid, channel) => { @@ -442,19 +444,19 @@ const getBrandAbout = (domain, uid, channel) => {
442 444
443 return finalResult; 445 return finalResult;
444 }); 446 });
445 -}; 447 +}
446 448
447 449
448 /** 450 /**
449 * 获取店铺介绍页面数据 451 * 获取店铺介绍页面数据
450 */ 452 */
451 -const getShopAbout = (shopId, uid, channel) => { 453 +function getShopAbout(shopId, uid, channel) {
452 let resData = {}; 454 let resData = {};
453 455
454 return Promise.all([ 456 return Promise.all([
455 headerModel.requestHeaderData(channel), 457 headerModel.requestHeaderData(channel),
456 - searchApi.getShopDecorator(shopId), // 店铺装修数据  
457 - searchApi.getShopInfo(shopId, uid) 458 + this.searchApi.getShopDecorator(shopId), // 店铺装修数据
  459 + this.searchApi.getShopInfo(shopId, uid)
458 ]).then(result => { 460 ]).then(result => {
459 resData.headerData = Object.assign(result[0].headerData, { 461 resData.headerData = Object.assign(result[0].headerData, {
460 header: true 462 header: true
@@ -485,27 +487,30 @@ const getShopAbout = (shopId, uid, channel) => { @@ -485,27 +487,30 @@ const getShopAbout = (shopId, uid, channel) => {
485 487
486 return resData; 488 return resData;
487 }); 489 });
488 -}; 490 +}
489 491
490 /** 492 /**
491 * 获取品牌页面水牌 493 * 获取品牌页面水牌
492 */ 494 */
493 -const getNodeContentData = (params) => {  
494 - return searchApi.getNodeContent(params).then(result => { 495 +function getNodeContentData(params) {
  496 + return this.searchApi.getNodeContent(params).then(result => {
495 497
496 if (result.code === 200 && result.data) { 498 if (result.code === 200 && result.data) {
497 return result.data; 499 return result.data;
498 } 500 }
499 }); 501 });
500 -}; 502 +}
501 503
502 /** 504 /**
503 * 获取品牌页面系列 505 * 获取品牌页面系列
504 */ 506 */
505 -const getAdnav = (params) => { 507 +function getAdnav(params) {
506 let resData = {}; 508 let resData = {};
507 509
508 - return Promise.all([searchApi.getBrandShopFolder(params), searchApi.getBrandShopSeries(params)]).then(result => { 510 + return Promise.all([
  511 + this.searchApi.getBrandShopFolder(params),
  512 + this.searchApi.getBrandShopSeries(params)
  513 + ]).then(result => {
509 let flist = []; 514 let flist = [];
510 let slist = []; 515 let slist = [];
511 516
@@ -540,15 +545,15 @@ const getAdnav = (params) => { @@ -540,15 +545,15 @@ const getAdnav = (params) => {
540 545
541 return resData; 546 return resData;
542 }); 547 });
543 -}; 548 +}
544 549
545 /** 550 /**
546 * 获取店铺基本信息 551 * 获取店铺基本信息
547 */ 552 */
548 553
549 -const getShopInfo = (shopId, uid) => { 554 +function getShopInfo(shopId, uid) {
550 555
551 - return searchApi.getShopInfo(shopId, uid).then(result => { 556 + return this.searchApi.getShopInfo(shopId, uid).then(result => {
552 if (result.code === 200) { 557 if (result.code === 200) {
553 return { 558 return {
554 brandName: result.data.shop_name, 559 brandName: result.data.shop_name,
@@ -565,7 +570,7 @@ const getShopInfo = (shopId, uid) => { @@ -565,7 +570,7 @@ const getShopInfo = (shopId, uid) => {
565 return {}; 570 return {};
566 } 571 }
567 }); 572 });
568 -}; 573 +}
569 574
570 /** 575 /**
571 * 获取经典模板店铺数据 576 * 获取经典模板店铺数据
@@ -574,7 +579,7 @@ const getShopInfo = (shopId, uid) => { @@ -574,7 +579,7 @@ const getShopInfo = (shopId, uid) => {
574 * @param params 579 * @param params
575 * @param shopInfo 店铺介绍 580 * @param shopInfo 店铺介绍
576 */ 581 */
577 -const getShopData = (shopId, channel, params, shopInfo) => { 582 +function getShopData(shopId, channel, params, shopInfo) {
578 let gender = _getGender(channel); 583 let gender = _getGender(channel);
579 584
580 params = params || {}; 585 params = params || {};
@@ -582,12 +587,12 @@ const getShopData = (shopId, channel, params, shopInfo) => { @@ -582,12 +587,12 @@ const getShopData = (shopId, channel, params, shopInfo) => {
582 587
583 return Promise.all([ 588 return Promise.all([
584 headerModel.requestHeaderData(channel), // 头部数据 589 headerModel.requestHeaderData(channel), // 头部数据
585 - searchApi.getShopDecorator(shopId), // 店铺装修数据  
586 - searchApi.getProductList(Object.assign({ 590 + this.searchApi.getShopDecorator(shopId), // 店铺装修数据
  591 + this.searchApi.getProductList(Object.assign({
587 shop_id: shopId 592 shop_id: shopId
588 }, params), 'shop'), // 搜索店铺商品 593 }, params), 'shop'), // 搜索店铺商品
589 - searchApi.getShopBrands(shopId), // 店铺品牌数据  
590 - shopApi.shopCouponListAsync(shopId) // 店铺优惠券数据 594 + this.searchApi.getShopBrands(shopId), // 店铺品牌数据
  595 + this.shopApi.shopCouponListAsync(shopId) // 店铺优惠券数据
591 ]).then(result => { 596 ]).then(result => {
592 let finalResult = {}; 597 let finalResult = {};
593 598
@@ -641,7 +646,7 @@ const getShopData = (shopId, channel, params, shopInfo) => { @@ -641,7 +646,7 @@ const getShopData = (shopId, channel, params, shopInfo) => {
641 646
642 let articleApiMethod = [], // 通过品牌获取相关文章接口 647 let articleApiMethod = [], // 通过品牌获取相关文章接口
643 apiMethod = [ 648 apiMethod = [
644 - searchApi.getProductList({ 649 + this.searchApi.getProductList({
645 viewNum: sknList.length, 650 viewNum: sknList.length,
646 query: _.join(_.uniq(sknList), ',') 651 query: _.join(_.uniq(sknList), ',')
647 }, 'shop') 652 }, 'shop')
@@ -650,7 +655,7 @@ const getShopData = (shopId, channel, params, shopInfo) => { @@ -650,7 +655,7 @@ const getShopData = (shopId, channel, params, shopInfo) => {
650 if (result[3].code === 200 && result[3].data) { 655 if (result[3].code === 200 && result[3].data) {
651 _.forEach(result[3].data, value => { 656 _.forEach(result[3].data, value => {
652 articleApiMethod.push( 657 articleApiMethod.push(
653 - searchApi.getArticleByBrand(value.brand_id, 'udid') // 品牌推荐文章 658 + this.searchApi.getArticleByBrand(value.brand_id, 'udid') // 品牌推荐文章
654 ); 659 );
655 }); 660 });
656 } 661 }
@@ -660,7 +665,7 @@ const getShopData = (shopId, channel, params, shopInfo) => { @@ -660,7 +665,7 @@ const getShopData = (shopId, channel, params, shopInfo) => {
660 } 665 }
661 666
662 // 根据店铺id获取分类 667 // 根据店铺id获取分类
663 - apiMethod.push(searchApi.getSortList({shop_id: shopId})); 668 + apiMethod.push(this.searchApi.getSortList({shop_id: shopId}));
664 apiMethod = _.concat(apiMethod, articleApiMethod); 669 apiMethod = _.concat(apiMethod, articleApiMethod);
665 670
666 return Promise.all(apiMethod).then(subRes => { 671 return Promise.all(apiMethod).then(subRes => {
@@ -725,7 +730,7 @@ const getShopData = (shopId, channel, params, shopInfo) => { @@ -725,7 +730,7 @@ const getShopData = (shopId, channel, params, shopInfo) => {
725 trendList.push({ 730 trendList.push({
726 href: helpers.urlFormat(`/guang/${articleList[i].id}.html`, null), 731 href: helpers.urlFormat(`/guang/${articleList[i].id}.html`, null),
727 src: helpers.getForceSourceUrl(articleList[i].src) + 732 src: helpers.getForceSourceUrl(articleList[i].src) +
728 - '?imageView2/1/w/{width}/h/{height}', 733 + '?imageView2/1/w/{width}/h/{height}',
729 mainTitle: articleList[i].title, 734 mainTitle: articleList[i].title,
730 Subtitle: articleList[i].intro 735 Subtitle: articleList[i].intro
731 }); 736 });
@@ -741,21 +746,21 @@ const getShopData = (shopId, channel, params, shopInfo) => { @@ -741,21 +746,21 @@ const getShopData = (shopId, channel, params, shopInfo) => {
741 return finalResult; 746 return finalResult;
742 }); 747 });
743 }); 748 });
744 -}; 749 +}
745 750
746 /** 751 /**
747 * 获取店铺商品数据 752 * 获取店铺商品数据
748 */ 753 */
749 -const getShopGoodsData = (shopId, channel, params) => { 754 +function getShopGoodsData(shopId, channel, params) {
750 let gender = _getGender(channel); 755 let gender = _getGender(channel);
751 let resData = {}; 756 let resData = {};
752 757
753 _.unset(params, '_pjax'); 758 _.unset(params, '_pjax');
754 return Promise.all([ 759 return Promise.all([
755 - searchApi.getProductList(Object.assign({ 760 + this.searchApi.getProductList(Object.assign({
756 shop_id: shopId 761 shop_id: shopId
757 }, params), 'shop'), // 搜索店铺商品 762 }, params), 'shop'), // 搜索店铺商品
758 - searchApi.getSortList({shop_id: shopId}) // 根据店铺id获取分类 763 + this.searchApi.getSortList({shop_id: shopId}) // 根据店铺id获取分类
759 ]).then(result => { 764 ]).then(result => {
760 // 获取商品数据和顶部筛选条件 765 // 获取商品数据和顶部筛选条件
761 if (result[0].code === 200) { 766 if (result[0].code === 200) {
@@ -779,24 +784,24 @@ const getShopGoodsData = (shopId, channel, params) => { @@ -779,24 +784,24 @@ const getShopGoodsData = (shopId, channel, params) => {
779 784
780 return resData; 785 return resData;
781 }); 786 });
782 -}; 787 +}
783 788
784 -const getShopListData = (channel, params, uid) => { 789 +function getShopListData(channel, params, uid) {
785 let gender = _getGender(channel), 790 let gender = _getGender(channel),
786 shopId = params.shopId, 791 shopId = params.shopId,
787 navBar = params.navBar || 1; 792 navBar = params.navBar || 1;
788 let apiArr = [ 793 let apiArr = [
789 headerModel.requestHeaderData(channel), // 头部数据 794 headerModel.requestHeaderData(channel), // 头部数据
790 - searchApi.getShopDecorator(shopId), // 店铺装修数据  
791 - searchApi.getShopInfo(shopId, uid), // 店铺介绍  
792 - searchApi.getProductList(Object.assign({shop_id: shopId}, params, 795 + this.searchApi.getShopDecorator(shopId), // 店铺装修数据
  796 + this.searchApi.getShopInfo(shopId, uid), // 店铺介绍
  797 + this.searchApi.getProductList(Object.assign({shop_id: shopId}, params,
793 {limit: (params.limit || 60) - 1}), 'shop'), // 搜索店铺商品 798 {limit: (params.limit || 60) - 1}), 'shop'), // 搜索店铺商品
794 - searchApi.getSortList({shop_id: shopId}) // 店铺分类 799 + this.searchApi.getSortList({shop_id: shopId}) // 店铺分类
795 ]; 800 ];
796 801
797 if (_.has(params, 'query')) { 802 if (_.has(params, 'query')) {
798 // 如果有店内搜索,则并行查询店铺所有商品,搜索不到商品则显示所有商品 803 // 如果有店内搜索,则并行查询店铺所有商品,搜索不到商品则显示所有商品
799 - apiArr.push(searchApi.getProductList(Object.assign({shop_id: shopId}, 804 + apiArr.push(this.searchApi.getProductList(Object.assign({shop_id: shopId},
800 params, {query: ''}), 'shop')); // 搜索店铺所有商品 805 params, {query: ''}), 'shop')); // 搜索店铺所有商品
801 } 806 }
802 807
@@ -897,21 +902,21 @@ const getShopListData = (channel, params, uid) => { @@ -897,21 +902,21 @@ const getShopListData = (channel, params, uid) => {
897 902
898 return finalResult; 903 return finalResult;
899 }); 904 });
900 -}; 905 +}
901 906
902 /** 907 /**
903 * 获取基础模板店铺数据 908 * 获取基础模板店铺数据
904 */ 909 */
905 -const getBaseShopData = (params, extra, channel, shopId) => { 910 +function getBaseShopData(params, extra, channel, shopId) {
906 let resData = {}; 911 let resData = {};
907 912
908 params.shopId = shopId; 913 params.shopId = shopId;
909 914
910 return Promise.all([ 915 return Promise.all([
911 getBrandData(params, extra, channel), 916 getBrandData(params, extra, channel),
912 - searchApi.getShopDecorator(shopId), // 店铺装修数据  
913 - searchApi.getShopInfo(shopId, extra.uid),  
914 - shopApi.shopCouponListAsync(shopId) // 店铺优惠券数据 917 + this.searchApi.getShopDecorator(shopId), // 店铺装修数据
  918 + this.searchApi.getShopInfo(shopId, extra.uid),
  919 + this.shopApi.shopCouponListAsync(shopId) // 店铺优惠券数据
915 ]).then(result => { 920 ]).then(result => {
916 let brand = result[0] || {}; 921 let brand = result[0] || {};
917 922
@@ -961,11 +966,11 @@ const getBaseShopData = (params, extra, channel, shopId) => { @@ -961,11 +966,11 @@ const getBaseShopData = (params, extra, channel, shopId) => {
961 966
962 return resData; 967 return resData;
963 }); 968 });
964 -}; 969 +}
965 970
966 -const getUserCoupunStatus = (id, uid, type) => { 971 +function getUserCoupunStatus(id, uid, type) {
967 if (type === 'shop') { 972 if (type === 'shop') {
968 - return shopApi.shopCouponListAsync(id, uid).then(result => { 973 + return this.shopApi.shopCouponListAsync(id, uid).then(result => {
969 if (result.data) { 974 if (result.data) {
970 _.forEach(result.data, value => { 975 _.forEach(result.data, value => {
971 Object.assign(value, { 976 Object.assign(value, {
@@ -978,7 +983,7 @@ const getUserCoupunStatus = (id, uid, type) => { @@ -978,7 +983,7 @@ const getUserCoupunStatus = (id, uid, type) => {
978 return result; 983 return result;
979 }); 984 });
980 } else { 985 } else {
981 - return searchApi.getBrandCouponAsync(id, uid).then(result => { 986 + return this.searchApi.getBrandCouponAsync(id, uid).then(result => {
982 if (result.data) { 987 if (result.data) {
983 result.data = _.get(result, 'data.coupons', []); 988 result.data = _.get(result, 'data.coupons', []);
984 _.forEach(result.data, value => { 989 _.forEach(result.data, value => {
@@ -992,22 +997,28 @@ const getUserCoupunStatus = (id, uid, type) => { @@ -992,22 +997,28 @@ const getUserCoupunStatus = (id, uid, type) => {
992 return result; 997 return result;
993 }); 998 });
994 } 999 }
995 -  
996 -};  
997 -  
998 -module.exports = {  
999 - getListData,  
1000 - getListNewData,  
1001 - getBrandInfo,  
1002 - getBrandData,  
1003 - getBrandAbout,  
1004 - getShopAbout,  
1005 - getNodeContentData,  
1006 - getAdnav,  
1007 - getShopInfo,  
1008 - getShopData,  
1009 - getShopGoodsData,  
1010 - getShopListData,  
1011 - getBaseShopData,  
1012 - getUserCoupunStatus 1000 +}
  1001 +
  1002 +module.exports = class extends global.yoho.BaseModel {
  1003 + constructor(ctx) {
  1004 + super(ctx);
  1005 +
  1006 + this.searchApi = new SearchApiModel(ctx);
  1007 + this.shopApi = new ShopApiModel(ctx);
  1008 +
  1009 + this.getListData = getListData.bind(this);
  1010 + this.getListNewData = getListNewData.bind(this);
  1011 + this.getBrandInfo = getBrandInfo.bind(this);
  1012 + this.getBrandData = getBrandData.bind(this);
  1013 + this.getBrandAbout = getBrandAbout.bind(this);
  1014 + this.getShopAbout = getShopAbout.bind(this);
  1015 + this.getNodeContentData = getNodeContentData.bind(this);
  1016 + this.getAdnav = getAdnav.bind(this);
  1017 + this.getShopInfo = getShopInfo.bind(this);
  1018 + this.getShopData = getShopData.bind(this);
  1019 + this.getShopGoodsData = getShopGoodsData.bind(this);
  1020 + this.getShopListData = getShopListData.bind(this);
  1021 + this.getBaseShopData = getBaseShopData.bind(this);
  1022 + this.getUserCoupunStatus = getUserCoupunStatus.bind(this);
  1023 + }
1013 }; 1024 };