Quellcode durchsuchen

1、调整直播抽奖调整

yys vor 3 Wochen
Ursprung
Commit
51b364078f

+ 8 - 8
fs-service/src/main/java/com/fs/core/utils/OrderCodeUtils.java

@@ -46,14 +46,14 @@ public class OrderCodeUtils {
     public static String getOrderSn(){
         String url= FSConfig.getCommonApi()+ "/app/common/genOrderCode";
 //        String url= "42.194.245.189:8010/app/common/genOrderCode";
-        String json = HttpRequest.get(url)
-                .execute().body();
-        OrderCodeVO vo= JSONUtil.toBean(json, OrderCodeVO.class);
-        if(vo.getCode()==200){
-            return vo.getOrderCode();
-        }
-        else return null;
-//        return OrderCodeUtils.genOrderSn();
+//        String json = HttpRequest.get(url)
+//                .execute().body();
+//        OrderCodeVO vo= JSONUtil.toBean(json, OrderCodeVO.class);
+//        if(vo.getCode()==200){
+//            return vo.getOrderCode();
+//        }
+//        else return null;
+        return OrderCodeUtils.genOrderSn();
 
     }
 

+ 3 - 3
fs-service/src/main/java/com/fs/hisStore/mapper/FsStoreProductScrmMapper.java

@@ -255,9 +255,9 @@ public interface FsStoreProductScrmMapper
     @Update("update fs_store_product_scrm set stock=stock-#{num}, sales=sales+#{num}" +
             " where product_id=#{productId} and stock >= #{num}")
     int decProductAttrStock(@Param("productId")Long productId, @Param("num")Integer cartNum);
-    @Update("update fs_store_product_scrm set stock=stock+#{num}, sales=sales-#{num}" +
-            " where product_id=#{productId}")
-    int incStockDecSales( @Param("num")Long num, @Param("productId")Long productId);
+    @Update("update fs_store_product_scrm set stock = stock + #{num}, sales = sales - #{num} " +
+            "where product_id = #{productId} and sales >= #{num}")
+    int incStockDecSales(@Param("num") Long num, @Param("productId") Long productId);
 
     List<FsStoreProductListQueryVO> selectFsStoreProductNewQuery(Map<String, Object> params);
 

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

@@ -2252,24 +2252,24 @@ public class LiveOrderServiceImpl implements ILiveOrderService {
 
     @Override
     public R createRewardLiveOrder(LiveOrder liveOrder) {
-        String orderKey= redisCache.getCacheObject("orderKey:"+liveOrder.getOrderKey());
+        String orderKey = redisCache.getCacheObject("orderKey:" + liveOrder.getOrderKey());
         if (StringUtils.isEmpty(orderKey)) {
             return R.error("订单已过期");
         }
         LiveUserLotteryRecord liveUserLotteryRecord = liveUserLotteryRecordMapper.selectLiveUserLotteryRecordById(liveOrder.getRecordId());
-        if(liveUserLotteryRecord == null) 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("商品数量不能为空");
+        if (liveUserLotteryRecord == null) 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("当前直播不存在");
+        if (live == null) return R.error("当前直播不存在");
         FsStoreProductScrm fsStoreProduct = fsStoreProductService.selectFsStoreProductById(liveOrder.getProductId());
         LiveGoods goods = liveGoodsMapper.selectLiveGoodsByProductId(liveOrder.getLiveId(), liveOrder.getProductId());
-        if(goods == null) return R.error("当前商品不存在");
+        if (goods == null) return R.error("当前商品不存在");
         FsStoreProductAttrValueScrm attrValue = null;
         if (!Objects.isNull(liveOrder.getAttrValueId())) {
             attrValue = fsStoreProductAttrValueMapper.selectFsStoreProductAttrValueById(liveOrder.getAttrValueId());
@@ -2281,12 +2281,12 @@ public class LiveOrderServiceImpl implements ILiveOrderService {
         }
 
         // 更改店铺库存
-        fsStoreProduct.setStock(fsStoreProduct.getStock()-Integer.parseInt(liveOrder.getTotalNum()));
-        fsStoreProduct.setSales(fsStoreProduct.getSales()+Integer.parseInt(liveOrder.getTotalNum()));
-        fsStoreProductScrmMapper.incStockDecSales(Long.valueOf("-" + liveOrder.getTotalNum()),fsStoreProduct.getProductId());
+        fsStoreProduct.setStock(fsStoreProduct.getStock() - Integer.parseInt(liveOrder.getTotalNum()));
+        fsStoreProduct.setSales(fsStoreProduct.getSales() + Integer.parseInt(liveOrder.getTotalNum()));
+        fsStoreProductScrmMapper.incStockDecSales(Long.valueOf(liveOrder.getTotalNum()), fsStoreProduct.getProductId());
         // 更新直播间库存
-        goods.setStock(goods.getStock()-Integer.parseInt(liveOrder.getTotalNum()));
-        goods.setSales(goods.getSales()+Integer.parseInt(liveOrder.getTotalNum()));
+        goods.setStock(goods.getStock() - Integer.parseInt(liveOrder.getTotalNum()));
+        goods.setSales(goods.getSales() + Integer.parseInt(liveOrder.getTotalNum()));
         liveGoodsMapper.updateLiveGoods(goods);
 
         //判断是否是三种特定产品
@@ -2303,8 +2303,8 @@ public class LiveOrderServiceImpl implements ILiveOrderService {
         liveOrder.setCompanyUserId(liveUserFirstEntry.getCompanyUserId());
         liveOrder.setTuiUserId(liveUserFirstEntry.getCompanyUserId());
 
-        String orderSn = OrderCodeUtils.getOrderSn();
-        log.info("订单生成:"+orderSn);
+        String orderSn = SnowflakeUtil.nextIdStr();
+        log.info("订单生成:" + orderSn);
         liveOrder.setOrderCode(orderSn);
         BigDecimal totalPrice = fsStoreProduct.getPrice().multiply(new BigDecimal(liveOrder.getTotalNum()));
         // 直播不需要服务费 0915 1735 左
@@ -2341,7 +2341,7 @@ public class LiveOrderServiceImpl implements ILiveOrderService {
                 liveUserLotteryRecord.setOrderId(liveOrder.getOrderId());
                 liveUserLotteryRecord.setOrderStatus(liveOrder.getStatus());
                 liveUserLotteryRecordMapper.updateLiveUserLotteryRecord(liveUserLotteryRecord);
-                LiveOrderItemDTO dto=new LiveOrderItemDTO();
+                LiveOrderItemDTO dto = new LiveOrderItemDTO();
                 dto.setImage(fsStoreProduct.getImage());
                 dto.setSku(String.valueOf(fsStoreProduct.getStock()));
                 if (StringUtils.isEmpty(fsStoreProduct.getBarCode())) {
@@ -2364,7 +2364,7 @@ public class LiveOrderServiceImpl implements ILiveOrderService {
                 liveOrderItem.setJsonInfo(JSON.toJSONString(dto));
                 liveOrderItemMapper.insertLiveOrderItem(liveOrderItem);
                 redisCache.deleteObject("orderKey:" + liveOrder.getOrderKey());
-                return R.ok("下单成功").put("order",liveOrder);
+                return R.ok("下单成功").put("order", liveOrder);
             } else {
                 return R.error("订单创建失败");
             }

+ 5 - 2
fs-user-app/src/main/java/com/fs/app/controller/live/LiveOrderController.java

@@ -272,8 +272,11 @@ public class LiveOrderController extends AppBaseController
     @Log(title = "新增中奖订单", businessType = BusinessType.INSERT)
     @PostMapping("/createReward")
     @RepeatSubmit
-    public R createReward(@RequestBody LiveOrder liveOrder)
-    {
+    public R createReward(@RequestBody LiveOrder liveOrder,
+                          @RequestHeader(value = "AppId", required = false) String AppId){
+        if (AppId != null && !AppId.isEmpty()) {
+            liveOrder.setAppId(AppId);
+        }
         // 校验appId
         if (StringUtils.isEmpty(liveOrder.getAppId())) {
             return R.error("appId不能为空");