diff --git a/litemall-db/src/main/java/org/linlinjava/litemall/db/service/LitemallGoodsService.java b/litemall-db/src/main/java/org/linlinjava/litemall/db/service/LitemallGoodsService.java index 5b0b9b12..678a296f 100644 --- a/litemall-db/src/main/java/org/linlinjava/litemall/db/service/LitemallGoodsService.java +++ b/litemall-db/src/main/java/org/linlinjava/litemall/db/service/LitemallGoodsService.java @@ -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 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 goodsList = goodsMapper.selectByExampleSelective(example, Column.categoryId); + List cats = new ArrayList(); + for(LitemallGoods goods : goodsList){ + cats.add(goods.getCategoryId()); + } + return cats; + } } diff --git a/litemall-wx-api/src/main/java/org/linlinjava/litemall/wx/web/WxGoodsController.java b/litemall-wx-api/src/main/java/org/linlinjava/litemall/wx/web/WxGoodsController.java index 2e7e30ab..faa481fb 100644 --- a/litemall-wx-api/src/main/java/org/linlinjava/litemall/wx/web/WxGoodsController.java +++ b/litemall-wx-api/src/main/java/org/linlinjava/litemall/wx/web/WxGoodsController.java @@ -186,45 +186,17 @@ public class WxGoodsController { List goodsList = goodsService.querySelective(categoryId, brandId, keyword, isHot, isNew, page, size, sortWithOrder); int total = goodsService.countSelective(categoryId, brandId, keyword, isHot, isNew, page, size, sortWithOrder); - List cats = new ArrayList(); - for(LitemallGoods goods : goodsList){ - cats.add(goods.getCategoryId()); - } - + // 查询商品所属类目列表。 + List goodsCatIds = goodsService.getCatIds(brandId, keyword, isHot, isNew); List categoryList = null; - if(cats.size() != 0) { - categoryList = categoryService.queryL2ByIds(cats); + if(goodsCatIds.size() != 0) { + categoryList = categoryService.queryL2ByIds(goodsCatIds); } Map 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 goodsList = goodsService.querySelective(categoryId, brandId, keyword, isHot, isNew, page, size, sortWithOrder); - int total = goodsService.countSelective(categoryId, brandId, keyword, isHot, isNew, page, size, sortWithOrder); - List cats = new ArrayList(); - for(LitemallGoods goods : goodsList){ - cats.add(goods.getCategoryId()); - } - List categoryList = categoryService.queryL2ByIds(cats); - Map data = new HashMap(); - data.put("count", total); data.put("filterCategoryList", categoryList); + data.put("count", total); return ResponseUtil.ok(data); } diff --git a/litemall-wx/config/api.js b/litemall-wx/config/api.js index cf61315e..0112869a 100644 --- a/litemall-wx/config/api.js +++ b/litemall-wx/config/api.js @@ -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', //品牌详情 diff --git a/litemall-wx/pages/hotGoods/hotGoods.js b/litemall-wx/pages/hotGoods/hotGoods.js index 47b0de38..1c7ccbde 100644 --- a/litemall-wx/pages/hotGoods/hotGoods.js +++ b/litemall-wx/pages/hotGoods/hotGoods.js @@ -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 () { // 页面渲染完成 diff --git a/litemall-wx/pages/newGoods/newGoods.js b/litemall-wx/pages/newGoods/newGoods.js index 7e41c00c..f9ca292d 100644 --- a/litemall-wx/pages/newGoods/newGoods.js +++ b/litemall-wx/pages/newGoods/newGoods.js @@ -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 () { // 页面渲染完成 diff --git a/litemall-wx/pages/search/search.js b/litemall-wx/pages/search/search.js index 93d5da02..57eae413 100644 --- a/litemall-wx/pages/search/search.js +++ b/litemall-wx/pages/search/search.js @@ -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: [] diff --git a/litemall-wx/pages/search/search.wxml b/litemall-wx/pages/search/search.wxml index 6064f64e..0fde8aca 100644 --- a/litemall-wx/pages/search/search.wxml +++ b/litemall-wx/pages/search/search.wxml @@ -2,13 +2,13 @@ - + 取消 - + 历史记录 @@ -17,7 +17,7 @@ {{item.keyword}} - + 热门搜索 diff --git a/litemall-wx/pages/search/search.wxss b/litemall-wx/pages/search/search.wxss index 7a1df44b..39d24d95 100644 --- a/litemall-wx/pages/search/search.wxss +++ b/litemall-wx/pages/search/search.wxss @@ -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; }