|
|
@@ -6,10 +6,7 @@ import com.izouma.nineth.config.GeneralProperties;
|
|
|
import com.izouma.nineth.domain.*;
|
|
|
import com.izouma.nineth.dto.PayQuery;
|
|
|
import com.izouma.nineth.dto.UserBankCard;
|
|
|
-import com.izouma.nineth.enums.AuctionOrderStatus;
|
|
|
-import com.izouma.nineth.enums.MintOrderStatus;
|
|
|
-import com.izouma.nineth.enums.OrderStatus;
|
|
|
-import com.izouma.nineth.enums.PayMethod;
|
|
|
+import com.izouma.nineth.enums.*;
|
|
|
import com.izouma.nineth.event.OrderNotifyEvent;
|
|
|
import com.izouma.nineth.exception.BusinessException;
|
|
|
import com.izouma.nineth.repo.*;
|
|
|
@@ -55,6 +52,7 @@ public class OrderPayService {
|
|
|
private final UserBankCardRepo userBankCardRepo;
|
|
|
private final AuctionOrderRepo auctionOrderRepo;
|
|
|
private final AuctionOrderService auctionOrderService;
|
|
|
+ private final IdentityAuthRepo identityAuthRepo;
|
|
|
|
|
|
public static void setPayChannel(String payChannel) {
|
|
|
log.info("set pay channel {}", payChannel);
|
|
|
@@ -92,6 +90,20 @@ public class OrderPayService {
|
|
|
generalProperties.getHost() + "/9th/home");
|
|
|
}
|
|
|
|
|
|
+ @Cacheable(value = "payOrder", key = "'order#'+#orderId")
|
|
|
+ public String payOrderQuickBind(Long orderId) {
|
|
|
+ Order order = orderRepo.findById(orderId).orElseThrow(new BusinessException("订单不存在"));
|
|
|
+ if (order.getStatus() != OrderStatus.NOT_PAID) {
|
|
|
+ throw new BusinessException("订单状态错误");
|
|
|
+ }
|
|
|
+ IdentityAuth identityAuth = identityAuthRepo.findFirstByUserIdAndStatusAndDelFalseOrderByCreatedAtDesc(order.getUserId(), AuthStatus.SUCCESS)
|
|
|
+ .orElseThrow(new BusinessException("请先完成实名认证"));
|
|
|
+ return sandPayService.payQuickBind(orderId + "", order.getName(), order.getTotalPrice(),
|
|
|
+ order.getCreatedAt().plusMinutes(3), Constants.OrderNotifyType.ORDER,
|
|
|
+ generalProperties.getHost() + "/9th/home",
|
|
|
+ order.getUserId(), identityAuth.getRealName(), identityAuth.getIdNo());
|
|
|
+ }
|
|
|
+
|
|
|
public void payOrderBalance(Long orderId, Long userId, String tradeCode) {
|
|
|
Order order = orderRepo.findById(orderId).orElseThrow(new BusinessException("订单不存在"));
|
|
|
if (order.getStatus() != OrderStatus.NOT_PAID) {
|
|
|
@@ -165,6 +177,20 @@ public class OrderPayService {
|
|
|
generalProperties.getHost() + "/9th/home");
|
|
|
}
|
|
|
|
|
|
+ @Cacheable(value = "payOrder", key = "'gift#'+#orderId")
|
|
|
+ public String payGiftQuickBind(Long orderId) {
|
|
|
+ GiftOrder order = giftOrderRepo.findById(orderId).orElseThrow(new BusinessException("订单不存在"));
|
|
|
+ if (order.getStatus() != OrderStatus.NOT_PAID) {
|
|
|
+ throw new BusinessException("订单状态错误");
|
|
|
+ }
|
|
|
+ IdentityAuth identityAuth = identityAuthRepo.findFirstByUserIdAndStatusAndDelFalseOrderByCreatedAtDesc(order.getUserId(), AuthStatus.SUCCESS)
|
|
|
+ .orElseThrow(new BusinessException("请先完成实名认证"));
|
|
|
+ return sandPayService.payQuickBind(orderId + "", "转赠" + order.getAssetId(), order.getGasPrice(),
|
|
|
+ order.getCreatedAt().plusMinutes(3), Constants.OrderNotifyType.GIFT,
|
|
|
+ generalProperties.getHost() + "/9th/home",
|
|
|
+ order.getUserId(), identityAuth.getRealName(), identityAuth.getIdNo());
|
|
|
+ }
|
|
|
+
|
|
|
public void payGiftBalance(Long orderId, Long userId, String tradeCode) {
|
|
|
GiftOrder order = giftOrderRepo.findById(orderId).orElseThrow(new BusinessException("订单不存在"));
|
|
|
if (order.getStatus() != OrderStatus.NOT_PAID) {
|
|
|
@@ -222,6 +248,20 @@ public class OrderPayService {
|
|
|
generalProperties.getHost() + "/9th/home");
|
|
|
}
|
|
|
|
|
|
+ @Cacheable(value = "payOrder", key = "'mintOrder#'+#orderId")
|
|
|
+ public String payMintQuickBind(Long orderId) {
|
|
|
+ MintOrder order = mintOrderRepo.findById(orderId).orElseThrow(new BusinessException("订单不存在"));
|
|
|
+ if (order.getStatus() != MintOrderStatus.NOT_PAID) {
|
|
|
+ throw new BusinessException("订单状态错误");
|
|
|
+ }
|
|
|
+ IdentityAuth identityAuth = identityAuthRepo.findFirstByUserIdAndStatusAndDelFalseOrderByCreatedAtDesc(order.getUserId(), AuthStatus.SUCCESS)
|
|
|
+ .orElseThrow(new BusinessException("请先完成实名认证"));
|
|
|
+ return sandPayService.payQuickBind(orderId + "", "铸造活动:" + order.getMintActivityId(),
|
|
|
+ order.getGasPrice(), order.getCreatedAt().plusMinutes(3), Constants.OrderNotifyType.MINT,
|
|
|
+ generalProperties.getHost() + "/9th/home",
|
|
|
+ order.getUserId(), identityAuth.getRealName(), identityAuth.getIdNo());
|
|
|
+ }
|
|
|
+
|
|
|
public void payMintOrderBalance(Long orderId, Long userId, String tradeCode) {
|
|
|
MintOrder order = mintOrderRepo.findById(orderId).orElseThrow(new BusinessException("订单不存在"));
|
|
|
if (order.getStatus() != MintOrderStatus.NOT_PAID) {
|
|
|
@@ -336,6 +376,29 @@ public class OrderPayService {
|
|
|
generalProperties.getHost() + "/9th/home");
|
|
|
}
|
|
|
|
|
|
+ public String rechargeQuickBind(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");
|
|
|
+ }
|
|
|
+ IdentityAuth identityAuth = identityAuthRepo.findFirstByUserIdAndStatusAndDelFalseOrderByCreatedAtDesc(userId, AuthStatus.SUCCESS)
|
|
|
+ .orElseThrow(new BusinessException("请先完成实名认证"));
|
|
|
+ RechargeOrder order = RechargeOrder.builder()
|
|
|
+ .id(snowflakeIdWorker.nextId())
|
|
|
+ .userId(userId)
|
|
|
+ .amount(amount)
|
|
|
+ .status(OrderStatus.NOT_PAID)
|
|
|
+ .build();
|
|
|
+ rechargeOrderRepo.save(order);
|
|
|
+ return sandPayService.payQuickBind(order.getId() + "", "余额充值",
|
|
|
+ order.getAmount(), LocalDateTime.now().plusMinutes(3), Constants.OrderNotifyType.RECHARGE,
|
|
|
+ generalProperties.getHost() + "/9th/home",
|
|
|
+ userId, identityAuth.getRealName(), identityAuth.getIdNo());
|
|
|
+ }
|
|
|
+
|
|
|
public JSONObject refund(String orderId, String transactionId, BigDecimal amount, String channel) {
|
|
|
switch (channel) {
|
|
|
case Constants.PayChannel.SAND: {
|
|
|
@@ -417,9 +480,26 @@ public class OrderPayService {
|
|
|
if (order.getStatus() != AuctionOrderStatus.NOT_PAID) {
|
|
|
throw new BusinessException("订单状态错误");
|
|
|
}
|
|
|
- return sandPayService.payQuick(orderId + "", "拍卖:" + order.getName(),
|
|
|
+ IdentityAuth identityAuth = identityAuthRepo.findFirstByUserIdAndStatusAndDelFalseOrderByCreatedAtDesc(order.getUserId(), AuthStatus.SUCCESS)
|
|
|
+ .orElseThrow(new BusinessException("请先完成实名认证"));
|
|
|
+ return sandPayService.payQuickBind(orderId + "", "拍卖:" + order.getName(),
|
|
|
order.getTotalPrice(), order.getCreatedAt().plusMinutes(3), Constants.OrderNotifyType.AUCTION,
|
|
|
- generalProperties.getHost() + "/9th/home");
|
|
|
+ generalProperties.getHost() + "/9th/home",
|
|
|
+ order.getUserId(), identityAuth.getRealName(), identityAuth.getIdNo());
|
|
|
+ }
|
|
|
+
|
|
|
+ @Cacheable(value = "payOrder", key = "'auctionOrder#'+#orderId")
|
|
|
+ public String payAuctionQuickBind(Long orderId) {
|
|
|
+ AuctionOrder order = auctionOrderRepo.findById(orderId).orElseThrow(new BusinessException("订单不存在"));
|
|
|
+ if (order.getStatus() != AuctionOrderStatus.NOT_PAID) {
|
|
|
+ throw new BusinessException("订单状态错误");
|
|
|
+ }
|
|
|
+ IdentityAuth identityAuth = identityAuthRepo.findFirstByUserIdAndStatusAndDelFalseOrderByCreatedAtDesc(order.getUserId(), AuthStatus.SUCCESS)
|
|
|
+ .orElseThrow(new BusinessException("请先完成实名认证"));
|
|
|
+ return sandPayService.payQuickBind(orderId + "", "拍卖:" + order.getName(),
|
|
|
+ order.getTotalPrice(), order.getCreatedAt().plusMinutes(3), Constants.OrderNotifyType.AUCTION,
|
|
|
+ generalProperties.getHost() + "/9th/home",
|
|
|
+ order.getUserId(), identityAuth.getRealName(), identityAuth.getIdNo());
|
|
|
}
|
|
|
|
|
|
public void payAuctionOrderBalance(Long orderId, Long userId, String tradeCode) {
|