src/main/java/com/xcong/excoin/modules/fish/controller/MemberCannonController.java
@@ -3,10 +3,7 @@ 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.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.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; @@ -86,5 +83,13 @@ return memberCannonService.getOwnCannon(); } /** * 捕鱼 */ @ApiOperation(value = "捕鱼") @PostMapping(value = "/fishing") public Result fishing(@RequestBody FishingDto fishingDto) { return memberCannonService.fishing(fishingDto); } } src/main/java/com/xcong/excoin/modules/fish/dao/CannonOwnRecordDao.java
@@ -12,4 +12,6 @@ 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); } src/main/java/com/xcong/excoin/modules/fish/dao/CannonSettingDao.java
@@ -15,4 +15,6 @@ List<CannonExchangeRatio> selectCannonExchangeRatio(); IPage<CannonSettingVo> findCannonSettingInPage(Page<CannonSettingVo> page, @Param("cannonSetting")CannonSetting cannonSetting); CannonSetting selectCannonSettingByCannonCode(@Param("cannonCode")String cannonCode); } src/main/java/com/xcong/excoin/modules/fish/dto/FishingDto.java
New file @@ -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; } src/main/java/com/xcong/excoin/modules/fish/service/MemberCannonService.java
@@ -2,10 +2,7 @@ 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.dto.*; import com.xcong.excoin.modules.fish.entity.CannonOwnRecord; import org.apache.ibatis.annotations.Param; @@ -26,4 +23,6 @@ Result getGoldAccount(); Result getOwnCannon(); Result fishing(FishingDto fishingDto); } src/main/java/com/xcong/excoin/modules/fish/service/impl/MemberCannonServiceImpl.java
@@ -14,10 +14,7 @@ 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.dto.*; import com.xcong.excoin.modules.fish.entity.*; import com.xcong.excoin.modules.fish.service.MemberCannonService; import com.xcong.excoin.modules.fish.vo.CannonSettingVo; @@ -237,6 +234,27 @@ 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()); } src/main/java/com/xcong/excoin/modules/fish/vo/OwnCannonVo.java
@@ -9,6 +9,7 @@ @ApiModel(value = "OwnCannonVo", description = "金币账户") public class OwnCannonVo { private Long id; private Long memberId; @ApiModelProperty(value = "炮台UUID")//炮台UUID private String cannonUuid; src/main/resources/mapper/fish/CannonOwnRecordDao.xml
@@ -13,4 +13,8 @@ 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> src/main/resources/mapper/fish/CannonSettingDao.xml
@@ -10,4 +10,8 @@ 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>