Quellcode durchsuchen

运营端钱包功能接口,剩余提现统计接口待完成

xucaiqin vor 2 Jahren
Ursprung
Commit
b3c23efb2d

+ 65 - 0
sckw-modules/sckw-payment/src/main/java/com/sckw/payment/controller/operate/OperateWalletController.java

@@ -0,0 +1,65 @@
+package com.sckw.payment.controller.operate;
+
+import com.sckw.core.web.response.HttpResult;
+import com.sckw.payment.model.vo.req.CashPageReq;
+import com.sckw.payment.model.vo.req.WalletDetailReq;
+import com.sckw.payment.model.vo.req.page.PrePayPage;
+import com.sckw.payment.service.WalletService;
+import jakarta.annotation.Resource;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.validation.annotation.Validated;
+import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RestController;
+
+/**
+ * 钱包
+ *
+ * @author xucaiqin
+ * @date 2023-08-28 15:36:48
+ */
+@Validated
+@RestController
+@RequestMapping("/operateWallet")
+@Slf4j
+public class OperateWalletController {
+    @Resource
+    private WalletService walletService;
+
+
+    /**
+     * 查询资金明细
+     *
+     * @return
+     */
+    @GetMapping("detail")
+    public HttpResult detail(WalletDetailReq walletDetailReq) {
+        return HttpResult.ok(walletService.walletDetail2(walletDetailReq));
+    }
+
+
+    /**
+     * 提现记录
+     *
+     * @param cashPageReq
+     * @return
+     */
+    @GetMapping("cashList")
+    public HttpResult cashList(CashPageReq cashPageReq) {
+        return HttpResult.ok(walletService.cashList2(cashPageReq));
+    }
+
+
+
+    /**
+     * 预付列表
+     *
+     * @param prePayPage
+     * @return
+     */
+    @GetMapping("prePayList")
+    public HttpResult prePayList(PrePayPage prePayPage) {
+        return HttpResult.ok(walletService.prePayList2(prePayPage));
+    }
+
+}

+ 13 - 0
sckw-modules/sckw-payment/src/main/java/com/sckw/payment/service/KwpWalletRelationService.java

@@ -3,6 +3,7 @@ package com.sckw.payment.service;
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.sckw.core.common.enums.NumberConstant;
 import com.sckw.core.model.constant.Global;
+import com.sckw.core.utils.CollectionUtils;
 import com.sckw.core.utils.IdWorker;
 import com.sckw.core.web.context.LoginUserHolder;
 import com.sckw.payment.dao.KwpWalletRelationMapper;
@@ -15,8 +16,11 @@ import org.apache.commons.lang3.StringUtils;
 import org.springframework.data.redis.core.RedisTemplate;
 import org.springframework.stereotype.Service;
 
+import java.util.ArrayList;
 import java.util.Date;
+import java.util.List;
 import java.util.Objects;
+import java.util.stream.Collectors;
 
 /**
  * @author xucaiqin
@@ -29,6 +33,15 @@ public class KwpWalletRelationService {
     private final KwpWalletRelationMapper relationMapper;
     private final RedisTemplate<String, Object> redisTemplate;
 
+    public List<String> getAll() {
+        List<KwpWalletRelation> kwpWalletRelations = relationMapper.selectList(new LambdaQueryWrapper<KwpWalletRelation>()
+                .eq(KwpWalletRelation::getDelFlag, 0));
+        if (!CollectionUtils.isEmpty(kwpWalletRelations)) {
+            return kwpWalletRelations.stream().map(KwpWalletRelation::getUid).collect(Collectors.toList());
+        }
+        return new ArrayList<>();
+    }
+
     /**
      * 根据企业id查询中台用户
      *

+ 250 - 2
sckw-modules/sckw-payment/src/main/java/com/sckw/payment/service/WalletService.java

@@ -485,6 +485,86 @@ public class WalletService {
         return new MorePageRes<>(walletDetailReq.getPage(), walletDetailReq.getPageSize(), vo, df.format(sum / 100.0D));
     }
 
+    /**
+     * 运营端查询资金明细
+     *
+     * @param walletDetailReq
+     * @return
+     */
+    public Object walletDetail2(WalletDetailReq walletDetailReq) {
+        log.info("运营端查询资金明细:{}", JSONObject.toJSONString(walletDetailReq));
+        List<String> all = walletRelationService.getAll();
+        if (CollectionUtils.isEmpty(all)) {
+            return PageRes.handPage(walletDetailReq.getPage(), walletDetailReq.getPageSize(), new ArrayList<>());
+        }
+
+        ChannelEnum channelEnum = null;
+        if (StringUtils.isNotBlank(walletDetailReq.getChannel())) {
+            channelEnum = ChannelEnum.getByValue(walletDetailReq.getChannel());
+            if (Objects.isNull(channelEnum)) {
+                throw new BusinessException("支付通道不存在");
+            }
+        }
+
+        List<WalletDto> res = new ArrayList<>();
+        long sum = 0L;
+        //筛选企业
+        String entName = walletDetailReq.getEntName();
+        if (StringUtils.isNotBlank(entName)) {
+            List<String> filterList = findFilter(entName);
+            //未筛选出数据
+            if (CollectionUtils.isEmpty(filterList)) {
+                return PageRes.handPage(walletDetailReq.getPage(), walletDetailReq.getPageSize(), new ArrayList<>());
+            }
+            for (String uid : all) {
+                for (String filter : filterList) {
+                    R<Wallet> walletR = payCenterService.walletSum(uid, channelEnum, filter);
+                    if (walletR.getStatus()) {
+                        Wallet data = walletR.getData();
+                        sum += data.getTotalMoney();
+                        List<WalletDto> rows = data.getRows();
+                        if (CollectionUtils.isEmpty(rows)) {
+                            continue;
+                        }
+                        res.addAll(rows);
+                    }
+                }
+            }
+        } else {
+            //不搜索往来单位
+            for (String uid : all) {
+                R<Wallet> wallet = payCenterService.walletSum(uid, channelEnum, "");
+                if (wallet.getStatus()) {
+                    Wallet data = wallet.getData();
+                    sum += data.getTotalMoney();
+                    if (!CollectionUtils.isEmpty(data.getRows())) {
+                        res.addAll(data.getRows());
+                    }
+                }
+            }
+        }
+
+        List<FundVo> vo = new ArrayList<>();
+        FundVo fundVo;
+
+        //组装res数据
+        for (WalletDto re : res) {
+            fundVo = new FundVo();
+            BeanUtils.copyProperties(re, fundVo);
+            fundVo.setChannelLabel(ChannelEnum.getDesc(re.getChannel()));
+            fundVo.setUidName(getFirmName(re.getUid()));
+            fundVo.setFilterName(getFirmName(re.getFilter()));
+            fundVo.setMoney(dfMoney(re.getMoney()));
+            fundVo.setWithdrawingMoney(dfMoney(re.getWithdrawingMoney()));
+            fundVo.setChargingMoney(dfMoney(re.getChargingMoney()));
+            fundVo.setTotalMoney(dfMoney(re.getTotalMoney()));
+            refundMoney2(fundVo);
+            transferMoney(fundVo);
+            vo.add(fundVo);
+        }
+        DecimalFormat df = new DecimalFormat("0.00");
+        return new MorePageRes<>(walletDetailReq.getPage(), walletDetailReq.getPageSize(), vo, df.format(sum / 100.0D));
+    }
 
     /**
      * 新增账目
@@ -695,7 +775,84 @@ public class WalletService {
             }
         }
         //组装数据
-        return new MorePageRes<>(cashPageReq.getPage(), cashPageReq.getPageSize(), data.getTotal(), (int) (data.getTotal() / cashPageReq.getPageSize() + 1), rows, String.valueOf(Long.parseLong(data.getTotalWithdrawMoney()) / 100.0D));
+        return new MorePageRes<>(cashPageReq.getPage(), cashPageReq.getPageSize(), data.getTotal(), (int) (data.getTotal() / cashPageReq.getPageSize() + 1), rows, String.valueOf(data.getTotalWithdrawMoney() / 100.0D));
+    }
+
+    /**
+     * 运营端提现记录
+     *
+     * @param cashPageReq
+     * @return
+     */
+    public Object cashList2(CashPageReq cashPageReq) {
+        log.info("提现记录:{}", JSONObject.toJSONString(cashPageReq));
+
+        List<String> all = walletRelationService.getAll();
+        if (CollectionUtils.isEmpty(all)) {
+            return PageRes.handPage(cashPageReq.getPage(), cashPageReq.getPageSize(), new ArrayList<>());
+        }
+        ChannelEnum channelEnum = null;
+        if (StringUtils.isNotBlank(cashPageReq.getChannel())) {
+            channelEnum = ChannelEnum.getByValue(cashPageReq.getChannel());
+            if (Objects.isNull(channelEnum)) {
+                throw new BusinessException("支付通道不存在");
+            }
+        }
+        Long sum = 0L;
+        List<CashItem> res = new ArrayList<>();
+        for (String uid : all) {
+            sum += queryAll(res, uid, channelEnum, cashPageReq.getStatus(), cashPageReq.getPage());
+        }
+        res.sort((c1, c2) -> {
+            DateTimeFormatter df = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
+            if (StringUtils.isBlank(c1.getCreateTime())) {
+                return 0;
+            }
+            if (StringUtils.isBlank(c2.getCreateTime())) {
+                return 1;
+            }
+            LocalDateTime parse = LocalDateTime.parse(c1.getCreateTime(), df);
+            LocalDateTime parse2 = LocalDateTime.parse(c2.getCreateTime(), df);
+            return parse.compareTo(parse2);
+        });
+        //组装数据
+        return new MorePageRes<>(cashPageReq.getPage(), cashPageReq.getPageSize(), res, String.valueOf(sum / 100.0D));
+    }
+
+    /**
+     * 查询一个钱包的所有
+     *
+     * @param res
+     * @param uid
+     * @param channelEnum
+     * @param status
+     * @param page
+     * @return
+     */
+    private Long queryAll(List<CashItem> res, String uid, ChannelEnum channelEnum, String status, int page) {
+        long sum = 0L;
+        R<CashPage> cashPageR = payCenterService.withdrawIndex(uid, channelEnum, status, page, 10);
+        if (cashPageR.getStatus()) {
+            CashPage data = cashPageR.getData();
+            List<CashItem> rows = data.getRows();
+            sum = data.getTotalWithdrawMoney();
+            if (!CollectionUtils.isEmpty(rows)) {
+                for (CashItem row : rows) {
+                    row.setBalance(smallMoney(row.getBalance()));
+                    row.setMoney(smallMoney(row.getMoney()));
+                }
+                res.addAll(rows);
+            }
+
+            //计算余量
+            long total = data.getTotal();
+            long page1 = data.getPage();
+            long pageSize1 = data.getPageSize();
+            if (page1 * pageSize1 < total) {
+                queryAll(res, uid, channelEnum, status, page + 1);
+            }
+        }
+        return sum;
     }
 
     /**
@@ -734,7 +891,7 @@ public class WalletService {
         Long entId = LoginUserHolder.getEntId();
         String uid = walletRelationService.getRelation(entId);
         if (StringUtils.isBlank(uid)) {
-            return null;
+            return new ApPageRes<>(prePayPage.getPage(), prePayPage.getPageSize(), 0, 0, new ArrayList<>());
         }
         ChannelEnum channelEnum = null;
         if (StringUtils.isNotBlank(prePayPage.getChannel())) {
@@ -784,6 +941,97 @@ public class WalletService {
 
     }
 
+    /**
+     * 运营端预付列表
+     *
+     * @param prePayPage
+     * @return
+     */
+    public Object prePayList2(PrePayPage prePayPage) {
+        List<String> all = walletRelationService.getAll();
+        if (CollectionUtils.isEmpty(all)) {
+            return new ApPageRes<>(prePayPage.getPage(), prePayPage.getPageSize(), 0, 0, new ArrayList<>());
+        }
+        ChannelEnum channelEnum = null;
+        if (StringUtils.isNotBlank(prePayPage.getChannel())) {
+            channelEnum = ChannelEnum.getByValue(prePayPage.getChannel());
+            if (Objects.isNull(channelEnum)) {
+                throw new BusinessException("支付通道异常");
+            }
+        }
+        String entName = prePayPage.getEntName();
+        String filter = "";
+        //筛选企业名称
+        if (StringUtils.isNotBlank(entName)) {
+            filter = findFilterStr(entName);
+        }
+        List<PrePayWalletVo> list = new ArrayList<>();
+        long apSum = 0L;
+        long usingApSum = 0L;
+        long totalApSum = 0L;
+        for (String uid : all) {
+            Map<String, Long> map = queryAdvance(list, uid, channelEnum, filter, prePayPage.getPage());
+            apSum += map.get("apSum");
+            usingApSum += map.get("usingApSum");
+            totalApSum += map.get("totalApSum");
+        }
+        ApPageRes<PrePayWalletVo> page = new ApPageRes<>(prePayPage.getPage(), prePayPage.getPageSize(), list);
+        page.setApMoney(dfMoney(apSum));
+        page.setUsingApMoney(dfMoney(usingApSum));
+        page.setTotalApMoney(dfMoney(totalApSum));
+        return page;
+
+    }
+
+    private Map<String, Long> queryAdvance(List<PrePayWalletVo> list, String uid, ChannelEnum channelEnum, String filter, int page) {
+        long apSum = 0L;
+        long usingApSum = 0L;
+        long totalApSum = 0L;
+        R<PrePayWalletPage> prePayIndexPageR = payCenterService.advancePayWALLET(uid, channelEnum, filter, page, 10);
+        if (prePayIndexPageR.getStatus()) {
+            PrePayWalletPage data = prePayIndexPageR.getData();
+            //数据转换
+            if (!CollectionUtils.isEmpty(data.getRows())) {
+                apSum = data.getApMoney();
+                usingApSum = data.getUsingApMoney();
+                totalApSum = data.getTotalApMoney();
+                PrePayWalletVo prePayWalletVo;
+                for (PrePayWallet row : data.getRows()) {
+                    prePayWalletVo = new PrePayWalletVo();
+                    BeanUtils.copyProperties(row, prePayWalletVo);
+                    ChannelEnum byChannel = ChannelEnum.getByChannel(row.getChannel());
+                    prePayWalletVo.setChannelDict(Objects.nonNull(byChannel) ? byChannel.getValue() : "");
+                    prePayWalletVo.setApMoney(dfMoney(row.getApMoney()));
+                    prePayWalletVo.setUidName(getFirmName(row.getUid()));
+                    prePayWalletVo.setUidEnt(getEnt(row.getUid()));
+                    prePayWalletVo.setFilterName(getFirmName(row.getFilter()));
+                    prePayWalletVo.setFilterEnt(getEnt(row.getFilter()));
+                    prePayWalletVo.setUsingApMoney(dfMoney(row.getUsingApMoney()));
+                    prePayWalletVo.setSettlingApMoney(dfMoney(row.getSettlingApMoney()));
+                    prePayWalletVo.setTotalApMoney(dfMoney(row.getTotalApMoney()));
+                    refundMoney(row, prePayWalletVo, false);
+                    list.add(prePayWalletVo);
+                }
+
+                //计算余量
+                long total = data.getTotal();
+                long page1 = data.getPage();
+                long pageSize1 = data.getPageSize();
+                if (page1 * pageSize1 < total) {
+                    queryAdvance(list, uid, channelEnum, filter, page + 1);
+                }
+            }
+        }
+        Long finalApSum = apSum;
+        Long finalUsingApSum = usingApSum;
+        Long finalTotalApSum = totalApSum;
+        return new HashMap<>() {{
+            put("apSum", finalApSum);
+            put("usingApSum", finalUsingApSum);
+            put("totalApSum", finalTotalApSum);
+        }};
+    }
+
     /**
      * 预付列表钱包统计
      *