我的钱包业务逻辑实现

This commit is contained in:
2025-02-20 17:26:54 +08:00
parent 416f1d4558
commit 88d7814ad4
9 changed files with 237 additions and 0 deletions

View File

@@ -0,0 +1,41 @@
package com.buy507.mall.portal.controller;
import com.buy507.mall.common.api.CommonResult;
import com.buy507.mall.portal.service.MyWalletService;
import com.buy507.mall.portal.vo.WalletCashVo;
import com.buy507.mall.portal.vo.WalletPointsVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
@RestController
@RequestMapping("/wallet")
public class MyWalletController {
@Autowired
private MyWalletService myWalletService;
/**
* 获取现金余额和流水
* @param userId
* @return
*/
@GetMapping("/balance")
public CommonResult<WalletCashVo> getBalance(@RequestParam Long userId){
WalletCashVo walletCashVo = myWalletService.getBalanceAndCashFlow(userId);
return CommonResult.success(walletCashVo);
}
/**
* 获取积分余额和流水
* @param userId
* @return
*/
@GetMapping("/points")
public CommonResult<WalletPointsVo> getIntegration(@RequestParam Long userId){
WalletPointsVo walletPointsVo = myWalletService.getIntegrationAndPointsFlow(userId);
return CommonResult.success(walletPointsVo);
}
}

View File

@@ -0,0 +1,47 @@
package com.buy507.mall.portal.dao;
import com.buy507.mall.portal.vo.TransactionCashVo;
import com.buy507.mall.portal.vo.TransactionPointsVo;
import com.buy507.mall.portal.vo.WalletCashVo;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import java.math.BigDecimal;
import java.util.List;
@Mapper
public interface MyWalletMapper {
/**
* 获取用户现金余额
* @param userId
* @return
*/
@Select("SELECT balance FROM ums_member WHERE id = #{userId}")
BigDecimal getBalance(Long userId);
/**
* 获取用户现金流水
* @param userId
* @return
*/
@Select("SELECT revenue_amount, remarks, transfer_payment_time FROM ums_member_account_transaction " +
"WHERE ums_member_account_transaction.member_id = #{userId} ORDER BY transfer_payment_time DESC")
List<TransactionCashVo> getCashFlow(Long userId);
/**
* 获取用户积分余额
* @param userId
* @return
*/
@Select("SELECT integration FROM ums_member WHERE id = #{userId}")
Integer getIntegration(Long userId);
/**
* 获取用户积分流水
* @param userId
* @return
*/
@Select("SELECT revenue_points, remarks, transfer_payment_time FROM ums_member_account_transaction " +
"WHERE ums_member_account_transaction.member_id = #{userId} ORDER BY transfer_payment_time DESC")
List<TransactionPointsVo> getPointsFlow(Long userId);
}

View File

@@ -0,0 +1,21 @@
package com.buy507.mall.portal.service;
import com.buy507.mall.portal.vo.WalletCashVo;
import com.buy507.mall.portal.vo.WalletPointsVo;
public interface MyWalletService {
/**
* 获取现金余额和流水
* @param userId
* @return
*/
WalletCashVo getBalanceAndCashFlow(Long userId);
/**
* 获取积分余额和流水
* @param userId
* @return
*/
WalletPointsVo getIntegrationAndPointsFlow(Long userId);
}

View File

@@ -0,0 +1,49 @@
package com.buy507.mall.portal.service.impl;
import com.buy507.mall.portal.dao.MyWalletMapper;
import com.buy507.mall.portal.service.MyWalletService;
import com.buy507.mall.portal.vo.WalletCashVo;
import com.buy507.mall.portal.vo.WalletPointsVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
@Service
public class MyWalletServiceImpl implements MyWalletService {
@Autowired
private MyWalletMapper myWalletMapper;
/**
* 获取现金余额和流水
* @param userId
* @return
*/
@Override
public WalletCashVo getBalanceAndCashFlow(Long userId) {
WalletCashVo walletCashVo = new WalletCashVo();
//获取现金余额
walletCashVo.setBalance(myWalletMapper.getBalance(userId));
//获取现金流水
walletCashVo.setCashVoList(myWalletMapper.getCashFlow(userId));
return walletCashVo;
}
/**
* 获取积分余额和流水
* @param userId
* @return
*/
@Override
public WalletPointsVo getIntegrationAndPointsFlow(Long userId) {
WalletPointsVo walletPointsVo = new WalletPointsVo();
//获取积分余额
walletPointsVo.setIntegration(myWalletMapper.getIntegration(userId));
//获取积分流水
walletPointsVo.setPointsVoList(myWalletMapper.getPointsFlow(userId));
return walletPointsVo;
}
}

View File

@@ -0,0 +1,22 @@
package com.buy507.mall.portal.vo;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import java.io.Serializable;
@Data
@AllArgsConstructor
@NoArgsConstructor
public class TransactionCashVo implements Serializable {
//现金数额
private Integer revenueAmount;
//备注
private String remarks;
//时间
private Data transferPaymentTime;
}

View File

@@ -0,0 +1,21 @@
package com.buy507.mall.portal.vo;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import java.io.Serializable;
@Data
@AllArgsConstructor
@NoArgsConstructor
public class TransactionPointsVo implements Serializable {
//积分数额
private Integer revenuePoints;
//备注
private String remarks;
//时间
private Data transferPaymentTime;
}

View File

@@ -0,0 +1,16 @@
package com.buy507.mall.portal.vo;
import lombok.Data;
import java.math.BigDecimal;
import java.util.List;
@Data
public class WalletCashVo {
// 余额现金
private BigDecimal balance;
//现金流水
private List<TransactionCashVo> cashVoList;
}

View File

@@ -0,0 +1,15 @@
package com.buy507.mall.portal.vo;
import lombok.Data;
import java.math.BigDecimal;
import java.util.List;
@Data
public class WalletPointsVo {
// 余额积分
private Integer integration;
//积分流水
private List<TransactionPointsVo> pointsVoList;
}

View File

@@ -0,0 +1,5 @@
<?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.buy507.mall.portal.dao.MyWalletMapper">
</mapper>