Authored by 陈峰

uniontype fix

@@ -548,7 +548,8 @@ exports.user = function(req, res, next) { @@ -548,7 +548,8 @@ exports.user = function(req, res, next) {
548 let result = { 548 let result = {
549 code: 403, 549 code: 403,
550 message: '未登录', 550 message: '未登录',
551 - data: '' 551 + data: '',
  552 + unionType: req.query.union_type || req.cookies.unionTypeYas || ''
552 }; 553 };
553 554
554 if (req.user.uid) { 555 if (req.user.uid) {
@@ -13,9 +13,10 @@ const isTest = process.env.NODE_ENV === 'test3' || process.env.NODE_ENV === 'tes @@ -13,9 +13,10 @@ const isTest = process.env.NODE_ENV === 'test3' || process.env.NODE_ENV === 'tes
13 13
14 const domains = { 14 const domains = {
15 15
16 - // api: 'http://api.yoho.cn/', 16 + api: 'http://api.yoho.cn/',
  17 +
  18 + service: 'http://service.yoho.cn/',
17 19
18 - // service: 'http://service.yoho.cn/',  
19 // yoLuck: 'https://action.yoho.cn', 20 // yoLuck: 'https://action.yoho.cn',
20 21
21 // liveApi: 'http://testapi.live.yohops.com:9999/', 22 // liveApi: 'http://testapi.live.yohops.com:9999/',
@@ -27,8 +28,8 @@ const domains = { @@ -27,8 +28,8 @@ const domains = {
27 28
28 // platformApi: 'http://172.16.6.210:8088/', 29 // platformApi: 'http://172.16.6.210:8088/',
29 30
30 - api: 'http://api-test3.dev.yohocorp.com/',  
31 - service: 'http://api-test3.dev.yohocorp.com/', 31 + // api: 'http://api-test3.dev.yohocorp.com/',
  32 + // service: 'http://api-test3.dev.yohocorp.com/',
32 liveApi: 'http://testapi.live.yohops.com:9999/', 33 liveApi: 'http://testapi.live.yohops.com:9999/',
33 singleApi: 'http://api-test3.dev.yohocorp.com/', 34 singleApi: 'http://api-test3.dev.yohocorp.com/',
34 ufo: 'http://java-yohoufo-fore.test3.ingress.dev.yohocorp.com/ufo-gateway/', 35 ufo: 'http://java-yohoufo-fore.test3.ingress.dev.yohocorp.com/ufo-gateway/',
@@ -132,7 +133,7 @@ module.exports = { @@ -132,7 +133,7 @@ module.exports = {
132 notifyUrl: domains.service + 'payment/weixin_notify', 133 notifyUrl: domains.service + 'payment/weixin_notify',
133 }, 134 },
134 geetestJs: '//static.geetest.com/static/tools/gt.js', 135 geetestJs: '//static.geetest.com/static/tools/gt.js',
135 - jsSdk: '//cdn.yoho.cn/js-sdk/1.3.17/jssdk.js', 136 + jsSdk: '//cdn.yoho.cn/js-sdk/1.3.19/jssdk.js',
136 redis: { 137 redis: {
137 connect: { 138 connect: {
138 host: '192.168.102.49', 139 host: '192.168.102.49',
@@ -54,6 +54,8 @@ module.exports = () => { @@ -54,6 +54,8 @@ module.exports = () => {
54 // IP 地址 54 // IP 地址
55 yoho.clientIp = _getClientIp(req); 55 yoho.clientIp = _getClientIp(req);
56 56
  57 + yoho.unionTypeYas = req.query.union_type || req.cookies.unionTypeYas || '';
  58 +
57 if (req.query.fullscreen) { 59 if (req.query.fullscreen) {
58 yoho.fullScreen = true; 60 yoho.fullScreen = true;
59 } 61 }
@@ -79,6 +81,12 @@ module.exports = () => { @@ -79,6 +81,12 @@ module.exports = () => {
79 res.locals.showHeader = false; 81 res.locals.showHeader = false;
80 } 82 }
81 83
  84 + if (yoho.unionTypeYas && req.cookies.unionTypeYas !== yoho.unionTypeYas) {
  85 + res.cookie('unionTypeYas', yoho.unionTypeYas, {
  86 + path: '/'
  87 + });
  88 + }
  89 +
82 next(); 90 next();
83 }; 91 };
84 }; 92 };
@@ -12,7 +12,7 @@ @@ -12,7 +12,7 @@
12 a.async = 1; 12 a.async = 1;
13 a.src = j; 13 a.src = j;
14 m.parentNode.insertBefore(a, m); 14 m.parentNode.insertBefore(a, m);
15 - }(window, document, 'script', (document.location.protocol === 'https:' ? 'https:' : 'http:') + '//cdn.yoho.cn/yas-jssdk/2.4.19/yas.js', '_yas')); 15 + }(window, document, 'script', (document.location.protocol === 'https:' ? 'https:' : 'http:') + '//cdn.yoho.cn/yas-jssdk/2.4.20/yas.js', '_yas'));
16 16
17 var _hmt = _hmt || []; 17 var _hmt = _hmt || [];
18 18
@@ -244,7 +244,7 @@ $.extend({ @@ -244,7 +244,7 @@ $.extend({
244 // 单击下载按钮 - 接受微信商城或者第三方来源的数据埋点信息 244 // 单击下载按钮 - 接受微信商城或者第三方来源的数据埋点信息
245 let unionType = queryString().union_type || ''; 245 let unionType = queryString().union_type || '';
246 246
247 - if (unionType) { 247 + if (unionType && cookie('unionTypeYas') !== unionType) {
248 setCookie('unionTypeYas', unionType, { 248 setCookie('unionTypeYas', unionType, {
249 path: '/' 249 path: '/'
250 }); 250 });
@@ -332,6 +332,20 @@ $('body').on('touchstart', '.similar-btn', function() { @@ -332,6 +332,20 @@ $('body').on('touchstart', '.similar-btn', function() {
332 return false; 332 return false;
333 }); 333 });
334 334
  335 +// 更新union_type
  336 ++(() => {
  337 + $('a[href*=activity]').each(function() {
  338 + const $el = $(this);
  339 + const href = $el.attr('href');
  340 +
  341 + if (href.indexOf('union_type') < 0) {
  342 + const sps = href.split('?');
  343 +
  344 + $el.attr('href', `${sps[0]}?union_type=${cookie('unionTypeYas')}&${sps[1]}`);
  345 + }
  346 + });
  347 +})();
  348 +
335 (function() { 349 (function() {
336 let lastTime = 0, 350 let lastTime = 0,
337 prefixes = 'webkit moz ms o'.split(' '), 351 prefixes = 'webkit moz ms o'.split(' '),
@@ -3,6 +3,8 @@ @@ -3,6 +3,8 @@
3 */ 3 */
4 const qs = require('yoho-qs'); 4 const qs = require('yoho-qs');
5 const cookie = require('yoho-cookie'); 5 const cookie = require('yoho-cookie');
  6 +const dialog = require('js/plugin/dialog');
  7 +const yoho = require('js/yoho-app');
6 8
7 const u = navigator.userAgent; 9 const u = navigator.userAgent;
8 const isFromYOHO = /m\.yohobuy\.com/i.test(document.referrer); 10 const isFromYOHO = /m\.yohobuy\.com/i.test(document.referrer);
@@ -49,7 +51,7 @@ const getMktcBySeo = function() { @@ -49,7 +51,7 @@ const getMktcBySeo = function() {
49 }; 51 };
50 52
51 const getMktc = () => { 53 const getMktc = () => {
52 - return qs.mkt_code || qs.union_type || getMktcBySeo() || '100000000000349'; 54 + return qs.mkt_code || qs.union_type || cookie.get('unionTypeYas') || getMktcBySeo() || '100000000000349';
53 }; 55 };
54 56
55 const canOpenApp = () => { 57 const canOpenApp = () => {
@@ -76,36 +78,117 @@ const getAppPath = () => { @@ -76,36 +78,117 @@ const getAppPath = () => {
76 }; 78 };
77 79
78 80
79 -if (canOpenApp()) {  
80 - setTimeout(function() {  
81 - // if (window._yas && window._yas.sendCustomInfo) {  
82 - // window._yas.sendCustomInfo({  
83 - // op: 'YB_H5_AWAKE_APP',  
84 - // param: JSON.stringify({  
85 - // PAGE_NAME: encodeURIComponent(document.title),  
86 - // PAGE_URL: encodeURIComponent(location.href)  
87 - // })  
88 - // }, true);  
89 - // } 81 +window._getMktCode = getMktc;
90 82
91 - if (window._hmt && window._hmt.push) {  
92 - window._hmt.push(['_trackEvent', 'H5唤起APP', isiOS ? 'Apple' : 'Android', document.title, location.href]); 83 +const getIOSVersion = () => {
  84 + const verion = navigator.appVersion.match(/OS (\d+)_(\d+)_?(\d+)?/);
  85 +
  86 + return parseInt(verion[1], 10);
  87 +};
  88 +const ua = navigator.userAgent;
  89 +const isOriginalChrome = /chrome\/[\d.]+ Mobile Safari\/[\d.]+/i.test(ua) &&
  90 + yoho.isAndroid &&
  91 + ua.indexOf('Version') < 0;
  92 +
  93 +
  94 +const getFallUrl = (schemeUrl) => {
  95 + let clientId = cookie.get('_yasvd');
  96 + let unionTypeYas = cookie.get('unionTypeYas');
  97 + const appPath = (schemeUrl || '').replace('yohobuy://yohobuy.com/goapp?', '') || 'openby:yohobuy={"action":"go.home","params":{"gender":"1","channel":"2"}}';
  98 +
  99 + return `https://union.yoho.cn/union/app-downloads.html?union_type=${unionTypeYas}&client_id=${clientId}&${appPath}`;
  100 +};
  101 +
  102 +const checkOpenFall = (url, callFunc, noFall) => {
  103 + let time = Date.now();
  104 +
  105 + callFunc();
  106 +
  107 + const fallUrl = getFallUrl(url);
  108 +
  109 + if (noFall) {
  110 + return;
  111 + }
  112 + window.setTimeout(function() {
  113 + if (Date.now() - time < 1200) {
  114 + window.location.href = fallUrl;
93 } 115 }
94 }, 1000); 116 }, 1000);
  117 +};
95 118
96 - setTimeout(function() {  
97 - let appPath = getAppPath();  
98 - let ifr; 119 +const callIframe = (url, noFall) => {
  120 + checkOpenFall(url, () => {
  121 + const ifr = document.createElement('iframe');
99 122
100 - if (isiOS) {  
101 - window.location.href = appPath;  
102 - } else {  
103 - ifr = document.createElement('iframe');  
104 - ifr.src = appPath; 123 + ifr.src = url;
105 ifr.style.display = 'none'; 124 ifr.style.display = 'none';
106 document.body.appendChild(ifr); 125 document.body.appendChild(ifr);
  126 + }, noFall);
  127 +};
  128 +
  129 +const callUrl = (url, noFall) => {
  130 + checkOpenFall(url, () => {
  131 + window.location.href = url;
  132 + }, noFall);
  133 +};
  134 +
  135 +const callA = (url, noFall) => {
  136 + checkOpenFall(url, () => {
  137 + const ca = document.createElement('a');
  138 +
  139 + ca.setAttribute('href', url);
  140 + ca.style.display = 'none';
  141 + document.body.appendChild(ca);
  142 +
  143 + ca.click();
  144 + }, noFall);
  145 +};
  146 +
  147 +
  148 +export const toAppPage = (appUrl, noFall) => {
  149 + if (isOriginalChrome) {
  150 + callA(appUrl, noFall);
  151 + } else if (yoho.isiOS) {
  152 + if (getIOSVersion() < 9) {
  153 + callIframe(appUrl, noFall);
  154 + } else {
  155 + callUrl(appUrl, noFall);
  156 + }
  157 + } else {
  158 + callIframe(appUrl, noFall);
  159 + }
  160 +};
  161 +
  162 +export const toAppPageDialog = (options) => {
  163 + dialog.showDialog({
  164 + dialogText: options.title,
  165 + hasFooter: {
  166 + rightBtnText: '打开Yoho!Buy有货APP'
  167 + }
  168 + }, function() {
  169 + toAppPage(options.appUrl);
  170 + }, null, true);
  171 +};
  172 +
  173 +
  174 +export const openApp = () => {
  175 + if (canOpenApp()) {
  176 + setTimeout(function() {
  177 + if (window._hmt && window._hmt.push) {
  178 + window._hmt.push(['_trackEvent',
  179 + 'H5唤起APP',
  180 + isiOS ? 'Apple' : 'Android',
  181 + document.title,
  182 + location.href]);
107 } 183 }
  184 + }, 1000);
  185 +
  186 + setTimeout(function() {
  187 + let appPath = getAppPath();
  188 +
  189 + toAppPage(appPath, true);
108 }, 2000); 190 }, 2000);
109 -} 191 + }
  192 +};
110 193
111 -window._getMktCode = getMktc; 194 +openApp();
1 require('scss/product/detail/detail.page.scss'); 1 require('scss/product/detail/detail.page.scss');
  2 +import {toAppPageDialog} from 'js/common/open-app';
2 let $ = require('yoho-jquery'), 3 let $ = require('yoho-jquery'),
3 tip = require('js/plugin/tip'); 4 tip = require('js/plugin/tip');
4 let productId = $('#productId').val(); 5 let productId = $('#productId').val();
@@ -277,9 +278,6 @@ setTimeout(() => { @@ -277,9 +278,6 @@ setTimeout(() => {
277 return false; 278 return false;
278 }); 279 });
279 $('#limit-sale').on('touchend', function(e) { 280 $('#limit-sale').on('touchend', function(e) {
280 - let time,  
281 - ifr;  
282 -  
283 e.stopPropagation(); 281 e.stopPropagation();
284 282
285 if ($('.is-mars-app').length > 0 && yoho && yoho.isMarsApp) { 283 if ($('.is-mars-app').length > 0 && yoho && yoho.isMarsApp) {
@@ -291,28 +289,10 @@ setTimeout(() => { @@ -291,28 +289,10 @@ setTimeout(() => {
291 return false; 289 return false;
292 } 290 }
293 291
294 - dialog.showDialog({  
295 - dialogText: '进入有货APP,获取限购码',  
296 - hasFooter: {  
297 - rightBtnText: '打开Yoho!Buy有货APP'  
298 - }  
299 - }, function() {  
300 - let appUrl = $('input[name="limitCodeUrl"]').val();  
301 -  
302 - ifr = document.createElement('iframe');  
303 - ifr.src = appUrl;  
304 - ifr.style.display = 'none';  
305 - document.body.appendChild(ifr);  
306 - window.location.href = appUrl;  
307 -  
308 - time = Date.now();  
309 - window.setTimeout(function() {  
310 - document.body.removeChild(ifr);  
311 - if (Date.now() - time < 1200) {  
312 - window.location.href = 'http://a.app.qq.com/o/simple.jsp?pkgname=com.yoho';  
313 - }  
314 - }, 1000);  
315 - }, null, true); 292 + toAppPageDialog({
  293 + appUrl: $('input[name="limitCodeUrl"]').val(),
  294 + title: '进入有货APP,获取限购码'
  295 + });
316 296
317 $('.dialog-wrapper').off('touchstart').on('touchstart', function(para) { 297 $('.dialog-wrapper').off('touchstart').on('touchstart', function(para) {
318 para.stopPropagation(); 298 para.stopPropagation();
@@ -11056,9 +11056,9 @@ yo-cli@=2.1.9: @@ -11056,9 +11056,9 @@ yo-cli@=2.1.9:
11056 webpack-merge "^4.1.1" 11056 webpack-merge "^4.1.1"
11057 yargs "^10.0.3" 11057 yargs "^10.0.3"
11058 11058
11059 -yoho-activity-sdk@1.1.2:  
11060 - version "1.1.2"  
11061 - resolved "http://npm.yohops.com/yoho-activity-sdk/-/yoho-activity-sdk-1.1.2.tgz#47870af1221ad1bfb8cbb9cbc8dd4d70c5eb28bf" 11059 +yoho-activity-sdk@1.1.3:
  11060 + version "1.1.3"
  11061 + resolved "http://npm.yohops.com/yoho-activity-sdk/-/yoho-activity-sdk-1.1.3.tgz#14a8a952e1fd68cc7c167f1e6336d67262d55ba6"
11062 11062
11063 yoho-cookie@^1.2.0: 11063 yoho-cookie@^1.2.0:
11064 version "1.2.0" 11064 version "1.2.0"