Showing
1 changed file
with
1 additions
and
149 deletions
@@ -5,7 +5,6 @@ | @@ -5,7 +5,6 @@ | ||
5 | 'use strict'; | 5 | 'use strict'; |
6 | const _ = require('lodash'); | 6 | const _ = require('lodash'); |
7 | const helpers = global.yoho.helpers; | 7 | const helpers = global.yoho.helpers; |
8 | -const productNameProcess = require('./product-name-process'); | ||
9 | const productPrcs = require('./product-process'); | 8 | const productPrcs = require('./product-process'); |
10 | 9 | ||
11 | /** | 10 | /** |
@@ -205,154 +204,8 @@ const getProductIcon = (type) => { | @@ -205,154 +204,8 @@ const getProductIcon = (type) => { | ||
205 | }; | 204 | }; |
206 | 205 | ||
207 | /** | 206 | /** |
208 | - * [根据性别获取] | ||
209 | - * @param {[type]} gender [description] | ||
210 | - * @return {[type]} [description] | 207 | + * 逛详情页数据处理 |
211 | */ | 208 | */ |
212 | -const _getGenderByCookie = (gender) => { | ||
213 | - switch (gender) { | ||
214 | - case 1: // 男 | ||
215 | - return '1,3'; | ||
216 | - case 2: // 女 | ||
217 | - return '2,3'; | ||
218 | - default: // 其它 | ||
219 | - return '1,2,3'; | ||
220 | - } | ||
221 | -}; | ||
222 | - | ||
223 | -/** | ||
224 | - * [根据性别来决定 默认图片获取字段 如果是 2、3] | ||
225 | - * | ||
226 | - * 则优先从cover2 --》 cover1 -- 》 images_url | ||
227 | - * 否则优先从cover1 --》 cover2 -- 》 images_url | ||
228 | - * | ||
229 | - * @param {[array]} images [images] | ||
230 | - * @param {[Boolean]} gender [性别] | ||
231 | - * @return {[type]} | ||
232 | - */ | ||
233 | -const _procProductImg = (images, gender) => { | ||
234 | - let imgUrl = images.images_url || ''; | ||
235 | - let cover1 = images.cover_1 || ''; | ||
236 | - let cover2 = images.cover_2 || ''; | ||
237 | - | ||
238 | - gender = _getGenderByCookie(gender); | ||
239 | - if (gender === '2,3') { | ||
240 | - return cover2 || (cover1 || imgUrl); | ||
241 | - } else { | ||
242 | - return cover1 || (cover2 || imgUrl); | ||
243 | - } | ||
244 | -}; | ||
245 | - | ||
246 | -/** | ||
247 | - * 格式化商品信息 | ||
248 | - * | ||
249 | - * @param array productData 需要格式化的商品数据 | ||
250 | - * @param bool showTags 控制是否显示标签 | ||
251 | - * @param bool showNew 控制是否显示NEW图标 | ||
252 | - * @param bool showSale 控制是否显示SALE图标 | ||
253 | - * @param int width 图片的宽度 | ||
254 | - * @param int height 图片的高度 | ||
255 | - * @param bool isApp 判断是不是APP访问 | ||
256 | - * @param bool showPoint 商品价格是否显示小数位,默认显示 | ||
257 | - * @param int gender 性别 | ||
258 | - * @return array | false | ||
259 | - */ | ||
260 | -const formatProduct = (productData, showTags, showNew, showSale, width, height, isApp, showPoint, gender) => { | ||
261 | - // 商品信息有问题,则不显示 | ||
262 | - if (!productData.product_skn || !productData.goods_list[0]) { | ||
263 | - return false; | ||
264 | - } | ||
265 | - productData.sales_price = productData.sales_price || ''; | ||
266 | - productData.market_price = productData.market_price || ''; | ||
267 | - | ||
268 | - // 市场价和售价一样,则不显示市场价 | ||
269 | - if (parseInt(productData.market_price, 10) === parseInt(productData.sales_price, 10)) { | ||
270 | - productData.market_price = false; | ||
271 | - } | ||
272 | - | ||
273 | - // 判别默认的商品是否将默认的图片URL赋值到skn | ||
274 | - let flag = false; | ||
275 | - | ||
276 | - // 如果设置了默认图片,就取默认的图片 | ||
277 | - for (let oneGoods of productData.goods_list) { | ||
278 | - // 此skc是默认的,则将图片赋值给skn | ||
279 | - if (oneGoods.is_default === 'Y') { | ||
280 | - productData.default_images = _procProductImg(oneGoods, gender); | ||
281 | - flag = true; | ||
282 | - break; | ||
283 | - } | ||
284 | - } | ||
285 | - | ||
286 | - // 如果还未赋值,则取第一个skc产品的默认图片 | ||
287 | - if (!flag) { | ||
288 | - productData.default_images = _procProductImg(productData.goods_list[0], gender); | ||
289 | - } | ||
290 | - | ||
291 | - let result = { | ||
292 | - id: productData.product_skn, | ||
293 | - product_id: productData.product_id, | ||
294 | - thumb: helpers.image(productData.default_images, width, height), | ||
295 | - name: productData.product_name, | ||
296 | - price: productData.market_price || false, | ||
297 | - salePrice: productData.sales_price | ||
298 | - }; | ||
299 | - | ||
300 | - if (showPoint) { | ||
301 | - if (result.price) { | ||
302 | - result.price += '.00'; | ||
303 | - } | ||
304 | - if (result.salePrice) { | ||
305 | - result.salePrice += '.00'; | ||
306 | - } | ||
307 | - } | ||
308 | - | ||
309 | - // TODO student price | ||
310 | - result.studentPrice = parseInt(productData.sales_price * 100 * 0.9, 10) / 100; | ||
311 | - result.is_soon_sold_out = (productData.is_soon_sold_out === 'Y'); | ||
312 | - | ||
313 | - if (productData.cn_alphabet) { | ||
314 | - productData.cn_alphabet = productNameProcess(productData.cn_alphabet); | ||
315 | - } | ||
316 | - | ||
317 | - let url = encodeURI(helpers.urlFormat(`/product/${productData.product_skn}.html`));// 商品url改版 | ||
318 | - | ||
319 | - result.url = url.replace('http://', '//'); | ||
320 | - | ||
321 | - // APP访问需要加附加的参数 | ||
322 | - // 备注:如果以后APP的接口太多,可以把这边参数提取出来,变成一个公共的方法来生成,便于以后管理维护 | ||
323 | - if (isApp) { | ||
324 | - result.url += `?openby:yohobuy={"action":"go.productDetail","params":{"product_skn":${productData.product_skn}}}`; //eslint-disable-line | ||
325 | - } | ||
326 | - if (showTags) { | ||
327 | - result.tags = { | ||
328 | - is_new: showNew && productData.is_new === 'Y', // 新品 | ||
329 | - is_discount: showSale && productData.is_discount === 'Y', // 在售 | ||
330 | - is_limited: productData.is_limited && productData.is_limited === 'Y', // 限量 | ||
331 | - is_yohood: productData.is_yohood && productData.is_yohood === 'Y', // YOHOOD | ||
332 | - midYear: productData.midear && productData.midear === 'Y', // 年中 | ||
333 | - yearEnd: productData.yearnd && productData.yearnd === 'Y', // 年末 | ||
334 | - is_advance: productData.is_advance && productData.is_advance === 'Y' // 再到着 | ||
335 | - }; | ||
336 | - | ||
337 | - // 打折与即将售完组合显示打折 | ||
338 | - if (result.is_soon_sold_out && result.tags.is_discount) { | ||
339 | - result.tags.is_new = false; | ||
340 | - } else if (result.tags.is_discount && | ||
341 | - (result.tags.is_new || | ||
342 | - result.tags.is_limited || | ||
343 | - result.tags.is_yohood || | ||
344 | - result.tags.is_advance) // 打折与其它组合则隐藏打折 | ||
345 | - ) { | ||
346 | - result.tags.is_discount = false; | ||
347 | - } else if (result.tags.is_yohood && result.tags.is_new) { // YOHOOD和新品组合显示YOHOOD | ||
348 | - result.tags.is_new = false; | ||
349 | - } | ||
350 | - } | ||
351 | - | ||
352 | - return result; | ||
353 | -}; | ||
354 | - | ||
355 | - | ||
356 | const processArticleDetail = (articleContent, isApp, gender, isWeixin, isqq, isWeibo) => { | 209 | const processArticleDetail = (articleContent, isApp, gender, isWeixin, isqq, isWeibo) => { |
357 | let finalDetail = []; | 210 | let finalDetail = []; |
358 | let allgoods = ''; | 211 | let allgoods = ''; |
@@ -515,7 +368,6 @@ module.exports = { | @@ -515,7 +368,6 @@ module.exports = { | ||
515 | formatArticle, | 368 | formatArticle, |
516 | transHttpsUrl, | 369 | transHttpsUrl, |
517 | getFilterUrl, | 370 | getFilterUrl, |
518 | - formatProduct, | ||
519 | getProductIcon, | 371 | getProductIcon, |
520 | processArticleDetail, | 372 | processArticleDetail, |
521 | pushGoodsInfo | 373 | pushGoodsInfo |
-
Please register or login to post a comment