pay:同步最新功能的代码(钱包、转账)

This commit is contained in:
YunaiV
2023-10-24 08:00:01 +08:00
parent 9fc31ac2ae
commit df2b1b45a4
122 changed files with 5161 additions and 455 deletions

View File

@@ -1,5 +1,6 @@
package cn.iocoder.yudao.module.pay.api.order;
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.module.pay.api.order.dto.PayOrderCreateReqDTO;
import cn.iocoder.yudao.module.pay.api.order.dto.PayOrderRespDTO;
import cn.iocoder.yudao.module.pay.enums.ApiConstants;
@@ -15,8 +16,6 @@ import org.springframework.web.bind.annotation.RequestParam;
import javax.validation.Valid;
// TODO 芋艿CommonResult
@FeignClient(name = ApiConstants.NAME) // TODO 芋艿fallbackFactory =
@Tag(name = "RPC 服务 - 支付单")
public interface PayOrderApi {
@@ -25,12 +24,12 @@ public interface PayOrderApi {
@PostMapping(PREFIX + "/create")
@Operation(summary = "创建支付单")
Long createOrder(@Valid @RequestBody PayOrderCreateReqDTO reqDTO);
CommonResult<Long> createOrder(@Valid @RequestBody PayOrderCreateReqDTO reqDTO);
@PostMapping(PREFIX + "/get")
@Operation(summary = "获得支付单")
@Parameter(name = "id", description = "支付单编号", example = "1", required = true)
PayOrderRespDTO getOrder(Long id);
CommonResult<PayOrderRespDTO> getOrder(Long id);
@PutMapping(PREFIX + "/update-price")
@Operation(summary = "更新支付订单价格")
@@ -38,7 +37,7 @@ public interface PayOrderApi {
@Parameter(name = "id", description = "支付单编号", example = "1", required = true),
@Parameter(name = "payPrice", description = "支付单价格", example = "100", required = true)
})
void updatePayOrderPrice(@RequestParam("id") Long id,
@RequestParam("payPrice") Integer payPrice);
CommonResult<Boolean> updatePayOrderPrice(@RequestParam("id") Long id,
@RequestParam("payPrice") Integer payPrice);
}

View File

@@ -1,5 +1,6 @@
package cn.iocoder.yudao.module.pay.api.refund;
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
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.enums.ApiConstants;
@@ -20,11 +21,11 @@ public interface PayRefundApi {
@PostMapping(PREFIX + "/create")
@Operation(summary = "创建退款单")
Long createRefund(@Valid @RequestBody PayRefundCreateReqDTO reqDTO);
CommonResult<Long> createRefund(@Valid @RequestBody PayRefundCreateReqDTO reqDTO);
@PostMapping(PREFIX + "/get")
@Operation(summary = "获得退款单")
@Parameter(name = "id", description = "退款单编号", example = "1", required = true)
PayRefundRespDTO getRefund(Long id);
CommonResult<PayRefundRespDTO> getRefund(Long id);
}

View File

@@ -0,0 +1,24 @@
package cn.iocoder.yudao.module.pay.api.transfer;
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.module.pay.api.transfer.dto.PayTransferCreateReqDTO;
import cn.iocoder.yudao.module.pay.enums.ApiConstants;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import javax.validation.Valid;
@FeignClient(name = ApiConstants.NAME) // TODO 芋艿fallbackFactory =
@Tag(name = "RPC 服务 - 转账单")
public interface PayTransferApi {
String PREFIX = ApiConstants.PREFIX + "/transfer";
@PostMapping(PREFIX + "/create")
@Operation(summary = "创建转账单")
CommonResult<Long> createTransfer(@Valid @RequestBody PayTransferCreateReqDTO reqDTO);
}

View File

@@ -0,0 +1,43 @@
package cn.iocoder.yudao.module.pay.api.transfer.dto;
import cn.iocoder.yudao.framework.common.validation.InEnum;
import cn.iocoder.yudao.module.pay.enums.transfer.PayTransferTypeEnum;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import javax.validation.constraints.Min;
import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;
import java.util.Map;
@Schema(description = "RPC 服务 - 转账单创建 Request DTO")
@Data
public class PayTransferCreateReqDTO {
@Schema(description = "应用编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024")
@NotNull(message = "应用编号不能为空")
private Long appId;
@Schema(description = "类型", requiredMode = Schema.RequiredMode.REQUIRED, example = "1")
@NotNull(message = "转账类型不能为空")
@InEnum(PayTransferTypeEnum.class)
private Integer type;
@Schema(description = "商户订单编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "M101") // 例如说,内部系统 A 的订单号。需要保证每个 PayMerchantDO 唯一
@NotEmpty(message = "商户订单编号不能为空")
private String merchantOrderId;
@Schema(description = "转账金额,单位:分", requiredMode = Schema.RequiredMode.REQUIRED, example = "80")
@Min(value = 1, message = "转账金额必须大于零")
@NotNull(message = "转账金额不能为空")
private Integer price;
@Schema(description = "转账标题", requiredMode = Schema.RequiredMode.REQUIRED, example = "我是标题")
@NotEmpty(message = "转账标题不能为空")
private String title;
@Schema(description = "收款方信息", requiredMode = Schema.RequiredMode.REQUIRED)
@NotEmpty(message = "收款方信息不能为空")
private Map<String, String> payeeInfo;
}

View File

@@ -21,17 +21,17 @@ public interface ErrorCodeConstants {
ErrorCode CHANNEL_EXIST_SAME_CHANNEL_ERROR = new ErrorCode(1_007_001_004, "已存在相同的渠道");
// ========== ORDER 模块 1-007-002-000 ==========
ErrorCode ORDER_NOT_FOUND = new ErrorCode(1_007_002_000, "支付订单不存在");
ErrorCode ORDER_STATUS_IS_NOT_WAITING = new ErrorCode(1_007_002_001, "支付订单不处于待支付");
ErrorCode ORDER_STATUS_IS_SUCCESS = new ErrorCode(1_007_002_002, "订单已支付,请刷新页面");
ErrorCode ORDER_IS_EXPIRED = new ErrorCode(1_007_002_003, "支付订单已经过期");
ErrorCode ORDER_SUBMIT_CHANNEL_ERROR = new ErrorCode(1_007_002_004, "发起支付报错,错误码:{},错误提示:{}");
ErrorCode ORDER_REFUND_FAIL_STATUS_ERROR = new ErrorCode(1_007_002_005, "支付订单退款失败,原因:状态不是已支付或已退款");
ErrorCode PAY_ORDER_NOT_FOUND = new ErrorCode(1_007_002_000, "支付订单不存在");
ErrorCode PAY_ORDER_STATUS_IS_NOT_WAITING = new ErrorCode(1_007_002_001, "支付订单不处于待支付");
ErrorCode PAY_ORDER_STATUS_IS_SUCCESS = new ErrorCode(1_007_002_002, "订单已支付,请刷新页面");
ErrorCode PAY_ORDER_IS_EXPIRED = new ErrorCode(1_007_002_003, "支付订单已经过期");
ErrorCode PAY_ORDER_SUBMIT_CHANNEL_ERROR = new ErrorCode(1_007_002_004, "发起支付报错,错误码:{},错误提示:{}");
ErrorCode PAY_ORDER_REFUND_FAIL_STATUS_ERROR = new ErrorCode(1_007_002_005, "支付订单退款失败,原因:状态不是已支付或已退款");
// ========== ORDER 模块(拓展单) 1-007-003-000 ==========
ErrorCode ORDER_EXTENSION_NOT_FOUND = new ErrorCode(1_007_003_000, "支付交易拓展单不存在");
ErrorCode ORDER_EXTENSION_STATUS_IS_NOT_WAITING = new ErrorCode(1_007_003_001, "支付交易拓展单不处于待支付");
ErrorCode ORDER_EXTENSION_IS_PAID = new ErrorCode(1_007_003_002, "订单已支付,请等待支付结果");
ErrorCode PAY_ORDER_EXTENSION_NOT_FOUND = new ErrorCode(1_007_003_000, "支付交易拓展单不存在");
ErrorCode PAY_ORDER_EXTENSION_STATUS_IS_NOT_WAITING = new ErrorCode(1_007_003_001, "支付交易拓展单不处于待支付");
ErrorCode PAY_ORDER_EXTENSION_IS_PAID = new ErrorCode(1_007_003_002, "订单已支付,请等待支付结果");
// ========== 支付模块(退款) 1-007-006-000 ==========
ErrorCode REFUND_PRICE_EXCEED = new ErrorCode(1_007_006_000, "退款金额超过订单可退款金额");
@@ -40,6 +40,42 @@ public interface ErrorCodeConstants {
ErrorCode REFUND_NOT_FOUND = new ErrorCode(1_007_006_004, "支付退款单不存在");
ErrorCode REFUND_STATUS_IS_NOT_WAITING = new ErrorCode(1_007_006_005, "支付退款单不处于待退款");
// ========== 钱包模块 1-007-007-000 ==========
ErrorCode WALLET_NOT_FOUND = new ErrorCode(1_007_007_000, "用户钱包不存在");
ErrorCode WALLET_BALANCE_NOT_ENOUGH = new ErrorCode(1_007_007_001, "钱包余额不足");
ErrorCode WALLET_TRANSACTION_NOT_FOUND = new ErrorCode(1_007_007_002, "未找到对应的钱包交易");
ErrorCode WALLET_REFUND_EXIST = new ErrorCode(1_007_007_003, "已经存在钱包退款");
ErrorCode WALLET_FREEZE_PRICE_NOT_ENOUGH = new ErrorCode(1_007_007_004, "钱包冻结余额不足");
// ========== 钱包充值模块 1-007-008-000 ==========
ErrorCode WALLET_RECHARGE_NOT_FOUND = new ErrorCode(1_007_008_000, "钱包充值记录不存在");
ErrorCode WALLET_RECHARGE_UPDATE_PAID_STATUS_NOT_UNPAID = new ErrorCode(1_007_008_001, "钱包充值更新支付状态失败,钱包充值记录不是【未支付】状态");
ErrorCode WALLET_RECHARGE_UPDATE_PAID_PAY_ORDER_ID_ERROR = new ErrorCode(1_007_008_002, "钱包充值更新支付状态失败,支付单编号不匹配");
ErrorCode WALLET_RECHARGE_UPDATE_PAID_PAY_ORDER_STATUS_NOT_SUCCESS = new ErrorCode(1_007_008_003, "钱包充值更新支付状态失败,支付单状态不是【支付成功】状态");
ErrorCode WALLET_RECHARGE_UPDATE_PAID_PAY_PRICE_NOT_MATCH = new ErrorCode(1_007_008_004, "钱包充值更新支付状态失败,支付单金额不匹配");
ErrorCode WALLET_RECHARGE_REFUND_FAIL_NOT_PAID = new ErrorCode(1_007_008_005, "钱包发起退款失败,钱包充值订单未支付");
ErrorCode WALLET_RECHARGE_REFUND_FAIL_REFUNDED = new ErrorCode(1_007_008_006, "钱包发起退款失败,钱包充值订单已退款");
ErrorCode WALLET_RECHARGE_REFUND_BALANCE_NOT_ENOUGH = new ErrorCode(1_007_008_007, "钱包发起退款失败,钱包余额不足");
ErrorCode WALLET_RECHARGE_REFUND_FAIL_REFUND_ORDER_ID_ERROR = new ErrorCode(1_007_008_008, "钱包退款更新失败,钱包退款单编号不匹配");
ErrorCode WALLET_RECHARGE_REFUND_FAIL_REFUND_NOT_FOUND = new ErrorCode(1_007_008_009, "钱包退款更新失败,退款订单不存在");
ErrorCode WALLET_RECHARGE_REFUND_FAIL_REFUND_PRICE_NOT_MATCH = new ErrorCode(1_007_008_010, "钱包退款更新失败,退款单金额不匹配");
ErrorCode WALLET_RECHARGE_PACKAGE_AND_PRICE_IS_EMPTY = new ErrorCode(1_007_008_011, "充值金额和充钱套餐不能同时为空");
ErrorCode WALLET_RECHARGE_PACKAGE_NOT_FOUND = new ErrorCode(1_007_008_012, "钱包充值套餐不存在");
ErrorCode WALLET_RECHARGE_PACKAGE_IS_DISABLE = new ErrorCode(1_007_008_013, "钱包充值套餐已禁用");
ErrorCode WALLET_RECHARGE_PACKAGE_NAME_EXISTS = new ErrorCode(1_007_008_014, "钱包充值套餐名称已存在");
// ========== 转账模块 1-007-009-000 ==========
ErrorCode PAY_TRANSFER_SUBMIT_CHANNEL_ERROR = new ErrorCode(1_007_009_000, "发起转账报错,错误码:{},错误提示:{}");
ErrorCode PAY_TRANSFER_ALIPAY_LOGIN_ID_IS_EMPTY = new ErrorCode(1_007_009_001, "支付宝登录 ID 不能为空");
ErrorCode PAY_TRANSFER_ALIPAY_ACCOUNT_NAME_IS_EMPTY = new ErrorCode(1_007_009_002, "支付宝账号名称不能为空");
ErrorCode PAY_TRANSFER_NOT_FOUND = new ErrorCode(1_007_009_003, "转账交易单不存在");
ErrorCode PAY_TRANSFER_STATUS_IS_SUCCESS = new ErrorCode(1_007_009_004, "转账单已成功转账");
ErrorCode PAY_TRANSFER_STATUS_IS_NOT_WAITING = new ErrorCode(1_007_009_005, "转账单不处于待转账");
ErrorCode PAY_TRANSFER_STATUS_IS_NOT_PENDING = new ErrorCode(1_007_009_006, "转账单不处于待转账或转账中");
ErrorCode PAY_TRANSFER_EXTENSION_NOT_FOUND = new ErrorCode(1_007_009_007, "转账交易拓展单不存在");
ErrorCode PAY_TRANSFER_TYPE_AND_CHANNEL_NOT_MATCH = new ErrorCode(1_007_009_008, "转账类型和转账渠道不匹配");
ErrorCode PAY_TRANSFER_EXTENSION_STATUS_IS_NOT_PENDING = new ErrorCode(1_007_009_009, "转账拓展单不处于待转账或转账中");
// ========== 示例订单 1-007-900-000 ==========
ErrorCode DEMO_ORDER_NOT_FOUND = new ErrorCode(1_007_900_000, "示例订单不存在");
ErrorCode DEMO_ORDER_UPDATE_PAID_STATUS_NOT_UNPAID = new ErrorCode(1_007_900_001, "示例订单更新支付状态失败,订单不是【未支付】状态");

View File

@@ -1,21 +0,0 @@
package cn.iocoder.yudao.module.pay.enums.member;
import lombok.AllArgsConstructor;
import lombok.Getter;
/**
* 钱包操作类型枚举
*
* @author jason
*/
@AllArgsConstructor
@Getter
public enum WalletOperateTypeEnum {
TOP_UP_INC(1, "充值增加"),
ORDER_DEC(2, "订单消费扣除");
// TODO 其它类型
private final Integer type;
private final String desc;
}

View File

@@ -1,26 +0,0 @@
package cn.iocoder.yudao.module.pay.enums.member;
import lombok.AllArgsConstructor;
import lombok.Getter;
/**
* 钱包交易大类枚举
*
* @author jason
*/
@AllArgsConstructor
@Getter
public enum WalletTransactionGategoryEnum {
TOP_UP(1, "充值"),
SPENDING(2, "支出");
/**
* 分类
*/
private final Integer category;
/**
* 说明
*/
private final String desc;
}

View File

@@ -0,0 +1,55 @@
package cn.iocoder.yudao.module.pay.enums.transfer;
import lombok.AllArgsConstructor;
import lombok.Getter;
import java.util.Objects;
/**
* @author jason
*/
@Getter
@AllArgsConstructor
public enum PayTransferStatusEnum {
WAITING(0, "待转账"),
/**
* TODO 转账到银行卡. 会有T+0 T+1 到账的请情况。 还未实现
*/
IN_PROGRESS(10, "转账进行中"),
SUCCESS(20, "转账成功"),
/**
* 转账关闭 (失败,或者其它情况)
*/
CLOSED(30, "转账关闭");
/**
* 状态
*/
private final Integer status;
/**
* 状态名
*/
private final String name;
public static boolean isSuccess(Integer status) {
return Objects.equals(status, SUCCESS.getStatus());
}
public static boolean isClosed(Integer status) {
return Objects.equals(status, CLOSED.getStatus());
}
public static boolean isWaiting(Integer status) {
return Objects.equals(status, WAITING.getStatus());
}
/**
* 是否处于待转账或者转账中的状态
* @param status 状态
*/
public static boolean isPendingStatus(Integer status) {
return Objects.equals(status, WAITING.getStatus()) || Objects.equals(status, IN_PROGRESS.status);
}
}

View File

@@ -0,0 +1,41 @@
package cn.iocoder.yudao.module.pay.enums.transfer;
import cn.hutool.core.util.ArrayUtil;
import cn.iocoder.yudao.framework.common.core.IntArrayValuable;
import lombok.AllArgsConstructor;
import lombok.Getter;
import java.util.Arrays;
/**
* 转账类型枚举
*
* @author jason
*/
@AllArgsConstructor
@Getter
public enum PayTransferTypeEnum implements IntArrayValuable {
ALIPAY_BALANCE(1, "支付宝余额"),
WX_BALANCE(2, "微信余额"),
BANK_CARD(3, "银行卡"),
WALLET_BALANCE(4, "钱包余额");
public static final String ALIPAY_LOGON_ID = "ALIPAY_LOGON_ID";
public static final String ALIPAY_ACCOUNT_NAME = "ALIPAY_ACCOUNT_NAME";
private final Integer type;
private final String name;
public static final int[] ARRAYS = Arrays.stream(values()).mapToInt(PayTransferTypeEnum::getType).toArray();
@Override
public int[] array() {
return ARRAYS;
}
public static PayTransferTypeEnum typeOf(Integer type) {
return ArrayUtil.firstMatch(item -> item.getType().equals(type), values());
}
}

View File

@@ -30,6 +30,11 @@
<artifactId>yudao-module-pay-api</artifactId>
<version>${revision}</version>
</dependency>
<dependency>
<groupId>cn.iocoder.cloud</groupId>
<artifactId>yudao-module-member-api</artifactId>
<version>${revision}</version>
</dependency>
<!-- 业务组件 -->
<dependency>

View File

@@ -1,17 +1,18 @@
package cn.iocoder.yudao.module.pay.api.order;
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.module.pay.api.order.dto.PayOrderCreateReqDTO;
import cn.iocoder.yudao.module.pay.api.order.dto.PayOrderRespDTO;
import cn.iocoder.yudao.module.pay.convert.order.PayOrderConvert;
import cn.iocoder.yudao.module.pay.dal.dataobject.order.PayOrderDO;
import cn.iocoder.yudao.module.pay.service.order.PayOrderService;
import org.springframework.stereotype.Service;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RestController;
import javax.annotation.Resource;
@Service
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
@RestController // 提供 RESTful API 接口,给 Feign 调用
@Validated
public class PayOrderApiImpl implements PayOrderApi {
@@ -20,19 +21,20 @@ public class PayOrderApiImpl implements PayOrderApi {
private PayOrderService payOrderService;
@Override
public Long createOrder(PayOrderCreateReqDTO reqDTO) {
return payOrderService.createOrder(reqDTO);
public CommonResult<Long> createOrder(PayOrderCreateReqDTO reqDTO) {
return success(payOrderService.createOrder(reqDTO));
}
@Override
public PayOrderRespDTO getOrder(Long id) {
public CommonResult<PayOrderRespDTO> getOrder(Long id) {
PayOrderDO order = payOrderService.getOrder(id);
return PayOrderConvert.INSTANCE.convert2(order);
return success(PayOrderConvert.INSTANCE.convert2(order));
}
@Override
public void updatePayOrderPrice(Long id, Integer payPrice) {
public CommonResult<Boolean> updatePayOrderPrice(Long id, Integer payPrice) {
payOrderService.updatePayOrderPrice(id, payPrice);
return success(true);
}
}

View File

@@ -1,16 +1,17 @@
package cn.iocoder.yudao.module.pay.api.refund;
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
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.convert.refund.PayRefundConvert;
import cn.iocoder.yudao.module.pay.service.refund.PayRefundService;
import org.springframework.stereotype.Service;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RestController;
import javax.annotation.Resource;
@Service
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
@RestController // 提供 RESTful API 接口,给 Feign 调用
@Validated
public class PayRefundApiImpl implements PayRefundApi {
@@ -19,13 +20,13 @@ public class PayRefundApiImpl implements PayRefundApi {
private PayRefundService payRefundService;
@Override
public Long createRefund(PayRefundCreateReqDTO reqDTO) {
return payRefundService.createPayRefund(reqDTO);
public CommonResult<Long> createRefund(PayRefundCreateReqDTO reqDTO) {
return success(payRefundService.createPayRefund(reqDTO));
}
@Override
public PayRefundRespDTO getRefund(Long id) {
return PayRefundConvert.INSTANCE.convert02(payRefundService.getRefund(id));
public CommonResult<PayRefundRespDTO> getRefund(Long id) {
return success(PayRefundConvert.INSTANCE.convert02(payRefundService.getRefund(id)));
}
}

View File

@@ -0,0 +1,30 @@
package cn.iocoder.yudao.module.pay.api.transfer;
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.module.pay.api.transfer.dto.PayTransferCreateReqDTO;
import cn.iocoder.yudao.module.pay.service.transfer.PayTransferService;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RestController;
import javax.annotation.Resource;
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
/**
* 转账单 API 实现类
*
* @author jason
*/
@RestController // 提供 RESTful API 接口,给 Feign 调用
@Validated
public class PayTransferApiImpl implements PayTransferApi {
@Resource
private PayTransferService payTransferService;
@Override
public CommonResult<Long> createTransfer(PayTransferCreateReqDTO reqDTO) {
return success(payTransferService.createTransfer(reqDTO));
}
}

View File

@@ -0,0 +1,33 @@
package cn.iocoder.yudao.module.pay.controller.admin.demo;
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.module.pay.controller.admin.demo.vo.transfer.PayDemoTransferCreateReqVO;
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 javax.annotation.Resource;
import javax.validation.Valid;
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
import static cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils.getLoginUserId;
@Tag(name = "管理后台 - 示例转账单")
@RestController
@RequestMapping("/pay/demo-transfer")
@Validated
public class PayDemoTransferController {
@Resource
private PayDemoTransferService demoTransferService;
@PostMapping("/create")
@Operation(summary = "创建示例转账订单")
public CommonResult<Long> createDemoOrder(@Valid @RequestBody PayDemoTransferCreateReqVO createReqVO) {
return success(demoTransferService.createDemoTransfer(getLoginUserId(), createReqVO));
}
}

View File

@@ -0,0 +1,34 @@
package cn.iocoder.yudao.module.pay.controller.admin.demo.vo.transfer;
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 lombok.Data;
import javax.validation.constraints.Min;
import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;
import java.util.Map;
/**
* @author jason
*/
@Schema(description = "管理后台 - 示例转账单创建 Request VO")
@Data
public class PayDemoTransferCreateReqVO {
@Schema(description = "转账类型", requiredMode = Schema.RequiredMode.REQUIRED, example = "1")
@NotNull(message = "转账类型不能为空")
@InEnum(PayTransferTypeEnum.class)
private Integer type;
@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;
}

View File

@@ -5,13 +5,16 @@ import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils;
import cn.iocoder.yudao.framework.operatelog.core.annotations.OperateLog;
import cn.iocoder.yudao.framework.pay.core.enums.channel.PayChannelEnum;
import cn.iocoder.yudao.module.pay.controller.admin.order.vo.*;
import cn.iocoder.yudao.module.pay.convert.order.PayOrderConvert;
import cn.iocoder.yudao.module.pay.dal.dataobject.app.PayAppDO;
import cn.iocoder.yudao.module.pay.dal.dataobject.order.PayOrderDO;
import cn.iocoder.yudao.module.pay.dal.dataobject.order.PayOrderExtensionDO;
import cn.iocoder.yudao.module.pay.framework.pay.core.WalletPayClient;
import cn.iocoder.yudao.module.pay.service.app.PayAppService;
import cn.iocoder.yudao.module.pay.service.order.PayOrderService;
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;
@@ -26,11 +29,14 @@ import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Objects;
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.operatelog.core.enums.OperateTypeEnum.EXPORT;
import static cn.iocoder.yudao.framework.web.core.util.WebFrameworkUtils.getLoginUserId;
import static cn.iocoder.yudao.framework.web.core.util.WebFrameworkUtils.getLoginUserType;
@Tag(name = "管理后台 - 支付订单")
@RestController
@@ -70,6 +76,16 @@ public class PayOrderController {
@PostMapping("/submit")
@Operation(summary = "提交支付订单")
public CommonResult<PayOrderSubmitRespVO> submitPayOrder(@RequestBody PayOrderSubmitReqVO reqVO) {
// 1. 钱包支付事,需要额外传 user_id 和 user_type
if (Objects.equals(reqVO.getChannelCode(), PayChannelEnum.WALLET.getCode())) {
Map<String, String> channelExtras = reqVO.getChannelExtras() == null ?
Maps.newHashMapWithExpectedSize(2) : reqVO.getChannelExtras();
channelExtras.put(WalletPayClient.USER_ID_KEY, String.valueOf(getLoginUserId()));
channelExtras.put(WalletPayClient.USER_TYPE_KEY, String.valueOf(getLoginUserType()));
reqVO.setChannelExtras(channelExtras);
}
// 2. 提交支付
PayOrderSubmitRespVO respVO = orderService.submitOrder(reqVO, getClientIP());
return success(respVO);
}
@@ -93,7 +109,7 @@ public class PayOrderController {
@PreAuthorize("@ss.hasPermission('pay:order:export')")
@OperateLog(type = 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", "数据",

View File

@@ -13,16 +13,16 @@ import java.time.LocalDateTime;
@ToString(callSuper = true)
public class PayOrderDetailsRespVO extends PayOrderBaseVO {
@Schema(description = "支付订单编号", required = true, example = "1024")
@Schema(description = "支付订单编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024")
private Long id;
@Schema(description = "应用名称", requiredMode = Schema.RequiredMode.REQUIRED, example = "芋道源码")
private String appName;
@Schema(description = "创建时间", required = true)
@Schema(description = "创建时间", requiredMode = Schema.RequiredMode.REQUIRED)
private LocalDateTime createTime;
@Schema(description = "更新时间", required = true)
@Schema(description = "更新时间", requiredMode = Schema.RequiredMode.REQUIRED)
private LocalDateTime updateTime;
/**
@@ -34,7 +34,7 @@ public class PayOrderDetailsRespVO extends PayOrderBaseVO {
@Schema(description = "支付订单扩展")
public static class PayOrderExtension {
@Schema(description = "支付订单号", required = true, example = "1024")
@Schema(description = "支付订单号", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024")
private String no;
@Schema(description = "支付异步通知的内容")

View File

@@ -0,0 +1,38 @@
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.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 javax.annotation.Resource;
import javax.validation.Valid;
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
import static cn.iocoder.yudao.framework.common.util.servlet.ServletUtils.getClientIP;
@Tag(name = "管理后台 - 转账单")
@RestController
@RequestMapping("/pay/transfer")
@Validated
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);
}
}

View File

@@ -0,0 +1,25 @@
package cn.iocoder.yudao.module.pay.controller.admin.transfer.vo;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import javax.validation.constraints.NotEmpty;
import javax.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;
}

View File

@@ -0,0 +1,13 @@
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")
@Data
public class PayTransferSubmitRespVO {
@Schema(description = "转账状态", requiredMode = Schema.RequiredMode.REQUIRED, example = "1") // 参见 PayTransferStatusEnum 枚举
private Integer status;
}

View File

@@ -0,0 +1,76 @@
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;
import cn.iocoder.yudao.module.pay.convert.wallet.PayWalletConvert;
import cn.iocoder.yudao.module.pay.dal.dataobject.wallet.PayWalletDO;
import cn.iocoder.yudao.module.pay.service.wallet.PayWalletService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.springframework.security.access.prepost.PreAuthorize;
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 javax.annotation.Resource;
import javax.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
@RequestMapping("/pay/wallet")
@Validated
@Slf4j
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));
}
@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));
}
}

View File

@@ -0,0 +1,61 @@
package cn.iocoder.yudao.module.pay.controller.admin.wallet;
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.framework.operatelog.core.annotations.OperateLog;
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.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 javax.annotation.Resource;
import javax.annotation.security.PermitAll;
import javax.validation.Valid;
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
import static cn.iocoder.yudao.framework.common.util.servlet.ServletUtils.getClientIP;
@Tag(name = "管理后台 - 钱包充值")
@RestController
@RequestMapping("/pay/wallet-recharge")
@Validated
@Slf4j
public class PayWalletRechargeController {
@Resource
private PayWalletRechargeService walletRechargeService;
@PostMapping("/update-paid")
@Operation(summary = "更新钱包充值为已充值") // 由 pay-module 支付服务,进行回调,可见 PayNotifyJob
@PermitAll // 无需登录, 内部校验实现
@OperateLog(enable = false) // 禁用操作日志,因为没有操作人
public CommonResult<Boolean> updateWalletRechargerPaid(@Valid @RequestBody PayOrderNotifyReqDTO notifyReqDTO) {
walletRechargeService.updateWalletRechargerPaid(Long.valueOf(notifyReqDTO.getMerchantOrderId()),
notifyReqDTO.getPayOrderId());
return success(true);
}
// TODO @jason发起退款要 post 操作哈;
@GetMapping("/refund")
@Operation(summary = "发起钱包充值退款")
@Parameter(name = "id", description = "编号", required = true, example = "1024")
public CommonResult<Boolean> refundWalletRecharge(@RequestParam("id") Long id) {
walletRechargeService.refundWalletRecharge(id, getClientIP());
return success(true);
}
@PostMapping("/update-refunded")
@Operation(summary = "更新钱包充值为已退款") // 由 pay-module 支付服务,进行回调,可见 PayNotifyJob
@PermitAll // 无需登录, 内部校验实现
@OperateLog(enable = false) // 禁用操作日志,因为没有操作人
public CommonResult<Boolean> updateWalletRechargeRefunded(@RequestBody PayRefundNotifyReqDTO notifyReqDTO) {
walletRechargeService.updateWalletRechargeRefunded(
Long.valueOf(notifyReqDTO.getMerchantOrderId()), notifyReqDTO.getPayRefundId());
return success(true);
}
}

View File

@@ -0,0 +1,75 @@
package cn.iocoder.yudao.module.pay.controller.admin.wallet;
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
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.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.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 org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import javax.validation.Valid;
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
@Tag(name = "管理后台 - 钱包充值套餐")
@RestController
@RequestMapping("/pay/wallet-recharge-package")
@Validated
public class PayWalletRechargePackageController {
@Resource
private PayWalletRechargePackageService walletRechargePackageService;
@PostMapping("/create")
@Operation(summary = "创建钱包充值套餐")
@PreAuthorize("@ss.hasPermission('pay:wallet-recharge-package:create')")
public CommonResult<Long> createWalletRechargePackage(@Valid @RequestBody WalletRechargePackageCreateReqVO createReqVO) {
return success(walletRechargePackageService.createWalletRechargePackage(createReqVO));
}
@PutMapping("/update")
@Operation(summary = "更新钱包充值套餐")
@PreAuthorize("@ss.hasPermission('pay:wallet-recharge-package:update')")
public CommonResult<Boolean> updateWalletRechargePackage(@Valid @RequestBody WalletRechargePackageUpdateReqVO updateReqVO) {
walletRechargePackageService.updateWalletRechargePackage(updateReqVO);
return success(true);
}
@DeleteMapping("/delete")
@Operation(summary = "删除钱包充值套餐")
@Parameter(name = "id", description = "编号", required = true)
@PreAuthorize("@ss.hasPermission('pay:wallet-recharge-package:delete')")
public CommonResult<Boolean> deleteWalletRechargePackage(@RequestParam("id") Long id) {
walletRechargePackageService.deleteWalletRechargePackage(id);
return success(true);
}
@GetMapping("/get")
@Operation(summary = "获得钱包充值套餐")
@Parameter(name = "id", description = "编号", required = true, example = "1024")
@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));
}
@GetMapping("/page")
@Operation(summary = "获得钱包充值套餐分页")
@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));
}
}

View File

@@ -0,0 +1,43 @@
package cn.iocoder.yudao.module.pay.controller.admin.wallet;
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.module.pay.controller.admin.wallet.vo.transaction.PayWalletTransactionPageReqVO;
import cn.iocoder.yudao.module.pay.controller.admin.wallet.vo.transaction.PayWalletTransactionRespVO;
import cn.iocoder.yudao.module.pay.convert.wallet.PayWalletTransactionConvert;
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 lombok.extern.slf4j.Slf4j;
import org.springframework.security.access.prepost.PreAuthorize;
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 javax.annotation.Resource;
import javax.validation.Valid;
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
@Tag(name = "管理后台 - 钱包余额明细")
@RestController
@RequestMapping("/pay/wallet-transaction")
@Validated
@Slf4j
public class PayWalletTransactionController {
@Resource
private PayWalletTransactionService payWalletTransactionService;
@GetMapping("/page")
@Operation(summary = "获得钱包流水分页")
@PreAuthorize("@ss.hasPermission('pay:wallet:query')")
public CommonResult<PageResult<PayWalletTransactionRespVO>> getWalletTransactionPage(
@Valid PayWalletTransactionPageReqVO pageReqVO) {
PageResult<PayWalletTransactionDO> result = payWalletTransactionService.getWalletTransactionPage(pageReqVO);
return success(PayWalletTransactionConvert.INSTANCE.convertPage2(result));
}
}

View File

@@ -0,0 +1,31 @@
package cn.iocoder.yudao.module.pay.controller.admin.wallet.vo.rechargepackage;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import javax.validation.constraints.NotNull;
/**
* 充值套餐 Base VO提供给添加、修改、详细的子 VO 使用
* 如果子 VO 存在差异的字段,请不要添加到这里,影响 Swagger 文档生成
*/
@Data
public class WalletRechargePackageBaseVO {
@Schema(description = "套餐名", requiredMode = Schema.RequiredMode.REQUIRED, example = "李四")
@NotNull(message = "套餐名不能为空")
private String name;
@Schema(description = "支付金额", requiredMode = Schema.RequiredMode.REQUIRED, example = "16454")
@NotNull(message = "支付金额不能为空")
private Integer payPrice;
@Schema(description = "赠送金额", requiredMode = Schema.RequiredMode.REQUIRED, example = "20887")
@NotNull(message = "赠送金额不能为空")
private Integer bonusPrice;
@Schema(description = "状态", requiredMode = Schema.RequiredMode.REQUIRED, example = "2")
@NotNull(message = "状态不能为空")
private Byte status;
}

View File

@@ -0,0 +1,14 @@
package cn.iocoder.yudao.module.pay.controller.admin.wallet.vo.rechargepackage;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.ToString;
@Schema(description = "管理后台 - 充值套餐创建 Request VO")
@Data
@EqualsAndHashCode(callSuper = true)
@ToString(callSuper = true)
public class WalletRechargePackageCreateReqVO extends WalletRechargePackageBaseVO {
}

View File

@@ -0,0 +1,30 @@
package cn.iocoder.yudao.module.pay.controller.admin.wallet.vo.rechargepackage;
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 WalletRechargePackagePageReqVO extends PageParam {
@Schema(description = "套餐名", example = "李四")
private String name;
@Schema(description = "状态", example = "2")
private Integer status;
@Schema(description = "创建时间")
@DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND)
private LocalDateTime[] createTime;
}

View File

@@ -0,0 +1,22 @@
package cn.iocoder.yudao.module.pay.controller.admin.wallet.vo.rechargepackage;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.ToString;
import java.time.LocalDateTime;
@Schema(description = "管理后台 - 充值套餐 Response VO")
@Data
@EqualsAndHashCode(callSuper = true)
@ToString(callSuper = true)
public class WalletRechargePackageRespVO extends WalletRechargePackageBaseVO {
@Schema(description = "编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "9032")
private Long id;
@Schema(description = "创建时间", requiredMode = Schema.RequiredMode.REQUIRED)
private LocalDateTime createTime;
}

View File

@@ -0,0 +1,20 @@
package cn.iocoder.yudao.module.pay.controller.admin.wallet.vo.rechargepackage;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.ToString;
import javax.validation.constraints.NotNull;
@Schema(description = "管理后台 - 充值套餐更新 Request VO")
@Data
@EqualsAndHashCode(callSuper = true)
@ToString(callSuper = true)
public class WalletRechargePackageUpdateReqVO extends WalletRechargePackageBaseVO {
@Schema(description = "编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "9032")
@NotNull(message = "编号不能为空")
private Long id;
}

View File

@@ -0,0 +1,14 @@
package cn.iocoder.yudao.module.pay.controller.admin.wallet.vo.transaction;
import cn.iocoder.yudao.framework.common.pojo.PageParam;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
@Schema(description = "管理后台 - 钱包流水分页 Request VO")
@Data
public class PayWalletTransactionPageReqVO extends PageParam {
@Schema(description = "钱包编号", example = "1")
private Long walletId;
}

View File

@@ -0,0 +1,35 @@
package cn.iocoder.yudao.module.pay.controller.admin.wallet.vo.transaction;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import java.time.LocalDateTime;
@Schema(description = "用户 APP - 钱包流水分页 Response VO")
@Data
public class PayWalletTransactionRespVO {
@Schema(description = "编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "1")
private Long id;
@Schema(description = "钱包编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "5")
private Long walletId;
@Schema(description = "业务分类", requiredMode = Schema.RequiredMode.REQUIRED, example = "1")
private Integer bizType;
@Schema(description = "交易金额,单位分", requiredMode = Schema.RequiredMode.REQUIRED, example = "100")
private Long price;
@Schema(description = "流水标题", requiredMode = Schema.RequiredMode.REQUIRED, example = "土豆土豆")
private String title;
@Schema(description = "交易后的余额,单位分", requiredMode = Schema.RequiredMode.REQUIRED, example = "100")
private Long balance;
@Schema(description = "交易时间", requiredMode = Schema.RequiredMode.REQUIRED)
private LocalDateTime createTime;
// TODO @jasonmerchantOrderId 字段,需要在 PayWalletTransaction 存储下;然后,前端也返回下这个字段,界面也展示下商户名
}

View File

@@ -0,0 +1,39 @@
package cn.iocoder.yudao.module.pay.controller.admin.wallet.vo.wallet;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import javax.validation.constraints.NotNull;
/**
* 用户钱包 Base VO提供给添加、修改、详细的子 VO 使用
* 如果子 VO 存在差异的字段,请不要添加到这里,影响 Swagger 文档生成
*/
@Data
public class PayWalletBaseVO {
@Schema(description = "用户编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "20020")
@NotNull(message = "用户编号不能为空")
private Long userId;
@Schema(description = "用户类型", requiredMode = Schema.RequiredMode.REQUIRED, example = "1")
@NotNull(message = "用户类型不能为空")
private Integer userType;
@Schema(description = "余额,单位分", requiredMode = Schema.RequiredMode.REQUIRED)
@NotNull(message = "余额,单位分不能为空")
private Integer balance;
@Schema(description = "累计支出,单位分", requiredMode = Schema.RequiredMode.REQUIRED)
@NotNull(message = "累计支出,单位分不能为空")
private Integer totalExpense;
@Schema(description = "累计充值,单位分", requiredMode = Schema.RequiredMode.REQUIRED)
@NotNull(message = "累计充值,单位分不能为空")
private Integer totalRecharge;
@Schema(description = "冻结金额,单位分", requiredMode = Schema.RequiredMode.REQUIRED, example = "20737")
@NotNull(message = "冻结金额,单位分不能为空")
private Integer freezePrice;
}

View File

@@ -0,0 +1,31 @@
package cn.iocoder.yudao.module.pay.controller.admin.wallet.vo.wallet;
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 java.util.Collection;
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 PayWalletPageReqVO extends PageParam {
@Schema(description = "用户昵称", example = "李四")
private String nickname;
@Schema(description = "用户编号", example = "[1,2]")
private Collection<Long> userIds;
@Schema(description = "创建时间")
@DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND)
private LocalDateTime[] createTime;
}

View File

@@ -0,0 +1,27 @@
package cn.iocoder.yudao.module.pay.controller.admin.wallet.vo.wallet;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.ToString;
import java.time.LocalDateTime;
@Schema(description = "管理后台 - 用户钱包 Response VO")
@Data
@EqualsAndHashCode(callSuper = true)
@ToString(callSuper = true)
public class PayWalletRespVO extends PayWalletBaseVO {
@Schema(description = "编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "29528")
private Long id;
@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;
}

View File

@@ -0,0 +1,16 @@
package cn.iocoder.yudao.module.pay.controller.admin.wallet.vo.wallet;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import javax.validation.constraints.NotNull;
@Schema(description = "管理后台 - 用户钱包明细 Request VO")
@Data
public class PayWalletUserReqVO {
@Schema(description = "用户编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "1")
@NotNull(message = "用户编号不能为空")
private Long userId;
}

View File

@@ -1,12 +1,15 @@
package cn.iocoder.yudao.module.pay.controller.app.order;
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.framework.pay.core.enums.channel.PayChannelEnum;
import cn.iocoder.yudao.module.pay.controller.admin.order.vo.PayOrderRespVO;
import cn.iocoder.yudao.module.pay.controller.admin.order.vo.PayOrderSubmitRespVO;
import cn.iocoder.yudao.module.pay.controller.app.order.vo.AppPayOrderSubmitReqVO;
import cn.iocoder.yudao.module.pay.controller.app.order.vo.AppPayOrderSubmitRespVO;
import cn.iocoder.yudao.module.pay.convert.order.PayOrderConvert;
import cn.iocoder.yudao.module.pay.framework.pay.core.WalletPayClient;
import cn.iocoder.yudao.module.pay.service.order.PayOrderService;
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;
@@ -16,8 +19,13 @@ import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import java.util.Map;
import java.util.Objects;
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
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;
@Tag(name = "用户 APP - 支付订单")
@RestController
@@ -40,6 +48,16 @@ public class AppPayOrderController {
@PostMapping("/submit")
@Operation(summary = "提交支付订单")
public CommonResult<AppPayOrderSubmitRespVO> submitPayOrder(@RequestBody AppPayOrderSubmitReqVO reqVO) {
// 1. 钱包支付事,需要额外传 user_id 和 user_type
if (Objects.equals(reqVO.getChannelCode(), PayChannelEnum.WALLET.getCode())) {
Map<String, String> channelExtras = reqVO.getChannelExtras() == null ?
Maps.newHashMapWithExpectedSize(2) : reqVO.getChannelExtras();
channelExtras.put(WalletPayClient.USER_ID_KEY, String.valueOf(getLoginUserId()));
channelExtras.put(WalletPayClient.USER_TYPE_KEY, String.valueOf(getLoginUserType()));
reqVO.setChannelExtras(channelExtras);
}
// 2. 提交支付
PayOrderSubmitRespVO respVO = payOrderService.submitOrder(reqVO, getClientIP());
return success(PayOrderConvert.INSTANCE.convert3(respVO));
}

View File

@@ -0,0 +1,44 @@
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.security.core.annotations.PreAuthenticated;
import cn.iocoder.yudao.module.pay.controller.app.wallet.vo.wallet.AppPayWalletRespVO;
import cn.iocoder.yudao.module.pay.convert.wallet.PayWalletConvert;
import cn.iocoder.yudao.module.pay.dal.dataobject.wallet.PayWalletDO;
import cn.iocoder.yudao.module.pay.service.wallet.PayWalletService;
import 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.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import javax.annotation.Resource;
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
import static cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils.getLoginUserId;
/**
* @author jason
*/
@Tag(name = "用户 APP - 钱包")
@RestController
@RequestMapping("/pay/wallet")
@Validated
@Slf4j
public class AppPayWalletController {
@Resource
private PayWalletService payWalletService;
@GetMapping("/get")
@Operation(summary = "获取钱包")
@PreAuthenticated
public CommonResult<AppPayWalletRespVO> getPayWallet() {
PayWalletDO wallet = payWalletService.getOrCreateWallet(getLoginUserId(), UserTypeEnum.MEMBER.getValue());
return success(PayWalletConvert.INSTANCE.convert(wallet));
}
}

View File

@@ -0,0 +1,45 @@
package cn.iocoder.yudao.module.pay.controller.app.wallet;
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
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.convert.wallet.PayWalletRechargeConvert;
import cn.iocoder.yudao.module.pay.dal.dataobject.wallet.PayWalletRechargeDO;
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 javax.annotation.Resource;
import javax.validation.Valid;
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
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;
@Tag(name = "用户 APP - 钱包充值")
@RestController
@RequestMapping("/pay/wallet-recharge")
@Validated
@Slf4j
public class AppPayWalletRechargeController {
@Resource
private PayWalletRechargeService walletRechargeService;
@PostMapping("/create")
@Operation(summary = "创建钱包充值记录(发起充值)")
public CommonResult<AppPayWalletRechargeCreateRespVO> createWalletRecharge(
@Valid @RequestBody AppPayWalletRechargeCreateReqVO reqVO) {
PayWalletRechargeDO walletRecharge = walletRechargeService.createWalletRecharge(
getLoginUserId(), getLoginUserType(), getClientIP(), reqVO);
return success(PayWalletRechargeConvert.INSTANCE.convert(walletRecharge));
}
}

View File

@@ -0,0 +1,35 @@
package cn.iocoder.yudao.module.pay.controller.app.wallet;
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.module.pay.controller.app.wallet.vo.recharge.AppPayWalletPackageRespVO;
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.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.util.ArrayList;
import java.util.List;
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
@Tag(name = "用户 APP - 钱包充值套餐")
@RestController
@RequestMapping("/pay/wallet-recharge-package")
@Validated
@Slf4j
public class AppPayWalletRechargePackageController {
@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);
}
}

View File

@@ -0,0 +1,52 @@
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.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.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 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 javax.annotation.Resource;
import javax.validation.Valid;
import java.time.LocalDateTime;
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
import static cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils.getLoginUserId;
@Tag(name = "用户 APP - 钱包余额明细")
@RestController
@RequestMapping("/pay/wallet-transaction")
@Validated
@Slf4j
public class AppPayWalletTransactionController {
@Resource
private PayWalletTransactionService payWalletTransactionService;
@GetMapping("/page")
@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));
}
}

View File

@@ -0,0 +1,20 @@
package cn.iocoder.yudao.module.pay.controller.app.wallet.vo.recharge;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
@Schema(description = "用户 APP - 用户充值套餐 Response VO")
@Data
public class AppPayWalletPackageRespVO {
@Schema(description = "编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024")
private Long id;
@Schema(description = "套餐名", requiredMode = Schema.RequiredMode.REQUIRED, example = "小套餐")
private String name;
@Schema(description = "支付金额", requiredMode = Schema.RequiredMode.REQUIRED, example = "10")
private Integer payPrice;
@Schema(description = "赠送金额", requiredMode = Schema.RequiredMode.REQUIRED, example = "20")
private Integer bonusPrice;
}

View File

@@ -0,0 +1,25 @@
package cn.iocoder.yudao.module.pay.controller.app.wallet.vo.recharge;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import javax.validation.constraints.AssertTrue;
import javax.validation.constraints.Min;
import java.util.Objects;
@Schema(description = "用户 APP - 创建钱包充值 Request VO")
@Data
public class AppPayWalletRechargeCreateReqVO {
@Schema(description = "支付金额", example = "1000")
@Min(value = 1, message = "支付金额必须大于零")
private Integer payPrice;
@Schema(description = "充值套餐编号", example = "1024")
private Long packageId;
@AssertTrue(message = "充值金额和充钱套餐不能同时为空")
public boolean validatePayPriceAndPackageId() {
return Objects.nonNull(payPrice) || Objects.nonNull(packageId);
}
}

View File

@@ -0,0 +1,16 @@
package cn.iocoder.yudao.module.pay.controller.app.wallet.vo.recharge;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
@Schema(description = "用户 APP - 创建钱包充值 Resp VO")
@Data
public class AppPayWalletRechargeCreateRespVO {
@Schema(description = "钱包充值编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "1")
private Long id;
@Schema(description = "支付订单编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "100")
private Long payOrderId;
}

View File

@@ -0,0 +1,23 @@
package cn.iocoder.yudao.module.pay.controller.app.wallet.vo.transaction;
import cn.iocoder.yudao.framework.common.pojo.PageParam;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
@Schema(description = "用户 APP - 钱包流水分页 Request VO")
@Data
public class AppPayWalletTransactionPageReqVO extends PageParam {
/**
* 类型 - 收入
*/
public static final Integer TYPE_INCOME = 1;
/**
* 类型 - 支出
*/
public static final Integer TYPE_EXPENSE = 2;
@Schema(description = "类型", example = "1")
private Integer type;
}

View File

@@ -0,0 +1,24 @@
package cn.iocoder.yudao.module.pay.controller.app.wallet.vo.transaction;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import java.time.LocalDateTime;
@Schema(description = "用户 APP - 钱包流水分页 Response VO")
@Data
public class AppPayWalletTransactionRespVO {
@Schema(description = "业务分类", requiredMode = Schema.RequiredMode.REQUIRED, example = "1")
private Integer bizType;
@Schema(description = "交易金额,单位分", requiredMode = Schema.RequiredMode.REQUIRED, example = "100")
private Long price;
@Schema(description = "流水标题", requiredMode = Schema.RequiredMode.REQUIRED, example = "土豆土豆")
private String title;
@Schema(description = "交易时间", requiredMode = Schema.RequiredMode.REQUIRED)
private LocalDateTime createTime;
}

View File

@@ -0,0 +1,19 @@
package cn.iocoder.yudao.module.pay.controller.app.wallet.vo.wallet;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
@Schema(description = "用户 APP - 用户钱包 Response VO")
@Data
public class AppPayWalletRespVO {
@Schema(description = "钱包余额,单位分", requiredMode = Schema.RequiredMode.REQUIRED, example = "100")
private Integer balance;
@Schema(description = "累计支出, 单位分", requiredMode = Schema.RequiredMode.REQUIRED, example = "1000")
private Integer totalExpense;
@Schema(description = "累计充值, 单位分", requiredMode = Schema.RequiredMode.REQUIRED, example = "2000")
private Integer totalRecharge;
}

View File

@@ -0,0 +1,20 @@
package cn.iocoder.yudao.module.pay.convert.transfer;
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.dal.dataobject.transfer.PayTransferDO;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import org.mapstruct.factory.Mappers;
@Mapper
public interface PayTransferConvert {
PayTransferConvert INSTANCE = Mappers.getMapper(PayTransferConvert.class);
@Mapping(source = "title", target = "subject") // TODO @jason是不是都改成 subject 完事呀?
PayTransferDO convert(PayTransferCreateReqDTO dto);
PayTransferCreateReqDTO convert(PayDemoTransferCreateReqVO vo);
}

View File

@@ -0,0 +1,36 @@
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 {
PayWalletConvert INSTANCE = Mappers.getMapper(PayWalletConvert.class);
AppPayWalletRespVO convert(PayWalletDO bean);
PayWalletRespVO convert02(String nickname,String avatar, 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;
}
}

View File

@@ -0,0 +1,19 @@
package cn.iocoder.yudao.module.pay.convert.wallet;
import cn.iocoder.yudao.module.pay.controller.app.wallet.vo.recharge.AppPayWalletRechargeCreateRespVO;
import cn.iocoder.yudao.module.pay.dal.dataobject.wallet.PayWalletRechargeDO;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import org.mapstruct.factory.Mappers;
@Mapper
public interface PayWalletRechargeConvert {
PayWalletRechargeConvert INSTANCE = Mappers.getMapper(PayWalletRechargeConvert.class);
@Mapping(target = "totalPrice", expression = "java( payPrice + bonusPrice)")
PayWalletRechargeDO convert(Long walletId, Integer payPrice, Integer bonusPrice, Long packageId);
AppPayWalletRechargeCreateRespVO convert(PayWalletRechargeDO bean);
}

View File

@@ -0,0 +1,22 @@
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;
import org.mapstruct.factory.Mappers;
@Mapper
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);
}

View File

@@ -0,0 +1,28 @@
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.rechargepackage.WalletRechargePackageCreateReqVO;
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.dal.dataobject.wallet.PayWalletRechargePackageDO;
import org.mapstruct.Mapper;
import org.mapstruct.factory.Mappers;
import java.util.List;
@Mapper
public interface WalletRechargePackageConvert {
WalletRechargePackageConvert INSTANCE = Mappers.getMapper(WalletRechargePackageConvert.class);
PayWalletRechargePackageDO convert(WalletRechargePackageCreateReqVO bean);
PayWalletRechargePackageDO convert(WalletRechargePackageUpdateReqVO bean);
WalletRechargePackageRespVO convert(PayWalletRechargePackageDO bean);
List<WalletRechargePackageRespVO> convertList(List<PayWalletRechargePackageDO> list);
PageResult<WalletRechargePackageRespVO> convertPage(PageResult<PayWalletRechargePackageDO> page);
}

View File

@@ -0,0 +1,72 @@
package cn.iocoder.yudao.module.pay.dal.dataobject.demo;
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.time.LocalDateTime;
import java.util.Map;
/**
* 示例转账订单
*
* 演示业务系统的转账业务
*/
@TableName(value ="pay_demo_transfer", autoResultMap = true)
@KeySequence("pay_demo_transfer_seq") // 用于 Oracle、PostgreSQL、Kingbase、DB2、H2 数据库的主键自增。如果是 MySQL 等数据库,可不写。
@Data
public class PayDemoTransferDO extends BaseDO {
/**
* 订单编号
*/
@TableId
private Long id;
/**
* 用户编号
*/
private Long userId;
/**
* 转账金额,单位:分
*/
private Integer price;
/**
* 转账类型
*/
private Integer type;
// TODO @jason要不字段还是弄成正确的平铺开
/**
* 收款人信息,不同类型和渠道不同
*/
@TableField(typeHandler = JacksonTypeHandler.class)
private Map<String, String> payeeInfo;
/**
* 转账状态
*/
private Integer transferStatus;
/**
* 转账订单编号
*/
private Long payTransferId;
/**
* 转账支付成功渠道
*/
private String payChannelCode;
/**
* 转账支付时间
*/
private LocalDateTime transferTime;
}

View File

@@ -1,49 +0,0 @@
package cn.iocoder.yudao.module.pay.dal.dataobject.member;
import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO;
import com.baomidou.mybatisplus.annotation.KeySequence;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import lombok.Data;
// TODO @jason修改 MemberWalletDO 为 PayWalletDO
/**
* 支付 - 会员钱包 DO
*
* @author jason
*/
@TableName(value ="pay_member_wallet")
@KeySequence("pay_member_wallet_seq") // 用于 Oracle、PostgreSQL、Kingbase、DB2、H2 数据库的主键自增。如果是 MySQL 等数据库,可不写。
@Data
public class MemberWalletDO extends BaseDO {
/**
* 编号
*/
@TableId
private Long id;
// TODO @jaosn增加 userType 字段;
/**
* 用户 id
*
* 关联 MemberUserDO 的 id 编号
* 关联 AdminUserDO 的 id 编号
*/
private Long userId;
/**
* 余额, 单位分
*/
private Integer balance;
/**
* 累计支出, 单位分
*/
private Integer totalSpending;
/**
* 累计充值, 单位分
*/
private Integer totalTopUp;
}

View File

@@ -1,86 +0,0 @@
package cn.iocoder.yudao.module.pay.dal.dataobject.member;
import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO;
import cn.iocoder.yudao.module.pay.enums.member.WalletOperateTypeEnum;
import cn.iocoder.yudao.module.pay.enums.member.WalletTransactionGategoryEnum;
import com.baomidou.mybatisplus.annotation.KeySequence;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import lombok.Data;
import java.time.LocalDateTime;
/**
* 支付-会员钱包明细 DO
*
* @author jason
*/
@TableName(value ="pay_member_wallet_transaction")
@KeySequence("pay_member_wallet_transaction_seq") // 用于 Oracle、PostgreSQL、Kingbase、DB2、H2 数据库的主键自增。如果是 MySQL 等数据库,可不写。
@Data
public class MemberWalletTransactionDO extends BaseDO {
/**
* 编号
*/
@TableId
private Long id;
/**
* 会员钱包 id
*
* 关联 {@link MemberWalletDO#getId()}
*/
private Long walletId;
/**
* 用户 id
*
* 关联 MemberUserDO 的 id 编号
*/
private Long userId;
/**
* 交易单号 @芋艿 这里是关联交易单号, 还是订单号 , 退款单号! ??
*/
private String tradeNo;
/**
* 交易分类
*
* 枚举 {@link WalletTransactionGategoryEnum#getCategory()}
*/
private Integer category;
/**
* 操作分类
*
* 枚举 {@link WalletOperateTypeEnum#getType()}
*/
private Integer operateType;
/**
* 操作详情
*/
private String operateDesc;
/**
* 交易金额, 单位分
*/
private Integer price;
/**
* 余额, 单位分
*/
private Integer balance;
/**
* 备注
*/
private String mark;
/**
* 交易时间
*/
private LocalDateTime transactionTime;
}

View File

@@ -0,0 +1,106 @@
package cn.iocoder.yudao.module.pay.dal.dataobject.transfer;
import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO;
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.module.pay.dal.dataobject.app.PayAppDO;
import cn.iocoder.yudao.module.pay.dal.dataobject.channel.PayChannelDO;
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;
/**
* 转账单 DO
*
* @author jason
*/
@TableName(value ="pay_transfer", autoResultMap = true)
@KeySequence("pay_transfer_seq") // 用于 Oracle、PostgreSQL、Kingbase、DB2、H2 数据库的主键自增。如果是 MySQL 等数据库,可不写。
@Data
public class PayTransferDO extends BaseDO {
/**
* 编号
*/
@TableId
private Long id;
/**
* 应用编号
*
* 关联 {@link PayAppDO#getId()}
*/
private Long appId;
/**
* 转账渠道编号
*
* 关联 {@link PayChannelDO#getId()}
*/
private Long channelId;
/**
* 转账渠道编码
*
* 枚举 {@link PayChannelEnum}
*/
private String channelCode;
/**
* 类型
*
* 枚举 {@link PayTransferTypeEnum}
*/
private Integer type;
// ========== 商户相关字段 ==========
/**
* 商户订单编号
*
* 例如说,内部系统 A 的订单号,需要保证每个 PayAppDO 唯一
*/
private String merchantOrderId;
/**
* 转账标题
*/
private String subject;
// ========== 转账相关字段 ==========
/**
* 转账金额,单位:分
*/
private Integer price;
/**
* 转账状态
*
* 枚举 {@link PayTransferStatusRespEnum}
*/
private Integer status;
/**
* 订单转账成功时间
*/
private LocalDateTime successTime;
/**
* 转账成功的转账拓展单编号
*
* 关联 {@link PayTransferExtensionDO#getId()}
*/
private Long extensionId;
/**
* 转账成功的转账拓展单号
*
* 关联 {@link PayTransferExtensionDO#getNo()}
*/
private String no;
/**
* 收款人信息,不同类型和渠道不同
*/
@TableField(typeHandler = JacksonTypeHandler.class)
private Map<String, String> payeeInfo;
}

View File

@@ -0,0 +1,68 @@
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;
}

View File

@@ -0,0 +1,59 @@
package cn.iocoder.yudao.module.pay.dal.dataobject.wallet;
import cn.iocoder.yudao.framework.common.enums.UserTypeEnum;
import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO;
import com.baomidou.mybatisplus.annotation.KeySequence;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import lombok.Data;
/**
* 会员钱包 DO
*
* @author jason
*/
@TableName(value ="pay_wallet")
@KeySequence("pay_wallet_seq") // 用于 Oracle、PostgreSQL、Kingbase、DB2、H2 数据库的主键自增。如果是 MySQL 等数据库,可不写。
@Data
public class PayWalletDO extends BaseDO {
/**
* 编号
*/
@TableId
private Long id;
/**
* 用户 id
*
* 关联 MemberUserDO 的 id 编号
* 关联 AdminUserDO 的 id 编号
*/
private Long userId;
/**
* 用户类型, 预留 多商户转帐可能需要用到
*
* 关联 {@link UserTypeEnum}
*/
private Integer userType;
/**
* 余额,单位分
*/
private Integer balance;
/**
* 冻结金额,单位分
*/
private Integer freezePrice;
/**
* 累计支出,单位分
*/
private Integer totalExpense;
/**
* 累计充值,单位分
*/
private Integer totalRecharge;
}

View File

@@ -0,0 +1,116 @@
package cn.iocoder.yudao.module.pay.dal.dataobject.wallet;
import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO;
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.enums.refund.PayRefundStatusEnum;
import com.baomidou.mybatisplus.annotation.KeySequence;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import lombok.Data;
import java.time.LocalDateTime;
/**
* 会员钱包充值
*/
@TableName(value ="pay_wallet_recharge")
@KeySequence("pay_wallet_recharge_seq") // 用于 Oracle、PostgreSQL、Kingbase、DB2、H2 数据库的主键自增。如果是 MySQL 等数据库,可不写。
@Data
public class PayWalletRechargeDO extends BaseDO {
/**
* 编号
*/
@TableId
private Long id;
/**
* 钱包编号
*
* 关联 {@link PayWalletDO#getId()}
*/
private Long walletId;
/**
* 用户实际到账余额
*
* 例如充 100 送 20则该值是 120
*/
private Integer totalPrice;
/**
* 实际支付金额
*/
private Integer payPrice;
/**
* 钱包赠送金额
*/
private Integer bonusPrice;
/**
* 充值套餐编号
*
* 关联 {@link PayWalletRechargeDO#getPackageId()} 字段
*/
private Long packageId;
/**
* 是否已支付
*
* true - 已支付
* false - 未支付
*/
private Boolean payStatus;
/**
* 支付订单编号
*
* 关联 {@link PayOrderDO#getId()}
*/
private Long payOrderId;
/**
* 支付成功的支付渠道
*
* 冗余 {@link PayOrderDO#getChannelCode()}
*/
private String payChannelCode;
/**
* 订单支付时间
*/
private LocalDateTime payTime;
/**
* 支付退款单编号
*
* 关联 {@link PayRefundDO#getId()}
*/
private Long payRefundId;
/**
* 退款金额,包含赠送金额
*/
private Integer refundTotalPrice;
/**
* 退款支付金额
*/
private Integer refundPayPrice;
/**
* 退款钱包赠送金额
*/
private Integer refundBonusPrice;
/**
* 退款时间
*/
private LocalDateTime refundTime;
/**
* 退款状态
*
* 枚举 {@link PayRefundStatusEnum}
*/
private Integer refundStatus;
}

View File

@@ -0,0 +1,47 @@
package cn.iocoder.yudao.module.pay.dal.dataobject.wallet;
import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO;
import com.baomidou.mybatisplus.annotation.KeySequence;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import lombok.Data;
/**
* 会员钱包充值套餐 DO
*
* 通过充值套餐时,可以赠送一定金额;
*
* @author 芋道源码
*/
@TableName(value ="pay_wallet_recharge_package")
@KeySequence("pay_wallet_recharge_package_seq") // 用于 Oracle、PostgreSQL、Kingbase、DB2、H2 数据库的主键自增。如果是 MySQL 等数据库,可不写。
@Data
public class PayWalletRechargePackageDO extends BaseDO {
/**
* 编号
*/
@TableId
private Long id;
/**
* 套餐名
*/
private String name;
/**
* 支付金额
*/
private Integer payPrice;
/**
* 赠送金额
*/
private Integer bonusPrice;
/**
* 状态
*
* 枚举 {@link cn.iocoder.yudao.framework.common.enums.CommonStatusEnum}
*/
private Integer status;
}

View File

@@ -0,0 +1,66 @@
package cn.iocoder.yudao.module.pay.dal.dataobject.wallet;
import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO;
import cn.iocoder.yudao.module.pay.enums.wallet.PayWalletBizTypeEnum;
import com.baomidou.mybatisplus.annotation.KeySequence;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import lombok.Data;
/**
* 会员钱包流水 DO
*
* @author jason
*/
@TableName(value ="pay_wallet_transaction")
@KeySequence("pay_wallet_transaction_seq") // 用于 Oracle、PostgreSQL、Kingbase、DB2、H2 数据库的主键自增。如果是 MySQL 等数据库,可不写。
@Data
public class PayWalletTransactionDO extends BaseDO {
/**
* 编号
*/
@TableId
private Long id;
/**
* 流水号
*/
private String no;
/**
* 钱包编号
*
* 关联 {@link PayWalletDO#getId()}
*/
private Long walletId;
/**
* 关联业务分类
*
* 枚举 {@link PayWalletBizTypeEnum#getType()}
*/
private Integer bizType;
/**
* 关联业务编号
*/
private String bizId;
/**
* 流水说明
*/
private String title;
/**
* 交易金额,单位分
*
* 正值表示余额增加,负值表示余额减少
*/
private Integer price;
/**
* 交易后余额,单位分
*/
private Integer balance;
}

View File

@@ -0,0 +1,10 @@
package cn.iocoder.yudao.module.pay.dal.mysql.demo;
import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
import cn.iocoder.yudao.module.pay.dal.dataobject.demo.PayDemoTransferDO;
import org.apache.ibatis.annotations.Mapper;
@Mapper
public interface PayDemoTransferMapper extends BaseMapperX<PayDemoTransferDO> {
}

View File

@@ -1,15 +0,0 @@
package cn.iocoder.yudao.module.pay.dal.mysql.member;
import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
import cn.iocoder.yudao.module.pay.dal.dataobject.member.MemberWalletDO;
import org.apache.ibatis.annotations.Mapper;
@Mapper
public interface MemberWalletMapper extends BaseMapperX<MemberWalletDO> {
}

View File

@@ -1,15 +0,0 @@
package cn.iocoder.yudao.module.pay.dal.mysql.member;
import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
import cn.iocoder.yudao.module.pay.dal.dataobject.member.MemberWalletTransactionDO;
import org.apache.ibatis.annotations.Mapper;
@Mapper
public interface MemberWalletTransactionMapper extends BaseMapperX<MemberWalletTransactionDO> {
}

View File

@@ -0,0 +1,26 @@
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));
}
}

View File

@@ -0,0 +1,22 @@
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.PayTransferDO;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import org.apache.ibatis.annotations.Mapper;
import java.util.List;
@Mapper
public interface PayTransferMapper extends BaseMapperX<PayTransferDO> {
default int updateByIdAndStatus(Long id, List<Integer> status, PayTransferDO updateObj) {
return update(updateObj, new LambdaQueryWrapper<PayTransferDO>()
.eq(PayTransferDO::getId, id).in(PayTransferDO::getStatus, status));
}
}

View File

@@ -0,0 +1,122 @@
package cn.iocoder.yudao.module.pay.dal.mysql.wallet;
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.wallet.vo.wallet.PayWalletPageReqVO;
import cn.iocoder.yudao.module.pay.dal.dataobject.wallet.PayWalletDO;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import org.apache.ibatis.annotations.Mapper;
@Mapper
public interface PayWalletMapper extends BaseMapperX<PayWalletDO> {
default PayWalletDO selectByUserIdAndType(Long userId, Integer userType) {
return selectOne(PayWalletDO::getUserId, userId,
PayWalletDO::getUserType, userType);
}
default PageResult<PayWalletDO> selectPage(Integer userType, PayWalletPageReqVO reqVO) {
return selectPage(reqVO, new LambdaQueryWrapperX<PayWalletDO>()
.inIfPresent(PayWalletDO::getUserId, reqVO.getUserIds())
.eqIfPresent(PayWalletDO::getUserType, userType)
.betweenIfPresent(PayWalletDO::getCreateTime, reqVO.getCreateTime())
.orderByDesc(PayWalletDO::getId));
}
/**
* 当消费退款时候, 更新钱包
*
* @param id 钱包 id
* @param price 消费金额
*/
default int updateWhenConsumptionRefund(Long id, Integer price){
LambdaUpdateWrapper<PayWalletDO> lambdaUpdateWrapper = new LambdaUpdateWrapper<PayWalletDO>()
.setSql(" balance = balance + " + price
+ ", total_expense = total_expense - " + price)
.eq(PayWalletDO::getId, id);
return update(null, lambdaUpdateWrapper);
}
/**
* 当消费时候, 更新钱包
*
* @param price 消费金额
* @param id 钱包 id
*/
default int updateWhenConsumption(Long id, Integer price){
LambdaUpdateWrapper<PayWalletDO> lambdaUpdateWrapper = new LambdaUpdateWrapper<PayWalletDO>()
.setSql(" balance = balance - " + price
+ ", total_expense = total_expense + " + price)
.eq(PayWalletDO::getId, id)
.ge(PayWalletDO::getBalance, price); // cas 逻辑
return update(null, lambdaUpdateWrapper);
}
/**
* 当充值的时候,更新钱包
*
* @param id 钱包 id
* @param price 钱包金额
*/
default int updateWhenRecharge(Long id, Integer price){
LambdaUpdateWrapper<PayWalletDO> lambdaUpdateWrapper = new LambdaUpdateWrapper<PayWalletDO>()
.setSql(" balance = balance + " + price
+ ", total_recharge = total_recharge + " + price)
.eq(PayWalletDO::getId, id);
return update(null, lambdaUpdateWrapper);
}
/**
* 冻结钱包部分余额
*
* @param id 钱包 id
* @param price 冻结金额
*/
default int freezePrice(Long id, Integer price){
LambdaUpdateWrapper<PayWalletDO> lambdaUpdateWrapper = new LambdaUpdateWrapper<PayWalletDO>()
.setSql(" balance = balance - " + price
+ ", freeze_price = freeze_price + " + price)
.eq(PayWalletDO::getId, id)
.ge(PayWalletDO::getBalance, price); // cas 逻辑
return update(null, lambdaUpdateWrapper);
}
/**
* 解冻钱包余额
*
* @param id 钱包 id
* @param price 解冻金额
*/
default int unFreezePrice(Long id, Integer price){
LambdaUpdateWrapper<PayWalletDO> lambdaUpdateWrapper = new LambdaUpdateWrapper<PayWalletDO>()
.setSql(" balance = balance + " + price
+ ", freeze_price = freeze_price - " + price)
.eq(PayWalletDO::getId, id)
.ge(PayWalletDO::getFreezePrice, price); // cas 逻辑
return update(null, lambdaUpdateWrapper);
}
/**
* 当充值退款时, 更新钱包
*
* @param id 钱包 id
* @param price 退款金额
*/
default int updateWhenRechargeRefund(Long id, Integer price){
LambdaUpdateWrapper<PayWalletDO> lambdaUpdateWrapper = new LambdaUpdateWrapper<PayWalletDO>()
.setSql(" freeze_price = freeze_price - " + price
+ ", total_recharge = total_recharge - " + price)
.eq(PayWalletDO::getId, id)
.ge(PayWalletDO::getFreezePrice, price)
.ge(PayWalletDO::getTotalRecharge, price);// cas 逻辑
return update(null, lambdaUpdateWrapper);
}
}

View File

@@ -0,0 +1,21 @@
package cn.iocoder.yudao.module.pay.dal.mysql.wallet;
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;
import org.apache.ibatis.annotations.Mapper;
@Mapper
public interface PayWalletRechargeMapper extends BaseMapperX<PayWalletRechargeDO> {
default int updateByIdAndPaid(Long id, boolean wherePayStatus, PayWalletRechargeDO updateObj) {
return update(updateObj, new LambdaQueryWrapperX<PayWalletRechargeDO>()
.eq(PayWalletRechargeDO::getId, id).eq(PayWalletRechargeDO::getPayStatus, wherePayStatus));
}
default int updateByIdAndRefunded(Long id, Integer whereRefundStatus, PayWalletRechargeDO updateObj) {
return update(updateObj, new LambdaQueryWrapperX<PayWalletRechargeDO>()
.eq(PayWalletRechargeDO::getId, id).eq(PayWalletRechargeDO::getRefundStatus, whereRefundStatus));
}
}

View File

@@ -0,0 +1,27 @@
package cn.iocoder.yudao.module.pay.dal.mysql.wallet;
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.wallet.vo.rechargepackage.WalletRechargePackagePageReqVO;
import cn.iocoder.yudao.module.pay.dal.dataobject.wallet.PayWalletRechargePackageDO;
import org.apache.ibatis.annotations.Mapper;
@Mapper
public interface PayWalletRechargePackageMapper extends BaseMapperX<PayWalletRechargePackageDO> {
default PageResult<PayWalletRechargePackageDO> selectPage(WalletRechargePackagePageReqVO reqVO) {
return selectPage(reqVO, new LambdaQueryWrapperX<PayWalletRechargePackageDO>()
.likeIfPresent(PayWalletRechargePackageDO::getName, reqVO.getName())
.eqIfPresent(PayWalletRechargePackageDO::getStatus, reqVO.getStatus())
.betweenIfPresent(PayWalletRechargePackageDO::getCreateTime, reqVO.getCreateTime())
.orderByDesc(PayWalletRechargePackageDO::getPayPrice));
}
// TODO @jason这里要有空格哈String name) {
default PayWalletRechargePackageDO selectByName(String name){
return selectOne(PayWalletRechargePackageDO::getName, name);
}
}

View File

@@ -0,0 +1,43 @@
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.controller.app.wallet.vo.transaction.AppPayWalletTransactionPageReqVO;
import cn.iocoder.yudao.module.pay.dal.dataobject.wallet.PayWalletTransactionDO;
import org.apache.ibatis.annotations.Mapper;
import java.util.Objects;
@Mapper
public interface PayWalletTransactionMapper extends BaseMapperX<PayWalletTransactionDO> {
default PageResult<PayWalletTransactionDO> selectPage(Long walletId, Integer type,
PageParam pageParam) {
LambdaQueryWrapperX<PayWalletTransactionDO> query = new LambdaQueryWrapperX<PayWalletTransactionDO>()
.eqIfPresent(PayWalletTransactionDO::getWalletId, walletId);
if (Objects.equals(type, AppPayWalletTransactionPageReqVO.TYPE_INCOME)) {
query.gt(PayWalletTransactionDO::getPrice, 0);
} else if (Objects.equals(type, AppPayWalletTransactionPageReqVO.TYPE_EXPENSE)) {
query.lt(PayWalletTransactionDO::getPrice, 0);
}
query.orderByDesc(PayWalletTransactionDO::getId);
return selectPage(pageParam, query);
}
default PayWalletTransactionDO selectByNo(String no) {
return selectOne(PayWalletTransactionDO::getNo, no);
}
default PayWalletTransactionDO selectByBiz(String bizId, Integer bizType) {
return selectOne(PayWalletTransactionDO::getBizId, bizId,
PayWalletTransactionDO::getBizType, bizType);
}
}

View File

@@ -22,6 +22,6 @@ public interface RedisKeyConstants {
* KEY 格式pay_no:{prefix}
* VALUE 数据格式:编号自增
*/
String PAY_NO = "pay_no";
String PAY_NO = "pay_no:";
}

View File

@@ -1,9 +1,13 @@
package cn.iocoder.yudao.module.pay.dal.redis.no;
import cn.hutool.core.date.DatePattern;import cn.hutool.core.date.DateUtil;import org.springframework.data.redis.core.StringRedisTemplate;
import cn.hutool.core.date.DatePattern;import cn.hutool.core.date.DateUtil;
import cn.iocoder.yudao.module.pay.dal.redis.RedisKeyConstants;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Repository;
import javax.annotation.Resource;import java.time.LocalDateTime;
import javax.annotation.Resource;
import java.time.Duration;
import java.time.LocalDateTime;
/**
* 支付序号的 Redis DAO
@@ -23,8 +27,12 @@ public class PayNoRedisDAO {
* @return 序号
*/
public String generate(String prefix) {
// 递增序号
String noPrefix = prefix + DateUtil.format(LocalDateTime.now(), DatePattern.PURE_DATETIME_PATTERN);
Long no = stringRedisTemplate.opsForValue().increment(noPrefix);
String key = RedisKeyConstants.PAY_NO + noPrefix;
Long no = stringRedisTemplate.opsForValue().increment(key);
// 设置过期时间
stringRedisTemplate.expire(key, Duration.ofMinutes(1L));
return noPrefix + no;
}

View File

@@ -0,0 +1,184 @@
package cn.iocoder.yudao.module.pay.framework.pay.core;
import cn.hutool.core.lang.Assert;
import cn.hutool.core.map.MapUtil;
import cn.hutool.extra.spring.SpringUtil;
import cn.iocoder.yudao.framework.common.exception.ServiceException;
import cn.iocoder.yudao.framework.pay.core.client.dto.order.PayOrderRespDTO;
import cn.iocoder.yudao.framework.pay.core.client.dto.order.PayOrderUnifiedReqDTO;
import cn.iocoder.yudao.framework.pay.core.client.dto.refund.PayRefundRespDTO;
import cn.iocoder.yudao.framework.pay.core.client.dto.refund.PayRefundUnifiedReqDTO;
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.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.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;
import cn.iocoder.yudao.module.pay.enums.wallet.PayWalletBizTypeEnum;
import cn.iocoder.yudao.module.pay.enums.order.PayOrderStatusEnum;
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.PayWalletService;
import cn.iocoder.yudao.module.pay.service.wallet.PayWalletTransactionService;
import lombok.extern.slf4j.Slf4j;
import java.util.Map;
import static cn.iocoder.yudao.framework.common.exception.enums.GlobalErrorCodeConstants.INTERNAL_SERVER_ERROR;
import static cn.iocoder.yudao.module.pay.enums.ErrorCodeConstants.PAY_ORDER_EXTENSION_NOT_FOUND;
import static cn.iocoder.yudao.module.pay.enums.ErrorCodeConstants.REFUND_NOT_FOUND;
/**
* 钱包支付的 PayClient 实现类
*
* @author jason
*/
@Slf4j
public class WalletPayClient extends AbstractPayClient<NonePayClientConfig> {
public static final String USER_ID_KEY = "user_id";
public static final String USER_TYPE_KEY = "user_type";
private PayWalletService wallService;
private PayWalletTransactionService walletTransactionService;
private PayOrderService orderService;
private PayRefundService refundService;
public WalletPayClient(Long channelId, NonePayClientConfig config) {
super(channelId, PayChannelEnum.WALLET.getCode(), config);
}
@Override
protected void doInit() {
if (wallService == null) {
wallService = SpringUtil.getBean(PayWalletService.class);
}
if (walletTransactionService == null) {
walletTransactionService = SpringUtil.getBean(PayWalletTransactionService.class);
}
}
@Override
protected PayOrderRespDTO doUnifiedOrder(PayOrderUnifiedReqDTO reqDTO) {
try {
Long userId = MapUtil.getLong(reqDTO.getChannelExtras(), USER_ID_KEY);
Integer userType = MapUtil.getInt(reqDTO.getChannelExtras(), USER_TYPE_KEY);
Assert.notNull(userId, "用户 id 不能为空");
Assert.notNull(userType, "用户类型不能为空");
PayWalletTransactionDO transaction = wallService.orderPay(userId, userType, reqDTO.getOutTradeNo(),
reqDTO.getPrice());
return PayOrderRespDTO.successOf(transaction.getNo(), transaction.getCreator(),
transaction.getCreateTime(),
reqDTO.getOutTradeNo(), transaction);
} catch (Throwable ex) {
log.error("[doUnifiedOrder] 失败", ex);
Integer errorCode = INTERNAL_SERVER_ERROR.getCode();
String errorMsg = INTERNAL_SERVER_ERROR.getMsg();
if (ex instanceof ServiceException) {
ServiceException serviceException = (ServiceException) ex;
errorCode = serviceException.getCode();
errorMsg = serviceException.getMessage();
}
return PayOrderRespDTO.closedOf(String.valueOf(errorCode), errorMsg,
reqDTO.getOutTradeNo(), "");
}
}
@Override
protected PayOrderRespDTO doParseOrderNotify(Map<String, String> params, String body) {
throw new UnsupportedOperationException("钱包支付无支付回调");
}
@Override
protected PayOrderRespDTO doGetOrder(String outTradeNo) {
if (orderService == null) {
orderService = SpringUtil.getBean(PayOrderService.class);
}
PayOrderExtensionDO orderExtension = orderService.getOrderExtensionByNo(outTradeNo);
// 支付交易拓展单不存在, 返回关闭状态
if (orderExtension == null) {
return PayOrderRespDTO.closedOf(String.valueOf(PAY_ORDER_EXTENSION_NOT_FOUND.getCode()),
PAY_ORDER_EXTENSION_NOT_FOUND.getMsg(), outTradeNo, "");
}
// 关闭状态
if (PayOrderStatusEnum.isClosed(orderExtension.getStatus())) {
return PayOrderRespDTO.closedOf(orderExtension.getChannelErrorCode(),
orderExtension.getChannelErrorMsg(), outTradeNo, "");
}
// 成功状态
if (PayOrderStatusEnum.isSuccess(orderExtension.getStatus())) {
PayWalletTransactionDO walletTransaction = walletTransactionService.getWalletTransaction(
String.valueOf(orderExtension.getOrderId()), PayWalletBizTypeEnum.PAYMENT);
Assert.notNull(walletTransaction, "支付单 {} 钱包流水不能为空", outTradeNo);
return PayOrderRespDTO.successOf(walletTransaction.getNo(), walletTransaction.getCreator(),
walletTransaction.getCreateTime(), outTradeNo, walletTransaction);
}
// 其它状态为无效状态
log.error("[doGetOrder] 支付单 {} 的状态不正确", outTradeNo);
throw new IllegalStateException(String.format("支付单[%s] 状态不正确", outTradeNo));
}
@Override
protected PayRefundRespDTO doUnifiedRefund(PayRefundUnifiedReqDTO reqDTO) {
try {
PayWalletTransactionDO payWalletTransaction = wallService.orderRefund(reqDTO.getOutRefundNo(),
reqDTO.getRefundPrice(), reqDTO.getReason());
return PayRefundRespDTO.successOf(payWalletTransaction.getNo(), payWalletTransaction.getCreateTime(),
reqDTO.getOutRefundNo(), payWalletTransaction);
} catch (Throwable ex) {
log.error("[doUnifiedRefund] 失败", ex);
Integer errorCode = INTERNAL_SERVER_ERROR.getCode();
String errorMsg = INTERNAL_SERVER_ERROR.getMsg();
if (ex instanceof ServiceException) {
ServiceException serviceException = (ServiceException) ex;
errorCode = serviceException.getCode();
errorMsg = serviceException.getMessage();
}
return PayRefundRespDTO.failureOf(String.valueOf(errorCode), errorMsg,
reqDTO.getOutRefundNo(), "");
}
}
@Override
protected PayRefundRespDTO doParseRefundNotify(Map<String, String> params, String body) {
throw new UnsupportedOperationException("钱包支付无退款回调");
}
@Override
protected PayRefundRespDTO doGetRefund(String outTradeNo, String outRefundNo) {
if (refundService == null) {
refundService = SpringUtil.getBean(PayRefundService.class);
}
PayRefundDO payRefund = refundService.getRefundByNo(outRefundNo);
// 支付退款单不存在, 返回退款失败状态
if (payRefund == null) {
return PayRefundRespDTO.failureOf(String.valueOf(REFUND_NOT_FOUND), REFUND_NOT_FOUND.getMsg(),
outRefundNo, "");
}
// 退款失败
if (PayRefundStatusRespEnum.isFailure(payRefund.getStatus())) {
return PayRefundRespDTO.failureOf(payRefund.getChannelErrorCode(), payRefund.getChannelErrorMsg(),
outRefundNo, "");
}
// 退款成功
if (PayRefundStatusRespEnum.isSuccess(payRefund.getStatus())) {
PayWalletTransactionDO walletTransaction = walletTransactionService.getWalletTransaction(
String.valueOf(payRefund.getId()), PayWalletBizTypeEnum.PAYMENT_REFUND);
Assert.notNull(walletTransaction, "支付退款单 {} 钱包流水不能为空", outRefundNo);
return PayRefundRespDTO.successOf(walletTransaction.getNo(), walletTransaction.getCreateTime(),
outRefundNo, walletTransaction);
}
// 其它状态为无效状态
log.error("[doGetRefund] 支付退款单 {} 的状态不正确", outRefundNo);
throw new IllegalStateException(String.format("支付退款单[%s] 状态不正确", outRefundNo));
}
@Override
public PayTransferRespDTO doUnifiedTransfer(PayTransferUnifiedReqDTO reqDTO) {
throw new UnsupportedOperationException("待实现");
}
}

View File

@@ -1,4 +0,0 @@
/**
* 占位,无实际作用
*/
package cn.iocoder.yudao.module.pay.framework.pay.core;

View File

@@ -0,0 +1,10 @@
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 {
}

View File

@@ -0,0 +1,4 @@
/**
* 占位
*/
package cn.iocoder.yudao.module.pay.framework.rpc;

View File

@@ -1,7 +1,7 @@
package cn.iocoder.yudao.module.pay.framework.security.config;
import cn.iocoder.yudao.framework.security.config.AuthorizeRequestsCustomizer;
import cn.iocoder.yudao.module.system.enums.ApiConstants;
import cn.iocoder.yudao.module.pay.enums.ApiConstants;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;

View File

@@ -13,6 +13,7 @@ import cn.iocoder.yudao.module.pay.controller.admin.channel.vo.PayChannelUpdateR
import cn.iocoder.yudao.module.pay.convert.channel.PayChannelConvert;
import cn.iocoder.yudao.module.pay.dal.dataobject.channel.PayChannelDO;
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 lombok.Getter;
@@ -20,6 +21,7 @@ import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.validation.annotation.Validated;
import javax.annotation.PostConstruct;
import javax.annotation.Resource;
import javax.validation.Validator;
import java.time.Duration;
@@ -68,6 +70,14 @@ public class PayChannelServiceImpl implements PayChannelService {
@Resource
private Validator validator;
/**
* 初始化,为了注册钱包
*/
@PostConstruct
public void init() {
payClientFactory.registerPayClientClass(PayChannelEnum.WALLET, WalletPayClient.class);
}
@Override
public Long createChannel(PayChannelCreateReqVO reqVO) {
// 断言是否有重复的

View File

@@ -25,7 +25,7 @@ import java.util.HashMap;
import java.util.Map;
import java.util.Objects;
import static cn.hutool.core.util.ObjectUtil.*;
import static cn.hutool.core.util.ObjectUtil.notEqual;
import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
import static cn.iocoder.yudao.framework.common.util.date.LocalDateTimeUtils.addTime;
import static cn.iocoder.yudao.framework.common.util.json.JsonUtils.toJsonString;
@@ -91,7 +91,7 @@ public class PayDemoOrderServiceImpl implements PayDemoOrderService {
.setAppId(PAY_APP_ID).setUserIp(getClientIP()) // 支付应用
.setMerchantOrderId(demoOrder.getId().toString()) // 业务的订单编号
.setSubject(spuName).setBody("").setPrice(price) // 价格信息
.setExpireTime(addTime(Duration.ofHours(2L)))); // 支付的过期时间
.setExpireTime(addTime(Duration.ofHours(2L)))).getCheckedData(); // 支付的过期时间
// 2.2 更新支付单到 demo 订单
payDemoOrderMapper.updateById(new PayDemoOrderDO().setId(demoOrder.getId())
.setPayOrderId(payOrderId));
@@ -153,10 +153,10 @@ public class PayDemoOrderServiceImpl implements PayDemoOrderService {
}
// 2.1 校验支付单是否存在
PayOrderRespDTO payOrder = payOrderApi.getOrder(payOrderId);
PayOrderRespDTO payOrder = payOrderApi.getOrder(payOrderId).getCheckedData();
if (payOrder == null) {
log.error("[validateDemoOrderCanPaid][order({}) payOrder({}) 不存在,请进行处理!]", id, payOrderId);
throw exception(ORDER_NOT_FOUND);
throw exception(PAY_ORDER_NOT_FOUND);
}
// 2.2 校验支付单已支付
if (!PayOrderStatusEnum.isSuccess(payOrder.getStatus())) {
@@ -193,7 +193,7 @@ public class PayDemoOrderServiceImpl implements PayDemoOrderService {
.setAppId(PAY_APP_ID).setUserIp(getClientIP()) // 支付应用
.setMerchantOrderId(String.valueOf(order.getId())) // 支付单号
.setMerchantRefundId(refundId)
.setReason("想退钱").setPrice(order.getPrice()));// 价格信息
.setReason("想退钱").setPrice(order.getPrice())).getCheckedData();// 价格信息
// 2.3 更新退款单到 demo 订单
payDemoOrderMapper.updateById(new PayDemoOrderDO().setId(id)
.setPayRefundId(payRefundId).setRefundPrice(order.getPrice()));
@@ -239,7 +239,7 @@ public class PayDemoOrderServiceImpl implements PayDemoOrderService {
}
// 2.1 校验退款订单
PayRefundRespDTO payRefund = payRefundApi.getRefund(payRefundId);
PayRefundRespDTO payRefund = payRefundApi.getRefund(payRefundId).getCheckedData();
if (payRefund == null) {
throw exception(DEMO_ORDER_REFUND_FAIL_REFUND_NOT_FOUND);
}

View File

@@ -0,0 +1,22 @@
package cn.iocoder.yudao.module.pay.service.demo;
import cn.iocoder.yudao.module.pay.controller.admin.demo.vo.transfer.PayDemoTransferCreateReqVO;
import javax.validation.Valid;
/**
* 示例转账业务 Service 接口
*
* @author jason
*/
public interface PayDemoTransferService {
/**
* 创建转账单
*
* @param userId 用户编号
* @param createReqVO 创建信息
* @return 编号
*/
Long createDemoTransfer(Long userId, @Valid PayDemoTransferCreateReqVO createReqVO);
}

View File

@@ -0,0 +1,89 @@
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.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.dal.dataobject.demo.PayDemoTransferDO;
import cn.iocoder.yudao.module.pay.dal.mysql.demo.PayDemoTransferMapper;
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 javax.annotation.Resource;
import javax.validation.Valid;
import java.util.Map;
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.transfer.PayTransferStatusEnum.WAITING;
/**
* 示例转账业务 Service 实现类
*
* @author jason
*/
@Service
@Validated
public class PayDemoTransferServiceImpl implements PayDemoTransferService {
/**
* 接入的实力应用编号
* 从 [支付管理 -> 应用信息] 里添加
*/
private static final Long TRANSFER_APP_ID = 8L;
@Resource
private PayDemoTransferMapper demoTransferMapper;
@Resource
private PayTransferService transferService;
@Override
@Transactional(rollbackFor = Exception.class)
public Long createDemoTransfer(Long userId, @Valid PayDemoTransferCreateReqVO vo) {
// 1 校验收款账号
validatePayeeInfo(vo.getType(), vo.getPayeeInfo());
// 2 保存示例转账业务表
PayDemoTransferDO demoTransfer = new PayDemoTransferDO().setUserId(userId).setType(vo.getType())
.setPrice(vo.getPrice()).setPayeeInfo(vo.getPayeeInfo())
.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("待实现");
}
}
}
}

View File

@@ -106,14 +106,6 @@ public interface PayOrderService {
*/
void updatePayOrderPrice(Long id, Integer payPrice);
/**
* 更新支付订单价格
*
* @param payOrderId 支付单编号
* @param payPrice 支付单价格
*/
void updatePayOrderPriceById(Long payOrderId, Integer payPrice);
/**
* 获得支付订单
*

View File

@@ -156,7 +156,7 @@ public class PayOrderServiceImpl implements PayOrderService {
getSelf().notifyOrder(channel, unifiedOrderResp);
// 如有渠道错误码,则抛出业务异常,提示用户
if (StrUtil.isNotEmpty(unifiedOrderResp.getChannelErrorCode())) {
throw exception(ORDER_SUBMIT_CHANNEL_ERROR, unifiedOrderResp.getChannelErrorCode(),
throw exception(PAY_ORDER_SUBMIT_CHANNEL_ERROR, unifiedOrderResp.getChannelErrorCode(),
unifiedOrderResp.getChannelErrorMsg());
}
// 此处需要读取最新的状态
@@ -168,16 +168,16 @@ public class PayOrderServiceImpl implements PayOrderService {
private PayOrderDO validateOrderCanSubmit(Long id) {
PayOrderDO order = orderMapper.selectById(id);
if (order == null) { // 是否存在
throw exception(ORDER_NOT_FOUND);
throw exception(PAY_ORDER_NOT_FOUND);
}
if (PayOrderStatusEnum.isSuccess(order.getStatus())) { // 校验状态,发现已支付
throw exception(ORDER_STATUS_IS_SUCCESS);
throw exception(PAY_ORDER_STATUS_IS_SUCCESS);
}
if (!PayOrderStatusEnum.WAITING.getStatus().equals(order.getStatus())) { // 校验状态,必须是待支付
throw exception(ORDER_STATUS_IS_NOT_WAITING);
throw exception(PAY_ORDER_STATUS_IS_NOT_WAITING);
}
if (LocalDateTimeUtils.beforeNow(order.getExpireTime())) { // 校验是否过期
throw exception(ORDER_IS_EXPIRED);
throw exception(PAY_ORDER_IS_EXPIRED);
}
// 【重要】校验是否支付拓展单已支付,只是没有回调、或者数据不正常
@@ -198,7 +198,7 @@ public class PayOrderServiceImpl implements PayOrderService {
if (PayOrderStatusEnum.isSuccess(orderExtension.getStatus())) {
log.warn("[validateOrderCanSubmit][order({}) 的 extension({}) 已支付,可能是数据不一致]",
id, orderExtension.getId());
throw exception(ORDER_EXTENSION_IS_PAID);
throw exception(PAY_ORDER_EXTENSION_IS_PAID);
}
// 情况二:调用三方接口,查询支付单状态,是不是已支付
PayClient payClient = channelService.getPayClient(orderExtension.getChannelId());
@@ -210,7 +210,7 @@ public class PayOrderServiceImpl implements PayOrderService {
if (respDTO != null && PayOrderStatusRespEnum.isSuccess(respDTO.getStatus())) {
log.warn("[validateOrderCanSubmit][order({}) 的 PayOrderRespDTO({}) 已支付,可能是回调延迟]",
id, toJsonString(respDTO));
throw exception(ORDER_EXTENSION_IS_PAID);
throw exception(PAY_ORDER_EXTENSION_IS_PAID);
}
});
}
@@ -250,9 +250,10 @@ public class PayOrderServiceImpl implements PayOrderService {
* 通知并更新订单的支付结果
*
* @param channel 支付渠道
* @param notify 通知
* @param notify 通知
*/
@Transactional(rollbackFor = Exception.class) // 注意,如果是方法内调用该方法,需要通过 getSelf().notifyPayOrder(channel, notify) 调用,否则事务不生效
@Transactional(rollbackFor = Exception.class)
// 注意,如果是方法内调用该方法,需要通过 getSelf().notifyPayOrder(channel, notify) 调用,否则事务不生效
public void notifyOrder(PayChannelDO channel, PayOrderRespDTO notify) {
// 情况一:支付成功的回调
if (PayOrderStatusRespEnum.isSuccess(notify.getStatus())) {
@@ -291,21 +292,21 @@ public class PayOrderServiceImpl implements PayOrderService {
// 1. 查询 PayOrderExtensionDO
PayOrderExtensionDO orderExtension = orderExtensionMapper.selectByNo(notify.getOutTradeNo());
if (orderExtension == null) {
throw exception(ORDER_EXTENSION_NOT_FOUND);
throw exception(PAY_ORDER_EXTENSION_NOT_FOUND);
}
if (PayOrderStatusEnum.isSuccess(orderExtension.getStatus())) { // 如果已经是成功,直接返回,不用重复更新
log.info("[updateOrderExtensionSuccess][orderExtension({}) 已经是已支付,无需更新]", orderExtension.getId());
return orderExtension;
}
if (ObjectUtil.notEqual(orderExtension.getStatus(), PayOrderStatusEnum.WAITING.getStatus())) { // 校验状态,必须是待支付
throw exception(ORDER_EXTENSION_STATUS_IS_NOT_WAITING);
throw exception(PAY_ORDER_EXTENSION_STATUS_IS_NOT_WAITING);
}
// 2. 更新 PayOrderExtensionDO
int updateCounts = orderExtensionMapper.updateByIdAndStatus(orderExtension.getId(), orderExtension.getStatus(),
PayOrderExtensionDO.builder().status(PayOrderStatusEnum.SUCCESS.getStatus()).channelNotifyData(toJsonString(notify)).build());
if (updateCounts == 0) { // 校验状态,必须是待支付
throw exception(ORDER_EXTENSION_STATUS_IS_NOT_WAITING);
throw exception(PAY_ORDER_EXTENSION_STATUS_IS_NOT_WAITING);
}
log.info("[updateOrderExtensionSuccess][orderExtension({}) 更新为已支付]", orderExtension.getId());
return orderExtension;
@@ -314,9 +315,9 @@ public class PayOrderServiceImpl implements PayOrderService {
/**
* 更新 PayOrderDO 支付成功
*
* @param channel 支付渠道
* @param channel 支付渠道
* @param orderExtension 支付拓展单
* @param notify 通知回调
* @param notify 通知回调
* @return 是否之前已经成功回调
*/
private Boolean updateOrderSuccess(PayChannelDO channel, PayOrderExtensionDO orderExtension,
@@ -324,7 +325,7 @@ public class PayOrderServiceImpl implements PayOrderService {
// 1. 判断 PayOrderDO 是否处于待支付
PayOrderDO order = orderMapper.selectById(orderExtension.getOrderId());
if (order == null) {
throw exception(ORDER_NOT_FOUND);
throw exception(PAY_ORDER_NOT_FOUND);
}
if (PayOrderStatusEnum.isSuccess(order.getStatus()) // 如果已经是成功,直接返回,不用重复更新
&& Objects.equals(order.getExtensionId(), orderExtension.getId())) {
@@ -332,7 +333,7 @@ public class PayOrderServiceImpl implements PayOrderService {
return true;
}
if (!PayOrderStatusEnum.WAITING.getStatus().equals(order.getStatus())) { // 校验状态,必须是待支付
throw exception(ORDER_STATUS_IS_NOT_WAITING);
throw exception(PAY_ORDER_STATUS_IS_NOT_WAITING);
}
// 2. 更新 PayOrderDO
@@ -345,7 +346,7 @@ public class PayOrderServiceImpl implements PayOrderService {
.channelFeePrice(MoneyUtils.calculateRatePrice(order.getPrice(), channel.getFeeRate()))
.build());
if (updateCounts == 0) { // 校验状态,必须是待支付
throw exception(ORDER_STATUS_IS_NOT_WAITING);
throw exception(PAY_ORDER_STATUS_IS_NOT_WAITING);
}
log.info("[updateOrderExtensionSuccess][order({}) 更新为已支付]", order.getId());
return false;
@@ -359,7 +360,7 @@ public class PayOrderServiceImpl implements PayOrderService {
// 1. 查询 PayOrderExtensionDO
PayOrderExtensionDO orderExtension = orderExtensionMapper.selectByNo(notify.getOutTradeNo());
if (orderExtension == null) {
throw exception(ORDER_EXTENSION_NOT_FOUND);
throw exception(PAY_ORDER_EXTENSION_NOT_FOUND);
}
if (PayOrderStatusEnum.isClosed(orderExtension.getStatus())) { // 如果已经是关闭,直接返回,不用重复更新
log.info("[updateOrderExtensionClosed][orderExtension({}) 已经是支付关闭,无需更新]", orderExtension.getId());
@@ -371,7 +372,7 @@ public class PayOrderServiceImpl implements PayOrderService {
return;
}
if (ObjectUtil.notEqual(orderExtension.getStatus(), PayOrderStatusEnum.WAITING.getStatus())) { // 校验状态,必须是待支付
throw exception(ORDER_EXTENSION_STATUS_IS_NOT_WAITING);
throw exception(PAY_ORDER_EXTENSION_STATUS_IS_NOT_WAITING);
}
// 2. 更新 PayOrderExtensionDO
@@ -379,7 +380,7 @@ public class PayOrderServiceImpl implements PayOrderService {
PayOrderExtensionDO.builder().status(PayOrderStatusEnum.CLOSED.getStatus()).channelNotifyData(toJsonString(notify))
.channelErrorCode(notify.getChannelErrorCode()).channelErrorMsg(notify.getChannelErrorMsg()).build());
if (updateCounts == 0) { // 校验状态,必须是待支付
throw exception(ORDER_EXTENSION_STATUS_IS_NOT_WAITING);
throw exception(PAY_ORDER_EXTENSION_STATUS_IS_NOT_WAITING);
}
log.info("[updateOrderExtensionClosed][orderExtension({}) 更新为支付关闭]", orderExtension.getId());
}
@@ -388,10 +389,10 @@ public class PayOrderServiceImpl implements PayOrderService {
public void updateOrderRefundPrice(Long id, Integer incrRefundPrice) {
PayOrderDO order = orderMapper.selectById(id);
if (order == null) {
throw exception(ORDER_NOT_FOUND);
throw exception(PAY_ORDER_NOT_FOUND);
}
if (!PayOrderStatusEnum.isSuccessOrRefund(order.getStatus())) {
throw exception(ORDER_REFUND_FAIL_STATUS_ERROR);
throw exception(PAY_ORDER_REFUND_FAIL_STATUS_ERROR);
}
if (order.getRefundPrice() + incrRefundPrice > order.getPrice()) {
throw exception(REFUND_PRICE_EXCEED);
@@ -403,7 +404,7 @@ public class PayOrderServiceImpl implements PayOrderService {
.setStatus(PayOrderStatusEnum.REFUND.getStatus());
int updateCount = orderMapper.updateByIdAndStatus(id, order.getStatus(), updateObj);
if (updateCount == 0) {
throw exception(ORDER_REFUND_FAIL_STATUS_ERROR);
throw exception(PAY_ORDER_REFUND_FAIL_STATUS_ERROR);
}
}
@@ -411,10 +412,10 @@ public class PayOrderServiceImpl implements PayOrderService {
public void updatePayOrderPrice(Long id, Integer payPrice) {
PayOrderDO order = orderMapper.selectById(id);
if (order == null) {
throw exception(ORDER_NOT_FOUND);
throw exception(PAY_ORDER_NOT_FOUND);
}
if (ObjectUtil.notEqual(PayOrderStatusEnum.WAITING.getStatus(), order.getStatus())) {
throw exception(ORDER_STATUS_IS_NOT_WAITING);
throw exception(PAY_ORDER_STATUS_IS_NOT_WAITING);
}
if (ObjectUtil.equal(order.getPrice(), payPrice)) {
return;
@@ -425,18 +426,6 @@ public class PayOrderServiceImpl implements PayOrderService {
orderMapper.updateById(order);
}
@Override
public void updatePayOrderPriceById(Long payOrderId, Integer payPrice) {
// TODO @puhui999不能直接这样修改哈应该只有未支付状态的订单才可以改另外如果价格如果没变可以直接 return 哈;
PayOrderDO order = orderMapper.selectById(payOrderId);
if (order == null) {
throw exception(ORDER_NOT_FOUND);
}
order.setPrice(payPrice);
orderMapper.updateById(order);
}
@Override
public PayOrderExtensionDO getOrderExtension(Long id) {
return orderExtensionMapper.selectById(id);

View File

@@ -156,11 +156,11 @@ public class PayRefundServiceImpl implements PayRefundService {
private PayOrderDO validatePayOrderCanRefund(PayRefundCreateReqDTO reqDTO) {
PayOrderDO order = orderService.getOrder(reqDTO.getAppId(), reqDTO.getMerchantOrderId());
if (order == null) {
throw exception(ORDER_NOT_FOUND);
throw exception(PAY_ORDER_NOT_FOUND);
}
// 校验状态,必须是已支付、或者已退款
if (!PayOrderStatusEnum.isSuccessOrRefund(order.getStatus())) {
throw exception(ORDER_REFUND_FAIL_STATUS_ERROR);
throw exception(PAY_ORDER_REFUND_FAIL_STATUS_ERROR);
}
// 校验金额,退款金额不能大于原定的金额

View File

@@ -0,0 +1,35 @@
package cn.iocoder.yudao.module.pay.service.transfer;
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 javax.validation.Valid;
/**
* 转账 Service 接口
*
* @author jason
*/
public interface PayTransferService {
/**
* 提交转账单
*
* 此时,会发起支付渠道的调用
*
* @param reqVO 请求
* @param userIp 用户 ip
* @return 渠道的返回结果
*/
PayTransferSubmitRespVO submitTransfer(@Valid PayTransferSubmitReqVO reqVO, String userIp);
/**
* 创建转账单
*
* @param reqDTO 创建请求
* @return 转账单编号
*/
Long createTransfer(@Valid PayTransferCreateReqDTO reqDTO);
}

View File

@@ -0,0 +1,271 @@
package cn.iocoder.yudao.module.pay.service.transfer;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.util.StrUtil;
import cn.hutool.extra.spring.SpringUtil;
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.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.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.transfer.PayTransferStatusEnum;
import cn.iocoder.yudao.module.pay.service.app.PayAppService;
import cn.iocoder.yudao.module.pay.service.channel.PayChannelService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import javax.annotation.Resource;
import java.util.Objects;
import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
import static cn.iocoder.yudao.module.pay.enums.ErrorCodeConstants.*;
import static cn.iocoder.yudao.module.pay.enums.transfer.PayTransferStatusEnum.*;
// TODO @jason等彻底实现完单测写写
/**
* 转账 Service 实现类
*
* @author jason
*/
@Service
@Slf4j
public class PayTransferServiceImpl implements PayTransferService {
private static final String TRANSFER_NO_PREFIX = "T";
@Resource
private PayTransferMapper transferMapper;
@Resource
private PayTransferExtensionMapper transferExtensionMapper;
@Resource
private PayAppService appService;
@Resource
private PayChannelService channelService;
@Resource
private PayNoRedisDAO noRedisDAO;
@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());
// 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);
// 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());
}
@Override
public Long createTransfer(PayTransferCreateReqDTO reqDTO) {
// 校验 App
appService.validPayApp(reqDTO.getAppId());
// 创建转账单
PayTransferDO transfer = PayTransferConvert.INSTANCE.convert(reqDTO)
.setStatus(WAITING.getStatus());
transferMapper.insert(transfer);
return transfer.getId();
}
@Transactional(rollbackFor = Exception.class)
// 注意,如果是方法内调用该方法,需要通过 getSelf().notifyTransfer(channel, notify) 调用,否则事务不生效
public void notifyTransfer(PayChannelDO channel, PayTransferRespDTO notify) {
// 转账成功的回调
if (PayTransferStatusRespEnum.isSuccess(notify.getStatus())) {
notifyTransferSuccess(channel, notify);
}
// 转账关闭的回调
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;
}
// 3. TODO 插入转账通知记录
}
private Boolean updateTransferSuccess(PayChannelDO channel, PayTransferExtensionDO transferExtension,
PayTransferRespDTO notify) {
// 1.校验
PayTransferDO transfer = transferMapper.selectById(transferExtension.getTransferId());
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 (!isPendingStatus(transfer.getStatus())) {
throw exception(PAY_TRANSFER_STATUS_IS_NOT_PENDING);
}
// 2.更新
int updateCounts = transferMapper.updateByIdAndStatus(transfer.getId(),
CollUtil.newArrayList(WAITING.getStatus(), IN_PROGRESS.getStatus()),
new PayTransferDO().setStatus(SUCCESS.getStatus()).setSuccessTime(notify.getSuccessTime())
.setChannelId(channel.getId()).setChannelCode(channel.getCode())
.setExtensionId(transferExtension.getId()).setNo(transferExtension.getNo()));
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;
}
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) { // 是否存在
throw exception(PAY_TRANSFER_NOT_FOUND);
}
if (PayTransferStatusEnum.isSuccess(transfer.getStatus())) {
throw exception(PAY_TRANSFER_STATUS_IS_SUCCESS);
}
if (!PayTransferStatusEnum.isWaiting(transfer.getStatus())) {
throw exception(PAY_TRANSFER_STATUS_IS_NOT_WAITING);
}
// TODO 查询拓展单是否未已转账和转账中
return transfer;
}
/**
* 获得自身的代理对象,解决 AOP 生效问题
*
* @return 自己
*/
private PayTransferServiceImpl getSelf() {
return SpringUtil.getBean(getClass());
}
}

View File

@@ -0,0 +1,61 @@
package cn.iocoder.yudao.module.pay.service.wallet;
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.dal.dataobject.wallet.PayWalletRechargePackageDO;
import javax.validation.Valid;
/**
* 钱包充值套餐 Service 接口
*
* @author jason
*/
public interface PayWalletRechargePackageService {
/**
* 获取钱包充值套餐
* @param packageId 充值套餐编号
*/
PayWalletRechargePackageDO getWalletRechargePackage(Long packageId);
/**
* 校验钱包充值套餐的有效性, 无效的话抛出 ServiceException 异常
*
* @param packageId 充值套餐编号
*/
PayWalletRechargePackageDO validWalletRechargePackage(Long packageId);
/**
* 创建充值套餐
*
* @param createReqVO 创建信息
* @return 编号
*/
Long createWalletRechargePackage(@Valid WalletRechargePackageCreateReqVO createReqVO);
/**
* 更新充值套餐
*
* @param updateReqVO 更新信息
*/
void updateWalletRechargePackage(@Valid WalletRechargePackageUpdateReqVO updateReqVO);
/**
* 删除充值套餐
*
* @param id 编号
*/
void deleteWalletRechargePackage(Long id);
/**
* 获得充值套餐分页
*
* @param pageReqVO 分页查询
* @return 充值套餐分页
*/
PageResult<PayWalletRechargePackageDO> getWalletRechargePackagePage(WalletRechargePackagePageReqVO pageReqVO);
}

View File

@@ -0,0 +1,106 @@
package cn.iocoder.yudao.module.pay.service.wallet;
import cn.hutool.core.util.StrUtil;
import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum;
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.dal.dataobject.wallet.PayWalletRechargePackageDO;
import cn.iocoder.yudao.module.pay.dal.mysql.wallet.PayWalletRechargePackageMapper;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
import static cn.iocoder.yudao.module.pay.enums.ErrorCodeConstants.*;
/**
* 钱包充值套餐 Service 实现类
*
* @author jason
*/
@Service
public class PayWalletRechargePackageServiceImpl implements PayWalletRechargePackageService {
@Resource
private PayWalletRechargePackageMapper walletRechargePackageMapper;
@Override
public PayWalletRechargePackageDO getWalletRechargePackage(Long packageId) {
return walletRechargePackageMapper.selectById(packageId);
}
@Override
public PayWalletRechargePackageDO validWalletRechargePackage(Long packageId) {
PayWalletRechargePackageDO rechargePackageDO = walletRechargePackageMapper.selectById(packageId);
if (rechargePackageDO == null) {
throw exception(WALLET_RECHARGE_PACKAGE_NOT_FOUND);
}
if (CommonStatusEnum.DISABLE.getStatus().equals(rechargePackageDO.getStatus())) {
throw exception(WALLET_RECHARGE_PACKAGE_IS_DISABLE);
}
return rechargePackageDO;
}
@Override
public Long createWalletRechargePackage(WalletRechargePackageCreateReqVO createReqVO) {
// 校验套餐名是否唯一
validateRechargePackageNameUnique(null, createReqVO.getName());
// 插入
PayWalletRechargePackageDO walletRechargePackage = WalletRechargePackageConvert.INSTANCE.convert(createReqVO);
walletRechargePackageMapper.insert(walletRechargePackage);
// 返回
return walletRechargePackage.getId();
}
@Override
public void updateWalletRechargePackage(WalletRechargePackageUpdateReqVO updateReqVO) {
// 校验存在
validateWalletRechargePackageExists(updateReqVO.getId());
// 校验套餐名是否唯一
validateRechargePackageNameUnique(updateReqVO.getId(), updateReqVO.getName());
// 更新
PayWalletRechargePackageDO updateObj = WalletRechargePackageConvert.INSTANCE.convert(updateReqVO);
walletRechargePackageMapper.updateById(updateObj);
}
private void validateRechargePackageNameUnique(Long id, String name) {
if (StrUtil.isBlank(name)) {
return;
}
PayWalletRechargePackageDO rechargePackage = walletRechargePackageMapper.selectByName(name);
if (rechargePackage == null) {
return ;
}
if (id == null) {
throw exception(WALLET_RECHARGE_PACKAGE_NAME_EXISTS);
}
if (!id.equals(rechargePackage.getId())) {
throw exception(WALLET_RECHARGE_PACKAGE_NAME_EXISTS);
}
}
@Override
public void deleteWalletRechargePackage(Long id) {
// 校验存在
validateWalletRechargePackageExists(id);
// 删除
walletRechargePackageMapper.deleteById(id);
}
private void validateWalletRechargePackageExists(Long id) {
if (walletRechargePackageMapper.selectById(id) == null) {
throw exception(WALLET_RECHARGE_PACKAGE_NOT_FOUND);
}
}
@Override
public PageResult<PayWalletRechargePackageDO> getWalletRechargePackagePage(WalletRechargePackagePageReqVO pageReqVO) {
return walletRechargePackageMapper.selectPage(pageReqVO);
}
}

View File

@@ -0,0 +1,49 @@
package cn.iocoder.yudao.module.pay.service.wallet;
import cn.iocoder.yudao.module.pay.controller.app.wallet.vo.recharge.AppPayWalletRechargeCreateReqVO;
import cn.iocoder.yudao.module.pay.dal.dataobject.wallet.PayWalletRechargeDO;
/**
* 钱包充值 Service 接口
*
* @author jason
*/
public interface PayWalletRechargeService {
/**
* 创建钱包充值记录(发起充值)
*
* @param userId 用户 id
* @param userType 用户类型
* @param createReqVO 钱包充值请求 VO
* @param userIp 用户Ip
* @return 钱包充值记录
*/
PayWalletRechargeDO createWalletRecharge(Long userId, Integer userType, String userIp,
AppPayWalletRechargeCreateReqVO createReqVO);
/**
* 更新钱包充值成功
*
* @param id 钱包充值记录 id
* @param payOrderId 支付订单 id
*/
void updateWalletRechargerPaid(Long id, Long payOrderId);
/**
* 发起钱包充值退款
*
* @param id 钱包充值编号
* @param userIp 用户 ip 地址
*/
void refundWalletRecharge(Long id, String userIp);
/**
* 更新钱包充值记录为已退款
*
* @param id 钱包充值 id
* @param payRefundId 退款单id
*/
void updateWalletRechargeRefunded(Long id, Long payRefundId);
}

View File

@@ -0,0 +1,281 @@
package cn.iocoder.yudao.module.pay.service.wallet;
import cn.hutool.core.lang.Assert;
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;
import cn.iocoder.yudao.module.pay.controller.app.wallet.vo.recharge.AppPayWalletRechargeCreateReqVO;
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.wallet.PayWalletDO;
import cn.iocoder.yudao.module.pay.dal.dataobject.wallet.PayWalletRechargeDO;
import cn.iocoder.yudao.module.pay.dal.dataobject.wallet.PayWalletRechargePackageDO;
import cn.iocoder.yudao.module.pay.dal.mysql.wallet.PayWalletRechargeMapper;
import cn.iocoder.yudao.module.pay.enums.order.PayOrderStatusEnum;
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 lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import javax.annotation.Resource;
import java.time.Duration;
import java.time.LocalDateTime;
import java.util.Objects;
import static cn.hutool.core.util.ObjectUtil.notEqual;
import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
import static cn.iocoder.yudao.framework.common.util.date.LocalDateTimeUtils.addTime;
import static cn.iocoder.yudao.framework.common.util.json.JsonUtils.toJsonString;
import static cn.iocoder.yudao.module.pay.convert.wallet.PayWalletRechargeConvert.INSTANCE;
import static cn.iocoder.yudao.module.pay.enums.ErrorCodeConstants.*;
import static cn.iocoder.yudao.module.pay.enums.refund.PayRefundStatusEnum.*;
/**
* 钱包充值 Service 实现类
*
* @author jason
*/
@Service
@Slf4j
public class PayWalletRechargeServiceImpl implements PayWalletRechargeService {
/**
* TODO 芋艿:放到 payconfig
*/
private static final Long WALLET_PAY_APP_ID = 8L;
private static final String WALLET_RECHARGE_ORDER_SUBJECT = "钱包余额充值";
@Resource
private PayWalletRechargeMapper walletRechargeMapper;
@Resource
private PayWalletService payWalletService;
@Resource
private PayOrderService payOrderService;
@Resource
private PayRefundService payRefundService;
@Resource
private PayWalletRechargePackageService payWalletRechargePackageService;
@Override
@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;
if (Objects.nonNull(reqVO.getPackageId())) {
PayWalletRechargePackageDO rechargePackage = payWalletRechargePackageService.validWalletRechargePackage(reqVO.getPackageId());
payPrice = rechargePackage.getPayPrice();
bonusPrice = rechargePackage.getBonusPrice();
} else {
payPrice = reqVO.getPayPrice();
}
// 1.2 插入充值记录
PayWalletDO wallet = payWalletService.getOrCreateWallet(userId, userType);
PayWalletRechargeDO recharge = INSTANCE.convert(wallet.getId(), payPrice, bonusPrice, reqVO.getPackageId());
walletRechargeMapper.insert(recharge);
// 2.1 创建支付单
Long payOrderId = payOrderService.createOrder(new PayOrderCreateReqDTO()
.setAppId(WALLET_PAY_APP_ID).setUserIp(userIp)
.setMerchantOrderId(recharge.getId().toString()) // 业务的订单编号
.setSubject(WALLET_RECHARGE_ORDER_SUBJECT).setBody("")
.setPrice(recharge.getPayPrice())
.setExpireTime(addTime(Duration.ofHours(2L)))); // TODO @芋艿:支付超时时间
// 2.2 更新钱包充值记录中支付订单
walletRechargeMapper.updateById(new PayWalletRechargeDO().setId(recharge.getId()).setPayOrderId(payOrderId));
recharge.setPayOrderId(payOrderId);
return recharge;
}
@Override
@Transactional(rollbackFor = Exception.class)
public void updateWalletRechargerPaid(Long id, Long payOrderId) {
// 1.1 获取钱包充值记录
PayWalletRechargeDO walletRecharge = walletRechargeMapper.selectById(id);
if (walletRecharge == null) {
log.error("[updateWalletRechargerPaid][钱包充值记录不存在,钱包充值记录 id({})]", id);
throw exception(WALLET_RECHARGE_NOT_FOUND);
}
// 1.2 校验钱包充值是否可以支付
PayOrderDO payOrderDO = validateWalletRechargerCanPaid(walletRecharge, payOrderId);
// 2. 更新钱包充值的支付状态
int updateCount = walletRechargeMapper.updateByIdAndPaid(id, false,
new PayWalletRechargeDO().setId(id).setPayStatus(true).setPayTime(LocalDateTime.now())
.setPayChannelCode(payOrderDO.getChannelCode()));
if (updateCount == 0) {
throw exception(WALLET_RECHARGE_UPDATE_PAID_STATUS_NOT_UNPAID);
}
// 3. 更新钱包余额
// TODO @jason这样的话未来提现会不会把充值的也提现走哈。类似先充 100送 110然后提现 110
// TODO 需要钱包中加个可提现余额
payWalletService.addWalletBalance(walletRecharge.getWalletId(), String.valueOf(id),
PayWalletBizTypeEnum.RECHARGE, walletRecharge.getTotalPrice());
}
@Override
@Transactional(rollbackFor = Exception.class)
public void refundWalletRecharge(Long id, String userIp) {
// 1.1 获取钱包充值记录
PayWalletRechargeDO walletRecharge = walletRechargeMapper.selectById(id);
if (walletRecharge == null) {
log.error("[refundWalletRecharge][钱包充值记录不存在,钱包充值记录 id({})]", id);
throw exception(WALLET_RECHARGE_NOT_FOUND);
}
// 1.2 校验钱包充值是否可以发起退款
PayWalletDO wallet = validateWalletRechargeCanRefund(walletRecharge);
// 2. 冻结退款的余额,暂时只处理赠送的余额也全部退回
payWalletService.freezePrice(wallet.getId(), walletRecharge.getTotalPrice());
// 3. 创建退款单
String walletRechargeId = String.valueOf(id);
String refundId = walletRechargeId + "-refund";
Long payRefundId = payRefundService.createPayRefund(new PayRefundCreateReqDTO()
.setAppId(WALLET_PAY_APP_ID).setUserIp(userIp)
.setMerchantOrderId(walletRechargeId)
.setMerchantRefundId(refundId)
.setReason("想退钱").setPrice(walletRecharge.getPayPrice()));
// 4. 更新充值记录退款单号
// TODO @jaosn一般新建这种 update 对象,建议是,第一个 set id 属性,容易知道以它为更新
walletRechargeMapper.updateById(new PayWalletRechargeDO().setPayRefundId(payRefundId)
.setRefundStatus(WAITING.getStatus()).setId(walletRecharge.getId()));
}
@Override
@Transactional(rollbackFor = Exception.class)
public void updateWalletRechargeRefunded(Long id, Long payRefundId) {
// 1.1 获取钱包充值记录
PayWalletRechargeDO walletRecharge = walletRechargeMapper.selectById(id);
if (walletRecharge == null) {
log.error("[updateWalletRechargerPaid][钱包充值记录不存在,钱包充值记录 id({})]", id);
throw exception(WALLET_RECHARGE_NOT_FOUND);
}
// 1.2 校验钱包充值是否可以更新已退款
PayRefundDO payRefund = validateWalletRechargeCanRefunded(walletRecharge, payRefundId);
PayWalletRechargeDO updateObj = new PayWalletRechargeDO().setId(id);
// 退款成功
if (PayRefundStatusEnum.isSuccess(payRefund.getStatus())) {
// 2.1 更新钱包余额
payWalletService.reduceWalletBalance(walletRecharge.getWalletId(), id,
PayWalletBizTypeEnum.RECHARGE_REFUND, walletRecharge.getTotalPrice());
updateObj.setRefundStatus(SUCCESS.getStatus()).setRefundTime(payRefund.getSuccessTime())
.setRefundTotalPrice(walletRecharge.getTotalPrice()).setRefundPayPrice(walletRecharge.getPayPrice())
.setRefundBonusPrice(walletRecharge.getBonusPrice());
}
// 退款失败
if (PayRefundStatusRespEnum.isFailure(payRefund.getStatus())) {
// 2.2 解冻余额
payWalletService.unfreezePrice(walletRecharge.getWalletId(), walletRecharge.getTotalPrice());
updateObj.setRefundStatus(FAILURE.getStatus());
}
// 3. 更新钱包充值的退款字段
walletRechargeMapper.updateByIdAndRefunded(id, WAITING.getStatus(), updateObj);
}
private PayRefundDO validateWalletRechargeCanRefunded(PayWalletRechargeDO walletRecharge, Long payRefundId) {
// 1. 校验退款订单匹配
if (notEqual(walletRecharge.getPayRefundId(), payRefundId)) {
log.error("[validateWalletRechargeCanRefunded][钱包充值({}) 退款单不匹配({}),请进行处理!钱包充值的数据是:{}]",
walletRecharge.getId(), payRefundId, toJsonString(walletRecharge));
throw exception(WALLET_RECHARGE_REFUND_FAIL_REFUND_ORDER_ID_ERROR);
}
// 2.1 校验退款订单
PayRefundDO payRefund = payRefundService.getRefund(payRefundId);
if (payRefund == null) {
log.error("[validateWalletRechargeCanRefunded][payRefund({})不存在]", payRefundId);
throw exception(WALLET_RECHARGE_REFUND_FAIL_REFUND_NOT_FOUND);
}
// 2.2 校验退款金额一致
if (notEqual(payRefund.getRefundPrice(), walletRecharge.getPayPrice())) {
log.error("[validateWalletRechargeCanRefunded][钱包({}) payRefund({}) 退款金额不匹配,请进行处理!钱包数据是:{}payRefund 数据是:{}]",
walletRecharge.getId(), payRefundId, toJsonString(walletRecharge), toJsonString(payRefund));
throw exception(WALLET_RECHARGE_REFUND_FAIL_REFUND_PRICE_NOT_MATCH);
}
// 2.3 校验退款订单商户订单是否匹配
if (notEqual(payRefund.getMerchantOrderId(), walletRecharge.getId().toString())) {
log.error("[validateWalletRechargeCanRefunded][钱包({}) 退款单不匹配({})请进行处理payRefund 数据是:{}]",
walletRecharge.getId(), payRefundId, toJsonString(payRefund));
throw exception(WALLET_RECHARGE_REFUND_FAIL_REFUND_ORDER_ID_ERROR);
}
return payRefund;
}
private PayWalletDO validateWalletRechargeCanRefund(PayWalletRechargeDO walletRecharge) {
// 校验充值订单是否支付
if (!walletRecharge.getPayStatus()) {
throw exception(WALLET_RECHARGE_REFUND_FAIL_NOT_PAID);
}
// 校验充值订单是否已退款
if (walletRecharge.getPayRefundId() != null) {
throw exception(WALLET_RECHARGE_REFUND_FAIL_REFUNDED);
}
// 校验钱包余额是否足够
PayWalletDO wallet = payWalletService.getWallet(walletRecharge.getWalletId());
Assert.notNull(wallet, "用户钱包({}) 不存在", wallet.getId());
if (wallet.getBalance() < walletRecharge.getTotalPrice()) {
throw exception(WALLET_RECHARGE_REFUND_BALANCE_NOT_ENOUGH);
}
// TODO @芋艿:需要考虑下,赠送的金额,会不会导致提现超过;
return wallet;
}
private PayOrderDO validateWalletRechargerCanPaid(PayWalletRechargeDO walletRecharge, Long payOrderId) {
// 1.1 校验充值记录的支付状态
if (walletRecharge.getPayStatus()) {
log.error("[validateWalletRechargerCanPaid][钱包({}) 不处于未支付状态! 钱包数据是:{}]",
walletRecharge.getId(), toJsonString(walletRecharge));
throw exception(WALLET_RECHARGE_UPDATE_PAID_STATUS_NOT_UNPAID);
}
// 1.2 校验支付订单匹配
if (notEqual(walletRecharge.getPayOrderId(), payOrderId)) { // 支付单号
log.error("[validateWalletRechargerCanPaid][钱包({}) 支付单不匹配({}),请进行处理! 钱包数据是:{}]",
walletRecharge.getId(), payOrderId, toJsonString(walletRecharge));
throw exception(WALLET_RECHARGE_UPDATE_PAID_PAY_ORDER_ID_ERROR);
}
// 2.1 校验支付单是否存在
PayOrderDO payOrder = payOrderService.getOrder(payOrderId);
if (payOrder == null) {
log.error("[validateWalletRechargerCanPaid][钱包({}) payOrder({}) 不存在,请进行处理!]",
walletRecharge.getId(), payOrderId);
throw exception(PAY_ORDER_NOT_FOUND);
}
// 2.2 校验支付单已支付
if (!PayOrderStatusEnum.isSuccess(payOrder.getStatus())) {
log.error("[validateWalletRechargerCanPaid][钱包({}) payOrder({}) 未支付请进行处理payOrder 数据是:{}]",
walletRecharge.getId(), payOrderId, toJsonString(payOrder));
throw exception(WALLET_RECHARGE_UPDATE_PAID_PAY_ORDER_STATUS_NOT_SUCCESS);
}
// 2.3 校验支付金额一致
if (notEqual(payOrder.getPrice(), walletRecharge.getPayPrice())) {
log.error("[validateDemoOrderCanPaid][钱包({}) payOrder({}) 支付金额不匹配,请进行处理!钱包 数据是:{}payOrder 数据是:{}]",
walletRecharge.getId(), payOrderId, toJsonString(walletRecharge), toJsonString(payOrder));
throw exception(WALLET_RECHARGE_UPDATE_PAID_PAY_PRICE_NOT_MATCH);
}
// 2.4 校验支付订单的商户订单匹配
if (notEqual(payOrder.getMerchantOrderId(), walletRecharge.getId().toString())) {
log.error("[validateDemoOrderCanPaid][钱包({}) 支付单不匹配({})请进行处理payOrder 数据是:{}]",
walletRecharge.getId(), payOrderId, toJsonString(payOrder));
throw exception(WALLET_RECHARGE_UPDATE_PAID_PAY_ORDER_ID_ERROR);
}
return payOrder;
}
}

View File

@@ -0,0 +1,101 @@
package cn.iocoder.yudao.module.pay.service.wallet;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.module.pay.controller.admin.wallet.vo.wallet.PayWalletPageReqVO;
import cn.iocoder.yudao.module.pay.dal.dataobject.wallet.PayWalletDO;
import cn.iocoder.yudao.module.pay.dal.dataobject.wallet.PayWalletTransactionDO;
import cn.iocoder.yudao.module.pay.enums.wallet.PayWalletBizTypeEnum;
/**
* 钱包 Service 接口
*
* @author jason
*/
public interface PayWalletService {
/**
* 获取钱包信息
* <p>
* 如果不存在,则创建钱包。由于用户注册时候不会创建钱包
*
* @param userId 用户编号
* @param userType 用户类型
*/
PayWalletDO getOrCreateWallet(Long userId, Integer userType);
/**
* 获取钱包信息
*
* @param walletId 钱包 id
*/
PayWalletDO getWallet(Long walletId);
/**
* 获得会员钱包分页
*
* @param pageReqVO 分页查询
* @return 会员钱包分页
*/
PageResult<PayWalletDO> getWalletPage(Integer userType, PayWalletPageReqVO pageReqVO);
/**
* 钱包订单支付
*
* @param userId 用户 id
* @param userType 用户类型
* @param outTradeNo 外部订单号
* @param price 金额
*/
PayWalletTransactionDO orderPay(Long userId, Integer userType, String outTradeNo, Integer price);
/**
* 钱包订单支付退款
*
* @param outRefundNo 外部退款号
* @param refundPrice 退款金额
* @param reason 退款原因
*/
PayWalletTransactionDO orderRefund(String outRefundNo, Integer refundPrice, String reason);
/**
* 扣减钱包余额
*
* @param walletId 钱包 id
* @param bizId 业务关联 id
* @param bizType 业务关联分类
* @param price 扣减金额
* @return 钱包流水
*/
PayWalletTransactionDO reduceWalletBalance(Long walletId, Long bizId,
PayWalletBizTypeEnum bizType, Integer price);
/**
* 增加钱包余额
*
* @param walletId 钱包 id
* @param bizId 业务关联 id
* @param bizType 业务关联分类
* @param price 增加金额
* @return 钱包流水
*/
PayWalletTransactionDO addWalletBalance(Long walletId, String bizId,
PayWalletBizTypeEnum bizType, Integer price);
/**
* 冻结钱包部分余额
*
* @param id 钱包编号
* @param price 冻结金额
*/
void freezePrice(Long id, Integer price);
/**
* 解冻钱包余额
*
* @param id 钱包编号
* @param price 解冻金额
*/
void unfreezePrice(Long id, Integer price);
}

View File

@@ -0,0 +1,206 @@
package cn.iocoder.yudao.module.pay.service.wallet;
import cn.hutool.core.lang.Assert;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.module.pay.controller.admin.wallet.vo.wallet.PayWalletPageReqVO;
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.PayWalletDO;
import cn.iocoder.yudao.module.pay.dal.dataobject.wallet.PayWalletTransactionDO;
import cn.iocoder.yudao.module.pay.dal.mysql.wallet.PayWalletMapper;
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 lombok.extern.slf4j.Slf4j;
import org.springframework.context.annotation.Lazy;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import javax.annotation.Resource;
import java.time.LocalDateTime;
import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
import static cn.iocoder.yudao.module.pay.enums.ErrorCodeConstants.*;
import static cn.iocoder.yudao.module.pay.enums.wallet.PayWalletBizTypeEnum.PAYMENT;
import static cn.iocoder.yudao.module.pay.enums.wallet.PayWalletBizTypeEnum.PAYMENT_REFUND;
/**
* 钱包 Service 实现类
*
* @author jason
*/
@Service
@Slf4j
public class PayWalletServiceImpl implements PayWalletService {
@Resource
private PayWalletMapper walletMapper;
@Resource
private PayWalletTransactionService walletTransactionService;
@Resource
@Lazy
private PayOrderService orderService;
@Resource
@Lazy
private PayRefundService refundService;
@Override
public PayWalletDO getOrCreateWallet(Long userId, Integer userType) {
PayWalletDO wallet = walletMapper.selectByUserIdAndType(userId, userType);
if (wallet == null) {
wallet = new PayWalletDO().setUserId(userId).setUserType(userType)
.setBalance(0).setTotalExpense(0).setTotalRecharge(0);
wallet.setCreateTime(LocalDateTime.now());
walletMapper.insert(wallet);
}
return wallet;
}
@Override
public PayWalletDO getWallet(Long walletId) {
return walletMapper.selectById(walletId);
}
@Override
public PageResult<PayWalletDO> getWalletPage(Integer userType,PayWalletPageReqVO pageReqVO) {
return walletMapper.selectPage(userType, pageReqVO);
}
@Override
@Transactional(rollbackFor = Exception.class)
public PayWalletTransactionDO orderPay(Long userId, Integer userType, String outTradeNo, Integer price) {
// 1. 判断支付交易拓展单是否存
PayOrderExtensionDO orderExtension = orderService.getOrderExtensionByNo(outTradeNo);
if (orderExtension == null) {
throw exception(PAY_ORDER_EXTENSION_NOT_FOUND);
}
PayWalletDO wallet = getOrCreateWallet(userId, userType);
// 2. 扣减余额
return reduceWalletBalance(wallet.getId(), orderExtension.getOrderId(), PAYMENT, price);
}
@Override
@Transactional(rollbackFor = Exception.class)
public PayWalletTransactionDO orderRefund(String outRefundNo, Integer refundPrice, String reason) {
// 1.1 判断退款单是否存在
PayRefundDO payRefund = refundService.getRefundByNo(outRefundNo);
if (payRefund == null) {
throw exception(REFUND_NOT_FOUND);
}
// 1.2 校验是否可以退款
Long walletId = validateWalletCanRefund(payRefund.getId(), payRefund.getChannelOrderNo());
PayWalletDO wallet = walletMapper.selectById(walletId);
Assert.notNull(wallet, "钱包 {} 不存在", walletId);
// 2. 增加余额
return addWalletBalance(walletId, String.valueOf(payRefund.getId()), PAYMENT_REFUND, refundPrice);
}
/**
* 校验是否能退款
*
* @param refundId 支付退款单 id
* @param walletPayNo 钱包支付 no
*/
private Long validateWalletCanRefund(Long refundId, String walletPayNo) {
// 1. 校验钱包支付交易存在
PayWalletTransactionDO walletTransaction = walletTransactionService.getWalletTransactionByNo(walletPayNo);
if (walletTransaction == null) {
throw exception(WALLET_TRANSACTION_NOT_FOUND);
}
// 2. 校验退款是否存在
PayWalletTransactionDO refundTransaction = walletTransactionService.getWalletTransaction(
String.valueOf(refundId), PAYMENT_REFUND);
if (refundTransaction != null) {
throw exception(WALLET_REFUND_EXIST);
}
return walletTransaction.getWalletId();
}
@Override
public PayWalletTransactionDO reduceWalletBalance(Long walletId, Long bizId,
PayWalletBizTypeEnum bizType, Integer price) {
// 1. 获取钱包
PayWalletDO payWallet = getWallet(walletId);
if (payWallet == null) {
log.error("[reduceWalletBalance],用户钱包({})不存在.", walletId);
throw exception(WALLET_NOT_FOUND);
}
// 2.1 扣除余额
int updateCounts;
switch (bizType) {
case PAYMENT: {
updateCounts = walletMapper.updateWhenConsumption(payWallet.getId(), price);
break;
}
case RECHARGE_REFUND: {
updateCounts = walletMapper.updateWhenRechargeRefund(payWallet.getId(), price);
break;
}
default: {
// TODO 其它类型待实现
throw new UnsupportedOperationException("待实现");
}
}
if (updateCounts == 0) {
throw exception(WALLET_BALANCE_NOT_ENOUGH);
}
// 2.2 生成钱包流水
Integer afterBalance = payWallet.getBalance() - price;
WalletTransactionCreateReqBO bo = new WalletTransactionCreateReqBO().setWalletId(payWallet.getId())
.setPrice(-price).setBalance(afterBalance).setBizId(String.valueOf(bizId))
.setBizType(bizType.getType()).setTitle(bizType.getDescription());
return walletTransactionService.createWalletTransaction(bo);
}
@Override
public PayWalletTransactionDO addWalletBalance(Long walletId, String bizId,
PayWalletBizTypeEnum bizType, Integer price) {
// 1.1 获取钱包
PayWalletDO payWallet = getWallet(walletId);
if (payWallet == null) {
log.error("[addWalletBalance],用户钱包({})不存在.", walletId);
throw exception(WALLET_NOT_FOUND);
}
// 1.2 更新钱包金额
switch (bizType) {
case PAYMENT_REFUND: { // 退款更新
walletMapper.updateWhenConsumptionRefund(payWallet.getId(), price);
break;
}
case RECHARGE: { // 充值更新
walletMapper.updateWhenRecharge(payWallet.getId(), price);
break;
}
default: {
// TODO 其它类型待实现
throw new UnsupportedOperationException("待实现");
}
}
// 2. 生成钱包流水
WalletTransactionCreateReqBO transactionCreateReqBO = new WalletTransactionCreateReqBO()
.setWalletId(payWallet.getId()).setPrice(price).setBalance(payWallet.getBalance() + price)
.setBizId(bizId).setBizType(bizType.getType()).setTitle(bizType.getDescription());
return walletTransactionService.createWalletTransaction(transactionCreateReqBO);
}
@Override
public void freezePrice(Long id, Integer price) {
int updateCounts = walletMapper.freezePrice(id, price);
if (updateCounts == 0) {
throw exception(WALLET_BALANCE_NOT_ENOUGH);
}
}
@Override
public void unfreezePrice(Long id, Integer price) {
int updateCounts = walletMapper.unFreezePrice(id, price);
if (updateCounts == 0) {
throw exception(WALLET_FREEZE_PRICE_NOT_ENOUGH);
}
}
}

View File

@@ -0,0 +1,60 @@
package cn.iocoder.yudao.module.pay.service.wallet;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.module.pay.controller.admin.wallet.vo.transaction.PayWalletTransactionPageReqVO;
import cn.iocoder.yudao.module.pay.controller.app.wallet.vo.transaction.AppPayWalletTransactionPageReqVO;
import cn.iocoder.yudao.module.pay.dal.dataobject.wallet.PayWalletTransactionDO;
import cn.iocoder.yudao.module.pay.enums.wallet.PayWalletBizTypeEnum;
import cn.iocoder.yudao.module.pay.service.wallet.bo.WalletTransactionCreateReqBO;
import javax.validation.Valid;
/**
* 钱包余额流水 Service 接口
*
* @author jason
*/
public interface PayWalletTransactionService {
/**
* 查询钱包余额流水分页
*
* @param userId 用户编号
* @param userType 用户类型
* @param pageVO 分页查询参数
*/
PageResult<PayWalletTransactionDO> getWalletTransactionPage(Long userId, Integer userType,
AppPayWalletTransactionPageReqVO pageVO);
/**
* 查询钱包余额流水分页
*
* @param pageVO 分页查询参数
*/
PageResult<PayWalletTransactionDO> getWalletTransactionPage(PayWalletTransactionPageReqVO pageVO);
/**
* 新增钱包余额流水
*
* @param bo 创建钱包流水 bo
* @return 新建的钱包 do
*/
PayWalletTransactionDO createWalletTransaction(@Valid WalletTransactionCreateReqBO bo);
/**
* 根据 no获取钱包余流水
*
* @param no 流水号
*/
PayWalletTransactionDO getWalletTransactionByNo(String no);
/**
* 获取钱包流水
*
* @param bizId 业务编号
* @param type 业务类型
* @return 钱包流水
*/
PayWalletTransactionDO getWalletTransaction(String bizId, PayWalletBizTypeEnum type);
}

View File

@@ -0,0 +1,71 @@
package cn.iocoder.yudao.module.pay.service.wallet;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.module.pay.controller.admin.wallet.vo.transaction.PayWalletTransactionPageReqVO;
import cn.iocoder.yudao.module.pay.controller.app.wallet.vo.transaction.AppPayWalletTransactionPageReqVO;
import cn.iocoder.yudao.module.pay.convert.wallet.PayWalletTransactionConvert;
import cn.iocoder.yudao.module.pay.dal.dataobject.wallet.PayWalletDO;
import cn.iocoder.yudao.module.pay.dal.dataobject.wallet.PayWalletTransactionDO;
import cn.iocoder.yudao.module.pay.dal.mysql.wallet.PayWalletTransactionMapper;
import cn.iocoder.yudao.module.pay.dal.redis.no.PayNoRedisDAO;
import cn.iocoder.yudao.module.pay.enums.wallet.PayWalletBizTypeEnum;
import cn.iocoder.yudao.module.pay.service.wallet.bo.WalletTransactionCreateReqBO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.validation.annotation.Validated;
import javax.annotation.Resource;
/**
* 钱包流水 Service 实现类
*
* @author jason
*/
@Service
@Slf4j
@Validated
public class PayWalletTransactionServiceImpl implements PayWalletTransactionService {
/**
* 钱包流水的 no 前缀
*/
private static final String WALLET_NO_PREFIX = "W";
@Resource
private PayWalletService payWalletService;
@Resource
private PayWalletTransactionMapper payWalletTransactionMapper;
@Resource
private PayNoRedisDAO noRedisDAO;
@Override
public PageResult<PayWalletTransactionDO> getWalletTransactionPage(Long userId, Integer userType,
AppPayWalletTransactionPageReqVO pageVO) {
PayWalletDO wallet = payWalletService.getOrCreateWallet(userId, userType);
return payWalletTransactionMapper.selectPage(wallet.getId(), pageVO.getType(), pageVO);
}
@Override
public PageResult<PayWalletTransactionDO> getWalletTransactionPage(PayWalletTransactionPageReqVO pageVO) {
return payWalletTransactionMapper.selectPage(pageVO.getWalletId(), null, pageVO);
}
@Override
public PayWalletTransactionDO createWalletTransaction(WalletTransactionCreateReqBO bo) {
PayWalletTransactionDO transaction = PayWalletTransactionConvert.INSTANCE.convert(bo)
.setNo(noRedisDAO.generate(WALLET_NO_PREFIX));
payWalletTransactionMapper.insert(transaction);
return transaction;
}
@Override
public PayWalletTransactionDO getWalletTransactionByNo(String no) {
return payWalletTransactionMapper.selectByNo(no);
}
@Override
public PayWalletTransactionDO getWalletTransaction(String bizId, PayWalletBizTypeEnum type) {
return payWalletTransactionMapper.selectByBiz(bizId, type.getType());
}
}

View File

@@ -0,0 +1,59 @@
package cn.iocoder.yudao.module.pay.service.wallet.bo;
import cn.iocoder.yudao.framework.common.validation.InEnum;
import cn.iocoder.yudao.module.pay.enums.wallet.PayWalletBizTypeEnum;
import lombok.Data;
import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;
/**
* 创建钱包流水 BO
*
* @author jason
*/
@Data
public class WalletTransactionCreateReqBO {
/**
* 钱包编号
*
*/
@NotNull(message = "钱包编号不能为空")
private Long walletId;
/**
* 交易金额,单位分
*
* 正值表示余额增加,负值表示余额减少
*/
@NotNull(message = "交易金额不能为空")
private Integer price;
/**
* 交易后余额,单位分
*/
@NotNull(message = "交易后余额不能为空")
private Integer balance;
/**
* 关联业务分类
*
* 枚举 {@link PayWalletBizTypeEnum#getType()}
*/
@NotNull(message = "关联业务分类不能为空")
@InEnum(PayWalletBizTypeEnum.class)
private Integer bizType;
/**
* 关联业务编号
*/
@NotEmpty(message = "关联业务编号不能为空")
private String bizId;
/**
* 流水说明
*/
@NotEmpty(message = "流水说明不能为空")
private String title;
}

View File

@@ -74,7 +74,7 @@ spring:
--- #################### 定时任务相关配置 ####################
xxl:
job:
enabled: true # 是否开启调度中心,默认为 true 开启
enabled: false # 是否开启调度中心,默认为 true 开启
admin:
addresses: http://127.0.0.1:8000/xxl-job-admin # 调度中心部署跟地址

View File

@@ -261,7 +261,7 @@ public class PayOrderServiceTest extends BaseDbAndRedisUnitTest {
String userIp = randomString();
// 调用, 并断言异常
assertServiceException(() -> orderService.submitOrder(reqVO, userIp), ORDER_NOT_FOUND);
assertServiceException(() -> orderService.submitOrder(reqVO, userIp), PAY_ORDER_NOT_FOUND);
}
@Test
@@ -274,7 +274,7 @@ public class PayOrderServiceTest extends BaseDbAndRedisUnitTest {
String userIp = randomString();
// 调用, 并断言异常
assertServiceException(() -> orderService.submitOrder(reqVO, userIp), ORDER_STATUS_IS_NOT_WAITING);
assertServiceException(() -> orderService.submitOrder(reqVO, userIp), PAY_ORDER_STATUS_IS_NOT_WAITING);
}
@Test
@@ -287,7 +287,7 @@ public class PayOrderServiceTest extends BaseDbAndRedisUnitTest {
String userIp = randomString();
// 调用, 并断言异常
assertServiceException(() -> orderService.submitOrder(reqVO, userIp), ORDER_STATUS_IS_SUCCESS);
assertServiceException(() -> orderService.submitOrder(reqVO, userIp), PAY_ORDER_STATUS_IS_SUCCESS);
}
@Test
@@ -301,7 +301,7 @@ public class PayOrderServiceTest extends BaseDbAndRedisUnitTest {
String userIp = randomString();
// 调用, 并断言异常
assertServiceException(() -> orderService.submitOrder(reqVO, userIp), ORDER_IS_EXPIRED);
assertServiceException(() -> orderService.submitOrder(reqVO, userIp), PAY_ORDER_IS_EXPIRED);
}
@Test
@@ -366,7 +366,7 @@ public class PayOrderServiceTest extends BaseDbAndRedisUnitTest {
// 调用,并断言异常
assertServiceException(() -> orderService.submitOrder(reqVO, userIp),
ORDER_SUBMIT_CHANNEL_ERROR, "001", "模拟异常");
PAY_ORDER_SUBMIT_CHANNEL_ERROR, "001", "模拟异常");
// 断言数据记录PayOrderExtensionDO
PayOrderExtensionDO orderExtension = orderExtensionMapper.selectOne(null);
assertNotNull(orderExtension);
@@ -450,7 +450,7 @@ public class PayOrderServiceTest extends BaseDbAndRedisUnitTest {
// 调用,并断言异常
assertServiceException(() -> orderService.validateOrderActuallyPaid(id),
ORDER_EXTENSION_IS_PAID);
PAY_ORDER_EXTENSION_IS_PAID);
}
@Test
@@ -469,7 +469,7 @@ public class PayOrderServiceTest extends BaseDbAndRedisUnitTest {
// 调用,并断言异常
assertServiceException(() -> orderService.validateOrderActuallyPaid(id),
ORDER_EXTENSION_IS_PAID);
PAY_ORDER_EXTENSION_IS_PAID);
}
@Test
@@ -519,7 +519,7 @@ public class PayOrderServiceTest extends BaseDbAndRedisUnitTest {
// 调用,并断言异常
assertServiceException(() -> orderService.notifyOrder(channel, notify),
ORDER_EXTENSION_NOT_FOUND);
PAY_ORDER_EXTENSION_NOT_FOUND);
}
@Test
@@ -537,7 +537,7 @@ public class PayOrderServiceTest extends BaseDbAndRedisUnitTest {
// 调用,并断言异常
assertServiceException(() -> orderService.notifyOrder(channel, notify),
ORDER_EXTENSION_STATUS_IS_NOT_WAITING);
PAY_ORDER_EXTENSION_STATUS_IS_NOT_WAITING);
}
@Test
@@ -555,7 +555,7 @@ public class PayOrderServiceTest extends BaseDbAndRedisUnitTest {
// 调用,并断言异常
assertServiceException(() -> orderService.notifyOrder(channel, notify),
ORDER_NOT_FOUND);
PAY_ORDER_NOT_FOUND);
// 断言 PayOrderExtensionDO :数据更新被回滚
assertPojoEquals(orderExtension, orderExtensionMapper.selectOne(null));
}
@@ -588,7 +588,7 @@ public class PayOrderServiceTest extends BaseDbAndRedisUnitTest {
// 调用,并断言异常
assertServiceException(() -> orderService.notifyOrder(channel, notify),
ORDER_STATUS_IS_NOT_WAITING);
PAY_ORDER_STATUS_IS_NOT_WAITING);
// 断言 PayOrderExtensionDO :数据未更新,因为它是 SUCCESS
assertPojoEquals(orderExtension, orderExtensionMapper.selectOne(null));
}
@@ -661,7 +661,7 @@ public class PayOrderServiceTest extends BaseDbAndRedisUnitTest {
"updateTime", "updater");
// 断言,调用
verify(notifyService).createPayNotifyTask(eq(PayNotifyTypeEnum.ORDER.getType()),
eq(orderExtension.getOrderId()));
eq(orderExtension.getOrderId()));
}
@Test
@@ -673,7 +673,7 @@ public class PayOrderServiceTest extends BaseDbAndRedisUnitTest {
// 调用,并断言异常
assertServiceException(() -> orderService.notifyOrder(channel, notify),
ORDER_EXTENSION_NOT_FOUND);
PAY_ORDER_EXTENSION_NOT_FOUND);
}
@Test
@@ -729,7 +729,7 @@ public class PayOrderServiceTest extends BaseDbAndRedisUnitTest {
// 调用,并断言异常
assertServiceException(() -> orderService.notifyOrder(channel, notify),
ORDER_EXTENSION_STATUS_IS_NOT_WAITING);
PAY_ORDER_EXTENSION_STATUS_IS_NOT_WAITING);
}
@Test
@@ -762,7 +762,7 @@ public class PayOrderServiceTest extends BaseDbAndRedisUnitTest {
// 调用,并断言异常
assertServiceException(() -> orderService.updateOrderRefundPrice(id, incrRefundPrice),
ORDER_NOT_FOUND);
PAY_ORDER_NOT_FOUND);
}
@Test
@@ -786,7 +786,7 @@ public class PayOrderServiceTest extends BaseDbAndRedisUnitTest {
// 调用,并断言异常
assertServiceException(() -> orderService.updateOrderRefundPrice(id, incrRefundPrice),
ORDER_REFUND_FAIL_STATUS_ERROR);
PAY_ORDER_REFUND_FAIL_STATUS_ERROR);
}
@Test

View File

@@ -219,7 +219,7 @@ public class PayRefundServiceTest extends BaseDbAndRedisUnitTest {
// 调用,并断言异常
assertServiceException(() -> refundService.createPayRefund(reqDTO),
ORDER_NOT_FOUND);
PAY_ORDER_NOT_FOUND);
}
@Test
@@ -245,7 +245,7 @@ public class PayRefundServiceTest extends BaseDbAndRedisUnitTest {
// 调用,并断言异常
assertServiceException(() -> refundService.createPayRefund(reqDTO),
ORDER_REFUND_FAIL_STATUS_ERROR);
PAY_ORDER_REFUND_FAIL_STATUS_ERROR);
}
@Test
@@ -418,7 +418,7 @@ public class PayRefundServiceTest extends BaseDbAndRedisUnitTest {
assertNotNull(unifiedReqDTO.getOutRefundNo());
assertThat(unifiedReqDTO)
.extracting("payPrice", "refundPrice", "outTradeNo",
"notifyUrl", "reason")
"notifyUrl", "reason")
.containsExactly(order.getPrice(), reqDTO.getPrice(), order.getNo(),
"http://127.0.0.1/10", reqDTO.getReason());
return true;