Commit 1a36c5c834a91b1c793dc959c53e5ec5d18cb82e

Authored by 痴货
1 parent 325d5e6b

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

yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/job/order/TradeOrderAutoCommentJob.java
@@ -21,7 +21,7 @@ public class TradeOrderAutoCommentJob implements JobHandler { @@ -21,7 +21,7 @@ public class TradeOrderAutoCommentJob implements JobHandler {
21 @Override 21 @Override
22 @TenantJob 22 @TenantJob
23 public String execute(String param) { 23 public String execute(String param) {
24 - int count = tradeOrderUpdateService.createOrderItemCommentBySystem(); 24 + int count = tradeOrderUpdateService.createOrderItemCommentBySystem();
25 return String.format("评论订单 %s 个", count); 25 return String.format("评论订单 %s 个", count);
26 } 26 }
27 27
yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/BrokerageWithdrawServiceImpl.java
@@ -10,8 +10,12 @@ import cn.iocoder.yudao.framework.common.util.number.MoneyUtils; @@ -10,8 +10,12 @@ import cn.iocoder.yudao.framework.common.util.number.MoneyUtils;
10 import cn.iocoder.yudao.module.pay.api.transfer.PayTransferApi; 10 import cn.iocoder.yudao.module.pay.api.transfer.PayTransferApi;
11 import cn.iocoder.yudao.module.pay.api.transfer.dto.PayTransferCreateReqDTO; 11 import cn.iocoder.yudao.module.pay.api.transfer.dto.PayTransferCreateReqDTO;
12 import cn.iocoder.yudao.module.pay.api.transfer.dto.PayTransferRespDTO; 12 import cn.iocoder.yudao.module.pay.api.transfer.dto.PayTransferRespDTO;
  13 +import cn.iocoder.yudao.module.pay.api.wallet.PayWalletApi;
  14 +import cn.iocoder.yudao.module.pay.api.wallet.dto.PayWalletCreateReqDto;
  15 +import cn.iocoder.yudao.module.pay.api.wallet.dto.PayWalletRespDTO;
13 import cn.iocoder.yudao.module.pay.enums.transfer.PayTransferStatusEnum; 16 import cn.iocoder.yudao.module.pay.enums.transfer.PayTransferStatusEnum;
14 import cn.iocoder.yudao.module.pay.enums.transfer.PayTransferTypeEnum; 17 import cn.iocoder.yudao.module.pay.enums.transfer.PayTransferTypeEnum;
  18 +import cn.iocoder.yudao.module.pay.enums.wallet.PayWalletBizTypeEnum;
15 import cn.iocoder.yudao.module.system.api.notify.NotifyMessageSendApi; 19 import cn.iocoder.yudao.module.system.api.notify.NotifyMessageSendApi;
16 import cn.iocoder.yudao.module.system.api.notify.dto.NotifySendSingleToUserReqDTO; 20 import cn.iocoder.yudao.module.system.api.notify.dto.NotifySendSingleToUserReqDTO;
17 import cn.iocoder.yudao.module.system.api.social.SocialUserApi; 21 import cn.iocoder.yudao.module.system.api.social.SocialUserApi;
@@ -68,6 +72,8 @@ public class BrokerageWithdrawServiceImpl implements BrokerageWithdrawService { @@ -68,6 +72,8 @@ public class BrokerageWithdrawServiceImpl implements BrokerageWithdrawService {
68 private PayTransferApi payTransferApi; 72 private PayTransferApi payTransferApi;
69 @Resource 73 @Resource
70 private SocialUserApi socialUserApi; 74 private SocialUserApi socialUserApi;
  75 + @Resource
  76 + private PayWalletApi payWalletApi;
71 77
72 @Resource 78 @Resource
73 private Validator validator; 79 private Validator validator;
@@ -98,7 +104,18 @@ public class BrokerageWithdrawServiceImpl implements BrokerageWithdrawService { @@ -98,7 +104,18 @@ public class BrokerageWithdrawServiceImpl implements BrokerageWithdrawService {
98 templateCode = MessageTemplateConstants.SMS_BROKERAGE_WITHDRAW_AUDIT_APPROVE; 104 templateCode = MessageTemplateConstants.SMS_BROKERAGE_WITHDRAW_AUDIT_APPROVE;
99 // 3.1 通过时佣金转余额 105 // 3.1 通过时佣金转余额
100 if (BrokerageWithdrawTypeEnum.WALLET.getType().equals(withdraw.getType())) { 106 if (BrokerageWithdrawTypeEnum.WALLET.getType().equals(withdraw.getType())) {
101 - // todo 疯狂: 107 + PayWalletRespDTO wallet = payWalletApi.getWalletByUserId(withdraw.getUserId());
  108 + payWalletApi.addWallet(new PayWalletCreateReqDto()
  109 + .setWalletId(wallet.getId())
  110 + .setBizType(PayWalletBizTypeEnum.WITHDRAW)
  111 + .setBizId(withdraw.getId().toString())
  112 + .setPrice(withdraw.getPrice())
  113 + .setTitle("分佣提现"));
  114 + rows = brokerageWithdrawMapper.updateByIdAndStatus(id, BrokerageWithdrawStatusEnum.AUDIT_SUCCESS.getStatus(),
  115 + new BrokerageWithdrawDO().setStatus(BrokerageWithdrawStatusEnum.WITHDRAW_SUCCESS.getStatus()).setAuditReason(auditReason).setAuditTime(LocalDateTime.now()));
  116 + if (rows == 0) {
  117 + throw exception(BROKERAGE_WITHDRAW_STATUS_NOT_AUDITING);
  118 + }
102 }else if (BrokerageWithdrawTypeEnum.ALIPAY_SMALL.getType().equals(withdraw.getType())){ 119 }else if (BrokerageWithdrawTypeEnum.ALIPAY_SMALL.getType().equals(withdraw.getType())){
103 //获取openid 120 //获取openid
104 SocialUserRespDTO socialUser = socialUserApi.getSocialUserByUserId(UserTypeEnum.MEMBER.getValue(), withdraw.getUserId(), SocialTypeEnum.WECHAT_MINI_APP.getType()); 121 SocialUserRespDTO socialUser = socialUserApi.getSocialUserByUserId(UserTypeEnum.MEMBER.getValue(), withdraw.getUserId(), SocialTypeEnum.WECHAT_MINI_APP.getType());
yudao-module-pay/yudao-module-pay-api/src/main/java/cn/iocoder/yudao/module/pay/api/wallet/PayWalletApi.java 0 → 100644
  1 +package cn.iocoder.yudao.module.pay.api.wallet;
  2 +
  3 +import cn.iocoder.yudao.module.pay.api.wallet.dto.PayWalletCreateReqDto;
  4 +import cn.iocoder.yudao.module.pay.api.wallet.dto.PayWalletRespDTO;
  5 +
  6 +/**
  7 + * 钱包 API 接口
  8 + *
  9 + * @author liurulin
  10 + */
  11 +public interface PayWalletApi {
  12 +
  13 + /**
  14 + * 添加钱包
  15 + * @param reqDTO 创建请求
  16 + */
  17 + void addWallet(PayWalletCreateReqDto reqDTO);
  18 +
  19 + /**
  20 + * 根据用户id获取钱包信息
  21 + * @param userId 用户id
  22 + * @return 钱包信息
  23 + */
  24 + PayWalletRespDTO getWalletByUserId(Long userId);
  25 +}
yudao-module-pay/yudao-module-pay-api/src/main/java/cn/iocoder/yudao/module/pay/api/wallet/dto/PayWalletCreateReqDto.java 0 → 100644
  1 +package cn.iocoder.yudao.module.pay.api.wallet.dto;
  2 +
  3 +import cn.iocoder.yudao.module.pay.enums.wallet.PayWalletBizTypeEnum;
  4 +import jakarta.validation.constraints.NotNull;
  5 +import lombok.Data;
  6 +
  7 +@Data
  8 +public class PayWalletCreateReqDto {
  9 +
  10 + /**
  11 + * 钱包编号
  12 + */
  13 + @NotNull(message = "钱包编号不能为空")
  14 + private Long walletId;
  15 +
  16 + /**
  17 + * 关联业务分类
  18 + */
  19 + @NotNull(message = "关联业务分类不能为空")
  20 + private PayWalletBizTypeEnum bizType;
  21 +
  22 + /**
  23 + * 关联业务编号
  24 + */
  25 + @NotNull(message = "关联业务编号不能为空")
  26 + private String bizId;
  27 +
  28 + /**
  29 + * 流水说明
  30 + */
  31 + @NotNull(message = "流水说明不能为空")
  32 + private String title;
  33 +
  34 + /**
  35 + * 交易金额,单位分
  36 + *
  37 + * 正值表示余额增加,负值表示余额减少
  38 + */
  39 + @NotNull(message = "交易金额不能为空")
  40 + private Integer price;
  41 +
  42 +}
yudao-module-pay/yudao-module-pay-api/src/main/java/cn/iocoder/yudao/module/pay/api/wallet/dto/PayWalletRespDTO.java 0 → 100644
  1 +package cn.iocoder.yudao.module.pay.api.wallet.dto;
  2 +
  3 +import lombok.Data;
  4 +
  5 +@Data
  6 +public class PayWalletRespDTO {
  7 +
  8 + /**
  9 + * 编号
  10 + */
  11 + private Long id;
  12 +
  13 + /**
  14 + * 余额,单位分
  15 + */
  16 + private Integer balance;
  17 +
  18 +}
yudao-module-pay/yudao-module-pay-api/src/main/java/cn/iocoder/yudao/module/pay/enums/wallet/PayWalletBizTypeEnum.java
@@ -19,7 +19,8 @@ public enum PayWalletBizTypeEnum implements IntArrayValuable { @@ -19,7 +19,8 @@ public enum PayWalletBizTypeEnum implements IntArrayValuable {
19 RECHARGE_REFUND(2, "充值退款"), 19 RECHARGE_REFUND(2, "充值退款"),
20 PAYMENT(3, "支付"), 20 PAYMENT(3, "支付"),
21 PAYMENT_REFUND(4, "支付退款"), 21 PAYMENT_REFUND(4, "支付退款"),
22 - UPDATE_BALANCE(5, "更新余额"); 22 + UPDATE_BALANCE(5, "更新余额"),
  23 + WITHDRAW(6, "分佣提现");
23 24
24 /** 25 /**
25 * 业务分类 26 * 业务分类
@@ -36,4 +37,5 @@ public enum PayWalletBizTypeEnum implements IntArrayValuable { @@ -36,4 +37,5 @@ public enum PayWalletBizTypeEnum implements IntArrayValuable {
36 public int[] array() { 37 public int[] array() {
37 return ARRAYS; 38 return ARRAYS;
38 } 39 }
  40 +
39 } 41 }
yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/api/wallet/PayWalletApiImpl.java 0 → 100644
  1 +package cn.iocoder.yudao.module.pay.api.wallet;
  2 +
  3 +import cn.iocoder.yudao.framework.common.enums.UserTypeEnum;
  4 +import cn.iocoder.yudao.module.pay.api.wallet.dto.PayWalletCreateReqDto;
  5 +import cn.iocoder.yudao.module.pay.api.wallet.dto.PayWalletRespDTO;
  6 +import cn.iocoder.yudao.module.pay.convert.wallet.PayWalletConvert;
  7 +import cn.iocoder.yudao.module.pay.dal.dataobject.wallet.PayWalletDO;
  8 +import cn.iocoder.yudao.module.pay.service.wallet.PayWalletService;
  9 +import jakarta.annotation.Resource;
  10 +import org.springframework.stereotype.Service;
  11 +
  12 +/**
  13 + * 钱包 API 实现类
  14 + *
  15 + * @author 芋道源码
  16 + */
  17 +@Service
  18 +public class PayWalletApiImpl implements PayWalletApi {
  19 +
  20 + @Resource
  21 + private PayWalletService payWalletService;
  22 +
  23 + @Override
  24 + public void addWallet(PayWalletCreateReqDto reqDTO) {
  25 + //添加钱包金额
  26 + payWalletService.addWalletBalance(reqDTO.getWalletId(), reqDTO.getBizId(), reqDTO.getBizType(), reqDTO.getPrice());
  27 + }
  28 +
  29 + @Override
  30 + public PayWalletRespDTO getWalletByUserId(Long userId) {
  31 + PayWalletDO orCreateWallet = payWalletService.getOrCreateWallet(userId, UserTypeEnum.MEMBER.getValue());
  32 + return PayWalletConvert.INSTANCE.convert03(orCreateWallet);
  33 + }
  34 +}
yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/convert/wallet/PayWalletConvert.java
1 package cn.iocoder.yudao.module.pay.convert.wallet; 1 package cn.iocoder.yudao.module.pay.convert.wallet;
2 2
3 import cn.iocoder.yudao.framework.common.pojo.PageResult; 3 import cn.iocoder.yudao.framework.common.pojo.PageResult;
  4 +import cn.iocoder.yudao.module.pay.api.wallet.dto.PayWalletCreateReqDto;
  5 +import cn.iocoder.yudao.module.pay.api.wallet.dto.PayWalletRespDTO;
4 import cn.iocoder.yudao.module.pay.controller.admin.wallet.vo.wallet.PayWalletRespVO; 6 import cn.iocoder.yudao.module.pay.controller.admin.wallet.vo.wallet.PayWalletRespVO;
5 import cn.iocoder.yudao.module.pay.controller.app.wallet.vo.wallet.AppPayWalletRespVO; 7 import cn.iocoder.yudao.module.pay.controller.app.wallet.vo.wallet.AppPayWalletRespVO;
6 import cn.iocoder.yudao.module.pay.dal.dataobject.wallet.PayWalletDO; 8 import cn.iocoder.yudao.module.pay.dal.dataobject.wallet.PayWalletDO;
@@ -18,4 +20,6 @@ public interface PayWalletConvert { @@ -18,4 +20,6 @@ public interface PayWalletConvert {
18 20
19 PageResult<PayWalletRespVO> convertPage(PageResult<PayWalletDO> page); 21 PageResult<PayWalletRespVO> convertPage(PageResult<PayWalletDO> page);
20 22
  23 + PayWalletRespDTO convert03(PayWalletDO orCreateWallet);
  24 +
21 } 25 }
yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/service/wallet/PayWalletServiceImpl.java
@@ -200,6 +200,9 @@ public class PayWalletServiceImpl implements PayWalletService { @@ -200,6 +200,9 @@ public class PayWalletServiceImpl implements PayWalletService {
200 case UPDATE_BALANCE: // 更新余额 200 case UPDATE_BALANCE: // 更新余额
201 walletMapper.updateWhenRecharge(payWallet.getId(), price); 201 walletMapper.updateWhenRecharge(payWallet.getId(), price);
202 break; 202 break;
  203 + case WITHDRAW:
  204 + walletMapper.updateWhenRecharge(payWallet.getId(), price);
  205 + break;
203 default: { 206 default: {
204 // TODO 其它类型待实现 207 // TODO 其它类型待实现
205 throw new UnsupportedOperationException("待实现"); 208 throw new UnsupportedOperationException("待实现");