|
|
@@ -136,7 +136,7 @@ public class OrderDonServiceImpl extends ServiceImpl<OrderDonMapper, OrderDon> i
|
|
|
CouponUser couponUser = null;
|
|
|
if (StrUtil.isNotBlank(payRequest.getCouponExCode()) || payRequest.getCouponId() != null) {
|
|
|
checkCouponStatus(payRequest.getSkuId(), payRequest.getCouponExCode(), payRequest.getCouponId(), payRequest.getUserId(), false);
|
|
|
- //记录优惠卷使用状态
|
|
|
+ //记录优惠券使用状态
|
|
|
couponUser = couponStatusRecord(payRequest.getCouponExCode(), payRequest.getCouponId(), payRequest.getUserId());
|
|
|
}
|
|
|
User user = userMapper.selectById(payRequest.getUserId());
|
|
|
@@ -219,7 +219,7 @@ public class OrderDonServiceImpl extends ServiceImpl<OrderDonMapper, OrderDon> i
|
|
|
orderDon.setOpenId(payOpenId);
|
|
|
orderDon.setMoney(payRequest.getDonMoney());
|
|
|
orderDon.setRealMoney(payRequest.getDonMoney());
|
|
|
- //存在优惠卷
|
|
|
+ //存在优惠券
|
|
|
if (couponUser != null) {
|
|
|
Long couponId = couponUser.getCouponId();
|
|
|
Coupon coupon = couponMapper.selectById(couponId);
|
|
|
@@ -462,7 +462,7 @@ public class OrderDonServiceImpl extends ServiceImpl<OrderDonMapper, OrderDon> i
|
|
|
CouponUser couponUser = null;
|
|
|
if (StrUtil.isNotBlank(payRequest.getCouponExCode()) || payRequest.getCouponId() != null) {
|
|
|
checkCouponStatus(payRequest.getSkuId(), payRequest.getCouponExCode(), payRequest.getCouponId(), payRequest.getUserId(), true);
|
|
|
- //记录优惠卷使用状态
|
|
|
+ //记录优惠券使用状态
|
|
|
couponUser = couponStatusRecord(payRequest.getCouponExCode(), payRequest.getCouponId(), payRequest.getUserId());
|
|
|
}
|
|
|
Long relationId = payRequest.getRelationId();
|
|
|
@@ -510,7 +510,7 @@ public class OrderDonServiceImpl extends ServiceImpl<OrderDonMapper, OrderDon> i
|
|
|
orderDon.setUserId(user.getId());
|
|
|
orderDon.setGoodsId(goodsDon.getId());
|
|
|
orderDon.setRealMoney(payRequest.getDonMoney());
|
|
|
- //存在优惠卷
|
|
|
+ //存在优惠券
|
|
|
if (couponUser != null) {
|
|
|
Long couponId = couponUser.getCouponId();
|
|
|
Coupon coupon = couponMapper.selectById(couponId);
|
|
|
@@ -644,7 +644,7 @@ public class OrderDonServiceImpl extends ServiceImpl<OrderDonMapper, OrderDon> i
|
|
|
});
|
|
|
//虚物订单退款,清出车队,车票变为已过期
|
|
|
clearUnrealGoodsDetail(orderDon, goodsDon);
|
|
|
- //若存在优惠卷使用,退还优惠卷
|
|
|
+ //若存在优惠券使用,退还优惠券
|
|
|
if (orderDon.getCouponUserId() != 0) {
|
|
|
redisService.set(String.format("%s-%s", orderDon.getId(), orderDon.getCouponUserId()), orderDon.getId(), 120l);
|
|
|
updateOrderDonCouponStatus(orderDon);
|
|
|
@@ -714,7 +714,7 @@ public class OrderDonServiceImpl extends ServiceImpl<OrderDonMapper, OrderDon> i
|
|
|
//虚物订单退款,清出车队,车票变为已过期
|
|
|
clearUnrealGoodsDetail(orderDon, goodsDon);
|
|
|
if (orderDon.getCouponUserId() != 0) {
|
|
|
- //zfb订单退款,返还优惠卷
|
|
|
+ //zfb订单退款,返还优惠券
|
|
|
updateOrderDonCouponStatus(orderDon);
|
|
|
}
|
|
|
return GatewayResponse.SUCCESS.newBuilder().toResult("退款成功");
|
|
|
@@ -1011,7 +1011,7 @@ public class OrderDonServiceImpl extends ServiceImpl<OrderDonMapper, OrderDon> i
|
|
|
}
|
|
|
|
|
|
public void checkCouponStatus(Long skuId, String couponExCode, Long couponId, Long userId, Boolean isRenew) throws Exception {
|
|
|
- log.info("开始校验兑换码:{},优惠卷id:{}状态", couponExCode, couponId);
|
|
|
+ log.info("开始校验兑换码:{},优惠券id:{}状态", couponExCode, couponId);
|
|
|
//实物还是虚物商品
|
|
|
GoodsDonSku goodsDonSku = goodsDonSkuMapper.selectById(skuId);
|
|
|
GoodsDon goodsDon = goodsDonMapper.selectById(goodsDonSku.getGoodsId());
|
|
|
@@ -1023,10 +1023,10 @@ public class OrderDonServiceImpl extends ServiceImpl<OrderDonMapper, OrderDon> i
|
|
|
if (exists == null) {
|
|
|
throw BusinessRuntimeException.getInstance("该优惠码不存在");
|
|
|
}
|
|
|
- checkCouponGoods(goodsDon, skuId, exists.getType(), exists.getGoodsSkuIds());
|
|
|
+ checkCouponGoods(goodsDon, skuId, exists.getType(), exists.getGoodsSkuIds(), true);
|
|
|
//检验是否续费可使用
|
|
|
if (isRenew && !exists.getIsRenew()) {
|
|
|
- throw BusinessRuntimeException.getInstance("该优惠卷续费时不可使用");
|
|
|
+ throw BusinessRuntimeException.getInstance("该优惠券续费时不可使用");
|
|
|
}
|
|
|
} else if (couponId != null) {
|
|
|
CouponUserView couponUserView = beanSearcher.searchFirst(CouponUserView.class, MapUtils.builder()
|
|
|
@@ -1034,10 +1034,10 @@ public class OrderDonServiceImpl extends ServiceImpl<OrderDonMapper, OrderDon> i
|
|
|
.field(CouponUserView::getUserId, userId).op(Operator.Equal)
|
|
|
.build());
|
|
|
if (couponUserView == null) {
|
|
|
- throw BusinessRuntimeException.getInstance("该优惠卷不存在");
|
|
|
+ throw BusinessRuntimeException.getInstance("该优惠券不存在");
|
|
|
}
|
|
|
if (couponUserView.getCouponUserStatus() == CouponUser.Status.used) {
|
|
|
- throw BusinessRuntimeException.getInstance("该优惠卷已使用");
|
|
|
+ throw BusinessRuntimeException.getInstance("该优惠券已使用");
|
|
|
}
|
|
|
if (!couponUserView.getIsValidTime()) {
|
|
|
couponUserView.setValidStartTime(couponUserView.getCreatedTime());
|
|
|
@@ -1045,18 +1045,18 @@ public class OrderDonServiceImpl extends ServiceImpl<OrderDonMapper, OrderDon> i
|
|
|
}
|
|
|
couponFontService.setCouponUserStatus(couponUserView, DateTime.now());
|
|
|
if (couponUserView.getCouponUserStatus() != CouponUser.Status.unused) {
|
|
|
- throw BusinessRuntimeException.getInstance("该优惠卷不可使用");
|
|
|
+ throw BusinessRuntimeException.getInstance("该优惠券不可使用");
|
|
|
}
|
|
|
- checkCouponGoods(goodsDon, skuId, couponUserView.getType(), couponUserView.getGoodsSkuIds());
|
|
|
+ checkCouponGoods(goodsDon, skuId, couponUserView.getType(), couponUserView.getGoodsSkuIds(), false);
|
|
|
//检验是否续费可使用
|
|
|
if (isRenew && !couponUserView.getIsRenew()) {
|
|
|
- throw BusinessRuntimeException.getInstance("该优惠卷续费时不可使用");
|
|
|
+ throw BusinessRuntimeException.getInstance("该优惠券续费时不可使用");
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
private CouponUser couponStatusRecord(String couponExCode, Long couponId, Long userId) {
|
|
|
- log.info("兑换码:{},优惠卷id:{},更新其优惠卷状态", couponExCode, couponId);
|
|
|
+ log.info("兑换码:{},优惠券id:{},更新其优惠券状态", couponExCode, couponId);
|
|
|
CouponUser couponUser = null;
|
|
|
if (StrUtil.isNotBlank(couponExCode)) {
|
|
|
CouponPopularizeDto exists = couponMapper.checkExCode(couponExCode);
|
|
|
@@ -1071,7 +1071,7 @@ public class OrderDonServiceImpl extends ServiceImpl<OrderDonMapper, OrderDon> i
|
|
|
}
|
|
|
CouponUser received = couponUserMapper.selectOne(Wrappers.lambdaQuery(CouponUser.class).eq(CouponUser::getUserId, userId).eq(CouponUser::getCouponId, couponUser.getCouponId()).last("limit 1"));
|
|
|
if (received != null && received.getStatus() != CouponUser.Status.unused) {
|
|
|
- throw BusinessRuntimeException.getInstance("该优惠卷已使用");
|
|
|
+ throw BusinessRuntimeException.getInstance("该优惠券已使用");
|
|
|
}
|
|
|
couponUser.setUserId(userId);
|
|
|
couponUser.setStatus(CouponUser.Status.used);
|
|
|
@@ -1079,13 +1079,13 @@ public class OrderDonServiceImpl extends ServiceImpl<OrderDonMapper, OrderDon> i
|
|
|
try {
|
|
|
couponUserMapper.insert(couponUser);
|
|
|
} catch (DuplicateKeyException e) {
|
|
|
- log.info("用户已领取该{}优惠卷", couponUser.getCouponId());
|
|
|
- throw BusinessRuntimeException.getInstance("该优惠卷已使用");
|
|
|
+ log.info("用户已领取该{}优惠券", couponUser.getCouponId());
|
|
|
+ throw BusinessRuntimeException.getInstance("该优惠券已使用");
|
|
|
}
|
|
|
} else {
|
|
|
couponUser = couponUserMapper.selectOne(Wrappers.lambdaQuery(CouponUser.class).eq(CouponUser::getUserId, userId).eq(CouponUser::getCouponId, couponId).last("limit 1"));
|
|
|
if (couponUser == null) {
|
|
|
- throw BusinessRuntimeException.getInstance("该优惠卷不存在");
|
|
|
+ throw BusinessRuntimeException.getInstance("该优惠券不存在");
|
|
|
}
|
|
|
couponUser.setStatus(CouponUser.Status.used);
|
|
|
couponUserMapper.updateById(couponUser);
|
|
|
@@ -1094,13 +1094,13 @@ public class OrderDonServiceImpl extends ServiceImpl<OrderDonMapper, OrderDon> i
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * 退款时,归还优惠卷
|
|
|
+ * 退款时,归还优惠券
|
|
|
*/
|
|
|
private void updateOrderDonCouponStatus(OrderDon orderDon) {
|
|
|
- log.info("订单:{}退款,优惠卷返还start...", orderDon.getId());
|
|
|
+ log.info("订单:{}退款,优惠券返还start...", orderDon.getId());
|
|
|
CouponUser couponUser = couponUserMapper.selectById(orderDon.getCouponUserId());
|
|
|
if (CouponUser.Channel.exCode == couponUser.getChannel()) {
|
|
|
- //兑换码兑换的优惠卷退款时,直接删除
|
|
|
+ //兑换码兑换的优惠券退款时,直接删除
|
|
|
couponUserMapper.deleteById(couponUser.getId());
|
|
|
}else {
|
|
|
CouponUserView couponUserView = beanSearcher.searchFirst(CouponUserView.class, MapUtils.builder().field(CouponUserView::getCouponId, couponUser.getCouponId()).build());
|
|
|
@@ -1113,23 +1113,23 @@ public class OrderDonServiceImpl extends ServiceImpl<OrderDonMapper, OrderDon> i
|
|
|
couponUser.setStatus(couponUserView.getCouponUserStatus());
|
|
|
couponUserMapper.updateById(couponUser);
|
|
|
}
|
|
|
- log.info("订单:{}退款,优惠卷返还end...", orderDon.getId());
|
|
|
+ log.info("订单:{}退款,优惠券返还end...", orderDon.getId());
|
|
|
}
|
|
|
|
|
|
- public void checkCouponGoods(GoodsDon goodsDon, Long skuId, Coupon.Type type, String goodsSkuIds) throws Exception {
|
|
|
+ public void checkCouponGoods(GoodsDon goodsDon, Long skuId, Coupon.Type type, String goodsSkuIds, Boolean isCouponCode) throws Exception {
|
|
|
if (goodsDon.getType() == 1) {
|
|
|
if (type == Coupon.Type.reduce) {
|
|
|
- List<Coupon.CouponGoodsSku> skuIds = Jsons.parseObject(goodsSkuIds, List.class);
|
|
|
+ List<Coupon.CouponGoodsSku> skuIds = Jsons.parseList(goodsSkuIds, Coupon.CouponGoodsSku.class);
|
|
|
Set<Long> collect = skuIds.stream().map(Coupon.CouponGoodsSku::getSkuId).collect(Collectors.toSet());
|
|
|
- if (!collect.contains(Integer.valueOf(String.valueOf(skuId)))) {
|
|
|
- throw BusinessRuntimeException.getInstance("该优惠码不适用于该规格");
|
|
|
+ if (!collect.contains(skuId)) {
|
|
|
+ throw BusinessRuntimeException.getInstance(String.format("该%s不适用于该规格", isCouponCode ? "优惠码" : "优惠券"));
|
|
|
}
|
|
|
}
|
|
|
} else {
|
|
|
Long gid = goodsDon.getId();
|
|
|
CouponSku couponSku = couponSkuMapper.selectOne(Wrappers.lambdaQuery(CouponSku.class).eq(CouponSku::getGoodsId, gid).eq(CouponSku::getDeleted, true).select(CouponSku::getId).last("limit 1"));
|
|
|
if (couponSku == null) {
|
|
|
- throw BusinessRuntimeException.getInstance("该优惠卷不可用于实物商品");
|
|
|
+ throw BusinessRuntimeException.getInstance(String.format("该%s不可用于实物商品", isCouponCode ? "优惠码" : "优惠券"));
|
|
|
}
|
|
|
}
|
|
|
}
|