|
|
@@ -3,9 +3,11 @@ package com.izouma.nineth.service;
|
|
|
import cn.com.sandpay.cashier.sdk.*;
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
import com.izouma.nineth.config.SandPayProperties;
|
|
|
+import com.izouma.nineth.domain.GiftOrder;
|
|
|
import com.izouma.nineth.domain.Order;
|
|
|
import com.izouma.nineth.enums.OrderStatus;
|
|
|
import com.izouma.nineth.exception.BusinessException;
|
|
|
+import com.izouma.nineth.repo.GiftOrderRepo;
|
|
|
import com.izouma.nineth.repo.OrderRepo;
|
|
|
import com.izouma.nineth.utils.DateTimeUtils;
|
|
|
import lombok.AllArgsConstructor;
|
|
|
@@ -33,6 +35,7 @@ import java.util.Map;
|
|
|
@Slf4j
|
|
|
public class SandPayService {
|
|
|
private final OrderRepo orderRepo;
|
|
|
+ private final GiftOrderRepo giftOrderRepo;
|
|
|
private final SandPayProperties sandPayProperties;
|
|
|
|
|
|
public JSONObject requestServer(JSONObject header, JSONObject body, String reqAddr) {
|
|
|
@@ -160,4 +163,22 @@ public class SandPayService {
|
|
|
|
|
|
return res.getJSONObject("body").getString("qrCode");
|
|
|
}
|
|
|
+
|
|
|
+ @Cacheable(value = "sandPay", key = "#orderId")
|
|
|
+ public String payGiftOrder(Long orderId) {
|
|
|
+ GiftOrder order = giftOrderRepo.findById(orderId).orElseThrow(new BusinessException("订单不存在"));
|
|
|
+ if (order.getStatus() != OrderStatus.NOT_PAID) {
|
|
|
+ throw new BusinessException("订单状态错误");
|
|
|
+ }
|
|
|
+ JSONObject extend = new JSONObject();
|
|
|
+ extend.put("type", "gift");
|
|
|
+ extend.put("id", orderId);
|
|
|
+
|
|
|
+ JSONObject res = requestAlipay(orderId.toString(), order.getGasPrice(), "转增" + order.getAssetId(), "转增" + order.getAssetId(),
|
|
|
+ order.getCreatedAt().plusMinutes(3), extend.toJSONString());
|
|
|
+ if (res == null)
|
|
|
+ throw new BusinessException("下单失败,请稍后再试");
|
|
|
+
|
|
|
+ return res.getJSONObject("body").getString("qrCode");
|
|
|
+ }
|
|
|
}
|