拒单
OrderController
java
复制代码
/**
* 拒单
*/
@PutMapping("/rejection")
@ApiOperation("拒单")
public Result rejection(@RequestBody OrdersRejectionDTO ordersRejectionDTO) throws Exception {
orderService.rejection(ordersRejectionDTO);
return Result.success();
}
OrderService
java
复制代码
/**
* 拒单
*/
void rejection(OrdersRejectionDTO ordersRejectionDTO) throws Exception;
OrderServiceImpl
java
复制代码
/**
* 拒单
*/
@Override
public void rejection(OrdersRejectionDTO ordersRejectionDTO) throws Exception{
// 根据id查询订单
Orders ordersDB = orderMapper.selectById(ordersRejectionDTO.getId());
// 订单只有存在且状态为2(待接单)才可以拒单
if (ordersDB == null || !ordersDB.getStatus().equals(Orders.TO_BE_CONFIRMED)) {
throw new OrderBusinessException(MessageConstant.ORDER_STATUS_ERROR);
}
//支付状态
Integer payStatus = ordersDB.getPayStatus();
//订单状态
if (payStatus.equals(Orders.PAID)) {
//调用微信支付退款接口,用户已支付,需要退款
// String refund = weChatPayUtil.refund(
// ordersDB.getNumber(),
// ordersDB.getNumber(),
// new BigDecimal(0.01),
// new BigDecimal(0.01));
// log.info("申请退款:{}", refund);
}
// 拒单需要退款,根据订单id更新订单状态、拒单原因、取消时间
Orders orders = new Orders();
orders.setId(ordersDB.getId());
orders.setStatus(Orders.CANCELLED);
orders.setRejectionReason(ordersRejectionDTO.getRejectionReason());
orders.setCancelTime(LocalDateTime.now());
orderMapper.updateById(orders);
}
取消订单
OrderController
java
复制代码
/**
* 取消订单
*/
@PutMapping("/cancel")
@ApiOperation("取消订单")
public Result cancel(@RequestBody OrdersCancelDTO ordersCancelDTO) throws Exception {
orderService.cancel(ordersCancelDTO);
return Result.success();
}
OrderService
java
复制代码
/**
* 取消订单
*/
void cancel(OrdersCancelDTO ordersCancelDTO) throws Exception;
OrderServiceImpl
java
复制代码
/**
* 取消订单
*/
@Override
public void cancel(OrdersCancelDTO ordersCancelDTO) throws Exception {
// 根据id查询订单
Orders ordersDB = orderMapper.selectById(ordersCancelDTO.getId());
//支付状态
Integer payStatus = ordersDB.getPayStatus();
//订单状态
if (payStatus.equals(Orders.PAID)) {
//调用微信支付退款接口,用户已支付,需要退款
// String refund = weChatPayUtil.refund(
// ordersDB.getNumber(),
// ordersDB.getNumber(),
// new BigDecimal(0.01),
// new BigDecimal(0.01));
// log.info("申请退款:{}", refund);
}
// 管理端取消订单需要退款,根据订单id更新订单状态、取消原因、取消时间
Orders orders = new Orders();
orders.setId(ordersCancelDTO.getId());
orders.setStatus(Orders.CANCELLED);
orders.setCancelReason(ordersCancelDTO.getCancelReason());
orders.setCancelTime(LocalDateTime.now());
orderMapper.updateById(orders);
}
派送订单
OrderController
java
复制代码
/**
* 派送订单
*/
@PutMapping("/delivery/{id}")
@ApiOperation("派送订单")
public Result delivery(@PathVariable("id") Long id) {
orderService.delivery(id);
return Result.success();
}
OrderService
java
复制代码
/**
* 派送订单
*/
void delivery(Long id);
OrderServiceImpl
java
复制代码
/**
* 派送订单
*/
@Override
public void delivery(Long id) {
// 根据id查询订单
Orders ordersDB = orderMapper.selectById(id);
// 订单只有存在且状态为3(已接单)才可以派送
if (ordersDB == null || !ordersDB.getStatus().equals(Orders.CONFIRMED)) {
throw new OrderBusinessException(MessageConstant.ORDER_STATUS_ERROR);
}
// 根据订单id更新订单状态、派送时间
Orders orders = Orders.builder()
.id(ordersDB.getId())
.status(Orders.DELIVERY_IN_PROGRESS)
.build();
orderMapper.updateById(orders);
}
完成订单
OrderController
java
复制代码
/**
* 完成订单
*/
@PutMapping("/complete/{id}")
@ApiOperation("完成订单")
public Result complete (@PathVariable("id") Long id) {
orderService.complete(id);
return Result.success();
}
OrderService
java
复制代码
/**
* 完成订单
*/
void complete(Long id);
OrderServiceImpl
java
复制代码
/**
* 完成订单
*/
@Override
public void complete(Long id) {
// 根据id查询订单
Orders ordersDB = orderMapper.selectById(id);
// 校验订单是否存在,并且状态为4
if (ordersDB == null || !ordersDB.getStatus().equals(Orders.DELIVERY_IN_PROGRESS)) {
throw new OrderBusinessException(MessageConstant.ORDER_STATUS_ERROR);
}
// 根据订单id更新订单状态、完成时间
Orders orders = Orders.builder()
.id(ordersDB.getId())
.status(Orders.COMPLETED)
.deliveryTime(LocalDateTime.now())
.build();
orderMapper.updateById(orders);
}