update[litemall-wx,litemall-wx-api]查询商品时即返回商品所属类目。
This commit is contained in:
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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(cats.size() != 0) {
|
||||
categoryList = categoryService.queryL2ByIds(cats);
|
||||
if(goodsCatIds.size() != 0) {
|
||||
categoryList = categoryService.queryL2ByIds(goodsCatIds);
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
|
||||
@@ -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', //品牌详情
|
||||
|
||||
@@ -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 () {
|
||||
// 页面渲染完成
|
||||
|
||||
@@ -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 () {
|
||||
// 页面渲染完成
|
||||
|
||||
@@ -93,7 +93,7 @@ Page({
|
||||
searchStatus: true,
|
||||
categoryFilter: false,
|
||||
goodsList: res.data.goodsList,
|
||||
filterCategory: res.data.filterCategory
|
||||
filterCategory: res.data.filterCategoryList
|
||||
});
|
||||
}
|
||||
|
||||
@@ -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: []
|
||||
|
||||
@@ -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="serach-keywords search-history" wx:if="{{!keyword && historyKeyword.length}}">
|
||||
<view class="search-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="serach-keywords search-hot" wx:if="{{!keyword}}">
|
||||
<view class="search-keywords search-hot" wx:if="{{!keyword && hotKeyword.length}}">
|
||||
<view class="h">
|
||||
<text class="title">热门搜索</text>
|
||||
</view>
|
||||
|
||||
@@ -75,7 +75,7 @@ page{
|
||||
margin-top: 91rpx;
|
||||
}
|
||||
|
||||
.serach-keywords{
|
||||
.search-keywords{
|
||||
background: #fff;
|
||||
width: 750rpx;
|
||||
height: auto;
|
||||
@@ -83,7 +83,7 @@ page{
|
||||
margin-bottom: 20rpx;
|
||||
}
|
||||
|
||||
.serach-keywords .h{
|
||||
.search-keywords .h{
|
||||
padding: 0 31.25rpx;
|
||||
height: 93rpx;
|
||||
line-height: 93rpx;
|
||||
@@ -92,13 +92,13 @@ page{
|
||||
font-size: 29rpx;
|
||||
}
|
||||
|
||||
.serach-keywords .title{
|
||||
.search-keywords .title{
|
||||
display: block;
|
||||
width: 120rpx;
|
||||
float: left;
|
||||
}
|
||||
|
||||
.serach-keywords .icon{
|
||||
.search-keywords .icon{
|
||||
margin-top: 19rpx;
|
||||
float: right;
|
||||
display: block;
|
||||
@@ -107,14 +107,14 @@ page{
|
||||
width: 55rpx;
|
||||
}
|
||||
|
||||
.serach-keywords .b{
|
||||
.search-keywords .b{
|
||||
width: 750rpx;
|
||||
height: auto;
|
||||
overflow: hidden;
|
||||
padding-left: 31.25rpx;
|
||||
}
|
||||
|
||||
.serach-keywords .item{
|
||||
.search-keywords .item{
|
||||
display: inline-block;
|
||||
width: auto;
|
||||
height: 48rpx;
|
||||
@@ -126,7 +126,7 @@ page{
|
||||
color: #333;
|
||||
}
|
||||
|
||||
.serach-keywords .item.active{
|
||||
.search-keywords .item.active{
|
||||
color: #b4282d;
|
||||
border: 1px solid #b4282d;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user