Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
jinli gu
Litemall
Commits
bf84c2c1
Commit
bf84c2c1
authored
Apr 01, 2018
by
Junling Bu
Browse files
update[litemall-wx,litemall-wx-api]查询商品时即返回商品所属类目。
parent
b7493531
Changes
8
Hide whitespace changes
Inline
Side-by-side
litemall-db/src/main/java/org/linlinjava/litemall/db/service/LitemallGoodsService.java
View file @
bf84c2c1
...
...
@@ -2,12 +2,14 @@ package org.linlinjava.litemall.db.service;
import
com.github.pagehelper.PageHelper
;
import
org.linlinjava.litemall.db.domain.LitemallGoods
;
import
org.linlinjava.litemall.db.domain.LitemallGoods.Column
;
import
org.linlinjava.litemall.db.dao.LitemallGoodsMapper
;
import
org.linlinjava.litemall.db.domain.LitemallGoodsExample
;
import
org.springframework.stereotype.Service
;
import
org.springframework.util.StringUtils
;
import
javax.annotation.Resource
;
import
java.util.ArrayList
;
import
java.util.List
;
import
java.util.Random
;
...
...
@@ -88,7 +90,8 @@ public class LitemallGoodsService {
PageHelper
.
startPage
(
offset
,
limit
);
}
return
goodsMapper
.
selectByExample
(
example
);
Column
[]
columns
=
new
Column
[]{
Column
.
id
,
Column
.
name
,
Column
.
listPicUrl
,
Column
.
retailPrice
};
return
goodsMapper
.
selectByExampleSelective
(
example
,
columns
);
}
public
int
countSelective
(
Integer
catId
,
Integer
brandId
,
String
keyword
,
Integer
isHot
,
Integer
isNew
,
Integer
offset
,
Integer
limit
,
String
sort
)
{
...
...
@@ -186,4 +189,31 @@ public class LitemallGoodsService {
return
(
int
)
goodsMapper
.
countByExample
(
example
);
}
public
List
<
Integer
>
getCatIds
(
Integer
brandId
,
String
keyword
,
Integer
isHot
,
Integer
isNew
)
{
LitemallGoodsExample
example
=
new
LitemallGoodsExample
();
LitemallGoodsExample
.
Criteria
criteria
=
example
.
createCriteria
();
if
(
brandId
!=
null
){
criteria
.
andBrandIdEqualTo
(
brandId
);
}
if
(
isNew
!=
null
){
criteria
.
andIsNewEqualTo
(
isNew
.
intValue
()
==
1
);
}
if
(
isHot
!=
null
){
criteria
.
andIsHotEqualTo
(
isHot
.
intValue
()
==
1
);
}
if
(
keyword
!=
null
){
criteria
.
andKeywordsLike
(
"%"
+
keyword
+
"%"
);
}
List
<
LitemallGoods
>
goodsList
=
goodsMapper
.
selectByExampleSelective
(
example
,
Column
.
categoryId
);
List
<
Integer
>
cats
=
new
ArrayList
<
Integer
>();
for
(
LitemallGoods
goods
:
goodsList
){
cats
.
add
(
goods
.
getCategoryId
());
}
return
cats
;
}
}
litemall-wx-api/src/main/java/org/linlinjava/litemall/wx/web/WxGoodsController.java
View file @
bf84c2c1
...
...
@@ -186,45 +186,17 @@ public class WxGoodsController {
List
<
LitemallGoods
>
goodsList
=
goodsService
.
querySelective
(
categoryId
,
brandId
,
keyword
,
isHot
,
isNew
,
page
,
size
,
sortWithOrder
);
int
total
=
goodsService
.
countSelective
(
categoryId
,
brandId
,
keyword
,
isHot
,
isNew
,
page
,
size
,
sortWithOrder
);
List
<
Integer
>
cats
=
new
ArrayList
<
Integer
>();
for
(
LitemallGoods
goods
:
goodsList
){
cats
.
add
(
goods
.
getCategoryId
());
}
// 查询商品所属类目列表。
List
<
Integer
>
goodsCatIds
=
goodsService
.
getCatIds
(
brandId
,
keyword
,
isHot
,
isNew
);
List
<
LitemallCategory
>
categoryList
=
null
;
if
(
cat
s
.
size
()
!=
0
)
{
categoryList
=
categoryService
.
queryL2ByIds
(
cat
s
);
if
(
goodsCatId
s
.
size
()
!=
0
)
{
categoryList
=
categoryService
.
queryL2ByIds
(
goodsCatId
s
);
}
Map
<
String
,
Object
>
data
=
new
HashMap
();
data
.
put
(
"goodsList"
,
goodsList
);
data
.
put
(
"filterCategory"
,
categoryList
);
data
.
put
(
"count"
,
total
);
return
ResponseUtil
.
ok
(
data
);
}
/**
* 商品列表筛选的分类列表
* 1. 这里的前五个参数都是可选的,甚至都是空
*/
@RequestMapping
(
"filter"
)
public
Object
filter
(
Integer
categoryId
,
Integer
brandId
,
String
keyword
,
Integer
isNew
,
Integer
isHot
,
@RequestParam
(
value
=
"page"
,
defaultValue
=
"1"
)
Integer
page
,
@RequestParam
(
value
=
"size"
,
defaultValue
=
"10"
)
Integer
size
,
String
sort
,
String
order
)
{
String
sortWithOrder
=
SortUtil
.
goodsSort
(
sort
,
order
);
List
<
LitemallGoods
>
goodsList
=
goodsService
.
querySelective
(
categoryId
,
brandId
,
keyword
,
isHot
,
isNew
,
page
,
size
,
sortWithOrder
);
int
total
=
goodsService
.
countSelective
(
categoryId
,
brandId
,
keyword
,
isHot
,
isNew
,
page
,
size
,
sortWithOrder
);
List
<
Integer
>
cats
=
new
ArrayList
<
Integer
>();
for
(
LitemallGoods
goods
:
goodsList
){
cats
.
add
(
goods
.
getCategoryId
());
}
List
<
LitemallCategory
>
categoryList
=
categoryService
.
queryL2ByIds
(
cats
);
Map
<
String
,
Object
>
data
=
new
HashMap
();
data
.
put
(
"count"
,
total
);
data
.
put
(
"filterCategoryList"
,
categoryList
);
data
.
put
(
"count"
,
total
);
return
ResponseUtil
.
ok
(
data
);
}
...
...
litemall-wx/config/api.js
View file @
bf84c2c1
...
...
@@ -29,7 +29,6 @@ module.exports = {
GoodsNew
:
WxApiRoot
+
'
goods/new
'
,
//新品
GoodsHot
:
WxApiRoot
+
'
goods/hot
'
,
//热门
GoodsRelated
:
WxApiRoot
+
'
goods/related
'
,
//商品详情页的关联商品(大家都在看)
GoodsFilter
:
WxApiRoot
+
'
goods/filter
'
,
//商品目录查询接口
BrandList
:
WxApiRoot
+
'
brand/list
'
,
//品牌列表
BrandDetail
:
WxApiRoot
+
'
brand/detail
'
,
//品牌详情
...
...
litemall-wx/pages/hotGoods/hotGoods.js
View file @
bf84c2c1
...
...
@@ -47,6 +47,7 @@ Page({
if
(
res
.
errno
===
0
)
{
that
.
setData
({
goodsList
:
res
.
data
.
goodsList
,
filterCategory
:
res
.
data
.
filterCategoryList
});
}
});
...
...
@@ -56,7 +57,6 @@ Page({
// 页面初始化 options为页面跳转所带来的参数
this
.
getBanner
();
this
.
getGoodsList
();
this
.
getCategoryList
();
},
onReady
:
function
()
{
// 页面渲染完成
...
...
litemall-wx/pages/newGoods/newGoods.js
View file @
bf84c2c1
...
...
@@ -27,18 +27,6 @@ Page({
}
});
},
getCategoryList
:
function
()
{
var
that
=
this
;
util
.
request
(
api
.
GoodsFilter
,
{
isNew
:
1
})
.
then
(
function
(
res
)
{
if
(
res
.
errno
===
0
)
{
that
.
setData
({
filterCategory
:
res
.
data
.
filterCategoryList
,
});
}
});
},
getGoodsList
:
function
()
{
var
that
=
this
;
...
...
@@ -47,6 +35,7 @@ Page({
if
(
res
.
errno
===
0
)
{
that
.
setData
({
goodsList
:
res
.
data
.
goodsList
,
filterCategory
:
res
.
data
.
filterCategoryList
});
}
});
...
...
@@ -55,7 +44,6 @@ Page({
// 页面初始化 options为页面跳转所带来的参数
this
.
getBanner
();
this
.
getGoodsList
();
this
.
getCategoryList
();
},
onReady
:
function
()
{
// 页面渲染完成
...
...
litemall-wx/pages/search/search.js
View file @
bf84c2c1
...
...
@@ -93,7 +93,7 @@ Page({
searchStatus
:
true
,
categoryFilter
:
false
,
goodsList
:
res
.
data
.
goodsList
,
filterCategory
:
res
.
data
.
filterCategory
filterCategory
:
res
.
data
.
filterCategory
List
});
}
...
...
@@ -121,8 +121,8 @@ Page({
switch
(
currentId
)
{
case
'
categoryFilter
'
:
this
.
setData
({
'
categoryFilter
'
:
!
this
.
data
.
categoryFilter
,
'
currentSortOrder
'
:
'
asc
'
categoryFilter
:
!
this
.
data
.
categoryFilter
,
currentSortOrder
:
'
asc
'
});
break
;
case
'
priceSort
'
:
...
...
@@ -131,9 +131,9 @@ Page({
tmpSortOrder
=
'
desc
'
;
}
this
.
setData
({
'
currentSortType
'
:
'
price
'
,
'
currentSortOrder
'
:
tmpSortOrder
,
'
categoryFilter
'
:
false
currentSortType
:
'
price
'
,
currentSortOrder
:
tmpSortOrder
,
categoryFilter
:
false
});
this
.
getGoodsList
();
...
...
@@ -141,9 +141,9 @@ Page({
default
:
//综合排序
this
.
setData
({
'
currentSortType
'
:
'
default
'
,
'
currentSortOrder
'
:
'
desc
'
,
'
categoryFilter
'
:
false
currentSortType
:
'
default
'
,
currentSortOrder
:
'
desc
'
,
categoryFilter
:
false
});
this
.
getGoodsList
();
}
...
...
@@ -161,8 +161,8 @@ Page({
}
}
this
.
setData
({
'
filterCategory
'
:
filterCategory
,
'
categoryFilter
'
:
false
,
filterCategory
:
filterCategory
,
categoryFilter
:
false
,
categoryId
:
currentCategory
.
id
,
page
:
1
,
goodsList
:
[]
...
...
litemall-wx/pages/search/search.wxml
View file @
bf84c2c1
...
...
@@ -2,13 +2,13 @@
<view class="search-header">
<view class="input-box">
<image class="icon" src="http://yanxuan.nosdn.127.net/hxm/yanxuan-wap/p/20161201/style/img/icon-normal/search2-2fb94833aa.png"></image>
<input name="input" class="keywrod" focus="true" value="{{keyword}}" confirm-type="search" bindinput="inputChange" bindfocus="inputFocus" bindconfirm="onKeywordConfirm"
confirm-type="search"
placeholder="{{defaultKeyword.keyword}}" />
<input name="input" class="keywrod" focus="true" value="{{keyword}}" confirm-type="search" bindinput="inputChange" bindfocus="inputFocus" bindconfirm="onKeywordConfirm" placeholder="{{defaultKeyword.keyword}}" />
<image class="del" wx:if="{{keyword}}" bindtap="clearKeyword" src="http://nos.netease.com/mailpub/hxm/yanxuan-wap/p/20150730/style/img/icon-normal/clearIpt-f71b83e3c2.png"></image>
</view>
<view class="right" bindtap="closeSearch">取消</view>
</view>
<view class="no-search" wx:if="{{ !searchStatus}}">
<view class="se
r
ach-keywords search-history" wx:if="{{!keyword && historyKeyword.length}}">
<view class="sea
r
ch-keywords search-history" wx:if="{{!keyword && historyKeyword.length}}">
<view class="h">
<text class="title">历史记录</text>
<image class="icon" bindtap="clearHistory" src="http://nos.netease.com/mailpub/hxm/yanxuan-wap/p/20150730/style/img/icon-normal/del1-93f0a4add4.png"></image>
...
...
@@ -17,7 +17,7 @@
<view class="item" bindtap="onKeywordTap" data-keyword="{{item}}" wx:for="{{historyKeyword}}" wx:key="keyword" hover-class="navigator-hover">{{item.keyword}}</view>
</view>
</view>
<view class="se
r
ach-keywords search-hot" wx:if="{{!keyword}}">
<view class="sea
r
ch-keywords search-hot" wx:if="{{!keyword
&& hotKeyword.length
}}">
<view class="h">
<text class="title">热门搜索</text>
</view>
...
...
litemall-wx/pages/search/search.wxss
View file @
bf84c2c1
...
...
@@ -75,7 +75,7 @@ page{
margin-top: 91rpx;
}
.se
r
ach-keywords{
.sea
r
ch-keywords{
background: #fff;
width: 750rpx;
height: auto;
...
...
@@ -83,7 +83,7 @@ page{
margin-bottom: 20rpx;
}
.se
r
ach-keywords .h{
.sea
r
ch-keywords .h{
padding: 0 31.25rpx;
height: 93rpx;
line-height: 93rpx;
...
...
@@ -92,13 +92,13 @@ page{
font-size: 29rpx;
}
.se
r
ach-keywords .title{
.sea
r
ch-keywords .title{
display: block;
width: 120rpx;
float: left;
}
.se
r
ach-keywords .icon{
.sea
r
ch-keywords .icon{
margin-top: 19rpx;
float: right;
display: block;
...
...
@@ -107,14 +107,14 @@ page{
width: 55rpx;
}
.se
r
ach-keywords .b{
.sea
r
ch-keywords .b{
width: 750rpx;
height: auto;
overflow: hidden;
padding-left: 31.25rpx;
}
.se
r
ach-keywords .item{
.sea
r
ch-keywords .item{
display: inline-block;
width: auto;
height: 48rpx;
...
...
@@ -126,7 +126,7 @@ page{
color: #333;
}
.se
r
ach-keywords .item.active{
.sea
r
ch-keywords .item.active{
color: #b4282d;
border: 1px solid #b4282d;
}
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment