|
@@ -1,18 +1,24 @@
|
|
|
package com.fs.course.service.impl;
|
|
|
|
|
|
import java.math.BigDecimal;
|
|
|
+import java.time.LocalDateTime;
|
|
|
+import java.time.format.DateTimeFormatter;
|
|
|
import java.util.Date;
|
|
|
+import java.util.HashMap;
|
|
|
import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
|
|
|
import cn.hutool.json.JSONUtil;
|
|
|
import com.alibaba.fastjson.JSON;
|
|
|
import com.fs.common.core.domain.R;
|
|
|
import com.fs.common.utils.DateUtils;
|
|
|
+import com.fs.common.utils.StringUtils;
|
|
|
import com.fs.company.domain.Company;
|
|
|
import com.fs.company.domain.CompanyMoneyLogs;
|
|
|
import com.fs.company.mapper.CompanyMapper;
|
|
|
import com.fs.company.mapper.CompanyMoneyLogsMapper;
|
|
|
import com.fs.course.config.CourseConfig;
|
|
|
+import com.fs.course.config.RedPacketConfig;
|
|
|
import com.fs.course.domain.FsCourseWatchLog;
|
|
|
import com.fs.course.mapper.FsCourseWatchLogMapper;
|
|
|
import com.fs.course.param.FsCourseRedPacketLogParam;
|
|
@@ -22,9 +28,16 @@ import com.fs.his.mapper.FsUserMapper;
|
|
|
import com.fs.his.param.WxSendRedPacketParam;
|
|
|
import com.fs.his.service.IFsStorePaymentService;
|
|
|
import com.fs.system.service.ISysConfigService;
|
|
|
+import com.github.binarywang.wxpay.bean.transfer.TransferBillsGetResult;
|
|
|
import com.github.binarywang.wxpay.bean.transfer.TransferBillsResult;
|
|
|
+import com.github.binarywang.wxpay.config.WxPayConfig;
|
|
|
+import com.github.binarywang.wxpay.exception.WxPayException;
|
|
|
+import com.github.binarywang.wxpay.service.TransferService;
|
|
|
+import com.github.binarywang.wxpay.service.WxPayService;
|
|
|
+import com.github.binarywang.wxpay.service.impl.WxPayServiceImpl;
|
|
|
import org.slf4j.Logger;
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
+import org.springframework.beans.BeanUtils;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import com.fs.course.mapper.FsCourseRedPacketLogMapper;
|
|
@@ -300,6 +313,64 @@ public class FsCourseRedPacketLogServiceImpl implements IFsCourseRedPacketLogSer
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ @Override
|
|
|
+ public void queryRedPacketResult(String startTime, String endTime) {
|
|
|
+ LocalDateTime tenMinutesAgo;
|
|
|
+ LocalDateTime twentyMinutesAgo;
|
|
|
+ if(StringUtils.isEmpty(startTime) || StringUtils.isEmpty(endTime)){
|
|
|
+ // 获取前十分钟时间 和 前二十分钟时间
|
|
|
+ tenMinutesAgo = LocalDateTime.now().minusMinutes(10);
|
|
|
+ twentyMinutesAgo = tenMinutesAgo.minusMinutes(10);
|
|
|
+ }else {
|
|
|
+ tenMinutesAgo = LocalDateTime.parse(endTime, DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
|
|
|
+ twentyMinutesAgo = LocalDateTime.parse(startTime, DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
|
|
|
+ }
|
|
|
+
|
|
|
+ // 获取前分钟时间
|
|
|
+ Map<String, Object> params = new HashMap<>();
|
|
|
+ params.put("startTime", twentyMinutesAgo);
|
|
|
+ params.put("endTime",tenMinutesAgo);
|
|
|
+ // 获取前十分钟红包记录状态为发送中的记录
|
|
|
+ List<FsCourseRedPacketLog> redPacketLogs = fsCourseRedPacketLogMapper.selectFsCourseRedPacketLogListBySending(params);
|
|
|
+ if(redPacketLogs!=null && !redPacketLogs.isEmpty()){
|
|
|
+ String json = configService.selectConfigByKey("redPacket.config");
|
|
|
+ RedPacketConfig config = JSONUtil.toBean(json, RedPacketConfig.class);
|
|
|
+ //创建微信订单
|
|
|
+ WxPayConfig payConfig = new WxPayConfig();
|
|
|
+ BeanUtils.copyProperties(config,payConfig);
|
|
|
+ WxPayService wxPayService = new WxPayServiceImpl();
|
|
|
+ wxPayService.setConfig(payConfig);
|
|
|
+ TransferService transferService=wxPayService.getTransferService();
|
|
|
+ for(FsCourseRedPacketLog redPacket:redPacketLogs){
|
|
|
+ // 获取批次号
|
|
|
+ // redPacket.getResult() {"msg":"发送红包成功","code":200,"mchId":"1703311381","data":{"createTime":"2025-06-26T18:00:48+08:00","outBillNo":"fsCourse1938175604536901632","packageInfo":"ABBQO+oYAAABAAAAAABRil0NtaWxBS5JURpdaBAAAADnGpepZahT9IkJjn90+1qgtzWOmCRNZJfek1QMbZ9ktG8idrj37//0xOSt0T67XUFE+PGeXO8qZoNKHYlU3RicIHExIjZr342xE+QjrpjaHIFYoPg=","state":"WAIT_USER_CONFIRM","transferBillNo":"1330007292140242506260028904279364"},"isNew":1}
|
|
|
+ // 获取 transferBillNo
|
|
|
+ String batchId;
|
|
|
+ try {
|
|
|
+ batchId = StringUtils.isNotEmpty(redPacket.getBatchId())?redPacket.getBatchId():JSON.parseObject(redPacket.getResult()).getJSONObject("data").getString("transferBillNo");
|
|
|
+ }catch (Exception e){
|
|
|
+ logger.error("【红包处理】获取批次号失败,FsCourseRedPacketLog-log_id:{}",redPacket.getLogId());
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+
|
|
|
+ try {
|
|
|
+ TransferBillsGetResult queryRedPacketResult = transferService.getBillsByTransferBillNo(batchId);
|
|
|
+ logger.info("FsCourseRedPacketLog-log_id:{},【红包处理】查询批次结果:{}",redPacket.getLogId(),queryRedPacketResult);
|
|
|
+ if(queryRedPacketResult!=null && "SUCCESS".equals(queryRedPacketResult.getState())){
|
|
|
+ FsCourseRedPacketLog fsCourseRedPacketLog=new FsCourseRedPacketLog();
|
|
|
+ fsCourseRedPacketLog.setLogId(redPacket.getLogId());
|
|
|
+ fsCourseRedPacketLog.setStatus(1); // 已发送
|
|
|
+ fsCourseRedPacketLog.setUpdateTime(new Date());
|
|
|
+// updateFsCourseRedPacketLog(fsCourseRedPacketLog);
|
|
|
+ }
|
|
|
+ } catch (WxPayException e) {
|
|
|
+ logger.error(e.getMessage());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
private void processRedPacket(FsCourseRedPacketLog redPacket, CourseConfig config) {
|
|
|
// 获取用户信息
|
|
|
FsUser user = fsUserMapper.selectFsUserByUserId(redPacket.getUserId());
|