|
|
@@ -2,17 +2,22 @@ package com.kym.service.impl;
|
|
|
|
|
|
import cn.dev33.satoken.stp.StpUtil;
|
|
|
import com.github.pagehelper.PageHelper;
|
|
|
+import com.kym.common.exception.BusinessException;
|
|
|
import com.kym.common.utils.CommUtil;
|
|
|
import com.kym.entity.StationAccount;
|
|
|
+import com.kym.entity.WithdrawnRecord;
|
|
|
import com.kym.entity.common.PageBean;
|
|
|
import com.kym.entity.queryParams.StationQueryParam;
|
|
|
+import com.kym.entity.queryParams.WithdrawnQueryParam;
|
|
|
import com.kym.entity.vo.StationAccountVo;
|
|
|
import com.kym.mapper.StationAccountMapper;
|
|
|
import com.kym.service.StationAccountService;
|
|
|
+import com.kym.service.WithdrawnRecordService;
|
|
|
import com.kym.service.cache.KymCache;
|
|
|
import com.kym.service.mybatisplus.MyBaseServiceImpl;
|
|
|
import org.springframework.beans.BeanUtils;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
+import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
/**
|
|
|
* <p>
|
|
|
@@ -25,6 +30,12 @@ import org.springframework.stereotype.Service;
|
|
|
@Service
|
|
|
public class StationAccountServiceImpl extends MyBaseServiceImpl<StationAccountMapper, StationAccount> implements StationAccountService {
|
|
|
|
|
|
+ private final WithdrawnRecordService withdrawnRecordService;
|
|
|
+
|
|
|
+ public StationAccountServiceImpl(WithdrawnRecordService withdrawnRecordService) {
|
|
|
+ this.withdrawnRecordService = withdrawnRecordService;
|
|
|
+ }
|
|
|
+
|
|
|
@Override
|
|
|
public StationAccount getStationAccount(String stationId) {
|
|
|
return lambdaQuery().eq(StationAccount::getStationId, stationId).one();
|
|
|
@@ -57,4 +68,29 @@ public class StationAccountServiceImpl extends MyBaseServiceImpl<StationAccountM
|
|
|
}).toList();
|
|
|
return new PageBean<>(voList);
|
|
|
}
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 提现申请
|
|
|
+ *
|
|
|
+ * @param params
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ @Transactional
|
|
|
+ public void applyWithdrawn(WithdrawnQueryParam params) {
|
|
|
+ // 校验可提现金额
|
|
|
+ var stationAccount = getStationAccount(params.getStationId());
|
|
|
+ if (stationAccount.getFrozenAmount() < params.getAmount()) {
|
|
|
+ throw new BusinessException("提现金额超出可提现金额!");
|
|
|
+ }
|
|
|
+ // 冻结提现金额
|
|
|
+ lambdaUpdate().setSql("balance = balance - {0}, withdrawn_frozen_amount = withdrawn_frozen_amount + {0}", params.getAmount())
|
|
|
+ .eq(StationAccount::getStationId, params.getStationId()).update();
|
|
|
+
|
|
|
+ // 提现记录
|
|
|
+ var withdrawnRecord = new WithdrawnRecord()
|
|
|
+ .setStationId(params.getStationId())
|
|
|
+ .setWithdrawnAmount(params.getAmount());
|
|
|
+ withdrawnRecordService.save(withdrawnRecord);
|
|
|
+ }
|
|
|
}
|