|
@@ -15,6 +15,25 @@ const helpers = global.yoho.helpers; |
|
@@ -15,6 +15,25 @@ const helpers = global.yoho.helpers; |
15
|
const productProcess = require(`${utils}/product-process`);
|
15
|
const productProcess = require(`${utils}/product-process`);
|
16
|
|
16
|
|
17
|
/**
|
17
|
/**
|
|
|
18
|
+ * 从 useragent 获取 uid
|
|
|
19
|
+ * @returns {*}
|
|
|
20
|
+ * @private
|
|
|
21
|
+ */
|
|
|
22
|
+const _getUidFromUserAgent = (req) => {
|
|
|
23
|
+ let userAgent = _.split(req.headers['user-agent'], ';');
|
|
|
24
|
+ let uidString = '';
|
|
|
25
|
+
|
|
|
26
|
+ _.forEach(userAgent, value => {
|
|
|
27
|
+ if (_.startsWith(value, 'uid')) {
|
|
|
28
|
+ uidString = value;
|
|
|
29
|
+ return;
|
|
|
30
|
+ }
|
|
|
31
|
+ });
|
|
|
32
|
+
|
|
|
33
|
+ return _.split(uidString, '=')[1];
|
|
|
34
|
+};
|
|
|
35
|
+
|
|
|
36
|
+/**
|
18
|
* 店铺 - 基础模板
|
37
|
* 店铺 - 基础模板
|
19
|
*/
|
38
|
*/
|
20
|
const _baseShop = (req, res, shopInfo, shopId) => {
|
39
|
const _baseShop = (req, res, shopInfo, shopId) => {
|
|
@@ -51,7 +70,7 @@ const baseShopFav = (req, res) => { |
|
@@ -51,7 +70,7 @@ const baseShopFav = (req, res) => { |
51
|
listModel.getShopData(req, shopId, uid, isApp).then(result => {
|
70
|
listModel.getShopData(req, shopId, uid, isApp).then(result => {
|
52
|
res.json({
|
71
|
res.json({
|
53
|
code: 200,
|
72
|
code: 200,
|
54
|
- collect: result.goBrand && result.goBrand.isFavorite === 'Y' ? true : false,
|
73
|
+ collect: result.goBrand && result.goBrand.is_favorite === 'Y' ? true : false,
|
55
|
});
|
74
|
});
|
56
|
});
|
75
|
});
|
57
|
};
|
76
|
};
|
|
@@ -80,6 +99,13 @@ const _shop = (req, res, shopId) => { |
|
@@ -80,6 +99,13 @@ const _shop = (req, res, shopId) => { |
80
|
navTitle: false
|
99
|
navTitle: false
|
81
|
}))
|
100
|
}))
|
82
|
};
|
101
|
};
|
|
|
102
|
+ } else {
|
|
|
103
|
+ uid = req.query.uid;
|
|
|
104
|
+ req.session.appUid = uid;
|
|
|
105
|
+ res.cookie('appUid', uid, {
|
|
|
106
|
+ domain: 'yohobuy.com',
|
|
|
107
|
+ expires: new Date(Date.now() + 2592000000) // 有效期一年
|
|
|
108
|
+ });
|
83
|
}
|
109
|
}
|
84
|
|
110
|
|
85
|
listModel.getShopData(req, shopId, uid, isApp).then(result => {
|
111
|
listModel.getShopData(req, shopId, uid, isApp).then(result => {
|
|
@@ -146,7 +172,7 @@ const shopFav = (req, res) => { |
|
@@ -146,7 +172,7 @@ const shopFav = (req, res) => { |
146
|
listModel.getShopFav(req, shopId, uid, isApp).then(result => {
|
172
|
listModel.getShopFav(req, shopId, uid, isApp).then(result => {
|
147
|
res.json({
|
173
|
res.json({
|
148
|
code: 200,
|
174
|
code: 200,
|
149
|
- collect: result.isFavorite === 'Y',
|
175
|
+ collect: result.is_favorite === 'Y',
|
150
|
});
|
176
|
});
|
151
|
});
|
177
|
});
|
152
|
};
|
178
|
};
|
|
@@ -321,12 +347,34 @@ const favoriteBrand = (req, res, next) => { |
|
@@ -321,12 +347,34 @@ const favoriteBrand = (req, res, next) => { |
321
|
let opt = req.query.opt || 'ok';
|
347
|
let opt = req.query.opt || 'ok';
|
322
|
let type = req.query.type || 'product';
|
348
|
let type = req.query.type || 'product';
|
323
|
let appVersion = req.query.appVersion || false;
|
349
|
let appVersion = req.query.appVersion || false;
|
324
|
- let refer = req.get('Referer') || `${global.yoho.config.siteUrl}/${req.cookies._Channel || ''}`;
|
350
|
+ let refer = req.headers.origin;
|
|
|
351
|
+
|
|
|
352
|
+ if (req.headers.referer) {
|
|
|
353
|
+ let refererSplit = _.split(req.headers.referer, '?');
|
|
|
354
|
+
|
|
|
355
|
+ let shopIdSplit = _.split(refererSplit[1], '&');
|
|
|
356
|
+ let shopId = '';
|
|
|
357
|
+
|
|
|
358
|
+ _.forEach(shopIdSplit, value => {
|
|
|
359
|
+ if (_.startsWith(value, 'shop_id')) {
|
|
|
360
|
+ shopId = value;
|
|
|
361
|
+ return;
|
|
|
362
|
+ }
|
|
|
363
|
+ });
|
|
|
364
|
+
|
|
|
365
|
+ refer = refererSplit[0] + '?' + shopId;
|
|
|
366
|
+ }
|
|
|
367
|
+
|
325
|
let url = helpers.urlFormat('/signin.html') + '?refer=' + refer;
|
368
|
let url = helpers.urlFormat('/signin.html') + '?refer=' + refer;
|
326
|
|
369
|
|
327
|
- if (appVersion === 'true') {
|
|
|
328
|
- uid = req.cookies.appUid;
|
|
|
329
|
- url = `${url}&openby:yohobuy={"action":"go.weblogin","params":{"jumpurl":{"url":${decodeURI(req.cookies.refer)},"param":{}},"requesturl":{"param":{},"url":""},"priority":"Y"}}`; // eslint-disable-line
|
370
|
+ if (appVersion) {
|
|
|
371
|
+ uid = req.query.uid ? crypto.decrypt('', req.query.uid) : req.cookies.appUid;
|
|
|
372
|
+
|
|
|
373
|
+ if (!uid || uid === 'undefined') {
|
|
|
374
|
+ uid = _getUidFromUserAgent(req);
|
|
|
375
|
+ }
|
|
|
376
|
+
|
|
|
377
|
+ url = `${refer}&openby:yohobuy={"action":"go.weblogin","params":{"jumpurl":{"url":"${refer}","param":{}},"requesturl":{"param":{},"url":""},"priority":"Y"}}`; // eslint-disable-line
|
330
|
}
|
378
|
}
|
331
|
|
379
|
|
332
|
if (!id) {
|
380
|
if (!id) {
|
|
@@ -399,32 +447,65 @@ const userCoupon = (req, res, next) => { |
|
@@ -399,32 +447,65 @@ const userCoupon = (req, res, next) => { |
399
|
}
|
447
|
}
|
400
|
|
448
|
|
401
|
let cryptCouponId = crypto.decrypt('', req.query.couponID);
|
449
|
let cryptCouponId = crypto.decrypt('', req.query.couponID);
|
|
|
450
|
+ let uid = req.user.uid;
|
|
|
451
|
+
|
|
|
452
|
+ if (req.yoho.isApp !== 'false') {
|
|
|
453
|
+ uid = req.query.uid ? crypto.decrypt('', req.query.uid) : req.cookies.appUid;
|
|
|
454
|
+
|
|
|
455
|
+ if (!uid || uid === 'undefined') {
|
|
|
456
|
+ uid = _getUidFromUserAgent(req);
|
|
|
457
|
+ }
|
|
|
458
|
+ }
|
402
|
|
459
|
|
403
|
- if (req.user.uid) {
|
460
|
+ if (uid) {
|
404
|
listModel.receiveCoupon(
|
461
|
listModel.receiveCoupon(
|
405
|
- req.user.uid,
|
462
|
+ uid,
|
406
|
cryptCouponId
|
463
|
cryptCouponId
|
407
|
).then(result => {
|
464
|
).then(result => {
|
408
|
res.json(result);
|
465
|
res.json(result);
|
|
|
466
|
+ return;
|
409
|
}).catch(next);
|
467
|
}).catch(next);
|
410
|
} else {
|
468
|
} else {
|
411
|
- let refer = req.headers.referer || req.headers.origin;
|
|
|
412
|
- let toUrl = helpers.urlFormat('/signin.html', {refer: refer});
|
469
|
+ let refer = req.headers.origin;
|
|
|
470
|
+
|
|
|
471
|
+ if (req.headers.referer) {
|
|
|
472
|
+ let refererSplit = _.split(req.headers.referer, '?');
|
|
|
473
|
+
|
|
|
474
|
+ let shopIdSplit = _.split(refererSplit[1], '&');
|
|
|
475
|
+ let shopId = '';
|
413
|
|
476
|
|
414
|
- if (req.yoho.isApp) {
|
|
|
415
|
- toUrl += '&openby:yohobuy={"action":"go.weblogin","params":{"jumpurl":{"url":"' +
|
477
|
+ _.forEach(shopIdSplit, value => {
|
|
|
478
|
+ if (_.startsWith(value, 'shop_id')) {
|
|
|
479
|
+ shopId = value;
|
|
|
480
|
+ return;
|
|
|
481
|
+ }
|
|
|
482
|
+ });
|
|
|
483
|
+
|
|
|
484
|
+ refer = refererSplit[0] + '?' + shopId;
|
|
|
485
|
+ }
|
|
|
486
|
+
|
|
|
487
|
+ if (req.yoho.isApp !== 'false') {
|
|
|
488
|
+ let toUrl = refer + '&openby:yohobuy={"action":"go.weblogin","params":{"jumpurl":{"url":"' +
|
416
|
refer +
|
489
|
refer +
|
417
|
'","param":{}},"requesturl":{"param":{"method":"app.promotion.getCoupon","couponId":"' +
|
490
|
'","param":{}},"requesturl":{"param":{"method":"app.promotion.getCoupon","couponId":"' +
|
418
|
cryptCouponId +
|
491
|
cryptCouponId +
|
419
|
'"},"url":"' +
|
492
|
'"},"url":"' +
|
420
|
_.get(global, 'yoho.API.ApiUrl', '') +
|
493
|
_.get(global, 'yoho.API.ApiUrl', '') +
|
421
|
'"},"priority":"Y"}}';
|
494
|
'"},"priority":"Y"}}';
|
422
|
- }
|
|
|
423
|
|
495
|
|
424
|
res.json({
|
496
|
res.json({
|
425
|
code: 4401,
|
497
|
code: 4401,
|
426
|
url: toUrl
|
498
|
url: toUrl
|
427
|
});
|
499
|
});
|
|
|
500
|
+
|
|
|
501
|
+ } else {
|
|
|
502
|
+ res.json({
|
|
|
503
|
+ code: 4401,
|
|
|
504
|
+ url: helpers.urlFormat('/signin.html', {refer: refer})
|
|
|
505
|
+ });
|
|
|
506
|
+ }
|
|
|
507
|
+
|
|
|
508
|
+
|
428
|
}
|
509
|
}
|
429
|
|
510
|
|
430
|
};
|
511
|
};
|