From 35d0c67bb3391d69a8333e5fad664a88a8ccfd0e Mon Sep 17 00:00:00 2001 From: xiaoyong931011 <15274802129@163.com> Date: Wed, 24 Nov 2021 18:00:40 +0800 Subject: [PATCH] 20211124 fish --- src/main/java/com/xcong/excoin/modules/fish/service/impl/MemberCannonServiceImpl.java | 118 +++++++++++++++++++++++++++++++++++++++++++++++++++------- 1 files changed, 103 insertions(+), 15 deletions(-) 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 index d13af5a..44150bc 100644 --- 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 @@ -10,17 +10,14 @@ 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.CannonExchangeDto; -import com.xcong.excoin.modules.fish.dto.CoinGoldExchangeDto; -import com.xcong.excoin.modules.fish.dto.GetCannonsDto; -import com.xcong.excoin.modules.fish.dto.GoldExchangeDto; +import com.xcong.excoin.modules.fish.dao.*; +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.AccountAvaBanlaceVo; 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; @@ -34,21 +31,23 @@ public class MemberCannonServiceImpl extends ServiceImpl<CannonOwnRecordDao, CannonOwnRecord> implements MemberCannonService { @Resource - CannonSettingDao cannonSettingDao; - @Resource MemberAccountGoldDao memberAccountGoldDao; - @Resource - CannonAccountMoneyChangeDao cannonAccountMoneyChangeDao; @Resource MemberWalletCoinDao memberWalletCoinDao; @Resource + private MemberCannonService memberCannonService; + @Resource + CannonAccountMoneyChangeDao cannonAccountMoneyChangeDao; + @Resource CannonOwnRecordDao cannonOwnRecordDao; + @Resource + CannonSettingDao cannonSettingDao; + @Resource + CannonGameRecordDao cannonGameRecordDao; @Resource RedisUtils redisUtils; @Resource private CoinService coinService; - @Resource - private MemberCannonService memberCannonService; @Override public Result coinGoldExchange(CoinGoldExchangeDto coinGoldExchangeDto) { @@ -77,6 +76,16 @@ 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()); @@ -89,6 +98,16 @@ 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("兑换成功"); } @@ -156,7 +175,8 @@ CannonAccountMoneyChange cannonAccountMoneyChange = new CannonAccountMoneyChange(); cannonAccountMoneyChange.setMemberId(memberId); cannonAccountMoneyChange.setAmount(exchangePrice); - cannonAccountMoneyChange.setType(2); + cannonAccountMoneyChange.setType(1); + cannonAccountMoneyChange.setContent("购买炮塔"); cannonAccountMoneyChange.setChangeBalance(exchangePrice); cannonAccountMoneyChange.setChangeBefore(memberWalletCoinEntity.getAvailableBalance()); cannonAccountMoneyChange.setChangeAfter(memberWalletCoinEntity.getAvailableBalance().subtract(exchangePrice)); @@ -191,6 +211,74 @@ 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); + //增加一条游戏记录 + CannonGameRecord cannonGameRecord = new CannonGameRecord(); + cannonGameRecord.setMemberId(memberId); + cannonGameRecord.setCannonOwnId(cannonOwnRecord.getId()); + cannonGameRecord.setCannonName(cannonOwnRecord.getCannonName()); + cannonGameRecord.setCannonCode(cannonOwnRecord.getCannonCode()); + cannonGameRecord.setGoldConsume(cannonSetting.getGoldConsume()); + cannonGameRecord.setGoldReward(new BigDecimal(goldWin)); + cannonGameRecordDao.insert(cannonGameRecord); + + return Result.ok("success"); + } + + @Override + public Result getAccountAvaBanlace() { + Long memberId = LoginUserUtils.getAppLoginUser().getId(); + MemberAccountGold memberAccountGold = memberAccountGoldDao.selectAccountGoldByMemberId(memberId); + MemberWalletCoinEntity memberWalletCoinEntityXCT = memberWalletCoinDao.selectWalletCoinBymIdAndCode(memberId, CoinTypeEnum.XCT.name()); + MemberWalletCoinEntity memberWalletCoinEntityUSDT = memberWalletCoinDao.selectWalletCoinBymIdAndCode(memberId, CoinTypeEnum.USDT.name()); + AccountAvaBanlaceVo accountAvaBanlaceVo = new AccountAvaBanlaceVo(); + accountAvaBanlaceVo.setMemberId(memberId); + accountAvaBanlaceVo.setGoldAvailableBalance(memberAccountGold.getAvailableBalance() == null?BigDecimal.ZERO:memberAccountGold.getAvailableBalance()); + accountAvaBanlaceVo.setCoinAvailableBalance(memberWalletCoinEntityXCT.getAvailableBalance() == null?BigDecimal.ZERO:memberWalletCoinEntityXCT.getAvailableBalance()); + accountAvaBanlaceVo.setUsdtAvailableBalance(memberWalletCoinEntityUSDT.getAvailableBalance() == null?BigDecimal.ZERO:memberWalletCoinEntityUSDT.getAvailableBalance()); + return Result.ok(accountAvaBanlaceVo); + } + public static void main(String[] args) { System.out.println(UUID.randomUUID().toString()); } -- Gitblit v1.9.1