init
This commit is contained in:
@@ -2,6 +2,7 @@ package com.ruoyi.cai.service;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import com.ruoyi.cai.domain.CaiAccountCash;
|
||||
import com.ruoyi.cai.dto.app.query.WithdrawRes;
|
||||
|
||||
/**
|
||||
* 用户提现记录Service接口
|
||||
@@ -11,4 +12,5 @@ import com.ruoyi.cai.domain.CaiAccountCash;
|
||||
*/
|
||||
public interface CaiAccountCashService extends IService<CaiAccountCash> {
|
||||
|
||||
void withdraw(WithdrawRes res);
|
||||
}
|
||||
|
||||
@@ -16,4 +16,6 @@ public interface CaiAccountService extends IService<CaiAccount> {
|
||||
boolean incs(Long userId, Long value);
|
||||
|
||||
boolean decr(Long userId, Long value);
|
||||
|
||||
boolean withdraw(Long userId, Long incomeCoin);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,14 @@
|
||||
package com.ruoyi.cai.service;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import com.ruoyi.cai.domain.CaiGoods;
|
||||
|
||||
/**
|
||||
* 充值配置Service接口
|
||||
*
|
||||
* @author 77
|
||||
* @date 2023-12-24
|
||||
*/
|
||||
public interface CaiGoodsService extends IService<CaiGoods> {
|
||||
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
package com.ruoyi.cai.service;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import com.ruoyi.cai.domain.CaiWithdrawExchange;
|
||||
|
||||
/**
|
||||
* 提现 - 兑换配置Service接口
|
||||
*
|
||||
* @author 77
|
||||
* @date 2023-12-24
|
||||
*/
|
||||
public interface CaiWithdrawExchangeService extends IService<CaiWithdrawExchange> {
|
||||
|
||||
}
|
||||
@@ -1,11 +1,47 @@
|
||||
package com.ruoyi.cai.service.impl;
|
||||
|
||||
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.ruoyi.cai.domain.CaiAccountBankcard;
|
||||
import com.ruoyi.cai.domain.CaiAccountCash;
|
||||
import com.ruoyi.cai.dto.app.query.WithdrawRes;
|
||||
import com.ruoyi.cai.mapper.CaiAccountCashMapper;
|
||||
import com.ruoyi.cai.service.CaiAccountBankcardService;
|
||||
import com.ruoyi.cai.service.CaiAccountCashService;
|
||||
import com.ruoyi.cai.service.CaiAccountService;
|
||||
import com.ruoyi.common.exception.ServiceException;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
|
||||
@Service
|
||||
public class CaiAccountCashServiceImpl extends ServiceImpl<CaiAccountCashMapper, CaiAccountCash> implements CaiAccountCashService {
|
||||
@Autowired
|
||||
private CaiAccountBankcardService accountBankcardService;
|
||||
@Autowired
|
||||
private CaiAccountService accountService;
|
||||
@Override
|
||||
public void withdraw(WithdrawRes res) {
|
||||
CaiAccountBankcard one = accountBankcardService.getOne(Wrappers.lambdaQuery(CaiAccountBankcard.class)
|
||||
.eq(CaiAccountBankcard::getUserId, res.getUserId()).last("limit 1"));
|
||||
if(one == null){
|
||||
throw new ServiceException("请先配置支付宝提现账号");
|
||||
}
|
||||
Long coinNum = res.getCoinNum();
|
||||
boolean withdraw = accountService.withdraw(res.getUserId(), coinNum);
|
||||
if(!withdraw){
|
||||
throw new ServiceException("余额不足");
|
||||
}
|
||||
CaiAccountCash cash = new CaiAccountCash();
|
||||
cash.setUserId(res.getUserId());
|
||||
cash.setOrderNo("orderNo");
|
||||
cash.setCashMoney(BigDecimal.valueOf(res.getMoney()));
|
||||
cash.setRealCashMoney(BigDecimal.valueOf(res.getMoney()));
|
||||
cash.setCashFees(BigDecimal.ZERO);
|
||||
cash.setBank(one.getBank());
|
||||
cash.setCardName(one.getCardName());
|
||||
cash.setCardAccount(one.getCardAccount());
|
||||
this.save(cash);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -26,7 +26,7 @@ public class CaiAccountServiceImpl extends ServiceImpl<CaiAccountMapper,CaiAccou
|
||||
|
||||
@Override
|
||||
public boolean incs(Long userId, Long value) {
|
||||
return baseMapper.incs(userId,value);
|
||||
return baseMapper.incs(userId,value) > 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -36,8 +36,8 @@ public class CaiAccountServiceImpl extends ServiceImpl<CaiAccountMapper,CaiAccou
|
||||
if(account.getTotalCoin() < value){
|
||||
throw new ServiceException("余额不足");
|
||||
}
|
||||
boolean incs = baseMapper.incs(userId, -value);
|
||||
if(!incs){
|
||||
long incs = baseMapper.incs(userId, -value);
|
||||
if(incs <= 0){
|
||||
return false;
|
||||
}
|
||||
CaiAccount newAccount = this.getByUserId(userId);
|
||||
@@ -47,6 +47,20 @@ public class CaiAccountServiceImpl extends ServiceImpl<CaiAccountMapper,CaiAccou
|
||||
}else{
|
||||
baseMapper.incsCoin(userId, -newAccount.getCoin(), decrCoinFlag);
|
||||
}
|
||||
return incs;
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public boolean withdraw(Long userId, Long incomeCoin){
|
||||
CaiAccount account = this.getByUserId(userId);
|
||||
if(account.getIncomeCoin() < incomeCoin){
|
||||
throw new ServiceException("余额不足");
|
||||
}
|
||||
long incs = baseMapper.decrIncomeCoin(userId, incomeCoin);
|
||||
if(incs <= 0){
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,20 @@
|
||||
package com.ruoyi.cai.service.impl;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.ruoyi.cai.domain.CaiGoods;
|
||||
import com.ruoyi.cai.mapper.CaiGoodsMapper;
|
||||
import com.ruoyi.cai.service.CaiGoodsService;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
/**
|
||||
* 充值配置Service业务层处理
|
||||
*
|
||||
* @author 77
|
||||
* @date 2023-12-24
|
||||
*/
|
||||
@RequiredArgsConstructor
|
||||
@Service
|
||||
public class CaiGoodsServiceImpl extends ServiceImpl<CaiGoodsMapper,CaiGoods> implements CaiGoodsService {
|
||||
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
package com.ruoyi.cai.service.impl;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.ruoyi.cai.domain.CaiWithdrawExchange;
|
||||
import com.ruoyi.cai.mapper.CaiWithdrawExchangeMapper;
|
||||
import com.ruoyi.cai.service.CaiWithdrawExchangeService;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
/**
|
||||
* 提现 - 兑换配置Service业务层处理
|
||||
*
|
||||
* @author 77
|
||||
* @date 2023-12-24
|
||||
*/
|
||||
@Service
|
||||
public class CaiWithdrawExchangeServiceImpl extends ServiceImpl<CaiWithdrawExchangeMapper,CaiWithdrawExchange> implements CaiWithdrawExchangeService {
|
||||
}
|
||||
Reference in New Issue
Block a user