|
@@ -3,19 +3,13 @@ package com.etotem.cfc.service;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
import com.etotem.cfc.common.Result;
|
|
import com.etotem.cfc.common.Result;
|
|
|
-import com.etotem.cfc.entity.CommissionRecord;
|
|
|
|
|
import com.etotem.cfc.entity.WithdrawalRequest;
|
|
import com.etotem.cfc.entity.WithdrawalRequest;
|
|
|
-import com.etotem.cfc.mapper.CommissionRecordMapper;
|
|
|
|
|
import com.etotem.cfc.mapper.WithdrawalRequestMapper;
|
|
import com.etotem.cfc.mapper.WithdrawalRequestMapper;
|
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
|
|
-import lombok.extern.slf4j.Slf4j;
|
|
|
|
|
-
|
|
|
|
|
import javax.annotation.Resource;
|
|
import javax.annotation.Resource;
|
|
|
import java.util.Date;
|
|
import java.util.Date;
|
|
|
-import java.util.List;
|
|
|
|
|
|
|
|
|
|
-@Slf4j
|
|
|
|
|
@Service
|
|
@Service
|
|
|
public class WithdrawalService {
|
|
public class WithdrawalService {
|
|
|
|
|
|
|
@@ -25,13 +19,7 @@ public class WithdrawalService {
|
|
|
private WithdrawalRequestMapper withdrawalRequestMapper;
|
|
private WithdrawalRequestMapper withdrawalRequestMapper;
|
|
|
|
|
|
|
|
@Resource
|
|
@Resource
|
|
|
- private CommissionService commissionService;
|
|
|
|
|
-
|
|
|
|
|
- @Resource
|
|
|
|
|
- private PendingRefundService pendingRefundService;
|
|
|
|
|
-
|
|
|
|
|
- @Resource
|
|
|
|
|
- private CommissionRecordMapper commissionRecordMapper;
|
|
|
|
|
|
|
+ private PlatformPointsService platformPointsService;
|
|
|
|
|
|
|
|
public Result<String> apply(Long userId, Integer amount, String accountInfo) {
|
|
public Result<String> apply(Long userId, Integer amount, String accountInfo) {
|
|
|
if (amount == null || amount <= 0) {
|
|
if (amount == null || amount <= 0) {
|
|
@@ -43,17 +31,27 @@ public class WithdrawalService {
|
|
|
if (accountInfo == null || accountInfo.trim().isEmpty()) {
|
|
if (accountInfo == null || accountInfo.trim().isEmpty()) {
|
|
|
return Result.error("请填写账户信息");
|
|
return Result.error("请填写账户信息");
|
|
|
}
|
|
}
|
|
|
- Integer available = commissionService.getAvailableAmount(userId);
|
|
|
|
|
|
|
+ Integer available = platformPointsService.getWithdrawable(userId);
|
|
|
if (available < amount) {
|
|
if (available < amount) {
|
|
|
- return Result.error("可提现余额不足,当前可提现 ¥" + String.format("%.2f", available / 100.0));
|
|
|
|
|
|
|
+ return Result.error("可提现CF值不足,当前可提现 ¥" + String.format("%.2f", available / 100.0));
|
|
|
}
|
|
}
|
|
|
WithdrawalRequest request = new WithdrawalRequest();
|
|
WithdrawalRequest request = new WithdrawalRequest();
|
|
|
request.setUserId(userId);
|
|
request.setUserId(userId);
|
|
|
request.setAmount(amount);
|
|
request.setAmount(amount);
|
|
|
request.setAccountInfo(accountInfo);
|
|
request.setAccountInfo(accountInfo);
|
|
|
request.setStatus("pending");
|
|
request.setStatus("pending");
|
|
|
|
|
+ request.setType("platform_points");
|
|
|
request.setCreatedAt(new Date());
|
|
request.setCreatedAt(new Date());
|
|
|
withdrawalRequestMapper.insert(request);
|
|
withdrawalRequestMapper.insert(request);
|
|
|
|
|
+ // 冻结 CF 值(以提现申请 ID 作为流水关联)
|
|
|
|
|
+ try {
|
|
|
|
|
+ platformPointsService.freeze(userId, amount, request.getId());
|
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
|
+ request.setStatus("rejected");
|
|
|
|
|
+ request.setRemark("CF值冻结失败");
|
|
|
|
|
+ withdrawalRequestMapper.updateById(request);
|
|
|
|
|
+ return Result.error("提现申请失败:" + e.getMessage());
|
|
|
|
|
+ }
|
|
|
return Result.success("提现申请已提交,等待审核");
|
|
return Result.success("提现申请已提交,等待审核");
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -67,60 +65,21 @@ public class WithdrawalService {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
if ("approved".equals(status)) {
|
|
if ("approved".equals(status)) {
|
|
|
- Integer available = commissionService.getAvailableAmount(request.getUserId());
|
|
|
|
|
- if (available < request.getAmount()) {
|
|
|
|
|
- pendingRefundService.createPendingRefund(
|
|
|
|
|
- request.getUserId(),
|
|
|
|
|
- request.getId(),
|
|
|
|
|
- request.getAmount()
|
|
|
|
|
- );
|
|
|
|
|
- log.info("提现审核通过但余额不足,已加入待退款队列:userId={}, amount={}",
|
|
|
|
|
- request.getUserId(), request.getAmount());
|
|
|
|
|
- } else {
|
|
|
|
|
- processWithdrawal(request);
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ platformPointsService.confirmWithdraw(request.getUserId(), request.getAmount(), requestId);
|
|
|
|
|
+ request.setStatus("processed");
|
|
|
|
|
+ request.setRemark("提现成功");
|
|
|
|
|
+ } else if ("rejected".equals(status)) {
|
|
|
|
|
+ platformPointsService.unfreeze(request.getUserId(), request.getAmount(), requestId);
|
|
|
|
|
+ request.setStatus("rejected");
|
|
|
|
|
+ request.setRemark("提现审核拒绝");
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- request.setStatus(status);
|
|
|
|
|
request.setAuditBy(adminId);
|
|
request.setAuditBy(adminId);
|
|
|
request.setAuditAt(new Date());
|
|
request.setAuditAt(new Date());
|
|
|
- request.setRemark(remark != null ? remark : "");
|
|
|
|
|
- withdrawalRequestMapper.updateById(request);
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- private void processWithdrawal(WithdrawalRequest request) {
|
|
|
|
|
- Long userId = request.getUserId();
|
|
|
|
|
- Integer amount = request.getAmount();
|
|
|
|
|
-
|
|
|
|
|
- List<CommissionRecord> settledRecords = commissionRecordMapper.selectList(
|
|
|
|
|
- new LambdaQueryWrapper<CommissionRecord>()
|
|
|
|
|
- .eq(CommissionRecord::getReferrerId, userId)
|
|
|
|
|
- .eq(CommissionRecord::getStatus, "settled")
|
|
|
|
|
- );
|
|
|
|
|
-
|
|
|
|
|
- int remainingAmount = amount;
|
|
|
|
|
- for (CommissionRecord record : settledRecords) {
|
|
|
|
|
- if (remainingAmount <= 0) {
|
|
|
|
|
- break;
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- int recordAmount = record.getCommissionAmount() != null ? record.getCommissionAmount() : 0;
|
|
|
|
|
- int withdrawAmount = Math.min(recordAmount, remainingAmount);
|
|
|
|
|
-
|
|
|
|
|
- record.setStatus("withdrawn");
|
|
|
|
|
- record.setWithdrawnAt(new Date());
|
|
|
|
|
- commissionRecordMapper.updateById(record);
|
|
|
|
|
-
|
|
|
|
|
- remainingAmount -= withdrawAmount;
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- request.setStatus("processed");
|
|
|
|
|
- if (remainingAmount > 0) {
|
|
|
|
|
- pendingRefundService.createPendingRefund(userId, request.getId(), remainingAmount);
|
|
|
|
|
- request.setRemark("部分提现成功,剩余 " + remainingAmount + " 分已加入待退款队列");
|
|
|
|
|
- } else {
|
|
|
|
|
- request.setRemark("提现成功");
|
|
|
|
|
|
|
+ if (remark != null && !remark.isEmpty()) {
|
|
|
|
|
+ request.setRemark(remark);
|
|
|
}
|
|
}
|
|
|
|
|
+ withdrawalRequestMapper.updateById(request);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
public Page<WithdrawalRequest> getHistory(Long userId, int page, int size) {
|
|
public Page<WithdrawalRequest> getHistory(Long userId, int page, int size) {
|
|
@@ -140,4 +99,4 @@ public class WithdrawalService {
|
|
|
}
|
|
}
|
|
|
return withdrawalRequestMapper.selectPage(pageParam, wrapper);
|
|
return withdrawalRequestMapper.selectPage(pageParam, wrapper);
|
|
|
}
|
|
}
|
|
|
-}
|
|
|
|
|
|
|
+}
|