Bladeren bron

Merge remote-tracking branch 'origin/master_exclusive_shop_20250718' into master_fhhx_20250718

xdd 1 dag geleden
bovenliggende
commit
6a25f67127

+ 4 - 4
fs-admin/src/main/java/com/fs/live/controller/LiveLotteryConfController.java

@@ -112,10 +112,10 @@ public class LiveLotteryConfController extends BaseController
     }
 
 //    @PreAuthorize("@ss.hasPermi('live:liveLotteryConf:remove')")
-    @DeleteMapping("/{id}")
-    public void delete(@PathVariable Long id) {
-        liveLotteryConfService.delete(id);
-    }
+//    @DeleteMapping("/{id}")
+//    public void delete(@PathVariable Long id) {
+//        liveLotteryConfService.delete(id);
+//    }
 
     /**
      * 发起抽奖

+ 4 - 4
fs-company/src/main/java/com/fs/company/controller/live/LiveLotteryConfController.java

@@ -113,10 +113,10 @@ public class LiveLotteryConfController extends BaseController
     }
 
 //    @PreAuthorize("@ss.hasPermi('live:liveLotteryConf:remove')")
-    @DeleteMapping("/{id}")
-    public void delete(@PathVariable Long id) {
-        liveLotteryConfService.delete(id);
-    }
+//    @DeleteMapping("/{id}")
+//    public void delete(@PathVariable Long id) {
+//        liveLotteryConfService.delete(id);
+//    }
 
     /**
      * 发起抽奖

+ 5 - 0
fs-service-system/src/main/java/com/fs/live/mapper/LiveSensitiveWordsMapper.java

@@ -2,6 +2,8 @@ package com.fs.live.mapper;
 
 
 import com.fs.live.domain.LiveSensitiveWords;
+import org.apache.ibatis.annotations.Param;
+import org.apache.ibatis.annotations.Select;
 
 import java.util.List;
 
@@ -65,4 +67,7 @@ public interface LiveSensitiveWordsMapper {
      * @return
      */
     List<String> selectAllWords();
+
+    @Select("select count(1) from live_sensitive_words where word=#{word}")
+    int selectWordsByName(@Param("word") String word);
 }

+ 3 - 0
fs-service-system/src/main/java/com/fs/live/service/ILiveOrderService.java

@@ -205,4 +205,7 @@ public interface ILiveOrderService {
 
     void orderCancel();
 
+    LiveOrderComputeDTO computedReward(long l, LiveOrderComputedParam param);
+
+    R createRewardLiveOrder(LiveOrder liveOrder);
 }

+ 127 - 0
fs-service-system/src/main/java/com/fs/live/service/impl/LiveOrderServiceImpl.java

@@ -1498,6 +1498,29 @@ public class LiveOrderServiceImpl implements ILiveOrderService {
         }
     }
 
+
+    @Override
+    public LiveOrderComputeDTO computedReward(long l, LiveOrderComputedParam param) {
+        String orderKey= redisCache.getCacheObject("orderKey:"+param.getOrderKey());
+        if (StringUtils.isEmpty(orderKey)) {
+            return null;
+        }
+        FsStoreProduct fsStoreProduct = fsStoreProductService.selectFsStoreProductById(param.getProductId());
+        BigDecimal payPrice = BigDecimal.ZERO;
+        BigDecimal payDelivery = BigDecimal.ZERO;
+        BigDecimal totalPrice = fsStoreProduct.getPrice().multiply(new BigDecimal(param.getTotalNum()));
+        if (param.getCityId() != null) {
+            payDelivery = handleDeliveryMoney(param.getCityId(), fsStoreProduct, param.getTotalNum());
+            totalPrice = totalPrice.add(payDelivery);
+        }
+        return LiveOrderComputeDTO.builder().payPrice(payPrice)
+                .payDelivery(payDelivery)
+                .deductionPrice(totalPrice)
+                .totalPrice(totalPrice)
+                .build();
+    }
+
+
     @Override
     public LiveOrderComputeDTO computedOrder(long userId, LiveOrderComputedParam param) {
         String orderKey= redisCache.getCacheObject("orderKey:"+param.getOrderKey());
@@ -2120,6 +2143,110 @@ public class LiveOrderServiceImpl implements ILiveOrderService {
     }
 
 
+    @Override
+    public R createRewardLiveOrder(LiveOrder liveOrder) {
+        String orderKey= redisCache.getCacheObject("orderKey:"+liveOrder.getOrderKey());
+        if (StringUtils.isEmpty(orderKey)) {
+            return R.error("订单已过期");
+        }
+        if(liveOrder.getLiveId() == null) return R.error("直播ID不能为空");
+        if(liveOrder.getProductId() == null) return R.error("购物商品ID不能为空");
+        if(liveOrder.getUserName() == null) return R.error("用户名不能为空");
+        if(liveOrder.getUserPhone() == null) return R.error("用户手机号不能为空");
+        if(liveOrder.getUserAddress() == null) return R.error("用户地址不能为空");
+        if(liveOrder.getTotalNum() == null) return R.error("商品数量不能为空");
+
+        Live live = liveMapper.selectLiveByLiveId(liveOrder.getLiveId());
+        if(live == null) return R.error("当前直播不存在");
+        FsStoreProduct fsStoreProduct = fsStoreProductService.selectFsStoreProductById(liveOrder.getProductId());
+        LiveGoods goods = liveGoodsMapper.selectLiveGoodsByProductId(liveOrder.getLiveId(), liveOrder.getProductId());
+
+        // 更改店铺库存
+        fsStoreProduct.setStock(fsStoreProduct.getStock()-Integer.parseInt(liveOrder.getTotalNum()));
+        fsStoreProductService.updateFsStoreProduct(fsStoreProduct);
+        // 更新直播间库存
+        goods.setStock(goods.getStock()-Integer.parseInt(liveOrder.getTotalNum()));
+        liveGoodsMapper.updateLiveGoods(goods);
+
+        //判断是否是三种特定产品
+        if (fsStoreProduct.getProductId() != null && (fsStoreProduct.getProductId().equals(3168L)
+                || fsStoreProduct.getProductId().equals(3184L)
+                || fsStoreProduct.getProductId().equals(3185L))) {
+            liveOrder.setStoreHouseCode("YDSP001");
+        } else {
+            liveOrder.setStoreHouseCode("CQDS001");
+        }
+
+        LiveUserFirstEntry liveUserFirstEntry = liveUserFirstEntryService.selectEntityByLiveIdUserId(liveOrder.getLiveId(), Long.parseLong(liveOrder.getUserId()));
+        liveOrder.setCompanyId(liveUserFirstEntry.getCompanyId());
+        liveOrder.setCompanyUserId(liveUserFirstEntry.getCompanyUserId());
+        liveOrder.setTuiUserId(liveUserFirstEntry.getCompanyUserId());
+
+        String orderSn = SnowflakeUtils.nextId();
+        log.info("订单生成:"+orderSn);
+        liveOrder.setOrderCode(orderSn);
+        BigDecimal totalPrice = fsStoreProduct.getPrice().multiply(new BigDecimal(liveOrder.getTotalNum()));
+        // 直播不需要服务费 0915 1735 左
+//        String config=configService.selectConfigByKey("store.config");
+//        StoreConfig storeConfig= JSONUtil.toBean(config,StoreConfig.class);
+//        BigDecimal serviceFee=new BigDecimal(0);
+//        if(storeConfig.getServiceFee()!=null){
+//            if(liveOrder.getCompanyUserId()==null||liveOrder.getCompanyUserId()==0){
+//                serviceFee=storeConfig.getServiceFee();
+//            }
+//        }
+//        payPrice = payPrice.add(serviceFee);
+        // 生成
+        BigDecimal deliveryMoney = handleDeliveryMoney(liveOrder);
+        totalPrice = totalPrice.add(deliveryMoney);
+        liveOrder.setDiscountMoney(totalPrice);
+
+
+        liveOrder.setItemJson(JSON.toJSONString(fsStoreProduct));
+        liveOrder.setCreateTime(new Date());
+        liveOrder.setUpdateTime(new Date());
+        liveOrder.setPayDelivery(deliveryMoney);
+        liveOrder.setProductId(fsStoreProduct.getProductId());
+        liveOrder.setStatus(OrderInfoEnum.STATUS_1.getValue());
+        liveOrder.setPayType("1");
+        liveOrder.setTotalPrice(totalPrice);
+        liveOrder.setPayMoney(BigDecimal.ZERO);
+        try {
+            if (baseMapper.insertLiveOrder(liveOrder) > 0) {
+                LiveOrderItemDTO dto=new LiveOrderItemDTO();
+                dto.setImage(fsStoreProduct.getImage());
+                dto.setSku(String.valueOf(fsStoreProduct.getStock()));
+                if (StringUtils.isEmpty(fsStoreProduct.getBarCode())) {
+                    FsStoreProductAttrValue fsStoreProductAttrValue = fsStoreProductAttrValueMapper.selectFsStoreProductAttrValueByProductId(fsStoreProduct.getProductId()).stream().filter(attrValue -> StringUtils.isNotEmpty(attrValue.getBarCode())).findFirst().orElse(null);
+                    if (fsStoreProductAttrValue != null) {
+                        dto.setBarCode(fsStoreProductAttrValue.getBarCode());
+                    }
+                } else {
+                    dto.setBarCode(fsStoreProduct.getBarCode());
+                }
+                dto.setPrice(fsStoreProduct.getPrice());
+                dto.setProductName(fsStoreProduct.getProductName());
+                dto.setNum(Long.valueOf(liveOrder.getTotalNum()));
+
+                LiveOrderItem liveOrderItem = new LiveOrderItem();
+                liveOrderItem.setOrderCode(liveOrder.getOrderCode());
+                liveOrderItem.setOrderId(liveOrder.getOrderId());
+                liveOrderItem.setProductId(liveOrder.getProductId());
+                liveOrderItem.setNum(Long.valueOf(liveOrder.getTotalNum()));
+                liveOrderItem.setJsonInfo(JSON.toJSONString(dto));
+                liveOrderItemMapper.insertLiveOrderItem(liveOrderItem);
+                redisCache.deleteObject("orderKey:" + liveOrder.getOrderKey());
+                return R.ok("下单成功").put("order",liveOrder);
+            } else {
+                return R.error("订单创建失败");
+            }
+        } catch (Exception e) {
+            // 异常处理
+            return R.error("订单创建失败:" + e.getMessage());
+        }
+    }
+
+
     @Override
     @Transactional(rollbackFor = Throwable.class,propagation = Propagation.REQUIRED)
     public R createLiveOrder(LiveOrder liveOrder) {

+ 2 - 0
fs-service-system/src/main/java/com/fs/live/service/impl/LiveSensitiveWordsServiceImpl.java

@@ -55,6 +55,8 @@ public class LiveSensitiveWordsServiceImpl implements ILiveSensitiveWordsService
     @Override
     public int insertLiveSensitiveWords(LiveSensitiveWords liveSensitiveWords)
     {
+        int count = baseMapper.selectWordsByName(liveSensitiveWords.getWord());
+        if(count > 0) return -1;
         liveSensitiveWords.setCreateTime(new Date());
         return baseMapper.insertLiveSensitiveWords(liveSensitiveWords);
     }

+ 20 - 13
fs-service-system/src/main/java/com/fs/live/service/impl/LiveServiceImpl.java

@@ -723,7 +723,12 @@ public class LiveServiceImpl implements ILiveService
         // 运营自动化
         List<LiveAutoTask> liveAutoTasksList = liveAutoTaskService.selectLiveAutoTaskByLiveId(existLiveId);
         List<LiveAutoTask> barrageTask = liveAutoTasksList.stream().filter(liveAutoTask -> liveAutoTask.getTaskType() == 3L).collect(Collectors.toList());
-        List<LiveAutoTask> goodsTask = liveAutoTasksList.stream().filter(liveAutoTask -> liveAutoTask.getTaskType() == 1L).collect(Collectors.toList());
+        Map<Long, LiveAutoTask> goodsMap = liveAutoTasksList.stream()
+                .filter(liveAutoTask -> liveAutoTask.getTaskType() == 1L)
+                .collect(Collectors.toMap(liveAutoTask -> {
+                            return parseIdFromContent(liveAutoTask.getContent(),"goodsId");
+                        }, liveAutoTask -> liveAutoTask, (existing, replacement) -> replacement
+                ));
         Map<Long, LiveAutoTask> redMap = liveAutoTasksList.stream()
                 .filter(liveAutoTask -> liveAutoTask.getTaskType() == 2L)
                 .collect(Collectors.toMap(liveAutoTask -> {
@@ -736,18 +741,6 @@ public class LiveServiceImpl implements ILiveService
                     return parseIdFromContent(liveAutoTask.getContent(),"lotteryId");
                         }, liveAutoTask -> liveAutoTask, (existing, replacement) -> replacement
                 ));
-        if (!goodsTask.isEmpty()) {
-            LiveAutoTask liveAutoTaskEntity = new LiveAutoTask();
-            for (LiveAutoTask liveAutoTask : goodsTask) {
-                BeanUtils.copyBeanProp(liveAutoTaskEntity, liveAutoTask);
-                liveAutoTaskEntity.setId(null);
-                liveAutoTaskEntity.setLiveId(newLiveId);
-                liveAutoTaskEntity.setCreateTime(now);
-                liveAutoTaskEntity.setUpdateTime(now);
-                liveAutoTaskEntity.setFinishStatus(0L);
-                liveAutoTaskService.copyInsertLiveAutoTask(liveAutoTaskEntity,liveEntity);
-            }
-        }
         if (!barrageTask.isEmpty()) {
             LiveAutoTask liveAutoTaskEntity = new LiveAutoTask();
             for (LiveAutoTask liveAutoTask : barrageTask) {
@@ -831,9 +824,23 @@ public class LiveServiceImpl implements ILiveService
                 liveGoodsEntity.setCompanyId(live.getCompanyId());
                 liveGoodsEntity.setCompanyUserId(live.getCompanyUserId());
                 liveGoodsService.insertLiveGoods(liveGoodsEntity);
+                // 优惠券
                 if (collect.containsKey(liveGoods.getGoodsId())) {
                     liveCouponIssueRelations.stream().filter(relation -> relation.getGoodsId().equals(liveGoods.getGoodsId())).findFirst().ifPresent(liveCouponIssueRelation -> liveCouponIssueRelation.setGoodsId(liveGoodsEntity.getGoodsId()));
                 }
+                // 直播商品task
+                if (goodsMap.containsKey(liveGoods.getGoodsId())) {
+                    LiveAutoTask liveAutoTaskEntity = new LiveAutoTask();
+                    LiveAutoTask liveAutoTask = goodsMap.get(liveGoods.getGoodsId());
+                    BeanUtils.copyBeanProp(liveAutoTaskEntity, liveAutoTask);
+                    liveAutoTaskEntity.setId(null);
+                    liveAutoTaskEntity.setLiveId(newLiveId);
+                    liveAutoTaskEntity.setCreateTime(now);
+                    liveAutoTaskEntity.setUpdateTime(now);
+                    liveAutoTaskEntity.setFinishStatus(0L);
+                    liveAutoTaskEntity.setContent(JSON.toJSONString(liveGoodsEntity));
+                    liveAutoTaskService.copyInsertLiveAutoTask(liveAutoTaskEntity,liveEntity);
+                }
             }
         }
         for (LiveCouponIssueRelation liveCouponIssueRelation : liveCouponIssueRelations) {

+ 25 - 0
fs-user-app/src/main/java/com/fs/app/controller/LiveOrderController.java

@@ -196,6 +196,31 @@ public class LiveOrderController extends AppBaseController
         return R.ok().put("data",dto);
     }
 
+    @Login
+    @ApiOperation("计算中奖订单")
+    @PostMapping("/computedReward")
+    public R computedReward(@Validated @RequestBody LiveOrderComputedParam param){
+        log.info("计算中奖订单 {}",JSON.toJSONString(param));
+
+        LiveOrderComputeDTO dto=liveOrderService.computedReward(Long.parseLong(getUserId()),param);
+        return R.ok().put("data",dto);
+    }
+
+    /**
+     * 新增中奖订单
+     */
+    @Login
+    @Log(title = "新增中奖订单", businessType = BusinessType.INSERT)
+    @PostMapping("/createReward")
+    @RepeatSubmit
+    public R createReward(@RequestBody LiveOrder liveOrder)
+    {
+        log.info("新增中奖订单: {}", JSON.toJSONString(liveOrder));
+
+        liveOrder.setUserId(getUserId());
+        return liveOrderService.createRewardLiveOrder(liveOrder);
+    }
+
     /**
      * 修改订单
      */