wujiefeng 1 éve
szülő
commit
de7dcdd841

+ 1 - 1
PaymentClient/src/main/java/com/zhongshu/payment/client/model/TotalStatisticsModel.java

@@ -10,7 +10,7 @@ import lombok.Data;
 @Data
 public class TotalStatisticsModel {
 
-    private String tradeType;
+    private String id;
 
     private Integer totalAmount;
 }

+ 22 - 17
PaymentServer/src/main/java/com/zhongshu/payment/server/core/controller/TransferController.java

@@ -1,6 +1,5 @@
 package com.zhongshu.payment.server.core.controller;
 
-import com.zhongshu.payment.client.model.param.ExamineParam;
 import com.zhongshu.payment.client.model.param.RechargeParam;
 import com.zhongshu.payment.client.model.param.TransferSearchParam;
 import com.zhongshu.payment.server.core.service.TransferService;
@@ -29,24 +28,30 @@ public class TransferController {
     TransferService transferService;
 
 
-    @Operation(summary = "创建提现订单", description = "创建提现订单")
-    @PostMapping(value = "create", consumes = MediaType.APPLICATION_JSON_VALUE)
-    public Object create(@RequestBody RechargeParam param){
-        return transferService.create(param);
-    }
-
-
-    @Operation(summary = "通过提现审批", description = "创建提现订单")
-    @PostMapping(value = "passTransfer", consumes = MediaType.APPLICATION_JSON_VALUE)
-    public Object passTransfer(@RequestBody ExamineParam param){
-        return transferService.passTransfer(param);
-    }
 
-    @Operation(summary = "拒绝提现审批", description = "创建提现订单")
-    @PostMapping(value = "refuseTransfer", consumes = MediaType.APPLICATION_JSON_VALUE)
-    public Object refuseTransfer(@RequestBody ExamineParam param){
-        return transferService.refuseTransfer(param);
+    @Operation(summary = "提现", description = "创建提现订单")
+    @PostMapping(value = "transfer", consumes = MediaType.APPLICATION_JSON_VALUE)
+    public Object transfer(@RequestBody RechargeParam param){
+        return transferService.transfer(param);
     }
+//    @Operation(summary = "创建提现订单", description = "创建提现订单")
+//    @PostMapping(value = "create", consumes = MediaType.APPLICATION_JSON_VALUE)
+//    public Object create(@RequestBody RechargeParam param){
+//        return transferService.create(param);
+//    }
+//
+//
+//    @Operation(summary = "通过提现审批", description = "创建提现订单")
+//    @PostMapping(value = "passTransfer", consumes = MediaType.APPLICATION_JSON_VALUE)
+//    public Object passTransfer(@RequestBody ExamineParam param){
+//        return transferService.passTransfer(param);
+//    }
+//
+//    @Operation(summary = "拒绝提现审批", description = "创建提现订单")
+//    @PostMapping(value = "refuseTransfer", consumes = MediaType.APPLICATION_JSON_VALUE)
+//    public Object refuseTransfer(@RequestBody ExamineParam param){
+//        return transferService.refuseTransfer(param);
+//    }
     @Operation(summary = "提现查询-分页查询", description = "项目列表-分页查询")
     @RequestMapping(value = {"pageTransfer"}, method = {RequestMethod.POST})
     public Object pageProject(

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

@@ -36,7 +36,7 @@ public class WalletController {
     }
 
     @Operation(summary = "获取可提现金额及订单数量", description = "获取可提现金额及订单数量")
-    @PostMapping("getTransferTotal")
+    @GetMapping("getTransferTotal")
     public Object getTransferTotal(@RequestParam(name = "walletId") String walletId){
         return walletService.getTransferTotal(walletId);
     }

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

@@ -36,7 +36,7 @@ public class TestController {
 //        sendMessageModel.setUserId("665fc0389083d203896d3541");
 
 
-        return ResultContent.buildContent(rechargeRecordDao.getTotalAmountByTradeType("66a749a66f75da30730658c7"));
+        return null;
     }
 
 

+ 3 - 2
PaymentServer/src/main/java/com/zhongshu/payment/server/core/dao/extend/RechargeRecordDaoExtend.java

@@ -1,7 +1,8 @@
 package com.zhongshu.payment.server.core.dao.extend;
 
-import com.zhongshu.payment.client.model.TotalStatisticsModel;
 import com.zhongshu.payment.client.model.param.TransferSearchParam;
+import com.zhongshu.payment.client.types.RechargeState;
+import com.zhongshu.payment.client.types.TradeType;
 import com.zhongshu.payment.server.core.domain.wallet.RechargeRecord;
 import com.zhongshu.payment.server.core.domain.wallet.Wallet;
 import org.springframework.data.domain.Page;
@@ -19,5 +20,5 @@ public interface RechargeRecordDaoExtend {
 
     Page<RechargeRecord> pageTransfer(Pageable pageable, TransferSearchParam param);
 
-    public List<TotalStatisticsModel> getTotalAmountByTradeType(String walletId);
+    public Integer sumTotalByWalletId(String walletId, RechargeState RechargeState, TradeType tradeType, Long startTime, Long endTime);
 }

+ 30 - 14
PaymentServer/src/main/java/com/zhongshu/payment/server/core/dao/impl/RechargeRecordDaoImpl.java

@@ -5,13 +5,13 @@ import com.github.microservice.components.data.mongo.mongo.helper.DBHelper;
 import com.zhongshu.payment.client.model.TotalStatisticsModel;
 import com.zhongshu.payment.client.model.param.TransferSearchParam;
 import com.zhongshu.payment.client.types.RechargeState;
+import com.zhongshu.payment.client.types.TradeType;
 import com.zhongshu.payment.server.core.dao.extend.RechargeRecordDaoExtend;
 import com.zhongshu.payment.server.core.domain.wallet.RechargeRecord;
 import com.zhongshu.payment.server.core.domain.wallet.Wallet;
 import com.zhongshu.payment.server.core.utils.CommonUtil;
 import lombok.extern.slf4j.Slf4j;
 import org.apache.commons.lang3.ObjectUtils;
-import org.bson.types.ObjectId;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.data.domain.Page;
 import org.springframework.data.domain.Pageable;
@@ -99,29 +99,45 @@ public class RechargeRecordDaoImpl implements RechargeRecordDaoExtend {
         return dbHelper.pages(query, pageable, RechargeRecord.class);
     }
 
-    public List<TotalStatisticsModel> getTotalAmountByTradeType(String walletId){
+    public Integer sumTotalByWalletId(String walletId, RechargeState rechargeState, TradeType tradeType, Long startTime, Long endTime){
         Criteria criteria = new  Criteria();
 
-        if (StringUtil.notNullNorEmpty(walletId)){
-            criteria.and("wallet._id").is(new ObjectId(walletId));
+        if (StringUtil.isNullOrEmpty(walletId)){
+            criteria.and("wallet._id").is(walletId);
         }
-        criteria.and("rechargeState").in(List.of(RechargeState.SUCCESS, RechargeState.TakeSuccess));
+
+        if (tradeType!=null){
+            criteria.and("tradeType").is(tradeType);
+        }
+
+        if (rechargeState!=null){
+            criteria.and("rechargeState").is(rechargeState);
+        }
+
+        if (!CommonUtil.longIsEmpty(startTime)){
+            criteria.and("createTime").gte(startTime);
+        }
+
+        if (CommonUtil.longIsEmpty(endTime)){
+            criteria.and("createTime").lte(endTime);
+        }
+
         Aggregation aggregation = Aggregation.newAggregation(
                 Aggregation.match(criteria),
-                Aggregation.project("_id","amountTotal"),
-                Aggregation.group("tradeType").sum("total").as("amountTotal")
+//                Aggregation.project("_id","amountTotal"),
+                Aggregation.group("wallet._id").sum("total").as("totalAmount")
+//                Aggregation.group("tradeType").last("tradeType").as("_id")
                 );
 
 
-        log.info("聚合查询{}\n{}",aggregation.getOptions(), aggregation.getPipeline());
-        Query query =Query.query(criteria);
-
-        AggregationResults<TotalStatisticsModel> groupList = mongoTemplate.aggregate(aggregation, TotalStatisticsModel.class, TotalStatisticsModel.class);
+        AggregationResults<TotalStatisticsModel> groupList = mongoTemplate.aggregate(aggregation, RechargeRecord.class, TotalStatisticsModel.class);
         List<TotalStatisticsModel> list = new ArrayList<>();
 
-        for (TotalStatisticsModel object : groupList){
-            list.add(object);
+        if (groupList.getMappedResults().size()==0){
+            return 0;
         }
-        return list;
+
+        return groupList.getMappedResults().get(0).getTotalAmount();
+
     }
 }

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

@@ -40,6 +40,7 @@ import org.springframework.transaction.annotation.Transactional;
 
 import java.math.BigDecimal;
 import java.util.List;
+import java.util.Map;
 
 /**
  * 充值服务
@@ -245,7 +246,11 @@ public class RechargeService {
         Long monthStartTime = DateUtils.getMonthStartTime(year, month);
         Long monthEndTime = DateUtils.getMonthEndTime(year, month);
         List<RechargeRecord> list = rechargeRecordDao.ListByWallet(wallet, monthStartTime, monthEndTime);
-        return ResultContent.buildSuccess(list.stream().map(this::toModel).toList());
+
+        Integer chargeTotal = rechargeRecordDao.sumTotalByWalletId(walletId, RechargeState.SUCCESS, TradeType.Charge, monthStartTime, monthEndTime);
+        Integer transferTotal = rechargeRecordDao.sumTotalByWalletId(walletId, RechargeState.TakeSuccess, TradeType.Take, monthStartTime, monthEndTime);
+
+        return ResultContent.buildSuccess(Map.of("list", list.stream().map(this::toModel).toList(), "chargeTotal", chargeTotal, "transferTotal", transferTotal));
     }
 
     /** 查询充值订单详情 */

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

@@ -65,9 +65,8 @@ public class TransferService {
     @Autowired
     OrganizationFeignService organizationFeignService;
 
-    /** 发起提现 */
     @Transactional
-    public Object create(RechargeParam param){
+    public Object transfer(RechargeParam param){
         String userId = authHelper.getCurrentUser().getUserId();
         Wallet userWallet = walletDao.findTop1ById(param.getWalletId());
         //判断钱包是否初始化
@@ -75,6 +74,23 @@ public class TransferService {
             return ResultContent.buildFail("用户钱包未开通");
         }
 
+        //判断微信支付配置
+        ProjectWxPayParam wxPayParam = new ProjectWxPayParam();
+        wxPayParam.setAppId(param.getAppid());
+        com.zhongshu.card.client.ret.ResultContent<WxPayConfigModel> paySetResult = paySettingFeignService.getProjectWxPayConfig(wxPayParam);
+        if (paySetResult.isFailed()){
+            return ResultContent.buildFail("获取微信支付配置失败");
+        }
+
+        //设置人员信息
+        OrgUserDetailParam orgUserDetailParam = new OrgUserDetailParam();
+        orgUserDetailParam.setOid(userWallet.getOid());
+        orgUserDetailParam.setUserId(userWallet.getUserId());
+        com.zhongshu.card.client.ret.ResultContent<OrganizationUserModel> orgUserDetail = organizationFeignService.getOrgUserDetail(orgUserDetailParam);
+        if (orgUserDetail.isFailed()){
+            return ResultContent.buildFail("获取用户信息失败");
+        }
+
         RechargeRecord rechargeRecord = new RechargeRecord();
         org.springframework.beans.BeanUtils.copyProperties(param, rechargeRecord, "total");
         String outTradeNo = CommonUtil.UUID();
@@ -82,9 +98,85 @@ public class TransferService {
         rechargeRecord.setTotal(BigDecimal.valueOf(param.getTotal()));
         rechargeRecord.setOid(userWallet.getOid());
         rechargeRecord.setTradeType(TradeType.Take);
-        rechargeRecord.setRechargeState(RechargeState.TakeReview);
+        rechargeRecord.setRechargeState(RechargeState.Taking);
         rechargeRecord.setWallet(userWallet);
         rechargeRecord.setUserId(userId);
+        rechargeRecord.setId(CommonUtil.UUID());
+        rechargeRecord.setUserInfo(orgUserDetail.getContent());
+
+        //构建转账请求参数
+        InitiateBatchTransferRequest request = new InitiateBatchTransferRequest();
+        request.setAppid(rechargeRecord.getAppid());
+        request.setOutBatchNo(rechargeRecord.getId());
+        request.setBatchRemark("余额提现");
+        request.setTotalAmount(rechargeRecord.getTotal().longValue());
+        request.setTotalNum(1);
+
+        TransferDetailInput transferDetailInput = new TransferDetailInput();
+        //todo openid
+        transferDetailInput.setOpenid(userWallet.getOpenid());
+        transferDetailInput.setOutDetailNo(rechargeRecord.getOutTradeNo());
+        transferDetailInput.setTransferAmount(rechargeRecord.getTotal().longValue());
+        transferDetailInput.setTransferRemark("余额提现");
+        if(rechargeRecord.getTotal().compareTo(BigDecimal.valueOf(2000L))>=0){
+            //todo 获取用户信息
+            transferDetailInput.setUserName("用户名");
+        }
+        if (rechargeRecord.getTotal().compareTo(BigDecimal.valueOf(0.3))<0){
+            transferDetailInput.setUserName(null);
+        }
+        request.setTransferDetailList(List.of(transferDetailInput));
+        //todo 设置转账场景id
+        request.setTransferSceneId("");
+
+        InitiateBatchTransferResponse initiateBatchTransferResponse = wxTransferBatchService.InitiateBatchTransferResponse(request, paySetResult.getContent());
+        TransferModel transferModel = new TransferModel();
+        BeanUtils.copyProperties(initiateBatchTransferResponse, transferModel);
+        rechargeRecord.setTransferModel(transferModel);
+        if (initiateBatchTransferResponse.getBatchStatus().equals("ACCEPTED")){
+            rechargeRecord.setRechargeState(RechargeState.Taking);
+        }
+        if (initiateBatchTransferResponse.getBatchStatus().equals("PROCESSING")){
+            rechargeRecord.setRechargeState(RechargeState.Taking);
+        }
+        if (initiateBatchTransferResponse.getBatchStatus().equals("FINISHED")){
+            rechargeRecord.setRechargeState(RechargeState.TakeSuccess);
+        }
+        if (initiateBatchTransferResponse.getBatchStatus().equals("CLOSED")){
+            rechargeRecord.setRechargeState(RechargeState.CLOSED);
+            return ResultContent.buildFail("该订单已关闭");
+        }
+
+        AmountUpdateParam amountUpdateParam = new AmountUpdateParam();
+        amountUpdateParam.setOutTradeNo(rechargeRecord.getOutTradeNo());
+        amountUpdateParam.setOid(rechargeRecord.getOid());
+        amountUpdateParam.setUserId(userId);
+        amountUpdateParam.setTotal(rechargeRecord.getTotal());
+        amountUpdateParam.setSchoolId(rechargeRecord.getSchoolId());
+        walletFeignService.commitTake(amountUpdateParam);
+
+        RechargeRecord record = rechargeRecordDao.save(rechargeRecord);
+        return ResultContent.buildSuccess(toModel(record));
+    }
+
+    /** 发起提现 */
+    @Transactional
+    public Object create(RechargeParam param){
+        String userId = authHelper.getCurrentUser().getUserId();
+        Wallet userWallet = walletDao.findTop1ById(param.getWalletId());
+        //判断钱包是否初始化
+        if (userWallet==null){
+            return ResultContent.buildFail("用户钱包未开通");
+        }
+
+        //判断微信支付配置
+        ProjectWxPayParam wxPayParam = new ProjectWxPayParam();
+        wxPayParam.setAppId(param.getAppid());
+        com.zhongshu.card.client.ret.ResultContent<WxPayConfigModel> paySetResult = paySettingFeignService.getProjectWxPayConfig(wxPayParam);
+        if (paySetResult.isFailed()){
+            return ResultContent.buildFail("获取微信支付配置失败");
+        }
+
         //设置人员信息
         OrgUserDetailParam orgUserDetailParam = new OrgUserDetailParam();
         orgUserDetailParam.setOid(userWallet.getOid());
@@ -93,6 +185,18 @@ public class TransferService {
         if (orgUserDetail.isFailed()){
             return ResultContent.buildFail("获取用户信息失败");
         }
+
+        RechargeRecord rechargeRecord = new RechargeRecord();
+        org.springframework.beans.BeanUtils.copyProperties(param, rechargeRecord, "total");
+        String outTradeNo = CommonUtil.UUID();
+        rechargeRecord.setOutTradeNo(outTradeNo);
+        rechargeRecord.setTotal(BigDecimal.valueOf(param.getTotal()));
+        rechargeRecord.setOid(userWallet.getOid());
+        rechargeRecord.setTradeType(TradeType.Take);
+        rechargeRecord.setRechargeState(RechargeState.TakeReview);
+        rechargeRecord.setWallet(userWallet);
+        rechargeRecord.setUserId(userId);
+
         rechargeRecord.setUserInfo(orgUserDetail.getContent());
 
         AmountUpdateParam amountUpdateParam = new AmountUpdateParam();