diff --git a/ff-admin/src/main/java/com/ff/api/controller/ApiGameController.java b/ff-admin/src/main/java/com/ff/api/controller/ApiGameController.java index b1fd8a4..ce3b7e1 100644 --- a/ff-admin/src/main/java/com/ff/api/controller/ApiGameController.java +++ b/ff-admin/src/main/java/com/ff/api/controller/ApiGameController.java @@ -1,20 +1,25 @@ package com.ff.api.controller; +import cn.hutool.core.util.NumberUtil; import com.ff.annotation.CheckHeader; +import com.ff.api.request.GameExchangeBalanceRequest; import com.ff.api.request.GameLoginRequest; import com.ff.api.request.MemberCreateApiRequest; import com.ff.base.constant.Constants; import com.ff.base.core.controller.BaseController; import com.ff.base.core.domain.AjaxResult; +import com.ff.base.enums.OperationType; import com.ff.base.utils.SecurityUtils; import com.ff.base.utils.StringUtils; +import com.ff.common.domain.TenantGameQuotaFlow; import com.ff.common.domain.TenantSecretKey; +import com.ff.common.dto.BalanceChangesDTO; +import com.ff.common.service.ITenantGameQuotaFlowService; +import com.ff.common.service.ITenantGameQuotaService; import com.ff.config.KeyConfig; import com.ff.game.api.IGamesService; -import com.ff.game.api.request.CreateMemberRequestDTO; -import com.ff.game.api.request.GamesLogin; -import com.ff.game.api.request.MemberInfoRequestDTO; +import com.ff.game.api.request.*; import com.ff.game.domain.Game; import com.ff.game.domain.GamePlatform; import com.ff.game.domain.GameSecretKey; @@ -24,6 +29,7 @@ import com.ff.game.service.IGameService; import com.ff.member.domain.Member; import com.ff.member.service.IMemberService; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.transaction.annotation.Transactional; import org.springframework.util.Assert; import org.springframework.validation.annotation.Validated; import org.springframework.web.bind.annotation.PostMapping; @@ -32,6 +38,7 @@ import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; import javax.annotation.Resource; +import java.math.BigDecimal; import java.util.Map; /** @@ -67,6 +74,13 @@ public class ApiGameController extends BaseController { private IGamePlatformService gamePlatformService; + @Resource + private ITenantGameQuotaService tenantGameQuotaService; + + @Resource + private ITenantGameQuotaFlowService tenantGameQuotaFlowService; + + /** * 登录 * @@ -84,7 +98,6 @@ public class ApiGameController extends BaseController { IGamesService iGamesService = gamesService.get(gamePlatform.getPlatformCode() + Constants.SERVICE); - Assert.notNull(iGamesService, "平台不存在"); TenantSecretKey tenantSecretKey = keyConfig.get(); @@ -95,6 +108,7 @@ public class ApiGameController extends BaseController { Assert.notNull(gameSecretKeyLang, "当前语言不存在"); Member member = memberService.selectMemberByGameAccount(StringUtils.addSuffix(memberCreateApiRequest.getAccount(), memberCreateApiRequest.getCurrencyCode() + tenantSecretKey.getTenantSn())); + Assert.notNull(member, "会员不存在"); GamesLogin gamesLogin = GamesLogin.builder() .agentId(gameSecretKey.getCode()) @@ -113,7 +127,82 @@ public class ApiGameController extends BaseController { } + /** + * 汇兑差额 + * + * @param gameExchangeBalanceRequest 游戏兑换余额请求 + * @return {@link AjaxResult } + */ + @PostMapping("/exchange/balance") + @Transactional + public AjaxResult exchangeBalance(@Validated @RequestBody GameExchangeBalanceRequest gameExchangeBalanceRequest) { + IGamesService iGamesService = gamesService.get(gameExchangeBalanceRequest.getPlatformCode() + Constants.SERVICE); + + + TenantSecretKey tenantSecretKey = keyConfig.get(); + GameSecretKey gameSecretKey = gameSecretKeyService.findSecretKeyByPlatformAndSystemCode(gameExchangeBalanceRequest.getPlatformCode(), gameExchangeBalanceRequest.getCurrencyCode()); + Assert.notNull(gameSecretKey, "货币游戏平台不存在"); + + + Member member = memberService.selectMemberByGameAccount(StringUtils.addSuffix(gameExchangeBalanceRequest.getAccount(), gameExchangeBalanceRequest.getCurrencyCode() + tenantSecretKey.getTenantSn())); + Assert.notNull(member, "会员不存在"); + + //操作租户额度 + boolean isOut = gameExchangeBalanceRequest.getTransferType() == 1; + BigDecimal balanceRequestAmount = gameExchangeBalanceRequest.getAmount(); + //如果是增加不可以超过对应的额度 + if (isOut) { + + //获取第三方钱包余额 + MemberInfoRequestDTO gamesBaseRequestDTO = MemberInfoRequestDTO.builder() + .accounts(member.getGameAccount()) + .agentId(gameSecretKey.getCode()) + .agentKey(gameSecretKey.getKey()) + .build(); + balanceRequestAmount = iGamesService.getMemberInfo(gamesBaseRequestDTO).getBalance(); + //转入金额 + BigDecimal balanceInto = tenantGameQuotaFlowService.getBalanceByMemberId(TenantGameQuotaFlow.builder() + .isOut(Boolean.TRUE) + .tenantKey(tenantSecretKey.getTenantKey()) + .memberId(member.getId()) + .build()); + //转出金额 + BigDecimal balanceOut = tenantGameQuotaFlowService.getBalanceByMemberId(TenantGameQuotaFlow.builder() + .isOut(Boolean.FALSE) + .tenantKey(tenantSecretKey.getTenantKey()) + .memberId(member.getId()) + .build()); + //如果转入金额+本次转入金额 大于转出额度则取差值 + if (NumberUtil.add(balanceInto, balanceRequestAmount).compareTo(balanceOut) > 0){ + balanceRequestAmount=NumberUtil.sub(balanceOut, balanceInto); + } + } + //余额扣除 + tenantGameQuotaService.balanceChanges(BalanceChangesDTO.builder() + .isOut(isOut) + .tenantKey(tenantSecretKey.getTenantKey()) + .balance(balanceRequestAmount) + .memberId(member.getId()) + .operationType(OperationType.API_BALANCE.getCode()) + .remark(OperationType.API_BALANCE.getDescription()) + .build()); + + + ExchangeTransferMoneyRequestDTO exchangeTransferMoneyRequestDTO = ExchangeTransferMoneyRequestDTO.builder() + .agentId(gameSecretKey.getCode()) + .agentKey(gameSecretKey.getKey()) + .account(member.getGameAccount()) + .quota(balanceRequestAmount) + .amount(gameExchangeBalanceRequest.getAmount()) + .transferType(gameExchangeBalanceRequest.getTransferType()) + .orderId(gameExchangeBalanceRequest.getOrderId()) + .build(); + String transferByAgentId = iGamesService.exchangeTransferByAgentId(exchangeTransferMoneyRequestDTO); + + return AjaxResult.success(transferByAgentId); + } + } diff --git a/ff-admin/src/main/java/com/ff/api/controller/ApiMemberController.java b/ff-admin/src/main/java/com/ff/api/controller/ApiMemberController.java index c7f239d..33bdb11 100644 --- a/ff-admin/src/main/java/com/ff/api/controller/ApiMemberController.java +++ b/ff-admin/src/main/java/com/ff/api/controller/ApiMemberController.java @@ -11,6 +11,7 @@ import com.ff.common.domain.TenantSecretKey; import com.ff.config.KeyConfig; import com.ff.game.api.IGamesService; import com.ff.game.api.request.CreateMemberRequestDTO; +import com.ff.game.api.request.GamesBaseRequestDTO; import com.ff.game.api.request.MemberInfoRequestDTO; import com.ff.game.domain.GameSecretKey; import com.ff.game.service.IGameSecretKeyService; @@ -83,7 +84,7 @@ public class ApiMemberController extends BaseController { Assert.isTrue(result, "建立游戏账号失败"); //注册本地账号 Member member = Member.builder() - .tenantKey(tenantSecretKey.getTenantSn()) + .tenantKey(tenantSecretKey.getTenantKey()) .memberAccount(memberCreateApiRequest.getAccount()) .gameAccount(gameAccount) .platformCode(memberCreateApiRequest.getPlatformCode()) @@ -111,6 +112,7 @@ public class ApiMemberController extends BaseController { Member member = memberService.selectMemberByGameAccount(StringUtils.addSuffix(memberCreateApiRequest.getAccount(), memberCreateApiRequest.getCurrencyCode() + tenantSecretKey.getTenantSn())); Assert.notNull(member, "会员不存在"); + //向第三方查询账号 MemberInfoRequestDTO gamesBaseRequestDTO = MemberInfoRequestDTO.builder() .accounts(member.getGameAccount()) diff --git a/ff-admin/src/main/java/com/ff/api/request/GameExchangeBalanceRequest.java b/ff-admin/src/main/java/com/ff/api/request/GameExchangeBalanceRequest.java new file mode 100644 index 0000000..0942b78 --- /dev/null +++ b/ff-admin/src/main/java/com/ff/api/request/GameExchangeBalanceRequest.java @@ -0,0 +1,68 @@ +package com.ff.api.request; + +import com.ff.base.annotation.Excel; +import lombok.Data; +import org.hibernate.validator.constraints.Length; + +import javax.validation.constraints.Max; +import javax.validation.constraints.Min; +import javax.validation.constraints.NotBlank; +import javax.validation.constraints.NotNull; +import java.io.Serializable; +import java.math.BigDecimal; + + +/** + * 游戏兑换余额请求 + * + * @author shi + * @date 2025/02/11 + */ +@Data +public class GameExchangeBalanceRequest implements Serializable { + private final static long serialVersionUID = -881298930995538038L; + + + /** + * 账户 + */ + @NotBlank(message = "account不能为空") + private String account; + + + /** 平台编码 */ + @NotBlank(message = "platformCode不能为空") + private String platformCode; + + + /** + * 金额 + */ + @NotNull(message = "amount不能为空") + private BigDecimal amount; + + + /** 币种编码 */ + @NotBlank(message = "currencyCode不能为空") + private String currencyCode; + + /** + * 转账类型 + * 1: 从 游戏商 转移额度到 平台商 (不看 amount 值,全 + * 部转出) + * 2: 从 平台商 转移额度到 游戏商 + */ + @NotNull(message = "transferType不能为空") + @Min(value = 1, message = "transferType最小值为1") + @Max(value = 2, message = "transferType最大值为2") + private Integer transferType; + + /** + * 订单id + */ + @NotBlank(message = "orderId不能为空") + @Length(min = 32,max = 32, message = "orderId长度不能超过32个字符") + private String orderId; + + +} diff --git a/ff-admin/src/main/java/com/ff/api/request/GameLoginRequest.java b/ff-admin/src/main/java/com/ff/api/request/GameLoginRequest.java index c39eab4..0837ab1 100644 --- a/ff-admin/src/main/java/com/ff/api/request/GameLoginRequest.java +++ b/ff-admin/src/main/java/com/ff/api/request/GameLoginRequest.java @@ -1,9 +1,9 @@ package com.ff.api.request; -import com.dtflys.forest.annotation.NotNull; import lombok.Data; import javax.validation.constraints.NotBlank; +import javax.validation.constraints.NotNull; import java.io.Serializable; /** @@ -39,7 +39,7 @@ public class GameLoginRequest implements Serializable { /** * 游戏id */ - @NotBlank(message = "gameId不能为空") + @NotNull(message = "gameId不能为空") private Long gameId; diff --git a/ff-admin/src/main/java/com/ff/common/controller/TenantGameQuotaController.java b/ff-admin/src/main/java/com/ff/common/controller/TenantGameQuotaController.java new file mode 100644 index 0000000..efed705 --- /dev/null +++ b/ff-admin/src/main/java/com/ff/common/controller/TenantGameQuotaController.java @@ -0,0 +1,104 @@ +package com.ff.common.controller; + +import java.util.List; +import javax.servlet.http.HttpServletResponse; +import org.springframework.security.access.prepost.PreAuthorize; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.PutMapping; +import org.springframework.web.bind.annotation.DeleteMapping; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; +import com.ff.base.annotation.Log; +import com.ff.base.core.controller.BaseController; +import com.ff.base.core.domain.AjaxResult; +import com.ff.base.enums.BusinessType; +import com.ff.common.domain.TenantGameQuota; +import com.ff.common.service.ITenantGameQuotaService; +import com.ff.base.utils.poi.ExcelUtil; +import com.ff.base.core.page.TableDataInfo; + +/** + * 租户游戏配额Controller + * + * @author shi + * @date 2025-02-12 + */ +@RestController +@RequestMapping("/common/quota") +public class TenantGameQuotaController extends BaseController +{ + @Autowired + private ITenantGameQuotaService tenantGameQuotaService; + + /** + * 查询租户游戏配额列表 + */ + @PreAuthorize("@ss.hasPermi('common:quota:list')") + @GetMapping("/list") + public TableDataInfo list(TenantGameQuota tenantGameQuota) + { + startPage(); + List list = tenantGameQuotaService.selectTenantGameQuotaList(tenantGameQuota); + return getDataTable(list); + } + + /** + * 导出租户游戏配额列表 + */ + @PreAuthorize("@ss.hasPermi('common:quota:export')") + @Log(title = "租户游戏配额", businessType = BusinessType.EXPORT) + @PostMapping("/export") + public void export(HttpServletResponse response, TenantGameQuota tenantGameQuota) + { + List list = tenantGameQuotaService.selectTenantGameQuotaList(tenantGameQuota); + ExcelUtil util = new ExcelUtil(TenantGameQuota.class); + util.exportExcel(response, list, "租户游戏配额数据"); + } + + /** + * 获取租户游戏配额详细信息 + */ + @PreAuthorize("@ss.hasPermi('common:quota:query')") + @GetMapping(value = "/{id}") + public AjaxResult getInfo(@PathVariable("id") Long id) + { + return success(tenantGameQuotaService.selectTenantGameQuotaById(id)); + } + + /** + * 新增租户游戏配额 + */ + @PreAuthorize("@ss.hasPermi('common:quota:add')") + @Log(title = "租户游戏配额", businessType = BusinessType.INSERT) + @PostMapping + public AjaxResult add(@RequestBody TenantGameQuota tenantGameQuota) + { + return toAjax(tenantGameQuotaService.insertTenantGameQuota(tenantGameQuota)); + } + + /** + * 修改租户游戏配额 + */ + @PreAuthorize("@ss.hasPermi('common:quota:edit')") + @Log(title = "租户游戏配额", businessType = BusinessType.UPDATE) + @PutMapping + public AjaxResult edit(@RequestBody TenantGameQuota tenantGameQuota) + { + return toAjax(tenantGameQuotaService.updateTenantGameQuota(tenantGameQuota)); + } + + /** + * 删除租户游戏配额 + */ + @PreAuthorize("@ss.hasPermi('common:quota:remove')") + @Log(title = "租户游戏配额", businessType = BusinessType.DELETE) + @DeleteMapping("/{ids}") + public AjaxResult remove(@PathVariable Long[] ids) + { + return toAjax(tenantGameQuotaService.deleteTenantGameQuotaByIds(ids)); + } +} diff --git a/ff-admin/src/main/java/com/ff/common/controller/TenantGameQuotaFlowController.java b/ff-admin/src/main/java/com/ff/common/controller/TenantGameQuotaFlowController.java new file mode 100644 index 0000000..b2ac893 --- /dev/null +++ b/ff-admin/src/main/java/com/ff/common/controller/TenantGameQuotaFlowController.java @@ -0,0 +1,104 @@ +package com.ff.common.controller; + +import java.util.List; +import javax.servlet.http.HttpServletResponse; +import org.springframework.security.access.prepost.PreAuthorize; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.PutMapping; +import org.springframework.web.bind.annotation.DeleteMapping; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; +import com.ff.base.annotation.Log; +import com.ff.base.core.controller.BaseController; +import com.ff.base.core.domain.AjaxResult; +import com.ff.base.enums.BusinessType; +import com.ff.common.domain.TenantGameQuotaFlow; +import com.ff.common.service.ITenantGameQuotaFlowService; +import com.ff.base.utils.poi.ExcelUtil; +import com.ff.base.core.page.TableDataInfo; + +/** + * 租户游戏额度流水Controller + * + * @author shi + * @date 2025-02-12 + */ +@RestController +@RequestMapping("/common/flow") +public class TenantGameQuotaFlowController extends BaseController +{ + @Autowired + private ITenantGameQuotaFlowService tenantGameQuotaFlowService; + + /** + * 查询租户游戏额度流水列表 + */ + @PreAuthorize("@ss.hasPermi('common:flow:list')") + @GetMapping("/list") + public TableDataInfo list(TenantGameQuotaFlow tenantGameQuotaFlow) + { + startPage(); + List list = tenantGameQuotaFlowService.selectTenantGameQuotaFlowList(tenantGameQuotaFlow); + return getDataTable(list); + } + + /** + * 导出租户游戏额度流水列表 + */ + @PreAuthorize("@ss.hasPermi('common:flow:export')") + @Log(title = "租户游戏额度流水", businessType = BusinessType.EXPORT) + @PostMapping("/export") + public void export(HttpServletResponse response, TenantGameQuotaFlow tenantGameQuotaFlow) + { + List list = tenantGameQuotaFlowService.selectTenantGameQuotaFlowList(tenantGameQuotaFlow); + ExcelUtil util = new ExcelUtil(TenantGameQuotaFlow.class); + util.exportExcel(response, list, "租户游戏额度流水数据"); + } + + /** + * 获取租户游戏额度流水详细信息 + */ + @PreAuthorize("@ss.hasPermi('common:flow:query')") + @GetMapping(value = "/{id}") + public AjaxResult getInfo(@PathVariable("id") Long id) + { + return success(tenantGameQuotaFlowService.selectTenantGameQuotaFlowById(id)); + } + + /** + * 新增租户游戏额度流水 + */ + @PreAuthorize("@ss.hasPermi('common:flow:add')") + @Log(title = "租户游戏额度流水", businessType = BusinessType.INSERT) + @PostMapping + public AjaxResult add(@RequestBody TenantGameQuotaFlow tenantGameQuotaFlow) + { + return toAjax(tenantGameQuotaFlowService.insertTenantGameQuotaFlow(tenantGameQuotaFlow)); + } + + /** + * 修改租户游戏额度流水 + */ + @PreAuthorize("@ss.hasPermi('common:flow:edit')") + @Log(title = "租户游戏额度流水", businessType = BusinessType.UPDATE) + @PutMapping + public AjaxResult edit(@RequestBody TenantGameQuotaFlow tenantGameQuotaFlow) + { + return toAjax(tenantGameQuotaFlowService.updateTenantGameQuotaFlow(tenantGameQuotaFlow)); + } + + /** + * 删除租户游戏额度流水 + */ + @PreAuthorize("@ss.hasPermi('common:flow:remove')") + @Log(title = "租户游戏额度流水", businessType = BusinessType.DELETE) + @DeleteMapping("/{ids}") + public AjaxResult remove(@PathVariable Long[] ids) + { + return toAjax(tenantGameQuotaFlowService.deleteTenantGameQuotaFlowByIds(ids)); + } +} diff --git a/ff-admin/src/main/java/com/ff/common/domain/TenantGameQuota.java b/ff-admin/src/main/java/com/ff/common/domain/TenantGameQuota.java new file mode 100644 index 0000000..5b6f7d6 --- /dev/null +++ b/ff-admin/src/main/java/com/ff/common/domain/TenantGameQuota.java @@ -0,0 +1,45 @@ +package com.ff.common.domain; + +import java.math.BigDecimal; +import com.ff.base.annotation.Excel; +import com.ff.base.core.domain.BaseEntity; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; + +import javax.validation.constraints.NotNull; + +/** + * 租户游戏配额对象 ff_tenant_game_quota + * + * @author shi + * @date 2025-02-12 + */ +@Data +@AllArgsConstructor +@NoArgsConstructor +@Builder +public class TenantGameQuota extends BaseEntity +{ + private static final long serialVersionUID = 1L; + + /** 主键id */ + private Long id; + + /** 租户key */ + @Excel(name = "租户key") + private String tenantKey; + + /** 游戏额度 */ + @Excel(name = "游戏额度") + private BigDecimal balance; + + + + /** 版本号 */ + @Excel(name = "版本号") + private Integer version; + + +} diff --git a/ff-admin/src/main/java/com/ff/common/domain/TenantGameQuotaFlow.java b/ff-admin/src/main/java/com/ff/common/domain/TenantGameQuotaFlow.java new file mode 100644 index 0000000..58118b4 --- /dev/null +++ b/ff-admin/src/main/java/com/ff/common/domain/TenantGameQuotaFlow.java @@ -0,0 +1,57 @@ +package com.ff.common.domain; + +import java.math.BigDecimal; +import com.ff.base.annotation.Excel; +import com.ff.base.core.domain.BaseEntity; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; + +/** + * 租户游戏额度流水对象 ff_tenant_game_quota_flow + * + * @author shi + * @date 2025-02-12 + */ +@Data +@AllArgsConstructor +@NoArgsConstructor +@Builder +public class TenantGameQuotaFlow extends BaseEntity +{ + private static final long serialVersionUID = 1L; + + /** 主键id */ + private Long id; + + /** 租户key */ + @Excel(name = "租户key") + private String tenantKey; + + /** 用户账号id */ + @Excel(name = "用户账号id") + private Long memberId; + + /** 充值类型 false 扣除 true 充值 */ + @Excel(name = "充值类型 false 扣除 true 充值") + private Boolean isOut; + + /** 操作类型 operationType枚举 */ + @Excel(name = "操作类型 operationType枚举") + private Integer operationType; + + /** 游戏额度之前 */ + @Excel(name = "游戏额度之前") + private BigDecimal balanceBefore; + + /** 游戏额度 */ + @Excel(name = "游戏额度") + private BigDecimal balance; + + /** 游戏额度之后 */ + @Excel(name = "游戏额度之后") + private BigDecimal balanceAfter; + + +} diff --git a/ff-admin/src/main/java/com/ff/common/dto/BalanceChangesDTO.java b/ff-admin/src/main/java/com/ff/common/dto/BalanceChangesDTO.java new file mode 100644 index 0000000..aee24f6 --- /dev/null +++ b/ff-admin/src/main/java/com/ff/common/dto/BalanceChangesDTO.java @@ -0,0 +1,47 @@ +package com.ff.common.dto; + + +import com.ff.base.annotation.Excel; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; + +import java.io.Serializable; +import java.math.BigDecimal; + +/** + * 余额更改为 + * + * @author shi + * @date 2025/02/12 + */ +@Data +@AllArgsConstructor +@NoArgsConstructor +@Builder +public class BalanceChangesDTO implements Serializable { + private static final long serialVersionUID = -7479292236485670076L; + + /** 充值类型 false 扣除 true 充值 */ + private Boolean isOut; + + + /** 租户key */ + private String tenantKey; + + /** 游戏额度 */ + private BigDecimal balance; + + /** 备注 */ + private String remark; + + /** + * 成员id + */ + private Long memberId; + + + /** 操作类型 OperationType枚举 */ + private Integer operationType; +} diff --git a/ff-admin/src/main/java/com/ff/common/mapper/TenantGameQuotaFlowMapper.java b/ff-admin/src/main/java/com/ff/common/mapper/TenantGameQuotaFlowMapper.java new file mode 100644 index 0000000..945c066 --- /dev/null +++ b/ff-admin/src/main/java/com/ff/common/mapper/TenantGameQuotaFlowMapper.java @@ -0,0 +1,71 @@ +package com.ff.common.mapper; + +import java.math.BigDecimal; +import java.util.List; +import com.ff.common.domain.TenantGameQuotaFlow; + +/** + * 租户游戏额度流水Mapper接口 + * + * @author shi + * @date 2025-02-12 + */ +public interface TenantGameQuotaFlowMapper +{ + /** + * 查询租户游戏额度流水 + * + * @param id 租户游戏额度流水主键 + * @return 租户游戏额度流水 + */ + TenantGameQuotaFlow selectTenantGameQuotaFlowById(Long id); + + /** + * 查询租户游戏额度流水列表 + * + * @param tenantGameQuotaFlow 租户游戏额度流水 + * @return 租户游戏额度流水集合 + */ + List selectTenantGameQuotaFlowList(TenantGameQuotaFlow tenantGameQuotaFlow); + + /** + * 新增租户游戏额度流水 + * + * @param tenantGameQuotaFlow 租户游戏额度流水 + * @return 结果 + */ + int insertTenantGameQuotaFlow(TenantGameQuotaFlow tenantGameQuotaFlow); + + /** + * 修改租户游戏额度流水 + * + * @param tenantGameQuotaFlow 租户游戏额度流水 + * @return 结果 + */ + int updateTenantGameQuotaFlow(TenantGameQuotaFlow tenantGameQuotaFlow); + + /** + * 删除租户游戏额度流水 + * + * @param id 租户游戏额度流水主键 + * @return 结果 + */ + int deleteTenantGameQuotaFlowById(Long id); + + /** + * 批量删除租户游戏额度流水 + * + * @param ids 需要删除的数据主键集合 + * @return 结果 + */ + int deleteTenantGameQuotaFlowByIds(Long[] ids); + + + /** + * 通过会员id获取余额 + * + * @param tenantGameQuotaFlow 租户游戏配额流 + * @return {@link BigDecimal } + */ + BigDecimal getBalanceByMemberId(TenantGameQuotaFlow tenantGameQuotaFlow); +} diff --git a/ff-admin/src/main/java/com/ff/common/mapper/TenantGameQuotaMapper.java b/ff-admin/src/main/java/com/ff/common/mapper/TenantGameQuotaMapper.java new file mode 100644 index 0000000..ebefb12 --- /dev/null +++ b/ff-admin/src/main/java/com/ff/common/mapper/TenantGameQuotaMapper.java @@ -0,0 +1,79 @@ +package com.ff.common.mapper; + +import java.util.List; +import com.ff.common.domain.TenantGameQuota; + +/** + * 租户游戏配额Mapper接口 + * + * @author shi + * @date 2025-02-12 + */ +public interface TenantGameQuotaMapper +{ + /** + * 查询租户游戏配额 + * + * @param id 租户游戏配额主键 + * @return 租户游戏配额 + */ + TenantGameQuota selectTenantGameQuotaById(Long id); + + + /** + * 查询租户游戏配额 + * + * @param tenantKey 租户游戏配额主键 + * @return 租户游戏配额 + */ + TenantGameQuota selectTenantGameQuotaByTenantKey(String tenantKey); + + /** + * 查询租户游戏配额列表 + * + * @param tenantGameQuota 租户游戏配额 + * @return 租户游戏配额集合 + */ + List selectTenantGameQuotaList(TenantGameQuota tenantGameQuota); + + /** + * 新增租户游戏配额 + * + * @param tenantGameQuota 租户游戏配额 + * @return 结果 + */ + int insertTenantGameQuota(TenantGameQuota tenantGameQuota); + + /** + * 修改租户游戏配额 + * + * @param tenantGameQuota 租户游戏配额 + * @return 结果 + */ + int updateTenantGameQuota(TenantGameQuota tenantGameQuota); + + + /** + * 改变余额 + * + * @param tenantGameQuota sys游戏配额 + * @return {@link Boolean } + */ + Boolean changeBalance(TenantGameQuota tenantGameQuota); + + /** + * 删除租户游戏配额 + * + * @param id 租户游戏配额主键 + * @return 结果 + */ + int deleteTenantGameQuotaById(Long id); + + /** + * 批量删除租户游戏配额 + * + * @param ids 需要删除的数据主键集合 + * @return 结果 + */ + int deleteTenantGameQuotaByIds(Long[] ids); +} diff --git a/ff-admin/src/main/java/com/ff/common/service/ITenantGameQuotaFlowService.java b/ff-admin/src/main/java/com/ff/common/service/ITenantGameQuotaFlowService.java new file mode 100644 index 0000000..3f0eb11 --- /dev/null +++ b/ff-admin/src/main/java/com/ff/common/service/ITenantGameQuotaFlowService.java @@ -0,0 +1,70 @@ +package com.ff.common.service; + +import java.math.BigDecimal; +import java.util.List; +import com.ff.common.domain.TenantGameQuotaFlow; + +/** + * 租户游戏额度流水Service接口 + * + * @author shi + * @date 2025-02-12 + */ +public interface ITenantGameQuotaFlowService +{ + /** + * 查询租户游戏额度流水 + * + * @param id 租户游戏额度流水主键 + * @return 租户游戏额度流水 + */ + TenantGameQuotaFlow selectTenantGameQuotaFlowById(Long id); + + /** + * 查询租户游戏额度流水列表 + * + * @param tenantGameQuotaFlow 租户游戏额度流水 + * @return 租户游戏额度流水集合 + */ + List selectTenantGameQuotaFlowList(TenantGameQuotaFlow tenantGameQuotaFlow); + + /** + * 新增租户游戏额度流水 + * + * @param tenantGameQuotaFlow 租户游戏额度流水 + * @return 结果 + */ + int insertTenantGameQuotaFlow(TenantGameQuotaFlow tenantGameQuotaFlow); + + /** + * 修改租户游戏额度流水 + * + * @param tenantGameQuotaFlow 租户游戏额度流水 + * @return 结果 + */ + int updateTenantGameQuotaFlow(TenantGameQuotaFlow tenantGameQuotaFlow); + + /** + * 批量删除租户游戏额度流水 + * + * @param ids 需要删除的租户游戏额度流水主键集合 + * @return 结果 + */ + int deleteTenantGameQuotaFlowByIds(Long[] ids); + + /** + * 删除租户游戏额度流水信息 + * + * @param id 租户游戏额度流水主键 + * @return 结果 + */ + int deleteTenantGameQuotaFlowById(Long id); + + /** + * 通过会员id获取余额 + * + * @param tenantGameQuotaFlow 租户游戏配额流 + * @return {@link BigDecimal } + */ + BigDecimal getBalanceByMemberId(TenantGameQuotaFlow tenantGameQuotaFlow); +} diff --git a/ff-admin/src/main/java/com/ff/common/service/ITenantGameQuotaService.java b/ff-admin/src/main/java/com/ff/common/service/ITenantGameQuotaService.java new file mode 100644 index 0000000..3623a2f --- /dev/null +++ b/ff-admin/src/main/java/com/ff/common/service/ITenantGameQuotaService.java @@ -0,0 +1,70 @@ +package com.ff.common.service; + +import java.util.List; +import com.ff.common.domain.TenantGameQuota; +import com.ff.common.dto.BalanceChangesDTO; + +/** + * 租户游戏配额Service接口 + * + * @author shi + * @date 2025-02-12 + */ +public interface ITenantGameQuotaService +{ + /** + * 查询租户游戏配额 + * + * @param id 租户游戏配额主键 + * @return 租户游戏配额 + */ + TenantGameQuota selectTenantGameQuotaById(Long id); + + /** + * 查询租户游戏配额列表 + * + * @param tenantGameQuota 租户游戏配额 + * @return 租户游戏配额集合 + */ + List selectTenantGameQuotaList(TenantGameQuota tenantGameQuota); + + /** + * 新增租户游戏配额 + * + * @param tenantGameQuota 租户游戏配额 + * @return 结果 + */ + int insertTenantGameQuota(TenantGameQuota tenantGameQuota); + + /** + * 修改租户游戏配额 + * + * @param tenantGameQuota 租户游戏配额 + * @return 结果 + */ + int updateTenantGameQuota(TenantGameQuota tenantGameQuota); + + /** + * 批量删除租户游戏配额 + * + * @param ids 需要删除的租户游戏配额主键集合 + * @return 结果 + */ + int deleteTenantGameQuotaByIds(Long[] ids); + + /** + * 删除租户游戏配额信息 + * + * @param id 租户游戏配额主键 + * @return 结果 + */ + int deleteTenantGameQuotaById(Long id); + + /** + * 余额变化 + * + * @param balanceChangesDTO 余额更改为 + * @return {@link Boolean } + */ + Boolean balanceChanges(BalanceChangesDTO balanceChangesDTO); +} diff --git a/ff-admin/src/main/java/com/ff/common/service/impl/TenantGameQuotaFlowServiceImpl.java b/ff-admin/src/main/java/com/ff/common/service/impl/TenantGameQuotaFlowServiceImpl.java new file mode 100644 index 0000000..de12c51 --- /dev/null +++ b/ff-admin/src/main/java/com/ff/common/service/impl/TenantGameQuotaFlowServiceImpl.java @@ -0,0 +1,108 @@ +package com.ff.common.service.impl; + +import java.math.BigDecimal; +import java.util.List; +import com.ff.base.utils.DateUtils; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; +import com.ff.common.mapper.TenantGameQuotaFlowMapper; +import com.ff.common.domain.TenantGameQuotaFlow; +import com.ff.common.service.ITenantGameQuotaFlowService; + +/** + * 租户游戏额度流水Service业务层处理 + * + * @author shi + * @date 2025-02-12 + */ +@Service +public class TenantGameQuotaFlowServiceImpl implements ITenantGameQuotaFlowService +{ + @Autowired + private TenantGameQuotaFlowMapper tenantGameQuotaFlowMapper; + + /** + * 查询租户游戏额度流水 + * + * @param id 租户游戏额度流水主键 + * @return 租户游戏额度流水 + */ + @Override + public TenantGameQuotaFlow selectTenantGameQuotaFlowById(Long id) + { + return tenantGameQuotaFlowMapper.selectTenantGameQuotaFlowById(id); + } + + /** + * 查询租户游戏额度流水列表 + * + * @param tenantGameQuotaFlow 租户游戏额度流水 + * @return 租户游戏额度流水 + */ + @Override + public List selectTenantGameQuotaFlowList(TenantGameQuotaFlow tenantGameQuotaFlow) + { + return tenantGameQuotaFlowMapper.selectTenantGameQuotaFlowList(tenantGameQuotaFlow); + } + + /** + * 新增租户游戏额度流水 + * + * @param tenantGameQuotaFlow 租户游戏额度流水 + * @return 结果 + */ + @Override + public int insertTenantGameQuotaFlow(TenantGameQuotaFlow tenantGameQuotaFlow) + { + tenantGameQuotaFlow.setCreateTime(DateUtils.getNowDate()); + return tenantGameQuotaFlowMapper.insertTenantGameQuotaFlow(tenantGameQuotaFlow); + } + + /** + * 修改租户游戏额度流水 + * + * @param tenantGameQuotaFlow 租户游戏额度流水 + * @return 结果 + */ + @Override + public int updateTenantGameQuotaFlow(TenantGameQuotaFlow tenantGameQuotaFlow) + { + tenantGameQuotaFlow.setUpdateTime(DateUtils.getNowDate()); + return tenantGameQuotaFlowMapper.updateTenantGameQuotaFlow(tenantGameQuotaFlow); + } + + /** + * 批量删除租户游戏额度流水 + * + * @param ids 需要删除的租户游戏额度流水主键 + * @return 结果 + */ + @Override + public int deleteTenantGameQuotaFlowByIds(Long[] ids) + { + return tenantGameQuotaFlowMapper.deleteTenantGameQuotaFlowByIds(ids); + } + + /** + * 删除租户游戏额度流水信息 + * + * @param id 租户游戏额度流水主键 + * @return 结果 + */ + @Override + public int deleteTenantGameQuotaFlowById(Long id) + { + return tenantGameQuotaFlowMapper.deleteTenantGameQuotaFlowById(id); + } + + /** + * 通过会员id获取余额 + * + * @param tenantGameQuotaFlow 租户游戏配额流 + * @return {@link BigDecimal } + */ + @Override + public BigDecimal getBalanceByMemberId(TenantGameQuotaFlow tenantGameQuotaFlow) { + return tenantGameQuotaFlowMapper.getBalanceByMemberId(tenantGameQuotaFlow); + } +} diff --git a/ff-admin/src/main/java/com/ff/common/service/impl/TenantGameQuotaServiceImpl.java b/ff-admin/src/main/java/com/ff/common/service/impl/TenantGameQuotaServiceImpl.java new file mode 100644 index 0000000..d03ed26 --- /dev/null +++ b/ff-admin/src/main/java/com/ff/common/service/impl/TenantGameQuotaServiceImpl.java @@ -0,0 +1,166 @@ +package com.ff.common.service.impl; + +import java.math.BigDecimal; +import java.util.List; + +import cn.hutool.core.util.NumberUtil; +import com.ff.base.constant.Constants; +import com.ff.base.utils.DateUtils; +import com.ff.base.utils.MessageUtils; +import com.ff.base.utils.SecurityUtils; +import com.ff.common.domain.TenantGameQuotaFlow; +import com.ff.common.dto.BalanceChangesDTO; +import com.ff.common.mapper.TenantGameQuotaFlowMapper; +import com.ff.common.service.ITenantGameQuotaFlowService; +import com.ff.common.service.ITenantSecretKeyService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; +import com.ff.common.mapper.TenantGameQuotaMapper; +import com.ff.common.domain.TenantGameQuota; +import com.ff.common.service.ITenantGameQuotaService; +import org.springframework.util.Assert; +import org.springframework.util.ObjectUtils; + +import javax.annotation.Resource; + +/** + * 租户游戏配额Service业务层处理 + * + * @author shi + * @date 2025-02-12 + */ +@Service +public class TenantGameQuotaServiceImpl implements ITenantGameQuotaService +{ + @Autowired + private TenantGameQuotaMapper tenantGameQuotaMapper; + + + @Resource + private ITenantGameQuotaFlowService tenantGameQuotaFlowService; + + + /** + * 查询租户游戏配额 + * + * @param id 租户游戏配额主键 + * @return 租户游戏配额 + */ + @Override + public TenantGameQuota selectTenantGameQuotaById(Long id) + { + return tenantGameQuotaMapper.selectTenantGameQuotaById(id); + } + + /** + * 查询租户游戏配额列表 + * + * @param tenantGameQuota 租户游戏配额 + * @return 租户游戏配额 + */ + @Override + public List selectTenantGameQuotaList(TenantGameQuota tenantGameQuota) + { + return tenantGameQuotaMapper.selectTenantGameQuotaList(tenantGameQuota); + } + + /** + * 新增租户游戏配额 + * + * @param tenantGameQuota 租户游戏配额 + * @return 结果 + */ + @Override + public int insertTenantGameQuota(TenantGameQuota tenantGameQuota) + { + tenantGameQuota.setCreateTime(DateUtils.getNowDate()); + return tenantGameQuotaMapper.insertTenantGameQuota(tenantGameQuota); + } + + /** + * 修改租户游戏配额 + * + * @param tenantGameQuota 租户游戏配额 + * @return 结果 + */ + @Override + public int updateTenantGameQuota(TenantGameQuota tenantGameQuota) + { + tenantGameQuota.setUpdateTime(DateUtils.getNowDate()); + return tenantGameQuotaMapper.updateTenantGameQuota(tenantGameQuota); + } + + /** + * 批量删除租户游戏配额 + * + * @param ids 需要删除的租户游戏配额主键 + * @return 结果 + */ + @Override + public int deleteTenantGameQuotaByIds(Long[] ids) + { + return tenantGameQuotaMapper.deleteTenantGameQuotaByIds(ids); + } + + /** + * 删除租户游戏配额信息 + * + * @param id 租户游戏配额主键 + * @return 结果 + */ + @Override + public int deleteTenantGameQuotaById(Long id) + { + return tenantGameQuotaMapper.deleteTenantGameQuotaById(id); + } + + /** + * 平衡变化 + * + * @param balanceChangesDTO 余额更改为 + * @return {@link Boolean } + */ + @Override + public Boolean balanceChanges(BalanceChangesDTO balanceChangesDTO) { + TenantGameQuota tenantGameQuota = tenantGameQuotaMapper.selectTenantGameQuotaByTenantKey(balanceChangesDTO.getTenantKey()); + Assert.isTrue(!ObjectUtils.isEmpty(tenantGameQuota), "余额额度不足"); + + BigDecimal balanceBefore = tenantGameQuota.getBalance(); + BigDecimal balance =balanceChangesDTO.getBalance(); + if (BigDecimal.ZERO.compareTo(balance) >= 0) { + return Boolean.TRUE; + } + BigDecimal balanceAfter = tenantGameQuota.getBalance(); + //判断是充值还是扣除 + if (balanceChangesDTO.getIsOut()) { + balanceAfter = NumberUtil.add(balanceBefore, balance); + } else { + balanceAfter = NumberUtil.sub(balanceBefore, balance); + } + //判断剩余额度是否大于0 + Assert.isTrue(balanceAfter.compareTo(BigDecimal.ZERO)>=0, "余额额度不足"); + //修改余额 + Boolean changedBalanceResult = tenantGameQuotaMapper.changeBalance(TenantGameQuota.builder() + .tenantKey(balanceChangesDTO.getTenantKey()) + .balance(balanceAfter) + .version(tenantGameQuota.getVersion()) + .build()); + Assert.isTrue(changedBalanceResult, "租户游戏额度操作失败"); + + //插入流水 + TenantGameQuotaFlow tenantGameQuotaFlow = TenantGameQuotaFlow.builder() + .tenantKey(balanceChangesDTO.getTenantKey()) + .isOut(balanceChangesDTO.getIsOut()) + .balanceAfter(balanceAfter) + .memberId(balanceChangesDTO.getMemberId()) + .balance(balance) + .balanceBefore(balanceBefore) + .operationType(balanceChangesDTO.getOperationType()) + .build(); + tenantGameQuotaFlow.setRemark(balanceChangesDTO.getRemark()); + tenantGameQuotaFlow.setCreateTime(DateUtils.getNowDate()); + tenantGameQuotaFlow.setCreateBy(Constants.SYSTEM); + tenantGameQuotaFlowService.insertTenantGameQuotaFlow(tenantGameQuotaFlow); + return changedBalanceResult; + } +} diff --git a/ff-admin/src/main/java/com/ff/game/api/IGamesService.java b/ff-admin/src/main/java/com/ff/game/api/IGamesService.java index 6722464..e3ef627 100644 --- a/ff-admin/src/main/java/com/ff/game/api/IGamesService.java +++ b/ff-admin/src/main/java/com/ff/game/api/IGamesService.java @@ -67,7 +67,7 @@ public interface IGamesService { * @param exchangeTransferMoneyRequestDTO 外汇转账moeny dto * @return {@link Long } */ - Long exchangeTransferByAgentId(ExchangeTransferMoneyRequestDTO exchangeTransferMoneyRequestDTO); + String exchangeTransferByAgentId(ExchangeTransferMoneyRequestDTO exchangeTransferMoneyRequestDTO); /** * 按时间获取投注记录 diff --git a/ff-admin/src/main/java/com/ff/game/api/jili/client/JILIClient.java b/ff-admin/src/main/java/com/ff/game/api/jili/client/JILIClient.java index 6d93e57..82afc1a 100644 --- a/ff-admin/src/main/java/com/ff/game/api/jili/client/JILIClient.java +++ b/ff-admin/src/main/java/com/ff/game/api/jili/client/JILIClient.java @@ -1,14 +1,9 @@ package com.ff.game.api.jili.client; -import com.dtflys.forest.annotation.Address; -import com.dtflys.forest.annotation.Get; -import com.dtflys.forest.annotation.Request; -import com.dtflys.forest.annotation.Var; +import com.dtflys.forest.annotation.*; import com.ff.game.api.jili.address.MyJILIAddressSource; -import com.ff.game.api.jili.dto.JILICreateMemberResponseDTO; -import com.ff.game.api.jili.dto.JILIGamesDTO; -import com.ff.game.api.jili.dto.JILILoginWithoutRedirectResponseDTO; -import com.ff.game.api.jili.dto.JILIMemberInfoDTO; +import com.ff.game.api.jili.dto.*; +import com.ff.game.api.request.GamesBaseRequestDTO; /** * jili 请求 @@ -53,4 +48,18 @@ public interface JILIClient { */ @Get("/GetGameList?${parameters}") JILIGamesDTO getGameList(@Var("parameters") String parameters); + + /** + * 按代理id进行交换转账 + * + * @param parameters 参数 + * @return {@link JILIExchangeMoneyResponseDTO } + */ + @Post( + url = "/ExchangeTransferByAgentId?${parameters}", + headers = { + "Content-type: application/x-www-form-urlencoded" + } + ) + JILIExchangeMoneyResponseDTO exchangeTransferByAgentId(@Var("parameters") String parameters,@Body("AgentId") String username); } diff --git a/ff-admin/src/main/java/com/ff/game/api/jili/service/impl/GamesJILIServiceImpl.java b/ff-admin/src/main/java/com/ff/game/api/jili/service/impl/GamesJILIServiceImpl.java index dd06303..4de956f 100644 --- a/ff-admin/src/main/java/com/ff/game/api/jili/service/impl/GamesJILIServiceImpl.java +++ b/ff-admin/src/main/java/com/ff/game/api/jili/service/impl/GamesJILIServiceImpl.java @@ -5,10 +5,7 @@ import com.alibaba.fastjson2.JSON; import com.ff.base.constant.CacheConstants; import com.ff.base.constant.Constants; import com.ff.base.core.redis.RedisCache; -import com.ff.base.enums.FreeStatus; -import com.ff.base.enums.GamePlatforms; -import com.ff.base.enums.GameStatus; -import com.ff.base.enums.JILIGameType; +import com.ff.base.enums.*; import com.ff.base.exception.base.BaseException; import com.ff.base.system.service.ISysConfigService; import com.ff.base.utils.DateUtils; @@ -19,6 +16,10 @@ import com.ff.base.utils.http.HttpClientSslUtils; import com.ff.base.utils.http.HttpUtils; import com.ff.base.utils.sign.Md5Utils; import com.ff.base.utils.uuid.IdUtils; +import com.ff.common.domain.TenantSecretKey; +import com.ff.common.dto.BalanceChangesDTO; +import com.ff.common.service.ITenantGameQuotaService; +import com.ff.config.KeyConfig; import com.ff.game.api.IGamesService; import com.ff.game.api.jili.client.JILIClient; import com.ff.game.api.jili.dto.*; @@ -31,6 +32,7 @@ import lombok.extern.slf4j.Slf4j; import org.apache.http.entity.ContentType; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; +import org.springframework.util.Assert; import org.springframework.util.CollectionUtils; import org.springframework.util.ObjectUtils; @@ -82,6 +84,13 @@ public class GamesJILIServiceImpl implements IGamesService { @Resource private JILIClient jiliClient; + + @Resource + private KeyConfig keyConfig; + + + + /** * 获得就是成功 * @@ -225,10 +234,6 @@ public class GamesJILIServiceImpl implements IGamesService { if (this.getIsSuccess(jiliGames.getErrorCode())) { for (JILIGamesDataDTO gamesDataDTO : jiliGames.getData()) { - if (JILIGameType.GAME_HALL.getCode().equals(gamesDataDTO.getGameCategoryId())) { - continue; - } - GamePlatform gamePlatform = GamePlatform.builder() .platformType(JILIGameType.findSystemByCode(gamesDataDTO.getGameCategoryId())) .platformCode(GamePlatforms.JILI.getCode()) @@ -250,6 +255,7 @@ public class GamesJILIServiceImpl implements IGamesService { List games = gameService.selectGameList(game); //不存在这个游戏 if (CollectionUtils.isEmpty(games)) { + game.setGameSourceType(gamesDataDTO.getGameCategoryId()); game.setFreespin(gamesDataDTO.isFreespin()); game.setSortNo(gameService.selectMaxSortNoByPlatformId(gamePlatform.getId()) + 1); game.setGameName(gamesDataDTO.getName().getZhCN()); @@ -267,8 +273,7 @@ public class GamesJILIServiceImpl implements IGamesService { redisCache.setCacheList(CacheConstants.JILI_GAMES, jiliGames.getData()); redisCache.expire(CacheConstants.JILI_GAMES, 5L, TimeUnit.HOURS); } else { - log.error("GameBettingDataJILIServiceImpl [getGameList] 获取游戏列表失败,错误代码{},错误信息{}", jiliGames.getErrorCode(), jiliGames.getMessage()); - throw new BaseException(MessageUtils.message("game.list.retrieve.failed")); + throw new BaseException(jiliGames.getMessage()); } @@ -283,24 +288,33 @@ public class GamesJILIServiceImpl implements IGamesService { */ @Override @Transactional - public Long exchangeTransferByAgentId(ExchangeTransferMoneyRequestDTO exchangeTransferMoneyRequestDTO) { + public String exchangeTransferByAgentId(ExchangeTransferMoneyRequestDTO exchangeTransferMoneyRequestDTO) { String systemByCode = gameSecretKeyService.findSystemByCode(exchangeTransferMoneyRequestDTO.getAgentId(), GamePlatforms.JILI.getInfo()); - Member member = memberService.selectMemberByMemberAccount(exchangeTransferMoneyRequestDTO.getAccount()); - String transactionId = exchangeTransferMoneyRequestDTO.getTransactionId(); - //如果没有自定义单号 - if (!StringUtils.hasText(exchangeTransferMoneyRequestDTO.getTransactionId())) { - transactionId = GamePlatforms.JILI.getCode() + IdUtils.simpleUUID(); - } + Member member = memberService.selectMemberByGameAccount(exchangeTransferMoneyRequestDTO.getAccount()); + String transactionId = GamePlatforms.JILI.getCode() + IdUtils.simpleUUID(); + TenantSecretKey tenantSecretKey = keyConfig.get(); + List gameExchangeMonies = gameExchangeMoneyService.selectGameExchangeMoneyList( + GameExchangeMoney.builder() + .tenantKey(tenantSecretKey.getTenantKey()) + .orderId(exchangeTransferMoneyRequestDTO.getOrderId()) + .build() + ); + Assert.isTrue(CollectionUtils.isEmpty(gameExchangeMonies), "订单号重复"); + + + //获取下一个自增id GameExchangeMoney exchangeMoney = GameExchangeMoney .builder() + .tenantKey(tenantSecretKey.getTenantKey()) .quota(exchangeTransferMoneyRequestDTO.getQuota()) - .platformId(exchangeTransferMoneyRequestDTO.getPlatformId()) .balance(exchangeTransferMoneyRequestDTO.getAmount()) .exchangeType(exchangeTransferMoneyRequestDTO.getTransferType()) .currencyCode(systemByCode) .memberId(member.getId()) + .transactionId(transactionId) + .orderId(exchangeTransferMoneyRequestDTO.getOrderId()) .platformCode(GamePlatforms.JILI.getCode()) .build(); exchangeMoney.setCreateBy(Constants.SYSTEM); @@ -315,34 +329,29 @@ public class GamesJILIServiceImpl implements IGamesService { exchangeTransferMoneyRequestDTO.setQuery(query); String key = this.getKey(exchangeTransferMoneyRequestDTO); - String apiBaseUrl = configService.selectConfigByKey(Constants.JILI_API_BASE_URL); - try { - String result = HttpClientSslUtils.doPost(apiBaseUrl + "/ExchangeTransferByAgentId?" + query + "&Key=" + key, "AgentId=" + exchangeTransferMoneyRequestDTO.getAgentId(), ContentType.APPLICATION_FORM_URLENCODED); - JILIExchangeMoneyResponseDTO exchangeMoneyResponse = JsonUtil.stringToObj(result, JILIExchangeMoneyResponseDTO.class); - //判断是否转移成功 - if (this.getIsSuccess(exchangeMoneyResponse.getErrorCode())) { - JILIExchangeMoneyResponseDTO.BeanData exchangeMoneyResponseData = exchangeMoneyResponse.getData(); - //更新数据 - exchangeMoney.setBalance(NumberUtil.sub(exchangeMoneyResponseData.getCurrencyAfter(), exchangeMoneyResponseData.getCurrencyBefore()).abs()); - exchangeMoney.setCoinBefore(exchangeMoneyResponseData.getCoinBefore()); - exchangeMoney.setCoinAfter(exchangeMoneyResponseData.getCoinAfter()); - exchangeMoney.setCurrencyBefore(exchangeMoneyResponseData.getCurrencyBefore()); - exchangeMoney.setCurrencyAfter(exchangeMoneyResponseData.getCurrencyAfter()); - exchangeMoney.setStatus(exchangeMoneyResponseData.getStatus()); - gameExchangeMoneyService.insertGameExchangeMoney(exchangeMoney); - } else { - log.error("GameBettingDataJILIServiceImpl [exchangeTransferByAgentId] 金额转移失败,错误代码{},错误信息{}", exchangeMoneyResponse.getErrorCode(), exchangeMoneyResponse.getMessage()); - throw new BaseException(MessageUtils.message("game.account.balance.transfer.failed")); + JILIExchangeMoneyResponseDTO exchangeMoneyResponse = jiliClient.exchangeTransferByAgentId(query + "&Key=" + key, exchangeTransferMoneyRequestDTO.getAgentId()); - } - } catch (Exception e) { - log.error("GameBettingDataJILIServiceImpl [exchangeTransferByAgentId] 金额转移失败,错误信息{}", e); - throw new BaseException(MessageUtils.message("game.account.balance.transfer.failed")); + //判断是否转移成功 + if (this.getIsSuccess(exchangeMoneyResponse.getErrorCode())) { + + JILIExchangeMoneyResponseDTO.BeanData exchangeMoneyResponseData = exchangeMoneyResponse.getData(); + //更新数据 + exchangeMoney.setBalance(NumberUtil.sub(exchangeMoneyResponseData.getCurrencyAfter(), exchangeMoneyResponseData.getCurrencyBefore()).abs()); + exchangeMoney.setCoinBefore(exchangeMoneyResponseData.getCoinBefore()); + exchangeMoney.setCoinAfter(exchangeMoneyResponseData.getCoinAfter()); + exchangeMoney.setCurrencyBefore(exchangeMoneyResponseData.getCurrencyBefore()); + exchangeMoney.setCurrencyAfter(exchangeMoneyResponseData.getCurrencyAfter()); + exchangeMoney.setStatus(exchangeMoneyResponseData.getStatus()); + gameExchangeMoneyService.insertGameExchangeMoney(exchangeMoney); + + } else { + throw new BaseException(exchangeMoneyResponse.getMessage()); } - return exchangeMoney.getId(); + + return transactionId; } diff --git a/ff-admin/src/main/java/com/ff/game/api/request/ExchangeTransferMoneyRequestDTO.java b/ff-admin/src/main/java/com/ff/game/api/request/ExchangeTransferMoneyRequestDTO.java index a1a29ab..b9657df 100644 --- a/ff-admin/src/main/java/com/ff/game/api/request/ExchangeTransferMoneyRequestDTO.java +++ b/ff-admin/src/main/java/com/ff/game/api/request/ExchangeTransferMoneyRequestDTO.java @@ -1,8 +1,12 @@ package com.ff.game.api.request; import com.ff.base.annotation.Excel; +import lombok.AllArgsConstructor; import lombok.Data; +import lombok.NoArgsConstructor; +import lombok.experimental.SuperBuilder; +import javax.validation.constraints.NotNull; import java.math.BigDecimal; /** @@ -12,6 +16,9 @@ import java.math.BigDecimal; * @date 2024/10/22 */ @Data +@NoArgsConstructor +@AllArgsConstructor +@SuperBuilder public class ExchangeTransferMoneyRequestDTO extends GamesBaseRequestDTO { @@ -21,9 +28,8 @@ public class ExchangeTransferMoneyRequestDTO extends GamesBaseRequestDTO { private String account; - /** 游戏平台id */ - @Excel(name = "游戏平台id") - private Long platformId; + + /** * 金额 */ @@ -48,5 +54,5 @@ public class ExchangeTransferMoneyRequestDTO extends GamesBaseRequestDTO { /** * 交易id */ - private String transactionId; + private String orderId; } diff --git a/ff-admin/src/main/java/com/ff/game/api/xk/service/impl/GamesXKServiceImpl.java b/ff-admin/src/main/java/com/ff/game/api/xk/service/impl/GamesXKServiceImpl.java index d0b3a6a..cf857b3 100644 --- a/ff-admin/src/main/java/com/ff/game/api/xk/service/impl/GamesXKServiceImpl.java +++ b/ff-admin/src/main/java/com/ff/game/api/xk/service/impl/GamesXKServiceImpl.java @@ -319,7 +319,7 @@ public class GamesXKServiceImpl implements IGamesService { */ @Override @Transactional - public Long exchangeTransferByAgentId(ExchangeTransferMoneyRequestDTO exchangeTransferMoneyRequestDTO) { + public String exchangeTransferByAgentId(ExchangeTransferMoneyRequestDTO exchangeTransferMoneyRequestDTO) { log.info("GamesXKServiceImpl [exchangeTransferByAgentId] 请求参数 {}", exchangeTransferMoneyRequestDTO); String systemByCode = gameSecretKeyService.findSystemByCode(exchangeTransferMoneyRequestDTO.getAgentId(),GamePlatforms.XK.getInfo()); Member member = memberService.selectMemberByMemberAccount(exchangeTransferMoneyRequestDTO.getAccount()); @@ -327,7 +327,6 @@ public class GamesXKServiceImpl implements IGamesService { GameExchangeMoney exchangeMoney = GameExchangeMoney .builder() .quota(exchangeTransferMoneyRequestDTO.getQuota()) - .platformId(exchangeTransferMoneyRequestDTO.getPlatformId()) .balance(exchangeTransferMoneyRequestDTO.getAmount()) .exchangeType(exchangeTransferMoneyRequestDTO.getTransferType()) .currencyCode(systemByCode) @@ -372,7 +371,7 @@ public class GamesXKServiceImpl implements IGamesService { throw new BaseException(MessageUtils.message("game.account.balance.transfer.failed")); } - return exchangeMoney.getId(); + return exchangeMoney.getId().toString(); } diff --git a/ff-admin/src/main/java/com/ff/game/domain/GameExchangeMoney.java b/ff-admin/src/main/java/com/ff/game/domain/GameExchangeMoney.java index 6251d64..d84c7b1 100644 --- a/ff-admin/src/main/java/com/ff/game/domain/GameExchangeMoney.java +++ b/ff-admin/src/main/java/com/ff/game/domain/GameExchangeMoney.java @@ -12,7 +12,7 @@ import lombok.NoArgsConstructor; * 会员金额转移记录对象 ff_game_exchange_money * * @author shi - * @date 2025-02-10 + * @date 2025-02-12 */ @Data @AllArgsConstructor @@ -25,12 +25,16 @@ public class GameExchangeMoney extends BaseEntity /** 主键id */ private Long id; + /** 租户key */ + @Excel(name = "租户key") + private String tenantKey; + /** 币种编码 */ @Excel(name = "币种编码") private String currencyCode; - /** 交易id */ - @Excel(name = "交易id") + /** 第三方交易id */ + @Excel(name = "第三方交易id") private String transactionId; /** 会员id */ @@ -41,10 +45,6 @@ public class GameExchangeMoney extends BaseEntity @Excel(name = "游戏平台 ") private String platformCode; - /** 平台id */ - @Excel(name = "平台id") - private Long platformId; - /** 操作金额 */ @Excel(name = "操作金额") private BigDecimal balance; @@ -69,6 +69,10 @@ public class GameExchangeMoney extends BaseEntity @Excel(name = "转账后金额(指定货币)") private BigDecimal currencyAfter; + /** 系统订单id */ + @Excel(name = "系统订单id") + private String orderId; + /** 转出类型 1游戏商转入到用户全部转出 2 用户转移到游戏商 3 游戏商转移额度到平台商 */ @Excel(name = "转出类型 1游戏商转入到用户全部转出 2 用户转移到游戏商 3 游戏商转移额度到平台商") private Integer exchangeType; diff --git a/ff-admin/src/main/resources/mapper/common/TenantGameQuotaFlowMapper.xml b/ff-admin/src/main/resources/mapper/common/TenantGameQuotaFlowMapper.xml new file mode 100644 index 0000000..fef0349 --- /dev/null +++ b/ff-admin/src/main/resources/mapper/common/TenantGameQuotaFlowMapper.xml @@ -0,0 +1,121 @@ + + + + + + + + + + + + + + + + + + + + + + select id, tenant_key, member_id, is_out, operation_type, balance_before, balance, balance_after, remark, create_by, create_time, update_by, update_time from ff_tenant_game_quota_flow + + + + + + + + insert into ff_tenant_game_quota_flow + + tenant_key, + member_id, + is_out, + operation_type, + balance_before, + balance, + balance_after, + remark, + create_by, + create_time, + update_by, + update_time, + + + #{tenantKey}, + #{memberId}, + #{isOut}, + #{operationType}, + #{balanceBefore}, + #{balance}, + #{balanceAfter}, + #{remark}, + #{createBy}, + #{createTime}, + #{updateBy}, + #{updateTime}, + + + + + update ff_tenant_game_quota_flow + + tenant_key = #{tenantKey}, + member_id = #{memberId}, + is_out = #{isOut}, + operation_type = #{operationType}, + balance_before = #{balanceBefore}, + balance = #{balance}, + balance_after = #{balanceAfter}, + remark = #{remark}, + create_by = #{createBy}, + create_time = #{createTime}, + update_by = #{updateBy}, + update_time = #{updateTime}, + + where id = #{id} + + + + delete from ff_tenant_game_quota_flow where id = #{id} + + + + delete from ff_tenant_game_quota_flow where id in + + #{id} + + + + + + \ No newline at end of file diff --git a/ff-admin/src/main/resources/mapper/common/TenantGameQuotaMapper.xml b/ff-admin/src/main/resources/mapper/common/TenantGameQuotaMapper.xml new file mode 100644 index 0000000..d0a50c8 --- /dev/null +++ b/ff-admin/src/main/resources/mapper/common/TenantGameQuotaMapper.xml @@ -0,0 +1,94 @@ + + + + + + + + + + + + + + + + + select id, tenant_key, balance, version, create_by, create_time, update_by, update_time from ff_tenant_game_quota + + + + + + + + + + insert into ff_tenant_game_quota + + tenant_key, + balance, + version, + create_by, + create_time, + update_by, + update_time, + + + #{tenantKey}, + #{balance}, + #{version}, + #{createBy}, + #{createTime}, + #{updateBy}, + #{updateTime}, + + + + + update ff_tenant_game_quota + + tenant_key = #{tenantKey}, + balance = #{balance}, + version = #{version}, + create_by = #{createBy}, + create_time = #{createTime}, + update_by = #{updateBy}, + update_time = #{updateTime}, + + where id = #{id} + + + + + update ff_tenant_game_quota set balance = #{balance},version =version+1 + where tenant_key = #{tenantKey} and version = #{version} + + + + + delete from ff_tenant_game_quota where id = #{id} + + + + delete from ff_tenant_game_quota where id in + + #{id} + + + \ No newline at end of file diff --git a/ff-admin/src/main/resources/mapper/game/GameExchangeMoneyMapper.xml b/ff-admin/src/main/resources/mapper/game/GameExchangeMoneyMapper.xml index b9f1c25..1e2b8e1 100644 --- a/ff-admin/src/main/resources/mapper/game/GameExchangeMoneyMapper.xml +++ b/ff-admin/src/main/resources/mapper/game/GameExchangeMoneyMapper.xml @@ -1,22 +1,23 @@ + PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" + "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> - + + - + @@ -26,28 +27,29 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" - select id, currency_code, transaction_id, member_id, platform_code, platform_id, balance, quota, coin_before, coin_after, currency_before, currency_after, exchange_type, status, create_by, create_time, update_by, update_time from ff_game_exchange_money + select id, tenant_key, currency_code, transaction_id, member_id, platform_code, balance, quota, coin_before, coin_after, currency_before, currency_after, order_id, exchange_type, status, create_by, create_time, update_by, update_time from ff_game_exchange_money - + - + + and tenant_key = #{tenantKey} and currency_code = #{currencyCode} and transaction_id = #{transactionId} and member_id = #{memberId} and platform_code = #{platformCode} - and platform_id = #{platformId} and balance = #{balance} and quota = #{quota} and coin_before = #{coinBefore} and coin_after = #{coinAfter} and currency_before = #{currencyBefore} and currency_after = #{currencyAfter} + and order_id = #{orderId} and exchange_type = #{exchangeType} and status = #{status} - +