소스 검색

提现限制

wangqifan 4 년 전
부모
커밋
d7f516efd1

+ 3 - 0
src/main/java/com/izouma/tcg/repo/customizeStore/WithdrawApplyRepo.java

@@ -8,6 +8,7 @@ import org.springframework.data.jpa.repository.Modifying;
 import org.springframework.data.jpa.repository.Query;
 import org.springframework.data.jpa.repository.Query;
 
 
 import javax.transaction.Transactional;
 import javax.transaction.Transactional;
+import java.time.LocalDateTime;
 import java.util.List;
 import java.util.List;
 
 
 public interface WithdrawApplyRepo extends JpaRepository<WithdrawApply, Long>, JpaSpecificationExecutor<WithdrawApply> {
 public interface WithdrawApplyRepo extends JpaRepository<WithdrawApply, Long>, JpaSpecificationExecutor<WithdrawApply> {
@@ -17,4 +18,6 @@ public interface WithdrawApplyRepo extends JpaRepository<WithdrawApply, Long>, J
     void softDelete(Long id);
     void softDelete(Long id);
 
 
     List<WithdrawApply> findAllByUserIdAndStatus(Long userId, WithdrawStatus status);
     List<WithdrawApply> findAllByUserIdAndStatus(Long userId, WithdrawStatus status);
+
+    List<WithdrawApply> findAllByUserIdAndStatusAndPassTimeBetween(Long userId, WithdrawStatus status, LocalDateTime start, LocalDateTime end);
 }
 }

+ 10 - 0
src/main/java/com/izouma/tcg/service/customizeStore/WithdrawApplyService.java

@@ -27,7 +27,9 @@ import org.springframework.data.domain.Page;
 import org.springframework.stereotype.Service;
 import org.springframework.stereotype.Service;
 
 
 import java.math.BigDecimal;
 import java.math.BigDecimal;
+import java.time.LocalDate;
 import java.time.LocalDateTime;
 import java.time.LocalDateTime;
+import java.time.LocalTime;
 import java.util.List;
 import java.util.List;
 
 
 @Service
 @Service
@@ -48,6 +50,14 @@ public class WithdrawApplyService {
     }
     }
 
 
     public WithdrawApply withdraw(Long userId, BigDecimal money) {
     public WithdrawApply withdraw(Long userId, BigDecimal money) {
+        BigDecimal todayWithdraw = withdrawApplyRepo
+                .findAllByUserIdAndStatusAndPassTimeBetween(userId, WithdrawStatus.PASS, LocalDate
+                        .now().atStartOfDay(), LocalDate.now().atTime(LocalTime.MAX)).stream()
+                .map(WithdrawApply::getMoney).reduce(BigDecimal::add).orElse(BigDecimal.ZERO);
+        BigDecimal total = todayWithdraw.add(money);
+        if (total.compareTo(BigDecimal.valueOf(200)) > 0) {
+            throw new BusinessException("今日提现超过200元,已达今日上限.");
+        }
         Store store = storeRepo.findFirstByUserId(userId);
         Store store = storeRepo.findFirstByUserId(userId);
         MemberInfo memberInfo = memberInfoRepo.findAllByUserId(userId);
         MemberInfo memberInfo = memberInfoRepo.findAllByUserId(userId);
         BigDecimal rest = memberInfo.getMoney().subtract(money);
         BigDecimal rest = memberInfo.getMoney().subtract(money);