新增订单强制取消功能
- 新增管理后台强制取消进行中订单接口 - 实现已接单/服务中订单强制取消业务逻辑 - 支持自定义退款金额,默认退回全额支付金额 - 新增订单强制取消请求VO类及参数校验 - 新增单元测试验证强制取消功能的正确性 - 更新服务接口定义及文档注释
This commit is contained in:
@@ -124,6 +124,18 @@ public class PlayOrderInfoController {
|
||||
return R.ok("退款成功");
|
||||
}
|
||||
|
||||
/**
|
||||
* 管理后台强制取消进行中订单
|
||||
*/
|
||||
@ApiOperation(value = "强制取消订单", notes = "管理员强制取消已接单或服务中的订单")
|
||||
@ApiResponses({@ApiResponse(code = 200, message = "操作成功"), @ApiResponse(code = 500, message = "操作失败")})
|
||||
@PostMapping("/forceCancel")
|
||||
public R forceCancel(@ApiParam(value = "取消参数", required = true) @Validated @RequestBody PlayOrderForceCancelVo vo) {
|
||||
orderInfoService.forceCancelOngoingOrder("2", CustomSecurityContextHolder.getUserId(), vo.getOrderId(),
|
||||
vo.getRefundAmount(), vo.getRefundReason(), vo.getImages());
|
||||
return R.ok("操作成功");
|
||||
}
|
||||
|
||||
/**
|
||||
* 更换店员
|
||||
*/
|
||||
|
||||
@@ -0,0 +1,42 @@
|
||||
package com.starry.admin.modules.order.module.vo;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import javax.validation.constraints.DecimalMin;
|
||||
import javax.validation.constraints.NotBlank;
|
||||
import javax.validation.constraints.Size;
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* 强制取消订单请求对象
|
||||
*
|
||||
* <p>用于管理员或店员在订单已接单/服务中时发起取消操作。</p>
|
||||
*/
|
||||
@Data
|
||||
public class PlayOrderForceCancelVo {
|
||||
|
||||
/**
|
||||
* 订单ID
|
||||
*/
|
||||
@NotBlank(message = "订单ID不能为空")
|
||||
private String orderId;
|
||||
|
||||
/**
|
||||
* 退款原因
|
||||
*/
|
||||
@NotBlank(message = "请填写退款原因")
|
||||
@Size(max = 200, message = "退款原因不能超过200个字符")
|
||||
private String refundReason;
|
||||
|
||||
/**
|
||||
* 退款金额,可选。不填默认退回订单支付金额
|
||||
*/
|
||||
@DecimalMin(value = "0.00", message = "退款金额不能小于0")
|
||||
private BigDecimal refundAmount;
|
||||
|
||||
/**
|
||||
* 退款凭证图片
|
||||
*/
|
||||
private List<String> images = new ArrayList<>();
|
||||
}
|
||||
@@ -271,6 +271,19 @@ public interface IPlayOrderInfoService extends IService<PlayOrderInfoEntity> {
|
||||
void updateStateTo4(String operatorByType, String operatorBy, String orderId, String refundReason,
|
||||
List<String> images);
|
||||
|
||||
/**
|
||||
* 已接单/服务中的订单强制取消
|
||||
*
|
||||
* @param operatorByType 操作人类型(1:店员;2:管理员)
|
||||
* @param operatorBy 操作人ID
|
||||
* @param orderId 订单ID
|
||||
* @param refundAmount 退款金额(为空则退回实际支付金额)
|
||||
* @param refundReason 取消原因
|
||||
* @param images 退款凭证图片
|
||||
*/
|
||||
void forceCancelOngoingOrder(String operatorByType, String operatorBy, String orderId, BigDecimal refundAmount,
|
||||
String refundReason, List<String> images);
|
||||
|
||||
/**
|
||||
* 修改订单
|
||||
*
|
||||
|
||||
@@ -1015,6 +1015,56 @@ public class PlayOrderInfoServiceImpl extends ServiceImpl<PlayOrderInfoMapper, P
|
||||
wxCustomMpService.sendOrderCancelMessage(orderInfo, refundReason);
|
||||
}
|
||||
|
||||
/**
|
||||
* 已接单/服务中的订单强制取消,仅允许店员本人或管理员操作
|
||||
*/
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void forceCancelOngoingOrder(String operatorByType, String operatorBy, String orderId, BigDecimal refundAmount,
|
||||
String refundReason, List<String> images) {
|
||||
if (!"2".equals(operatorByType)) {
|
||||
throw new CustomException("禁止操作");
|
||||
}
|
||||
PlayOrderInfoEntity orderInfo = this.selectOrderInfoById(orderId);
|
||||
if (!OrderConstant.ORDER_STATUS_1.equals(orderInfo.getOrderStatus())
|
||||
&& !OrderConstant.ORDER_STATUS_2.equals(orderInfo.getOrderStatus())) {
|
||||
throw new CustomException("订单状态异常,无法取消");
|
||||
}
|
||||
BigDecimal actualRefundAmount = refundAmount != null ? refundAmount : orderInfo.getFinalAmount();
|
||||
if (actualRefundAmount.compareTo(BigDecimal.ZERO) < 0) {
|
||||
throw new CustomException("退款金额不能小于0");
|
||||
}
|
||||
if (actualRefundAmount.compareTo(orderInfo.getFinalAmount()) > 0) {
|
||||
throw new CustomException("退款金额不能大于支付金额");
|
||||
}
|
||||
|
||||
LocalDateTime now = LocalDateTime.now();
|
||||
PlayOrderInfoEntity updateEntity = new PlayOrderInfoEntity(orderId, OrderConstant.ORDER_STATUS_4);
|
||||
updateEntity.setRefundAmount(actualRefundAmount);
|
||||
updateEntity.setRefundReason(refundReason);
|
||||
updateEntity.setRefundType("1");
|
||||
updateEntity.setOrderCancelTime(now);
|
||||
if (OrderConstant.ORDER_STATUS_2.equals(orderInfo.getOrderStatus())) {
|
||||
updateEntity.setOrderEndTime(now);
|
||||
}
|
||||
this.baseMapper.updateById(updateEntity);
|
||||
|
||||
PlayCustomUserInfoEntity customUserInfo = customUserInfoService.getById(orderInfo.getPurchaserBy());
|
||||
if (customUserInfo == null) {
|
||||
throw new CustomException("顾客信息不存在");
|
||||
}
|
||||
|
||||
customUserInfoService.updateAccountBalanceById(customUserInfo.getId(), customUserInfo.getAccountBalance(),
|
||||
customUserInfo.getAccountBalance().add(actualRefundAmount), "3", "订单取消退款",
|
||||
actualRefundAmount, BigDecimal.ZERO, orderId);
|
||||
|
||||
playOrderRefundInfoService.add(orderId, orderInfo.getPurchaserBy(), orderInfo.getAcceptBy(),
|
||||
orderInfo.getPayMethod(), "0", actualRefundAmount, refundReason, operatorByType, operatorBy, "0", "0");
|
||||
|
||||
PlayOrderInfoEntity latest = this.selectOrderInfoById(orderId);
|
||||
wxCustomMpService.sendOrderCancelMessage(latest, refundReason);
|
||||
}
|
||||
|
||||
@Override
|
||||
public PlayOrderInfoEntity queryByOrderNo(String orderNo) {
|
||||
LambdaQueryWrapper<PlayOrderInfoEntity> lambdaQueryWrapper = new LambdaQueryWrapper<>();
|
||||
|
||||
Reference in New Issue
Block a user