mirror of
https://gitee.com/huangge1199_admin/vue-pro.git
synced 2024-11-23 07:41:53 +08:00
code review:增加取消售后的优化建议
This commit is contained in:
parent
ad535e674f
commit
debf568750
@ -140,7 +140,7 @@ public class AppTradeOrderController {
|
|||||||
@Operation(summary = "确认交易订单收货")
|
@Operation(summary = "确认交易订单收货")
|
||||||
@Parameter(name = "id", description = "交易订单编号")
|
@Parameter(name = "id", description = "交易订单编号")
|
||||||
public CommonResult<Boolean> receiveOrder(@RequestParam("id") Long id) {
|
public CommonResult<Boolean> receiveOrder(@RequestParam("id") Long id) {
|
||||||
tradeOrderUpdateService.receiveOrder(getLoginUserId(), id);
|
tradeOrderUpdateService.receiveOrderByMember(getLoginUserId(), id);
|
||||||
return success(true);
|
return success(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -148,7 +148,7 @@ public class AppTradeOrderController {
|
|||||||
@Operation(summary = "取消交易订单")
|
@Operation(summary = "取消交易订单")
|
||||||
@Parameter(name = "id", description = "交易订单编号")
|
@Parameter(name = "id", description = "交易订单编号")
|
||||||
public CommonResult<Boolean> cancelOrder(@RequestParam("id") Long id) {
|
public CommonResult<Boolean> cancelOrder(@RequestParam("id") Long id) {
|
||||||
tradeOrderUpdateService.cancelOrder(getLoginUserId(), id);
|
tradeOrderUpdateService.cancelOrderByMember(getLoginUserId(), id);
|
||||||
return success(true);
|
return success(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -21,7 +21,7 @@ public class TradeOrderAutoCancelJob implements JobHandler {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String execute(String param) {
|
public String execute(String param) {
|
||||||
int count = tradeOrderUpdateService.autoCancelOrder();
|
int count = tradeOrderUpdateService.cancelOrderBySystem();
|
||||||
return String.format("过期订单 %s 个", count);
|
return String.format("过期订单 %s 个", count);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -21,7 +21,7 @@ public class TradeOrderAutoReceiveJob implements JobHandler {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String execute(String param) {
|
public String execute(String param) {
|
||||||
int count = tradeOrderUpdateService.autoReceiveOrder();
|
int count = tradeOrderUpdateService.receiveOrderBySystem();
|
||||||
return String.format("自动收货 %s 个", count);
|
return String.format("自动收货 %s 个", count);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -60,14 +60,14 @@ public interface TradeOrderUpdateService {
|
|||||||
* @param userId 用户编号
|
* @param userId 用户编号
|
||||||
* @param id 订单编号
|
* @param id 订单编号
|
||||||
*/
|
*/
|
||||||
void receiveOrder(Long userId, Long id);
|
void receiveOrderByMember(Long userId, Long id);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 【系统】自动收货交易订单
|
* 【系统】自动收货交易订单
|
||||||
*
|
*
|
||||||
* @return 收货数量
|
* @return 收货数量
|
||||||
*/
|
*/
|
||||||
int autoReceiveOrder();
|
int receiveOrderBySystem();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 【会员】取消交易订单
|
* 【会员】取消交易订单
|
||||||
@ -75,14 +75,14 @@ public interface TradeOrderUpdateService {
|
|||||||
* @param userId 用户编号
|
* @param userId 用户编号
|
||||||
* @param id 订单编号
|
* @param id 订单编号
|
||||||
*/
|
*/
|
||||||
void cancelOrder(Long userId, Long id);
|
void cancelOrderByMember(Long userId, Long id);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 【系统】自动取消订单
|
* 【系统】自动取消订单
|
||||||
*
|
*
|
||||||
* @return 取消数量
|
* @return 取消数量
|
||||||
*/
|
*/
|
||||||
int autoCancelOrder();
|
int cancelOrderBySystem();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 【会员】删除订单
|
* 【会员】删除订单
|
||||||
|
@ -488,7 +488,7 @@ public class TradeOrderUpdateServiceImpl implements TradeOrderUpdateService {
|
|||||||
@Override
|
@Override
|
||||||
@Transactional(rollbackFor = Exception.class)
|
@Transactional(rollbackFor = Exception.class)
|
||||||
@TradeOrderLog(operateType = TradeOrderOperateTypeEnum.MEMBER_RECEIVE)
|
@TradeOrderLog(operateType = TradeOrderOperateTypeEnum.MEMBER_RECEIVE)
|
||||||
public void receiveOrder(Long userId, Long id) {
|
public void receiveOrderByMember(Long userId, Long id) {
|
||||||
// 校验并获得交易订单(可收货)
|
// 校验并获得交易订单(可收货)
|
||||||
TradeOrderDO order = validateOrderReceivable(userId, id);
|
TradeOrderDO order = validateOrderReceivable(userId, id);
|
||||||
|
|
||||||
@ -497,7 +497,7 @@ public class TradeOrderUpdateServiceImpl implements TradeOrderUpdateService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int autoReceiveOrder() {
|
public int receiveOrderBySystem() {
|
||||||
// 1. 查询过期的待支付订单
|
// 1. 查询过期的待支付订单
|
||||||
LocalDateTime expireTime = addTime(tradeOrderProperties.getReceiveExpireTime());
|
LocalDateTime expireTime = addTime(tradeOrderProperties.getReceiveExpireTime());
|
||||||
List<TradeOrderDO> orders = tradeOrderMapper.selectListByStatusAndDeliveryTimeLt(
|
List<TradeOrderDO> orders = tradeOrderMapper.selectListByStatusAndDeliveryTimeLt(
|
||||||
@ -510,7 +510,7 @@ public class TradeOrderUpdateServiceImpl implements TradeOrderUpdateService {
|
|||||||
int count = 0;
|
int count = 0;
|
||||||
for (TradeOrderDO order : orders) {
|
for (TradeOrderDO order : orders) {
|
||||||
try {
|
try {
|
||||||
getSelf().autoReceiveOrder(order);
|
getSelf().receiveOrderBySystem(order);
|
||||||
count ++;
|
count ++;
|
||||||
} catch (Throwable e) {
|
} catch (Throwable e) {
|
||||||
log.error("[autoReceiveOrder][order({}) 自动收货订单异常]", order.getId(), e);
|
log.error("[autoReceiveOrder][order({}) 自动收货订单异常]", order.getId(), e);
|
||||||
@ -526,7 +526,7 @@ public class TradeOrderUpdateServiceImpl implements TradeOrderUpdateService {
|
|||||||
*/
|
*/
|
||||||
@Transactional(rollbackFor = Exception.class)
|
@Transactional(rollbackFor = Exception.class)
|
||||||
@TradeOrderLog(operateType = TradeOrderOperateTypeEnum.SYSTEM_RECEIVE)
|
@TradeOrderLog(operateType = TradeOrderOperateTypeEnum.SYSTEM_RECEIVE)
|
||||||
public void autoReceiveOrder(TradeOrderDO order) {
|
public void receiveOrderBySystem(TradeOrderDO order) {
|
||||||
receiveOrder0(order);
|
receiveOrder0(order);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -572,7 +572,7 @@ public class TradeOrderUpdateServiceImpl implements TradeOrderUpdateService {
|
|||||||
@Override
|
@Override
|
||||||
@Transactional(rollbackFor = Exception.class)
|
@Transactional(rollbackFor = Exception.class)
|
||||||
@TradeOrderLog(operateType = TradeOrderOperateTypeEnum.MEMBER_CANCEL)
|
@TradeOrderLog(operateType = TradeOrderOperateTypeEnum.MEMBER_CANCEL)
|
||||||
public void cancelOrder(Long userId, Long id) {
|
public void cancelOrderByMember(Long userId, Long id) {
|
||||||
// 1.1 校验存在
|
// 1.1 校验存在
|
||||||
TradeOrderDO order = tradeOrderMapper.selectOrderByIdAndUserId(id, userId);
|
TradeOrderDO order = tradeOrderMapper.selectOrderByIdAndUserId(id, userId);
|
||||||
if (order == null) {
|
if (order == null) {
|
||||||
@ -588,7 +588,7 @@ public class TradeOrderUpdateServiceImpl implements TradeOrderUpdateService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int autoCancelOrder() {
|
public int cancelOrderBySystem() {
|
||||||
// 1. 查询过期的待支付订单
|
// 1. 查询过期的待支付订单
|
||||||
LocalDateTime expireTime = addTime(tradeOrderProperties.getPayExpireTime());
|
LocalDateTime expireTime = addTime(tradeOrderProperties.getPayExpireTime());
|
||||||
List<TradeOrderDO> orders = tradeOrderMapper.selectListByStatusAndCreateTimeLt(
|
List<TradeOrderDO> orders = tradeOrderMapper.selectListByStatusAndCreateTimeLt(
|
||||||
@ -601,7 +601,7 @@ public class TradeOrderUpdateServiceImpl implements TradeOrderUpdateService {
|
|||||||
int count = 0;
|
int count = 0;
|
||||||
for (TradeOrderDO order : orders) {
|
for (TradeOrderDO order : orders) {
|
||||||
try {
|
try {
|
||||||
getSelf().autoCancelOrder(order);
|
getSelf().cancelOrderBySystem(order);
|
||||||
count ++;
|
count ++;
|
||||||
} catch (Throwable e) {
|
} catch (Throwable e) {
|
||||||
log.error("[autoCancelOrder][order({}) 过期订单异常]", order.getId(), e);
|
log.error("[autoCancelOrder][order({}) 过期订单异常]", order.getId(), e);
|
||||||
@ -617,7 +617,7 @@ public class TradeOrderUpdateServiceImpl implements TradeOrderUpdateService {
|
|||||||
*/
|
*/
|
||||||
@Transactional(rollbackFor = Exception.class)
|
@Transactional(rollbackFor = Exception.class)
|
||||||
@TradeOrderLog(operateType = TradeOrderOperateTypeEnum.SYSTEM_CANCEL)
|
@TradeOrderLog(operateType = TradeOrderOperateTypeEnum.SYSTEM_CANCEL)
|
||||||
public void autoCancelOrder(TradeOrderDO order) {
|
public void cancelOrderBySystem(TradeOrderDO order) {
|
||||||
cancelOrder0(order, TradeOrderCancelTypeEnum.PAY_TIMEOUT);
|
cancelOrder0(order, TradeOrderCancelTypeEnum.PAY_TIMEOUT);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -773,9 +773,11 @@ public class TradeOrderUpdateServiceImpl implements TradeOrderUpdateService {
|
|||||||
|
|
||||||
// =================== Order Item ===================
|
// =================== Order Item ===================
|
||||||
|
|
||||||
|
// TODO 疯狂:帮我重构下:
|
||||||
|
// 1. updateOrderItemAfterSaleStatus 拆分成三个方法:发起;同意;拒绝。原因是,职责更清晰,操作日志也更容易记录;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@Transactional(rollbackFor = Exception.class)
|
@Transactional(rollbackFor = Exception.class)
|
||||||
// TODO 芋艿:
|
|
||||||
public void updateOrderItemAfterSaleStatus(Long id, Integer oldAfterSaleStatus, Integer newAfterSaleStatus,
|
public void updateOrderItemAfterSaleStatus(Long id, Integer oldAfterSaleStatus, Integer newAfterSaleStatus,
|
||||||
Long afterSaleId, Integer refundPrice) {
|
Long afterSaleId, Integer refundPrice) {
|
||||||
// 如果退款成功,则 refundPrice 非空
|
// 如果退款成功,则 refundPrice 非空
|
||||||
@ -803,6 +805,7 @@ public class TradeOrderUpdateServiceImpl implements TradeOrderUpdateService {
|
|||||||
TradeOrderItemDO orderItem = tradeOrderItemMapper.selectById(id);
|
TradeOrderItemDO orderItem = tradeOrderItemMapper.selectById(id);
|
||||||
TradeOrderDO order = tradeOrderMapper.selectById(orderItem.getOrderId());
|
TradeOrderDO order = tradeOrderMapper.selectById(orderItem.getOrderId());
|
||||||
Integer orderRefundPrice = order.getRefundPrice() + refundPrice;
|
Integer orderRefundPrice = order.getRefundPrice() + refundPrice;
|
||||||
|
// TODO @疯狂:809 到 817 改成:cancelOrderByAfterSale:相当于全部售后成功后,就是要取消胆子;
|
||||||
if (isAllOrderItemAfterSaleSuccess(order.getId())) { // 如果都售后成功,则需要取消订单
|
if (isAllOrderItemAfterSaleSuccess(order.getId())) { // 如果都售后成功,则需要取消订单
|
||||||
tradeOrderMapper.updateById(new TradeOrderDO().setId(order.getId())
|
tradeOrderMapper.updateById(new TradeOrderDO().setId(order.getId())
|
||||||
.setRefundStatus(TradeOrderRefundStatusEnum.ALL.getStatus()).setRefundPrice(orderRefundPrice).setRefundPoint(order.getRefundPoint() + orderItem.getUsePoint())
|
.setRefundStatus(TradeOrderRefundStatusEnum.ALL.getStatus()).setRefundPrice(orderRefundPrice).setRefundPoint(order.getRefundPoint() + orderItem.getUsePoint())
|
||||||
@ -812,7 +815,6 @@ public class TradeOrderUpdateServiceImpl implements TradeOrderUpdateService {
|
|||||||
|
|
||||||
// TODO 芋艿:要不要退优惠劵
|
// TODO 芋艿:要不要退优惠劵
|
||||||
|
|
||||||
// TODO 芋艿:站内信?
|
|
||||||
} else { // 如果部分售后,则更新退款金额
|
} else { // 如果部分售后,则更新退款金额
|
||||||
tradeOrderMapper.updateById(new TradeOrderDO().setId(order.getId())
|
tradeOrderMapper.updateById(new TradeOrderDO().setId(order.getId())
|
||||||
.setRefundStatus(TradeOrderRefundStatusEnum.PART.getStatus()).setRefundPrice(orderRefundPrice));
|
.setRefundStatus(TradeOrderRefundStatusEnum.PART.getStatus()).setRefundPrice(orderRefundPrice));
|
||||||
@ -821,6 +823,7 @@ public class TradeOrderUpdateServiceImpl implements TradeOrderUpdateService {
|
|||||||
// TODO 芋艿:这块扣减规则,需要在考虑下
|
// TODO 芋艿:这块扣减规则,需要在考虑下
|
||||||
// 售后成功后,执行数据回滚逻辑
|
// 售后成功后,执行数据回滚逻辑
|
||||||
if (Objects.equals(newAfterSaleStatus, TradeOrderItemAfterSaleStatusEnum.SUCCESS.getStatus())) {
|
if (Objects.equals(newAfterSaleStatus, TradeOrderItemAfterSaleStatusEnum.SUCCESS.getStatus())) {
|
||||||
|
// TODO @疯狂:这里库存也要扣减下;
|
||||||
// 扣减用户积分(赠送的)
|
// 扣减用户积分(赠送的)
|
||||||
reduceUserPoint(order.getUserId(), orderItem.getGivePoint(), MemberPointBizTypeEnum.AFTER_SALE_DEDUCT_GIVE, afterSaleId);
|
reduceUserPoint(order.getUserId(), orderItem.getGivePoint(), MemberPointBizTypeEnum.AFTER_SALE_DEDUCT_GIVE, afterSaleId);
|
||||||
// 增加用户积分(返还抵扣)
|
// 增加用户积分(返还抵扣)
|
||||||
@ -880,6 +883,8 @@ public class TradeOrderUpdateServiceImpl implements TradeOrderUpdateService {
|
|||||||
TradeOrderItemAfterSaleStatusEnum.SUCCESS.getStatus()));
|
TradeOrderItemAfterSaleStatusEnum.SUCCESS.getStatus()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// =================== 营销相关的操作 ===================
|
||||||
|
|
||||||
@Async
|
@Async
|
||||||
protected void addUserExperienceAsync(Long userId, Integer payPrice, Long orderId) {
|
protected void addUserExperienceAsync(Long userId, Integer payPrice, Long orderId) {
|
||||||
int bizType = MemberExperienceBizTypeEnum.ORDER.getType();
|
int bizType = MemberExperienceBizTypeEnum.ORDER.getType();
|
||||||
|
@ -306,7 +306,7 @@ public class TradeOrderUpdateServiceTest extends BaseDbUnitTest {
|
|||||||
// mock 方法(支付单)
|
// mock 方法(支付单)
|
||||||
|
|
||||||
// 调用
|
// 调用
|
||||||
tradeOrderUpdateService.receiveOrder(userId, id);
|
tradeOrderUpdateService.receiveOrderByMember(userId, id);
|
||||||
// 断言
|
// 断言
|
||||||
TradeOrderDO dbOrder = tradeOrderMapper.selectById(1L);
|
TradeOrderDO dbOrder = tradeOrderMapper.selectById(1L);
|
||||||
assertEquals(dbOrder.getStatus(), TradeOrderStatusEnum.COMPLETED.getStatus());
|
assertEquals(dbOrder.getStatus(), TradeOrderStatusEnum.COMPLETED.getStatus());
|
||||||
|
Loading…
Reference in New Issue
Block a user