|
|
@@ -0,0 +1,116 @@
|
|
|
+package io.renren.modules.qyh.service.impl;
|
|
|
+
|
|
|
+import cn.hutool.core.lang.Snowflake;
|
|
|
+import cn.hutool.core.map.MapUtil;
|
|
|
+import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
|
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
+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.PageUtils;
|
|
|
+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.WithdrawInfoVO;
|
|
|
+import io.renren.modules.qyh.service.MemberWalletService;
|
|
|
+import io.renren.modules.qyh.service.WithdrawConfigService;
|
|
|
+import io.renren.modules.qyh.service.WithdrawInfoService;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
+import org.springframework.transaction.annotation.Transactional;
|
|
|
+
|
|
|
+import java.math.BigDecimal;
|
|
|
+import java.time.LocalDateTime;
|
|
|
+import java.util.Map;
|
|
|
+
|
|
|
+/**
|
|
|
+ * 提现记录表
|
|
|
+ *
|
|
|
+ * @author qingyunhui
|
|
|
+ * @date 2026-04-24
|
|
|
+ */
|
|
|
+@Service("withdrawInfoService")
|
|
|
+public class WithdrawInfoServiceImpl extends ServiceImpl<WithdrawInfoMapper, WithdrawInfoEntity>
|
|
|
+ implements WithdrawInfoService {
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private MemberWalletService memberWalletService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private WithdrawConfigService withdrawConfigService;
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public PageUtils queryPage(Map<String, Object> params) {
|
|
|
+ Integer page = MapUtil.getInt(params, Constant.PAGE);
|
|
|
+ Integer limit = MapUtil.getInt(params, Constant.LIMIT);
|
|
|
+ IPage<WithdrawInfoEntity> iPage = new Page<>(page, limit);
|
|
|
+ IPage<WithdrawInfoVO> resultPage = baseMapper.queryPage(iPage, params);
|
|
|
+ return new PageUtils(resultPage);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
+ public void apply(WithdrawInfoEntity dto) {
|
|
|
+ // 1. 获取配置
|
|
|
+ WithdrawConfigEntity config = withdrawConfigService.getOne();
|
|
|
+ // 2. 校验金额
|
|
|
+ BigDecimal money = dto.getMoney();
|
|
|
+ Long memberId = dto.getMemberId();
|
|
|
+ if (money.compareTo(config.getMinWithdrawAmount()) < 0) {
|
|
|
+ throw new RRException("提现金额不能低于" + config.getMinWithdrawAmount() + "元");
|
|
|
+ }
|
|
|
+ if (money.compareTo(config.getMaxWithdrawAmount()) > 0) {
|
|
|
+ throw new RRException("提现金额不能高于" + config.getMaxWithdrawAmount() + "元");
|
|
|
+ }
|
|
|
+ // 3. 获取钱包并校验余额
|
|
|
+ MemberWalletEntity wallet = memberWalletService.getOrCreateWallet(memberId);
|
|
|
+ if (wallet.getBalance().compareTo(money) < 0) {
|
|
|
+ throw new RRException("钱包余额不足");
|
|
|
+ }
|
|
|
+ // 4. 冻结钱包余额
|
|
|
+ memberWalletService.freezeBalance(memberId, money);
|
|
|
+ // 5. 生成提现记录
|
|
|
+ WithdrawInfoEntity entity = new WithdrawInfoEntity();
|
|
|
+ entity.setMemberId(memberId);
|
|
|
+ entity.setWithdrawType(WithdrawTypeEnum.MEMBER_COMMISSION_WITHDRAW.value());
|
|
|
+ entity.setMoney(money);
|
|
|
+ entity.setPaymentTerm(dto.getPaymentTerm());
|
|
|
+ entity.setBusinessCode("WD" + new Snowflake().nextIdStr());
|
|
|
+ entity.setApplyTime(LocalDateTime.now());
|
|
|
+ entity.setAuditState(WithdrawAuditStateEnum.WAIT_AUDIT.value());
|
|
|
+ entity.setPayee(dto.getPayee());
|
|
|
+ baseMapper.insert(entity);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
+ public void audit(WithdrawInfoEntity dto) {
|
|
|
+ WithdrawInfoEntity entity = this.getById(dto.getId());
|
|
|
+ if (entity == null) {
|
|
|
+ throw new RRException("提现记录不存在");
|
|
|
+ }
|
|
|
+ if (!entity.getAuditState().equals(1)) {
|
|
|
+ throw new RRException("当前状态不可审核");
|
|
|
+ }
|
|
|
+
|
|
|
+ entity.setAuditState(dto.getAuditState());
|
|
|
+ entity.setAuditExplain(dto.getAuditExplain());
|
|
|
+ entity.setAuditPer(dto.getAuditPer());
|
|
|
+ entity.setAuditTime(LocalDateTime.now());
|
|
|
+
|
|
|
+ // 如果是拒绝,需要退回余额 (这里简单处理,具体看业务逻辑是否需要退回)
|
|
|
+ // 正常逻辑是:审核通过 -> 调用微信打款 -> 打款成功 -> 更新状态
|
|
|
+ // 或者:审核通过 -> 状态变为已打款
|
|
|
+ if (dto.getAuditState().equals(2)) {
|
|
|
+ // 假设审核通过即视为已打款(如果是手动打款流程)
|
|
|
+ // 实际对接微信企业付款需要异步回调
|
|
|
+ entity.setRemitStatus(1);
|
|
|
+ entity.setRemitTime(LocalDateTime.now());
|
|
|
+ }
|
|
|
+
|
|
|
+ baseMapper.updateById(entity);
|
|
|
+ }
|
|
|
+}
|