Authored by zhangxiaoru

yohocoin

... ... @@ -13,14 +13,7 @@ const _ = require('lodash');
const myCurrency = (req, res, next) => {
let uid = req.user.uid || 8039759;
let contentCode = '05afedf76886d732573f10f7451a1703';
let gender = req.query.gender || '1,3';
let lifestyleHomePage = '';
if (gender === '3,3') {
lifestyleHomePage = true;
} else {
lifestyleHomePage = false;
}
// let gender = req.query.gender || '3,3';
myCurrencyModel.myCurrency(uid, contentCode).then(result => {
... ... @@ -36,8 +29,7 @@ const myCurrency = (req, res, next) => {
title: '有货币',
pageFooter: true,
yohoCoin: result.yohoCoin,
banner: result.banner,
lifestyleHomePage: lifestyleHomePage
banner: result.banner
});
}).catch(next);
};
... ...
... ... @@ -25,7 +25,6 @@ const bannerData = (contentCode) => {
return serviceAPI.get('operations/api/v5/resource/get', {
content_code: contentCode
}).then((result) => {
// console.log(result)
if (result && result.code === 200) {
... ... @@ -60,16 +59,16 @@ const currencyDetail = (uid, page, limit) => {
if (result && result.code === 200) {
let total = parseInt(result.data.page_total, 10) + 1;
if (page && page < total) {
if (page && page <= total) {
return yohoCoin(uid).then(list => {
if (list.yohocoinNum && list.yohocoinNum === 0) {
if (list.yohocoinNum && list.yohocoinNum !== 0) {
result.data = _.assign(result.data, {
money: false
money: true
});
} else {
result.data = _.assign(result.data, {
money: true
money: false
});
}
... ... @@ -86,25 +85,9 @@ const currencyDetail = (uid, page, limit) => {
});
};
// const mayLike = (uid, page, limit, udid, gender, recPos, channel) => {
// return api.get('', {
// method: 'app.search.newLast7day',
// uid: uid,
// page: page,
// limit: limit,
// udid: udid,
// rec_pos: recPos,
// yh_channel: channel
// }).then((result) => {
// console.log(result);
// });
// };
module.exports = {
myCurrency,
currencyDetail,
bannerData,
yohoCoin
// mayLike
};
... ...
... ... @@ -18,18 +18,16 @@
{{/ yohoCoin}}
</div>
<div class="banner">
{{#banner}}
{{#data}}
{{# banner}}
{{# data}}
<a href="{{url}}">
<img src="{{image src 640 200 2}}" alt="img">
</a>
{{/data}}
{{/banner}}
{{/ data}}
{{/ banner}}
</div>
{{#if lifestyleHomePage}}
{{> home/maybe-like-lifestyle}}
{{else}}
{{> home/maybe-like}}
{{/if}}
{{> home/maybe-like}}
</div>
\ No newline at end of file
... ...
... ... @@ -4,24 +4,55 @@ const mRoot = '../models';
const headerModel = require('../../../doraemon/models/header'); // 头部model
const mayLikeModel = require('../models/recom');
/**
* 你可能喜欢的BOYS或GIRLS的商品列表
*/
const mayLike = (req, res, next) => {
let uid = req.user.uid || 8039759;
let page = req.body.page || 1;
let page = req.query.page || 1;
let limit = 50;
let gender = req.query.gender || '1,3';
let gender = req.query.gender || '2,3';
let udid = req.sessionID || 'yoho';
let recPos = 100009;
let channel = req.query.channel || 1;
mayLikeModel.mayLike(uid, page, limit, gender, udid, recPos, channel).then((result) => {
if (channel === 1 || channel === 2) {
mayLikeModel.mayLike(uid, page, limit, gender, udid, recPos, channel).then((result) => {
console.log(recPos);
// res.render('../common/goods', {
// layout: false
// });
}).catch(next);
res.render('recom/goods', Object.assign({
layout: false
}, result));
}).catch(next);
} else if (channel === 4) {
recPos = 100001;
mayLikeModel.mayLike(uid, page, limit, gender, udid, recPos, channel).then((result) => {
res.render('recom/goods', Object.assign({
layout: false
}, result));
}).catch(next);
}
};
/**
* 你可能喜欢的潮童的商品列表
*/
const mayLikeKids = (req, res, next) => {
let page = req.body.page || 1;
let limit = 50;
let channel = req.query.channel || 3;
mayLikeModel.mayLikeKids(page, limit, channel).then((result) => {
res.render('recom/goods', Object.assign({
layout: false
}, result));
}).catch(next);
};
module.exports = {
mayLike
mayLike,
mayLikeKids
};
... ...
'use strict';
const serviceAPI = global.yoho.ServiceAPI;
const api = global.yoho.API;
const _ = require('lodash');
const camelCase = global.yoho.camelCase;
const logger = global.yoho.logger;
const formatProduct = (list) => {
list = list || [];
list = camelCase(list);
_.forEach(list, function(val) {
let tag = [];
if (val.isSoonSoldOut) {
val.isSoonSoldOut = val.isSoonSoldOut === 'Y';
}
tag.push({
isNew: val.isNew === 'Y',
isDiscount: val.isDiscount === 'Y',
isLimited: val.isLimited === 'Y',
isYohood: val.isYohood === 'Y',
isAdvance: val.isAdvance === 'Y'
});
_.forEach(tag, function(data) {
if (data.isDiscount === true && val.isSoonSoldOut === true) {
data.isNew = true;
data.isDiscount = false;
} else if (data.isDiscount === true && (data.isNew === true || data.isLimited === true || data.isYohood === true || data.isAdvance === true)) {
data.isDiscount = false;
} else if (data.isYohood === true && data.isNew === true) {
data.isNew = false;
}
});
val.tags = tag;
});
return list;
};
const mayLike = (uid, page, limit, gender, udid, recPos, channel) => {
return api.get('', {
method: 'app.search.newLast7day',
... ... @@ -16,10 +55,50 @@ const mayLike = (uid, page, limit, gender, udid, recPos, channel) => {
rec_pos: recPos,
yh_channel: channel
}).then((result) => {
// console.log(result);
if (result && result.code === 200) {
if (page > result.data.page_total) {
return;
}
if (result.data.product_list) {
return formatProduct(result.data.product_list);
}
} else {
logger.error('mayLike cood 不是 200');
}
});
};
const mayLikeKids = (page, limit, channel) => {
return api.get('', {
method: 'app.search.kids',
page: page,
limit: limit,
yh_channel: channel
}).then((result) => {
if (result && result.code === 200) {
if (page > result.data.page_total) {
return;
}
if (result.data.product_list) {
return formatProduct(result.data.product_list);
}
} else {
logger.error('mayLikeKids cood 不是 200');
}
});
};
module.exports = {
mayLike
mayLike,
mayLikeKids
};
... ...
... ... @@ -38,6 +38,8 @@ router.get('/detail/consultform', auth, detail.consultform); // 商å“咨询表å
router.get('/detail/comments', detail.comments);
router.post('/detail/consultsubmit', auth, detail.consultsubmit); // 商品咨询提交接口
router.get('/recom/maylike', recom.mayLike);// 你可能喜欢
router.get('/recom/maylikekids', recom.mayLikeKids); // 潮童你可能喜欢
// router.get('/recom/maylikelife', recom.mayLikeLifestyle); // 创意生活你可能喜欢
router.get('/sale', sale.index);
router.get('/sale/discount', sale.discount);
... ...
{{#if this}} {{!-- 剔除值为false的项 --}}
{{#each this}}
<div class="good-info {{#if @root.saleViplogin}}sale-vip{{/if}}" data-id="{{productSkn}}" data-bp-id="guang_goodList_{{productName}}_false">
<div class="tag-container clearfix">
{{#each tags}}
{{#if isNew}}
<p class="good-tag new-tag">NEW</p>
{{/if}}
{{#if isAdvance}}
<p class="good-tag renew-tag">再到着</p>
{{/if}}
{{#if isDiscount}}
<p class="good-tag sale-tag">SALE</p>
{{/if}}
{{#if isYohoood}}
<p class="good-tag running-man-tag">跑男同款</p>
{{/if}}
{{#if isLimited}}
<p class="good-tag limit-tag">限量商品</p>
{{/if}}
{{/each}}
</div>
<div class="good-detail-img">
<a class="good-thumb" href="{{url}}">
<img class="lazy" data-original="{{image defaultImages 235 314}}">
</a>
{{!-- {{log isSoonSoldOut}} --}}
{{#if isSoonSoldOut}}
<p class="few-tag">即将售罄</p>
{{/if}}
{{#if noStorage}}
<div class="no-storage">
<div class="no-storage-img"></div>
</div>
{{/if}}
</div>
<div class="good-detail-text">
<div class="name">
<a href="{{url}}">{{productName}}</a>
</div>
<div class="price">
{{#if @root.saleViplogin}}
<i class="vip-grade vip-grade-{{@root.vipLevel}}"></i>
<span class="sale-price {{^marketPrice}}no-price{{/marketPrice}}">¥
{{#if @root.vipPrice1}}{{round vip1Price}}{{/if}}
{{#if @root.vipPrice2}}{{round vip2Price}}{{/if}}
{{#if @root.vipPrice3}}{{round vip3Price}}{{/if}}
</span>
{{else}}
<span class="sale-price {{^marketPrice}}no-price{{/marketPrice}}">¥{{round salesPrice}}</span>
{{/if}}
{{#marketPrice}}
<span class="market-price">¥{{round .}}</span>
{{/marketPrice}}
</div>
{{#if @root.saleVip}}
<div class="vip-info">
<i class="vip-icon"></i>更优惠
</div>
{{/if}}
</div>
</div>
{{/each}}
{{/if}}
... ...
<div class="maybe-like">
<ul id="maybe-like-nav" class="maybe-like-nav clearfix">
<li class="maybe-like-nav-item focus">新品到着</li>
<li class="maybe-like-nav-item">人气单品</li>
</ul>
<div id="goods-list">
{{# goodsContainer}}
<div class="goods-list {{^show}}hide{{/show}}">
{{# goods}}
{{> goods}}
{{/ goods}}
</div>
{{/ goodsContainer}}
</div>
<div id="load-more-info" class="load-more-info">
<div class="loading status hide">
正在加载...
</div>
<span class="no-more status hide">没有更多啦</span>
</div>
</div>
\ No newline at end of file
... ...
{{#if this}} {{!-- 剔除值为false的项 --}}
{{#each this}}
<div class="good-info {{#if @root.saleViplogin}}sale-vip{{/if}}" data-id="{{productSkn}}" data-bp-id="guang_goodList_{{productName}}_false">
<div class="tag-container clearfix">
{{# tags}}
... ... @@ -27,11 +28,11 @@
<p class="few-tag">即将售罄</p>
{{/ isSoonSoldOut}}
{{#if noStorage}}
{{# noStorage}}
<div class="no-storage">
<div class="no-storage-img"></div>
</div>
{{/if}}
{{/ noStorage}}
</div>
<div class="good-detail-text">
<div class="name">
... ... @@ -59,4 +60,5 @@
{{/if}}
</div>
</div>
{{/each}}
{{/if}}
... ...
... ... @@ -8,7 +8,7 @@
{{# goodsContainer}}
<div class="goods-list {{^show}}hide{{/show}}">
{{# goods}}
{{> good}}
{{> common/goods}}
{{/ goods}}
</div>
{{/ goodsContainer}}
... ...
... ... @@ -4,6 +4,248 @@
* @date: 2015/10/12
*/
module.exports = function(specificGender) {
var $ = require('yoho-jquery'),
Hammer = require('yoho-hammer'),
ellipsis = require('yoho-mlellipsis'),
tip = require('../plugin/tip'),
loading = require('../plugin/loading'),
lazyLoad = require('yoho-jquery-lazyload');
var navHammer,
winH = $(window).height(),
$goodList = $('#goods-list'),
searching = false,
page = 0,
gender = null,
num,
url,
RECPOSE = '110001';
// The kidsType can be specified by the parameter. Add by @ZhaoBiao
var kidsType = specificGender === 'kids' || $('.mobile-wrap').hasClass('kids-wrap') ? true : false,
lifestyleType = specificGender === 'lifestyle' ||
$('.mobile-wrap').hasClass('lifestyle-wrap') ? true : false,
yohoCoinType = $('.coin').length ? true : false,
logisticType = $('.logistic-page').length ? true : false;
var $curNav,
index,
$navList = $('#maybe-like-nav');
var $footer;
ellipsis.init();
// ajax url
if (kidsType) {
url = '/product/recom/maylikekids';
} else if (lifestyleType) {
// 有货币页面加载男生首页的数据
url = specificGender === 'lifestyle' ? '/product/recom/maylike?gender=1,3&rec_pos=100001' : '/product/recom/maylikelife';
} else if (yohoCoinType) {
gender = (specificGender === 'boys' || $('.mobile-wrap').hasClass('boys-wrap')) ?
'1,3&rec_pos=100009' : '2,3&rec_pos=100009',
url = '/product/recom/maylike?gender=' + gender;
RECPOSE = 110009;
} else if (logisticType) { // 物流页面
gender = (specificGender === 'boys' || $('.mobile-wrap').hasClass('boys-wrap')) ?
'1,3&rec_pos=100006' : '2,3&rec_pos=100006',
url = '/product/recom/maylike?gender=' + gender;
RECPOSE = 110006;
} else {
gender = (specificGender === 'boys' || $('.mobile-wrap').hasClass('boys-wrap')) ?
'1,3&rec_pos=100001' : '2,3&rec_pos=100002',
url = '/product/recom/maylike?gender=' + gender;
}
// 日韩馆-你可能喜欢的
if ($('.mobile-wrap').hasClass('yoho-channel-page')) {
url = '/product/recom/newPreference?template_id=' + $.queryString().template_id;
}
// 首页男生和女生,推荐位ID,埋点
if (window.location.pathname === '/boys') {
RECPOSE = 110001;
} else if (window.location.pathname === '/girls') {
RECPOSE = 110002;
}
$curNav = $navList.children('.focus');
if (lifestyleType) {
navHammer = $navList[0] ? new Hammer($navList[0]) : undefined;
if (navHammer) {
navHammer.on('tap', function(e) {
var $this = $(e.target).closest('li'),
$goods = $('.goods-list'),
$content;
e.preventDefault();
if ($this.hasClass('focus')) {
return;
}
index = $this.index();
$this.addClass('focus');
$curNav.removeClass('focus');
$goods.not('.hide').addClass('hide');
$content = $goods.eq(index);
$content.removeClass('hide');
$curNav = $this;
$(document).trigger('scroll'); // Trigger lazyLoad
e.srcEvent.stopPropagation();
});
}
}
loading.init($('.maybe-like'));
function search() {
if (searching) {
return;
}
searching = true;
loading.showLoadingMask();
// num = $goodList.find('.good-info').length;
$.ajax({
type: 'GET',
url: url,
data: {
page: page + 1
},
success: function(data) {
var PRDID = [];
if (data === ' ') {
searching = false;
loading.hideLoadingMask();
// 有货币页面不加载底部
if (gender && !specificGender) {
if (gender === '1,3') {
url = '/boys/bottomBanner';
} else {
url = '/girls/bottomBanner';
}
$.ajax({
type: 'GET',
url: url,
success: function(data) {
if (data && data.img) {
$('#load-more-img').show();
$('#load-more-img a').attr('href', data.url);
$('#load-more-img a > img').attr('src', data.img);
}
},
error: function() {
}
});
}
return;
}
// 加载到数据后,去除bottom样式,使得footer能够随着页面长度的增加改变位置
if (data.length > 1) {
$footer ? null : $footer = $('#yoho-footer');
$footer.hasClass('bottom') ? $footer.removeClass('bottom') : null;
}
num = $goodList.find('.good-info').length;
$goodList.append(data);
// 2015/10/31 fei.hong: 修复第一页分页不显示图片的问题
if (num === 0) {
lazyLoad($goodList.find('.good-info').find('img.lazy'));
} else {
lazyLoad($goodList.find('.good-info:gt(' + (num - 1) + ')').find('img.lazy'));
}
searching = false;
loading.hideLoadingMask();
page++;
$('.good-detail-text .name').each(function() {
var $this = $(this),
$title = $this.find('a');
$title[0].mlellipsis(2);
});
// 为您优选埋点 start
$(data).closest('.good-info').each(function() {
PRDID.push($(this).data('id'));
});
window.givePoint({
'REC_POSE': RECPOSE,
'PRD_ID': PRDID.join(','),
'PRD_NUM': $(data).closest('.good-info').length,
'ACTION_ID': 0,
'page_num': RECPOSE === 110009 ? 1 : page
});
// 为您优选埋点 end
},
error: function() {
tip.show('网络断开连接了~');
searching = false;
loading.hideLoadingMask();
}
});
}
$('.maybe-like p').on('touchstart', function(e) {
search();
});
function scrollHandler() {
if ($(window).scrollTop() + winH >= $(document).height() - 200) {
search();
}
}
// 优惠券页面直接加载你可能喜欢。add by @zhaobiao
if (specificGender) {
search();
}
// srcoll to load more
$(window).scroll(function() {
window.requestAnimationFrame(scrollHandler);
});
// 为您优选埋点 http://redmine.yoho.cn/issues/10116
$('.maybe-like .goods-list').on('click', 'a', function() {
var index = $(this).closest('.good-info').index() + 1,
pageNum = 50;
window.givePoint({
'REC_POSE': RECPOSE,
'PRD_ID': $(this).closest('.good-info').data('id'),
'PRD_NUM': index % pageNum === 0 ? pageNum : index % pageNum,
'ACTION_ID': 1,
'page_num': Math.ceil(index / pageNum)
});
return true;
});
};
/**
* “你可能喜欢”模块JS
* @author: liangzhifeng<zhifeng.liang@yoho.cn>
* @date: 2015/10/12
*/
// module.exports = function(specificGender) {
// var $ = require('yoho-jquery'),
// Hammer = require('yoho-hammer'),
... ... @@ -245,245 +487,3 @@
// });
// };
/**
* “你可能喜欢”模块JS
* @author: liangzhifeng<zhifeng.liang@yoho.cn>
* @date: 2015/10/12
*/
module.exports = function(specificGender) {
var $ = require('yoho-jquery'),
Hammer = require('yoho-hammer'),
ellipsis = require('yoho-mlellipsis'),
tip = require('../plugin/tip'),
loading = require('../plugin/loading'),
lazyLoad = require('yoho-jquery-lazyload');
var navHammer,
winH = $(window).height(),
$goodList = $('#goods-list'),
searching = false,
page = 0,
gender = null,
num,
url,
RECPOSE = '110001';
// The kidsType can be specified by the parameter. Add by @ZhaoBiao
var kidsType = specificGender === 'kids' || $('.mobile-wrap').hasClass('kids-wrap') ? true : false,
lifestyleType = specificGender === 'lifestyle' ||
$('.mobile-wrap').hasClass('lifestyle-wrap') ? true : false,
yohoCoinType = $('.coin').length ? true : false,
logisticType = $('.logistic-page').length ? true : false;
var $curNav,
index,
$navList = $('#maybe-like-nav');
var $footer;
ellipsis.init();
// ajax url
if (kidsType) {
url = '/product/recom/maylikekids';
} else if (lifestyleType) {
// 有货币页面加载男生首页的数据
url = specificGender === 'lifestyle' ? '/product/recom/maylike?gender=1,3&rec_pos=100001' : '/product/recom/maylikelife';
} else if (yohoCoinType) {
gender = (specificGender === 'boys' || $('.mobile-wrap').hasClass('boys-wrap')) ?
'1,3&rec_pos=100009' : '2,3&rec_pos=100009',
url = '/product/recom/maylike?gender=' + gender;
RECPOSE = 110009;
} else if (logisticType) { // 物流页面
gender = (specificGender === 'boys' || $('.mobile-wrap').hasClass('boys-wrap')) ?
'1,3&rec_pos=100006' : '2,3&rec_pos=100006',
url = '/product/recom/maylike?gender=' + gender;
RECPOSE = 110006;
} else {
gender = (specificGender === 'boys' || $('.mobile-wrap').hasClass('boys-wrap')) ?
'1,3&rec_pos=100001' : '2,3&rec_pos=100002',
url = '/product/recom/maylike?gender=' + gender;
}
// 日韩馆-你可能喜欢的
if ($('.mobile-wrap').hasClass('yoho-channel-page')) {
url = '/product/recom/newPreference?template_id=' + $.queryString().template_id;
}
// 首页男生和女生,推荐位ID,埋点
if (window.location.pathname === '/boys') {
RECPOSE = 110001;
} else if (window.location.pathname === '/girls') {
RECPOSE = 110002;
}
$curNav = $navList.children('.focus');
if (lifestyleType) {
navHammer = $navList[0] ? new Hammer($navList[0]) : undefined;
if (navHammer) {
navHammer.on('tap', function(e) {
var $this = $(e.target).closest('li'),
$goods = $('.goods-list'),
$content;
e.preventDefault();
if ($this.hasClass('focus')) {
return;
}
index = $this.index();
$this.addClass('focus');
$curNav.removeClass('focus');
$goods.not('.hide').addClass('hide');
$content = $goods.eq(index);
$content.removeClass('hide');
$curNav = $this;
$(document).trigger('scroll'); // Trigger lazyLoad
e.srcEvent.stopPropagation();
});
}
}
loading.init($('.maybe-like'));
function search() {
if (searching) {
return;
}
searching = true;
loading.showLoadingMask();
// num = $goodList.find('.good-info').length;
$.ajax({
type: 'GET',
url: url,
data: {
page: page + 1
},
success: function(data) {
var PRDID = [];
if (data === ' ') {
searching = false;
loading.hideLoadingMask();
// 有货币页面不加载底部
if (gender && !specificGender) {
if (gender === '1,3') {
url = '/boys/bottomBanner';
} else {
url = '/girls/bottomBanner';
}
$.ajax({
type: 'GET',
url: url,
success: function(data) {
if (data && data.img) {
$('#load-more-img').show();
$('#load-more-img a').attr('href', data.url);
$('#load-more-img a > img').attr('src', data.img);
}
},
error: function() {
}
});
}
return;
}
// 加载到数据后,去除bottom样式,使得footer能够随着页面长度的增加改变位置
if (data.length > 1) {
$footer ? null : $footer = $('#yoho-footer');
$footer.hasClass('bottom') ? $footer.removeClass('bottom') : null;
}
num = $goodList.find('.good-info').length;
$goodList.append(data);
// 2015/10/31 fei.hong: 修复第一页分页不显示图片的问题
if (num === 0) {
lazyLoad($goodList.find('.good-info').find('img.lazy'));
} else {
lazyLoad($goodList.find('.good-info:gt(' + (num - 1) + ')').find('img.lazy'));
}
searching = false;
loading.hideLoadingMask();
page++;
$('.good-detail-text .name').each(function() {
var $this = $(this),
$title = $this.find('a');
$title[0].mlellipsis(2);
});
// 为您优选埋点 start
$(data).closest('.good-info').each(function() {
PRDID.push($(this).data('id'));
});
window.givePoint({
'REC_POSE': RECPOSE,
'PRD_ID': PRDID.join(','),
'PRD_NUM': $(data).closest('.good-info').length,
'ACTION_ID': 0,
'page_num': RECPOSE === 110009 ? 1 : page
});
// 为您优选埋点 end
},
error: function() {
tip.show('网络断开连接了~');
searching = false;
loading.hideLoadingMask();
}
});
}
$('.maybe-like p').on('touchstart', function(e) {
search();
});
function scrollHandler() {
if ($(window).scrollTop() + winH >= $(document).height() - 200) {
search();
}
}
// 优惠券页面直接加载你可能喜欢。add by @zhaobiao
if (specificGender) {
search();
}
// srcoll to load more
$(window).scroll(function() {
window.requestAnimationFrame(scrollHandler);
});
// 为您优选埋点 http://redmine.yoho.cn/issues/10116
$('.maybe-like .goods-list').on('click', 'a', function() {
var index = $(this).closest('.good-info').index() + 1,
pageNum = 50;
window.givePoint({
'REC_POSE': RECPOSE,
'PRD_ID': $(this).closest('.good-info').data('id'),
'PRD_NUM': index % pageNum === 0 ? pageNum : index % pageNum,
'ACTION_ID': 1,
'page_num': Math.ceil(index / pageNum)
});
return true;
});
};
... ...
/**
* 新有货币界面
*/
var $ = require('yoho-jquery');
var $ = require('yoho-jquery'),
lazyLoad = require('yoho-jquery-lazyload');
require('../common');
lazyLoad($('img.lazy'));
function getGender() {
return window.cookie('_Channel') || 'boys';
}
... ...