update 获取累计充值金额

This commit is contained in:
2024-03-04 16:34:55 +08:00
parent b88fdb0467
commit 7c6b7eab72
5 changed files with 60 additions and 8 deletions

View File

@@ -332,26 +332,40 @@ public class MemberService {
// 查询会员钱包信息表,获取 本金余额
// MemberWalletInfo memberWalletInfo = memberWalletInfoService.selectByMemberId(dto.getMemberId(), null);
MemberWalletInfo memberWalletInfo = memberWalletInfoService.selectByWalletCode(dto.getWalletCode());
if (memberWalletInfo == null) {
MemberWalletVO memberWalletVO = memberWalletInfoService.selectMemberWalletInfo(dto.getWalletCode());
// MemberWalletInfo memberWalletInfo = memberWalletInfoService.selectByWalletCode(dto.getWalletCode());
if (memberWalletVO == null) {
// 用户未注册小程序
throw new BusinessException(ReturnCodeEnum.CODE_AUTHENTICATION_ERROR);
}
// 当前余额
vo.setCurrentBalance(memberWalletInfo.getPrincipalBalance().add(memberWalletInfo.getGiftBalance()));
vo.setCurrentBalance(memberWalletVO.getPrincipalBalance().add(memberWalletVO.getGiftBalance()));
// 累计充值金额
vo.setAccumulatedRechargeAmount(memberWalletVO.getAccumulatedRechargeAmount());
// 累计赠送金额
vo.setAccumulatedRechargeGift(memberWalletVO.getAccumulatedRechargeGift());
// 累计消费金额
vo.setAccumulatedConsumptionAmount(memberWalletVO.getAccumulatedConsumptionAmount());
// 根据日期查询会员钱包变动明细
// 分页
// PageHelper.startPage(pageNum, pageSize);
List<MemberWalletLogVO> list = memberBasicInfoService.getMemberWalletDetail(dto);
// 总支出
BigDecimal totalConsumption = list.stream()
.map(MemberWalletLogVO::getOrderAmount)
.filter(Objects::nonNull)
.reduce(BigDecimal.ZERO, BigDecimal::add);
vo.setTotalConsumption(totalConsumption);
// 总充值
BigDecimal totalRechargeAmount = list.stream()
.filter(x -> StringUtils.equals(x.getType(), "1"))
.filter(x -> StringUtils.equals(x.getSubType(), "10") || StringUtils.equals(x.getSubType(), "11"))
.map(MemberWalletLogVO::getAmount)
.reduce(BigDecimal.ZERO, BigDecimal::add);
vo.setTotalRechargeAmount(totalRechargeAmount);
// PageInfo<MemberWalletLogVO> pageInfo = new PageInfo<>(list);
// 获取 type 和 subType 的对应信息
for (MemberWalletLogVO walletLogVO : list) {
@@ -382,7 +396,6 @@ public class MemberService {
.build();
vo.setPageResponse(pageResponse);
// log.info("查询用户余额信息 service方法 end");
return vo;
}

View File

@@ -23,4 +23,6 @@ public interface MemberWalletInfoService {
int updateByPrimaryKey(MemberWalletInfo record);
List<MemberWalletVO> selectByMemberWalletList(String memberId);
MemberWalletVO selectMemberWalletInfo(String walletCode);
}

View File

@@ -11,6 +11,7 @@ import org.apache.commons.collections4.CollectionUtils;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.math.BigDecimal;
import java.util.List;
import java.util.Objects;
@@ -86,8 +87,21 @@ public class MemberWalletInfoServiceImpl implements MemberWalletInfoService {
return resultList;
}
/**
* 查询会员钱包信息
* @param walletCode
* @return
*/
@Override
public MemberWalletVO selectMemberWalletInfo(String walletCode) {
return memberWalletInfoMapper.selectMemberWalletInfo(walletCode);
MemberWalletVO memberWalletVO = memberWalletInfoMapper.selectMemberWalletInfo(walletCode);
// 累计消费金额 = 累计充值 + 累计赠送 - 本金余额 - 赠送金余额
BigDecimal accumulatedConsumptionAmount = memberWalletVO.getAccumulatedRechargeAmount()
.add(memberWalletVO.getAccumulatedRechargeAmount())
.subtract(memberWalletVO.getPrincipalBalance())
.subtract(memberWalletVO.getGiftBalance());
memberWalletVO.setAccumulatedConsumptionAmount(accumulatedConsumptionAmount);
return memberWalletVO;
}
}

View File

@@ -28,6 +28,11 @@ public class MemberWalletInfoVO {
*/
private BigDecimal accumulatedRechargeAmount;
/**
* 累计赠送金额
*/
private BigDecimal accumulatedRechargeGift;
/**
* 累计消费
*/

View File

@@ -203,6 +203,24 @@
</select>
<select id="selectMemberWalletInfo" resultType="com.jsowell.pile.vo.base.MemberWalletVO">
SELECT t1.member_id as memberId,
t1.wallet_code as walletCode,
t1.merchant_id as merchantId,
t1.principal_balance as principalBalance,
t1.gift_balance as giftBalance,
t2.accumulatedRechargeAmount as accumulatedRechargeAmount,
t3.accumulatedRechargeGift as accumulatedRechargeGift
from member_wallet_info t1
left join (select wallet_code, sum(amount) as accumulatedRechargeAmount
from `member_wallet_log`
WHERE `wallet_code` = #{walletCode,jdbcType=VARCHAR}
and type = '1'
and sub_type = '10') t2 on t2.wallet_code = t1.wallet_code
left join (select wallet_code, sum(amount) as accumulatedRechargeGift
from `member_wallet_log`
WHERE `wallet_code` = #{walletCode,jdbcType=VARCHAR}
and type = '1'
and sub_type = '11') t3 on t3.wallet_code = t1.wallet_code
where t1.wallet_code = #{walletCode,jdbcType=VARCHAR}
</select>
</mapper>