From f5e6133809c553cfd9fb28ee61019927c547c374 Mon Sep 17 00:00:00 2001
From: xiaoyong931011 <15274802129@163.com>
Date: Wed, 08 Dec 2021 15:58:33 +0800
Subject: [PATCH] 20211208  fish

---
 src/main/java/com/xcong/excoin/modules/fish/service/impl/MemberCannonServiceImpl.java |  153 +++++++++++++++++++++++++++++++++++++++++++++++---
 1 files changed, 143 insertions(+), 10 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 44150bc..fd5277a 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
@@ -3,6 +3,8 @@
 import cn.hutool.core.collection.CollUtil;
 import cn.hutool.core.lang.UUID;
 import cn.hutool.core.util.ObjectUtil;
+import cn.hutool.core.util.RandomUtil;
+import cn.hutool.core.util.StrUtil;
 import com.baomidou.mybatisplus.core.metadata.IPage;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
@@ -14,10 +16,7 @@
 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.fish.vo.*;
 import com.xcong.excoin.modules.member.dao.MemberWalletCoinDao;
 import com.xcong.excoin.modules.member.entity.MemberWalletCoinEntity;
 import com.xcong.excoin.utils.RedisUtils;
@@ -45,6 +44,8 @@
     @Resource
     CannonGameRecordDao cannonGameRecordDao;
     @Resource
+    CannonWinRecordDao cannonWinRecordDao;
+    @Resource
     RedisUtils redisUtils;
     @Resource
     private CoinService coinService;
@@ -66,7 +67,7 @@
         //1:金币兑换1代币 2:1代币兑换金币
         if(type == 1){
             MemberAccountGold memberAccountGold = memberAccountGoldDao.selectAccountGoldByMemberId(memberId);
-            MemberWalletCoinEntity memberWalletCoinEntity = memberWalletCoinDao.selectWalletCoinBymIdAndCode(memberId, CoinTypeEnum.XCT.name());
+            MemberWalletCoinEntity memberWalletCoinEntity = memberWalletCoinDao.selectWalletCoinBymIdAndCode(memberId, CoinTypeEnum.XCC.name());
             if(balance.compareTo(memberAccountGold.getAvailableBalance()) > 0){
                 return Result.fail("金币不足");
             }
@@ -88,7 +89,7 @@
             cannonAccountMoneyChangeDao.insert(cannonAccountMoneyChange);
         }else if(type == 2){
             MemberAccountGold memberAccountGold = memberAccountGoldDao.selectAccountGoldByMemberId(memberId);
-            MemberWalletCoinEntity memberWalletCoinEntity = memberWalletCoinDao.selectWalletCoinBymIdAndCode(memberId, CoinTypeEnum.XCT.name());
+            MemberWalletCoinEntity memberWalletCoinEntity = memberWalletCoinDao.selectWalletCoinBymIdAndCode(memberId, CoinTypeEnum.XCC.name());
             if(balance.compareTo(memberWalletCoinEntity.getAvailableBalance()) > 0){
                 return Result.fail("代币不足");
             }
@@ -269,18 +270,150 @@
     public Result getAccountAvaBanlace() {
         Long memberId = LoginUserUtils.getAppLoginUser().getId();
         MemberAccountGold memberAccountGold = memberAccountGoldDao.selectAccountGoldByMemberId(memberId);
-        MemberWalletCoinEntity memberWalletCoinEntityXCT = memberWalletCoinDao.selectWalletCoinBymIdAndCode(memberId, CoinTypeEnum.XCT.name());
+        MemberWalletCoinEntity memberWalletCoinEntityXCC = memberWalletCoinDao.selectWalletCoinBymIdAndCode(memberId, CoinTypeEnum.XCC.name());
         MemberWalletCoinEntity memberWalletCoinEntityUSDT = memberWalletCoinDao.selectWalletCoinBymIdAndCode(memberId, CoinTypeEnum.USDT.name());
         AccountAvaBanlaceVo accountAvaBanlaceVo = new AccountAvaBanlaceVo();
-        accountAvaBanlaceVo.setMemberId(memberId);
+//        accountAvaBanlaceVo.setMemberId(memberId);
         accountAvaBanlaceVo.setGoldAvailableBalance(memberAccountGold.getAvailableBalance() == null?BigDecimal.ZERO:memberAccountGold.getAvailableBalance());
-        accountAvaBanlaceVo.setCoinAvailableBalance(memberWalletCoinEntityXCT.getAvailableBalance() == null?BigDecimal.ZERO:memberWalletCoinEntityXCT.getAvailableBalance());
+        accountAvaBanlaceVo.setCoinAvailableBalance(memberWalletCoinEntityXCC.getAvailableBalance() == null?BigDecimal.ZERO:memberWalletCoinEntityXCC.getAvailableBalance());
         accountAvaBanlaceVo.setUsdtAvailableBalance(memberWalletCoinEntityUSDT.getAvailableBalance() == null?BigDecimal.ZERO:memberWalletCoinEntityUSDT.getAvailableBalance());
         return Result.ok(accountAvaBanlaceVo);
     }
 
+    @Override
+    public Result getAwards() {
+        Long memberId = LoginUserUtils.getAppLoginUser().getId();
+
+//        Long memberId = 1L;
+        AwardsVo awardsVo = cannonOwnRecordDao.getAwards();
+        return Result.ok(awardsVo);
+    }
+
+    @Override
+    public Result lotteryDraw(LotteryDrawDto lotteryDrawDto) {
+        Long memberId = LoginUserUtils.getAppLoginUser().getId();
+
+//        Long memberId = 1L;
+        //获取每次抽奖需要的USDT数量
+        CannonAwardSet cannonAwardSet = cannonOwnRecordDao.getCannonAwardSet();
+        if(ObjectUtil.isEmpty(cannonAwardSet)){
+            Result.fail("活动还没开始,请稍候");
+        }
+        BigDecimal consume = cannonAwardSet.getConsume() == null ? BigDecimal.ZERO : cannonAwardSet.getConsume();
+        if(consume.compareTo(BigDecimal.ZERO) <= 0){
+            Result.fail("活动还没开始,请稍候");
+        }
+        //验证账户USDT余额是否足够
+        MemberWalletCoinEntity memberWalletCoinEntity = memberWalletCoinDao.selectWalletCoinBymIdAndCode(memberId, CoinTypeEnum.USDT.name());
+        BigDecimal availableBalance = memberWalletCoinEntity.getAvailableBalance() == null ? BigDecimal.ZERO : memberWalletCoinEntity.getAvailableBalance();
+        if(availableBalance.compareTo(consume) < 0){
+            Result.fail("用户USDT余额不足");
+        }
+        //用户USDT余额减少
+        coinService.updateWalletBalance(memberWalletCoinEntity.getId(),consume.negate(),consume.negate(),null);
+        //增加一条抽奖记录
+        CannonAccountMoneyChange cannonAccountMoneyChange = new CannonAccountMoneyChange();
+        cannonAccountMoneyChange.setMemberId(memberId);
+        cannonAccountMoneyChange.setAmount(consume);
+        cannonAccountMoneyChange.setType(4);
+        cannonAccountMoneyChange.setContent("抽奖");
+        cannonAccountMoneyChange.setChangeBalance(consume);
+        cannonAccountMoneyChange.setChangeBefore(memberWalletCoinEntity.getAvailableBalance());
+        cannonAccountMoneyChange.setChangeAfter(memberWalletCoinEntity.getAvailableBalance().subtract(consume));
+        cannonAccountMoneyChangeDao.insert(cannonAccountMoneyChange);
+        //抽奖品
+        CannonAwardVo award = getAward(memberId);
+
+        CannonWinRecord cannonWinRecord = new CannonWinRecord();
+        cannonWinRecord.setMemberId(memberId);
+        cannonWinRecord.setAwardName(award.getName()+"*"+award.getQuantity());
+        cannonWinRecord.setConsumeNum(consume);
+        cannonWinRecordDao.insert(cannonWinRecord);
+        return Result.ok(award);
+    }
+
+    @Override
+    public Result getOwnAwards(CannonWinRecordDto cannonWinRecordDto) {
+        Long memberId = LoginUserUtils.getAppLoginUser().getId();
+        Page<CannonWinRecordVo> page = new Page<>(cannonWinRecordDto.getPageNum(), cannonWinRecordDto.getPageSize());
+        CannonWinRecord cannonWinRecord = new CannonWinRecord();
+        cannonWinRecord.setMemberId(memberId);
+        IPage<CannonWinRecordVo> list = cannonSettingDao.findCannonWinRecordInPage(page, cannonWinRecord);
+        return Result.ok(list);
+    }
+
+    @Override
+    public Result getListAwards() {
+        Long memberId = LoginUserUtils.getAppLoginUser().getId();
+        List<CannonWinRecordVo> list = cannonSettingDao.findCannonWinRecordList();
+        return Result.ok(list);
+    }
+
+    private CannonAwardVo getAward(Long memberId) {
+        CannonAwardVo cannonAwardVo = new CannonAwardVo();
+        //获取所有的奖品列表
+        List<CannonAward> cannonAwards = cannonOwnRecordDao.selectCannonAward();
+        if(CollUtil.isNotEmpty(cannonAwards)){
+            CannonAward cannonAward = RandomUtil.randomEle(cannonAwards);
+            //获得金币
+            if("GOLD".equals(cannonAward.getCode())){
+                BigDecimal quantity = new BigDecimal(cannonAward.getQuantity());
+                MemberAccountGold memberAccountGold = memberAccountGoldDao.selectAccountGoldByMemberId(memberId);
+                memberCannonService.updateTotalBalanceAndAvailableBalance(memberAccountGold.getId(),quantity,quantity,null);
+                cannonAwardVo.setName(cannonAward.getName());
+                cannonAwardVo.setImage(cannonAward.getImage());
+                cannonAwardVo.setQuantity(cannonAward.getQuantity());
+            }else if("COIN".equals(cannonAward.getCode())){
+                BigDecimal quantity = new BigDecimal(cannonAward.getQuantity());
+                MemberWalletCoinEntity memberWalletCoinEntity = memberWalletCoinDao.selectWalletCoinBymIdAndCode(memberId, CoinTypeEnum.XCC.name());
+                coinService.updateWalletBalance(memberWalletCoinEntity.getId(),quantity,quantity,null);
+                cannonAwardVo.setName(cannonAward.getName());
+                cannonAwardVo.setImage(cannonAward.getImage());
+                cannonAwardVo.setQuantity(cannonAward.getQuantity());
+            }else if("USDT".equals(cannonAward.getCode())){
+                BigDecimal quantity = new BigDecimal(cannonAward.getQuantity());
+                MemberWalletCoinEntity memberWalletCoinEntity = memberWalletCoinDao.selectWalletCoinBymIdAndCode(memberId, CoinTypeEnum.USDT.name());
+                coinService.updateWalletBalance(memberWalletCoinEntity.getId(),quantity,quantity,null);
+                cannonAwardVo.setName(cannonAward.getName());
+                cannonAwardVo.setImage(cannonAward.getImage());
+                cannonAwardVo.setQuantity(cannonAward.getQuantity());
+            }else{
+                CannonSetting cannonSetting = cannonSettingDao.selectCannonSettingByCannonCode(cannonAward.getCode());
+                List<CannonOwnRecord> cannonOwnRecords = cannonOwnRecordDao.selectCannonOwnRecordsByMemberIdAndCannonCode(memberId, cannonAward.getCode());
+                Integer cannonAccountMoneyChanges = cannonOwnRecordDao.selectCannonAccountMoneyChangeByMemberId(memberId);
+                //抽奖次数小于十次的抽不到炮台
+                if(CollUtil.isEmpty(cannonOwnRecords) && cannonAccountMoneyChanges > 10){
+                    //增加一条拥有记录【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);
+
+                    cannonAwardVo.setName(cannonAward.getName());
+                    cannonAwardVo.setImage(cannonAward.getImage());
+                    cannonAwardVo.setQuantity(cannonAward.getQuantity());
+                }else{
+                    CannonAward cannonAwardGold = cannonOwnRecordDao.selectCannonAwardByCode("GOLD");
+                    BigDecimal quantity = new BigDecimal(cannonAwardGold.getQuantity());
+                    MemberAccountGold memberAccountGold = memberAccountGoldDao.selectAccountGoldByMemberId(memberId);
+                    memberCannonService.updateTotalBalanceAndAvailableBalance(memberAccountGold.getId(),quantity,quantity,null);
+                    cannonAwardVo.setName(cannonAwardGold.getName());
+                    cannonAwardVo.setImage(cannonAwardGold.getImage());
+                    cannonAwardVo.setQuantity(cannonAwardGold.getQuantity());
+                }
+            }
+        }
+
+        return cannonAwardVo;
+    }
+
+
+
     public static void main(String[] args) {
-        System.out.println(UUID.randomUUID().toString());
     }
 
 

--
Gitblit v1.9.1