Commit 30a8efdd authored by Junling Bu's avatar Junling Bu
Browse files

团团购专区页面

parent 59966c7c
......@@ -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<LitemallGrouponRules> queryByIndex(int offset, int limit) {
public List<Map<String, Object>> 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<Map<String, Object>> 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<LitemallGrouponRules> grouponRules = mapper.selectByExample(example);
List<Map<String, Object>> grouponList = new ArrayList<>(grouponRules.size());
for (LitemallGrouponRules rule : grouponRules) {
Integer goodsId = rule.getGoodsId();
LitemallGoods goods = goodsMapper.selectByPrimaryKeySelective(goodsId, goodsColumns);
if (goods == null)
continue;
Map<String, Object> 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<LitemallGrouponRules> 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)) {
......
......@@ -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<String, Object> data = new HashMap<String, Object>();
data.put("data", topicList);
data.put("count", total);
return ResponseUtil.ok(data);
}
@GetMapping("detail")
public Object detail(@LoginUser Integer userId, @NotNull Integer grouponId) {
......
......@@ -99,24 +99,8 @@ public class WxHomeController {
List<LitemallTopic> topicList = topicService.queryList(0, SystemConfig.getTopicLimit());
data.put("topicList", topicList);
//优惠专区
List<LitemallGrouponRules> grouponRules = grouponRulesService.queryByIndex(0, 5);
List<LitemallGoods> grouponGoods = new ArrayList<>();
List<Map<String, Object>> grouponList = new ArrayList<>();
for (LitemallGrouponRules rule : grouponRules) {
LitemallGoods goods = goodsService.findByIdVO(rule.getGoodsId());
if (goods == null)
continue;
if (!grouponGoods.contains(goods)) {
Map<String, Object> 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<Map<String, Object>> grouponList = grouponRulesService.queryList(0, 5);
data.put("grouponList", grouponList);
List<Map> categoryList = new ArrayList<>();
......
......@@ -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",
......
......@@ -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-详情
......
// 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
{
"navigationBarTitleText": "团购专区",
"usingComponents": {
"zan-capsule": "../../../lib/zanui-weapp/capsule/index"
}
}
\ No newline at end of file
<view class="container">
<scroll-view class="groupon-list" scroll-y="true" scroll-top="{{scrollTop}}">
<view class="item" wx:for="{{grouponList}}" wx:for-index="index" wx:for-item="item" wx:key="id">
<navigator url="/pages/goods/goods?id={{item.goods.id}}">
<image class="img" src="{{item.goods.picUrl}}" background-size="cover"></image>
<view class="right">
<view class="text">
<view class="header">
<text class="name">{{item.goods.name}}</text>
<view class="capsule-tag">
<zan-capsule color="#a78845" leftText="团购" rightText="{{item.groupon_member}}" />
</view>
</view>
<text class="desc">{{item.goods.brief}}</text>
<view class="price">
<view class="counterPrice">原价:¥{{item.goods.counterPrice}}</view>
<view class="retailPrice">现价:¥{{item.groupon_price}}</view>
</view>
</view>
</view>
</navigator>
</view>
<view class="page" wx:if="{{showPage}}">
<view class="prev {{ page <= 1 ? 'disabled' : ''}}" bindtap="prevPage">上一页</view>
<view class="next {{ (count / size) < page ? 'disabled' : ''}}" bindtap="nextPage">下一页</view>
</view>
</scroll-view>
</view>
\ No newline at end of file
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
......@@ -18,9 +18,9 @@
<view class="h">
<view class="title">
<view>
<!-- <navigator url="../hotGoods/hotGoods"> -->
<text class="txt">优惠专区</text>
<!-- </navigator> -->
<navigator url="/pages/groupon/grouponList/grouponList">
<text class="txt">团购专区</text>
</navigator>
</view>
</view>
</view>
......
......@@ -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-详情
......
// 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
{
"navigationBarTitleText": "团购专区",
"usingComponents": {
"zan-capsule": "/components/capsule/index"
}
}
\ No newline at end of file
<view class="container">
<scroll-view class="groupon-list" scroll-y="true" scroll-top="{{scrollTop}}">
<view class="item" wx:for="{{grouponList}}" wx:for-index="index" wx:for-item="item" wx:key="id">
<navigator url="/pages/goods/goods?id={{item.goods.id}}">
<image class="img" src="{{item.goods.picUrl}}" background-size="cover"></image>
<view class="right">
<view class="text">
<view class="header">
<text class="name">{{item.goods.name}}</text>
<view class="capsule-tag">
<zan-capsule color="#a78845" leftText="团购" rightText="{{item.groupon_member}}" />
</view>
</view>
<text class="desc">{{item.goods.brief}}</text>
<view class="price">
<view class="counterPrice">原价:¥{{item.goods.counterPrice}}</view>
<view class="retailPrice">现价:¥{{item.groupon_price}}</view>
</view>
</view>
</view>
</navigator>
</view>
<view class="page" wx:if="{{showPage}}">
<view class="prev {{ page <= 1 ? 'disabled' : ''}}" bindtap="prevPage">上一页</view>
<view class="next {{ (count / size) < page ? 'disabled' : ''}}" bindtap="nextPage">下一页</view>
</view>
</scroll-view>
</view>
\ No newline at end of file
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
......@@ -42,9 +42,9 @@
<view class="h">
<view class="title">
<view>
<!-- <navigator url="../hotGoods/hotGoods"> -->
<text class="txt">优惠专区</text>
<!-- </navigator> -->
<navigator url="/pages/groupon/grouponList/grouponList">
<text class="txt">优惠专区</text>
</navigator>
</view>
</view>
</view>
......
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