Toggle navigation
Toggle navigation
This project
Loading...
Sign in
fe
/
yohobuywap-node
·
Commits
Go to a project
GitLab
Go to group
Project
Activity
Files
Commits
Pipelines
0
Builds
0
Graphs
Milestones
Issues
0
Merge Requests
0
Members
Labels
Wiki
Forks
Network
Create a new issue
Download as
Email Patches
Plain Diff
Browse Files
Authored by
郭成尧
8 years ago
Commit
c897539269952f7899676d8cac1f97143e67b662
1 parent
23123be6
'search-activity-word-jump'
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
101 additions
and
97 deletions
apps/product/controllers/search.js
apps/product/controllers/search.js
View file @
c897539
...
...
@@ -25,106 +25,109 @@ const list = (req, res, next) => {
let
isQuerySecondClass
=
false
;
// 标识用户搜的是不是二级品类
let
domain
=
null
;
if
(
params
.
query
)
{
let
activity
=
_
.
get
(
searchModel
.
searchKeyActivity
(
params
.
query
),
'data.urlobj.appUrl'
,
''
);
if
(
activity
)
{
res
.
redirect
(
activity
);
}
}
if
(
params
.
shop_id
)
{
params
.
shopId
=
params
.
shop_id
;
}
/* 判断是不是品牌, 是品牌跳到品牌列表页(显示搜索框),判断是不是品类, 是品类加导航标题(不显示搜索框) */
Promise
.
all
([
searchModel
.
getAllBrandNames
(),
searchModel
.
getClassNames
()
]).
then
(
result
=>
{
if
(
query
)
{
query
=
query
.
toLowerCase
();
_
.
forEach
(
result
[
0
],
obj
=>
{
if
(
query
===
obj
.
brandDomain
)
{
// 精确查品牌域名
domain
=
query
;
return
false
;
}
if
(
query
===
obj
.
brandName
||
query
===
obj
.
brandName
||
query
===
obj
.
brandName
)
{
// 精确查品牌名称
domain
=
obj
.
brandDomain
;
return
false
;
}
// if (obj.brandDomain.indexOf(query) > 0) { // 模糊查品牌域名
// domain = obj.brandDomain;
// return false;
// }
});
// 跳转到品牌商品列表页
if
(
domain
!==
null
&&
!
params
.
shop_id
)
{
let
url
=
helpers
.
urlFormat
(
''
,
{
from
:
'search'
,
query
:
query
},
domain
);
return
res
.
redirect
(
url
);
}
// 品类名称为空时跳出
if
(
!
result
[
1
])
{
return
;
}
_
.
forEach
(
result
[
1
].
first
,
(
obj
)
=>
{
// 精确查一级品类
if
(
obj
===
query
)
{
isQueryFirstClass
=
true
;
return
false
;
}
});
_
.
forEach
(
result
[
1
].
second
,
(
obj
)
=>
{
// 精确查二级品类
if
(
obj
===
query
)
{
isQuerySecondClass
=
true
;
return
false
;
}
});
}
else
{
params
.
query
=
''
;
}
// 搜索是一级品类
if
(
isQueryFirstClass
)
{
title
=
'全部'
+
query
;
}
else
if
(
isQuerySecondClass
)
{
// 搜索是二级品类
title
=
query
;
}
else
{
// 搜索其它内容
if
(
query
||
params
.
form
)
{
params
.
search
=
{
default
:
query
===
''
?
false
:
query
,
url
:
helpers
.
urlFormat
(
''
,
null
,
'search'
)
};
if
(
params
.
query
)
{
return
searchModel
.
searchKeyActivity
(
params
.
query
).
then
(
activityResult
=>
{
let
activity
=
_
.
get
(
activityResult
,
'urlobj.appUrl'
,
''
);
if
(
activity
)
{
return
res
.
redirect
(
activity
);
}
else
{
/* 判断是不是品牌, 是品牌跳到品牌列表页(显示搜索框),判断是不是品类, 是品类加导航标题(不显示搜索框) */
return
Promise
.
all
([
searchModel
.
getAllBrandNames
(),
searchModel
.
getClassNames
()
]).
then
(
result
=>
{
if
(
query
)
{
query
=
query
.
toLowerCase
();
_
.
forEach
(
result
[
0
],
obj
=>
{
if
(
query
===
obj
.
brandDomain
)
{
// 精确查品牌域名
domain
=
query
;
return
false
;
}
if
(
query
===
obj
.
brandName
||
query
===
obj
.
brandName
||
query
===
obj
.
brandName
)
{
// 精确查品牌名称
domain
=
obj
.
brandDomain
;
return
false
;
}
// if (obj.brandDomain.indexOf(query) > 0) { // 模糊查品牌域名
// domain = obj.brandDomain;
// return false;
// }
});
// 跳转到品牌商品列表页
if
(
domain
!==
null
&&
!
params
.
shop_id
)
{
let
url
=
helpers
.
urlFormat
(
''
,
{
from
:
'search'
,
query
:
query
},
domain
);
return
res
.
redirect
(
url
);
}
// 品类名称为空时跳出
if
(
!
result
[
1
])
{
return
;
}
_
.
forEach
(
result
[
1
].
first
,
(
obj
)
=>
{
// 精确查一级品类
if
(
obj
===
query
)
{
isQueryFirstClass
=
true
;
return
false
;
}
});
_
.
forEach
(
result
[
1
].
second
,
(
obj
)
=>
{
// 精确查二级品类
if
(
obj
===
query
)
{
isQuerySecondClass
=
true
;
return
false
;
}
});
}
else
{
params
.
query
=
''
;
}
// 搜索是一级品类
if
(
isQueryFirstClass
)
{
title
=
'全部'
+
query
;
}
else
if
(
isQuerySecondClass
)
{
// 搜索是二级品类
title
=
query
;
}
else
{
// 搜索其它内容
if
(
query
||
params
.
form
)
{
params
.
search
=
{
default
:
query
===
''
?
false
:
query
,
url
:
helpers
.
urlFormat
(
''
,
null
,
'search'
)
};
}
title
=
'搜索'
;
}
title
=
params
.
title
?
params
.
title
:
title
;
res
.
render
(
'search/list'
,
{
module
:
'product'
,
page
:
'search-list'
,
pageHeader
:
headerModel
.
setNav
({
navTitle
:
title
}),
title
:
title
,
goodList
:
params
,
pageFooter
:
true
});
}).
catch
(
next
);
}
title
=
'搜索'
;
}
title
=
params
.
title
?
params
.
title
:
title
;
res
.
render
(
'search/list'
,
{
module
:
'product'
,
page
:
'search-list'
,
pageHeader
:
headerModel
.
setNav
({
navTitle
:
title
}),
title
:
title
,
goodList
:
params
,
pageFooter
:
true
});
}
).
catch
(
next
);
}
};
/**
...
...
@@ -132,6 +135,7 @@ const list = (req, res, next) => {
*/
const
index
=
(
req
,
res
,
next
)
=>
{
let
title
=
'搜索'
;
((
render
)
=>
{
if
(
_
.
get
(
req
,
'app.locals.wap.search.removeHotSearch'
,
false
))
{
render
([]);
...
...
@@ -140,7 +144,7 @@ const index = (req, res, next) => {
render
(
result
);
}).
catch
(
next
);
}
})((
result
)
=>
{
res
.
render
(
'search/index'
,
{
module
:
'product'
,
...
...
@@ -156,8 +160,8 @@ const index = (req, res, next) => {
}
});
})
});
};
/**
...
...
Please
register
or
login
to post a comment