Authored by 郭成尧

yas-process

@@ -2,7 +2,6 @@ @@ -2,7 +2,6 @@
2 const _ = require('lodash'); 2 const _ = require('lodash');
3 const api = global.yoho.API; 3 const api = global.yoho.API;
4 const helpers = global.yoho.helpers; 4 const helpers = global.yoho.helpers;
5 -const logger = global.yoho.logger;  
6 const yasProcess = require('../../../utils/yas-process'); 5 const yasProcess = require('../../../utils/yas-process');
7 6
8 const _getProductBySkns = function(productObj, ctx) { 7 const _getProductBySkns = function(productObj, ctx) {
@@ -39,67 +38,6 @@ const _getProductBySkns = function(productObj, ctx) { @@ -39,67 +38,6 @@ const _getProductBySkns = function(productObj, ctx) {
39 }; 38 };
40 39
41 /** 40 /**
42 - * openbyStr 处理  
43 - */  
44 -const _handleOpenbyParams = (openbyStr, ctx) => {  
45 - const paramsKeyStr = 'openby:yohobuy=';  
46 -  
47 - let openByStrNew = '';  
48 - let openByParamObj = {};  
49 -  
50 - if (_.isString(openbyStr)) {  
51 - openByStrNew = _.replace(openbyStr, paramsKeyStr, '');  
52 - } else {  
53 - return openbyStr;  
54 - }  
55 -  
56 - if (_.isString(openByStrNew)) {  
57 - try {  
58 - openByParamObj = JSON.parse(openByStrNew);  
59 - } catch (error) {  
60 - logger.info(`openbyStr json parse err, raw string is ${openByStrNew}`);  
61 - }  
62 - } else {  
63 - return openbyStr;  
64 - }  
65 -  
66 - if (!_.isEmpty(openByParamObj)) {  
67 - _.assign(openByParamObj, {  
68 - from_page_name: yasProcess.getPname(ctx.req),  
69 - from_page_param: _.get(ctx, 'req.url', '')  
70 - });  
71 -  
72 - openByStrNew = `${paramsKeyStr}${JSON.stringify(openByParamObj)}`;  
73 - }  
74 -  
75 - return openByStrNew;  
76 -};  
77 -  
78 -/**  
79 - * 配置的商品添加参数  
80 - */  
81 -const _imageGoodsAddParams = (href, ctx) => {  
82 - let finalHref = '';  
83 - let paramsSplitArr = href.split('?') || [];  
84 - let paramsArr = paramsSplitArr[1].split('&');  
85 - let paramsArrNew = [];  
86 - let paramsStrNew = '';  
87 -  
88 - paramsArrNew = _.map(paramsArr, param => {  
89 - if (_.isString(param) && param.indexOf('openby:yohobuy=') !== -1) {  
90 - param = _handleOpenbyParams(param, ctx);  
91 - }  
92 -  
93 - return param;  
94 - });  
95 -  
96 - paramsStrNew = paramsArrNew.join('&');  
97 - finalHref = `${paramsSplitArr[0]}?${paramsStrNew}`;  
98 -  
99 - return finalHref;  
100 -};  
101 -  
102 -/**  
103 * 获取店铺组店铺数据 41 * 获取店铺组店铺数据
104 */ 42 */
105 const _getShopGroup = (shopRawData) => { 43 const _getShopGroup = (shopRawData) => {
@@ -183,7 +121,12 @@ class featureModel extends global.yoho.BaseModel { @@ -183,7 +121,12 @@ class featureModel extends global.yoho.BaseModel {
183 121
184 _.forEach(f.component, component => { 122 _.forEach(f.component, component => {
185 if (component.url && component.url.indexOf('go.productDetail') !== -1) { 123 if (component.url && component.url.indexOf('go.productDetail') !== -1) {
186 - component.url = _imageGoodsAddParams(component.url, self.ctx); 124 +
  125 + component.url = yasProcess.addParamsToGoodsHref({
  126 + href: component.url,
  127 + fromPageName: yasProcess.getPname(_.get(self, 'ctx.req', {})),
  128 + fromPageParam: _.get(self, 'ctx.req.path', '')
  129 + });
187 } 130 }
188 131
189 if (component.persenal_enable === '1') { 132 if (component.persenal_enable === '1') {
@@ -11,6 +11,7 @@ const headerModel = require('../../../doraemon/models/header'); @@ -11,6 +11,7 @@ const headerModel = require('../../../doraemon/models/header');
11 const saleModel = require(`${mRoot}/sale`); 11 const saleModel = require(`${mRoot}/sale`);
12 const _ = require('lodash'); 12 const _ = require('lodash');
13 const listParamsProcess = require(`${utils}/list-params-process`); 13 const listParamsProcess = require(`${utils}/list-params-process`);
  14 +const yasProcess = require(`${utils}/yas-process`);
14 15
15 const channelToAppChannel = (channel) => { 16 const channelToAppChannel = (channel) => {
16 return { 17 return {
@@ -282,6 +283,20 @@ let search = (req, res, next) => { @@ -282,6 +283,20 @@ let search = (req, res, next) => {
282 }; 283 };
283 } 284 }
284 285
  286 + if (params.from === 'seckill' && req.yoho.isApp && _.isArray(result[0])) {
  287 + _.forEach(result[0], goods => {
  288 + goods.url = yasProcess.addParamsToGoodsHref(goods.url, req);
  289 + });
  290 + }
  291 +
  292 + _.forEach(result[0], goods => {
  293 + goods.url = yasProcess.addParamsToGoodsHref({
  294 + href: goods.url,
  295 + fromPageName: yasProcess.getPname(req),
  296 + fromPageParam: req.get('referer')
  297 + });
  298 + });
  299 +
285 res.render('sale/product', Object.assign({ 300 res.render('sale/product', Object.assign({
286 layout: false, 301 layout: false,
287 params: params, 302 params: params,
  1 +const _ = require('lodash');
  2 +const logger = global.yoho.logger;
  3 +
1 const getPname = (req) => { 4 const getPname = (req) => {
2 let userAgent = req.get('User-Agent'); 5 let userAgent = req.get('User-Agent');
3 let isiOS = /\(i[^;]+;( U;)? CPU.+Mac OS X/i.test(userAgent); 6 let isiOS = /\(i[^;]+;( U;)? CPU.+Mac OS X/i.test(userAgent);
@@ -16,6 +19,76 @@ const getPname = (req) => { @@ -16,6 +19,76 @@ const getPname = (req) => {
16 return pName; 19 return pName;
17 }; 20 };
18 21
  22 +/**
  23 + * openbyStr 处理
  24 + */
  25 +const _handleOpenbyParams = (params) => {
  26 + const paramsKeyStr = 'openby:yohobuy=';
  27 +
  28 + let openByStrNew = '';
  29 + let openByParamObj = {};
  30 +
  31 + if (_.isString(params.openbyStr)) {
  32 + openByStrNew = _.replace(params.openbyStr, paramsKeyStr, '');
  33 + } else {
  34 + return params.openbyStr;
  35 + }
  36 +
  37 + if (_.isString(openByStrNew)) {
  38 + try {
  39 + openByParamObj = JSON.parse(openByStrNew);
  40 + } catch (error) {
  41 + logger.info(`openbyStr json parse err, raw string is ${openByStrNew}`);
  42 + }
  43 + } else {
  44 + return params.openbyStr;
  45 + }
  46 +
  47 + if (!_.isEmpty(openByParamObj)) {
  48 + _.assign(openByParamObj, {
  49 + from_page_name: params.fromPageName,
  50 + from_page_param: params.fromPageParam
  51 + });
  52 +
  53 + openByStrNew = `${paramsKeyStr}${JSON.stringify(openByParamObj)}`;
  54 + }
  55 +
  56 + return openByStrNew;
  57 +};
  58 +
  59 +/**
  60 + * 配置的商品添加参数
  61 + */
  62 +const addParamsToGoodsHref = (params) => {
  63 + let finalHref = '';
  64 + let paramsSplitArr = params.href.split('?') || [];
  65 + let paramsArr = _.has(paramsSplitArr, '1') ? paramsSplitArr[1].split('&') : [];
  66 + let paramsArrNew = [];
  67 + let paramsStrNew = '';
  68 +
  69 + paramsArrNew = _.map(paramsArr, param => {
  70 + if (_.isString(param) && param.indexOf('openby:yohobuy=') !== -1) {
  71 + param = _handleOpenbyParams({
  72 + openbyStr: param,
  73 + fromPageName: params.fromPageName,
  74 + fromPageParam: params.fromPageParam
  75 + });
  76 + }
  77 +
  78 + return param;
  79 + });
  80 +
  81 + if (paramsArrNew.length) {
  82 + paramsStrNew = paramsArrNew.join('&');
  83 + finalHref = `${paramsSplitArr[0]}?${paramsStrNew}`;
  84 + } else {
  85 + finalHref = params.href;
  86 + }
  87 +
  88 + return finalHref;
  89 +};
  90 +
19 module.exports = { 91 module.exports = {
20 - getPname 92 + getPname,
  93 + addParamsToGoodsHref
21 }; 94 };