|
|
@@ -1,15 +1,17 @@
|
|
|
package com.izouma.nineth.web;
|
|
|
|
|
|
import com.alibaba.fastjson.JSON;
|
|
|
+import com.izouma.nineth.config.Constants;
|
|
|
+import com.izouma.nineth.dto.PayQuery;
|
|
|
+import com.izouma.nineth.exception.BusinessException;
|
|
|
import com.izouma.nineth.service.HMPayService;
|
|
|
+import com.izouma.nineth.service.OrderPayService;
|
|
|
+import com.izouma.nineth.service.PayEaseService;
|
|
|
import com.izouma.nineth.service.SandPayService;
|
|
|
import com.izouma.nineth.utils.SnowflakeIdWorker;
|
|
|
import lombok.AllArgsConstructor;
|
|
|
import org.springframework.security.access.prepost.PreAuthorize;
|
|
|
-import org.springframework.web.bind.annotation.GetMapping;
|
|
|
-import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
-import org.springframework.web.bind.annotation.RequestParam;
|
|
|
-import org.springframework.web.bind.annotation.RestController;
|
|
|
+import org.springframework.web.bind.annotation.*;
|
|
|
|
|
|
import java.math.BigDecimal;
|
|
|
import java.time.LocalDateTime;
|
|
|
@@ -21,20 +23,30 @@ public class PayChannelMgmtController {
|
|
|
private final SandPayService sandPayService;
|
|
|
private final HMPayService hmPayService;
|
|
|
private final SnowflakeIdWorker snowflakeIdWorker;
|
|
|
+ private final PayEaseService payEaseService;
|
|
|
+ private final OrderPayService orderPayService;
|
|
|
|
|
|
- @GetMapping(value = "/pay")
|
|
|
+ @PostMapping(value = "/pay")
|
|
|
@PreAuthorize("hasRole('ADMIN')")
|
|
|
- public String pay(@RequestParam String channel) {
|
|
|
+ public Object pay(@RequestParam String channel, @RequestParam String orderId, String userId, String bindCardId,
|
|
|
+ BigDecimal amount) {
|
|
|
+ if (amount == null) {
|
|
|
+ amount = new BigDecimal("0.01");
|
|
|
+ }
|
|
|
switch (channel) {
|
|
|
- case "sandPay":
|
|
|
- return sandPayService.pay(snowflakeIdWorker.nextId() + "", "话费充值",
|
|
|
- new BigDecimal("0.01"), LocalDateTime.now().plusMinutes(3), "test");
|
|
|
- case "hmPay":
|
|
|
- return hmPayService.requestAlipay(snowflakeIdWorker.nextId() + "",
|
|
|
- new BigDecimal("0.01"), "话费充值",
|
|
|
+ case "sandQuick":
|
|
|
+ return sandPayService.payQuick(orderId, "测试", amount,
|
|
|
+ LocalDateTime.now().plusMinutes(3), "test", "https://www.baidu.com");
|
|
|
+ case Constants.PayChannel.SAND:
|
|
|
+ return sandPayService.pay(orderId, "测试", amount,
|
|
|
+ LocalDateTime.now().plusMinutes(3), "test");
|
|
|
+ case Constants.PayChannel.HM:
|
|
|
+ return hmPayService.requestAlipay(orderId, amount, "测试",
|
|
|
HMPayService.getTimeout(180), "test", "https://www.baidu.com");
|
|
|
+ case Constants.PayChannel.PE:
|
|
|
+ return payEaseService.pay("测试", orderId, amount, userId, bindCardId, "test");
|
|
|
}
|
|
|
- return null;
|
|
|
+ throw new BusinessException("不支持此渠道");
|
|
|
}
|
|
|
|
|
|
@GetMapping(value = "/transfer")
|
|
|
@@ -43,38 +55,17 @@ public class PayChannelMgmtController {
|
|
|
return JSON.toJSONString(sandPayService.transfer(snowflakeIdWorker.nextId() + "", name, bank, amount), true);
|
|
|
}
|
|
|
|
|
|
- @GetMapping(value = "/refund")
|
|
|
+ @PostMapping(value = "/refund")
|
|
|
@PreAuthorize("hasRole('ADMIN')")
|
|
|
- public String refund(@RequestParam String channel, @RequestParam String orderId, @RequestParam BigDecimal amount) {
|
|
|
- switch (channel) {
|
|
|
- case "sandPay":
|
|
|
- if (orderId.length() < 12) {
|
|
|
- for (int i = orderId.length(); i < 12; i++) {
|
|
|
- orderId = "0" + orderId;
|
|
|
- }
|
|
|
- }
|
|
|
- return JSON.toJSONString(sandPayService.refund(orderId, amount), true);
|
|
|
- case "hmPay":
|
|
|
- if (orderId.length() < 12) {
|
|
|
- for (int i = orderId.length(); i < 12; i++) {
|
|
|
- orderId = "0" + orderId;
|
|
|
- }
|
|
|
- }
|
|
|
- return JSON.toJSONString(hmPayService.refund(orderId, amount), true);
|
|
|
- }
|
|
|
- return null;
|
|
|
+ public Object refund(@RequestParam String channel, @RequestParam String orderId, String transactionId,
|
|
|
+ @RequestParam BigDecimal amount) {
|
|
|
+ return orderPayService.refund(orderId, transactionId, amount, channel);
|
|
|
}
|
|
|
|
|
|
@GetMapping(value = "/query")
|
|
|
@PreAuthorize("hasRole('ADMIN')")
|
|
|
- public String query(@RequestParam String channel, @RequestParam String id) {
|
|
|
- switch (channel) {
|
|
|
- case "sandPay":
|
|
|
- return JSON.toJSONString(sandPayService.query(id), true);
|
|
|
- case "hmPay":
|
|
|
- return JSON.toJSONString(hmPayService.query(id), true);
|
|
|
- }
|
|
|
- return null;
|
|
|
+ public PayQuery query(@RequestParam String orderId) {
|
|
|
+ return orderPayService.query(orderId);
|
|
|
}
|
|
|
|
|
|
@GetMapping("/queryTransfer")
|