ebike-plus/ebike-user/src/main/java/com/cdzy/user/controller/EbikeOrderController.java

161 lines
5.1 KiB
Java
Raw Normal View History

2025-10-15 17:38:13 +08:00
package com.cdzy.user.controller;
2025-10-29 16:10:00 +08:00
import cn.dev33.satoken.stp.StpUtil;
import com.cdzy.common.model.request.PageParam;
2025-10-16 11:39:47 +08:00
import com.cdzy.common.model.response.JsonResult;
2025-10-29 17:01:46 +08:00
import com.cdzy.user.model.entity.EbikeOrder;
import com.cdzy.user.service.EbikeOrderService;
2025-10-29 16:10:00 +08:00
import com.ebike.feign.model.dto.FeignOrderPaymentDto;
import com.mybatisflex.core.paginate.Page;
import com.mybatisflex.core.query.QueryWrapper;
2025-10-15 17:38:13 +08:00
import jakarta.annotation.Resource;
2025-10-16 11:39:47 +08:00
import jakarta.validation.constraints.NotBlank;
import org.springframework.validation.annotation.Validated;
2025-10-29 14:06:51 +08:00
import org.springframework.web.bind.annotation.*;
2025-10-15 17:38:13 +08:00
2025-10-29 16:10:00 +08:00
import java.util.Objects;
2025-10-29 17:01:46 +08:00
import static com.cdzy.user.model.entity.table.EbikeOrderTableDef.EBIKE_ORDER;
2025-10-29 16:10:00 +08:00
2025-10-15 17:38:13 +08:00
/**
* 用户订单 控制层
*
2025-10-21 09:57:21 +08:00
* @author: yanglei
* @since: 2025-10-15 17:15
2025-10-15 17:38:13 +08:00
*/
@RestController
2025-10-29 17:01:46 +08:00
@RequestMapping("/ebikeOrder")
public class EbikeOrderController {
2025-10-15 17:38:13 +08:00
@Resource
2025-10-29 17:01:46 +08:00
private EbikeOrderService ebikeOrderTransactionService;
2025-10-15 17:38:13 +08:00
2025-10-28 09:40:32 +08:00
/**
* 开始骑行生成订单开锁
*
* @param orderDto 骑行信息
* @ {@code 200} 添加成功{@code 500} 添加失败
*/
2025-10-28 11:22:10 +08:00
// @PostMapping("saveRide")
// public JsonResult<?> saveRide(@RequestBody @Validated EbikeUserCyclingDto orderDto) {
// Long orderId = ebikeOrderTransactionService.saveRide(orderDto);
// return JsonResult.success(orderId);
// }
2025-10-28 09:40:32 +08:00
2025-10-16 11:39:47 +08:00
/**
* 查看用户是否有未完成订单
*
* @param userId 用户id
* @ {@code 200} 添加成功{@code 500} 添加失败
*/
@GetMapping("checkHistoryOrder")
public JsonResult<?> checkHistoryOrder(@Validated @NotBlank(message = "用户id不能为空") @RequestParam("userId") Long userId) {
2025-10-29 17:01:46 +08:00
EbikeOrder userOrders = ebikeOrderTransactionService.checkHistoryOrder(userId);
2025-10-16 11:39:47 +08:00
return JsonResult.success(userOrders);
}
2025-10-15 17:38:13 +08:00
2025-10-29 16:10:00 +08:00
/**
* 订单支付
*
* @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")
2025-10-29 17:01:46 +08:00
public JsonResult<?> refundApply(@RequestParam("orderId") Long orderId) {
2025-10-29 16:10:00 +08:00
ebikeOrderTransactionService.refundApply(orderId);
return JsonResult.success();
}
2025-10-29 14:06:51 +08:00
/**
* 订单退款
*
* @param orderId 订单ID
* @ {@code 200} 添加成功{@code 500} 添加失败
*/
@GetMapping("refund")
2025-10-29 17:01:46 +08:00
public JsonResult<?> refund(@RequestParam("orderId") Long orderId) {
2025-10-29 14:06:51 +08:00
ebikeOrderTransactionService.refund(orderId);
return JsonResult.success();
}
/**
* 订单退款完成
*
* @param orderId 订单ID
* @ {@code 200} 添加成功{@code 500} 添加失败
*/
@GetMapping("doneRefund")
2025-10-29 17:01:46 +08:00
public JsonResult<?> doneRefund(@RequestParam("orderId") Long orderId) {
2025-10-29 14:06:51 +08:00
ebikeOrderTransactionService.doneRefund(orderId);
return JsonResult.success();
}
/**
* 订单退款失败
*
* @param orderId 订单ID
* @ {@code 200} 添加成功{@code 500} 添加失败
*/
@GetMapping("failRefund")
2025-10-29 17:01:46 +08:00
public JsonResult<?> failRefund(@RequestParam("orderId") Long orderId) {
2025-10-29 14:06:51 +08:00
ebikeOrderTransactionService.failRefund(orderId);
return JsonResult.success();
}
2025-10-29 16:10:00 +08:00
/**
* 订单退款驳回
*
* @param orderId 订单ID
* @ {@code 200} 添加成功{@code 500} 添加失败
*/
@GetMapping("rejectRefund")
2025-10-29 17:01:46 +08:00
public JsonResult<?> rejectRefund(@RequestParam("orderId") Long orderId) {
2025-10-29 16:10:00 +08:00
ebikeOrderTransactionService.rejectRefund(orderId);
return JsonResult.success();
}
/**
* 根据用户订单表主键获取详细信
*
* @param transactionId 用户订单表主键
* @ 用户订单表详情
*/
@GetMapping("getInfo/{transactionId}")
public JsonResult<?> getInfo(@PathVariable("transactionId") Long transactionId) {
2025-10-29 17:01:46 +08:00
EbikeOrder userOrder = ebikeOrderTransactionService.getById(transactionId);
2025-10-29 16:10:00 +08:00
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()
2025-10-29 17:01:46 +08:00
.where(EBIKE_ORDER.USER_ID.eq(userId))
.where(EBIKE_ORDER.ORDER_STATUS.eq(orderStatus, Objects.nonNull(orderStatus)))
.orderBy(EBIKE_ORDER.CREATE_TIME, Boolean.TRUE);
Page<EbikeOrder> page = ebikeOrderTransactionService.page(pageParam.getPage(), queryWrapper);
2025-10-29 16:10:00 +08:00
return JsonResult.success(page);
}
2025-10-15 17:38:13 +08:00
}