|
@@ -3,396 +3,9 @@ |
|
@@ -3,396 +3,9 @@ |
3
|
*/
|
3
|
*/
|
4
|
'use strict';
|
4
|
'use strict';
|
5
|
const _ = require('lodash');
|
5
|
const _ = require('lodash');
|
6
|
-const commentModel = require('./consult-comment');
|
|
|
7
|
-const bundle = require('./bundle');
|
|
|
8
|
-const productProcess = require(`${utils}/product-process`);
|
|
|
9
|
-
|
|
|
10
|
-
|
|
|
11
|
const api = global.yoho.API;
|
6
|
const api = global.yoho.API;
|
12
|
-const helpers = global.yoho.helpers;
|
|
|
13
|
-
|
|
|
14
|
-const tool = {
|
|
|
15
|
- prodessDetailData(origin) {
|
|
|
16
|
- let dest = {}; // 结果输出
|
|
|
17
|
-
|
|
|
18
|
- // 商品名称
|
|
|
19
|
- if (!origin.product_name) {
|
|
|
20
|
- return dest;
|
|
|
21
|
- }
|
|
|
22
|
-
|
|
|
23
|
- dest.goodsName = origin.product_name;
|
|
|
24
|
-
|
|
|
25
|
- // 是否是虚拟商品
|
|
|
26
|
- // dest.virtualGoods = (origin.attribute * 1 === 3);
|
|
|
27
|
-
|
|
|
28
|
- // 活动促销短语
|
|
|
29
|
- origin.market_phrase && origin.market_phrase !== ' ' && (dest.marketPhrase = origin.market_phrase);
|
|
|
30
|
-
|
|
|
31
|
- // 商品促销短语
|
|
|
32
|
- origin.sales_phrase && origin.sales_phrase !== ' ' && (dest.goodsSubtitle = origin.sales_phrase);
|
|
|
33
|
-
|
|
|
34
|
- // 商品标签
|
|
|
35
|
- if (origin.tags) {
|
|
|
36
|
- let productTags = {};
|
|
|
37
|
-
|
|
|
38
|
- _.forEach(origin.tags, function(value) {
|
|
|
39
|
- productTags[value] = true;
|
|
|
40
|
- });
|
|
|
41
|
-
|
|
|
42
|
- dest.tags = productTags;
|
|
|
43
|
- }
|
|
|
44
|
-
|
|
|
45
|
- // 商品价格
|
|
|
46
|
- let goodsPrice = {
|
|
|
47
|
- currentPrice: origin.format_sales_price === '0' ? origin.format_market_price : origin.format_sales_price
|
|
|
48
|
- };
|
|
|
49
|
-
|
|
|
50
|
- if (origin.format_sales_price !== '0' && origin.format_market_price !== origin.format_sales_price) {
|
|
|
51
|
- goodsPrice.previousPrice = origin.format_market_price;
|
|
|
52
|
- }
|
|
|
53
|
-
|
|
|
54
|
- dest.goodsPrice = goodsPrice;
|
|
|
55
|
-
|
|
|
56
|
- // 商品返回 YOHO 币
|
|
|
57
|
- // origin.yohoCoinNum && (dest.commodityReturn = origin.yohoCoinNum);
|
|
|
58
|
-
|
|
|
59
|
- // 上市期
|
|
|
60
|
- origin.expect_arrival_time && (dest.periodOfMarket = origin.expect_arrival_time);
|
|
|
61
|
-
|
|
|
62
|
-
|
|
|
63
|
- // 品牌信息
|
|
|
64
|
- if (origin.shop_id) {
|
|
|
65
|
- let extra = `?productSkn=${origin.product_skn}&shopId=${origin.shop_id}`;
|
|
|
66
|
-
|
|
|
67
|
- dest.preferenceUrl = `/product/detail/preference${extra}`;
|
|
|
68
|
- }
|
|
|
69
|
-
|
|
|
70
|
- // dest.brandId = origin.brand_info && origin.brand_info.brand_id || 0;
|
|
|
71
|
- dest.brandId = _.get(origin, 'brand_info.brand_id', 0);
|
|
|
72
|
- dest.productSkn = origin.product_skn;
|
|
|
73
|
- dest.id = origin.product_id;
|
|
|
74
|
-
|
|
|
75
|
- dest.goodsId = origin.goods_id;
|
|
|
76
|
- dest.isDepositAdvance = origin.is_deposit_advance === 'Y'; // 是否定金预售
|
|
|
77
|
- dest.isSeckill = origin.is_secKill === 'Y'; // 是否秒杀
|
|
|
78
|
- dest.isLimitBuy = origin.isLimitBuy; // 是否 限购
|
|
|
79
|
- dest.isPresale = Boolean(origin.expect_arrival_time); // 是否普通预售
|
|
|
80
|
- dest.bundleType = origin.bundle_type; // 商品活动标记
|
|
|
81
|
-
|
|
|
82
|
- // 自定义 属性
|
|
|
83
|
- dest.showCoupon = !(
|
|
|
84
|
- dest.isDepositAdvance || dest.isSeckill || dest.isLimitBuy || dest.isPresale
|
|
|
85
|
- ); // 商品有限购、秒杀、定金预售、普通预售 不显示领
|
|
|
86
|
-
|
|
|
87
|
- // 20170113 要求关闭商品详情页面领券功能
|
|
|
88
|
- // dest.showCoupon = false;
|
|
|
89
|
-
|
|
|
90
|
- // 商品信息
|
|
|
91
|
- if (origin.goods_list.length) {
|
|
|
92
|
- let goodsGroup = [];
|
|
|
93
|
-
|
|
|
94
|
- // pagecache重构
|
|
|
95
|
- _.forEach(origin.goods_list, function(value) {
|
|
|
96
|
-
|
|
|
97
|
- // 商品分组
|
|
|
98
|
- if (value.images_list) {
|
|
|
99
|
- _.forEach(value.images_list, function(good) {
|
|
|
100
|
- goodsGroup.push({
|
|
|
101
|
- goodsId: value.goods_id,
|
|
|
102
|
- img: good.image_url
|
|
|
103
|
- });
|
|
|
104
|
- });
|
|
|
105
|
- }
|
|
|
106
|
- });
|
|
|
107
|
-
|
|
|
108
|
-
|
|
|
109
|
- // 商品图:多个
|
|
|
110
|
- if (goodsGroup.length > 1) {
|
|
|
111
|
- let bannerList = [];
|
|
|
112
|
-
|
|
|
113
|
- _.forEach(goodsGroup, function(value) {
|
|
|
114
|
- value.img = _.replace(value.img, '/quality/80', '/quality/70');
|
|
|
115
|
-
|
|
|
116
|
- bannerList.push({
|
|
|
117
|
- img: value.img
|
|
|
118
|
- });
|
|
|
119
|
- });
|
|
|
120
|
-
|
|
|
121
|
- dest.bannerTop = {
|
|
|
122
|
- list: bannerList
|
|
|
123
|
- };
|
|
|
124
|
- } else if (goodsGroup[0]) {
|
|
|
125
|
- dest.bannerTop = {
|
|
|
126
|
- img: goodsGroup[0].img
|
|
|
127
|
- };
|
|
|
128
|
- }
|
|
|
129
|
- }
|
|
|
130
|
-
|
|
|
131
|
- // 底部简介URL链接
|
|
|
132
|
- dest.introUrl = '/product/detail/intro/' + origin.product_skn;
|
|
|
133
|
-
|
|
|
134
|
- return dest;
|
|
|
135
|
- },
|
|
|
136
|
-
|
|
|
137
|
- /**
|
|
|
138
|
- * 处理品牌关联店铺信息
|
|
|
139
|
- * @param {array}
|
|
|
140
|
- * @return {array}
|
|
|
141
|
- */
|
|
|
142
|
- processShopsInfo(data) {
|
|
|
143
|
- let enterStore = [];
|
|
|
144
|
-
|
|
|
145
|
- _.forEach(data, function(value) {
|
|
|
146
|
- let shopInfo = {
|
|
|
147
|
- img: value.brand_ico,
|
|
|
148
|
- storeName: value.brand_name
|
|
|
149
|
- };
|
|
|
150
|
-
|
|
|
151
|
- if (value.shop_id) {
|
|
|
152
|
- shopInfo.url = helpers.urlFormat('/product/index/brand', {
|
|
|
153
|
- shop_id: value.shop_id
|
|
|
154
|
- });
|
|
|
155
|
- } else {
|
|
|
156
|
- shopInfo.url = helpers.urlFormat('', null, value.brand_domain);
|
|
|
157
|
- }
|
|
|
158
|
-
|
|
|
159
|
- enterStore.push(shopInfo);
|
|
|
160
|
- });
|
|
|
161
|
- return enterStore;
|
|
|
162
|
- },
|
|
|
163
|
-
|
|
|
164
|
- /**
|
|
|
165
|
- * 处理商品 feedback
|
|
|
166
|
- * @param data feedback要处理数据
|
|
|
167
|
- * {
|
|
|
168
|
- * comment, defaultConsult, userConsult
|
|
|
169
|
- * }
|
|
|
170
|
- * @param productId 商品id
|
|
|
171
|
- * @return feedback
|
|
|
172
|
- */
|
|
|
173
|
- processFeedback(data, productId) {
|
|
|
174
|
- // let {comment, defaultConsult, userConsult} = data;
|
|
|
175
|
- let comment = data.comment;
|
|
|
176
|
- let defaultConsult = data.defaultConsult;
|
|
|
177
|
- let userConsult = data.userConsult;
|
|
|
178
|
-
|
|
|
179
|
- let feedbacks = {consults: [], consultsNum: 0};
|
|
|
180
|
-
|
|
|
181
|
- Object.assign(feedbacks, comment);
|
|
|
182
|
-
|
|
|
183
|
- // 商品评价
|
|
|
184
|
- feedbacks.commentsUrl = helpers.urlFormat('/product/detail/comments', {
|
|
|
185
|
- product_id: productId
|
|
|
186
|
- });
|
|
|
187
|
-
|
|
|
188
|
- /* 如果有用户咨询,显示用户咨询,否则显示常见问题 */
|
|
|
189
|
- let obj = {};
|
|
|
190
|
-
|
|
|
191
|
- if (userConsult.total) {
|
|
|
192
|
- obj = {
|
|
|
193
|
- commonConsults: false,
|
|
|
194
|
- consultsNum: parseInt(userConsult.total, 10),
|
|
|
195
|
- consults: _.take(userConsult.list, 2)
|
|
|
196
|
- };
|
|
|
197
|
- } else if (!_.isEmpty(defaultConsult) && !_.get(comment, 'consultsNum', 0)) {
|
|
|
198
|
- obj = {
|
|
|
199
|
- commonConsults: true,
|
|
|
200
|
- consultsNum: true,
|
|
|
201
|
- consults: _.take(defaultConsult.faq, 2)
|
|
|
202
|
- };
|
|
|
203
|
- }
|
|
|
204
|
-
|
|
|
205
|
- Object.assign(feedbacks, obj);
|
|
|
206
|
-
|
|
|
207
|
- if (_.get(feedbacks, 'consultsNum')) {
|
|
|
208
|
- feedbacks.consultsUrl = helpers.urlFormat('/product/detail/consults', {
|
|
|
209
|
- product_id: productId,
|
|
|
210
|
- total: feedbacks.consultsNum
|
|
|
211
|
- });
|
|
|
212
|
- } else {
|
|
|
213
|
- feedbacks.consultsUrl = helpers.urlFormat('/product/detail/consultform', {
|
|
|
214
|
- product_id: productId
|
|
|
215
|
- });
|
|
|
216
|
- }
|
|
|
217
|
- return feedbacks;
|
|
|
218
|
- },
|
|
|
219
|
-
|
|
|
220
|
- /**
|
|
|
221
|
- * 套餐数据处理
|
|
|
222
|
- * @param bundleData
|
|
|
223
|
- * @param skn
|
|
|
224
|
- * @returns {{}}
|
|
|
225
|
- */
|
|
|
226
|
- processBundle(bundleData, skn, gid) {
|
|
|
227
|
- let subPrice = _.get(bundleData, 'bundleInfo.subPrice', 0);
|
|
|
228
|
-
|
|
|
229
|
- return {
|
|
|
230
|
- title: '优惠套装',
|
|
|
231
|
- href: helpers.urlFormat('/product/bundle/detail', {skn: skn, gid: gid}),
|
|
|
232
|
- description: subPrice ? '立省¥' + subPrice : 0,
|
|
|
233
|
- productList: productProcess.processProductList(bundleData && bundleData.productList)
|
|
|
234
|
- };
|
|
|
235
|
- },
|
|
|
236
|
-
|
|
|
237
|
- /**
|
|
|
238
|
- * 处理量贩数据
|
|
|
239
|
- * @param finalResult
|
|
|
240
|
- * @param bundleData
|
|
|
241
|
- */
|
|
|
242
|
- processDiscount(finalResult, bundleData) {
|
|
|
243
|
- finalResult.discountBuy = {
|
|
|
244
|
- num: _.get(bundleData, 'bundleInfo.bundleCount', 1),
|
|
|
245
|
- promotionPhrase: _.get(bundleData, 'bundleInfo.promotionPhrase', ''),
|
|
|
246
|
- discount: _.get(bundleData, 'bundleInfo.discount', 1)
|
|
|
247
|
- };
|
|
|
248
|
-
|
|
|
249
|
- let oldPromotion = finalResult.promotion;
|
|
|
250
|
-
|
|
|
251
|
- finalResult.promotion = [{
|
|
|
252
|
- promotionTitle: _.get(bundleData, 'bundleInfo.promotionPhrase', ''),
|
|
|
253
|
- promotionType: '量贩'
|
|
|
254
|
- }];
|
|
|
255
|
-
|
|
|
256
|
- _.forEach(oldPromotion, value => {
|
|
|
257
|
- finalResult.promotion.push(value);
|
|
|
258
|
- });
|
|
|
259
|
- }
|
|
|
260
|
-};
|
|
|
261
|
|
7
|
|
262
|
const newDetail = {
|
8
|
const newDetail = {
|
263
|
- getProductData(data) {
|
|
|
264
|
- let params = {
|
|
|
265
|
- method: 'app.product.data'
|
|
|
266
|
- };
|
|
|
267
|
-
|
|
|
268
|
- if (data.id) { // 通过 productId 获取商品详情
|
|
|
269
|
- Object.assign(params, {
|
|
|
270
|
- product_id: data.id
|
|
|
271
|
- });
|
|
|
272
|
- } else if (data.productSkn) { // 通过 productSkn 获取商品详情
|
|
|
273
|
- Object.assign(params, {
|
|
|
274
|
- product_skn: data.productSkn
|
|
|
275
|
- });
|
|
|
276
|
- }
|
|
|
277
|
-
|
|
|
278
|
- return api.get('', params, {
|
|
|
279
|
- code: 200,
|
|
|
280
|
- cache: true
|
|
|
281
|
- }).then(result => {
|
|
|
282
|
- if (!result || result.code === 500 || !result.data) {
|
|
|
283
|
- return {};
|
|
|
284
|
- }
|
|
|
285
|
-
|
|
|
286
|
- result.data.goods_id = data.goodsId;
|
|
|
287
|
-
|
|
|
288
|
- return tool.prodessDetailData(result.data);
|
|
|
289
|
- });
|
|
|
290
|
- },
|
|
|
291
|
-
|
|
|
292
|
- /*
|
|
|
293
|
- 获取 促销,评论,咨询,品牌信息
|
|
|
294
|
- */
|
|
|
295
|
- querySknData(params) {
|
|
|
296
|
- let brandId = params.brandId;
|
|
|
297
|
- let productId = params.productId;
|
|
|
298
|
- let skn = params.skn;
|
|
|
299
|
- let gid = params.gid;
|
|
|
300
|
-
|
|
|
301
|
- let apiArray = [
|
|
|
302
|
- this.queryShopsByBrandId(brandId), // 0 品牌信息
|
|
|
303
|
- commentModel.getCommentInfo({
|
|
|
304
|
- productId: productId
|
|
|
305
|
- }), // 1 评论信息
|
|
|
306
|
- commentModel.getCommonConsult(), // 2 默认咨询信息
|
|
|
307
|
- commentModel.getConsults(productId, 1, 2), // 3 咨询列表
|
|
|
308
|
- this.queryPromotion(skn), // 4 促销活动
|
|
|
309
|
- ];
|
|
|
310
|
-
|
|
|
311
|
- if (params.bundleType) {
|
|
|
312
|
- apiArray.push(bundle.getBundleBySkn(skn));
|
|
|
313
|
- }
|
|
|
314
|
-
|
|
|
315
|
- return Promise.all(apiArray).then(info => {
|
|
|
316
|
- let finalResult = {
|
|
|
317
|
- promotion: null,
|
|
|
318
|
- enterStore: null,
|
|
|
319
|
- feedbacks: {
|
|
|
320
|
- consults: [],
|
|
|
321
|
- consultsNum: 0
|
|
|
322
|
- },
|
|
|
323
|
- };
|
|
|
324
|
-
|
|
|
325
|
- finalResult.promotion = info[4];
|
|
|
326
|
- finalResult.enterStore = info[0];
|
|
|
327
|
- finalResult.feedbacks = tool.processFeedback({
|
|
|
328
|
- comment: info[1],
|
|
|
329
|
- defaultConsult: info[2],
|
|
|
330
|
- userConsult: info[3]
|
|
|
331
|
- }, productId);
|
|
|
332
|
-
|
|
|
333
|
- let bundleData = _.get(info[5], 'data', null);
|
|
|
334
|
-
|
|
|
335
|
- /* 套装 */
|
|
|
336
|
- if (bundleData && _.get(bundleData, 'bundleInfo.discountType', null) === 1) {
|
|
|
337
|
- finalResult.bundleData = tool.processBundle(bundleData, skn, gid);
|
|
|
338
|
- }
|
|
|
339
|
-
|
|
|
340
|
- /* 量贩 */
|
|
|
341
|
- if (bundleData && _.get(bundleData, 'bundleInfo.discountType', null) === 2) {
|
|
|
342
|
- tool.processDiscount(finalResult, bundleData);
|
|
|
343
|
- }
|
|
|
344
|
-
|
|
|
345
|
- return finalResult;
|
|
|
346
|
- });
|
|
|
347
|
- },
|
|
|
348
|
-
|
|
|
349
|
- // ------------------------------接口
|
|
|
350
|
-
|
|
|
351
|
- /*
|
|
|
352
|
- 接口: 根据BrandID, 查询品牌信息
|
|
|
353
|
- */
|
|
|
354
|
- queryShopsByBrandId(brandId) {
|
|
|
355
|
- let params = {
|
|
|
356
|
- method: 'app.shop.queryShopsByBrandId',
|
|
|
357
|
- brand_id: brandId
|
|
|
358
|
- };
|
|
|
359
|
-
|
|
|
360
|
- let cacheConf = {
|
|
|
361
|
- cache: true
|
|
|
362
|
- };
|
|
|
363
|
-
|
|
|
364
|
- return api.get('', params, cacheConf)
|
|
|
365
|
- .then(result => {
|
|
|
366
|
- if (result && result.code === 200) {
|
|
|
367
|
- return tool.processShopsInfo(result.data);
|
|
|
368
|
- }
|
|
|
369
|
- return [];
|
|
|
370
|
- }, () => []);
|
|
|
371
|
- },
|
|
|
372
|
-
|
|
|
373
|
- /**
|
|
|
374
|
- * 接口: 商品 促销活动
|
|
|
375
|
- */
|
|
|
376
|
- queryPromotion(skn) {
|
|
|
377
|
- let params = {
|
|
|
378
|
- method: 'app.product.promotion',
|
|
|
379
|
- product_skn: skn
|
|
|
380
|
- };
|
|
|
381
|
-
|
|
|
382
|
- let cacheConf = {
|
|
|
383
|
- cache: true
|
|
|
384
|
- };
|
|
|
385
|
-
|
|
|
386
|
- return api.get('', params, cacheConf)
|
|
|
387
|
- .then(result => {
|
|
|
388
|
- if (result && result.code === 200) {
|
|
|
389
|
- return result.data;
|
|
|
390
|
- }
|
|
|
391
|
-
|
|
|
392
|
- return {};
|
|
|
393
|
- });
|
|
|
394
|
- },
|
|
|
395
|
-
|
|
|
396
|
/**
|
9
|
/**
|
397
|
* 获取秒杀列表
|
10
|
* 获取秒杀列表
|
398
|
*/
|
11
|
*/
|
|
@@ -410,7 +23,7 @@ const newDetail = { |
|
@@ -410,7 +23,7 @@ const newDetail = { |
410
|
.catch()
|
23
|
.catch()
|
411
|
.then(result => {
|
24
|
.then(result => {
|
412
|
let data = {};
|
25
|
let data = {};
|
413
|
-
|
26
|
+
|
414
|
if (result.data) {
|
27
|
if (result.data) {
|
415
|
data = result.data;
|
28
|
data = result.data;
|
416
|
if (data.storageSum > 0) {
|
29
|
if (data.storageSum > 0) {
|