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

1.去支付后再回到积分我请求购物车商品数量之前加的商品数量没清空
2.todayRewardReceived;
3.用户查询自己所有的领取积分

xw 3 днів тому
батько
коміт
6153ff98d1

+ 44 - 0
fs-service/src/main/java/com/fs/his/service/impl/FsIntegralOrderServiceImpl.java

@@ -690,6 +690,8 @@ public class FsIntegralOrderServiceImpl implements IFsIntegralOrderService
         integralParam.setBusinessId(order.getOrderId().toString());
         userIntegralLogsService.addIntegralTemplate(integralParam);
 
+        clearCartAfterPayment(order);
+
         order.setIsPay(1);
         order.setStatus(1);
         order.setPayTime(LocalDateTime.now());
@@ -697,6 +699,48 @@ public class FsIntegralOrderServiceImpl implements IFsIntegralOrderService
         return R.ok();
     }
 
+    /**
+     * 支付成功后清空购物车
+     * @param order 订单信息
+     */
+    private void clearCartAfterPayment(FsIntegralOrder order) {
+        try {
+            if (StringUtils.isEmpty(order.getItemJson())) {
+                return;
+            }
+
+            List<Long> goodsIds = new ArrayList<>();
+            
+            // 解析订单商品信息,获取商品ID列表
+            if (order.getItemJson().startsWith("[") && order.getItemJson().endsWith("]")) {
+                // 多个商品
+                List<FsIntegralGoods> goodsItem = JSONUtil.toBean(order.getItemJson(), new TypeReference<List<FsIntegralGoods>>(){}, true);
+                for (FsIntegralGoods goods : goodsItem) {
+                    if (goods.getGoodsId() != null) {
+                        goodsIds.add(goods.getGoodsId());
+                    }
+                }
+            } else if (order.getItemJson().startsWith("{") && order.getItemJson().endsWith("}")) {
+                // 单个商品
+                FsIntegralGoods goods = JSONUtil.toBean(order.getItemJson(), FsIntegralGoods.class);
+                if (goods.getGoodsId() != null) {
+                    goodsIds.add(goods.getGoodsId());
+                }
+            }
+
+            // 删除购物车中对应商品
+            if (!goodsIds.isEmpty()) {
+                Wrapper<FsIntegralCart> wrapper = Wrappers.<FsIntegralCart>lambdaQuery()
+                        .eq(FsIntegralCart::getUserId, order.getUserId())
+                        .in(FsIntegralCart::getGoodsId, goodsIds);
+                cartService.remove(wrapper);
+                log.info("支付成功后清空购物车,userId: {}, goodsIds: {}", order.getUserId(), goodsIds);
+            }
+        } catch (Exception e) {
+            log.error("清空购物车失败,orderId: {}, error: {}", order.getOrderId(), e.getMessage(), e);
+        }
+    }
+
     @Override
     public AjaxResult export(FsIntegralOrder fsIntegralOrder) {
         List<FsIntegralOrder> list = fsIntegralOrderMapper.selectFsIntegralOrderList(fsIntegralOrder);

+ 3 - 0
fs-service/src/main/java/com/fs/live/vo/LiveVo.java

@@ -61,4 +61,7 @@ public class LiveVo {
     
     /** 是否开启直播完课积分功能 */
     private Boolean completionPointsEnabled;
+    
+    /** 今天是否已领取完课奖励 */
+    private Boolean todayRewardReceived;
 }

+ 1 - 2
fs-service/src/main/resources/mapper/live/LiveCompletionPointsRecordMapper.xml

@@ -101,8 +101,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
     <!-- 查询用户的完课积分领取记录列表 -->
     <select id="selectRecordsByUser" resultMap="LiveCompletionPointsRecordResult">
         SELECT * FROM live_completion_points_record
-        WHERE live_id = #{liveId}
-          AND user_id = #{userId}
+        WHERE user_id = #{userId}
         ORDER BY current_completion_date DESC
     </select>
 

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

@@ -117,7 +117,8 @@ public class LiveController extends AppBaseController {
 //			liveVo.setNowPri(BigDecimal.valueOf(liveVo.getDuration()).divide(BigDecimal.valueOf(liveVo.getNowDuration()), 20, RoundingMode.UP));
 //		}
 		return R.ok().put("data", liveVo).put("storeId", storeId);*/
-		return liveFacadeService.liveDetail(id);
+		Long userId = Long.parseLong(getUserId());
+		return liveFacadeService.liveDetail(id, userId);
 	}
 
 	@Login

+ 1 - 1
fs-user-app/src/main/java/com/fs/app/facade/LiveFacadeService.java

@@ -13,7 +13,7 @@ public interface LiveFacadeService {
 
     TableDataInfo watchUserList(LiveWatchUser param);
 
-    R liveDetail(Long id);
+    R liveDetail(Long id, Long userId);
 
     R currentActivities(Long liveId, String userId);
 

+ 62 - 1
fs-user-app/src/main/java/com/fs/app/facade/impl/LiveFacadeServiceImpl.java

@@ -52,6 +52,9 @@ public class LiveFacadeServiceImpl extends BaseController implements LiveFacadeS
 
     @Autowired
     private ILiveLotteryConfService liveLotteryConfService;
+    
+    @Autowired
+    private ILiveCompletionPointsRecordService completionPointsRecordService;
 
     @Override
     public R liveList(PageRequest pageRequest) {
@@ -115,7 +118,7 @@ public class LiveFacadeServiceImpl extends BaseController implements LiveFacadeS
 
 
     @Override
-    public R liveDetail(Long id) {
+    public R liveDetail(Long id, Long userId) {
         Object o = redisCache.hashGet(LiveKeysConstant.LIVE_HOME_PAGE_DETAIL, String.valueOf(id));
         LiveVo liveVo;
         if (ObjectUtil.isNotEmpty(o)) {
@@ -129,8 +132,66 @@ public class LiveFacadeServiceImpl extends BaseController implements LiveFacadeS
         if(liveVo.getIsShow() == 2) {
             return R.error("直播未开放");
         }
+        
+        // 查询用户今天是否已领取完课奖励
+        if (userId != null) {
+            try {
+                List<LiveCompletionPointsRecord> unreceivedRecords = 
+                    completionPointsRecordService.getUserUnreceivedRecords(id, userId);
+                
+                // 判断是否有未领取的奖励,如果有则说明今天还未领取
+                // 如果没有未领取的,再查询是否有已领取的记录
+                if (unreceivedRecords != null && !unreceivedRecords.isEmpty()) {
+                    liveVo.setTodayRewardReceived(false);
+                } else {
+                    // 查询所有记录(包括已领取和未领取)
+                    List<LiveCompletionPointsRecord> allRecords = 
+                        completionPointsRecordService.getUserRecords(id, userId);
+                    
+                    if (allRecords != null && !allRecords.isEmpty()) {
+                        // 检查最近一条记录是否是今天的且已领取
+                        LiveCompletionPointsRecord latestRecord = allRecords.get(0);
+                        Date today = new Date();
+                        Date recordDate = latestRecord.getCurrentCompletionDate();
+                        
+                        // 判断是否为同一天
+                        boolean isSameDay = recordDate != null && 
+                            isSameDay(recordDate, today);
+                        
+                        if (isSameDay && latestRecord.getReceiveStatus() == 1) {
+                            liveVo.setTodayRewardReceived(true);
+                        } else {
+                            liveVo.setTodayRewardReceived(false);
+                        }
+                    } else {
+                        liveVo.setTodayRewardReceived(false);
+                    }
+                }
+            } catch (Exception e) {
+                log.error("查询用户完课奖励领取状态失败, liveId={}, userId={}", id, userId, e);
+                liveVo.setTodayRewardReceived(false);
+            }
+        } else {
+            liveVo.setTodayRewardReceived(false);
+        }
+        
         return R.ok().put("data", liveVo);
     }
+    
+    /**
+     * 判断两个日期是否为同一天
+     */
+    private boolean isSameDay(Date date1, Date date2) {
+        if (date1 == null || date2 == null) {
+            return false;
+        }
+        Calendar cal1 = Calendar.getInstance();
+        Calendar cal2 = Calendar.getInstance();
+        cal1.setTime(date1);
+        cal2.setTime(date2);
+        return cal1.get(Calendar.YEAR) == cal2.get(Calendar.YEAR) &&
+               cal1.get(Calendar.DAY_OF_YEAR) == cal2.get(Calendar.DAY_OF_YEAR);
+    }
 
     @Override
     public R currentActivities(Long liveId, String userId) {