|
|
@@ -2,6 +2,7 @@ package io.renren.modules.qyh.service.impl;
|
|
|
|
|
|
import cn.hutool.core.lang.Snowflake;
|
|
|
import cn.hutool.core.map.MapUtil;
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
@@ -9,11 +10,16 @@ import io.renren.common.enums.WithdrawAuditStateEnum;
|
|
|
import io.renren.common.enums.WithdrawTypeEnum;
|
|
|
import io.renren.common.exception.RRException;
|
|
|
import io.renren.common.utils.Constant;
|
|
|
+import io.renren.common.utils.LocalDateTimeUtils;
|
|
|
import io.renren.common.utils.PageUtils;
|
|
|
+import io.renren.modules.qmgj.entity.MemberInfoEntity;
|
|
|
+import io.renren.modules.qmgj.service.MemberInfoService;
|
|
|
+import io.renren.modules.qmjz.utils.BeanCopyUtils;
|
|
|
import io.renren.modules.qyh.entity.MemberWalletEntity;
|
|
|
import io.renren.modules.qyh.entity.WithdrawConfigEntity;
|
|
|
import io.renren.modules.qyh.entity.WithdrawInfoEntity;
|
|
|
import io.renren.modules.qyh.mapper.WithdrawInfoMapper;
|
|
|
+import io.renren.modules.qyh.model.vo.MyWalletVO;
|
|
|
import io.renren.modules.qyh.model.vo.WithdrawInfoVO;
|
|
|
import io.renren.modules.qyh.service.MemberWalletService;
|
|
|
import io.renren.modules.qyh.service.WithdrawConfigService;
|
|
|
@@ -24,6 +30,7 @@ import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
import java.math.BigDecimal;
|
|
|
import java.time.LocalDateTime;
|
|
|
+import java.util.List;
|
|
|
import java.util.Map;
|
|
|
|
|
|
/**
|
|
|
@@ -42,6 +49,9 @@ public class WithdrawInfoServiceImpl extends ServiceImpl<WithdrawInfoMapper, Wit
|
|
|
@Autowired
|
|
|
private WithdrawConfigService withdrawConfigService;
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private MemberInfoService memberInfoService;
|
|
|
+
|
|
|
@Override
|
|
|
public PageUtils queryPage(Map<String, Object> params) {
|
|
|
Integer page = MapUtil.getInt(params, Constant.PAGE);
|
|
|
@@ -65,6 +75,23 @@ public class WithdrawInfoServiceImpl extends ServiceImpl<WithdrawInfoMapper, Wit
|
|
|
if (money.compareTo(config.getMaxWithdrawAmount()) > 0) {
|
|
|
throw new RRException("提现金额不能高于" + config.getMaxWithdrawAmount() + "元");
|
|
|
}
|
|
|
+ //单日限额
|
|
|
+ LocalDateTime now = LocalDateTime.now();
|
|
|
+ List<WithdrawInfoEntity> todayWithdraws = baseMapper.selectList(
|
|
|
+ new LambdaQueryWrapper<WithdrawInfoEntity>()
|
|
|
+ .eq(WithdrawInfoEntity::getMemberId, memberId)
|
|
|
+ .ge(WithdrawInfoEntity::getApplyTime, LocalDateTimeUtils.getDayStart(now))
|
|
|
+ .le(WithdrawInfoEntity::getApplyTime, LocalDateTimeUtils.getDayEnd(now)));
|
|
|
+ BigDecimal todayTotalAmount = todayWithdraws.stream()
|
|
|
+ .map(WithdrawInfoEntity::getMoney)
|
|
|
+ .reduce(BigDecimal.ZERO, BigDecimal::add);
|
|
|
+ if (todayTotalAmount.add(money).compareTo(config.getDailyMaxAmount()) > 0) {
|
|
|
+ throw new RRException("今日提现金额已达上限(单日限额" + config.getDailyMaxAmount() + "元)");
|
|
|
+ }
|
|
|
+ // 校验每日最多提现次数
|
|
|
+ if (todayWithdraws.size() >= config.getDailyMaxCount()) {
|
|
|
+ throw new RRException("今日提现次数已达上限(每日最多" + config.getDailyMaxCount() + "次)");
|
|
|
+ }
|
|
|
// 3. 获取钱包并校验余额
|
|
|
MemberWalletEntity wallet = memberWalletService.getOrCreateWallet(memberId);
|
|
|
if (wallet.getBalance().compareTo(money) < 0) {
|
|
|
@@ -92,25 +119,46 @@ public class WithdrawInfoServiceImpl extends ServiceImpl<WithdrawInfoMapper, Wit
|
|
|
if (entity == null) {
|
|
|
throw new RRException("提现记录不存在");
|
|
|
}
|
|
|
- if (!entity.getAuditState().equals(1)) {
|
|
|
+ if (!entity.getAuditState().equals(WithdrawAuditStateEnum.WAIT_AUDIT.value())) {
|
|
|
throw new RRException("当前状态不可审核");
|
|
|
}
|
|
|
-
|
|
|
- entity.setAuditState(dto.getAuditState());
|
|
|
+ Integer auditState = dto.getAuditState();
|
|
|
+ entity.setAuditState(auditState);
|
|
|
entity.setAuditExplain(dto.getAuditExplain());
|
|
|
entity.setAuditPer(dto.getAuditPer());
|
|
|
entity.setAuditTime(LocalDateTime.now());
|
|
|
-
|
|
|
- // 如果是拒绝,需要退回余额 (这里简单处理,具体看业务逻辑是否需要退回)
|
|
|
- // 正常逻辑是:审核通过 -> 调用微信打款 -> 打款成功 -> 更新状态
|
|
|
- // 或者:审核通过 -> 状态变为已打款
|
|
|
- if (dto.getAuditState().equals(2)) {
|
|
|
- // 假设审核通过即视为已打款(如果是手动打款流程)
|
|
|
- // 实际对接微信企业付款需要异步回调
|
|
|
- entity.setRemitStatus(1);
|
|
|
- entity.setRemitTime(LocalDateTime.now());
|
|
|
+ // 审核通过
|
|
|
+ if (auditState.equals(WithdrawAuditStateEnum.AUDIT_PASS.value())) {
|
|
|
+ // TODO: 这里调用微信接口进行打款
|
|
|
+ } else if (auditState.equals(WithdrawAuditStateEnum.AUDIT_REFUSE.value())) {
|
|
|
+ // 拒绝后需要解冻并退回钱包余额
|
|
|
+ memberWalletService.unfreezeAndRefund(entity.getMemberId(), entity.getMoney());
|
|
|
+ } else {
|
|
|
+ throw new RRException("审核状态不正确");
|
|
|
}
|
|
|
-
|
|
|
baseMapper.updateById(entity);
|
|
|
}
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public Map<String, BigDecimal> getWithdrawStatistics(Map<String, Object> params) {
|
|
|
+ return baseMapper.getWithdrawStatistics(params);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public WithdrawInfoVO info(Long id) {
|
|
|
+ WithdrawInfoEntity withdrawInfoEntity = baseMapper.selectById(id);
|
|
|
+ if (withdrawInfoEntity == null) {
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ WithdrawInfoVO withdrawInfoVO = new WithdrawInfoVO();
|
|
|
+ BeanCopyUtils.copyPropertiesIgnoreNull(withdrawInfoEntity, withdrawInfoVO);
|
|
|
+ // 获取会员信息
|
|
|
+ MemberInfoEntity memberInfo = memberInfoService.getById(withdrawInfoEntity.getMemberId());
|
|
|
+ withdrawInfoVO.setUserName(memberInfo.getVipname());
|
|
|
+ withdrawInfoVO.setPhone(memberInfo.getPhone());
|
|
|
+ //获取余额
|
|
|
+ MyWalletVO myWallet = memberWalletService.getMyWallet(withdrawInfoEntity.getMemberId());
|
|
|
+ withdrawInfoVO.setAvailableAmount(myWallet.getAvailableAmount());
|
|
|
+ return withdrawInfoVO;
|
|
|
+ }
|
|
|
}
|