feat(game): 添加平台成本计算功能
- 在 Constants 中添加 HUNDRED 常量,用于成本计算 - 在 ITenantPlatformService 中添加 findTenantPlatform 方法,用于获取租户平台信息 - 修改 TenantGameQuotaFlowMapper,增加 platform_code 字段查询 - 更新 TenantGameQuotaServiceImpl 中的 balanceChanges 方法,加入平台成本计算逻辑 - 在 TenantPlatformMapper 中添加 findTenantPlatform 方法的 SQL 查询- 更新 TenantPlatformServiceImpl,实现 findTenantPlatform 方法 - 修改 TenantQuotaTask 中的 updateBalance 方法,考虑平台成本因素main-p
parent
dc6e3966ff
commit
b29e21816c
|
@ -2,6 +2,7 @@ package com.ff.base.constant;
|
||||||
|
|
||||||
import io.jsonwebtoken.Claims;
|
import io.jsonwebtoken.Claims;
|
||||||
|
|
||||||
|
import java.math.BigDecimal;
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -261,4 +262,8 @@ public class Constants {
|
||||||
* 租户角色
|
* 租户角色
|
||||||
*/
|
*/
|
||||||
public static final String TENANT_ROLE = "tenant";
|
public static final String TENANT_ROLE = "tenant";
|
||||||
|
/**
|
||||||
|
* 一百
|
||||||
|
*/
|
||||||
|
public static final BigDecimal HUNDRED =new BigDecimal("100") ;
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,6 +20,15 @@ public interface TenantPlatformMapper
|
||||||
TenantPlatform selectTenantPlatformById(Long id);
|
TenantPlatform selectTenantPlatformById(Long id);
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 查找租户平台
|
||||||
|
*
|
||||||
|
* @param tenantPlatform 租户平台
|
||||||
|
* @return {@link TenantPlatform }
|
||||||
|
*/
|
||||||
|
TenantPlatform findTenantPlatform(TenantPlatform tenantPlatform);
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 按租户id选择货币代码
|
* 按租户id选择货币代码
|
||||||
*
|
*
|
||||||
|
|
|
@ -19,6 +19,15 @@ public interface ITenantPlatformService
|
||||||
*/
|
*/
|
||||||
TenantPlatform selectTenantPlatformById(Long id);
|
TenantPlatform selectTenantPlatformById(Long id);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 查找租户平台
|
||||||
|
*
|
||||||
|
* @param tenantPlatform 租户平台
|
||||||
|
* @return {@link TenantPlatform }
|
||||||
|
*/
|
||||||
|
TenantPlatform findTenantPlatform(TenantPlatform tenantPlatform);
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 查询租户成本管理列表
|
* 查询租户成本管理列表
|
||||||
*
|
*
|
||||||
|
|
|
@ -35,6 +35,17 @@ public class TenantPlatformServiceImpl implements ITenantPlatformService
|
||||||
return tenantPlatformMapper.selectTenantPlatformById(id);
|
return tenantPlatformMapper.selectTenantPlatformById(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 查找租户平台
|
||||||
|
*
|
||||||
|
* @param tenantPlatform 租户平台
|
||||||
|
* @return {@link TenantPlatform }
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public TenantPlatform findTenantPlatform(TenantPlatform tenantPlatform) {
|
||||||
|
return tenantPlatformMapper.findTenantPlatform(tenantPlatform);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 查询租户成本管理列表
|
* 查询租户成本管理列表
|
||||||
*
|
*
|
||||||
|
|
|
@ -37,6 +37,19 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||||
where id = #{id}
|
where id = #{id}
|
||||||
</select>
|
</select>
|
||||||
|
|
||||||
|
|
||||||
|
<select id="findTenantPlatform" parameterType="TenantPlatform" resultMap="TenantPlatformResult">
|
||||||
|
<include refid="selectTenantPlatformVo"/>
|
||||||
|
<where>
|
||||||
|
<if test="tenantId != null "> and tenant_id = #{tenantId}</if>
|
||||||
|
<if test="platformCode != null and platformCode != ''"> and platform_code = #{platformCode}</if>
|
||||||
|
<if test="currencyCode != null and currencyCode != ''"> and currency_code = #{currencyCode}</if>
|
||||||
|
<if test="cost != null "> and cost = #{cost}</if>
|
||||||
|
<if test="useCost != null "> and use_cost = #{useCost}</if>
|
||||||
|
</where>
|
||||||
|
limit 1
|
||||||
|
</select>
|
||||||
|
|
||||||
<select id="selectCurrencyCodeByTenantId" >
|
<select id="selectCurrencyCodeByTenantId" >
|
||||||
select currency_code from ff_tenant_platform
|
select currency_code from ff_tenant_platform
|
||||||
|
|
||||||
|
|
|
@ -10,6 +10,8 @@ import cn.hutool.core.util.NumberUtil;
|
||||||
import com.ff.base.constant.Constants;
|
import com.ff.base.constant.Constants;
|
||||||
import com.ff.base.enums.*;
|
import com.ff.base.enums.*;
|
||||||
import com.ff.base.exception.base.ApiException;
|
import com.ff.base.exception.base.ApiException;
|
||||||
|
import com.ff.base.system.domain.TenantPlatform;
|
||||||
|
import com.ff.base.system.service.ITenantPlatformService;
|
||||||
import com.ff.base.utils.DateUtils;
|
import com.ff.base.utils.DateUtils;
|
||||||
import com.ff.base.utils.QuotaUtils;
|
import com.ff.base.utils.QuotaUtils;
|
||||||
import com.ff.base.utils.StringUtils;
|
import com.ff.base.utils.StringUtils;
|
||||||
|
@ -73,6 +75,8 @@ public class TenantGameQuotaServiceImpl implements ITenantGameQuotaService {
|
||||||
@Resource
|
@Resource
|
||||||
private ITenantQuotaExchangeService tenantQuotaExchangeService;
|
private ITenantQuotaExchangeService tenantQuotaExchangeService;
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
private ITenantPlatformService tenantPlatformService;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 查询租户游戏配额
|
* 查询租户游戏配额
|
||||||
|
@ -285,9 +289,20 @@ public class TenantGameQuotaServiceImpl implements ITenantGameQuotaService {
|
||||||
TenantQuotaExchange tenantQuotaExchange = tenantQuotaExchangeService.getTenantQuotaExchange(Constants.USDT, gameBalanceExchange.getCurrencyCode());
|
TenantQuotaExchange tenantQuotaExchange = tenantQuotaExchangeService.getTenantQuotaExchange(Constants.USDT, gameBalanceExchange.getCurrencyCode());
|
||||||
ApiException.notNull(tenantQuotaExchange, ErrorCode.CURRENCY_EXCHANGE.getCode());
|
ApiException.notNull(tenantQuotaExchange, ErrorCode.CURRENCY_EXCHANGE.getCode());
|
||||||
|
|
||||||
|
|
||||||
// 获取租户信息
|
// 获取租户信息
|
||||||
TenantSecretKey tenantSecretKey = tenantSecretKeyService.selectTenantSecretKeyByTenantKey(gameBalanceExchange.getTenantKey());
|
TenantSecretKey tenantSecretKey = tenantSecretKeyService.selectTenantSecretKeyByTenantKey(gameBalanceExchange.getTenantKey());
|
||||||
|
|
||||||
|
|
||||||
|
// 获取平台币种格外成本
|
||||||
|
TenantPlatform tenantPlatform = tenantPlatformService.findTenantPlatform(TenantPlatform.builder()
|
||||||
|
.tenantId(tenantSecretKey.getId())
|
||||||
|
.currencyCode(gameBalanceExchange.getCurrencyCode())
|
||||||
|
.platformCode(gameBalanceExchange.getPlatformCode())
|
||||||
|
.build());
|
||||||
|
// 检查获取平台币种格外成本是否存在,否则抛出异常
|
||||||
|
ApiException.notNull(tenantPlatform, ErrorCode.PLATFORM_NOT_EXIST.getCode());
|
||||||
|
|
||||||
|
|
||||||
// 获取用户信息
|
// 获取用户信息
|
||||||
Member member = memberService.selectMemberByGameAccount(StringUtils.addSuffix(gameBalanceExchange.getAccount(), gameBalanceExchange.getCurrencyCode() + tenantSecretKey.getTenantSn()));
|
Member member = memberService.selectMemberByGameAccount(StringUtils.addSuffix(gameBalanceExchange.getAccount(), gameBalanceExchange.getCurrencyCode() + tenantSecretKey.getTenantSn()));
|
||||||
// 检查用户是否存在,否则抛出异常
|
// 检查用户是否存在,否则抛出异常
|
||||||
|
@ -317,6 +332,7 @@ public class TenantGameQuotaServiceImpl implements ITenantGameQuotaService {
|
||||||
.agentKey(gameSecretKey.getKey())
|
.agentKey(gameSecretKey.getKey())
|
||||||
.build();
|
.build();
|
||||||
balanceRequestAmount = iGamesService.getMemberInfo(gamesBaseRequestDTO).getBalance();
|
balanceRequestAmount = iGamesService.getMemberInfo(gamesBaseRequestDTO).getBalance();
|
||||||
|
balanceRequestAmount = NumberUtil.add(balanceRequestAmount, NumberUtil.mul(balanceRequestAmount, NumberUtil.div(tenantPlatform.getUseCost(), Constants.HUNDRED)));
|
||||||
|
|
||||||
// 计算累计转入和转出金额
|
// 计算累计转入和转出金额
|
||||||
BigDecimal balanceInto = tenantGameQuotaFlowService.getExchangeMoneyByMemberId(TenantGameQuotaFlow.builder()
|
BigDecimal balanceInto = tenantGameQuotaFlowService.getExchangeMoneyByMemberId(TenantGameQuotaFlow.builder()
|
||||||
|
@ -359,7 +375,7 @@ public class TenantGameQuotaServiceImpl implements ITenantGameQuotaService {
|
||||||
|
|
||||||
// 进行租户余额调整
|
// 进行租户余额调整
|
||||||
this.balanceChanges(BalanceChangesDTO.builder()
|
this.balanceChanges(BalanceChangesDTO.builder()
|
||||||
.isOut(isOut)
|
.isOut(Boolean.TRUE)
|
||||||
.sourceId(gameBalanceExchange.getSourceId())
|
.sourceId(gameBalanceExchange.getSourceId())
|
||||||
.platformCode(gameBalanceExchange.getPlatformCode())
|
.platformCode(gameBalanceExchange.getPlatformCode())
|
||||||
.currencyCode(gameBalanceExchange.getCurrencyCode())
|
.currencyCode(gameBalanceExchange.getCurrencyCode())
|
||||||
|
@ -373,13 +389,18 @@ public class TenantGameQuotaServiceImpl implements ITenantGameQuotaService {
|
||||||
.build());
|
.build());
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
// 如果是扣账操作,首先处理假额度
|
// 如果是扣账操作,首先处理假额度
|
||||||
String falseTenantQuotaType = QuotaUtils.getFalseTenantQuota(gameBalanceExchange.getPlatformCode(), gameBalanceExchange.getCurrencyCode());
|
String falseTenantQuotaType = QuotaUtils.getFalseTenantQuota(gameBalanceExchange.getPlatformCode(), gameBalanceExchange.getCurrencyCode());
|
||||||
TenantGameQuota falseTenantQuota = selectTenantGameQuotaByTenantKey(tenantSecretKey.getTenantKey(), falseTenantQuotaType);
|
TenantGameQuota falseTenantQuota = selectTenantGameQuotaByTenantKey(tenantSecretKey.getTenantKey(), falseTenantQuotaType);
|
||||||
|
balanceRequestAmount = NumberUtil.add(gameBalanceExchange.getAmount(), NumberUtil.mul(gameBalanceExchange.getAmount(), NumberUtil.div(tenantPlatform.getUseCost(), Constants.HUNDRED)));
|
||||||
if (falseTenantQuota.getBalance().compareTo(BigDecimal.ZERO) > 0) {
|
if (falseTenantQuota.getBalance().compareTo(BigDecimal.ZERO) > 0) {
|
||||||
BigDecimal amountToDeduct = gameBalanceExchange.getAmount();
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
BigDecimal falseQuotaBalance = falseTenantQuota.getBalance();
|
BigDecimal falseQuotaBalance = falseTenantQuota.getBalance();
|
||||||
if (falseQuotaBalance.compareTo(amountToDeduct) >= 0) {
|
if (falseQuotaBalance.compareTo(balanceRequestAmount) >= 0) {
|
||||||
// 假额度足够扣除本次所需金额
|
// 假额度足够扣除本次所需金额
|
||||||
this.balanceChanges(BalanceChangesDTO.builder()
|
this.balanceChanges(BalanceChangesDTO.builder()
|
||||||
.isOut(Boolean.FALSE)
|
.isOut(Boolean.FALSE)
|
||||||
|
@ -387,7 +408,7 @@ public class TenantGameQuotaServiceImpl implements ITenantGameQuotaService {
|
||||||
.platformCode(gameBalanceExchange.getPlatformCode())
|
.platformCode(gameBalanceExchange.getPlatformCode())
|
||||||
.currencyCode(gameBalanceExchange.getCurrencyCode())
|
.currencyCode(gameBalanceExchange.getCurrencyCode())
|
||||||
.tenantKey(tenantSecretKey.getTenantKey())
|
.tenantKey(tenantSecretKey.getTenantKey())
|
||||||
.balance(amountToDeduct)
|
.balance(balanceRequestAmount)
|
||||||
.memberId(member.getId())
|
.memberId(member.getId())
|
||||||
.operationType(OperationType.API_BALANCE.getCode())
|
.operationType(OperationType.API_BALANCE.getCode())
|
||||||
.quotaType(falseTenantQuotaType)
|
.quotaType(falseTenantQuotaType)
|
||||||
|
@ -396,7 +417,7 @@ public class TenantGameQuotaServiceImpl implements ITenantGameQuotaService {
|
||||||
balanceRequestAmount = BigDecimal.ZERO;
|
balanceRequestAmount = BigDecimal.ZERO;
|
||||||
} else {
|
} else {
|
||||||
// 假额度不足以扣除本次所需金额,扣除全部假额度
|
// 假额度不足以扣除本次所需金额,扣除全部假额度
|
||||||
balanceRequestAmount = amountToDeduct.subtract(falseQuotaBalance);
|
balanceRequestAmount = balanceRequestAmount.subtract(falseQuotaBalance);
|
||||||
this.balanceChanges(BalanceChangesDTO.builder()
|
this.balanceChanges(BalanceChangesDTO.builder()
|
||||||
.isOut(Boolean.FALSE)
|
.isOut(Boolean.FALSE)
|
||||||
.sourceId(gameBalanceExchange.getSourceId())
|
.sourceId(gameBalanceExchange.getSourceId())
|
||||||
|
|
|
@ -1,9 +1,13 @@
|
||||||
package com.ff.quartz.task;
|
package com.ff.quartz.task;
|
||||||
|
|
||||||
|
|
||||||
|
import cn.hutool.core.util.NumberUtil;
|
||||||
import com.ff.base.constant.Constants;
|
import com.ff.base.constant.Constants;
|
||||||
import com.ff.base.enums.OperationType;
|
import com.ff.base.enums.OperationType;
|
||||||
import com.ff.base.enums.QuotaType;
|
import com.ff.base.enums.QuotaType;
|
||||||
|
import com.ff.base.system.domain.TenantPlatform;
|
||||||
|
import com.ff.base.system.domain.TenantSecretKey;
|
||||||
|
import com.ff.base.system.service.ITenantPlatformService;
|
||||||
import com.ff.base.utils.DateUtils;
|
import com.ff.base.utils.DateUtils;
|
||||||
import com.ff.common.domain.TenantGameQuotaFlow;
|
import com.ff.common.domain.TenantGameQuotaFlow;
|
||||||
import com.ff.common.domain.TenantQuotaExchange;
|
import com.ff.common.domain.TenantQuotaExchange;
|
||||||
|
@ -42,6 +46,9 @@ public class TenantQuotaTask {
|
||||||
@Resource
|
@Resource
|
||||||
private ITenantQuotaExchangeService tenantQuotaExchangeService;
|
private ITenantQuotaExchangeService tenantQuotaExchangeService;
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
private ITenantPlatformService tenantPlatformService;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 更新租户实际配额
|
* 更新租户实际配额
|
||||||
*/
|
*/
|
||||||
|
@ -64,6 +71,7 @@ public class TenantQuotaTask {
|
||||||
balance = balance.abs();
|
balance = balance.abs();
|
||||||
isOut = Boolean.FALSE;
|
isOut = Boolean.FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
TenantQuotaExchange tenantQuotaExchange = tenantQuotaExchangeService.getTenantQuotaExchange(Constants.USDT, tenantGameQuotaFlow.getCurrencyCode());
|
TenantQuotaExchange tenantQuotaExchange = tenantQuotaExchangeService.getTenantQuotaExchange(Constants.USDT, tenantGameQuotaFlow.getCurrencyCode());
|
||||||
//更新额度
|
//更新额度
|
||||||
BalanceRealChangesDTO realChangesDTO = BalanceRealChangesDTO.builder()
|
BalanceRealChangesDTO realChangesDTO = BalanceRealChangesDTO.builder()
|
||||||
|
|
|
@ -326,11 +326,12 @@
|
||||||
<select id="getBalanceByTenantKey" resultMap="TenantGameQuotaFlowResult">
|
<select id="getBalanceByTenantKey" resultMap="TenantGameQuotaFlowResult">
|
||||||
select tenant_key,
|
select tenant_key,
|
||||||
sum(if(is_out, exchange_money, 0)) - sum(if(!is_out, exchange_money, 0)) as exchange_money,
|
sum(if(is_out, exchange_money, 0)) - sum(if(!is_out, exchange_money, 0)) as exchange_money,
|
||||||
currency_code
|
currency_code,
|
||||||
|
platform_code
|
||||||
from ff_tenant_game_quota_flow
|
from ff_tenant_game_quota_flow
|
||||||
where create_time between #{params.beginTime} and #{params.endTime}
|
where create_time between #{params.beginTime} and #{params.endTime}
|
||||||
and quota_type = #{quotaType}
|
and quota_type = #{quotaType}
|
||||||
and operation_type = #{operationType}
|
and operation_type = #{operationType} and currency_code is not null and platform_code is not null
|
||||||
group by tenant_key, currency_code
|
group by tenant_key,platform_code, currency_code
|
||||||
</select>
|
</select>
|
||||||
</mapper>
|
</mapper>
|
Loading…
Reference in New Issue