|
|
@@ -25,9 +25,7 @@ import com.izouma.nineth.enums.AssetStatus;
|
|
|
import com.izouma.nineth.enums.OrderStatus;
|
|
|
import com.izouma.nineth.enums.PayMethod;
|
|
|
import com.izouma.nineth.exception.BusinessException;
|
|
|
-import com.izouma.nineth.repo.AssetRepo;
|
|
|
-import com.izouma.nineth.repo.GiftOrderRepo;
|
|
|
-import com.izouma.nineth.repo.UserRepo;
|
|
|
+import com.izouma.nineth.repo.*;
|
|
|
import com.izouma.nineth.utils.SnowflakeIdWorker;
|
|
|
import lombok.AllArgsConstructor;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
@@ -70,6 +68,7 @@ public class GiftOrderService {
|
|
|
private AdapayProperties adapayProperties;
|
|
|
private GeneralProperties generalProperties;
|
|
|
private SnowflakeIdWorker snowflakeIdWorker;
|
|
|
+ private ErrorOrderRepo errorOrderRepo;
|
|
|
|
|
|
@Transactional
|
|
|
public GiftOrder gift(Long userId, Long assetId, Long toUserId) {
|
|
|
@@ -118,16 +117,29 @@ public class GiftOrderService {
|
|
|
@Transactional
|
|
|
public void giftNotify(Long orderId, PayMethod payMethod, String transactionId) {
|
|
|
GiftOrder giftOrder = giftOrderRepo.findById(orderId).orElseThrow(new BusinessException("订单不存在"));
|
|
|
- Asset asset = assetRepo.findById(giftOrder.getAssetId()).orElseThrow(new BusinessException("资产不存在"));
|
|
|
- User newOwner = userRepo.findById(giftOrder.getToUserId()).orElseThrow(new BusinessException("用户不存在"));
|
|
|
+ log.error("转赠回调 orderId={} transactionId={}", orderId, transactionId);
|
|
|
|
|
|
- giftOrder.setPayMethod(payMethod);
|
|
|
- giftOrder.setStatus(OrderStatus.FINISH);
|
|
|
- giftOrder.setTransactionId(transactionId);
|
|
|
- giftOrder.setPayTime(LocalDateTime.now());
|
|
|
- giftOrder.setPayMethod(PayMethod.ALIPAY);
|
|
|
+ if (giftOrder.getStatus() == OrderStatus.NOT_PAID) {
|
|
|
+ Asset asset = assetRepo.findById(giftOrder.getAssetId()).orElseThrow(new BusinessException("资产不存在"));
|
|
|
+ User newOwner = userRepo.findById(giftOrder.getToUserId()).orElseThrow(new BusinessException("用户不存在"));
|
|
|
+
|
|
|
+ giftOrder.setPayMethod(payMethod);
|
|
|
+ giftOrder.setStatus(OrderStatus.FINISH);
|
|
|
+ giftOrder.setTransactionId(transactionId);
|
|
|
+ giftOrder.setPayTime(LocalDateTime.now());
|
|
|
+ giftOrder.setPayMethod(PayMethod.ALIPAY);
|
|
|
+
|
|
|
+ assetService.transfer(asset, asset.getPrice(), newOwner, "转赠", null);
|
|
|
+ } else {
|
|
|
+ log.error("转赠回调出错 状态错误 orderid={} transactionid={} status={}", orderId, transactionId, giftOrder.getStatus());
|
|
|
+ errorOrderRepo.save(ErrorOrder.builder()
|
|
|
+ .orderId(orderId)
|
|
|
+ .transactionId(transactionId)
|
|
|
+ .payMethod(payMethod)
|
|
|
+ .type("gift")
|
|
|
+ .build());
|
|
|
+ }
|
|
|
|
|
|
- assetService.transfer(asset, asset.getPrice(), newOwner, "转赠", null);
|
|
|
}
|
|
|
|
|
|
public void payOrderAlipay(Long id, Model model) {
|