|
|
@ -16,8 +16,10 @@ import com.qs.serve.modules.goods.service.GoodsSkuService; |
|
|
|
import com.qs.serve.modules.goods.service.GoodsSpuService; |
|
|
|
import com.qs.serve.modules.oms.entity.OmsOrderItem; |
|
|
|
import com.qs.serve.modules.oms.entity.OmsShoppingCart; |
|
|
|
import com.qs.serve.modules.oms.entity.bo.CreateOrderParam; |
|
|
|
import com.qs.serve.modules.oms.entity.bo.OmsOrderBo; |
|
|
|
import com.qs.serve.modules.oms.entity.bo.OmsOrderBo.*; |
|
|
|
import com.qs.serve.modules.oms.entity.bo.OmsOrderPcBo; |
|
|
|
import com.qs.serve.modules.oms.entity.dto.OmsCalcAmount; |
|
|
|
import com.qs.serve.modules.oms.entity.dto.ShoppingCartsCheckResult; |
|
|
|
import com.qs.serve.modules.oms.entity.vo.OmsConfirmOrderResult; |
|
|
@ -27,6 +29,7 @@ import com.qs.serve.modules.sys.entity.SysUser; |
|
|
|
import com.qs.serve.modules.sys.service.SysUserService; |
|
|
|
import lombok.AllArgsConstructor; |
|
|
|
import lombok.extern.slf4j.Slf4j; |
|
|
|
import org.jetbrains.annotations.NotNull; |
|
|
|
import org.springframework.stereotype.Service; |
|
|
|
import com.qs.serve.modules.oms.entity.OmsOrder; |
|
|
|
import com.qs.serve.modules.oms.service.OmsOrderService; |
|
|
@ -105,11 +108,80 @@ public class OmsOrderServiceImpl extends ServiceImpl<OmsOrderMapper,OmsOrder> im |
|
|
|
return confirmOrderResult; |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public OmsConfirmOrderResult confirmOrderPc(OmsOrderPcBo confirmOrder) { |
|
|
|
BmsSupplier supplier = AuthContextUtils.getCurrentSupplier(); |
|
|
|
String supplierCode = supplier.getSupplierCode(); |
|
|
|
//构建Sku
|
|
|
|
List<Long> skuIds = confirmOrder.getSkuParamList().stream() |
|
|
|
.map(OmsOrderPcBo.SkuParam::getSkuId).collect(Collectors.toList()); |
|
|
|
List<GoodsSku> skuList = goodsSkuService.listByIds(skuIds); |
|
|
|
if(StringUtils.hasText(supplierCode)){ |
|
|
|
goodsSkuService.initSkuCusPrice(supplierCode,skuList); |
|
|
|
} |
|
|
|
//关联库存到SKU
|
|
|
|
for (OmsOrderPcBo.SkuParam skuParam : confirmOrder.getSkuParamList()) { |
|
|
|
for (GoodsSku sku : skuList) { |
|
|
|
if(sku.getId().equals(skuParam.getSkuId())){ |
|
|
|
sku.setQty(skuParam.getQty()); |
|
|
|
break; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
//构建临时购物车列表
|
|
|
|
List<OmsShoppingCart> shoppingCartList = new ArrayList<>(); |
|
|
|
for (GoodsSku goodsSku : skuList) { |
|
|
|
GoodsSpu goodsSpu = goodsSpuService.getById(goodsSku.getSpuId()); |
|
|
|
OmsShoppingCart shoppingCart = new OmsShoppingCart(); |
|
|
|
shoppingCart.setSpuId(goodsSku.getSpuId()); |
|
|
|
shoppingCart.setSkuId(goodsSku.getId()); |
|
|
|
shoppingCart.setSpuCode(goodsSpu.getSpuCode()); |
|
|
|
shoppingCart.setSkuCode(goodsSku.getSkuCode()); |
|
|
|
shoppingCart.setQuantity(goodsSku.getQty()); |
|
|
|
shoppingCart.setSpecInfo(goodsSku.getSpecInfos()); |
|
|
|
shoppingCart.setPicUrl(goodsSku.getPicUrl()); |
|
|
|
shoppingCartList.add(shoppingCart); |
|
|
|
} |
|
|
|
|
|
|
|
//计算合计
|
|
|
|
OmsCalcAmount calcAmount = new OmsCalcAmount(); |
|
|
|
BigDecimal totalAmount = BigDecimal.ZERO; |
|
|
|
for (GoodsSku sku : skuList) { |
|
|
|
BigDecimal salePrice = sku.getSalesPrice(); |
|
|
|
BigDecimal itemPrice = new BigDecimal(sku.getQty()).multiply(salePrice); |
|
|
|
totalAmount.add(itemPrice); |
|
|
|
} |
|
|
|
calcAmount.setTotalAmount(totalAmount); |
|
|
|
|
|
|
|
//todo 计算供应商折扣
|
|
|
|
//todo 计算是否有活动优惠
|
|
|
|
BmsSupplierAddress supplierAddress = bmsSupplierAddressService.getDefault(Long.parseLong(supplier.getId())); |
|
|
|
OmsConfirmOrderResult confirmOrderResult = new OmsConfirmOrderResult(); |
|
|
|
confirmOrderResult.setSupplier(supplier); |
|
|
|
confirmOrderResult.setDefaultAddress(supplierAddress); |
|
|
|
confirmOrderResult.setAmountInfo(calcAmount); |
|
|
|
confirmOrderResult.setShoppingCarts(shoppingCartList); |
|
|
|
return confirmOrderResult; |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
@Transactional(rollbackFor = Exception.class) |
|
|
|
public OmsOrder createOrder(OmsOrderBo omsOrderBo) { |
|
|
|
OmsConfirmOrderResult confirmOrder = this.confirmOrder(omsOrderBo); |
|
|
|
CreateOrderParam createOrderParam = omsOrderBo.getCreateOrderParam(); |
|
|
|
return this.buildOmsOrder(confirmOrder, createOrderParam); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
public OmsOrder createOrderPc(OmsOrderPcBo omsOrderBo) { |
|
|
|
OmsConfirmOrderResult confirmOrder = this.confirmOrderPc(omsOrderBo); |
|
|
|
CreateOrderParam createOrderParam = omsOrderBo.getCreateOrderParam(); |
|
|
|
return this.buildOmsOrder(confirmOrder, createOrderParam); |
|
|
|
} |
|
|
|
|
|
|
|
@NotNull |
|
|
|
private OmsOrder buildOmsOrder(OmsConfirmOrderResult confirmOrder, CreateOrderParam createOrderParam) { |
|
|
|
SysUser user = sysUserService.getById(AuthContextUtils.getSysUserId()); |
|
|
|
BmsSupplier supplier = confirmOrder.getSupplier(); |
|
|
|
BmsSupplierAddress address = confirmOrder.getDefaultAddress(); |
|
|
@ -127,7 +199,7 @@ public class OmsOrderServiceImpl extends ServiceImpl<OmsOrderMapper,OmsOrder> im |
|
|
|
order.setUserName(user.getName()); |
|
|
|
order.setUserCode(user.getCode()); |
|
|
|
order.setUserPhone(user.getMobile()); |
|
|
|
if(createOrderParam!=null){ |
|
|
|
if(createOrderParam !=null){ |
|
|
|
order.setBillType(createOrderParam.getBillType()); |
|
|
|
order.setUrgentFlag(createOrderParam.getUrgentFlag()); |
|
|
|
} |
|
|
|