From aa0e95612c83cc03b8c815503f2acb5e1874647a Mon Sep 17 00:00:00 2001
From: xiaoyong931011 <15274802129@163.com>
Date: Wed, 24 Nov 2021 15:19:52 +0800
Subject: [PATCH] 20211124 fish
---
src/main/java/com/xcong/excoin/modules/fish/dao/CannonAccountMoneyChangeDao.java | 7
src/main/java/com/xcong/excoin/modules/fish/dao/MemberAccountGoldDao.java | 14 +
src/main/java/com/xcong/excoin/modules/fish/dto/CannonExchangeDto.java | 17 +
src/main/resources/mapper/fish/MemberAccountGoldDao.xml | 31 ++
src/main/resources/mapper/fish/CannonSettingDao.xml | 13 +
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/controller/MemberCannonController.java | 69 +++++
src/main/java/com/xcong/excoin/modules/fish/dto/GoldExchangeDto.java | 18 +
src/main/java/com/xcong/excoin/modules/fish/service/MemberCannonService.java | 25 ++
src/main/resources/mapper/fish/CannonGameRecordDao.xml | 6
src/main/java/com/xcong/excoin/modules/fish/entity/CannonSetting.java | 25 ++
src/main/java/com/xcong/excoin/modules/fish/dao/CannonSettingDao.java | 18 +
src/main/java/com/xcong/excoin/modules/fish/service/impl/MemberCannonServiceImpl.java | 199 ++++++++++++++++
src/main/java/com/xcong/excoin/modules/fish/dao/CannonOwnRecordDao.java | 13 +
src/main/resources/mapper/fish/CannonOwnRecordDao.xml | 9
src/main/java/com/xcong/excoin/modules/fish/dto/GetCannonsDto.java | 23 +
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/resources/mapper/fish/CannonAccountMoneyChangeDao.xml | 6
src/main/java/com/xcong/excoin/modules/fish/entity/CannonOwnRecord.java | 27 ++
src/main/java/com/xcong/excoin/modules/fish/entity/MemberAccountGold.java | 24 ++
24 files changed, 676 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..84c8a7a
--- /dev/null
+++ b/src/main/java/com/xcong/excoin/modules/fish/controller/MemberCannonController.java
@@ -0,0 +1,69 @@
+package com.xcong.excoin.modules.fish.controller;
+
+import com.xcong.excoin.common.response.Result;
+import com.xcong.excoin.modules.coin.parameter.vo.OrderWalletCoinDealVo;
+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.service.MemberCannonService;
+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.PostMapping;
+import org.springframework.web.bind.annotation.RequestBody;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RestController;
+
+import javax.annotation.Resource;
+
+@Slf4j
+@Api(value = "MemberCannonController", tags = "炮台接口类")
+@RestController
+@RequestMapping(value = "/api/account")
+public class MemberCannonController {
+
+ @Resource
+ private MemberCannonService memberCannonService;
+
+ /**
+ * 代币金币互转
+ */
+ @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 = OrderWalletCoinDealVo.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);
+ }
+
+
+}
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..4ce4f00
--- /dev/null
+++ b/src/main/java/com/xcong/excoin/modules/fish/dao/CannonOwnRecordDao.java
@@ -0,0 +1,13 @@
+package com.xcong.excoin.modules.fish.dao;
+
+import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+import com.xcong.excoin.modules.fish.entity.CannonOwnRecord;
+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);
+
+}
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..5decbb4
--- /dev/null
+++ b/src/main/java/com/xcong/excoin/modules/fish/dao/CannonSettingDao.java
@@ -0,0 +1,18 @@
+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);
+}
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..5b69ac8
--- /dev/null
+++ b/src/main/java/com/xcong/excoin/modules/fish/dao/MemberAccountGoldDao.java
@@ -0,0 +1,14 @@
+package com.xcong.excoin.modules.fish.dao;
+
+import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+import com.xcong.excoin.modules.fish.entity.MemberAccountGold;
+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);
+}
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/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..1c4579d
--- /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:USDT购买炮台 3:代币兑换记录…
+ 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..1f363dd
--- /dev/null
+++ b/src/main/java/com/xcong/excoin/modules/fish/service/MemberCannonService.java
@@ -0,0 +1,25 @@
+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.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.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);
+}
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..d13af5a
--- /dev/null
+++ b/src/main/java/com/xcong/excoin/modules/fish/service/impl/MemberCannonServiceImpl.java
@@ -0,0 +1,199 @@
+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.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.entity.*;
+import com.xcong.excoin.modules.fish.service.MemberCannonService;
+import com.xcong.excoin.modules.fish.vo.CannonSettingVo;
+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);
+ }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);
+ }
+ 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(2);
+ 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("兑换成功");
+ }
+
+ 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..c1dc0fd
--- /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 = "1发炮弹消耗金币数")//消耗金币
+ private BigDecimal goldConsume;
+
+}
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..bd80702
--- /dev/null
+++ b/src/main/resources/mapper/fish/CannonOwnRecordDao.xml
@@ -0,0 +1,9 @@
+<?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>
+
+</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..c32369d
--- /dev/null
+++ b/src/main/resources/mapper/fish/CannonSettingDao.xml
@@ -0,0 +1,13 @@
+<?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>
+
+</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..199f771
--- /dev/null
+++ b/src/main/resources/mapper/fish/MemberAccountGoldDao.xml
@@ -0,0 +1,31 @@
+<?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>
+
+</mapper>
\ No newline at end of file
--
Gitblit v1.9.1