|
|
@@ -78,25 +78,27 @@ public class OrderPayService {
|
|
|
if (order.getStatus() != OrderStatus.NOT_PAID) {
|
|
|
throw new BusinessException("订单状态错误");
|
|
|
}
|
|
|
-// switch (PAY_CHANNEL) {
|
|
|
-// case Constants.PayChannel.SAND:
|
|
|
-// return sandPayService.pay(orderId + "", order.getName(), order.getTotalPrice(),
|
|
|
-// order.getCreatedAt().plusMinutes(3), "order");
|
|
|
-// case Constants.PayChannel.HM:
|
|
|
-// return hmPayService.requestAlipay(orderId + "", order.getTotalPrice(), order.getName(),
|
|
|
-// HMPayService.getTimeout(order.getCreatedAt(), 180), Constants.OrderNotifyType.ORDER,
|
|
|
-// generalProperties.getHost() + "/9th/orderDetail?id=" + orderId);
|
|
|
-// }
|
|
|
-// throw new BusinessException(Constants.PAY_ERR_MSG);
|
|
|
+ switch (PAY_CHANNEL) {
|
|
|
+ case Constants.PayChannel.SAND:
|
|
|
+ return sandPayService.pay(orderId + "", order.getName(), order.getTotalPrice(),
|
|
|
+ order.getCreatedAt().plusMinutes(3), "order");
|
|
|
+ case Constants.PayChannel.HM:
|
|
|
+ return hmPayService.requestAlipay(orderId + "", order.getTotalPrice(), order.getName(),
|
|
|
+ HMPayService.getTimeout(order.getCreatedAt(), 180), Constants.OrderNotifyType.ORDER,
|
|
|
+ generalProperties.getHost() + "/9th/orderDetail?id=" + orderId);
|
|
|
+ }
|
|
|
+ throw new BusinessException(Constants.PAY_ERR_MSG);
|
|
|
+ }
|
|
|
|
|
|
+ private String aliRequest(Long orderId, BigDecimal amount, String subject, String type) {
|
|
|
AlipayTradePrecreateRequest request = new AlipayTradePrecreateRequest();
|
|
|
request.setNotifyUrl(alipayProperties.getNotifyUrl());
|
|
|
JSONObject bizContent = new JSONObject();
|
|
|
bizContent.put("out_trade_no", orderId + "");
|
|
|
- bizContent.put("total_amount", order.getTotalPrice());
|
|
|
- bizContent.put("subject", order.getName());
|
|
|
+ bizContent.put("total_amount", amount);
|
|
|
+ bizContent.put("subject", subject);
|
|
|
JSONObject body = new JSONObject();
|
|
|
- body.put("type", Constants.OrderNotifyType.ORDER);
|
|
|
+ body.put("type", type);
|
|
|
body.put("orderId", orderId);
|
|
|
bizContent.put("body", body.toString());
|
|
|
|
|
|
@@ -108,12 +110,22 @@ public class OrderPayService {
|
|
|
e.printStackTrace();
|
|
|
throw new BusinessException(Constants.PAY_ERR_MSG, e.getErrMsg());
|
|
|
}
|
|
|
- String qrCode;
|
|
|
if (response.isSuccess()) {
|
|
|
- qrCode = response.getQrCode();
|
|
|
+ return response.getQrCode();
|
|
|
} else {
|
|
|
throw new BusinessException(response.getSubMsg());
|
|
|
}
|
|
|
+ }
|
|
|
+
|
|
|
+ @Cacheable(value = "payOrder", key = "'order#'+#orderId")
|
|
|
+ public String payOrderAli(Long orderId) {
|
|
|
+ Order order = orderRepo.findById(orderId).orElseThrow(new BusinessException("订单不存在"));
|
|
|
+ if (order.getStatus() != OrderStatus.NOT_PAID) {
|
|
|
+ throw new BusinessException("订单状态错误");
|
|
|
+ }
|
|
|
+
|
|
|
+ String qrCode = aliRequest(orderId, order.getTotalPrice(), order.getName(), Constants.OrderNotifyType.ORDER);
|
|
|
+
|
|
|
String ua = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest().getHeader("User-Agent");
|
|
|
if (ua.toLowerCase().contains("micromessenger")) {
|
|
|
return "/static/wx_alipay_bridge.html?payUrl=" + URLEncoder.encode(qrCode, StandardCharsets.UTF_8)
|
|
|
@@ -211,6 +223,25 @@ public class OrderPayService {
|
|
|
throw new BusinessException(Constants.PAY_ERR_MSG);
|
|
|
}
|
|
|
|
|
|
+ @Cacheable(value = "payOrder", key = "'gift#'+#orderId")
|
|
|
+ public String payGiftAli(Long orderId) {
|
|
|
+ GiftOrder order = giftOrderRepo.findById(orderId).orElseThrow(new BusinessException("订单不存在"));
|
|
|
+ if (order.getStatus() != OrderStatus.NOT_PAID) {
|
|
|
+ throw new BusinessException("订单状态错误");
|
|
|
+ }
|
|
|
+
|
|
|
+ String qrCode = aliRequest(orderId, order.getGasPrice(), "转赠", Constants.OrderNotifyType.GIFT);
|
|
|
+
|
|
|
+ String ua = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest().getHeader("User-Agent");
|
|
|
+ if (ua.toLowerCase().contains("micromessenger")) {
|
|
|
+ return "/static/wx_alipay_bridge.html?payUrl=" + URLEncoder.encode(qrCode, StandardCharsets.UTF_8)
|
|
|
+ + "&orderId=" + orderId + "&type=gift&returnUrl="
|
|
|
+ + URLEncoder.encode(generalProperties.getHost() + "/9th/store", StandardCharsets.UTF_8);
|
|
|
+ } else {
|
|
|
+ return "alipays://platformapi/startapp?saId=10000007&qrcode=" + qrCode;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
@Cacheable(value = "payOrder", key = "'gift#'+#orderId")
|
|
|
public String payGiftQuick(Long orderId) {
|
|
|
GiftOrder order = giftOrderRepo.findById(orderId).orElseThrow(new BusinessException("订单不存在"));
|
|
|
@@ -282,6 +313,25 @@ public class OrderPayService {
|
|
|
throw new BusinessException("绿洲宇宙冷却系统已启动,请稍后支付");
|
|
|
}
|
|
|
|
|
|
+ @Cacheable(value = "payOrder", key = "'mintOrder#'+#orderId")
|
|
|
+ public String payMintAli(Long orderId) {
|
|
|
+ MintOrder order = mintOrderRepo.findById(orderId).orElseThrow(new BusinessException("订单不存在"));
|
|
|
+ if (order.getStatus() != MintOrderStatus.NOT_PAID) {
|
|
|
+ throw new BusinessException("订单状态错误");
|
|
|
+ }
|
|
|
+
|
|
|
+ String qrCode = aliRequest(orderId, order.getGasPrice(), "铸造活动:" + order.getMintActivityId(), Constants.OrderNotifyType.MINT);
|
|
|
+
|
|
|
+ String ua = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest().getHeader("User-Agent");
|
|
|
+ if (ua.toLowerCase().contains("micromessenger")) {
|
|
|
+ return "/static/wx_alipay_bridge.html?payUrl=" + URLEncoder.encode(qrCode, StandardCharsets.UTF_8)
|
|
|
+ + "&orderId=" + orderId + "&type=mintOrder&returnUrl="
|
|
|
+ + URLEncoder.encode(generalProperties.getHost() + "/9th/store", StandardCharsets.UTF_8);
|
|
|
+ } else {
|
|
|
+ return "alipays://platformapi/startapp?saId=10000007&qrcode=" + qrCode;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
@Cacheable(value = "payOrder", key = "'mintOrder#'+#orderId")
|
|
|
public String payMintQuick(Long orderId) {
|
|
|
MintOrder order = mintOrderRepo.findById(orderId).orElseThrow(new BusinessException("订单不存在"));
|
|
|
@@ -375,6 +425,34 @@ public class OrderPayService {
|
|
|
throw new BusinessException("绿洲宇宙冷却系统已启动,请稍后支付");
|
|
|
}
|
|
|
|
|
|
+ public String payRechargeAli(Long userId, BigDecimal amount) {
|
|
|
+ BigDecimal minAmount = sysConfigService.getBigDecimal("min_recharge_amount");
|
|
|
+ if (amount.compareTo(minAmount) < 0) {
|
|
|
+ throw new BusinessException("充值金额不能小于" + minAmount);
|
|
|
+ }
|
|
|
+ if (amount.compareTo(new BigDecimal("50000")) > 0) {
|
|
|
+ throw new BusinessException("充值金额不能大于50000");
|
|
|
+ }
|
|
|
+ RechargeOrder order = RechargeOrder.builder()
|
|
|
+ .id(snowflakeIdWorker.nextId())
|
|
|
+ .userId(userId)
|
|
|
+ .amount(amount)
|
|
|
+ .status(OrderStatus.NOT_PAID)
|
|
|
+ .build();
|
|
|
+ rechargeOrderRepo.save(order);
|
|
|
+
|
|
|
+ String qrCode = aliRequest(order.getId(), order.getAmount(), "余额充值", Constants.OrderNotifyType.RECHARGE);
|
|
|
+
|
|
|
+ String ua = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest().getHeader("User-Agent");
|
|
|
+ if (ua.toLowerCase().contains("micromessenger")) {
|
|
|
+ return "/static/wx_alipay_bridge.html?payUrl=" + URLEncoder.encode(qrCode, StandardCharsets.UTF_8)
|
|
|
+ + "&orderId=" + order.getId() + "&type=recharge&returnUrl="
|
|
|
+ + URLEncoder.encode(generalProperties.getHost() + "/9th/store", StandardCharsets.UTF_8);
|
|
|
+ } else {
|
|
|
+ return "alipays://platformapi/startapp?saId=10000007&qrcode=" + qrCode;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
public Map<String, Object> rechargeAgreement(Long userId, BigDecimal amount, String bindCardId) {
|
|
|
BigDecimal minAmount = sysConfigService.getBigDecimal("min_recharge_amount");
|
|
|
if (amount.compareTo(minAmount) < 0) {
|
|
|
@@ -519,6 +597,25 @@ public class OrderPayService {
|
|
|
throw new BusinessException("绿洲宇宙冷却系统已启动,请稍后支付");
|
|
|
}
|
|
|
|
|
|
+ @Cacheable(value = "payOrder", key = "'auctionOrder#'+#orderId")
|
|
|
+ public String payAuctionAli(Long orderId) {
|
|
|
+ AuctionOrder order = auctionOrderRepo.findById(orderId).orElseThrow(new BusinessException("订单不存在"));
|
|
|
+ if (order.getStatus() != AuctionOrderStatus.NOT_PAID) {
|
|
|
+ throw new BusinessException("订单状态错误");
|
|
|
+ }
|
|
|
+
|
|
|
+ String qrCode = aliRequest(orderId, order.getTotalPrice(), "拍卖:" + order.getName(), Constants.OrderNotifyType.AUCTION);
|
|
|
+
|
|
|
+ String ua = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest().getHeader("User-Agent");
|
|
|
+ if (ua.toLowerCase().contains("micromessenger")) {
|
|
|
+ return "/static/wx_alipay_bridge.html?payUrl=" + URLEncoder.encode(qrCode, StandardCharsets.UTF_8)
|
|
|
+ + "&orderId=" + orderId + "&type=auctionOrder&returnUrl="
|
|
|
+ + URLEncoder.encode(generalProperties.getHost() + "/9th/store", StandardCharsets.UTF_8);
|
|
|
+ } else {
|
|
|
+ return "alipays://platformapi/startapp?saId=10000007&qrcode=" + qrCode;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
@Cacheable(value = "payOrder", key = "'auctionOrder#'+#orderId")
|
|
|
public String payAuctionQuick(Long orderId) {
|
|
|
AuctionOrder order = auctionOrderRepo.findById(orderId).orElseThrow(new BusinessException("订单不存在"));
|