TRX 1 год назад
Родитель
Сommit
4fa92b61d7
13 измененных файлов с 238 добавлено и 101 удалено
  1. 3 0
      PaymentClient/src/main/java/com/zhongshu/payment/client/model/WalletModel.java
  2. 31 0
      PaymentClient/src/main/java/com/zhongshu/payment/client/model/param/WalletQueryParam.java
  3. 4 1
      PaymentClient/src/main/java/com/zhongshu/payment/client/service/WalletFeignService.java
  4. 1 1
      PaymentServer/src/main/java/com/zhongshu/payment/server/core/controller/WalletController.java
  5. 1 8
      PaymentServer/src/main/java/com/zhongshu/payment/server/core/service/RechargeService.java
  6. 1 1
      PaymentServer/src/main/java/com/zhongshu/payment/server/core/service/TransferService.java
  7. 33 0
      PaymentServer/src/main/java/com/zhongshu/payment/server/core/service/pay/SuperPayService.java
  8. 6 0
      PaymentServer/src/main/java/com/zhongshu/payment/server/core/service/pay/impl/unionFrictionlessPay/UnionFrictionlessPayMainService.java
  9. 78 65
      PaymentServer/src/main/java/com/zhongshu/payment/server/core/service/pay/impl/wallet/WalletFeignServiceImpl.java
  10. 56 15
      PaymentServer/src/main/java/com/zhongshu/payment/server/core/service/pay/impl/wallet/WalletService.java
  11. 4 0
      PaymentServer/src/main/java/com/zhongshu/payment/server/core/service/pay/impl/wallet/package-info.java
  12. 12 9
      PaymentServer/src/main/java/com/zhongshu/payment/server/core/service/pay/impl/wxPaymentV3/WxPayNotifyService.java
  13. 8 1
      PaymentServer/src/main/java/com/zhongshu/payment/server/core/service/pay/impl/wxPaymentV3/WxPaymentMainService.java

+ 3 - 0
PaymentClient/src/main/java/com/zhongshu/payment/client/model/WalletModel.java

@@ -14,10 +14,13 @@ import java.math.BigDecimal;
 @Data
 public class WalletModel {
 
+    @Schema(description = "数据ID")
     private String id;
 
+    @Schema(description = "创建时间")
     private Long createTime;
 
+    @Schema(description = "更新时间")
     private Long updateTime;
 
     @Schema(description = "项目id")

+ 31 - 0
PaymentClient/src/main/java/com/zhongshu/payment/client/model/param/WalletQueryParam.java

@@ -0,0 +1,31 @@
+package com.zhongshu.payment.client.model.param;
+
+import com.zhongshu.payment.client.types.WalletType;
+import io.swagger.v3.oas.annotations.media.Schema;
+import lombok.AllArgsConstructor;
+import lombok.Builder;
+import lombok.Data;
+import lombok.NoArgsConstructor;
+
+/**
+ * @author TRX
+ * @date 2024/8/22
+ */
+@Data
+@AllArgsConstructor
+@NoArgsConstructor
+@Builder
+public class WalletQueryParam {
+
+    @Schema(description = "项目Oid")
+    private String projectOid;
+
+    @Schema(description = "钱包类型")
+    private WalletType walletType;
+
+    @Schema(description = "商户oid")
+    private String shopId;
+
+    @Schema(description = "用户userId")
+    private String userId;
+}

+ 4 - 1
PaymentClient/src/main/java/com/zhongshu/payment/client/service/WalletFeignService.java

@@ -20,7 +20,10 @@ public interface WalletFeignService {
 
     /** 获取钱包信息 */
     @RequestMapping(value = "getWallet", method = RequestMethod.POST, consumes = MediaType.APPLICATION_FORM_URLENCODED_VALUE)
-    ResultContent<WalletModel> getWallet(@RequestParam("oid") String oid, @RequestParam("walletType") WalletType walletType, @RequestParam("shopId") String shopId,
+    ResultContent<WalletModel> getWallet(
+            @RequestParam("oid") String oid,
+            @RequestParam("walletType") WalletType walletType,
+            @RequestParam("shopId") String shopId,
             @RequestParam ("userId")String userId);
 
     /** 充值 */

+ 1 - 1
PaymentServer/src/main/java/com/zhongshu/payment/server/core/controller/WalletController.java

@@ -3,7 +3,7 @@ package com.zhongshu.payment.server.core.controller;
 import com.github.microservice.auth.security.annotations.ResourceAuth;
 import com.github.microservice.auth.security.type.AuthType;
 import com.zhongshu.payment.client.model.param.GetWalletParam;
-import com.zhongshu.payment.server.core.service.wallet.WalletService;
+import com.zhongshu.payment.server.core.service.pay.impl.wallet.WalletService;
 import io.swagger.v3.oas.annotations.Operation;
 import io.swagger.v3.oas.annotations.tags.Tag;
 import lombok.extern.slf4j.Slf4j;

+ 1 - 8
PaymentServer/src/main/java/com/zhongshu/payment/server/core/service/RechargeService.java

@@ -4,18 +4,13 @@ import ch.qos.logback.core.util.StringUtil;
 import com.github.microservice.auth.security.helper.AuthHelper;
 import com.github.microservice.core.helper.ApplicationContextHolder;
 import com.github.microservice.net.ResultContent;
-import com.wechat.pay.java.service.payments.jsapi.model.Amount;
-import com.wechat.pay.java.service.payments.jsapi.model.Payer;
-import com.wechat.pay.java.service.payments.jsapi.model.PrepayRequest;
 import com.wechat.pay.java.service.payments.model.Transaction;
 import com.zhongshu.card.client.model.feign.ProjectWxPayParam;
 import com.zhongshu.card.client.model.org.OrgUserDetailParam;
 import com.zhongshu.card.client.model.org.OrganizationUserModel;
 import com.zhongshu.card.client.model.payment.paySetting.WxPayConfigModel;
-import com.zhongshu.card.client.model.wechat.MiniAppUserInfoVo;
 import com.zhongshu.card.client.service.feign.OrganizationFeignService;
 import com.zhongshu.card.client.service.feign.ProjectPaySettingFeignService;
-import com.zhongshu.payment.client.model.PrePayModel;
 import com.zhongshu.payment.client.model.RechargeRecordModel;
 import com.zhongshu.payment.client.model.param.OrderParam;
 import com.zhongshu.payment.client.model.param.RechargeParam;
@@ -33,21 +28,19 @@ import com.zhongshu.payment.server.core.domain.unionFrictionlessPay.ExecuteMetho
 import com.zhongshu.payment.server.core.domain.wallet.RechargeRecord;
 import com.zhongshu.payment.server.core.domain.wallet.Wallet;
 import com.zhongshu.payment.server.core.service.base.SuperService;
-import com.zhongshu.payment.server.core.service.impl.WalletFeignServiceImpl;
+import com.zhongshu.payment.server.core.service.pay.impl.wallet.WalletFeignServiceImpl;
 import com.zhongshu.payment.server.core.service.pay.SuperPayService;
 import com.zhongshu.payment.server.core.service.pay.impl.wxPaymentV3.WxPaymentMainService;
 import com.zhongshu.payment.server.core.utils.CommonUtil;
 import com.zhongshu.payment.server.core.utils.DateUtils;
 import com.zhongshu.payment.server.core.utils.wx.WechatCUtil;
 import jakarta.servlet.http.HttpServletRequest;
-import lombok.SneakyThrows;
 import lombok.extern.slf4j.Slf4j;
 import org.apache.commons.lang3.ObjectUtils;
 import org.springframework.beans.BeanUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
-import org.springframework.web.bind.annotation.PathVariable;
 
 import java.math.BigDecimal;
 import java.util.List;

+ 1 - 1
PaymentServer/src/main/java/com/zhongshu/payment/server/core/service/TransferService.java

@@ -22,7 +22,7 @@ import com.zhongshu.payment.server.core.dao.RechargeRecordDao;
 import com.zhongshu.payment.server.core.dao.WalletDao;
 import com.zhongshu.payment.server.core.domain.wallet.RechargeRecord;
 import com.zhongshu.payment.server.core.domain.wallet.Wallet;
-import com.zhongshu.payment.server.core.service.impl.WalletFeignServiceImpl;
+import com.zhongshu.payment.server.core.service.pay.impl.wallet.WalletFeignServiceImpl;
 import com.zhongshu.payment.server.core.service.pay.impl.wxPaymentV3.WxTransferBatchService;
 import com.zhongshu.payment.server.core.utils.CommonUtil;
 import io.netty.util.internal.StringUtil;

+ 33 - 0
PaymentServer/src/main/java/com/zhongshu/payment/server/core/service/pay/SuperPayService.java

@@ -1,19 +1,28 @@
 package com.zhongshu.payment.server.core.service.pay;
 
+import com.github.microservice.auth.security.helper.AuthHelper;
 import com.wechat.pay.java.service.payments.jsapi.model.PrepayRequest;
 import com.zhongshu.card.client.model.payment.paySetting.WxPayConfigModel;
 import com.zhongshu.payment.client.model.PrePayModel;
 import com.github.microservice.net.ResultContent;
+import com.zhongshu.payment.client.model.WalletModel;
 import com.zhongshu.payment.client.model.param.OrderParam;
+import com.zhongshu.payment.client.model.param.WalletQueryParam;
 import com.zhongshu.payment.client.payModel.commn.PayNotityParam;
 import jakarta.servlet.http.HttpServletRequest;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.beans.factory.annotation.Autowired;
 
 /**
  * @author TRX
  * @date 2024/8/15
  */
+@Slf4j
 public abstract class SuperPayService {
 
+    @Autowired
+    private AuthHelper authHelper;
+
     /**
      * 更加本地 创建渠道支付订单
      *
@@ -30,4 +39,28 @@ public abstract class SuperPayService {
      * @return
      */
     public abstract ResultContent payNotify(HttpServletRequest request, PayNotityParam param);
+
+    /**
+     * 查询付款账户信息
+     *
+     * @param param
+     * @return
+     */
+    public abstract ResultContent<WalletModel> getWallet(WalletQueryParam param);
+
+    /**
+     * 得到当前的用户ID
+     *
+     * @return
+     */
+    public String getCurrentUserId() {
+        try {
+            if (authHelper != null && authHelper.getCurrentUser() != null) {
+                return authHelper.getCurrentUser().getUserId();
+            }
+        } catch (Exception e) {
+            log.error("getCurrentUserId error {}", e.getMessage());
+        }
+        return null;
+    }
 }

+ 6 - 0
PaymentServer/src/main/java/com/zhongshu/payment/server/core/service/pay/impl/unionFrictionlessPay/UnionFrictionlessPayMainService.java

@@ -1,7 +1,9 @@
 package com.zhongshu.payment.server.core.service.pay.impl.unionFrictionlessPay;
 
 import com.github.microservice.net.ResultContent;
+import com.zhongshu.payment.client.model.WalletModel;
 import com.zhongshu.payment.client.model.param.OrderParam;
+import com.zhongshu.payment.client.model.param.WalletQueryParam;
 import com.zhongshu.payment.client.payModel.commn.PayNotityParam;
 import com.zhongshu.payment.server.core.service.pay.SuperPayService;
 import jakarta.servlet.http.HttpServletRequest;
@@ -28,4 +30,8 @@ public class UnionFrictionlessPayMainService extends SuperPayService {
         return null;
     }
 
+    public ResultContent<WalletModel> getWallet(WalletQueryParam param) {
+        return ResultContent.buildFail("无感支付不支持查询账户信息");
+    }
+
 }

+ 78 - 65
PaymentServer/src/main/java/com/zhongshu/payment/server/core/service/impl/WalletFeignServiceImpl.java → PaymentServer/src/main/java/com/zhongshu/payment/server/core/service/pay/impl/wallet/WalletFeignServiceImpl.java

@@ -1,18 +1,16 @@
-package com.zhongshu.payment.server.core.service.impl;
+package com.zhongshu.payment.server.core.service.pay.impl.wallet;
 
+import com.github.microservice.net.ResultContent;
 import com.zhongshu.payment.client.model.WalletModel;
 import com.zhongshu.payment.client.model.param.AmountUpdateParam;
-import com.github.microservice.net.ResultContent;
+import com.zhongshu.payment.client.model.param.WalletQueryParam;
 import com.zhongshu.payment.client.service.WalletFeignService;
 import com.zhongshu.payment.client.types.TradeType;
-import com.zhongshu.payment.client.types.WalletState;
 import com.zhongshu.payment.client.types.WalletType;
 import com.zhongshu.payment.server.core.dao.WalletDao;
 import com.zhongshu.payment.server.core.dao.WalletFlowDao;
 import com.zhongshu.payment.server.core.domain.wallet.Wallet;
 import com.zhongshu.payment.server.core.domain.wallet.WalletFlow;
-import com.zhongshu.payment.server.core.utils.BeanUtils;
-import org.jetbrains.annotations.NotNull;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
@@ -32,43 +30,30 @@ public class WalletFeignServiceImpl implements WalletFeignService {
     @Autowired
     WalletFlowDao walletFlowDao;
 
+    @Autowired
+    WalletService walletService;
 
     @Override
     public ResultContent<WalletModel> getWallet(String oid, WalletType walletType, String shopId, String userId) {
-
-        return ResultContent.buildContent(toModel(findWallet(oid, walletType, shopId, userId)));
-    }
-
-    @NotNull
-    private Wallet findWallet(String oid, @NotNull WalletType walletType, String shopId, String userId){
-        Wallet findWallet = null;;
-        Wallet wallet = new Wallet();;
-        if (walletType.equals(WalletType.User)){
-            findWallet = walletDao.findByUserIdAndOidAndWalletType(userId, oid, walletType);
-            wallet.setUserId(userId);
-        }
-        if (walletType.equals(WalletType.Shop)){
-            findWallet = walletDao.findByShopIdAndOidAndWalletType(shopId, oid, walletType);
-            wallet.setShopId(shopId);
-        }
-        if (findWallet!=null){
-            return findWallet;
-        }
-        wallet.setOid(oid);
-        wallet.setAmount(BigDecimal.ZERO);
-        wallet.setAmount(BigDecimal.ZERO);
-        wallet.setDataState(WalletState.Enable);
-        wallet.setWalletType(walletType);
-        walletDao.save(wallet);
-        return wallet;
+        WalletQueryParam param = new WalletQueryParam();
+        param.setProjectOid(oid);
+        param.setWalletType(walletType);
+        param.setShopId(shopId);
+        param.setUserId(userId);
+        return walletService.getWallet(param);
     }
 
-
-    /** 充值 */
+    /**
+     * 充值
+     */
     @Override
     @Transactional
-    public ResultContent recharge(AmountUpdateParam param){
-        Wallet wallet = findWallet(param.getOid(), WalletType.User, param.getShopId(), param.getUserId());
+    public ResultContent recharge(AmountUpdateParam param) {
+        WalletQueryParam queryParam = WalletQueryParam.builder().projectOid(param.getOid())
+                .walletType(WalletType.User)
+                .userId(param.getUserId())
+                .shopId(param.getShopId()).build();
+        Wallet wallet = walletService.findWallet(queryParam);
         wallet.setAmount(wallet.getAmount().add(param.getTotal()));
         wallet.setTotalAmount(wallet.getTotalAmount().add(param.getTotal()));
         walletDao.save(wallet);
@@ -76,16 +61,22 @@ public class WalletFeignServiceImpl implements WalletFeignService {
         return ResultContent.buildSuccess();
     }
 
-    /** 消费 */
+    /**
+     * 消费
+     */
     @Override
     @Transactional
-    public ResultContent consume(AmountUpdateParam param){
-        Wallet userWallet = findWallet(param.getOid(), WalletType.User, param.getShopId(), param.getUserId());
+    public ResultContent consume(AmountUpdateParam param) {
+        WalletQueryParam queryParam = WalletQueryParam.builder().projectOid(param.getOid())
+                .walletType(WalletType.User)
+                .userId(param.getUserId())
+                .shopId(param.getShopId()).build();
+        Wallet userWallet = walletService.findWallet(queryParam);
 
-        if (userWallet.getAmount().compareTo(param.getTotal()) < 0 ){
+        if (userWallet.getAmount().compareTo(param.getTotal()) < 0) {
             return ResultContent.buildFail("可用余额不足");
         }
-        if (userWallet.getTotalAmount().compareTo(param.getTotal()) < 0 ){
+        if (userWallet.getTotalAmount().compareTo(param.getTotal()) < 0) {
             return ResultContent.buildFail("总额不足");
         }
         userWallet.setAmount(userWallet.getAmount().subtract(param.getTotal()));
@@ -93,7 +84,12 @@ public class WalletFeignServiceImpl implements WalletFeignService {
         walletDao.save(userWallet);
         createWalletFlow(userWallet.getId(), param.getTotal(), param.getOutTradeNo(), TradeType.Pay, param.getAttach(), param.getSchoolId());
 
-        Wallet shopWallet = findWallet(param.getOid(), WalletType.Shop, param.getShopId(), param.getUserId());
+        WalletQueryParam shopQuery = WalletQueryParam.builder().projectOid(param.getOid())
+                .walletType(WalletType.Shop)
+                .userId(param.getUserId())
+                .shopId(param.getShopId()).build();
+
+        Wallet shopWallet = walletService.findWallet(shopQuery);
         shopWallet.setAmount(shopWallet.getAmount().add(param.getTotal()));
         shopWallet.setTotalAmount(shopWallet.getTotalAmount().add(param.getTotal()));
         walletDao.save(shopWallet);
@@ -130,15 +126,21 @@ public class WalletFeignServiceImpl implements WalletFeignService {
 //        return ResultContent.buildSuccess();
 //    }
 
-    /** 退款 */
+    /**
+     * 退款
+     */
     @Transactional
-    public ResultContent refund(AmountUpdateParam param){
-        Wallet shopWallet = findWallet(param.getOid(), WalletType.Shop, param.getShopId(), param.getUserId());
+    public ResultContent refund(AmountUpdateParam param) {
+        WalletQueryParam shopQuery = WalletQueryParam.builder().projectOid(param.getOid())
+                .walletType(WalletType.Shop)
+                .userId(param.getUserId())
+                .shopId(param.getShopId()).build();
+        Wallet shopWallet = walletService.findWallet(shopQuery);
 
         BigDecimal amount = shopWallet.getAmount();
 //        //加上冻结金额
 //        BigDecimal _amount = amount.add(param.getTotal());
-        if (amount.compareTo(param.getTotal()) < 0 ){
+        if (amount.compareTo(param.getTotal()) < 0) {
             return ResultContent.buildFail("可用余额不足");
         }
         shopWallet.setAmount(shopWallet.getAmount().subtract(param.getTotal()));
@@ -146,7 +148,11 @@ public class WalletFeignServiceImpl implements WalletFeignService {
         walletDao.save(shopWallet);
         createWalletFlow(shopWallet.getId(), param.getTotal(), param.getOutTradeNo(), TradeType.Refund, param.getAttach(), param.getSchoolId());
 
-        Wallet userWallet = findWallet(param.getOid(), WalletType.User, param.getShopId(), param.getUserId());
+        WalletQueryParam userQuery = WalletQueryParam.builder().projectOid(param.getOid())
+                .walletType(WalletType.User)
+                .userId(param.getUserId())
+                .shopId(param.getShopId()).build();
+        Wallet userWallet = walletService.findWallet(userQuery);
         userWallet.setAmount(userWallet.getAmount().add(param.getTotal()));
         userWallet.setTotalAmount(userWallet.getTotalAmount().add(param.getTotal()));
         walletDao.save(userWallet);
@@ -154,14 +160,20 @@ public class WalletFeignServiceImpl implements WalletFeignService {
         return ResultContent.buildSuccess();
     }
 
-    /** 用户发起提现 */
+    /**
+     * 用户发起提现
+     */
     @Transactional
-    public ResultContent commitTake(AmountUpdateParam param){
-        Wallet userWallet = findWallet(param.getOid(), WalletType.User, param.getShopId(), param.getUserId());
-        if (userWallet.getAmount().compareTo(param.getTotal()) < 0 ){
+    public ResultContent commitTake(AmountUpdateParam param) {
+        WalletQueryParam userQuery = WalletQueryParam.builder().projectOid(param.getOid())
+                .walletType(WalletType.User)
+                .userId(param.getUserId())
+                .shopId(param.getShopId()).build();
+        Wallet userWallet = walletService.findWallet(userQuery);
+        if (userWallet.getAmount().compareTo(param.getTotal()) < 0) {
             return ResultContent.buildFail("可用余额不足");
         }
-        if (userWallet.getTotalAmount().compareTo(param.getTotal()) < 0 ){
+        if (userWallet.getTotalAmount().compareTo(param.getTotal()) < 0) {
             return ResultContent.buildFail("总额不足");
         }
         userWallet.setAmount(userWallet.getAmount().subtract(param.getTotal()));
@@ -171,17 +183,27 @@ public class WalletFeignServiceImpl implements WalletFeignService {
         return ResultContent.buildSuccess();
     }
 
-    /** 用户提现(审批失败) */
+    /**
+     * 用户提现(审批失败)
+     */
     @Transactional
-    public ResultContent failTake(AmountUpdateParam param){
-        Wallet userWallet = findWallet(param.getOid(), WalletType.User, param.getShopId(), param.getUserId());
+    public ResultContent failTake(AmountUpdateParam param) {
+        WalletQueryParam userQuery = WalletQueryParam.builder().projectOid(param.getOid())
+                .walletType(WalletType.User)
+                .userId(param.getUserId())
+                .shopId(param.getShopId()).build();
+
+        Wallet userWallet = walletService.findWallet(userQuery);
         userWallet.setAmount(userWallet.getAmount().add(param.getTotal()));
         userWallet.setTotalAmount(userWallet.getTotalAmount().add(param.getTotal()));
         walletDao.save(userWallet);
         createWalletFlow(userWallet.getId(), param.getTotal(), param.getOutTradeNo(), TradeType.TakeReturn, param.getAttach(), param.getSchoolId());
         return ResultContent.buildSuccess();
     }
-    /** 用户提现(审批通过) */
+
+    /**
+     * 用户提现(审批通过)
+     */
 //    public ResultContent takePass(AmountUpdateParam param){
 //        Wallet userWallet = findWallet(param.getOid(), WalletType.User, param.getShopId(), param.getUserId());
 //        return ResultContent.buildSuccess();
@@ -245,8 +267,7 @@ public class WalletFeignServiceImpl implements WalletFeignService {
 //    public List<WalletFlowModel> queryWalletFlow(String walletId) {
 //        return null;
 //    }
-
-    private WalletFlow createWalletFlow(String walletId, BigDecimal total, String outTradeNo, TradeType type, Object attach, String schoolId){
+    private WalletFlow createWalletFlow(String walletId, BigDecimal total, String outTradeNo, TradeType type, Object attach, String schoolId) {
         WalletFlow walletFlow = new WalletFlow();
         Wallet wallet = new Wallet();
         wallet.setId(walletId);
@@ -303,12 +324,4 @@ public class WalletFeignServiceImpl implements WalletFeignService {
 //        walletDao.saveAll(List.of(shopWallet, userWallet));
 //        return ResultContent.buildSuccess();
 //    }
-
-    private WalletModel toModel(Wallet wallet){
-        WalletModel model = new WalletModel();
-        if (wallet!=null){
-            BeanUtils.copyPropertiesWithoutNull(wallet, model);
-        }
-        return model;
-    }
 }

+ 56 - 15
PaymentServer/src/main/java/com/zhongshu/payment/server/core/service/wallet/WalletService.java → PaymentServer/src/main/java/com/zhongshu/payment/server/core/service/pay/impl/wallet/WalletService.java

@@ -1,4 +1,4 @@
-package com.zhongshu.payment.server.core.service.wallet;
+package com.zhongshu.payment.server.core.service.pay.impl.wallet;
 
 import ch.qos.logback.core.util.StringUtil;
 import com.github.microservice.auth.security.helper.AuthHelper;
@@ -10,13 +10,19 @@ import com.zhongshu.card.client.service.feign.ProjectPaySettingFeignService;
 import com.zhongshu.payment.client.model.WalletModel;
 import com.zhongshu.payment.client.model.WalletOrderModel;
 import com.zhongshu.payment.client.model.param.GetWalletParam;
+import com.zhongshu.payment.client.model.param.OrderParam;
+import com.zhongshu.payment.client.model.param.WalletQueryParam;
+import com.zhongshu.payment.client.payModel.commn.PayNotityParam;
 import com.zhongshu.payment.client.types.WalletState;
 import com.zhongshu.payment.client.types.WalletType;
 import com.zhongshu.payment.server.core.dao.RechargeRecordDao;
 import com.zhongshu.payment.server.core.dao.WalletDao;
 import com.zhongshu.payment.server.core.domain.wallet.Wallet;
+import com.zhongshu.payment.server.core.service.pay.SuperPayService;
 import com.zhongshu.payment.server.core.utils.BeanUtils;
 import groovy.util.logging.Slf4j;
+import jakarta.servlet.http.HttpServletRequest;
+import org.jetbrains.annotations.NotNull;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 
@@ -28,10 +34,9 @@ import java.math.BigDecimal;
  * @author wjf
  * @date 2024/7/24
  */
-
 @Slf4j
 @Service
-public class WalletService {
+public class WalletService extends SuperPayService {
 
     @Autowired
     WalletDao walletDao;
@@ -48,23 +53,58 @@ public class WalletService {
     @Autowired
     RechargeRecordDao rechargeRecordDao;
 
+    /**
+     * 创建渠道支付订单
+     *
+     * @param param
+     * @return
+     */
+    @Override
+    public ResultContent createChannelOrder(OrderParam param) {
+        return ResultContent.buildFail("钱包不支持创建订单");
+    }
 
-//    /** 获取钱包微信授权状态 */
-//    public Object getWeChatAuthState(String walletId){
-//        Wallet wallet = walletDao.findTop1ById(walletId);
-//        if (wallet==null){
-//            return ResultContent.buildFail("钱包未开通");
-//        }
-//        if (StringUtil.isNullOrEmpty(wallet.getOpenid())){
-//            return ResultContent.buildContent(ResultState.NOT_WECHAT_AUTH);
-//        }
-//        return ResultContent.buildSuccess();
-//    }
+    @Override
+    public ResultContent payNotify(HttpServletRequest request, PayNotityParam param) {
+        return ResultContent.buildFail("钱包不支持成功回调");
+    }
+
+    /**
+     * 查询账户信息
+     *
+     * @param param
+     * @return
+     */
+    public ResultContent<WalletModel> getWallet(WalletQueryParam param) {
+        return ResultContent.buildContent(toModel(findWallet(param)));
+    }
+
+    //----------------------------渠道的方法 start-----------------------
+
+    @NotNull
+    public Wallet findWallet(WalletQueryParam param) {
+        String oid = param.getProjectOid();
+        WalletType walletType = param.getWalletType();
+        String shopId = param.getShopId();
+        String userId = param.getUserId();
+        Wallet wallet = null;
+        if (walletType.equals(WalletType.User)) {
+            wallet = walletDao.findByUserIdAndOidAndWalletType(userId, oid, walletType);
+        }
+        if (walletType.equals(WalletType.Shop)) {
+            wallet = walletDao.findByShopIdAndOidAndWalletType(shopId, oid, walletType);
+        }
+        if (wallet != null) {
+            return wallet;
+        }
+        wallet = initUserWallet(oid, userId, shopId, walletType);
+        return wallet;
+    }
 
     /**
      * 查询用户钱包
      */
-    public Object getWalletByUser(GetWalletParam param) {
+    public ResultContent<WalletModel> getWalletByUser(GetWalletParam param) {
         String userId = authHelper.getCurrentUser().getUserId();
 
         ProjectWxPayParam projectWxPayParam = new ProjectWxPayParam();
@@ -142,4 +182,5 @@ public class WalletService {
         }
         return model;
     }
+
 }

+ 4 - 0
PaymentServer/src/main/java/com/zhongshu/payment/server/core/service/pay/impl/wallet/package-info.java

@@ -0,0 +1,4 @@
+package com.zhongshu.payment.server.core.service.pay.impl.wallet;
+/**
+ * 个人钱包
+ */

+ 12 - 9
PaymentServer/src/main/java/com/zhongshu/payment/server/core/service/pay/impl/wxPaymentV3/WxPayNotifyService.java

@@ -16,7 +16,7 @@ import com.zhongshu.payment.client.model.param.AmountUpdateParam;
 import com.zhongshu.payment.client.types.RechargeState;
 import com.zhongshu.payment.server.core.dao.RechargeRecordDao;
 import com.zhongshu.payment.server.core.domain.wallet.RechargeRecord;
-import com.zhongshu.payment.server.core.service.impl.WalletFeignServiceImpl;
+import com.zhongshu.payment.server.core.service.pay.impl.wallet.WalletFeignServiceImpl;
 import com.zhongshu.payment.server.core.utils.DateUtils;
 import jakarta.servlet.ServletInputStream;
 import jakarta.servlet.http.HttpServletRequest;
@@ -75,7 +75,7 @@ public class WxPayNotifyService {
             // 没有的话,则构造一个
 //            log.error(JSON.toJSONString(wxPayV3Bean));
             String privateKeyPath = configModel.getPrivateKeyPath();
-            if (configModel.getPrivateKeyType().equals("local")){
+            if (configModel.getPrivateKeyType().equals("local")) {
                 privateKeyPath = Thread.currentThread().getContextClassLoader().getResource("").getPath() + configModel.getPrivateKeyPath();
             }
 
@@ -87,7 +87,7 @@ public class WxPayNotifyService {
                     .build();
             // 初始化 NotificationParser
             NotificationParser parser = new NotificationParser(config);
-            RequestParam requestParam=new RequestParam.Builder()
+            RequestParam requestParam = new RequestParam.Builder()
                     .serialNumber(serialNo)
                     .nonce(nonce)
                     .signature(signature)
@@ -100,17 +100,18 @@ public class WxPayNotifyService {
             System.out.println("parse = " + transaction);
 
             RechargeRecord record = rechargeRecordDao.findByOutTradeNo(transaction.getOutTradeNo());
-            if (record == null){
+            if (record == null) {
                 log.error("微信支付通知回调错误:找不到订单outTradeNo:{}", transaction.getOutTradeNo());
                 return;
             }
             //parse.getTradeState().equals("SUCCESS");说明支付成功
-            if (transaction.getTradeState().equals(Transaction.TradeStateEnum.SUCCESS)){
+            if (transaction.getTradeState().equals(Transaction.TradeStateEnum.SUCCESS)) {
                 //你的业务代码
                 log.info("微信支付成功");
                 record.setRechargeState(RechargeState.SUCCESS);
                 record.setTradeTime(DateUtils.timeToLong(transaction.getSuccessTime(), DateUtils.patternWx));
                 rechargeRecordDao.save(record);
+
                 //增加余额
                 AmountUpdateParam amountUpdateParam = new AmountUpdateParam();
                 amountUpdateParam.setOid(record.getOid());
@@ -119,14 +120,16 @@ public class WxPayNotifyService {
                 amountUpdateParam.setOutTradeNo(record.getOutTradeNo());
                 amountUpdateParam.setAttach(JsonUtil.toJson(transaction));
                 ResultContent recharge = walletService.recharge(amountUpdateParam);
-                if (recharge.isFailed()){
+                if (recharge.isFailed()) {
                     log.error("充值失败:钱包余额增加失败");
                 }
-            }else {
+            } else {
                 log.info("微信支付异常:{}", transaction.getTradeState());
                 record.setRechargeState(RechargeState.valueOf(transaction.getTradeState().name()));
                 rechargeRecordDao.save(record);
             }
+
+            // 发送成功通知消息
             SendMessageModel sendMessageModel = new SendMessageModel();
             sendMessageModel.setMessage(JsonUtil.toJson(Map.of("status", transaction.getTradeState().name(), "outTradeNo", transaction.getOutTradeNo())));
             String userId = record.getUserId();
@@ -136,7 +139,7 @@ public class WxPayNotifyService {
             mqttFeignService.sendMessage(sendMessageModel);
         } catch (Exception e) {
             Log.info("微信支付回调验签错误:{}", e.getMessage());
-        }finally {
+        } finally {
 
         }
     }
@@ -147,7 +150,7 @@ public class WxPayNotifyService {
         ProjectWxPayParam wxPayParam = new ProjectWxPayParam();
         wxPayParam.setAppId(recordByOutTradeNo.getAppid());
         ResultContent<WxPayConfigModel> paySetResult = paySettingFeignService.getProjectWxPayConfig(wxPayParam);
-        if (paySetResult.isFailed()){
+        if (paySetResult.isFailed()) {
             log.error("获取微信支付配置失败 \"outTradeNo\": {}", outTradeNo);
         }
         return paySetResult.getContent();

+ 8 - 1
PaymentServer/src/main/java/com/zhongshu/payment/server/core/service/pay/impl/wxPaymentV3/WxPaymentMainService.java

@@ -17,7 +17,9 @@ import com.zhongshu.card.client.model.wechat.MiniAppUserInfoVo;
 import com.zhongshu.card.client.service.feign.ProjectPaySettingFeignService;
 import com.zhongshu.payment.client.annotation.PayAnnotationService;
 import com.zhongshu.payment.client.model.PrePayModel;
+import com.zhongshu.payment.client.model.WalletModel;
 import com.zhongshu.payment.client.model.param.OrderParam;
+import com.zhongshu.payment.client.model.param.WalletQueryParam;
 import com.zhongshu.payment.client.payModel.commn.PayNotityParam;
 import com.zhongshu.payment.client.types.RechargeState;
 import com.zhongshu.payment.server.core.dao.RechargeRecordDao;
@@ -114,7 +116,8 @@ public class WxPaymentMainService extends SuperPayService {
     }
 
     /**
-     * 支付成功
+     * 支付回调
+     *
      * @param request
      * @param param
      * @return
@@ -124,6 +127,10 @@ public class WxPaymentMainService extends SuperPayService {
         return ResultContent.buildSuccess();
     }
 
+    public ResultContent<WalletModel> getWallet(WalletQueryParam param) {
+        return ResultContent.buildFail("微信不支持查询账户信息");
+    }
+
     //----------------------------------------- 渠道方法 start------------------------
 
     // 初始化商户配置