|
|
@@ -5,6 +5,7 @@ import cn.hutool.core.date.DateField;
|
|
|
import cn.hutool.core.date.DateTime;
|
|
|
import cn.hutool.core.date.DateUtil;
|
|
|
import cn.hutool.core.lang.Assert;
|
|
|
+import cn.hutool.core.util.ObjectUtil;
|
|
|
import cn.hutool.core.util.RandomUtil;
|
|
|
import cn.hutool.core.util.StrUtil;
|
|
|
import com.alipay.api.AlipayApiException;
|
|
|
@@ -281,6 +282,10 @@ public class OrderDonServiceImpl extends ServiceImpl<OrderDonMapper, OrderDon> i
|
|
|
|
|
|
private final OrderDonLocationRelateMapper orderDonLocationRelateMapper;
|
|
|
|
|
|
+ private final GoodsDonSkuSubsidyMapper goodsDonSkuSubsidyMapper;
|
|
|
+
|
|
|
+ private final OrderDonSubsidyRelateMapper orderDonSubsidyRelateMapper;
|
|
|
+
|
|
|
private final List<String> noChekGoodsTemp = List.of("Apple One", "Youtube", "Spotify");
|
|
|
|
|
|
@Transactional(rollbackFor = Throwable.class)
|
|
|
@@ -500,71 +505,16 @@ public class OrderDonServiceImpl extends ServiceImpl<OrderDonMapper, OrderDon> i
|
|
|
if (isSpecificPrice && (orderDon.getMoney().compareTo(BigDecimal.ZERO) == 0 || orderDon.getMoney().compareTo(specificPrice) != 0)) {
|
|
|
throw BusinessRuntimeException.getInstance("专属价格不支持使用其他优惠");
|
|
|
}
|
|
|
- orderDon.setPayDesc(goodsDon.getPayDesc());
|
|
|
- StringBuilder payTitle = new StringBuilder();
|
|
|
- payTitle.append(goodsDon.getTitle());
|
|
|
- if (sku != null) {
|
|
|
- payTitle.append(sku.getSpecVal());
|
|
|
- }
|
|
|
- if (isGiftCardPay.get()) {
|
|
|
- //礼品卡规格
|
|
|
- Map<Long, Integer> giftCardPayNumMap = new ConcurrentHashMap<>();
|
|
|
- giftCards.stream().forEach(data -> {
|
|
|
- if (data.getNum() <= 0) {
|
|
|
- return;
|
|
|
- }
|
|
|
- giftCardPayNumMap.putIfAbsent(data.getGcId(), data.getNum());
|
|
|
- });
|
|
|
- if (giftCardPayNumMap.isEmpty()) {
|
|
|
- throw BusinessRuntimeException.getInstance("请选择要购买礼品卡的数量");
|
|
|
- }
|
|
|
- List<GiftCardGoodsSkuFrontView> giftCardViews = beanSearcher.searchAll(GiftCardGoodsSkuFrontView.class, MapUtils.builder().field(GiftCardGoodsSkuFrontView::getId, giftCardPayNumMap.keySet()).op(Operator.InList).build());
|
|
|
- if (giftCardViews.size() != giftCards.size()) {
|
|
|
- throw BusinessRuntimeException.getInstance("系统异常,请刷新页面重试");
|
|
|
- }
|
|
|
- payTitle.append("购买详情:");
|
|
|
- BigDecimal gift_card_pay_money = BigDecimal.ZERO;
|
|
|
- for (GiftCardGoodsSkuFrontView data : giftCardViews) {
|
|
|
- //礼品卡数量
|
|
|
- Integer num = giftCardPayNumMap.get(data.getId());
|
|
|
- data.setGcNum(num);
|
|
|
- data.setGcShowType(gcPayInfo.getGcShowType());
|
|
|
- data.setGcImg(gcPayInfo.getGcImg());
|
|
|
- gift_card_pay_money = gift_card_pay_money.add(data.getPrice().multiply(BigDecimal.valueOf(num)));
|
|
|
|
|
|
- //礼品卡关系
|
|
|
- if (!payTitle.toString().endsWith("购买详情:")) {
|
|
|
- payTitle.append(" + ");
|
|
|
- }
|
|
|
- String gcDetail;
|
|
|
- if (data.getGcType() == 1) {
|
|
|
- gcDetail = String.format("%s张现金卡%s%s", num, Constant.CN_CYS, data.getCash().divide(BigDecimal.valueOf(100)));
|
|
|
- payTitle.append(gcDetail);
|
|
|
- } else {
|
|
|
- gcDetail = String.format("%s张虚拟卡%s%s", num, data.getGcGoodsTitle(), data.getGcSpecVal());
|
|
|
- payTitle.append(gcDetail);
|
|
|
- }
|
|
|
- }
|
|
|
- gcPayInfo.setGcPayDetail(giftCardViews);
|
|
|
-
|
|
|
- //调整礼品卡金额
|
|
|
- if (gift_card_pay_money.compareTo(orderDon.getMoney()) > 0) {
|
|
|
- orderDon.setMoney(gift_card_pay_money);
|
|
|
- orderDon.setRealMoney(gift_card_pay_money);
|
|
|
- }
|
|
|
+ //规格补贴id
|
|
|
+ Long subsidyId = payRequest.getSubsidyId();
|
|
|
+ if (subsidyId != null) {
|
|
|
+ //校验百亿补贴规格,并设置参数
|
|
|
+ setSubsidyOrderDonInfo(subsidyId, user, orderDon);
|
|
|
}
|
|
|
- if (orderDon.getIsDp()) {
|
|
|
- List<GoodsDonSkuView> dp_skuViewList = beanSearcher.searchAll(GoodsDonSkuView.class, MapUtils.builder().field(GoodsDonSkuView::getSkuId, dpSkuIds).op(Operator.InList).build());
|
|
|
- if (dp_skuViewList.size() != dpSkuIds.size()) {
|
|
|
- throw BusinessRuntimeException.getInstance("系统异常,请刷新页面重新下单");
|
|
|
- }
|
|
|
- dp_skuViewList.forEach(dp_SkuView -> {
|
|
|
- payTitle.append(" + ");
|
|
|
- payTitle.append(dp_SkuView.getGoodsTitle());
|
|
|
- payTitle.append(dp_SkuView.getSpecVal());
|
|
|
- });
|
|
|
- }
|
|
|
- orderDon.setPayTitle(payTitle.toString());
|
|
|
+ orderDon.setPayDesc(goodsDon.getPayDesc());
|
|
|
+ //设置订单支付商品信息
|
|
|
+ setOrderDonPayTile(isGiftCardPay, gcPayInfo, giftCards, orderDon, goodsDon, sku, dpSkuIds);
|
|
|
//下单手机号
|
|
|
orderDon.setPhone(orderPhone);
|
|
|
this.saveOrUpdate(orderDon);
|
|
|
@@ -647,6 +597,8 @@ public class OrderDonServiceImpl extends ServiceImpl<OrderDonMapper, OrderDon> i
|
|
|
}
|
|
|
//记录订单ip关联
|
|
|
recordOrderDonLocationRelate(orderDon.getId(), payRequest.getIp());
|
|
|
+ //记录补贴订单关联
|
|
|
+ recordOrderDonSubsidyRelate(orderDon.getId(), subsidyId);
|
|
|
return orderDon;
|
|
|
}
|
|
|
|
|
|
@@ -2988,4 +2940,112 @@ public class OrderDonServiceImpl extends ServiceImpl<OrderDonMapper, OrderDon> i
|
|
|
orderDonLocationRelate.setIp(ip);
|
|
|
orderDonLocationRelateMapper.insert(orderDonLocationRelate);
|
|
|
}
|
|
|
+
|
|
|
+ private void recordOrderDonSubsidyRelate(Long orderId, Long subsidyId) {
|
|
|
+ if (subsidyId != null) {
|
|
|
+ OrderDonSubsidyRelate orderDonSubsidyRelate = new OrderDonSubsidyRelate();
|
|
|
+ orderDonSubsidyRelate.setSubsidyId(subsidyId);
|
|
|
+ orderDonSubsidyRelate.setOrderId(orderId);
|
|
|
+ orderDonSubsidyRelateMapper.insert(orderDonSubsidyRelate);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 设置订单支付商品属性
|
|
|
+ */
|
|
|
+ public void setOrderDonPayTile(AtomicBoolean isGiftCardPay, GiftCardDto gcPayInfo, List<GiftCardPayReq> giftCards, OrderDon orderDon, GoodsDon goodsDon, GoodsDonSku sku, List<Long> dpSkuIds) {
|
|
|
+ StringBuilder payTitle = new StringBuilder();
|
|
|
+ payTitle.append(goodsDon.getTitle());
|
|
|
+ if (sku != null) {
|
|
|
+ payTitle.append(sku.getSpecVal());
|
|
|
+ }
|
|
|
+ if (isGiftCardPay.get()) {
|
|
|
+ //礼品卡规格
|
|
|
+ Map<Long, Integer> giftCardPayNumMap = new ConcurrentHashMap<>();
|
|
|
+ giftCards.stream().forEach(data -> {
|
|
|
+ if (data.getNum() <= 0) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ giftCardPayNumMap.putIfAbsent(data.getGcId(), data.getNum());
|
|
|
+ });
|
|
|
+ if (giftCardPayNumMap.isEmpty()) {
|
|
|
+ throw BusinessRuntimeException.getInstance("请选择要购买礼品卡的数量");
|
|
|
+ }
|
|
|
+ List<GiftCardGoodsSkuFrontView> giftCardViews = beanSearcher.searchAll(GiftCardGoodsSkuFrontView.class, MapUtils.builder().field(GiftCardGoodsSkuFrontView::getId, giftCardPayNumMap.keySet()).op(Operator.InList).build());
|
|
|
+ if (giftCardViews.size() != giftCards.size()) {
|
|
|
+ throw BusinessRuntimeException.getInstance("系统异常,请刷新页面重试");
|
|
|
+ }
|
|
|
+ payTitle.append("购买详情:");
|
|
|
+ BigDecimal gift_card_pay_money = BigDecimal.ZERO;
|
|
|
+ for (GiftCardGoodsSkuFrontView data : giftCardViews) {
|
|
|
+ //礼品卡数量
|
|
|
+ Integer num = giftCardPayNumMap.get(data.getId());
|
|
|
+ data.setGcNum(num);
|
|
|
+ data.setGcShowType(gcPayInfo.getGcShowType());
|
|
|
+ data.setGcImg(gcPayInfo.getGcImg());
|
|
|
+ gift_card_pay_money = gift_card_pay_money.add(data.getPrice().multiply(BigDecimal.valueOf(num)));
|
|
|
+
|
|
|
+ //礼品卡关系
|
|
|
+ if (!payTitle.toString().endsWith("购买详情:")) {
|
|
|
+ payTitle.append(" + ");
|
|
|
+ }
|
|
|
+ String gcDetail;
|
|
|
+ if (data.getGcType() == 1) {
|
|
|
+ gcDetail = String.format("%s张现金卡%s%s", num, Constant.CN_CYS, data.getCash().divide(BigDecimal.valueOf(100)));
|
|
|
+ payTitle.append(gcDetail);
|
|
|
+ } else {
|
|
|
+ gcDetail = String.format("%s张虚拟卡%s%s", num, data.getGcGoodsTitle(), data.getGcSpecVal());
|
|
|
+ payTitle.append(gcDetail);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ gcPayInfo.setGcPayDetail(giftCardViews);
|
|
|
+
|
|
|
+ //调整礼品卡金额
|
|
|
+ if (gift_card_pay_money.compareTo(orderDon.getMoney()) > 0) {
|
|
|
+ orderDon.setMoney(gift_card_pay_money);
|
|
|
+ orderDon.setRealMoney(gift_card_pay_money);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (orderDon.getIsDp()) {
|
|
|
+ List<GoodsDonSkuView> dp_skuViewList = beanSearcher.searchAll(GoodsDonSkuView.class, MapUtils.builder().field(GoodsDonSkuView::getSkuId, dpSkuIds).op(Operator.InList).build());
|
|
|
+ if (dp_skuViewList.size() != dpSkuIds.size()) {
|
|
|
+ throw BusinessRuntimeException.getInstance("系统异常,请刷新页面重新下单");
|
|
|
+ }
|
|
|
+ dp_skuViewList.forEach(dp_SkuView -> {
|
|
|
+ payTitle.append(" + ");
|
|
|
+ payTitle.append(dp_SkuView.getGoodsTitle());
|
|
|
+ payTitle.append(dp_SkuView.getSpecVal());
|
|
|
+ });
|
|
|
+ }
|
|
|
+ orderDon.setPayTitle(payTitle.toString());
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 百亿补贴订单
|
|
|
+ */
|
|
|
+ private void setSubsidyOrderDonInfo(Long subsidyId, User user, OrderDon orderDon) {
|
|
|
+ Assert.notNull(user, "用户不存在");
|
|
|
+ GoodsDonSkuSubsidy goodsDonSkuSubsidy = goodsDonSkuSubsidyMapper.selectOne(Wrappers.lambdaQuery(GoodsDonSkuSubsidy.class)
|
|
|
+ .eq(GoodsDonSkuSubsidy::getId, subsidyId)
|
|
|
+ .eq(GoodsDonSkuSubsidy::getDeleted, 1)
|
|
|
+ .last("limit 1"));
|
|
|
+ Assert.notNull(goodsDonSkuSubsidy, "商品不存在");
|
|
|
+ Long skuId = goodsDonSkuSubsidy.getSkuId();
|
|
|
+ Long paySkuId = orderDon.getSkuId();
|
|
|
+ if (ObjectUtil.equal(skuId, paySkuId)) {
|
|
|
+ throw BusinessRuntimeException.getInstance("规格不存在");
|
|
|
+ }
|
|
|
+ BigDecimal price = goodsDonSkuSubsidy.getPrice();
|
|
|
+ if (price.compareTo(BigDecimal.ZERO) <= 0) {
|
|
|
+ throw BusinessRuntimeException.getInstance("商品价格异常..");
|
|
|
+ }
|
|
|
+ //是否购买过该规格
|
|
|
+ Integer selectCount = orderDonMapper.selectCount(Wrappers.lambdaQuery(OrderDon.class)
|
|
|
+ .eq(OrderDon::getSkuId, skuId)
|
|
|
+ .ne(OrderDon::getStatus, OrderDon.Status.close));
|
|
|
+ if (selectCount > 0) {
|
|
|
+ throw BusinessRuntimeException.getInstance("只可购买一次该补贴规格");
|
|
|
+ }
|
|
|
+ orderDon.setMoney(price);
|
|
|
+ }
|
|
|
}
|