|
|
@@ -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)
|
|
|
@@ -479,10 +484,16 @@ public class OrderDonServiceImpl extends ServiceImpl<OrderDonMapper, OrderDon> i
|
|
|
orderDon.setCouponExCode(payRequest.getCouponExCode());
|
|
|
//店铺id
|
|
|
orderDon.setYhsId(yhsId);
|
|
|
+ //规格补贴id
|
|
|
+ Long subsidyId = payRequest.getSubsidyId();
|
|
|
+ if (subsidyId != null) {
|
|
|
+ //校验百亿补贴规格,并设置参数
|
|
|
+ setSubsidyOrderDonInfo(subsidyId, user, orderDon);
|
|
|
+ }
|
|
|
if (relation != null && relation.getStatus() == GroupsRelation.Status.outside) {
|
|
|
orderDon.setIsOt(true);
|
|
|
}
|
|
|
- if (orderDon.getYhsId() == 0) {
|
|
|
+ if (orderDon.getYhsId() == 0 && subsidyId == null) {
|
|
|
//虚拟商品订单,是否是分销订单
|
|
|
setDistributeOrderMark(orderDon, goodsDon.getType(), user.getId());
|
|
|
}
|
|
|
@@ -494,77 +505,15 @@ public class OrderDonServiceImpl extends ServiceImpl<OrderDonMapper, OrderDon> i
|
|
|
}
|
|
|
if (sku != null) {
|
|
|
//扣除使用优惠券、余额的订单金额
|
|
|
- deductOrderMoney(orderDon, couponUser, payRequest.getBalance(), user, sku.getPrice(), goodsDon.getType(), payRequest.getGcCash(), payRequest.getGcpIds(), payRequest.getIsAcReduce());
|
|
|
+ deductOrderMoney(orderDon, couponUser, payRequest.getBalance(), user, sku.getPrice(), goodsDon.getType(), payRequest.getGcCash(), payRequest.getGcpIds(), payRequest.getIsAcReduce(), subsidyId);
|
|
|
}
|
|
|
|
|
|
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);
|
|
|
- }
|
|
|
- }
|
|
|
- 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());
|
|
|
+ //设置订单支付商品信息
|
|
|
+ setOrderDonPayTile(isGiftCardPay, gcPayInfo, giftCards, orderDon, goodsDon, sku, dpSkuIds);
|
|
|
//下单手机号
|
|
|
orderDon.setPhone(orderPhone);
|
|
|
this.saveOrUpdate(orderDon);
|
|
|
@@ -647,6 +596,8 @@ public class OrderDonServiceImpl extends ServiceImpl<OrderDonMapper, OrderDon> i
|
|
|
}
|
|
|
//记录订单ip关联
|
|
|
recordOrderDonLocationRelate(orderDon.getId(), payRequest.getIp());
|
|
|
+ //记录补贴订单关联
|
|
|
+ recordOrderDonSubsidyRelate(orderDon.getId(), subsidyId);
|
|
|
return orderDon;
|
|
|
}
|
|
|
|
|
|
@@ -1005,7 +956,7 @@ public class OrderDonServiceImpl extends ServiceImpl<OrderDonMapper, OrderDon> i
|
|
|
}
|
|
|
orderDon.setRealMoney(orderDon.getMoney());
|
|
|
//扣除使用优惠券、余额的订单金额
|
|
|
- deductOrderMoney(orderDon, couponUser, payRequest.getBalance(), user, sku.getPrice(), goodsDon.getType(), payRequest.getGcCash(), payRequest.getGcpIds(), false);
|
|
|
+ deductOrderMoney(orderDon, couponUser, payRequest.getBalance(), user, sku.getPrice(), goodsDon.getType(), payRequest.getGcCash(), payRequest.getGcpIds(), false, null);
|
|
|
this.saveOrUpdate(orderDon);
|
|
|
if (orderDon.getStatus() == OrderDon.Status.noPayment) {
|
|
|
jobManager.addJob(EXPIRY_TIME, () -> {
|
|
|
@@ -2093,13 +2044,13 @@ public class OrderDonServiceImpl extends ServiceImpl<OrderDonMapper, OrderDon> i
|
|
|
/**
|
|
|
* 使用优惠营销 订单金额抵扣
|
|
|
*/
|
|
|
- public void deductOrderMoney(OrderDon orderDon, CouponUser couponUser, BigDecimal balance, User user, BigDecimal skuMoney, Integer goodsType, BigDecimal gcCash, List<Long> gcpIds, Boolean isAcReduce) {
|
|
|
+ public void deductOrderMoney(OrderDon orderDon, CouponUser couponUser, BigDecimal balance, User user, BigDecimal skuMoney, Integer goodsType, BigDecimal gcCash, List<Long> gcpIds, Boolean isAcReduce, Long subsidyId) {
|
|
|
if (gcCash != null && gcCash.compareTo(BigDecimal.ZERO) > 0 && couponUser != null) {
|
|
|
throw BusinessRuntimeException.getInstance("现金卡不能与其他优惠叠加使用");
|
|
|
}
|
|
|
BigDecimal first_money = orderDon.getMoney();
|
|
|
//礼品卡现金支付 不参与其他优惠
|
|
|
- if (gcCash != null && gcCash.compareTo(BigDecimal.ZERO) > 0) {
|
|
|
+ if (subsidyId == null && gcCash != null && gcCash.compareTo(BigDecimal.ZERO) > 0) {
|
|
|
if (CollUtil.isEmpty(gcpIds)) {
|
|
|
throw BusinessRuntimeException.getInstance("礼品卡现金支付参数异常");
|
|
|
}
|
|
|
@@ -2151,7 +2102,7 @@ public class OrderDonServiceImpl extends ServiceImpl<OrderDonMapper, OrderDon> i
|
|
|
return;
|
|
|
}
|
|
|
//存在优惠券
|
|
|
- if (couponUser != null) {
|
|
|
+ if (couponUser != null && subsidyId == null) {
|
|
|
Long couponId = couponUser.getCouponId();
|
|
|
Coupon coupon = couponMapper.getCouponById(couponId);
|
|
|
BigDecimal couponMoney = null;
|
|
|
@@ -2191,7 +2142,7 @@ public class OrderDonServiceImpl extends ServiceImpl<OrderDonMapper, OrderDon> i
|
|
|
orderDon.setCouponUserId(couponUser.getId());
|
|
|
}
|
|
|
//特殊渠道推广优惠. 360
|
|
|
- if (orderDon.getPopularizeId() != null && orderDon.getPopularizeId() != 0L) {
|
|
|
+ if (subsidyId == null && orderDon.getPopularizeId() != null && orderDon.getPopularizeId() != 0L) {
|
|
|
//使用了优惠券 不再使用360渠道 折扣
|
|
|
if (couponUser == null && goodsType == 1) {
|
|
|
//百度渠道 专门优惠链接
|
|
|
@@ -2793,7 +2744,7 @@ public class OrderDonServiceImpl extends ServiceImpl<OrderDonMapper, OrderDon> i
|
|
|
clearUserLockingRelation(groupsRelationMapper.selectById(orderDon.getRelationId()), orderDon);
|
|
|
|
|
|
//记录退款
|
|
|
- orderRefundService.refundRecord(orderDon, orderRefundReq.getRefundMoney(), null, goodsDon, sku, outNo, orderDon.getType().getType());
|
|
|
+ orderRefundService.refundRecord(orderDon, orderRefundReq.getRefundMoney(), null, goodsDon, sku, outNo, orderDon.getType().getType(), null);
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
@@ -2988,4 +2939,119 @@ 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"));
|
|
|
+ if (goodsDonSkuSubsidy == null || !goodsDonSkuSubsidy.getDeleted()) {
|
|
|
+ throw BusinessRuntimeException.getInstance("商品不存在");
|
|
|
+ }
|
|
|
+ if (!goodsDonSkuSubsidy.getStatus()) {
|
|
|
+ throw BusinessRuntimeException.getInstance("规格已下架");
|
|
|
+ }
|
|
|
+ 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("商品价格异常..");
|
|
|
+ }
|
|
|
+ //是否购买过该规格
|
|
|
+ List<Long> userIdList = userBindRelationService.getRelationUserIdList(user.getId(), user);
|
|
|
+ Integer selectCount = orderDonMapper.selectCount(Wrappers.lambdaQuery(OrderDon.class)
|
|
|
+ .eq(OrderDon::getSkuId, skuId)
|
|
|
+ .in(OrderDon::getUserId, userIdList)
|
|
|
+ .ne(OrderDon::getStatus, OrderDon.Status.close));
|
|
|
+ if (selectCount > 0) {
|
|
|
+ throw BusinessRuntimeException.getInstance("只可购买一次该补贴规格");
|
|
|
+ }
|
|
|
+ orderDon.setMoney(price);
|
|
|
+ }
|
|
|
}
|