【功能优化】增加钱包分佣提现功能

This commit is contained in:
痴货
2024-10-07 11:32:14 +08:00
parent 325d5e6b12
commit 1a36c5c834
9 changed files with 148 additions and 3 deletions

View File

@@ -0,0 +1,25 @@
package cn.iocoder.yudao.module.pay.api.wallet;
import cn.iocoder.yudao.module.pay.api.wallet.dto.PayWalletCreateReqDto;
import cn.iocoder.yudao.module.pay.api.wallet.dto.PayWalletRespDTO;
/**
* 钱包 API 接口
*
* @author liurulin
*/
public interface PayWalletApi {
/**
* 添加钱包
* @param reqDTO 创建请求
*/
void addWallet(PayWalletCreateReqDto reqDTO);
/**
* 根据用户id获取钱包信息
* @param userId 用户id
* @return 钱包信息
*/
PayWalletRespDTO getWalletByUserId(Long userId);
}

View File

@@ -0,0 +1,42 @@
package cn.iocoder.yudao.module.pay.api.wallet.dto;
import cn.iocoder.yudao.module.pay.enums.wallet.PayWalletBizTypeEnum;
import jakarta.validation.constraints.NotNull;
import lombok.Data;
@Data
public class PayWalletCreateReqDto {
/**
* 钱包编号
*/
@NotNull(message = "钱包编号不能为空")
private Long walletId;
/**
* 关联业务分类
*/
@NotNull(message = "关联业务分类不能为空")
private PayWalletBizTypeEnum bizType;
/**
* 关联业务编号
*/
@NotNull(message = "关联业务编号不能为空")
private String bizId;
/**
* 流水说明
*/
@NotNull(message = "流水说明不能为空")
private String title;
/**
* 交易金额,单位分
*
* 正值表示余额增加,负值表示余额减少
*/
@NotNull(message = "交易金额不能为空")
private Integer price;
}

View File

@@ -0,0 +1,18 @@
package cn.iocoder.yudao.module.pay.api.wallet.dto;
import lombok.Data;
@Data
public class PayWalletRespDTO {
/**
* 编号
*/
private Long id;
/**
* 余额,单位分
*/
private Integer balance;
}

View File

@@ -19,7 +19,8 @@ public enum PayWalletBizTypeEnum implements IntArrayValuable {
RECHARGE_REFUND(2, "充值退款"),
PAYMENT(3, "支付"),
PAYMENT_REFUND(4, "支付退款"),
UPDATE_BALANCE(5, "更新余额");
UPDATE_BALANCE(5, "更新余额"),
WITHDRAW(6, "分佣提现");
/**
* 业务分类
@@ -36,4 +37,5 @@ public enum PayWalletBizTypeEnum implements IntArrayValuable {
public int[] array() {
return ARRAYS;
}
}

View File

@@ -0,0 +1,34 @@
package cn.iocoder.yudao.module.pay.api.wallet;
import cn.iocoder.yudao.framework.common.enums.UserTypeEnum;
import cn.iocoder.yudao.module.pay.api.wallet.dto.PayWalletCreateReqDto;
import cn.iocoder.yudao.module.pay.api.wallet.dto.PayWalletRespDTO;
import cn.iocoder.yudao.module.pay.convert.wallet.PayWalletConvert;
import cn.iocoder.yudao.module.pay.dal.dataobject.wallet.PayWalletDO;
import cn.iocoder.yudao.module.pay.service.wallet.PayWalletService;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;
/**
* 钱包 API 实现类
*
* @author 芋道源码
*/
@Service
public class PayWalletApiImpl implements PayWalletApi {
@Resource
private PayWalletService payWalletService;
@Override
public void addWallet(PayWalletCreateReqDto reqDTO) {
//添加钱包金额
payWalletService.addWalletBalance(reqDTO.getWalletId(), reqDTO.getBizId(), reqDTO.getBizType(), reqDTO.getPrice());
}
@Override
public PayWalletRespDTO getWalletByUserId(Long userId) {
PayWalletDO orCreateWallet = payWalletService.getOrCreateWallet(userId, UserTypeEnum.MEMBER.getValue());
return PayWalletConvert.INSTANCE.convert03(orCreateWallet);
}
}

View File

@@ -1,6 +1,8 @@
package cn.iocoder.yudao.module.pay.convert.wallet;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.module.pay.api.wallet.dto.PayWalletCreateReqDto;
import cn.iocoder.yudao.module.pay.api.wallet.dto.PayWalletRespDTO;
import cn.iocoder.yudao.module.pay.controller.admin.wallet.vo.wallet.PayWalletRespVO;
import cn.iocoder.yudao.module.pay.controller.app.wallet.vo.wallet.AppPayWalletRespVO;
import cn.iocoder.yudao.module.pay.dal.dataobject.wallet.PayWalletDO;
@@ -18,4 +20,6 @@ public interface PayWalletConvert {
PageResult<PayWalletRespVO> convertPage(PageResult<PayWalletDO> page);
PayWalletRespDTO convert03(PayWalletDO orCreateWallet);
}

View File

@@ -200,6 +200,9 @@ public class PayWalletServiceImpl implements PayWalletService {
case UPDATE_BALANCE: // 更新余额
walletMapper.updateWhenRecharge(payWallet.getId(), price);
break;
case WITHDRAW:
walletMapper.updateWhenRecharge(payWallet.getId(), price);
break;
default: {
// TODO 其它类型待实现
throw new UnsupportedOperationException("待实现");