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

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

@ -21,7 +21,7 @@ public class TradeOrderAutoCommentJob implements JobHandler {
@Override
@TenantJob
public String execute(String param) {
int count = tradeOrderUpdateService.createOrderItemCommentBySystem();
int count = tradeOrderUpdateService.createOrderItemCommentBySystem();
return String.format("评论订单 %s 个", count);
}

View File

@ -10,8 +10,12 @@ import cn.iocoder.yudao.framework.common.util.number.MoneyUtils;
import cn.iocoder.yudao.module.pay.api.transfer.PayTransferApi;
import cn.iocoder.yudao.module.pay.api.transfer.dto.PayTransferCreateReqDTO;
import cn.iocoder.yudao.module.pay.api.transfer.dto.PayTransferRespDTO;
import cn.iocoder.yudao.module.pay.api.wallet.PayWalletApi;
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.enums.transfer.PayTransferStatusEnum;
import cn.iocoder.yudao.module.pay.enums.transfer.PayTransferTypeEnum;
import cn.iocoder.yudao.module.pay.enums.wallet.PayWalletBizTypeEnum;
import cn.iocoder.yudao.module.system.api.notify.NotifyMessageSendApi;
import cn.iocoder.yudao.module.system.api.notify.dto.NotifySendSingleToUserReqDTO;
import cn.iocoder.yudao.module.system.api.social.SocialUserApi;
@ -68,6 +72,8 @@ public class BrokerageWithdrawServiceImpl implements BrokerageWithdrawService {
private PayTransferApi payTransferApi;
@Resource
private SocialUserApi socialUserApi;
@Resource
private PayWalletApi payWalletApi;
@Resource
private Validator validator;
@ -98,7 +104,18 @@ public class BrokerageWithdrawServiceImpl implements BrokerageWithdrawService {
templateCode = MessageTemplateConstants.SMS_BROKERAGE_WITHDRAW_AUDIT_APPROVE;
// 3.1 通过时佣金转余额
if (BrokerageWithdrawTypeEnum.WALLET.getType().equals(withdraw.getType())) {
// todo 疯狂
PayWalletRespDTO wallet = payWalletApi.getWalletByUserId(withdraw.getUserId());
payWalletApi.addWallet(new PayWalletCreateReqDto()
.setWalletId(wallet.getId())
.setBizType(PayWalletBizTypeEnum.WITHDRAW)
.setBizId(withdraw.getId().toString())
.setPrice(withdraw.getPrice())
.setTitle("分佣提现"));
rows = brokerageWithdrawMapper.updateByIdAndStatus(id, BrokerageWithdrawStatusEnum.AUDIT_SUCCESS.getStatus(),
new BrokerageWithdrawDO().setStatus(BrokerageWithdrawStatusEnum.WITHDRAW_SUCCESS.getStatus()).setAuditReason(auditReason).setAuditTime(LocalDateTime.now()));
if (rows == 0) {
throw exception(BROKERAGE_WITHDRAW_STATUS_NOT_AUDITING);
}
}else if (BrokerageWithdrawTypeEnum.ALIPAY_SMALL.getType().equals(withdraw.getType())){
//获取openid
SocialUserRespDTO socialUser = socialUserApi.getSocialUserByUserId(UserTypeEnum.MEMBER.getValue(), withdraw.getUserId(), SocialTypeEnum.WECHAT_MINI_APP.getType());

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("待实现");