diff --git a/litemall-db/src/main/java/org/linlinjava/litemall/db/service/LitemallGrouponRulesService.java b/litemall-db/src/main/java/org/linlinjava/litemall/db/service/LitemallGrouponRulesService.java index 4c677192..bc553fb7 100644 --- a/litemall-db/src/main/java/org/linlinjava/litemall/db/service/LitemallGrouponRulesService.java +++ b/litemall-db/src/main/java/org/linlinjava/litemall/db/service/LitemallGrouponRulesService.java @@ -2,19 +2,26 @@ package org.linlinjava.litemall.db.service; import com.alibaba.druid.util.StringUtils; import com.github.pagehelper.PageHelper; +import org.linlinjava.litemall.db.dao.LitemallGoodsMapper; import org.linlinjava.litemall.db.dao.LitemallGrouponRulesMapper; +import org.linlinjava.litemall.db.domain.LitemallGoods; import org.linlinjava.litemall.db.domain.LitemallGrouponRules; import org.linlinjava.litemall.db.domain.LitemallGrouponRulesExample; import org.springframework.stereotype.Service; import javax.annotation.Resource; import java.time.LocalDateTime; +import java.util.ArrayList; +import java.util.HashMap; import java.util.List; +import java.util.Map; @Service public class LitemallGrouponRulesService { @Resource - LitemallGrouponRulesMapper mapper; + private LitemallGrouponRulesMapper mapper; + @Resource + private LitemallGoodsMapper goodsMapper; public int createRules(LitemallGrouponRules rules) { return mapper.insertSelective(rules); @@ -51,12 +58,39 @@ public class LitemallGrouponRulesService { * @param limit * @return */ - public List queryByIndex(int offset, int limit) { + public List> queryList(int offset, int limit) { + return queryList(offset, limit, "add_time", "desc"); + } + + private LitemallGoods.Column[] goodsColumns = new LitemallGoods.Column[]{LitemallGoods.Column.id, LitemallGoods.Column.name, LitemallGoods.Column.brief, LitemallGoods.Column.picUrl, LitemallGoods.Column.counterPrice, LitemallGoods.Column.retailPrice}; + public List> queryList(int offset, int limit, String sort, String order) { LitemallGrouponRulesExample example = new LitemallGrouponRulesExample(); example.or().andDeletedEqualTo(false); - example.orderBy("add_time desc"); + example.setOrderByClause(sort + " " + order); PageHelper.startPage(offset, limit); - return mapper.selectByExample(example); + List grouponRules = mapper.selectByExample(example); + + List> grouponList = new ArrayList<>(grouponRules.size()); + for (LitemallGrouponRules rule : grouponRules) { + Integer goodsId = rule.getGoodsId(); + LitemallGoods goods = goodsMapper.selectByPrimaryKeySelective(goodsId, goodsColumns); + if (goods == null) + continue; + + Map item = new HashMap<>(); + item.put("goods", goods); + item.put("groupon_price", goods.getRetailPrice().subtract(rule.getDiscount())); + item.put("groupon_member", rule.getDiscountMember()); + grouponList.add(item); + } + + return grouponList; + } + + public int countList(int offset, int limit, String sort, String order) { + LitemallGrouponRulesExample example = new LitemallGrouponRulesExample(); + example.or().andDeletedEqualTo(false); + return (int)mapper.countByExample(example); } /** @@ -80,6 +114,8 @@ public class LitemallGrouponRulesService { */ public List querySelective(String goodsId, Integer page, Integer size, String sort, String order) { LitemallGrouponRulesExample example = new LitemallGrouponRulesExample(); + example.setOrderByClause(sort + " " + order); + LitemallGrouponRulesExample.Criteria criteria = example.createCriteria(); if (!StringUtils.isEmpty(goodsId)) { diff --git a/litemall-wx-api/src/main/java/org/linlinjava/litemall/wx/web/WxGrouponController.java b/litemall-wx-api/src/main/java/org/linlinjava/litemall/wx/web/WxGrouponController.java index b60b7793..3bb39bd8 100644 --- a/litemall-wx-api/src/main/java/org/linlinjava/litemall/wx/web/WxGrouponController.java +++ b/litemall-wx-api/src/main/java/org/linlinjava/litemall/wx/web/WxGrouponController.java @@ -3,6 +3,8 @@ package org.linlinjava.litemall.wx.web; import org.linlinjava.litemall.core.express.ExpressService; import org.linlinjava.litemall.core.express.dao.ExpressInfo; import org.linlinjava.litemall.core.util.ResponseUtil; +import org.linlinjava.litemall.core.validator.Order; +import org.linlinjava.litemall.core.validator.Sort; import org.linlinjava.litemall.db.domain.*; import org.linlinjava.litemall.db.service.*; import org.linlinjava.litemall.db.util.OrderUtil; @@ -42,6 +44,40 @@ public class WxGrouponController { private LitemallUserService userService; @Autowired private ExpressService expressService; + @Autowired + private LitemallGrouponRulesService grouponRulesService; + + + /** + * 专题列表 + * + * @param page 分页页数 + * @param size 分页大小 + * @return 专题列表 + * 成功则 + * { + * errno: 0, + * errmsg: '成功', + * data: + * { + * data: xxx, + * count: xxx + * } + * } + * 失败则 { errno: XXX, errmsg: XXX } + */ + @GetMapping("list") + public Object list(@RequestParam(defaultValue = "1") Integer page, + @RequestParam(defaultValue = "10") Integer size, + @Sort @RequestParam(defaultValue = "add_time") String sort, + @Order @RequestParam(defaultValue = "desc") String order) { + Object topicList = grouponRulesService.queryList(page, size, sort, order); + int total = grouponRulesService.countList(page, size, sort, order); + Map data = new HashMap(); + data.put("data", topicList); + data.put("count", total); + return ResponseUtil.ok(data); + } @GetMapping("detail") public Object detail(@LoginUser Integer userId, @NotNull Integer grouponId) { diff --git a/litemall-wx-api/src/main/java/org/linlinjava/litemall/wx/web/WxHomeController.java b/litemall-wx-api/src/main/java/org/linlinjava/litemall/wx/web/WxHomeController.java index abcb780c..d4a83505 100644 --- a/litemall-wx-api/src/main/java/org/linlinjava/litemall/wx/web/WxHomeController.java +++ b/litemall-wx-api/src/main/java/org/linlinjava/litemall/wx/web/WxHomeController.java @@ -99,24 +99,8 @@ public class WxHomeController { List topicList = topicService.queryList(0, SystemConfig.getTopicLimit()); data.put("topicList", topicList); - //优惠专区 - List grouponRules = grouponRulesService.queryByIndex(0, 5); - List grouponGoods = new ArrayList<>(); - List> grouponList = new ArrayList<>(); - for (LitemallGrouponRules rule : grouponRules) { - LitemallGoods goods = goodsService.findByIdVO(rule.getGoodsId()); - if (goods == null) - continue; - - if (!grouponGoods.contains(goods)) { - Map item = new HashMap<>(); - item.put("goods", goods); - item.put("groupon_price", goods.getRetailPrice().subtract(rule.getDiscount())); - item.put("groupon_member", rule.getDiscountMember()); - grouponList.add(item); - grouponGoods.add(goods); - } - } + //团购专区 + List> grouponList = grouponRulesService.queryList(0, 5); data.put("grouponList", grouponList); List categoryList = new ArrayList<>(); diff --git a/litemall-wx/app.json b/litemall-wx/app.json index 9553e838..113eb763 100644 --- a/litemall-wx/app.json +++ b/litemall-wx/app.json @@ -33,7 +33,8 @@ "pages/goods/goods", "pages/about/about", "pages/groupon/myGroupon/myGroupon", - "pages/groupon/grouponDetail/grouponDetail" + "pages/groupon/grouponDetail/grouponDetail", + "pages/groupon/grouponList/grouponList" ], "window": { "navigationBarBackgroundColor": "#FFFFFF", diff --git a/litemall-wx/config/api.js b/litemall-wx/config/api.js index 57e611f3..cd5e9259 100644 --- a/litemall-wx/config/api.js +++ b/litemall-wx/config/api.js @@ -82,6 +82,7 @@ module.exports = { UserFormIdCreate: WxApiRoot + 'formid/create', //用户FromId,用于发送模版消息 + GroupOnList: WxApiRoot + 'groupon/list', //团购列表 GroupOn: WxApiRoot + 'groupon/query', //团购API-查询 GroupOnMy: WxApiRoot + 'groupon/my', //团购API-我的团购 GroupOnDetail: WxApiRoot + 'groupon/detail', //团购API-详情 diff --git a/litemall-wx/pages/groupon/grouponList/grouponList.js b/litemall-wx/pages/groupon/grouponList/grouponList.js new file mode 100644 index 00000000..c00d1d51 --- /dev/null +++ b/litemall-wx/pages/groupon/grouponList/grouponList.js @@ -0,0 +1,129 @@ +// pages/groupon/grouponList/grouponList.js +var util = require('../../../utils/util.js'); +var api = require('../../../config/api.js'); +var app = getApp(); + +Page({ + + /** + * 页面的初始数据 + */ + data: { + grouponList: [], + page: 1, + size: 10, + count: 0, + scrollTop: 0, + showPage: false + }, + + /** + * 生命周期函数--监听页面加载 + */ + onLoad: function (options) { + this.getGrouponList(); + }, + + /** + * 生命周期函数--监听页面初次渲染完成 + */ + onReady: function () { + + }, + + /** + * 生命周期函数--监听页面显示 + */ + onShow: function () { + + }, + + /** + * 生命周期函数--监听页面隐藏 + */ + onHide: function () { + + }, + + /** + * 生命周期函数--监听页面卸载 + */ + onUnload: function () { + + }, + + /** + * 页面相关事件处理函数--监听用户下拉动作 + */ + onPullDownRefresh: function () { + + }, + + /** + * 页面上拉触底事件的处理函数 + */ + onReachBottom: function () { + + }, + + /** + * 用户点击右上角分享 + */ + onShareAppMessage: function () { + + }, + getGrouponList: function () { + + let that = this; + that.setData({ + scrollTop: 0, + showPage: false, + grouponList: [] + }); + // 页面渲染完成 + wx.showToast({ + title: '加载中...', + icon: 'loading', + duration: 2000 + }); + + util.request(api.GroupOnList, { page: that.data.page, size: that.data.size }).then(function (res) { + if (res.errno === 0) { + + that.setData({ + scrollTop: 0, + grouponList: res.data.data, + showPage: true, + count: res.data.count + }); + } + wx.hideToast(); + }); + + }, + nextPage: function (event) { + var that = this; + if (this.data.page > that.data.count / that.data.size) { + return true; + } + + + that.setData({ + page: that.data.page + 1 + }); + + this.getTopic(); + + }, + prevPage: function (event) { + if (this.data.page <= 1) { + return false; + } + + var that = this; + that.setData({ + page: that.data.page - 1 + }); + this.getTopic(); + } +}) \ No newline at end of file diff --git a/litemall-wx/pages/groupon/grouponList/grouponList.json b/litemall-wx/pages/groupon/grouponList/grouponList.json new file mode 100644 index 00000000..aff9451f --- /dev/null +++ b/litemall-wx/pages/groupon/grouponList/grouponList.json @@ -0,0 +1,6 @@ +{ + "navigationBarTitleText": "团购专区", + "usingComponents": { + "zan-capsule": "../../../lib/zanui-weapp/capsule/index" + } +} \ No newline at end of file diff --git a/litemall-wx/pages/groupon/grouponList/grouponList.wxml b/litemall-wx/pages/groupon/grouponList/grouponList.wxml new file mode 100644 index 00000000..29f30173 --- /dev/null +++ b/litemall-wx/pages/groupon/grouponList/grouponList.wxml @@ -0,0 +1,30 @@ + + + + + + + + + + {{item.goods.name}} + + + + + {{item.goods.brief}} + + 原价:¥{{item.goods.counterPrice}} + 现价:¥{{item.groupon_price}} + + + + + + + + 上一页 + 下一页 + + + \ No newline at end of file diff --git a/litemall-wx/pages/groupon/grouponList/grouponList.wxss b/litemall-wx/pages/groupon/grouponList/grouponList.wxss new file mode 100644 index 00000000..6f0e9526 --- /dev/null +++ b/litemall-wx/pages/groupon/grouponList/grouponList.wxss @@ -0,0 +1,123 @@ +page ,.container{ + width: 750rpx; + height: 100%; + overflow: hidden; + background: #f4f4f4; +} +.groupon-list{ + width: 750rpx; + height: 100%; + overflow: hidden; + background: #f4f4f4; +} + +.groupon-list { + width: 750rpx; + height: auto; + overflow: hidden; +} + +.groupon-list .item { + border-top: 1px solid #d9d9d9; + margin: 0 20rpx; + height: 244rpx; + width: 710rpx; +} + +.groupon-list .img { + margin-top: 12rpx; + margin-right: 12rpx; + float: left; + width: 220rpx; + height: 220rpx; +} + +.groupon-list .right { + float: left; + height: 244rpx; + width: 476rpx; + display: flex; + flex-flow: row nowrap; +} + +.groupon-list .text { + display: flex; + flex-wrap: nowrap; + flex-direction: column; + justify-content: center; + overflow: hidden; + height: 244rpx; + width: 476rpx; +} + +.groupon-list .name { + float: left; + width: 330rpx; + display: block; + color: #333; + line-height: 50rpx; + font-size: 30rpx; +} + +.groupon-list .capsule-tag { + float: right; + padding-right: 0rpx; + padding-top: 8rpx; +} + +.groupon-list .zan-capsule + .zan-capsule { + margin-left: 10px; +} + +.groupon-list .desc { + width: 476rpx; + display: block; + color: #999; + line-height: 50rpx; + font-size: 25rpx; +} + +.groupon-list .price { + width: 476rpx; + display: flex; + color: #AB956D; + line-height: 50rpx; + font-size: 33rpx; +} + +.groupon-list .counterPrice { + text-decoration: line-through; + font-size: 28rpx; + color: #999; +} + +.groupon-list .retailPrice { + margin-left: 30rpx; + font-size: 28rpx; + color: #a78845; +} + +.page{ + width: 750rpx; + height: 108rpx; + background: #fff; + margin-bottom: 20rpx; +} + +.page view{ + height: 108rpx; + width: 50%; + float: left; + font-size: 29rpx; + color: #333; + text-align: center; + line-height: 108rpx; +} + +.page .prev{ + border-right: 1px solid #D9D9D9; +} + +.page .disabled{ + color: #ccc; +} \ No newline at end of file diff --git a/litemall-wx/pages/index/index.wxml b/litemall-wx/pages/index/index.wxml index 45b068ae..00ac5b88 100644 --- a/litemall-wx/pages/index/index.wxml +++ b/litemall-wx/pages/index/index.wxml @@ -18,9 +18,9 @@ - - 优惠专区 - + + 团购专区 + diff --git a/renard-wx/config/api.js b/renard-wx/config/api.js index 368d927d..b03b1b44 100644 --- a/renard-wx/config/api.js +++ b/renard-wx/config/api.js @@ -78,6 +78,7 @@ module.exports = { UserFormIdCreate: WxApiRoot + 'formid/create', //用户FromId,用于发送模版消息 + GroupOnList: WxApiRoot + 'groupon/list', //团购列表 GroupOn: WxApiRoot + 'groupon/query', //团购API-查询 GroupOnMy: WxApiRoot + 'groupon/my', //团购API-我的团购 GroupOnDetail: WxApiRoot + 'groupon/detail', //团购API-详情 diff --git a/renard-wx/pages/groupon/grouponList/grouponList.js b/renard-wx/pages/groupon/grouponList/grouponList.js new file mode 100644 index 00000000..c00d1d51 --- /dev/null +++ b/renard-wx/pages/groupon/grouponList/grouponList.js @@ -0,0 +1,129 @@ +// pages/groupon/grouponList/grouponList.js +var util = require('../../../utils/util.js'); +var api = require('../../../config/api.js'); +var app = getApp(); + +Page({ + + /** + * 页面的初始数据 + */ + data: { + grouponList: [], + page: 1, + size: 10, + count: 0, + scrollTop: 0, + showPage: false + }, + + /** + * 生命周期函数--监听页面加载 + */ + onLoad: function (options) { + this.getGrouponList(); + }, + + /** + * 生命周期函数--监听页面初次渲染完成 + */ + onReady: function () { + + }, + + /** + * 生命周期函数--监听页面显示 + */ + onShow: function () { + + }, + + /** + * 生命周期函数--监听页面隐藏 + */ + onHide: function () { + + }, + + /** + * 生命周期函数--监听页面卸载 + */ + onUnload: function () { + + }, + + /** + * 页面相关事件处理函数--监听用户下拉动作 + */ + onPullDownRefresh: function () { + + }, + + /** + * 页面上拉触底事件的处理函数 + */ + onReachBottom: function () { + + }, + + /** + * 用户点击右上角分享 + */ + onShareAppMessage: function () { + + }, + getGrouponList: function () { + + let that = this; + that.setData({ + scrollTop: 0, + showPage: false, + grouponList: [] + }); + // 页面渲染完成 + wx.showToast({ + title: '加载中...', + icon: 'loading', + duration: 2000 + }); + + util.request(api.GroupOnList, { page: that.data.page, size: that.data.size }).then(function (res) { + if (res.errno === 0) { + + that.setData({ + scrollTop: 0, + grouponList: res.data.data, + showPage: true, + count: res.data.count + }); + } + wx.hideToast(); + }); + + }, + nextPage: function (event) { + var that = this; + if (this.data.page > that.data.count / that.data.size) { + return true; + } + + + that.setData({ + page: that.data.page + 1 + }); + + this.getTopic(); + + }, + prevPage: function (event) { + if (this.data.page <= 1) { + return false; + } + + var that = this; + that.setData({ + page: that.data.page - 1 + }); + this.getTopic(); + } +}) \ No newline at end of file diff --git a/renard-wx/pages/groupon/grouponList/grouponList.json b/renard-wx/pages/groupon/grouponList/grouponList.json new file mode 100644 index 00000000..20418036 --- /dev/null +++ b/renard-wx/pages/groupon/grouponList/grouponList.json @@ -0,0 +1,6 @@ +{ + "navigationBarTitleText": "团购专区", + "usingComponents": { + "zan-capsule": "/components/capsule/index" +} +} \ No newline at end of file diff --git a/renard-wx/pages/groupon/grouponList/grouponList.wxml b/renard-wx/pages/groupon/grouponList/grouponList.wxml new file mode 100644 index 00000000..29f30173 --- /dev/null +++ b/renard-wx/pages/groupon/grouponList/grouponList.wxml @@ -0,0 +1,30 @@ + + + + + + + + + + {{item.goods.name}} + + + + + {{item.goods.brief}} + + 原价:¥{{item.goods.counterPrice}} + 现价:¥{{item.groupon_price}} + + + + + + + + 上一页 + 下一页 + + + \ No newline at end of file diff --git a/renard-wx/pages/groupon/grouponList/grouponList.wxss b/renard-wx/pages/groupon/grouponList/grouponList.wxss new file mode 100644 index 00000000..6f0e9526 --- /dev/null +++ b/renard-wx/pages/groupon/grouponList/grouponList.wxss @@ -0,0 +1,123 @@ +page ,.container{ + width: 750rpx; + height: 100%; + overflow: hidden; + background: #f4f4f4; +} +.groupon-list{ + width: 750rpx; + height: 100%; + overflow: hidden; + background: #f4f4f4; +} + +.groupon-list { + width: 750rpx; + height: auto; + overflow: hidden; +} + +.groupon-list .item { + border-top: 1px solid #d9d9d9; + margin: 0 20rpx; + height: 244rpx; + width: 710rpx; +} + +.groupon-list .img { + margin-top: 12rpx; + margin-right: 12rpx; + float: left; + width: 220rpx; + height: 220rpx; +} + +.groupon-list .right { + float: left; + height: 244rpx; + width: 476rpx; + display: flex; + flex-flow: row nowrap; +} + +.groupon-list .text { + display: flex; + flex-wrap: nowrap; + flex-direction: column; + justify-content: center; + overflow: hidden; + height: 244rpx; + width: 476rpx; +} + +.groupon-list .name { + float: left; + width: 330rpx; + display: block; + color: #333; + line-height: 50rpx; + font-size: 30rpx; +} + +.groupon-list .capsule-tag { + float: right; + padding-right: 0rpx; + padding-top: 8rpx; +} + +.groupon-list .zan-capsule + .zan-capsule { + margin-left: 10px; +} + +.groupon-list .desc { + width: 476rpx; + display: block; + color: #999; + line-height: 50rpx; + font-size: 25rpx; +} + +.groupon-list .price { + width: 476rpx; + display: flex; + color: #AB956D; + line-height: 50rpx; + font-size: 33rpx; +} + +.groupon-list .counterPrice { + text-decoration: line-through; + font-size: 28rpx; + color: #999; +} + +.groupon-list .retailPrice { + margin-left: 30rpx; + font-size: 28rpx; + color: #a78845; +} + +.page{ + width: 750rpx; + height: 108rpx; + background: #fff; + margin-bottom: 20rpx; +} + +.page view{ + height: 108rpx; + width: 50%; + float: left; + font-size: 29rpx; + color: #333; + text-align: center; + line-height: 108rpx; +} + +.page .prev{ + border-right: 1px solid #D9D9D9; +} + +.page .disabled{ + color: #ccc; +} \ No newline at end of file diff --git a/renard-wx/pages/index/index.wxml b/renard-wx/pages/index/index.wxml index ed52a6d2..e02d7671 100644 --- a/renard-wx/pages/index/index.wxml +++ b/renard-wx/pages/index/index.wxml @@ -42,9 +42,9 @@ - - 优惠专区 - + + 优惠专区 +