|
|
@@ -35,6 +35,7 @@ import com.cyksj.dto.Result;
|
|
|
import com.cyksj.enums.GatewayResponse;
|
|
|
import com.cyksj.mapper.*;
|
|
|
import com.cyksj.mapper.manage.coupon.CouponMapper;
|
|
|
+import com.cyksj.mapper.manage.coupon.CouponSkuMapper;
|
|
|
import com.cyksj.mapper.manage.coupon.CouponUserMapper;
|
|
|
import com.cyksj.model.dto.*;
|
|
|
import com.cyksj.model.entity.*;
|
|
|
@@ -63,6 +64,7 @@ import org.springframework.transaction.annotation.Transactional;
|
|
|
import java.math.BigDecimal;
|
|
|
import java.math.RoundingMode;
|
|
|
import java.util.*;
|
|
|
+import java.util.stream.Collectors;
|
|
|
|
|
|
import static com.cyksj.enums.GatewayApiCode.GROUP_INDEX_ALREADY_BE_USER;
|
|
|
import static com.cyksj.enums.GatewayApiCode.GROUP_INDEX_NOT_FIND;
|
|
|
@@ -126,6 +128,7 @@ public class OrderDonServiceImpl extends ServiceImpl<OrderDonMapper, OrderDon> i
|
|
|
|
|
|
private final CouponUserMapper couponUserMapper;
|
|
|
|
|
|
+ private final CouponSkuMapper couponSkuMapper;
|
|
|
|
|
|
@Transactional(rollbackFor = Throwable.class)
|
|
|
@Override
|
|
|
@@ -986,6 +989,9 @@ public class OrderDonServiceImpl extends ServiceImpl<OrderDonMapper, OrderDon> i
|
|
|
|
|
|
public void checkCouponStatus(Long skuId, String couponExCode, Long couponId, Long userId) throws Exception {
|
|
|
log.info("开始校验兑换码:{},优惠卷id:{}状态", couponExCode, couponId);
|
|
|
+ //实物还是虚物商品
|
|
|
+ GoodsDonSku goodsDonSku = goodsDonSkuMapper.selectById(skuId);
|
|
|
+ GoodsDon goodsDon = goodsDonMapper.selectById(goodsDonSku.getGoodsId());
|
|
|
if (StrUtil.isNotBlank(couponExCode) && couponId != null) {
|
|
|
throw BusinessRuntimeException.getInstance("优惠券与优惠码不可同时使用..");
|
|
|
}
|
|
|
@@ -994,12 +1000,8 @@ public class OrderDonServiceImpl extends ServiceImpl<OrderDonMapper, OrderDon> i
|
|
|
if (exists == null) {
|
|
|
throw BusinessRuntimeException.getInstance("该优惠码不存在");
|
|
|
}
|
|
|
- if (exists.getType() == Coupon.Type.reduce) {
|
|
|
- Set<Integer> skuIds = Jsons.parseObject(exists.getSkuIds(), Set.class);
|
|
|
- if (!skuIds.contains(Integer.valueOf(String.valueOf(skuId)))) {
|
|
|
- throw BusinessRuntimeException.getInstance("该优惠码不适用于该规格");
|
|
|
- }
|
|
|
- }
|
|
|
+ checkCouponGoods(goodsDon, skuId, exists.getType(), exists.getGoodsSkuIds());
|
|
|
+
|
|
|
} else if (couponId != null) {
|
|
|
CouponUserView couponUserView = beanSearcher.searchFirst(CouponUserView.class, MapUtils.builder()
|
|
|
.field(CouponUserView::getCouponId, couponId).op(Operator.Equal)
|
|
|
@@ -1019,12 +1021,7 @@ public class OrderDonServiceImpl extends ServiceImpl<OrderDonMapper, OrderDon> i
|
|
|
if (couponUserView.getCouponUserStatus() != CouponUser.Status.unused) {
|
|
|
throw BusinessRuntimeException.getInstance("该优惠卷不可使用");
|
|
|
}
|
|
|
- if (couponUserView.getType() == Coupon.Type.reduce) {
|
|
|
- Set<Integer> skuIds = Jsons.parseObject(couponUserView.getSkuIds(), Set.class);
|
|
|
- if (!skuIds.contains(Integer.valueOf(String.valueOf(skuId)))) {
|
|
|
- throw BusinessRuntimeException.getInstance("该优惠码不适用于该规格");
|
|
|
- }
|
|
|
- }
|
|
|
+ checkCouponGoods(goodsDon, skuId, couponUserView.getType(), couponUserView.getGoodsSkuIds());
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@@ -1103,4 +1100,22 @@ public class OrderDonServiceImpl extends ServiceImpl<OrderDonMapper, OrderDon> i
|
|
|
}
|
|
|
log.info("订单:{}退款,优惠卷返还end...", orderDon.getId());
|
|
|
}
|
|
|
+
|
|
|
+ public void checkCouponGoods(GoodsDon goodsDon, Long skuId, Coupon.Type type, String goodsSkuIds) throws Exception {
|
|
|
+ if (goodsDon.getType() == 1) {
|
|
|
+ if (type == Coupon.Type.reduce) {
|
|
|
+ List<Coupon.CouponGoodsSku> skuIds = Jsons.parseObject(goodsSkuIds, List.class);
|
|
|
+ Set<Long> collect = skuIds.stream().map(Coupon.CouponGoodsSku::getSkuId).collect(Collectors.toSet());
|
|
|
+ if (!collect.contains(Integer.valueOf(String.valueOf(skuId)))) {
|
|
|
+ throw BusinessRuntimeException.getInstance("该优惠码不适用于该规格");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } 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("该优惠卷不可用于实物商品");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|