|
|
@@ -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) {
|