Przeglądaj źródła

代理费开发

xucaiqin 2 dni temu
rodzic
commit
452bd96ba3
16 zmienionych plików z 1193 dodań i 32 usunięć
  1. 5 4
      sckw-modules/sckw-payment/src/main/java/com/sckw/payment/config/ApplicationProperties.java
  2. 19 0
      sckw-modules/sckw-payment/src/main/java/com/sckw/payment/controller/WalletAgentBalanceController.java
  3. 58 0
      sckw-modules/sckw-payment/src/main/java/com/sckw/payment/controller/WalletAgentController.java
  4. 32 2
      sckw-modules/sckw-payment/src/main/java/com/sckw/payment/controller/WalletAgentRecordController.java
  5. 0 17
      sckw-modules/sckw-payment/src/main/java/com/sckw/payment/controller/WalletController.java
  6. 0 3
      sckw-modules/sckw-payment/src/main/java/com/sckw/payment/controller/WalletPrepaidController.java
  7. 43 0
      sckw-modules/sckw-payment/src/main/java/com/sckw/payment/pojo/vo/req/WalletAgentBalanceQuery.java
  8. 23 0
      sckw-modules/sckw-payment/src/main/java/com/sckw/payment/pojo/vo/req/WalletAgentManualDto.java
  9. 23 0
      sckw-modules/sckw-payment/src/main/java/com/sckw/payment/pojo/vo/req/WalletAgentPayDto.java
  10. 28 0
      sckw-modules/sckw-payment/src/main/java/com/sckw/payment/pojo/vo/req/WalletAgentQuery.java
  11. 37 0
      sckw-modules/sckw-payment/src/main/java/com/sckw/payment/pojo/vo/req/WalletAgentRecordQuery.java
  12. 56 0
      sckw-modules/sckw-payment/src/main/java/com/sckw/payment/pojo/vo/res/WalletAgentBalanceRes.java
  13. 44 0
      sckw-modules/sckw-payment/src/main/java/com/sckw/payment/pojo/vo/res/WalletAgentRecordRes.java
  14. 38 0
      sckw-modules/sckw-payment/src/main/java/com/sckw/payment/pojo/vo/res/WalletAgentRes.java
  15. 15 0
      sckw-modules/sckw-payment/src/main/java/com/sckw/payment/pojo/vo/res/WalletAgentSummary.java
  16. 772 6
      sckw-modules/sckw-payment/src/main/java/com/sckw/payment/service/impl/WalletAgentService.java

+ 5 - 4
sckw-modules/sckw-payment/src/main/java/com/sckw/payment/config/ApplicationProperties.java

@@ -9,12 +9,13 @@ import org.springframework.context.annotation.Configuration;
 @ConfigurationProperties(prefix = "payment.xw")
 public class ApplicationProperties {
     private String url;
+    //预付到账回调
     private String charge;
+    //运费到账回调
+    private String charge2;
+    //代理费到账回调
+    private String charge3;
     private String prefix;
-    private String appId;
-    private Integer platNo;
-    private String amtMaxOrder;
-    private String amtMaxDay;
     private String account;
     private String split;
     private String cash;

+ 19 - 0
sckw-modules/sckw-payment/src/main/java/com/sckw/payment/controller/WalletAgentBalanceController.java

@@ -1,7 +1,18 @@
 package com.sckw.payment.controller;
 
+import com.github.pagehelper.PageInfo;
+import com.sckw.core.web.response.BaseResult;
+import com.sckw.core.web.response.result.PageDataResult;
+import com.sckw.payment.pojo.vo.req.WalletAgentBalanceQuery;
+import com.sckw.payment.pojo.vo.res.WalletAgentBalanceRes;
+import com.sckw.payment.service.impl.WalletAgentService;
+import io.swagger.v3.oas.annotations.Operation;
 import io.swagger.v3.oas.annotations.tags.Tag;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.validation.annotation.Validated;
+import org.springframework.web.bind.annotation.PostMapping;
 import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RequestBody;
 import org.springframework.web.bind.annotation.RestController;
 
 
@@ -10,6 +21,14 @@ import org.springframework.web.bind.annotation.RestController;
 @RequestMapping("/walletAgent/balance")
 public class WalletAgentBalanceController {
 
+    @Autowired
+    private WalletAgentService walletAgentService;
 
+    @Operation(summary = "分页查询代理费余额明细列表")
+    @PostMapping("/list")
+    public BaseResult<PageDataResult<WalletAgentBalanceRes>> list(@RequestBody @Validated WalletAgentBalanceQuery query) {
+        PageInfo<WalletAgentBalanceRes> list = walletAgentService.balanceList(query);
+        return BaseResult.success(PageDataResult.of(list));
+    }
 
 }

+ 58 - 0
sckw-modules/sckw-payment/src/main/java/com/sckw/payment/controller/WalletAgentController.java

@@ -1,15 +1,73 @@
 package com.sckw.payment.controller;
 
+import com.github.pagehelper.PageInfo;
+import com.sckw.core.web.response.BaseResult;
+import com.sckw.core.web.response.result.PageDataResult;
+import com.sckw.payment.api.model.TradeEntInfoResVo;
+import com.sckw.payment.pojo.vo.req.ReceivedCallbackDto;
+import com.sckw.payment.pojo.vo.req.WalletAgentManualDto;
+import com.sckw.payment.pojo.vo.req.WalletAgentPayDto;
+import com.sckw.payment.pojo.vo.req.WalletAgentQuery;
+import com.sckw.payment.pojo.vo.res.WalletAgentRes;
+import com.sckw.payment.pojo.vo.res.WalletAgentSummary;
+import com.sckw.payment.pojo.vo.res.WalletPayAddRes;
+import com.sckw.payment.service.impl.WalletAgentService;
+import io.swagger.v3.oas.annotations.Operation;
 import io.swagger.v3.oas.annotations.tags.Tag;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.validation.annotation.Validated;
+import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.PostMapping;
 import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RequestBody;
 import org.springframework.web.bind.annotation.RestController;
 
+import java.util.List;
+
 
 @Tag(name = "代理账户")
 @RestController
 @RequestMapping("/walletAgent")
 public class WalletAgentController {
 
+    @Autowired
+    private WalletAgentService walletAgentService;
+
+    @Operation(summary = "查询待付代理费汇总")
+    @GetMapping("/queryAgentSummary")
+    public BaseResult<WalletAgentSummary> queryAgentSummary() {
+        return BaseResult.success(walletAgentService.queryAgentSummary());
+    }
+
+    @Operation(summary = "分页查询待付代理费列表")
+    @PostMapping("/agentList")
+    public BaseResult<PageDataResult<WalletAgentRes>> agentList(@RequestBody @Validated WalletAgentQuery query) {
+        PageInfo<WalletAgentRes> list = walletAgentService.agentList(query);
+        return BaseResult.success(PageDataResult.of(list));
+    }
+
+    @Operation(summary = "查询交易对方企业列表")
+    @GetMapping("/queryTradeEntList")
+    public BaseResult<List<TradeEntInfoResVo>> queryTradeEntList() {
+        return BaseResult.success(walletAgentService.queryTradeEntList());
+    }
+
+    @Operation(summary = "发起代理费付款")
+    @PostMapping("/pay")
+    public BaseResult<WalletPayAddRes> pay(@RequestBody @Validated WalletAgentPayDto payDto) {
+        return walletAgentService.pay(payDto);
+    }
 
+    @Operation(summary = "人工录入(线下收款)")
+    @PostMapping("/manualEntry")
+    public BaseResult<Object> manualEntry(@RequestBody @Validated WalletAgentManualDto manualDto) {
+        return walletAgentService.manualEntry(manualDto);
+    }
 
+    @Operation(summary = "代理费到账回调接口")
+    @PostMapping("/receivedCallback")
+    public BaseResult<Object> receivedCallback(@RequestBody @Validated ReceivedCallbackDto receivedCallbackDto) {
+        walletAgentService.receivedCallback(receivedCallbackDto);
+        return BaseResult.success();
+    }
 }

+ 32 - 2
sckw-modules/sckw-payment/src/main/java/com/sckw/payment/controller/WalletAgentRecordController.java

@@ -1,8 +1,19 @@
 package com.sckw.payment.controller;
 
+import com.github.pagehelper.PageInfo;
+import com.sckw.core.web.response.BaseResult;
+import com.sckw.core.web.response.result.PageDataResult;
+import com.sckw.payment.pojo.vo.req.WalletAgentRecordQuery;
+import com.sckw.payment.pojo.vo.res.WalletAgentRecordRes;
+import com.sckw.payment.pojo.vo.res.WalletPayAddRes;
+import com.sckw.payment.service.impl.WalletAgentService;
+import io.swagger.v3.oas.annotations.Operation;
 import io.swagger.v3.oas.annotations.tags.Tag;
-import org.springframework.web.bind.annotation.RequestMapping;
-import org.springframework.web.bind.annotation.RestController;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.validation.annotation.Validated;
+import org.springframework.web.bind.annotation.*;
+
+import java.util.List;
 
 
 @Tag(name = "代理账户支付记录")
@@ -10,6 +21,25 @@ import org.springframework.web.bind.annotation.RestController;
 @RequestMapping("/walletAgent/record")
 public class WalletAgentRecordController {
 
+    @Autowired
+    private WalletAgentService walletAgentService;
+
+    @Operation(summary = "分页查询代理费支付记录列表")
+    @PostMapping("/list")
+    public BaseResult<PageDataResult<WalletAgentRecordRes>> list(@RequestBody @Validated WalletAgentRecordQuery query) {
+        PageInfo<WalletAgentRecordRes> list = walletAgentService.recordList(query);
+        return BaseResult.success(PageDataResult.of(list));
+    }
 
+    @Operation(summary = "查询付款信息")
+    @GetMapping("/getPayInfo")
+    public BaseResult<WalletPayAddRes> getPayInfo(@RequestParam("id") Long id) {
+        return walletAgentService.getPayInfo(id);
+    }
 
+    @Operation(summary = "查询历史支付记录信息")
+    @GetMapping("/get")
+    public BaseResult<List<WalletAgentRecordRes>> getPay(@RequestParam("agentId") Long agentId) {
+        return walletAgentService.getPayList(agentId);
+    }
 }

+ 0 - 17
sckw-modules/sckw-payment/src/main/java/com/sckw/payment/controller/WalletController.java

@@ -119,23 +119,6 @@ public class WalletController {
     }
     //1、查询钱包信息
 
-    /**
-     * 企业用户钱包查询
-     *
-     * @return
-     */
-//    @GetMapping("/queryWalletInfo")
-//    public BaseResult queryWalletInfo() {
-//        Wallet wallet = walletService.selectWalletByEntId(LoginUserHolder.getEntId());
-//        if (Objects.isNull(wallet)) {
-//            return BaseResult.success("钱包账号不存在");
-//        }
-//        return BaseResult.success(wallet);
-////        BankService bankService = BankServiceUtil.getBankService(properties.getBankCode());
-////        bankService.queryWalletInfo(wallet);
-//    }
-
-
     //查询钱包可提现、预付余额及运费的汇总接口
     @Operation(summary = "查询钱包可提现、预付余额及运费的汇总接口")
     @GetMapping("/querySummary")

+ 0 - 3
sckw-modules/sckw-payment/src/main/java/com/sckw/payment/controller/WalletPrepaidController.java

@@ -146,7 +146,6 @@ public class WalletPrepaidController  {
      *
      * @return ModelAndView
      */
-
     @Operation(summary = "人工录入")
     @PostMapping("/manualEntry")
     public BaseResult<Object> manualEntry(@RequestBody @Validated WalletPrepaidManualDto performanceAddDto) {
@@ -162,8 +161,6 @@ public class WalletPrepaidController  {
      *
      * @return ModelAndView
      */
-
-
     @Operation(summary = "预付")
     @PostMapping("/prepay")
     public BaseResult<WalletPayAddRes> prepay(@RequestBody @Validated WalletPrepaidAddDto prepaidAddDto) {

+ 43 - 0
sckw-modules/sckw-payment/src/main/java/com/sckw/payment/pojo/vo/req/WalletAgentBalanceQuery.java

@@ -0,0 +1,43 @@
+package com.sckw.payment.pojo.vo.req;
+
+import com.sckw.core.web.page.BaseQuery;
+import io.swagger.v3.oas.annotations.media.Schema;
+import lombok.Data;
+
+import java.math.BigDecimal;
+
+@Data
+public class WalletAgentBalanceQuery extends BaseQuery {
+    @Schema(description = "代理费清单id")
+    private Long agentId;
+
+    @Schema(description = "订单号(模糊匹配)")
+    private String orderNo;
+
+    @Schema(description = "对方企业id")
+    private Long tradeEntId;
+
+    @Schema(description = "对方企业名称(模糊匹配)")
+    private String tradeEntName;
+
+    @Schema(description = "订单类型")
+    private Integer orderType;
+
+    @Schema(description = "交易类型 1-消费 2-申请付款 3-付款成功 4-人工录入")
+    private Integer tradeType;
+
+    @Schema(description = "金额最小值")
+    private BigDecimal tradeAmountMin;
+
+    @Schema(description = "金额最大值")
+    private BigDecimal tradeAmountMax;
+
+    @Schema(description = "执行状态 1-进行中 2-成功 3-失败")
+    private Integer status;
+
+    @Schema(description = "查询开始时间,yyyy-MM-dd HH:mm:ss")
+    private String startTime;
+
+    @Schema(description = "查询结束时间,yyyy-MM-dd HH:mm:ss")
+    private String endTime;
+}

+ 23 - 0
sckw-modules/sckw-payment/src/main/java/com/sckw/payment/pojo/vo/req/WalletAgentManualDto.java

@@ -0,0 +1,23 @@
+package com.sckw.payment.pojo.vo.req;
+
+import io.swagger.v3.oas.annotations.media.Schema;
+import jakarta.validation.constraints.DecimalMin;
+import jakarta.validation.constraints.NotNull;
+import lombok.Data;
+
+import java.math.BigDecimal;
+
+@Data
+public class WalletAgentManualDto {
+    @Schema(description = "对方企业id")
+    @NotNull
+    private Long tradeEntId;
+
+    @Schema(description = "金额")
+    @NotNull
+    @DecimalMin(value = "0.01", message = "金额必须大于0")
+    private BigDecimal amount;
+
+    @Schema(description = "备注")
+    private String remark;
+}

+ 23 - 0
sckw-modules/sckw-payment/src/main/java/com/sckw/payment/pojo/vo/req/WalletAgentPayDto.java

@@ -0,0 +1,23 @@
+package com.sckw.payment.pojo.vo.req;
+
+import io.swagger.v3.oas.annotations.media.Schema;
+import jakarta.validation.constraints.DecimalMin;
+import jakarta.validation.constraints.NotNull;
+import lombok.Data;
+
+import java.math.BigDecimal;
+
+@Data
+public class WalletAgentPayDto {
+    @Schema(description = "代理费清单id")
+    @NotNull
+    private Long agentId;
+
+    @Schema(description = "付款金额")
+    @NotNull
+    @DecimalMin(value = "0.01", message = "付款金额必须大于0")
+    private BigDecimal payAmount;
+
+    @Schema(description = "备注")
+    private String remark;
+}

+ 28 - 0
sckw-modules/sckw-payment/src/main/java/com/sckw/payment/pojo/vo/req/WalletAgentQuery.java

@@ -0,0 +1,28 @@
+package com.sckw.payment.pojo.vo.req;
+
+import com.sckw.core.web.page.BaseQuery;
+import io.swagger.v3.oas.annotations.media.Schema;
+import lombok.Data;
+
+import java.math.BigDecimal;
+
+@Data
+public class WalletAgentQuery extends BaseQuery {
+    @Schema(description = "对方企业id")
+    private Long tradeEntId;
+
+    @Schema(description = "对方企业名称(模糊匹配)")
+    private String tradeEntName;
+
+    @Schema(description = "待付代理费最小值")
+    private BigDecimal preBalanceMin;
+
+    @Schema(description = "待付代理费最大值")
+    private BigDecimal preBalanceMax;
+
+    @Schema(description = "付款中金额最小值")
+    private BigDecimal tradingAmountMin;
+
+    @Schema(description = "付款中金额最大值")
+    private BigDecimal tradingAmountMax;
+}

+ 37 - 0
sckw-modules/sckw-payment/src/main/java/com/sckw/payment/pojo/vo/req/WalletAgentRecordQuery.java

@@ -0,0 +1,37 @@
+package com.sckw.payment.pojo.vo.req;
+
+import com.sckw.core.web.page.BaseQuery;
+import io.swagger.v3.oas.annotations.media.Schema;
+import lombok.Data;
+
+import java.math.BigDecimal;
+
+@Data
+public class WalletAgentRecordQuery extends BaseQuery {
+    @Schema(description = "代理费清单id")
+    private Long agentId;
+
+    @Schema(description = "订单号(模糊匹配)")
+    private String orderNo;
+
+    @Schema(description = "对方企业id")
+    private Long tradeEntId;
+
+    @Schema(description = "对方企业名称(模糊匹配)")
+    private String tradeEntName;
+
+    @Schema(description = "支付金额最小值")
+    private BigDecimal prepaidAmountMin;
+
+    @Schema(description = "支付金额最大值")
+    private BigDecimal prepaidAmountMax;
+
+    @Schema(description = "支付状态,0-等待支付 1-支付成功")
+    private Integer status;
+
+    @Schema(description = "查询开始时间,yyyy-MM-dd HH:mm:ss")
+    private String startTime;
+
+    @Schema(description = "查询结束时间,yyyy-MM-dd HH:mm:ss")
+    private String endTime;
+}

+ 56 - 0
sckw-modules/sckw-payment/src/main/java/com/sckw/payment/pojo/vo/res/WalletAgentBalanceRes.java

@@ -0,0 +1,56 @@
+package com.sckw.payment.pojo.vo.res;
+
+import com.fasterxml.jackson.annotation.JsonFormat;
+import io.swagger.v3.oas.annotations.media.Schema;
+import lombok.Data;
+
+import java.math.BigDecimal;
+import java.util.Date;
+
+@Data
+public class WalletAgentBalanceRes {
+    @Schema(description = "明细id")
+    @JsonFormat(shape = JsonFormat.Shape.STRING)
+    private Long id;
+
+    @Schema(description = "关联订单编号")
+    private String orderNo;
+
+    @Schema(description = "对方企业id")
+    @JsonFormat(shape = JsonFormat.Shape.STRING)
+    private Long tradeEntId;
+
+    @Schema(description = "对方企业名称")
+    private String tradeEntName;
+
+    @Schema(description = "订单类型")
+    private Integer orderType;
+
+    @Schema(description = "交易类型 1-消费 2-申请付款 3-付款成功 4-人工录入")
+    private Integer tradeType;
+
+    @Schema(description = "交易类型描述")
+    private String tradeTypeDesc;
+
+    @Schema(description = "交易金额")
+    private BigDecimal tradeAmount;
+
+    @Schema(description = "待付代理费余额")
+    private BigDecimal preBalance;
+
+    @Schema(description = "交易中金额")
+    private BigDecimal tradingAmount;
+
+    @Schema(description = "执行状态 1-进行中 2-成功 3-失败")
+    private Integer status;
+
+    @Schema(description = "执行状态描述")
+    private String statusDesc;
+
+    @Schema(description = "备注")
+    private String remark;
+
+    @Schema(description = "创建时间")
+    @JsonFormat(timezone = "GMT+8", pattern = "yyyy-MM-dd HH:mm:ss")
+    private Date createTime;
+}

+ 44 - 0
sckw-modules/sckw-payment/src/main/java/com/sckw/payment/pojo/vo/res/WalletAgentRecordRes.java

@@ -0,0 +1,44 @@
+package com.sckw.payment.pojo.vo.res;
+
+import com.fasterxml.jackson.annotation.JsonFormat;
+import io.swagger.v3.oas.annotations.media.Schema;
+import lombok.Data;
+
+import java.math.BigDecimal;
+import java.util.Date;
+
+@Data
+public class WalletAgentRecordRes {
+    @Schema(description = "支付记录id")
+    @JsonFormat(shape = JsonFormat.Shape.STRING)
+    private Long id;
+
+    @Schema(description = "支付订单号")
+    private String orderNo;
+
+    @Schema(description = "对方企业id")
+    @JsonFormat(shape = JsonFormat.Shape.STRING)
+    private Long tradeEntId;
+
+    @Schema(description = "对方企业名称")
+    private String tradeEntName;
+
+    @Schema(description = "支付金额")
+    private BigDecimal prepaidAmount;
+
+    @Schema(description = "到账金额")
+    private BigDecimal receivedAmount;
+
+    @Schema(description = "支付状态,0-等待支付 1-支付成功")
+    private Integer status;
+
+    @Schema(description = "支付状态描述")
+    private String statusDesc;
+
+    @Schema(description = "备注")
+    private String remark;
+
+    @Schema(description = "创建时间")
+    @JsonFormat(timezone = "GMT+8", pattern = "yyyy-MM-dd HH:mm:ss")
+    private Date createTime;
+}

+ 38 - 0
sckw-modules/sckw-payment/src/main/java/com/sckw/payment/pojo/vo/res/WalletAgentRes.java

@@ -0,0 +1,38 @@
+package com.sckw.payment.pojo.vo.res;
+
+import com.fasterxml.jackson.annotation.JsonFormat;
+import io.swagger.v3.oas.annotations.media.Schema;
+import lombok.Data;
+
+import java.math.BigDecimal;
+import java.util.Date;
+
+@Data
+public class WalletAgentRes {
+    @Schema(description = "代理费清单id")
+    @JsonFormat(shape = JsonFormat.Shape.STRING)
+    private Long id;
+
+    @Schema(description = "对方企业id")
+    @JsonFormat(shape = JsonFormat.Shape.STRING)
+    private Long tradeEntId;
+
+    @Schema(description = "对方企业名称")
+    private String tradeEntName;
+
+    @Schema(description = "待付代理费")
+    private BigDecimal preBalance;
+
+    @Schema(description = "付款中金额")
+    private BigDecimal tradingAmount;
+
+    @Schema(description = "更新时间")
+    @JsonFormat(timezone = "GMT+8", pattern = "yyyy-MM-dd HH:mm:ss")
+    private Date updateTime;
+
+    @Schema(description = "是否可付款 1-是 0-否")
+    private Integer canPay;
+
+    @Schema(description = "是否可人工录入 1-是 0-否")
+    private Integer canManualEntry;
+}

+ 15 - 0
sckw-modules/sckw-payment/src/main/java/com/sckw/payment/pojo/vo/res/WalletAgentSummary.java

@@ -0,0 +1,15 @@
+package com.sckw.payment.pojo.vo.res;
+
+import io.swagger.v3.oas.annotations.media.Schema;
+import lombok.Data;
+
+import java.math.BigDecimal;
+
+@Data
+public class WalletAgentSummary {
+    @Schema(description = "待付代理费")
+    private BigDecimal preBalanceTotal = BigDecimal.ZERO;
+
+    @Schema(description = "付款中金额")
+    private BigDecimal tradingAmountTotal = BigDecimal.ZERO;
+}

+ 772 - 6
sckw-modules/sckw-payment/src/main/java/com/sckw/payment/service/impl/WalletAgentService.java

@@ -1,16 +1,782 @@
 package com.sckw.payment.service.impl;
 
-import org.springframework.stereotype.Service;
-import org.springframework.beans.factory.annotation.Autowired;
-import java.util.List;
+import com.alibaba.fastjson2.JSONObject;
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
+import com.baomidou.mybatisplus.core.toolkit.Wrappers;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import com.github.pagehelper.Page;
+import com.github.pagehelper.PageInfo;
+import com.sckw.core.exception.BusinessException;
+import com.sckw.core.model.enums.EntTypeEnum;
+import com.sckw.core.utils.PageUtils;
+import com.sckw.core.web.context.LoginEntHolder;
+import com.sckw.core.web.context.LoginUserHolder;
+import com.sckw.core.web.response.BaseResult;
+import com.sckw.payment.config.ApplicationProperties;
 import com.sckw.payment.entity.WalletAgent;
+import com.sckw.payment.entity.WalletAgentBalance;
+import com.sckw.payment.entity.WalletAgentRecord;
+import com.sckw.payment.entity.KwpWallet;
+import com.sckw.payment.enums.ExecutionStatusEnum;
+import com.sckw.payment.enums.OrderTypeEnum;
+import com.sckw.payment.enums.PayStatusEnum;
 import com.sckw.payment.mapper.WalletAgentMapper;
+import com.sckw.payment.mapper.WalletAgentBalanceMapper;
+import com.sckw.payment.mapper.WalletAgentRecordMapper;
+import com.sckw.payment.mapper.KwpWalletMapper;
+import com.sckw.payment.pojo.dto.PayDto;
+import com.sckw.payment.pojo.vo.PayRes;
+import com.sckw.payment.pojo.vo.req.ReceivedCallbackDto;
+import com.sckw.payment.pojo.vo.req.WalletAgentManualDto;
+import com.sckw.payment.pojo.vo.req.WalletAgentBalanceQuery;
+import com.sckw.payment.pojo.vo.req.WalletAgentPayDto;
+import com.sckw.payment.pojo.vo.req.WalletAgentQuery;
+import com.sckw.payment.pojo.vo.req.WalletAgentRecordQuery;
+import com.sckw.payment.pojo.vo.res.WalletAgentBalanceRes;
+import com.sckw.payment.pojo.vo.res.WalletAgentRecordRes;
+import com.sckw.payment.pojo.vo.res.WalletAgentRes;
+import com.sckw.payment.pojo.vo.res.WalletAgentSummary;
+import com.sckw.payment.pojo.vo.res.WalletPayAddRes;
+import com.sckw.payment.service.PayXwService;
+import com.sckw.payment.api.model.dto.common.R;
+import com.sckw.payment.api.model.TradeEntInfoResVo;
+import com.sckw.system.api.RemoteSystemService;
+import com.sckw.system.api.model.dto.res.EntCacheResDto;
+import jakarta.annotation.Resource;
+import org.apache.dubbo.config.annotation.DubboReference;
+import org.springframework.beans.BeanUtils;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+import org.springframework.util.CollectionUtils;
+import org.springframework.util.StringUtils;
+
+import java.math.BigDecimal;
+import java.time.LocalDateTime;
+import java.time.ZoneId;
+import java.time.format.DateTimeFormatter;
+import java.util.ArrayList;
+import java.util.Date;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Objects;
+import java.util.stream.Collectors;
+
 /**
-* @date 2026-06-15 10:58:32
-* @author xucaiqin
-*/
+ * @author xucaiqin
+ * @date 2026-06-15 10:58:32
+ */
 @Service
 public class WalletAgentService extends ServiceImpl<WalletAgentMapper, WalletAgent> {
 
+    private static final DateTimeFormatter DATE_TIME_FORMATTER = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
+
+    @Autowired
+    private WalletAgentRecordMapper walletAgentRecordMapper;
+
+    @Autowired
+    private WalletAgentBalanceMapper walletAgentBalanceMapper;
+
+    @Autowired
+    private PayXwService payXwService;
+
+    @Autowired
+    private KwpWalletMapper kwpWalletMapper;
+    @Resource
+    private ApplicationProperties applicationProperties;
+
+    @DubboReference(version = "1.0.0", group = "design", check = false, timeout = 8000)
+    private RemoteSystemService remoteSystemService;
+
+    public WalletAgentSummary queryAgentSummary() {
+        WalletAgentSummary summary = new WalletAgentSummary();
+        Long curEntId = LoginEntHolder.getEntId();
+        boolean proxy = isProxyEnt();
+
+        LambdaQueryWrapper<WalletAgent> wrapper = Wrappers.lambdaQuery(WalletAgent.class)
+                .eq(WalletAgent::getDelFlag, 0)
+                .eq(proxy ? WalletAgent::getAgtEntId : WalletAgent::getSupEntId, curEntId);
+
+        List<WalletAgent> list = baseMapper.selectList(wrapper);
+        if (CollectionUtils.isEmpty(list)) {
+            return summary;
+        }
+        BigDecimal preTotal = list.stream()
+                .map(WalletAgent::getPreBalance)
+                .filter(Objects::nonNull)
+                .reduce(BigDecimal.ZERO, BigDecimal::add);
+        BigDecimal tradingTotal = list.stream()
+                .map(WalletAgent::getTradingAmount)
+                .filter(Objects::nonNull)
+                .reduce(BigDecimal.ZERO, BigDecimal::add);
+        summary.setPreBalanceTotal(preTotal);
+        summary.setTradingAmountTotal(tradingTotal);
+        return summary;
+    }
+
+    public PageInfo<WalletAgentRes> agentList(WalletAgentQuery query) {
+        PageInfo<WalletAgentRes> pageInfo = new PageInfo<>(new ArrayList<>());
+        Long curEntId = LoginEntHolder.getEntId();
+        boolean proxy = isProxyEnt();
+
+        LambdaQueryWrapper<WalletAgent> wrapper = Wrappers.lambdaQuery(WalletAgent.class)
+                .eq(WalletAgent::getDelFlag, 0)
+                .eq(proxy ? WalletAgent::getAgtEntId : WalletAgent::getSupEntId, curEntId);
+
+        if (query.getTradeEntId() != null) {
+            wrapper.eq(proxy ? WalletAgent::getSupEntId : WalletAgent::getAgtEntId, query.getTradeEntId());
+        } else if (StringUtils.hasText(query.getTradeEntName())) {
+            List<EntCacheResDto> entCacheResDtos = remoteSystemService.queryEntCacheByName(query.getTradeEntName());
+            if (CollectionUtils.isEmpty(entCacheResDtos)) {
+                return pageInfo;
+            }
+            List<Long> ids = entCacheResDtos.stream().map(EntCacheResDto::getId).distinct().toList();
+            wrapper.in(proxy ? WalletAgent::getSupEntId : WalletAgent::getAgtEntId, ids);
+        }
+
+        if (query.getPreBalanceMin() != null) {
+            wrapper.ge(WalletAgent::getPreBalance, query.getPreBalanceMin());
+        }
+        if (query.getPreBalanceMax() != null) {
+            wrapper.le(WalletAgent::getPreBalance, query.getPreBalanceMax());
+        }
+        if (query.getTradingAmountMin() != null) {
+            wrapper.ge(WalletAgent::getTradingAmount, query.getTradingAmountMin());
+        }
+        if (query.getTradingAmountMax() != null) {
+            wrapper.le(WalletAgent::getTradingAmount, query.getTradingAmountMax());
+        }
+
+        wrapper.orderByDesc(WalletAgent::getUpdateTime, WalletAgent::getId);
+
+        PageUtils.startPage(query);
+        List<WalletAgent> walletAgents = baseMapper.selectList(wrapper);
+        if (CollectionUtils.isEmpty(walletAgents)) {
+            return pageInfo;
+        }
+
+        List<Long> tradeEntIds = walletAgents.stream()
+                .map(e -> proxy ? e.getSupEntId() : e.getAgtEntId())
+                .filter(Objects::nonNull)
+                .distinct()
+                .toList();
+        Map<Long, String> entNameMap = new HashMap<>();
+        if (!CollectionUtils.isEmpty(tradeEntIds)) {
+            List<EntCacheResDto> entInfos = remoteSystemService.queryEntCacheByIds(tradeEntIds);
+            if (!CollectionUtils.isEmpty(entInfos)) {
+                entNameMap = entInfos.stream().collect(Collectors.toMap(EntCacheResDto::getId, EntCacheResDto::getFirmName, (a, b) -> a));
+            }
+        }
+
+        Map<Long, String> finalEntNameMap = entNameMap;
+        pageInfo = ((Page<WalletAgent>) walletAgents).toPageInfo(e -> {
+            WalletAgentRes res = new WalletAgentRes();
+            res.setId(e.getId());
+            Long tradeEntId = proxy ? e.getSupEntId() : e.getAgtEntId();
+            res.setTradeEntId(tradeEntId);
+            res.setTradeEntName(finalEntNameMap.getOrDefault(tradeEntId, ""));
+            res.setPreBalance(e.getPreBalance());
+            res.setTradingAmount(e.getTradingAmount());
+            res.setUpdateTime(toDate(e.getUpdateTime()));
+            res.setCanPay(proxy ? 0 : (e.getPreBalance() != null && e.getPreBalance().compareTo(BigDecimal.ZERO) > 0 ? 1 : 0));
+            res.setCanManualEntry(proxy && e.getPreBalance() != null && e.getPreBalance().compareTo(BigDecimal.ZERO) > 0 ? 1 : 0);
+            return res;
+        });
+        return pageInfo;
+    }
+
+    public List<TradeEntInfoResVo> queryTradeEntList() {
+        boolean proxy = isProxyEnt();
+        Long curEntId = LoginEntHolder.getEntId();
+
+        LambdaQueryWrapper<WalletAgent> wrapper = Wrappers.lambdaQuery(WalletAgent.class)
+                .select(WalletAgent::getAgtEntId, WalletAgent::getSupEntId)
+                .eq(WalletAgent::getDelFlag, 0)
+                .eq(proxy ? WalletAgent::getAgtEntId : WalletAgent::getSupEntId, curEntId);
+
+        List<WalletAgent> list = baseMapper.selectList(wrapper);
+        if (CollectionUtils.isEmpty(list)) {
+            return new ArrayList<>();
+        }
+        List<Long> tradeEntIds = list.stream()
+                .map(e -> proxy ? e.getSupEntId() : e.getAgtEntId())
+                .filter(Objects::nonNull)
+                .distinct()
+                .toList();
+        if (CollectionUtils.isEmpty(tradeEntIds)) {
+            return new ArrayList<>();
+        }
+        List<EntCacheResDto> entInfos = remoteSystemService.queryEntCacheByIds(tradeEntIds);
+        if (CollectionUtils.isEmpty(entInfos)) {
+            return new ArrayList<>();
+        }
+        return entInfos.stream().map(e -> {
+            TradeEntInfoResVo vo = new TradeEntInfoResVo();
+            vo.setEntId(e.getId());
+            vo.setEntName(e.getFirmName());
+            return vo;
+        }).toList();
+    }
+
+    public PageInfo<WalletAgentBalanceRes> balanceList(WalletAgentBalanceQuery query) {
+        PageInfo<WalletAgentBalanceRes> pageInfo = new PageInfo<>(new ArrayList<>());
+        Long curEntId = LoginEntHolder.getEntId();
+        boolean proxy = isProxyEnt();
+
+        Long agtEntId;
+        Long supEntId;
+        if (query.getAgentId() != null) {
+            WalletAgent walletAgent = baseMapper.selectById(query.getAgentId());
+            if (walletAgent == null || !Objects.equals(walletAgent.getDelFlag(), 0)) {
+                return pageInfo;
+            }
+            if (!Objects.equals(walletAgent.getSupEntId(), curEntId) && !Objects.equals(walletAgent.getAgtEntId(), curEntId)) {
+                throw new BusinessException("无权限查看该代理费明细");
+            }
+            agtEntId = walletAgent.getAgtEntId();
+            supEntId = walletAgent.getSupEntId();
+        } else {
+            agtEntId = proxy ? curEntId : null;
+            supEntId = proxy ? null : curEntId;
+        }
+
+        LambdaQueryWrapper<WalletAgentBalance> wrapper = Wrappers.lambdaQuery(WalletAgentBalance.class)
+                .eq(WalletAgentBalance::getDelFlag, 0);
+
+        if (agtEntId != null) {
+            wrapper.eq(WalletAgentBalance::getAgtEntId, agtEntId);
+        }
+        if (supEntId != null) {
+            wrapper.eq(WalletAgentBalance::getSupEntId, supEntId);
+        }
+
+        if (StringUtils.hasText(query.getOrderNo())) {
+            wrapper.like(WalletAgentBalance::getOrderNo, query.getOrderNo());
+        }
+        if (query.getOrderType() != null) {
+            wrapper.eq(WalletAgentBalance::getOrderType, query.getOrderType());
+        }
+
+        if (query.getTradeType() != null) {
+            wrapper.eq(WalletAgentBalance::getTradeType, query.getTradeType());
+        }
+        if (query.getTradeAmountMin() != null) {
+            wrapper.ge(WalletAgentBalance::getTradeAmount, query.getTradeAmountMin());
+        }
+        if (query.getTradeAmountMax() != null) {
+            wrapper.le(WalletAgentBalance::getTradeAmount, query.getTradeAmountMax());
+        }
+        if (query.getStatus() != null) {
+            wrapper.eq(WalletAgentBalance::getStatus, query.getStatus());
+        }
+
+        if (query.getTradeEntId() != null || StringUtils.hasText(query.getTradeEntName())) {
+            List<Long> tradeEntIds;
+            if (query.getTradeEntId() != null) {
+                tradeEntIds = List.of(query.getTradeEntId());
+            } else {
+                List<EntCacheResDto> entCacheResDtos = remoteSystemService.queryEntCacheByName(query.getTradeEntName());
+                if (CollectionUtils.isEmpty(entCacheResDtos)) {
+                    return pageInfo;
+                }
+                tradeEntIds = entCacheResDtos.stream().map(EntCacheResDto::getId).distinct().toList();
+            }
+            if (proxy) {
+                wrapper.in(WalletAgentBalance::getSupEntId, tradeEntIds);
+            } else {
+                wrapper.in(WalletAgentBalance::getAgtEntId, tradeEntIds);
+            }
+        }
+
+        LocalDateTime startTime = parseDateTime(query.getStartTime());
+        LocalDateTime endTime = parseDateTime(query.getEndTime());
+        if (startTime != null) {
+            wrapper.ge(WalletAgentBalance::getCreateTime, startTime);
+        }
+        if (endTime != null) {
+            wrapper.le(WalletAgentBalance::getCreateTime, endTime);
+        }
+        wrapper.orderByDesc(WalletAgentBalance::getCreateTime, WalletAgentBalance::getId);
+
+        PageUtils.startPage(query);
+        List<WalletAgentBalance> list = walletAgentBalanceMapper.selectList(wrapper);
+        if (CollectionUtils.isEmpty(list)) {
+            return pageInfo;
+        }
+
+        List<Long> tradeEntIdList = list.stream()
+                .map(e -> proxy ? e.getSupEntId() : e.getAgtEntId())
+                .filter(Objects::nonNull)
+                .distinct()
+                .toList();
+        Map<Long, String> entNameMap = new HashMap<>();
+        if (!CollectionUtils.isEmpty(tradeEntIdList)) {
+            List<EntCacheResDto> entInfos = remoteSystemService.queryEntCacheByIds(tradeEntIdList);
+            if (!CollectionUtils.isEmpty(entInfos)) {
+                entNameMap = entInfos.stream().collect(Collectors.toMap(EntCacheResDto::getId, EntCacheResDto::getFirmName, (a, b) -> a));
+            }
+        }
+        Map<Long, String> finalEntNameMap = entNameMap;
+
+        pageInfo = ((Page<WalletAgentBalance>) list).toPageInfo(e -> {
+            WalletAgentBalanceRes res = new WalletAgentBalanceRes();
+            BeanUtils.copyProperties(e, res);
+            res.setStatusDesc(ExecutionStatusEnum.getByCode(e.getStatus()));
+            Long tradeEntId = proxy ? e.getSupEntId() : e.getAgtEntId();
+            res.setTradeEntId(tradeEntId);
+            res.setTradeEntName(finalEntNameMap.getOrDefault(tradeEntId, ""));
+            res.setTradeTypeDesc(getAgentTradeTypeDesc(e.getTradeType()));
+            res.setCreateTime(toDate(e.getCreateTime()));
+            return res;
+        });
+        return pageInfo;
+    }
+
+    public PageInfo<WalletAgentRecordRes> recordList(WalletAgentRecordQuery query) {
+        PageInfo<WalletAgentRecordRes> pageInfo = new PageInfo<>(new ArrayList<>());
+        Long curEntId = LoginEntHolder.getEntId();
+        boolean proxy = isProxyEnt();
+
+        List<Long> agentIds;
+        if (query.getAgentId() != null) {
+            WalletAgent walletAgent = baseMapper.selectById(query.getAgentId());
+            if (walletAgent == null || !Objects.equals(walletAgent.getDelFlag(), 0)) {
+                return pageInfo;
+            }
+            if (!Objects.equals(walletAgent.getSupEntId(), curEntId) && !Objects.equals(walletAgent.getAgtEntId(), curEntId)) {
+                throw new BusinessException("无权限查看该支付记录");
+            }
+            agentIds = List.of(query.getAgentId());
+        } else {
+            agentIds = resolveAgentIds(curEntId, proxy, query.getTradeEntId(), query.getTradeEntName());
+            if (CollectionUtils.isEmpty(agentIds)) {
+                return pageInfo;
+            }
+        }
+
+        LambdaQueryWrapper<WalletAgentRecord> wrapper = Wrappers.lambdaQuery(WalletAgentRecord.class)
+                .eq(WalletAgentRecord::getDelFlag, 0)
+                .in(WalletAgentRecord::getAgentId, agentIds);
+
+        if (StringUtils.hasText(query.getOrderNo())) {
+            wrapper.like(WalletAgentRecord::getOrderNo, query.getOrderNo());
+        }
+        if (query.getPrepaidAmountMin() != null) {
+            wrapper.ge(WalletAgentRecord::getPrepaidAmount, query.getPrepaidAmountMin());
+        }
+        if (query.getPrepaidAmountMax() != null) {
+            wrapper.le(WalletAgentRecord::getPrepaidAmount, query.getPrepaidAmountMax());
+        }
+        if (query.getStatus() != null) {
+            wrapper.eq(WalletAgentRecord::getStatus, query.getStatus());
+        }
+        LocalDateTime startTime = parseDateTime(query.getStartTime());
+        LocalDateTime endTime = parseDateTime(query.getEndTime());
+        if (startTime != null) {
+            wrapper.ge(WalletAgentRecord::getCreateTime, startTime);
+        }
+        if (endTime != null) {
+            wrapper.le(WalletAgentRecord::getCreateTime, endTime);
+        }
+        wrapper.orderByDesc(WalletAgentRecord::getCreateTime, WalletAgentRecord::getId);
+
+        PageUtils.startPage(query);
+        List<WalletAgentRecord> list = walletAgentRecordMapper.selectList(wrapper);
+        if (CollectionUtils.isEmpty(list)) {
+            return pageInfo;
+        }
+
+        List<Long> agentIdList = list.stream().map(WalletAgentRecord::getAgentId).filter(Objects::nonNull).distinct().toList();
+        Map<Long, WalletAgent> agentMap = new HashMap<>();
+        if (!CollectionUtils.isEmpty(agentIdList)) {
+            List<WalletAgent> agents = baseMapper.selectList(Wrappers.lambdaQuery(WalletAgent.class).in(WalletAgent::getId, agentIdList).eq(WalletAgent::getDelFlag, 0));
+            if (!CollectionUtils.isEmpty(agents)) {
+                agentMap = agents.stream().collect(Collectors.toMap(WalletAgent::getId, e -> e, (a, b) -> a));
+            }
+        }
+        List<Long> tradeEntIdList = agentMap.values().stream()
+                .map(e -> proxy ? e.getSupEntId() : e.getAgtEntId())
+                .filter(Objects::nonNull)
+                .distinct()
+                .toList();
+        Map<Long, String> entNameMap = new HashMap<>();
+        if (!CollectionUtils.isEmpty(tradeEntIdList)) {
+            List<EntCacheResDto> entInfos = remoteSystemService.queryEntCacheByIds(tradeEntIdList);
+            if (!CollectionUtils.isEmpty(entInfos)) {
+                entNameMap = entInfos.stream().collect(Collectors.toMap(EntCacheResDto::getId, EntCacheResDto::getFirmName, (a, b) -> a));
+            }
+        }
+        Map<Long, WalletAgent> finalAgentMap = agentMap;
+        Map<Long, String> finalEntNameMap = entNameMap;
+
+        pageInfo = ((Page<WalletAgentRecord>) list).toPageInfo(e -> {
+            WalletAgentRecordRes res = new WalletAgentRecordRes();
+            BeanUtils.copyProperties(e, res);
+            PayStatusEnum statusEnum = PayStatusEnum.getByCode(e.getStatus());
+            res.setStatusDesc(statusEnum == null ? "" : statusEnum.getName());
+            WalletAgent agent = finalAgentMap.get(e.getAgentId());
+            Long tradeEntId = agent == null ? null : (proxy ? agent.getSupEntId() : agent.getAgtEntId());
+            res.setTradeEntId(tradeEntId);
+            res.setTradeEntName(tradeEntId == null ? "" : finalEntNameMap.getOrDefault(tradeEntId, ""));
+            res.setCreateTime(toDate(e.getCreateTime()));
+            return res;
+        });
+        return pageInfo;
+    }
+
+    public BaseResult<Object> manualEntry(WalletAgentManualDto manualDto) {
+        if (!isProxyEnt()) {
+            return BaseResult.failed("非代理企业不可人工录入");
+        }
+        Long curEntId = LoginEntHolder.getEntId();
+        WalletAgent walletAgent = baseMapper.selectOne(Wrappers.lambdaQuery(WalletAgent.class)
+                .eq(WalletAgent::getDelFlag, 0)
+                .eq(WalletAgent::getAgtEntId, curEntId)
+                .eq(WalletAgent::getSupEntId, manualDto.getTradeEntId())
+                .last("limit 1"));
+        if (walletAgent == null) {
+            return BaseResult.failed("代理费清单不存在");
+        }
+        if (walletAgent.getPreBalance() == null || walletAgent.getPreBalance().compareTo(manualDto.getAmount()) < 0) {
+            return BaseResult.failed("金额不能大于待收代理费");
+        }
+
+        Long userId = LoginUserHolder.getUserId();
+        LocalDateTime now = LocalDateTime.now();
+        String orderNo = "M" + System.currentTimeMillis();
+
+        BigDecimal newPre = walletAgent.getPreBalance().subtract(manualDto.getAmount());
+        walletAgent.setPreBalance(newPre);
+        walletAgent.setUpdateBy(userId);
+        walletAgent.setUpdateTime(now);
+        baseMapper.updateById(walletAgent);
+
+        WalletAgentBalance balance = new WalletAgentBalance();
+        balance.setOrderNo(orderNo);
+        balance.setOrderType(OrderTypeEnum.PAYMENT_ORDER.getCode());
+        balance.setAgtEntId(walletAgent.getAgtEntId());
+        balance.setSupEntId(walletAgent.getSupEntId());
+        balance.setTradeType(4);
+        balance.setTradeAmount(manualDto.getAmount());
+        balance.setPreBalance(newPre);
+        balance.setTradingAmount(walletAgent.getTradingAmount());
+        balance.setStatus(ExecutionStatusEnum.SUCCESS.getCode());
+        balance.setRemark(manualDto.getRemark());
+        balance.setCreateBy(userId);
+        balance.setCreateTime(now);
+        balance.setUpdateBy(userId);
+        balance.setUpdateTime(now);
+        balance.setDelFlag(0);
+        walletAgentBalanceMapper.insert(balance);
+
+        WalletAgentRecord record = new WalletAgentRecord();
+        record.setAgentId(walletAgent.getId());
+        record.setOrderNo(orderNo);
+        record.setPrepaidAmount(manualDto.getAmount());
+        record.setReceivedAmount(manualDto.getAmount());
+        record.setStatus(PayStatusEnum.PAID.getCode());
+        record.setData("");
+        record.setRemark(manualDto.getRemark());
+        record.setCreateBy(userId);
+        record.setCreateTime(now);
+        record.setUpdateBy(userId);
+        record.setUpdateTime(now);
+        record.setDelFlag(0);
+        walletAgentRecordMapper.insert(record);
+        return BaseResult.success();
+    }
+
+    public BaseResult<WalletPayAddRes> pay(WalletAgentPayDto payDto) {
+        if (isProxyEnt()) {
+            return BaseResult.failed("代理企业不可发起代理费付款");
+        }
+
+        WalletAgent walletAgent = baseMapper.selectById(payDto.getAgentId());
+        if (walletAgent == null || !Objects.equals(walletAgent.getDelFlag(), 0)) {
+            return BaseResult.failed("代理费清单不存在");
+        }
+        Long curEntId = LoginEntHolder.getEntId();
+        if (!Objects.equals(walletAgent.getSupEntId(), curEntId)) {
+            return BaseResult.failed("无权限发起付款");
+        }
+        if (walletAgent.getPreBalance() == null || walletAgent.getPreBalance().compareTo(payDto.getPayAmount()) < 0) {
+            return BaseResult.failed("付款金额不能大于待付代理费");
+        }
+
+        String orderNo = String.valueOf(System.currentTimeMillis());
+
+        PayDto payReq = new PayDto();
+        payReq.setUid(getUid(curEntId));
+        payReq.setFilter(getUid(walletAgent.getAgtEntId()));
+        payReq.setOrderNo(orderNo);
+        payReq.setAmt(payDto.getPayAmount().toString());
+        payReq.setNoticeUrl(applicationProperties.getCharge());
+        payReq.setRemark(payDto.getRemark());
+
+        R<PayRes> pay;
+        try {
+            pay = payXwService.pay(payReq);
+            if (pay.getCode() != 200) {
+                throw new RuntimeException(pay.getMsg());
+            }
+        } catch (Exception e) {
+            throw new RuntimeException(e);
+        }
+
+        Long userId = LoginUserHolder.getUserId();
+        LocalDateTime now = LocalDateTime.now();
+
+        WalletAgentRecord record = new WalletAgentRecord();
+        record.setAgentId(walletAgent.getId());
+        record.setOrderNo(orderNo);
+        record.setPrepaidAmount(payDto.getPayAmount());
+        record.setReceivedAmount(BigDecimal.ZERO);
+        record.setStatus(PayStatusEnum.PAYABLE.getCode());
+        record.setData(JSONObject.toJSONString(pay.getData()));
+        record.setRemark(payDto.getRemark());
+        record.setCreateBy(userId);
+        record.setCreateTime(now);
+        record.setUpdateBy(userId);
+        record.setUpdateTime(now);
+        record.setDelFlag(0);
+        walletAgentRecordMapper.insert(record);
+
+        BigDecimal newPre = walletAgent.getPreBalance().subtract(payDto.getPayAmount());
+        BigDecimal newTrading = (walletAgent.getTradingAmount() == null ? BigDecimal.ZERO : walletAgent.getTradingAmount()).add(payDto.getPayAmount());
+        walletAgent.setPreBalance(newPre);
+        walletAgent.setTradingAmount(newTrading);
+        walletAgent.setUpdateBy(userId);
+        walletAgent.setUpdateTime(now);
+        baseMapper.updateById(walletAgent);
+
+        WalletAgentBalance balance = new WalletAgentBalance();
+        balance.setOrderNo(orderNo);
+        balance.setOrderType(OrderTypeEnum.PAYMENT_ORDER.getCode());
+        balance.setAgtEntId(walletAgent.getAgtEntId());
+        balance.setSupEntId(walletAgent.getSupEntId());
+        balance.setTradeType(2);
+        balance.setTradeAmount(payDto.getPayAmount());
+        balance.setPreBalance(newPre);
+        balance.setTradingAmount(newTrading);
+        balance.setStatus(ExecutionStatusEnum.IN_PROGRESS.getCode());
+        balance.setRemark(payDto.getRemark());
+        balance.setCreateBy(userId);
+        balance.setCreateTime(now);
+        balance.setUpdateBy(userId);
+        balance.setUpdateTime(now);
+        balance.setDelFlag(0);
+        walletAgentBalanceMapper.insert(balance);
+
+        WalletPayAddRes walletPayAddRes = new WalletPayAddRes();
+        PayRes data = pay.getData();
+        walletPayAddRes.setId(record.getId());
+        walletPayAddRes.setOrderNo(data.getOrderNo());
+        walletPayAddRes.setSettleAcctName(data.getFullName());
+        walletPayAddRes.setSettleAcctNo(data.getSettleAcct());
+        walletPayAddRes.setAmount(new BigDecimal(data.getAmt()));
+        walletPayAddRes.setBankName("新网银行");
+        return BaseResult.success(walletPayAddRes);
+    }
+
+    public BaseResult<WalletPayAddRes> getPayInfo(Long id) {
+        WalletAgentRecord record = walletAgentRecordMapper.selectById(id);
+        if (record == null || !Objects.equals(record.getDelFlag(), 0)) {
+            return BaseResult.failed("支付记录不存在");
+        }
+        if (!StringUtils.hasText(record.getData())) {
+            return BaseResult.failed("该记录无付款信息");
+        }
+        WalletAgent walletAgent = baseMapper.selectById(record.getAgentId());
+        if (walletAgent == null || !Objects.equals(walletAgent.getDelFlag(), 0)) {
+            return BaseResult.failed("代理费清单不存在");
+        }
+        Long curEntId = LoginEntHolder.getEntId();
+        if (!Objects.equals(walletAgent.getSupEntId(), curEntId) && !Objects.equals(walletAgent.getAgtEntId(), curEntId)) {
+            return BaseResult.failed("无权限查看付款信息");
+        }
+        WalletPayAddRes walletPayAddRes = new WalletPayAddRes();
+        PayRes data = JSONObject.parseObject(record.getData(), PayRes.class);
+        walletPayAddRes.setId(record.getId());
+        walletPayAddRes.setOrderNo(data.getOrderNo());
+        walletPayAddRes.setSettleAcctName(data.getFullName());
+        walletPayAddRes.setSettleAcctNo(data.getSettleAcct());
+        walletPayAddRes.setAmount(new BigDecimal(data.getAmt()));
+        walletPayAddRes.setBankName("新网银行");
+        return BaseResult.success(walletPayAddRes);
+    }
+
+    public void receivedCallback(ReceivedCallbackDto receivedCallbackDto) {
+        WalletAgentRecord record = walletAgentRecordMapper.selectOne(Wrappers.lambdaQuery(WalletAgentRecord.class)
+                .eq(WalletAgentRecord::getOrderNo, receivedCallbackDto.getPayOrderNo())
+                .eq(WalletAgentRecord::getDelFlag, 0)
+                .last("limit 1"));
+        if (record == null) {
+            throw new BusinessException("支付记录不存在");
+        }
+
+        Long userId = LoginUserHolder.getUserId();
+        LocalDateTime now = LocalDateTime.now();
+
+        record.setReceivedAmount(receivedCallbackDto.getTranAmt());
+        record.setStatus(PayStatusEnum.PAID.getCode());
+        record.setUpdateBy(userId);
+        record.setUpdateTime(now);
+        walletAgentRecordMapper.updateById(record);
+
+        WalletAgent walletAgent = baseMapper.selectById(record.getAgentId());
+        if (walletAgent != null && Objects.equals(walletAgent.getDelFlag(), 0)) {
+            BigDecimal newTrading = (walletAgent.getTradingAmount() == null ? BigDecimal.ZERO : walletAgent.getTradingAmount()).subtract(receivedCallbackDto.getTranAmt());
+            walletAgent.setTradingAmount(newTrading.compareTo(BigDecimal.ZERO) < 0 ? BigDecimal.ZERO : newTrading);
+            walletAgent.setUpdateBy(userId);
+            walletAgent.setUpdateTime(now);
+            baseMapper.updateById(walletAgent);
+
+            WalletAgentBalance update = new WalletAgentBalance();
+            update.setStatus(ExecutionStatusEnum.SUCCESS.getCode());
+            update.setUpdateBy(userId);
+            update.setUpdateTime(now);
+            walletAgentBalanceMapper.update(update, Wrappers.lambdaQuery(WalletAgentBalance.class)
+                    .eq(WalletAgentBalance::getOrderNo, record.getOrderNo())
+                    .eq(WalletAgentBalance::getDelFlag, 0)
+                    .eq(WalletAgentBalance::getTradeType, 2));
+
+            WalletAgentBalance balance = new WalletAgentBalance();
+            balance.setOrderNo(record.getOrderNo());
+            balance.setOrderType(OrderTypeEnum.PAYMENT_ORDER.getCode());
+            balance.setAgtEntId(walletAgent.getAgtEntId());
+            balance.setSupEntId(walletAgent.getSupEntId());
+            balance.setTradeType(3);
+            balance.setTradeAmount(receivedCallbackDto.getTranAmt());
+            balance.setPreBalance(walletAgent.getPreBalance());
+            balance.setTradingAmount(walletAgent.getTradingAmount());
+            balance.setStatus(ExecutionStatusEnum.SUCCESS.getCode());
+            balance.setRemark(record.getRemark());
+            balance.setCreateBy(userId);
+            balance.setCreateTime(now);
+            balance.setUpdateBy(userId);
+            balance.setUpdateTime(now);
+            balance.setDelFlag(0);
+            walletAgentBalanceMapper.insert(balance);
+        }
+    }
+
+    private boolean isProxyEnt() {
+        String entTypes = LoginEntHolder.get().getEntTypes();
+        return entTypes != null && entTypes.contains(String.valueOf(EntTypeEnum.PROXY.getCode()));
+    }
+
+    private static String getAgentTradeTypeDesc(Integer tradeType) {
+        if (tradeType == null) {
+            return "";
+        }
+        return switch (tradeType) {
+            case 1 -> "消费";
+            case 2 -> "申请付款";
+            case 3 -> "付款成功";
+            case 4 -> "人工录入";
+            default -> "";
+        };
+    }
+
+    private List<Long> resolveAgentIds(Long curEntId, boolean proxy, Long tradeEntId, String tradeEntName) {
+        LambdaQueryWrapper<WalletAgent> agentWrapper = Wrappers.lambdaQuery(WalletAgent.class)
+                .select(WalletAgent::getId)
+                .eq(WalletAgent::getDelFlag, 0)
+                .eq(proxy ? WalletAgent::getAgtEntId : WalletAgent::getSupEntId, curEntId);
+
+        if (tradeEntId != null) {
+            agentWrapper.eq(proxy ? WalletAgent::getSupEntId : WalletAgent::getAgtEntId, tradeEntId);
+        } else if (StringUtils.hasText(tradeEntName)) {
+            List<EntCacheResDto> entCacheResDtos = remoteSystemService.queryEntCacheByName(tradeEntName);
+            if (CollectionUtils.isEmpty(entCacheResDtos)) {
+                return new ArrayList<>();
+            }
+            List<Long> ids = entCacheResDtos.stream().map(EntCacheResDto::getId).distinct().toList();
+            agentWrapper.in(proxy ? WalletAgent::getSupEntId : WalletAgent::getAgtEntId, ids);
+        }
+        List<WalletAgent> agents = baseMapper.selectList(agentWrapper);
+        if (CollectionUtils.isEmpty(agents)) {
+            return new ArrayList<>();
+        }
+        return agents.stream().map(WalletAgent::getId).filter(Objects::nonNull).toList();
+    }
+
+    private String getUid(Long entId) {
+        if (Objects.isNull(entId)) {
+            return null;
+        }
+        KwpWallet kwpWallet = kwpWalletMapper.selectOne(Wrappers.lambdaQuery(KwpWallet.class)
+                .eq(KwpWallet::getEntId, entId)
+                .eq(KwpWallet::getStatus, 2)
+                .eq(KwpWallet::getDelFlag, 0)
+                .last("limit 1"));
+        if (Objects.isNull(kwpWallet)) {
+            return null;
+        }
+        return kwpWallet.getUid();
+    }
+
+    private static LocalDateTime parseDateTime(String time) {
+        if (!StringUtils.hasText(time)) {
+            return null;
+        }
+        try {
+            return LocalDateTime.parse(time, DATE_TIME_FORMATTER);
+        } catch (Exception ignored) {
+            return null;
+        }
+    }
+
+    private static Date toDate(LocalDateTime localDateTime) {
+        if (localDateTime == null) {
+            return null;
+        }
+        return Date.from(localDateTime.atZone(ZoneId.systemDefault()).toInstant());
+    }
+
+    public BaseResult<List<WalletAgentRecordRes>> getPayList(Long agentId) {
+        if (agentId == null) {
+            return BaseResult.success(new ArrayList<>());
+        }
+        WalletAgent walletAgent = baseMapper.selectById(agentId);
+        if (walletAgent == null || !Objects.equals(walletAgent.getDelFlag(), 0)) {
+            return BaseResult.success(new ArrayList<>());
+        }
+        Long curEntId = LoginEntHolder.getEntId();
+        if (!Objects.equals(walletAgent.getSupEntId(), curEntId) && !Objects.equals(walletAgent.getAgtEntId(), curEntId)) {
+            return BaseResult.failed("无权限查看该支付记录");
+        }
+
+        LambdaQueryWrapper<WalletAgentRecord> wrapper = Wrappers.lambdaQuery(WalletAgentRecord.class)
+                .eq(WalletAgentRecord::getDelFlag, 0)
+                .eq(WalletAgentRecord::getAgentId, agentId)
+                .orderByAsc(WalletAgentRecord::getStatus)
+                .orderByDesc(WalletAgentRecord::getCreateTime, WalletAgentRecord::getId);
+        List<WalletAgentRecord> list = walletAgentRecordMapper.selectList(wrapper);
+        if (CollectionUtils.isEmpty(list)) {
+            return BaseResult.success(new ArrayList<>());
+        }
+
+        boolean proxy = isProxyEnt();
+        Long tradeEntId = proxy ? walletAgent.getSupEntId() : walletAgent.getAgtEntId();
+        String tradeEntName = "";
+        if (tradeEntId != null) {
+            EntCacheResDto entCacheResDto = remoteSystemService.queryEntCacheById(tradeEntId);
+            tradeEntName = entCacheResDto == null ? "" : entCacheResDto.getFirmName();
+        }
+        String finalTradeEntName = tradeEntName;
+
+        List<WalletAgentRecordRes> resList = list.stream().map(e -> {
+            WalletAgentRecordRes res = new WalletAgentRecordRes();
+            BeanUtils.copyProperties(e, res);
+            PayStatusEnum statusEnum = PayStatusEnum.getByCode(e.getStatus());
+            res.setStatusDesc(statusEnum == null ? "" : statusEnum.getName());
+            res.setCreateTime(toDate(e.getCreateTime()));
+            res.setTradeEntId(tradeEntId);
+            res.setTradeEntName(finalTradeEntName);
+            return res;
+        }).toList();
+
+        return BaseResult.success(resList);
+    }
 }