|
@@ -6,6 +6,7 @@ import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
|
|
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
|
|
|
import com.qs.mp.admin.domain.Goods;
|
|
|
+import com.qs.mp.admin.domain.GoodsSku;
|
|
|
import com.qs.mp.admin.service.IGoodsService;
|
|
|
import com.qs.mp.admin.service.IGoodsSkuService;
|
|
|
import com.qs.mp.channel.domain.ChannelGoods;
|
|
@@ -36,6 +37,7 @@ import org.springframework.util.Assert;
|
|
|
import java.util.ArrayList;
|
|
|
import java.util.Date;
|
|
|
import java.util.List;
|
|
|
+import java.util.Objects;
|
|
|
|
|
|
/**
|
|
|
* @auther quanshu
|
|
@@ -74,16 +76,16 @@ public class ChannelGoodsOrderServiceImpl extends ServiceImpl<ChannelGoodsOrderM
|
|
|
String orderId = bizIdGenerator.newId();
|
|
|
Goods goods = goodsService.getById(orderSettleVO.getGoodsId());
|
|
|
|
|
|
- if (goods.getQuantity() < orderSettleVO.getOrderNum()) {
|
|
|
- throw new ServiceException(goods.getTitle() + "库存不足,请重新下单");
|
|
|
- }
|
|
|
- // 更新库存
|
|
|
- boolean updateGoods = goodsService.update(new LambdaUpdateWrapper<Goods>()
|
|
|
- .set(goods.getQuantity() - orderSettleVO.getOrderNum() == 0, Goods::getStatus,
|
|
|
- GoodsStatusEnum.PUT_OFF)
|
|
|
- .set(Goods::getQuantity, goods.getQuantity() - orderSettleVO.getOrderNum())
|
|
|
- .eq(Goods::getGoodsId, goods.getGoodsId()).eq(Goods::getQuantity, goods.getQuantity()));
|
|
|
- Assert.isTrue(updateGoods, "门店购买采购商品更新GOODS库存失败。goodsId:" + goods.getGoodsId());
|
|
|
+// if (goods.getQuantity() < orderSettleVO.getOrderNum()) {
|
|
|
+// throw new ServiceException(goods.getTitle() + "库存不足,请重新下单");
|
|
|
+// }
|
|
|
+// // 更新库存
|
|
|
+// boolean updateGoods = goodsService.update(new LambdaUpdateWrapper<Goods>()
|
|
|
+// .set(goods.getQuantity() - orderSettleVO.getOrderNum() == 0, Goods::getStatus,
|
|
|
+// GoodsStatusEnum.PUT_OFF)
|
|
|
+// .set(Goods::getQuantity, goods.getQuantity() - orderSettleVO.getOrderNum())
|
|
|
+// .eq(Goods::getGoodsId, goods.getGoodsId()).eq(Goods::getQuantity, goods.getQuantity()));
|
|
|
+// Assert.isTrue(updateGoods, "门店购买采购商品更新GOODS库存失败。goodsId:" + goods.getGoodsId());
|
|
|
|
|
|
// 创建订单
|
|
|
ChannelGoodsOrder channelGoodsOrder = new ChannelGoodsOrder();
|
|
@@ -109,16 +111,49 @@ public class ChannelGoodsOrderServiceImpl extends ServiceImpl<ChannelGoodsOrderM
|
|
|
channelGoodsOrderService.save(channelGoodsOrder);
|
|
|
|
|
|
// 创建订单明细
|
|
|
- ChannelGoodsOrderItem item = new ChannelGoodsOrderItem();
|
|
|
- item.setChannelId(channelId);
|
|
|
- item.setOrderId(orderId);
|
|
|
- item.setGoodsId(goods.getGoodsId());
|
|
|
-
|
|
|
- item.setTitle(goods.getTitle());
|
|
|
- item.setGoodsNum(orderSettleVO.getOrderNum());
|
|
|
- item.setPicUrl(goods.getPicUrl());
|
|
|
- item.setSupplierId(goods.getSupplierId());
|
|
|
- channelGoodsOrderItemService.save(item);
|
|
|
+ for (ChannelGoods channelGoods : orderSettleVO.getItems()) {
|
|
|
+ ChannelGoodsOrderItem item = new ChannelGoodsOrderItem();
|
|
|
+ item.setChannelId(channelId);
|
|
|
+ item.setOrderId(orderId);
|
|
|
+ item.setGoodsId(goods.getGoodsId());
|
|
|
+ item.setSkuId(channelGoods.getSkuId());
|
|
|
+ item.setProperties(channelGoods.getProperties());
|
|
|
+ item.setTitle(goods.getTitle());
|
|
|
+ item.setGoodsNum(channelGoods.getQuantity());
|
|
|
+ item.setPicUrl(goods.getPicUrl());
|
|
|
+ item.setSupplierId(goods.getSupplierId());
|
|
|
+ channelGoodsOrderItemService.save(item);
|
|
|
+
|
|
|
+ if (Objects.nonNull(channelGoods.getSkuId()) && channelGoods.getSkuId() != 0) {
|
|
|
+ GoodsSku goodsSku = goodsSkuService.getById(channelGoods.getSkuId());
|
|
|
+ if (goodsSku.getQuantity() < channelGoods.getQuantity()) {
|
|
|
+ throw new ServiceException(channelGoods.getTitle() + "库存不足,请重新下单");
|
|
|
+ }
|
|
|
+
|
|
|
+ // 更新库存
|
|
|
+ boolean updateSku = goodsSkuService.update(new LambdaUpdateWrapper<GoodsSku>()
|
|
|
+ .set(GoodsSku::getQuantity, goodsSku.getQuantity() - channelGoods.getQuantity())
|
|
|
+ .set(GoodsSku::getSoldQty, goodsSku.getSoldQty() + channelGoods.getQuantity())
|
|
|
+ .eq(GoodsSku::getSkuId, goodsSku.getSkuId())
|
|
|
+ .eq(GoodsSku::getQuantity, goodsSku.getQuantity())
|
|
|
+ .eq(GoodsSku::getSoldQty, goodsSku.getSoldQty()));
|
|
|
+ Assert.isTrue(updateSku,
|
|
|
+ "门店购买采购商品更新SKU库存失败。goodsId:" + goodsSku.getGoodsId() + ",skuId:" + goodsSku.getSkuId());
|
|
|
+
|
|
|
+ } else {
|
|
|
+ if (goods.getQuantity() < channelGoods.getQuantity()) {
|
|
|
+ throw new ServiceException(channelGoods.getTitle() + "库存不足,请重新下单");
|
|
|
+ }
|
|
|
+ // 更新库存
|
|
|
+ boolean updateGoods = goodsService.update(new LambdaUpdateWrapper<Goods>()
|
|
|
+ .set(goods.getQuantity() - channelGoods.getQuantity() == 0, Goods::getStatus,
|
|
|
+ GoodsStatusEnum.PUT_OFF)
|
|
|
+ .set(Goods::getQuantity, goods.getQuantity() - channelGoods.getQuantity())
|
|
|
+ .eq(Goods::getGoodsId, goods.getGoodsId())
|
|
|
+ .eq(Goods::getQuantity, goods.getQuantity()));
|
|
|
+ Assert.isTrue(updateGoods, "门店购买采购商品更新GOODS库存失败。goodsId:" + goods.getGoodsId());
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
|
|
|
return channelGoodsOrder.getOrderId();
|
|
@@ -194,6 +229,8 @@ public class ChannelGoodsOrderServiceImpl extends ServiceImpl<ChannelGoodsOrderM
|
|
|
channelGoods.setChannelId(item.getChannelId());
|
|
|
channelGoods.setGoodsId(item.getGoodsId());
|
|
|
channelGoods.setOrderId(item.getOrderId());
|
|
|
+ channelGoods.setSkuId(item.getSkuId());
|
|
|
+ channelGoods.setProperties(item.getProperties());
|
|
|
channelGoods.setTitle(item.getTitle());
|
|
|
channelGoods.setPicUrl(item.getPicUrl());
|
|
|
channelGoods.setStatus(ChannelGoodsSettleStatusTypeEnum.NO);
|
|
@@ -231,6 +268,8 @@ public class ChannelGoodsOrderServiceImpl extends ServiceImpl<ChannelGoodsOrderM
|
|
|
channelGoods.setChannelId(item.getChannelId());
|
|
|
channelGoods.setGoodsId(item.getGoodsId());
|
|
|
channelGoods.setOrderId(item.getOrderId());
|
|
|
+ channelGoods.setSkuId(item.getSkuId());
|
|
|
+ channelGoods.setProperties(item.getProperties());
|
|
|
channelGoods.setTitle(item.getTitle());
|
|
|
channelGoods.setPicUrl(item.getPicUrl());
|
|
|
channelGoods.setStatus(ChannelGoodsSettleStatusTypeEnum.NO);
|