diff --git a/hai-cweb/src/main/java/com/cweb/controller/HighOrderController.java b/hai-cweb/src/main/java/com/cweb/controller/HighOrderController.java index e6362783..ea5307d0 100644 --- a/hai-cweb/src/main/java/com/cweb/controller/HighOrderController.java +++ b/hai-cweb/src/main/java/com/cweb/controller/HighOrderController.java @@ -20,6 +20,7 @@ import com.hai.config.TuanYouConfig; import com.hai.entity.*; import com.hai.enum_type.DiscountUseScope; import com.hai.enum_type.GasClassGroupTaskStatus; +import com.hai.enum_type.OrderChildGoodsTypeEnum; import com.hai.model.GasPayPriceModel; import com.hai.model.HighMerchantStoreModel; import com.hai.model.HighUserModel; @@ -432,7 +433,7 @@ public class HighOrderController { if (highDiscountUserRel != null) { highOrder.setMemDiscountName(highDiscountUserRel.getHighDiscount().getDiscountName()); - // 交易优惠券使用范围 + // 优惠券使用范围 if (highDiscountUserRel.getHighDiscount().getUseScope().equals(DiscountUseScope.type1.getType())) { // 暂无限制 } else if (highDiscountUserRel.getHighDiscount().getUseScope().equals(DiscountUseScope.type2.getType())) { @@ -617,4 +618,71 @@ public class HighOrderController { return ResponseMsgUtil.exception(e); } } + + @RequestMapping(value="/orderCanUseDiscount",method = RequestMethod.POST) + @ResponseBody + @ApiOperation(value = "订单可以使用的优惠券") + public ResponseData orderCanUseDiscount(@RequestBody JSONObject body) { + try { + // 用户 + HighUserModel userInfoModel = userCenter.getSessionModel(HighUserModel.class); + if (userInfoModel == null) { + throw ErrorHelp.genException(SysCode.System, ErrorCode.COMPETENCE_INSUFFICIENT, ""); + } + if (body == null + || body.getInteger("goodsType") == null + || body.getLong("goodsId") == null + || body.getBigDecimal("goodsPrice") == null + ) { + throw ErrorHelp.genException(SysCode.System, ErrorCode.REQ_PARAMS_ERROR, ""); + } + + // 商品类型 + OrderChildGoodsTypeEnum goodsType = OrderChildGoodsTypeEnum.getDataByType(body.getInteger("goodsType")); + if (goodsType == null) { + throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "未知的商品类型"); + } + + Map map = new HashMap<>(); + map.put("userId", userInfoModel.getHighUser().getId()); + map.put("status", 1); + // 查询用户的优惠券 + List userDiscountList = highDiscountUserRelService.getDiscountList(map); + + List list = new ArrayList<>(); + + if (userDiscountList.size() > 0) { + + if (goodsType.getType().equals(OrderChildGoodsTypeEnum.type1.getType())) { + // 查询当前卡券有哪些优惠券 + List discountCouponRelList = highDiscountCouponRelService.getRelByCoupon(body.getLong("goodsId")); + if (discountCouponRelList.size() > 0) { + for (HighDiscountCouponRel highDiscountCouponRel : discountCouponRelList) { + List collect = userDiscountList.stream().filter(o -> o.getDiscountId().equals(highDiscountCouponRel.getDiscountId())).collect(Collectors.toList()); + if (collect != null && collect.size() > 0) { + for (HighDiscountUserRel discountUser : collect) { + list.add(discountUser); + } + } + } + } + } + + if (goodsType.getType().equals(OrderChildGoodsTypeEnum.type3.getType())) { + // 过滤出加油服务的加油券 + List collect = userDiscountList.stream().filter(o -> o.getHighDiscount().getUseScope().equals(DiscountUseScope.type7.getType())).collect(Collectors.toList()); + for (HighDiscountUserRel userDiscount : collect) { + + } + } + + list.sort(Comparator.comparing(o -> o.getUseEndTime())); + } + return ResponseMsgUtil.success(list); + + } catch (Exception e) { + log.error("HighDiscountController -> getDiscountListByCoupon() error!",e); + return ResponseMsgUtil.exception(e); + } + } } diff --git a/hai-service/src/main/java/com/hai/enum_type/DiscountUseScope.java b/hai-service/src/main/java/com/hai/enum_type/DiscountUseScope.java index ff85e3ff..856ce611 100644 --- a/hai-service/src/main/java/com/hai/enum_type/DiscountUseScope.java +++ b/hai-service/src/main/java/com/hai/enum_type/DiscountUseScope.java @@ -14,6 +14,7 @@ public enum DiscountUseScope { type4(4 , "肯德基"), type5(5 , "星巴克"), type6(6 , "会员充值"), + type7(7 , "加油服务"), ; private Integer type; diff --git a/hai-service/src/main/java/com/hai/enum_type/OrderChildGoodsTypeEnum.java b/hai-service/src/main/java/com/hai/enum_type/OrderChildGoodsTypeEnum.java new file mode 100644 index 00000000..3dddce2b --- /dev/null +++ b/hai-service/src/main/java/com/hai/enum_type/OrderChildGoodsTypeEnum.java @@ -0,0 +1,51 @@ +package com.hai.enum_type; + +import java.util.Objects; + +/** + * 子订单商品类型 + * @author hurui + */ +public enum OrderChildGoodsTypeEnum { + type1(1 , "卡券"), + type2(2 , "金币充值"), + type3(3 , "加油服务"), + type4(4 , "KFC"), + type5(5 , "电影票"), + type6(6 , "话费充值"), + type7(7 , "优惠券包"), + type8(8 , "贵州汇联通充值"), + ; + + private Integer type; + private String name; + + OrderChildGoodsTypeEnum(int type , String name) { + this.type = type; + this.name = name; + } + + public static OrderChildGoodsTypeEnum getDataByType(Integer type) { + for (OrderChildGoodsTypeEnum ele : values()) { + if(Objects.equals(type,ele.getType())) return ele; + } + return null; + } + + + public Integer getType() { + return type; + } + + public void setType(Integer type) { + this.type = type; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } +}