订单 退款 问题

This commit is contained in:
2025-12-25 16:28:19 +08:00
parent 0b5ec53187
commit b171b1a81f
8 changed files with 105 additions and 36 deletions

View File

@@ -21,6 +21,7 @@ public interface MkConsumeCashbackService extends IService<MkConsumeCashback> {
/** /**
* 消费返现 * 消费返现
*
* @param shopId 店铺id * @param shopId 店铺id
* @param userId 用户id * @param userId 用户id
* @param amount 金额 * @param amount 金额
@@ -28,4 +29,6 @@ public interface MkConsumeCashbackService extends IService<MkConsumeCashback> {
* @param orderNo 订单号 * @param orderNo 订单号
*/ */
void cashback(Long shopId, Long userId, BigDecimal amount, Long orderId, String orderNo); void cashback(Long shopId, Long userId, BigDecimal amount, Long orderId, String orderNo);
void removeCashback(Long shopId, Long userId, Long orderId, String orderNo);
} }

View File

@@ -22,6 +22,12 @@ public interface MkShopConsumerCouponService extends IService<MkShopConsumerCoup
*/ */
void receiveConsumerCoupon(Long shopId, Long orderId, BigDecimal orderAmount, Long userId, Long shopUserId); void receiveConsumerCoupon(Long shopId, Long orderId, BigDecimal orderAmount, Long userId, Long shopUserId);
/**
* 订单退款 移除消费赠券
*
*/
void removeConsumerCoupon(Long shopId, Long userId, Long orderId);
MkShopConsumerCouponDTO getConsumerCouponById(Long id); MkShopConsumerCouponDTO getConsumerCouponById(Long id);
void addConsumerCoupon(MkShopConsumerCouponDTO param); void addConsumerCoupon(MkShopConsumerCouponDTO param);

View File

@@ -160,7 +160,7 @@ public class MkConsumeCashbackServiceImpl extends ServiceImpl<MkConsumeCashbackM
shopUserService.updateMoney(new ShopUserMoneyEditDTO().setId(shopUser.getId()).setType(1) shopUserService.updateMoney(new ShopUserMoneyEditDTO().setId(shopUser.getId()).setType(1)
.setRelationId(mkConsumeCashbackRecord.getId()).setMoney(cashbackAmount).setBizEnum(ShopUserFlowBizEnum.CASHBACK) .setRelationId(mkConsumeCashbackRecord.getId()).setMoney(cashbackAmount).setBizEnum(ShopUserFlowBizEnum.CASHBACK)
.setRemark(StrUtil.format("订单消费: {}, 返现: {}", amount, cashbackAmount))); .setRemark(StrUtil.format("订单消费: {}, 返现: {}", amount, cashbackAmount)));
log.info("订单返现 订单ID:{}, 店铺用户id: {}, 订单消费: {}, 返现: {}",orderId, shopUser.getId(), amount, cashbackAmount); log.info("订单返现 订单ID:{}, 店铺用户id: {}, 订单消费: {}, 返现: {}", orderId, shopUser.getId(), amount, cashbackAmount);
AcUserMsg msg = new AcUserMsg() AcUserMsg msg = new AcUserMsg()
.setUserId(userId) .setUserId(userId)
@@ -176,4 +176,43 @@ public class MkConsumeCashbackServiceImpl extends ServiceImpl<MkConsumeCashbackM
} }
} }
} }
@Override
@Transactional(rollbackFor = Exception.class)
public void removeCashback(Long shopId, Long userId, Long orderId, String orderNo) {
MkConsumeCashbackRecord record = consumeCashbackRecordService.getOne(query()
.eq(MkConsumeCashbackRecord::getShopId, shopId)
.eq(MkConsumeCashbackRecord::getUserId, userId)
.eq(MkConsumeCashbackRecord::getOrderNo, orderNo)
.eq(MkConsumeCashbackRecord::getOrderId, orderId));
if (record == null) {
return;
}
MkConsumeCashbackRecord mkConsumeCashbackRecord = new MkConsumeCashbackRecord()
.setOrderNo(orderNo)
.setOrderId(orderId)
.setMainShopId(record.getMainShopId())
.setShopId(shopId)
.setAmount(BigDecimal.ZERO)
.setCashbackAmount(record.getAmount().negate())
.setUserId(userId)
.setShopUserId(record.getShopUserId());
consumeCashbackRecordService.save(mkConsumeCashbackRecord);
shopUserService.updateMoney(new ShopUserMoneyEditDTO().setId(record.getShopUserId()).setType(0)
.setRelationId(mkConsumeCashbackRecord.getId())
.setMoney(record.getAmount())
.setBizEnum(ShopUserFlowBizEnum.CASHBACK)
.setRemark(StrUtil.format("订单退款,扣除返现: {}", record.getAmount())));
log.info("订单退款扣除返现 订单ID:{}, 店铺用户id: {}, 扣除返现: {}", orderId, record.getShopUserId(), record.getAmount());
AcUserMsg msg = new AcUserMsg()
.setUserId(userId)
.setShopId(shopId)
.setSourceId(orderId)
.setSourceType("order")
.setType("cash")
.setTitle("订单退款,消费返现扣除")
.setContent(StrUtil.format("返现扣除提醒: 订单退款扣除的{}元返现。订单编号:{}", record.getAmount(), orderNo));
acUserMsgService.addUserMsg(msg);
}
} }

View File

@@ -23,6 +23,7 @@ import com.mybatisflex.spring.service.impl.ServiceImpl;
import jakarta.annotation.Resource; import jakarta.annotation.Resource;
import org.apache.dubbo.config.annotation.DubboReference; import org.apache.dubbo.config.annotation.DubboReference;
import org.apache.dubbo.config.annotation.DubboService; import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.transaction.annotation.Transactional;
import java.util.List; import java.util.List;
@@ -131,9 +132,6 @@ public class MkPointsUserServiceImpl extends ServiceImpl<MkPointsUserMapper, MkP
break; break;
case SUB: case SUB:
pointsUser.setPointBalance(pointsUser.getPointBalance() - points); pointsUser.setPointBalance(pointsUser.getPointBalance() - points);
if (pointsUser.getPointBalance() < 0) {
throw new CzgException("积分操作失败,积分不足");
}
points = -points; points = -points;
break; break;
default: default:

View File

@@ -110,6 +110,17 @@ public class MkShopConsumerCouponServiceImpl extends ServiceImpl<MkShopConsumerC
} }
} }
@Override
public void removeConsumerCoupon(Long shopId, Long userId, Long orderId) {
recordService.remove(query()
.eq(MkShopCouponRecord::getShopId, shopId)
.eq(MkShopCouponRecord::getUserId, userId)
.eq(MkShopCouponRecord::getSourceFlowId, orderId)
.eq(MkShopCouponRecord::getSource, "消费赠券")
);
}
@Override @Override
public MkShopConsumerCouponDTO getConsumerCouponById(Long id) { public MkShopConsumerCouponDTO getConsumerCouponById(Long id) {
AssertUtil.isNull(id, "ID不能为空"); AssertUtil.isNull(id, "ID不能为空");

View File

@@ -1060,8 +1060,7 @@ public class OrderInfoCustomServiceImpl implements OrderInfoCustomService {
distributionUserService.costUpgradeLevelBefore(orderInfo.getUserId(), orderInfo.getShopId()); distributionUserService.costUpgradeLevelBefore(orderInfo.getUserId(), orderInfo.getShopId());
// 分销奖励 // 分销奖励
distributionUserService.distribute(orderInfo.getId(), orderInfo.getOrderNo(), payment.getAmount(), orderInfo.getUserId(), orderInfo.getShopId(), "order"); distributionUserService.distribute(orderInfo.getId(), orderInfo.getOrderNo(), payment.getAmount(), orderInfo.getUserId(), orderInfo.getShopId(), "order");
} } else if (PayTypeConstants.SourceType.MEMBER_IN.equals(payment.getSourceType()) || PayTypeConstants.SourceType.FREE.equals(payment.getSourceType())) {
else if (PayTypeConstants.SourceType.MEMBER_IN.equals(payment.getSourceType()) || PayTypeConstants.SourceType.FREE.equals(payment.getSourceType())) {
boolean isFree = PayTypeConstants.SourceType.FREE.equals(payment.getSourceType()); boolean isFree = PayTypeConstants.SourceType.FREE.equals(payment.getSourceType());
ShopUser shopUser = shopUserService.getById(payment.getSourceId()); ShopUser shopUser = shopUserService.getById(payment.getSourceId());
OrderInfo orderInfo = null; OrderInfo orderInfo = null;
@@ -1162,8 +1161,7 @@ public class OrderInfoCustomServiceImpl implements OrderInfoCustomService {
// if (orderInfo != null) { // if (orderInfo != null) {
// distributionUserService.distribute(payment.getId(), payment.getOrderNo(), payment.getAmount(), orderInfo.getUserId(), payment.getShopId(), "recharge"); // distributionUserService.distribute(payment.getId(), payment.getOrderNo(), payment.getAmount(), orderInfo.getUserId(), payment.getShopId(), "recharge");
// } // }
} } else if (PayTypeConstants.SourceType.MEMBER_PAY.equals(payment.getSourceType())) {
else if (PayTypeConstants.SourceType.MEMBER_PAY.equals(payment.getSourceType())) {
//购买会员 //购买会员
ShopUser shopUser = shopUserService.getById(payment.getSourceId()); ShopUser shopUser = shopUserService.getById(payment.getSourceId());
memberConfigService.joinMember(payment.getShopId(), shopUser.getUserId(), payment.getRelatedId()); memberConfigService.joinMember(payment.getShopId(), shopUser.getUserId(), payment.getRelatedId());
@@ -1171,17 +1169,13 @@ public class OrderInfoCustomServiceImpl implements OrderInfoCustomService {
// memberConfigService.deliver(shopUser.getMainShopId(), shopUser.getUserId(), TableValueConstant.MemberExpFlow.Type.COST, payment.getAmount(), null, payment.getId()); // memberConfigService.deliver(shopUser.getMainShopId(), shopUser.getUserId(), TableValueConstant.MemberExpFlow.Type.COST, payment.getAmount(), null, payment.getId());
// 分销员开通 // 分销员开通
} } else if (PayTypeConstants.SourceType.DISTRIBUTION.equals(payment.getSourceType())) {
else if (PayTypeConstants.SourceType.DISTRIBUTION.equals(payment.getSourceType())) {
distributionUserService.open(payment.getSourceId(), payment.getAmount(), payment.getShopId(), payment.getId()); distributionUserService.open(payment.getSourceId(), payment.getAmount(), payment.getShopId(), payment.getId());
} } else if (PayTypeConstants.SourceType.POINT.equals(payment.getSourceType())) {
else if (PayTypeConstants.SourceType.POINT.equals(payment.getSourceType())) {
goodPayService.payCallBack(payment.getSourceId(), payment.getId()); goodPayService.payCallBack(payment.getSourceId(), payment.getId());
} } else if (PayTypeConstants.SourceType.WARE.equals(payment.getSourceType())) {
else if (PayTypeConstants.SourceType.WARE.equals(payment.getSourceType())) {
gbOrderService.payCallBack(payment.getSourceId(), payment.getId()); gbOrderService.payCallBack(payment.getSourceId(), payment.getId());
} } else if (PayTypeConstants.SourceType.PP.equals(payment.getSourceType())) {
else if (PayTypeConstants.SourceType.PP.equals(payment.getSourceType())) {
ppPackageOrderService.paySuccess(payment.getSourceId(), payment.getId()); ppPackageOrderService.paySuccess(payment.getSourceId(), payment.getId());
} }
} }

View File

@@ -24,6 +24,7 @@ import com.czg.market.dto.MemberOrderDTO;
import com.czg.market.entity.MemberOrder; import com.czg.market.entity.MemberOrder;
import com.czg.market.entity.MkShopCouponRecord; import com.czg.market.entity.MkShopCouponRecord;
import com.czg.market.entity.MkShopRechargeDetail; import com.czg.market.entity.MkShopRechargeDetail;
import com.czg.market.enums.PointsConstant;
import com.czg.market.service.*; import com.czg.market.service.*;
import com.czg.market.vo.MkShopRechargeVO; import com.czg.market.vo.MkShopRechargeVO;
import com.czg.order.dto.CheckOrderPay; import com.czg.order.dto.CheckOrderPay;
@@ -51,12 +52,14 @@ import com.czg.service.order.service.PayService;
import com.czg.system.service.SysParamsService; import com.czg.system.service.SysParamsService;
import com.czg.utils.AssertUtil; import com.czg.utils.AssertUtil;
import com.czg.utils.CzgRandomUtils; import com.czg.utils.CzgRandomUtils;
import com.czg.utils.FunUtils;
import com.mybatisflex.core.query.QueryWrapper; import com.mybatisflex.core.query.QueryWrapper;
import jakarta.annotation.Resource; import jakarta.annotation.Resource;
import jakarta.validation.constraints.NotBlank; import jakarta.validation.constraints.NotBlank;
import lombok.NonNull; import lombok.NonNull;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.apache.dubbo.config.annotation.DubboReference; import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
@@ -116,9 +119,13 @@ public class PayServiceImpl implements PayService {
@Resource @Resource
private MkShopRechargeDetailService shopRechargeDetailService; private MkShopRechargeDetailService shopRechargeDetailService;
@Resource @Resource
private TbMemberConfigService memberConfigService;
@Resource
private MkDistributionUserService distributionUserService; private MkDistributionUserService distributionUserService;
@Resource
private MkShopConsumerCouponService consumerCouponService;
@Resource
private MkPointsUserService mkPointsUserService;
@Resource
private MkConsumeCashbackService consumeCashbackService;
private final BigDecimal MONEY_RATE = new BigDecimal("100"); private final BigDecimal MONEY_RATE = new BigDecimal("100");
@@ -152,7 +159,6 @@ public class PayServiceImpl implements PayService {
throw new CzgException("该店铺未启用霸王餐"); throw new CzgException("该店铺未启用霸王餐");
} }
CheckOrderPay checkOrderPay = payParam.getCheckOrderPay(); CheckOrderPay checkOrderPay = payParam.getCheckOrderPay();
// CheckOrderPay checkOrderPay = BeanUtil.copyProperties(payParam, CheckOrderPay.class);
OrderInfo orderInfo = orderInfoCustomService.checkOrderPay(checkOrderPay.setFreeDine(true).setWithCoupon(freeConfig.getWithCoupon()).setWithPoints(freeConfig.getWithPoints())); OrderInfo orderInfo = orderInfoCustomService.checkOrderPay(checkOrderPay.setFreeDine(true).setWithCoupon(freeConfig.getWithCoupon()).setWithPoints(freeConfig.getWithPoints()));
payParam.setAmount(orderInfo.getOrderAmount().multiply(BigDecimal.valueOf(freeConfig.getRechargeTimes()))); payParam.setAmount(orderInfo.getOrderAmount().multiply(BigDecimal.valueOf(freeConfig.getRechargeTimes())));
return true; return true;
@@ -245,14 +251,9 @@ public class PayServiceImpl implements PayService {
orderInfo.setRemark(payParam.getCheckOrderPay().getRemark()); orderInfo.setRemark(payParam.getCheckOrderPay().getRemark());
} }
// log.info("发放经验值");
// memberConfigService.deliver(shopUser, TableValueConstant.MemberExpFlow.Type.COST, orderInfo.getOrderAmount(), null, orderInfo.getId());
Long flowId = shopUserService.updateMoney(shopUserMoneyEditDTO); Long flowId = shopUserService.updateMoney(shopUserMoneyEditDTO);
orderInfoCustomService.upOrderInfo(orderInfo, orderInfo.getOrderAmount(), orderInfoCustomService.upOrderInfo(orderInfo, orderInfo.getOrderAmount(),
LocalDateTime.now(), flowId, PayEnums.VIP_PAY); LocalDateTime.now(), flowId, PayEnums.VIP_PAY);
return CzgResult.success(); return CzgResult.success();
} }
@@ -261,9 +262,6 @@ public class PayServiceImpl implements PayService {
OrderInfo orderInfo = checkPay(payParam.getCheckOrderPay()); OrderInfo orderInfo = checkPay(payParam.getCheckOrderPay());
ShopInfo shopInfo = shopInfoService.getById(payParam.getShopId()); ShopInfo shopInfo = shopInfoService.getById(payParam.getShopId());
AssertUtil.isNull(shopInfo, "店铺不存在"); AssertUtil.isNull(shopInfo, "店铺不存在");
// if (!shopInfo.getIsAccountPay().equals(1)) {
// return CzgResult.failure("支付失败,店铺暂未开启会员余额支付。");
// }
AssertUtil.isNull(payParam.getShopUserId(), "请选择付款人后重试"); AssertUtil.isNull(payParam.getShopUserId(), "请选择付款人后重试");
ShopUser shopUser = shopUserService.getById(payParam.getShopUserId()); ShopUser shopUser = shopUserService.getById(payParam.getShopUserId());
AssertUtil.isNull(shopUser, "支付失败 该店铺用户不存在"); AssertUtil.isNull(shopUser, "支付失败 该店铺用户不存在");
@@ -812,16 +810,36 @@ public class PayServiceImpl implements PayService {
} }
orderInfo.setRefundRemark(orderInfo.getRefundRemark() + param.getRefundReason()); orderInfo.setRefundRemark(orderInfo.getRefundRemark() + param.getRefundReason());
orderInfoService.updateById(orderInfo); orderInfoService.updateById(orderInfo);
//退款后续
//退款返还库存 //退款返还库存
if (!returnProMap.isEmpty()) { if (!returnProMap.isEmpty()) {
rabbitPublisher.sendOrderRefundMsg(JSONObject.toJSONString(Map.of("orderId", orderInfo.getId(), "returnProMap", returnProMap))); rabbitPublisher.sendOrderRefundMsg(JSONObject.toJSONString(Map.of("orderId", orderInfo.getId(), "returnProMap", returnProMap)));
} }
refundOrderAfter(orderInfo.getId(), orderInfo.getShopId(), orderInfo.getUserId(), orderInfo.getOrderNo(), orderInfo.getPointsNum());
// 退款分销还原
distributionUserService.refund(orderInfo.getId(), orderInfo.getOrderNo());
return CzgResult.success(); return CzgResult.success();
} }
//触发订单退款时 后续处理
@Async
public void refundOrderAfter(@NonNull Long orderId, @NonNull Long shopId, Long userId, String orderNo, Integer pointsNum) {
// 退款分销还原
FunUtils.safeRunVoid(() -> distributionUserService.refund(orderId, orderNo),
"订单id:{} 退款,分销处理失败", orderId);
if (userId != null) {
FunUtils.safeRunVoid(() -> consumerCouponService.removeConsumerCoupon(shopId, userId, orderId),
"订单id:{} 退款,消费赠券回撤处理失败", orderId);
FunUtils.safeRunVoid(() -> consumeCashbackService.removeCashback(shopId, userId, orderId, orderNo),
"订单id:{} 退款,消费返现处理失败", orderId);
FunUtils.safeRunVoid(() -> {
if (pointsNum != null && pointsNum > 0) {
mkPointsUserService.alterPoints(userId, null, shopId, PointsConstant.ADD,
pointsNum, orderId, StrUtil.format("订单退款返还{}积分", pointsNum));
}
},
"订单id:{} 退款,积分返还处理失败", orderId);
}
}
@Override @Override
@Transactional @Transactional
public void refundOrder(@NonNull Long shopId, @NonNull Long orderId, @NonNull Long payOrderId, @NonNull String refPayOrderNo, public void refundOrder(@NonNull Long shopId, @NonNull Long orderId, @NonNull Long payOrderId, @NonNull String refPayOrderNo,