wujiefeng 1 an în urmă
părinte
comite
6d73891e8d

+ 10 - 0
FullCardClient/src/main/java/com/zhongshu/card/client/model/pay/WithdrawOrderModel.java

@@ -1,6 +1,7 @@
 package com.zhongshu.card.client.model.pay;
 
 import com.github.microservice.types.payment.PaymentType;
+import com.zhongshu.card.client.type.AuditStatus;
 import com.zhongshu.card.client.type.WithdrawStatus;
 import com.zhongshu.card.client.type.paySetting.WithdrawMethodType;
 import com.zhongshu.card.client.type.paySetting.WithdrawType;
@@ -52,6 +53,9 @@ public class WithdrawOrderModel {
     @Schema(description = "附件")
     private List<AttachFileModel> attachFile;
 
+    @Schema(description = "审核状态")
+    private AuditStatus auditStatus;
+
     @Schema(description = "提现状态")
     private WithdrawStatus withdrawStatus;
 
@@ -61,9 +65,15 @@ public class WithdrawOrderModel {
     @Schema(description = "发起人")
     private String withdrawUser;
 
+    @Schema(description = "发起人UserId")
+    private String withdrawUserId;
+
     @Schema(description = "处理人")
     private String processUser;
 
+    @Schema(description = "处理人userId")
+    private String processUserId;
+
     @Schema(description = "处理时间")
     private Long processTime;
 

+ 7 - 0
FullCardServer/src/main/java/com/zhongshu/card/server/core/controller/pay/statistics/PayOverviewController.java

@@ -47,4 +47,11 @@ public class PayOverviewController {
                                         @Parameter(required = true) PeriodDetailQueryModel periodDetailQueryModel){
         return orgOverviewService.queryCreditBillDetail(pageable, periodDetailQueryModel);
     }
+
+    @Operation(summary = "查询结算账单", description = "查询收入账单详情")
+    @RequestMapping(value = "querySettleBill", method = RequestMethod.POST)
+    public Object querySettleBill(@Parameter(hidden = true) @PageableDefault(page = 0, size = 10) Pageable pageable,
+                                  @Parameter(required = false) PeriodQueryModel param){
+        return orgOverviewService.querySettleBill(pageable, param);
+    }
 }

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

@@ -1,6 +1,7 @@
 package com.zhongshu.card.server.core.dao.pay.extend;
 
 import com.zhongshu.card.client.model.pay.WithdrawPageParam;
+import com.zhongshu.card.client.type.WithdrawStatus;
 import com.zhongshu.card.server.core.domain.pay.WithdrawOrder;
 import org.springframework.data.domain.Page;
 import org.springframework.data.domain.Pageable;
@@ -8,4 +9,6 @@ import org.springframework.data.domain.Pageable;
 public interface WithdrawOrderDaoExtend {
 
     Page<WithdrawOrder> page(Pageable pageable, String projectOid, String oid, Long startTime, Long endTime, String search);
+
+    boolean updateWithdrawStatus(String id, WithdrawStatus status, String withdrawStatusDesc);
 }

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

@@ -1,7 +1,9 @@
 package com.zhongshu.card.server.core.dao.pay.impl;
 
+import com.github.microservice.components.data.mongo.mongo.dao.MongoDao;
 import com.github.microservice.components.data.mongo.mongo.helper.DBHelper;
 import com.zhongshu.card.client.model.pay.WithdrawPageParam;
+import com.zhongshu.card.client.type.WithdrawStatus;
 import com.zhongshu.card.server.core.dao.pay.WithdrawOrderDao;
 import com.zhongshu.card.server.core.dao.pay.extend.WithdrawOrderDaoExtend;
 import com.zhongshu.card.server.core.domain.pay.WithdrawOrder;
@@ -10,8 +12,10 @@ 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;
+import org.springframework.data.mongodb.core.query.Update;
 
 import java.util.regex.Pattern;
 
@@ -20,6 +24,9 @@ public class WithdrawOrderDaoImpl implements WithdrawOrderDaoExtend {
     @Autowired
     DBHelper dbHelper;
 
+    @Autowired
+    MongoTemplate mongoTemplate;
+
     @Override
     public Page<WithdrawOrder> page(Pageable pageable, String projectOid, String oid, Long startTime, Long endTime, String search) {
         Criteria criteria = new Criteria();
@@ -45,4 +52,19 @@ public class WithdrawOrderDaoImpl implements WithdrawOrderDaoExtend {
         query.with(Sort.by(Sort.Order.asc("sort"), Sort.Order.desc("createTime")));
         return dbHelper.pages(query, pageable, WithdrawOrder.class);
     }
+
+    @Override
+    public boolean updateWithdrawStatus(String id, WithdrawStatus status, String withdrawStatusDesc) {
+
+        Criteria criteria = new Criteria();
+        criteria.and("_id").is(id);
+        criteria.and("withdrawStatus").is(WithdrawStatus.Accepted);
+        Query query = new Query(criteria);
+
+        Update update = new Update();
+        update.set("withdrawStatus", status);
+        update.set("withdrawStatusDesc", withdrawStatusDesc);
+        dbHelper.updateTime(update);
+        return mongoTemplate.updateFirst(query, update, WithdrawOrder.class).getMatchedCount() > 0;
+    }
 }

+ 60 - 15
FullCardServer/src/main/java/com/zhongshu/card/server/core/service/pay/WithdrawService.java

@@ -4,7 +4,6 @@ import com.github.microservice.components.data.base.util.PageEntityUtil;
 import com.github.microservice.components.data.mongo.queue.service.ExecQueueService;
 import com.github.microservice.core.util.JsonUtil;
 import com.github.microservice.pay.client.model.AccountModel;
-import com.github.microservice.pay.client.model.PayProductChannelConf;
 import com.github.microservice.pay.client.model.PayProductParameter;
 import com.github.microservice.pay.client.model.ledger.GeneralLedgerQueryModel;
 import com.github.microservice.pay.client.model.ledger.TransactionLogModel;
@@ -52,7 +51,6 @@ import org.springframework.data.domain.Pageable;
 import org.springframework.stereotype.Service;
 
 import java.math.BigDecimal;
-import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
 
@@ -401,8 +399,12 @@ public class WithdrawService extends SuperService {
                 withdrawOrder.setProcessTime(System.currentTimeMillis());
                 withdrawOrderDao.save(withdrawOrder);
                 execQueueService.add(Map.of("withdrawOrderId", withdrawOrder.getId()), 5, data->{
-                    withdrawQuery((String) data.get("withdrawOrderId"));
-                    return false;
+                    com.github.microservice.net.ResultContent<WithdrawStatus> resultContent = withdrawQuery((String) data.get("withdrawUserId"));
+                    if (resultContent.getState().equals(com.github.microservice.net.ResultState.Success)){
+                        WithdrawStatus withdrawStatus = resultContent.getContent();
+                        return !withdrawStatus.equals(WithdrawStatus.Accepted);
+                    }
+                    return true;
                 });
                 return com.github.microservice.net.ResultContent.buildSuccess();
             }
@@ -460,16 +462,17 @@ public class WithdrawService extends SuperService {
     private WithdrawOrderModel toModel(WithdrawOrder withdrawOrder){
         WithdrawOrderModel model = new WithdrawOrderModel();
         if (withdrawOrder!=null){
-            BeanUtils.copyProperties(withdrawOrder, model, "withdrawUser", "processUser");
+            BeanUtils.copyProperties(withdrawOrder, model);
         }
         return model;
     }
 
+
     /**
      * 查询提现状态
      */
     @SneakyThrows
-    public Object withdrawQuery(String id){
+    public com.github.microservice.net.ResultContent<WithdrawStatus> withdrawQuery(String id){
         //获取提现订单数据
         WithdrawOrder withdrawOrder = withdrawOrderDao.findTop1ById(id);
         if (withdrawOrder == null){
@@ -477,13 +480,17 @@ public class WithdrawService extends SuperService {
         }
 
         if (!WithdrawStatus.Accepted.equals(withdrawOrder.getWithdrawStatus())){
-//            return ResultContent.buildContent(withdrawOrder.getWithdrawStatus())
+            return com.github.microservice.net.ResultContent.buildContent(withdrawOrder.getWithdrawStatus());
         }
 
+        PayAccount withdrawFrozenAccount = payAccountService.getOrgChildren(withdrawOrder.getProjectOid(), withdrawOrder.getOid(), PaymentChannelType.WithdrawFrozen);
+        PayAccount projectAccount = payAccountService.getProjectChildren(withdrawOrder.getProjectOid(), PaymentChannelType.SecretFreePayment);
+        PayAccount settleAccount = payAccountService.getOrgChildren(withdrawOrder.getProjectOid(), withdrawOrder.getOid(), PaymentChannelType.Settle);
+
+
         switch (withdrawOrder.getPaymentType()){
             case UnionFrictionlessPay -> {
 
-
                 String orgAccount = orgPayAccountService.queryOgPayAccount(withdrawOrder.getOid(), PaymentType.UnionFrictionlessPay);
                 String projectPayAccount = orgPayAccountService.queryOgPayAccount(withdrawOrder.getProjectOid(), PaymentType.UnionFrictionlessPay);
 
@@ -506,20 +513,58 @@ public class WithdrawService extends SuperService {
 
                 ResultContent<Object> resultContent = senselessPayService.withdrawQuery(parameter);
                 if (!resultContent.getState().equals(ResultState.Success)){
-                    return resultContent;
+                    return com.github.microservice.net.ResultContent.buildFail("银联请求失败");
                 }
                 String json = JsonUtil.toJson(resultContent.getContent());
                 Map map = JsonUtil.toObject(json, Map.class);
-                //TODO 有问题,提现时,如果是银联,则不从机构冻结账本- 项目账本+,这里成功再加,这里失败,机构冻结- 机构已结算账本+
 
-                PayAccount orgChildren = payAccountService.getOrgChildren(withdrawOrder.getProjectOid(), withdrawOrder.getOid(), PaymentChannelType.WithdrawFrozen);
-                PayAccount projectChildren = payAccountService.getProjectChildren(withdrawOrder.getProjectOid(), withdrawOrder.getPaymentType().getChannelType());
+                if (!map.get("respCode").equals("000000")){//查询成功
+                    return com.github.microservice.net.ResultContent.buildFail("银联请求错误");
+                }
+                String status = (String) map.get("status");
+                if (status.equals("-1") || status.equals("0") || status.equals("1") || status.equals("2") || status.equals("6")){
+                    return com.github.microservice.net.ResultContent.buildContent(WithdrawStatus.Accepted);
+                }
 
-//                buildTransferModel(projectChildren, orgChildren, withdrawOrder.getOrderNo(), withdrawOrder.getAmount(), TransactionType.Withdrawal, )
-                return ResultContent.buildContent(map.get("desc"));
+                if (status.equals("3")){
+                    boolean update = withdrawOrderDao.updateWithdrawStatus(withdrawOrder.getId(), WithdrawStatus.Success, (String) map.get("desc"));
+                    if (!update){
+                        return com.github.microservice.net.ResultContent.buildFail("系统繁忙请重试");
+                    }
+                    //TODO 处理账单
+                    //划账,机构已冻结金额- 项目无感支付+
+                    TransferTransactionsModel transferTransactionsModel = buildTransferModel(projectAccount, withdrawFrozenAccount, withdrawOrder.getOrderNo(),
+                            withdrawOrder.getAmount(), TransactionType.Withdrawal,
+                            Map.of("paymentType", withdrawOrder.getPaymentType(), "paymentChannelType", withdrawOrder.getPaymentType().getChannelType(), "description", "提现"));
+                    ResultContent<List<TransactionLogModel>> transferResult = transactionLogService.transfer(transferTransactionsModel);
+                    if (!transferResult.getState().equals(ResultState.Success)){
+                        return com.github.microservice.net.ResultContent.buildFail(transferResult.getMsg());
+                    }
+                    withdrawOrder.setWithdrawTransactionLogs(transferResult.getContent());
+                    withdrawOrderDao.save(withdrawOrder);
+                    return com.github.microservice.net.ResultContent.buildContent(WithdrawStatus.Success);
+                }
+
+                if (status.equals("4")){
+                    boolean update = withdrawOrderDao.updateWithdrawStatus(withdrawOrder.getId(), WithdrawStatus.Fail, (String) map.get("desc"));
+                    if (!update){
+                        return com.github.microservice.net.ResultContent.buildFail("系统繁忙请重试");
+                    }
+                    //TODO 处理账单
+                    TransferTransactionsModel transferTransactionsModel = buildTransferModel(settleAccount, withdrawFrozenAccount, withdrawOrder.getOrderNo(),
+                            withdrawOrder.getAmount(), TransactionType.WithdrawRefund,
+                            Map.of("paymentType", withdrawOrder.getPaymentType(), "paymentChannelType", withdrawOrder.getPaymentType().getChannelType(), "description", "提现退回"));
+                    ResultContent<List<TransactionLogModel>> transfer = transactionLogService.transfer(transferTransactionsModel);
+                    if (!transfer.getState().equals(ResultState.Success)){
+                        return com.github.microservice.net.ResultContent.buildFail("余额退回失败");
+                    }
+                    withdrawOrder.setWithdrawTransactionLogs(transfer.getContent());
+                    withdrawOrderDao.save(withdrawOrder);
+                    return com.github.microservice.net.ResultContent.buildContent(WithdrawStatus.Fail);
+                }
             }
         }
-        return ResultContent.buildContent(withdrawOrder.getWithdrawStatus().getRemark());
+        return com.github.microservice.net.ResultContent.buildContent(withdrawOrder.getWithdrawStatus());
     }
 
     /**