|
|
@@ -94,6 +94,7 @@ import java.math.RoundingMode;
|
|
|
import java.util.Date;
|
|
|
import java.util.List;
|
|
|
import java.util.Map;
|
|
|
+import java.util.Objects;
|
|
|
import java.util.Optional;
|
|
|
import java.util.UUID;
|
|
|
import java.util.concurrent.atomic.AtomicInteger;
|
|
|
@@ -479,10 +480,10 @@ public class CmsOrderDonServiceImpl extends ServiceImpl<OrderDonMapper,OrderDon>
|
|
|
return;
|
|
|
}
|
|
|
validateMultiQuantityWholeRefund(refundReq, orderDon);
|
|
|
- multiQuantityOrderService.prepareRefund(orderId);
|
|
|
- if (orderDon.getType() == OrderDon.Type.PAYPAL || orderDon.getType() == OrderDon.Type.STRIPE) {
|
|
|
+ if (requiresManualMultiQuantityRefund(orderDon)) {
|
|
|
throw BusinessRuntimeException.getInstance("PayPal/Stripe批量订单请人工核对后退款");
|
|
|
}
|
|
|
+ multiQuantityOrderService.prepareRefund(orderId);
|
|
|
OrderDonBusinessEvent refundEvent = orderDonBusinessEventService.get(
|
|
|
orderId, OrderDonBusinessEvent.Type.refund);
|
|
|
if (refundEvent != null && refundEvent.getStatus() == OrderDonBusinessEvent.Status.processing) {
|
|
|
@@ -588,17 +589,13 @@ public class CmsOrderDonServiceImpl extends ServiceImpl<OrderDonMapper,OrderDon>
|
|
|
}
|
|
|
return;
|
|
|
}
|
|
|
- String workerToken;
|
|
|
- if (providerStatus == ProviderRefundStatus.SUCCESS) {
|
|
|
- workerToken = refundEvent.getWorkerToken();
|
|
|
- if (StrUtil.isBlank(workerToken)) {
|
|
|
- throw new IllegalStateException("refund worker token is missing");
|
|
|
- }
|
|
|
- } else {
|
|
|
- workerToken = orderDonTicketRecordService.reclaimExpiredRefund(order.getId(), leaseMinutes);
|
|
|
- if (workerToken == null) {
|
|
|
- return;
|
|
|
- }
|
|
|
+ if (!requiresRefundLeaseReclaim(providerStatus)) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ String workerToken = orderDonTicketRecordService.reclaimExpiredRefund(
|
|
|
+ order.getId(), leaseMinutes);
|
|
|
+ if (workerToken == null) {
|
|
|
+ return;
|
|
|
}
|
|
|
|
|
|
if (providerStatus == ProviderRefundStatus.FAILED) {
|
|
|
@@ -752,7 +749,16 @@ public class CmsOrderDonServiceImpl extends ServiceImpl<OrderDonMapper,OrderDon>
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- private enum ProviderRefundStatus {
|
|
|
+ static boolean requiresManualMultiQuantityRefund(OrderDon order) {
|
|
|
+ return order != null && (order.getType() == OrderDon.Type.PAYPAL
|
|
|
+ || order.getType() == OrderDon.Type.STRIPE);
|
|
|
+ }
|
|
|
+
|
|
|
+ static boolean requiresRefundLeaseReclaim(ProviderRefundStatus status) {
|
|
|
+ return status == ProviderRefundStatus.SUCCESS || status == ProviderRefundStatus.FAILED;
|
|
|
+ }
|
|
|
+
|
|
|
+ enum ProviderRefundStatus {
|
|
|
SUCCESS,
|
|
|
PROCESSING,
|
|
|
FAILED,
|
|
|
@@ -1742,10 +1748,10 @@ public class CmsOrderDonServiceImpl extends ServiceImpl<OrderDonMapper,OrderDon>
|
|
|
goodsDonStockService.upStockRelate(null, orderDon.getId(), "refund");
|
|
|
}
|
|
|
try {
|
|
|
- if (!multiQuantityOrder && !orderDon.getIsDp()) {
|
|
|
+ if (!multiQuantityOrder && !Boolean.TRUE.equals(orderDon.getIsDp())) {
|
|
|
GroupsRelation relation = relationMapper.selectById(orderDon.getRelationId());
|
|
|
//冻结车票 清除
|
|
|
- if (relation != null && relation.getIsFrozen()) {
|
|
|
+ if (relation != null && Boolean.TRUE.equals(relation.getIsFrozen())) {
|
|
|
Optional.ofNullable(receivedRecordMapper.selectOne(Wrappers.lambdaQuery(AccountNetflixFrozenTicketReceivedRecord.class).eq(AccountNetflixFrozenTicketReceivedRecord::getRelationId, relation.getId()).last("limit 1")))
|
|
|
.ifPresent(rr -> {
|
|
|
Long sendRelationId = rr.getSendRelationId();
|
|
|
@@ -1763,7 +1769,7 @@ public class CmsOrderDonServiceImpl extends ServiceImpl<OrderDonMapper,OrderDon>
|
|
|
log.error("清除车票错误:{}", StringUtil.getErrorText(e));
|
|
|
}
|
|
|
//若存在优惠券使用,退还优惠券
|
|
|
- if (orderDon.getCouponUserId() != 0) {
|
|
|
+ if (orderDon.getCouponUserId() != null && orderDon.getCouponUserId() != 0L) {
|
|
|
couponFontService.updateOrderDonCouponStatus(orderDon);
|
|
|
}
|
|
|
//退等比例
|
|
|
@@ -1799,7 +1805,8 @@ public class CmsOrderDonServiceImpl extends ServiceImpl<OrderDonMapper,OrderDon>
|
|
|
// }
|
|
|
|
|
|
//扣除 该笔订单产生的返现银河币
|
|
|
- if (orderDon.getMoney().compareTo(BigDecimal.ZERO) > 0) {
|
|
|
+ if (Optional.ofNullable(orderDon.getMoney()).orElse(BigDecimal.ZERO)
|
|
|
+ .compareTo(BigDecimal.ZERO) > 0) {
|
|
|
userGalaxyCoinService.subOrderGenerateGalaxyCoin(orderDon.getId(), OrderDonGalaxyCoinRecord.Source.ordinary);
|
|
|
}
|
|
|
|
|
|
@@ -1810,7 +1817,8 @@ public class CmsOrderDonServiceImpl extends ServiceImpl<OrderDonMapper,OrderDon>
|
|
|
|
|
|
try {
|
|
|
marketFrontService.subSpecificChanceNum(orderDon.getUserId(), orderDon.getId(), orderDon.getGoodsId(), orderDon.getUpdateTime());
|
|
|
- if (goodsDon.getType() == 2 && !orderDon.getIsDistribute()) {
|
|
|
+ if (goodsDon != null && Objects.equals(goodsDon.getType(), 2)
|
|
|
+ && !Boolean.TRUE.equals(orderDon.getIsDistribute())) {
|
|
|
equipmentDistributeService.subDistributeBenefitsChance(orderDon.getUserId(), orderDon.getId());
|
|
|
//扣除用户自身实物权益
|
|
|
userRealOrderBenefitsService.deductUserRealGoodsBenefits(orderDon.getId());
|
|
|
@@ -1839,7 +1847,7 @@ public class CmsOrderDonServiceImpl extends ServiceImpl<OrderDonMapper,OrderDon>
|
|
|
deductUserMirrorShopMoney(orderDon);
|
|
|
}
|
|
|
|
|
|
- if (orderDon.getIsFixedDistribute()) {
|
|
|
+ if (Boolean.TRUE.equals(orderDon.getIsFixedDistribute())) {
|
|
|
//商务提成 因订单退款去掉
|
|
|
UserDistributeBusinessOrderDonRecord record = businessOrderDonRecordMapper.selectOne(Wrappers.lambdaQuery(UserDistributeBusinessOrderDonRecord.class)
|
|
|
.eq(UserDistributeBusinessOrderDonRecord::getOrderId, orderDon.getId())
|
|
|
@@ -1863,7 +1871,7 @@ public class CmsOrderDonServiceImpl extends ServiceImpl<OrderDonMapper,OrderDon>
|
|
|
}
|
|
|
}
|
|
|
//是否是优惠加购关联订单
|
|
|
- if (orderDon.getIsDp()) {
|
|
|
+ if (Boolean.TRUE.equals(orderDon.getIsDp())) {
|
|
|
OrderDiscountPlusPurchaseSkuRelation discountPlusPurchaseSkuRelation = orderDiscountPlusPurchaseSkuRelationMapper.selectOne(Wrappers.lambdaQuery(OrderDiscountPlusPurchaseSkuRelation.class)
|
|
|
.eq(OrderDiscountPlusPurchaseSkuRelation::getOrderId, orderDon.getId()).last("limit 1"));
|
|
|
if (discountPlusPurchaseSkuRelation != null) {
|
|
|
@@ -1946,7 +1954,7 @@ public class CmsOrderDonServiceImpl extends ServiceImpl<OrderDonMapper,OrderDon>
|
|
|
handleSubRewards(orderDon);
|
|
|
|
|
|
//是否是用户套餐优惠权益订单
|
|
|
- if (orderDon.getGoodsId() == 15) {
|
|
|
+ if (Objects.equals(orderDon.getGoodsId(), 15L)) {
|
|
|
UserBenefitsComboRelationRecord userBenefitsComboRelationRecord = userBenefitsComboRelationRecordMapper.selectOne(Wrappers.lambdaQuery(UserBenefitsComboRelationRecord.class)
|
|
|
.eq(UserBenefitsComboRelationRecord::getOrderId, orderDon.getId()).last("limit 1"));
|
|
|
if (userBenefitsComboRelationRecord != null) {
|
|
|
@@ -1965,7 +1973,7 @@ public class CmsOrderDonServiceImpl extends ServiceImpl<OrderDonMapper,OrderDon>
|
|
|
//HBO GO退款,车队上架
|
|
|
setUpIfEmpty(orderDon.getGoodsId(), orderDon.getRelationId());
|
|
|
|
|
|
- if (orderDon.getGoodsId() == Constant.NETFLIX_GID) {
|
|
|
+ if (Objects.equals(orderDon.getGoodsId(), Constant.NETFLIX_GID)) {
|
|
|
List<Long> userIdList = userBindRelationService.getRelationUserIdList(orderDon.getUserId(), null);
|
|
|
NetflixUserAccountSubmitRecoverRecord recoverRecord = netflixUserAccountSubmitRecoverRecordMapper.selectOne(Wrappers.lambdaQuery(NetflixUserAccountSubmitRecoverRecord.class)
|
|
|
.eq(NetflixUserAccountSubmitRecoverRecord::getRelationId, orderDon.getRelationId())
|
|
|
@@ -1979,12 +1987,15 @@ public class CmsOrderDonServiceImpl extends ServiceImpl<OrderDonMapper,OrderDon>
|
|
|
}
|
|
|
|
|
|
//GPT独立会员
|
|
|
- if (orderDon.getGoodsId() == Constant.GPT_PLUS_GID && sku.getNum() == 1) {
|
|
|
+ if (Objects.equals(orderDon.getGoodsId(), Constant.GPT_PLUS_GID)
|
|
|
+ && sku != null && Objects.equals(sku.getNum(), 1)) {
|
|
|
subRechargeNumOrder(orderDon.getUserId(), orderDon.getRelationId(), sku.getMonths(), operator);
|
|
|
}
|
|
|
|
|
|
//GPT独立会员退款 或代充退款 退还平台发券
|
|
|
- if ((orderDon.getGoodsId() == Constant.GPT_PLUS_GID && sku.getNum() == 1) || orderDon.getGoodsId() == Constant.GPT_RECHARGE_GOODS_ID) {
|
|
|
+ if ((Objects.equals(orderDon.getGoodsId(), Constant.GPT_PLUS_GID)
|
|
|
+ && sku != null && Objects.equals(sku.getNum(), 1))
|
|
|
+ || Objects.equals(orderDon.getGoodsId(), Constant.GPT_RECHARGE_GOODS_ID)) {
|
|
|
//若不存在对应的车票 则清除优惠券
|
|
|
List<Long> skuIds = goodsDonSkuMapper.selectIdpGptAndRechargeSkuIds(Constant.GPT_PLUS_GID, Constant.GPT_RECHARGE_GOODS_ID);
|
|
|
List<Long> userIdList = userBindRelationService.getRelationUserIdList(orderDon.getUserId(), null);
|
|
|
@@ -2005,7 +2016,7 @@ public class CmsOrderDonServiceImpl extends ServiceImpl<OrderDonMapper,OrderDon>
|
|
|
}
|
|
|
|
|
|
//claude code 退款
|
|
|
- if (orderDon.getGoodsId() == Constant.CLAUDE_CODE_GOODS_ID) {
|
|
|
+ if (Objects.equals(orderDon.getGoodsId(), Constant.CLAUDE_CODE_GOODS_ID)) {
|
|
|
DistributeWaitingSendPoints distributeWaitingSendPoints = distributeWaitingSendPointsMapper.selectOne(Wrappers.lambdaQuery(DistributeWaitingSendPoints.class).eq(DistributeWaitingSendPoints::getOrderId, orderDon.getId()).last("limit 1"));
|
|
|
if (distributeWaitingSendPoints != null) {
|
|
|
if (distributeWaitingSendPoints.getSendStatus() == DistributeWaitingSendPoints.Status.close) {
|
|
|
@@ -2022,13 +2033,13 @@ public class CmsOrderDonServiceImpl extends ServiceImpl<OrderDonMapper,OrderDon>
|
|
|
|
|
|
//处理下级渠道分销提成
|
|
|
static boolean shouldRestoreStock(GoodsDon goodsDon, boolean multiQuantityOrder) {
|
|
|
- return !multiQuantityOrder || goodsDon == null || goodsDon.getType() != 1;
|
|
|
+ return !multiQuantityOrder || goodsDon == null || !Objects.equals(goodsDon.getType(), 1);
|
|
|
}
|
|
|
|
|
|
public void handleSubRewards(OrderDon orderDon) {
|
|
|
//是否是分销订单
|
|
|
//处理下级渠道分销提成
|
|
|
- if (orderDon.getIsDistribute()) {
|
|
|
+ if (orderDon != null && Boolean.TRUE.equals(orderDon.getIsDistribute())) {
|
|
|
UserDistributeSub subRelate = userDistributeSubMapper.getSubRelate(orderDon.getUserId());
|
|
|
if (subRelate != null) {
|
|
|
List<UserDistributeSubWaiting> subWaitings = subWaitingMapper.selectList(Wrappers.lambdaQuery(UserDistributeSubWaiting.class)
|
|
|
@@ -2061,7 +2072,7 @@ public class CmsOrderDonServiceImpl extends ServiceImpl<OrderDonMapper,OrderDon>
|
|
|
* 退款 分销提成积分扣除
|
|
|
*/
|
|
|
public void deductDsPoints(OrderDon orderDon) {
|
|
|
- if (orderDon.getIsDistribute()) {
|
|
|
+ if (orderDon != null && Boolean.TRUE.equals(orderDon.getIsDistribute())) {
|
|
|
DistributeWaitingSendPoints distributeWaitingSendPoints = distributeWaitingSendPointsMapper.selectOne(Wrappers.lambdaQuery(DistributeWaitingSendPoints.class).eq(DistributeWaitingSendPoints::getOrderId, orderDon.getId()).eq(DistributeWaitingSendPoints::getIsVip,Boolean.FALSE).last("limit 1"));
|
|
|
if (distributeWaitingSendPoints != null) {
|
|
|
BigDecimal money = orderDon.getMoney();
|
|
|
@@ -2071,7 +2082,7 @@ public class CmsOrderDonServiceImpl extends ServiceImpl<OrderDonMapper,OrderDon>
|
|
|
BigDecimal points = distributeWaitingSendPoints.getPoints();
|
|
|
if (sendStatus == DistributeWaitingSendPoints.Status.waiting) {
|
|
|
//实物设备退款就清0
|
|
|
- if (refundMoney.compareTo(money) == 0 || orderDon.getGoodsId() == 15) {
|
|
|
+ if (refundMoney.compareTo(money) == 0 || Objects.equals(orderDon.getGoodsId(), 15L)) {
|
|
|
//待发送状态 全额退款
|
|
|
distributeWaitingSendPoints.setSendStatus(DistributeWaitingSendPoints.Status.close);
|
|
|
distributeWaitingSendPoints.setRefundPoints(points);
|
|
|
@@ -2092,9 +2103,10 @@ public class CmsOrderDonServiceImpl extends ServiceImpl<OrderDonMapper,OrderDon>
|
|
|
BigDecimal remainPoints = points.subtract(needSubPoints);
|
|
|
distributeWaitingSendPoints.setPoints(remainPoints);
|
|
|
//原先获取积分也扣除
|
|
|
- if (distributeWaitingSendPoints.getOriPoints().compareTo(BigDecimal.ZERO) > 0) {
|
|
|
- BigDecimal oriNeedSubPoints = distributeWaitingSendPoints.getOriPoints().multiply(refundRate);
|
|
|
- distributeWaitingSendPoints.setOriPoints(distributeWaitingSendPoints.getOriPoints().subtract(oriNeedSubPoints));
|
|
|
+ BigDecimal oriPoints = distributeWaitingSendPoints.getOriPoints();
|
|
|
+ if (oriPoints != null && oriPoints.compareTo(BigDecimal.ZERO) > 0) {
|
|
|
+ BigDecimal oriNeedSubPoints = oriPoints.multiply(refundRate);
|
|
|
+ distributeWaitingSendPoints.setOriPoints(oriPoints.subtract(oriNeedSubPoints));
|
|
|
}
|
|
|
distributeWaitingSendPointsMapper.updateById(distributeWaitingSendPoints);
|
|
|
}
|
|
|
@@ -2102,7 +2114,7 @@ public class CmsOrderDonServiceImpl extends ServiceImpl<OrderDonMapper,OrderDon>
|
|
|
//已发送的提成 部分退款 全额退款 需要扣除用户积分
|
|
|
//扣除固定推广者积分
|
|
|
//实物设备退款就清0
|
|
|
- if (refundMoney.compareTo(money) == 0 || orderDon.getGoodsId() == 15) {
|
|
|
+ if (refundMoney.compareTo(money) == 0 || Objects.equals(orderDon.getGoodsId(), 15L)) {
|
|
|
userBenefitsService.deductDistributePoints(orderDon.getId(), distributeWaitingSendPoints.getSharedId(), points);
|
|
|
distributeWaitingSendPoints.setRefundPoints(points);
|
|
|
distributeWaitingSendPoints.setPoints(BigDecimal.ZERO);
|
|
|
@@ -2123,9 +2135,10 @@ public class CmsOrderDonServiceImpl extends ServiceImpl<OrderDonMapper,OrderDon>
|
|
|
distributeWaitingSendPoints.setRefundPoints(needSubPoints);
|
|
|
distributeWaitingSendPoints.setPoints(points.subtract(needSubPoints));
|
|
|
//原先获取积分也扣除
|
|
|
- if (distributeWaitingSendPoints.getOriPoints().compareTo(BigDecimal.ZERO) > 0) {
|
|
|
- BigDecimal oriNeedSubPoints = distributeWaitingSendPoints.getOriPoints().multiply(refundRate);
|
|
|
- distributeWaitingSendPoints.setOriPoints(distributeWaitingSendPoints.getOriPoints().subtract(oriNeedSubPoints));
|
|
|
+ BigDecimal oriPoints = distributeWaitingSendPoints.getOriPoints();
|
|
|
+ if (oriPoints != null && oriPoints.compareTo(BigDecimal.ZERO) > 0) {
|
|
|
+ BigDecimal oriNeedSubPoints = oriPoints.multiply(refundRate);
|
|
|
+ distributeWaitingSendPoints.setOriPoints(oriPoints.subtract(oriNeedSubPoints));
|
|
|
}
|
|
|
distributeWaitingSendPointsMapper.updateById(distributeWaitingSendPoints);
|
|
|
}
|