diff --git a/odcs2.com/src/components/pkHome/lotterySeat.vue b/odcs2.com/src/components/pkHome/lotterySeat.vue index 54d99ad..dd84540 100644 --- a/odcs2.com/src/components/pkHome/lotterySeat.vue +++ b/odcs2.com/src/components/pkHome/lotterySeat.vue @@ -115,9 +115,6 @@ > -
- {{ record.ornamentName }} -
{{ record.ornamentsPrice }} @@ -137,9 +134,6 @@ >
-
- {{ record.ornamentName }} -
{{ record.ornamentsPrice }} diff --git a/odcs2.com/src/components/swiperUser.vue b/odcs2.com/src/components/swiperUser.vue index e9b3dda..7d0dd62 100644 --- a/odcs2.com/src/components/swiperUser.vue +++ b/odcs2.com/src/components/swiperUser.vue @@ -9,7 +9,6 @@
-

{{ item.itemName }}

diff --git a/odcs2.com/src/views/Home/common/knapsack.vue b/odcs2.com/src/views/Home/common/knapsack.vue index 30a811c..015bcb0 100644 --- a/odcs2.com/src/views/Home/common/knapsack.vue +++ b/odcs2.com/src/views/Home/common/knapsack.vue @@ -160,7 +160,6 @@
-
{{ item.shortName || item.name }}
@@ -265,17 +264,6 @@ export default { isOver: "加载中", totalOrnamentNumber: 0, totalOrnamentPrice: 0, - // 价格 → 本地奖品图片映射 - priceImgMap: { - 1.88: require("@/assets/bonus/jb1.png"), // 金币1 - 3.88: require("@/assets/bonus/jb2.png"), // 金币2 - 6.88: require("@/assets/bonus/jb3.png"), // 金币3 - 8.88: require("@/assets/bonus/jb4.png"), // 金币4 - 18.88: require("@/assets/bonus/hb1.png"), // 红包1 - 38.88: require("@/assets/bonus/hb2.png"), // 红包2 - 68.88: require("@/assets/bonus/hb3.png"), // 红包3 - 88.88: require("@/assets/bonus/hb4.png"), // 红包4 - }, }; }, computed: { @@ -296,17 +284,13 @@ export default { }, methods: { - // 根据价格获取本地奖品图,无映射时降级使用服务器imageUrl + // 直接使用后端返回的图片地址 getPrizeImg(item) { - const price = parseFloat(item.ornamentsPrice); - if (this.priceImgMap[price]) return this.priceImgMap[price]; - if (item.imageUrl) { - const baseUrl = 'http://95.40.65.4:8081'; - const url = item.imageUrl.trim(); - if (/^(http|https):\/\//i.test(url)) return url; - return baseUrl + url; - } - return ''; + const imgUrl = item.imageUrl || ''; + if (!imgUrl) return ''; + const url = imgUrl.trim(); + if (/^(http|https):\/\//i.test(url)) return url; + return 'http://95.40.65.4:8081' + url; }, playAudio() { this.$store.commit("playAudio"); diff --git a/odcs2.com/src/views/Home/common/personal.vue b/odcs2.com/src/views/Home/common/personal.vue index 2660da7..694891b 100644 --- a/odcs2.com/src/views/Home/common/personal.vue +++ b/odcs2.com/src/views/Home/common/personal.vue @@ -99,7 +99,6 @@
-
{{ item.ornamentName }}
{{ item.ornamentsPrice }} @@ -194,7 +193,6 @@
-
{{ item.ornamentName }}
{{ item.ornamentsPrice }} diff --git a/odcs2.com/src/views/rollHome/common/rolldetial.vue b/odcs2.com/src/views/rollHome/common/rolldetial.vue index 381ee06..581e9fa 100644 --- a/odcs2.com/src/views/rollHome/common/rolldetial.vue +++ b/odcs2.com/src/views/rollHome/common/rolldetial.vue @@ -87,7 +87,6 @@
-
{{ item.ornamentName }}
@@ -213,17 +212,6 @@ export default { countdown: { h: '00', m: '00', s: '00' }, countdownTimer: null, defaultAvatar: require("@/assets/images/default-header.png"), - // 价格 → 本地奖品图片映射 - priceImgMap: { - 1.88: require("@/assets/bonus/jb1.png"), // 金币1 - 3.88: require("@/assets/bonus/jb2.png"), // 金币2 - 6.88: require("@/assets/bonus/jb3.png"), // 金币3 - 8.88: require("@/assets/bonus/jb4.png"), // 金币4 - 18.88: require("@/assets/bonus/hb1.png"), // 红包1 - 38.88: require("@/assets/bonus/hb2.png"), // 红包2 - 68.88: require("@/assets/bonus/hb3.png"), // 红包3 - 88.88: require("@/assets/bonus/hb4.png"), // 红包4 - }, awardResult: [], awardResultIsover: "加载中", playerListIsover: "加载中", @@ -440,17 +428,13 @@ export default { if (/^(http|https):\/\//i.test(trimmed)) return trimmed; return baseUrl + trimmed; }, - // 根据价格获取本地奖品图,无映射时降级使用服务器imgUrl + // 直接使用后端返回的图片地址 getPrizeImg(item) { - const price = parseFloat(item.price); - if (this.priceImgMap[price]) return this.priceImgMap[price]; - if (item.imgUrl) { - const baseUrl = 'http://95.40.65.4:8081'; - const url = item.imgUrl.trim(); - if (/^(http|https):\/\//i.test(url)) return url; - return baseUrl + url; - } - return ''; + const imgUrl = item.imgUrl || item.imageUrl || ''; + if (!imgUrl) return ''; + const url = imgUrl.trim(); + if (/^(http|https):\/\//i.test(url)) return url; + return 'http://95.40.65.4:8081' + url; }, }, }; diff --git a/odcs2.com/src/views/rollHome/index.vue b/odcs2.com/src/views/rollHome/index.vue index b623a67..6caa999 100644 --- a/odcs2.com/src/views/rollHome/index.vue +++ b/odcs2.com/src/views/rollHome/index.vue @@ -126,17 +126,6 @@ export default { rolllist: [], isloading: true, daqweq: "roll", - // 价格 → 本地奖品图片映射 - priceImgMap: { - 1.88: require("@/assets/bonus/jb1.png"), // 金币1 - 3.88: require("@/assets/bonus/jb2.png"), // 金币2 - 6.88: require("@/assets/bonus/jb3.png"), // 金币3 - 8.88: require("@/assets/bonus/jb4.png"), // 金币4 - 18.88: require("@/assets/bonus/hb1.png"), // 红包1 - 38.88: require("@/assets/bonus/hb2.png"), // 红包2 - 68.88: require("@/assets/bonus/hb3.png"), // 红包3 - 88.88: require("@/assets/bonus/hb4.png"), // 红包4 - }, }; }, mounted() { @@ -263,17 +252,13 @@ export default { } }); }, - // 根据价格获取本地奖品图,无映射时降级使用服务器imgUrl + // 直接使用后端返回的图片地址 getPrizeImg(weapon) { - const price = parseFloat(weapon.price); - if (this.priceImgMap[price]) return this.priceImgMap[price]; - if (weapon.imgUrl) { - const baseUrl = 'http://95.40.65.4:8081'; - const url = weapon.imgUrl.trim(); - if (/^(http|https):\/\//i.test(url)) return url; - return baseUrl + url; - } - return ''; + const imgUrl = weapon.imgUrl || weapon.imageUrl || ''; + if (!imgUrl) return ''; + const url = imgUrl.trim(); + if (/^(http|https):\/\//i.test(url)) return url; + return 'http://95.40.65.4:8081' + url; }, }, }; diff --git a/ruoyi-admin/pom.xml b/ruoyi-admin/pom.xml index 984891b..e6e8dc5 100644 --- a/ruoyi-admin/pom.xml +++ b/ruoyi-admin/pom.xml @@ -77,12 +77,6 @@ ${ruoyi.version} - - com.ruoyi - game-wheel-service - ${ruoyi.version} - - com.ruoyi service-thirdparty diff --git a/skins-service/game-wheel-service/doc/data.sql b/skins-service/game-wheel-service/doc/data.sql deleted file mode 100644 index 4d94406..0000000 --- a/skins-service/game-wheel-service/doc/data.sql +++ /dev/null @@ -1 +0,0 @@ -todo \ No newline at end of file diff --git a/skins-service/game-wheel-service/doc/init.sql b/skins-service/game-wheel-service/doc/init.sql deleted file mode 100644 index 0ff3458..0000000 --- a/skins-service/game-wheel-service/doc/init.sql +++ /dev/null @@ -1,60 +0,0 @@ -CREATE TABLE `game_wheel_round` ( - `id` bigint NOT NULL AUTO_INCREMENT COMMENT '唯一自增id', - `date` varchar(10) NOT NULL COMMENT '所属日期', - `round_id` bigint NOT NULL COMMENT 'round id', - `start_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '开始时间', - `end_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '结束时间', - `phase_times` varchar(128) NOT NULL DEFAULT '' COMMENT '每个阶段的时间点', - `total_bet` decimal(10,2) NOT NULL DEFAULT 0.00 COMMENT '本期总下注数', - `total_win` decimal(10,2) NOT NULL DEFAULT 0.00 COMMENT '本期玩家总赢数', - `symbols` varchar(64) NOT NULL DEFAULT '' COMMENT '转盘上的符号', - `result` varchar(64) NOT NULL COMMENT '开出的奖的集合', - `is_manual` int NOT NULL DEFAULT 0 COMMENT '是否后台开奖', - `status` varchar(16) NOT NULL DEFAULT '' COMMENT '状态', - `create_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '记录创建时间', - `update_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '记录更新时间', - PRIMARY KEY (`id`), - UNIQUE KEY `uk_date_round_id` (`date`, `round_id`) -) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='转盘每期表'; - -CREATE TABLE `game_wheel_round_bet` ( - `id` bigint NOT NULL AUTO_INCREMENT COMMENT '唯一自增id', - `round_id` bigint NOT NULL COMMENT 'round id', - `user_id` bigint NOT NULL DEFAULT 0 COMMENT '用户id', - `bet` decimal(10,2) NOT NULL DEFAULT 0.00 COMMENT '下注数', - `bet_symbol` varchar(4) NOT NULL DEFAULT '' COMMENT '压注目标', - `win` decimal(10,2) NOT NULL DEFAULT 0.00 COMMENT '赔付结果', - `create_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '记录创建时间', - `update_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '记录更新时间', - PRIMARY KEY (`id`), - UNIQUE KEY `uk_round_user_symbol` (`round_id`, `user_id`, `bet_symbol`), - KEY `idx_user_id` (`user_id`) -) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='转盘下注表'; - -CREATE TABLE `game_wheel_user` ( - `id` bigint NOT NULL AUTO_INCREMENT COMMENT 'id', - `user_id` bigint NOT NULL COMMENT 'user表的id', - `total_bet` decimal(10,2) NOT NULL DEFAULT '0.00' COMMENT '用户总下注额', - `total_win` decimal(10,2) NOT NULL DEFAULT '0.00' COMMENT '用户总赢得金额', - `count` int NOT NULL DEFAULT '0' COMMENT '总下注次数', - `create_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '记录创建时间', - `update_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '记录更新时间', - PRIMARY KEY (`id`), - UNIQUE KEY `idx_user_id` (`user_id`) -) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='转盘用户表'; - - -ALTER TABLE sys_config MODIFY COLUMN config_value VARCHAR(1024); - -游戏配置数据: -``` -{ - // 核心配置 - "symbols": [1,2,3,4,5,6,7,8,7,6,5,4,3,2,1], // 转盘格子配置 - "buffer_ratio": 0.9, // 一次旋转,最多可用的奖池比例 - "rtp": 0.85, // 一次旋转最多返回给玩家的总投注比例 - // 下面是体验相关,不影响利润 - "special_effects": [{"name": "系统赢", "ratio": 0.7},{"name": "免费旋转1次", "ratio": 0.2},{"name": "免费旋转2次", "ratio": 0.1}] -} -``` - diff --git a/skins-service/game-wheel-service/pom.xml b/skins-service/game-wheel-service/pom.xml deleted file mode 100644 index c619528..0000000 --- a/skins-service/game-wheel-service/pom.xml +++ /dev/null @@ -1,44 +0,0 @@ - - - 4.0.0 - - com.ruoyi - skins-service - 4.8.2 - - - - 幸运转盘 - - - game-wheel-service - - - 8 - 8 - UTF-8 - - - - - - com.ruoyi - ruoyi-framework - - - - com.ruoyi - service-admin - 4.8.2 - - - - com.ruoyi - service-user - 4.8.2 - - - - \ No newline at end of file diff --git a/skins-service/game-wheel-service/src/main/java/com/ruoyi/game/wheel/cache/WheelRewardPoolCacheRepository.java b/skins-service/game-wheel-service/src/main/java/com/ruoyi/game/wheel/cache/WheelRewardPoolCacheRepository.java deleted file mode 100644 index 0151c0f..0000000 --- a/skins-service/game-wheel-service/src/main/java/com/ruoyi/game/wheel/cache/WheelRewardPoolCacheRepository.java +++ /dev/null @@ -1,34 +0,0 @@ -package com.ruoyi.game.wheel.cache; -import com.ruoyi.game.wheel.model.cache.WheelRewardPoolCache; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.data.redis.core.RedisTemplate; -import org.springframework.stereotype.Component; - -import java.math.BigDecimal; - -import static com.ruoyi.admin.config.RedisConstants.WHEEL_GAME_REWARD_POOL_CACHE; -@Component -public class WheelRewardPoolCacheRepository { - @Autowired - public RedisTemplate redisTemplate; - - /** 封盘时将本局总下注全额注入奖池统计 */ - public void incrementalBet(BigDecimal totalBet) { - redisTemplate.opsForValue().increment(WHEEL_GAME_REWARD_POOL_CACHE + ":bet", totalBet.doubleValue()); - } - - /** 开奖后将本局实际总返奖全额记录到奖池统计 */ - public void incrementalWin(BigDecimal totalWin) { - redisTemplate.opsForValue().increment(WHEEL_GAME_REWARD_POOL_CACHE + ":win", totalWin.doubleValue()); - } - - /** 读取奖池当前累计数据 */ - public WheelRewardPoolCache getCache() { - var totalBetS = redisTemplate.opsForValue().get(WHEEL_GAME_REWARD_POOL_CACHE + ":bet"); - var totalWinS = redisTemplate.opsForValue().get(WHEEL_GAME_REWARD_POOL_CACHE + ":win"); - WheelRewardPoolCache cache = new WheelRewardPoolCache(); - cache.setTotalBet(totalBetS == null ? BigDecimal.ZERO : new BigDecimal(totalBetS.toString())); - cache.setTotalWin(totalWinS == null ? BigDecimal.ZERO : new BigDecimal(totalWinS.toString())); - return cache; - } -} diff --git a/skins-service/game-wheel-service/src/main/java/com/ruoyi/game/wheel/cache/WheelRoundCacheRepository.java b/skins-service/game-wheel-service/src/main/java/com/ruoyi/game/wheel/cache/WheelRoundCacheRepository.java deleted file mode 100644 index 1de3175..0000000 --- a/skins-service/game-wheel-service/src/main/java/com/ruoyi/game/wheel/cache/WheelRoundCacheRepository.java +++ /dev/null @@ -1,30 +0,0 @@ -package com.ruoyi.game.wheel.cache; - -import com.ruoyi.common.core.redis.RedisCache; -import com.ruoyi.common.utils.json.SnakeCaseJsonUtils; -import com.ruoyi.game.wheel.constants.CacheConstants; -import com.ruoyi.game.wheel.model.cache.WheelRoundCache; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.stereotype.Component; - -import java.util.concurrent.TimeUnit; - -@Component -public class WheelRoundCacheRepository { - @Autowired - private RedisCache redisCache; - - public WheelRoundCache getCache() { - String s = redisCache.getCacheObject(CacheConstants.WHEEL_ROUND); - return SnakeCaseJsonUtils.fromSnakeCaseJson(s, WheelRoundCache.class); - } - - public void setCache(WheelRoundCache cache) { - if (cache == null) { - redisCache.setCacheObject(CacheConstants.WHEEL_ROUND, null, 1, TimeUnit.DAYS); - } else { - String json = SnakeCaseJsonUtils.toSnakeCaseJson(cache); - redisCache.setCacheObject(CacheConstants.WHEEL_ROUND, json, 1, TimeUnit.DAYS); - } - } -} diff --git a/skins-service/game-wheel-service/src/main/java/com/ruoyi/game/wheel/constants/CacheConstants.java b/skins-service/game-wheel-service/src/main/java/com/ruoyi/game/wheel/constants/CacheConstants.java deleted file mode 100644 index 8cab6b3..0000000 --- a/skins-service/game-wheel-service/src/main/java/com/ruoyi/game/wheel/constants/CacheConstants.java +++ /dev/null @@ -1,9 +0,0 @@ -package com.ruoyi.game.wheel.constants; - -public class CacheConstants { - private static final String PREFIX = "ruoyi:wheel:"; - - public static final String WHEEL_ROUND = PREFIX + "round"; - - public static final String WHEEL_LOCK = PREFIX + "lock"; -} diff --git a/skins-service/game-wheel-service/src/main/java/com/ruoyi/game/wheel/contract/admin/response/QueryWheelGameConfig.java b/skins-service/game-wheel-service/src/main/java/com/ruoyi/game/wheel/contract/admin/response/QueryWheelGameConfig.java deleted file mode 100644 index f71e465..0000000 --- a/skins-service/game-wheel-service/src/main/java/com/ruoyi/game/wheel/contract/admin/response/QueryWheelGameConfig.java +++ /dev/null @@ -1,11 +0,0 @@ -package com.ruoyi.game.wheel.contract.admin.response; - -import com.ruoyi.game.wheel.domain.GameWheelGameConfig; -import lombok.Data; - -@Data -public class QueryWheelGameConfig { - private GameWheelGameConfig config; - private double totalBet; - private double totalWin; -} diff --git a/skins-service/game-wheel-service/src/main/java/com/ruoyi/game/wheel/contract/api/request/DoBetRequest.java b/skins-service/game-wheel-service/src/main/java/com/ruoyi/game/wheel/contract/api/request/DoBetRequest.java deleted file mode 100644 index 74a294d..0000000 --- a/skins-service/game-wheel-service/src/main/java/com/ruoyi/game/wheel/contract/api/request/DoBetRequest.java +++ /dev/null @@ -1,9 +0,0 @@ -package com.ruoyi.game.wheel.contract.api.request; - -import lombok.Data; - -@Data -public class DoBetRequest { - private Integer bet; - private String symbol; -} diff --git a/skins-service/game-wheel-service/src/main/java/com/ruoyi/game/wheel/contract/api/request/GetHistoryBetRequest.java b/skins-service/game-wheel-service/src/main/java/com/ruoyi/game/wheel/contract/api/request/GetHistoryBetRequest.java deleted file mode 100644 index 3645dd0..0000000 --- a/skins-service/game-wheel-service/src/main/java/com/ruoyi/game/wheel/contract/api/request/GetHistoryBetRequest.java +++ /dev/null @@ -1,9 +0,0 @@ -package com.ruoyi.game.wheel.contract.api.request; - -import lombok.Data; - -@Data -public class GetHistoryBetRequest { - private Integer pageNum; - private Integer pageSize; -} diff --git a/skins-service/game-wheel-service/src/main/java/com/ruoyi/game/wheel/contract/api/request/GetRoundHistoryRequest.java b/skins-service/game-wheel-service/src/main/java/com/ruoyi/game/wheel/contract/api/request/GetRoundHistoryRequest.java deleted file mode 100644 index f762b3f..0000000 --- a/skins-service/game-wheel-service/src/main/java/com/ruoyi/game/wheel/contract/api/request/GetRoundHistoryRequest.java +++ /dev/null @@ -1,9 +0,0 @@ -package com.ruoyi.game.wheel.contract.api.request; - -import lombok.Data; - -@Data -public class GetRoundHistoryRequest { - private Integer pageNum; - private Integer pageSize; -} diff --git a/skins-service/game-wheel-service/src/main/java/com/ruoyi/game/wheel/contract/api/response/DoBetResponse.java b/skins-service/game-wheel-service/src/main/java/com/ruoyi/game/wheel/contract/api/response/DoBetResponse.java deleted file mode 100644 index bf32e22..0000000 --- a/skins-service/game-wheel-service/src/main/java/com/ruoyi/game/wheel/contract/api/response/DoBetResponse.java +++ /dev/null @@ -1,13 +0,0 @@ -package com.ruoyi.game.wheel.contract.api.response; - -import lombok.AllArgsConstructor; -import lombok.Data; - -@Data -@AllArgsConstructor -public class DoBetResponse { - private Long roundId; - private String cost; - private String balance; - private String credits; -} diff --git a/skins-service/game-wheel-service/src/main/java/com/ruoyi/game/wheel/contract/api/response/GetGameConfigResponse.java b/skins-service/game-wheel-service/src/main/java/com/ruoyi/game/wheel/contract/api/response/GetGameConfigResponse.java deleted file mode 100644 index 66626ff..0000000 --- a/skins-service/game-wheel-service/src/main/java/com/ruoyi/game/wheel/contract/api/response/GetGameConfigResponse.java +++ /dev/null @@ -1,20 +0,0 @@ -package com.ruoyi.game.wheel.contract.api.response; - -import lombok.AllArgsConstructor; -import lombok.Data; - -import java.util.List; - -@Data -public class GetGameConfigResponse { - private String symbols; - private List symbolScores; - private List bets; - - @Data - @AllArgsConstructor - public static class SymbolScore { - private String symbol; - private Integer score; - } -} diff --git a/skins-service/game-wheel-service/src/main/java/com/ruoyi/game/wheel/contract/api/response/GetHistoryBetResponse.java b/skins-service/game-wheel-service/src/main/java/com/ruoyi/game/wheel/contract/api/response/GetHistoryBetResponse.java deleted file mode 100644 index a4c089d..0000000 --- a/skins-service/game-wheel-service/src/main/java/com/ruoyi/game/wheel/contract/api/response/GetHistoryBetResponse.java +++ /dev/null @@ -1,34 +0,0 @@ -package com.ruoyi.game.wheel.contract.api.response; - -import lombok.Data; - -import java.util.List; - -@Data -public class GetHistoryBetResponse { - /** - * 总记录数 - */ - private long total; - - /** - * 列表数据 - */ - private List rows; - - @Data - public static class RoundItem { - private Long roundId; - private String totalBet; - private String endTime; - private List items; - } - - @Data - public static class Item { - private String bet; - // 下注信息 - private String betSymbol; - private String win; - } -} diff --git a/skins-service/game-wheel-service/src/main/java/com/ruoyi/game/wheel/contract/api/response/GetRoundHistoryResponse.java b/skins-service/game-wheel-service/src/main/java/com/ruoyi/game/wheel/contract/api/response/GetRoundHistoryResponse.java deleted file mode 100644 index 9e429fe..0000000 --- a/skins-service/game-wheel-service/src/main/java/com/ruoyi/game/wheel/contract/api/response/GetRoundHistoryResponse.java +++ /dev/null @@ -1,26 +0,0 @@ -package com.ruoyi.game.wheel.contract.api.response; - -import lombok.Data; - -import java.util.List; - -@Data -public class GetRoundHistoryResponse { - - /** - * 总记录数 - */ - private long total; - - /** - * 列表数据 - */ - private List rows; - - @Data - public static class Item { - private Integer roundId; - private List resultSymbols; - private String endTime; - } -} diff --git a/skins-service/game-wheel-service/src/main/java/com/ruoyi/game/wheel/contract/api/response/GetRoundInfoResponse.java b/skins-service/game-wheel-service/src/main/java/com/ruoyi/game/wheel/contract/api/response/GetRoundInfoResponse.java deleted file mode 100644 index 7acb5d6..0000000 --- a/skins-service/game-wheel-service/src/main/java/com/ruoyi/game/wheel/contract/api/response/GetRoundInfoResponse.java +++ /dev/null @@ -1,48 +0,0 @@ -package com.ruoyi.game.wheel.contract.api.response; - -import lombok.AllArgsConstructor; -import lombok.Data; - -import java.util.List; - -@Data -public class GetRoundInfoResponse { - private Long roundId; - private Long serverTime; - // 本局转盘开始时间 - private Long startTime; - // 本句转盘下注结束时间 - private Long bettedTime; - // 开始旋转时间。目前bettedTime=spinTime - private Long spinTime; - // 结束时间 - private Long endTime; - /** - * @see com.ruoyi.game.wheel.enums.WheelRoundStatusEnum - */ - private String status; - private String result; - - // 总返奖 - private String totalWin; - // 每个符号的下注统计 - private List symbolBets; - // 请求用户的下注信息和开奖结果 - private List userResults; - - @Data - @AllArgsConstructor - public static class SymbolBet { - private String symbol; - private String totalBet; - private String userCount; - } - - @Data - @AllArgsConstructor - public static class UserResult { - private String bet; - private String betSymbol; - private String win; - } -} diff --git a/skins-service/game-wheel-service/src/main/java/com/ruoyi/game/wheel/controller/AdminWheelController.java b/skins-service/game-wheel-service/src/main/java/com/ruoyi/game/wheel/controller/AdminWheelController.java deleted file mode 100644 index 6d4c321..0000000 --- a/skins-service/game-wheel-service/src/main/java/com/ruoyi/game/wheel/controller/AdminWheelController.java +++ /dev/null @@ -1,33 +0,0 @@ -package com.ruoyi.game.wheel.controller; - -import com.ruoyi.common.core.controller.BaseController; -import com.ruoyi.common.core.domain.AjaxResult; -import com.ruoyi.game.wheel.domain.GameWheelGameConfig; -import com.ruoyi.game.wheel.service.AdminWheelService; -import io.swagger.annotations.Api; -import io.swagger.annotations.ApiOperation; -import lombok.extern.slf4j.Slf4j; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.web.bind.annotation.*; - -@Api(tags = "幸运转盘") -@Slf4j -@RestController -@RequestMapping("/admin/wheel") -public class AdminWheelController extends BaseController { - - @Autowired - private AdminWheelService adminWheelService; - - @ApiOperation("获取糖果游戏配置") - @GetMapping("/gameconfig") - public AjaxResult getGameConfig() { - return adminWheelService.getGameConfig(); - } - - @ApiOperation("更新糖果游戏配置") - @PostMapping("/gameconfig") - public AjaxResult updateGameConfig(@RequestBody GameWheelGameConfig request) { - return adminWheelService.updateGameConfig(request); - } -} diff --git a/skins-service/game-wheel-service/src/main/java/com/ruoyi/game/wheel/controller/ApiWheelController.java b/skins-service/game-wheel-service/src/main/java/com/ruoyi/game/wheel/controller/ApiWheelController.java deleted file mode 100644 index 7184364..0000000 --- a/skins-service/game-wheel-service/src/main/java/com/ruoyi/game/wheel/controller/ApiWheelController.java +++ /dev/null @@ -1,98 +0,0 @@ -package com.ruoyi.game.wheel.controller; - -import cn.hutool.core.util.ObjectUtil; -import com.ruoyi.common.annotation.UpdateUserCache; -import com.ruoyi.common.core.controller.BaseController; -import com.ruoyi.common.core.domain.R; -import com.ruoyi.game.wheel.contract.api.request.DoBetRequest; -import com.ruoyi.game.wheel.contract.api.request.GetHistoryBetRequest; -import com.ruoyi.game.wheel.contract.api.request.GetRoundHistoryRequest; -import com.ruoyi.game.wheel.contract.api.response.DoBetResponse; -import com.ruoyi.game.wheel.contract.api.response.GetGameConfigResponse; -import com.ruoyi.game.wheel.contract.api.response.GetHistoryBetResponse; -import com.ruoyi.game.wheel.contract.api.response.GetRoundHistoryResponse; -import com.ruoyi.game.wheel.contract.api.response.GetRoundInfoResponse; -import com.ruoyi.game.wheel.service.ApiWheelService; -import com.ruoyi.system.service.ISysConfigService; -import com.ruoyi.user.service.ApiUserService; -import io.swagger.annotations.Api; -import io.swagger.annotations.ApiOperation; -import lombok.extern.slf4j.Slf4j; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RestController; - -@Api(tags = "幸运转盘") -@Slf4j -@RestController -@RequestMapping("/api/wheel") -public class ApiWheelController extends BaseController { - - @Autowired - private ApiWheelService apiWheelService; - - @Autowired - private ApiUserService userService; - - @Autowired - private ISysConfigService sysConfigService; - - public Long checkLogin() { - Long userId; - try { - userId = getUserId(); - if (ObjectUtil.isEmpty(userId)) return 0L; - return userId; - } catch (Exception e) { - return 0L; - } - } - - @ApiOperation("获取游戏配置") - @GetMapping("/game_config") - public R getGameConfig() { - return apiWheelService.getGameConfig(); - } - - @ApiOperation("投注") - @GetMapping("/dobet") - @UpdateUserCache - public R doBet(DoBetRequest request) { - String websiteMaintenance = sysConfigService.selectConfigByKey("websiteMaintenance"); - if ("1".equals(websiteMaintenance)) { - return R.fail("网站维护中......"); - } - Long userId = checkLogin(); - if (userId == 0L) return R.fail("登录过期,请重新登录。"); - - var r = userService.checkRecharge(userId.intValue()); - if (R.isError(r)) { - return R.fail(r.getMsg()); - } - return apiWheelService.doBet(request, userId); - } - - @ApiOperation("获取最新一期游戏状态") - @GetMapping("/last_round_info") - public R getLastRoundInfo() { - Long userId = checkLogin(); - if (userId == 0L) return R.fail("登录过期,请重新登录。"); - return apiWheelService.getLastRoundInfo(userId); - } - - @ApiOperation("获取玩家的游戏历史记录") - @GetMapping("/history_bet_info") - public R getHistoryBetInfo(GetHistoryBetRequest request) { - Long userId = checkLogin(); - if (userId == 0L) return R.fail("登录过期,请重新登录。"); - return apiWheelService.getHistoryBetInfo(request, userId); - } - - @ApiOperation("获取转盘游戏历史记录") - @GetMapping("/round_history_bet_info") - public R getRoundHistoryBetInfo(GetRoundHistoryRequest request) { - return apiWheelService.getRoundHistoryInfo(request); - } - -} diff --git a/skins-service/game-wheel-service/src/main/java/com/ruoyi/game/wheel/domain/GameWheelGameConfig.java b/skins-service/game-wheel-service/src/main/java/com/ruoyi/game/wheel/domain/GameWheelGameConfig.java deleted file mode 100644 index 6df5ff1..0000000 --- a/skins-service/game-wheel-service/src/main/java/com/ruoyi/game/wheel/domain/GameWheelGameConfig.java +++ /dev/null @@ -1,56 +0,0 @@ -package com.ruoyi.game.wheel.domain; - -import lombok.AllArgsConstructor; -import lombok.Data; - -import java.util.List; - -@Data -public class GameWheelGameConfig { - // 玩法配置 - // 是否关闭游戏 false - private boolean switchOff; - // 可选的下注数 - private List bets; - // 每个符号的赔率设置 - private List symbolScores; - // ABCDEFGFEDCBA 转盘格子配置 - private String symbols; - - // 下注期55分钟 - private int bettingDuration = 10; - // 封盘期5秒 - private int bettedDuration = 0; - // 开奖期15秒。这是最少要求,如果命中免费多次开奖,则时间进行累加 - private int animationDuration = 5; - - // 盈利配置 - // 一次旋转,最多可用的奖池比例 0.9 total_bet * buff_ratio = reward_pool - private double bufferRatio; - // 一次旋转最多返回给玩家的总投注比例 0.85 reward_pool < total_bet * rtp - private double rtp; - - // 下面是体验相关,不影响盈利 - // 命中特殊效果的概率。 - private double specialEffectRatio; - // 每种特殊效果的概率。 - // [{"name": "系统赢", "ratio": 0.7},{"name": "免费旋转1次", "ratio": 0.2},{"name": "免费旋转2次", "ratio": 0.1}] - private List specialEffects; - - - - @Data - @AllArgsConstructor - public static class SpecialEffect { - private String name; - private double weight; - } - - @Data - @AllArgsConstructor - public static class SymbolScore { - private String symbol; - // 符号赔率 - private Integer score; - } -} diff --git a/skins-service/game-wheel-service/src/main/java/com/ruoyi/game/wheel/domain/GameWheelRound.java b/skins-service/game-wheel-service/src/main/java/com/ruoyi/game/wheel/domain/GameWheelRound.java deleted file mode 100644 index 26b1938..0000000 --- a/skins-service/game-wheel-service/src/main/java/com/ruoyi/game/wheel/domain/GameWheelRound.java +++ /dev/null @@ -1,44 +0,0 @@ -package com.ruoyi.game.wheel.domain; - - -import com.baomidou.mybatisplus.annotation.TableField; -import com.baomidou.mybatisplus.annotation.TableName; -import com.ruoyi.game.wheel.domain.handler.WheelRoundPhaseTimesTypeHandler; -import lombok.AllArgsConstructor; -import lombok.Builder; -import lombok.Data; -import lombok.NoArgsConstructor; -import lombok.experimental.Accessors; - -import java.io.Serializable; -import java.math.BigDecimal; -import java.time.LocalDateTime; -import java.util.List; - -@Data -@NoArgsConstructor -@AllArgsConstructor -@Accessors(chain = true) -@Builder -@TableName(value = "game_wheel_round", autoResultMap = true) -public class GameWheelRound implements Serializable { - - private Long id; - private String date; - private Long roundId; - private LocalDateTime startTime; - private LocalDateTime endTime; - @TableField(typeHandler = WheelRoundPhaseTimesTypeHandler.class) - private List phaseTimes; - private String symbols; - // 下面的字段只做统计用,不参与业务逻辑 - private BigDecimal totalBet; - private BigDecimal totalWin; - // 旋转的结果,包含中间旋转结果,每个结果用`,`分割。如S2,6,9,表示命中额外抽奖两次,6,9,表示命中额外抽奖一次 - private String result; - private Integer isManual; - private String status; - - private LocalDateTime create_time; - private LocalDateTime update_time; -} \ No newline at end of file diff --git a/skins-service/game-wheel-service/src/main/java/com/ruoyi/game/wheel/domain/GameWheelRoundBet.java b/skins-service/game-wheel-service/src/main/java/com/ruoyi/game/wheel/domain/GameWheelRoundBet.java deleted file mode 100644 index 734fd33..0000000 --- a/skins-service/game-wheel-service/src/main/java/com/ruoyi/game/wheel/domain/GameWheelRoundBet.java +++ /dev/null @@ -1,32 +0,0 @@ -package com.ruoyi.game.wheel.domain; - - -import com.baomidou.mybatisplus.annotation.TableName; -import lombok.AllArgsConstructor; -import lombok.Builder; -import lombok.Data; -import lombok.NoArgsConstructor; -import lombok.experimental.Accessors; - -import java.io.Serializable; -import java.math.BigDecimal; -import java.time.LocalDateTime; - -@Data -@NoArgsConstructor -@AllArgsConstructor -@Accessors(chain = true) -@Builder -@TableName(value = "game_wheel_round_bet") -public class GameWheelRoundBet implements Serializable { - - private Long id; - private Long roundId; - private Long userId; - private BigDecimal bet; - private String betSymbol; - private BigDecimal win; - - private LocalDateTime createTime; - private LocalDateTime updateTime; -} \ No newline at end of file diff --git a/skins-service/game-wheel-service/src/main/java/com/ruoyi/game/wheel/domain/GameWheelUser.java b/skins-service/game-wheel-service/src/main/java/com/ruoyi/game/wheel/domain/GameWheelUser.java deleted file mode 100644 index 66bc703..0000000 --- a/skins-service/game-wheel-service/src/main/java/com/ruoyi/game/wheel/domain/GameWheelUser.java +++ /dev/null @@ -1,31 +0,0 @@ -package com.ruoyi.game.wheel.domain; - - -import com.baomidou.mybatisplus.annotation.TableName; -import lombok.AllArgsConstructor; -import lombok.Builder; -import lombok.Data; -import lombok.NoArgsConstructor; -import lombok.experimental.Accessors; - -import java.io.Serializable; -import java.math.BigDecimal; -import java.time.LocalDateTime; - -@Data -@NoArgsConstructor -@AllArgsConstructor -@Accessors(chain = true) -@Builder -@TableName(value = "game_wheel_user") -public class GameWheelUser implements Serializable { - - private Long id; - private Long userId; - private BigDecimal totalBet; - private BigDecimal totalWin; - private Integer count; - - private LocalDateTime create_time; - private LocalDateTime update_time; -} \ No newline at end of file diff --git a/skins-service/game-wheel-service/src/main/java/com/ruoyi/game/wheel/domain/handler/WheelRoundPhaseTimesTypeHandler.java b/skins-service/game-wheel-service/src/main/java/com/ruoyi/game/wheel/domain/handler/WheelRoundPhaseTimesTypeHandler.java deleted file mode 100644 index 98f2fa8..0000000 --- a/skins-service/game-wheel-service/src/main/java/com/ruoyi/game/wheel/domain/handler/WheelRoundPhaseTimesTypeHandler.java +++ /dev/null @@ -1,14 +0,0 @@ -package com.ruoyi.game.wheel.domain.handler; - -import com.ruoyi.common.typehandler.JsonObjectHandler; -import org.apache.ibatis.type.JdbcType; -import org.apache.ibatis.type.MappedJdbcTypes; -import org.apache.ibatis.type.MappedTypes; - -import java.util.List; - - -@MappedJdbcTypes(JdbcType.VARCHAR) -@MappedTypes(List.class) -public class WheelRoundPhaseTimesTypeHandler extends JsonObjectHandler> { -} diff --git a/skins-service/game-wheel-service/src/main/java/com/ruoyi/game/wheel/enums/SpecialEffectEnum.java b/skins-service/game-wheel-service/src/main/java/com/ruoyi/game/wheel/enums/SpecialEffectEnum.java deleted file mode 100644 index 57a48f4..0000000 --- a/skins-service/game-wheel-service/src/main/java/com/ruoyi/game/wheel/enums/SpecialEffectEnum.java +++ /dev/null @@ -1,25 +0,0 @@ -package com.ruoyi.game.wheel.enums; - - -public enum SpecialEffectEnum { - SystemWin("系统赢"), - FreeSpin1("免费旋转1次"), - FreeSpin2("免费旋转2次"), - FreeSpin3("免费旋转3次"); - - private String desc; - - SpecialEffectEnum(String desc) { - this.desc = desc; - } - - @Override - public String toString() { - return this.name().toLowerCase(); - } - - - public boolean equals(String other) { - return this.desc.equals(other); - } -} \ No newline at end of file diff --git a/skins-service/game-wheel-service/src/main/java/com/ruoyi/game/wheel/enums/WheelRoundStatusEnum.java b/skins-service/game-wheel-service/src/main/java/com/ruoyi/game/wheel/enums/WheelRoundStatusEnum.java deleted file mode 100644 index 626a875..0000000 --- a/skins-service/game-wheel-service/src/main/java/com/ruoyi/game/wheel/enums/WheelRoundStatusEnum.java +++ /dev/null @@ -1,14 +0,0 @@ -package com.ruoyi.game.wheel.enums; - - -public enum WheelRoundStatusEnum { - BETTING, - @Deprecated - BETED, - SPINED; - - @Override - public String toString() { - return this.name().toLowerCase(); - } -} \ No newline at end of file diff --git a/skins-service/game-wheel-service/src/main/java/com/ruoyi/game/wheel/mapper/ApiGameWheelRoundBetMapper.java b/skins-service/game-wheel-service/src/main/java/com/ruoyi/game/wheel/mapper/ApiGameWheelRoundBetMapper.java deleted file mode 100644 index de12a84..0000000 --- a/skins-service/game-wheel-service/src/main/java/com/ruoyi/game/wheel/mapper/ApiGameWheelRoundBetMapper.java +++ /dev/null @@ -1,41 +0,0 @@ -package com.ruoyi.game.wheel.mapper; - -import com.baomidou.mybatisplus.core.mapper.BaseMapper; -import com.ruoyi.game.wheel.domain.GameWheelRoundBet; -import org.apache.ibatis.annotations.Mapper; -import org.apache.ibatis.annotations.Param; -import org.apache.ibatis.annotations.Select; - -import java.util.List; - -@Mapper -public interface ApiGameWheelRoundBetMapper extends BaseMapper { - @Select("select * from game_wheel_round_bet where round_id = #{roundId}") - List selectByRoundId(@Param("roundId") Long roundId); - - @Select("select * from game_wheel_round_bet where round_id = #{roundId} and bet_symbol = #{symbol}") - List selectByRoundIdAndTarget(@Param("roundId") Long roundId, @Param("symbol") String symbol); - - @Select("select * from game_wheel_round_bet where round_id = #{roundId} and user_id = #{uid} limit 1") - GameWheelRoundBet selectByRoundIdAndUid(@Param("roundId") Long roundId, @Param("uid") Long uid); - - @Select( - "SELECT rbt.round_id " + - "FROM game_wheel_round_bet rbt " + - "LEFT JOIN game_wheel_round rt ON rbt.round_id = rt.round_id " + - "WHERE rbt.user_id = #{userId} AND rt.date = #{date} " + - "GROUP BY rbt.round_id " + - "ORDER BY rbt.round_id DESC " + - "LIMIT #{offset}, #{pageSize}") - List selectHistoryBetRound(@Param("userId") Long userId, @Param("date") String date, @Param("offset") Integer offset, @Param("pageSize") Integer pageSize); - - @Select("" - ) - List selectHistoryBetInfo(@Param("userId") Long userId, @Param("roundIds") List roundIds); -} diff --git a/skins-service/game-wheel-service/src/main/java/com/ruoyi/game/wheel/mapper/ApiGameWheelRoundMapper.java b/skins-service/game-wheel-service/src/main/java/com/ruoyi/game/wheel/mapper/ApiGameWheelRoundMapper.java deleted file mode 100644 index bd505ab..0000000 --- a/skins-service/game-wheel-service/src/main/java/com/ruoyi/game/wheel/mapper/ApiGameWheelRoundMapper.java +++ /dev/null @@ -1,21 +0,0 @@ -package com.ruoyi.game.wheel.mapper; - -import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; -import com.baomidou.mybatisplus.core.mapper.BaseMapper; -import com.ruoyi.game.wheel.domain.GameWheelRound; -import org.apache.ibatis.annotations.Mapper; -import org.apache.ibatis.annotations.Param; -import org.apache.ibatis.annotations.Select; - - -@Mapper -public interface ApiGameWheelRoundMapper extends BaseMapper { - @Select("SELECT MAX(round_id) FROM game_wheel_round where `date` = #{today}") - public Long getTodayLastRoundId(@Param("today") String today); - - default GameWheelRound selectByRoundId(@Param("roundId") Long roundId) { - LambdaQueryWrapper wrapper = new LambdaQueryWrapper<>(); - wrapper.eq(GameWheelRound::getRoundId, roundId); - return selectOne(wrapper); - } -} diff --git a/skins-service/game-wheel-service/src/main/java/com/ruoyi/game/wheel/mapper/ApiGameWheelUserMapper.java b/skins-service/game-wheel-service/src/main/java/com/ruoyi/game/wheel/mapper/ApiGameWheelUserMapper.java deleted file mode 100644 index 4597de0..0000000 --- a/skins-service/game-wheel-service/src/main/java/com/ruoyi/game/wheel/mapper/ApiGameWheelUserMapper.java +++ /dev/null @@ -1,21 +0,0 @@ -package com.ruoyi.game.wheel.mapper; - -import com.baomidou.mybatisplus.core.mapper.BaseMapper; -import com.ruoyi.game.wheel.domain.GameWheelUser; -import org.apache.ibatis.annotations.Mapper; -import org.apache.ibatis.annotations.Param; -import org.apache.ibatis.annotations.Select; -import org.apache.ibatis.annotations.Update; - -import java.math.BigDecimal; - -@Mapper -public interface ApiGameWheelUserMapper extends BaseMapper { - @Select("select * from game_wheel_user where user_id = #{userId}") - GameWheelUser getByUserId(@Param("userId") Long userId); - - @Update("update game_wheel_user set total_bet = total_bet + #{totalBet}, total_win = total_win + #{totalWin}, count = count + #{count} where user_id = #{userId}") - int updateIncrement(@Param("totalBet") BigDecimal totalBet, - @Param("totalWin") BigDecimal totalWin, - @Param("count") Integer count, @Param("userId") Long userId); -} diff --git a/skins-service/game-wheel-service/src/main/java/com/ruoyi/game/wheel/model/cache/WheelRewardPoolCache.java b/skins-service/game-wheel-service/src/main/java/com/ruoyi/game/wheel/model/cache/WheelRewardPoolCache.java deleted file mode 100644 index d421bce..0000000 --- a/skins-service/game-wheel-service/src/main/java/com/ruoyi/game/wheel/model/cache/WheelRewardPoolCache.java +++ /dev/null @@ -1,16 +0,0 @@ -package com.ruoyi.game.wheel.model.cache; - -import lombok.Data; - -import java.math.BigDecimal; - -@Data -public class WheelRewardPoolCache { - /** - * 疯狂转盘奖池缓存 - * totalBet:累计总投注 - * totalWin:累计总返奖 - */ - private BigDecimal totalBet; - private BigDecimal totalWin; -} diff --git a/skins-service/game-wheel-service/src/main/java/com/ruoyi/game/wheel/model/cache/WheelRoundCache.java b/skins-service/game-wheel-service/src/main/java/com/ruoyi/game/wheel/model/cache/WheelRoundCache.java deleted file mode 100644 index be2d9b9..0000000 --- a/skins-service/game-wheel-service/src/main/java/com/ruoyi/game/wheel/model/cache/WheelRoundCache.java +++ /dev/null @@ -1,27 +0,0 @@ -package com.ruoyi.game.wheel.model.cache; - -import com.ruoyi.game.wheel.domain.GameWheelRound; -import com.ruoyi.game.wheel.domain.GameWheelRoundBet; -import lombok.Data; - -import java.io.Serializable; -import java.util.Map; - -@Data -public class WheelRoundCache implements Serializable { - private Long lastRoundId; - private GameWheelRound round; - - private Map betMap; - - public static String betKey(Long roundId, Long userId, String symbol) { - return String.format("%s_%s_%s", roundId, userId, symbol.toLowerCase()); - } - - public static String betKey(GameWheelRoundBet bet) { - if (bet == null) { - return ""; - } - return String.format("%s_%s_%s", bet.getRoundId(), bet.getUserId(), bet.getBetSymbol().toLowerCase()); - } -} diff --git a/skins-service/game-wheel-service/src/main/java/com/ruoyi/game/wheel/service/AdminWheelService.java b/skins-service/game-wheel-service/src/main/java/com/ruoyi/game/wheel/service/AdminWheelService.java deleted file mode 100644 index 37054fb..0000000 --- a/skins-service/game-wheel-service/src/main/java/com/ruoyi/game/wheel/service/AdminWheelService.java +++ /dev/null @@ -1,51 +0,0 @@ -package com.ruoyi.game.wheel.service; - -import com.ruoyi.common.core.domain.AjaxResult; -import com.ruoyi.game.wheel.cache.WheelRewardPoolCacheRepository; -import com.ruoyi.game.wheel.contract.admin.response.QueryWheelGameConfig; -import com.ruoyi.game.wheel.domain.GameWheelGameConfig; -import com.ruoyi.game.wheel.model.cache.WheelRewardPoolCache; -import io.swagger.annotations.ApiOperation; -import lombok.extern.slf4j.Slf4j; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.stereotype.Service; -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.PostMapping; -import org.springframework.web.bind.annotation.RequestBody; - -@Service -@Slf4j -public class AdminWheelService { - - private static final String EVENT_TAG = "幸运转盘"; - - - @Autowired - private CommonWheelService commonWheelService; - - @Autowired - private WheelRewardPoolCacheRepository wheelRewardPoolCacheRepository; - - @ApiOperation("获取糖果游戏配置") - @GetMapping("/gameconfig") - public AjaxResult getGameConfig() { - GameWheelGameConfig config = commonWheelService.getGameConfig(); - - QueryWheelGameConfig result = new QueryWheelGameConfig(); - result.setConfig(config); - - // 读取奖池 Redis 数据,与极速永恒保持一致 - WheelRewardPoolCache cache = wheelRewardPoolCacheRepository.getCache(); - result.setTotalBet(cache.getTotalBet().doubleValue()); - result.setTotalWin(cache.getTotalWin().doubleValue()); - - return AjaxResult.success(result); - } - - @ApiOperation("更新糖果游戏配置") - @PostMapping("/gameconfig") - public AjaxResult updateGameConfig(@RequestBody GameWheelGameConfig params) { - commonWheelService.updateGameConfig(params); - return AjaxResult.success(); - } -} diff --git a/skins-service/game-wheel-service/src/main/java/com/ruoyi/game/wheel/service/ApiWheelService.java b/skins-service/game-wheel-service/src/main/java/com/ruoyi/game/wheel/service/ApiWheelService.java deleted file mode 100644 index 50ceab3..0000000 --- a/skins-service/game-wheel-service/src/main/java/com/ruoyi/game/wheel/service/ApiWheelService.java +++ /dev/null @@ -1,745 +0,0 @@ -package com.ruoyi.game.wheel.service; - -import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; -import com.baomidou.mybatisplus.core.metadata.IPage; -import com.baomidou.mybatisplus.core.toolkit.Wrappers; -import com.baomidou.mybatisplus.extension.conditions.query.LambdaQueryChainWrapper; -import com.baomidou.mybatisplus.extension.plugins.pagination.Page; -import com.ruoyi.admin.mapper.TtUserMapper; -import com.ruoyi.admin.model.UpdateUserAccountBo; -import com.ruoyi.admin.service.TtUserService; -import com.ruoyi.common.core.domain.R; -import com.ruoyi.common.redis.config.RedisLock; -import com.ruoyi.common.utils.DateTimeUtils; -import com.ruoyi.common.utils.MoneyUtil; -import com.ruoyi.common.utils.RandomUtil; -import com.ruoyi.domain.common.constant.TtAccountRecordSource; -import com.ruoyi.domain.common.constant.UserType; -import com.ruoyi.domain.entity.sys.TtUser; -import com.ruoyi.framework.manager.AsyncManager; -import com.ruoyi.game.wheel.cache.WheelRoundCacheRepository; -import com.ruoyi.game.wheel.constants.CacheConstants; -import com.ruoyi.game.wheel.contract.api.request.DoBetRequest; -import com.ruoyi.game.wheel.contract.api.request.GetHistoryBetRequest; -import com.ruoyi.game.wheel.contract.api.request.GetRoundHistoryRequest; -import com.ruoyi.game.wheel.contract.api.response.*; -import com.ruoyi.game.wheel.domain.GameWheelGameConfig; -import com.ruoyi.game.wheel.domain.GameWheelRound; -import com.ruoyi.game.wheel.domain.GameWheelRoundBet; -import com.ruoyi.game.wheel.domain.GameWheelUser; -import com.ruoyi.game.wheel.enums.SpecialEffectEnum; -import com.ruoyi.game.wheel.enums.WheelRoundStatusEnum; -import com.ruoyi.game.wheel.mapper.ApiGameWheelRoundBetMapper; -import com.ruoyi.game.wheel.mapper.ApiGameWheelRoundMapper; -import com.ruoyi.game.wheel.mapper.ApiGameWheelUserMapper; -import com.ruoyi.game.wheel.model.cache.WheelRoundCache; -import com.ruoyi.game.wheel.cache.WheelRewardPoolCacheRepository; -import com.ruoyi.game.wheel.model.cache.WheelRewardPoolCache; -import com.ruoyi.thirdparty.common.service.ApiNoticeService; -import jakarta.annotation.PostConstruct; -import jakarta.annotation.PreDestroy; -import lombok.extern.slf4j.Slf4j; -import org.apache.commons.collections4.CollectionUtils; -import org.apache.commons.lang3.StringUtils; -import org.apache.commons.lang3.math.NumberUtils; -import org.apache.commons.lang3.tuple.Pair; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.stereotype.Service; -import org.springframework.transaction.interceptor.TransactionAspectSupport; - -import java.math.BigDecimal; -import java.time.Duration; -import java.time.LocalDate; -import java.time.LocalDateTime; -import java.time.format.DateTimeFormatter; -import java.util.*; -import java.util.concurrent.Executors; -import java.util.concurrent.ScheduledExecutorService; -import java.util.concurrent.TimeUnit; -import java.util.stream.Collectors; -import java.util.stream.IntStream; - -@Service -@Slf4j -public class ApiWheelService { - - private static final String EVENT_TAG = "幸运转盘"; - private ScheduledExecutorService scheduler; - - private static GameWheelGameConfig gameConfig; - - @Autowired - private RedisLock redisLock; - - @Autowired - private WheelRoundCacheRepository wheelRoundCacheRepository; - - @Autowired - private CommonWheelService commonWheelService; - @Autowired - private ApiGameWheelRoundMapper wheelRoundMapper; - @Autowired - private ApiGameWheelRoundBetMapper wheelRoundBetMapper; - @Autowired - private ApiGameWheelUserMapper wheelUserMapper; - - @Autowired - private TtUserMapper ttUserMapper; - - @Autowired - private TtUserService userService; - - @Autowired - private WheelRewardPoolCacheRepository wheelRewardPoolCacheRepository; - - @Autowired - private ApiNoticeService apiNoticeService; - - - @PostConstruct - public void init() { - // 创建单线程的定时任务执行器 - this.scheduler = Executors.newSingleThreadScheduledExecutor(); - - // 开启一个线程执行开始新一局的逻辑 - AsyncManager.me().run(() -> { - newRound(); - }); - } - - @PreDestroy - public void destroy() { - if (scheduler != null) { - scheduler.shutdown(); - } - } - - private boolean getLock() { - return redisLock.tryLock(CacheConstants.WHEEL_LOCK, 3, 5, TimeUnit.SECONDS); - } - - private void newRound() { - log.info("{} 开始新的转盘游戏", EVENT_TAG); - - if (!getLock()) { - log.info("{} newRound,获取锁失败,{} 秒后重试", EVENT_TAG, gameConfig.getBettingDuration()); - scheduler.schedule(this::newRound, gameConfig.getBettingDuration(), TimeUnit.SECONDS); - return; - } - try { - while (true) { - // 新的一局,检查更新游戏配置 - gameConfig = commonWheelService.getGameConfig(); - if (gameConfig.isSwitchOff()) { - log.debug("{} 游戏已关闭,{} 秒后重新开始", EVENT_TAG, 10); - wheelRoundCacheRepository.setCache(null); - Thread.sleep(Duration.ofSeconds(10)); - continue; - } - - String today = DateTimeUtils.dateTime(); - WheelRoundCache cache = wheelRoundCacheRepository.getCache(); - if (cache == null) { - cache = initCache(today); - } else { - // 检查是否跨天 - if (cache.getRound() != null && !today.equals(cache.getRound().getDate())) { - cache.setLastRoundId(0L); - } - } - - cache.setBetMap(new HashMap<>()); - cache.setLastRoundId(cache.getLastRoundId() + 1); - GameWheelRound round = createGameWheelRound(cache.getLastRoundId(), today); - if (round == null) { - continue; - } - cache.setRound(round); - wheelRoundCacheRepository.setCache(cache); - break; - } - } catch (Exception e) { - log.error("newRound错误", e); - } finally { - // 等待进入封盘期 - scheduler.schedule(this::drawReward, gameConfig.getBettingDuration(), TimeUnit.SECONDS); - redisLock.unlock(CacheConstants.WHEEL_LOCK); - } - - } - - private WheelRoundCache initCache(String today) { - WheelRoundCache cache = new WheelRoundCache(); - Long roundId = wheelRoundMapper.getTodayLastRoundId(today); - if (roundId == null) { - roundId = 0L; - } - cache.setLastRoundId(roundId); - return cache; - } - - private Collection getAllBets(WheelRoundCache cache) { - return cache.getBetMap().values(); - } - - // 进入开奖期 - private void drawReward() { - if (!getLock()) { - log.info("{} drawReward,获取锁失败,{} 秒后重试", EVENT_TAG, gameConfig.getBettedDuration()); - scheduler.schedule(this::drawReward, gameConfig.getBettedDuration(), TimeUnit.SECONDS); - return; - } - - try { - WheelRoundCache cache = wheelRoundCacheRepository.getCache(); - cache.getRound().setStatus(WheelRoundStatusEnum.SPINED.toString()); - - // 开奖 - Collection bets = getAllBets(cache); - BigDecimal totalBet = calculateTotalBet(bets); - cache.getRound().setTotalBet(totalBet); - /*List result = this.doSpin(cache.getRound(), bets, totalBet); - - cache.getRound().setEndTime(LocalDateTime.now().plusSeconds( - (long) gameConfig.getAnimationDuration() * result.size())); - cache.getRound().setResult(String.join(",", result));*/ - // 封盘后将本局总下注全额注入奖池统计 - if (totalBet.compareTo(BigDecimal.ZERO) > 0) { - wheelRewardPoolCacheRepository.incrementalBet(totalBet); - } - List result = this.doSpin(cache.getRound(), bets, totalBet); - - cache.getRound().setEndTime(LocalDateTime.now().plusSeconds( - (long) gameConfig.getAnimationDuration() * result.size())); - cache.getRound().setResult(String.join(",", result)); - - // 进行赔付 - this.processResult(cache, result); - - wheelRoundCacheRepository.setCache(cache); - wheelRoundMapper.updateById(cache.getRound()); - } catch (Exception e) { - log.error("drawReward错误", e); - } finally { - redisLock.unlock(CacheConstants.WHEEL_LOCK); - // 等待一个前端播放动画时间, 开启下一局 - scheduler.schedule(this::newRound, gameConfig.getAnimationDuration(), TimeUnit.SECONDS); - } - } - - private List selectBySymbol(WheelRoundCache cache, String symbol) { - return getAllBets(cache).stream(). - filter(v -> v.getBetSymbol().equals(symbol)).collect(Collectors.toList()); - } - - private void processResult(WheelRoundCache cache, List result) { - GameWheelRound round = cache.getRound(); - - for (String spinResult : result) { - int target = NumberUtils.toInt(spinResult, -1); - // 特殊效果不处理 - if (target < 0) { - continue; - } - - String symbol = String.valueOf(round.getSymbols().charAt(target)); - GameWheelGameConfig.SymbolScore score = gameConfig.getSymbolScores().stream() - .filter(s -> s.getSymbol().equals(symbol)).findFirst().orElse(null); - if (score == null) { - continue; - } - - double s = score.getScore(); - List betsOnTarget = selectBySymbol(cache, symbol); - if (CollectionUtils.isEmpty(betsOnTarget)) { - continue; - } - - for (GameWheelRoundBet bet : betsOnTarget) { - BigDecimal amount = bet.getBet().multiply(BigDecimal.valueOf(s)); - bet.setWin(amount); - } - } - - // 存储 - BigDecimal min = new BigDecimal("0.01"); - BigDecimal totalWin = BigDecimal.ZERO; - for (GameWheelRoundBet bet : getAllBets(cache)) { - BigDecimal amount = bet.getWin(); - if (amount.compareTo(BigDecimal.ZERO) > 0) { - totalWin = totalWin.add(amount); - userService.updateUserAccount(bet.getUserId().intValue(), amount, - TtAccountRecordSource.LUCKLY_WHEEL_REWARD); - } else { - bet.setWin(min); - userService.updateUserAccount(bet.getUserId().intValue(), min, - TtAccountRecordSource.LUCKLY_WHEEL_REWARD); - } - wheelRoundBetMapper.insert(bet); - wheelUserMapper.updateIncrement(BigDecimal.ZERO, amount, 0, bet.getUserId()); - } - round.setTotalWin(totalWin); - // 将本局实际总返奖写入奖池统计 - if (totalWin.compareTo(BigDecimal.ZERO) > 0) { - wheelRewardPoolCacheRepository.incrementalWin(totalWin); - } - - // ===== 新增:疯狂转盘结果通知(过滤机器人用户)===== - AsyncManager.me().run(() -> sendWheelResultNotice(cache)); - // ===== 新增疯狂转盘结果通知结束 ===== - } - - /** - * 疯狂转盘结果通知(过滤机器人用户) - * 示例:张三 疯狂转盘本局结果:投入 50 元,获得回报 120 元。 - */ - private void sendWheelResultNotice(WheelRoundCache cache) { - try { - Collection allBets = getAllBets(cache); - if (allBets.isEmpty()) return; - - // 获取所有下注用户ID,过滤机器人 - List betUserIds = allBets.stream() - .map(GameWheelRoundBet::getUserId) - .filter(Objects::nonNull) - .distinct() - .collect(Collectors.toList()); - List realUsers = new LambdaQueryChainWrapper<>(ttUserMapper) - .in(TtUser::getUserId, betUserIds) - .ne(TtUser::getUserType, UserType.ROBOT_USER.getCode()) - .list(); - - // 合并同一用户的多次下注(bet 和 win 分别累加) - Map betByUser = new HashMap<>(); - for (GameWheelRoundBet bet : allBets) { - if (bet.getUserId() == null) continue; - betByUser.merge(bet.getUserId(), bet, (a, b) -> { - a.setBet(a.getBet().add(b.getBet())); - a.setWin(a.getWin().add(b.getWin())); - return a; - }); - } - - for (TtUser realUser : realUsers) { - Long userId = Long.valueOf(realUser.getUserId()); - GameWheelRoundBet userBet = betByUser.get(userId); - if (userBet == null) continue; - BigDecimal betAmount = userBet.getBet() != null ? userBet.getBet() : BigDecimal.ZERO; - BigDecimal winAmount = userBet.getWin() != null ? userBet.getWin() : BigDecimal.ZERO; - String content = realUser.getNickName() + " 疯狂转盘本局结果:投入 " + betAmount + " 元,获得回报 " + winAmount + " 元。"; - apiNoticeService.sendNotice(userId, "疯狂转盘结果通知", content); - } - } catch (Exception e) { - log.error("疯狂转盘通知推送失败,error={}", e.getMessage(), e); - } - } - - private BigDecimal calculateTotalBet(Collection bets) { - return bets.stream() - .map(GameWheelRoundBet::getBet) - .reduce(BigDecimal.ZERO, BigDecimal::add); - } - - private BigDecimal payoutIf(Collection bets, String symbol) { - BigDecimal totalBet = bets.stream().filter(bet -> Objects.equals(bet.getBetSymbol(), symbol)) - .map(GameWheelRoundBet::getBet) - .reduce(BigDecimal.ZERO, BigDecimal::add); - - return gameConfig.getSymbolScores().stream() - .filter(s -> s.getSymbol().equals(String.valueOf(symbol))).map(GameWheelGameConfig.SymbolScore::getScore) - .map(score -> totalBet.multiply(BigDecimal.valueOf(score))) - .findFirst().orElse(BigDecimal.valueOf(1_0000_0000)); - } - - private Integer getRandomScotterIndex(String symbol) { - List indices = new ArrayList<>(); - for (int i = 0; i < symbol.length(); i++) { - if (symbol.charAt(i) != 'S') indices.add(i); - } - return RandomUtil.choice(indices); - } - - private List doSpin(GameWheelRound round, Collection bets, BigDecimal totalBet) { - List result = new ArrayList<>(); - - // 无人下注,踢出特殊符号,随机开奖 - if (totalBet.compareTo(BigDecimal.ZERO) == 0) { - List validTargets = IntStream.range(0, round.getSymbols().length()) - .filter(target -> round.getSymbols().charAt(target) != 'S') - .boxed() - .collect(Collectors.toList()); - - int target = RandomUtil.choice(validTargets); - return Collections.singletonList(String.valueOf(target)); - } - - // 计算每个选区的净利润 - List> candidates = new ArrayList<>(); - for (int num = 0; num < gameConfig.getSymbols().length(); num++) { - char symbol = gameConfig.getSymbols().charAt(num); - // 特殊符号不计算赔付 - if (symbol == 'S') { - continue; - } - BigDecimal payout = payoutIf(bets, String.valueOf(symbol)); - BigDecimal profit = totalBet.subtract(payout); - candidates.add(Pair.of(num, profit)); - } - - // 判断是否能命中特殊效果 - String specialEffectName = ""; - if (RandomUtil.random() < gameConfig.getSpecialEffectRatio()) { - // 命中特殊效果 - double[] weights = gameConfig.getSpecialEffects().stream().mapToDouble(GameWheelGameConfig.SpecialEffect::getWeight).toArray(); - GameWheelGameConfig.SpecialEffect specialEffect = RandomUtil.choices(gameConfig.getSpecialEffects(), weights, 1).get(0); - specialEffectName = specialEffect.getName(); - } - - if (SpecialEffectEnum.SystemWin.equals(specialEffectName)) { - Integer index = getRandomScotterIndex(round.getSymbols()); - result.add(index + ":S0"); - return result; - } - int spinCount = 1; - if (SpecialEffectEnum.FreeSpin1.equals(specialEffectName)) { - Integer index = getRandomScotterIndex(round.getSymbols()); - result.add(index + ":S1"); - spinCount = 1; - } - if (SpecialEffectEnum.FreeSpin2.equals(specialEffectName)) { - Integer index = getRandomScotterIndex(round.getSymbols()); - result.add(index + ":S2"); - spinCount = 2; - } - if (SpecialEffectEnum.FreeSpin3.equals(specialEffectName)) { - Integer index = getRandomScotterIndex(round.getSymbols()); - result.add(index + ":S3"); - spinCount = 3; - } - - /*for (int i = 0; i < spinCount; i++) { - List> profitableCandidates = candidates.stream() - .filter(v -> v.getRight().compareTo(BigDecimal.ZERO) > 0).collect(Collectors.toList()); - if (profitableCandidates.isEmpty()) { - // 没有盈利的选区, 选择一个亏本最小的开 - Pair minLoss = candidates.stream() - .min(Comparator.comparing(Pair::getRight)).orElse(null); - assert minLoss != null; - result.add(minLoss.getLeft() + ""); - } - - // 有盈利的选区, 随机选择一个开 - result.add(RandomUtil.choice(profitableCandidates).getLeft() + ""); - }*/ - /*for (int i = 0; i < spinCount; i++) { - // 筛选出赔付率 < 0.8 的格子(即赔付 < 总下注 * 0.8,对系统盈利) - BigDecimal rtpCap = totalBet.multiply(BigDecimal.valueOf(0.8));//BigDecimal.valueOf(gameConfig.getRtp())系统配置0.85暂时不改 - List> rtpSafeCandidates = candidates.stream() - .filter(v -> { - // 计算赔付金额 - BigDecimal payout = totalBet.subtract(v.getRight()); - // 判断赔付金额是否小于 rtpCap(rpt上限 总下注 * 0.8) - return payout.compareTo(rtpCap) < 0; - }) - .collect(Collectors.toList()); - - if (!rtpSafeCandidates.isEmpty()) { - // 有多个赔率 < 0.8 的格子,随机选一个(不一定选赔付最小的) - result.add(RandomUtil.choice(rtpSafeCandidates).getLeft() + ""); - } else { - // 所有格子赔付都 >= 0.8,选赔付最小的(亏损最少) - Pair minLoss = candidates.stream() - .max(Comparator.comparing(Pair::getRight)).orElse(null); - assert minLoss != null; - result.add(minLoss.getLeft() + ""); - } - }*/ - // ===== 奖池 RTP 逻辑===== - // 读取全局奖池累计数据 - WheelRewardPoolCache poolCache = wheelRewardPoolCacheRepository.getCache(); - BigDecimal poolTotalBet = poolCache.getTotalBet(); - BigDecimal poolTotalWin = poolCache.getTotalWin(); - - // 奖池余额 = 累计总投注 - 累计总返奖 - BigDecimal jackpotBalance = poolTotalBet.subtract(poolTotalWin); - if (jackpotBalance.compareTo(BigDecimal.ZERO) < 0) { - jackpotBalance = BigDecimal.ZERO; - } - - // 本局赔付上限 = 奖池余额 * 0.8 - BigDecimal payoutCap = jackpotBalance.multiply(BigDecimal.valueOf(0.8)); - - for (int i = 0; i < spinCount; i++) { - // 筛选赔付 <= 上限 - List> safeCandidates = candidates.stream() - .filter(v -> { - // v.getRight() 是 profit = totalBet - payout,所以 payout = totalBet - profit - BigDecimal payout = totalBet.subtract(v.getRight()); - return payout.compareTo(payoutCap) <= 0; - }) - .collect(Collectors.toList()); - - if (!safeCandidates.isEmpty()) { - // 有满足条件的格子,随机选一个 - result.add(RandomUtil.choice(safeCandidates).getLeft() + ""); - } else { - // 全部格子赔付都超过 payoutCap,选赔率最小的(profit 最大 = 系统亏损最少) - Pair minPayout = candidates.stream() - .max(Comparator.comparing(Pair::getRight)).orElse(null); - assert minPayout != null; - result.add(minPayout.getLeft() + ""); - } - } - return result; - - } - - private GameWheelRound createGameWheelRound(long roundId, String today) { - - GameWheelRound round = new GameWheelRound(); - round.setRoundId(roundId); - round.setDate(today); - round.setStartTime(LocalDateTime.now()); - round.setPhaseTimes(Arrays.asList( - DateTimeUtils.now() + gameConfig.getBettingDuration(), // 开始封盘 - DateTimeUtils.now() + gameConfig.getBettingDuration() + gameConfig.getBettedDuration()) // 开始开奖 - ); - round.setEndTime(LocalDateTime.now().plusSeconds(gameConfig.getBettingDuration() - + gameConfig.getBettedDuration() - + gameConfig.getAnimationDuration() - )); - round.setSymbols(gameConfig.getSymbols()); - round.setTotalBet(BigDecimal.ZERO); - round.setTotalWin(BigDecimal.ZERO); - round.setResult(""); - round.setIsManual(0); - round.setStatus(WheelRoundStatusEnum.BETTING.toString()); - - try { - wheelRoundMapper.insert(round); - } catch (Exception e) { - log.error("{} 创建新局失败", EVENT_TAG, e); - wheelRoundCacheRepository.setCache(null); - return null; - } - - - return round; - } - - public R getGameConfig() { - GameWheelGameConfig config = commonWheelService.getGameConfig(); - GetGameConfigResponse resp = new GetGameConfigResponse(); - resp.setSymbols(config.getSymbols()); - resp.setBets(config.getBets()); - resp.setSymbolScores(config.getSymbolScores().stream() - .map(s -> new GetGameConfigResponse.SymbolScore(s.getSymbol(), s.getScore())) - .collect(Collectors.toList())); - return R.ok(resp); - } - - // 实时更新ttUser|流水和wheelUser信息 - public R doBet(DoBetRequest request, Long uid) { - if (request.getBet() == null || request.getSymbol() == null) { - return R.fail("参数错误"); - } - if (!gameConfig.getBets().contains(request.getBet())) { - return R.fail("下注金额错误"); - } - if (!gameConfig.getSymbols().contains(request.getSymbol())) { - return R.fail("下注符号错误"); - } - - WheelRoundCache cache = wheelRoundCacheRepository.getCache(); - if (cache == null || cache.getRound() == null) { - return R.fail("游戏未开始"); - } - if (!cache.getRound().getStatus().equals(WheelRoundStatusEnum.BETTING.toString())) { - return R.fail("游戏不在投注期"); - } - - Boolean lock = getLock(); - if (!Boolean.TRUE.equals(lock)) { - return R.fail("请求频繁,加锁失败"); - } - try { - R updateResult = userService.updateUserAccount(uid.intValue(), - BigDecimal.valueOf(request.getBet()).negate(), - TtAccountRecordSource.LUCKLY_WHEEL_SPIN); - if (R.isError(updateResult)) { - return R.fail(updateResult.getMsg()); - } - - GameWheelRoundBet bet = cache.getBetMap().get(WheelRoundCache.betKey(cache.getRound().getRoundId(), - uid, request.getSymbol())); - if (bet != null) { - // 追加下注 - bet.setBet(bet.getBet().add(BigDecimal.valueOf(request.getBet()))); - } else { - bet = new GameWheelRoundBet(); - bet.setRoundId(cache.getRound().getRoundId()); - bet.setUserId(uid); - bet.setBet(BigDecimal.valueOf(request.getBet())); - bet.setBetSymbol(request.getSymbol()); - bet.setWin(BigDecimal.ZERO); - } - cache.getBetMap().put(WheelRoundCache.betKey(bet), bet); - wheelRoundCacheRepository.setCache(cache); - - if (wheelUserMapper.getByUserId(uid) == null) { - initWheelUser(uid); - } - wheelUserMapper.updateIncrement(bet.getBet(), BigDecimal.ZERO, 1, uid); - - return R.ok(new DoBetResponse(cache.getRound().getRoundId(), request.getBet().toString(), - MoneyUtil.toStr(updateResult.getData().getAccountAmount()), - MoneyUtil.toStr(updateResult.getData().getAccountCredits())) - ); - } catch (Exception e) { - TransactionAspectSupport.currentTransactionStatus().setRollbackOnly(); - log.error("错误", e); - return R.fail("内部错误,请联系管理员"); - } finally { - redisLock.unlock(CacheConstants.WHEEL_LOCK); - } - } - - private void initWheelUser(Long uid) { - GameWheelUser user = new GameWheelUser(); - user.setUserId(uid); - user.setTotalBet(BigDecimal.ZERO); - user.setTotalWin(BigDecimal.ZERO); - user.setCount(0); - wheelUserMapper.insert(user); - } - - public R getLastRoundInfo(Long uid) { - WheelRoundCache cache = wheelRoundCacheRepository.getCache(); - if (cache == null || cache.getRound() == null) { - return R.fail("游戏未开始"); - } - return R.ok(buildRoundResp(cache, cache.getRound(), uid)); - } - - private GetRoundInfoResponse buildRoundResp(WheelRoundCache cache, GameWheelRound round, Long uid) { - GetRoundInfoResponse resp = new GetRoundInfoResponse(); - resp.setRoundId(round.getRoundId()); - resp.setServerTime(DateTimeUtils.now()); - resp.setStartTime(DateTimeUtils.toSeconds(round.getStartTime())); - resp.setEndTime(DateTimeUtils.toSeconds(round.getEndTime())); - resp.setBettedTime(round.getPhaseTimes().get(0)); - resp.setSpinTime(round.getPhaseTimes().get(1)); - resp.setStatus(round.getStatus()); - resp.setResult(round.getResult()); - resp.setTotalWin(MoneyUtil.toStr(round.getTotalWin())); - - // 统计每个符号的下注数据 - Map> symbolMap = cache.getBetMap().values().stream().collect(Collectors.groupingBy(GameWheelRoundBet::getBetSymbol)); - List symbolBets = new ArrayList<>(); - symbolMap.forEach((symbol, bets) -> { - String totalBet = MoneyUtil.toStr(bets.stream().map(GameWheelRoundBet::getBet).reduce(BigDecimal.ZERO, BigDecimal::add)); - symbolBets.add(new GetRoundInfoResponse.SymbolBet(symbol, totalBet, String.valueOf(bets.size()))); - }); - resp.setSymbolBets(symbolBets); - - List bets = cache.getBetMap().values().stream().filter(v -> v.getUserId().equals(uid)) - .map(bet -> { - return new GetRoundInfoResponse.UserResult( - MoneyUtil.toStr(bet.getBet()), - bet.getBetSymbol(), - MoneyUtil.toStr(bet.getWin())); - }) - .collect(Collectors.toList()); - resp.setUserResults(bets); - return resp; - } - - public R getHistoryBetInfo(GetHistoryBetRequest request, Long userId) { - if (request.getPageNum() == null || request.getPageNum() <= 0) { - request.setPageNum(1); - } - if (request.getPageSize() == null || request.getPageSize() <= 0) { - request.setPageSize(10); - } - List roundIds = wheelRoundBetMapper.selectHistoryBetRound(userId, DateTimeUtils.dateTime(), (request.getPageNum() - 1) * request.getPageSize(), request.getPageSize()); - - if (CollectionUtils.isEmpty(roundIds)) { - GetHistoryBetResponse resp = new GetHistoryBetResponse(); - resp.setRows(new ArrayList<>()); - resp.setTotal(0); - return R.ok(resp); - } - - List rounds = wheelRoundBetMapper.selectHistoryBetInfo(userId, roundIds); - Map> roundMap = rounds.stream().collect(Collectors.groupingBy(GameWheelRoundBet::getRoundId)); - - GetHistoryBetResponse resp = new GetHistoryBetResponse(); - resp.setTotal(rounds.size() + 1); - resp.setRows(new ArrayList<>()); - - DateTimeFormatter formatter = DateTimeFormatter.ofPattern("MM-dd HH:mm:ss"); - for (Integer roundId : roundIds) { - GetHistoryBetResponse.RoundItem item = new GetHistoryBetResponse.RoundItem(); - item.setRoundId(roundId.longValue()); - item.setEndTime(roundMap.get(roundId.longValue()).get(0).getUpdateTime().format(formatter)); - - List betitems = new ArrayList<>(); - BigDecimal totalBet = BigDecimal.ZERO; - for (GameWheelRoundBet betItem : roundMap.get(roundId.longValue())) { - GetHistoryBetResponse.Item i = new GetHistoryBetResponse.Item(); - i.setBet(MoneyUtil.toStr(betItem.getBet())); - totalBet = totalBet.add(betItem.getBet()); - i.setBetSymbol(betItem.getBetSymbol()); - i.setWin(MoneyUtil.toStr(betItem.getWin())); - betitems.add(i); - } - item.setTotalBet(MoneyUtil.toStr(totalBet)); - item.setItems(betitems); - resp.getRows().add(item); - } - - return R.ok(resp); - } - - public R getRoundHistoryInfo(GetRoundHistoryRequest request) { - if (request.getPageNum() == null || request.getPageNum() <= 0) { - request.setPageNum(1); - } - if (request.getPageSize() == null || request.getPageSize() <= 0) { - request.setPageSize(10); - } - - Page page = new Page<>(request.getPageNum(), request.getPageSize()); - page.setOptimizeCountSql(false); - LambdaQueryWrapper wrapper = Wrappers.lambdaQuery(); - // 只获取今天的游戏回合数据 - LocalDate today = LocalDate.now(); - LocalDateTime startOfDay = today.atStartOfDay(); - LocalDateTime endOfDay = today.plusDays(1).atStartOfDay().minusSeconds(1); - wrapper.between(GameWheelRound::getStartTime, startOfDay, endOfDay); - wrapper.orderByDesc(GameWheelRound::getStartTime); - IPage listPage = wheelRoundMapper.selectPage(page, wrapper); - List userList = listPage.getRecords(); - - - GetRoundHistoryResponse response = new GetRoundHistoryResponse(); - DateTimeFormatter formatter = DateTimeFormatter.ofPattern("MM-dd HH:mm:ss"); - response.setRows(userList.stream().map(v -> { - GetRoundHistoryResponse.Item item = new GetRoundHistoryResponse.Item(); - item.setRoundId(v.getRoundId().intValue()); - item.setEndTime(v.getEndTime().format(formatter)); - item.setResultSymbols(new ArrayList<>()); - if (StringUtils.isNotBlank(v.getResult())) { - for (String i : v.getResult().split(",")) { - int index = NumberUtils.toInt(i.split(":")[0], 0); - item.getResultSymbols().add(String.valueOf(v.getSymbols().charAt(index))); - } - } - - return item; - }).collect(Collectors.toList())); - response.setTotal(listPage.getTotal()); - - return R.ok(response); - } -} diff --git a/skins-service/game-wheel-service/src/main/java/com/ruoyi/game/wheel/service/CommonWheelService.java b/skins-service/game-wheel-service/src/main/java/com/ruoyi/game/wheel/service/CommonWheelService.java deleted file mode 100644 index 183807f..0000000 --- a/skins-service/game-wheel-service/src/main/java/com/ruoyi/game/wheel/service/CommonWheelService.java +++ /dev/null @@ -1,76 +0,0 @@ -package com.ruoyi.game.wheel.service; - - -import com.ruoyi.common.utils.json.SnakeCaseJsonUtils; -import com.ruoyi.game.wheel.domain.GameWheelGameConfig; -import com.ruoyi.system.domain.SysConfig; -import com.ruoyi.system.mapper.SysConfigMapper; -import lombok.extern.slf4j.Slf4j; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.stereotype.Service; - -import java.util.Arrays; - -@Service -@Slf4j -public class CommonWheelService { - @Autowired - private SysConfigMapper sysConfigMapper; - - public GameWheelGameConfig getGameConfig() { - SysConfig sysConfig = sysConfigMapper.checkConfigKeyUnique("game.wheel.setting"); - if (sysConfig == null) { - GameWheelGameConfig config = new GameWheelGameConfig(); - config.setSwitchOff(false); - config.setBets(Arrays.asList(5, 10, 20, 50, 100, 200, 500)); - config.setSymbolScores(Arrays.asList( - new GameWheelGameConfig.SymbolScore("S", 0), - new GameWheelGameConfig.SymbolScore("A", 10), - new GameWheelGameConfig.SymbolScore("B", 10), - new GameWheelGameConfig.SymbolScore("C", 10), - new GameWheelGameConfig.SymbolScore("D", 10), - new GameWheelGameConfig.SymbolScore("E", 10), - new GameWheelGameConfig.SymbolScore("F", 10), - new GameWheelGameConfig.SymbolScore("G", 10) - )); - config.setSymbols("SSAABBCCDDEEFFGG"); - config.setBufferRatio(0.9); - config.setRtp(0.85); - - config.setSpecialEffectRatio(0.05); - config.setSpecialEffects(Arrays.asList( - new GameWheelGameConfig.SpecialEffect("系统赢", 0.5), - new GameWheelGameConfig.SpecialEffect("免费旋转1次", 0.25), - new GameWheelGameConfig.SpecialEffect("免费旋转2次", 0.15), - new GameWheelGameConfig.SpecialEffect("免费旋转3次", 0.10) - )); - - - sysConfig = new SysConfig(); - sysConfig.setConfigName("幸运转盘游戏配置"); - sysConfig.setConfigKey("game.wheel.setting"); - sysConfig.setConfigValue(SnakeCaseJsonUtils.toSnakeCaseJson(config)); - sysConfig.setConfigType("N"); - - sysConfigMapper.insertConfig(sysConfig); - return config; - } - return SnakeCaseJsonUtils.fromSnakeCaseJson(sysConfig.getConfigValue(), GameWheelGameConfig.class); - } - - public void updateGameConfig(GameWheelGameConfig config) { - SysConfig sysConfig = sysConfigMapper.checkConfigKeyUnique("game.wheel.setting"); - if (sysConfig == null) { - sysConfig = new SysConfig(); - sysConfig.setConfigName("幸运转盘游戏配置"); - sysConfig.setConfigKey("game.wheel.setting"); - sysConfig.setConfigType("N"); - sysConfig.setConfigValue(SnakeCaseJsonUtils.toSnakeCaseJson(config)); - sysConfigMapper.insertConfig(sysConfig); - } else { - sysConfig.setConfigValue(SnakeCaseJsonUtils.toSnakeCaseJson(config)); - sysConfigMapper.updateConfig(sysConfig); - } - - } -} diff --git a/skins-service/pom.xml b/skins-service/pom.xml index 8b5be74..c11425d 100644 --- a/skins-service/pom.xml +++ b/skins-service/pom.xml @@ -18,7 +18,6 @@ service-playingmethod service-task game-sugar-service - game-wheel-service