Jelajahi Sumber

机构资金-提现

wujiefeng 1 tahun lalu
induk
melakukan
716030094a

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

@@ -0,0 +1,78 @@
+package com.zhongshu.card.client.model.pay;
+
+import com.github.microservice.types.payment.PaymentType;
+import com.zhongshu.card.client.type.WithdrawStatus;
+import com.zhongshu.card.client.type.paySetting.WithdrawMethodType;
+import com.zhongshu.card.client.type.paySetting.WithdrawType;
+import io.swagger.v3.oas.annotations.media.Schema;
+import lombok.Data;
+
+import java.math.BigDecimal;
+import java.util.List;
+
+@Data
+public class WithdrawOrderModel {
+
+    private String id;
+
+    private String createTime;
+
+    private String updateTime;
+
+    @Schema(description = "项目oid")
+    private String projectOid;
+
+    @Schema(description = "机构oid")
+    private String oid;
+
+    @Schema(description = "支付渠道")
+    private PaymentType paymentType;
+
+    @Schema(description = "订单编号")
+    private String orderNo;
+
+    @Schema(description = "提现金额")
+    private BigDecimal amount;
+
+    @Schema(description = "实际到账")
+    private BigDecimal receiveAmount;
+
+    @Schema(description = "提现方式")
+    private WithdrawMethodType withdrawMethodType;
+
+    @Schema(description = "提现规则")
+    private WithdrawType withdrawType;
+
+    @Schema(description = "银行卡号")
+    private String bankAccountNumber;
+
+    @Schema(description = "附加信息")
+    private String attachInfo;
+
+    @Schema(description = "附件")
+    private List<AttachFileModel> attachFile;
+
+    @Schema(description = "提现状态")
+    private WithdrawStatus withdrawStatus;
+
+    @Schema(description = "提现状态说明")
+    private String withdrawStatusDesc;
+
+    @Schema(description = "发起人")
+    private String withdrawUser;
+
+    @Schema(description = "处理人")
+    private String processUser;
+
+    @Schema(description = "处理时间")
+    private Long processTime;
+
+//    @Schema(description = "冻结账单")
+//    private List<TransactionLogModel> frozenTransactionLogs;
+//
+//    @Schema(description = "提现账单")
+//    private List<TransactionLogModel> withdrawTransactionLogs;
+
+    @Schema(description = "排序")
+    private Integer sort;
+}

+ 23 - 0
FullCardClient/src/main/java/com/zhongshu/card/client/model/pay/WithdrawPageParam.java

@@ -0,0 +1,23 @@
+package com.zhongshu.card.client.model.pay;
+
+import io.swagger.v3.oas.annotations.media.Schema;
+import lombok.Data;
+
+@Data
+public class WithdrawPageParam {
+
+    @Schema(description = "项目oid")
+    private String projectOid;
+
+    @Schema(description = "机构oid")
+    private String oid;
+
+    @Schema(description = "开始时间")
+    private Long startTime;
+
+    @Schema(description = "结束时间")
+    private Long endTime;
+
+    @Schema(description = "索引")
+    private String search;
+}

+ 8 - 4
FullCardClient/src/main/java/com/zhongshu/card/client/type/WithdrawStatus.java

@@ -4,15 +4,19 @@ import lombok.Getter;
 
 public enum WithdrawStatus {
 
-    Processing("提现处理中"),
-    Success("提现成功"),
-    Fail("提现失败")
+    Processing("提现处理中", 0),
+    Success("提现成功",1),
+    Fail("提现失败",1)
     ;
 
     @Getter
     private String remark;
 
-    WithdrawStatus(String remark) {
+    @Getter
+    private Integer sort;
+
+    WithdrawStatus(String remark, Integer sort) {
         this.remark = remark;
+        this.sort = sort;
     }
 }

+ 57 - 0
FullCardServer/src/main/java/com/zhongshu/card/server/core/controller/pay/withdraw/WithdrawController.java

@@ -0,0 +1,57 @@
+package com.zhongshu.card.server.core.controller.pay.withdraw;
+
+import com.github.microservice.types.payment.PaymentType;
+import com.zhongshu.card.client.model.pay.ProcessWithdrawParam;
+import com.zhongshu.card.client.model.pay.WithdrawPageParam;
+import com.zhongshu.card.client.model.pay.WithdrawParam;
+import com.zhongshu.card.server.core.service.pay.WithdrawService;
+import io.swagger.v3.oas.annotations.Operation;
+import io.swagger.v3.oas.annotations.Parameter;
+import io.swagger.v3.oas.annotations.tags.Tag;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.data.domain.Pageable;
+import org.springframework.data.web.PageableDefault;
+import org.springframework.web.bind.annotation.*;
+
+@RestController
+@RequestMapping("withdraw")
+@Tag(name = "机构资金-提现", description = "机构资金-提现")
+public class WithdrawController {
+
+    @Autowired
+    private WithdrawService withdrawService;
+
+    @Operation(summary = "查询账户可提案余额", description = "顶部数据及资金概况-折线图")
+    @RequestMapping(value = "queryWithdrawAmount", method = RequestMethod.GET)
+    public Object queryWithdrawAmount(@RequestParam(value = "projectId", required = false) String projectOid,
+                                      @RequestParam(value = "oid", required = false) String oid){
+        return withdrawService.queryWithdrawAmount(projectOid, oid);
+    }
+
+    @Operation(summary = "查询渠道可提案余额", description = "顶部数据及资金概况-折线图")
+    @RequestMapping(value = "queryWithdrawAmountByPayment", method = RequestMethod.GET)
+    public Object queryWithdrawAmountByPayment(@RequestParam(value = "projectId", required = false) String projectOid,
+                                      @RequestParam(value = "oid", required = false) String oid,
+                                      @RequestParam("paymentType") PaymentType paymentType){
+        return withdrawService.queryWithdrawAmount(projectOid, oid, paymentType);
+    }
+
+    @Operation(summary = "发起提现", description = "发起提现")
+    @RequestMapping(value = "withdrawApply", method = RequestMethod.POST)
+    public Object withdrawApply(@RequestBody WithdrawParam param){
+        return withdrawService.withdrawApply(param);
+    }
+
+    @Operation(summary = "审核提现", description = "审核提现")
+    @RequestMapping(value = "withdraw", method = RequestMethod.POST)
+    public Object withdraw(@RequestBody ProcessWithdrawParam param){
+        return withdrawService.withdraw(param);
+    }
+
+    @Operation(summary = "分页查询-提现记录", description = "查询收入账单-年月日汇总")
+    @RequestMapping(value = "page", method = RequestMethod.POST)
+    public Object page(@Parameter(hidden = true) @PageableDefault(page = 0, size = 10)Pageable pageable,
+                       @Parameter(required = false) WithdrawPageParam param){
+        return withdrawService.page(pageable, param);
+    }
+}

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

@@ -1,4 +1,11 @@
 package com.zhongshu.card.server.core.dao.pay.extend;
 
+import com.zhongshu.card.client.model.pay.WithdrawPageParam;
+import com.zhongshu.card.server.core.domain.pay.WithdrawOrder;
+import org.springframework.data.domain.Page;
+import org.springframework.data.domain.Pageable;
+
 public interface WithdrawOrderDaoExtend {
+
+    Page<WithdrawOrder> page(Pageable pageable, String projectOid, String oid, Long startTime, Long endTime, String search);
 }

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

@@ -1,7 +1,48 @@
 package com.zhongshu.card.server.core.dao.pay.impl;
 
+import com.github.microservice.components.data.mongo.mongo.helper.DBHelper;
+import com.zhongshu.card.client.model.pay.WithdrawPageParam;
 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;
+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.query.Criteria;
+import org.springframework.data.mongodb.core.query.Query;
+
+import java.util.regex.Pattern;
 
 public class WithdrawOrderDaoImpl implements WithdrawOrderDaoExtend {
+
+    @Autowired
+    DBHelper dbHelper;
+
+    @Override
+    public Page<WithdrawOrder> page(Pageable pageable, String projectOid, String oid, Long startTime, Long endTime, String search) {
+        Criteria criteria = new Criteria();
+
+        if (StringUtils.isNotBlank(projectOid)) {
+            criteria.and("projectOid").is(projectOid);
+        }
+
+        if (StringUtils.isNotBlank(oid)) {
+            criteria.and("oid").is(oid);
+        }
+
+        if (startTime != null && endTime != null) {
+            criteria.and("createTime").gte(startTime).lte(endTime);
+        }
+
+        if (StringUtils.isNotBlank(search)) {
+            java.util.regex.Pattern namePattern = Pattern.compile("^.*" + search + ".*$");
+            criteria.and("withdrawUser.name").regex(namePattern);
+        }
+
+        Query query = new Query(criteria);
+        query.with(Sort.by(Sort.Order.asc("sort"), Sort.Order.desc("createTime")));
+        return dbHelper.pages(query, pageable, WithdrawOrder.class);
+    }
 }

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

@@ -72,4 +72,7 @@ public class WithdrawOrder extends SuperEntity {
 
     @Schema(description = "提现账单")
     private List<TransactionLogModel> withdrawTransactionLogs;
+
+    @Schema(description = "排序")
+    private Integer sort;
 }

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

@@ -1,5 +1,6 @@
 package com.zhongshu.card.server.core.service.pay;
 
+import com.github.microservice.components.data.base.util.PageEntityUtil;
 import com.github.microservice.pay.client.model.ledger.GeneralLedgerQueryModel;
 import com.github.microservice.pay.client.model.ledger.TransactionLogModel;
 import com.github.microservice.pay.client.model.ledger.TransferTransactionsModel;
@@ -14,9 +15,10 @@ import com.github.microservice.pay.client.type.ledger.TransactionType;
 import com.github.microservice.types.payment.PaymentChannelType;
 import com.github.microservice.types.payment.PaymentType;
 import com.zhongshu.card.client.model.pay.ProcessWithdrawParam;
+import com.zhongshu.card.client.model.pay.WithdrawOrderModel;
+import com.zhongshu.card.client.model.pay.WithdrawPageParam;
 import com.zhongshu.card.client.model.pay.WithdrawParam;
 import com.zhongshu.card.client.model.paySetting.paySetting.OrgPayConfigModel;
-import com.zhongshu.card.client.service.org.UserAccountService;
 import com.zhongshu.card.client.type.WithdrawStatus;
 import com.zhongshu.card.client.type.paySetting.WithdrawMethodType;
 import com.zhongshu.card.server.core.dao.pay.WithdrawOrderDao;
@@ -25,17 +27,19 @@ import com.zhongshu.card.server.core.domain.pay.PayAccount;
 import com.zhongshu.card.server.core.domain.pay.WithdrawOrder;
 import com.zhongshu.card.server.core.domain.paySetting.ProjectMainPaySetting;
 import com.zhongshu.card.server.core.service.base.SuperService;
+import com.zhongshu.card.server.core.service.org.UserOrgPermissService;
 import com.zhongshu.card.server.core.service.paySetting.ProjectMainPaySettingService;
 import com.zhongshu.card.server.core.service.paySetting.ProjectPaySettingServiceImpl;
 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 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 java.awt.print.Pageable;
 import java.math.BigDecimal;
-import java.math.RoundingMode;
 import java.util.List;
 import java.util.Map;
 
@@ -63,6 +67,9 @@ public class WithdrawService extends SuperService {
     @Autowired
     WithdrawOrderDao withdrawOrderDao;
 
+    @Autowired
+    UserOrgPermissService userOrgPermissService;
+
     /**
      * 查询可提现余额
      */
@@ -86,6 +93,13 @@ public class WithdrawService extends SuperService {
      * 查询当前支付渠道可提现余额
      */
     public com.github.microservice.net.ResultContent queryWithdrawAmount(String projectOid, String oid, PaymentType paymentType){
+        if (StringUtils.isBlank(projectOid)){
+            projectOid = getCurrentProjectOid();
+        }
+
+        if (StringUtils.isBlank(oid)){
+            oid = getCurrentOid();
+        }
         Long amount = queryWithdrawAmountByPaymentType(projectOid, oid, paymentType);
         if (null == amount){
             return  com.github.microservice.net.ResultContent.buildFail("查询余额失败");
@@ -182,6 +196,7 @@ public class WithdrawService extends SuperService {
         withdrawOrder.setOrderNo(withdrawOrderNo);
         withdrawOrder.setAmount(amount);
         withdrawOrder.setWithdrawStatus(WithdrawStatus.Processing);
+        withdrawOrder.setSort(WithdrawStatus.Processing.getSort());
         withdrawOrder.setWithdrawUser(userAccounts.get(0));
         withdrawOrder.setFrozenTransactionLogs(transfer.getContent());
         withdrawOrder.setProjectOid(projectOid);
@@ -199,6 +214,15 @@ public class WithdrawService extends SuperService {
         if (StringUtils.isBlank(userId)){
             userId = getCurrentUserId();
         }
+        String projectOid = getCurrentProjectOid();
+        if (StringUtils.isBlank(projectOid)){
+            return com.github.microservice.net.ResultContent.buildFail("当前项目oid为空");
+        }
+        boolean isProjectManager = userOrgPermissService.userIsProjectManager(projectOid, userId);
+        if (!isProjectManager){
+            return com.github.microservice.net.ResultContent.buildFail("无操作权限");
+        }
+
         List<UserAccount> userAccounts = userAccountService.getUserAccounts(List.of(userId));
         if (userAccounts==null || userAccounts.isEmpty()){
             return com.github.microservice.net.ResultContent.buildFail("用户信息不存在");
@@ -237,9 +261,11 @@ public class WithdrawService extends SuperService {
             }
 
             withdrawOrder.setWithdrawStatus(WithdrawStatus.Success);
+            withdrawOrder.setSort(WithdrawStatus.Success.getSort());
             withdrawOrder.setReceiveAmount(withdrawOrder.getAmount().movePointLeft(2));
         }else if (param.getStatus().equals(WithdrawStatus.Fail)){ //审批拒绝
             withdrawOrder.setWithdrawStatus(WithdrawStatus.Fail);
+            withdrawOrder.setSort(WithdrawStatus.Fail.getSort());
             //划账退回金额: 机构已冻结金额- 机构已结算 +
             TransferTransactionsModel transferTransactionsModel = buildTransferModel(settleAccount, withdrawFrozenAccount, withdrawOrder.getOrderNo(),
                     withdrawOrder.getAmount(), TransactionType.WithdrawRefund,
@@ -284,8 +310,39 @@ public class WithdrawService extends SuperService {
     /**
      * 查询机构提现记录
      */
-    public Object page(Pageable pageable){
-        return null;
+    public com.github.microservice.net.ResultContent page(Pageable pageable, WithdrawPageParam param) {
+        String userId = getCurrentUserId();
+        String projectOid = param.getProjectOid();
+        if (StringUtils.isBlank(projectOid)){
+            projectOid = getCurrentProjectOid();
+        }
+        boolean isProjectManager = userOrgPermissService.userIsProjectManager(projectOid, userId);
+        if (isProjectManager){
+            Page<WithdrawOrder> page = withdrawOrderDao.page(pageable, projectOid, null, param.getStartTime(), param.getEndTime(), param.getSearch());
+            return com.github.microservice.net.ResultContent.buildContent(PageEntityUtil.concurrent2PageModel(page, this::toModel));
+        }
+        List<String> userManagerOids = userOrgPermissService.getUserManagerOids(projectOid, userId);
+
+        if (userManagerOids==null || userManagerOids.isEmpty()){
+            return com.github.microservice.net.ResultContent.buildContent(PageEntityUtil.buildEmptyPage(pageable));
+        }
+
+        Page<WithdrawOrder> page = withdrawOrderDao.page(pageable, projectOid, userManagerOids.get(0), param.getStartTime(), param.getEndTime(), param.getSearch());
+        return com.github.microservice.net.ResultContent.buildContent(PageEntityUtil.concurrent2PageModel(page, this::toModel));
+    }
+
+    private WithdrawOrderModel toModel(WithdrawOrder withdrawOrder){
+        WithdrawOrderModel model = new WithdrawOrderModel();
+        if (withdrawOrder!=null){
+            BeanUtils.copyProperties(withdrawOrder, model, "withdrawUser", "processUser");
+            if (withdrawOrder.getWithdrawUser()!=null){
+                model.setWithdrawUser(withdrawOrder.getWithdrawUser().getName());
+            }
+            if (withdrawOrder.getProcessUser()!=null){
+                model.setProcessUser(withdrawOrder.getProcessUser().getName());
+            }
+        }
+        return model;
     }
 
     /**