|
@@ -11,6 +11,7 @@ import java.time.format.DateTimeFormatter;
|
|
|
import java.time.temporal.ChronoUnit;
|
|
|
import java.util.*;
|
|
|
import java.util.concurrent.TimeUnit;
|
|
|
+import java.util.stream.Collectors;
|
|
|
|
|
|
import cn.hutool.core.date.DateTime;
|
|
|
import cn.hutool.core.util.IdUtil;
|
|
@@ -62,7 +63,10 @@ import com.fs.huifuPay.service.HuiFuService;
|
|
|
import com.fs.live.domain.*;
|
|
|
import com.fs.live.mapper.*;
|
|
|
import com.fs.live.param.LiveOrderConfirmParam;
|
|
|
+import com.fs.live.service.ILiveOrderLogsService;
|
|
|
import com.fs.live.vo.LiveGoodsVo;
|
|
|
+import com.fs.live.vo.LiveOrderItemVo;
|
|
|
+import com.fs.live.vo.LiveOrderListVo;
|
|
|
import com.fs.live.vo.LiveOrderVo;
|
|
|
import com.fs.qw.service.IQwExternalContactService;
|
|
|
import com.fs.system.domain.SysConfig;
|
|
@@ -179,6 +183,12 @@ public class LiveOrderServiceImpl extends ServiceImpl<LiveOrderMapper, LiveOrder
|
|
|
@Autowired
|
|
|
private SysConfigMapper sysConfigMapper;
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private ILiveOrderLogsService liveOrderLogsService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private LiveCartMapper liveCartMapper;
|
|
|
+
|
|
|
|
|
|
public LiveOrderServiceImpl(RedisCache redisCache) {
|
|
|
this.redisCache = redisCache;
|
|
@@ -483,7 +493,7 @@ public class LiveOrderServiceImpl extends ServiceImpl<LiveOrderMapper, LiveOrder
|
|
|
paymentMap.setPayTypeCode(PayType.支付宝条码支付.name());
|
|
|
}
|
|
|
liveOrderPaymentMapper.updateLiveOrderPayment(paymentMap);
|
|
|
- order=baseMapper.selectFsUserVipOrderByOrderCode(storePayment.getBusinessId());
|
|
|
+ order=baseMapper.selectFsUserVipOrderByOrderCode(storePayment.getPayCode());
|
|
|
}
|
|
|
}
|
|
|
else{
|
|
@@ -531,13 +541,11 @@ public class LiveOrderServiceImpl extends ServiceImpl<LiveOrderMapper, LiveOrder
|
|
|
this.payConfirm(order.getOrderCode(), "", "", "", 2);
|
|
|
return R.ok().put("isPay", 1);
|
|
|
} else {
|
|
|
- String json = configService.selectConfigByKey("his.pay");
|
|
|
+ // todo yhq 没有走缓存
|
|
|
+ String json = configService.selectConfigByConfigKey("his.pay").getConfigValue();
|
|
|
PayConfigDTO payConfigDTO = JSONUtil.toBean(json, PayConfigDTO.class);
|
|
|
- payConfigDTO.setType("wx");
|
|
|
// todo yhq
|
|
|
String payCode = OrderCodeUtils.getOrderSn();
|
|
|
-// String payCode = String.valueOf(UUID.randomUUID());
|
|
|
- payCode = payCode.substring(0, payCode.lastIndexOf('-'));
|
|
|
if(StringUtils.isEmpty(payCode)){
|
|
|
return R.error("订单生成失败,请重试");
|
|
|
}
|
|
@@ -685,6 +693,109 @@ public class LiveOrderServiceImpl extends ServiceImpl<LiveOrderMapper, LiveOrder
|
|
|
return baseMapper.selectLiveOrderList(liveOrder);
|
|
|
}
|
|
|
|
|
|
+ @Override
|
|
|
+ public List<LiveOrderListVo> selectLiveOrderListVo(LiveOrder liveOrder) {
|
|
|
+ List<LiveOrderListVo> liveOrders = baseMapper.selectLiveOrderListVo(liveOrder.getUserId(),liveOrder.getStatus());
|
|
|
+ if (liveOrders.isEmpty()) {
|
|
|
+ return liveOrders;
|
|
|
+ }
|
|
|
+ List<Long> orderIds = liveOrders.stream().map(LiveOrderListVo::getOrderId).collect(Collectors.toList());
|
|
|
+ List<LiveOrderItemVo> liveOrderItems = liveOrderItemMapper.selectLiveOrderItemByOrderIds(orderIds);
|
|
|
+
|
|
|
+ liveOrders.forEach(item -> {
|
|
|
+ item.setOrderItemList(liveOrderItems.stream().filter(liveOrderItem -> liveOrderItem.getOrderId().equals(item.getOrderId())).collect(Collectors.toList()));
|
|
|
+ });
|
|
|
+ return liveOrders;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ @Transactional
|
|
|
+ public R buy(LiveOrder liveOrder) {
|
|
|
+ String orderKey= redisCache.getCacheObject("orderKey:"+liveOrder.getOrderKey());
|
|
|
+ if (StringUtils.isEmpty(orderKey)) {
|
|
|
+ return R.error("订单已过期");
|
|
|
+ }
|
|
|
+ List<LiveCart> itemList = liveCartMapper.selectCheckedLiveCartByUserId(Long.valueOf(liveOrder.getUserId()));
|
|
|
+ if (itemList == null || itemList.isEmpty()) {
|
|
|
+ return R.error("请选择商品");
|
|
|
+ }
|
|
|
+ List<String> productIds = itemList.stream().map(LiveCart::getProductId).collect(Collectors.toList());
|
|
|
+ List<FsStoreProduct> productList = fsStoreProductService.selectFsStoreProductByProductIds(productIds);
|
|
|
+ if (productList == null || productList.isEmpty()) {
|
|
|
+ return R.error("商品不存在");
|
|
|
+ }
|
|
|
+ BigDecimal totalPrice = new BigDecimal("0");
|
|
|
+ List<LiveOrderItem> liveOrderItemList = new ArrayList<>();
|
|
|
+// String orderSn = OrderCodeUtils.getOrderSn();
|
|
|
+ String orderSn = UUID.randomUUID().toString();
|
|
|
+ log.info("订单生成:"+orderSn);
|
|
|
+ // 检查数据库存
|
|
|
+ for (LiveCart item : itemList) {
|
|
|
+ FsStoreProduct product = productList.stream().filter(p -> {
|
|
|
+ if (item.getProductId() != null) {
|
|
|
+ return p.getProductId() != null && p.getProductId().toString().equals(item.getProductId());
|
|
|
+ }
|
|
|
+ return false;}
|
|
|
+ ).findFirst().orElse(null);
|
|
|
+ if (product == null) {
|
|
|
+ return R.error("商品不存在");
|
|
|
+ }
|
|
|
+ if (product.getStock() < item.getCartNum()) {
|
|
|
+ return R.error("商品库存不足");
|
|
|
+ }
|
|
|
+ if (product.getIsShow() == 0) {
|
|
|
+ return R.error("商品已下架");
|
|
|
+ }
|
|
|
+ product.setStock(product.getStock() - item.getCartNum());
|
|
|
+ totalPrice = totalPrice.add(product.getPrice().multiply(new BigDecimal(item.getCartNum())));
|
|
|
+
|
|
|
+ // 订单商品详情
|
|
|
+ FsStoreOrderItemDTO dto=new FsStoreOrderItemDTO();
|
|
|
+ dto.setImage(product.getImgUrl());
|
|
|
+ dto.setSku(String.valueOf(product.getStoreId()));
|
|
|
+ dto.setBarCode(product.getBarCode());
|
|
|
+ dto.setPrice(product.getPrice());
|
|
|
+ dto.setNum(Long.valueOf(item.getCartNum()));
|
|
|
+
|
|
|
+ LiveOrderItem liveOrderItem = new LiveOrderItem();
|
|
|
+ liveOrderItem.setOrderCode(orderSn);
|
|
|
+ liveOrderItem.setOrderId(liveOrder.getOrderId());
|
|
|
+ liveOrderItem.setCartId(item.getCartId());
|
|
|
+ liveOrderItem.setProductId(product.getProductId());
|
|
|
+ liveOrderItem.setNum(Long.valueOf(item.getCartNum()));
|
|
|
+ liveOrderItem.setJsonInfo(JSON.toJSONString(dto));
|
|
|
+ liveOrderItemList.add(liveOrderItem);
|
|
|
+
|
|
|
+ }
|
|
|
+ productList.forEach(product -> {fsStoreProductService.updateStoreProductStock(product.getProductId(), product.getStock());});
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ liveOrder.setOrderCode(orderSn);
|
|
|
+
|
|
|
+ liveOrder.setCreateTime(new Date());
|
|
|
+ liveOrder.setUpdateTime(new Date());
|
|
|
+ liveOrder.setStatus(FsStoreOrderStatusEnum.STATUS_1.getValue());
|
|
|
+ liveOrder.setPayType("1");
|
|
|
+ liveOrder.setTotalPrice(totalPrice);
|
|
|
+ liveOrder.setPayMoney(liveOrder.getTotalPrice());
|
|
|
+
|
|
|
+
|
|
|
+ if (baseMapper.insertLiveOrder(liveOrder) > 0) {
|
|
|
+ for (LiveOrderItem liveOrderItem : liveOrderItemList) {
|
|
|
+ liveOrderItem.setOrderId(liveOrder.getOrderId());
|
|
|
+ }
|
|
|
+ liveOrderItemMapper.insertBatchList(liveOrderItemList);
|
|
|
+ // list Long 转为Long数组
|
|
|
+
|
|
|
+ liveCartMapper.deleteLiveCartByCartIds(liveOrderItemList.stream().map(LiveOrderItem::getCartId).toArray(Long[]::new));
|
|
|
+ return R.ok("下单成功").put("order",liveOrder);
|
|
|
+ } else {
|
|
|
+ return R.error("订单创建失败");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* 新增订单
|
|
|
*
|
|
@@ -910,6 +1021,8 @@ public class LiveOrderServiceImpl extends ServiceImpl<LiveOrderMapper, LiveOrder
|
|
|
return liveGoodsMapper.selectProductListByOrder(liveOrder);
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+
|
|
|
@Override
|
|
|
@Transactional
|
|
|
public R createLiveOrder(LiveOrder liveOrder) {
|
|
@@ -934,12 +1047,19 @@ public class LiveOrderServiceImpl extends ServiceImpl<LiveOrderMapper, LiveOrder
|
|
|
LiveGoods goods = liveGoodsMapper.selectLiveGoodsByProductId(liveOrder.getLiveId(), liveOrder.getProductId());
|
|
|
if(fsStoreProduct == null || goods == null) return R.error("商品不存在");
|
|
|
if(fsStoreProduct.getIsShow() == 0 || goods.getStatus() == 0) return R.error("商品已下架");
|
|
|
+ if(fsStoreProduct.getStock() < Integer.parseInt(liveOrder.getTotalNum())) return R.error("库存不足");
|
|
|
+
|
|
|
+ // 更改库存
|
|
|
+ fsStoreProduct.setStock(fsStoreProduct.getStock()-Integer.parseInt(liveOrder.getTotalNum()));
|
|
|
+ fsStoreProductService.updateFsStoreProduct(fsStoreProduct);
|
|
|
|
|
|
// liveOrderItemMapper
|
|
|
|
|
|
|
|
|
//todo yhq
|
|
|
- liveOrder.setOrderCode(OrderCodeUtils.getOrderSn());
|
|
|
+ String orderSn = OrderCodeUtils.getOrderSn();
|
|
|
+ log.info("订单生成:"+orderSn);
|
|
|
+ liveOrder.setOrderCode(orderSn);
|
|
|
|
|
|
// liveOrder.setOrderCode(String.valueOf(UUID.randomUUID()));
|
|
|
liveOrder.setCreateTime(new Date());
|
|
@@ -987,6 +1107,20 @@ public class LiveOrderServiceImpl extends ServiceImpl<LiveOrderMapper, LiveOrder
|
|
|
}
|
|
|
|
|
|
|
|
|
+ @Override
|
|
|
+ public R cancelOrder(LiveOrder order) {
|
|
|
+ if(order.getStatus() == FsStoreOrderStatusEnum.STATUS_1.getValue()){
|
|
|
+ baseMapper.cancelOrder(order.getOrderId());
|
|
|
+ liveOrderLogsService.create(order.getOrderId(), FsStoreOrderLogEnum.CANCEL_ORDER.getValue(),
|
|
|
+ FsStoreOrderLogEnum.CANCEL_ORDER.getDesc());
|
|
|
+ return R.ok("操作成功");
|
|
|
+ }else {
|
|
|
+ return R.error("非法操作");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
|
|
|
/**
|
|
|
* 订单操作记录
|