订单 退款 问题
This commit is contained in:
@@ -9,7 +9,7 @@ import com.czg.market.entity.MkConsumeCashback;
|
||||
import java.math.BigDecimal;
|
||||
|
||||
/**
|
||||
* 服务层。
|
||||
* 服务层。
|
||||
*
|
||||
* @author zs
|
||||
* @since 2025-10-13
|
||||
@@ -21,11 +21,14 @@ public interface MkConsumeCashbackService extends IService<MkConsumeCashback> {
|
||||
|
||||
/**
|
||||
* 消费返现
|
||||
* @param shopId 店铺id
|
||||
* @param userId 用户id
|
||||
* @param amount 金额
|
||||
*
|
||||
* @param shopId 店铺id
|
||||
* @param userId 用户id
|
||||
* @param amount 金额
|
||||
* @param orderId 订单id
|
||||
* @param orderNo 订单号
|
||||
*/
|
||||
void cashback(Long shopId, Long userId, BigDecimal amount, Long orderId, String orderNo);
|
||||
|
||||
void removeCashback(Long shopId, Long userId, Long orderId, String orderNo);
|
||||
}
|
||||
|
||||
@@ -29,9 +29,9 @@ public interface MkPointsUserService extends IService<MkPointsUser> {
|
||||
* 获取用户积分信息
|
||||
* 返回的数据ID可能为空 不影响修改用户积分 统一接口的处理
|
||||
*
|
||||
* @param shopId 店铺Id
|
||||
* @param shopId 店铺Id
|
||||
* @param shopUserId 店铺用户Id
|
||||
* @param userId 会员Id
|
||||
* @param userId 会员Id
|
||||
*/
|
||||
MkPointsUser getPointsUser(Long shopId, Long shopUserId, Long userId);
|
||||
|
||||
|
||||
@@ -22,6 +22,12 @@ public interface MkShopConsumerCouponService extends IService<MkShopConsumerCoup
|
||||
*/
|
||||
void receiveConsumerCoupon(Long shopId, Long orderId, BigDecimal orderAmount, Long userId, Long shopUserId);
|
||||
|
||||
/**
|
||||
* 订单退款 移除消费赠券
|
||||
*
|
||||
*/
|
||||
void removeConsumerCoupon(Long shopId, Long userId, Long orderId);
|
||||
|
||||
MkShopConsumerCouponDTO getConsumerCouponById(Long id);
|
||||
|
||||
void addConsumerCoupon(MkShopConsumerCouponDTO param);
|
||||
|
||||
@@ -160,7 +160,7 @@ public class MkConsumeCashbackServiceImpl extends ServiceImpl<MkConsumeCashbackM
|
||||
shopUserService.updateMoney(new ShopUserMoneyEditDTO().setId(shopUser.getId()).setType(1)
|
||||
.setRelationId(mkConsumeCashbackRecord.getId()).setMoney(cashbackAmount).setBizEnum(ShopUserFlowBizEnum.CASHBACK)
|
||||
.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()
|
||||
.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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -23,6 +23,7 @@ import com.mybatisflex.spring.service.impl.ServiceImpl;
|
||||
import jakarta.annotation.Resource;
|
||||
import org.apache.dubbo.config.annotation.DubboReference;
|
||||
import org.apache.dubbo.config.annotation.DubboService;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@@ -131,9 +132,6 @@ public class MkPointsUserServiceImpl extends ServiceImpl<MkPointsUserMapper, MkP
|
||||
break;
|
||||
case SUB:
|
||||
pointsUser.setPointBalance(pointsUser.getPointBalance() - points);
|
||||
if (pointsUser.getPointBalance() < 0) {
|
||||
throw new CzgException("积分操作失败,积分不足");
|
||||
}
|
||||
points = -points;
|
||||
break;
|
||||
default:
|
||||
|
||||
@@ -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
|
||||
public MkShopConsumerCouponDTO getConsumerCouponById(Long id) {
|
||||
AssertUtil.isNull(id, "ID不能为空");
|
||||
|
||||
@@ -1060,8 +1060,7 @@ public class OrderInfoCustomServiceImpl implements OrderInfoCustomService {
|
||||
distributionUserService.costUpgradeLevelBefore(orderInfo.getUserId(), orderInfo.getShopId());
|
||||
// 分销奖励
|
||||
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());
|
||||
ShopUser shopUser = shopUserService.getById(payment.getSourceId());
|
||||
OrderInfo orderInfo = null;
|
||||
@@ -1162,8 +1161,7 @@ public class OrderInfoCustomServiceImpl implements OrderInfoCustomService {
|
||||
// if (orderInfo != null) {
|
||||
// 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());
|
||||
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());
|
||||
|
||||
// 分销员开通
|
||||
}
|
||||
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());
|
||||
}
|
||||
else if (PayTypeConstants.SourceType.POINT.equals(payment.getSourceType())) {
|
||||
} else if (PayTypeConstants.SourceType.POINT.equals(payment.getSourceType())) {
|
||||
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());
|
||||
}
|
||||
else if (PayTypeConstants.SourceType.PP.equals(payment.getSourceType())) {
|
||||
} else if (PayTypeConstants.SourceType.PP.equals(payment.getSourceType())) {
|
||||
ppPackageOrderService.paySuccess(payment.getSourceId(), payment.getId());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -24,6 +24,7 @@ import com.czg.market.dto.MemberOrderDTO;
|
||||
import com.czg.market.entity.MemberOrder;
|
||||
import com.czg.market.entity.MkShopCouponRecord;
|
||||
import com.czg.market.entity.MkShopRechargeDetail;
|
||||
import com.czg.market.enums.PointsConstant;
|
||||
import com.czg.market.service.*;
|
||||
import com.czg.market.vo.MkShopRechargeVO;
|
||||
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.utils.AssertUtil;
|
||||
import com.czg.utils.CzgRandomUtils;
|
||||
import com.czg.utils.FunUtils;
|
||||
import com.mybatisflex.core.query.QueryWrapper;
|
||||
import jakarta.annotation.Resource;
|
||||
import jakarta.validation.constraints.NotBlank;
|
||||
import lombok.NonNull;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.dubbo.config.annotation.DubboReference;
|
||||
import org.springframework.scheduling.annotation.Async;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
@@ -116,9 +119,13 @@ public class PayServiceImpl implements PayService {
|
||||
@Resource
|
||||
private MkShopRechargeDetailService shopRechargeDetailService;
|
||||
@Resource
|
||||
private TbMemberConfigService memberConfigService;
|
||||
@Resource
|
||||
private MkDistributionUserService distributionUserService;
|
||||
@Resource
|
||||
private MkShopConsumerCouponService consumerCouponService;
|
||||
@Resource
|
||||
private MkPointsUserService mkPointsUserService;
|
||||
@Resource
|
||||
private MkConsumeCashbackService consumeCashbackService;
|
||||
|
||||
private final BigDecimal MONEY_RATE = new BigDecimal("100");
|
||||
|
||||
@@ -152,7 +159,6 @@ public class PayServiceImpl implements PayService {
|
||||
throw new CzgException("该店铺未启用霸王餐");
|
||||
}
|
||||
CheckOrderPay checkOrderPay = payParam.getCheckOrderPay();
|
||||
// CheckOrderPay checkOrderPay = BeanUtil.copyProperties(payParam, CheckOrderPay.class);
|
||||
OrderInfo orderInfo = orderInfoCustomService.checkOrderPay(checkOrderPay.setFreeDine(true).setWithCoupon(freeConfig.getWithCoupon()).setWithPoints(freeConfig.getWithPoints()));
|
||||
payParam.setAmount(orderInfo.getOrderAmount().multiply(BigDecimal.valueOf(freeConfig.getRechargeTimes())));
|
||||
return true;
|
||||
@@ -245,14 +251,9 @@ public class PayServiceImpl implements PayService {
|
||||
orderInfo.setRemark(payParam.getCheckOrderPay().getRemark());
|
||||
}
|
||||
|
||||
// log.info("发放经验值");
|
||||
// memberConfigService.deliver(shopUser, TableValueConstant.MemberExpFlow.Type.COST, orderInfo.getOrderAmount(), null, orderInfo.getId());
|
||||
|
||||
Long flowId = shopUserService.updateMoney(shopUserMoneyEditDTO);
|
||||
orderInfoCustomService.upOrderInfo(orderInfo, orderInfo.getOrderAmount(),
|
||||
LocalDateTime.now(), flowId, PayEnums.VIP_PAY);
|
||||
|
||||
|
||||
return CzgResult.success();
|
||||
}
|
||||
|
||||
@@ -261,9 +262,6 @@ public class PayServiceImpl implements PayService {
|
||||
OrderInfo orderInfo = checkPay(payParam.getCheckOrderPay());
|
||||
ShopInfo shopInfo = shopInfoService.getById(payParam.getShopId());
|
||||
AssertUtil.isNull(shopInfo, "店铺不存在");
|
||||
// if (!shopInfo.getIsAccountPay().equals(1)) {
|
||||
// return CzgResult.failure("支付失败,店铺暂未开启会员余额支付。");
|
||||
// }
|
||||
AssertUtil.isNull(payParam.getShopUserId(), "请选择付款人后重试");
|
||||
ShopUser shopUser = shopUserService.getById(payParam.getShopUserId());
|
||||
AssertUtil.isNull(shopUser, "支付失败 该店铺用户不存在");
|
||||
@@ -812,16 +810,36 @@ public class PayServiceImpl implements PayService {
|
||||
}
|
||||
orderInfo.setRefundRemark(orderInfo.getRefundRemark() + param.getRefundReason());
|
||||
orderInfoService.updateById(orderInfo);
|
||||
//退款后续
|
||||
//退款返还库存
|
||||
if (!returnProMap.isEmpty()) {
|
||||
rabbitPublisher.sendOrderRefundMsg(JSONObject.toJSONString(Map.of("orderId", orderInfo.getId(), "returnProMap", returnProMap)));
|
||||
}
|
||||
|
||||
// 退款分销还原
|
||||
distributionUserService.refund(orderInfo.getId(), orderInfo.getOrderNo());
|
||||
refundOrderAfter(orderInfo.getId(), orderInfo.getShopId(), orderInfo.getUserId(), orderInfo.getOrderNo(), orderInfo.getPointsNum());
|
||||
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
|
||||
@Transactional
|
||||
public void refundOrder(@NonNull Long shopId, @NonNull Long orderId, @NonNull Long payOrderId, @NonNull String refPayOrderNo,
|
||||
|
||||
Reference in New Issue
Block a user