|
|
@@ -16,6 +16,7 @@ import com.izouma.nineth.repo.WithdrawApplyRepo;
|
|
|
import com.izouma.nineth.utils.JpaUtils;
|
|
|
import com.izouma.nineth.utils.SnowflakeIdWorker;
|
|
|
import lombok.AllArgsConstructor;
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
import org.redisson.api.RLock;
|
|
|
import org.redisson.api.RedissonClient;
|
|
|
@@ -25,6 +26,7 @@ import org.springframework.scheduling.annotation.Async;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
import java.math.BigDecimal;
|
|
|
+import java.math.RoundingMode;
|
|
|
import java.time.LocalDate;
|
|
|
import java.time.LocalDateTime;
|
|
|
import java.time.LocalTime;
|
|
|
@@ -37,6 +39,7 @@ import java.util.regex.Pattern;
|
|
|
|
|
|
@Service
|
|
|
@AllArgsConstructor
|
|
|
+@Slf4j
|
|
|
public class WithdrawApplyService {
|
|
|
|
|
|
private WithdrawApplyRepo withdrawApplyRepo;
|
|
|
@@ -61,7 +64,7 @@ public class WithdrawApplyService {
|
|
|
}
|
|
|
int limit = sysConfigService.getInt("daily_withdraw_limit");
|
|
|
if (withdrawApplyRepo.countByUserIdAndCreatedAtBetween(userId,
|
|
|
- LocalDate.now().atStartOfDay(), LocalDate.now().atTime(LocalTime.MAX)) > limit) {
|
|
|
+ LocalDate.now().atStartOfDay(), LocalDate.now().atTime(LocalTime.MAX)) >= limit) {
|
|
|
throw new BusinessException("每天只能申请提现" + limit + "次");
|
|
|
}
|
|
|
userBalanceService.preWithdraw(userId, amount);
|
|
|
@@ -96,7 +99,8 @@ public class WithdrawApplyService {
|
|
|
String withdrawCharge = sysConfigService.getString("withdraw_charge");
|
|
|
if (StringUtils.isNotEmpty(withdrawCharge) && Pattern.matches("^(\\d+|\\d+.\\d+),\\d+$", withdrawCharge)) {
|
|
|
String[] arr = withdrawCharge.split(",");
|
|
|
- chargeAmount = new BigDecimal(arr[0]);
|
|
|
+ chargeAmount = apply.getAmount().multiply(new BigDecimal(arr[0]))
|
|
|
+ .divide(new BigDecimal("100"), 2, RoundingMode.HALF_UP);
|
|
|
BigDecimal minChargeAmount = new BigDecimal(arr[1]);
|
|
|
if (chargeAmount.compareTo(minChargeAmount) < 0) {
|
|
|
chargeAmount = minChargeAmount;
|
|
|
@@ -166,8 +170,8 @@ public class WithdrawApplyService {
|
|
|
@RedisLock(value = "'approveAll'", expire = 1, unit = TimeUnit.HOURS)
|
|
|
public void approveAll() throws ExecutionException, InterruptedException {
|
|
|
new ForkJoinPool(5).submit(() -> {
|
|
|
- withdrawApplyRepo.findByCreatedAtBetweenAndStatus(LocalDate.now().minusDays(1).atStartOfDay(),
|
|
|
- LocalDate.now().minusDays(1).atTime(LocalTime.MAX), WithdrawStatus.PENDING)
|
|
|
+ withdrawApplyRepo.findByCreatedAtBeforeAndStatus(LocalDate.now().atStartOfDay(),
|
|
|
+ WithdrawStatus.PENDING)
|
|
|
.parallelStream().forEach(withdrawApply -> {
|
|
|
try {
|
|
|
finishWithdrawApply(withdrawApply.getId(), true, null);
|
|
|
@@ -176,4 +180,23 @@ public class WithdrawApplyService {
|
|
|
});
|
|
|
}).get();
|
|
|
}
|
|
|
+
|
|
|
+ @Async
|
|
|
+ public void fixCharge() throws ExecutionException, InterruptedException {
|
|
|
+ new ForkJoinPool(5).submit(() -> {
|
|
|
+ withdrawApplyRepo.findByStatusAndAmountLessThanEqual(WithdrawStatus.SUCCESS, new BigDecimal("1000"))
|
|
|
+ .parallelStream().forEach(apply -> {
|
|
|
+ try {
|
|
|
+ UserBankCard bankCard = userBankCardRepo.findByUserId(apply.getUserId())
|
|
|
+ .stream().findFirst()
|
|
|
+ .orElseThrow(new BusinessException("未绑卡"));
|
|
|
+ JSONObject res = sandPayService.transfer(snowflakeIdWorker.nextId() + "", bankCard.getRealName(),
|
|
|
+ bankCard.getBankNo(), new BigDecimal("6"));
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error("fixCharge", e);
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }).get();
|
|
|
+
|
|
|
+ }
|
|
|
}
|