Commit bf84c2c1 authored by Junling Bu's avatar Junling Bu
Browse files

update[litemall-wx,litemall-wx-api]查询商品时即返回商品所属类目。

parent b7493531
...@@ -2,12 +2,14 @@ package org.linlinjava.litemall.db.service; ...@@ -2,12 +2,14 @@ package org.linlinjava.litemall.db.service;
import com.github.pagehelper.PageHelper; import com.github.pagehelper.PageHelper;
import org.linlinjava.litemall.db.domain.LitemallGoods; 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.dao.LitemallGoodsMapper;
import org.linlinjava.litemall.db.domain.LitemallGoodsExample; import org.linlinjava.litemall.db.domain.LitemallGoodsExample;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils; import org.springframework.util.StringUtils;
import javax.annotation.Resource; import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.Random; import java.util.Random;
...@@ -88,7 +90,8 @@ public class LitemallGoodsService { ...@@ -88,7 +90,8 @@ public class LitemallGoodsService {
PageHelper.startPage(offset, limit); 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) { 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 { ...@@ -186,4 +189,31 @@ public class LitemallGoodsService {
return (int)goodsMapper.countByExample(example); 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 { ...@@ -186,45 +186,17 @@ public class WxGoodsController {
List<LitemallGoods> goodsList = goodsService.querySelective(categoryId, brandId, keyword, isHot, isNew, page, size, sortWithOrder); 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); int total = goodsService.countSelective(categoryId, brandId, keyword, isHot, isNew, page, size, sortWithOrder);
List<Integer> cats = new ArrayList<Integer>(); // 查询商品所属类目列表。
for(LitemallGoods goods : goodsList){ List<Integer> goodsCatIds = goodsService.getCatIds(brandId, keyword, isHot, isNew);
cats.add(goods.getCategoryId());
}
List<LitemallCategory> categoryList = null; List<LitemallCategory> categoryList = null;
if(cats.size() != 0) { if(goodsCatIds.size() != 0) {
categoryList = categoryService.queryL2ByIds(cats); categoryList = categoryService.queryL2ByIds(goodsCatIds);
} }
Map<String, Object> data = new HashMap(); Map<String, Object> data = new HashMap();
data.put("goodsList", goodsList); 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("filterCategoryList", categoryList);
data.put("count", total);
return ResponseUtil.ok(data); return ResponseUtil.ok(data);
} }
......
...@@ -29,7 +29,6 @@ module.exports = { ...@@ -29,7 +29,6 @@ module.exports = {
GoodsNew: WxApiRoot + 'goods/new', //新品 GoodsNew: WxApiRoot + 'goods/new', //新品
GoodsHot: WxApiRoot + 'goods/hot', //热门 GoodsHot: WxApiRoot + 'goods/hot', //热门
GoodsRelated: WxApiRoot + 'goods/related', //商品详情页的关联商品(大家都在看) GoodsRelated: WxApiRoot + 'goods/related', //商品详情页的关联商品(大家都在看)
GoodsFilter: WxApiRoot + 'goods/filter', //商品目录查询接口
BrandList: WxApiRoot + 'brand/list', //品牌列表 BrandList: WxApiRoot + 'brand/list', //品牌列表
BrandDetail: WxApiRoot + 'brand/detail', //品牌详情 BrandDetail: WxApiRoot + 'brand/detail', //品牌详情
......
...@@ -47,6 +47,7 @@ Page({ ...@@ -47,6 +47,7 @@ Page({
if (res.errno === 0) { if (res.errno === 0) {
that.setData({ that.setData({
goodsList: res.data.goodsList, goodsList: res.data.goodsList,
filterCategory: res.data.filterCategoryList
}); });
} }
}); });
...@@ -56,7 +57,6 @@ Page({ ...@@ -56,7 +57,6 @@ Page({
// 页面初始化 options为页面跳转所带来的参数 // 页面初始化 options为页面跳转所带来的参数
this.getBanner(); this.getBanner();
this.getGoodsList(); this.getGoodsList();
this.getCategoryList();
}, },
onReady: function () { onReady: function () {
// 页面渲染完成 // 页面渲染完成
......
...@@ -27,18 +27,6 @@ Page({ ...@@ -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() { getGoodsList: function() {
var that = this; var that = this;
...@@ -47,6 +35,7 @@ Page({ ...@@ -47,6 +35,7 @@ Page({
if (res.errno === 0) { if (res.errno === 0) {
that.setData({ that.setData({
goodsList: res.data.goodsList, goodsList: res.data.goodsList,
filterCategory: res.data.filterCategoryList
}); });
} }
}); });
...@@ -55,7 +44,6 @@ Page({ ...@@ -55,7 +44,6 @@ Page({
// 页面初始化 options为页面跳转所带来的参数 // 页面初始化 options为页面跳转所带来的参数
this.getBanner(); this.getBanner();
this.getGoodsList(); this.getGoodsList();
this.getCategoryList();
}, },
onReady: function () { onReady: function () {
// 页面渲染完成 // 页面渲染完成
......
...@@ -93,7 +93,7 @@ Page({ ...@@ -93,7 +93,7 @@ Page({
searchStatus: true, searchStatus: true,
categoryFilter: false, categoryFilter: false,
goodsList: res.data.goodsList, goodsList: res.data.goodsList,
filterCategory: res.data.filterCategory filterCategory: res.data.filterCategoryList
}); });
} }
...@@ -121,8 +121,8 @@ Page({ ...@@ -121,8 +121,8 @@ Page({
switch (currentId) { switch (currentId) {
case 'categoryFilter': case 'categoryFilter':
this.setData({ this.setData({
'categoryFilter': !this.data.categoryFilter, categoryFilter: !this.data.categoryFilter,
'currentSortOrder': 'asc' currentSortOrder: 'asc'
}); });
break; break;
case 'priceSort': case 'priceSort':
...@@ -131,9 +131,9 @@ Page({ ...@@ -131,9 +131,9 @@ Page({
tmpSortOrder = 'desc'; tmpSortOrder = 'desc';
} }
this.setData({ this.setData({
'currentSortType': 'price', currentSortType: 'price',
'currentSortOrder': tmpSortOrder, currentSortOrder: tmpSortOrder,
'categoryFilter': false categoryFilter: false
}); });
this.getGoodsList(); this.getGoodsList();
...@@ -141,9 +141,9 @@ Page({ ...@@ -141,9 +141,9 @@ Page({
default: default:
//综合排序 //综合排序
this.setData({ this.setData({
'currentSortType': 'default', currentSortType: 'default',
'currentSortOrder': 'desc', currentSortOrder: 'desc',
'categoryFilter': false categoryFilter: false
}); });
this.getGoodsList(); this.getGoodsList();
} }
...@@ -161,8 +161,8 @@ Page({ ...@@ -161,8 +161,8 @@ Page({
} }
} }
this.setData({ this.setData({
'filterCategory': filterCategory, filterCategory: filterCategory,
'categoryFilter': false, categoryFilter: false,
categoryId: currentCategory.id, categoryId: currentCategory.id,
page: 1, page: 1,
goodsList: [] goodsList: []
......
...@@ -2,13 +2,13 @@ ...@@ -2,13 +2,13 @@
<view class="search-header"> <view class="search-header">
<view class="input-box"> <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> <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> <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>
<view class="right" bindtap="closeSearch">取消</view> <view class="right" bindtap="closeSearch">取消</view>
</view> </view>
<view class="no-search" wx:if="{{ !searchStatus}}"> <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"> <view class="h">
<text class="title">历史记录</text> <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> <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 @@ ...@@ -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 class="item" bindtap="onKeywordTap" data-keyword="{{item}}" wx:for="{{historyKeyword}}" wx:key="keyword" hover-class="navigator-hover">{{item.keyword}}</view>
</view> </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"> <view class="h">
<text class="title">热门搜索</text> <text class="title">热门搜索</text>
</view> </view>
......
...@@ -75,7 +75,7 @@ page{ ...@@ -75,7 +75,7 @@ page{
margin-top: 91rpx; margin-top: 91rpx;
} }
.serach-keywords{ .search-keywords{
background: #fff; background: #fff;
width: 750rpx; width: 750rpx;
height: auto; height: auto;
...@@ -83,7 +83,7 @@ page{ ...@@ -83,7 +83,7 @@ page{
margin-bottom: 20rpx; margin-bottom: 20rpx;
} }
.serach-keywords .h{ .search-keywords .h{
padding: 0 31.25rpx; padding: 0 31.25rpx;
height: 93rpx; height: 93rpx;
line-height: 93rpx; line-height: 93rpx;
...@@ -92,13 +92,13 @@ page{ ...@@ -92,13 +92,13 @@ page{
font-size: 29rpx; font-size: 29rpx;
} }
.serach-keywords .title{ .search-keywords .title{
display: block; display: block;
width: 120rpx; width: 120rpx;
float: left; float: left;
} }
.serach-keywords .icon{ .search-keywords .icon{
margin-top: 19rpx; margin-top: 19rpx;
float: right; float: right;
display: block; display: block;
...@@ -107,14 +107,14 @@ page{ ...@@ -107,14 +107,14 @@ page{
width: 55rpx; width: 55rpx;
} }
.serach-keywords .b{ .search-keywords .b{
width: 750rpx; width: 750rpx;
height: auto; height: auto;
overflow: hidden; overflow: hidden;
padding-left: 31.25rpx; padding-left: 31.25rpx;
} }
.serach-keywords .item{ .search-keywords .item{
display: inline-block; display: inline-block;
width: auto; width: auto;
height: 48rpx; height: 48rpx;
...@@ -126,7 +126,7 @@ page{ ...@@ -126,7 +126,7 @@ page{
color: #333; color: #333;
} }
.serach-keywords .item.active{ .search-keywords .item.active{
color: #b4282d; color: #b4282d;
border: 1px solid #b4282d; border: 1px solid #b4282d;
} }
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment