| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075 |
- package com.izouma.nineth.service;
- import com.alibaba.fastjson.JSONObject;
- import com.alipay.api.AlipayApiException;
- import com.alipay.api.AlipayClient;
- import com.alipay.api.request.AlipayTradePrecreateRequest;
- import com.alipay.api.response.AlipayTradePrecreateResponse;
- import com.google.zxing.WriterException;
- import com.izouma.nineth.config.AlipayProperties;
- import com.izouma.nineth.config.Constants;
- import com.izouma.nineth.config.GeneralProperties;
- import com.izouma.nineth.domain.*;
- import com.izouma.nineth.domain.nftdomain.DomainAsk;
- import com.izouma.nineth.dto.PayQuery;
- import com.izouma.nineth.dto.UserBankCard;
- import com.izouma.nineth.enums.*;
- import com.izouma.nineth.event.OrderNotifyEvent;
- import com.izouma.nineth.exception.BusinessException;
- import com.izouma.nineth.repo.*;
- import com.izouma.nineth.repo.nftdomain.DomainAskRepo;
- import com.izouma.nineth.service.nftdomain.DomainAskService;
- import com.izouma.nineth.utils.SnowflakeIdWorker;
- import lombok.AllArgsConstructor;
- import lombok.extern.slf4j.Slf4j;
- import org.apache.commons.lang3.StringUtils;
- import org.apache.rocketmq.spring.core.RocketMQTemplate;
- import org.springframework.cache.annotation.Cacheable;
- import org.springframework.security.crypto.password.PasswordEncoder;
- import org.springframework.stereotype.Service;
- import org.springframework.web.context.request.RequestContextHolder;
- import org.springframework.web.context.request.ServletRequestAttributes;
- import javax.swing.text.DateFormatter;
- import java.awt.*;
- import java.io.IOException;
- import java.math.BigDecimal;
- import java.net.URLEncoder;
- import java.nio.charset.StandardCharsets;
- import java.text.DateFormat;
- import java.time.LocalDateTime;
- import java.time.format.DateTimeFormatter;
- import java.util.Map;
- import java.util.Objects;
- import java.util.Optional;
- import java.util.stream.Stream;
- @Service
- @Slf4j
- @AllArgsConstructor
- public class OrderPayService {
- private static String PAY_CHANNEL = Constants.PayChannel.SAND;
- private final OrderService orderService;
- private final OrderRepo orderRepo;
- private final MintOrderRepo mintOrderRepo;
- private final GiftOrderRepo giftOrderRepo;
- private final SandPayService sandPayService;
- private final HMPayService hmPayService;
- private final GeneralProperties generalProperties;
- private final UserBalanceService userBalanceService;
- private final RocketMQTemplate rocketMQTemplate;
- private final GiftOrderService giftOrderService;
- private final MintOrderService mintOrderService;
- private final UserRepo userRepo;
- private final SnowflakeIdWorker snowflakeIdWorker;
- private final RechargeOrderRepo rechargeOrderRepo;
- private final SysConfigService sysConfigService;
- private final PasswordEncoder passwordEncoder;
- private final PayEaseService payEaseService;
- private final UserBankCardRepo userBankCardRepo;
- private final AuctionOrderRepo auctionOrderRepo;
- private final AuctionOrderService auctionOrderService;
- private final IdentityAuthRepo identityAuthRepo;
- private final AlipayClient alipayClient;
- private final AlipayProperties alipayProperties;
- private final AlipayService alipayService;
- private final PhotoAssetRepo photoAssetRepo;
- private final PhotoAssetService photoAssetService;
- private final DomainOrderService domainOrderService;
- private final DomainOrderRepo domainOrderRepo;
- private final TradeAuctionRepo tradeAuctionRepo;
- private final TradeAuctionOrderRepo tradeAuctionOrderRepo;
- private final TradeAuctionOrderService tradeAuctionOrderService;
- private final DomainAskRepo domainAskRepo;
- private final DomainAskService domainAskService;
- public static void setPayChannel(String payChannel) {
- log.info("set pay channel {}", payChannel);
- if (Constants.PayChannel.HM.equals(payChannel) || Constants.PayChannel.SAND.equals(payChannel)) {
- PAY_CHANNEL = payChannel;
- }
- }
- @Cacheable(value = "payOrder", key = "'order#'+#orderId")
- public String payOrder(Long orderId) {
- Order order = orderRepo.findById(orderId).orElseThrow(new BusinessException("订单不存在"));
- 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.resolveFrontUrl(order.getCompanyId(), "/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", amount);
- bizContent.put("subject", subject);
- DateTimeFormatter df = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
- bizContent.put("time_expire", df.format(LocalDateTime.now().plusSeconds(175)));
- JSONObject body = new JSONObject();
- body.put("type", type);
- body.put("orderId", orderId);
- bizContent.put("body", body.toString());
- request.setBizContent(bizContent.toString());
- AlipayTradePrecreateResponse response = null;
- try {
- response = alipayClient.execute(request);
- } catch (AlipayApiException e) {
- e.printStackTrace();
- throw new BusinessException(Constants.PAY_ERR_MSG, e.getErrMsg());
- }
- if (response.isSuccess()) {
- 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(Constants.ALIPAY_URL_SCHEME + qrCode, StandardCharsets.UTF_8)
- + "&orderId=" + orderId + "&type=order&returnUrl="
- + URLEncoder
- .encode(generalProperties.resolveFrontUrl(order.getCompanyId(), "/store"), StandardCharsets.UTF_8);
- } else {
- return Constants.ALIPAY_URL_SCHEME + qrCode;
- }
- }
- @Cacheable(value = "payOrder", key = "'order#'+#orderId")
- public String payOrderQuick(Long orderId) {
- Order order = orderRepo.findById(orderId).orElseThrow(new BusinessException("订单不存在"));
- if (order.getStatus() != OrderStatus.NOT_PAID) {
- throw new BusinessException("订单状态错误");
- }
- return sandPayService.payQuick(orderId + "", order.getName(), order.getTotalPrice(),
- order.getCreatedAt().plusMinutes(3), Constants.OrderNotifyType.ORDER,
- generalProperties.resolveFrontUrl(order.getCompanyId(), "/store"));
- }
- @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.resolveFrontUrl(order.getCompanyId(), "/store"),
- 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) {
- throw new BusinessException("订单状态错误");
- }
- checkTradeCode(userId, tradeCode, order.getUserId());
- BalanceRecord record = userBalanceService
- .balancePay(order.getUserId(), order.getTotalPrice(), orderId, order.getName());
- rocketMQTemplate.syncSend(generalProperties.getOrderNotifyTopic(),
- new OrderNotifyEvent(orderId, PayMethod.BALANCE, record.getId().toString(),
- System.currentTimeMillis()));
- }
- @Cacheable(value = "payOrder", key = "'order#'+#orderId")
- public Map<String, Object> payOrderAgreement(Long orderId, String bindCardId) {
- Order order = orderRepo.findById(orderId).orElseThrow(new BusinessException("订单不存在"));
- if (order.getStatus() != OrderStatus.NOT_PAID) {
- throw new BusinessException("订单状态错误");
- }
- if (StringUtils.isEmpty(bindCardId)) {
- bindCardId = userBankCardRepo.findByUserId(order.getUserId())
- .stream().map(UserBankCard::getBindCardId).findFirst().orElse(null);
- }
- if (StringUtils.isEmpty(bindCardId)) {
- throw new BusinessException("请先绑定银行卡");
- }
- return payEaseService.pay(order.getName(), orderId.toString(), order.getTotalPrice(),
- order.getUserId().toString(), bindCardId, Constants.OrderNotifyType.ORDER);
- }
- public void confirmOrderAgreement(String requestId, String paymentOrderId, String code) {
- try {
- payEaseService.payConfirm(requestId, paymentOrderId, code);
- } catch (BusinessException e) {
- try {
- new Thread(() -> {
- orderService.cancel(Long.parseLong(requestId));
- }).start();
- } catch (Exception ee) {
- }
- throw e;
- }
- }
- @Cacheable(value = "payOrder", key = "'gift#'+#orderId")
- public String payGiftOrder(Long orderId) {
- GiftOrder order = giftOrderRepo.findById(orderId).orElseThrow(new BusinessException("订单不存在"));
- if (order.getStatus() != OrderStatus.NOT_PAID) {
- throw new BusinessException("订单状态错误");
- }
- switch (PAY_CHANNEL) {
- case Constants.PayChannel.SAND:
- return sandPayService.pay(orderId + "", "转赠" + order.getAssetId(), order.getGasPrice(),
- order.getCreatedAt().plusMinutes(3), Constants.OrderNotifyType.GIFT);
- case Constants.PayChannel.HM:
- return hmPayService.requestAlipay(orderId + "", order.getGasPrice(),
- "转赠" + order.getAssetId(),
- HMPayService.getTimeout(order.getCreatedAt(), 180),
- Constants.OrderNotifyType.GIFT, generalProperties
- .resolveFrontUrl(order.getCompanyId(), "/store"));
- }
- 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(Constants.ALIPAY_URL_SCHEME + qrCode, StandardCharsets.UTF_8)
- + "&orderId=" + orderId + "&type=gift&returnUrl="
- + URLEncoder
- .encode(generalProperties.resolveFrontUrl(order.getCompanyId(), "/store"), StandardCharsets.UTF_8);
- } else {
- return Constants.ALIPAY_URL_SCHEME + qrCode;
- }
- }
- @Cacheable(value = "payOrder", key = "'gift#'+#orderId")
- public String payGiftQuick(Long orderId) {
- GiftOrder order = giftOrderRepo.findById(orderId).orElseThrow(new BusinessException("订单不存在"));
- if (order.getStatus() != OrderStatus.NOT_PAID) {
- throw new BusinessException("订单状态错误");
- }
- return sandPayService.payQuick(orderId + "", "转赠" + order.getAssetId(), order.getGasPrice(),
- order.getCreatedAt().plusMinutes(3), Constants.OrderNotifyType.GIFT,
- generalProperties.resolveFrontUrl(order.getCompanyId(), "/store"));
- }
- @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.resolveFrontUrl(order.getCompanyId(), "/store"),
- 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) {
- throw new BusinessException("订单状态错误");
- }
- checkTradeCode(userId, tradeCode, order.getUserId());
- BalanceRecord record = userBalanceService.balancePay(order.getUserId(), order.getGasPrice(), orderId, "转赠");
- giftOrderService.giftNotify(orderId, PayMethod.BALANCE, record.getId().toString());
- }
- @Cacheable(value = "payOrder", key = "'gift#'+#orderId")
- public Map<String, Object> payGiftOrderAgreement(Long orderId, String bindCardId) {
- GiftOrder order = giftOrderRepo.findById(orderId).orElseThrow(new BusinessException("订单不存在"));
- if (order.getStatus() != OrderStatus.NOT_PAID) {
- throw new BusinessException("订单状态错误");
- }
- if (StringUtils.isEmpty(bindCardId)) {
- bindCardId = userBankCardRepo.findByUserId(order.getUserId())
- .stream().map(UserBankCard::getBindCardId).findFirst().orElse(null);
- }
- if (StringUtils.isEmpty(bindCardId)) {
- throw new BusinessException("请先绑定银行卡");
- }
- return payEaseService.pay("转赠" + order.getAssetId(), orderId.toString(), order.getGasPrice(),
- order.getUserId().toString(), bindCardId, Constants.OrderNotifyType.GIFT);
- }
- @Cacheable(value = "payOrder", key = "'mintOrder#'+#orderId")
- public String payMintOrder(Long orderId) {
- MintOrder order = mintOrderRepo.findById(orderId).orElseThrow(new BusinessException("订单不存在"));
- if (order.getStatus() != MintOrderStatus.NOT_PAID) {
- throw new BusinessException("订单状态错误");
- }
- switch (PAY_CHANNEL) {
- case Constants.PayChannel.SAND:
- return sandPayService.pay(orderId + "", "铸造活动:" + order.getMintActivityId(),
- order.getGasPrice(), order.getCreatedAt().plusMinutes(3), Constants.OrderNotifyType.MINT);
- case Constants.PayChannel.HM:
- return hmPayService.requestAlipay(orderId + "", order.getGasPrice(),
- "铸造活动:" + order.getMintActivityId(),
- HMPayService.getTimeout(order.getCreatedAt(), 180),
- Constants.OrderNotifyType.MINT, generalProperties
- .resolveFrontUrl(order.getCompanyId(), "/home"));
- }
- 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(Constants.ALIPAY_URL_SCHEME + qrCode, StandardCharsets.UTF_8)
- + "&orderId=" + orderId + "&type=mintOrder&returnUrl="
- + URLEncoder
- .encode(generalProperties.resolveFrontUrl(order.getCompanyId(), "/home"), StandardCharsets.UTF_8);
- } else {
- return Constants.ALIPAY_URL_SCHEME + qrCode;
- }
- }
- @Cacheable(value = "payOrder", key = "'mintOrder#'+#orderId")
- public String payMintQuick(Long orderId) {
- MintOrder order = mintOrderRepo.findById(orderId).orElseThrow(new BusinessException("订单不存在"));
- if (order.getStatus() != MintOrderStatus.NOT_PAID) {
- throw new BusinessException("订单状态错误");
- }
- return sandPayService.payQuick(orderId + "", "铸造活动:" + order.getMintActivityId(),
- order.getGasPrice(), order.getCreatedAt().plusMinutes(3), Constants.OrderNotifyType.MINT,
- generalProperties.resolveFrontUrl(order.getCompanyId(), "/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.resolveFrontUrl(order.getCompanyId(), "/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) {
- throw new BusinessException("订单状态错误");
- }
- checkTradeCode(userId, tradeCode, order.getUserId());
- BalanceRecord record = userBalanceService.balancePay(order.getUserId(), order.getGasPrice(), orderId, "铸造活动");
- mintOrderService.mintNotify(orderId, PayMethod.BALANCE, record.getId().toString());
- }
- private void checkTradeCode(Long userId, String tradeCode, Long orderUserId) {
- if (!Objects.equals(orderUserId, userId)) {
- throw new BusinessException("订单不属于该用户");
- }
- String encodedPwd = userRepo.findTradeCode(userId);
- if (StringUtils.isEmpty(encodedPwd)) {
- throw new BusinessException("请先设置交易密码");
- }
- if (!passwordEncoder.matches(tradeCode, encodedPwd)) {
- throw new BusinessException("交易码错误");
- }
- }
- @Cacheable(value = "payOrder", key = "'mint#'+#orderId")
- public Map<String, Object> payMintOrderAgreement(Long orderId, String bindCardId) {
- MintOrder order = mintOrderRepo.findById(orderId).orElseThrow(new BusinessException("订单不存在"));
- if (order.getStatus() != MintOrderStatus.NOT_PAID) {
- throw new BusinessException("订单状态错误");
- }
- if (StringUtils.isEmpty(bindCardId)) {
- bindCardId = userBankCardRepo.findByUserId(order.getUserId())
- .stream().map(UserBankCard::getBindCardId).findFirst().orElse(null);
- }
- if (StringUtils.isEmpty(bindCardId)) {
- throw new BusinessException("请先绑定银行卡");
- }
- return payEaseService.pay("铸造活动:" + order.getMintActivityId(), orderId.toString(), order.getGasPrice(),
- order.getUserId().toString(), bindCardId, Constants.OrderNotifyType.MINT);
- }
- private Long getCompanyId() {
- Long companyId = 1L;
- try {
- String hCompanyId = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest()
- .getHeader("companyId");
- if (StringUtils.isNotBlank(hCompanyId)) {
- companyId = Long.parseLong(hCompanyId);
- }
- } catch (Exception ignored) {
- }
- return companyId;
- }
- public String recharge(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);
- switch (PAY_CHANNEL) {
- case Constants.PayChannel.SAND:
- return sandPayService.pay(order.getId() + "", "余额充值", order.getAmount(),
- order.getCreatedAt().plusMinutes(3), Constants.OrderNotifyType.RECHARGE);
- case Constants.PayChannel.HM:
- return hmPayService.requestAlipay(order.getId() + "", order.getAmount(),
- "余额充值",
- HMPayService.getTimeout(order.getCreatedAt(), 180),
- Constants.OrderNotifyType.RECHARGE, generalProperties.resolveFrontUrl(getCompanyId(), "/home"));
- }
- 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(Constants.ALIPAY_URL_SCHEME + qrCode, StandardCharsets.UTF_8)
- + "&orderId=" + order.getId() + "&type=recharge&returnUrl="
- + URLEncoder
- .encode(generalProperties.resolveFrontUrl(getCompanyId(), "/home"), StandardCharsets.UTF_8);
- } else {
- return Constants.ALIPAY_URL_SCHEME + qrCode;
- }
- }
- public Map<String, Object> rechargeAgreement(Long userId, BigDecimal amount, String bindCardId) {
- 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);
- if (StringUtils.isEmpty(bindCardId)) {
- bindCardId = userBankCardRepo.findByUserId(order.getUserId())
- .stream().map(UserBankCard::getBindCardId).findFirst().orElse(null);
- }
- if (StringUtils.isEmpty(bindCardId)) {
- throw new BusinessException("请先绑定银行卡");
- }
- return payEaseService.pay("余额充值", order.getId().toString(), order.getAmount(),
- order.getUserId().toString(), bindCardId, Constants.OrderNotifyType.RECHARGE);
- }
- public String rechargeQuick(Long userId, BigDecimal amount, Long companyId) {
- 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);
- return sandPayService.payQuick(order.getId() + "", "余额充值",
- order.getAmount(), LocalDateTime.now().plusMinutes(3), Constants.OrderNotifyType.RECHARGE,
- generalProperties.resolveFrontUrl(companyId, "/home"));
- }
- public String rechargeQuickBind(Long userId, BigDecimal amount, Long companyId) {
- 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.resolveFrontUrl(companyId, "/home"),
- userId, identityAuth.getRealName(), identityAuth.getIdNo());
- }
- public JSONObject refund(String orderId, String transactionId, BigDecimal amount, String channel) {
- switch (channel) {
- case Constants.PayChannel.SAND: {
- JSONObject res = sandPayService.refund(orderId, amount);
- if (!"000000".equals(res.getJSONObject("head").getString("respCode"))) {
- String msg = res.getJSONObject("head").getString("respMsg");
- throw new BusinessException("退款失败:" + msg);
- }
- return res;
- }
- case Constants.PayChannel.HM: {
- JSONObject res = hmPayService.refund(orderId, amount);
- if (!"REFUND_SUCCESS".equals(res.getString("sub_code"))) {
- String msg = res.getString("msg");
- throw new BusinessException("退款失败:" + msg);
- }
- return res;
- }
- case Constants.PayChannel.PE: {
- JSONObject res = payEaseService.refund(orderId, transactionId, amount);
- String status = res.getString("status");
- if (!"SUCCESS".equals(status)) {
- String error = res.getString("error");
- String cause = res.getString("cause");
- throw new BusinessException("退款失败:" + error + ";" + cause);
- }
- return res;
- }
- case Constants.PayChannel.ALI: {
- alipayService.refund(orderId, amount);
- return null;
- }
- }
- throw new BusinessException("退款失败");
- }
- public PayQuery query(String orderId) {
- return query(orderId, null);
- }
- public PayQuery query(String orderId, String channel) {
- if (StringUtils.isNotEmpty(channel)) {
- switch (channel) {
- case Constants.PayChannel.SAND:
- return sandPayService.payQuery(orderId);
- case Constants.PayChannel.HM:
- return hmPayService.payQuery(orderId);
- case Constants.PayChannel.PE:
- return payEaseService.payQuery(orderId);
- }
- }
- PayQuery query = sandPayService.payQuery(orderId);
- if (query == null || !query.isExist()) {
- query = hmPayService.payQuery(orderId);
- }
- if (query == null || !query.isExist()) {
- query = payEaseService.payQuery(orderId);
- }
- if (query == null || !query.isExist()) {
- query = alipayService.payQuery(orderId);
- }
- return Optional.ofNullable(query).orElse(PayQuery.builder().exist(false).build());
- }
- @Cacheable(value = "payOrder", key = "'auctionOrder#'+#orderId")
- public String payAuctionOrder(Long orderId) {
- AuctionOrder order = auctionOrderRepo.findById(orderId).orElseThrow(new BusinessException("订单不存在"));
- if (order.getStatus() != AuctionOrderStatus.NOT_PAID) {
- throw new BusinessException("订单状态错误");
- }
- switch (PAY_CHANNEL) {
- case Constants.PayChannel.SAND:
- return sandPayService.pay(orderId + "", "拍卖:" + order.getName(), order.getTotalPrice(),
- order.getCreatedAt().plusMinutes(3), Constants.OrderNotifyType.AUCTION);
- case Constants.PayChannel.HM:
- return hmPayService.requestAlipay(orderId + "", order.getTotalPrice(),
- "拍卖:" + order.getName(), HMPayService.getTimeout(order.getCreatedAt(), 180),
- Constants.OrderNotifyType.AUCTION, generalProperties.resolveFrontUrl(getCompanyId(), "/home"));
- }
- 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(Constants.ALIPAY_URL_SCHEME + qrCode, StandardCharsets.UTF_8)
- + "&orderId=" + orderId + "&type=auctionOrder&returnUrl="
- + URLEncoder
- .encode(generalProperties.resolveFrontUrl(getCompanyId(), "/home"), StandardCharsets.UTF_8);
- } else {
- return Constants.ALIPAY_URL_SCHEME + qrCode;
- }
- }
- @Cacheable(value = "payOrder", key = "'auctionOrder#'+#orderId")
- public String payAuctionQuick(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.payQuick(orderId + "", "拍卖:" + order.getName(),
- order.getTotalPrice(), order.getCreatedAt().plusMinutes(3), Constants.OrderNotifyType.AUCTION,
- generalProperties.resolveFrontUrl(getCompanyId(), "/home"));
- }
- @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.resolveFrontUrl(getCompanyId(), "/home"),
- order.getUserId(), identityAuth.getRealName(), identityAuth.getIdNo());
- }
- public void payAuctionOrderBalance(Long orderId, Long userId, String tradeCode) {
- AuctionOrder order = auctionOrderRepo.findById(orderId).orElseThrow(new BusinessException("订单不存在"));
- if (order.getStatus() != AuctionOrderStatus.NOT_PAID) {
- throw new BusinessException("订单状态错误");
- }
- checkTradeCode(userId, tradeCode, order.getUserId());
- BalanceRecord record = userBalanceService.balancePay(order.getUserId(), order.getTotalPrice(), orderId, "拍卖");
- auctionOrderService.notify(orderId, PayMethod.BALANCE, record.getId().toString());
- }
- public void payTradeAuctionOrderBalance(Long orderId, Long userId, String tradeCode) {
- TradeAuctionOrder order = tradeAuctionOrderRepo.findById(orderId).orElseThrow(new BusinessException("订单不存在"));
- TradeAuction tradeAuction = tradeAuctionRepo.findById(order.getTradeAuctionId())
- .orElseThrow(new BusinessException("暂无"));
- if (order.getStatus() != AuctionOrderStatus.NOT_PAID) {
- throw new BusinessException("订单状态错误");
- }
- if (tradeAuction.getStock() < 1) {
- throw new BusinessException("库存不足");
- }
- if (LocalDateTime.now().compareTo(tradeAuction.getCurrentStartTime()) < 0) {
- throw new BusinessException("未到竞价时间");
- }
- if (!tradeAuction.getStatus().equals(TradeAuctionStatus.ONGOING) & !tradeAuction.getStatus()
- .equals(TradeAuctionStatus.PURCHASED)) {
- throw new BusinessException("易拍产品未处在竞价状态");
- }
- if (order.getPaymentType().equals(AuctionPaymentType.DEPOSIT)) {
- if (order.getPrice().compareTo(tradeAuction.getNextPrice()) != 0) {
- throw new BusinessException("已经失去购买资格");
- }
- if (tradeAuction.getSale() >= 30) {
- throw new BusinessException("已无购买资格");
- }
- }
- checkTradeCode(userId, tradeCode, order.getUserId());
- BigDecimal amount;
- if (order.getPaymentType() != AuctionPaymentType.DEPOSIT) {
- amount = order.getPrice();
- } else {
- amount = order.getServiceCharge();
- }
- BalanceRecord record = userBalanceService
- .balancePay(order.getUserId(), amount, orderId, "拍卖");
- tradeAuctionOrderService.commission(order, order.getPrice());
- tradeAuctionOrderService.notify(orderId, record.getId().toString(), PayMethod.BALANCE);
- }
- @Cacheable(value = "payOrder", key = "'auctionOrder#'+#orderId")
- public Map<String, Object> payAuctionOrderAgreement(Long orderId, String bindCardId) {
- AuctionOrder order = auctionOrderRepo.findById(orderId).orElseThrow(new BusinessException("订单不存在"));
- if (order.getStatus() != AuctionOrderStatus.NOT_PAID) {
- throw new BusinessException("订单状态错误");
- }
- if (StringUtils.isEmpty(bindCardId)) {
- bindCardId = userBankCardRepo.findByUserId(order.getUserId())
- .stream().map(UserBankCard::getBindCardId).findFirst().orElse(null);
- }
- if (StringUtils.isEmpty(bindCardId)) {
- throw new BusinessException("请先绑定银行卡");
- }
- return payEaseService.pay("拍卖:" + order.getAuctionId(), orderId.toString(), order.getTotalPrice(),
- order.getUserId().toString(), bindCardId, Constants.OrderNotifyType.AUCTION);
- }
- @Cacheable(value = "payOrder", key = "'picOrder#'+#orderId")
- public String payPicOrder(Long orderId) {
- PhotoAsset order = photoAssetRepo.findById(orderId).orElseThrow(new BusinessException("订单不存在"));
- if (order.getOrderStatus() != OrderStatus.NOT_PAID) {
- throw new BusinessException("订单状态错误");
- }
- switch (PAY_CHANNEL) {
- case Constants.PayChannel.SAND:
- return sandPayService.pay(orderId + "", "星图:" + order.getPicName(), order.getPrice(),
- order.getCreatedAt().plusMinutes(3), Constants.OrderNotifyType.PIC);
- case Constants.PayChannel.HM:
- return hmPayService.requestAlipay(orderId + "", order.getPrice(),
- "星图:" + order.getPicName(), HMPayService.getTimeout(order.getCreatedAt(), 180),
- Constants.OrderNotifyType.PIC, generalProperties
- .resolveFrontUrl(getCompanyId(), "/orderDetail?id=" + orderId));
- }
- throw new BusinessException("绿洲宇宙冷却系统已启动,请稍后支付");
- }
- @Cacheable(value = "payOrder", key = "'picOrder#'+#orderId")
- public String payPicAli(Long orderId) {
- PhotoAsset order = photoAssetRepo.findById(orderId).orElseThrow(new BusinessException("订单不存在"));
- if (order.getOrderStatus() != OrderStatus.NOT_PAID) {
- throw new BusinessException("订单状态错误");
- }
- String qrCode = aliRequest(orderId, order.getPrice(), "星图:" + order
- .getPicName(), Constants.OrderNotifyType.PIC);
- String ua = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest()
- .getHeader("User-Agent");
- if (ua.toLowerCase().contains("micromessenger")) {
- return "/static/wx_alipay_bridge.html?payUrl=" + URLEncoder
- .encode(Constants.ALIPAY_URL_SCHEME + qrCode, StandardCharsets.UTF_8)
- + "&orderId=" + orderId + "&type=pic&returnUrl="
- + URLEncoder
- .encode(generalProperties
- .resolveFrontUrl(getCompanyId(), "/orderDetail?id=" + orderId), StandardCharsets.UTF_8);
- } else {
- return Constants.ALIPAY_URL_SCHEME + qrCode;
- }
- }
- @Cacheable(value = "payOrder", key = "'picOrder#'+#orderId")
- public String payPicQuick(Long orderId) {
- PhotoAsset order = photoAssetRepo.findById(orderId).orElseThrow(new BusinessException("订单不存在"));
- if (order.getOrderStatus() != OrderStatus.NOT_PAID) {
- throw new BusinessException("订单状态错误");
- }
- IdentityAuth identityAuth = identityAuthRepo
- .findFirstByUserIdAndStatusAndDelFalseOrderByCreatedAtDesc(order.getUserId(), AuthStatus.SUCCESS)
- .orElseThrow(new BusinessException("请先完成实名认证"));
- return sandPayService.payQuick(orderId + "", "星图:" + order.getPicName(),
- order.getPrice(), order.getCreatedAt().plusMinutes(3), Constants.OrderNotifyType.PIC,
- generalProperties.resolveFrontUrl(getCompanyId(), "/orderDetail?id=" + orderId));
- }
- @Cacheable(value = "payOrder", key = "'picOrder#'+#orderId")
- public String payPicQuickBind(Long orderId) {
- PhotoAsset order = photoAssetRepo.findById(orderId).orElseThrow(new BusinessException("订单不存在"));
- if (order.getOrderStatus() != OrderStatus.NOT_PAID) {
- throw new BusinessException("订单状态错误");
- }
- IdentityAuth identityAuth = identityAuthRepo
- .findFirstByUserIdAndStatusAndDelFalseOrderByCreatedAtDesc(order.getUserId(), AuthStatus.SUCCESS)
- .orElseThrow(new BusinessException("请先完成实名认证"));
- return sandPayService.payQuickBind(orderId + "", "星图:" + order.getPicName(),
- order.getPrice(), order.getCreatedAt().plusMinutes(3), Constants.OrderNotifyType.PIC,
- generalProperties.resolveFrontUrl(getCompanyId(), "/orderDetail?id=" + orderId),
- order.getUserId(), identityAuth.getRealName(), identityAuth.getIdNo());
- }
- public void payPicOrderBalance(Long orderId, Long userId, String tradeCode) {
- PhotoAsset order = photoAssetRepo.findById(orderId).orElseThrow(new BusinessException("订单不存在"));
- if (order.getOrderStatus() != OrderStatus.NOT_PAID) {
- throw new BusinessException("订单状态错误");
- }
- checkTradeCode(userId, tradeCode, order.getUserId());
- BalanceRecord record = userBalanceService.balancePay(order.getUserId(), order.getPrice(), orderId, "星图");
- photoAssetService.notify(orderId, PayMethod.BALANCE, record.getId().toString());
- }
- @Cacheable(value = "payOrder", key = "'picOrder#'+#orderId")
- public Map<String, Object> payPicOrderAgreement(Long orderId, String bindCardId) {
- PhotoAsset order = photoAssetRepo.findById(orderId).orElseThrow(new BusinessException("订单不存在"));
- if (order.getOrderStatus() != OrderStatus.NOT_PAID) {
- throw new BusinessException("订单状态错误");
- }
- if (StringUtils.isEmpty(bindCardId)) {
- bindCardId = userBankCardRepo.findByUserId(order.getUserId())
- .stream().map(UserBankCard::getBindCardId).findFirst().orElse(null);
- }
- if (StringUtils.isEmpty(bindCardId)) {
- throw new BusinessException("请先绑定银行卡");
- }
- return payEaseService.pay("星图:" + order.getPicName(), orderId.toString(), order.getPrice(),
- order.getUserId().toString(), bindCardId, Constants.OrderNotifyType.PIC);
- }
- @Cacheable(value = "payOrder", key = "'domain#'+#orderId")
- public String payDomainOrder(Long orderId) {
- DomainOrder order = domainOrderRepo.findById(orderId).orElseThrow(new BusinessException("订单不存在"));
- if (order.getOrderStatus() != OrderStatus.NOT_PAID) {
- throw new BusinessException("订单状态错误");
- }
- switch (PAY_CHANNEL) {
- case Constants.PayChannel.SAND:
- return sandPayService.pay(orderId + "", "域名:" + order.getPicName(), order.getPrice(),
- order.getCreatedAt().plusMinutes(3), Constants.OrderNotifyType.DOMAIN);
- case Constants.PayChannel.HM:
- return hmPayService.requestAlipay(orderId + "", order.getPrice(),
- "域名:" + order.getPicName(), HMPayService.getTimeout(order.getCreatedAt(), 180),
- Constants.OrderNotifyType.DOMAIN, generalProperties
- .resolveFrontUrl(getCompanyId(), "/domainname"));
- }
- throw new BusinessException("绿洲宇宙冷却系统已启动,请稍后支付");
- }
- @Cacheable(value = "payOrder", key = "'domain#'+#orderId")
- public String payDomainAli(Long orderId) {
- DomainOrder order = domainOrderRepo.findById(orderId).orElseThrow(new BusinessException("订单不存在"));
- if (order.getOrderStatus() != OrderStatus.NOT_PAID) {
- throw new BusinessException("订单状态错误");
- }
- String qrCode = aliRequest(orderId, order.getPrice(), "域名:" + order
- .getPicName(), Constants.OrderNotifyType.DOMAIN);
- String ua = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest()
- .getHeader("User-Agent");
- if (ua.toLowerCase().contains("micromessenger")) {
- return "/static/wx_alipay_bridge.html?payUrl=" + URLEncoder
- .encode(Constants.ALIPAY_URL_SCHEME + qrCode, StandardCharsets.UTF_8)
- + "&orderId=" + orderId + "&type=domain&returnUrl="
- + URLEncoder
- .encode(generalProperties
- .resolveFrontUrl(getCompanyId(), "/domainname"), StandardCharsets.UTF_8);
- } else {
- return Constants.ALIPAY_URL_SCHEME + qrCode;
- }
- }
- @Cacheable(value = "payOrder", key = "'domain#'+#orderId")
- public String payDomainQuick(Long orderId) {
- DomainOrder order = domainOrderRepo.findById(orderId).orElseThrow(new BusinessException("订单不存在"));
- if (order.getOrderStatus() != OrderStatus.NOT_PAID) {
- throw new BusinessException("订单状态错误");
- }
- IdentityAuth identityAuth = identityAuthRepo
- .findFirstByUserIdAndStatusAndDelFalseOrderByCreatedAtDesc(order.getUserId(), AuthStatus.SUCCESS)
- .orElseThrow(new BusinessException("请先完成实名认证"));
- return sandPayService.payQuick(orderId + "", "域名:" + order.getPicName(),
- order.getPrice(), order.getCreatedAt().plusMinutes(3), Constants.OrderNotifyType.DOMAIN,
- generalProperties.resolveFrontUrl(getCompanyId(), "/domainname"));
- }
- @Cacheable(value = "payOrder", key = "'domain#'+#orderId")
- public String payDomainQuickBind(Long orderId) {
- DomainOrder order = domainOrderRepo.findById(orderId).orElseThrow(new BusinessException("订单不存在"));
- if (order.getOrderStatus() != OrderStatus.NOT_PAID) {
- throw new BusinessException("订单状态错误");
- }
- IdentityAuth identityAuth = identityAuthRepo
- .findFirstByUserIdAndStatusAndDelFalseOrderByCreatedAtDesc(order.getUserId(), AuthStatus.SUCCESS)
- .orElseThrow(new BusinessException("请先完成实名认证"));
- return sandPayService.payQuickBind(orderId + "", "域名:" + order.getPicName(),
- order.getPrice(), order.getCreatedAt().plusMinutes(3), Constants.OrderNotifyType.DOMAIN,
- generalProperties.resolveFrontUrl(getCompanyId(), "/domainname"),
- order.getUserId(), identityAuth.getRealName(), identityAuth.getIdNo());
- }
- public void payDomainOrderBalance(Long orderId, Long userId, String tradeCode) throws FontFormatException, IOException, WriterException {
- DomainOrder order = domainOrderRepo.findById(orderId).orElseThrow(new BusinessException("订单不存在"));
- if (order.getOrderStatus() != OrderStatus.NOT_PAID) {
- throw new BusinessException("订单状态错误");
- }
- checkTradeCode(userId, tradeCode, order.getUserId());
- BalanceRecord record = userBalanceService.balancePay(order.getUserId(), order.getPrice(), orderId, "域名");
- domainOrderService.notify(orderId, PayMethod.BALANCE, record.getId().toString());
- }
- @Cacheable(value = "payOrder", key = "'domain#'+#orderId")
- public Map<String, Object> payDomainOrderAgreement(Long orderId, String bindCardId) {
- DomainOrder order = domainOrderRepo.findById(orderId).orElseThrow(new BusinessException("订单不存在"));
- if (order.getOrderStatus() != OrderStatus.NOT_PAID) {
- throw new BusinessException("订单状态错误");
- }
- if (StringUtils.isEmpty(bindCardId)) {
- bindCardId = userBankCardRepo.findByUserId(order.getUserId())
- .stream().map(UserBankCard::getBindCardId).findFirst().orElse(null);
- }
- if (StringUtils.isEmpty(bindCardId)) {
- throw new BusinessException("请先绑定银行卡");
- }
- return payEaseService.pay("域名:" + order.getPicName(), orderId.toString(), order.getPrice(),
- order.getUserId().toString(), bindCardId, Constants.OrderNotifyType.DOMAIN);
- }
- public void payDomainAskBalance(Long orderId, Long userId, String tradeCode) throws FontFormatException, IOException, WriterException {
- DomainAsk order = domainAskRepo.findById(orderId).orElseThrow(new BusinessException("订单不存在"));
- if (order.getStatus() != DomainAskStatus.NOT_PAID) {
- throw new BusinessException("订单状态错误");
- }
- checkTradeCode(userId, tradeCode, order.getUserId());
- BalanceRecord record = userBalanceService.balancePay(order.getUserId(), order.getPrice(), orderId, "元域名叫价");
- domainAskService.notifyOrder(orderId, PayMethod.BALANCE, record.getId().toString());
- }
- @Cacheable(value = "payOrder", key = "'ask#'+#orderId")
- public String payAskOrder(Long orderId) {
- DomainAsk order = domainAskRepo.findById(orderId).orElseThrow(new BusinessException("订单不存在"));
- if (order.getStatus() != DomainAskStatus.NOT_PAID) {
- throw new BusinessException("订单状态错误");
- }
- switch (PAY_CHANNEL) {
- case Constants.PayChannel.SAND:
- return sandPayService.pay(orderId + "", "域名:" + order.getName(), order.getPrice(),
- order.getCreatedAt().plusMinutes(3), Constants.OrderNotifyType.ASK);
- case Constants.PayChannel.HM:
- return hmPayService.requestAlipay(orderId + "", order.getPrice(),
- "域名:" + order.getName(), HMPayService.getTimeout(order.getCreatedAt(), 180),
- Constants.OrderNotifyType.ASK, generalProperties
- .resolveFrontUrl(getCompanyId(), "/domainname"));
- }
- throw new BusinessException("绿洲宇宙冷却系统已启动,请稍后支付");
- }
- @Cacheable(value = "payOrder", key = "'ask#'+#orderId")
- public String payAskAli(Long orderId) {
- DomainAsk order = domainAskRepo.findById(orderId).orElseThrow(new BusinessException("订单不存在"));
- if (order.getStatus() != DomainAskStatus.NOT_PAID) {
- throw new BusinessException("订单状态错误");
- }
- String qrCode = aliRequest(orderId, order.getPrice(), "叫价:" + order
- .getName(), Constants.OrderNotifyType.ASK);
- String ua = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest()
- .getHeader("User-Agent");
- if (ua.toLowerCase().contains("micromessenger")) {
- return "/static/wx_alipay_bridge.html?payUrl=" + URLEncoder
- .encode(Constants.ALIPAY_URL_SCHEME + qrCode, StandardCharsets.UTF_8)
- + "&orderId=" + orderId + "&type=domain&returnUrl="
- + URLEncoder
- .encode(generalProperties
- .resolveFrontUrl(getCompanyId(), "/domainname"), StandardCharsets.UTF_8);
- } else {
- return Constants.ALIPAY_URL_SCHEME + qrCode;
- }
- }
- @Cacheable(value = "payOrder", key = "'ask#'+#orderId")
- public String payAskQuick(Long orderId) {
- DomainAsk order = domainAskRepo.findById(orderId).orElseThrow(new BusinessException("订单不存在"));
- if (order.getStatus() != DomainAskStatus.NOT_PAID) {
- throw new BusinessException("订单状态错误");
- }
- IdentityAuth identityAuth = identityAuthRepo
- .findFirstByUserIdAndStatusAndDelFalseOrderByCreatedAtDesc(order.getUserId(), AuthStatus.SUCCESS)
- .orElseThrow(new BusinessException("请先完成实名认证"));
- return sandPayService.payQuick(orderId + "", "叫价:" + order.getName(),
- order.getPrice(), order.getCreatedAt().plusMinutes(3), Constants.OrderNotifyType.ASK,
- generalProperties.resolveFrontUrl(getCompanyId(), "/domainname"));
- }
- @Cacheable(value = "payOrder", key = "'ask#'+#orderId")
- public String payAskQuickBind(Long orderId) {
- DomainAsk order = domainAskRepo.findById(orderId).orElseThrow(new BusinessException("订单不存在"));
- if (order.getStatus() != DomainAskStatus.NOT_PAID) {
- throw new BusinessException("订单状态错误");
- }
- IdentityAuth identityAuth = identityAuthRepo
- .findFirstByUserIdAndStatusAndDelFalseOrderByCreatedAtDesc(order.getUserId(), AuthStatus.SUCCESS)
- .orElseThrow(new BusinessException("请先完成实名认证"));
- return sandPayService.payQuickBind(orderId + "", "叫价:" + order.getName(),
- order.getPrice(), order.getCreatedAt().plusMinutes(3), Constants.OrderNotifyType.ASK,
- generalProperties.resolveFrontUrl(getCompanyId(), "/domainname"),
- order.getUserId(), identityAuth.getRealName(), identityAuth.getIdNo());
- }
- @Cacheable(value = "payOrder", key = "'ask#'+#orderId")
- public Map<String, Object> payAskOrderAgreement(Long orderId, String bindCardId) {
- DomainAsk order = domainAskRepo.findById(orderId).orElseThrow(new BusinessException("订单不存在"));
- if (order.getStatus() != DomainAskStatus.NOT_PAID) {
- throw new BusinessException("订单状态错误");
- }
- if (StringUtils.isEmpty(bindCardId)) {
- bindCardId = userBankCardRepo.findByUserId(order.getUserId())
- .stream().map(UserBankCard::getBindCardId).findFirst().orElse(null);
- }
- if (StringUtils.isEmpty(bindCardId)) {
- throw new BusinessException("请先绑定银行卡");
- }
- return payEaseService.pay("叫价:" + order.getName(), orderId.toString(), order.getPrice(),
- order.getUserId().toString(), bindCardId, Constants.OrderNotifyType.ASK);
- }
- }
|