Просмотр исходного кода

Merge remote-tracking branch 'origin/master'

TRX 1 год назад
Родитель
Сommit
7bce354f0d
23 измененных файлов с 564 добавлено и 427 удалено
  1. 22 0
      FullCardClient/src/main/java/com/zhongshu/card/client/model/pay/PayAccountParam.java
  2. 32 0
      FullCardClient/src/main/java/com/zhongshu/card/client/model/pay/RechargeOrderModel.java
  3. 39 0
      FullCardClient/src/main/java/com/zhongshu/card/client/model/pay/RechargeParam.java
  4. 16 0
      FullCardClient/src/main/java/com/zhongshu/card/client/type/payAccount/PayAccountLevel.java
  5. 19 0
      FullCardClient/src/main/java/com/zhongshu/card/client/type/payAccount/RechargeOrderStatus.java
  6. 18 0
      FullCardClient/src/main/java/com/zhongshu/card/client/type/wallet/WalletType.java
  7. 34 0
      FullCardServer/src/main/java/com/zhongshu/card/server/core/controller/openAPI/AccessRecordController.java
  8. 26 0
      FullCardServer/src/main/java/com/zhongshu/card/server/core/controller/pay/balance/RechargeController.java
  9. 0 46
      FullCardServer/src/main/java/com/zhongshu/card/server/core/controller/wallet/WalletController.java
  10. 7 0
      FullCardServer/src/main/java/com/zhongshu/card/server/core/dao/pay/BalanceRechargeOrderDao.java
  11. 14 0
      FullCardServer/src/main/java/com/zhongshu/card/server/core/dao/pay/PayAccountDao.java
  12. 4 0
      FullCardServer/src/main/java/com/zhongshu/card/server/core/dao/pay/extend/PayAccountDaoExtend.java
  13. 6 0
      FullCardServer/src/main/java/com/zhongshu/card/server/core/dao/pay/impl/PayAccountDaoImpl.java
  14. 0 11
      FullCardServer/src/main/java/com/zhongshu/card/server/core/dao/wallet/WalletRechargeDao.java
  15. 0 15
      FullCardServer/src/main/java/com/zhongshu/card/server/core/dao/wallet/extend/WalletRechargeExtend.java
  16. 0 95
      FullCardServer/src/main/java/com/zhongshu/card/server/core/dao/wallet/impl/WalletRechargeDaoImpl.java
  17. 30 0
      FullCardServer/src/main/java/com/zhongshu/card/server/core/domain/pay/BalanceRechargeOrder.java
  18. 47 0
      FullCardServer/src/main/java/com/zhongshu/card/server/core/domain/pay/PayAccount.java
  19. 8 1
      FullCardServer/src/main/java/com/zhongshu/card/server/core/domain/wallet/Wallet.java
  20. 84 0
      FullCardServer/src/main/java/com/zhongshu/card/server/core/service/pay/BalancePayService.java
  21. 143 0
      FullCardServer/src/main/java/com/zhongshu/card/server/core/service/pay/PayAccountService.java
  22. 0 259
      FullCardServer/src/main/java/com/zhongshu/card/server/core/service/wallet/WalletService.java
  23. 15 0
      FullCardServer/src/main/java/com/zhongshu/card/server/core/stream/WeChatMiniAppPayStream.java

+ 22 - 0
FullCardClient/src/main/java/com/zhongshu/card/client/model/pay/PayAccountParam.java

@@ -0,0 +1,22 @@
+package com.zhongshu.card.client.model.pay;
+
+import com.github.microservice.types.payment.PaymentType;
+import com.zhongshu.card.client.type.payAccount.PayAccountLevel;
+import jakarta.validation.constraints.NotEmpty;
+import lombok.Data;
+
+@Data
+public class PayAccountParam {
+
+    private String userId;
+
+    @NotEmpty
+    private String projectOid;
+
+    @NotEmpty
+    private String oid;
+
+    private PaymentType paymentType;
+
+    private PayAccountLevel level;
+}

+ 32 - 0
FullCardClient/src/main/java/com/zhongshu/card/client/model/pay/RechargeOrderModel.java

@@ -0,0 +1,32 @@
+package com.zhongshu.card.client.model.pay;
+
+import com.zhongshu.card.client.type.payAccount.RechargeOrderStatus;
+import io.swagger.v3.oas.annotations.media.Schema;
+import lombok.Data;
+
+import java.math.BigDecimal;
+
+@Data
+public class RechargeOrderModel {
+
+    private String id;
+
+    private Long createTime;
+
+    private Long updateTime;
+
+    @Schema(description = "支付账户")
+    private String payAccount;
+
+    @Schema(description = "预支付单号(用于前端调起支付的参数)")
+    private String prepay;
+
+    @Schema(description = "订单状态")
+    private RechargeOrderStatus status;
+
+    @Schema(description = "金额")
+    private BigDecimal total = BigDecimal.ZERO;
+
+    @Schema(description = "订单号")
+    private String orderNo;
+}

+ 39 - 0
FullCardClient/src/main/java/com/zhongshu/card/client/model/pay/RechargeParam.java

@@ -0,0 +1,39 @@
+package com.zhongshu.card.client.model.pay;
+
+import com.github.microservice.types.payment.PaymentType;
+import io.swagger.v3.oas.annotations.media.Schema;
+import lombok.Data;
+
+import java.math.BigDecimal;
+
+@Data
+public class RechargeParam {
+
+    @Schema(description = "appid")
+    private String appid;
+
+    @Schema(description = "支付渠道")
+    private PaymentType paymentType;
+
+    @Schema(description = "项目oid")
+    private String projectOid;
+
+    @Schema(description = "机构oid")
+    private String oid;
+
+    @Schema(description = "用户id")
+    private String userId;
+
+    @Schema(description = "openid")
+    private String openid;
+
+    @Schema(description = "金额")
+    private long total;
+
+    @Schema(description = "描述")
+    private String description;
+
+    @Schema(description = "订单id")
+    private String orderNo;
+
+}

+ 16 - 0
FullCardClient/src/main/java/com/zhongshu/card/client/type/payAccount/PayAccountLevel.java

@@ -0,0 +1,16 @@
+package com.zhongshu.card.client.type.payAccount;
+
+import lombok.Getter;
+
+public enum PayAccountLevel {
+
+    Parent("父账户"),
+    Children("子账户");
+
+    @Getter
+    private String remark;
+
+    PayAccountLevel(String remark) {
+        this.remark = remark;
+    }
+}

+ 19 - 0
FullCardClient/src/main/java/com/zhongshu/card/client/type/payAccount/RechargeOrderStatus.java

@@ -0,0 +1,19 @@
+package com.zhongshu.card.client.type.payAccount;
+
+import lombok.Getter;
+
+public enum RechargeOrderStatus {
+
+    Wait("待支付"),
+    Success("已支付"),
+    Expired("已过期"),
+    Cancel("已取消"),
+    Fail("支付失败")
+    ;
+
+    @Getter
+    String remark;
+    RechargeOrderStatus(String remark){
+        this.remark = remark;
+    }
+}

+ 18 - 0
FullCardClient/src/main/java/com/zhongshu/card/client/type/wallet/WalletType.java

@@ -0,0 +1,18 @@
+package com.zhongshu.card.client.type.wallet;
+
+import lombok.Getter;
+
+public enum WalletType {
+    Wechat("微信钱包"),
+    Balance("余额钱包"),
+
+    ;
+
+
+    @Getter
+    private String remark;
+
+    WalletType(String remark) {
+        this.remark = remark;
+    }
+}

+ 34 - 0
FullCardServer/src/main/java/com/zhongshu/card/server/core/controller/openAPI/AccessRecordController.java

@@ -0,0 +1,34 @@
+package com.zhongshu.card.server.core.controller.openAPI;
+
+import com.zhongshu.opengateway.client.model.param.AccessRecordSearchParam;
+import com.zhongshu.opengateway.client.model.param.OpenApiSearchParam;
+import com.zhongshu.opengateway.client.model.ret.ResultContent;
+import com.zhongshu.opengateway.client.service.AccessRecordService;
+import io.swagger.v3.oas.annotations.Operation;
+import io.swagger.v3.oas.annotations.tags.Tag;
+import lombok.experimental.Delegate;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.data.domain.Pageable;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RequestMethod;
+import org.springframework.web.bind.annotation.RestController;
+
+@RestController
+@RequestMapping("/openApi/accessRecord")
+@Tag(name = "OpenApi--访问日志")
+public class AccessRecordController {
+
+    @Autowired
+    AccessRecordService accessRecordService;
+
+    @Operation(summary = "分页查询App下openApi", description = "分页查询App下openApi")
+//    @ResourceAuth(value = AuthConstant.SuperAdmin, type = AuthType.Platform, remark = "")
+//    @ResourceAuth(value = "openapi", type = AuthType.Project, remark = "")
+    @RequestMapping(value = "pageByApp", method = RequestMethod.POST)
+    public ResultContent pageByApp(AccessRecordSearchParam param) {
+        param.setPage(param.getPage());
+        param.setSize(param.getSize());
+        return accessRecordService.page(param);
+    }
+
+}

+ 26 - 0
FullCardServer/src/main/java/com/zhongshu/card/server/core/controller/pay/balance/RechargeController.java

@@ -0,0 +1,26 @@
+package com.zhongshu.card.server.core.controller.pay.balance;
+
+import com.zhongshu.card.client.model.pay.RechargeParam;
+import com.zhongshu.card.server.core.service.pay.BalancePayService;
+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.web.bind.annotation.RequestBody;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RequestMethod;
+import org.springframework.web.bind.annotation.RestController;
+
+@RestController
+@RequestMapping("balance/recharge")
+@Tag(name = "余额支付", description = "余额支付充值接口")
+public class RechargeController {
+
+    @Autowired
+    BalancePayService balancePayService;
+
+    @Operation(summary = "余额充值", description = "余额充值")
+    @RequestMapping(value = "recharge", method = RequestMethod.POST)
+    public Object recharge(@RequestBody RechargeParam param){
+        return balancePayService.recharge(param);
+    }
+}

+ 0 - 46
FullCardServer/src/main/java/com/zhongshu/card/server/core/controller/wallet/WalletController.java

@@ -1,46 +0,0 @@
-package com.zhongshu.card.server.core.controller.wallet;
-
-import com.github.microservice.auth.security.annotations.ResourceAuth;
-import com.github.microservice.auth.security.helper.AuthHelper;
-import com.github.microservice.auth.security.type.AuthType;
-import com.zhongshu.card.client.model.base.IDParam;
-import com.zhongshu.card.client.model.wallet.WalletModel;
-import com.zhongshu.card.client.model.wallet.WalletRechargeModel;
-import com.zhongshu.card.client.model.wallet.WalletRechargeParam;
-import com.zhongshu.card.client.model.wallet.WalletRechargeSearch;
-import com.github.microservice.net.ResultContent;
-import com.zhongshu.card.server.core.domain.wallet.Wallet;
-import com.zhongshu.card.server.core.service.wallet.WalletService;
-import io.swagger.v3.oas.annotations.Hidden;
-import io.swagger.v3.oas.annotations.Operation;
-import io.swagger.v3.oas.annotations.Parameter;
-import io.swagger.v3.oas.annotations.tags.Tag;
-import lombok.extern.slf4j.Slf4j;
-import org.apache.commons.lang3.StringUtils;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.data.domain.Page;
-import org.springframework.data.domain.Pageable;
-import org.springframework.data.web.PageableDefault;
-import org.springframework.web.bind.annotation.RequestBody;
-import org.springframework.web.bind.annotation.RequestMapping;
-import org.springframework.web.bind.annotation.RequestMethod;
-import org.springframework.web.bind.annotation.RestController;
-
-/**
- * @author TRX
- * @date 2024/6/29
- */
-@Slf4j
-@RestController
-@RequestMapping("wallet")
-@Tag(name = "个人-钱包")
-@Hidden
-public class WalletController {
-
-    @Autowired
-    WalletService walletService;
-
-    @Autowired
-    AuthHelper authHelper;
-
-}

+ 7 - 0
FullCardServer/src/main/java/com/zhongshu/card/server/core/dao/pay/BalanceRechargeOrderDao.java

@@ -0,0 +1,7 @@
+package com.zhongshu.card.server.core.dao.pay;
+
+import com.github.microservice.components.data.mongo.mongo.dao.MongoDao;
+import com.zhongshu.card.server.core.domain.pay.BalanceRechargeOrder;
+
+public interface BalanceRechargeOrderDao extends MongoDao<BalanceRechargeOrder> {
+}

+ 14 - 0
FullCardServer/src/main/java/com/zhongshu/card/server/core/dao/pay/PayAccountDao.java

@@ -0,0 +1,14 @@
+package com.zhongshu.card.server.core.dao.pay;
+
+import com.github.microservice.components.data.mongo.mongo.dao.MongoDao;
+import com.github.microservice.types.payment.PaymentChannelType;
+import com.zhongshu.card.client.type.payAccount.PayAccountLevel;
+import com.zhongshu.card.server.core.dao.pay.extend.PayAccountDaoExtend;
+import com.zhongshu.card.server.core.domain.pay.PayAccount;
+
+public interface PayAccountDao extends MongoDao<PayAccount>, PayAccountDaoExtend {
+
+    PayAccount findTopByProjectOidAndOidAndLevelAndPaymentChannelType(String projectOid, String oid, PayAccountLevel level, PaymentChannelType paymentChannelType);
+
+    PayAccount findTopByProjectOidAndOidAndLevel(String projectOid, String oid, PayAccountLevel level);
+}

+ 4 - 0
FullCardServer/src/main/java/com/zhongshu/card/server/core/dao/pay/extend/PayAccountDaoExtend.java

@@ -0,0 +1,4 @@
+package com.zhongshu.card.server.core.dao.pay.extend;
+
+public interface PayAccountDaoExtend {
+}

+ 6 - 0
FullCardServer/src/main/java/com/zhongshu/card/server/core/dao/pay/impl/PayAccountDaoImpl.java

@@ -0,0 +1,6 @@
+package com.zhongshu.card.server.core.dao.pay.impl;
+
+import com.zhongshu.card.server.core.dao.pay.extend.PayAccountDaoExtend;
+
+public class PayAccountDaoImpl implements PayAccountDaoExtend {
+}

+ 0 - 11
FullCardServer/src/main/java/com/zhongshu/card/server/core/dao/wallet/WalletRechargeDao.java

@@ -1,11 +0,0 @@
-package com.zhongshu.card.server.core.dao.wallet;
-
-import com.github.microservice.components.data.mongo.mongo.dao.MongoDao;
-import com.zhongshu.card.server.core.dao.wallet.extend.WalletRechargeExtend;
-import com.zhongshu.card.server.core.domain.wallet.WalletRecharge;
-
-public interface WalletRechargeDao extends MongoDao<WalletRecharge>, WalletRechargeExtend {
-
-    WalletRecharge findTopById(String id);
-
-}

+ 0 - 15
FullCardServer/src/main/java/com/zhongshu/card/server/core/dao/wallet/extend/WalletRechargeExtend.java

@@ -1,15 +0,0 @@
-package com.zhongshu.card.server.core.dao.wallet.extend;
-
-import com.zhongshu.card.client.model.wallet.WalletRechargeSearch;
-import com.zhongshu.card.server.core.domain.wallet.WalletRecharge;
-import org.springframework.data.domain.Page;
-import org.springframework.data.domain.Pageable;
-
-/**
- * @Author TRX
- * @CreateDate: 2023/7/7
- * @Version: 1.0
- */
-public interface WalletRechargeExtend {
-    Page<WalletRecharge> page(Pageable pageable, WalletRechargeSearch param);
-}

+ 0 - 95
FullCardServer/src/main/java/com/zhongshu/card/server/core/dao/wallet/impl/WalletRechargeDaoImpl.java

@@ -1,95 +0,0 @@
-package com.zhongshu.card.server.core.dao.wallet.impl;
-
-import com.github.microservice.components.data.mongo.mongo.helper.DBHelper;
-import com.zhongshu.card.client.model.wallet.WalletRechargeSearch;
-import com.zhongshu.card.server.core.dao.BaseImpl;
-import com.zhongshu.card.server.core.dao.wallet.extend.WalletRechargeExtend;
-import com.zhongshu.card.server.core.domain.wallet.WalletRecharge;
-import com.zhongshu.card.server.core.util.CommonUtil;
-import org.apache.commons.lang3.ObjectUtils;
-import org.apache.commons.lang3.StringUtils;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.data.domain.Page;
-import org.springframework.data.domain.Pageable;
-import org.springframework.data.domain.Sort;
-import org.springframework.data.mongodb.core.MongoTemplate;
-import org.springframework.data.mongodb.core.query.Criteria;
-import org.springframework.data.mongodb.core.query.Query;
-
-/**
- * @Author TRX
- * @CreateDate: 2023/4/12
- * @Version: 1.0
- */
-public class WalletRechargeDaoImpl extends BaseImpl implements WalletRechargeExtend {
-
-    @Autowired
-    private MongoTemplate mongoTemplate;
-
-    @Autowired
-    private DBHelper dbHelper;
-
-    @Override
-    public Page<WalletRecharge> page(Pageable pageable, WalletRechargeSearch param) {
-        Criteria criteria = new Criteria();
-
-        //
-        if (ObjectUtils.isNotEmpty(param.getUserId())) {
-            criteria.and("userId").is(param.getUserId());
-        }
-
-        // 充值类型
-        if (param.getRechargeType() != null) {
-            criteria.and("rechargeType").is(param.getRechargeType());
-        }
-
-        if (StringUtils.isNotEmpty(param.getAboutDataId())) {
-            criteria.and("aboutDataId").is(param.getAboutDataId());
-        }
-
-        if (StringUtils.isNotEmpty(param.getYear())) {
-            criteria.and("year").is(param.getYear());
-        }
-
-        if (StringUtils.isNotEmpty(param.getMonth())) {
-            criteria.and("month").is(CommonUtil.turnMonthSearch(param.getMonth()));
-        }
-
-        if (!CommonUtil.longIsEmpty(param.getStartTime()) && !CommonUtil.longIsEmpty(param.getEndTime())) {
-            criteria.and("createTime").gte(param.getStartTime()).and("createTime").lte(param.getEndTime());
-        }
-
-//        // 模糊搜索
-//        List<Criteria> criterias = new ArrayList<>();
-//        if (StringUtils.isNotEmpty(param.getName())) {
-//            Pattern pattern = Pattern.compile("^.*" + param.getName() + ".*$");
-//            criterias.add(Criteria.where("name").is(pattern));
-//        }
-//        if (StringUtils.isNotEmpty(param.getPhone())) {
-//            Pattern pattern = Pattern.compile("^.*" + param.getPhone() + ".*$");
-//            criterias.add(Criteria.where("phone").is(pattern));
-//        }
-//        if (StringUtils.isNotEmpty(param.getIdCard())) {
-//            Pattern pattern = Pattern.compile("^.*" + param.getIdCard() + ".*$");
-//            criterias.add(Criteria.where("idCard").is(pattern));
-//        }
-//        if (StringUtils.isNotEmpty(param.getCode())) {
-//            Pattern pattern = Pattern.compile("^.*" + param.getCode() + ".*$");
-//            criterias.add(Criteria.where("code").is(pattern));
-//        }
-//
-//        if (StringUtils.isNotEmpty(param.getClassName())) {
-//            Pattern pattern = Pattern.compile("^.*" + param.getClassName() + ".*$");
-//            criterias.add(Criteria.where("className").is(pattern));
-//        }
-//        if (!CollectionUtils.isEmpty(criterias)) {
-//            criteria.andOperator(criterias.toArray(new Criteria[]{}));
-//        }
-        criteria.and("isDelete").is(Boolean.FALSE);
-        Sort sort = buildSort(param);
-        Query query = Query.query(criteria);
-        query.with(sort);
-        return dbHelper.pages(query, pageable, WalletRecharge.class);
-    }
-
-}

+ 30 - 0
FullCardServer/src/main/java/com/zhongshu/card/server/core/domain/pay/BalanceRechargeOrder.java

@@ -0,0 +1,30 @@
+package com.zhongshu.card.server.core.domain.pay;
+
+import com.github.microservice.components.data.mongo.mongo.domain.SuperEntity;
+import com.zhongshu.card.client.type.RechargeType;
+import com.zhongshu.card.client.type.payAccount.RechargeOrderStatus;
+import io.swagger.v3.oas.annotations.media.Schema;
+import lombok.Data;
+import org.springframework.data.mongodb.core.mapping.Document;
+
+import java.math.BigDecimal;
+
+@Data
+@Document
+public class BalanceRechargeOrder extends SuperEntity {
+
+    @Schema(description = "支付账户")
+    private String payAccount;
+
+    @Schema(description = "预支付单号(用于前端调起支付的参数)")
+    private String prepayId;
+
+    @Schema(description = "订单状态")
+    private RechargeOrderStatus status;
+
+    @Schema(description = "金额")
+    private BigDecimal total = BigDecimal.ZERO;
+
+    @Schema(description = "订单号")
+    private String orderNo;
+}

+ 47 - 0
FullCardServer/src/main/java/com/zhongshu/card/server/core/domain/pay/PayAccount.java

@@ -0,0 +1,47 @@
+package com.zhongshu.card.server.core.domain.pay;
+
+import com.github.microservice.components.data.mongo.mongo.domain.SuperEntity;
+import com.github.microservice.types.payment.PaymentChannelType;
+import com.github.microservice.types.payment.PaymentType;
+import com.zhongshu.card.client.type.payAccount.PayAccountLevel;
+import com.zhongshu.card.server.core.domain.org.UserAccount;
+import lombok.Data;
+import org.springframework.data.mongodb.core.mapping.DBRef;
+import org.springframework.data.mongodb.core.mapping.Document;
+
+import java.math.BigDecimal;
+
+@Data
+@Document
+public class PayAccount extends SuperEntity {
+
+    private String ledgerId;
+
+    //父账户
+    @DBRef(lazy = true)
+    private PayAccount parent;
+
+    //账户级别
+    private PayAccountLevel level;
+
+    //用户id
+    private String userId;
+
+    @DBRef(lazy = true)
+    private UserAccount userAccount;
+
+    //机构id
+    private String oid;
+
+    //项目id
+    private String projectOid;
+
+    //账户类型(余额,无感支付,补贴, 扫码)
+    private PaymentChannelType paymentChannelType;
+
+    //支付渠道
+    private PaymentType paymentType;
+
+    //余额
+    private BigDecimal amount;
+}

+ 8 - 1
FullCardServer/src/main/java/com/zhongshu/card/server/core/domain/wallet/Wallet.java

@@ -3,6 +3,7 @@ package com.zhongshu.card.server.core.domain.wallet;
 import com.zhongshu.card.client.type.DataState;
 import com.zhongshu.card.server.core.domain.base.SuperMain;
 import com.zhongshu.card.server.core.domain.org.UserAccount;
+import com.zhongshu.payment.client.types.WalletType;
 import io.swagger.v3.oas.annotations.media.Schema;
 import lombok.AllArgsConstructor;
 import lombok.Builder;
@@ -33,7 +34,13 @@ public class Wallet extends SuperMain {
     @DBRef(lazy = true)
     private UserAccount userAccount;
 
-    @Schema(description = "可用金额,单位:分")
+    @Schema(description = "类型")
+    private WalletType walletType;
+
+    @Schema(description = "支付账户-对应支付中心")
+    private String payAccount;
+
+    @Schema(description = "余额,单位:分")
     private BigDecimal amount = BigDecimal.ZERO;
 
     @Schema(description = "钱包状态:是否可用")

+ 84 - 0
FullCardServer/src/main/java/com/zhongshu/card/server/core/service/pay/BalancePayService.java

@@ -0,0 +1,84 @@
+package com.zhongshu.card.server.core.service.pay;
+
+import com.github.microservice.core.util.JsonUtil;
+import com.github.microservice.core.util.bean.BeanUtil;
+import com.github.microservice.pay.client.model.PayProductParameter;
+import com.github.microservice.pay.client.ret.ResultContent;
+import com.github.microservice.pay.client.ret.ResultState;
+import com.github.microservice.pay.client.service.product.MiniAppPayService;
+import com.github.microservice.types.payment.PaymentType;
+import com.zhongshu.card.client.model.pay.PayAccountParam;
+import com.zhongshu.card.client.model.pay.RechargeOrderModel;
+import com.zhongshu.card.client.model.pay.RechargeParam;
+import com.zhongshu.card.client.type.payAccount.PayAccountLevel;
+import com.zhongshu.card.client.type.payAccount.RechargeOrderStatus;
+import com.zhongshu.card.server.core.dao.pay.BalanceRechargeOrderDao;
+import com.zhongshu.card.server.core.domain.pay.BalanceRechargeOrder;
+import com.zhongshu.card.server.core.domain.pay.PayAccount;
+import com.zhongshu.card.server.core.service.paySetting.OrgPayAccountService;
+import com.zhongshu.card.server.core.util.BeanUtils;
+import com.zhongshu.card.server.core.util.CommonUtil;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+
+import java.math.BigDecimal;
+import java.util.LinkedHashMap;
+import java.util.Map;
+
+@Service
+public class BalancePayService {
+
+    @Autowired
+    PayAccountService payAccountService;
+
+    @Autowired
+    MiniAppPayService miniAppPayService;
+
+    @Autowired
+    BalanceRechargeOrderDao rechargeOrderDao;
+
+    @Autowired
+    OrgPayAccountService orgPayAccountService;
+
+
+    /**
+     * 下单并生成调用支付参数
+     */
+    public Object recharge(RechargeParam param){
+        //根据项目id和支付渠道获取支付账户名
+        orgPayAccountService.getProjectWxAccount(param.getProjectOid());
+        String accountName = "";
+
+        //创建业务账户及支付中心账本
+        PayAccount payAccount = payAccountService.get(param.getUserId(), param.getProjectOid(), param.getOid(), PayAccountLevel.Children, param.getPaymentType());
+        //生成订单id
+        String orderNo = param.getPaymentType().name()+CommonUtil.UUID();
+        //调用小程序支付
+        PayProductParameter<Object> payProductParameter = new PayProductParameter<>();
+        param.setOrderNo(orderNo);
+        Map<String, Object> meta = BeanUtil.bean2Map(param);
+        payProductParameter.setMeta(meta);
+        payProductParameter.setAccountName(accountName);
+        ResultContent<Object> prepay = miniAppPayService.prepay(payProductParameter);
+        if (!prepay.getState().equals(ResultState.Success)){
+            return prepay;
+        }
+        //创建订单
+        BalanceRechargeOrder balanceRechargeOrder = new BalanceRechargeOrder();
+        balanceRechargeOrder.setPayAccount(payAccount.getId());
+        balanceRechargeOrder.setStatus(RechargeOrderStatus.Wait);
+        balanceRechargeOrder.setOrderNo(orderNo);
+        balanceRechargeOrder.setTotal(new BigDecimal(param.getTotal()));
+        balanceRechargeOrder.setPrepayId(JsonUtil.toJson(prepay.getContent()));
+        rechargeOrderDao.save(balanceRechargeOrder);
+        return ResultContent.buildContent(toModel(balanceRechargeOrder));
+    }
+
+    private RechargeOrderModel toModel(BalanceRechargeOrder balanceRechargeOrder){
+        RechargeOrderModel rechargeOrderModel = new RechargeOrderModel();
+        if (balanceRechargeOrder != null){
+            BeanUtils.copyProperties(balanceRechargeOrder, rechargeOrderModel);
+        }
+        return rechargeOrderModel;
+    }
+}

+ 143 - 0
FullCardServer/src/main/java/com/zhongshu/card/server/core/service/pay/PayAccountService.java

@@ -0,0 +1,143 @@
+package com.zhongshu.card.server.core.service.pay;
+
+import com.github.microservice.auth.security.helper.AuthHelper;
+import com.github.microservice.core.util.JsonUtil;
+import com.github.microservice.pay.client.model.ledger.GeneralLedgerModel;
+import com.github.microservice.pay.client.model.ledger.GeneralLedgerTreeModel;
+import com.github.microservice.pay.client.ret.ResultState;
+import com.github.microservice.pay.client.service.ledger.GeneralLedgerService;
+import com.github.microservice.types.payment.PaymentType;
+import com.zhongshu.card.client.model.pay.PayAccountParam;
+import com.zhongshu.card.client.type.payAccount.PayAccountLevel;
+import com.zhongshu.card.server.core.dao.pay.PayAccountDao;
+import com.zhongshu.card.server.core.domain.pay.PayAccount;
+import com.zhongshu.card.server.core.service.paySetting.ProjectPaySettingServiceImpl;
+import lombok.SneakyThrows;
+import lombok.extern.slf4j.Slf4j;
+import org.apache.commons.lang3.StringUtils;
+import org.jetbrains.annotations.NotNull;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Transactional;
+
+import java.util.Map;
+
+@Service
+@Slf4j
+public class PayAccountService {
+
+    @Autowired
+    ProjectPaySettingServiceImpl projectPaySettingService;
+
+    @Autowired
+    PayAccountDao payAccountDao;
+
+    @Autowired
+    AuthHelper authHelper;
+
+    @Autowired
+    GeneralLedgerService generalLedgerService;
+
+    @Transactional
+    public PayAccount get(String userId, String projectOid, String oid, PayAccountLevel level, PaymentType paymentType){
+        PayAccount payAccount = payAccountDao.findTopByProjectOidAndOidAndLevelAndPaymentChannelType(projectOid,
+                oid, level, paymentType.getChannelType());
+        if (payAccount == null){
+            payAccount = upsert(userId, projectOid, oid, level, paymentType);
+        }
+        return payAccount;
+    }
+    /**
+     * 获取账户
+     */
+    @Transactional
+    public PayAccount get(PayAccountParam param){
+        //参数校验
+        return get(param.getUserId(), param.getProjectOid(), param.getOid(), param.getLevel(), param.getPaymentType());
+    }
+
+    /**
+     * 创建账户
+     */
+    @Transactional
+    @SneakyThrows
+    public PayAccount upsert(String userId, String projectOid, String oid, PayAccountLevel level, PaymentType paymentType){
+        //处理userId
+        if (StringUtils.isBlank(userId)){
+            userId = authHelper.getCurrentUser().getUserId();
+        }
+        PayAccount parent = payAccountDao.findTopByProjectOidAndOidAndLevel(projectOid,
+                oid, PayAccountLevel.Parent);
+        //创建父账户
+        if (parent==null){
+            parent = createParentPayAccount(projectOid, oid, paymentType, userId);
+        }
+        if (level.equals(PayAccountLevel.Parent)){
+            return parent;
+        }else {
+            PayAccount children = payAccountDao.findTopByProjectOidAndOidAndLevelAndPaymentChannelType(projectOid,
+                    oid, PayAccountLevel.Parent, paymentType.getChannelType());
+            //创建子账户
+            if (children==null){
+                createChildrenPayAccount(projectOid, oid, paymentType, userId, parent);
+            }
+            return children;
+        }
+    }
+
+    private void createChildrenPayAccount(String projectOid, String oid, PaymentType paymentType, String userId, PayAccount parent) throws Exception {
+        PayAccount children;
+        children = new PayAccount();
+        children.setParent(parent);
+        children.setProjectOid(projectOid);
+        children.setOid(oid);
+        children.setUserId(userId);
+        children.setLevel(PayAccountLevel.Children);
+//        children.setPaymentType(paymentType);
+        children.setPaymentChannelType(paymentType.getChannelType());
+        String ledgerId = createLedger(paymentType.getChannelType().getRemark(), parent.getLedgerId(), null);
+        if (StringUtils.isBlank(ledgerId)){
+            throw new Exception("支付中心创建子账本失败");
+        }
+        payAccountDao.save(children);
+    }
+
+    @NotNull
+    private PayAccount createParentPayAccount(String projectOid, String oid, PaymentType paymentType, String userId) throws Exception {
+        PayAccount parent;
+        parent = new PayAccount();
+        parent.setProjectOid(projectOid);
+        parent.setOid(oid);
+        parent.setUserId(userId);
+        parent.setLevel(PayAccountLevel.Parent);
+        String ledgerId = createLedger(paymentType.getChannelType().getRemark(), null, null);
+        if (StringUtils.isBlank(ledgerId)){
+            throw new Exception("支付中心创建父账本失败");
+        }
+        parent.setLedgerId(ledgerId);
+        payAccountDao.save(parent);
+        return parent;
+    }
+
+    private String createLedger(String name, String parentLedgerId, Map<String, Object> meta){
+        GeneralLedgerTreeModel ledgerModel = new GeneralLedgerTreeModel();
+        ledgerModel.setName(name);
+        ledgerModel.setBalanceRangeMax(999999L);
+        ledgerModel.setBalanceRangeMin(-100L);
+        ledgerModel.setMeta(meta);
+        if (StringUtils.isNotEmpty(parentLedgerId)){
+            GeneralLedgerModel parentLedger = new GeneralLedgerModel();
+            parentLedger.setId(parentLedgerId);
+            ledgerModel.setParent(parentLedger);
+        }
+
+        com.github.microservice.pay.client.ret.ResultContent<GeneralLedgerTreeModel> generalLedgerTreeModelResultContent = generalLedgerService.create(ledgerModel);
+
+        if (generalLedgerTreeModelResultContent.getState().equals(ResultState.Success)){
+            return generalLedgerTreeModelResultContent.getContent().getId();
+        }
+        log.error("支付中心创建账户失败:{}", JsonUtil.toJson(generalLedgerTreeModelResultContent));
+        return null;
+    }
+
+}

+ 0 - 259
FullCardServer/src/main/java/com/zhongshu/card/server/core/service/wallet/WalletService.java

@@ -1,259 +0,0 @@
-package com.zhongshu.card.server.core.service.wallet;
-
-import com.github.microservice.components.data.base.util.PageEntityUtil;
-import com.zhongshu.card.client.model.org.UserCountModel;
-import com.zhongshu.card.client.model.wallet.WalletModel;
-import com.zhongshu.card.client.model.wallet.WalletRechargeModel;
-import com.zhongshu.card.client.model.wallet.WalletRechargeParam;
-import com.zhongshu.card.client.model.wallet.WalletRechargeSearch;
-import com.github.microservice.net.ResultContent;
-import com.zhongshu.card.client.type.DataState;
-import com.zhongshu.card.client.type.RechargeType;
-import com.zhongshu.card.server.core.dao.org.UserCountDao;
-import com.zhongshu.card.server.core.dao.wallet.WalletDao;
-import com.zhongshu.card.server.core.dao.wallet.WalletRechargeDao;
-import com.zhongshu.card.server.core.domain.org.UserAccount;
-import com.zhongshu.card.server.core.domain.wallet.Wallet;
-import com.zhongshu.card.server.core.domain.wallet.WalletRecharge;
-import com.zhongshu.card.server.core.service.base.SuperService;
-import com.zhongshu.card.server.core.service.user.UserAccountServiceImpl;
-import com.zhongshu.card.server.core.util.BeanUtils;
-import com.zhongshu.card.server.core.util.CommonUtil;
-import com.zhongshu.card.client.utils.DateUtils;
-import lombok.extern.slf4j.Slf4j;
-import org.apache.commons.lang3.ObjectUtils;
-import org.apache.commons.lang3.StringUtils;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.data.domain.Page;
-import org.springframework.data.domain.Pageable;
-import org.springframework.stereotype.Service;
-import org.springframework.transaction.annotation.Transactional;
-
-import java.math.BigDecimal;
-import java.util.concurrent.locks.ReentrantLock;
-
-/**
- * @author TRX
- * @date 2024/6/29
- */
-@Slf4j
-@Service
-public class WalletService extends SuperService {
-
-    @Autowired
-    WalletDao walletDao;
-
-    @Autowired
-    WalletRechargeDao walletRechargeDao;
-
-    @Autowired
-    UserCountDao userCountDao;
-
-    @Autowired
-    UserAccountServiceImpl userAccountService;
-
-    private final ReentrantLock lock = new ReentrantLock();
-
-
-    public ResultContent checkUserWallet(String userId, BigDecimal amount) {
-        Wallet wallet = getUserWalletByUserId(userId);
-        if (wallet.getDataState() != DataState.Enable) {
-            return ResultContent.buildFail(String.format("支付失败钱包", wallet.getDataState().getRemark()));
-        }
-        if (wallet.getAmount().compareTo(amount) < 0) {
-            return ResultContent.buildFail("余额不足");
-        }
-        return ResultContent.buildSuccess();
-    }
-
-    /**
-     * 初始当前用户钱包
-     *
-     * @return
-     */
-    public ResultContent<Wallet> initCurrentUserWallet() {
-        String userId = getCurrentUserId();
-        return initUserWallet(userId);
-    }
-
-    /**
-     * 初始用户钱包
-     *
-     * @param userId
-     * @return
-     */
-    public ResultContent<Wallet> initUserWallet(String userId) {
-        if (StringUtils.isEmpty(userId)) {
-            return ResultContent.buildFail("userId不能为空");
-        }
-        UserAccount userAccount = userCountDao.findTopByUserId(userId);
-        if (ObjectUtils.isEmpty(userAccount)) {
-            return ResultContent.buildFail(String.format("用户不存在:%s", userId));
-        }
-        Wallet wallet = walletDao.findByUserId(userId);
-        if (ObjectUtils.isEmpty(wallet)) {
-            wallet = new Wallet();
-            initEntityNoCheckOid(wallet);
-            wallet.setAmount(BigDecimal.ZERO);
-            wallet.setUserId(userId);
-            wallet.setUserAccount(userAccount);
-            wallet.setDataState(DataState.Enable);
-            walletDao.save(wallet);
-        }
-        return ResultContent.buildSuccess(wallet);
-    }
-
-    /**
-     * 通过用户userId得到钱包
-     *
-     * @param userId
-     * @return
-     */
-    public Wallet getUserWalletByUserId(String userId) {
-        Wallet wallet = walletDao.findByUserId(userId);
-        if (ObjectUtils.isEmpty(wallet)) {
-            ResultContent<Wallet> resultContent = initUserWallet(userId);
-            if (resultContent.isSuccess()) {
-                wallet = resultContent.getContent();
-            }
-        }
-        return wallet;
-    }
-
-
-    /**
-     * 得到用户钱包信息
-     *
-     * @param userId
-     * @return
-     */
-    public ResultContent<WalletModel> getUserWallet(String userId) {
-        Wallet wallet = walletDao.findByUserId(userId);
-        if (ObjectUtils.isEmpty(wallet)) {
-            ResultContent<Wallet> resultContent = initUserWallet(userId);
-            if (resultContent.isFailed()) {
-                return ResultContent.buildFail(resultContent.getMsg());
-            }
-            wallet = resultContent.getContent();
-        }
-        return ResultContent.buildSuccess(toModel(wallet));
-    }
-
-    //---------------------------充值 start------------------------
-
-    /**
-     * 充值列表
-     *
-     * @param param
-     * @param pageable
-     * @return
-     */
-    public ResultContent<Page<WalletRechargeModel>> page(WalletRechargeSearch param, Pageable pageable) {
-        initOidSearchParamNoCheckOid(param);
-        Page<WalletRecharge> page = walletRechargeDao.page(pageable, param);
-        return ResultContent.buildSuccess(PageEntityUtil.concurrent2PageModel(page, this::toModel));
-    }
-
-    /**
-     * 充值
-     *
-     * @param param
-     * @return
-     */
-    @Transactional
-    public ResultContent addWalletRecharge(WalletRechargeParam param) {
-        String userId = param.getUserId();
-        UserAccount userAccount = userCountDao.findTopByUserId(userId);
-        if (ObjectUtils.isEmpty(userAccount)) {
-            return ResultContent.buildFail(String.format("用户不存在:%s", userId));
-        }
-        Wallet wallet = getUserWalletByUserId(userId);
-        // 充值金额
-        BigDecimal amount = param.getAmount();
-        if (CommonUtil.bigDecimalIsEmpty(amount)) {
-            return ResultContent.buildFail(String.format("充值金额不能小于等于0"));
-        }
-
-        try {
-            getLock().lock();
-            WalletRecharge walletRecharge = new WalletRecharge();
-            initEntityNoCheckOid(walletRecharge);
-            BigDecimal preAmount = wallet.getAmount();
-            if (CommonUtil.bigDecimalIsEmpty(preAmount)) {
-                preAmount = BigDecimal.ZERO;
-            }
-            BigDecimal afterAmount = preAmount.add(amount);
-            wallet.setAmount(afterAmount);
-
-            walletRecharge.setPreAmount(preAmount);
-            walletRecharge.setAmount(amount);
-            walletRecharge.setRechargeType(RechargeType.Active);
-            walletRecharge.setAfterAmount(afterAmount);
-            walletRecharge.setUserId(userId);
-            walletRecharge.setUserAccount(userAccount);
-            walletRecharge.setWallet(wallet);
-            walletRecharge.setUserName(userAccount.getName());
-            walletRecharge.setPhone(userAccount.getPhone());
-            walletRecharge.setYear(DateUtils.paresTime(System.currentTimeMillis(), DateUtils.patternyyyy));
-            walletRecharge.setMonth(DateUtils.paresTime(System.currentTimeMillis(), DateUtils.patternMM));
-            walletRecharge.setTimeStr(DateUtils.paresTime(System.currentTimeMillis(), DateUtils.patternyyyySSS));
-
-            walletDao.save(wallet);
-            walletRechargeDao.save(walletRecharge);
-        } catch (Exception e) {
-            e.printStackTrace();
-            getLock().unlock();
-        }
-        return ResultContent.buildSuccess();
-    }
-
-
-    /**
-     * 得到充值详情
-     *
-     * @param id
-     * @return
-     */
-    public ResultContent<WalletRechargeModel> getUserWalletRecharge(String id) {
-        WalletRecharge walletRecharge = walletRechargeDao.findTopById(id);
-        if (ObjectUtils.isEmpty(walletRecharge)) {
-            return ResultContent.buildFail(String.format("数据ID不存在:%s", id));
-        }
-        return ResultContent.buildSuccess(toModelIncludeUser(walletRecharge));
-    }
-
-    //---------------------------充值 end--------------------------
-
-    public WalletModel toModel(Wallet entity) {
-        WalletModel model = null;
-        if (ObjectUtils.isNotEmpty(entity)) {
-            model = new WalletModel();
-            BeanUtils.copyProperties(entity, model);
-        }
-        return model;
-    }
-
-    public WalletRechargeModel toModel(WalletRecharge entity) {
-        WalletRechargeModel model = null;
-        if (ObjectUtils.isNotEmpty(entity)) {
-            model = new WalletRechargeModel();
-            BeanUtils.copyProperties(entity, model);
-        }
-        return model;
-    }
-
-    public WalletRechargeModel toModelIncludeUser(WalletRecharge entity) {
-        WalletRechargeModel model = null;
-        if (ObjectUtils.isNotEmpty(entity)) {
-            model = new WalletRechargeModel();
-            BeanUtils.copyProperties(entity, model);
-            UserCountModel userAccount = userAccountService.toModel(entity.getUserAccount());
-            model.setUserCount(userAccount);
-        }
-        return model;
-    }
-
-    public ReentrantLock getLock() {
-        return lock;
-    }
-}

+ 15 - 0
FullCardServer/src/main/java/com/zhongshu/card/server/core/stream/WeChatMiniAppPayStream.java

@@ -0,0 +1,15 @@
+package com.zhongshu.card.server.core.stream;
+
+import com.github.microservice.app.stream.StreamConsumer;
+import com.github.microservice.pay.client.model.weChatMiniApp.WeChatMiniAppPayRet;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.stereotype.Component;
+
+@Slf4j
+@Component("WeChatMiniAppPayStream")
+public class WeChatMiniAppPayStream extends StreamConsumer<WeChatMiniAppPayRet> {
+    @Override
+    public void accept(WeChatMiniAppPayRet weChatMiniAppPayRet) {
+
+    }
+}