AppletOrderController.java 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. package com.zsElectric.boot.business.controller.applet;
  2. import com.baomidou.mybatisplus.core.toolkit.Wrappers;
  3. import com.zsElectric.boot.business.model.entity.RechargeLevel;
  4. import com.zsElectric.boot.business.model.form.applet.LevelOrderForm;
  5. import com.zsElectric.boot.business.model.form.applet.UserPayForm;
  6. import com.zsElectric.boot.business.service.RechargeLevelService;
  7. import com.zsElectric.boot.business.service.UserOrderInfoService;
  8. import com.zsElectric.boot.common.annotation.RepeatSubmit;
  9. import com.zsElectric.boot.common.constant.SystemConstants;
  10. import com.zsElectric.boot.core.pay.WechatCallbackRefundData;
  11. import com.zsElectric.boot.core.pay.WechatRefundCallback;
  12. import com.zsElectric.boot.core.web.Result;
  13. import io.swagger.v3.oas.annotations.Operation;
  14. import io.swagger.v3.oas.annotations.media.Schema;
  15. import io.swagger.v3.oas.annotations.tags.Tag;
  16. import jakarta.servlet.http.HttpServletRequest;
  17. import jakarta.servlet.http.HttpServletResponse;
  18. import lombok.RequiredArgsConstructor;
  19. import lombok.extern.slf4j.Slf4j;
  20. import org.springframework.validation.annotation.Validated;
  21. import org.springframework.web.bind.annotation.*;
  22. import java.io.IOException;
  23. import java.text.ParseException;
  24. import java.util.List;
  25. import java.util.Map;
  26. @Tag(name = "订单相关接口")
  27. @Slf4j
  28. @RestController
  29. @RequestMapping("/applet/v1/order")
  30. @RequiredArgsConstructor
  31. public class AppletOrderController {
  32. private final RechargeLevelService rechargeLevelService;
  33. private final UserOrderInfoService userOrderInfoService;
  34. /**
  35. * 获取充电档位
  36. *
  37. * @return
  38. */
  39. @Operation(summary = "获取充电档位")
  40. @GetMapping("/getReChargeLevel")
  41. public Result<List<RechargeLevel>> getReChargeLevel() {
  42. List<RechargeLevel> list = rechargeLevelService.list(Wrappers.lambdaQuery(RechargeLevel.class).eq(RechargeLevel::getStatus, SystemConstants.STATUS_ONE));
  43. return Result.success(list);
  44. }
  45. /**
  46. * 创建订单
  47. *
  48. * @param levelOrderForm
  49. * @return
  50. */
  51. @Operation(summary = "创建订单")
  52. @PostMapping("/createOrder")
  53. public Result<UserPayForm> createOrder(@RequestBody LevelOrderForm levelOrderForm) {
  54. UserPayForm payForm = userOrderInfoService.createOrder(levelOrderForm);
  55. return Result.success(payForm);
  56. }
  57. /**
  58. * 订单-支付
  59. *
  60. * @param orderId
  61. * @return
  62. */
  63. @Operation(summary = "订单-支付")
  64. @PutMapping("/payOrder/{orderId}")
  65. public Result<UserPayForm> payOrder(@PathVariable("orderId") String orderId) {
  66. return Result.success(userOrderInfoService.payOrder(orderId));
  67. }
  68. /**
  69. * 支付回调
  70. *
  71. * @param request
  72. * @return
  73. */
  74. @Operation(summary = "支付回调")
  75. @RequestMapping("/wechatPayNotify")
  76. public Map<String, String> wechatPayNotify(HttpServletRequest request, HttpServletResponse response) throws InterruptedException {
  77. log.info("--------------------------------------------支付回调");
  78. return userOrderInfoService.wechatPayNotify(request, response);
  79. }
  80. /**
  81. * 订单支付是否成功查询
  82. *
  83. * @param orderNo
  84. * @return
  85. */
  86. @Operation(summary = "订单支付是否成功查询")
  87. @GetMapping("/orderQuery/{orderNo}")
  88. public Result<String> orderQuery(@PathVariable("orderNo") String orderNo) throws Exception {
  89. return Result.success(userOrderInfoService.orderQuery(orderNo));
  90. }
  91. /**
  92. * 订单主动取消
  93. *
  94. * @param orderId
  95. * @return
  96. */
  97. @Operation(summary = "订单主动取消")
  98. @PutMapping("/cancelOrder/{orderId}")
  99. public Result<String> cancelOrder(@PathVariable(name = "orderId") String orderId) {
  100. return Result.success(userOrderInfoService.cancelOrder(orderId));
  101. }
  102. /**
  103. * 账户退款
  104. * @return
  105. */
  106. @Operation(summary = "账户退款")
  107. @PutMapping("/refundOrder")
  108. public Result<String> refundOrder() throws Exception {
  109. return Result.success(userOrderInfoService.refundOrder());
  110. }
  111. @Operation(summary = "订单退款回调")
  112. @PostMapping("/callback/refundOrderNotify")
  113. public Map<String, Object> refundOrderNotify(HttpServletRequest request, HttpServletResponse response) {
  114. return userOrderInfoService.refundCallback(request, response);
  115. }
  116. }