Authored by 王水玲

sale

@@ -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 || {};
@@ -132,6 +146,8 @@ const special = (params) => { @@ -132,6 +146,8 @@ const special = (params) => {
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 return api.get('', sign.apiSign({ 207 return api.get('', sign.apiSign({
194 method: 'app.passport.profile', 208 method: 'app.passport.profile',
@@ -197,31 +211,9 @@ const getUserProfile = (uid) => { @@ -197,31 +211,9 @@ const getUserProfile = (uid) => {
197 }; 211 };
198 212
199 /** 213 /**
200 - * 获取商品数据  
201 - */  
202 -exports.getSearchData = (params, uid) => {  
203 - return Promise.all([  
204 - searchSales(params).then((result) => {  
205 - if (result && result.code === 200) {  
206 - return productProcess.processProductList(result.data.product_list || []);  
207 - } else {  
208 - logger.error('SALE 商品搜索返回 code 不是 200');  
209 - return [];  
210 - }  
211 - }),  
212 - getUserProfile(uid).then((result) => {  
213 - if (result && result.code === 200) {  
214 - return camelCase(result.data.vip_info);  
215 - } else {  
216 - logger.error('获取用户信息返回 code 不是 200');  
217 - return {};  
218 - }  
219 - })  
220 - ]);  
221 -};  
222 -  
223 -/**  
224 * 获取资源位数据 214 * 获取资源位数据
  215 + * @param {[string]} page
  216 + * @return {[array]}
225 */ 217 */
226 const getResources = (page) => { 218 const getResources = (page) => {
227 const contentCode = { 219 const contentCode = {
@@ -244,6 +236,8 @@ const getResources = (page) => { @@ -244,6 +236,8 @@ const getResources = (page) => {
244 236
245 /** 237 /**
246 * 获取断码区分类数据 238 * 获取断码区分类数据
  239 + * @param {[string]} yhChannel
  240 + * @return {[object]}
247 */ 241 */
248 const getBreakingSort = (yhChannel) => { 242 const getBreakingSort = (yhChannel) => {
249 return api.get('', sign.apiSign({ 243 return api.get('', sign.apiSign({
@@ -260,7 +254,54 @@ const getBreakingSort = (yhChannel) => { @@ -260,7 +254,54 @@ const getBreakingSort = (yhChannel) => {
260 }; 254 };
261 255
262 /** 256 /**
  257 + * 获取筛选数据
  258 + * @param {[object]} params
  259 + * @return {[array]}
  260 + */
  261 +exports.getFilterData = (params) => {
  262 + return searchSales(params).then((result) => {
  263 + if (result && result.code === 200) {
  264 + return productProcess.processFilter(result.data.filter || [], {
  265 + hideSize: params.saleType === '1',
  266 + hideSort: params.saleType === '1'
  267 + });
  268 + } else {
  269 + logger.error('SALE 商品搜索返回 code 不是 200');
  270 + return [];
  271 + }
  272 + });
  273 +};
  274 +
  275 +/**
  276 + * 获取商品数据
  277 + * @param {[object]} params
  278 + * @param {[string]} uid
  279 + * @return {[array]}
  280 + */
  281 +exports.getSearchData = (params, uid) => {
  282 + return Promise.all([
  283 + searchSales(params).then((result) => {
  284 + if (result && result.code === 200) {
  285 + return productProcess.processProductList(result.data.product_list || []);
  286 + } else {
  287 + logger.error('SALE 商品搜索返回 code 不是 200');
  288 + return [];
  289 + }
  290 + }),
  291 + getUserProfile(uid).then((result) => {
  292 + if (result && result.code === 200) {
  293 + return camelCase(result.data.vip_info);
  294 + } else {
  295 + logger.error('获取用户信息返回 code 不是 200');
  296 + return {};
  297 + }
  298 + })
  299 + ]);
  300 +};
  301 +
  302 +/**
263 * 获取sale首页数据 303 * 获取sale首页数据
  304 + * @return {[array]}
264 */ 305 */
265 exports.getSaleData = () => { 306 exports.getSaleData = () => {
266 return getResources('sale'); 307 return getResources('sale');
@@ -268,8 +309,7 @@ exports.getSaleData = () => { @@ -268,8 +309,7 @@ exports.getSaleData = () => {
268 309
269 /** 310 /**
270 * 获取会员享数据 311 * 获取会员享数据
271 - * @param {[object]} params  
272 - * @return {[object]} 312 + * @return {[array]}
273 */ 313 */
274 exports.getVipData = () => { 314 exports.getVipData = () => {
275 return getResources('vip'); 315 return getResources('vip');
@@ -312,7 +352,7 @@ exports.getSpecialData = (params) => { @@ -312,7 +352,7 @@ exports.getSpecialData = (params) => {
312 352
313 /** 353 /**
314 * 获取折扣专场专题详情数据 354 * 获取折扣专场专题详情数据
315 - * @param {[object]} params 355 + * @param {[string]} id
316 * @return {[object]} 356 * @return {[object]}
317 */ 357 */
318 exports.getSpecialDetailData = (id) => { 358 exports.getSpecialDetailData = (id) => {
@@ -324,6 +364,7 @@ exports.getSpecialDetailData = (id) => { @@ -324,6 +364,7 @@ exports.getSpecialDetailData = (id) => {
324 return special(param).then((result) => { 364 return special(param).then((result) => {
325 if (result && result.code === 200) { 365 if (result && result.code === 200) {
326 res = processSpecial(result.data); 366 res = processSpecial(result.data);
  367 + console.log(res)
327 return { 368 return {
328 title: res[0].title, 369 title: res[0].title,
329 activity: { 370 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: '所有性别',