mirror of
https://gitee.com/dromara/dax-pay.git
synced 2025-08-29 09:04:14 +00:00
feat 支付记录相关
This commit is contained in:
@@ -35,4 +35,7 @@ public interface MchAndAppCode {
|
||||
/** 停用 */
|
||||
String PAY_CONFIG_STATE_FORBIDDEN = "forbidden";
|
||||
|
||||
/** 封禁 */
|
||||
String PAY_CONFIG_STATE_BANNED = "banned";
|
||||
|
||||
}
|
||||
|
@@ -73,8 +73,8 @@ public class MchApplicationController {
|
||||
|
||||
@Operation(summary = "关联支付配置列表")
|
||||
@GetMapping("/findAllConfig")
|
||||
public ResResult<List<MchAppPayConfigResult>> findAllConfig(Long appId) {
|
||||
return Res.ok(appPayConfigService.ListByAppId(appId));
|
||||
public ResResult<List<MchAppPayConfigResult>> findAllConfig(String appCode) {
|
||||
return Res.ok(appPayConfigService.ListByAppId(appCode));
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -37,19 +37,19 @@ public class PayCallbackController {
|
||||
|
||||
@SneakyThrows
|
||||
@Operation(summary = "支付宝回调")
|
||||
@PostMapping("/alipay/{appCode}")
|
||||
public String aliPay(@PathVariable String appCode, HttpServletRequest request) {
|
||||
@PostMapping("/alipay/{mchCode}/{appCode}")
|
||||
public String aliPay(@PathVariable String mchCode,@PathVariable String appCode, HttpServletRequest request) {
|
||||
Map<String, String> stringStringMap = AliPayApi.toMap(request);
|
||||
return aliPayCallbackService.payCallback(appCode, stringStringMap);
|
||||
return aliPayCallbackService.payCallback(mchCode, appCode, stringStringMap);
|
||||
}
|
||||
|
||||
@SneakyThrows
|
||||
@Operation(summary = "微信支付回调")
|
||||
@PostMapping("/wechat/{appCode}")
|
||||
public String wechat(@PathVariable String appCode, HttpServletRequest request) {
|
||||
@PostMapping("/wechat/{mchCode}/{appCode}")
|
||||
public String wechat(@PathVariable String mchCode, @PathVariable String appCode, HttpServletRequest request) {
|
||||
String xmlMsg = HttpKit.readData(request);
|
||||
Map<String, String> params = WxPayKit.xmlToMap(xmlMsg);
|
||||
return weChatPayCallbackService.payCallback(appCode, params);
|
||||
return weChatPayCallbackService.payCallback(mchCode, appCode, params);
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -4,8 +4,8 @@ import cn.bootx.platform.common.core.annotation.IgnoreAuth;
|
||||
import cn.bootx.platform.common.core.rest.PageResult;
|
||||
import cn.bootx.platform.common.core.rest.Res;
|
||||
import cn.bootx.platform.common.core.rest.ResResult;
|
||||
import cn.bootx.platform.common.core.rest.param.OrderParam;
|
||||
import cn.bootx.platform.common.core.rest.param.PageParam;
|
||||
import cn.bootx.platform.common.query.entity.QueryOrder;
|
||||
import cn.bootx.platform.common.query.entity.QueryParams;
|
||||
import cn.bootx.platform.daxpay.core.payment.service.PaymentQueryService;
|
||||
import cn.bootx.platform.daxpay.dto.payment.PayChannelInfo;
|
||||
@@ -38,8 +38,8 @@ public class PaymentController {
|
||||
|
||||
@Operation(summary = "分页查询")
|
||||
@GetMapping("/page")
|
||||
public ResResult<PageResult<PaymentDto>> page(PageParam pageParam, PaymentQuery param, OrderParam orderParam) {
|
||||
return Res.ok(paymentQueryService.page(pageParam, param, orderParam));
|
||||
public ResResult<PageResult<PaymentDto>> page(PageParam pageParam, PaymentQuery param, QueryOrder queryOrder) {
|
||||
return Res.ok(paymentQueryService.page(pageParam, param, queryOrder));
|
||||
}
|
||||
|
||||
@Operation(summary = "分页查询(超级查询)")
|
||||
|
@@ -119,7 +119,10 @@ public class AlipayConfig extends MpBaseEntity implements EntityBaseFunction<Ali
|
||||
@DbColumn(comment = "可用支付方式")
|
||||
private String payWays;
|
||||
|
||||
/** 状态 */
|
||||
/**
|
||||
* 状态
|
||||
* @see cn.bootx.platform.daxpay.code.MchAndAppCode#PAY_CONFIG_STATE_NORMAL
|
||||
*/
|
||||
@DbColumn(comment = "状态")
|
||||
private String state;
|
||||
|
||||
|
@@ -6,6 +6,7 @@ import cn.bootx.platform.common.core.rest.PageResult;
|
||||
import cn.bootx.platform.common.core.rest.dto.KeyValue;
|
||||
import cn.bootx.platform.common.core.rest.param.PageParam;
|
||||
import cn.bootx.platform.common.mybatisplus.util.MpUtil;
|
||||
import cn.bootx.platform.daxpay.code.MchAndAppCode;
|
||||
import cn.bootx.platform.daxpay.code.pay.PayChannelEnum;
|
||||
import cn.bootx.platform.daxpay.code.paymodel.AliPayWay;
|
||||
import cn.bootx.platform.daxpay.core.channel.alipay.dao.AlipayConfigManager;
|
||||
@@ -50,10 +51,11 @@ public class AlipayConfigService {
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void add(AlipayConfigParam param) {
|
||||
// 是否有管理关系判断
|
||||
if (mchAppService.checkMatch(param.getMchCode(), param.getMchAppCode())) {
|
||||
if (!mchAppService.checkMatch(param.getMchCode(), param.getMchAppCode())) {
|
||||
throw new BizException("应用信息与商户信息不匹配");
|
||||
}
|
||||
AlipayConfig alipayConfig = AlipayConfig.init(param);
|
||||
alipayConfig.setState(MchAndAppCode.PAY_CONFIG_STATE_NORMAL);
|
||||
alipayConfigManager.save(alipayConfig);
|
||||
|
||||
// 保存关联关系
|
||||
|
@@ -6,6 +6,7 @@ import cn.bootx.platform.common.core.rest.PageResult;
|
||||
import cn.bootx.platform.common.core.rest.dto.KeyValue;
|
||||
import cn.bootx.platform.common.core.rest.param.PageParam;
|
||||
import cn.bootx.platform.common.mybatisplus.util.MpUtil;
|
||||
import cn.bootx.platform.daxpay.code.MchAndAppCode;
|
||||
import cn.bootx.platform.daxpay.code.pay.PayChannelEnum;
|
||||
import cn.bootx.platform.daxpay.code.paymodel.WeChatPayWay;
|
||||
import cn.bootx.platform.daxpay.core.channel.wechat.dao.WeChatPayConfigManager;
|
||||
@@ -48,11 +49,12 @@ public class WeChatPayConfigService {
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void add(WeChatPayConfigParam param) {
|
||||
// 是否有管理关系判断
|
||||
if (mchAppService.checkMatch(param.getMchCode(), param.getMchAppCode())) {
|
||||
if (!mchAppService.checkMatch(param.getMchCode(), param.getMchAppCode())) {
|
||||
throw new BizException("应用信息与商户信息不匹配");
|
||||
}
|
||||
|
||||
WeChatPayConfig weChatPayConfig = WeChatPayConfig.init(param);
|
||||
weChatPayConfig.setState(MchAndAppCode.PAY_CONFIG_STATE_NORMAL);
|
||||
weChatPayConfigManager.save(weChatPayConfig);
|
||||
// 保存关联关系
|
||||
MchAppPayConfig mchAppPayConfig = new MchAppPayConfig().setAppCode(weChatPayConfig.getMchAppCode())
|
||||
|
@@ -23,8 +23,8 @@ import lombok.experimental.Accessors;
|
||||
public class MchAppPayConfig extends MpBaseEntity {
|
||||
|
||||
/** 关联应用编码 */
|
||||
@DbMySqlIndex(comment = "关联应用编码索引")
|
||||
@DbColumn(comment = "关联应用编码")
|
||||
@DbMySqlIndex(comment = "关联商户应用编码索引")
|
||||
@DbColumn(comment = "关联商户应用编码")
|
||||
private String appCode;
|
||||
|
||||
/** 关联配置ID */
|
||||
|
@@ -40,12 +40,12 @@ public class MchAppPayConfigService {
|
||||
/**
|
||||
* 支付通道配置列表
|
||||
*/
|
||||
public List<MchAppPayConfigResult> ListByAppId(Long appId) {
|
||||
public List<MchAppPayConfigResult> ListByAppId(String appCode) {
|
||||
// 首先查询系统中配置的支付通道进行排序
|
||||
List<PayChannelConfig> channels = channelConfigManager.findAllByOrder();
|
||||
// 查询当前应用所拥有的配置, 进行合并生成相关信息
|
||||
|
||||
val mchAppPayConfigMap = mchAppPayConfigManager.findAllByField(MchAppPayConfig::getAppCode, appId)
|
||||
val mchAppPayConfigMap = mchAppPayConfigManager.findAllByField(MchAppPayConfig::getAppCode, appCode)
|
||||
.stream()
|
||||
.collect(Collectors.toMap(MchAppPayConfig::getChannel, Function.identity()));
|
||||
// 进行排序并返回
|
||||
|
@@ -34,6 +34,10 @@ public class PayNotifyRecord extends MpBaseEntity implements EntityBaseFunction<
|
||||
@DbComment("支付记录id")
|
||||
private Long paymentId;
|
||||
|
||||
/** 商户编码 */
|
||||
@DbComment("商户编码")
|
||||
private String mchCode;
|
||||
|
||||
/** 商户应用编码 */
|
||||
@DbComment("商户应用编码")
|
||||
private String mchAppCode;
|
||||
|
@@ -36,7 +36,7 @@ public abstract class AbsPayCallbackStrategy {
|
||||
/**
|
||||
* 支付回调
|
||||
*/
|
||||
public String payCallback(String appCode, Map<String, String> params) {
|
||||
public String payCallback(String mchCode,String appCode, Map<String, String> params) {
|
||||
PARAMS.set(params);
|
||||
try {
|
||||
log.info("支付回调处理: {}", params);
|
||||
@@ -49,10 +49,10 @@ public abstract class AbsPayCallbackStrategy {
|
||||
return this.getReturnMsg();
|
||||
}
|
||||
// 调用统一回调处理
|
||||
PayCallbackResult result = payCallbackService.callback(appCode, this.getPaymentId(), this.getTradeStatus(),
|
||||
PayCallbackResult result = payCallbackService.callback(this.getPaymentId(), this.getTradeStatus(),
|
||||
params);
|
||||
// 记录回调记录
|
||||
this.saveNotifyRecord(appCode, result);
|
||||
this.saveNotifyRecord(mchCode,appCode, result);
|
||||
}
|
||||
finally {
|
||||
PARAMS.remove();
|
||||
@@ -100,14 +100,15 @@ public abstract class AbsPayCallbackStrategy {
|
||||
/**
|
||||
* 保存回调记录
|
||||
*/
|
||||
public void saveNotifyRecord(String appCode, PayCallbackResult result) {
|
||||
public void saveNotifyRecord(String mchCode,String appCode, PayCallbackResult result) {
|
||||
PayNotifyRecord payNotifyRecord = new PayNotifyRecord().setNotifyInfo(JSONUtil.toJsonStr(PARAMS.get()))
|
||||
.setNotifyTime(LocalDateTime.now())
|
||||
.setPaymentId(this.getPaymentId())
|
||||
.setMchAppCode(appCode)
|
||||
.setPayChannel(this.getPayChannel().getCode())
|
||||
.setStatus(result.getCode())
|
||||
.setMsg(result.getMsg());
|
||||
.setNotifyTime(LocalDateTime.now())
|
||||
.setPaymentId(this.getPaymentId())
|
||||
.setMchAppCode(appCode)
|
||||
.setMchCode(mchCode)
|
||||
.setPayChannel(this.getPayChannel().getCode())
|
||||
.setStatus(result.getCode())
|
||||
.setMsg(result.getMsg());
|
||||
payNotifyRecordManager.save(payNotifyRecord);
|
||||
}
|
||||
|
||||
|
@@ -44,11 +44,10 @@ public class PayCallbackService {
|
||||
|
||||
/**
|
||||
* 统一回调处理
|
||||
* @param appCode
|
||||
* @param tradeStatus 支付状态
|
||||
* @see PayStatusCode
|
||||
*/
|
||||
public PayCallbackResult callback(String appCode, Long paymentId, String tradeStatus, Map<String, String> map) {
|
||||
public PayCallbackResult callback(Long paymentId, String tradeStatus, Map<String, String> map) {
|
||||
|
||||
// 获取payment和paymentParam数据
|
||||
Payment payment = paymentService.findById(paymentId).orElse(null);
|
||||
|
@@ -1,14 +1,13 @@
|
||||
package cn.bootx.platform.daxpay.core.payment.dao;
|
||||
|
||||
import cn.bootx.platform.common.core.rest.param.OrderParam;
|
||||
import cn.bootx.platform.common.core.rest.param.PageParam;
|
||||
import cn.bootx.platform.common.mybatisplus.impl.BaseManager;
|
||||
import cn.bootx.platform.common.mybatisplus.util.MpUtil;
|
||||
import cn.bootx.platform.common.query.entity.QueryOrder;
|
||||
import cn.bootx.platform.common.query.entity.QueryParams;
|
||||
import cn.bootx.platform.common.query.generator.QueryGenerator;
|
||||
import cn.bootx.platform.daxpay.core.payment.entity.Payment;
|
||||
import cn.bootx.platform.daxpay.param.payment.PaymentQuery;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
@@ -18,7 +17,6 @@ import org.springframework.cache.annotation.Caching;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Objects;
|
||||
import java.util.Optional;
|
||||
|
||||
import static cn.bootx.platform.daxpay.code.CachingCode.PAYMENT_BUSINESS_ID;
|
||||
@@ -52,20 +50,14 @@ public class PaymentManager extends BaseManager<PaymentMapper, Payment> {
|
||||
/**
|
||||
* 分页查询
|
||||
*/
|
||||
public Page<Payment> page(PageParam pageParam, PaymentQuery param, OrderParam orderParam) {
|
||||
public Page<Payment> page(PageParam pageParam, PaymentQuery param, QueryOrder queryOrder) {
|
||||
Page<Payment> mpPage = MpUtil.getMpPage(pageParam, Payment.class);
|
||||
return query().select(Payment.class, MpUtil::excludeBigField)
|
||||
.orderBy(Objects.nonNull(orderParam.getSortField()), orderParam.isAsc(),
|
||||
StrUtil.toUnderlineCase(orderParam.getSortField()))
|
||||
.like(Objects.nonNull(param.getPaymentId()), MpUtil.getColumnName(Payment::getId), param.getPaymentId())
|
||||
.like(Objects.nonNull(param.getBusinessId()), MpUtil.getColumnName(Payment::getBusinessId),
|
||||
param.getBusinessId())
|
||||
.like(Objects.nonNull(param.getTitle()), MpUtil.getColumnName(Payment::getTitle), param.getTitle())
|
||||
.page(mpPage);
|
||||
QueryWrapper<Payment> wrapper = QueryGenerator.generator(param, queryOrder);
|
||||
return this.page(mpPage,wrapper);
|
||||
}
|
||||
|
||||
/**
|
||||
* 分页查询
|
||||
* 超级分页查询
|
||||
*/
|
||||
public Page<Payment> superPage(PageParam pageParam, QueryParams queryParams) {
|
||||
QueryWrapper<Payment> wrapper = QueryGenerator.generator(queryParams);
|
||||
|
@@ -1,6 +1,7 @@
|
||||
package cn.bootx.platform.daxpay.core.payment.entity;
|
||||
|
||||
import cn.bootx.mybatis.table.modify.annotation.DbColumn;
|
||||
import cn.bootx.mybatis.table.modify.annotation.DbComment;
|
||||
import cn.bootx.mybatis.table.modify.annotation.DbTable;
|
||||
import cn.bootx.platform.common.core.annotation.BigField;
|
||||
import cn.bootx.platform.common.core.function.EntityBaseFunction;
|
||||
@@ -31,6 +32,7 @@ import java.util.List;
|
||||
@DbTable(isAppend = true)
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@Data
|
||||
@DbComment("支付记录")
|
||||
@FieldNameConstants
|
||||
@Accessors(chain = true)
|
||||
@TableName(value = "pay_payment", autoResultMap = true)
|
||||
|
@@ -2,9 +2,9 @@ package cn.bootx.platform.daxpay.core.payment.service;
|
||||
|
||||
import cn.bootx.platform.common.core.exception.DataNotExistException;
|
||||
import cn.bootx.platform.common.core.rest.PageResult;
|
||||
import cn.bootx.platform.common.core.rest.param.OrderParam;
|
||||
import cn.bootx.platform.common.core.rest.param.PageParam;
|
||||
import cn.bootx.platform.common.mybatisplus.util.MpUtil;
|
||||
import cn.bootx.platform.common.query.entity.QueryOrder;
|
||||
import cn.bootx.platform.common.query.entity.QueryParams;
|
||||
import cn.bootx.platform.daxpay.core.payment.dao.PaymentManager;
|
||||
import cn.bootx.platform.daxpay.core.payment.entity.Payment;
|
||||
@@ -64,8 +64,8 @@ public class PaymentQueryService {
|
||||
/**
|
||||
* 分页
|
||||
*/
|
||||
public PageResult<PaymentDto> page(PageParam pageParam, PaymentQuery param, OrderParam orderParam) {
|
||||
return MpUtil.convert2DtoPageResult(paymentManager.page(pageParam, param, orderParam));
|
||||
public PageResult<PaymentDto> page(PageParam pageParam, PaymentQuery param, QueryOrder queryOrder) {
|
||||
return MpUtil.convert2DtoPageResult(paymentManager.page(pageParam, param, queryOrder));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@@ -25,7 +25,7 @@ public class MchApplicationDto extends BaseDto {
|
||||
private String name;
|
||||
|
||||
@Schema(description = "商户号")
|
||||
private String mchNo;
|
||||
private String mchCode;
|
||||
|
||||
@Schema(description = "状态类型")
|
||||
private String state;
|
||||
|
@@ -28,7 +28,7 @@ public class PaymentDto extends BaseDto implements Serializable {
|
||||
private String businessId;
|
||||
|
||||
@Schema(description = "商户编码")
|
||||
private String mchNo;
|
||||
private String mchCode;
|
||||
|
||||
@Schema(description = "商户应用编码")
|
||||
private String mchAppNo;
|
||||
|
@@ -82,7 +82,7 @@ public class WeChatPayConfigParam {
|
||||
private Boolean activity;
|
||||
|
||||
@Schema(description = "状态")
|
||||
private Integer state;
|
||||
private String state;
|
||||
|
||||
@Schema(description = "备注")
|
||||
private String remark;
|
||||
|
@@ -1,5 +1,6 @@
|
||||
package cn.bootx.platform.daxpay.param.merchant;
|
||||
|
||||
import cn.bootx.platform.common.core.annotation.QueryParam;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.Data;
|
||||
import lombok.experimental.Accessors;
|
||||
@@ -11,6 +12,7 @@ import lombok.experimental.Accessors;
|
||||
* @date 2023-05-19
|
||||
*/
|
||||
@Data
|
||||
@QueryParam(type = QueryParam.CompareTypeEnum.LIKE)
|
||||
@Schema(title = "商户应用")
|
||||
@Accessors(chain = true)
|
||||
public class MchApplicationParam {
|
||||
@@ -19,13 +21,13 @@ public class MchApplicationParam {
|
||||
private Long id;
|
||||
|
||||
@Schema(description = "应用编码")
|
||||
private String appNo;
|
||||
private String code;
|
||||
|
||||
@Schema(description = "名称")
|
||||
private String name;
|
||||
|
||||
@Schema(description = "商户号")
|
||||
private String mchNo;
|
||||
private String mchCode;
|
||||
|
||||
@Schema(description = "状态类型")
|
||||
private String state;
|
||||
|
@@ -1,5 +1,6 @@
|
||||
package cn.bootx.platform.daxpay.param.payment;
|
||||
|
||||
import cn.bootx.platform.common.core.annotation.QueryParam;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.Data;
|
||||
import lombok.experimental.Accessors;
|
||||
@@ -12,6 +13,7 @@ import java.io.Serializable;
|
||||
*/
|
||||
@Data
|
||||
@Accessors(chain = true)
|
||||
@QueryParam(type = QueryParam.CompareTypeEnum.LIKE)
|
||||
@Schema(title = "支付记录查询参数")
|
||||
public class PaymentQuery implements Serializable {
|
||||
|
||||
@@ -23,7 +25,13 @@ public class PaymentQuery implements Serializable {
|
||||
@Schema(description = "关联的业务id")
|
||||
private String businessId;
|
||||
|
||||
@Schema(description = "关联的业务id")
|
||||
@Schema(description = "标题")
|
||||
private String title;
|
||||
|
||||
@Schema(description = "商户编码")
|
||||
private String mchCode;
|
||||
|
||||
@Schema(description = "商户编应用码")
|
||||
private String mchAppCode;
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user