Authored by ccbikai(👎🏻🍜)

删除重复代码

'use strict';
const mRoot = '../models';
const recommendForYouModel = require(`${mRoot}/recommend-for-you`); // 领取优惠券 model
exports.userCenter = (req, res, next) => {
var udid = req.sessionID,
uid = req.user.uid || 0,
yhChannel = req.query.yh_channel || '1',
limit = 30;
recommendForYouModel.getPreference({
yh_channel: yhChannel,
udid: udid,
limit: limit,
rec_pos: '100004',
uid: uid
}).then((preferenceData) => {
if (preferenceData.code === 200) {
// 获取信息成功
}
res.render('recommend-for-you/index', {
layout: false,
result: preferenceData,
module: 'product',
page: 'recommend'
});
}).catch(next);
};
exports.cart = (req, res, next) => {
var udid = req.sessionID,
uid = req.user.uid || 0,
yhChannel = req.query.yh_channel || '1',
limit = 30;
recommendForYouModel.getPreference({
yh_channel: yhChannel,
udid: udid,
limit: limit,
rec_pos: '100003',
uid: uid
}).then((preferenceData) => {
if (preferenceData.code === 200) {
// 获取信息成功
}
res.render('recommend-for-you/index', {
layout: false,
result: preferenceData,
module: 'product',
page: 'recommend'
});
}).catch(next);
};
'use strict';
var api = global.yoho.API;
const camelCase = global.yoho.camelCase;
const helpers = global.yoho.helpers;
const _ = require('lodash');
/**
* 分享页面基础参数
* @param {object} sizeInfo [接口原始数据]
* @return {object} [description]
*/
const getPreferenceData = (data) => {
var dest = {};
let list = data.data || {};
list = camelCase(list);
let distGoods = [];
_.forEach(list.productList, function(value) {
if (!value.productSkn || !value.goodsList || !value.goodsList.length) {
return;
}
value.goodsId = value.goodsList[0].goodsId;
let goods = value;
goods.url = helpers.urlFormat(`/product/pro_${value.productId}_${value.goodsId}/${value.cnAlphabet}.html`);
if (_.get(goods, 'tags[0]', null)) {
goods.tags = [];
if (goods.isNew === 'Y') {
goods.tags.push({isNew: true});
} else if (goods.isAdvance === 'Y') {
goods.tags.push({isAdvance: true});
} else if (goods.isDiscount === 'Y') {
goods.tags.push({isDiscount: true});
} else if (goods.isYohoood === 'Y') {
goods.tags.push({isYohoood: true});
} else if (goods.isLimited === 'Y') {
goods.tags.push({isLimited: true});
}
}
distGoods.push(goods);
});
dest.code = list.code;
dest.goods = distGoods;
dest.rec_id = list.recId;
dest.message = list.message;
// 清空变量,释放内存
data = {};
return dest;
};
/**
* 获取为你优选数据
*/
exports.getPreference = (data) => {
var defaultParam = {
method: 'app.home.newPreference'
},
infoData = Object.assign(defaultParam, data); // 处理完成后,发给后端
return api.get('', infoData).then(result => {
return getPreferenceData(result);
}); // 所有数据返回一个 Promise,方便 Promise.all 调用
};
... ... @@ -29,10 +29,6 @@ const suggest = require(`${cRoot}/suggest`);
const message = require(`${cRoot}/message`);
const onlineService = require(`${cRoot}/onlineService`);
// recommend-for-you controller
const recommendForYou = require(`${cRoot}/recommend-for-you`);
// const myDetail = require(`${cRoot}/myDetail);
... ... @@ -136,6 +132,4 @@ router.get('/installment/card-detail', installment.cardDetail); // 银行å¡è¯¦æ
router.get('/installment/delBankCard', installment.delBankCard); // 删除绑定
router.get('/installment/setMasterCard', installment.setMasterCard); // 切换主卡
router.get('/recommend-for-you/userCenter', recommendForYou.userCenter);// 为你优选
module.exports = router;
... ...
{{# result}}
<div id="goods-container" class="goods-container">
<p class="title">
<span>为你优选新品</span>
</p>
<div class="new-goods container clearfix">
{{# goods}}
{{> common/goods}}
{{/ goods}}
</div>
</div>
{{/result}}