mirror of
https://gitee.com/huangge1199_admin/vue-pro.git
synced 2024-11-22 23:31:52 +08:00
分销:调整 app 的 price 到 brokeragePrice
This commit is contained in:
parent
426594ae00
commit
cd51d57f12
@ -14,5 +14,6 @@ public interface PayWalletTransactionConvert {
|
|||||||
|
|
||||||
PageResult<AppPayWalletTransactionRespVO> convertPage(PageResult<PayWalletTransactionDO> page);
|
PageResult<AppPayWalletTransactionRespVO> convertPage(PageResult<PayWalletTransactionDO> page);
|
||||||
|
|
||||||
PayWalletTransactionDO convert(CreateWalletTransactionBO bo);
|
PayWalletTransactionDO convert(CreateWalletTransactionBO bean);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -22,7 +22,8 @@ public interface PayWalletMapper extends BaseMapperX<PayWalletDO> {
|
|||||||
*/
|
*/
|
||||||
default int updateWhenConsumptionRefund(Integer price, Long id){
|
default int updateWhenConsumptionRefund(Integer price, Long id){
|
||||||
LambdaUpdateWrapper<PayWalletDO> lambdaUpdateWrapper = new LambdaUpdateWrapper<PayWalletDO>()
|
LambdaUpdateWrapper<PayWalletDO> lambdaUpdateWrapper = new LambdaUpdateWrapper<PayWalletDO>()
|
||||||
.setSql(" balance = balance + " + price + ", total_expense = total_expense - " + price)
|
.setSql(" balance = balance + " + price
|
||||||
|
+ ", total_expense = total_expense - " + price)
|
||||||
.eq(PayWalletDO::getId, id);
|
.eq(PayWalletDO::getId, id);
|
||||||
return update(null, lambdaUpdateWrapper);
|
return update(null, lambdaUpdateWrapper);
|
||||||
}
|
}
|
||||||
@ -35,7 +36,8 @@ public interface PayWalletMapper extends BaseMapperX<PayWalletDO> {
|
|||||||
*/
|
*/
|
||||||
default int updateWhenConsumption(Integer price, Long id){
|
default int updateWhenConsumption(Integer price, Long id){
|
||||||
LambdaUpdateWrapper<PayWalletDO> lambdaUpdateWrapper = new LambdaUpdateWrapper<PayWalletDO>()
|
LambdaUpdateWrapper<PayWalletDO> lambdaUpdateWrapper = new LambdaUpdateWrapper<PayWalletDO>()
|
||||||
.setSql(" balance = balance - " + price + ", total_expense = total_expense + " + price)
|
.setSql(" balance = balance - " + price
|
||||||
|
+ ", total_expense = total_expense + " + price)
|
||||||
.eq(PayWalletDO::getId, id)
|
.eq(PayWalletDO::getId, id)
|
||||||
.ge(PayWalletDO::getBalance, price); // cas 逻辑
|
.ge(PayWalletDO::getBalance, price); // cas 逻辑
|
||||||
return update(null, lambdaUpdateWrapper);
|
return update(null, lambdaUpdateWrapper);
|
||||||
|
@ -112,13 +112,14 @@ public class PayWalletServiceImpl implements PayWalletService {
|
|||||||
@Override
|
@Override
|
||||||
public PayWalletTransactionDO reduceWalletBalance(Long userId, Integer userType,
|
public PayWalletTransactionDO reduceWalletBalance(Long userId, Integer userType,
|
||||||
Long bizId, PayWalletBizTypeEnum bizType, Integer price) {
|
Long bizId, PayWalletBizTypeEnum bizType, Integer price) {
|
||||||
// 1.1 获取钱包
|
// 1. 获取钱包
|
||||||
PayWalletDO payWallet = getOrCreateWallet(userId, userType);
|
PayWalletDO payWallet = getOrCreateWallet(userId, userType);
|
||||||
|
|
||||||
// 2.1 扣除余额
|
// 2.1 扣除余额
|
||||||
int number = 0 ;
|
int updateCounts = 0 ;
|
||||||
switch (bizType) {
|
switch (bizType) {
|
||||||
case PAYMENT: {
|
case PAYMENT: {
|
||||||
number = walletMapper.updateWhenConsumption(price, payWallet.getId());
|
updateCounts = walletMapper.updateWhenConsumption(price, payWallet.getId());
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case RECHARGE_REFUND: {
|
case RECHARGE_REFUND: {
|
||||||
@ -126,11 +127,11 @@ public class PayWalletServiceImpl implements PayWalletService {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (number == 0) {
|
if (updateCounts == 0) {
|
||||||
throw exception(WALLET_BALANCE_NOT_ENOUGH);
|
throw exception(WALLET_BALANCE_NOT_ENOUGH);
|
||||||
}
|
}
|
||||||
int afterBalance = payWallet.getBalance() - price;
|
|
||||||
// 2.2 生成钱包流水
|
// 2.2 生成钱包流水
|
||||||
|
Integer afterBalance = payWallet.getBalance() - price;
|
||||||
CreateWalletTransactionBO bo = new CreateWalletTransactionBO().setWalletId(payWallet.getId())
|
CreateWalletTransactionBO bo = new CreateWalletTransactionBO().setWalletId(payWallet.getId())
|
||||||
.setPrice(-price).setBalance(afterBalance).setBizId(String.valueOf(bizId))
|
.setPrice(-price).setBalance(afterBalance).setBizId(String.valueOf(bizId))
|
||||||
.setBizType(bizType.getType()).setTitle(bizType.getDescription());
|
.setBizType(bizType.getType()).setTitle(bizType.getDescription());
|
||||||
@ -140,7 +141,7 @@ public class PayWalletServiceImpl implements PayWalletService {
|
|||||||
@Override
|
@Override
|
||||||
public PayWalletTransactionDO addWalletBalance(Long userId, Integer userType,
|
public PayWalletTransactionDO addWalletBalance(Long userId, Integer userType,
|
||||||
Long bizId, PayWalletBizTypeEnum bizType, Integer price) {
|
Long bizId, PayWalletBizTypeEnum bizType, Integer price) {
|
||||||
// 获取钱包
|
// 1. 获取钱包
|
||||||
PayWalletDO payWallet = getOrCreateWallet(userId, userType);
|
PayWalletDO payWallet = getOrCreateWallet(userId, userType);
|
||||||
switch (bizType) {
|
switch (bizType) {
|
||||||
case PAYMENT_REFUND: {
|
case PAYMENT_REFUND: {
|
||||||
@ -153,7 +154,8 @@ public class PayWalletServiceImpl implements PayWalletService {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// 2.2 生成钱包流水
|
|
||||||
|
// 2. 生成钱包流水
|
||||||
CreateWalletTransactionBO bo = new CreateWalletTransactionBO().setWalletId(payWallet.getId())
|
CreateWalletTransactionBO bo = new CreateWalletTransactionBO().setWalletId(payWallet.getId())
|
||||||
.setPrice(price).setBalance(payWallet.getBalance()+price).setBizId(String.valueOf(bizId))
|
.setPrice(price).setBalance(payWallet.getBalance()+price).setBizId(String.valueOf(bizId))
|
||||||
.setBizType(bizType.getType()).setTitle(bizType.getDescription());
|
.setBizType(bizType.getType()).setTitle(bizType.getDescription());
|
||||||
|
@ -6,6 +6,8 @@ import cn.iocoder.yudao.module.pay.dal.dataobject.wallet.PayWalletTransactionDO;
|
|||||||
import cn.iocoder.yudao.module.pay.enums.member.PayWalletBizTypeEnum;
|
import cn.iocoder.yudao.module.pay.enums.member.PayWalletBizTypeEnum;
|
||||||
import cn.iocoder.yudao.module.pay.service.wallet.bo.CreateWalletTransactionBO;
|
import cn.iocoder.yudao.module.pay.service.wallet.bo.CreateWalletTransactionBO;
|
||||||
|
|
||||||
|
import javax.validation.Valid;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 钱包余额流水 Service 接口
|
* 钱包余额流水 Service 接口
|
||||||
*
|
*
|
||||||
@ -29,7 +31,7 @@ public interface PayWalletTransactionService {
|
|||||||
* @param bo 创建钱包流水 bo
|
* @param bo 创建钱包流水 bo
|
||||||
* @return 新建的钱包 do
|
* @return 新建的钱包 do
|
||||||
*/
|
*/
|
||||||
PayWalletTransactionDO createWalletTransaction(CreateWalletTransactionBO bo);
|
PayWalletTransactionDO createWalletTransaction(@Valid CreateWalletTransactionBO bo);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 根据 no,获取钱包余流水
|
* 根据 no,获取钱包余流水
|
||||||
@ -46,4 +48,5 @@ public interface PayWalletTransactionService {
|
|||||||
* @return 钱包流水
|
* @return 钱包流水
|
||||||
*/
|
*/
|
||||||
PayWalletTransactionDO getWalletTransaction(String bizId, PayWalletBizTypeEnum type);
|
PayWalletTransactionDO getWalletTransaction(String bizId, PayWalletBizTypeEnum type);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -22,10 +22,12 @@ import javax.annotation.Resource;
|
|||||||
@Service
|
@Service
|
||||||
@Slf4j
|
@Slf4j
|
||||||
public class PayWalletTransactionServiceImpl implements PayWalletTransactionService {
|
public class PayWalletTransactionServiceImpl implements PayWalletTransactionService {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 钱包流水的 no 前缀
|
* 钱包流水的 no 前缀
|
||||||
*/
|
*/
|
||||||
private static final String WALLET_NO_PREFIX = "W";
|
private static final String WALLET_NO_PREFIX = "W";
|
||||||
|
|
||||||
@Resource
|
@Resource
|
||||||
private PayWalletService payWalletService;
|
private PayWalletService payWalletService;
|
||||||
@Resource
|
@Resource
|
||||||
@ -42,10 +44,10 @@ public class PayWalletTransactionServiceImpl implements PayWalletTransactionServ
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public PayWalletTransactionDO createWalletTransaction(CreateWalletTransactionBO bo) {
|
public PayWalletTransactionDO createWalletTransaction(CreateWalletTransactionBO bo) {
|
||||||
PayWalletTransactionDO transactionDO = PayWalletTransactionConvert.INSTANCE.convert(bo);
|
PayWalletTransactionDO transaction = PayWalletTransactionConvert.INSTANCE.convert(bo)
|
||||||
transactionDO.setNo(noRedisDAO.generate(WALLET_NO_PREFIX));
|
.setNo(noRedisDAO.generate(WALLET_NO_PREFIX));
|
||||||
payWalletTransactionMapper.insert(transactionDO);
|
payWalletTransactionMapper.insert(transaction);
|
||||||
return transactionDO;
|
return transaction;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -57,4 +59,5 @@ public class PayWalletTransactionServiceImpl implements PayWalletTransactionServ
|
|||||||
public PayWalletTransactionDO getWalletTransaction(String bizId, PayWalletBizTypeEnum type) {
|
public PayWalletTransactionDO getWalletTransaction(String bizId, PayWalletBizTypeEnum type) {
|
||||||
return payWalletTransactionMapper.selectByBiz(bizId, type.getType());
|
return payWalletTransactionMapper.selectByBiz(bizId, type.getType());
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -11,6 +11,8 @@ import lombok.Data;
|
|||||||
@Data
|
@Data
|
||||||
public class CreateWalletTransactionBO {
|
public class CreateWalletTransactionBO {
|
||||||
|
|
||||||
|
// TODO @jason:bo 的话,最好加个参数校验哈;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 钱包编号
|
* 钱包编号
|
||||||
*
|
*
|
||||||
|
Loading…
Reference in New Issue
Block a user