Переглянути джерело

1、汇付支付问题处理
2、中奖定时任务处理

yys 2 тижнів тому
батько
коміт
4fc8a0a107

+ 12 - 5
fs-live-app/src/main/java/com/fs/live/task/Task.java

@@ -355,6 +355,8 @@ public class Task {
                     lotteryVo.setPrizeLevel(liveLotteryProductListVo.getPrizeLevel());
                     lotteryVo.setProductName(liveLotteryProductListVo.getProductName());
                     lotteryVo.setProductId(liveLotteryProductListVo.getProductId());
+                    //设置中奖记录id
+                    lotteryVo.setRecordId(record.getId());
                     lotteryVos.add(lotteryVo);
                 }
             }
@@ -557,8 +559,8 @@ public class Task {
 
                     liveCouponUserService.insertLiveCouponUser(couponUser);
 
-                    // 保存奖励记录
-                    saveUserRewardRecord(live, Collections.singletonList(userId), coupon.getCouponPrice(), 3);
+                    // 保存奖励记录 - 优惠券类型的sourceId为couponId
+                    saveUserRewardRecord(live, Collections.singletonList(userId), coupon.getCouponPrice(), 3, couponId);
 
                     successCount++;
 
@@ -570,7 +572,7 @@ public class Task {
                 }
             }
 
-            log.info("直播间观看奖励-优惠券发放完成,liveId={}, couponId={}, 成功发放 {} 个用户", 
+            log.info("直播间观看奖励-优惠券发放完成,liveId={}, couponId={}, 成功发放 {} 个用户",
                     live.getLiveId(), couponId, successCount);
 
         } catch (Exception e) {
@@ -604,14 +606,14 @@ public class Task {
             log.error("发送优惠券奖励消息失败,liveId={}, userId={}", liveId, userId, e);
         }
     }
-    private void saveUserRewardRecord(Live live, List<Long> userIds, BigDecimal amount, int rewardType) {
+    private void saveUserRewardRecord(Live live, List<Long> userIds, BigDecimal amount, int rewardType, Long sourceId) {
         for (Long userId : userIds) {
             LiveRewardRecord record = new LiveRewardRecord();
             record.setLiveId(live.getLiveId());
             record.setUserId(userId);
             record.setIncomeType(1L); // 收入
             record.setSourceType(3L); // 观看奖励
-            record.setSourceId(live.getCompanyId() == null ? 0L : live.getCompanyId());
+            record.setSourceId(sourceId);
             record.setRewardType((long) rewardType); // 1-现金 2-积分 3-优惠券
             record.setNum(amount);
             record.setCreateTime(new Date());
@@ -620,6 +622,11 @@ public class Task {
         }
     }
 
+    // 保留原有方法签名以兼容其他调用(积分类型,sourceId默认为companyId)
+    private void saveUserRewardRecord(Live live, List<Long> userIds, BigDecimal amount, int rewardType) {
+        saveUserRewardRecord(live, userIds, amount, rewardType, live.getCompanyId() == null ? 0L : live.getCompanyId());
+    }
+
     // 保留原有方法签名以兼容其他调用
     private void saveUserRewardRecord(Live live, List<Long> userIds, Long scoreAmount) {
         saveUserRewardRecord(live, userIds, BigDecimal.valueOf(scoreAmount), 2);

+ 11 - 65
fs-service/src/main/java/com/fs/huifuPay/service/impl/HuiFuServiceImpl.java

@@ -2,6 +2,7 @@ package com.fs.huifuPay.service.impl;
 
 import com.alibaba.fastjson.JSON;
 import com.alibaba.fastjson.JSONObject;
+import com.baomidou.mybatisplus.core.toolkit.ObjectUtils;
 import com.fs.common.exception.CustomException;
 import com.fs.common.utils.StringUtils;
 import com.fs.common.utils.spring.SpringUtils;
@@ -51,15 +52,8 @@ public class HuiFuServiceImpl implements HuiFuService {
         try {
 
             if (order.getAppId() != null) {
-                FsHfpayConfigMapper fsHfpayConfigMapper = SpringUtils.getBean(FsHfpayConfigMapper.class);
-                FsHfpayConfig fsHfpayConfig = fsHfpayConfigMapper.selectByAppId(order.getAppId());
-                if (fsHfpayConfig != null) {
-                    //多汇付支付获取配置
-                    doInit(getMerConfig(fsHfpayConfig));
-                } else {
-                    //多小程序
-                    doInit(getMerConfig(order.getAppId()));
-                }
+                //多小程序
+                doInit(getMerConfig(order.getAppId()));
             } else {
                 doInit(getMerConfig());
             }
@@ -140,15 +134,8 @@ public class HuiFuServiceImpl implements HuiFuService {
     @Override
     public HuiFuQueryOrderResult queryOrder(V2TradePaymentScanpayQueryRequest request) throws Exception{
         if (request.getAppId() != null) {
-            FsHfpayConfigMapper fsHfpayConfigMapper = SpringUtils.getBean(FsHfpayConfigMapper.class);
-            FsHfpayConfig fsHfpayConfig = fsHfpayConfigMapper.selectByAppId(request.getAppId());
-            if (fsHfpayConfig != null) {
-                //多汇付支付获取配置
-                doInit(getMerConfig(fsHfpayConfig));
-            } else {
-                //多小程序
-                doInit(getMerConfig());
-            }
+            //多汇付支付获取配置
+            doInit(getMerConfig(request.getAppId()));
         } else {
             doInit(getMerConfig());
         }
@@ -172,16 +159,8 @@ public class HuiFuServiceImpl implements HuiFuService {
     public HuiFuRefundResult refund(V2TradePaymentScanpayRefundRequest request) {
         HuiFuRefundResult huiFuRefundResult=null;
         try {
-            if (request.getAppId() != null) {
-                FsHfpayConfigMapper fsHfpayConfigMapper = SpringUtils.getBean(FsHfpayConfigMapper.class);
-                FsHfpayConfig fsHfpayConfig = fsHfpayConfigMapper.selectByAppId(request.getAppId());
-                if (fsHfpayConfig != null) {
-                    //多汇付支付获取配置
-                    doInit(getMerConfig(fsHfpayConfig));
-                } else {
-                    //多小程序
-                    doInit(getMerConfig());
-                }
+            if(ObjectUtils.isNotNull(request.getAppId())){
+                doInit(getMerConfig(request.getAppId()));
             } else {
                 doInit(getMerConfig());
             }
@@ -190,6 +169,7 @@ public class HuiFuServiceImpl implements HuiFuService {
             String jsonString = JSONObject.toJSONString(response);
             huiFuRefundResult = JSON.parseObject(jsonString, HuiFuRefundResult.class);
         } catch (Exception e){
+            e.printStackTrace();
             throw  new CustomException("退款创建失败");
         }
         return huiFuRefundResult;
@@ -198,19 +178,7 @@ public class HuiFuServiceImpl implements HuiFuService {
 
     @Override
     public HuiFuRefundResult queryRefundOrder(V2TradePaymentScanpayRefundqueryRequest request)throws Exception {
-        if (request.getAppId() != null) {
-            FsHfpayConfigMapper fsHfpayConfigMapper = SpringUtils.getBean(FsHfpayConfigMapper.class);
-            FsHfpayConfig fsHfpayConfig = fsHfpayConfigMapper.selectByAppId(request.getAppId());
-            if (fsHfpayConfig != null) {
-                //多汇付支付获取配置
-                doInit(getMerConfig(fsHfpayConfig));
-            } else {
-                //多小程序
-                doInit(getMerConfig());
-            }
-        } else {
-            doInit(getMerConfig());
-        }
+        doInit(getMerConfig());
         Map<String, Object> extendInfoMap = request.getExtendInfos();
         extendInfoMap.put("notify_url", config.getHfRefundNotifyUrl());
         request.setExtendInfo(extendInfoMap);
@@ -325,15 +293,8 @@ public class HuiFuServiceImpl implements HuiFuService {
         HuiFuQueryOrderResult result =null;
         try {
             if (order.getAppId() != null) {
-                FsHfpayConfigMapper fsHfpayConfigMapper = SpringUtils.getBean(FsHfpayConfigMapper.class);
-                FsHfpayConfig fsHfpayConfig = fsHfpayConfigMapper.selectByAppId(order.getAppId());
-                if (fsHfpayConfig != null) {
-                    //多汇付支付获取配置
-                    doInit(getMerConfig(fsHfpayConfig));
-                } else {
-                    //多小程序
-                    doInit(getMerConfig());
-                }
+                //多汇付支付获取配置
+                doInit(getMerConfig(order.getAppId()));
             } else {
                 doInit(getMerConfig());
             }
@@ -396,21 +357,6 @@ public class HuiFuServiceImpl implements HuiFuService {
         return merConfig;
     }
 
-    public MerConfig getMerConfig(FsHfpayConfig fsHfpayConfig) {
-        MerConfig merConfig = new MerConfig();
-        merConfig.setProcutId(fsHfpayConfig.getHfProductId());
-        merConfig.setSysId(fsHfpayConfig.getHfSysId());
-        merConfig.setRsaPrivateKey(fsHfpayConfig.getHfRsaPrivateKey());
-        merConfig.setRsaPublicKey(fsHfpayConfig.getHfRsaPublicKey());
-        merConfig.setHuifuId(fsHfpayConfig.getHuifuId());
-
-        FsPayConfig fsPayConfig = new FsPayConfig();
-        BeanUtils.copyProperties(fsHfpayConfig,fsPayConfig);
-
-        config = fsPayConfig;
-        return merConfig;
-    }
-
     public MerConfig getMerConfig(String appId) {
         if (StringUtils.isBlank(appId)) {
             throw new IllegalArgumentException("appId不能为空");

+ 0 - 1
fs-service/src/main/java/com/fs/live/mapper/LiveOrderMapper.java

@@ -107,7 +107,6 @@ public interface LiveOrderMapper {
             "</where> " +
             "order by create_time desc" +
             "</script>"})
-    @DataSource(DataSourceType.SLAVE)
     List<LiveOrderListVo> selectLiveOrderListVo(@Param("userId") String userId,@Param("status") Integer status);
 
     @Select("select * from live_order where `status` = 3 AND TIMESTAMPDIFF(HOUR, start_time, NOW()) >= 48  ")

+ 24 - 8
fs-service/src/main/java/com/fs/live/service/impl/LiveAfterSalesServiceImpl.java

@@ -748,26 +748,37 @@ public class LiveAfterSalesServiceImpl implements ILiveAfterSalesService {
 
     @Override
     public R audit1(LiveAfterSalesAudit1Param param) {
+        log.info("===== audit1 开始执行 =====");
         LiveAfterSales liveAfterSales = baseMapper.selectLiveAfterSalesById(param.getSalesId());
         if (liveAfterSales == null) {
             throw new CustomException("未查询到售后订单信息");
         }
-        if (!liveAfterSales.getStatus().equals(AfterStatusEnum.STATUS_0.getValue())) {
+        log.info("[audit1] 售后订单信息: id={}, status={}, refundType={}, orderStatus={}", 
+                liveAfterSales.getId(), liveAfterSales.getStatus(), 
+                liveAfterSales.getRefundType(), liveAfterSales.getOrderStatus());
+        if (!Objects.equals(liveAfterSales.getStatus(), AfterStatusEnum.STATUS_0.getValue())) {
             throw new CustomException("非法操作");
         }
         //仅退款
-        if(liveAfterSales.getRefundType().equals(0)){
+        if(Objects.equals(liveAfterSales.getRefundType(), 0)){
+            log.info("[audit1] 进入仅退款分支, refundType=0");
             //仅退款未发货处理
-            if(liveAfterSales.getOrderStatus().equals(OrderInfoEnum.STATUS_1.getValue())){
+            if(Objects.equals(liveAfterSales.getOrderStatus(), OrderInfoEnum.STATUS_1.getValue())){
+                log.info("[audit1] 进入仅退款-未发货处理, orderStatus={}", OrderInfoEnum.STATUS_1.getValue());
                 //审核通过
                 liveAfterSales.setStatus(3);
-                baseMapper.updateLiveAfterSales(liveAfterSales);
+                int updateCount = baseMapper.updateLiveAfterSales(liveAfterSales);
+                log.info("[audit1] 更新售后订单状态为3, updateCount={}", updateCount);
             }
             //仅退款待收货处理
-            else if(liveAfterSales.getOrderStatus().equals(OrderInfoEnum.STATUS_2.getValue())){
+            else if(Objects.equals(liveAfterSales.getOrderStatus(), OrderInfoEnum.STATUS_2.getValue())){
+                log.info("[audit1] 进入仅退款-待收货处理, orderStatus={}", OrderInfoEnum.STATUS_2.getValue());
                 liveAfterSales.setStatus(2);
-                baseMapper.updateLiveAfterSales(liveAfterSales);
+                int updateCount = baseMapper.updateLiveAfterSales(liveAfterSales);
+                log.info("[audit1] 更新售后订单状态为2, updateCount={}", updateCount);
             //已完成 退货退款
+            } else {
+                log.warn("[audit1] 仅退款分支: 未匹配到处理条件, orderStatus={}", liveAfterSales.getOrderStatus());
             }
             LiveAfterSalesLogs salesLogs = new LiveAfterSalesLogs();
             salesLogs.setStoreAfterSalesId(liveAfterSales.getId());
@@ -776,9 +787,11 @@ public class LiveAfterSalesServiceImpl implements ILiveAfterSalesService {
             salesLogs.setChangeTime(Timestamp.valueOf(LocalDateTime.now()));
             salesLogs.setOperator(param.getOperator());
             liveAfterSalesLogsMapper.insertLiveAfterSalesLogs(salesLogs);
+            log.info("[audit1] 插入售后日志完成");
         }
         //退款退货
-        else if(liveAfterSales.getRefundType().equals(1)){
+        else if(Objects.equals(liveAfterSales.getRefundType(), 1)){
+            log.info("[audit1] 进入退款退货分支, refundType=1");
             String json=configService.selectConfigByKey("store.config");
             StoreConfig config=JSONUtil.toBean(json,StoreConfig.class);
             LiveOrder order=liveOrderMapper.selectLiveOrderByOrderId(String.valueOf(liveAfterSales.getOrderId()));
@@ -802,7 +815,8 @@ public class LiveAfterSalesServiceImpl implements ILiveAfterSalesService {
             }
             //退款退货
             liveAfterSales.setStatus(1);
-            baseMapper.updateLiveAfterSales(liveAfterSales);
+            int updateCount = baseMapper.updateLiveAfterSales(liveAfterSales);
+            log.info("[audit1] 退款退货: 更新售后订单状态为1, updateCount={}", updateCount);
             LiveAfterSalesLogs salesLogs  = new LiveAfterSalesLogs();
             salesLogs.setStoreAfterSalesId(liveAfterSales.getId());
             salesLogs.setChangeType(1);
@@ -810,8 +824,10 @@ public class LiveAfterSalesServiceImpl implements ILiveAfterSalesService {
             salesLogs.setChangeTime(Timestamp.valueOf(LocalDateTime.now()));
             salesLogs.setOperator(param.getOperator());
             liveAfterSalesLogsMapper.insertLiveAfterSalesLogs(salesLogs);
+            log.info("[audit1] 退款退货: 插入售后日志完成");
         }
 
+        log.info("===== audit1 执行完成 =====");
         return R.ok("操作成功");
 
     }

+ 10 - 3
fs-service/src/main/java/com/fs/live/service/impl/LiveOrderServiceImpl.java

@@ -1158,11 +1158,11 @@ public class LiveOrderServiceImpl implements ILiveOrderService {
 
     @Override
     public List<LiveOrderListVo> selectLiveOrderListVo(LiveOrder liveOrder) {
-        List<LiveOrderListVo> liveOrders = baseMapper.selectLiveOrderListVo(liveOrder.getUserId(),liveOrder.getStatus());
+        List<LiveOrderListVo> liveOrders = baseMapper.selectLiveOrderListVo(liveOrder.getUserId(), liveOrder.getStatus());
         List<Long> allOrderIds = liveOrders.stream().map(LiveOrderListVo::getOrderId)
                 .filter(Objects::nonNull).collect(Collectors.toList());
 
-        if(CollectionUtils.isEmpty(allOrderIds)) {
+        if (CollectionUtils.isEmpty(allOrderIds)) {
             return Collections.emptyList();
         }
 
@@ -1189,6 +1189,13 @@ public class LiveOrderServiceImpl implements ILiveOrderService {
                 List<LiveOrderItemVo> liveOrderItemVos = orderItemsMap.get(orderId);
                 if(CollectionUtils.isNotEmpty(liveOrderItemVos)) {
                     order.setOrderItemList(liveOrderItemVos);
+                    // 根据子订单的isAfterSales更新外层订单的isAfterSales
+                    // 当所有子订单的isAfterSales都为0时,外层订单的isAfterSales设置为0
+                    boolean allNotAfterSales = liveOrderItemVos.stream()
+                            .allMatch(item -> item.getIsAfterSales() != null && item.getIsAfterSales() == 0);
+                    if (allNotAfterSales) {
+                        order.setIsAfterSales(0);
+                    }
                 }
             }
         }
@@ -3349,7 +3356,7 @@ public class LiveOrderServiceImpl implements ILiveOrderService {
                 log.info("支付单号不存在:"+payCode);
                 throw new CustomException("当前支付记录未找到!");
             }
-            if(liveOrder.getStatus()!=1){
+            if(liveOrder.getStatus()!=0){
                 TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
                 return R.error("当前订单未找到或者订单状态不为待支付!");
             }

+ 91 - 2
fs-user-app/src/main/java/com/fs/app/controller/live/LiveController.java

@@ -48,6 +48,7 @@ import org.springframework.security.access.prepost.PreAuthorize;
 import org.springframework.transaction.annotation.Transactional;
 import org.springframework.web.bind.annotation.*;
 
+import java.math.BigDecimal;
 import java.time.LocalDateTime;
 import java.util.*;
 import java.util.stream.Collectors;
@@ -87,10 +88,16 @@ public class LiveController extends AppBaseController {
 	private LiveWatchUserMapper liveWatchUserService;
     @Autowired
     private LiveVideoMapper liveVideoMapper;
-    @Autowired
-    private com.fs.live.mapper.LiveUserFirstEntryMapper liveUserFirstEntryMapper;
+	@Autowired
+	private com.fs.live.mapper.LiveUserFirstEntryMapper liveUserFirstEntryMapper;
     @Autowired
     private com.fs.live.mapper.LiveOrderMapper liveOrderMapper;
+    @Autowired
+    private ILiveRewardRecordService liveRewardRecordService;
+    @Autowired
+    private ILiveCouponUserService liveCouponUserService;
+    @Autowired
+    private ILiveUserRedRecordService liveUserRedRecordService;
 
 	/**
 	 * 查询未结束直播间(销售专用)
@@ -400,4 +407,86 @@ public class LiveController extends AppBaseController {
 		return liveService.liveDecryptLinkV2(param.getUrl(),userId);
 	}
 
+	/**
+	 * 查询当前用户在当前直播间获得的奖品记录
+	 * @param liveId 直播间ID
+	 * @return 奖品记录列表(积分、优惠券、红包等)
+	 */
+	@Login
+	@ApiOperation("查询我的直播间奖品记录")
+	@GetMapping("/myRewardRecords")
+	public R myRewardRecords(@RequestParam Long liveId) {
+		try {
+			Long userId = Long.valueOf(getUserId());
+
+			// 查询奖励记录(积分、现金、优惠券等)
+			LiveRewardRecord rewardQuery = new LiveRewardRecord();
+			rewardQuery.setLiveId(liveId);
+			rewardQuery.setUserId(userId);
+			rewardQuery.setIncomeType(1L); // 收入类型
+			List<LiveRewardRecord> rewardRecords = liveRewardRecordService.selectLiveRewardRecordList(rewardQuery);
+
+			// 从奖励记录中提取优惠券ID(rewardType=3时,sourceId为couponId)
+			List<Long> couponIds = rewardRecords.stream()
+					.filter(r -> r.getRewardType() != null && r.getRewardType() == 3)
+					.map(LiveRewardRecord::getSourceId)
+					.filter(Objects::nonNull)
+					.distinct()
+					.collect(Collectors.toList());
+
+			// 查询优惠券详情
+			List<LiveCouponUser> liveCoupons = new ArrayList<>();
+			if (!couponIds.isEmpty()) {
+				LiveCouponUser couponQuery = new LiveCouponUser();
+				couponQuery.setUserId(userId.intValue());
+				List<LiveCouponUser> allUserCoupons = liveCouponUserService.selectLiveCouponUserList(couponQuery);
+				// 过滤出当前直播间获得的优惠券
+				liveCoupons = allUserCoupons.stream()
+						.filter(c -> c.getCouponId() != null && couponIds.contains(c.getCouponId()))
+						.collect(Collectors.toList());
+			}
+
+			// 查询红包记录
+			LiveUserRedRecord redQuery = new LiveUserRedRecord();
+			redQuery.setLiveId(liveId);
+			redQuery.setUserId(userId);
+			List<LiveUserRedRecord> redRecords = liveUserRedRecordService.selectLiveUserRedRecordList(redQuery);
+
+			// 整合结果
+			Map<String, Object> result = new HashMap<>();
+			result.put("rewardRecords", rewardRecords);  // 积分、现金奖励记录
+			result.put("couponRecords", liveCoupons);     // 优惠券记录
+			result.put("redRecords", redRecords);          // 红包记录
+
+			// 统计
+			Map<String, Object> statistics = new HashMap<>();
+			statistics.put("totalRewards", rewardRecords.size());
+			statistics.put("totalCoupons", liveCoupons.size());
+			statistics.put("totalReds", redRecords.size());
+
+			// 计算总积分
+			BigDecimal totalPoints = rewardRecords.stream()
+					.filter(r -> r.getRewardType() != null && r.getRewardType() == 2)
+					.map(LiveRewardRecord::getNum)
+					.filter(Objects::nonNull)
+					.reduce(BigDecimal.ZERO, BigDecimal::add);
+			statistics.put("totalPoints", totalPoints);
+
+			// 计算总现金
+			BigDecimal totalCash = rewardRecords.stream()
+					.filter(r -> r.getRewardType() != null && r.getRewardType() == 1)
+					.map(LiveRewardRecord::getNum)
+					.filter(Objects::nonNull)
+					.reduce(BigDecimal.ZERO, BigDecimal::add);
+			statistics.put("totalCash", totalCash);
+
+			result.put("statistics", statistics);
+
+			return R.ok().put("data", result);
+		} catch (Exception e) {
+			log.error("查询奖品记录失败, liveId={}, userId={}", liveId, getUserId(), e);
+			return R.error("查询奖品记录失败: " + e.getMessage());
+		}
+	}
+
 }