From be6f79a634727b59c6a40e3fffa989b5de1b0ec7 Mon Sep 17 00:00:00 2001 From: Helius <wangdoubleone@gmail.com> Date: Wed, 24 Nov 2021 16:54:01 +0800 Subject: [PATCH] Merge branch 'fish' of http://120.27.238.55:7000/r/exchange into fish --- src/main/java/com/xcong/excoin/modules/fish/dao/CannonAccountMoneyChangeDao.java | 7 src/main/java/com/xcong/excoin/modules/fish/dao/MemberAccountGoldDao.java | 17 + src/main/java/com/xcong/excoin/modules/fish/dto/CannonExchangeDto.java | 17 + src/main/resources/mapper/fish/MemberAccountGoldDao.xml | 35 ++ src/main/resources/mapper/fish/CannonSettingDao.xml | 17 + src/main/java/com/xcong/excoin/modules/fish/controller/MemberCannonController.java | 95 ++++++ src/main/java/com/xcong/excoin/modules/fish/dto/GoldExchangeDto.java | 18 + src/main/resources/mapper/fish/CannonGameRecordDao.xml | 6 src/main/java/com/xcong/excoin/modules/fish/dao/CannonSettingDao.java | 20 + src/main/java/com/xcong/excoin/modules/fish/service/impl/MemberCannonServiceImpl.java | 263 +++++++++++++++++ src/main/java/com/xcong/excoin/modules/fish/dto/GetCannonsDto.java | 23 + src/main/java/com/xcong/excoin/modules/fish/vo/OwnCannonVo.java | 26 + src/main/java/com/xcong/excoin/modules/fish/dto/FishingDto.java | 21 + src/main/java/com/xcong/excoin/modules/fish/entity/CannonAccountMoneyChange.java | 30 ++ src/main/java/com/xcong/excoin/modules/fish/dto/CoinGoldExchangeDto.java | 22 + src/main/java/com/xcong/excoin/modules/fish/entity/CannonOwnRecord.java | 27 + src/main/java/com/xcong/excoin/modules/fish/vo/GoldAccountVo.java | 20 + src/main/java/com/xcong/excoin/modules/fish/entity/MemberAccountGold.java | 24 + src/main/java/com/xcong/excoin/modules/fish/entity/CannonGameRecord.java | 29 + src/main/java/com/xcong/excoin/modules/fish/entity/CannonExchangeRatio.java | 20 + src/main/java/com/xcong/excoin/modules/fish/vo/CannonSettingVo.java | 24 + src/main/java/com/xcong/excoin/modules/fish/dao/CannonGameRecordDao.java | 7 src/main/java/com/xcong/excoin/modules/fish/service/MemberCannonService.java | 28 + src/main/java/com/xcong/excoin/modules/fish/entity/CannonSetting.java | 25 + src/main/java/com/xcong/excoin/modules/fish/dao/CannonOwnRecordDao.java | 17 + src/main/resources/mapper/fish/CannonOwnRecordDao.xml | 20 + src/main/resources/mapper/fish/CannonAccountMoneyChangeDao.xml | 6 27 files changed, 864 insertions(+), 0 deletions(-) diff --git a/src/main/java/com/xcong/excoin/modules/fish/controller/MemberCannonController.java b/src/main/java/com/xcong/excoin/modules/fish/controller/MemberCannonController.java new file mode 100644 index 0000000..eb2af90 --- /dev/null +++ b/src/main/java/com/xcong/excoin/modules/fish/controller/MemberCannonController.java @@ -0,0 +1,95 @@ +package com.xcong.excoin.modules.fish.controller; + +import com.xcong.excoin.common.response.Result; +import com.xcong.excoin.modules.coin.parameter.vo.MemberWalletAgentInfoVo; +import com.xcong.excoin.modules.coin.parameter.vo.OrderWalletCoinDealVo; +import com.xcong.excoin.modules.fish.dto.*; +import com.xcong.excoin.modules.fish.service.MemberCannonService; +import com.xcong.excoin.modules.fish.vo.CannonSettingVo; +import com.xcong.excoin.modules.fish.vo.GoldAccountVo; +import com.xcong.excoin.modules.fish.vo.OwnCannonVo; +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiOperation; +import io.swagger.annotations.ApiResponse; +import io.swagger.annotations.ApiResponses; +import lombok.extern.slf4j.Slf4j; +import org.springframework.web.bind.annotation.*; + +import javax.annotation.Resource; + +@Slf4j +@Api(value = "MemberCannonController", tags = "炮台接口类") +@RestController +@RequestMapping(value = "/api/account") +public class MemberCannonController { + + @Resource + private MemberCannonService memberCannonService; + + /** + * 获取金币账户 + */ + @ApiOperation(value="获取金币账户", notes="获取金币账户") + @ApiResponses({@ApiResponse( code = 200, message = "success", response = GoldAccountVo.class)}) + @GetMapping(value="/getGoldAccount") + public Result getGoldAccount() { + return memberCannonService.getGoldAccount(); + } + + /** + * 代币金币互转 + */ + @ApiOperation(value = "代币金币互转") + @PostMapping(value = "/coinGoldExchange") + public Result coinGoldExchange(@RequestBody CoinGoldExchangeDto coinGoldExchangeDto) { + return memberCannonService.coinGoldExchange(coinGoldExchangeDto); + } + + /** + * USDT购买金币 + */ +// @ApiOperation(value = "USDT购买金币") +// @PostMapping(value = "/goldExchange") +// public Result goldExchange(@RequestBody GoldExchangeDto goldExchangeDto) { +// return memberCannonService.goldExchange(goldExchangeDto); +// } + + /** + * 获取大炮列表 + */ + @ApiOperation(value = "获取大炮列表") + @ApiResponses({@ApiResponse( code = 200, message = "success", response = CannonSettingVo.class)}) + @PostMapping(value = "/getCannons") + public Result getCannons(@RequestBody GetCannonsDto getCannonsDto) { + return memberCannonService.getCannons(getCannonsDto); + } + + /** + *兑换大炮 + */ + @ApiOperation(value = "兑换大炮") + @PostMapping(value = "/cannonExchange") + public Result cannonExchange(@RequestBody CannonExchangeDto cannonExchangeDto) { + return memberCannonService.cannonExchange(cannonExchangeDto); + } + + /** + * 获取用户拥有的炮台 + */ + @ApiOperation(value="获取用户拥有的炮台", notes="获取用户拥有的炮台") + @ApiResponses({@ApiResponse( code = 200, message = "success", response = OwnCannonVo.class)}) + @GetMapping(value="/getOwnCannon") + public Result getOwnCannon() { + return memberCannonService.getOwnCannon(); + } + + /** + * 捕鱼 + */ + @ApiOperation(value = "捕鱼") + @PostMapping(value = "/fishing") + public Result fishing(@RequestBody FishingDto fishingDto) { + return memberCannonService.fishing(fishingDto); + } + +} diff --git a/src/main/java/com/xcong/excoin/modules/fish/dao/CannonAccountMoneyChangeDao.java b/src/main/java/com/xcong/excoin/modules/fish/dao/CannonAccountMoneyChangeDao.java new file mode 100644 index 0000000..2aa5da3 --- /dev/null +++ b/src/main/java/com/xcong/excoin/modules/fish/dao/CannonAccountMoneyChangeDao.java @@ -0,0 +1,7 @@ +package com.xcong.excoin.modules.fish.dao; + +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import com.xcong.excoin.modules.fish.entity.CannonAccountMoneyChange; + +public interface CannonAccountMoneyChangeDao extends BaseMapper<CannonAccountMoneyChange> { +} diff --git a/src/main/java/com/xcong/excoin/modules/fish/dao/CannonGameRecordDao.java b/src/main/java/com/xcong/excoin/modules/fish/dao/CannonGameRecordDao.java new file mode 100644 index 0000000..f4a8735 --- /dev/null +++ b/src/main/java/com/xcong/excoin/modules/fish/dao/CannonGameRecordDao.java @@ -0,0 +1,7 @@ +package com.xcong.excoin.modules.fish.dao; + +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import com.xcong.excoin.modules.fish.entity.CannonGameRecord; + +public interface CannonGameRecordDao extends BaseMapper<CannonGameRecord> { +} diff --git a/src/main/java/com/xcong/excoin/modules/fish/dao/CannonOwnRecordDao.java b/src/main/java/com/xcong/excoin/modules/fish/dao/CannonOwnRecordDao.java new file mode 100644 index 0000000..722e17b --- /dev/null +++ b/src/main/java/com/xcong/excoin/modules/fish/dao/CannonOwnRecordDao.java @@ -0,0 +1,17 @@ +package com.xcong.excoin.modules.fish.dao; + +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import com.xcong.excoin.modules.fish.entity.CannonOwnRecord; +import com.xcong.excoin.modules.fish.vo.OwnCannonVo; +import org.apache.ibatis.annotations.Param; + +import java.util.List; + +public interface CannonOwnRecordDao extends BaseMapper<CannonOwnRecord> { + + List<CannonOwnRecord> selectCannonOwnRecordsByMemberIdAndCannonCode(@Param("memberId")Long memberId, @Param("code")String code); + + List<OwnCannonVo> selectCannonOwnRecordsByMemberId(@Param("memberId")Long memberId); + + List<CannonOwnRecord> selectCannonOwnRecordsByIdAndMemberId(@Param("id")Long cannonOwnId, @Param("memberId")Long memberId); +} diff --git a/src/main/java/com/xcong/excoin/modules/fish/dao/CannonSettingDao.java b/src/main/java/com/xcong/excoin/modules/fish/dao/CannonSettingDao.java new file mode 100644 index 0000000..14894b6 --- /dev/null +++ b/src/main/java/com/xcong/excoin/modules/fish/dao/CannonSettingDao.java @@ -0,0 +1,20 @@ +package com.xcong.excoin.modules.fish.dao; + +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import com.baomidou.mybatisplus.core.metadata.IPage; +import com.baomidou.mybatisplus.extension.plugins.pagination.Page; +import com.xcong.excoin.modules.fish.entity.CannonExchangeRatio; +import com.xcong.excoin.modules.fish.entity.CannonSetting; +import com.xcong.excoin.modules.fish.vo.CannonSettingVo; +import org.apache.ibatis.annotations.Param; + +import java.util.List; + +public interface CannonSettingDao extends BaseMapper<CannonSetting> { + + List<CannonExchangeRatio> selectCannonExchangeRatio(); + + IPage<CannonSettingVo> findCannonSettingInPage(Page<CannonSettingVo> page, @Param("cannonSetting")CannonSetting cannonSetting); + + CannonSetting selectCannonSettingByCannonCode(@Param("cannonCode")String cannonCode); +} diff --git a/src/main/java/com/xcong/excoin/modules/fish/dao/MemberAccountGoldDao.java b/src/main/java/com/xcong/excoin/modules/fish/dao/MemberAccountGoldDao.java new file mode 100644 index 0000000..5bc26ca --- /dev/null +++ b/src/main/java/com/xcong/excoin/modules/fish/dao/MemberAccountGoldDao.java @@ -0,0 +1,17 @@ +package com.xcong.excoin.modules.fish.dao; + +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import com.xcong.excoin.modules.fish.entity.MemberAccountGold; +import com.xcong.excoin.modules.fish.vo.GoldAccountVo; +import org.apache.ibatis.annotations.Param; + +import java.math.BigDecimal; + +public interface MemberAccountGoldDao extends BaseMapper<MemberAccountGold> { + + MemberAccountGold selectAccountGoldByMemberId(@Param("memberId")Long memberId); + + int updateTotalBalanceAndAvailableBalance(@Param("id") Long id, @Param("availableBalance") BigDecimal availableBalance, @Param("totalBalance") BigDecimal totalBalance, @Param("frozenBalance") BigDecimal frozenBalance); + + GoldAccountVo selectAccountGoldVoByMemberId(Long memberId); +} diff --git a/src/main/java/com/xcong/excoin/modules/fish/dto/CannonExchangeDto.java b/src/main/java/com/xcong/excoin/modules/fish/dto/CannonExchangeDto.java new file mode 100644 index 0000000..b24fe4c --- /dev/null +++ b/src/main/java/com/xcong/excoin/modules/fish/dto/CannonExchangeDto.java @@ -0,0 +1,17 @@ +package com.xcong.excoin.modules.fish.dto; + +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; + +import javax.validation.constraints.NotNull; + +@Data +@ApiModel(value = "CannonExchangeDto", description = "参数类") +public class CannonExchangeDto { + + @NotNull(message = "ID不能为空") + @ApiModelProperty(value = "兑换炮台ID", example = "1") + private Long cannonId; + +} diff --git a/src/main/java/com/xcong/excoin/modules/fish/dto/CoinGoldExchangeDto.java b/src/main/java/com/xcong/excoin/modules/fish/dto/CoinGoldExchangeDto.java new file mode 100644 index 0000000..8404623 --- /dev/null +++ b/src/main/java/com/xcong/excoin/modules/fish/dto/CoinGoldExchangeDto.java @@ -0,0 +1,22 @@ +package com.xcong.excoin.modules.fish.dto; + +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; + +import javax.validation.constraints.NotNull; +import java.math.BigDecimal; + +@Data +@ApiModel(value = "CoinGoldExchangeDto", description = "参数类") +public class CoinGoldExchangeDto { + + @NotNull(message = "兑换金额不能为空") + @ApiModelProperty(value = "兑换金额", example = "100") + private BigDecimal balance; + + @NotNull(message = "类型不能为空") + @ApiModelProperty(value = "类型", example = "1:金币兑换代币 2:代币兑换金币") + private Integer type; + +} diff --git a/src/main/java/com/xcong/excoin/modules/fish/dto/FishingDto.java b/src/main/java/com/xcong/excoin/modules/fish/dto/FishingDto.java new file mode 100644 index 0000000..23e9d52 --- /dev/null +++ b/src/main/java/com/xcong/excoin/modules/fish/dto/FishingDto.java @@ -0,0 +1,21 @@ +package com.xcong.excoin.modules.fish.dto; + +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; + +import javax.validation.constraints.NotNull; + +@Data +@ApiModel(value = "FishingDto", description = "参数类") +public class FishingDto { + + + @NotNull(message = "炮塔不能为空") + @ApiModelProperty(value = "炮塔ID", example = "100") + private Long cannonOwnId; + + @ApiModelProperty(value = "获得金币", example = "100") + private Integer goldWin; + +} diff --git a/src/main/java/com/xcong/excoin/modules/fish/dto/GetCannonsDto.java b/src/main/java/com/xcong/excoin/modules/fish/dto/GetCannonsDto.java new file mode 100644 index 0000000..3f0db2f --- /dev/null +++ b/src/main/java/com/xcong/excoin/modules/fish/dto/GetCannonsDto.java @@ -0,0 +1,23 @@ +package com.xcong.excoin.modules.fish.dto; + +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; + +import javax.validation.constraints.Min; +import javax.validation.constraints.NotNull; + +@Data +@ApiModel(value = "GetCannonsDto", description = "参数类") +public class GetCannonsDto { + + @NotNull + @Min(1) + @ApiModelProperty(value = "第几页", example = "1") + private int pageNum; + + @NotNull + @ApiModelProperty(value = "每页数量", example = "10") + private int pageSize; + +} diff --git a/src/main/java/com/xcong/excoin/modules/fish/dto/GoldExchangeDto.java b/src/main/java/com/xcong/excoin/modules/fish/dto/GoldExchangeDto.java new file mode 100644 index 0000000..f1821d5 --- /dev/null +++ b/src/main/java/com/xcong/excoin/modules/fish/dto/GoldExchangeDto.java @@ -0,0 +1,18 @@ +package com.xcong.excoin.modules.fish.dto; + +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; + +import javax.validation.constraints.NotNull; +import java.math.BigDecimal; + +@Data +@ApiModel(value = "GoldExchangeDto", description = "参数类") +public class GoldExchangeDto { + + @NotNull(message = "兑换金额不能为空") + @ApiModelProperty(value = "兑换金额", example = "100") + private BigDecimal balance; + +} diff --git a/src/main/java/com/xcong/excoin/modules/fish/entity/CannonAccountMoneyChange.java b/src/main/java/com/xcong/excoin/modules/fish/entity/CannonAccountMoneyChange.java new file mode 100644 index 0000000..e770697 --- /dev/null +++ b/src/main/java/com/xcong/excoin/modules/fish/entity/CannonAccountMoneyChange.java @@ -0,0 +1,30 @@ +package com.xcong.excoin.modules.fish.entity; + +import com.baomidou.mybatisplus.annotation.TableName; +import com.xcong.excoin.common.system.base.BaseEntity; +import lombok.Data; + +import java.math.BigDecimal; + +/** + * 用户的账户资金转换充值提现操作记录表 + */ +@Data +@TableName("cannon_account_money_change") +public class CannonAccountMoneyChange extends BaseEntity { + + private Long memberId; + //金额 + private BigDecimal amount; + //1:USDT购买炮台 2:金币兑换1代币 3:1代币兑换金币 + private Integer type; + //内容 + private String content; + //变更金额 + private BigDecimal changeBalance; + //变更前 + private BigDecimal changeBefore; + //变更后 + private BigDecimal changeAfter; + +} diff --git a/src/main/java/com/xcong/excoin/modules/fish/entity/CannonExchangeRatio.java b/src/main/java/com/xcong/excoin/modules/fish/entity/CannonExchangeRatio.java new file mode 100644 index 0000000..8923de7 --- /dev/null +++ b/src/main/java/com/xcong/excoin/modules/fish/entity/CannonExchangeRatio.java @@ -0,0 +1,20 @@ +package com.xcong.excoin.modules.fish.entity; + +import com.baomidou.mybatisplus.annotation.TableName; +import lombok.Data; + +import java.math.BigDecimal; + +/** + * 兑换比例设置 + */ +@Data +@TableName("cannon_exchange_ratio") +public class CannonExchangeRatio { + private Long id; + //金币兑换代币比例 + private BigDecimal goldRatio; + //代币兑换金币比例 + private BigDecimal coinRatio; + +} diff --git a/src/main/java/com/xcong/excoin/modules/fish/entity/CannonGameRecord.java b/src/main/java/com/xcong/excoin/modules/fish/entity/CannonGameRecord.java new file mode 100644 index 0000000..1e00477 --- /dev/null +++ b/src/main/java/com/xcong/excoin/modules/fish/entity/CannonGameRecord.java @@ -0,0 +1,29 @@ +package com.xcong.excoin.modules.fish.entity; + +import com.baomidou.mybatisplus.annotation.TableName; +import com.xcong.excoin.common.system.base.BaseEntity; +import lombok.Data; + +import java.math.BigDecimal; + +/** + * 游戏记录 + */ +@Data +@TableName("cannon_game_record") +public class CannonGameRecord extends BaseEntity { + + private Long memberId; + //用户拥有炮台记录ID + private Long cannonOwnId; + //炮台名称 + private String cannonName; + //炮台编码 + private String cannonCode; + //消耗金币 + private BigDecimal goldConsume; + //获得金币 + private BigDecimal goldReward; + + +} diff --git a/src/main/java/com/xcong/excoin/modules/fish/entity/CannonOwnRecord.java b/src/main/java/com/xcong/excoin/modules/fish/entity/CannonOwnRecord.java new file mode 100644 index 0000000..28f5c20 --- /dev/null +++ b/src/main/java/com/xcong/excoin/modules/fish/entity/CannonOwnRecord.java @@ -0,0 +1,27 @@ +package com.xcong.excoin.modules.fish.entity; + +import com.baomidou.mybatisplus.annotation.TableName; +import com.xcong.excoin.common.system.base.BaseEntity; +import lombok.Data; + +import java.math.BigDecimal; + +/** + * 用户拥有炮台 + */ +@Data +@TableName("cannon_own_record") +public class CannonOwnRecord extends BaseEntity { + + private Long memberId; + //炮台UUID + private String cannonUuid; + //炮台名称 + private String cannonName; + //炮台编码 + private String cannonCode; + //炮台兑换价格 + private BigDecimal cannonPrice; + //1:主动购买 2:系统赠送 + private Integer type; +} diff --git a/src/main/java/com/xcong/excoin/modules/fish/entity/CannonSetting.java b/src/main/java/com/xcong/excoin/modules/fish/entity/CannonSetting.java new file mode 100644 index 0000000..07461e4 --- /dev/null +++ b/src/main/java/com/xcong/excoin/modules/fish/entity/CannonSetting.java @@ -0,0 +1,25 @@ +package com.xcong.excoin.modules.fish.entity; + +import com.baomidou.mybatisplus.annotation.TableName; +import lombok.Data; + +import java.math.BigDecimal; + +/** + * 炮台设置表 + */ +@Data +@TableName("cannon_setting") +public class CannonSetting { + + private Long id; + //炮台名称 + private String name; + //炮台编码 + private String code; + //兑换价格 + private BigDecimal exchangePrice; + //消耗金币 + private BigDecimal goldConsume; + +} diff --git a/src/main/java/com/xcong/excoin/modules/fish/entity/MemberAccountGold.java b/src/main/java/com/xcong/excoin/modules/fish/entity/MemberAccountGold.java new file mode 100644 index 0000000..fa69f69 --- /dev/null +++ b/src/main/java/com/xcong/excoin/modules/fish/entity/MemberAccountGold.java @@ -0,0 +1,24 @@ +package com.xcong.excoin.modules.fish.entity; + +import com.baomidou.mybatisplus.annotation.TableName; +import com.xcong.excoin.common.system.base.BaseEntity; +import lombok.Data; + +import java.math.BigDecimal; + +/** + * 用戶金币賬戶信息表 + */ +@Data +@TableName("member_account_gold") +public class MemberAccountGold extends BaseEntity { + + private Long memberId; + //金币可用余额 + private BigDecimal availableBalance; + //金币总金额 + private BigDecimal totalBalance; + //金币冻结余额 + private BigDecimal frozenBalance; + +} diff --git a/src/main/java/com/xcong/excoin/modules/fish/service/MemberCannonService.java b/src/main/java/com/xcong/excoin/modules/fish/service/MemberCannonService.java new file mode 100644 index 0000000..207a488 --- /dev/null +++ b/src/main/java/com/xcong/excoin/modules/fish/service/MemberCannonService.java @@ -0,0 +1,28 @@ +package com.xcong.excoin.modules.fish.service; + +import com.baomidou.mybatisplus.extension.service.IService; +import com.xcong.excoin.common.response.Result; +import com.xcong.excoin.modules.fish.dto.*; +import com.xcong.excoin.modules.fish.entity.CannonOwnRecord; +import org.apache.ibatis.annotations.Param; + +import java.math.BigDecimal; + +public interface MemberCannonService extends IService<CannonOwnRecord> { + + Result coinGoldExchange(CoinGoldExchangeDto coinGoldExchangeDto); + + void updateTotalBalanceAndAvailableBalance(@Param("id") Long id, @Param("availableBalance") BigDecimal availableBalance, @Param("totalBalance")BigDecimal totalBalance, @Param("frozenBalance")BigDecimal frozenBalance); + + Result getCannons(GetCannonsDto getCannonsDto); + + Result cannonExchange(CannonExchangeDto cannonExchangeDto); + + Result goldExchange(GoldExchangeDto goldExchangeDto); + + Result getGoldAccount(); + + Result getOwnCannon(); + + Result fishing(FishingDto fishingDto); +} diff --git a/src/main/java/com/xcong/excoin/modules/fish/service/impl/MemberCannonServiceImpl.java b/src/main/java/com/xcong/excoin/modules/fish/service/impl/MemberCannonServiceImpl.java new file mode 100644 index 0000000..ea0460d --- /dev/null +++ b/src/main/java/com/xcong/excoin/modules/fish/service/impl/MemberCannonServiceImpl.java @@ -0,0 +1,263 @@ +package com.xcong.excoin.modules.fish.service.impl; + +import cn.hutool.core.collection.CollUtil; +import cn.hutool.core.lang.UUID; +import cn.hutool.core.util.ObjectUtil; +import com.baomidou.mybatisplus.core.metadata.IPage; +import com.baomidou.mybatisplus.extension.plugins.pagination.Page; +import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import com.xcong.excoin.common.LoginUserUtils; +import com.xcong.excoin.common.enumerates.CoinTypeEnum; +import com.xcong.excoin.common.response.Result; +import com.xcong.excoin.modules.coin.service.CoinService; +import com.xcong.excoin.modules.fish.dao.CannonAccountMoneyChangeDao; +import com.xcong.excoin.modules.fish.dao.CannonOwnRecordDao; +import com.xcong.excoin.modules.fish.dao.CannonSettingDao; +import com.xcong.excoin.modules.fish.dao.MemberAccountGoldDao; +import com.xcong.excoin.modules.fish.dto.*; +import com.xcong.excoin.modules.fish.entity.*; +import com.xcong.excoin.modules.fish.service.MemberCannonService; +import com.xcong.excoin.modules.fish.vo.CannonSettingVo; +import com.xcong.excoin.modules.fish.vo.GoldAccountVo; +import com.xcong.excoin.modules.fish.vo.OwnCannonVo; +import com.xcong.excoin.modules.member.dao.MemberWalletCoinDao; +import com.xcong.excoin.modules.member.entity.MemberWalletCoinEntity; +import com.xcong.excoin.utils.RedisUtils; +import org.springframework.stereotype.Service; + +import javax.annotation.Resource; +import java.math.BigDecimal; +import java.util.List; + +@Service +public class MemberCannonServiceImpl extends ServiceImpl<CannonOwnRecordDao, CannonOwnRecord> implements MemberCannonService { + + @Resource + CannonSettingDao cannonSettingDao; + @Resource + MemberAccountGoldDao memberAccountGoldDao; + @Resource + CannonAccountMoneyChangeDao cannonAccountMoneyChangeDao; + @Resource + MemberWalletCoinDao memberWalletCoinDao; + @Resource + CannonOwnRecordDao cannonOwnRecordDao; + @Resource + RedisUtils redisUtils; + @Resource + private CoinService coinService; + @Resource + private MemberCannonService memberCannonService; + + @Override + public Result coinGoldExchange(CoinGoldExchangeDto coinGoldExchangeDto) { + BigDecimal balance = coinGoldExchangeDto.getBalance(); + if (balance.compareTo(BigDecimal.ZERO) <= 0) { + return Result.fail("兑换金额不能小于或等于0"); + } + Long memberId = LoginUserUtils.getAppLoginUser().getId(); + //获取兑换比例 + List<CannonExchangeRatio> cannonExchangeRatios = cannonSettingDao.selectCannonExchangeRatio(); + if(CollUtil.isEmpty(cannonExchangeRatios)){ + return Result.fail("系统繁忙请稍候重试"); + } + CannonExchangeRatio cannonExchangeRatio = cannonExchangeRatios.get(0); + Integer type = coinGoldExchangeDto.getType(); + //1:金币兑换1代币 2:1代币兑换金币 + if(type == 1){ + MemberAccountGold memberAccountGold = memberAccountGoldDao.selectAccountGoldByMemberId(memberId); + MemberWalletCoinEntity memberWalletCoinEntity = memberWalletCoinDao.selectWalletCoinBymIdAndCode(memberId, CoinTypeEnum.XCT.name()); + if(balance.compareTo(memberAccountGold.getAvailableBalance()) > 0){ + return Result.fail("金币不足"); + } + BigDecimal coinRatio = cannonExchangeRatio.getCoinRatio(); + BigDecimal divide = balance.divide(coinRatio).setScale(8,BigDecimal.ROUND_DOWN); + //金币账户减少 + memberCannonService.updateTotalBalanceAndAvailableBalance(memberAccountGold.getId(),balance.negate(),balance.negate(),null); + //代币账户增加 + coinService.updateWalletBalance(memberWalletCoinEntity.getId(),divide,divide,null); + + CannonAccountMoneyChange cannonAccountMoneyChange = new CannonAccountMoneyChange(); + cannonAccountMoneyChange.setMemberId(memberId); + cannonAccountMoneyChange.setAmount(balance.negate()); + cannonAccountMoneyChange.setType(2); + cannonAccountMoneyChange.setContent("金币兑换"); + cannonAccountMoneyChange.setChangeBalance(balance); + cannonAccountMoneyChange.setChangeBefore(memberAccountGold.getAvailableBalance()); + cannonAccountMoneyChange.setChangeAfter(memberAccountGold.getAvailableBalance().subtract(balance)); + cannonAccountMoneyChangeDao.insert(cannonAccountMoneyChange); + }else if(type == 2){ + MemberAccountGold memberAccountGold = memberAccountGoldDao.selectAccountGoldByMemberId(memberId); + MemberWalletCoinEntity memberWalletCoinEntity = memberWalletCoinDao.selectWalletCoinBymIdAndCode(memberId, CoinTypeEnum.XCT.name()); + if(balance.compareTo(memberWalletCoinEntity.getAvailableBalance()) > 0){ + return Result.fail("代币不足"); + } + BigDecimal coinRatio = cannonExchangeRatio.getCoinRatio(); + BigDecimal multiply = balance.multiply(coinRatio); + //金币账户增加 + memberCannonService.updateTotalBalanceAndAvailableBalance(memberAccountGold.getId(),multiply,multiply,null); + //代币账户减少 + coinService.updateWalletBalance(memberWalletCoinEntity.getId(),balance.negate(),balance.negate(),null); + + CannonAccountMoneyChange cannonAccountMoneyChange = new CannonAccountMoneyChange(); + cannonAccountMoneyChange.setMemberId(memberId); + cannonAccountMoneyChange.setAmount(balance); + cannonAccountMoneyChange.setType(3); + cannonAccountMoneyChange.setContent("兑换金币"); + cannonAccountMoneyChange.setChangeBalance(balance); + cannonAccountMoneyChange.setChangeBefore(memberWalletCoinEntity.getAvailableBalance()); + cannonAccountMoneyChange.setChangeAfter(memberWalletCoinEntity.getAvailableBalance().add(balance)); + cannonAccountMoneyChangeDao.insert(cannonAccountMoneyChange); + } + return Result.ok("兑换成功"); + } + + @Override + public void updateTotalBalanceAndAvailableBalance(Long id, BigDecimal availableBalance, BigDecimal totalBalance,BigDecimal frozenBalance) { + if(id==null){ + return; + } + // 这里需要加锁 保证同一个时间只有一个线程操作一个钱包 + String key = "UPDATE_MEMBER_GOLD_"+id; + while (true){ + boolean b = redisUtils.setNotExist(key, 1, 2); + if(b){ + //System.out.println("我拿到了锁"); + // 拿到了锁才能扣 + memberAccountGoldDao.updateTotalBalanceAndAvailableBalance(id,availableBalance,totalBalance,frozenBalance); + // 扣完释放锁 + redisUtils.del(key); + break; + }else { + + } + } + } + + @Override + public Result getCannons(GetCannonsDto getCannonsDto) { + Long memberId = LoginUserUtils.getAppLoginUser().getId(); + Page<CannonSettingVo> page = new Page<>(getCannonsDto.getPageNum(), getCannonsDto.getPageSize()); + CannonSetting cannonSetting = new CannonSetting(); + IPage<CannonSettingVo> list = cannonSettingDao.findCannonSettingInPage(page, cannonSetting); + return Result.ok(list); + } + + @Override + public Result cannonExchange(CannonExchangeDto cannonExchangeDto) { + Long memberId = LoginUserUtils.getAppLoginUser().getId(); + Long cannonId = cannonExchangeDto.getCannonId(); + CannonSetting cannonSetting = cannonSettingDao.selectById(cannonId); + BigDecimal exchangePrice = cannonSetting.getExchangePrice(); + if(ObjectUtil.isEmpty(cannonSetting)){ + return Result.fail("炮塔不存在"); + } + List<CannonOwnRecord> cannonOwnRecords = cannonOwnRecordDao.selectCannonOwnRecordsByMemberIdAndCannonCode(memberId,cannonSetting.getCode()); + if(CollUtil.isNotEmpty(cannonOwnRecords)){ + return Result.fail("炮塔已拥有"); + } + //获取用户的USDT账户,可用余额总金额减少 + MemberWalletCoinEntity memberWalletCoinEntity = memberWalletCoinDao.selectWalletCoinBymIdAndCode(memberId, CoinTypeEnum.USDT.name()); + if(exchangePrice.compareTo(memberWalletCoinEntity.getAvailableBalance()) > 0){ + return Result.fail("可用余额不足"); + } + coinService.updateWalletBalance(memberWalletCoinEntity.getId(),exchangePrice.negate(),exchangePrice.negate(),null); + //增加一条拥有记录【cannon_own_record】 + CannonOwnRecord cannonOwnRecord = new CannonOwnRecord(); + cannonOwnRecord.setMemberId(memberId); + cannonOwnRecord.setCannonUuid(UUID.randomUUID().toString()); + cannonOwnRecord.setCannonCode(cannonSetting.getCode()); + cannonOwnRecord.setCannonName(cannonSetting.getName()); + cannonOwnRecord.setCannonPrice(cannonSetting.getExchangePrice()); + cannonOwnRecord.setType(1); + cannonOwnRecordDao.insert(cannonOwnRecord); + //增加一条买卖记录 + CannonAccountMoneyChange cannonAccountMoneyChange = new CannonAccountMoneyChange(); + cannonAccountMoneyChange.setMemberId(memberId); + cannonAccountMoneyChange.setAmount(exchangePrice); + cannonAccountMoneyChange.setType(1); + cannonAccountMoneyChange.setContent("购买炮塔"); + cannonAccountMoneyChange.setChangeBalance(exchangePrice); + cannonAccountMoneyChange.setChangeBefore(memberWalletCoinEntity.getAvailableBalance()); + cannonAccountMoneyChange.setChangeAfter(memberWalletCoinEntity.getAvailableBalance().subtract(exchangePrice)); + cannonAccountMoneyChangeDao.insert(cannonAccountMoneyChange); + return Result.ok("购买成功"); + } + + @Override + public Result goldExchange(GoldExchangeDto goldExchangeDto) { + Long memberId = LoginUserUtils.getAppLoginUser().getId(); + BigDecimal balance = goldExchangeDto.getBalance(); + if (balance.compareTo(BigDecimal.ZERO) <= 0) { + return Result.fail("兑换金额不能小于或等于0"); + } + //获取兑换比例 + List<CannonExchangeRatio> cannonExchangeRatios = cannonSettingDao.selectCannonExchangeRatio(); + if(CollUtil.isEmpty(cannonExchangeRatios)){ + return Result.fail("系统繁忙请稍候重试"); + } + CannonExchangeRatio cannonExchangeRatio = cannonExchangeRatios.get(0); + //金币账户增加 + MemberAccountGold memberAccountGold = memberAccountGoldDao.selectAccountGoldByMemberId(memberId); + BigDecimal goldRatio = cannonExchangeRatio.getGoldRatio(); + BigDecimal multiply = balance.multiply(goldRatio); + memberCannonService.updateTotalBalanceAndAvailableBalance(memberAccountGold.getId(),multiply,multiply,null); + //获取用户的USDT账户,可用余额总金额减少 + MemberWalletCoinEntity memberWalletCoinEntity = memberWalletCoinDao.selectWalletCoinBymIdAndCode(memberId, CoinTypeEnum.USDT.name()); + if(balance.compareTo(memberWalletCoinEntity.getAvailableBalance()) > 0){ + return Result.fail("可用余额不足"); + } + coinService.updateWalletBalance(memberWalletCoinEntity.getId(),balance.negate(),balance.negate(),null); + return Result.ok("兑换成功"); + } + + @Override + public Result getGoldAccount() { + Long memberId = LoginUserUtils.getAppLoginUser().getId(); + MemberAccountGold memberAccountGold = memberAccountGoldDao.selectAccountGoldByMemberId(memberId); + if(ObjectUtil.isEmpty(memberAccountGold)){ + MemberAccountGold memberAccountGoldNew = new MemberAccountGold(); + memberAccountGoldNew.setMemberId(memberId); + memberAccountGoldNew.setTotalBalance(BigDecimal.ZERO); + memberAccountGoldNew.setAvailableBalance(BigDecimal.ZERO); + memberAccountGoldNew.setFrozenBalance(BigDecimal.ZERO); + memberAccountGoldDao.insert(memberAccountGoldNew); + } + GoldAccountVo goldAccountVo = memberAccountGoldDao.selectAccountGoldVoByMemberId(memberId); + return Result.ok(goldAccountVo); + } + + @Override + public Result getOwnCannon() { + Long memberId = LoginUserUtils.getAppLoginUser().getId(); + List<OwnCannonVo> cannonOwnRecords = cannonOwnRecordDao.selectCannonOwnRecordsByMemberId(memberId); + return Result.ok(cannonOwnRecords); + } + + @Override + public Result fishing(FishingDto fishingDto) { + Long memberId = LoginUserUtils.getAppLoginUser().getId(); + Integer goldWin = fishingDto.getGoldWin() == null?0:fishingDto.getGoldWin(); + if(goldWin < 0){ + return Result.fail("请求异常,请刷新页面"); + } + Long cannonOwnId = fishingDto.getCannonOwnId(); + List<CannonOwnRecord> cannonOwnRecords = cannonOwnRecordDao.selectCannonOwnRecordsByIdAndMemberId(cannonOwnId,memberId); + if(CollUtil.isEmpty(cannonOwnRecords)){ + Result.fail("请求异常,请刷新页面"); + } + //消耗金币 = 每发炮弹的消耗 - 获得金币; + CannonOwnRecord cannonOwnRecord = cannonOwnRecords.get(0); + CannonSetting cannonSetting = cannonSettingDao.selectCannonSettingByCannonCode(cannonOwnRecord.getCannonCode()); + BigDecimal goldConsume = cannonSetting.getGoldConsume().subtract(new BigDecimal(goldWin)).setScale(0,BigDecimal.ROUND_DOWN); + MemberAccountGold memberAccountGold = memberAccountGoldDao.selectAccountGoldByMemberId(memberId); + memberCannonService.updateTotalBalanceAndAvailableBalance(memberAccountGold.getId(),goldConsume.negate(),goldConsume.negate(),null); + return Result.ok("success"); + } + + public static void main(String[] args) { + System.out.println(UUID.randomUUID().toString()); + } + + +} diff --git a/src/main/java/com/xcong/excoin/modules/fish/vo/CannonSettingVo.java b/src/main/java/com/xcong/excoin/modules/fish/vo/CannonSettingVo.java new file mode 100644 index 0000000..aba8c44 --- /dev/null +++ b/src/main/java/com/xcong/excoin/modules/fish/vo/CannonSettingVo.java @@ -0,0 +1,24 @@ +package com.xcong.excoin.modules.fish.vo; + +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; + +import java.math.BigDecimal; + +@Data +@ApiModel(value = "CannonSettingVo", description = "炮台列表") +public class CannonSettingVo { + + private Long id; + + @ApiModelProperty(value = "炮台名称")//炮台名称 + private String name; + @ApiModelProperty(value = "炮台编码")//炮台编码 + private String code; + @ApiModelProperty(value = "兑换价格")//兑换价格 + private BigDecimal exchangePrice; + @ApiModelProperty(value = "每发炮弹消耗金币数")//消耗金币 + private BigDecimal goldConsume; + +} diff --git a/src/main/java/com/xcong/excoin/modules/fish/vo/GoldAccountVo.java b/src/main/java/com/xcong/excoin/modules/fish/vo/GoldAccountVo.java new file mode 100644 index 0000000..81ebf0d --- /dev/null +++ b/src/main/java/com/xcong/excoin/modules/fish/vo/GoldAccountVo.java @@ -0,0 +1,20 @@ +package com.xcong.excoin.modules.fish.vo; + +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; + +import java.math.BigDecimal; + +@Data +@ApiModel(value = "GoldAccountVo", description = "金币账户") +public class GoldAccountVo { + + private Long memberId; + @ApiModelProperty(value = "金币可用余额")//金币可用余额 + private BigDecimal availableBalance; + @ApiModelProperty(value = "金币总金额")//金币总金额 + private BigDecimal totalBalance; + @ApiModelProperty(value = "金币冻结余额")//金币冻结余额 + private BigDecimal frozenBalance; +} diff --git a/src/main/java/com/xcong/excoin/modules/fish/vo/OwnCannonVo.java b/src/main/java/com/xcong/excoin/modules/fish/vo/OwnCannonVo.java new file mode 100644 index 0000000..6dc2329 --- /dev/null +++ b/src/main/java/com/xcong/excoin/modules/fish/vo/OwnCannonVo.java @@ -0,0 +1,26 @@ +package com.xcong.excoin.modules.fish.vo; + +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; + +import java.math.BigDecimal; +@Data +@ApiModel(value = "OwnCannonVo", description = "金币账户") +public class OwnCannonVo { + + private Long id; + private Long memberId; + @ApiModelProperty(value = "炮台UUID")//炮台UUID + private String cannonUuid; + @ApiModelProperty(value = "炮台名称")//炮台名称 + private String cannonName; + @ApiModelProperty(value = "炮台编码")//炮台编码 + private String cannonCode; + @ApiModelProperty(value = "炮台兑换价格")//炮台兑换价格 + private BigDecimal cannonPrice; + @ApiModelProperty(value = "每发炮弹消耗金币数")//消耗金币 + private BigDecimal goldConsume; + @ApiModelProperty(value = "1:主动购买 2:系统赠送")//1:主动购买 2:系统赠送 + private Integer type; +} diff --git a/src/main/resources/mapper/fish/CannonAccountMoneyChangeDao.xml b/src/main/resources/mapper/fish/CannonAccountMoneyChangeDao.xml new file mode 100644 index 0000000..e7deeda --- /dev/null +++ b/src/main/resources/mapper/fish/CannonAccountMoneyChangeDao.xml @@ -0,0 +1,6 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> +<mapper namespace="com.xcong.excoin.modules.fish.dao.CannonAccountMoneyChangeDao"> + + +</mapper> \ No newline at end of file diff --git a/src/main/resources/mapper/fish/CannonGameRecordDao.xml b/src/main/resources/mapper/fish/CannonGameRecordDao.xml new file mode 100644 index 0000000..441d380 --- /dev/null +++ b/src/main/resources/mapper/fish/CannonGameRecordDao.xml @@ -0,0 +1,6 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> +<mapper namespace="com.xcong.excoin.modules.fish.dao.CannonGameRecordDao"> + + +</mapper> \ No newline at end of file diff --git a/src/main/resources/mapper/fish/CannonOwnRecordDao.xml b/src/main/resources/mapper/fish/CannonOwnRecordDao.xml new file mode 100644 index 0000000..ba3b187 --- /dev/null +++ b/src/main/resources/mapper/fish/CannonOwnRecordDao.xml @@ -0,0 +1,20 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> +<mapper namespace="com.xcong.excoin.modules.fish.dao.CannonOwnRecordDao"> + + <select id="selectCannonOwnRecordsByMemberIdAndCannonCode" resultType="com.xcong.excoin.modules.fish.entity.CannonOwnRecord"> + select a.* from cannon_own_record a where a.member_id = #{memberId} and a.cannon_code = #{code} + </select> + + <select id="selectCannonOwnRecordsByMemberId" resultType="com.xcong.excoin.modules.fish.vo.OwnCannonVo"> + select a.*,b.gold_consume goldConsume + from cannon_own_record a + left join cannon_setting b on a.cannon_code = b.code + where a.member_id = #{memberId} + </select> + + <select id="selectCannonOwnRecordsByIdAndMemberId" resultType="com.xcong.excoin.modules.fish.entity.CannonOwnRecord"> + select a.* from cannon_own_record a where a.member_id = #{memberId} and a.id = #{id} + </select> + +</mapper> \ No newline at end of file diff --git a/src/main/resources/mapper/fish/CannonSettingDao.xml b/src/main/resources/mapper/fish/CannonSettingDao.xml new file mode 100644 index 0000000..0bdfba0 --- /dev/null +++ b/src/main/resources/mapper/fish/CannonSettingDao.xml @@ -0,0 +1,17 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> +<mapper namespace="com.xcong.excoin.modules.fish.dao.CannonSettingDao"> + + <select id="selectCannonExchangeRatio" resultType="com.xcong.excoin.modules.fish.entity.CannonExchangeRatio"> + select a.* from cannon_exchange_ratio a + </select> + + <select id="findCannonSettingInPage" resultType="com.xcong.excoin.modules.fish.vo.CannonSettingVo"> + select a.* from cannon_setting a order by id asc + </select> + + <select id="selectCannonSettingByCannonCode" resultType="com.xcong.excoin.modules.fish.entity.CannonSetting"> + select a.* from cannon_setting a where a.code = #{cannonCode} + </select> + +</mapper> \ No newline at end of file diff --git a/src/main/resources/mapper/fish/MemberAccountGoldDao.xml b/src/main/resources/mapper/fish/MemberAccountGoldDao.xml new file mode 100644 index 0000000..bf8057b --- /dev/null +++ b/src/main/resources/mapper/fish/MemberAccountGoldDao.xml @@ -0,0 +1,35 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> +<mapper namespace="com.xcong.excoin.modules.fish.dao.MemberAccountGoldDao"> + + <select id="selectAccountGoldByMemberId" resultType="com.xcong.excoin.modules.fish.entity.MemberAccountGold"> + select a.* from member_account_gold a where a.member_id = #{memberId} + </select> + + <update id="updateTotalBalanceAndAvailableBalance" parameterType="map"> + update member_account_gold + <set> + <if test="availableBalance != null"> + available_balance = ( + case when IFNULL(available_balance, 0) + #{available_balance}>0 then IFNULL(available_balance, 0) + #{availableBalance} else 0 end + ), + </if> + <if test="totalBalance != null"> + total_balance = ( + case when IFNULL(total_balance, 0) + #{totalBalance}>0 then IFNULL(total_balance, 0) + #{totalBalance} else 0 end + ), + </if> + <if test="frozenBalance != null"> + frozen_balance = ( + case when IFNULL(frozen_balance, 0) + #{frozenBalance}>0 then IFNULL(frozen_balance, 0) + #{frozenBalance} else 0 end + ), + </if> + </set> + where id=#{id} + </update> + + <select id="selectAccountGoldVoByMemberId" resultType="com.xcong.excoin.modules.fish.vo.GoldAccountVo"> + select a.* from member_account_gold a where a.member_id = #{memberId} + </select> + +</mapper> \ No newline at end of file -- Gitblit v1.9.1