|
@@ -272,6 +272,76 @@ public class CompanyServiceImpl implements ICompanyService
|
|
|
throw new CustomException("转账处理中");
|
|
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
|
|
@Override
|
|
|
public List<OptionsVO> selectAllCompanyList(Long deptId) {
|
|
public List<OptionsVO> selectAllCompanyList(Long deptId) {
|
|
|
return companyMapper.selectAllCompanyList(deptId);
|
|
return companyMapper.selectAllCompanyList(deptId);
|
|
@@ -1749,10 +1819,6 @@ public class CompanyServiceImpl implements ICompanyService
|
|
|
// 回滚前查询一下红包记录
|
|
// 回滚前查询一下红包记录
|
|
|
List<CompanyRedPacketBalanceLogs> companyRedPacketBalanceLogsList = companyRedPacketBalanceLogsMapper.selectCompanyRedPacketBalanceLogsListByStatus(createSTime, createETime);
|
|
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 -> {
|
|
Optional.ofNullable(companyRedPacketBalanceLogsList).ifPresent(list -> list.forEach(company -> {
|
|
|
|
|
|
|
|
if(company.getRedPacketId()==null){// 无数据跳过
|
|
if(company.getRedPacketId()==null){// 无数据跳过
|
|
@@ -1772,30 +1838,36 @@ public class CompanyServiceImpl implements ICompanyService
|
|
|
return;
|
|
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();
|
|
FsCourseRedPacketLog update = new FsCourseRedPacketLog();
|
|
|
- update.setLogId(redLogs.getLogId());
|
|
|
|
|
- update.setStatus(1);
|
|
|
|
|
update.setUpdateTime(new Date());
|
|
update.setUpdateTime(new Date());
|
|
|
- update.setBatchId(batchId);
|
|
|
|
|
- fsCourseRedPacketLogMapper.updateFsCourseRedPacketLog(update);
|
|
|
|
|
|
|
+ update.setLogId(redLogs.getLogId());
|
|
|
|
|
|
|
|
// 更新扣减状态
|
|
// 更新扣减状态
|
|
|
CompanyRedPacketBalanceLogs redBalanceLogs = new CompanyRedPacketBalanceLogs();
|
|
CompanyRedPacketBalanceLogs redBalanceLogs = new CompanyRedPacketBalanceLogs();
|
|
|
redBalanceLogs.setRedPacketId(company.getRedPacketId());
|
|
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 {
|
|
}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 {
|
|
}else {
|
|
|
logger.error("红包记录表中存在商户批次号为null的异常数据,流水{}",company.getLogsId());
|
|
logger.error("红包记录表中存在商户批次号为null的异常数据,流水{}",company.getLogsId());
|
|
|
return;
|
|
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);
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
}
|
|
}
|