【代码代码】PAY:移除对 member 的依赖
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
package cn.iocoder.yudao.module.pay.controller.admin.app;
|
||||
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum;
|
||||
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||
import cn.iocoder.yudao.module.pay.controller.admin.app.vo.*;
|
||||
@@ -12,14 +13,14 @@ import cn.iocoder.yudao.module.pay.service.channel.PayChannelService;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.Parameter;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import jakarta.annotation.Resource;
|
||||
import jakarta.validation.Valid;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import jakarta.annotation.Resource;
|
||||
import jakarta.validation.Valid;
|
||||
import java.util.*;
|
||||
import java.util.List;
|
||||
|
||||
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
|
||||
import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertList;
|
||||
@@ -87,9 +88,10 @@ public class PayAppController {
|
||||
return success(PageResult.empty());
|
||||
}
|
||||
|
||||
// 得到所有的应用编号,查出所有的渠道
|
||||
Collection<Long> appIds = convertList(pageResult.getList(), PayAppDO::getId);
|
||||
List<PayChannelDO> channels = channelService.getChannelListByAppIds(appIds);
|
||||
// 得到所有的应用编号,查出所有的渠道,并移除未启用的渠道
|
||||
List<PayChannelDO> channels = channelService.getChannelListByAppIds(
|
||||
convertList(pageResult.getList(), PayAppDO::getId));
|
||||
channels.removeIf(channel -> !CommonStatusEnum.ENABLE.getStatus().equals(channel.getStatus()));
|
||||
|
||||
// 拼接后返回
|
||||
return success(PayAppConvert.INSTANCE.convertPage(pageResult, channels));
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
package cn.iocoder.yudao.module.pay.controller.admin.app.vo;
|
||||
|
||||
import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum;
|
||||
import cn.iocoder.yudao.framework.common.validation.InEnum;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.*;
|
||||
import jakarta.validation.constraints.NotNull;
|
||||
import lombok.Data;
|
||||
import org.hibernate.validator.constraints.URL;
|
||||
|
||||
import jakarta.validation.constraints.*;
|
||||
|
||||
/**
|
||||
* 支付应用信息 Base VO,提供给添加、修改、详细的子 VO 使用
|
||||
* 如果子 VO 存在差异的字段,请不要添加到这里,影响 Swagger 文档生成
|
||||
|
||||
@@ -1,6 +1,9 @@
|
||||
package cn.iocoder.yudao.module.pay.controller.admin.app.vo;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.*;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.ToString;
|
||||
|
||||
@Schema(description = "管理后台 - 支付应用信息创建 Request VO")
|
||||
@Data
|
||||
|
||||
@@ -1,6 +1,9 @@
|
||||
package cn.iocoder.yudao.module.pay.controller.admin.app.vo;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.*;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.ToString;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
|
||||
@@ -1,7 +1,10 @@
|
||||
package cn.iocoder.yudao.module.pay.controller.admin.app.vo;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.*;
|
||||
import jakarta.validation.constraints.*;
|
||||
import jakarta.validation.constraints.NotNull;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.ToString;
|
||||
|
||||
@Schema(description = "管理后台 - 支付应用信息更新 Request VO")
|
||||
@Data
|
||||
|
||||
@@ -1,9 +1,8 @@
|
||||
package cn.iocoder.yudao.module.pay.controller.admin.app.vo;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.Data;
|
||||
|
||||
import jakarta.validation.constraints.NotNull;
|
||||
import lombok.Data;
|
||||
|
||||
@Schema(description = "管理后台 - 应用更新状态 Request VO")
|
||||
@Data
|
||||
|
||||
@@ -10,12 +10,12 @@ import cn.iocoder.yudao.module.pay.service.channel.PayChannelService;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.Parameter;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import jakarta.annotation.Resource;
|
||||
import jakarta.validation.Valid;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import jakarta.annotation.Resource;
|
||||
import jakarta.validation.Valid;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
|
||||
@@ -1,9 +1,10 @@
|
||||
package cn.iocoder.yudao.module.pay.controller.admin.channel.vo;
|
||||
|
||||
import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum;
|
||||
import cn.iocoder.yudao.framework.common.validation.InEnum;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.*;
|
||||
import jakarta.validation.constraints.*;
|
||||
import jakarta.validation.constraints.NotNull;
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* 支付渠道 Base VO,提供给添加、修改、详细的子 VO 使用
|
||||
|
||||
@@ -1,13 +1,12 @@
|
||||
package cn.iocoder.yudao.module.pay.controller.admin.channel.vo;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import jakarta.validation.constraints.NotBlank;
|
||||
import jakarta.validation.constraints.NotNull;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.ToString;
|
||||
|
||||
import jakarta.validation.constraints.NotBlank;
|
||||
import jakarta.validation.constraints.NotNull;
|
||||
|
||||
@Schema(description = "管理后台 - 支付渠道 创建 Request VO")
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
|
||||
@@ -1,6 +1,9 @@
|
||||
package cn.iocoder.yudao.module.pay.controller.admin.channel.vo;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.*;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.ToString;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
|
||||
@@ -1,7 +1,11 @@
|
||||
package cn.iocoder.yudao.module.pay.controller.admin.channel.vo;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.*;
|
||||
import jakarta.validation.constraints.*;
|
||||
import jakarta.validation.constraints.NotBlank;
|
||||
import jakarta.validation.constraints.NotNull;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.ToString;
|
||||
|
||||
@Schema(description = "管理后台 - 支付渠道 更新 Request VO")
|
||||
@Data
|
||||
|
||||
@@ -5,20 +5,19 @@ import cn.iocoder.yudao.framework.common.pojo.PageParam;
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||
import cn.iocoder.yudao.module.pay.api.notify.dto.PayOrderNotifyReqDTO;
|
||||
import cn.iocoder.yudao.module.pay.api.notify.dto.PayRefundNotifyReqDTO;
|
||||
import cn.iocoder.yudao.module.pay.controller.admin.demo.vo.PayDemoOrderCreateReqVO;
|
||||
import cn.iocoder.yudao.module.pay.controller.admin.demo.vo.PayDemoOrderRespVO;
|
||||
import cn.iocoder.yudao.module.pay.controller.admin.demo.vo.order.PayDemoOrderCreateReqVO;
|
||||
import cn.iocoder.yudao.module.pay.controller.admin.demo.vo.order.PayDemoOrderRespVO;
|
||||
import cn.iocoder.yudao.module.pay.convert.demo.PayDemoOrderConvert;
|
||||
import cn.iocoder.yudao.module.pay.dal.dataobject.demo.PayDemoOrderDO;
|
||||
import cn.iocoder.yudao.module.pay.service.demo.PayDemoOrderService;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.Parameter;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import jakarta.annotation.Resource;
|
||||
import jakarta.annotation.security.PermitAll;
|
||||
import jakarta.validation.Valid;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
|
||||
import static cn.iocoder.yudao.framework.common.util.servlet.ServletUtils.getClientIP;
|
||||
|
||||
@@ -1,21 +1,23 @@
|
||||
package cn.iocoder.yudao.module.pay.controller.admin.demo;
|
||||
|
||||
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageParam;
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||
import cn.iocoder.yudao.module.pay.api.notify.dto.PayTransferNotifyReqDTO;
|
||||
import cn.iocoder.yudao.module.pay.controller.admin.demo.vo.transfer.PayDemoTransferCreateReqVO;
|
||||
import cn.iocoder.yudao.module.pay.controller.admin.demo.vo.transfer.PayDemoTransferRespVO;
|
||||
import cn.iocoder.yudao.module.pay.convert.demo.PayDemoTransferConvert;
|
||||
import cn.iocoder.yudao.module.pay.dal.dataobject.demo.PayDemoTransferDO;
|
||||
import cn.iocoder.yudao.module.pay.service.demo.PayDemoTransferService;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import jakarta.annotation.Resource;
|
||||
import jakarta.annotation.security.PermitAll;
|
||||
import jakarta.validation.Valid;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
|
||||
import static cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils.getLoginUserId;
|
||||
|
||||
@Tag(name = "管理后台 - 示例转账单")
|
||||
@RestController
|
||||
@@ -27,7 +29,23 @@ public class PayDemoTransferController {
|
||||
|
||||
@PostMapping("/create")
|
||||
@Operation(summary = "创建示例转账订单")
|
||||
public CommonResult<Long> createDemoOrder(@Valid @RequestBody PayDemoTransferCreateReqVO createReqVO) {
|
||||
return success(demoTransferService.createDemoTransfer(getLoginUserId(), createReqVO));
|
||||
public CommonResult<Long> createDemoTransfer(@Valid @RequestBody PayDemoTransferCreateReqVO createReqVO) {
|
||||
return success(demoTransferService.createDemoTransfer(createReqVO));
|
||||
}
|
||||
|
||||
@GetMapping("/page")
|
||||
@Operation(summary = "获得示例转账订单分页")
|
||||
public CommonResult<PageResult<PayDemoTransferRespVO>> getDemoTransferPage(@Valid PageParam pageVO) {
|
||||
PageResult<PayDemoTransferDO> pageResult = demoTransferService.getDemoTransferPage(pageVO);
|
||||
return success(PayDemoTransferConvert.INSTANCE.convertPage(pageResult));
|
||||
}
|
||||
|
||||
@PostMapping("/update-status")
|
||||
@Operation(summary = "更新示例转账订单的转账状态") // 由 pay-module 转账服务,进行回调
|
||||
@PermitAll // 无需登录,安全由 PayDemoTransferService 内部校验实现
|
||||
public CommonResult<Boolean> updateDemoTransferStatus(@RequestBody PayTransferNotifyReqDTO notifyReqDTO) {
|
||||
demoTransferService.updateDemoTransferStatus(Long.valueOf(notifyReqDTO.getMerchantTransferId()),
|
||||
notifyReqDTO.getPayTransferId());
|
||||
return success(true);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,9 +1,8 @@
|
||||
package cn.iocoder.yudao.module.pay.controller.admin.demo.vo;
|
||||
package cn.iocoder.yudao.module.pay.controller.admin.demo.vo.order;
|
||||
|
||||
import lombok.*;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
|
||||
import jakarta.validation.constraints.NotNull;
|
||||
import lombok.Data;
|
||||
|
||||
@Schema(description = "管理后台 - 示例订单创建 Request VO")
|
||||
@Data
|
||||
@@ -1,7 +1,7 @@
|
||||
package cn.iocoder.yudao.module.pay.controller.admin.demo.vo;
|
||||
package cn.iocoder.yudao.module.pay.controller.admin.demo.vo.order;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.*;
|
||||
import lombok.Data;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
@@ -1,14 +1,17 @@
|
||||
package cn.iocoder.yudao.module.pay.controller.admin.demo.vo.transfer;
|
||||
|
||||
import cn.iocoder.yudao.framework.common.util.validation.ValidationUtils;
|
||||
import cn.iocoder.yudao.framework.common.validation.InEnum;
|
||||
import cn.iocoder.yudao.framework.pay.core.enums.transfer.PayTransferTypeEnum;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import jakarta.validation.Validator;
|
||||
import jakarta.validation.constraints.Min;
|
||||
import jakarta.validation.constraints.NotBlank;
|
||||
import jakarta.validation.constraints.NotNull;
|
||||
import lombok.Data;
|
||||
|
||||
import jakarta.validation.constraints.Min;
|
||||
import jakarta.validation.constraints.NotEmpty;
|
||||
import jakarta.validation.constraints.NotNull;
|
||||
import java.util.Map;
|
||||
import static cn.iocoder.yudao.module.pay.enums.transfer.PayTransferTypeEnum.Alipay;
|
||||
import static cn.iocoder.yudao.module.pay.enums.transfer.PayTransferTypeEnum.WxPay;
|
||||
|
||||
/**
|
||||
* @author jason
|
||||
@@ -22,13 +25,43 @@ public class PayDemoTransferCreateReqVO {
|
||||
@InEnum(PayTransferTypeEnum.class)
|
||||
private Integer type;
|
||||
|
||||
@Schema(description = "转账金额", requiredMode = Schema.RequiredMode.REQUIRED, example = "100")
|
||||
@NotNull(message = "转账金额不能为空")
|
||||
@Min(value = 1, message = "转账金额必须大于零")
|
||||
private Integer price;
|
||||
|
||||
// TODO @jason:感觉这个动态字段,晚点改;可能要讨论下怎么搞好;
|
||||
@Schema(description = "收款方信息", requiredMode = Schema.RequiredMode.REQUIRED, example = "{'ALIPAY_LOGON_ID':'xxxx'}")
|
||||
@NotEmpty(message = "收款方信息不能为空")
|
||||
private Map<String, String> payeeInfo;
|
||||
@Schema(description = "收款人姓名", example = "test1")
|
||||
@NotBlank(message = "收款人姓名不能为空", groups = {Alipay.class})
|
||||
private String userName;
|
||||
|
||||
// ========== 支付宝转账相关字段 ==========
|
||||
@Schema(description = "支付宝登录号,支持邮箱和手机号格式", example = "test1@@sandbox.com")
|
||||
@NotBlank(message = "支付宝登录号不能为空", groups = {Alipay.class})
|
||||
private String alipayLogonId;
|
||||
|
||||
// ========== 微信转账相关字段 ==========
|
||||
@Schema(description = "微信 openId", example = "oLefc4g5Gxx")
|
||||
@NotBlank(message = "微信 openId 不能为空", groups = {WxPay.class})
|
||||
private String openid;
|
||||
|
||||
|
||||
// ========== 转账到银行卡和钱包相关字段 待补充 ==========
|
||||
|
||||
public void validate(Validator validator) {
|
||||
PayTransferTypeEnum transferType = PayTransferTypeEnum.typeOf(type);
|
||||
switch (transferType) {
|
||||
case ALIPAY_BALANCE: {
|
||||
ValidationUtils.validate(validator, this, Alipay.class);
|
||||
break;
|
||||
}
|
||||
case WX_BALANCE: {
|
||||
ValidationUtils.validate(validator, this, WxPay.class);
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
throw new UnsupportedOperationException("待实现");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,47 @@
|
||||
package cn.iocoder.yudao.module.pay.controller.admin.demo.vo.transfer;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.Data;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
/**
|
||||
* 示例业务转账订单 Base VO,提供给添加、修改、详细的子 VO 使用
|
||||
* 如果子 VO 存在差异的字段,请不要添加到这里,影响 Swagger 文档生成
|
||||
*/
|
||||
@Data
|
||||
public class PayDemoTransferRespVO {
|
||||
|
||||
@Schema(description = "订单编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024")
|
||||
private Long id;
|
||||
|
||||
@Schema(description = "应用编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "1")
|
||||
private Long appId;
|
||||
|
||||
@Schema(description = "转账金额,单位:分", requiredMode = Schema.RequiredMode.REQUIRED, example = "22338")
|
||||
private Integer price;
|
||||
|
||||
@Schema(description = "转账类型", requiredMode = Schema.RequiredMode.REQUIRED, example = "1")
|
||||
private Integer type;
|
||||
|
||||
@Schema(description = "收款人姓名", example = "test")
|
||||
private String userName;
|
||||
|
||||
@Schema(description = "支付宝登录号", example = "32167")
|
||||
private String alipayLogonId;
|
||||
|
||||
@Schema(description = "微信 openId", example = "31139")
|
||||
private String openid;
|
||||
|
||||
@Schema(description = "转账状态", requiredMode = Schema.RequiredMode.REQUIRED, example = "2")
|
||||
private Integer transferStatus;
|
||||
|
||||
@Schema(description = "转账订单编号", example = "23695")
|
||||
private Long payTransferId;
|
||||
|
||||
@Schema(description = "转账支付成功渠道")
|
||||
private String payChannelCode;
|
||||
|
||||
@Schema(description = "转账支付时间")
|
||||
private LocalDateTime transferTime;
|
||||
}
|
||||
@@ -21,14 +21,14 @@ import cn.iocoder.yudao.module.pay.service.refund.PayRefundService;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.Parameter;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import jakarta.annotation.Resource;
|
||||
import jakarta.annotation.security.PermitAll;
|
||||
import jakarta.validation.Valid;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import jakarta.annotation.Resource;
|
||||
import jakarta.annotation.security.PermitAll;
|
||||
import jakarta.validation.Valid;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@@ -79,8 +79,8 @@ public class PayNotifyController {
|
||||
@Operation(summary = "支付渠道的统一【退款】回调")
|
||||
@PermitAll
|
||||
public String notifyRefund(@PathVariable("channelId") Long channelId,
|
||||
@RequestParam(required = false) Map<String, String> params,
|
||||
@RequestBody(required = false) String body) {
|
||||
@RequestParam(required = false) Map<String, String> params,
|
||||
@RequestBody(required = false) String body) {
|
||||
log.info("[notifyRefund][channelId({}) 回调数据({}/{})]", channelId, params, body);
|
||||
// 1. 校验支付渠道是否存在
|
||||
PayClient payClient = channelService.getPayClient(channelId);
|
||||
|
||||
@@ -1,7 +1,10 @@
|
||||
package cn.iocoder.yudao.module.pay.controller.admin.notify.vo;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.*;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.ToString;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
@Schema(description = "管理后台 - 回调通知 Response VO")
|
||||
|
||||
@@ -109,7 +109,7 @@ public class PayOrderController {
|
||||
@PreAuthorize("@ss.hasPermission('pay:order:export')")
|
||||
@ApiAccessLog(operateType = EXPORT)
|
||||
public void exportOrderExcel(@Valid PayOrderExportReqVO exportReqVO,
|
||||
HttpServletResponse response) throws IOException {
|
||||
HttpServletResponse response) throws IOException {
|
||||
List<PayOrderDO> list = orderService.getOrderList(exportReqVO);
|
||||
if (CollectionUtil.isEmpty(list)) {
|
||||
ExcelUtils.write(response, "支付订单.xls", "数据",
|
||||
|
||||
@@ -1,9 +1,10 @@
|
||||
package cn.iocoder.yudao.module.pay.controller.admin.order.vo;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import jakarta.validation.constraints.NotNull;
|
||||
import lombok.Data;
|
||||
import org.springframework.format.annotation.DateTimeFormat;
|
||||
|
||||
import jakarta.validation.constraints.NotNull;
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND;
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
package cn.iocoder.yudao.module.pay.controller.admin.order.vo;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import jakarta.validation.constraints.NotEmpty;
|
||||
import jakarta.validation.constraints.NotNull;
|
||||
import lombok.Data;
|
||||
import org.hibernate.validator.constraints.URL;
|
||||
|
||||
import jakarta.validation.constraints.NotEmpty;
|
||||
import jakarta.validation.constraints.NotNull;
|
||||
import java.util.Map;
|
||||
|
||||
@Schema(description = "管理后台 - 支付订单提交 Request VO")
|
||||
|
||||
@@ -1,19 +1,18 @@
|
||||
package cn.iocoder.yudao.module.pay.controller.admin.transfer;
|
||||
|
||||
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
|
||||
import cn.iocoder.yudao.module.pay.controller.admin.transfer.vo.PayTransferSubmitReqVO;
|
||||
import cn.iocoder.yudao.module.pay.controller.admin.transfer.vo.PayTransferSubmitRespVO;
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||
import cn.iocoder.yudao.module.pay.controller.admin.transfer.vo.*;
|
||||
import cn.iocoder.yudao.module.pay.convert.transfer.PayTransferConvert;
|
||||
import cn.iocoder.yudao.module.pay.dal.dataobject.transfer.PayTransferDO;
|
||||
import cn.iocoder.yudao.module.pay.service.transfer.PayTransferService;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import jakarta.annotation.Resource;
|
||||
import jakarta.validation.Valid;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
|
||||
import static cn.iocoder.yudao.framework.common.util.servlet.ServletUtils.getClientIP;
|
||||
@@ -27,12 +26,26 @@ public class PayTransferController {
|
||||
@Resource
|
||||
private PayTransferService payTransferService;
|
||||
|
||||
@PostMapping("/submit")
|
||||
@Operation(summary = "提交转账订单")
|
||||
// TODO @jason:权限的设置, 管理后台页面加的时候加一下
|
||||
public CommonResult<PayTransferSubmitRespVO> submitPayTransfer(@Valid @RequestBody PayTransferSubmitReqVO reqVO) {
|
||||
PayTransferSubmitRespVO respVO = payTransferService.submitTransfer(reqVO, getClientIP());
|
||||
return success(respVO);
|
||||
@PostMapping("/create")
|
||||
@Operation(summary = "创建转账单,发起转账")
|
||||
@PreAuthorize("@ss.hasPermission('pay:transfer:create')")
|
||||
public CommonResult<PayTransferCreateRespVO> createPayTransfer(@Valid @RequestBody PayTransferCreateReqVO reqVO) {
|
||||
PayTransferDO payTransfer = payTransferService.createTransfer(reqVO, getClientIP());
|
||||
return success(new PayTransferCreateRespVO().setId(payTransfer.getId()).setStatus(payTransfer.getStatus()));
|
||||
}
|
||||
|
||||
@GetMapping("/get")
|
||||
@Operation(summary = "获得转账订单")
|
||||
@PreAuthorize("@ss.hasPermission('pay:transfer:query')")
|
||||
public CommonResult<PayTransferRespVO> getTransfer(@RequestParam("id") Long id) {
|
||||
return success(PayTransferConvert.INSTANCE.convert(payTransferService.getTransfer(id)));
|
||||
}
|
||||
|
||||
@GetMapping("/page")
|
||||
@Operation(summary = "获得转账订单分页")
|
||||
@PreAuthorize("@ss.hasPermission('pay:transfer:query')")
|
||||
public CommonResult<PageResult<PayTransferPageItemRespVO>> getTransferPage(@Valid PayTransferPageReqVO pageVO) {
|
||||
PageResult<PayTransferDO> pageResult = payTransferService.getTransferPage(pageVO);
|
||||
return success(PayTransferConvert.INSTANCE.convertPage(pageResult));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,95 @@
|
||||
package cn.iocoder.yudao.module.pay.controller.admin.transfer.vo;
|
||||
|
||||
import cn.iocoder.yudao.framework.common.util.validation.ValidationUtils;
|
||||
import cn.iocoder.yudao.framework.common.validation.InEnum;
|
||||
import cn.iocoder.yudao.framework.pay.core.enums.channel.PayChannelEnum;
|
||||
import cn.iocoder.yudao.module.pay.enums.transfer.PayTransferTypeEnum;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import jakarta.validation.Validator;
|
||||
import jakarta.validation.constraints.*;
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import static cn.iocoder.yudao.framework.common.exception.enums.GlobalErrorCodeConstants.NOT_IMPLEMENTED;
|
||||
import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
|
||||
import static cn.iocoder.yudao.module.pay.enums.transfer.PayTransferTypeEnum.*;
|
||||
|
||||
@Schema(description = "管理后台 - 发起转账 Request VO")
|
||||
@Data
|
||||
public class PayTransferCreateReqVO {
|
||||
|
||||
@Schema(description = "应用编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "1")
|
||||
@NotNull(message = "应用编号不能为空")
|
||||
private Long appId;
|
||||
|
||||
@Schema(description = "商户转账单编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "1")
|
||||
@NotNull(message = "商户转账单编号不能为空")
|
||||
private String merchantTransferId;
|
||||
|
||||
@Schema(description = "转账类型", requiredMode = Schema.RequiredMode.REQUIRED, example = "1")
|
||||
@NotNull(message = "转账类型不能为空")
|
||||
@InEnum(PayTransferTypeEnum.class)
|
||||
private Integer type;
|
||||
|
||||
@Schema(description = "转账渠道", requiredMode = Schema.RequiredMode.REQUIRED, example = "alipay_pc")
|
||||
@NotEmpty(message = "转账渠道不能为空")
|
||||
private String channelCode;
|
||||
|
||||
@Min(value = 1, message = "转账金额必须大于零")
|
||||
@NotNull(message = "转账金额不能为空")
|
||||
private Integer price;
|
||||
|
||||
@Schema(description = "转账标题", requiredMode = Schema.RequiredMode.REQUIRED, example = "示例转账")
|
||||
@NotEmpty(message = "转账标题不能为空")
|
||||
private String subject;
|
||||
|
||||
@Schema(description = "收款人姓名", example = "test1")
|
||||
@NotBlank(message = "收款人姓名不能为空", groups = {Alipay.class})
|
||||
private String userName;
|
||||
|
||||
@Schema(description = "支付宝登录号", example = "test1@sandbox.com")
|
||||
@NotBlank(message = "支付宝登录号不能为空", groups = {Alipay.class})
|
||||
private String alipayLogonId;
|
||||
|
||||
@Schema(description = "微信 openId", example = "oLefc4g5Gxx")
|
||||
@NotBlank(message = "微信 openId 不能为空", groups = {WxPay.class})
|
||||
private String openid;
|
||||
|
||||
@Schema(description = "转账渠道的额外参数")
|
||||
private Map<String, String> channelExtras;
|
||||
|
||||
public void validate(Validator validator) {
|
||||
PayTransferTypeEnum transferType = typeOf(type);
|
||||
switch (transferType) {
|
||||
case ALIPAY_BALANCE: {
|
||||
ValidationUtils.validate(validator, this, Alipay.class);
|
||||
break;
|
||||
}
|
||||
case WX_BALANCE: {
|
||||
ValidationUtils.validate(validator, this, WxPay.class);
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
throw new UnsupportedOperationException("待实现");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@AssertTrue(message = "转账类型和转账渠道不匹配")
|
||||
public boolean isValidChannelCode() {
|
||||
PayTransferTypeEnum transferType = typeOf(type);
|
||||
switch (transferType) {
|
||||
case ALIPAY_BALANCE: {
|
||||
return PayChannelEnum.isAlipay(channelCode);
|
||||
}
|
||||
case WX_BALANCE:
|
||||
case BANK_CARD:
|
||||
case WALLET_BALANCE: {
|
||||
throw exception(NOT_IMPLEMENTED);
|
||||
}
|
||||
}
|
||||
return Boolean.FALSE;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -3,9 +3,12 @@ package cn.iocoder.yudao.module.pay.controller.admin.transfer.vo;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.Data;
|
||||
|
||||
@Schema(description = "管理后台 - 转账单提交 Response VO")
|
||||
@Schema(description = "管理后台 - 发起转账 Response VO")
|
||||
@Data
|
||||
public class PayTransferSubmitRespVO {
|
||||
public class PayTransferCreateRespVO {
|
||||
|
||||
@Schema(description = "转账单编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "1")
|
||||
private Long id;
|
||||
|
||||
@Schema(description = "转账状态", requiredMode = Schema.RequiredMode.REQUIRED, example = "1") // 参见 PayTransferStatusEnum 枚举
|
||||
private Integer status;
|
||||
@@ -0,0 +1,62 @@
|
||||
package cn.iocoder.yudao.module.pay.controller.admin.transfer.vo;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.Data;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
/**
|
||||
* @author jason
|
||||
*/
|
||||
@Schema(description = "管理后台 - 转账单分页项 Response VO")
|
||||
@Data
|
||||
public class PayTransferPageItemRespVO {
|
||||
|
||||
@Schema(description = "编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "2931")
|
||||
private Long id;
|
||||
|
||||
@Schema(description = "转账单号", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||
private String no;
|
||||
|
||||
@Schema(description = "应用编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "12831")
|
||||
private Long appId;
|
||||
|
||||
@Schema(description = "转账渠道编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "24833")
|
||||
private Long channelId;
|
||||
|
||||
@Schema(description = "转账渠道编码", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||
private String channelCode;
|
||||
|
||||
@Schema(description = "商户转账单编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "17481")
|
||||
private String merchantTransferId;
|
||||
|
||||
@Schema(description = "类型", requiredMode = Schema.RequiredMode.REQUIRED, example = "2")
|
||||
private Integer type;
|
||||
|
||||
@Schema(description = "转账状态", requiredMode = Schema.RequiredMode.REQUIRED, example = "2")
|
||||
private Integer status;
|
||||
|
||||
@Schema(description = "转账成功时间")
|
||||
private LocalDateTime successTime;
|
||||
|
||||
@Schema(description = "转账金额", requiredMode = Schema.RequiredMode.REQUIRED, example = "964")
|
||||
private Integer price;
|
||||
|
||||
@Schema(description = "转账标题", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||
private String subject;
|
||||
|
||||
@Schema(description = "收款人姓名", example = "王五")
|
||||
private String userName;
|
||||
|
||||
@Schema(description = "支付宝登录号", example = "29245")
|
||||
private String alipayLogonId;
|
||||
|
||||
@Schema(description = "微信 openId", example = "26589")
|
||||
private String openid;
|
||||
|
||||
@Schema(description = "渠道转账单号")
|
||||
private String channelTransferNo;
|
||||
|
||||
@Schema(description = "创建时间", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||
private LocalDateTime createTime;
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
package cn.iocoder.yudao.module.pay.controller.admin.transfer.vo;
|
||||
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageParam;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.ToString;
|
||||
import org.springframework.format.annotation.DateTimeFormat;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND;
|
||||
|
||||
@Schema(description = "管理后台 - 转账单分页 Request VO")
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@ToString(callSuper = true)
|
||||
public class PayTransferPageReqVO extends PageParam {
|
||||
|
||||
@Schema(description = "转账单号")
|
||||
private String no;
|
||||
|
||||
@Schema(description = "应用编号", example = "12831")
|
||||
private Long appId;
|
||||
|
||||
@Schema(description = "渠道编码", example = "wx_app")
|
||||
private String channelCode;
|
||||
|
||||
@Schema(description = "商户转账单编号", example = "17481")
|
||||
private String merchantTransferId;
|
||||
|
||||
@Schema(description = "类型", example = "2")
|
||||
private Integer type;
|
||||
|
||||
@Schema(description = "转账状态", example = "2")
|
||||
private Integer status;
|
||||
|
||||
@Schema(description = "收款人姓名", example = "王五")
|
||||
private String userName;
|
||||
|
||||
@Schema(description = "渠道转账单号")
|
||||
private String channelTransferNo;
|
||||
|
||||
@Schema(description = "创建时间")
|
||||
@DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND)
|
||||
private LocalDateTime[] createTime;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,79 @@
|
||||
package cn.iocoder.yudao.module.pay.controller.admin.transfer.vo;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.Data;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.Map;
|
||||
|
||||
@Schema(description = "管理后台 - 转账单 Response VO")
|
||||
@Data
|
||||
public class PayTransferRespVO {
|
||||
|
||||
@Schema(description = "编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "2931")
|
||||
private Long id;
|
||||
|
||||
@Schema(description = "转账单号", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||
private String no;
|
||||
|
||||
@Schema(description = "应用编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "12831")
|
||||
private Long appId;
|
||||
|
||||
@Schema(description = "转账渠道编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "24833")
|
||||
private Long channelId;
|
||||
|
||||
@Schema(description = "转账渠道编码", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||
private String channelCode;
|
||||
|
||||
@Schema(description = "商户转账单编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "17481")
|
||||
private String merchantTransferId;
|
||||
|
||||
@Schema(description = "类型", requiredMode = Schema.RequiredMode.REQUIRED, example = "2")
|
||||
private Integer type;
|
||||
|
||||
@Schema(description = "转账状态", requiredMode = Schema.RequiredMode.REQUIRED, example = "2")
|
||||
private Integer status;
|
||||
|
||||
@Schema(description = "转账成功时间")
|
||||
private LocalDateTime successTime;
|
||||
|
||||
@Schema(description = "转账金额", requiredMode = Schema.RequiredMode.REQUIRED, example = "964")
|
||||
private Integer price;
|
||||
|
||||
@Schema(description = "转账标题", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||
private String subject;
|
||||
|
||||
@Schema(description = "收款人姓名", example = "王五")
|
||||
private String userName;
|
||||
|
||||
@Schema(description = "支付宝登录号", example = "29245")
|
||||
private String alipayLogonId;
|
||||
|
||||
@Schema(description = "微信 openId", example = "26589")
|
||||
private String openid;
|
||||
|
||||
@Schema(description = "异步通知商户地址", requiredMode = Schema.RequiredMode.REQUIRED, example = "https://www.iocoder.cn")
|
||||
private String notifyUrl;
|
||||
|
||||
@Schema(description = "用户 IP", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||
private String userIp;
|
||||
|
||||
@Schema(description = "渠道的额外参数")
|
||||
private Map<String, String> channelExtras;
|
||||
|
||||
@Schema(description = "渠道转账单号")
|
||||
private String channelTransferNo;
|
||||
|
||||
@Schema(description = "调用渠道的错误码")
|
||||
private String channelErrorCode;
|
||||
|
||||
@Schema(description = "调用渠道的错误提示")
|
||||
private String channelErrorMsg;
|
||||
|
||||
@Schema(description = "渠道的同步/异步通知的内容")
|
||||
private String channelNotifyData;
|
||||
|
||||
@Schema(description = "创建时间", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||
private LocalDateTime createTime;
|
||||
|
||||
}
|
||||
@@ -1,25 +0,0 @@
|
||||
package cn.iocoder.yudao.module.pay.controller.admin.transfer.vo;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.Data;
|
||||
|
||||
import jakarta.validation.constraints.NotEmpty;
|
||||
import jakarta.validation.constraints.NotNull;
|
||||
import java.util.Map;
|
||||
|
||||
@Schema(description = "管理后台 - 转账单提交 Request VO")
|
||||
@Data
|
||||
public class PayTransferSubmitReqVO {
|
||||
|
||||
@Schema(description = "转账单编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "1")
|
||||
@NotNull(message = "转账单编号不能为空")
|
||||
private Long id;
|
||||
|
||||
@Schema(description = "转账渠道", requiredMode = Schema.RequiredMode.REQUIRED, example = "alipay_transfer")
|
||||
@NotEmpty(message = "转账渠道不能为空")
|
||||
private String channelCode;
|
||||
|
||||
@Schema(description = "转账渠道的额外参数")
|
||||
private Map<String, String> channelExtras;
|
||||
|
||||
}
|
||||
@@ -1,11 +1,7 @@
|
||||
package cn.iocoder.yudao.module.pay.controller.admin.wallet;
|
||||
|
||||
import cn.hutool.core.collection.CollectionUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||
import cn.iocoder.yudao.module.member.api.user.MemberUserApi;
|
||||
import cn.iocoder.yudao.module.member.api.user.dto.MemberUserRespDTO;
|
||||
import cn.iocoder.yudao.module.pay.controller.admin.wallet.vo.wallet.PayWalletPageReqVO;
|
||||
import cn.iocoder.yudao.module.pay.controller.admin.wallet.vo.wallet.PayWalletRespVO;
|
||||
import cn.iocoder.yudao.module.pay.controller.admin.wallet.vo.wallet.PayWalletUserReqVO;
|
||||
@@ -14,6 +10,8 @@ import cn.iocoder.yudao.module.pay.dal.dataobject.wallet.PayWalletDO;
|
||||
import cn.iocoder.yudao.module.pay.service.wallet.PayWalletService;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import jakarta.annotation.Resource;
|
||||
import jakarta.validation.Valid;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
@@ -21,14 +19,8 @@ import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import jakarta.annotation.Resource;
|
||||
import jakarta.validation.Valid;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import static cn.iocoder.yudao.framework.common.enums.UserTypeEnum.MEMBER;
|
||||
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
|
||||
import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.*;
|
||||
|
||||
@Tag(name = "管理后台 - 用户钱包")
|
||||
@RestController
|
||||
@@ -39,38 +31,21 @@ public class PayWalletController {
|
||||
|
||||
@Resource
|
||||
private PayWalletService payWalletService;
|
||||
@Resource
|
||||
private MemberUserApi memberUserApi;
|
||||
|
||||
@GetMapping("/get")
|
||||
@PreAuthorize("@ss.hasPermission('pay:wallet:query')")
|
||||
@Operation(summary = "获得用户钱包明细")
|
||||
public CommonResult<PayWalletRespVO> getWallet(PayWalletUserReqVO reqVO) {
|
||||
PayWalletDO wallet = payWalletService.getOrCreateWallet(reqVO.getUserId(), MEMBER.getValue());
|
||||
// TODO jason:如果为空,返回给前端只要 null 就可以了
|
||||
MemberUserRespDTO memberUser = memberUserApi.getUser(reqVO.getUserId()).getCheckedData();
|
||||
String nickname = memberUser == null ? "" : memberUser.getNickname();
|
||||
String avatar = memberUser == null ? "" : memberUser.getAvatar();
|
||||
return success(PayWalletConvert.INSTANCE.convert02(nickname, avatar, wallet));
|
||||
return success(PayWalletConvert.INSTANCE.convert02(wallet));
|
||||
}
|
||||
|
||||
@GetMapping("/page")
|
||||
@Operation(summary = "获得会员钱包分页")
|
||||
@PreAuthorize("@ss.hasPermission('pay:wallet:query')")
|
||||
public CommonResult<PageResult<PayWalletRespVO>> getWalletPage(@Valid PayWalletPageReqVO pageVO) {
|
||||
if (StrUtil.isNotEmpty(pageVO.getNickname())) {
|
||||
List<MemberUserRespDTO> users = memberUserApi.getUserListByNickname(pageVO.getNickname()).getCheckedData();
|
||||
pageVO.setUserIds(convertSet(users, MemberUserRespDTO::getId));
|
||||
}
|
||||
// TODO @jason:管理员也可以先查询下。。
|
||||
// 暂时支持查询 userType 会员类型。管理员类型还不知道使用场景
|
||||
PageResult<PayWalletDO> pageResult = payWalletService.getWalletPage(MEMBER.getValue(),pageVO);
|
||||
if (CollectionUtil.isEmpty(pageResult.getList())) {
|
||||
return success(new PageResult<>(pageResult.getTotal()));
|
||||
}
|
||||
List<MemberUserRespDTO> users = memberUserApi.getUserList(convertList(pageResult.getList(), PayWalletDO::getUserId)).getCheckedData();
|
||||
Map<Long, MemberUserRespDTO> userMap = convertMap(users, MemberUserRespDTO::getId);
|
||||
return success(PayWalletConvert.INSTANCE.convertPage(pageResult, userMap));
|
||||
PageResult<PayWalletDO> pageResult = payWalletService.getWalletPage(pageVO);
|
||||
return success(PayWalletConvert.INSTANCE.convertPage(pageResult));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -7,13 +7,12 @@ import cn.iocoder.yudao.module.pay.service.wallet.PayWalletRechargeService;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.Parameter;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import jakarta.annotation.Resource;
|
||||
import jakarta.annotation.security.PermitAll;
|
||||
import jakarta.validation.Valid;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
|
||||
import static cn.iocoder.yudao.framework.common.util.servlet.ServletUtils.getClientIP;
|
||||
|
||||
@@ -6,19 +6,18 @@ import cn.iocoder.yudao.module.pay.controller.admin.wallet.vo.rechargepackage.Wa
|
||||
import cn.iocoder.yudao.module.pay.controller.admin.wallet.vo.rechargepackage.WalletRechargePackagePageReqVO;
|
||||
import cn.iocoder.yudao.module.pay.controller.admin.wallet.vo.rechargepackage.WalletRechargePackageRespVO;
|
||||
import cn.iocoder.yudao.module.pay.controller.admin.wallet.vo.rechargepackage.WalletRechargePackageUpdateReqVO;
|
||||
import cn.iocoder.yudao.module.pay.convert.wallet.WalletRechargePackageConvert;
|
||||
import cn.iocoder.yudao.module.pay.convert.wallet.PayWalletRechargePackageConvert;
|
||||
import cn.iocoder.yudao.module.pay.dal.dataobject.wallet.PayWalletRechargePackageDO;
|
||||
import cn.iocoder.yudao.module.pay.service.wallet.PayWalletRechargePackageService;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.Parameter;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import jakarta.annotation.Resource;
|
||||
import jakarta.validation.Valid;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import jakarta.annotation.Resource;
|
||||
import jakarta.validation.Valid;
|
||||
|
||||
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
|
||||
|
||||
|
||||
@@ -61,7 +60,7 @@ public class PayWalletRechargePackageController {
|
||||
@PreAuthorize("@ss.hasPermission('pay:wallet-recharge-package:query')")
|
||||
public CommonResult<WalletRechargePackageRespVO> getWalletRechargePackage(@RequestParam("id") Long id) {
|
||||
PayWalletRechargePackageDO walletRechargePackage = walletRechargePackageService.getWalletRechargePackage(id);
|
||||
return success(WalletRechargePackageConvert.INSTANCE.convert(walletRechargePackage));
|
||||
return success(PayWalletRechargePackageConvert.INSTANCE.convert(walletRechargePackage));
|
||||
}
|
||||
|
||||
@GetMapping("/page")
|
||||
@@ -69,7 +68,7 @@ public class PayWalletRechargePackageController {
|
||||
@PreAuthorize("@ss.hasPermission('pay:wallet-recharge-package:query')")
|
||||
public CommonResult<PageResult<WalletRechargePackageRespVO>> getWalletRechargePackagePage(@Valid WalletRechargePackagePageReqVO pageVO) {
|
||||
PageResult<PayWalletRechargePackageDO> pageResult = walletRechargePackageService.getWalletRechargePackagePage(pageVO);
|
||||
return success(WalletRechargePackageConvert.INSTANCE.convertPage(pageResult));
|
||||
return success(PayWalletRechargePackageConvert.INSTANCE.convertPage(pageResult));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -9,6 +9,8 @@ import cn.iocoder.yudao.module.pay.dal.dataobject.wallet.PayWalletTransactionDO;
|
||||
import cn.iocoder.yudao.module.pay.service.wallet.PayWalletTransactionService;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import jakarta.annotation.Resource;
|
||||
import jakarta.validation.Valid;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
@@ -16,9 +18,6 @@ import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import jakarta.annotation.Resource;
|
||||
import jakarta.validation.Valid;
|
||||
|
||||
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
|
||||
|
||||
@Tag(name = "管理后台 - 钱包余额明细")
|
||||
|
||||
@@ -1,9 +1,8 @@
|
||||
package cn.iocoder.yudao.module.pay.controller.admin.wallet.vo.rechargepackage;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.Data;
|
||||
|
||||
import jakarta.validation.constraints.NotNull;
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* 充值套餐 Base VO,提供给添加、修改、详细的子 VO 使用
|
||||
|
||||
@@ -1,12 +1,11 @@
|
||||
package cn.iocoder.yudao.module.pay.controller.admin.wallet.vo.rechargepackage;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import jakarta.validation.constraints.NotNull;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.ToString;
|
||||
|
||||
import jakarta.validation.constraints.NotNull;
|
||||
|
||||
@Schema(description = "管理后台 - 充值套餐更新 Request VO")
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
|
||||
@@ -1,9 +1,8 @@
|
||||
package cn.iocoder.yudao.module.pay.controller.admin.wallet.vo.wallet;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.Data;
|
||||
|
||||
import jakarta.validation.constraints.NotNull;
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* 用户钱包 Base VO,提供给添加、修改、详细的子 VO 使用
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
package cn.iocoder.yudao.module.pay.controller.admin.wallet.vo.wallet;
|
||||
|
||||
import cn.iocoder.yudao.framework.common.enums.UserTypeEnum;
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageParam;
|
||||
import cn.iocoder.yudao.framework.common.validation.InEnum;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
@@ -8,7 +10,6 @@ import lombok.ToString;
|
||||
import org.springframework.format.annotation.DateTimeFormat;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.Collection;
|
||||
|
||||
import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND;
|
||||
|
||||
@@ -18,11 +19,12 @@ import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_
|
||||
@ToString(callSuper = true)
|
||||
public class PayWalletPageReqVO extends PageParam {
|
||||
|
||||
@Schema(description = "用户昵称", example = "李四")
|
||||
private String nickname;
|
||||
@Schema(description = "用户编号", example = "1024")
|
||||
private Long userId;
|
||||
|
||||
@Schema(description = "用户编号", example = "[1,2]")
|
||||
private Collection<Long> userIds;
|
||||
@Schema(description = "用户类型", example = "1")
|
||||
@InEnum(value = UserTypeEnum.class)
|
||||
private Integer userType;
|
||||
|
||||
@Schema(description = "创建时间")
|
||||
@DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND)
|
||||
|
||||
@@ -19,9 +19,4 @@ public class PayWalletRespVO extends PayWalletBaseVO {
|
||||
@Schema(description = "创建时间", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||
private LocalDateTime createTime;
|
||||
|
||||
@Schema(description = "用户昵称", requiredMode = Schema.RequiredMode.REQUIRED, example = "王**")
|
||||
private String nickname;
|
||||
@Schema(description = "用户头像", requiredMode = Schema.RequiredMode.REQUIRED, example = "https://www.iocoder.cn/xxx.jpg")
|
||||
private String avatar;
|
||||
|
||||
}
|
||||
|
||||
@@ -1,9 +1,8 @@
|
||||
package cn.iocoder.yudao.module.pay.controller.admin.wallet.vo.wallet;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.Data;
|
||||
|
||||
import jakarta.validation.constraints.NotNull;
|
||||
import lombok.Data;
|
||||
|
||||
@Schema(description = "管理后台 - 用户钱包明细 Request VO")
|
||||
@Data
|
||||
|
||||
@@ -6,13 +6,13 @@ import cn.iocoder.yudao.module.pay.service.channel.PayChannelService;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.Parameter;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import jakarta.annotation.Resource;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
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;
|
||||
|
||||
import jakarta.annotation.Resource;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
|
||||
@@ -13,12 +13,11 @@ import com.google.common.collect.Maps;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.Parameter;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import jakarta.annotation.Resource;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import jakarta.annotation.Resource;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
|
||||
|
||||
@@ -2,11 +2,7 @@ package cn.iocoder.yudao.module.pay.controller.app.order.vo;
|
||||
|
||||
import cn.iocoder.yudao.module.pay.controller.admin.order.vo.PayOrderSubmitRespVO;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.experimental.Accessors;
|
||||
|
||||
@Schema(description = "用户 APP - 支付订单提交 Response VO")
|
||||
@Data
|
||||
|
||||
@@ -9,14 +9,13 @@ import cn.iocoder.yudao.module.pay.dal.dataobject.wallet.PayWalletDO;
|
||||
import cn.iocoder.yudao.module.pay.service.wallet.PayWalletService;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import jakarta.annotation.Resource;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import jakarta.annotation.Resource;
|
||||
|
||||
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
|
||||
import static cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils.getLoginUserId;
|
||||
|
||||
|
||||
@@ -1,24 +1,30 @@
|
||||
package cn.iocoder.yudao.module.pay.controller.app.wallet;
|
||||
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
import cn.iocoder.yudao.framework.common.enums.UserTypeEnum;
|
||||
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageParam;
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||
import cn.iocoder.yudao.module.pay.controller.app.wallet.vo.recharge.AppPayWalletRechargeCreateReqVO;
|
||||
import cn.iocoder.yudao.module.pay.controller.app.wallet.vo.recharge.AppPayWalletRechargeCreateRespVO;
|
||||
import cn.iocoder.yudao.module.pay.controller.app.wallet.vo.recharge.AppPayWalletRechargeRespVO;
|
||||
import cn.iocoder.yudao.module.pay.convert.wallet.PayWalletRechargeConvert;
|
||||
import cn.iocoder.yudao.module.pay.dal.dataobject.order.PayOrderDO;
|
||||
import cn.iocoder.yudao.module.pay.dal.dataobject.wallet.PayWalletRechargeDO;
|
||||
import cn.iocoder.yudao.module.pay.service.order.PayOrderService;
|
||||
import cn.iocoder.yudao.module.pay.service.wallet.PayWalletRechargeService;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import jakarta.annotation.Resource;
|
||||
import jakarta.validation.Valid;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
|
||||
import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertList;
|
||||
import static cn.iocoder.yudao.framework.common.util.servlet.ServletUtils.getClientIP;
|
||||
import static cn.iocoder.yudao.framework.web.core.util.WebFrameworkUtils.getLoginUserId;
|
||||
import static cn.iocoder.yudao.framework.web.core.util.WebFrameworkUtils.getLoginUserType;
|
||||
@@ -32,14 +38,30 @@ public class AppPayWalletRechargeController {
|
||||
|
||||
@Resource
|
||||
private PayWalletRechargeService walletRechargeService;
|
||||
@Resource
|
||||
private PayOrderService payOrderService;
|
||||
|
||||
@PostMapping("/create")
|
||||
@Operation(summary = "创建钱包充值记录(发起充值)")
|
||||
public CommonResult<AppPayWalletRechargeCreateRespVO> createWalletRecharge(
|
||||
@Valid @RequestBody AppPayWalletRechargeCreateReqVO reqVO) {
|
||||
@Valid @RequestBody AppPayWalletRechargeCreateReqVO reqVO) {
|
||||
PayWalletRechargeDO walletRecharge = walletRechargeService.createWalletRecharge(
|
||||
getLoginUserId(), getLoginUserType(), getClientIP(), reqVO);
|
||||
return success(PayWalletRechargeConvert.INSTANCE.convert(walletRecharge));
|
||||
}
|
||||
|
||||
@GetMapping("/page")
|
||||
@Operation(summary = "获得钱包充值记录分页")
|
||||
public CommonResult<PageResult<AppPayWalletRechargeRespVO>> getWalletRechargePage(@Valid PageParam pageReqVO) {
|
||||
PageResult<PayWalletRechargeDO> pageResult = walletRechargeService.getWalletRechargePackagePage(
|
||||
getLoginUserId(), UserTypeEnum.MEMBER.getValue(), pageReqVO, true);
|
||||
if (CollUtil.isEmpty(pageResult.getList())) {
|
||||
return success(PageResult.empty(pageResult.getTotal()));
|
||||
}
|
||||
// 拼接数据
|
||||
List<PayOrderDO> payOrderList = payOrderService.getOrderList(
|
||||
convertList(pageResult.getList(), PayWalletRechargeDO::getPayOrderId));
|
||||
return success(PayWalletRechargeConvert.INSTANCE.convertPage(pageResult, payOrderList));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,16 +1,21 @@
|
||||
package cn.iocoder.yudao.module.pay.controller.app.wallet;
|
||||
|
||||
import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum;
|
||||
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
|
||||
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
|
||||
import cn.iocoder.yudao.module.pay.controller.app.wallet.vo.recharge.AppPayWalletPackageRespVO;
|
||||
import cn.iocoder.yudao.module.pay.dal.dataobject.wallet.PayWalletRechargePackageDO;
|
||||
import cn.iocoder.yudao.module.pay.service.wallet.PayWalletRechargePackageService;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import jakarta.annotation.Resource;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
|
||||
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
|
||||
@@ -22,14 +27,16 @@ import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
|
||||
@Slf4j
|
||||
public class AppPayWalletRechargePackageController {
|
||||
|
||||
@Resource
|
||||
private PayWalletRechargePackageService walletRechargePackageService;
|
||||
|
||||
@GetMapping("/list")
|
||||
@Operation(summary = "获得钱包充值套餐列表")
|
||||
public CommonResult<List<AppPayWalletPackageRespVO>> getWalletRechargePackageList() {
|
||||
// 只查询开启;需要按照 payPrice 排序;
|
||||
List<AppPayWalletPackageRespVO> list = new ArrayList<>();
|
||||
list.add(new AppPayWalletPackageRespVO().setId(1L).setName("土豆").setPayPrice(10).setBonusPrice(2));
|
||||
list.add(new AppPayWalletPackageRespVO().setId(2L).setName("番茄").setPayPrice(20).setBonusPrice(5));
|
||||
return success(list);
|
||||
List<PayWalletRechargePackageDO> list = walletRechargePackageService.getWalletRechargePackageList(
|
||||
CommonStatusEnum.ENABLE.getStatus());
|
||||
list.sort(Comparator.comparingInt(PayWalletRechargePackageDO::getPayPrice));
|
||||
return success(BeanUtils.toBean(list, AppPayWalletPackageRespVO.class));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -3,24 +3,29 @@ package cn.iocoder.yudao.module.pay.controller.app.wallet;
|
||||
import cn.iocoder.yudao.framework.common.enums.UserTypeEnum;
|
||||
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
|
||||
import cn.iocoder.yudao.module.pay.controller.app.wallet.vo.transaction.AppPayWalletTransactionPageReqVO;
|
||||
import cn.iocoder.yudao.module.pay.controller.app.wallet.vo.transaction.AppPayWalletTransactionRespVO;
|
||||
import cn.iocoder.yudao.module.pay.convert.wallet.PayWalletTransactionConvert;
|
||||
import cn.iocoder.yudao.module.pay.controller.app.wallet.vo.transaction.AppPayWalletTransactionSummaryRespVO;
|
||||
import cn.iocoder.yudao.module.pay.dal.dataobject.wallet.PayWalletTransactionDO;
|
||||
import cn.iocoder.yudao.module.pay.service.wallet.PayWalletTransactionService;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.Parameter;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import jakarta.annotation.Resource;
|
||||
import jakarta.validation.Valid;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.format.annotation.DateTimeFormat;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
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;
|
||||
|
||||
import jakarta.annotation.Resource;
|
||||
import jakarta.validation.Valid;
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
|
||||
import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND;
|
||||
import static cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils.getLoginUserId;
|
||||
|
||||
@Tag(name = "用户 APP - 钱包余额明细")
|
||||
@@ -37,16 +42,19 @@ public class AppPayWalletTransactionController {
|
||||
@Operation(summary = "获得钱包流水分页")
|
||||
public CommonResult<PageResult<AppPayWalletTransactionRespVO>> getWalletTransactionPage(
|
||||
@Valid AppPayWalletTransactionPageReqVO pageReqVO) {
|
||||
if (true) {
|
||||
PageResult<AppPayWalletTransactionRespVO> result = new PageResult<>(10L);
|
||||
result.getList().add(new AppPayWalletTransactionRespVO().setPrice(1L)
|
||||
.setTitle("测试").setCreateTime(LocalDateTime.now()));
|
||||
result.getList().add(new AppPayWalletTransactionRespVO().setPrice(-1L)
|
||||
.setTitle("测试2").setCreateTime(LocalDateTime.now()));
|
||||
return success(result);
|
||||
}
|
||||
PageResult<PayWalletTransactionDO> result = payWalletTransactionService.getWalletTransactionPage(getLoginUserId(),
|
||||
UserTypeEnum.MEMBER.getValue(), pageReqVO);
|
||||
return success(PayWalletTransactionConvert.INSTANCE.convertPage(result));
|
||||
PageResult<PayWalletTransactionDO> pageResult = payWalletTransactionService.getWalletTransactionPage(
|
||||
getLoginUserId(), UserTypeEnum.MEMBER.getValue(), pageReqVO);
|
||||
return success(BeanUtils.toBean(pageResult, AppPayWalletTransactionRespVO.class));
|
||||
}
|
||||
|
||||
@GetMapping("/get-summary")
|
||||
@Operation(summary = "获得钱包流水统计")
|
||||
@Parameter(name = "times", description = "时间段", required = true)
|
||||
public CommonResult<AppPayWalletTransactionSummaryRespVO> getWalletTransactionSummary(
|
||||
@RequestParam("createTime") @DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND) LocalDateTime[] createTime) {
|
||||
AppPayWalletTransactionSummaryRespVO summary = payWalletTransactionService.getWalletTransactionSummary(
|
||||
getLoginUserId(), UserTypeEnum.MEMBER.getValue(), createTime);
|
||||
return success(summary);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
package cn.iocoder.yudao.module.pay.controller.app.wallet.vo.recharge;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.Data;
|
||||
|
||||
import jakarta.validation.constraints.AssertTrue;
|
||||
import jakarta.validation.constraints.Min;
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
@Schema(description = "用户 APP - 创建钱包充值 Request VO")
|
||||
@@ -19,7 +19,8 @@ public class AppPayWalletRechargeCreateReqVO {
|
||||
private Long packageId;
|
||||
|
||||
@AssertTrue(message = "充值金额和充钱套餐不能同时为空")
|
||||
public boolean validatePayPriceAndPackageId() {
|
||||
public boolean isValidPayPriceAndPackageId() {
|
||||
return Objects.nonNull(payPrice) || Objects.nonNull(packageId);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,42 @@
|
||||
package cn.iocoder.yudao.module.pay.controller.app.wallet.vo.recharge;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.Data;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
@Schema(description = "用户 APP - 钱包充值记录 Resp VO")
|
||||
@Data
|
||||
public class AppPayWalletRechargeRespVO {
|
||||
|
||||
@Schema(description = "编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "1")
|
||||
private Long id;
|
||||
|
||||
@Schema(description = "用户实际到账余额", requiredMode = Schema.RequiredMode.REQUIRED, example = "100")
|
||||
private Integer totalPrice;
|
||||
|
||||
@Schema(description = "实际支付金额", requiredMode = Schema.RequiredMode.REQUIRED, example = "20")
|
||||
private Integer payPrice;
|
||||
|
||||
@Schema(description = "钱包赠送金额", requiredMode = Schema.RequiredMode.REQUIRED, example = "80")
|
||||
private Integer bonusPrice;
|
||||
|
||||
@Schema(description = "支付成功的支付渠道", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||
private String payChannelCode;
|
||||
|
||||
@Schema(description = "支付渠道名", example = "微信小程序支付")
|
||||
private String payChannelName;
|
||||
|
||||
@Schema(description = "支付订单编号", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||
private Long payOrderId;
|
||||
|
||||
@Schema(description = "支付成功的外部订单号", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||
private String payOrderChannelOrderNo; // 从 PayOrderDO 的 channelOrderNo 字段
|
||||
|
||||
@Schema(description = "订单支付时间", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||
private LocalDateTime payTime;
|
||||
|
||||
@Schema(description = "退款状态", requiredMode = Schema.RequiredMode.REQUIRED, example = "0")
|
||||
private Integer refundStatus;
|
||||
|
||||
}
|
||||
@@ -1,8 +1,12 @@
|
||||
package cn.iocoder.yudao.module.pay.controller.app.wallet.vo.transaction;
|
||||
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageParam;
|
||||
import cn.iocoder.yudao.framework.common.util.date.DateUtils;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.Data;
|
||||
import org.springframework.format.annotation.DateTimeFormat;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
@Schema(description = "用户 APP - 钱包流水分页 Request VO")
|
||||
@Data
|
||||
@@ -20,4 +24,8 @@ public class AppPayWalletTransactionPageReqVO extends PageParam {
|
||||
@Schema(description = "类型", example = "1")
|
||||
private Integer type;
|
||||
|
||||
@Schema(description = "创建时间")
|
||||
@DateTimeFormat(pattern = DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND)
|
||||
private LocalDateTime[] createTime;
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,16 @@
|
||||
package cn.iocoder.yudao.module.pay.controller.app.wallet.vo.transaction;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.Data;
|
||||
|
||||
@Schema(description = "用户 APP - 钱包流水统计 Request VO")
|
||||
@Data
|
||||
public class AppPayWalletTransactionSummaryRespVO {
|
||||
|
||||
@Schema(description = "累计支出,单位分", requiredMode = Schema.RequiredMode.REQUIRED, example = "1000")
|
||||
private Integer totalExpense;
|
||||
|
||||
@Schema(description = "累计收入,单位分", requiredMode = Schema.RequiredMode.REQUIRED, example = "2000")
|
||||
private Integer totalIncome;
|
||||
|
||||
}
|
||||
@@ -7,13 +7,13 @@ import lombok.Data;
|
||||
@Data
|
||||
public class AppPayWalletRespVO {
|
||||
|
||||
@Schema(description = "钱包余额,单位分", requiredMode = Schema.RequiredMode.REQUIRED, example = "100")
|
||||
@Schema(description = "钱包余额,单位分", requiredMode = Schema.RequiredMode.REQUIRED, example = "100")
|
||||
private Integer balance;
|
||||
|
||||
@Schema(description = "累计支出, 单位分", requiredMode = Schema.RequiredMode.REQUIRED, example = "1000")
|
||||
@Schema(description = "累计支出,单位分", requiredMode = Schema.RequiredMode.REQUIRED, example = "1000")
|
||||
private Integer totalExpense;
|
||||
|
||||
@Schema(description = "累计充值, 单位分", requiredMode = Schema.RequiredMode.REQUIRED, example = "2000")
|
||||
@Schema(description = "累计充值,单位分", requiredMode = Schema.RequiredMode.REQUIRED, example = "2000")
|
||||
private Integer totalRecharge;
|
||||
|
||||
}
|
||||
|
||||
@@ -14,7 +14,6 @@ import org.mapstruct.factory.Mappers;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
/**
|
||||
* 支付应用信息 Convert
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
package cn.iocoder.yudao.module.pay.convert.demo;
|
||||
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||
import cn.iocoder.yudao.module.pay.controller.admin.demo.vo.PayDemoOrderCreateReqVO;
|
||||
import cn.iocoder.yudao.module.pay.controller.admin.demo.vo.PayDemoOrderRespVO;
|
||||
import cn.iocoder.yudao.module.pay.controller.admin.demo.vo.order.PayDemoOrderCreateReqVO;
|
||||
import cn.iocoder.yudao.module.pay.controller.admin.demo.vo.order.PayDemoOrderRespVO;
|
||||
import cn.iocoder.yudao.module.pay.dal.dataobject.demo.PayDemoOrderDO;
|
||||
import org.mapstruct.Mapper;
|
||||
import org.mapstruct.factory.Mappers;
|
||||
|
||||
@@ -0,0 +1,21 @@
|
||||
package cn.iocoder.yudao.module.pay.convert.demo;
|
||||
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||
import cn.iocoder.yudao.module.pay.controller.admin.demo.vo.transfer.PayDemoTransferCreateReqVO;
|
||||
import cn.iocoder.yudao.module.pay.controller.admin.demo.vo.transfer.PayDemoTransferRespVO;
|
||||
import cn.iocoder.yudao.module.pay.dal.dataobject.demo.PayDemoTransferDO;
|
||||
import org.mapstruct.Mapper;
|
||||
import org.mapstruct.factory.Mappers;
|
||||
|
||||
/**
|
||||
* @author jason
|
||||
*/
|
||||
@Mapper
|
||||
public interface PayDemoTransferConvert {
|
||||
|
||||
PayDemoTransferConvert INSTANCE = Mappers.getMapper(PayDemoTransferConvert.class);
|
||||
|
||||
PayDemoTransferDO convert(PayDemoTransferCreateReqVO bean);
|
||||
|
||||
PageResult<PayDemoTransferRespVO> convertPage(PageResult<PayDemoTransferDO> pageResult);
|
||||
}
|
||||
@@ -1,10 +1,14 @@
|
||||
package cn.iocoder.yudao.module.pay.convert.transfer;
|
||||
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||
import cn.iocoder.yudao.framework.pay.core.client.dto.transfer.PayTransferUnifiedReqDTO;
|
||||
import cn.iocoder.yudao.module.pay.api.transfer.dto.PayTransferCreateReqDTO;
|
||||
import cn.iocoder.yudao.module.pay.controller.admin.demo.vo.transfer.PayDemoTransferCreateReqVO;
|
||||
import cn.iocoder.yudao.module.pay.controller.admin.transfer.vo.PayTransferCreateReqVO;
|
||||
import cn.iocoder.yudao.module.pay.controller.admin.transfer.vo.PayTransferPageItemRespVO;
|
||||
import cn.iocoder.yudao.module.pay.controller.admin.transfer.vo.PayTransferRespVO;
|
||||
import cn.iocoder.yudao.module.pay.dal.dataobject.transfer.PayTransferDO;
|
||||
import org.mapstruct.Mapper;
|
||||
import org.mapstruct.Mapping;
|
||||
import org.mapstruct.factory.Mappers;
|
||||
|
||||
@Mapper
|
||||
@@ -12,9 +16,15 @@ public interface PayTransferConvert {
|
||||
|
||||
PayTransferConvert INSTANCE = Mappers.getMapper(PayTransferConvert.class);
|
||||
|
||||
@Mapping(source = "title", target = "subject") // TODO @jason:是不是都改成 subject 完事呀?
|
||||
PayTransferDO convert(PayTransferCreateReqDTO dto);
|
||||
|
||||
PayTransferUnifiedReqDTO convert2(PayTransferDO dto);
|
||||
|
||||
PayTransferCreateReqDTO convert(PayTransferCreateReqVO vo);
|
||||
|
||||
PayTransferCreateReqDTO convert(PayDemoTransferCreateReqVO vo);
|
||||
|
||||
PayTransferRespVO convert(PayTransferDO bean);
|
||||
|
||||
PageResult<PayTransferPageItemRespVO> convertPage(PageResult<PayTransferDO> pageResult);
|
||||
}
|
||||
|
||||
@@ -1,16 +1,12 @@
|
||||
package cn.iocoder.yudao.module.pay.convert.wallet;
|
||||
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||
import cn.iocoder.yudao.framework.common.util.collection.MapUtils;
|
||||
import cn.iocoder.yudao.module.member.api.user.dto.MemberUserRespDTO;
|
||||
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;
|
||||
import org.mapstruct.Mapper;
|
||||
import org.mapstruct.factory.Mappers;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
@Mapper
|
||||
public interface PayWalletConvert {
|
||||
|
||||
@@ -18,19 +14,8 @@ public interface PayWalletConvert {
|
||||
|
||||
AppPayWalletRespVO convert(PayWalletDO bean);
|
||||
|
||||
PayWalletRespVO convert02(String nickname,String avatar, PayWalletDO bean);
|
||||
PayWalletRespVO convert02(PayWalletDO bean);
|
||||
|
||||
PageResult<PayWalletRespVO> convertPage(PageResult<PayWalletDO> page);
|
||||
|
||||
default PageResult<PayWalletRespVO> convertPage(PageResult<PayWalletDO> page, Map<Long, MemberUserRespDTO> userMap){
|
||||
PageResult<PayWalletRespVO> pageResult = convertPage(page);
|
||||
pageResult.getList().forEach( wallet -> MapUtils.findAndThen(userMap, wallet.getUserId(),
|
||||
user -> {
|
||||
// TODO @jason:可以链式调用哈;
|
||||
wallet.setNickname(user.getNickname());
|
||||
wallet.setAvatar(user.getAvatar());
|
||||
}));
|
||||
return pageResult;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,11 +1,22 @@
|
||||
package cn.iocoder.yudao.module.pay.convert.wallet;
|
||||
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||
import cn.iocoder.yudao.framework.common.util.collection.CollectionUtils;
|
||||
import cn.iocoder.yudao.framework.common.util.collection.MapUtils;
|
||||
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
|
||||
import cn.iocoder.yudao.framework.dict.core.DictFrameworkUtils;
|
||||
import cn.iocoder.yudao.module.pay.controller.app.wallet.vo.recharge.AppPayWalletRechargeCreateRespVO;
|
||||
import cn.iocoder.yudao.module.pay.controller.app.wallet.vo.recharge.AppPayWalletRechargeRespVO;
|
||||
import cn.iocoder.yudao.module.pay.dal.dataobject.order.PayOrderDO;
|
||||
import cn.iocoder.yudao.module.pay.dal.dataobject.wallet.PayWalletRechargeDO;
|
||||
import cn.iocoder.yudao.module.pay.enums.DictTypeConstants;
|
||||
import org.mapstruct.Mapper;
|
||||
import org.mapstruct.Mapping;
|
||||
import org.mapstruct.factory.Mappers;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@Mapper
|
||||
public interface PayWalletRechargeConvert {
|
||||
|
||||
@@ -16,4 +27,17 @@ public interface PayWalletRechargeConvert {
|
||||
|
||||
AppPayWalletRechargeCreateRespVO convert(PayWalletRechargeDO bean);
|
||||
|
||||
default PageResult<AppPayWalletRechargeRespVO> convertPage(PageResult<PayWalletRechargeDO> pageResult,
|
||||
List<PayOrderDO> payOrderList) {
|
||||
PageResult<AppPayWalletRechargeRespVO> voPageResult = BeanUtils.toBean(pageResult, AppPayWalletRechargeRespVO.class);
|
||||
Map<Long, PayOrderDO> payOrderMap = CollectionUtils.convertMap(payOrderList, PayOrderDO::getId);
|
||||
voPageResult.getList().forEach(recharge -> {
|
||||
recharge.setPayChannelName(DictFrameworkUtils.getDictDataLabel(
|
||||
DictTypeConstants.CHANNEL_CODE, recharge.getPayChannelCode()));
|
||||
MapUtils.findAndThen(payOrderMap, recharge.getPayOrderId(),
|
||||
order -> recharge.setPayOrderChannelOrderNo(order.getChannelOrderNo()));
|
||||
});
|
||||
return voPageResult;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -11,9 +11,9 @@ import org.mapstruct.factory.Mappers;
|
||||
import java.util.List;
|
||||
|
||||
@Mapper
|
||||
public interface WalletRechargePackageConvert {
|
||||
public interface PayWalletRechargePackageConvert {
|
||||
|
||||
WalletRechargePackageConvert INSTANCE = Mappers.getMapper(WalletRechargePackageConvert.class);
|
||||
PayWalletRechargePackageConvert INSTANCE = Mappers.getMapper(PayWalletRechargePackageConvert.class);
|
||||
|
||||
PayWalletRechargePackageDO convert(WalletRechargePackageCreateReqVO bean);
|
||||
|
||||
@@ -2,7 +2,6 @@ package cn.iocoder.yudao.module.pay.convert.wallet;
|
||||
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||
import cn.iocoder.yudao.module.pay.controller.admin.wallet.vo.transaction.PayWalletTransactionRespVO;
|
||||
import cn.iocoder.yudao.module.pay.controller.app.wallet.vo.transaction.AppPayWalletTransactionRespVO;
|
||||
import cn.iocoder.yudao.module.pay.dal.dataobject.wallet.PayWalletTransactionDO;
|
||||
import cn.iocoder.yudao.module.pay.service.wallet.bo.WalletTransactionCreateReqBO;
|
||||
import org.mapstruct.Mapper;
|
||||
@@ -13,8 +12,6 @@ public interface PayWalletTransactionConvert {
|
||||
|
||||
PayWalletTransactionConvert INSTANCE = Mappers.getMapper(PayWalletTransactionConvert.class);
|
||||
|
||||
PageResult<AppPayWalletTransactionRespVO> convertPage(PageResult<PayWalletTransactionDO> page);
|
||||
|
||||
PageResult<PayWalletTransactionRespVO> convertPage2(PageResult<PayWalletTransactionDO> page);
|
||||
|
||||
PayWalletTransactionDO convert(WalletTransactionCreateReqBO bean);
|
||||
|
||||
@@ -54,4 +54,9 @@ public class PayAppDO extends BaseDO {
|
||||
*/
|
||||
private String refundNotifyUrl;
|
||||
|
||||
/**
|
||||
* 转账结果的回调地址
|
||||
*/
|
||||
private String transferNotifyUrl;
|
||||
|
||||
}
|
||||
|
||||
@@ -1,16 +1,16 @@
|
||||
package cn.iocoder.yudao.module.pay.dal.dataobject.demo;
|
||||
|
||||
import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO;
|
||||
import cn.iocoder.yudao.framework.pay.core.enums.transfer.PayTransferTypeEnum;
|
||||
import cn.iocoder.yudao.module.pay.dal.dataobject.app.PayAppDO;
|
||||
import com.baomidou.mybatisplus.annotation.KeySequence;
|
||||
import com.baomidou.mybatisplus.annotation.TableField;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import com.baomidou.mybatisplus.extension.handlers.JacksonTypeHandler;
|
||||
import lombok.Data;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.Map;
|
||||
|
||||
// TODO 芋艿:需要详细 review
|
||||
/**
|
||||
* 示例转账订单
|
||||
*
|
||||
@@ -28,9 +28,18 @@ public class PayDemoTransferDO extends BaseDO {
|
||||
private Long id;
|
||||
|
||||
/**
|
||||
* 用户编号
|
||||
* 应用编号
|
||||
*
|
||||
* 关联 {@link PayAppDO#getId()}
|
||||
*/
|
||||
private Long userId;
|
||||
private Long appId;
|
||||
|
||||
/**
|
||||
* 转账类型
|
||||
* <p>
|
||||
* 枚举 {@link PayTransferTypeEnum}
|
||||
*/
|
||||
private Integer type;
|
||||
|
||||
/**
|
||||
* 转账金额,单位:分
|
||||
@@ -38,16 +47,19 @@ public class PayDemoTransferDO extends BaseDO {
|
||||
private Integer price;
|
||||
|
||||
/**
|
||||
* 转账类型
|
||||
* 收款人姓名
|
||||
*/
|
||||
private Integer type;
|
||||
private String userName;
|
||||
|
||||
// TODO @jason:要不字段还是弄成正确的平铺开?
|
||||
/**
|
||||
* 收款人信息,不同类型和渠道不同
|
||||
* 支付宝登录号
|
||||
*/
|
||||
@TableField(typeHandler = JacksonTypeHandler.class)
|
||||
private Map<String, String> payeeInfo;
|
||||
private String alipayLogonId;
|
||||
|
||||
/**
|
||||
* 微信 openId
|
||||
*/
|
||||
private String openid;
|
||||
|
||||
/**
|
||||
* 转账状态
|
||||
@@ -55,7 +67,7 @@ public class PayDemoTransferDO extends BaseDO {
|
||||
private Integer transferStatus;
|
||||
|
||||
/**
|
||||
* 转账订单编号
|
||||
* 转账单编号
|
||||
*/
|
||||
private Long payTransferId;
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package cn.iocoder.yudao.module.pay.dal.dataobject.notify;
|
||||
|
||||
import cn.iocoder.yudao.module.pay.enums.notify.PayNotifyStatusEnum;
|
||||
import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO;
|
||||
import cn.iocoder.yudao.module.pay.enums.notify.PayNotifyStatusEnum;
|
||||
import com.baomidou.mybatisplus.annotation.KeySequence;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import lombok.*;
|
||||
|
||||
@@ -66,6 +66,10 @@ public class PayNotifyTaskDO extends TenantBaseDO {
|
||||
* 商户订单编号
|
||||
*/
|
||||
private String merchantOrderId;
|
||||
/**
|
||||
* 商户转账单编号
|
||||
*/
|
||||
private String merchantTransferId;
|
||||
/**
|
||||
* 通知状态
|
||||
*
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
package cn.iocoder.yudao.module.pay.dal.dataobject.order;
|
||||
|
||||
import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO;
|
||||
import cn.iocoder.yudao.framework.pay.core.client.dto.order.PayOrderRespDTO;
|
||||
import cn.iocoder.yudao.module.pay.dal.dataobject.channel.PayChannelDO;
|
||||
import cn.iocoder.yudao.module.pay.enums.order.PayOrderStatusEnum;
|
||||
import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO;
|
||||
import com.baomidou.mybatisplus.annotation.KeySequence;
|
||||
import com.baomidou.mybatisplus.annotation.TableField;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
|
||||
@@ -16,6 +16,7 @@ import lombok.Data;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.Map;
|
||||
|
||||
// TODO 芋艿:需要详细 review
|
||||
/**
|
||||
* 转账单 DO
|
||||
*
|
||||
@@ -31,24 +32,44 @@ public class PayTransferDO extends BaseDO {
|
||||
*/
|
||||
@TableId
|
||||
private Long id;
|
||||
|
||||
/**
|
||||
* 转账单号
|
||||
*
|
||||
*/
|
||||
private String no;
|
||||
|
||||
/**
|
||||
* 应用编号
|
||||
*
|
||||
* 关联 {@link PayAppDO#getId()}
|
||||
*/
|
||||
private Long appId;
|
||||
|
||||
/**
|
||||
* 转账渠道编号
|
||||
*
|
||||
* 关联 {@link PayChannelDO#getId()}
|
||||
*/
|
||||
private Long channelId;
|
||||
|
||||
/**
|
||||
* 转账渠道编码
|
||||
*
|
||||
* 枚举 {@link PayChannelEnum}
|
||||
*/
|
||||
private String channelCode;
|
||||
|
||||
// ========== 商户相关字段 ==========
|
||||
/**
|
||||
* 商户转账单编号
|
||||
*
|
||||
* 例如说,内部系统 A 的订单号,需要保证每个 PayAppDO 唯一
|
||||
*/
|
||||
private String merchantTransferId;
|
||||
|
||||
// ========== 转账相关字段 ==========
|
||||
|
||||
/**
|
||||
* 类型
|
||||
*
|
||||
@@ -56,51 +77,82 @@ public class PayTransferDO extends BaseDO {
|
||||
*/
|
||||
private Integer type;
|
||||
|
||||
// ========== 商户相关字段 ==========
|
||||
|
||||
/**
|
||||
* 商户订单编号
|
||||
*
|
||||
* 例如说,内部系统 A 的订单号,需要保证每个 PayAppDO 唯一
|
||||
*/
|
||||
private String merchantOrderId;
|
||||
|
||||
/**
|
||||
* 转账标题
|
||||
*/
|
||||
private String subject;
|
||||
|
||||
// ========== 转账相关字段 ==========
|
||||
/**
|
||||
* 转账金额,单位:分
|
||||
*/
|
||||
private Integer price;
|
||||
|
||||
/**
|
||||
* 收款人姓名
|
||||
*/
|
||||
private String userName;
|
||||
|
||||
/**
|
||||
* 转账状态
|
||||
*
|
||||
* 枚举 {@link PayTransferStatusRespEnum}
|
||||
*/
|
||||
private Integer status;
|
||||
|
||||
/**
|
||||
* 订单转账成功时间
|
||||
*/
|
||||
private LocalDateTime successTime;
|
||||
|
||||
// ========== 支付宝转账相关字段 ==========
|
||||
/**
|
||||
* 转账成功的转账拓展单编号
|
||||
*
|
||||
* 关联 {@link PayTransferExtensionDO#getId()}
|
||||
* 支付宝登录号
|
||||
*/
|
||||
private Long extensionId;
|
||||
private String alipayLogonId;
|
||||
|
||||
|
||||
// ========== 微信转账相关字段 ==========
|
||||
/**
|
||||
* 转账成功的转账拓展单号
|
||||
*
|
||||
* 关联 {@link PayTransferExtensionDO#getNo()}
|
||||
* 微信 openId
|
||||
*/
|
||||
private String no;
|
||||
private String openid;
|
||||
|
||||
// ========== 其它字段 ==========
|
||||
|
||||
/**
|
||||
* 收款人信息,不同类型和渠道不同
|
||||
* 异步通知地址
|
||||
*/
|
||||
private String notifyUrl;
|
||||
|
||||
/**
|
||||
* 用户 IP
|
||||
*/
|
||||
private String userIp;
|
||||
|
||||
/**
|
||||
* 渠道的额外参数
|
||||
*/
|
||||
@TableField(typeHandler = JacksonTypeHandler.class)
|
||||
private Map<String, String> payeeInfo;
|
||||
private Map<String, String> channelExtras;
|
||||
|
||||
/**
|
||||
* 渠道转账单号
|
||||
*/
|
||||
private String channelTransferNo;
|
||||
|
||||
/**
|
||||
* 调用渠道的错误码
|
||||
*/
|
||||
private String channelErrorCode;
|
||||
/**
|
||||
* 调用渠道的错误提示
|
||||
*/
|
||||
private String channelErrorMsg;
|
||||
|
||||
/**
|
||||
* 渠道的同步/异步通知的内容
|
||||
*
|
||||
*/
|
||||
private String channelNotifyData;
|
||||
|
||||
}
|
||||
@@ -1,68 +0,0 @@
|
||||
package cn.iocoder.yudao.module.pay.dal.dataobject.transfer;
|
||||
|
||||
import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO;
|
||||
import com.baomidou.mybatisplus.annotation.KeySequence;
|
||||
import com.baomidou.mybatisplus.annotation.TableField;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import com.baomidou.mybatisplus.extension.handlers.JacksonTypeHandler;
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
// TODO @jason:转账是不是类似 refund,不用拓展单呀?支付做拓展单的原因,是因为它存在不确定性,可以切换多种;转账和退款,都是明确方式的;
|
||||
// @芋艿 转账是不是也存在多种方式。 例如转账到银行卡。 可以使用微信,也可以使用支付宝。 支付宝账号余额不够,可以切换到微信;
|
||||
// TODO @jason:发起了,就不允许调整了,类似退款哈;
|
||||
/**
|
||||
* 转账拓展单 DO
|
||||
*
|
||||
* @author jason
|
||||
*/
|
||||
@TableName(value ="pay_transfer_extension",autoResultMap = true)
|
||||
@KeySequence("pay_transfer_extension_seq") // 用于 Oracle、PostgreSQL、Kingbase、DB2、H2 数据库的主键自增。如果是 MySQL 等数据库,可不写。
|
||||
@Data
|
||||
public class PayTransferExtensionDO extends BaseDO {
|
||||
|
||||
/**
|
||||
* 编号
|
||||
*/
|
||||
@TableId
|
||||
private Long id;
|
||||
|
||||
/**
|
||||
* 转账单号
|
||||
*/
|
||||
private String no;
|
||||
|
||||
/**
|
||||
* 转账单编号
|
||||
*/
|
||||
private Long transferId;
|
||||
|
||||
/**
|
||||
* 转账渠道编号
|
||||
*/
|
||||
private Long channelId;
|
||||
|
||||
/**
|
||||
* 转账渠道编码
|
||||
*/
|
||||
private String channelCode;
|
||||
|
||||
/**
|
||||
* 支付渠道的额外参数
|
||||
*/
|
||||
@TableField(typeHandler = JacksonTypeHandler.class)
|
||||
private Map<String, String> channelExtras;
|
||||
|
||||
/**
|
||||
* 转账状态
|
||||
*/
|
||||
private Integer status;
|
||||
|
||||
/**
|
||||
* 支付渠道异步通知的内容
|
||||
*/
|
||||
private String channelNotifyData;
|
||||
|
||||
}
|
||||
@@ -3,7 +3,6 @@ package cn.iocoder.yudao.module.pay.dal.mysql.app;
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||
import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
|
||||
import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
|
||||
import cn.iocoder.yudao.framework.mybatis.core.query.QueryWrapperX;
|
||||
import cn.iocoder.yudao.module.pay.controller.admin.app.vo.PayAppPageReqVO;
|
||||
import cn.iocoder.yudao.module.pay.dal.dataobject.app.PayAppDO;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
@@ -1,10 +1,17 @@
|
||||
package cn.iocoder.yudao.module.pay.dal.mysql.demo;
|
||||
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageParam;
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||
import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
|
||||
import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
|
||||
import cn.iocoder.yudao.module.pay.dal.dataobject.demo.PayDemoTransferDO;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
@Mapper
|
||||
public interface PayDemoTransferMapper extends BaseMapperX<PayDemoTransferDO> {
|
||||
|
||||
}
|
||||
default PageResult<PayDemoTransferDO> selectPage(PageParam pageParam){
|
||||
return selectPage(pageParam, new LambdaQueryWrapperX<PayDemoTransferDO>()
|
||||
.orderByDesc(PayDemoTransferDO::getId));
|
||||
}
|
||||
}
|
||||
@@ -1,7 +1,7 @@
|
||||
package cn.iocoder.yudao.module.pay.dal.mysql.notify;
|
||||
|
||||
import cn.iocoder.yudao.module.pay.dal.dataobject.notify.PayNotifyLogDO;
|
||||
import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
|
||||
import cn.iocoder.yudao.module.pay.dal.dataobject.notify.PayNotifyLogDO;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@@ -1,26 +0,0 @@
|
||||
package cn.iocoder.yudao.module.pay.dal.mysql.transfer;
|
||||
|
||||
import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
|
||||
import cn.iocoder.yudao.module.pay.dal.dataobject.transfer.PayTransferExtensionDO;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Mapper
|
||||
public interface PayTransferExtensionMapper extends BaseMapperX<PayTransferExtensionDO> {
|
||||
|
||||
default PayTransferExtensionDO selectByNo(String no){
|
||||
return selectOne(PayTransferExtensionDO::getNo, no);
|
||||
}
|
||||
|
||||
default int updateByIdAndStatus(Long id, List<Integer> whereStatuses, PayTransferExtensionDO updateObj) {
|
||||
return update(updateObj, new LambdaQueryWrapper<PayTransferExtensionDO>()
|
||||
.eq(PayTransferExtensionDO::getId, id).in(PayTransferExtensionDO::getStatus, whereStatuses));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -1,6 +1,9 @@
|
||||
package cn.iocoder.yudao.module.pay.dal.mysql.transfer;
|
||||
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||
import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
|
||||
import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
|
||||
import cn.iocoder.yudao.module.pay.controller.admin.transfer.vo.PayTransferPageReqVO;
|
||||
import cn.iocoder.yudao.module.pay.dal.dataobject.transfer.PayTransferDO;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
@@ -15,6 +18,32 @@ public interface PayTransferMapper extends BaseMapperX<PayTransferDO> {
|
||||
.eq(PayTransferDO::getId, id).in(PayTransferDO::getStatus, status));
|
||||
}
|
||||
|
||||
default PayTransferDO selectByAppIdAndMerchantTransferId(Long appId, String merchantTransferId){
|
||||
return selectOne(PayTransferDO::getAppId, appId,
|
||||
PayTransferDO::getMerchantTransferId, merchantTransferId);
|
||||
}
|
||||
|
||||
default PayTransferDO selectByNo(String no){
|
||||
return selectOne(PayTransferDO::getNo, no);
|
||||
}
|
||||
|
||||
default PageResult<PayTransferDO> selectPage(PayTransferPageReqVO reqVO) {
|
||||
return selectPage(reqVO, new LambdaQueryWrapperX<PayTransferDO>()
|
||||
.eqIfPresent(PayTransferDO::getNo, reqVO.getNo())
|
||||
.eqIfPresent(PayTransferDO::getAppId, reqVO.getAppId())
|
||||
.eqIfPresent(PayTransferDO::getChannelCode, reqVO.getChannelCode())
|
||||
.eqIfPresent(PayTransferDO::getMerchantTransferId, reqVO.getMerchantTransferId())
|
||||
.eqIfPresent(PayTransferDO::getType, reqVO.getType())
|
||||
.eqIfPresent(PayTransferDO::getStatus, reqVO.getStatus())
|
||||
.likeIfPresent(PayTransferDO::getUserName, reqVO.getUserName())
|
||||
.eqIfPresent(PayTransferDO::getChannelTransferNo, reqVO.getChannelTransferNo())
|
||||
.betweenIfPresent(PayTransferDO::getCreateTime, reqVO.getCreateTime())
|
||||
.orderByDesc(PayTransferDO::getId));
|
||||
}
|
||||
|
||||
default List<PayTransferDO> selectListByStatus(Integer status){
|
||||
return selectList(PayTransferDO::getStatus, status);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -17,10 +17,10 @@ public interface PayWalletMapper extends BaseMapperX<PayWalletDO> {
|
||||
PayWalletDO::getUserType, userType);
|
||||
}
|
||||
|
||||
default PageResult<PayWalletDO> selectPage(Integer userType, PayWalletPageReqVO reqVO) {
|
||||
default PageResult<PayWalletDO> selectPage(PayWalletPageReqVO reqVO) {
|
||||
return selectPage(reqVO, new LambdaQueryWrapperX<PayWalletDO>()
|
||||
.inIfPresent(PayWalletDO::getUserId, reqVO.getUserIds())
|
||||
.eqIfPresent(PayWalletDO::getUserType, userType)
|
||||
.eqIfPresent(PayWalletDO::getUserId, reqVO.getUserId())
|
||||
.eqIfPresent(PayWalletDO::getUserType, reqVO.getUserType())
|
||||
.betweenIfPresent(PayWalletDO::getCreateTime, reqVO.getCreateTime())
|
||||
.orderByDesc(PayWalletDO::getId));
|
||||
}
|
||||
@@ -31,7 +31,7 @@ public interface PayWalletMapper extends BaseMapperX<PayWalletDO> {
|
||||
* @param id 钱包 id
|
||||
* @param price 消费金额
|
||||
*/
|
||||
default int updateWhenConsumptionRefund(Long id, Integer price){
|
||||
default int updateWhenConsumptionRefund(Long id, Integer price) {
|
||||
LambdaUpdateWrapper<PayWalletDO> lambdaUpdateWrapper = new LambdaUpdateWrapper<PayWalletDO>()
|
||||
.setSql(" balance = balance + " + price
|
||||
+ ", total_expense = total_expense - " + price)
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
package cn.iocoder.yudao.module.pay.dal.mysql.wallet;
|
||||
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageParam;
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||
import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
|
||||
import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
|
||||
import cn.iocoder.yudao.module.pay.dal.dataobject.wallet.PayWalletRechargeDO;
|
||||
@@ -18,4 +20,11 @@ public interface PayWalletRechargeMapper extends BaseMapperX<PayWalletRechargeDO
|
||||
.eq(PayWalletRechargeDO::getId, id).eq(PayWalletRechargeDO::getRefundStatus, whereRefundStatus));
|
||||
}
|
||||
|
||||
default PageResult<PayWalletRechargeDO> selectPage(PageParam pageReqVO, Long walletId, Boolean payStatus) {
|
||||
return selectPage(pageReqVO, new LambdaQueryWrapperX<PayWalletRechargeDO>()
|
||||
.eq(PayWalletRechargeDO::getWalletId, walletId)
|
||||
.eq(PayWalletRechargeDO::getPayStatus, payStatus)
|
||||
.orderByDesc(PayWalletRechargeDO::getId));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -8,6 +8,8 @@ import cn.iocoder.yudao.module.pay.controller.admin.wallet.vo.rechargepackage.Wa
|
||||
import cn.iocoder.yudao.module.pay.dal.dataobject.wallet.PayWalletRechargePackageDO;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Mapper
|
||||
public interface PayWalletRechargePackageMapper extends BaseMapperX<PayWalletRechargePackageDO> {
|
||||
|
||||
@@ -19,9 +21,12 @@ public interface PayWalletRechargePackageMapper extends BaseMapperX<PayWalletRec
|
||||
.orderByDesc(PayWalletRechargePackageDO::getPayPrice));
|
||||
}
|
||||
|
||||
// TODO @jason:这里要有空格哈;String name) {
|
||||
default PayWalletRechargePackageDO selectByName(String name){
|
||||
default PayWalletRechargePackageDO selectByName(String name) {
|
||||
return selectOne(PayWalletRechargePackageDO::getName, name);
|
||||
}
|
||||
|
||||
default List<PayWalletRechargePackageDO> selectListByStatus(Integer status) {
|
||||
return selectList(PayWalletRechargePackageDO::getStatus, status);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,32 +1,54 @@
|
||||
package cn.iocoder.yudao.module.pay.dal.mysql.wallet;
|
||||
|
||||
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
import cn.hutool.core.map.MapUtil;
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageParam;
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||
import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
|
||||
import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
|
||||
import cn.iocoder.yudao.module.pay.controller.app.wallet.vo.transaction.AppPayWalletTransactionPageReqVO;
|
||||
import cn.iocoder.yudao.framework.mybatis.core.query.QueryWrapperX;
|
||||
import cn.iocoder.yudao.module.pay.dal.dataobject.wallet.PayWalletTransactionDO;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
|
||||
import static cn.iocoder.yudao.module.pay.controller.app.wallet.vo.transaction.AppPayWalletTransactionPageReqVO.TYPE_EXPENSE;
|
||||
import static cn.iocoder.yudao.module.pay.controller.app.wallet.vo.transaction.AppPayWalletTransactionPageReqVO.TYPE_INCOME;
|
||||
|
||||
@Mapper
|
||||
public interface PayWalletTransactionMapper extends BaseMapperX<PayWalletTransactionDO> {
|
||||
|
||||
default PageResult<PayWalletTransactionDO> selectPage(Long walletId, Integer type,
|
||||
PageParam pageParam) {
|
||||
PageParam pageParam, LocalDateTime[] createTime) {
|
||||
LambdaQueryWrapperX<PayWalletTransactionDO> query = new LambdaQueryWrapperX<PayWalletTransactionDO>()
|
||||
.eqIfPresent(PayWalletTransactionDO::getWalletId, walletId);
|
||||
if (Objects.equals(type, AppPayWalletTransactionPageReqVO.TYPE_INCOME)) {
|
||||
if (Objects.equals(type, TYPE_INCOME)) {
|
||||
query.gt(PayWalletTransactionDO::getPrice, 0);
|
||||
} else if (Objects.equals(type, AppPayWalletTransactionPageReqVO.TYPE_EXPENSE)) {
|
||||
} else if (Objects.equals(type, TYPE_EXPENSE)) {
|
||||
query.lt(PayWalletTransactionDO::getPrice, 0);
|
||||
}
|
||||
query.betweenIfPresent(PayWalletTransactionDO::getCreateTime, createTime);
|
||||
query.orderByDesc(PayWalletTransactionDO::getId);
|
||||
return selectPage(pageParam, query);
|
||||
}
|
||||
|
||||
default Integer selectPriceSum(Long walletId, Integer type, LocalDateTime[] createTime) {
|
||||
// SQL sum 查询
|
||||
List<Map<String, Object>> result = selectMaps(new QueryWrapperX<PayWalletTransactionDO>()
|
||||
.select("SUM(price) AS priceSum")
|
||||
.gt(Objects.equals(type, TYPE_INCOME), "price", 0) // 收入
|
||||
.lt(Objects.equals(type, TYPE_EXPENSE), "price", 0) // 支出
|
||||
.eq("wallet_id", walletId)
|
||||
.between("create_time", createTime[0], createTime[1]));
|
||||
// 获得 sum 结果
|
||||
Map<String, Object> first = CollUtil.getFirst(result);
|
||||
return MapUtil.getInt(first, "priceSum", 0);
|
||||
}
|
||||
|
||||
default PayWalletTransactionDO selectByNo(String no) {
|
||||
return selectOne(PayWalletTransactionDO::getNo, no);
|
||||
}
|
||||
|
||||
@@ -1,11 +1,12 @@
|
||||
package cn.iocoder.yudao.module.pay.dal.redis.no;
|
||||
|
||||
import cn.hutool.core.date.DatePattern;import cn.hutool.core.date.DateUtil;
|
||||
import cn.hutool.core.date.DatePattern;
|
||||
import cn.hutool.core.date.DateUtil;
|
||||
import cn.iocoder.yudao.module.pay.dal.redis.RedisKeyConstants;
|
||||
import jakarta.annotation.Resource;
|
||||
import org.springframework.data.redis.core.StringRedisTemplate;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
import jakarta.annotation.Resource;
|
||||
import java.time.Duration;
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
package cn.iocoder.yudao.module.pay.dal.redis.notify;
|
||||
|
||||
import jakarta.annotation.Resource;
|
||||
import org.redisson.api.RLock;
|
||||
import org.redisson.api.RedissonClient;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
import jakarta.annotation.Resource;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import static cn.iocoder.yudao.module.pay.dal.redis.RedisKeyConstants.PAY_NOTIFY_LOCK;
|
||||
|
||||
@@ -14,6 +14,7 @@ import cn.iocoder.yudao.framework.pay.core.client.impl.AbstractPayClient;
|
||||
import cn.iocoder.yudao.framework.pay.core.client.impl.NonePayClientConfig;
|
||||
import cn.iocoder.yudao.framework.pay.core.enums.channel.PayChannelEnum;
|
||||
import cn.iocoder.yudao.framework.pay.core.enums.refund.PayRefundStatusRespEnum;
|
||||
import cn.iocoder.yudao.framework.pay.core.enums.transfer.PayTransferTypeEnum;
|
||||
import cn.iocoder.yudao.module.pay.dal.dataobject.order.PayOrderExtensionDO;
|
||||
import cn.iocoder.yudao.module.pay.dal.dataobject.refund.PayRefundDO;
|
||||
import cn.iocoder.yudao.module.pay.dal.dataobject.wallet.PayWalletTransactionDO;
|
||||
@@ -181,4 +182,9 @@ public class WalletPayClient extends AbstractPayClient<NonePayClientConfig> {
|
||||
throw new UnsupportedOperationException("待实现");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected PayTransferRespDTO doGetTransfer(String outTradeNo, PayTransferTypeEnum type) {
|
||||
throw new UnsupportedOperationException("待实现");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,10 +1,7 @@
|
||||
package cn.iocoder.yudao.module.pay.framework.rpc.config;
|
||||
|
||||
import cn.iocoder.yudao.module.member.api.user.MemberUserApi;
|
||||
import org.springframework.cloud.openfeign.EnableFeignClients;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
@Configuration(proxyBeanMethods = false)
|
||||
@EnableFeignClients(clients = MemberUserApi.class)
|
||||
public class RpcConfiguration {
|
||||
}
|
||||
|
||||
@@ -0,0 +1,30 @@
|
||||
package cn.iocoder.yudao.module.pay.job.transfer;
|
||||
|
||||
import cn.iocoder.yudao.framework.tenant.core.job.TenantJob;
|
||||
import cn.iocoder.yudao.module.pay.service.transfer.PayTransferService;
|
||||
import com.xxl.job.core.handler.annotation.XxlJob;
|
||||
import jakarta.annotation.Resource;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
/**
|
||||
* 转账订单的同步 Job
|
||||
*
|
||||
* 由于转账订单的转账结果,有些渠道是异步通知进行同步的,考虑到异步通知可能会失败(小概率),所以需要定时进行同步。
|
||||
*
|
||||
* @author jason
|
||||
*/
|
||||
@Component
|
||||
@Slf4j
|
||||
public class PayTransferSyncJob {
|
||||
|
||||
@Resource
|
||||
private PayTransferService transferService;
|
||||
|
||||
@XxlJob("payTransferSyncJob")
|
||||
@TenantJob // 多租户
|
||||
public void execute(String param) {
|
||||
int count = transferService.syncTransfer();
|
||||
log.info("[execute][同步转账订单 ({}) 个]", count);
|
||||
}
|
||||
}
|
||||
@@ -7,8 +7,8 @@ import cn.iocoder.yudao.module.pay.controller.admin.app.vo.PayAppCreateReqVO;
|
||||
import cn.iocoder.yudao.module.pay.controller.admin.app.vo.PayAppPageReqVO;
|
||||
import cn.iocoder.yudao.module.pay.controller.admin.app.vo.PayAppUpdateReqVO;
|
||||
import cn.iocoder.yudao.module.pay.dal.dataobject.app.PayAppDO;
|
||||
|
||||
import jakarta.validation.Valid;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@@ -11,11 +11,11 @@ import cn.iocoder.yudao.module.pay.dal.mysql.app.PayAppMapper;
|
||||
import cn.iocoder.yudao.module.pay.enums.ErrorCodeConstants;
|
||||
import cn.iocoder.yudao.module.pay.service.order.PayOrderService;
|
||||
import cn.iocoder.yudao.module.pay.service.refund.PayRefundService;
|
||||
import jakarta.annotation.Resource;
|
||||
import org.springframework.context.annotation.Lazy;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
|
||||
import jakarta.annotation.Resource;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
|
||||
@@ -5,8 +5,8 @@ import cn.iocoder.yudao.framework.pay.core.client.PayClient;
|
||||
import cn.iocoder.yudao.module.pay.controller.admin.channel.vo.PayChannelCreateReqVO;
|
||||
import cn.iocoder.yudao.module.pay.controller.admin.channel.vo.PayChannelUpdateReqVO;
|
||||
import cn.iocoder.yudao.module.pay.dal.dataobject.channel.PayChannelDO;
|
||||
|
||||
import jakarta.validation.Valid;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
|
||||
@@ -16,14 +16,14 @@ import cn.iocoder.yudao.module.pay.dal.mysql.channel.PayChannelMapper;
|
||||
import cn.iocoder.yudao.module.pay.framework.pay.core.WalletPayClient;
|
||||
import com.google.common.cache.CacheLoader;
|
||||
import com.google.common.cache.LoadingCache;
|
||||
import jakarta.annotation.PostConstruct;
|
||||
import jakarta.annotation.Resource;
|
||||
import jakarta.validation.Validator;
|
||||
import lombok.Getter;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
|
||||
import jakarta.annotation.PostConstruct;
|
||||
import jakarta.annotation.Resource;
|
||||
import jakarta.validation.Validator;
|
||||
import java.time.Duration;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
@@ -2,9 +2,8 @@ package cn.iocoder.yudao.module.pay.service.demo;
|
||||
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageParam;
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||
import cn.iocoder.yudao.module.pay.controller.admin.demo.vo.PayDemoOrderCreateReqVO;
|
||||
import cn.iocoder.yudao.module.pay.controller.admin.demo.vo.order.PayDemoOrderCreateReqVO;
|
||||
import cn.iocoder.yudao.module.pay.dal.dataobject.demo.PayDemoOrderDO;
|
||||
|
||||
import jakarta.validation.Valid;
|
||||
|
||||
/**
|
||||
|
||||
@@ -9,16 +9,16 @@ import cn.iocoder.yudao.module.pay.api.order.dto.PayOrderRespDTO;
|
||||
import cn.iocoder.yudao.module.pay.api.refund.PayRefundApi;
|
||||
import cn.iocoder.yudao.module.pay.api.refund.dto.PayRefundCreateReqDTO;
|
||||
import cn.iocoder.yudao.module.pay.api.refund.dto.PayRefundRespDTO;
|
||||
import cn.iocoder.yudao.module.pay.controller.admin.demo.vo.PayDemoOrderCreateReqVO;
|
||||
import cn.iocoder.yudao.module.pay.controller.admin.demo.vo.order.PayDemoOrderCreateReqVO;
|
||||
import cn.iocoder.yudao.module.pay.dal.dataobject.demo.PayDemoOrderDO;
|
||||
import cn.iocoder.yudao.module.pay.dal.mysql.demo.PayDemoOrderMapper;
|
||||
import cn.iocoder.yudao.module.pay.enums.order.PayOrderStatusEnum;
|
||||
import cn.iocoder.yudao.module.pay.enums.refund.PayRefundStatusEnum;
|
||||
import jakarta.annotation.Resource;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
|
||||
import jakarta.annotation.Resource;
|
||||
import java.time.Duration;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.HashMap;
|
||||
@@ -232,7 +232,7 @@ public class PayDemoOrderServiceImpl implements PayDemoOrderService {
|
||||
throw exception(DEMO_ORDER_NOT_FOUND);
|
||||
}
|
||||
// 1.2 校验退款订单匹配
|
||||
if (Objects.equals(order.getPayOrderId(), payRefundId)) {
|
||||
if (Objects.equals(order.getPayRefundId(), payRefundId)) {
|
||||
log.error("[validateDemoOrderCanRefunded][order({}) 退款单不匹配({}),请进行处理!order 数据是:{}]",
|
||||
id, payRefundId, toJsonString(order));
|
||||
throw exception(DEMO_ORDER_REFUND_FAIL_REFUND_ORDER_ID_ERROR);
|
||||
|
||||
@@ -1,7 +1,9 @@
|
||||
package cn.iocoder.yudao.module.pay.service.demo;
|
||||
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageParam;
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||
import cn.iocoder.yudao.module.pay.controller.admin.demo.vo.transfer.PayDemoTransferCreateReqVO;
|
||||
|
||||
import cn.iocoder.yudao.module.pay.dal.dataobject.demo.PayDemoTransferDO;
|
||||
import jakarta.validation.Valid;
|
||||
|
||||
/**
|
||||
@@ -12,11 +14,25 @@ import jakarta.validation.Valid;
|
||||
public interface PayDemoTransferService {
|
||||
|
||||
/**
|
||||
* 创建转账单
|
||||
* 创建转账业务示例订单
|
||||
*
|
||||
* @param userId 用户编号
|
||||
* @param createReqVO 创建信息
|
||||
* @return 编号
|
||||
*/
|
||||
Long createDemoTransfer(Long userId, @Valid PayDemoTransferCreateReqVO createReqVO);
|
||||
Long createDemoTransfer(@Valid PayDemoTransferCreateReqVO createReqVO);
|
||||
|
||||
/**
|
||||
* 获得转账业务示例订单分页
|
||||
*
|
||||
* @param pageVO 分页查询参数
|
||||
*/
|
||||
PageResult<PayDemoTransferDO> getDemoTransferPage(PageParam pageVO);
|
||||
|
||||
/**
|
||||
* 更新转账业务示例订单的转账状态
|
||||
*
|
||||
* @param id 编号
|
||||
* @param payTransferId 转账单编号
|
||||
*/
|
||||
void updateDemoTransferStatus(Long id, Long payTransferId);
|
||||
}
|
||||
|
||||
@@ -1,25 +1,25 @@
|
||||
package cn.iocoder.yudao.module.pay.service.demo;
|
||||
|
||||
import cn.hutool.core.map.MapUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import cn.iocoder.yudao.framework.pay.core.enums.transfer.PayTransferTypeEnum;
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageParam;
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||
import cn.iocoder.yudao.module.pay.controller.admin.demo.vo.transfer.PayDemoTransferCreateReqVO;
|
||||
import cn.iocoder.yudao.module.pay.convert.transfer.PayTransferConvert;
|
||||
import cn.iocoder.yudao.module.pay.convert.demo.PayDemoTransferConvert;
|
||||
import cn.iocoder.yudao.module.pay.dal.dataobject.demo.PayDemoTransferDO;
|
||||
import cn.iocoder.yudao.module.pay.dal.dataobject.transfer.PayTransferDO;
|
||||
import cn.iocoder.yudao.module.pay.dal.mysql.demo.PayDemoTransferMapper;
|
||||
import cn.iocoder.yudao.module.pay.enums.transfer.PayTransferStatusEnum;
|
||||
import cn.iocoder.yudao.module.pay.service.transfer.PayTransferService;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
|
||||
import jakarta.annotation.Resource;
|
||||
import jakarta.validation.Valid;
|
||||
import java.util.Map;
|
||||
import jakarta.validation.Validator;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
|
||||
import static cn.iocoder.yudao.framework.pay.core.enums.transfer.PayTransferTypeEnum.*;
|
||||
import static cn.iocoder.yudao.module.pay.enums.ErrorCodeConstants.PAY_TRANSFER_ALIPAY_ACCOUNT_NAME_IS_EMPTY;
|
||||
import static cn.iocoder.yudao.module.pay.enums.ErrorCodeConstants.PAY_TRANSFER_ALIPAY_LOGIN_ID_IS_EMPTY;
|
||||
import static cn.iocoder.yudao.module.pay.enums.ErrorCodeConstants.*;
|
||||
import static cn.iocoder.yudao.module.pay.enums.transfer.PayTransferStatusEnum.WAITING;
|
||||
|
||||
/**
|
||||
@@ -40,50 +40,60 @@ public class PayDemoTransferServiceImpl implements PayDemoTransferService {
|
||||
@Resource
|
||||
private PayDemoTransferMapper demoTransferMapper;
|
||||
@Resource
|
||||
private PayTransferService transferService;
|
||||
private PayTransferService payTransferService;
|
||||
@Resource
|
||||
private Validator validator;
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public Long createDemoTransfer(Long userId, @Valid PayDemoTransferCreateReqVO vo) {
|
||||
// 1 校验收款账号
|
||||
validatePayeeInfo(vo.getType(), vo.getPayeeInfo());
|
||||
|
||||
public Long createDemoTransfer(@Valid PayDemoTransferCreateReqVO vo) {
|
||||
// 1 校验参数
|
||||
vo.validate(validator);
|
||||
// 2 保存示例转账业务表
|
||||
PayDemoTransferDO demoTransfer = new PayDemoTransferDO().setUserId(userId).setType(vo.getType())
|
||||
.setPrice(vo.getPrice()).setPayeeInfo(vo.getPayeeInfo())
|
||||
.setTransferStatus(WAITING.getStatus());
|
||||
PayDemoTransferDO demoTransfer = PayDemoTransferConvert.INSTANCE.convert(vo)
|
||||
.setAppId(TRANSFER_APP_ID).setTransferStatus(WAITING.getStatus());
|
||||
demoTransferMapper.insert(demoTransfer);
|
||||
|
||||
// 3.1 创建转账单
|
||||
Long transferId = transferService.createTransfer(PayTransferConvert.INSTANCE.convert(vo)
|
||||
.setAppId(TRANSFER_APP_ID).setTitle("示例转账")
|
||||
.setMerchantOrderId(String.valueOf(demoTransfer.getId())));
|
||||
// 3.2 更新转账单编号
|
||||
demoTransferMapper.updateById(new PayDemoTransferDO().setId(demoTransfer.getId())
|
||||
.setPayTransferId(transferId));
|
||||
return demoTransfer.getId();
|
||||
}
|
||||
|
||||
// TODO @jason:可以参考 AppBrokerageWithdrawCreateReqVO 搞下字段哈,进行校验
|
||||
// @jason payeeinfo 字段确定改一下
|
||||
private void validatePayeeInfo(Integer transferType, Map<String, String> payeeInfo) {
|
||||
PayTransferTypeEnum transferTypeEnum = typeOf(transferType);
|
||||
switch (transferTypeEnum) {
|
||||
case ALIPAY_BALANCE: {
|
||||
if (StrUtil.isEmpty(MapUtil.getStr(payeeInfo, ALIPAY_LOGON_ID))) {
|
||||
throw exception(PAY_TRANSFER_ALIPAY_LOGIN_ID_IS_EMPTY);
|
||||
}
|
||||
if (StrUtil.isEmpty(MapUtil.getStr(payeeInfo, ALIPAY_ACCOUNT_NAME))) {
|
||||
throw exception(PAY_TRANSFER_ALIPAY_ACCOUNT_NAME_IS_EMPTY);
|
||||
}
|
||||
break;
|
||||
}
|
||||
case WX_BALANCE:
|
||||
case BANK_CARD:
|
||||
case WALLET_BALANCE: {
|
||||
throw new UnsupportedOperationException("待实现");
|
||||
}
|
||||
@Override
|
||||
public PageResult<PayDemoTransferDO> getDemoTransferPage(PageParam pageVO) {
|
||||
return demoTransferMapper.selectPage(pageVO);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateDemoTransferStatus(Long id, Long payTransferId) {
|
||||
PayTransferDO payTransfer = validateDemoTransferStatusCanUpdate(id, payTransferId);
|
||||
// 更新示例订单状态
|
||||
if (payTransfer != null) {
|
||||
demoTransferMapper.updateById(new PayDemoTransferDO().setId(id)
|
||||
.setPayTransferId(payTransferId)
|
||||
.setPayChannelCode(payTransfer.getChannelCode())
|
||||
.setTransferStatus(payTransfer.getStatus())
|
||||
.setTransferTime(payTransfer.getSuccessTime()));
|
||||
}
|
||||
}
|
||||
|
||||
private PayTransferDO validateDemoTransferStatusCanUpdate(Long id, Long payTransferId) {
|
||||
PayDemoTransferDO demoTransfer = demoTransferMapper.selectById(id);
|
||||
if (demoTransfer == null) {
|
||||
throw exception(DEMO_TRANSFER_NOT_FOUND);
|
||||
}
|
||||
if (PayTransferStatusEnum.isSuccess(demoTransfer.getTransferStatus())
|
||||
|| PayTransferStatusEnum.isClosed(demoTransfer.getTransferStatus())) {
|
||||
// 无需更新返回 null
|
||||
return null;
|
||||
}
|
||||
PayTransferDO transfer = payTransferService.getTransfer(payTransferId);
|
||||
if (transfer == null) {
|
||||
throw exception(PAY_TRANSFER_NOT_FOUND);
|
||||
}
|
||||
if (!Objects.equals(demoTransfer.getPrice(), transfer.getPrice())) {
|
||||
throw exception(DEMO_TRANSFER_FAIL_PRICE_NOT_MATCH);
|
||||
}
|
||||
if (ObjectUtil.notEqual(transfer.getMerchantTransferId(), id.toString())) {
|
||||
throw exception(DEMO_TRANSFER_FAIL_TRANSFER_ID_ERROR);
|
||||
}
|
||||
// TODO 校验账号
|
||||
return transfer;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,11 +13,13 @@ import cn.iocoder.yudao.framework.common.util.json.JsonUtils;
|
||||
import cn.iocoder.yudao.framework.tenant.core.util.TenantUtils;
|
||||
import cn.iocoder.yudao.module.pay.api.notify.dto.PayOrderNotifyReqDTO;
|
||||
import cn.iocoder.yudao.module.pay.api.notify.dto.PayRefundNotifyReqDTO;
|
||||
import cn.iocoder.yudao.module.pay.api.notify.dto.PayTransferNotifyReqDTO;
|
||||
import cn.iocoder.yudao.module.pay.controller.admin.notify.vo.PayNotifyTaskPageReqVO;
|
||||
import cn.iocoder.yudao.module.pay.dal.dataobject.notify.PayNotifyLogDO;
|
||||
import cn.iocoder.yudao.module.pay.dal.dataobject.notify.PayNotifyTaskDO;
|
||||
import cn.iocoder.yudao.module.pay.dal.dataobject.order.PayOrderDO;
|
||||
import cn.iocoder.yudao.module.pay.dal.dataobject.refund.PayRefundDO;
|
||||
import cn.iocoder.yudao.module.pay.dal.dataobject.transfer.PayTransferDO;
|
||||
import cn.iocoder.yudao.module.pay.dal.mysql.notify.PayNotifyLogMapper;
|
||||
import cn.iocoder.yudao.module.pay.dal.mysql.notify.PayNotifyTaskMapper;
|
||||
import cn.iocoder.yudao.module.pay.dal.redis.notify.PayNotifyLockRedisDAO;
|
||||
@@ -25,7 +27,10 @@ import cn.iocoder.yudao.module.pay.enums.notify.PayNotifyStatusEnum;
|
||||
import cn.iocoder.yudao.module.pay.enums.notify.PayNotifyTypeEnum;
|
||||
import cn.iocoder.yudao.module.pay.service.order.PayOrderService;
|
||||
import cn.iocoder.yudao.module.pay.service.refund.PayRefundService;
|
||||
import cn.iocoder.yudao.module.pay.service.transfer.PayTransferService;
|
||||
import com.google.common.annotations.VisibleForTesting;
|
||||
import jakarta.annotation.Resource;
|
||||
import jakarta.validation.Valid;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.context.annotation.Lazy;
|
||||
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
|
||||
@@ -34,8 +39,6 @@ import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.transaction.support.TransactionSynchronization;
|
||||
import org.springframework.transaction.support.TransactionSynchronizationManager;
|
||||
|
||||
import jakarta.annotation.Resource;
|
||||
import jakarta.validation.Valid;
|
||||
import java.time.Duration;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.HashMap;
|
||||
@@ -73,6 +76,9 @@ public class PayNotifyServiceImpl implements PayNotifyService {
|
||||
@Resource
|
||||
@Lazy // 循环依赖,避免报错
|
||||
private PayRefundService refundService;
|
||||
@Resource
|
||||
@Lazy // 循环依赖,避免报错
|
||||
private PayTransferService transferService;
|
||||
|
||||
@Resource
|
||||
private PayNotifyTaskMapper notifyTaskMapper;
|
||||
@@ -100,6 +106,10 @@ public class PayNotifyServiceImpl implements PayNotifyService {
|
||||
PayRefundDO refundDO = refundService.getRefund(task.getDataId());
|
||||
task.setAppId(refundDO.getAppId())
|
||||
.setMerchantOrderId(refundDO.getMerchantOrderId()).setNotifyUrl(refundDO.getNotifyUrl());
|
||||
} else if (Objects.equals(task.getType(), PayNotifyTypeEnum.TRANSFER.getType())) {
|
||||
PayTransferDO transfer = transferService.getTransfer(task.getDataId());
|
||||
task.setAppId(transfer.getAppId()).setMerchantTransferId(transfer.getMerchantTransferId())
|
||||
.setNotifyUrl(transfer.getNotifyUrl());
|
||||
}
|
||||
|
||||
// 执行插入
|
||||
@@ -214,6 +224,9 @@ public class PayNotifyServiceImpl implements PayNotifyService {
|
||||
} else if (Objects.equals(task.getType(), PayNotifyTypeEnum.REFUND.getType())) {
|
||||
request = PayRefundNotifyReqDTO.builder().merchantOrderId(task.getMerchantOrderId())
|
||||
.payRefundId(task.getDataId()).build();
|
||||
} else if (Objects.equals(task.getType(), PayNotifyTypeEnum.TRANSFER.getType())) {
|
||||
request = new PayTransferNotifyReqDTO().setMerchantTransferId(task.getMerchantTransferId())
|
||||
.setPayTransferId(task.getDataId());
|
||||
} else {
|
||||
throw new RuntimeException("未知的通知任务类型:" + JsonUtils.toJsonString(task));
|
||||
}
|
||||
@@ -252,6 +265,7 @@ public class PayNotifyServiceImpl implements PayNotifyService {
|
||||
notifyTaskMapper.updateById(updateTask);
|
||||
return updateTask.getStatus();
|
||||
}
|
||||
|
||||
// 情况二:调用失败、调用异常
|
||||
// 2.1 超过最大回调次数
|
||||
if (updateTask.getNotifyTimes() >= PayNotifyTaskDO.NOTIFY_FREQUENCY.length) {
|
||||
|
||||
@@ -9,10 +9,11 @@ import cn.iocoder.yudao.module.pay.controller.admin.order.vo.PayOrderSubmitReqVO
|
||||
import cn.iocoder.yudao.module.pay.controller.admin.order.vo.PayOrderSubmitRespVO;
|
||||
import cn.iocoder.yudao.module.pay.dal.dataobject.order.PayOrderDO;
|
||||
import cn.iocoder.yudao.module.pay.dal.dataobject.order.PayOrderExtensionDO;
|
||||
|
||||
import jakarta.validation.Valid;
|
||||
import jakarta.validation.constraints.NotEmpty;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
@@ -39,6 +40,14 @@ public interface PayOrderService {
|
||||
*/
|
||||
PayOrderDO getOrder(Long appId, String merchantOrderId);
|
||||
|
||||
/**
|
||||
* 获得支付订单列表
|
||||
*
|
||||
* @param ids 编号数组
|
||||
* @return 支付订单列表
|
||||
*/
|
||||
List<PayOrderDO> getOrderList(Collection<Long> ids);
|
||||
|
||||
/**
|
||||
* 获得指定应用的订单数量
|
||||
*
|
||||
|
||||
@@ -32,13 +32,15 @@ import cn.iocoder.yudao.module.pay.service.app.PayAppService;
|
||||
import cn.iocoder.yudao.module.pay.service.channel.PayChannelService;
|
||||
import cn.iocoder.yudao.module.pay.service.notify.PayNotifyService;
|
||||
import com.google.common.annotations.VisibleForTesting;
|
||||
import jakarta.annotation.Resource;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
|
||||
import jakarta.annotation.Resource;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
@@ -83,6 +85,14 @@ public class PayOrderServiceImpl implements PayOrderService {
|
||||
return orderMapper.selectByAppIdAndMerchantOrderId(appId, merchantOrderId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<PayOrderDO> getOrderList(Collection<Long> ids) {
|
||||
if (CollUtil.isEmpty(ids)) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
return orderMapper.selectBatchIds(ids);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Long getOrderCountByAppId(Long appId) {
|
||||
return orderMapper.selectCountByAppId(appId);
|
||||
@@ -438,7 +448,7 @@ public class PayOrderServiceImpl implements PayOrderService {
|
||||
|
||||
@Override
|
||||
public int syncOrder(LocalDateTime minCreateTime) {
|
||||
// 1. 查询指定创建时间内的待支付订单
|
||||
// 1. 查询指定创建时间前的待支付订单
|
||||
List<PayOrderExtensionDO> orderExtensions = orderExtensionMapper.selectListByStatusAndCreateTimeGe(
|
||||
PayOrderStatusEnum.WAITING.getStatus(), minCreateTime);
|
||||
if (CollUtil.isEmpty(orderExtensions)) {
|
||||
@@ -467,6 +477,14 @@ public class PayOrderServiceImpl implements PayOrderService {
|
||||
return false;
|
||||
}
|
||||
PayOrderRespDTO respDTO = payClient.getOrder(orderExtension.getNo());
|
||||
// 如果查询到订单不存在,PayClient 返回的状态为关闭。但此时不能关闭订单。存在以下一种场景:
|
||||
// 拉起渠道支付后,短时间内用户未及时完成支付,但是该订单同步定时任务恰巧自动触发了,主动查询结果为订单不存在。
|
||||
// 当用户支付成功之后,该订单状态在渠道的回调中无法从已关闭改为已支付,造成重大影响。
|
||||
// 考虑此定时任务是异常场景的兜底操作,因此这里不做变更,优先以回调为准。
|
||||
// 让订单自动随着支付渠道那边一起等到过期,确保渠道先过期关闭支付入口,而后通过订单过期定时任务关闭自己的订单。
|
||||
if (PayOrderStatusRespEnum.isClosed(respDTO.getStatus())) {
|
||||
return false;
|
||||
}
|
||||
// 1.2 回调支付结果
|
||||
notifyOrder(orderExtension.getChannelId(), respDTO);
|
||||
|
||||
|
||||
@@ -26,12 +26,12 @@ import cn.iocoder.yudao.module.pay.service.app.PayAppService;
|
||||
import cn.iocoder.yudao.module.pay.service.channel.PayChannelService;
|
||||
import cn.iocoder.yudao.module.pay.service.notify.PayNotifyService;
|
||||
import cn.iocoder.yudao.module.pay.service.order.PayOrderService;
|
||||
import jakarta.annotation.Resource;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
|
||||
import jakarta.annotation.Resource;
|
||||
import java.util.List;
|
||||
|
||||
import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
|
||||
|
||||
@@ -1,9 +1,10 @@
|
||||
package cn.iocoder.yudao.module.pay.service.transfer;
|
||||
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||
import cn.iocoder.yudao.module.pay.api.transfer.dto.PayTransferCreateReqDTO;
|
||||
import cn.iocoder.yudao.module.pay.controller.admin.transfer.vo.PayTransferSubmitReqVO;
|
||||
import cn.iocoder.yudao.module.pay.controller.admin.transfer.vo.PayTransferSubmitRespVO;
|
||||
|
||||
import cn.iocoder.yudao.module.pay.controller.admin.transfer.vo.PayTransferCreateReqVO;
|
||||
import cn.iocoder.yudao.module.pay.controller.admin.transfer.vo.PayTransferPageReqVO;
|
||||
import cn.iocoder.yudao.module.pay.dal.dataobject.transfer.PayTransferDO;
|
||||
import jakarta.validation.Valid;
|
||||
|
||||
/**
|
||||
@@ -14,22 +15,42 @@ import jakarta.validation.Valid;
|
||||
public interface PayTransferService {
|
||||
|
||||
/**
|
||||
* 提交转账单
|
||||
* 创建转账单,并发起转账
|
||||
*
|
||||
* 此时,会发起支付渠道的调用
|
||||
* 此时,会发起转账渠道的调用
|
||||
*
|
||||
* @param reqVO 请求
|
||||
* @param userIp 用户 ip
|
||||
* @return 渠道的返回结果
|
||||
*/
|
||||
PayTransferSubmitRespVO submitTransfer(@Valid PayTransferSubmitReqVO reqVO, String userIp);
|
||||
PayTransferDO createTransfer(@Valid PayTransferCreateReqVO reqVO, String userIp);
|
||||
|
||||
/**
|
||||
* 创建转账单
|
||||
* 创建转账单,并发起转账
|
||||
*
|
||||
* @param reqDTO 创建请求
|
||||
* @return 转账单编号
|
||||
*/
|
||||
Long createTransfer(@Valid PayTransferCreateReqDTO reqDTO);
|
||||
|
||||
/**
|
||||
* 获取转账单
|
||||
* @param id 转账单编号
|
||||
*/
|
||||
PayTransferDO getTransfer(Long id);
|
||||
|
||||
/**
|
||||
* 获得转账单分页
|
||||
*
|
||||
* @param pageReqVO 分页查询
|
||||
* @return 转账单分页
|
||||
*/
|
||||
PageResult<PayTransferDO> getTransferPage(PayTransferPageReqVO pageReqVO);
|
||||
|
||||
/**
|
||||
* 同步渠道转账单状态
|
||||
*
|
||||
* @return 同步到状态的转账数量,包括转账成功、转账失败、转账中的
|
||||
*/
|
||||
int syncTransfer();
|
||||
}
|
||||
|
||||
@@ -1,40 +1,44 @@
|
||||
package cn.iocoder.yudao.module.pay.service.transfer;
|
||||
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import cn.hutool.extra.spring.SpringUtil;
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||
import cn.iocoder.yudao.framework.common.util.json.JsonUtils;
|
||||
import cn.iocoder.yudao.framework.pay.core.client.PayClient;
|
||||
import cn.iocoder.yudao.framework.pay.core.client.dto.transfer.PayTransferRespDTO;
|
||||
import cn.iocoder.yudao.framework.pay.core.client.dto.transfer.PayTransferUnifiedReqDTO;
|
||||
import cn.iocoder.yudao.framework.pay.core.enums.channel.PayChannelEnum;
|
||||
import cn.iocoder.yudao.framework.pay.core.enums.transfer.PayTransferStatusRespEnum;
|
||||
import cn.iocoder.yudao.framework.pay.core.enums.transfer.PayTransferTypeEnum;
|
||||
import cn.iocoder.yudao.framework.tenant.core.util.TenantUtils;
|
||||
import cn.iocoder.yudao.module.pay.api.transfer.dto.PayTransferCreateReqDTO;
|
||||
import cn.iocoder.yudao.module.pay.controller.admin.transfer.vo.PayTransferSubmitReqVO;
|
||||
import cn.iocoder.yudao.module.pay.controller.admin.transfer.vo.PayTransferSubmitRespVO;
|
||||
import cn.iocoder.yudao.module.pay.convert.transfer.PayTransferConvert;
|
||||
import cn.iocoder.yudao.module.pay.controller.admin.transfer.vo.PayTransferCreateReqVO;
|
||||
import cn.iocoder.yudao.module.pay.controller.admin.transfer.vo.PayTransferPageReqVO;
|
||||
import cn.iocoder.yudao.module.pay.dal.dataobject.app.PayAppDO;
|
||||
import cn.iocoder.yudao.module.pay.dal.dataobject.channel.PayChannelDO;
|
||||
import cn.iocoder.yudao.module.pay.dal.dataobject.transfer.PayTransferDO;
|
||||
import cn.iocoder.yudao.module.pay.dal.dataobject.transfer.PayTransferExtensionDO;
|
||||
import cn.iocoder.yudao.module.pay.dal.mysql.transfer.PayTransferExtensionMapper;
|
||||
import cn.iocoder.yudao.module.pay.dal.mysql.transfer.PayTransferMapper;
|
||||
import cn.iocoder.yudao.module.pay.dal.redis.no.PayNoRedisDAO;
|
||||
import cn.iocoder.yudao.module.pay.enums.notify.PayNotifyTypeEnum;
|
||||
import cn.iocoder.yudao.module.pay.enums.transfer.PayTransferStatusEnum;
|
||||
import cn.iocoder.yudao.module.pay.service.app.PayAppService;
|
||||
import cn.iocoder.yudao.module.pay.service.channel.PayChannelService;
|
||||
import cn.iocoder.yudao.module.pay.service.notify.PayNotifyService;
|
||||
import jakarta.annotation.Resource;
|
||||
import jakarta.validation.Validator;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import jakarta.annotation.Resource;
|
||||
import java.util.Objects;
|
||||
import java.util.List;
|
||||
|
||||
import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
|
||||
import static cn.iocoder.yudao.module.pay.convert.transfer.PayTransferConvert.INSTANCE;
|
||||
import static cn.iocoder.yudao.module.pay.enums.ErrorCodeConstants.*;
|
||||
import static cn.iocoder.yudao.module.pay.enums.transfer.PayTransferStatusEnum.*;
|
||||
|
||||
// TODO @jason:等彻底实现完,单测写写;
|
||||
|
||||
/**
|
||||
* 转账 Service 实现类
|
||||
*
|
||||
@@ -48,63 +52,88 @@ public class PayTransferServiceImpl implements PayTransferService {
|
||||
|
||||
@Resource
|
||||
private PayTransferMapper transferMapper;
|
||||
@Resource
|
||||
private PayTransferExtensionMapper transferExtensionMapper;
|
||||
|
||||
@Resource
|
||||
private PayAppService appService;
|
||||
@Resource
|
||||
private PayChannelService channelService;
|
||||
|
||||
@Resource
|
||||
private PayNotifyService notifyService;
|
||||
@Resource
|
||||
private PayNoRedisDAO noRedisDAO;
|
||||
@Resource
|
||||
private Validator validator;
|
||||
|
||||
@Override
|
||||
public PayTransferSubmitRespVO submitTransfer(PayTransferSubmitReqVO reqVO, String userIp) {
|
||||
// 1.1 校验转账单是否可以提交
|
||||
PayTransferDO transfer = validateTransferCanSubmit(reqVO.getId());
|
||||
// 1.2 校验转账类型和渠道是否匹配
|
||||
validateChannelCodeAndTypeMatch(reqVO.getChannelCode(), transfer.getType());
|
||||
// 1.3 校验支付渠道是否有效
|
||||
PayChannelDO channel = validateChannelCanSubmit(transfer.getAppId(), reqVO.getChannelCode());
|
||||
PayClient client = channelService.getPayClient(channel.getId());
|
||||
public PayTransferDO createTransfer(PayTransferCreateReqVO reqVO, String userIp) {
|
||||
// 1. 校验参数
|
||||
reqVO.validate(validator);
|
||||
|
||||
// 2. 新增转账拓展单
|
||||
String no = noRedisDAO.generate(TRANSFER_NO_PREFIX);
|
||||
PayTransferExtensionDO transferExtension = new PayTransferExtensionDO().setNo(no)
|
||||
.setTransferId(transfer.getId()).setChannelId(channel.getId())
|
||||
.setChannelCode(channel.getCode()).setStatus(WAITING.getStatus());
|
||||
transferExtensionMapper.insert(transferExtension);
|
||||
// 2. 创建转账单,发起转账
|
||||
PayTransferCreateReqDTO req = INSTANCE.convert(reqVO).setUserIp(userIp);
|
||||
Long transferId = createTransfer(req);
|
||||
|
||||
// 3. 调用三方渠道发起转账
|
||||
PayTransferUnifiedReqDTO transferUnifiedReq = new PayTransferUnifiedReqDTO()
|
||||
.setOutTransferNo(transferExtension.getNo()).setPrice(transfer.getPrice())
|
||||
.setType(transfer.getType()).setTitle(transfer.getSubject())
|
||||
.setPayeeInfo(transfer.getPayeeInfo()).setUserIp(userIp)
|
||||
.setChannelExtras(reqVO.getChannelExtras());
|
||||
PayTransferRespDTO unifiedTransferResp = client.unifiedTransfer(transferUnifiedReq);
|
||||
|
||||
// 4. 通知转账结果
|
||||
getSelf().notifyTransfer(channel, unifiedTransferResp);
|
||||
// 如有渠道错误码,则抛出业务异常,提示用户
|
||||
if (StrUtil.isNotEmpty(unifiedTransferResp.getChannelErrorCode())) {
|
||||
throw exception(PAY_TRANSFER_SUBMIT_CHANNEL_ERROR, unifiedTransferResp.getChannelErrorCode(),
|
||||
unifiedTransferResp.getChannelErrorMsg());
|
||||
}
|
||||
return new PayTransferSubmitRespVO().setStatus(unifiedTransferResp.getStatus());
|
||||
// 3. 返回转账单
|
||||
return getTransfer(transferId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Long createTransfer(PayTransferCreateReqDTO reqDTO) {
|
||||
// 校验 App
|
||||
appService.validPayApp(reqDTO.getAppId());
|
||||
// 创建转账单
|
||||
PayTransferDO transfer = PayTransferConvert.INSTANCE.convert(reqDTO)
|
||||
.setStatus(WAITING.getStatus());
|
||||
transferMapper.insert(transfer);
|
||||
// 1.1 校验 App
|
||||
PayAppDO payApp = appService.validPayApp(reqDTO.getAppId());
|
||||
// 1.2 校验支付渠道是否有效
|
||||
PayChannelDO channel = channelService.validPayChannel(reqDTO.getAppId(), reqDTO.getChannelCode());
|
||||
PayClient client = channelService.getPayClient(channel.getId());
|
||||
if (client == null) {
|
||||
log.error("[createTransfer][渠道编号({}) 找不到对应的支付客户端]", channel.getId());
|
||||
throw exception(CHANNEL_NOT_FOUND);
|
||||
}
|
||||
// 1.3 校验转账单已经发起过转账。
|
||||
PayTransferDO transfer = validateTransferCanCreate(reqDTO);
|
||||
|
||||
if (transfer == null) {
|
||||
// 2.不存在创建转账单. 否则允许使用相同的 no 再次发起转账
|
||||
String no = noRedisDAO.generate(TRANSFER_NO_PREFIX);
|
||||
transfer = INSTANCE.convert(reqDTO)
|
||||
.setChannelId(channel.getId())
|
||||
.setNo(no).setStatus(WAITING.getStatus())
|
||||
.setNotifyUrl(payApp.getTransferNotifyUrl());
|
||||
transferMapper.insert(transfer);
|
||||
}
|
||||
try {
|
||||
// 3. 调用三方渠道发起转账
|
||||
PayTransferUnifiedReqDTO transferUnifiedReq = INSTANCE.convert2(transfer)
|
||||
.setOutTransferNo(transfer.getNo());
|
||||
PayTransferRespDTO unifiedTransferResp = client.unifiedTransfer(transferUnifiedReq);
|
||||
// 4. 通知转账结果
|
||||
getSelf().notifyTransfer(channel, unifiedTransferResp);
|
||||
} catch (Throwable e) {
|
||||
// 注意这里仅打印异常,不进行抛出。
|
||||
// 原因是:虽然调用支付渠道进行转账发生异常(网络请求超时),实际转账成功。这个结果,后续转账轮询可以拿到。
|
||||
// 或者使用相同 no 再次发起转账请求
|
||||
log.error("[createTransfer][转账 id({}) requestDTO({}) 发生异常]", transfer.getId(), reqDTO, e);
|
||||
}
|
||||
|
||||
return transfer.getId();
|
||||
}
|
||||
|
||||
private PayTransferDO validateTransferCanCreate(PayTransferCreateReqDTO dto) {
|
||||
PayTransferDO transfer = transferMapper.selectByAppIdAndMerchantTransferId(dto.getAppId(), dto.getMerchantTransferId());
|
||||
if (transfer != null) {
|
||||
// 已经存在,并且状态不为等待状态。说明已经调用渠道转账并返回结果.
|
||||
if (!PayTransferStatusEnum.isWaiting(transfer.getStatus())) {
|
||||
throw exception(PAY_MERCHANT_TRANSFER_EXISTS);
|
||||
}
|
||||
if (ObjectUtil.notEqual(dto.getPrice(), transfer.getPrice())) {
|
||||
throw exception(PAY_SAME_MERCHANT_TRANSFER_PRICE_NOT_MATCH);
|
||||
}
|
||||
if (ObjectUtil.notEqual(dto.getType(), transfer.getType())) {
|
||||
throw exception(PAY_SAME_MERCHANT_TRANSFER_TYPE_NOT_MATCH);
|
||||
}
|
||||
}
|
||||
// 如果状态为等待状态。不知道渠道转账是否发起成功。 允许使用相同的 no 再次发起转账,渠道会保证幂等
|
||||
return transfer;
|
||||
}
|
||||
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
// 注意,如果是方法内调用该方法,需要通过 getSelf().notifyTransfer(channel, notify) 调用,否则事务不生效
|
||||
public void notifyTransfer(PayChannelDO channel, PayTransferRespDTO notify) {
|
||||
@@ -116,32 +145,48 @@ public class PayTransferServiceImpl implements PayTransferService {
|
||||
if (PayTransferStatusRespEnum.isClosed(notify.getStatus())) {
|
||||
notifyTransferClosed(channel, notify);
|
||||
}
|
||||
// WAITING 状态无需处理
|
||||
// TODO IN_PROGRESS 待处理
|
||||
}
|
||||
|
||||
private void notifyTransferSuccess(PayChannelDO channel, PayTransferRespDTO notify) {
|
||||
// 1. 更新 PayTransferExtensionDO 转账成功
|
||||
PayTransferExtensionDO transferExtension = updateTransferExtensionSuccess(notify);
|
||||
|
||||
// 2. 更新 PayTransferDO 转账成功
|
||||
Boolean transferred = updateTransferSuccess(channel,transferExtension, notify);
|
||||
if (transferred) {
|
||||
return;
|
||||
// 转账处理中的回调
|
||||
if (PayTransferStatusRespEnum.isInProgress(notify.getStatus())) {
|
||||
notifyTransferInProgress(channel, notify);
|
||||
}
|
||||
// 3. TODO 插入转账通知记录
|
||||
// WAITING 状态无需处理
|
||||
}
|
||||
|
||||
private Boolean updateTransferSuccess(PayChannelDO channel, PayTransferExtensionDO transferExtension,
|
||||
PayTransferRespDTO notify) {
|
||||
private void notifyTransferInProgress(PayChannelDO channel, PayTransferRespDTO notify) {
|
||||
// 1.校验
|
||||
PayTransferDO transfer = transferMapper.selectById(transferExtension.getTransferId());
|
||||
PayTransferDO transfer = transferMapper.selectByNo(notify.getOutTransferNo());
|
||||
if (transfer == null) {
|
||||
throw exception(PAY_TRANSFER_NOT_FOUND);
|
||||
}
|
||||
if (isSuccess(transfer.getStatus()) && Objects.equals(transfer.getExtensionId(), transferExtension.getId())) {
|
||||
log.info("[updateTransferSuccess][transfer({}) 已经是已转账,无需更新]", transfer.getId());
|
||||
return true;
|
||||
if (isInProgress(transfer.getStatus())) { // 如果已经是转账中,直接返回,不用重复更新
|
||||
return;
|
||||
}
|
||||
if (!isWaiting(transfer.getStatus())) {
|
||||
throw exception(PAY_TRANSFER_STATUS_IS_NOT_WAITING);
|
||||
}
|
||||
// 2.更新
|
||||
int updateCounts = transferMapper.updateByIdAndStatus(transfer.getId(),
|
||||
CollUtil.newArrayList(WAITING.getStatus()),
|
||||
new PayTransferDO().setStatus(IN_PROGRESS.getStatus()));
|
||||
if (updateCounts == 0) {
|
||||
throw exception(PAY_TRANSFER_STATUS_IS_NOT_WAITING);
|
||||
}
|
||||
log.info("[notifyTransferInProgress][transfer({}) 更新为转账进行中状态]", transfer.getId());
|
||||
|
||||
// 3. 插入转账通知记录
|
||||
notifyService.createPayNotifyTask(PayNotifyTypeEnum.TRANSFER.getType(),
|
||||
transfer.getId());
|
||||
}
|
||||
|
||||
|
||||
private void notifyTransferSuccess(PayChannelDO channel, PayTransferRespDTO notify) {
|
||||
// 1.校验
|
||||
PayTransferDO transfer = transferMapper.selectByNo(notify.getOutTransferNo());
|
||||
if (transfer == null) {
|
||||
throw exception(PAY_TRANSFER_NOT_FOUND);
|
||||
}
|
||||
if (isSuccess(transfer.getStatus())) { // 如果已成功,直接返回,不用重复更新
|
||||
return;
|
||||
}
|
||||
if (!isPendingStatus(transfer.getStatus())) {
|
||||
throw exception(PAY_TRANSFER_STATUS_IS_NOT_PENDING);
|
||||
@@ -150,114 +195,99 @@ public class PayTransferServiceImpl implements PayTransferService {
|
||||
int updateCounts = transferMapper.updateByIdAndStatus(transfer.getId(),
|
||||
CollUtil.newArrayList(WAITING.getStatus(), IN_PROGRESS.getStatus()),
|
||||
new PayTransferDO().setStatus(SUCCESS.getStatus()).setSuccessTime(notify.getSuccessTime())
|
||||
.setChannelTransferNo(notify.getChannelTransferNo())
|
||||
.setChannelId(channel.getId()).setChannelCode(channel.getCode())
|
||||
.setExtensionId(transferExtension.getId()).setNo(transferExtension.getNo()));
|
||||
.setChannelNotifyData(JsonUtils.toJsonString(notify)));
|
||||
if (updateCounts == 0) {
|
||||
throw exception(PAY_TRANSFER_STATUS_IS_NOT_PENDING);
|
||||
}
|
||||
log.info("[updateTransferSuccess][transfer({}) 更新为已转账]", transfer.getId());
|
||||
return false;
|
||||
}
|
||||
|
||||
private PayTransferExtensionDO updateTransferExtensionSuccess(PayTransferRespDTO notify) {
|
||||
// 1 校验
|
||||
PayTransferExtensionDO transferExtension = transferExtensionMapper.selectByNo(notify.getOutTransferNo());
|
||||
if (transferExtension == null) {
|
||||
throw exception(PAY_TRANSFER_EXTENSION_NOT_FOUND);
|
||||
}
|
||||
if (isSuccess(transferExtension.getStatus())) { // 如果已成功,直接返回,不用重复更新
|
||||
log.info("[updateTransferExtensionSuccess][transferExtension({}) 已经是成功状态,无需更新]", transferExtension.getId());
|
||||
return transferExtension;
|
||||
}
|
||||
if (!isPendingStatus(transferExtension.getStatus())) {
|
||||
throw exception(PAY_TRANSFER_EXTENSION_STATUS_IS_NOT_PENDING);
|
||||
}
|
||||
// 2. 更新 PayTransferExtensionDO
|
||||
int updateCount = transferExtensionMapper.updateByIdAndStatus(transferExtension.getId(),
|
||||
CollUtil.newArrayList(WAITING.getStatus(), IN_PROGRESS.getStatus()),
|
||||
new PayTransferExtensionDO().setStatus(SUCCESS.getStatus())
|
||||
.setChannelNotifyData(JsonUtils.toJsonString(notify)));
|
||||
if (updateCount == 0) {
|
||||
throw exception(PAY_TRANSFER_EXTENSION_STATUS_IS_NOT_PENDING);
|
||||
}
|
||||
log.info("[updateTransferExtensionSuccess][transferExtension({}) 更新为已转账]", transferExtension.getId());
|
||||
return transferExtension;
|
||||
// 3. 插入转账通知记录
|
||||
notifyService.createPayNotifyTask(PayNotifyTypeEnum.TRANSFER.getType(),
|
||||
transfer.getId());
|
||||
}
|
||||
|
||||
private void notifyTransferClosed(PayChannelDO channel, PayTransferRespDTO notify) {
|
||||
// 更新 PayTransferExtensionDO 转账关闭
|
||||
updateTransferExtensionClosed(notify);
|
||||
}
|
||||
|
||||
private void updateTransferExtensionClosed(PayTransferRespDTO notify) {
|
||||
// 1 校验
|
||||
PayTransferExtensionDO transferExtension = transferExtensionMapper.selectByNo(notify.getOutTransferNo());
|
||||
if (transferExtension == null) {
|
||||
throw exception(PAY_TRANSFER_EXTENSION_NOT_FOUND);
|
||||
}
|
||||
if (isClosed(transferExtension.getStatus())) { // 如果已是关闭状态,直接返回,不用重复更新
|
||||
log.info("[updateTransferExtensionSuccess][transferExtension({}) 已经是关闭状态,无需更新]", transferExtension.getId());
|
||||
return;
|
||||
}
|
||||
if (!isPendingStatus(transferExtension.getStatus())) {
|
||||
throw exception(PAY_TRANSFER_EXTENSION_STATUS_IS_NOT_PENDING);
|
||||
}
|
||||
// 2. 更新 PayTransferExtensionDO
|
||||
int updateCount = transferExtensionMapper.updateByIdAndStatus(transferExtension.getId(),
|
||||
CollUtil.newArrayList(WAITING.getStatus(), IN_PROGRESS.getStatus()),
|
||||
new PayTransferExtensionDO().setStatus(CLOSED.getStatus())
|
||||
.setChannelNotifyData(JsonUtils.toJsonString(notify)));
|
||||
if (updateCount == 0) {
|
||||
throw exception(PAY_TRANSFER_EXTENSION_STATUS_IS_NOT_PENDING);
|
||||
}
|
||||
log.info("[updateTransferExtensionSuccess][transferExtension({}) 更新为关闭状态]", transferExtension.getId());
|
||||
}
|
||||
|
||||
private void validateChannelCodeAndTypeMatch(String channelCode, Integer type) {
|
||||
PayTransferTypeEnum transferType = PayTransferTypeEnum.typeOf(type);
|
||||
PayChannelEnum payChannel = PayChannelEnum.getByCode(channelCode);
|
||||
switch (transferType) {
|
||||
case ALIPAY_BALANCE: {
|
||||
// TODO @jason:可以抽到 PayChannelEnum 里,isAlipay? 类似这种哈
|
||||
if (!payChannel.getCode().startsWith("alipay")) {
|
||||
throw exception(PAY_TRANSFER_TYPE_AND_CHANNEL_NOT_MATCH);
|
||||
}
|
||||
break;
|
||||
}
|
||||
case WX_BALANCE:
|
||||
case BANK_CARD:
|
||||
case WALLET_BALANCE: {
|
||||
throw new UnsupportedOperationException("待实现");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private PayChannelDO validateChannelCanSubmit(Long appId, String channelCode) {
|
||||
// 校验 App
|
||||
appService.validPayApp(appId);
|
||||
// 校验支付渠道是否有效
|
||||
PayChannelDO channel = channelService.validPayChannel(appId, channelCode);
|
||||
PayClient client = channelService.getPayClient(channel.getId());
|
||||
if (client == null) {
|
||||
log.error("[validateChannelCanSubmit][渠道编号({}) 找不到对应的支付客户端]", channel.getId());
|
||||
throw exception(CHANNEL_NOT_FOUND);
|
||||
}
|
||||
return channel;
|
||||
}
|
||||
|
||||
private PayTransferDO validateTransferCanSubmit(Long id) {
|
||||
PayTransferDO transfer = transferMapper.selectById(id);
|
||||
if (transfer == null) { // 是否存在
|
||||
// 1.校验
|
||||
PayTransferDO transfer = transferMapper.selectByNo(notify.getOutTransferNo());
|
||||
if (transfer == null) {
|
||||
throw exception(PAY_TRANSFER_NOT_FOUND);
|
||||
}
|
||||
if (PayTransferStatusEnum.isSuccess(transfer.getStatus())) {
|
||||
throw exception(PAY_TRANSFER_STATUS_IS_SUCCESS);
|
||||
if (isClosed(transfer.getStatus())) { // 如果已是关闭状态,直接返回,不用重复更新
|
||||
log.info("[updateTransferClosed][transfer({}) 已经是关闭状态,无需更新]", transfer.getId());
|
||||
return;
|
||||
}
|
||||
if (!PayTransferStatusEnum.isWaiting(transfer.getStatus())) {
|
||||
throw exception(PAY_TRANSFER_STATUS_IS_NOT_WAITING);
|
||||
if (!isPendingStatus(transfer.getStatus())) {
|
||||
throw exception(PAY_TRANSFER_STATUS_IS_NOT_PENDING);
|
||||
}
|
||||
// TODO 查询拓展单是否未已转账和转账中
|
||||
return transfer;
|
||||
|
||||
// 2.更新
|
||||
int updateCount = transferMapper.updateByIdAndStatus(transfer.getId(),
|
||||
CollUtil.newArrayList(WAITING.getStatus(), IN_PROGRESS.getStatus()),
|
||||
new PayTransferDO().setStatus(CLOSED.getStatus()).setChannelId(channel.getId())
|
||||
.setChannelCode(channel.getCode()).setChannelTransferNo(notify.getChannelTransferNo())
|
||||
.setChannelErrorCode(notify.getChannelErrorCode()).setChannelErrorMsg(notify.getChannelErrorMsg())
|
||||
.setChannelNotifyData(JsonUtils.toJsonString(notify)));
|
||||
if (updateCount == 0) {
|
||||
throw exception(PAY_TRANSFER_STATUS_IS_NOT_PENDING);
|
||||
}
|
||||
log.info("[updateTransferClosed][transfer({}) 更新为关闭状态]", transfer.getId());
|
||||
|
||||
// 3. 插入转账通知记录
|
||||
notifyService.createPayNotifyTask(PayNotifyTypeEnum.TRANSFER.getType(),
|
||||
transfer.getId());
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public PayTransferDO getTransfer(Long id) {
|
||||
return transferMapper.selectById(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public PageResult<PayTransferDO> getTransferPage(PayTransferPageReqVO pageReqVO) {
|
||||
return transferMapper.selectPage(pageReqVO);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int syncTransfer() {
|
||||
List<PayTransferDO> list = transferMapper.selectListByStatus(WAITING.getStatus());
|
||||
if (CollUtil.isEmpty(list)) {
|
||||
return 0;
|
||||
}
|
||||
int count = 0;
|
||||
for (PayTransferDO transfer : list) {
|
||||
count += syncTransfer(transfer) ? 1 : 0;
|
||||
}
|
||||
return count;
|
||||
}
|
||||
|
||||
private boolean syncTransfer(PayTransferDO transfer) {
|
||||
try {
|
||||
// 1. 查询转账订单信息
|
||||
PayClient payClient = channelService.getPayClient(transfer.getChannelId());
|
||||
if (payClient == null) {
|
||||
log.error("[syncTransfer][渠道编号({}) 找不到对应的支付客户端]", transfer.getChannelId());
|
||||
return false;
|
||||
}
|
||||
PayTransferRespDTO resp = payClient.getTransfer(transfer.getNo(),
|
||||
PayTransferTypeEnum.typeOf(transfer.getType()));
|
||||
|
||||
// 2. 回调转账结果
|
||||
notifyTransfer(transfer.getChannelId(), resp);
|
||||
return true;
|
||||
} catch (Throwable ex) {
|
||||
log.error("[syncTransfer][transfer({}) 同步转账单状态异常]", transfer.getId(), ex);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
private void notifyTransfer(Long channelId, PayTransferRespDTO notify) {
|
||||
// 校验渠道是否有效
|
||||
PayChannelDO channel = channelService.validPayChannel(channelId);
|
||||
// 通知转账结果给对应的业务
|
||||
TenantUtils.execute(channel.getTenantId(), () -> getSelf().notifyTransfer(channel, notify));
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -5,9 +5,10 @@ import cn.iocoder.yudao.module.pay.controller.admin.wallet.vo.rechargepackage.Wa
|
||||
import cn.iocoder.yudao.module.pay.controller.admin.wallet.vo.rechargepackage.WalletRechargePackagePageReqVO;
|
||||
import cn.iocoder.yudao.module.pay.controller.admin.wallet.vo.rechargepackage.WalletRechargePackageUpdateReqVO;
|
||||
import cn.iocoder.yudao.module.pay.dal.dataobject.wallet.PayWalletRechargePackageDO;
|
||||
|
||||
import jakarta.validation.Valid;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 钱包充值套餐 Service 接口
|
||||
*
|
||||
@@ -58,4 +59,12 @@ public interface PayWalletRechargePackageService {
|
||||
*/
|
||||
PageResult<PayWalletRechargePackageDO> getWalletRechargePackagePage(WalletRechargePackagePageReqVO pageReqVO);
|
||||
|
||||
/**
|
||||
* 获得充值套餐列表
|
||||
*
|
||||
* @param status 状态
|
||||
* @return 充值套餐列表
|
||||
*/
|
||||
List<PayWalletRechargePackageDO> getWalletRechargePackageList(Integer status);
|
||||
|
||||
}
|
||||
|
||||
@@ -6,12 +6,13 @@ import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||
import cn.iocoder.yudao.module.pay.controller.admin.wallet.vo.rechargepackage.WalletRechargePackageCreateReqVO;
|
||||
import cn.iocoder.yudao.module.pay.controller.admin.wallet.vo.rechargepackage.WalletRechargePackagePageReqVO;
|
||||
import cn.iocoder.yudao.module.pay.controller.admin.wallet.vo.rechargepackage.WalletRechargePackageUpdateReqVO;
|
||||
import cn.iocoder.yudao.module.pay.convert.wallet.WalletRechargePackageConvert;
|
||||
import cn.iocoder.yudao.module.pay.convert.wallet.PayWalletRechargePackageConvert;
|
||||
import cn.iocoder.yudao.module.pay.dal.dataobject.wallet.PayWalletRechargePackageDO;
|
||||
import cn.iocoder.yudao.module.pay.dal.mysql.wallet.PayWalletRechargePackageMapper;
|
||||
import jakarta.annotation.Resource;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import jakarta.annotation.Resource;
|
||||
import java.util.List;
|
||||
|
||||
import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
|
||||
import static cn.iocoder.yudao.module.pay.enums.ErrorCodeConstants.*;
|
||||
@@ -50,7 +51,7 @@ public class PayWalletRechargePackageServiceImpl implements PayWalletRechargePac
|
||||
validateRechargePackageNameUnique(null, createReqVO.getName());
|
||||
|
||||
// 插入
|
||||
PayWalletRechargePackageDO walletRechargePackage = WalletRechargePackageConvert.INSTANCE.convert(createReqVO);
|
||||
PayWalletRechargePackageDO walletRechargePackage = PayWalletRechargePackageConvert.INSTANCE.convert(createReqVO);
|
||||
walletRechargePackageMapper.insert(walletRechargePackage);
|
||||
// 返回
|
||||
return walletRechargePackage.getId();
|
||||
@@ -64,7 +65,7 @@ public class PayWalletRechargePackageServiceImpl implements PayWalletRechargePac
|
||||
validateRechargePackageNameUnique(updateReqVO.getId(), updateReqVO.getName());
|
||||
|
||||
// 更新
|
||||
PayWalletRechargePackageDO updateObj = WalletRechargePackageConvert.INSTANCE.convert(updateReqVO);
|
||||
PayWalletRechargePackageDO updateObj = PayWalletRechargePackageConvert.INSTANCE.convert(updateReqVO);
|
||||
walletRechargePackageMapper.updateById(updateObj);
|
||||
}
|
||||
|
||||
@@ -103,4 +104,9 @@ public class PayWalletRechargePackageServiceImpl implements PayWalletRechargePac
|
||||
return walletRechargePackageMapper.selectPage(pageReqVO);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<PayWalletRechargePackageDO> getWalletRechargePackageList(Integer status) {
|
||||
return walletRechargePackageMapper.selectListByStatus(status);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
package cn.iocoder.yudao.module.pay.service.wallet;
|
||||
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageParam;
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||
import cn.iocoder.yudao.module.pay.controller.app.wallet.vo.recharge.AppPayWalletRechargeCreateReqVO;
|
||||
import cn.iocoder.yudao.module.pay.dal.dataobject.wallet.PayWalletRechargeDO;
|
||||
|
||||
@@ -22,6 +24,18 @@ public interface PayWalletRechargeService {
|
||||
PayWalletRechargeDO createWalletRecharge(Long userId, Integer userType, String userIp,
|
||||
AppPayWalletRechargeCreateReqVO createReqVO);
|
||||
|
||||
/**
|
||||
* 获得钱包充值记录分页
|
||||
*
|
||||
* @param userId 用户编号
|
||||
* @param userType 用户类型
|
||||
* @param pageReqVO 分页请求
|
||||
* @param payStatus 是否支付
|
||||
* @return 钱包充值记录分页
|
||||
*/
|
||||
PageResult<PayWalletRechargeDO> getWalletRechargePackagePage(Long userId, Integer userType,
|
||||
PageParam pageReqVO, Boolean payStatus);
|
||||
|
||||
/**
|
||||
* 更新钱包充值成功
|
||||
*
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
package cn.iocoder.yudao.module.pay.service.wallet;
|
||||
|
||||
import cn.hutool.core.lang.Assert;
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageParam;
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||
import cn.iocoder.yudao.framework.pay.core.enums.refund.PayRefundStatusRespEnum;
|
||||
import cn.iocoder.yudao.module.pay.api.order.dto.PayOrderCreateReqDTO;
|
||||
import cn.iocoder.yudao.module.pay.api.refund.dto.PayRefundCreateReqDTO;
|
||||
@@ -16,11 +18,11 @@ import cn.iocoder.yudao.module.pay.enums.refund.PayRefundStatusEnum;
|
||||
import cn.iocoder.yudao.module.pay.enums.wallet.PayWalletBizTypeEnum;
|
||||
import cn.iocoder.yudao.module.pay.service.order.PayOrderService;
|
||||
import cn.iocoder.yudao.module.pay.service.refund.PayRefundService;
|
||||
import jakarta.annotation.Resource;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import jakarta.annotation.Resource;
|
||||
import java.time.Duration;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.Objects;
|
||||
@@ -64,11 +66,6 @@ public class PayWalletRechargeServiceImpl implements PayWalletRechargeService {
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public PayWalletRechargeDO createWalletRecharge(Long userId, Integer userType, String userIp,
|
||||
AppPayWalletRechargeCreateReqVO reqVO) {
|
||||
|
||||
if (Objects.isNull(reqVO.getPayPrice()) && Objects.isNull(reqVO.getPackageId())) {
|
||||
// TODO @jason @AssertTrue 貌似没有效果。需要查下原因
|
||||
throw exception(WALLET_RECHARGE_PACKAGE_AND_PRICE_IS_EMPTY);
|
||||
}
|
||||
// 1.1 计算充值金额
|
||||
int payPrice;
|
||||
int bonusPrice = 0;
|
||||
@@ -97,6 +94,13 @@ public class PayWalletRechargeServiceImpl implements PayWalletRechargeService {
|
||||
return recharge;
|
||||
}
|
||||
|
||||
@Override
|
||||
public PageResult<PayWalletRechargeDO> getWalletRechargePackagePage(Long userId, Integer userType,
|
||||
PageParam pageReqVO, Boolean payStatus) {
|
||||
PayWalletDO wallet = payWalletService.getOrCreateWallet(userId, userType);
|
||||
return walletRechargeMapper.selectPage(pageReqVO, wallet.getId(), payStatus);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void updateWalletRechargerPaid(Long id, Long payOrderId) {
|
||||
|
||||
@@ -30,14 +30,13 @@ public interface PayWalletService {
|
||||
*/
|
||||
PayWalletDO getWallet(Long walletId);
|
||||
|
||||
|
||||
/**
|
||||
* 获得会员钱包分页
|
||||
*
|
||||
* @param pageReqVO 分页查询
|
||||
* @return 会员钱包分页
|
||||
*/
|
||||
PageResult<PayWalletDO> getWalletPage(Integer userType, PayWalletPageReqVO pageReqVO);
|
||||
PageResult<PayWalletDO> getWalletPage(PayWalletPageReqVO pageReqVO);
|
||||
|
||||
/**
|
||||
* 钱包订单支付
|
||||
|
||||
@@ -12,12 +12,12 @@ import cn.iocoder.yudao.module.pay.enums.wallet.PayWalletBizTypeEnum;
|
||||
import cn.iocoder.yudao.module.pay.service.order.PayOrderService;
|
||||
import cn.iocoder.yudao.module.pay.service.refund.PayRefundService;
|
||||
import cn.iocoder.yudao.module.pay.service.wallet.bo.WalletTransactionCreateReqBO;
|
||||
import jakarta.annotation.Resource;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.context.annotation.Lazy;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import jakarta.annotation.Resource;
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
|
||||
@@ -36,13 +36,15 @@ public class PayWalletServiceImpl implements PayWalletService {
|
||||
|
||||
@Resource
|
||||
private PayWalletMapper walletMapper;
|
||||
|
||||
@Resource
|
||||
@Lazy // 延迟加载,避免循环依赖
|
||||
private PayWalletTransactionService walletTransactionService;
|
||||
@Resource
|
||||
@Lazy
|
||||
@Lazy // 延迟加载,避免循环依赖
|
||||
private PayOrderService orderService;
|
||||
@Resource
|
||||
@Lazy
|
||||
@Lazy // 延迟加载,避免循环依赖
|
||||
private PayRefundService refundService;
|
||||
|
||||
@Override
|
||||
@@ -63,8 +65,8 @@ public class PayWalletServiceImpl implements PayWalletService {
|
||||
}
|
||||
|
||||
@Override
|
||||
public PageResult<PayWalletDO> getWalletPage(Integer userType,PayWalletPageReqVO pageReqVO) {
|
||||
return walletMapper.selectPage(userType, pageReqVO);
|
||||
public PageResult<PayWalletDO> getWalletPage(PayWalletPageReqVO pageReqVO) {
|
||||
return walletMapper.selectPage(pageReqVO);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user