提交代码

dev-discount
胡锐 2 years ago
parent 49a4648848
commit f4b4889413
  1. 72
      hai-cweb/src/main/java/com/cweb/controller/HighOrderController.java
  2. 81
      hai-cweb/src/main/java/com/cweb/controller/HighUserDiscountController.java

@ -409,6 +409,7 @@ public class HighOrderController {
totalPrice = totalPrice.add(childOrder.getTotalPrice());
totalActualPrice = totalActualPrice.add(childOrder.getGoodsActualPrice());
}
// 积分抵扣金额
BigDecimal integralDeductionPrice = new BigDecimal(0);
if (buyPoints && highOrder.getPayGold() != null) {
@ -447,6 +448,11 @@ public class HighOrderController {
log.error("HighOrderController --> addOrder() error!", "此优惠券只能充值话费中使用");
throw ErrorHelp.genException(SysCode.System, ErrorCode.UN_MEMBER_ERROR, "此优惠券只能充值话费中使用");
}
} else if (highDiscountUserRel.getHighDiscount().getUseScope().equals(DiscountUseScope.type3.getType())) {
if (!highOrder.getHighChildOrderList().get(0).getGoodsType().equals(3)) {
log.error("HighOrderController --> addOrder() error!", "此优惠券只能充值话费中使用");
throw ErrorHelp.genException(SysCode.System, ErrorCode.UN_MEMBER_ERROR, "此优惠券只能充值话费中使用");
}
} else {
log.error("HighOrderController --> addOrder() error!", "暂时无法使用此优惠券");
throw ErrorHelp.genException(SysCode.System, ErrorCode.UN_MEMBER_ERROR, "暂时无法使用此优惠券");
@ -619,70 +625,4 @@ public class HighOrderController {
}
}
@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<String,Object> map = new HashMap<>();
map.put("userId", userInfoModel.getHighUser().getId());
map.put("status", 1);
// 查询用户的优惠券
List<HighDiscountUserRel> userDiscountList = highDiscountUserRelService.getDiscountList(map);
List<HighDiscountUserRel> list = new ArrayList<>();
if (userDiscountList.size() > 0) {
if (goodsType.getType().equals(OrderChildGoodsTypeEnum.type1.getType())) {
// 查询当前卡券有哪些优惠券
List<HighDiscountCouponRel> discountCouponRelList = highDiscountCouponRelService.getRelByCoupon(body.getLong("goodsId"));
if (discountCouponRelList.size() > 0) {
for (HighDiscountCouponRel highDiscountCouponRel : discountCouponRelList) {
List<HighDiscountUserRel> 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<HighDiscountUserRel> 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);
}
}
}

@ -11,6 +11,8 @@ import com.hai.common.security.SessionObject;
import com.hai.common.security.UserCenter;
import com.hai.common.utils.ResponseMsgUtil;
import com.hai.entity.*;
import com.hai.enum_type.DiscountUseScope;
import com.hai.enum_type.OrderChildGoodsTypeEnum;
import com.hai.model.HighUserModel;
import com.hai.model.ResponseData;
import com.hai.service.*;
@ -250,4 +252,83 @@ public class HighUserDiscountController {
return ResponseMsgUtil.exception(e);
}
}
@RequestMapping(value="/canUseDiscount",method = RequestMethod.POST)
@ResponseBody
@ApiOperation(value = "商品可以使用的优惠券")
public ResponseData canUseDiscount(@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<String,Object> map = new HashMap<>();
map.put("userId", userInfoModel.getHighUser().getId());
map.put("status", 1);
// 查询用户的优惠券
List<HighDiscountUserRel> userDiscountList = highDiscountUserRelService.getDiscountList(map);
List<HighDiscountUserRel> list = new ArrayList<>();
if (userDiscountList.size() > 0) {
if (goodsType.getType().equals(OrderChildGoodsTypeEnum.type1.getType())) {
// 查询当前卡券有哪些优惠券
List<HighDiscountCouponRel> discountCouponRelList = highDiscountCouponRelService.getRelByCoupon(body.getLong("goodsId"));
if (discountCouponRelList.size() > 0) {
for (HighDiscountCouponRel highDiscountCouponRel : discountCouponRelList) {
List<HighDiscountUserRel> 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<HighDiscountUserRel> collect = userDiscountList.stream().filter(o -> o.getHighDiscount().getUseScope().equals(DiscountUseScope.type7.getType())).collect(Collectors.toList());
for (HighDiscountUserRel userDiscount : collect) {
// 满减
if (userDiscount.getHighDiscount().getDiscountType().equals(1)) {
if (body.getBigDecimal("goodsPrice").compareTo(userDiscount.getHighDiscount().getDiscountCondition()) >= 0) {
list.add(userDiscount);
}
}
if (userDiscount.getHighDiscount().getDiscountType().equals(2)
|| userDiscount.getHighDiscount().getDiscountType().equals(3)) {
list.add(userDiscount);
}
}
}
list.sort(Comparator.comparing(o -> o.getUseEndTime()));
}
return ResponseMsgUtil.success(list);
} catch (Exception e) {
log.error("HighDiscountController -> getDiscountListByCoupon() error!",e);
return ResponseMsgUtil.exception(e);
}
}
}

Loading…
Cancel
Save