Browse Source

Merge branch 'dev' into 2D展厅

licailing 4 years ago
parent
commit
3af0fe6415

+ 4 - 0
src/main/java/com/izouma/nineth/repo/ErrorOrder.java

@@ -7,6 +7,7 @@ import lombok.Builder;
 import lombok.Data;
 import lombok.NoArgsConstructor;
 
+import javax.persistence.Column;
 import javax.persistence.Entity;
 
 @Data
@@ -22,4 +23,7 @@ public class ErrorOrder extends BaseEntity {
     private String transactionId;
 
     private PayMethod payMethod;
+
+    @Column(columnDefinition = "varchar(255) default 'collection'")
+    private String type;
 }

+ 3 - 2
src/main/java/com/izouma/nineth/service/AirDropService.java

@@ -13,7 +13,6 @@ import org.springframework.beans.BeanUtils;
 import org.springframework.data.domain.Page;
 import org.springframework.stereotype.Service;
 
-import javax.transaction.Transactional;
 import java.util.List;
 
 @Service
@@ -33,7 +32,6 @@ public class AirDropService {
         return airDropRepo.findAll(JpaUtils.toSpecification(pageQuery, AirDrop.class), JpaUtils.toPageRequest(pageQuery));
     }
 
-    @Transactional
     public AirDrop create(AirDrop record) {
         if (AirDropType.coupon == record.getType()) {
             Coupon coupon = couponRepo.findById(record.getCouponId()).orElseThrow(new BusinessException("兑换券不存在"));
@@ -48,6 +46,9 @@ public class AirDropService {
         } else {
             Collection collection = collectionRepo.findById(record.getCollectionId())
                     .orElseThrow(new BusinessException("藏品不存在"));
+            if (collection.isSalable()) {
+                throw new BusinessException("请先设置藏品为不可购买");
+            }
             if (collection.getStock() < record.getUserIds().size()) {
                 throw new BusinessException("藏品库存不足");
             }

+ 23 - 11
src/main/java/com/izouma/nineth/service/GiftOrderService.java

@@ -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) {