Authored by ccbikai(👎🏻🍜)

Merge branch 'release/newSearch'

// 购物车数量
'use strict';
const countModel = require('../models/count');
let cartCount = (req, res, next) => {
let uid = req.user.uid;
let shoppingKey = req.cookies._SPK || '';
countModel.cartCount(uid, shoppingKey).then((result) => {
res.json(result);
}).catch(next);
};
module.exports = {
cartCount
};
... ...
/**
* sub app channel
* @author: Bi Kai<kai.bi@yoho.cn>
* @date: 2016/05/09
*/
var express = require('express'),
path = require('path'),
hbs = require('express-handlebars');
var app = express();
// set view engin
var doraemon = path.join(__dirname, '../../doraemon/views'); // parent view root
app.on('mount', function(parent) {
delete parent.locals.settings; // 不继承父 App 的设置
Object.assign(app.locals, parent.locals);
});
app.set('views', path.join(__dirname, 'views/action'));
app.engine('.hbs', hbs({
extname: '.hbs',
defaultLayout: 'layout',
layoutsDir: doraemon,
partialsDir: [path.join(__dirname, 'views/partial'), `${doraemon}/partial`],
helpers: global.yoho.helpers
}));
// router
app.use(require('./router'));
module.exports = app;
... ...
'use strict';
const api = global.yoho.API;
const cartCount = (uid, shoppingKey) => {
return api.get('', {
method: 'app.Shopping.count',
uid: uid,
shopping_key: shoppingKey
}).then((result) => {
return result;
});
};
module.exports = {
cartCount
};
... ...
/**
* router of sub app channel
* @author: Bi Kai<kai.bi@yoho.cn>
* @date: 2016/05/09
*/
'use strict';
const express = require('express');
const router = express.Router();
const cRoot = './controllers';
const countController = require(`${cRoot}/count`);
router.get('/index/count', countController.cartCount);
module.exports = router;
... ...
... ... @@ -5,12 +5,14 @@
*/
'use strict';
const utils = '../../../utils';
const mRoot = '../models';
const headerModel = require('../../../doraemon/models/header');
const listModel = require(`${mRoot}/list`);
const _ = require('lodash');
const crypto = global.yoho.crypto;
const helpers = global.yoho.helpers;
const productProcess = require(`${utils}/product-process`);
/**
* 店铺 - 基础模板
... ... @@ -80,40 +82,37 @@ const _shop = (req, res, shopId) => {
};
}
// uid = req.user.uid;
// } else {
// uid = req.query.uid;
// req.session.appUid = uid;
// res.cookie('appUid', uid, {
// domain: 'yohobuy.com',
// expires: new Date(Date.now() + 2592000000) // 有效期一年
// });
// }
listModel.getShopData(req, shopId, uid, isApp).then(result => {
if (result.goBrand) {
/* 若店铺使用基础模板跳转基础模板 */
_baseShop(req, res, result.goBrand, shopId);
} else {
result = _.assign(result, pageHeader);
res.render('shop/index', {
module: 'product',
page: 'shop',
shopIndex: result,
shopHeadHide: true,
gender: req.query.gender,
channel: req.query.channel,
// pageHeader: headerModel.setNav({
// navTitle: result.storeName
// }),
title: result.storeName + '|' + result.storeName + '潮流服装服饰-Yoho!Buy有货',
keywords: result.storeName + ',' + result.storeName + '服装服饰,' + result.storeName + '潮流服装服饰',
description: result.storeName + '|Yoho!Buy有货' + result.storeName + '潮流服饰官方授权店!100%品牌正品保证,支持货到付款。',
shopId: shopId,
shopPage: true
listModel.searchProductBySkn(result.hotListproductSkn).then(hotList => {
result = _.assign(result, pageHeader, {
hotList: productProcess.processProductList(hotList)
});
_.forEach(result.hotList, (value, key) => {
result.hotList[key].tags = {};
result.hotList[key].is_soon_sold_out = false;
result.hotList[key].tags.isHot = true;
});
res.render('shop/index', {
module: 'product',
page: 'shop',
shopIndex: result,
shopHeadHide: true,
gender: req.query.gender,
channel: req.query.channel,
title: result.storeName + '|' + result.storeName + '潮流服装服饰-Yoho!Buy有货',
keywords: result.storeName + ',' + result.storeName + '服装服饰,' + result.storeName + '潮流服装服饰',
description: result.storeName + '|Yoho!Buy有货' + result.storeName + '潮流服饰官方授权店!100%品牌正品保证,支持货到付款。',
shopId: shopId,
shopPage: true
});
});
}
});
... ...
... ... @@ -4,6 +4,7 @@
* @date: 2016/07/21
*/
'use strict';
const utils = '../../../utils';
const logger = global.yoho.logger;
const crypto = global.yoho.crypto;
const camelCase = global.yoho.camelCase;
... ... @@ -11,6 +12,7 @@ const _ = require('lodash');
const helpers = global.yoho.helpers;
const api = global.yoho.API;
const searchModel = require('./search');
const productProcess = require(`${utils}/product-process`);
/**
* 频道
... ... @@ -222,13 +224,28 @@ const getShopBrands = (shopId) => {
});
};
/**
* 通过 skn 搜索商品
* @param productSkn
* @returns {*|Promise.<TResult>}
* @private
*/
const searchProductBySkn = (productSkn) => {
return api.get('', {
method: 'h5.product.batch',
productSkn: productSkn,
}).then(result => {
return _.get(result, 'data.product_list', []);
});
};
/**
* 组织店铺页面数据
* @param {array} data 接口返回的店铺页所需数据
* @param {int} shopId 店铺id
* @param {int} isApp app版本
* @return array
* @return {shopId: int, appVersion: int}
*/
const _formShopData = (data, shopId, isApp) => {
let formatData = {
... ... @@ -350,25 +367,13 @@ const _formShopData = (data, shopId, isApp) => {
// 人气单品
if (floor.hotProductsApp) {
let goods = [];
_.forEach(resData, (item) => {
let url = '//item.yohobuy.com/product/pro_';
let productSkn = '';
if (!item.cnAlphabet) {
item.cnAlphabet = 'goods.html';
}
url += item.productId + '_' + item.goodsId + '/' + item.cnAlphabet + '.html';
goods.push({
url: url + (isApp ? `?openby:yohobuy={"action":"go.productDetail","params":{"product_skn":${item.productSkn}}}` : ''),//eslint-disable-line
img: helpers.image(item.src, 235, 314),
productName: item.productName,
salesPrice: item.salesPrice,
presentPrice: item.salesPrice
});
_.forEach(resData, value => {
productSkn += value.productSkn + ',';
});
formatData.hotList = goods;
formatData.hotListproductSkn = productSkn;
}
});
}
... ... @@ -527,12 +532,7 @@ const getShopData = (req, shopId, uid, isApp) => {
return Promise.all([
_getShopDecorator(shopId),
searchModel.getFilterData({
shop_id: shopId,
gender: req.query.gender || '1,3',
channel: channel
}),
searchModel.getSearchData({
searchModel.getFilterSearchData({
shop_id: shopId,
gender: req.query.gender || '1,3',
channel: channel
... ... @@ -544,8 +544,19 @@ const getShopData = (req, shopId, uid, isApp) => {
shopInfo: shopInfoResult // 店铺信息
};
/* 获取一次分类和商品数据 */
let shopFilterSearchData = {
filter: [],
goods: []
};
if (result[1]) {
shopFilterSearchData.filter = productProcess.processFilter(result[1].filter || []);
shopFilterSearchData.goods = productProcess.processProductList(result[1].product_list || []);
}
/* 店鋪優惠券 */
let shopCoupons = result[3] || [];
let shopCoupons = result[2] || [];
// 店铺分类
return _getShopCategory(shopId, channel).then((shopCategory) => {
... ... @@ -554,14 +565,16 @@ const getShopData = (req, shopId, uid, isApp) => {
}, shopData);
// noinspection JSCheckFunctionSignatures
return Object.assign(_formShopData(shopData, shopId, isApp), {
filter: result[1],
goods: result[2],
shopId: shopId,
coverChannel: channel,
shopCoupons: shopCoupons,
shopCouponsOne: shopCoupons.length === 1
});
return Object.assign(
_formShopData(shopData, shopId, isApp),
shopFilterSearchData,
{
shopId: shopId,
coverChannel: channel,
shopCoupons: shopCoupons,
shopCouponsOne: shopCoupons.length === 1
}
);
});
});
... ... @@ -573,10 +586,9 @@ const getShopData = (req, shopId, uid, isApp) => {
* @param req
* @param shopId
* @param uid
* @param isApp
* @returns {Promise.<TResult>|*}
*/
const getShopFav = (req, shopId, uid, isApp) => {
const getShopFav = (req, shopId, uid) => {
return _getShopInfo(shopId, uid).then(shopInfoResult => {
return shopInfoResult;
});
... ... @@ -802,5 +814,6 @@ module.exports = {
getShopBrands,
getShopCategory,
receiveCoupon,
getShopFav
getShopFav,
searchProductBySkn
};
... ...
... ... @@ -144,6 +144,22 @@ const getFilterData = (params) => {
};
/**
* 获取筛选数据
* @param {[object]} params
* @return {[array]}
*/
const getFilterSearchData = (params) => {
return _searchGoods(params).then((result) => {
if (result && result.code === 200) {
return result.data;
} else {
logger.error('get filter data api return code is not 200');
return [];
}
});
};
/**
* 获取所有的品类名称
**/
const getClassNames = () => {
... ... @@ -235,6 +251,7 @@ const searchKeyActivity = (params) => {
module.exports = {
getSearchData,
getFilterData,
getFilterSearchData,
getAllBrandNames,
getClassNames,
getSearchIndex,
... ...
... ... @@ -112,21 +112,11 @@
&#xe618;</a>
</div>
<div class="product-warp">
<ul class="product-list first">
{{#each hotList}}
<li class="buriedpoint" data-bp-id="shop_hotList_{{url}}">
<a href="{{url}}">
<img src="{{img}}">
</a>
<div class="list-price">
<p>{{productName}}</p>
<p><span class="red">{{originalPrice}}</span>
<span>{{presentPrice}}</span>
</p>
</div>
</li>
{{/each}}
</ul>
<div class="goods-container clearfix">
{{# hotList}}
{{> common/goods}}
{{/ hotList}}
</div>
</div>
</div>
... ...
... ... @@ -17,6 +17,7 @@ module.exports = app => {
app.use('/product', require('./apps/product'));
app.use('/guang', require('./apps/guang'));
app.use('/activity', require('./apps/activity'));
app.use('/cart', require('./apps/cart'));
// 分期付款
app.use('/home', require('./apps/home'));
... ...
... ... @@ -5,6 +5,9 @@
{{# isNew}}
<p class="good-tag new-tag">NEW</p>
{{/ isNew}}
{{# isHot}}
<p class="good-tag hot-tag">HOT</p>
{{/ isHot}}
{{# isAdvance}}
<p class="good-tag renew-tag">再到着</p>
{{/ isAdvance}}
... ...
... ... @@ -30,6 +30,12 @@
color: #fff;
}
.hot-tag {
width: 60px;
background-color: #ff575c;
color: #fff;
}
.renew-tag {
width: 90px;
background-color: #78dc7e;
... ...
... ... @@ -145,6 +145,12 @@ $basicBtnC: #eb0313;
color: #fff;
}
.hot-tag {
width: 60px;
background-color: #ff575c;
color: #fff;
}
.renew-tag {
background-color: #78dc7e;
color: #fff;
... ...