diff --git a/doc/api.md b/doc/api.md index 58bf2c9f..8252ca4e 100644 --- a/doc/api.md +++ b/doc/api.md @@ -623,6 +623,88 @@ API应该存在版本控制,以保证兼容性。 ### 2.15 团购服务 +注意 +> 团购业务还不完善 + + +#### 2.15.1 团购商品列表 + +应用场景 + + 参加团购的商品列表信息 + +接口链接 + + +请求参数 + + +响应内容 + + +错误码 + + 略 + + +#### 2.15.2 团购活动详情 + +应用场景 + + 团购活动详情 + +接口链接 + + +请求参数 + + +响应内容 + + +错误码 + + 略 + +#### 2.15.3 参加团购 + +应用场景 + + 参加团购的商品列表信息 + +接口链接 + + +请求参数 + + +响应内容 + + +错误码 + + 略 + + +#### 2.15.4 用户参团列表 + +应用场景 + + 用户参团列表 + +接口链接 + + +请求参数 + + +响应内容 + + +错误码 + + 略 + ### 2.16 帮助服务 ### 2.17 搜索服务 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 308064dc..a7407659 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 @@ -57,36 +57,20 @@ public class LitemallGrouponRulesService { /** * 获取首页团购活动列表 * - * @param offset + * @param page * @param limit * @return */ - public List> queryList(int offset, int limit) { - return queryList(offset, limit, "add_time", "desc"); + public List queryList(Integer page, Integer limit) { + return queryList(page, limit, "add_time", "desc"); } - public List> queryList(int offset, int limit, String sort, String order) { + public List queryList(Integer page, Integer limit, String sort, String order) { LitemallGrouponRulesExample example = new LitemallGrouponRulesExample(); example.or().andDeletedEqualTo(false); example.setOrderByClause(sort + " " + order); - PageHelper.startPage(offset, limit); - 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; + PageHelper.startPage(page, limit); + return mapper.selectByExample(example); } /** diff --git a/litemall-wx-api/src/main/java/org/linlinjava/litemall/wx/service/WxGrouponRuleService.java b/litemall-wx-api/src/main/java/org/linlinjava/litemall/wx/service/WxGrouponRuleService.java new file mode 100644 index 00000000..a404d7de --- /dev/null +++ b/litemall-wx-api/src/main/java/org/linlinjava/litemall/wx/service/WxGrouponRuleService.java @@ -0,0 +1,64 @@ +package org.linlinjava.litemall.wx.service; + +import com.github.pagehelper.Page; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.linlinjava.litemall.db.domain.LitemallGoods; +import org.linlinjava.litemall.db.domain.LitemallGrouponRules; +import org.linlinjava.litemall.db.service.LitemallGoodsService; +import org.linlinjava.litemall.db.service.LitemallGrouponRulesService; +import org.linlinjava.litemall.db.service.LitemallGrouponService; +import org.linlinjava.litemall.wx.vo.GrouponRuleVo; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import java.util.List; + +@Service +public class WxGrouponRuleService { + private final Log logger = LogFactory.getLog(WxGrouponRuleService.class); + + @Autowired + private LitemallGrouponRulesService grouponRulesService; + @Autowired + private LitemallGrouponService grouponService; + @Autowired + private LitemallGoodsService goodsService; + + + public List queryList(Integer page, Integer size) { + return queryList(page, size, "add_time", "desc"); + } + + + public List queryList(Integer page, Integer size, String sort, String order) { + Page grouponRulesList = (Page)grouponRulesService.queryList(page, size, sort, order); + + Page grouponList = new Page(); + grouponList.setPages(grouponRulesList.getPages()); + grouponList.setPageNum(grouponRulesList.getPageNum()); + grouponList.setPageSize(grouponRulesList.getPageSize()); + grouponList.setTotal(grouponRulesList.getTotal()); + + for (LitemallGrouponRules rule : grouponRulesList) { + Integer goodsId = rule.getGoodsId(); + LitemallGoods goods = goodsService.findById(goodsId); + if (goods == null) + continue; + + GrouponRuleVo grouponRuleVo = new GrouponRuleVo(); + grouponRuleVo.setId(goods.getId()); + grouponRuleVo.setName(goods.getName()); + grouponRuleVo.setBrief(goods.getBrief()); + grouponRuleVo.setPicUrl(goods.getPicUrl()); + grouponRuleVo.setCounterPrice(goods.getCounterPrice()); + grouponRuleVo.setRetailPrice(goods.getRetailPrice()); + grouponRuleVo.setGrouponPrice(goods.getRetailPrice().subtract(rule.getDiscount())); + grouponRuleVo.setGrouponDiscount(rule.getDiscount()); + grouponRuleVo.setGrouponMember(rule.getDiscountMember()); + grouponList.add(grouponRuleVo); + } + + return grouponList; + } +} \ No newline at end of file diff --git a/litemall-wx-api/src/main/java/org/linlinjava/litemall/wx/vo/GrouponRuleVo.java b/litemall-wx-api/src/main/java/org/linlinjava/litemall/wx/vo/GrouponRuleVo.java new file mode 100644 index 00000000..ee185572 --- /dev/null +++ b/litemall-wx-api/src/main/java/org/linlinjava/litemall/wx/vo/GrouponRuleVo.java @@ -0,0 +1,87 @@ +package org.linlinjava.litemall.wx.vo; + +import java.math.BigDecimal; + +public class GrouponRuleVo { + private Integer id; + private String name; + private String brief; + private String picUrl; + private BigDecimal counterPrice; + private BigDecimal retailPrice; + private BigDecimal grouponPrice; + private BigDecimal grouponDiscount; + private Integer grouponMember; + + public BigDecimal getGrouponDiscount() { + return grouponDiscount; + } + + public void setGrouponDiscount(BigDecimal grouponDiscount) { + this.grouponDiscount = grouponDiscount; + } + + public Integer getGrouponMember() { + return grouponMember; + } + + public void setGrouponMember(Integer grouponMember) { + this.grouponMember = grouponMember; + } + + public Integer getId() { + return id; + } + + public void setId(Integer id) { + this.id = id; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public String getBrief() { + return brief; + } + + public void setBrief(String brief) { + this.brief = brief; + } + + public String getPicUrl() { + return picUrl; + } + + public void setPicUrl(String picUrl) { + this.picUrl = picUrl; + } + + public BigDecimal getCounterPrice() { + return counterPrice; + } + + public void setCounterPrice(BigDecimal counterPrice) { + this.counterPrice = counterPrice; + } + + public BigDecimal getRetailPrice() { + return retailPrice; + } + + public void setRetailPrice(BigDecimal retailPrice) { + this.retailPrice = retailPrice; + } + + public BigDecimal getGrouponPrice() { + return grouponPrice; + } + + public void setGrouponPrice(BigDecimal grouponPrice) { + this.grouponPrice = grouponPrice; + } +} 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 9f4524b0..ad738819 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 @@ -1,6 +1,5 @@ package org.linlinjava.litemall.wx.web; -import com.github.pagehelper.PageInfo; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.linlinjava.litemall.core.express.ExpressService; @@ -12,6 +11,8 @@ import org.linlinjava.litemall.db.domain.*; import org.linlinjava.litemall.db.service.*; import org.linlinjava.litemall.db.util.OrderUtil; import org.linlinjava.litemall.wx.annotation.LoginUser; +import org.linlinjava.litemall.wx.service.WxGrouponRuleService; +import org.linlinjava.litemall.wx.vo.GrouponRuleVo; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.validation.annotation.Validated; import org.springframework.web.bind.annotation.GetMapping; @@ -41,6 +42,8 @@ public class WxGrouponController { @Autowired private LitemallGrouponRulesService rulesService; @Autowired + private WxGrouponRuleService wxGrouponRuleService; + @Autowired private LitemallGrouponService grouponService; @Autowired private LitemallGoodsService goodsService; @@ -67,12 +70,8 @@ public class WxGrouponController { @RequestParam(defaultValue = "10") Integer limit, @Sort @RequestParam(defaultValue = "add_time") String sort, @Order @RequestParam(defaultValue = "desc") String order) { - List> topicList = grouponRulesService.queryList(page, limit, sort, order); - long total = PageInfo.of(topicList).getTotal(); - Map data = new HashMap(); - data.put("data", topicList); - data.put("count", total); - return ResponseUtil.ok(data); + List grouponRuleVoList = wxGrouponRuleService.queryList(page, limit, sort, order); + return ResponseUtil.okList(grouponRuleVoList); } /** @@ -281,21 +280,4 @@ public class WxGrouponController { return ResponseUtil.ok(result); } - /** - * 商品所对应的团购规则 - * - * @param goodsId 商品ID - * @return 团购规则详情 - */ - @GetMapping("query") - public Object query(@NotNull Integer goodsId) { - LitemallGoods goods = goodsService.findById(goodsId); - if (goods == null) { - return ResponseUtil.fail(GOODS_UNKNOWN, "未找到对应的商品"); - } - - List rules = rulesService.queryByGoodsId(goodsId); - - return ResponseUtil.ok(rules); - } } 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 3fe20f76..70676b3a 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 @@ -9,6 +9,7 @@ import org.linlinjava.litemall.db.domain.LitemallGoods; import org.linlinjava.litemall.db.service.*; import org.linlinjava.litemall.wx.annotation.LoginUser; import org.linlinjava.litemall.wx.service.HomeCacheManager; +import org.linlinjava.litemall.wx.service.WxGrouponRuleService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.validation.annotation.Validated; import org.springframework.web.bind.annotation.GetMapping; @@ -47,7 +48,7 @@ public class WxHomeController { private LitemallCategoryService categoryService; @Autowired - private LitemallGrouponRulesService grouponRulesService; + private WxGrouponRuleService grouponService; @Autowired private LitemallCouponService couponService; @@ -82,8 +83,6 @@ public class WxHomeController { } ExecutorService executorService = Executors.newFixedThreadPool(10); - Map data = new HashMap<>(); - Callable bannerListCallable = () -> adService.queryIndex(); Callable channelListCallable = () -> categoryService.queryChannel(); @@ -100,12 +99,12 @@ public class WxHomeController { Callable hotGoodsListCallable = () -> goodsService.queryByHot(0, SystemConfig.getHotLimit()); - Callable brandListCallable = () -> brandService.queryVO(0, SystemConfig.getBrandLimit()); + Callable brandListCallable = () -> brandService.query(0, SystemConfig.getBrandLimit()); Callable topicListCallable = () -> topicService.queryList(0, SystemConfig.getTopicLimit()); //团购专区 - Callable grouponListCallable = () -> grouponRulesService.queryList(0, 5); + Callable grouponListCallable = () -> grouponService.queryList(0, 5); Callable floorGoodsListCallable = this::getCategoryList; @@ -129,25 +128,26 @@ public class WxHomeController { executorService.submit(grouponListTask); executorService.submit(floorGoodsListTask); + Map entity = new HashMap<>(); try { - data.put("banner", bannerTask.get()); - data.put("channel", channelTask.get()); - data.put("couponList", couponListTask.get()); - data.put("newGoodsList", newGoodsListTask.get()); - data.put("hotGoodsList", hotGoodsListTask.get()); - data.put("brandList", brandListTask.get()); - data.put("topicList", topicListTask.get()); - data.put("grouponList", grouponListTask.get()); - data.put("floorGoodsList", floorGoodsListTask.get()); + entity.put("banner", bannerTask.get()); + entity.put("channel", channelTask.get()); + entity.put("couponList", couponListTask.get()); + entity.put("newGoodsList", newGoodsListTask.get()); + entity.put("hotGoodsList", hotGoodsListTask.get()); + entity.put("brandList", brandListTask.get()); + entity.put("topicList", topicListTask.get()); + entity.put("grouponList", grouponListTask.get()); + entity.put("floorGoodsList", floorGoodsListTask.get()); //缓存数据 - HomeCacheManager.loadData(HomeCacheManager.INDEX, data); + HomeCacheManager.loadData(HomeCacheManager.INDEX, entity); } catch (Exception e) { e.printStackTrace(); }finally { executorService.shutdown(); } - return ResponseUtil.ok(data); + return ResponseUtil.ok(entity); } private List getCategoryList() {