Selaa lähdekoodia

Merge remote-tracking branch 'origin/Payment-Configuration' into Payment-Configuration

yfh 5 päivää sitten
vanhempi
commit
769c2fefa4

+ 15 - 0
fs-admin/src/main/java/com/fs/his/task/CompanyBalanceTask.java

@@ -1,5 +1,6 @@
 package com.fs.his.task;
 
+import com.fs.common.core.domain.R;
 import com.fs.common.utils.DateUtils;
 import com.fs.common.utils.StringUtils;
 import com.fs.company.service.ICompanyService;
@@ -114,6 +115,20 @@ public class CompanyBalanceTask {
 
 
 
+    /**
+     * @Description: 更具批次号查询转账结果
+     * @Param:
+     * @Return:
+     * @Author xgb
+     * @Date 2025/12/25 10:31
+     */
+    public void checkMchTransferStatusByBatchID(String batchId,String companyIdStr) {
+        Long companyId=Long.parseLong(companyIdStr);
+        R result=companyService.checkMchTransferStatusByBatchID(batchId,companyId);
+        log.info("查询商户转账结果:{}",result);
+    }
+
+
 
 
 }

+ 2 - 2
fs-admin/src/main/resources/application.yml

@@ -4,11 +4,11 @@ server:
 # Spring配置
 spring:
   profiles:
-    active: dev-test
+#    active: dev-test
 #    active: druid-hdt
 #    active: druid-yzt
 #    active: druid-sxjz-test
 #    active: druid-sft
 #    active: druid-fby
-#    active: dev
+    active: dev
 

+ 11 - 0
fs-company/src/main/java/com/fs/company/controller/common/CommonController.java

@@ -120,6 +120,17 @@ public class CommonController
         return R.ok();
     }
 
+    @GetMapping("common/test3")
+    public R test2(String companyIdStr,String outBatchNo) throws Exception
+    {
+        // 默认是前两天时间
+        Long companyId=Long.parseLong(companyIdStr);
+        R result=companyService.checkMchTransferStatusByBatchID(outBatchNo,companyId);
+        log.info("查询商户转账结果:{}",result);
+        return R.ok();
+    }
+
+
     /**
      * 通用下载请求
      *

+ 2 - 0
fs-service/src/main/java/com/fs/company/service/ICompanyService.java

@@ -200,4 +200,6 @@ public interface ICompanyService
     void subLiveCompanyMoney(LiveOrder order);
 
     String checkMchTransferStatus(String outBatchNo,Long companyId);
+
+    R checkMchTransferStatusByBatchID(String batchId, Long companyId);
 }

+ 92 - 29
fs-service/src/main/java/com/fs/company/service/impl/CompanyServiceImpl.java

@@ -272,6 +272,76 @@ public class CompanyServiceImpl implements ICompanyService
         throw new CustomException("转账处理中");
     }
 
+    @Override
+    public R checkMchTransferStatusByBatchID(String batchId, Long companyId) {
+        // 获取配置信息
+        CourseConfig courseConfig = JSONUtil.toBean(configService.selectConfigByKey("course.config"), CourseConfig.class);
+
+        String json;
+        RedPacketConfig config = new RedPacketConfig();
+        // 根据红包模式获取配置
+        switch (courseConfig.getRedPacketMode()){
+            case 1:
+                json = configService.selectConfigByKey("redPacket.config");
+                config = JSONUtil.toBean(json, RedPacketConfig.class);
+                break;
+            case 2:
+                json = companyConfigService.selectRedPacketConfigByKey(companyId);
+                //如果分公司配置为空就走总后台的配置
+                if (StringUtils.isEmpty(json)){
+                    json = configService.selectConfigByKey("redPacket.config");
+                }
+                config = JSONUtil.toBean(json, RedPacketConfig.class);
+                break;
+            default:
+                throw new UnsupportedOperationException("当前红包模式不支持!");
+        }
+
+        //创建微信订单
+        WxPayConfig payConfig = new WxPayConfig();
+        BeanUtils.copyProperties(config,payConfig);
+        WxPayService wxPayService = new WxPayServiceImpl();
+        wxPayService.setConfig(payConfig);
+        TransferService transferService=wxPayService.getTransferService();
+
+        Map<String,Object> map = new HashMap<>();
+        map.put("status","待确认"); //
+        if (config.getIsNew() != null && config.getIsNew() == 1) {
+            try {
+                TransferBillsGetResult queryRedPacketResult = transferService.getBillsByTransferBillNo(batchId);
+                logger.info("FsCourseRedPacketLog-batchId:{},【红包处理】查询批次结果:{}",batchId,queryRedPacketResult.toString());
+                if(("SUCCESS").equals(queryRedPacketResult.getState())){
+                    map.put("status","success");
+                }else if(("FAIL").equals(queryRedPacketResult.getState())){
+                    map.put("status","fail");
+                }
+                return R.ok(map);
+            } catch (WxPayException e) {
+                logger.error(e.getMessage());
+                return R.error(e.getMessage());
+            }
+        } else {
+            QueryTransferBatchesRequest request = new QueryTransferBatchesRequest();
+            request.setBatchId(batchId);
+            request.setNeedQueryDetail(false);
+
+            try {
+                QueryTransferBatchesResult queryTransferBatchesResult = transferService.transferBatchesBatchId(request);
+                logger.info("FsCourseRedPacketLog-batchId,【红包处理】查询批次结果:{}",batchId,queryTransferBatchesResult.toString());
+                if(("FINISHED").equals(queryTransferBatchesResult.getTransferBatch().getBatchStatus())){
+                    map.put("status","success");
+                }else if(("CLOSED").equals(queryTransferBatchesResult.getTransferBatch().getBatchStatus())){
+                    map.put("status","fail");
+                }
+                return R.ok(map);
+            } catch (WxPayException e) {
+                logger.error(e.getMessage());
+                return R.error(e.getMessage());
+            }
+        }
+
+    }
+
     @Override
     public List<OptionsVO> selectAllCompanyList(Long deptId) {
         return companyMapper.selectAllCompanyList(deptId);
@@ -1749,10 +1819,6 @@ public class CompanyServiceImpl implements ICompanyService
         // 回滚前查询一下红包记录
         List<CompanyRedPacketBalanceLogs> companyRedPacketBalanceLogsList = companyRedPacketBalanceLogsMapper.selectCompanyRedPacketBalanceLogsListByStatus(createSTime, createETime);
 
-//        List<RedPacketMoneyVO> redPacketMoneyVOS = fsCourseRedPacketLogMapper.selectFsCourseAddRedPacketLogByCompany();
-//        for(RedPacketMoneyVO company:redPacketMoneyVOS){
-//            logger.info("红包余额回滚开始:{}",company);
-//        }
         Optional.ofNullable(companyRedPacketBalanceLogsList).ifPresent(list -> list.forEach(company -> {
 
             if(company.getRedPacketId()==null){// 无数据跳过
@@ -1772,30 +1838,36 @@ public class CompanyServiceImpl implements ICompanyService
                 return;
             }
 
-            if(!StringUtils.isEmpty(redLogs.getOutBatchNo())){
-                String batchId=checkMchTransferStatus(redLogs.getOutBatchNo(),redLogs.getCompanyId());
-                if (StringUtils.isNotBlank(batchId)) {
+            if(!StringUtils.isEmpty(redLogs.getBatchId())){
+                R result=checkMchTransferStatusByBatchID(redLogs.getBatchId(),redLogs.getCompanyId());
+                if("200".equals(result.get("code"))){
                     FsCourseRedPacketLog update = new FsCourseRedPacketLog();
-                    update.setLogId(redLogs.getLogId());
-                    update.setStatus(1);
                     update.setUpdateTime(new Date());
-                    update.setBatchId(batchId);
-                    fsCourseRedPacketLogMapper.updateFsCourseRedPacketLog(update);
+                    update.setLogId(redLogs.getLogId());
 
                     // 更新扣减状态
                     CompanyRedPacketBalanceLogs redBalanceLogs = new CompanyRedPacketBalanceLogs();
                     redBalanceLogs.setRedPacketId(company.getRedPacketId());
-                    redBalanceLogs.setStatus(1L);
-                    companyRedPacketBalanceLogsMapper.updateCompanyRedPacketBalanceLogsByRedPacketId(redBalanceLogs);
-                    return;
+
+                    if("success".equals(result.get("status"))){
+                        update.setStatus(1);
+                        fsCourseRedPacketLogMapper.updateFsCourseRedPacketLog(update);
+
+                        redBalanceLogs.setStatus(1L);
+                        companyRedPacketBalanceLogsMapper.updateCompanyRedPacketBalanceLogsByRedPacketId(redBalanceLogs);
+                        return;
+                    }else if("fail".equals(result.get("status"))){// 只对失败的部分进行回滚
+                        // 更新支付状态
+                        update.setStatus(2); // 已退回
+                        fsCourseRedPacketLogMapper.updateFsCourseRedPacketLog(update);
+
+                        redBalanceLogs.setStatus(2L);
+                        companyRedPacketBalanceLogsMapper.updateCompanyRedPacketBalanceLogsByRedPacketId(redBalanceLogs);
+                    }
                 }else {
-                    logger.error("未查询到商户转账批次号,进行退款,流水{}",company.getLogsId());
-                    // 更新支付状态
-                    updateBalanceStatus(company.getLogsId(), 2,company.getRemark()+";退回经销商"); // 更新为已退款
+                    logger.info("商户转账状态查询失败,流水{}",company.getLogsId());
+                    return;
                 }
-                logger.error("未查询到OutBatchNo,进行退款,流水{}",company.getLogsId());
-                // 更新支付状态
-                updateBalanceStatus(company.getLogsId(), 2,company.getRemark()+";退回经销商"); // 更新为已退款
             }else {
                 logger.error("红包记录表中存在商户批次号为null的异常数据,流水{}",company.getLogsId());
                 return;
@@ -1837,13 +1909,4 @@ public class CompanyServiceImpl implements ICompanyService
         }));
     }
 
-
-    private void updateBalanceStatus(Long logsId, Integer status,String remark){
-        FsCourseRedPacketLog redLogs = new FsCourseRedPacketLog();
-        redLogs.setLogId(logsId);
-        redLogs.setStatus(status);
-        redLogs.setRemark(remark);
-        fsCourseRedPacketLogMapper.updateFsCourseRedPacketLog(redLogs);
-    }
-
 }

+ 9 - 0
fs-service/src/main/java/com/fs/course/service/impl/FsUserCoursePeriodServiceImpl.java

@@ -146,6 +146,15 @@ public class FsUserCoursePeriodServiceImpl implements IFsUserCoursePeriodService
             coursePeriodDays.setStartDateTime(startDateTime);
             coursePeriodDays.setEndDateTime(endDateTime);
             coursePeriodDays.setLastJoinTime(lastJsonTime);
+
+            if(LocalDate.now().isBefore(coursePeriodDays.getStartDateTime().toLocalDate())){
+                coursePeriodDays.setStatus(0);
+            } else if(LocalDate.now().isAfter(coursePeriodDays.getStartDateTime().toLocalDate())){
+                coursePeriodDays.setStatus(2);
+            } else{
+                coursePeriodDays.setStatus(1);
+            }
+
             fsUserCoursePeriodDaysMapper.updateFsUserCoursePeriodDays(coursePeriodDays); // 更新数据库中的课程日期
         }
 

+ 1 - 1
fs-service/src/main/resources/mapper/company/CompanyRedPacketBalanceLogsMapper.xml

@@ -89,7 +89,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
         <trim prefix="SET" suffixOverrides=",">
             <if test="status != null">status = #{status},</if>
         </trim>
-        where red_packet_id = #{redPacketId}
+        where red_packet_id = #{redPacketId} and logs_type = 15
     </update>
 
     <delete id="deleteCompanyRedPacketBalanceLogsByLogsId" parameterType="Long">