|
|
@ -46,6 +46,7 @@ import com.qs.serve.modules.oms.mapper.OmsOrderMapper; |
|
|
|
import org.springframework.transaction.annotation.Transactional; |
|
|
|
|
|
|
|
import java.math.BigDecimal; |
|
|
|
import java.time.LocalDate; |
|
|
|
import java.time.LocalDateTime; |
|
|
|
import java.util.*; |
|
|
|
import java.util.stream.Collectors; |
|
|
@ -82,6 +83,7 @@ public class OmsOrderServiceImpl extends ServiceImpl<OmsOrderMapper,OmsOrder> im |
|
|
|
private SeeYonRequestBaseService seeYonRequestBaseService; |
|
|
|
private GoodsRuleService goodsRuleService; |
|
|
|
private GoodsAccreditService goodsAccreditService; |
|
|
|
private GoodsImminentBatchService goodsImminentBatchService; |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
@ -333,35 +335,11 @@ public class OmsOrderServiceImpl extends ServiceImpl<OmsOrderMapper,OmsOrder> im |
|
|
|
//防止空指针
|
|
|
|
skuCodes.add("NULL"); |
|
|
|
|
|
|
|
List<GoodsCustomerPrice> customerPrices = goodsCustomerPriceService.getBySupplierCodeAndCode(supplier.getCode(),skuCodes); |
|
|
|
for (OmsOrderItem orderItem : newOrderItemList) { |
|
|
|
for (GoodsCustomerPrice customerPrice : customerPrices) { |
|
|
|
if(orderItem.getSkuCode().equals(customerPrice.getSkuCode())){ |
|
|
|
orderItem.setSalesPrice(customerPrice.getRealPrice()); |
|
|
|
break; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
//商品特殊价
|
|
|
|
this.buildSkuSpecPrice(supplier, newOrderItemList, skuCodes); |
|
|
|
|
|
|
|
//拦截商品授权维度规则
|
|
|
|
GoodsAccrIdsDto accrIdsDto = goodsAccreditService.listIgnoreAcc2(supplier.getId(),supplier.listBizRegionIds(),supplier.listSaleRegionIds()); |
|
|
|
if(accrIdsDto!=null){ |
|
|
|
List<Long> skuIds = goodsSkuMapper.listByOtherIds( |
|
|
|
accrIdsDto.getCateIds(), |
|
|
|
accrIdsDto.getSpuIds(), |
|
|
|
accrIdsDto.getSkuIds(), |
|
|
|
accrIdsDto.getNotInCateIds(), |
|
|
|
accrIdsDto.getNotInSpuIds(), |
|
|
|
accrIdsDto.getNotInSkuIds() |
|
|
|
); |
|
|
|
for (OmsOrderItem orderItem : newOrderItemList) { |
|
|
|
for (Long skuId : skuIds) { |
|
|
|
if(orderItem.getSkuId().equals(skuId)){ |
|
|
|
Assert.throwEx("商品未授权:"+orderItem.getSkuCode()); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
this.checkGoodsRule(supplier, newOrderItemList); |
|
|
|
|
|
|
|
//拦截客户维度规则
|
|
|
|
goodsRuleService.checkSkuCode(skuCodes,goodsRuleService.listBySupplierId(order.getSupplierId().toString()),true); |
|
|
@ -382,6 +360,27 @@ public class OmsOrderServiceImpl extends ServiceImpl<OmsOrderMapper,OmsOrder> im |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
private void checkGoodsRule(BmsSupplier supplier, List<OmsOrderItem> newOrderItemList) { |
|
|
|
GoodsAccrIdsDto accrIdsDto = goodsAccreditService.listIgnoreAcc2(supplier.getId(), supplier.listBizRegionIds(), supplier.listSaleRegionIds()); |
|
|
|
if(accrIdsDto!=null){ |
|
|
|
List<Long> skuIds = goodsSkuMapper.listByOtherIds( |
|
|
|
accrIdsDto.getCateIds(), |
|
|
|
accrIdsDto.getSpuIds(), |
|
|
|
accrIdsDto.getSkuIds(), |
|
|
|
accrIdsDto.getNotInCateIds(), |
|
|
|
accrIdsDto.getNotInSpuIds(), |
|
|
|
accrIdsDto.getNotInSkuIds() |
|
|
|
); |
|
|
|
for (OmsOrderItem orderItem : newOrderItemList) { |
|
|
|
for (Long skuId : skuIds) { |
|
|
|
if(orderItem.getSkuId().equals(skuId)){ |
|
|
|
Assert.throwEx("商品未授权:"+orderItem.getSkuCode()); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* 拦截规则 |
|
|
|
* @param categoryRule |
|
|
@ -640,6 +639,154 @@ public class OmsOrderServiceImpl extends ServiceImpl<OmsOrderMapper,OmsOrder> im |
|
|
|
return spuAssesInfoList; |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public String modifyImminentOrder(OmsOrderImminentBo param) { |
|
|
|
|
|
|
|
SysUser user = sysUserService.getById(AuthContextUtils.getSysUserId()); |
|
|
|
GoodsCategoryRule categoryRule = goodsCategoryRuleMapper.selectById(param.getBrandRuleId()); |
|
|
|
BmsSupplier supplier = bmsSupplierMapper.selectById(param.getSupplierId()); |
|
|
|
BmsSupplierAddress supplierDefaultAddress = bmsSupplierAddressService.getDefault(Long.parseLong(supplier.getId())); |
|
|
|
|
|
|
|
OmsOrder order; |
|
|
|
if(param.getId()!=null){ |
|
|
|
order = this.getById(param.getId()); |
|
|
|
}else { |
|
|
|
order = new OmsOrder(); |
|
|
|
order.setOrderSn("SP"+CodeGenUtil.generate(CodeGenUtil.SourceKey.OmsOrder)); |
|
|
|
} |
|
|
|
order.setLatitudeFrom("sp"); |
|
|
|
order.setCdOrderRemark(param.getCdOrderRemark()); |
|
|
|
order.setOrderType(1); |
|
|
|
order.setSupplierId(Long.parseLong(supplier.getId())); |
|
|
|
order.setSupplierCode(supplier.getCode()); |
|
|
|
order.setSupplierName(supplier.getName()); |
|
|
|
order.setSupplierAddrId(supplierDefaultAddress!=null?supplierDefaultAddress.getId():0); |
|
|
|
order.setBrandRuleId(param.getBrandRuleId()); |
|
|
|
order.setUserId(user.getId()); |
|
|
|
order.setUserName(user.getName()); |
|
|
|
order.setUserCode(user.getCode()); |
|
|
|
order.setUserPhone(user.getMobile()); |
|
|
|
order.setBillType(param.getBillType()); |
|
|
|
order.setUrgentFlag(param.getUrgentFlag()); |
|
|
|
order.setRemark(param.getRemark()); |
|
|
|
this.save(order); |
|
|
|
|
|
|
|
Set<Long> batchSkuIds = param.getItemList().stream().map(OmsOrderImminentBo.ItemParam::getBatchSkuId) |
|
|
|
.collect(Collectors.toSet()); |
|
|
|
if(CollectionUtil.isEmpty(param.getItemList())){ |
|
|
|
Assert.throwEx("请选择商品"); |
|
|
|
} |
|
|
|
List<GoodsImminentBatch> imminentBatches = goodsImminentBatchService |
|
|
|
.list( |
|
|
|
new LambdaQueryWrapper<GoodsImminentBatch>() |
|
|
|
.in(GoodsImminentBatch::getId,batchSkuIds) |
|
|
|
.ge(GoodsImminentBatch::getEndDate, LocalDate.now()) |
|
|
|
); |
|
|
|
if(CollectionUtil.isEmpty(imminentBatches)){ |
|
|
|
Assert.throwEx("参数过期或无效,请重新选择商品"); |
|
|
|
} |
|
|
|
|
|
|
|
Set<String> skuIds = imminentBatches.stream() |
|
|
|
.map(GoodsImminentBatch::getSkuId).collect(Collectors.toSet()); |
|
|
|
if(skuIds.size()!=imminentBatches.size()){ |
|
|
|
Assert.throwEx("不同批次相同产品,请分开下单"); |
|
|
|
} |
|
|
|
|
|
|
|
List<GoodsSku> goodsSkuList = goodsSkuService.listByIds(skuIds); |
|
|
|
|
|
|
|
List<Long> spuIds = goodsSkuList.stream().map(GoodsSku::getSpuId).collect(Collectors.toList()); |
|
|
|
spuIds.add(0L); |
|
|
|
List<GoodsSpu> spuList = goodsSpuService.listByIds(spuIds); |
|
|
|
|
|
|
|
List<OmsOrderItem> orderItems = new ArrayList<>(); |
|
|
|
|
|
|
|
for (OmsOrderImminentBo.ItemParam item : param.getItemList()) { |
|
|
|
for (GoodsImminentBatch batch : imminentBatches) { |
|
|
|
if(item.getBatchSkuId().equals(batch.getId())){ |
|
|
|
for (GoodsSku sku : goodsSkuList) { |
|
|
|
if(sku.getId().toString().equals(batch.getSkuId())){ |
|
|
|
//创建OrderItem
|
|
|
|
OmsOrderItem orderItem = createImminentOrderItem(order, spuList, item, batch, sku); |
|
|
|
orderItems.add(orderItem); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
List<String> skuCodes = orderItems.stream() |
|
|
|
.map(OmsOrderItem::getSkuCode).collect(Collectors.toList()); |
|
|
|
|
|
|
|
//商品特殊价
|
|
|
|
buildSkuSpecPrice(supplier, orderItems, skuCodes); |
|
|
|
|
|
|
|
//拦截商品授权维度规则
|
|
|
|
this.checkGoodsRule(supplier, orderItems); |
|
|
|
|
|
|
|
//拦截客户维度规则
|
|
|
|
goodsRuleService.checkSkuCode(skuCodes,goodsRuleService.listBySupplierId(order.getSupplierId().toString()),true); |
|
|
|
|
|
|
|
//拦截品类下单规则
|
|
|
|
this.handleCategoryRule(categoryRule,orderItems); |
|
|
|
|
|
|
|
this.updateById(order); |
|
|
|
//移除已有的ITEM
|
|
|
|
LambdaQueryWrapper<OmsOrderItem> rmItemLqw = new LambdaQueryWrapper<>(); |
|
|
|
rmItemLqw.eq(OmsOrderItem::getOrderId,param.getId()); |
|
|
|
omsOrderItemService.remove(rmItemLqw); |
|
|
|
//重新保存item
|
|
|
|
omsOrderItemService.saveBatch(orderItems); |
|
|
|
//立即下单
|
|
|
|
if(param.getInstantFlag()!=null&¶m.getInstantFlag().equals(1)){ |
|
|
|
this.buildPriceOrder(order.getId()+"",null); |
|
|
|
} |
|
|
|
|
|
|
|
return order.getId().toString(); |
|
|
|
} |
|
|
|
|
|
|
|
@NotNull |
|
|
|
private OmsOrderItem createImminentOrderItem(OmsOrder order, List<GoodsSpu> spuList, OmsOrderImminentBo.ItemParam item, GoodsImminentBatch batch, GoodsSku sku) { |
|
|
|
OmsOrderItem orderItem = new OmsOrderItem(); |
|
|
|
orderItem.setOrderId(order.getId()); |
|
|
|
orderItem.setOrderSn(order.getOrderSn()); |
|
|
|
orderItem.setSpuId(sku.getId()); |
|
|
|
for (GoodsSpu spu : spuList) { |
|
|
|
if(sku.getSpuId().equals(spu.getId())){ |
|
|
|
orderItem.setSpuCode(spu.getSpuCode()); |
|
|
|
orderItem.setSpuTitle(spu.getSpuCode()); |
|
|
|
break; |
|
|
|
} |
|
|
|
} |
|
|
|
orderItem.setWeight(sku.getWeight()); |
|
|
|
orderItem.setVolume(sku.getVolume()); |
|
|
|
orderItem.setRemark(sku.getRemark()); |
|
|
|
orderItem.setSkuBatchId(batch.getId()); |
|
|
|
orderItem.setSkuBatchCode(batch.getBatchCode()); |
|
|
|
orderItem.setSkuId(sku.getId()); |
|
|
|
orderItem.setSkuTitle(sku.getSkuName()); |
|
|
|
orderItem.setSkuCode(sku.getSkuCode()); |
|
|
|
orderItem.setSpecValues(sku.getSpecInfos()); |
|
|
|
orderItem.setSkuUnit(sku.getUnitName()); |
|
|
|
orderItem.setSkuImg(sku.getPicUrl()); |
|
|
|
orderItem.setSalesPrice(sku.getSalesPrice()); |
|
|
|
orderItem.setCusPrice(sku.getSalesPrice()); |
|
|
|
orderItem.setMarketPrice(sku.getMarketPrice()); |
|
|
|
orderItem.setQuantity(item.getQty()); |
|
|
|
return orderItem; |
|
|
|
} |
|
|
|
|
|
|
|
private void buildSkuSpecPrice(BmsSupplier supplier, List<OmsOrderItem> orderItems, List<String> skuCodes) { |
|
|
|
List<GoodsCustomerPrice> customerPrices = goodsCustomerPriceService.getBySupplierCodeAndCode(supplier.getCode(), skuCodes); |
|
|
|
for (OmsOrderItem orderItem : orderItems) { |
|
|
|
for (GoodsCustomerPrice customerPrice : customerPrices) { |
|
|
|
if (orderItem.getSkuCode().equals(customerPrice.getSkuCode())) { |
|
|
|
orderItem.setSalesPrice(customerPrice.getRealPrice()); |
|
|
|
break; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public void buildPriceOrder(String id,String amount) { |
|
|
|
OmsOrder omsOrder = super.getById(id); |
|
|
|