用户订单退款

This commit is contained in:
yanglei 2025-10-29 16:10:00 +08:00
parent ddc647c7f5
commit be4559dace
5 changed files with 128 additions and 26 deletions

View File

@ -37,13 +37,13 @@ public class EbikeOrderTransaction implements Serializable {
private static final long serialVersionUID = 1L;
/**
* 订单ID
* 主键ID
*/
@Id
private Long transactionId;
/**
* 订单Id
* 订单id
*/
private String orderId;
@ -105,7 +105,7 @@ public class EbikeOrderTransaction implements Serializable {
/**
* 支付方式wechat/alipay/balance
*/
private String paymentMethod;
private Integer paymentMethod;
/**
* 使用卡券ID集合JSON数组

View File

@ -1,14 +1,22 @@
package com.cdzy.user.controller;
import cn.dev33.satoken.stp.StpUtil;
import com.cdzy.common.model.request.PageParam;
import com.cdzy.common.model.response.JsonResult;
import com.cdzy.user.model.dto.EbikeUserCyclingDto;
import com.cdzy.user.model.entity.EbikeOrderTransaction;
import com.cdzy.user.service.EbikeOrderTransactionService;
import com.ebike.feign.model.dto.FeignOrderPaymentDto;
import com.mybatisflex.core.paginate.Page;
import com.mybatisflex.core.query.QueryWrapper;
import jakarta.annotation.Resource;
import jakarta.validation.constraints.NotBlank;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import java.util.Objects;
import static com.cdzy.user.model.entity.table.EbikeOrderTransactionTableDef.EBIKE_ORDER_TRANSACTION;
/**
* 用户订单 控制层
*
@ -47,6 +55,30 @@ public class EbikeOrderTransactionController {
return JsonResult.success(userOrders);
}
/**
* 订单支付
*
* @param orderPaymentDto 支付信息
* @ {@code 200} 添加成功{@code 500} 添加失败
*/
@PostMapping("payment")
public JsonResult<?> payment(@RequestBody @Validated FeignOrderPaymentDto orderPaymentDto) {
ebikeOrderTransactionService.payment(orderPaymentDto);
return JsonResult.success();
}
/**
* 订单退款申请
*
* @param orderId 订单ID
* @ {@code 200} 添加成功{@code 500} 添加失败
*/
@GetMapping("refundApply")
public JsonResult<?> refundApply(@RequestParam("orderId") String orderId) {
ebikeOrderTransactionService.refundApply(orderId);
return JsonResult.success();
}
/**
* 订单退款
*
@ -82,4 +114,47 @@ public class EbikeOrderTransactionController {
ebikeOrderTransactionService.failRefund(orderId);
return JsonResult.success();
}
/**
* 订单退款驳回
*
* @param orderId 订单ID
* @ {@code 200} 添加成功{@code 500} 添加失败
*/
@GetMapping("rejectRefund")
public JsonResult<?> rejectRefund(@RequestParam("orderId") String orderId) {
ebikeOrderTransactionService.rejectRefund(orderId);
return JsonResult.success();
}
/**
* 根据用户订单表主键获取详细信
*
* @param transactionId 用户订单表主键
* @ 用户订单表详情
*/
@GetMapping("getInfo/{transactionId}")
public JsonResult<?> getInfo(@PathVariable("transactionId") Long transactionId) {
EbikeOrderTransaction userOrder = ebikeOrderTransactionService.getById(transactionId);
return JsonResult.success(userOrder);
}
/**
* 分页查询用户用户订单
*
* @param pageParam 分页对象
* @param orderStatus 订单状态
*/
@GetMapping("page")
public JsonResult<?> page(@Validated PageParam pageParam, @RequestParam(value = "orderStatus", required = false) Integer orderStatus) {
long userId = StpUtil.getLoginIdAsLong();
QueryWrapper queryWrapper = QueryWrapper.create()
.where(EBIKE_ORDER_TRANSACTION.USER_ID.eq(userId))
.where(EBIKE_ORDER_TRANSACTION.ORDER_STATUS.eq(orderStatus, Objects.nonNull(orderStatus)))
.orderBy(EBIKE_ORDER_TRANSACTION.CREATE_TIME, Boolean.TRUE);
Page<EbikeOrderTransaction> page = ebikeOrderTransactionService.page(pageParam.getPage(), queryWrapper);
return JsonResult.success(page);
}
}

View File

@ -104,9 +104,9 @@ public class EbikeOrderTransaction implements Serializable {
private LocalDateTime paymentTime;
/**
* 支付方式wechat/alipay/balance
* 支付方式1-wechat 2-alipay 3-balance
*/
private String paymentMethod;
private Integer paymentMethod;
/**
* 使用卡券ID集合JSON数组

View File

@ -1,7 +1,7 @@
package com.cdzy.user.service;
import com.cdzy.user.model.dto.EbikeUserCyclingDto;
import com.cdzy.user.model.entity.EbikeOrderTransaction;
import com.ebike.feign.model.dto.FeignOrderPaymentDto;
import com.mybatisflex.core.service.IService;
/**
@ -28,6 +28,18 @@ public interface EbikeOrderTransactionService extends IService<EbikeOrderTransac
*/
EbikeOrderTransaction checkHistoryOrder(Long userId);
/**
* 订单支付
* @param orderPaymentDto 订单支付信息
*/
void payment(FeignOrderPaymentDto orderPaymentDto);
/**
* 订单发起退款
* @param orderId 订单ID
*/
void refundApply(String orderId);
/**
* 订单退款
* @param orderId 订单ID
@ -45,4 +57,11 @@ public interface EbikeOrderTransactionService extends IService<EbikeOrderTransac
* @param orderId 订单ID
*/
void failRefund(String orderId);
/**
* 订单退款驳回
* @param orderId 订单ID
*/
void rejectRefund(String orderId);
}

View File

@ -8,6 +8,7 @@ import com.cdzy.user.model.entity.EbikeOrderTransaction;
import com.cdzy.user.service.EbikeOrderTransactionService;
import com.cdzy.user.utils.RedisUtil;
import com.ebike.feign.clients.OperationsFeignClient;
import com.ebike.feign.model.dto.FeignOrderPaymentDto;
import com.ebike.feign.model.vo.FeignEbikeBikeInfoVo;
import com.mybatisflex.core.query.QueryWrapper;
import com.mybatisflex.spring.service.impl.ServiceImpl;
@ -25,7 +26,7 @@ import static com.cdzy.user.model.entity.table.EbikeOrderTransactionTableDef.EBI
*/
@Service
public class EbikeOrderTransactionServiceImpl extends ServiceImpl<EbikeOrderTransactionMapper, EbikeOrderTransaction> implements EbikeOrderTransactionService {
public class EbikeOrderTransactionImpl extends ServiceImpl<EbikeOrderTransactionMapper, EbikeOrderTransaction> implements EbikeOrderTransactionService {
@Resource
private RedisUtil redisUtil;
@ -43,14 +44,14 @@ public class EbikeOrderTransactionServiceImpl extends ServiceImpl<EbikeOrderTran
// public Long saveRide(EbikeUserCyclingDto orderDto) {
// Long userId = orderDto.getUserId();
// // 校验用户当前是否存在订单
// EbikeOrderTransaction history = checkHistoryOrder(userId);
// EbikeOrder history = checkHistoryOrder(userId);
// if (history != null && history.getOrderStatus() == OrderStatus.IN_PROGRESS) {
// throw new RuntimeException("请完成当前订单后再试");
// }
// if (history != null && history.getOrderStatus() == OrderStatus.PENDING_PAYMENT) {
// throw new RuntimeException("请完成未支付订单后再试");
// }
// EbikeOrderTransaction userOrders = new EbikeOrderTransaction();
// EbikeOrder userOrders = new EbikeOrder();
// userOrders.setUserId(userId);
// userOrders.setBikeCode(orderDto.getBikeCode());
// userOrders.setOrderType(OrderType.ONCE);
@ -96,7 +97,7 @@ public class EbikeOrderTransactionServiceImpl extends ServiceImpl<EbikeOrderTran
// operationsFeignClient.riding(bikeInfoDto.getBikeId());
// userOrders.setBikeId(bikeInfoDto.getBikeId());
// String stringBuilder = resGpsDto.getLongitude() + "," + resGpsDto.getLatitude();
// userOrders.setRidePoint(stringBuilder);
// userOrders.setStartLocation(stringBuilder);
// ebikeOrderTransactionMapper.insert(userOrders);
// //处理车辆
// return userOrders.getOrderId();
@ -110,34 +111,41 @@ public class EbikeOrderTransactionServiceImpl extends ServiceImpl<EbikeOrderTran
return ebikeOrderTransactionMapper.selectOneByQuery(queryWrapper);
}
/**
* 退款申请中 更新为 退款中
*
* @param orderId 订单ID
*/
@Override
public void payment(FeignOrderPaymentDto orderPaymentDto) {
EbikeOrderTransaction ebikeOrderTransaction = this.mapper.selectOneById(orderPaymentDto.getOrderId());
ebikeOrderTransaction.setOrderStatus(OrderStatus.PAID);
ebikeOrderTransaction.setPaymentTime(orderPaymentDto.getPaymentTime());
ebikeOrderTransaction.setPaymentMethod(orderPaymentDto.getPaymentMethod());
this.mapper.update(ebikeOrderTransaction);
}
@Override
public void refundApply(String orderId) {
updateOrderStatus(orderId, OrderStatus.PAID, OrderStatus.REFUND_APPLYING);
}
@Override
public void refund(String orderId) {
updateOrderStatus(orderId, OrderStatus.REFUND_APPLYING, OrderStatus.REFUNDING);
}
/**
* 退款中 更新为 已退款
* @param orderId 订单ID
*/
@Override
public void doneRefund(String orderId) {
updateOrderStatus(orderId, OrderStatus.REFUNDING, OrderStatus.REFUNDED);
}
/**
* 退款中 更新为 退款失败
* @param orderId 订单ID
*/
@Override
public void failRefund(String orderId) {
updateOrderStatus(orderId, OrderStatus.REFUNDING, OrderStatus.REFUND_FAILED);
}
@Override
public void rejectRefund(String orderId) {
updateOrderStatus(orderId, OrderStatus.REFUND_APPLYING, OrderStatus.REFUND_REJECTED);
}
/**
* 校验车辆是否可用
*
@ -168,8 +176,8 @@ public class EbikeOrderTransactionServiceImpl extends ServiceImpl<EbikeOrderTran
/**
* @param orderId 订单id
* @param currentStatus 当前状态
* @param targetStatus 目标状态
* @param currentStatus 订单当前状态
* @param targetStatus 订单目标状态
*/
private void updateOrderStatus(String orderId, Integer currentStatus, Integer targetStatus) {
EbikeOrderTransaction order = mapper.selectOneByQuery(