Authored by ccbikai

Merge branch 'feature/sale' into develop

@@ -13,14 +13,14 @@ const headerModel = require('../../../doraemon/models/header'); @@ -13,14 +13,14 @@ const headerModel = require('../../../doraemon/models/header');
13 const log = require(`${library}/logger`); 13 const log = require(`${library}/logger`);
14 const saleModel = require(`${mRoot}/sale`); 14 const saleModel = require(`${mRoot}/sale`);
15 15
16 -// const queryParam = {  
17 -// brand: '0',  
18 -// gender: '1,2,3',  
19 -// sort: '0',  
20 -// size: '0',  
21 -// price: '0',  
22 -// discount: '0.1,0.9'  
23 -// }; 16 +const queryParam = {
  17 + brand: '0',
  18 + gender: '1,2,3',
  19 + sort: '0',
  20 + size: '0',
  21 + price: '0',
  22 + pD: '0.1,0.9'
  23 +};
24 24
25 const saleLogger = (err, res) => { 25 const saleLogger = (err, res) => {
26 log.error('sale页面渲染错误:' + JSON.stringify(err)); 26 log.error('sale页面渲染错误:' + JSON.stringify(err));
@@ -28,7 +28,10 @@ const saleLogger = (err, res) => { @@ -28,7 +28,10 @@ const saleLogger = (err, res) => {
28 }; 28 };
29 29
30 /** 30 /**
31 - * sale 首页 31 + * sale 首页 资源位获取
  32 + * @param {[object]} req
  33 + * @param {[object]} res
  34 + * @return {[type]}
32 */ 35 */
33 exports.index = (req, res) => { 36 exports.index = (req, res) => {
34 let headerData = headerModel.setNavHeader('SALE'); 37 let headerData = headerModel.setNavHeader('SALE');
@@ -41,7 +44,7 @@ exports.index = (req, res) => { @@ -41,7 +44,7 @@ exports.index = (req, res) => {
41 }; 44 };
42 45
43 saleModel.getSaleData().then((result) => { 46 saleModel.getSaleData().then((result) => {
44 - res.render('sale', Object.assign(renderData, { 47 + res.render('sale', Object.assign(renderData, queryParam, {
45 content: result, 48 content: result,
46 floorHeader: { 49 floorHeader: {
47 title: { 50 title: {
@@ -56,6 +59,9 @@ exports.index = (req, res) => { @@ -56,6 +59,9 @@ exports.index = (req, res) => {
56 59
57 /** 60 /**
58 * 断码区 61 * 断码区
  62 + * @param {[object]} req
  63 + * @param {[object]} res
  64 + * @return {[type]}
59 */ 65 */
60 exports.breakCode = (req, res) => { 66 exports.breakCode = (req, res) => {
61 let headerData = headerModel.setNavHeader('断码区'); 67 let headerData = headerModel.setNavHeader('断码区');
@@ -66,7 +72,9 @@ exports.breakCode = (req, res) => { @@ -66,7 +72,9 @@ exports.breakCode = (req, res) => {
66 pageFooter: true 72 pageFooter: true
67 }; 73 };
68 74
69 - saleModel.getBreakCodeData().then((result) => { 75 + saleModel.getBreakCodeData({
  76 + yhChannel: req.query.channel
  77 + }).then((result) => {
70 res.render('break-code', Object.assign(renderData, result)); 78 res.render('break-code', Object.assign(renderData, result));
71 }).catch((err) => { 79 }).catch((err) => {
72 saleLogger(err, res); 80 saleLogger(err, res);
@@ -75,6 +83,9 @@ exports.breakCode = (req, res) => { @@ -75,6 +83,9 @@ exports.breakCode = (req, res) => {
75 83
76 /** 84 /**
77 * 折扣专场列表 85 * 折扣专场列表
  86 + * @param {[object]} req
  87 + * @param {[object]} res
  88 + * @return {[type]}
78 */ 89 */
79 exports.special = (req, res) => { 90 exports.special = (req, res) => {
80 let headerData = headerModel.setNavHeader('折扣专场'); 91 let headerData = headerModel.setNavHeader('折扣专场');
@@ -95,6 +106,9 @@ exports.special = (req, res) => { @@ -95,6 +106,9 @@ exports.special = (req, res) => {
95 106
96 /** 107 /**
97 * 折扣专场专题详情 108 * 折扣专场专题详情
  109 + * @param {[object]} req
  110 + * @param {[object]} res
  111 + * @return {[type]}
98 */ 112 */
99 exports.specialDetail = (req, res) => { 113 exports.specialDetail = (req, res) => {
100 let headerData = headerModel.setNavHeader(); 114 let headerData = headerModel.setNavHeader();
@@ -115,7 +129,10 @@ exports.specialDetail = (req, res) => { @@ -115,7 +129,10 @@ exports.specialDetail = (req, res) => {
115 }; 129 };
116 130
117 /** 131 /**
118 - * vip 132 + * vip 会员专享
  133 + * @param {[object]} req
  134 + * @param {[object]} res
  135 + * @return {[type]}
119 */ 136 */
120 exports.vip = (req, res) => { 137 exports.vip = (req, res) => {
121 let headerData = headerModel.setNavHeader('会员专享'); 138 let headerData = headerModel.setNavHeader('会员专享');
@@ -135,6 +152,12 @@ exports.vip = (req, res) => { @@ -135,6 +152,12 @@ exports.vip = (req, res) => {
135 }); 152 });
136 }; 153 };
137 154
  155 +/**
  156 + * 筛选
  157 + * @param {[object]} req
  158 + * @param {[object]} res
  159 + * @return {[type]}
  160 + */
138 exports.filter = (req, res) => { 161 exports.filter = (req, res) => {
139 let params = Object.assign({}, req.query); 162 let params = Object.assign({}, req.query);
140 163
@@ -147,18 +170,36 @@ exports.filter = (req, res) => { @@ -147,18 +170,36 @@ exports.filter = (req, res) => {
147 }); 170 });
148 }; 171 };
149 172
  173 +
  174 +/**
  175 + * 商品搜索
  176 + * @param {[object]} req
  177 + * @param {[object]} res
  178 + * @return {[type]}
  179 + */
150 exports.search = (req, res) => { 180 exports.search = (req, res) => {
151 let params = Object.assign({}, req.query); 181 let params = Object.assign({}, req.query);
152 - let uid = req.user.uid || 0; 182 + let uid = 9239279 || req.user.uid || 0;
153 183
154 saleModel.getSearchData(params, uid).then((result) => { 184 saleModel.getSearchData(params, uid).then((result) => {
155 let vipLevel = result[1].curLevel; 185 let vipLevel = result[1].curLevel;
156 -  
157 - res.render('product', { 186 + let vipObj = {};
  187 +
  188 + if (req.query.saleType === '2') {
  189 + vipObj = Object.assign({
  190 + saleVip: (req.query.saleType === '2' && (!uid || vipLevel === '1')),
  191 + vipLevel: vipLevel,
  192 + saleViplogin: vipLevel >= 1 ? true : false,
  193 + vipPrice1: vipLevel === '1',
  194 + vipPrice2: vipLevel === '2',
  195 + vipPrice3: vipLevel === '3'
  196 + }, vipObj);
  197 + }
  198 +
  199 + res.render('product', Object.assign({
158 layout: false, 200 layout: false,
159 params: params, 201 params: params,
160 - goods: result[0],  
161 - saleVip: (req.query.saleType === '2' && (!uid || vipLevel === '1'))  
162 - }); 202 + goods: result[0]
  203 + }, vipObj));
163 }); 204 });
164 }; 205 };
@@ -21,6 +21,9 @@ const aMinute = 60000; @@ -21,6 +21,9 @@ const aMinute = 60000;
21 const anHour = 3600000; 21 const anHour = 3600000;
22 const aDay = anHour * 24; 22 const aDay = anHour * 24;
23 23
  24 +/**
  25 + * 需要格式化的时间格式
  26 + */
24 const timeFormat = { 27 const timeFormat = {
25 d: '剩{d}天', 28 d: '剩{d}天',
26 h: '剩{h}小时', 29 h: '剩{h}小时',
@@ -32,6 +35,9 @@ const timeFormat = { @@ -32,6 +35,9 @@ const timeFormat = {
32 ms: '剩{m}分钟{s}秒' 35 ms: '剩{m}分钟{s}秒'
33 }; 36 };
34 37
  38 +/**
  39 + * 排序转换
  40 + */
35 const typeCont = { 41 const typeCont = {
36 price: ['s_p_desc', 's_p_asc'], 42 price: ['s_p_desc', 's_p_asc'],
37 discount: ['p_d_desc', 'p_d_asc'], 43 discount: ['p_d_desc', 'p_d_asc'],
@@ -42,6 +48,8 @@ const typeCont = { @@ -42,6 +48,8 @@ const typeCont = {
42 48
43 /** 49 /**
44 * 折扣专场专题列表过期时间处理 50 * 折扣专场专题列表过期时间处理
  51 + * @param {[string]} time
  52 + * @return {[object]}
45 */ 53 */
46 const processTime = (time) => { 54 const processTime = (time) => {
47 let data = {}; 55 let data = {};
@@ -65,6 +73,8 @@ const processTime = (time) => { @@ -65,6 +73,8 @@ const processTime = (time) => {
65 73
66 /** 74 /**
67 * 折扣专场专题详情过期时间处理 75 * 折扣专场专题详情过期时间处理
  76 + * @param {[string]} time
  77 + * @return {[boject]}
68 */ 78 */
69 const processTimes = (time) => { 79 const processTimes = (time) => {
70 let data = {}; 80 let data = {};
@@ -91,6 +101,8 @@ const processTimes = (time) => { @@ -91,6 +101,8 @@ const processTimes = (time) => {
91 101
92 /** 102 /**
93 * 折扣专场列表数据处理 103 * 折扣专场列表数据处理
  104 + * @param {[array]} list
  105 + * @return {[array]}
94 */ 106 */
95 const processSpecial = (list) => { 107 const processSpecial = (list) => {
96 const formatData = []; 108 const formatData = [];
@@ -119,6 +131,8 @@ const processSpecial = (list) => { @@ -119,6 +131,8 @@ const processSpecial = (list) => {
119 131
120 /** 132 /**
121 * 折扣专场接口调用 133 * 折扣专场接口调用
  134 + * @param {[object]} params
  135 + * @return {[array]}
122 */ 136 */
123 const special = (params) => { 137 const special = (params) => {
124 params = params || {}; 138 params = params || {};
@@ -126,12 +140,14 @@ const special = (params) => { @@ -126,12 +140,14 @@ const special = (params) => {
126 return api.get('', sign.apiSign(Object.assign({ 140 return api.get('', sign.apiSign(Object.assign({
127 method: 'app.activity.get', 141 method: 'app.activity.get',
128 sort: 2, 142 sort: 2,
129 - plateform: 2 143 + plateform: 3
130 }, params))); 144 }, params)));
131 }; 145 };
132 146
133 /** 147 /**
134 * 断码区分类数据处理 148 * 断码区分类数据处理
  149 + * @param {[array]} list
  150 + * @return {[array]}
135 */ 151 */
136 const processBreakingSort = (list) => { 152 const processBreakingSort = (list) => {
137 const formatData = {}; 153 const formatData = {};
@@ -157,8 +173,18 @@ const processBreakingSort = (list) => { @@ -157,8 +173,18 @@ const processBreakingSort = (list) => {
157 173
158 /** 174 /**
159 * 商品搜索接口请求 175 * 商品搜索接口请求
  176 + * @param {[object]} params
  177 + * @return {[array]}
160 */ 178 */
161 const searchSales = (params) => { 179 const searchSales = (params) => {
  180 +
  181 + // 排除基本筛选项默认值为0的对象
  182 + for (let str in params) {
  183 + if (str !== 'order' && params[str] === '0' || params[str] === null) {
  184 + delete params[str];
  185 + }
  186 + }
  187 +
162 params = Object.assign({ 188 params = Object.assign({
163 limit: '50' 189 limit: '50'
164 }, params); 190 }, params);
@@ -173,22 +199,10 @@ const searchSales = (params) => { @@ -173,22 +199,10 @@ const searchSales = (params) => {
173 }; 199 };
174 200
175 /** 201 /**
176 - * 获取筛选数据 202 + * 获取用户数据信息
  203 + * @param {[string]} uid
  204 + * @return {[array]}
177 */ 205 */
178 -exports.getFilterData = (params) => {  
179 - return searchSales(params).then((result) => {  
180 - if (result && result.code === 200) {  
181 - return productProcess.processFilter(result.data.filter || [], {  
182 - hideSize: params.saleType === '1',  
183 - hideSort: params.saleType === '1'  
184 - });  
185 - } else {  
186 - logger.error('SALE 商品搜索返回 code 不是 200');  
187 - return [];  
188 - }  
189 - });  
190 -};  
191 -  
192 const getUserProfile = (uid) => { 206 const getUserProfile = (uid) => {
193 if (!uid) { 207 if (!uid) {
194 return Promise.resolve({ 208 return Promise.resolve({
@@ -228,6 +242,8 @@ exports.getSearchData = (params, uid) => { @@ -228,6 +242,8 @@ exports.getSearchData = (params, uid) => {
228 242
229 /** 243 /**
230 * 获取资源位数据 244 * 获取资源位数据
  245 + * @param {[string]} page
  246 + * @return {[array]}
231 */ 247 */
232 const getResources = (page) => { 248 const getResources = (page) => {
233 const contentCode = { 249 const contentCode = {
@@ -250,6 +266,8 @@ const getResources = (page) => { @@ -250,6 +266,8 @@ const getResources = (page) => {
250 266
251 /** 267 /**
252 * 获取断码区分类数据 268 * 获取断码区分类数据
  269 + * @param {[string]} yhChannel
  270 + * @return {[object]}
253 */ 271 */
254 const getBreakingSort = (yhChannel) => { 272 const getBreakingSort = (yhChannel) => {
255 return api.get('', sign.apiSign({ 273 return api.get('', sign.apiSign({
@@ -266,7 +284,54 @@ const getBreakingSort = (yhChannel) => { @@ -266,7 +284,54 @@ const getBreakingSort = (yhChannel) => {
266 }; 284 };
267 285
268 /** 286 /**
  287 + * 获取筛选数据
  288 + * @param {[object]} params
  289 + * @return {[array]}
  290 + */
  291 +exports.getFilterData = (params) => {
  292 + return searchSales(params).then((result) => {
  293 + if (result && result.code === 200) {
  294 + return productProcess.processFilter(result.data.filter || [], {
  295 + hideSize: params.saleType === '1',
  296 + hideSort: params.saleType === '1'
  297 + });
  298 + } else {
  299 + logger.error('SALE 商品搜索返回 code 不是 200');
  300 + return [];
  301 + }
  302 + });
  303 +};
  304 +
  305 +/**
  306 + * 获取商品数据
  307 + * @param {[object]} params
  308 + * @param {[string]} uid
  309 + * @return {[array]}
  310 + */
  311 +exports.getSearchData = (params, uid) => {
  312 + return Promise.all([
  313 + searchSales(params).then((result) => {
  314 + if (result && result.code === 200) {
  315 + return productProcess.processProductList(result.data.product_list || []);
  316 + } else {
  317 + logger.error('SALE 商品搜索返回 code 不是 200');
  318 + return [];
  319 + }
  320 + }),
  321 + getUserProfile(uid).then((result) => {
  322 + if (result && result.code === 200) {
  323 + return camelCase(result.data.vip_info);
  324 + } else {
  325 + logger.error('获取用户信息返回 code 不是 200');
  326 + return {};
  327 + }
  328 + })
  329 + ]);
  330 +};
  331 +
  332 +/**
269 * 获取sale首页数据 333 * 获取sale首页数据
  334 + * @return {[array]}
270 */ 335 */
271 exports.getSaleData = () => { 336 exports.getSaleData = () => {
272 return getResources('sale'); 337 return getResources('sale');
@@ -274,8 +339,7 @@ exports.getSaleData = () => { @@ -274,8 +339,7 @@ exports.getSaleData = () => {
274 339
275 /** 340 /**
276 * 获取会员享数据 341 * 获取会员享数据
277 - * @param {[object]} params  
278 - * @return {[object]} 342 + * @return {[array]}
279 */ 343 */
280 exports.getVipData = () => { 344 exports.getVipData = () => {
281 return getResources('vip'); 345 return getResources('vip');
@@ -318,7 +382,7 @@ exports.getSpecialData = (params) => { @@ -318,7 +382,7 @@ exports.getSpecialData = (params) => {
318 382
319 /** 383 /**
320 * 获取折扣专场专题详情数据 384 * 获取折扣专场专题详情数据
321 - * @param {[object]} params 385 + * @param {[string]} id
322 * @return {[object]} 386 * @return {[object]}
323 */ 387 */
324 exports.getSpecialDetailData = (id) => { 388 exports.getSpecialDetailData = (id) => {
@@ -330,6 +394,7 @@ exports.getSpecialDetailData = (id) => { @@ -330,6 +394,7 @@ exports.getSpecialDetailData = (id) => {
330 return special(param).then((result) => { 394 return special(param).then((result) => {
331 if (result && result.code === 200) { 395 if (result && result.code === 200) {
332 res = processSpecial(result.data); 396 res = processSpecial(result.data);
  397 + console.log(res);
333 return { 398 return {
334 title: res[0].title, 399 title: res[0].title,
335 activity: { 400 activity: {
1 {{#if this}} {{!-- 剔除值为false的项 --}} 1 {{#if this}} {{!-- 剔除值为false的项 --}}
2 - <div class="good-info" data-id="{{productSkn}}" data-bp-id="guang_goodList_{{productName}}_false"> 2 + <div class="good-info {{#if @root.saleViplogin}}sale-vip{{/if}}" data-id="{{productSkn}}" data-bp-id="guang_goodList_{{productName}}_false">
3 <div class="tag-container clearfix"> 3 <div class="tag-container clearfix">
4 {{# tags}} 4 {{# tags}}
5 {{# isNew}} 5 {{# isNew}}
@@ -32,10 +32,16 @@ @@ -32,10 +32,16 @@
32 <a href="{{url}}">{{productName}}</a> 32 <a href="{{url}}">{{productName}}</a>
33 </div> 33 </div>
34 <div class="price"> 34 <div class="price">
35 - {{#if saleViplogin}}  
36 - <i class="vip-grade-{{vipGrade}}"></i> 35 + {{#if @root.saleViplogin}}
  36 + <i class="vip-grade vip-grade-{{@root.vipLevel}}"></i>
  37 + <span class="sale-price {{^marketPrice}}no-price{{/marketPrice}}">¥
  38 + {{#if @root.vipPrice1}}{{vip1Price}}{{/if}}
  39 + {{#if @root.vipPrice2}}{{vip2Price}}{{/if}}
  40 + {{#if @root.vipPrice3}}{{vip3Price}}{{/if}}
  41 + </span>
  42 + {{else}}
  43 + <span class="sale-price {{^marketPrice}}no-price{{/marketPrice}}">¥{{salesPrice}}</span>
37 {{/if}} 44 {{/if}}
38 - <span class="sale-price {{^marketPrice}}no-price{{/marketPrice}}">¥{{salesPrice}}</span>  
39 {{#marketPrice}} 45 {{#marketPrice}}
40 <span class="market-price">¥{{.}}</span> 46 <span class="market-price">¥{{.}}</span>
41 {{/marketPrice}} 47 {{/marketPrice}}
@@ -177,6 +177,11 @@ function search(opt) { @@ -177,6 +177,11 @@ function search(opt) {
177 discount: opt[i].id 177 discount: opt[i].id
178 }; 178 };
179 break; 179 break;
  180 + case 'p_d':
  181 + ext = {
  182 + p_d: opt[i].id
  183 + };
  184 + break;
180 default: 185 default:
181 break; 186 break;
182 } 187 }
@@ -69,6 +69,25 @@ ellipsis.init(); @@ -69,6 +69,25 @@ ellipsis.init();
69 lazyLoad($('img.lazy')); 69 lazyLoad($('img.lazy'));
70 70
71 71
  72 +// 获取url里面的参数的值
  73 +function getUrlParam(name) {
  74 + // 构造一个含有目标参数的正则表达式对象
  75 + var reg = new RegExp('(^|&)' + name + '=([^&]*)(&|$)');
  76 +
  77 + // 匹配目标参数
  78 + var r = window.location.search.substr(1).match(reg);
  79 +
  80 + if (r !== null) {
  81 + return r[2];
  82 + }
  83 + return null; // 返回参数值
  84 +}
  85 +
  86 +// 获取频道
  87 +$.extend(defaultOpt, {
  88 + yhChannel: getUrlParam('channel')
  89 +});
  90 +
72 // 判断导航类型 91 // 判断导航类型
73 function judgeType(dom) { 92 function judgeType(dom) {
74 var navType; 93 var navType;
@@ -153,6 +172,11 @@ function search(opt) { @@ -153,6 +172,11 @@ function search(opt) {
153 discount: opt.id 172 discount: opt.id
154 }; 173 };
155 break; 174 break;
  175 + case 'p_d':
  176 + ext = {
  177 + p_d: opt.id
  178 + };
  179 + break;
156 default: 180 default:
157 break; 181 break;
158 } 182 }
@@ -132,17 +132,17 @@ @@ -132,17 +132,17 @@
132 vertical-align: text-bottom; 132 vertical-align: text-bottom;
133 } 133 }
134 134
135 - .vip-grade-golden { 135 + .vip-grade-3 {
136 background: resolve('product/golden.png') no-repeat; 136 background: resolve('product/golden.png') no-repeat;
137 background-size: contain; 137 background-size: contain;
138 } 138 }
139 139
140 - .vip-grade-platinum { 140 + .vip-grade-2 {
141 background: resolve('product/platinum.png') no-repeat; 141 background: resolve('product/platinum.png') no-repeat;
142 background-size: contain; 142 background-size: contain;
143 } 143 }
144 144
145 - .vip-grade-silver { 145 + .vip-grade-1 {
146 background: resolve('product/silver.png') no-repeat; 146 background: resolve('product/silver.png') no-repeat;
147 background-size: contain; 147 background-size: contain;
148 } 148 }
@@ -36,4 +36,12 @@ @@ -36,4 +36,12 @@
36 .good-info { 36 .good-info {
37 height: 570px; 37 height: 570px;
38 } 38 }
  39 +
  40 + .sale-vip {
  41 + height: 506px;
  42 + }
  43 +
  44 + .good-detail-text .price {
  45 + white-space: nowrap;
  46 + }
39 } 47 }
@@ -73,8 +73,20 @@ exports.processProductList = (list, options) => { @@ -73,8 +73,20 @@ exports.processProductList = (list, options) => {
73 // }); 73 // });
74 74
75 if (options.showPoint) { 75 if (options.showPoint) {
76 - product.price += '.00';  
77 - product.salePrice += '.00'; 76 + product.marketPrice += '.00';
  77 + product.salesPrice += '.00';
  78 +
  79 + if (product.vip1Price) {
  80 + product.vip1Price = parseInt(product.vip1Price) + '.00';
  81 + }
  82 +
  83 + if (product.vip2Price) {
  84 + product.vip2Price = parseInt(product.vip2Price) + '.00';
  85 + }
  86 +
  87 + if (product.vip3Price) {
  88 + product.vip3Price = parseInt(product.vip3Price) + '.00';
  89 + }
78 } 90 }
79 91
80 product.isSoonSoldOut = product.isSoonSoldOut === 'Y'; 92 product.isSoonSoldOut = product.isSoonSoldOut === 'Y';
@@ -150,7 +162,7 @@ exports.processFilter = (list, options) => { @@ -150,7 +162,7 @@ exports.processFilter = (list, options) => {
150 dataId: 'key', 162 dataId: 'key',
151 subsName: 'name', 163 subsName: 'name',
152 firstSub: '0.1,0.9', 164 firstSub: '0.1,0.9',
153 - dataType: 'discount' 165 + dataType: 'p_d'
154 }, 166 },
155 gender: { 167 gender: {
156 name: '所有性别', 168 name: '所有性别',