Toggle navigation
Toggle navigation
This project
Loading...
Sign in
fe
/
yohobuy-node
·
Commits
Go to a project
GitLab
Go to group
Project
Activity
Files
Commits
Pipelines
0
Builds
0
Graphs
Milestones
Issues
1
Merge Requests
0
Members
Labels
Wiki
Forks
Network
Create a new issue
Download as
Email Patches
Plain Diff
Browse Files
Authored by
刘传洋
9 years ago
Commit
5da2955009842cb5baec0381cc41072ecc496e6a
1 parent
3879bea6
search bug mod
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
153 additions
and
24 deletions
apps/product/models/search-api.js
apps/product/models/search-handler.js
apps/product/models/search.js
apps/product/views/partial/list/shop-entry.hbs
apps/product/models/search-api.js
View file @
5da2955
...
...
@@ -10,6 +10,9 @@ const api = global.yoho.SearchAPI;
const
yohoApi
=
global
.
yoho
.
API
;
const
serviceApi
=
global
.
yoho
.
ServiceAPI
;
const
_
=
require
(
'lodash'
);
const
helpers
=
global
.
yoho
.
helpers
;
const
images
=
require
(
'../../../utils/images.js'
);
const
getSortByConditionAsync
=
(
condition
)
=>
{
return
api
.
get
(
'sortgroup.json'
,
condition
);
...
...
@@ -37,18 +40,7 @@ const getProductList = (params) => {
limit
:
60
};
let
nparams
=
{};
if
(
params
&&
params
.
price
)
{
let
mp
=
params
.
price
.
split
(
','
);
let
nmp
=
[];
nmp
[
0
]
=
(
mp
&&
mp
[
0
])
||
0
;
nmp
[
1
]
=
(
mp
&&
mp
[
1
])
||
99999
;
nparams
.
price
=
nmp
.
join
(
','
);
}
Object
.
assign
(
finalParams
,
params
,
nparams
);
Object
.
assign
(
finalParams
,
params
);
return
yohoApi
.
get
(
''
,
finalParams
);
};
...
...
@@ -151,14 +143,145 @@ const getWeekNew = (params) => {
* 根据关键词搜索品牌店铺信息 TODO
* @return
*/
const
getBrandShop
=
(
params
)
=>
{
const
getBrandShop
=
(
query
)
=>
{
let
finalParams
=
{
// method: 'web.regular.groupsort'
method
:
'
app.search.li
'
method
:
'
web.search.shopInfo
'
};
Object
.
assign
(
finalParams
,
params
);
return
yohoApi
.
get
(
''
,
finalParams
);
Object
.
assign
(
finalParams
,
{
keyword
:
query
});
return
yohoApi
.
get
(
''
,
finalParams
).
then
(
ret
=>
{
if
(
ret
&&
ret
.
code
===
200
)
{
return
ret
.
data
;
}
});
};
/**
* 根据品牌ID获取品牌下的店铺
* @return
*/
const
getShopsByBrandId
=
bid
=>
{
return
yohoApi
.
get
(
''
,
{
method
:
'app.shop.queryShopsByBrandId'
,
brand_id
:
bid
}).
then
(
ret
=>
{
if
(
ret
&&
ret
.
code
===
200
)
{
return
ret
.
data
;
}
});
};
const
shopFormat
=
shopDatas
=>
{
let
shopEntry
=
[];
_
.
forEach
(
shopDatas
,
val
=>
{
let
sorts
=
[];
let
shopId
=
val
.
shop
&&
(
val
.
shop
.
brand_id
||
val
.
shop
.
id
)
||
''
;
// 接口中品牌下的店铺为brand_id,品牌为id
let
url
=
helpers
.
urlFormat
(
''
,
{
shopId
:
shopId
},
val
.
shop
.
brand_domain
);
if
(
val
.
shopSort
)
{
for
(
let
ss
of
val
.
shopSort
)
{
if
(
!
ss
.
sub
)
{
continue
;
}
let
isFull
=
false
;
for
(
let
misort
of
ss
.
sub
)
{
if
(
sorts
.
length
>=
10
)
{
isFull
=
true
;
break
;
}
sorts
.
push
({
href
:
`
$
{
url
}
&
msort
=
$
{
ss
.
sort_id
}
&
misort
=
$
{
misort
.
sort_id
}
`
,
name
:
misort
.
sort_name
});
}
if
(
isFull
)
{
break
;
}
}
}
shopEntry
.
push
({
home
:
url
,
logo
:
images
.
getImageUrl
(
val
.
shop
.
brand_ico
,
80
,
50
,
1
,
'brandLogo'
),
shopName
:
val
.
shop
.
brand_name
,
sort
:
sorts
});
});
return
shopEntry
;
};
/**
* 根据搜索得到店铺/品牌 列表
*/
const
getShopList
=
params
=>
{
if
(
!
params
||
!
params
.
query
)
{
return
;
}
let
brandShop
;
let
brandShops
;
return
getBrandShop
(
params
.
query
).
then
(
shop
=>
{
// 获取品牌,并根据品牌获取品牌下的所有店铺
if
(
!
shop
||
!
shop
.
id
)
{
return
;
}
brandShop
=
shop
;
return
getShopsByBrandId
(
shop
.
id
).
then
(
shops
=>
{
if
(
shops
&&
shops
.
length
)
{
return
shops
;
}
else
{
return
shop
;
}
});
}).
then
(
shops
=>
{
// 获取品牌/品牌店下所有的分类
if
(
_
.
isArray
(
shops
))
{
brandShops
=
shops
;
let
promises
=
[];
for
(
let
s
of
shops
)
{
promises
.
push
(
getSortList
({
brand
:
s
.
brand_id
}));
}
return
Promise
.
all
(
promises
);
}
else
if
(
shops
&&
shops
.
id
)
{
return
getSortList
({
brand
:
shops
.
id
});
}
}).
then
(
sorts
=>
{
// 数组则为品牌店列表,否则为品牌
let
shopData
=
[];
if
(
_
.
isArray
(
sorts
))
{
_
.
forEach
(
sorts
,
(
val
,
index
)
=>
{
shopData
.
push
({
shop
:
brandShops
[
index
],
shopSort
:
val
&&
val
.
data
&&
val
.
data
.
sort
});
});
}
else
if
(
sorts
&&
sorts
.
code
===
200
&&
sorts
.
data
)
{
shopData
.
push
({
shop
:
brandShop
,
shopSort
:
sorts
.
data
.
sort
});
}
return
shopFormat
(
shopData
);
});
};
/**
...
...
@@ -258,7 +381,8 @@ module.exports = {
getShopInfo
,
getShopBrands
,
getShopDecorator
,
getArticleByBrand
getArticleByBrand
,
getShopList
};
...
...
apps/product/models/search-handler.js
View file @
5da2955
...
...
@@ -632,15 +632,18 @@ exports.handleFilterData = (origin, params, total) => {
// 处理年龄段
if
(
!
_
.
isEmpty
(
origin
.
ageLevel
))
{
// 只有一个默认选中
let
isChecked
=
origin
.
ageLevel
.
length
===
1
;
_
.
forEach
(
origin
.
ageLevel
,
(
value
)
=>
{
let
ageLevel
=
{
checked
:
params
.
ageLevel
===
value
.
id
,
checked
:
params
.
ageLevel
===
value
.
id
||
isChecked
,
href
:
handleFilterUrl
(
params
,
{
ageLevel
:
value
.
id
}),
name
:
value
.
name
};
// 处理颜色年龄段数据
if
(
ageLevel
.
checked
)
{
if
(
ageLevel
.
checked
||
isChecked
)
{
ageLevel
.
href
=
handleFilterUrl
(
params
,
null
,
{
ageLevel
:
value
.
id
});
dest
.
checkedConditions
.
conditions
.
push
(
ageLevel
);
}
...
...
apps/product/models/search.js
View file @
5da2955
...
...
@@ -35,13 +35,14 @@ exports.getSearchData = (params) => {
let
apiMethod
=
[
headerModel
.
requestHeaderData
(),
searchApi
.
getSortList
(
Object
.
assign
({},
params
,
nparams
)),
searchApi
.
getProductList
(
Object
.
assign
({},
params
,
{
limit
:
mlimit
},
nparams
))
searchApi
.
getProductList
(
Object
.
assign
({},
params
,
{
limit
:
mlimit
},
nparams
)),
searchApi
.
getShopList
(
params
)
];
// 搜索店铺
if
(
params
.
query
)
{
/*
if (params.query) {
apiMethod.push(searchApi.getBrandShop(params.query));
}
}
*/
return
api
.
all
(
apiMethod
).
then
(
result
=>
{
let
finalResult
=
{
...
...
@@ -69,7 +70,8 @@ exports.getSearchData = (params) => {
goods
:
productProcess
.
processProductList
(
result
[
2
].
data
.
product_list
,
Object
.
assign
({
showDiscount
:
false
},
params
)),
latestWalk
:
7
,
hasNextPage
:
searchHandler
.
handleNextPage
(
params
,
result
[
2
].
data
.
total
)
// ,
hasNextPage
:
searchHandler
.
handleNextPage
(
params
,
result
[
2
].
data
.
total
),
shopEntry
:
result
[
3
]
// ,
// brandBanner : isset($data['brand']) && !empty($data['brand']) ? self::getBannerFormat($data['brand'], $options['brandBanner']) : array();
});
}
...
...
apps/product/views/partial/list/shop-entry.hbs
View file @
5da2955
...
...
@@ -20,7 +20,7 @@
<a
class=
"entry-btn pull-right"
href=
"
{{
home
}}
"
>
进入品牌店铺
<span
class=
"iconfont"
>
๠
1
;
</span>
<span
class=
"iconfont"
>
๠
c
;
</span>
</a>
</div>
{{/
shopEntry
}}
...
...
Please
register
or
login
to post a comment