|
@@ -11,11 +11,31 @@ const _ = require('lodash'); |
|
@@ -11,11 +11,31 @@ const _ = require('lodash'); |
11
|
const helpers = global.yoho.helpers;
|
11
|
const helpers = global.yoho.helpers;
|
12
|
|
12
|
|
13
|
/**
|
13
|
/**
|
|
|
14
|
+ * 获取用户数据信息
|
|
|
15
|
+ * @param {[string]} uid
|
|
|
16
|
+ * @return {[array]}
|
|
|
17
|
+ */
|
|
|
18
|
+const _getUserProfile = (uid) => {
|
|
|
19
|
+ if (!uid) {
|
|
|
20
|
+ return Promise.resolve({
|
|
|
21
|
+ code: 200,
|
|
|
22
|
+ data: {}
|
|
|
23
|
+ });
|
|
|
24
|
+ }
|
|
|
25
|
+ return api.get('', {
|
|
|
26
|
+ method: 'app.passport.profile',
|
|
|
27
|
+ uid: uid
|
|
|
28
|
+ }, {
|
|
|
29
|
+ cache: true
|
|
|
30
|
+ });
|
|
|
31
|
+};
|
|
|
32
|
+
|
|
|
33
|
+/**
|
14
|
* 处理品牌关联店铺信息
|
34
|
* 处理品牌关联店铺信息
|
15
|
* @param {array}
|
35
|
* @param {array}
|
16
|
* @return {array}
|
36
|
* @return {array}
|
17
|
*/
|
37
|
*/
|
18
|
-const getShopsInfo = (data) => {
|
38
|
+const _getShopsInfo = (data) => {
|
19
|
let enterStore = [];
|
39
|
let enterStore = [];
|
20
|
|
40
|
|
21
|
_.forEach(data, function(value) {
|
41
|
_.forEach(data, function(value) {
|
|
@@ -44,7 +64,7 @@ const getShopsInfo = (data) => { |
|
@@ -44,7 +64,7 @@ const getShopsInfo = (data) => { |
44
|
* @param {Boolean} 限购商品是否已开售
|
64
|
* @param {Boolean} 限购商品是否已开售
|
45
|
* @return {array}
|
65
|
* @return {array}
|
46
|
*/
|
66
|
*/
|
47
|
-const procShowStatus = (data, showStatus, isBeginSale) => {
|
67
|
+const _procShowStatus = (data, showStatus, isBeginSale) => {
|
48
|
switch (showStatus) {
|
68
|
switch (showStatus) {
|
49
|
case 1: // 开售前/后,立即分享获得限购码(用户未领取限购码)
|
69
|
case 1: // 开售前/后,立即分享获得限购码(用户未领取限购码)
|
50
|
// 显示获取限购码按钮
|
70
|
// 显示获取限购码按钮
|
|
@@ -93,7 +113,7 @@ const procShowStatus = (data, showStatus, isBeginSale) => { |
|
@@ -93,7 +113,7 @@ const procShowStatus = (data, showStatus, isBeginSale) => { |
93
|
* @param {string} skn 限购商品skn
|
113
|
* @param {string} skn 限购商品skn
|
94
|
* @return {string} 限购商品跳转url
|
114
|
* @return {string} 限购商品跳转url
|
95
|
*/
|
115
|
*/
|
96
|
-const getLimitCodeUrl = (productCode, skn, ua) => {
|
116
|
+const _getLimitCodeUrl = (productCode, skn, ua) => {
|
97
|
let url = 'yohoapp://yoho.app/openwith?limit_product_code=' + productCode +
|
117
|
let url = 'yohoapp://yoho.app/openwith?limit_product_code=' + productCode +
|
98
|
'&product_skn=' + skn;
|
118
|
'&product_skn=' + skn;
|
99
|
|
119
|
|
|
@@ -114,7 +134,7 @@ const getLimitCodeUrl = (productCode, skn, ua) => { |
|
@@ -114,7 +134,7 @@ const getLimitCodeUrl = (productCode, skn, ua) => { |
114
|
* @param origin Object 原始数据
|
134
|
* @param origin Object 原始数据
|
115
|
* @return dest Object 格式化数据
|
135
|
* @return dest Object 格式化数据
|
116
|
*/
|
136
|
*/
|
117
|
-const detailDataPkg = (origin, uid, vipLevel, ua) => {
|
137
|
+const _detailDataPkg = (origin, uid, vipLevel, ua) => {
|
118
|
let dest = {}, // 结果输出
|
138
|
let dest = {}, // 结果输出
|
119
|
thumbImageList = [],
|
139
|
thumbImageList = [],
|
120
|
colorGroup = {},
|
140
|
colorGroup = {},
|
|
@@ -481,10 +501,10 @@ const detailDataPkg = (origin, uid, vipLevel, ua) => { |
|
@@ -481,10 +501,10 @@ const detailDataPkg = (origin, uid, vipLevel, ua) => { |
481
|
}
|
501
|
}
|
482
|
|
502
|
|
483
|
// 处理限购商品有关的按钮状态
|
503
|
// 处理限购商品有关的按钮状态
|
484
|
- dest = procShowStatus(dest, showStatus, isBeginSale);
|
|
|
485
|
- Object.assign;
|
504
|
+ dest = _procShowStatus(dest, showStatus, isBeginSale);
|
|
|
505
|
+
|
486
|
dest.cartInfo.limitProductCode = origin.limitProductCode;
|
506
|
dest.cartInfo.limitProductCode = origin.limitProductCode;
|
487
|
- dest.cartInfo.limitCodeUrl = getLimitCodeUrl(origin.limitProductCode, origin.erpProductId, ua);
|
507
|
+ dest.cartInfo.limitCodeUrl = _getLimitCodeUrl(origin.limitProductCode, origin.erpProductId, ua);
|
488
|
dest.cartInfo.limitProductPay = helpers.urlFormat('/cart/index/orderEnsure'); // 待处理 相关处理逻辑还不存在
|
508
|
dest.cartInfo.limitProductPay = helpers.urlFormat('/cart/index/orderEnsure'); // 待处理 相关处理逻辑还不存在
|
489
|
} else {
|
509
|
} else {
|
490
|
dest.cartInfo.addToCartUrl = helpers.urlFormat('/product/buy_' + origin.id + '_' +
|
510
|
dest.cartInfo.addToCartUrl = helpers.urlFormat('/product/buy_' + origin.id + '_' +
|
|
@@ -510,7 +530,7 @@ const detailDataPkg = (origin, uid, vipLevel, ua) => { |
|
@@ -510,7 +530,7 @@ const detailDataPkg = (origin, uid, vipLevel, ua) => { |
510
|
return dest;
|
530
|
return dest;
|
511
|
};
|
531
|
};
|
512
|
|
532
|
|
513
|
-module.exports = (data) => {
|
533
|
+let getProductData = (data) => {
|
514
|
let finalResult;
|
534
|
let finalResult;
|
515
|
let params = {
|
535
|
let params = {
|
516
|
productId: _.toString(data.id),
|
536
|
productId: _.toString(data.id),
|
|
@@ -521,18 +541,30 @@ module.exports = (data) => { |
|
@@ -521,18 +541,30 @@ module.exports = (data) => { |
521
|
params.uid = data.uid;
|
541
|
params.uid = data.uid;
|
522
|
}
|
542
|
}
|
523
|
|
543
|
|
524
|
- return api.get('', params).then(result => {
|
|
|
525
|
- finalResult = detailDataPkg(result, data.uid, data.vipLevel, data.ua);
|
|
|
526
|
-
|
|
|
527
|
- return api.get('', {
|
|
|
528
|
- method: 'app.shop.queryShopsByBrandId',
|
|
|
529
|
- brand_id: _.toString(result.brandId)
|
|
|
530
|
- }).then(shops => {
|
|
|
531
|
- if (shops.code === 200) {
|
|
|
532
|
- finalResult.enterStore = getShopsInfo(shops.data);
|
|
|
533
|
- }
|
544
|
+ return _getUserProfile(params.uid).then((user) => {
|
|
|
545
|
+ data.vipLevel = (user.data && user.data.vip_info && user.data.vip_info.cur_level) || '0';
|
|
|
546
|
+
|
|
|
547
|
+ return api.get('', params, {
|
|
|
548
|
+ cache: true
|
|
|
549
|
+ }).then(result => {
|
|
|
550
|
+ finalResult = _detailDataPkg(result, data.uid, data.vipLevel, data.ua);
|
|
|
551
|
+
|
|
|
552
|
+ return api.get('', {
|
|
|
553
|
+ method: 'app.shop.queryShopsByBrandId',
|
|
|
554
|
+ brand_id: _.toString(result.brandId)
|
|
|
555
|
+ }, {
|
|
|
556
|
+ cache: true
|
|
|
557
|
+ }).then(shops => {
|
|
|
558
|
+ if (shops.code === 200) {
|
|
|
559
|
+ finalResult.enterStore = _getShopsInfo(shops.data);
|
|
|
560
|
+ }
|
534
|
|
561
|
|
535
|
- return finalResult;
|
562
|
+ return finalResult;
|
|
|
563
|
+ });
|
536
|
});
|
564
|
});
|
537
|
});
|
565
|
});
|
538
|
};
|
566
|
};
|
|
|
567
|
+
|
|
|
568
|
+module.exports = {
|
|
|
569
|
+ getProductData
|
|
|
570
|
+}; |