From a4c1320597e618906f0793a0751beff35290e7ee Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=AE=B8=E5=85=81=E6=9E=9E?= <3422692813@qq.com> Date: Fri, 20 Sep 2024 17:59:07 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B09.20?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service/impl/UserBalanceServiceImpl.java | 99 ++++++++++++------- .../userManager/vo/UserBlanceUniVo.java | 6 ++ 2 files changed, 67 insertions(+), 38 deletions(-) diff --git a/fuintBackend/fuint-application/src/main/java/com/fuint/business/userManager/service/impl/UserBalanceServiceImpl.java b/fuintBackend/fuint-application/src/main/java/com/fuint/business/userManager/service/impl/UserBalanceServiceImpl.java index b4c33dc9a..326c4455f 100644 --- a/fuintBackend/fuint-application/src/main/java/com/fuint/business/userManager/service/impl/UserBalanceServiceImpl.java +++ b/fuintBackend/fuint-application/src/main/java/com/fuint/business/userManager/service/impl/UserBalanceServiceImpl.java @@ -1,6 +1,7 @@ package com.fuint.business.userManager.service.impl; import cn.hutool.core.bean.BeanUtil; +import cn.hutool.core.collection.CollUtil; import cn.hutool.core.util.ObjectUtil; import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSONArray; @@ -12,6 +13,9 @@ import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.fuint.business.marketingActivity.cardFavorable.entity.CardFavorableRecord; import com.fuint.business.marketingActivity.cardFavorable.mapper.CardFavorableRecordMapper; +import com.fuint.business.marketingActivity.cardGift.entity.CardGift; +import com.fuint.business.marketingActivity.cardGift.mapper.CardGiftMapper; +import com.fuint.business.marketingActivity.cardGiftActive.mapper.CardGiftActiveMapper; import com.fuint.business.marketingActivity.cardValue.entity.CardValueRecord; import com.fuint.business.marketingActivity.cardValue.mapper.CardValueRecordMapper; import com.fuint.business.order.mapper.AllOrderInfoMapper; @@ -44,6 +48,7 @@ import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.concurrent.TimeUnit; +import java.util.stream.Collectors; /** * 会员储值卡信息 业务层 @@ -77,6 +82,10 @@ public class UserBalanceServiceImpl extends ServiceImpl listByZt(Page page, UserBalanceVo user) { if (ObjectUtil.isEmpty(user.getDeptId())) { @@ -98,12 +107,14 @@ public class UserBalanceServiceImpl extends ServiceImpl amountAndConsume = cardValueRecordMapper.getAmountAndConsume(record); if (ObjectUtil.isNotEmpty(amountAndConsume)) { record.setCountNum(amountAndConsume.get("consumeNum").toString()); // 累计重置次数 - record.setAmount(ObjectUtil.isNotEmpty(amountAndConsume.get("amount"))?amountAndConsume.get("amount").toString():"0"); + record.setAmount(ObjectUtil.isNotEmpty(amountAndConsume.get("amount")) ? amountAndConsume.get("amount").toString() : "0"); } @@ -131,7 +142,7 @@ public class UserBalanceServiceImpl extends ServiceImpl getDataByZt(UserBalanceVo user) { + public Map getDataByZt(UserBalanceVo user) { if (ObjectUtil.isEmpty(user.getDeptId())) { AccountInfo nowAccountInfo = TokenUtil.getNowAccountInfo(); user.setDeptId(nowAccountInfo.getDeptId()); @@ -143,17 +154,17 @@ public class UserBalanceServiceImpl extends ServiceImpl dataByZt = userBalanceMapper.getDataByZt(user); Map leiJiInfo = allOrderInfoMapper.getShuJuVipInfo(user); - if (ObjectUtil.isEmpty(dataByZt)){ + if (ObjectUtil.isEmpty(dataByZt)) { dataByZt = new HashMap<>(); } if (ObjectUtil.isEmpty(leiJiInfo)) { leiJiInfo = new HashMap<>(); - leiJiInfo.put("tongjXfMoney","0"); - leiJiInfo.put("tongjMoney","0"); + leiJiInfo.put("tongjXfMoney", "0"); + leiJiInfo.put("tongjMoney", "0"); } - dataByZt.put("tongjMoney",ObjectUtil.isNotEmpty(leiJiInfo.get("tongjMoney"))?convertYuanToWanYuan((BigDecimal) leiJiInfo.get("tongjMoney")):"0"); - dataByZt.put("tongjXfMoney",ObjectUtil.isNotEmpty(leiJiInfo.get("tongjXfMoney"))?convertYuanToWanYuan((BigDecimal) leiJiInfo.get("tongjXfMoney")):"0"); + dataByZt.put("tongjMoney", ObjectUtil.isNotEmpty(leiJiInfo.get("tongjMoney")) ? convertYuanToWanYuan((BigDecimal) leiJiInfo.get("tongjMoney")) : "0"); + dataByZt.put("tongjXfMoney", ObjectUtil.isNotEmpty(leiJiInfo.get("tongjXfMoney")) ? convertYuanToWanYuan((BigDecimal) leiJiInfo.get("tongjXfMoney")) : "0"); return dataByZt; } @@ -164,12 +175,12 @@ public class UserBalanceServiceImpl extends ServiceImpl(); - queryWrapper.eq("mt_user_id",userId); - queryWrapper.eq("chain_store_id",store.getChainStoreId()); + queryWrapper.eq("mt_user_id", userId); + queryWrapper.eq("chain_store_id", store.getChainStoreId()); baseMapper.delete(queryWrapper); } @@ -180,8 +191,6 @@ public class UserBalanceServiceImpl extends ServiceImpl> resultMapList = JSON.parseObject(userBalance.getRefuelMoney(), new TypeReference>>() {}); + List> resultMapList = JSON.parseObject(userBalance.getRefuelMoney(), new TypeReference>>() { + }); if (ObjectUtil.isNotEmpty(resultMapList)) { for (Map stringStringMap : resultMapList) { if (oilId.equals(String.valueOf(stringStringMap.get("oilType")))) { BigDecimal resRefuelMoney = new BigDecimal(String.valueOf(stringStringMap.get("refuelMoney"))); BigDecimal refuelMoney = resRefuelMoney.add(new BigDecimal(changeOil.toString())); - stringStringMap.put("refuelMoney",refuelMoney.toString()); + stringStringMap.put("refuelMoney", refuelMoney.toString()); break; } } @@ -210,8 +220,6 @@ public class UserBalanceServiceImpl extends ServiceImpl(); - queryWrapper.eq("chain_store_id",ljStore.getChainStoreId()); + queryWrapper.eq("chain_store_id", ljStore.getChainStoreId()); queryWrapper.select("SUM(card_balance) as cardBalance"); UserBalance userBalance = baseMapper.selectOne(queryWrapper); Double cardBalance = 0.0; - if (ObjectUtil.isNotEmpty(userBalance) && ObjectUtil.isNotEmpty(userBalance.getCardBalance())){ + if (ObjectUtil.isNotEmpty(userBalance) && ObjectUtil.isNotEmpty(userBalance.getCardBalance())) { cardBalance = userBalance.getCardBalance(); } return cardBalance; @@ -258,23 +266,23 @@ public class UserBalanceServiceImpl extends ServiceImpl0) { + if (balance.getChangeCardBalance().compareTo(userBalance.getCardBalance()) > 0) { throw new RuntimeException("用户余额不足!"); } } if (ObjectUtil.isNotEmpty(balance.getChangePoints())) { - if (balance.getChangeCardBalance().compareTo(userBalance.getCardBalance())>0) { + if (balance.getChangeCardBalance().compareTo(userBalance.getCardBalance()) > 0) { throw new RuntimeException("用户积分不足!"); } } if (ObjectUtil.isNotEmpty(balance.getChangeGrowthValue())) { - if (balance.getChangeGrowthValue().compareTo(userBalance.getGrowthValue())>0) { + if (balance.getChangeGrowthValue().compareTo(userBalance.getGrowthValue()) > 0) { throw new RuntimeException("用户成长值不足!"); } } @@ -290,7 +298,7 @@ public class UserBalanceServiceImpl extends ServiceImpl selectUserBalance(int userId) { QueryWrapper queryWrapper = new QueryWrapper<>(); - queryWrapper.eq("mt_user_id",userId); + queryWrapper.eq("mt_user_id", userId); return baseMapper.selectList(queryWrapper); } @@ -298,7 +306,7 @@ public class UserBalanceServiceImpl extends ServiceImpl(); - queryWrapper.eq("mt_user_id",nowAccountInfo.getId()); + queryWrapper.eq("mt_user_id", nowAccountInfo.getId()); UserBalance balance = baseMapper.selectOne(queryWrapper); return balance; } @@ -306,8 +314,8 @@ public class UserBalanceServiceImpl extends ServiceImpl(); - queryWrapper.eq("mt_user_id",userId); - queryWrapper.eq("chain_store_id",chainStoreId); + queryWrapper.eq("mt_user_id", userId); + queryWrapper.eq("chain_store_id", chainStoreId); UserBalance balance = baseMapper.selectOne(queryWrapper); return balance; } @@ -315,57 +323,72 @@ public class UserBalanceServiceImpl extends ServiceImpl(); - queryWrapper.eq("mt_user_id",userId); - queryWrapper.eq("store_id",storeId); + queryWrapper.eq("mt_user_id", userId); + queryWrapper.eq("store_id", storeId); UserBalance balance = baseMapper.selectOne(queryWrapper); return balance; } /** * 查询会员储值卡余额 + * * @return */ @Override public UserBalance getUserBalance() { AccountInfo nowAccountInfo = TokenUtil.getNowAccountInfo(); QueryWrapper queryWrapper = new QueryWrapper<>(); - queryWrapper.eq("mt_user_id",nowAccountInfo.getId()); - queryWrapper.eq("store_id",nowAccountInfo.getStoreId()); + queryWrapper.eq("mt_user_id", nowAccountInfo.getId()); + queryWrapper.eq("store_id", nowAccountInfo.getStoreId()); UserBalance balance = baseMapper.selectOne(queryWrapper); return balance; } /** * 查询会员储值卡余额 + * * @return */ @Override public UserBlanceUniVo getUserBalanceApplet(UserBalance userBalance) { AccountInfo nowAccountInfo = TokenUtil.getNowAccountInfo(); QueryWrapper queryWrapper = new QueryWrapper<>(); - queryWrapper.eq("mt_user_id",nowAccountInfo.getId()); - queryWrapper.eq("chain_store_id",userBalance.getChainStoreId()); + queryWrapper.eq("mt_user_id", nowAccountInfo.getId()); + queryWrapper.eq("chain_store_id", userBalance.getChainStoreId()); UserBalance balance = baseMapper.selectOne(queryWrapper); UserBlanceUniVo userBlanceUniVo = new UserBlanceUniVo(); if (ObjectUtil.isNotEmpty(balance)) { - userBlanceUniVo = BeanUtil.copyProperties(balance,UserBlanceUniVo.class); + userBlanceUniVo = BeanUtil.copyProperties(balance, UserBlanceUniVo.class); Double giveAmount = ObjectUtil.isNotEmpty(balance.getGiveAmount()) ? balance.getGiveAmount() : 0; - userBlanceUniVo.setAllBalance(balance.getCardBalance()+ giveAmount); + userBlanceUniVo.setAllBalance(balance.getCardBalance() + giveAmount); //查询优惠券数量 Integer count = cardFavorableRecordMapper.selectCount(new LambdaQueryWrapper() - .eq(CardFavorableRecord::getMtUserId, balance.getMtUserId()) + .eq(CardFavorableRecord::getMtUserId, nowAccountInfo.getId()) .eq(CardFavorableRecord::getStatus, 0) .eq(CardFavorableRecord::getStoreId, balance.getStoreId())); userBlanceUniVo.setCardFavorableCount(count); - }else { + //查询礼品卡已兑换数量和金额 + List cardGifts = cardGiftMapper.selectList(new LambdaQueryWrapper() + .eq(CardGift::getUserId, nowAccountInfo.getId()) + .eq(CardGift::getStoreId, balance.getStoreId())); + + if (CollUtil.isNotEmpty(cardGifts)) { + Double giftCardAmount = cardGifts.stream().mapToDouble(CardGift::getCardAmount).sum(); + userBlanceUniVo.setGiftCardAmount(giftCardAmount); + } + + userBlanceUniVo.setGiftCardCount(cardGifts.size()); + } else { userBlanceUniVo.setAllBalance(0.0); userBlanceUniVo.setCardBalance(0.0); userBlanceUniVo.setGiveAmount(0.0); } return userBlanceUniVo; } + /** * 初始化用户余额信息 + * * @param userId * @param chainStoreId * @return diff --git a/fuintBackend/fuint-application/src/main/java/com/fuint/business/userManager/vo/UserBlanceUniVo.java b/fuintBackend/fuint-application/src/main/java/com/fuint/business/userManager/vo/UserBlanceUniVo.java index f4e21ecd9..109f74e65 100644 --- a/fuintBackend/fuint-application/src/main/java/com/fuint/business/userManager/vo/UserBlanceUniVo.java +++ b/fuintBackend/fuint-application/src/main/java/com/fuint/business/userManager/vo/UserBlanceUniVo.java @@ -10,4 +10,10 @@ public class UserBlanceUniVo extends UserBalance { //卡券数量 private int cardFavorableCount; + + //礼品卡数量 + private int giftCardCount; + + //礼品卡总金额 + private Double giftCardAmount; }