@ -97,6 +97,7 @@ import com.shop.cereshop.app.service.sensitive.CerePlatformSensitiveService;
import com.shop.cereshop.app.service.shop.CereShopCommentService ;
import com.shop.cereshop.app.service.shop.CereShopConversionService ;
import com.shop.cereshop.app.service.stock.CereStockService ;
import com.shop.cereshop.app.service.storehouse.CereShopStorehouseService ;
import com.shop.cereshop.app.utils.DistributionUtil ;
import com.shop.cereshop.commons.config.AlipayConfig ;
import com.shop.cereshop.commons.config.PayConfig ;
@ -133,6 +134,7 @@ import com.shop.cereshop.commons.domain.scene.CereShopSceneMember;
import com.shop.cereshop.commons.domain.sensitive.CerePlatformSensitive ;
import com.shop.cereshop.commons.domain.shop.CereShopComment ;
import com.shop.cereshop.commons.domain.shop.CereShopConversion ;
import com.shop.cereshop.commons.domain.storehouse.CereShopStorehouse ;
import com.shop.cereshop.commons.domain.tool.* ;
import com.shop.cereshop.commons.domain.word.CerePlatformWord ;
import com.shop.cereshop.commons.exception.CoBusinessException ;
@ -142,9 +144,9 @@ import com.shop.cereshop.commons.utils.third.WxCardUtil;
import lombok.extern.slf4j.Slf4j ;
import org.apache.commons.collections4.CollectionUtils ;
import org.apache.commons.collections4.MapUtils ;
import org.apache.poi.util.IOUtils ;
import org.redisson.api.RLock ;
import org.redisson.api.RedissonClient ;
import org.springframework.beans.BeanUtils ;
import org.springframework.beans.factory.annotation.Autowired ;
import org.springframework.beans.factory.annotation.Value ;
import org.springframework.stereotype.Service ;
@ -352,6 +354,9 @@ public class CereShopOrderServiceImpl implements CereShopOrderService {
@Autowired
private CereSkuRealInfoDAO cereSkuRealInfoDAO ;
@Autowired
private CereShopStorehouseService cereShopStorehouseService ;
/ * *
* app支付版本号
* /
@ -1635,12 +1640,7 @@ public class CereShopOrderServiceImpl implements CereShopOrderService {
List < SettlementShop > shopSettlementList = new ArrayList < > ( ) ;
/ / 查找所有的活动相关信息
/ / cerePlatformSeckillService .
List < Long > shopIdList = new ArrayList < > ( ) ;
for ( ShopProductParam shop : param . getShops ( ) ) {
shopIdList . add ( shop . getShopId ( ) ) ;
}
List < Long > shopIdList = param . getShops ( ) . stream ( ) . map ( ShopProductParam : : getShopId ) . distinct ( ) . collect ( Collectors . toList ( ) ) ;
/ / 平台秒杀
List < ShopPlatformSeckill > platformSeckillList = cerePlatformSeckillService . selectPlatformSeckillsByShopIdList ( shopIdList ) ;
Map < Long , List < ShopPlatformSeckill > > productIdPlatformSeckillMap = platformSeckillList . stream ( ) . collect ( Collectors . groupingBy ( ShopPlatformSeckill : : getProductId ) ) ;
@ -1657,9 +1657,6 @@ public class CereShopOrderServiceImpl implements CereShopOrderService {
List < ShopBusinessDiscount > discountList = cereShopDiscountService . selectByShopIdList ( shopIdList ) ;
Map < Long , List < ShopBusinessDiscount > > skuIdDiscountMap = discountList . stream ( ) . collect ( Collectors . groupingBy ( ShopBusinessDiscount : : getSkuId ) ) ;
/ / 定价捆绑
/ / Map < Long , Map < Long , List < CerePriceRule > > > priceMap = cereShopPriceService . selectPriceMap ( shopIdList ) ;
/ / 组合捆绑
List < CereShopComposeDTO > composeDTOList = Collections . emptyList ( ) ;
if ( ParamEnum . BUY_NOW . getCode ( ) . equals ( param . getType ( ) ) ) {
@ -1689,10 +1686,8 @@ public class CereShopOrderServiceImpl implements CereShopOrderService {
CerePlatformDict dict3 = cerePlatformDictService . getByName ( DictConstants . CREDIT_DEDUCT_LIMIT ) ;
/ / 1积分抵扣多少额度
CerePlatformDict dict4 = cerePlatformDictService . getByName ( DictConstants . CREDIT_EXCHANGE_RATE ) ;
log . info ( "dict: {} dict2: {} dict3:{} dict4: {}" , JSON . toJSONString ( dict ) , JSON . toJSONString ( dict2 ) ,
JSON . toJSONString ( dict3 ) , JSON . toJSONString ( dict4 ) ) ;
if ( dict ! = null & & StringUtils . isNotBlank ( dict . getDictDescribe ( ) )
& & IntegerEnum . YES . getCode ( ) . equals ( Integer . parseInt ( dict . getDictDescribe ( ) ) ) ) {
if ( dict ! = null & & StringUtils . isNotBlank ( dict . getDictDescribe ( ) ) & & IntegerEnum . YES . getCode ( ) . equals ( Integer . parseInt ( dict . getDictDescribe ( ) ) ) ) {
creditSwitch = true ;
CereBuyerUser buyerUser = cereBuyerUserService . selectByBuyerUserId ( user . getBuyerUserId ( ) ) ;
totalRemainCredit = buyerUser . getCredit ( ) ;
@ -1724,253 +1719,440 @@ public class CereShopOrderServiceImpl implements CereShopOrderService {
/ / 商家id 和 对应的定价捆绑的 商品id列表
Map < Long , List < Long > > shopPriceProductIdListMap = new HashMap < > ( ) ;
List < ProductSku > allSkus = new ArrayList ( ) ;
for ( ShopProductParam shop : param . getShops ( ) ) {
allSkus . addAll ( shop . getSkus ( ) ) ;
}
/ / 查询所有购买商品的库存数据
List < Long > skuIdList = allSkus . stream ( ) . map ( ProductSku : : getSkuId ) . distinct ( ) . collect ( Collectors . toList ( ) ) ;
List < CartSku > allProductSkus = cereProductSkuService . findStockNumberBySkus ( skuIdList ) ;
List < Long > storehouseIdList = allProductSkus . stream ( ) . map ( CartSku : : getStorehouseId ) . distinct ( ) . collect ( Collectors . toList ( ) ) ;
List < CereShopStorehouse > allStorehouseList = cereShopStorehouseService . getAll ( storehouseIdList ) ;
/ / 计算某个定价id优惠了多少钱
Map < Long , DiscountDescDTO > priceDiscountMap = new HashMap < > ( ) ;
/ / 计算某个组合捆绑id优惠了多少钱
Map < Long , DiscountDescDTO > composeDiscountMap = new HashMap < > ( ) ;
List < SettlementShop > settlementShopList = cereShopOrderDAO . findSettlementShopList ( shopIdList ) ;
/ / 满足使用优惠券条件的商品列表
List < Long > shopCanUseCouponProductIdList = new ArrayList < > ( ) ;
List < CereOrderLogistics > logisticsList = cereOrderLogisticsService . findLogisticsList ( shopIdList ) ;
/ / 查询店铺信息
SettlementShop settlementShop = cereShopOrderDAO . findSettlementShop ( shop . getShopId ( ) ) ;
settlementShop . setShopId ( shop . getShopId ( ) ) ;
List < CartSku > invalidSkus = new ArrayList < > ( ) ;
int invalidNumber = 0 ;
BigDecimal total = BigDecimal . ZERO ;
/ / sku后面接的 优惠信息
Map < Long , List < String > > skuDiscountInfoMap = new HashMap < > ( ) ;
settlementShop . setSkuDiscountInfoMap ( skuDiscountInfoMap ) ;
/ / 拆单后的结果 , 主键仓库Id , 值为对应的订单商品详情
Map < Long , List < ShopProductParam > > crossShopProductParamListMap = new HashMap < > ( ) ;
/ / 商品还可以抵扣多少积分
Map < Long , Integer > productRemainCreditMap = new HashMap < > ( ) ;
/ / 根据商家仓库限制等进行拆单
/ / 仓库限制到这里只需要根据订单总额来进行拆单 , 因为单商品限额的单商品数量已经在加入购物车的时候做了限制 , 总商品数量限制暂时不做支持 , 后续如果需要支持也放在这里
Map < Long , CartSku > map = new HashMap < > ( ) ;
for ( ShopProductParam shop : param . getShops ( ) ) {
/ / 这里进行拆单
if ( ! EmptyUtils . isEmpty ( shop . getSkus ( ) ) ) {
/ / 查询当前店铺所有购买商品的库存数据
List < CartSku > productSkus = cereProductSkuService . findStockNumberBySkus ( shop . getSkus ( ) ) ;
if ( ! EmptyUtils . isEmpty ( productSkus ) ) {
for ( CartSku sku : productSkus ) {
map . put ( sku . getSkuId ( ) , sku ) ;
if ( creditSwitch & & IntegerEnum . YES . getCode ( ) . equals ( sku . getIfCredit ( ) ) ) {
productRemainCreditMap . put ( sku . getProductId ( ) , sku . getCreditLimit ( ) ) ;
} else {
productRemainCreditMap . put ( sku . getProductId ( ) , 0 ) ;
/ / 同一个商家内的所有商品
for ( ProductSku skus : shop . getSkus ( ) ) {
CartSku findCartSku = allProductSkus . stream ( ) . filter ( item - > item . getSkuId ( ) . equals ( skus . getSkuId ( ) ) ) . findFirst ( ) . orElse ( null ) ;
if ( findCartSku ! = null ) {
CereShopStorehouse cereShopStorehouse = allStorehouseList . stream ( ) . filter ( item - > item . getStorehouseId ( ) . equals ( findCartSku . getStorehouseId ( ) ) ) . findFirst ( ) . orElse ( null ) ;
if ( cereShopStorehouse ! = null ) {
if ( cereShopStorehouse . getKind ( ) = = 1 ) {
/ / 国内仓 - 分仓库拆单 , 这里本来应该是国内订单并单的 , 但是因为订单的运费问题 , 保持拆单逻辑
if ( ! crossShopProductParamListMap . containsKey ( cereShopStorehouse . getStorehouseId ( ) ) ) {
crossShopProductParamListMap . put ( cereShopStorehouse . getStorehouseId ( ) , new ArrayList < > ( ) ) ;
}
List < ShopProductParam > storehouseShopProductParamList = crossShopProductParamListMap . get ( cereShopStorehouse . getStorehouseId ( ) ) ;
if ( storehouseShopProductParamList . isEmpty ( ) ) {
ShopProductParam storehouseShopProductParam = new ShopProductParam ( ) ;
BeanUtils . copyProperties ( shop , storehouseShopProductParam ) ;
storehouseShopProductParam . setSkus ( new ArrayList < > ( ) ) ;
storehouseShopProductParamList . add ( storehouseShopProductParam ) ;
}
storehouseShopProductParamList . get ( 0 ) . getSkus ( ) . add ( skus ) ;
} else if ( cereShopStorehouse . getKind ( ) = = 2 ) {
/ / 保税仓
if ( ! crossShopProductParamListMap . containsKey ( cereShopStorehouse . getStorehouseId ( ) ) ) {
crossShopProductParamListMap . put ( cereShopStorehouse . getStorehouseId ( ) , new ArrayList < > ( ) ) ;
}
List < ShopProductParam > storehouseShopProductParamList = crossShopProductParamListMap . get ( cereShopStorehouse . getStorehouseId ( ) ) ;
if ( storehouseShopProductParamList . isEmpty ( ) ) {
ShopProductParam storehouseShopProductParam = new ShopProductParam ( ) ;
BeanUtils . copyProperties ( shop , storehouseShopProductParam ) ;
storehouseShopProductParam . setSkus ( new ArrayList < > ( ) ) ;
storehouseShopProductParam . getSkus ( ) . add ( skus ) ;
storehouseShopProductParamList . add ( storehouseShopProductParam ) ;
} else {
ShopProductParam storehouseShopProductParam = storehouseShopProductParamList . get ( storehouseShopProductParamList . size ( ) - 1 ) ;
/ / 如果总价超过订单限制总价 , 则拆单
BigDecimal totalPrice = BigDecimal . ZERO ;
for ( ProductSku storehouseProductSkus : storehouseShopProductParam . getSkus ( ) ) {
CartSku findStorehouseCartSku = allProductSkus . stream ( ) . filter ( item - > item . getSkuId ( ) . equals ( storehouseProductSkus . getSkuId ( ) ) ) . findFirst ( ) . orElse ( null ) ;
if ( findStorehouseCartSku ! = null ) {
totalPrice = totalPrice . add ( findStorehouseCartSku . getPrice ( ) . multiply ( BigDecimal . valueOf ( storehouseProductSkus . getNumber ( ) ) ) ) ;
}
}
totalPrice = totalPrice . add ( findCartSku . getPrice ( ) . multiply ( BigDecimal . valueOf ( skus . getNumber ( ) ) ) ) ;
if ( totalPrice . compareTo ( cereShopStorehouse . getMoreProductOrderPriceLimit ( ) ) > 0 ) {
storehouseShopProductParam = new ShopProductParam ( ) ;
BeanUtils . copyProperties ( shop , storehouseShopProductParam ) ;
storehouseShopProductParam . setSkus ( new ArrayList < > ( ) ) ;
storehouseShopProductParam . getSkus ( ) . add ( skus ) ;
storehouseShopProductParamList . add ( storehouseShopProductParam ) ;
} else {
storehouseShopProductParam . getSkus ( ) . add ( skus ) ;
}
}
} else if ( cereShopStorehouse . getKind ( ) = = 3 ) {
/ / 海外仓
if ( ! crossShopProductParamListMap . containsKey ( cereShopStorehouse . getStorehouseId ( ) ) ) {
crossShopProductParamListMap . put ( cereShopStorehouse . getStorehouseId ( ) , new ArrayList < > ( ) ) ;
}
List < ShopProductParam > storehouseShopProductParamList = crossShopProductParamListMap . get ( cereShopStorehouse . getStorehouseId ( ) ) ;
if ( storehouseShopProductParamList . isEmpty ( ) ) {
ShopProductParam storehouseShopProductParam = new ShopProductParam ( ) ;
BeanUtils . copyProperties ( shop , storehouseShopProductParam ) ;
storehouseShopProductParam . setSkus ( new ArrayList < > ( ) ) ;
storehouseShopProductParamList . add ( storehouseShopProductParam ) ;
}
storehouseShopProductParamList . get ( 0 ) . getSkus ( ) . add ( skus ) ;
}
}
}
}
/ / 将商品数量放到map中
Map < Long , Integer > numberMap = shop . getSkus ( ) . stream ( )
. collect ( Collectors . toMap ( ProductSku : : getSkuId , ProductSku : : getNumber ) ) ;
Map < Long , Integer > productIdBuyNumberMap = new HashMap < > ( ) ;
Set < Long > usedSkuIdSet = new HashSet < > ( ) ;
if ( ! EmptyUtils . isEmpty ( numberMap ) ) {
/ / 查询规格信息数据
List < CartSku > skus = cereProductSkuService . findStockNumberBySkus ( shop . getSkus ( ) ) ;
if ( ! EmptyUtils . isEmpty ( skus ) ) {
/ / 设置商品数量
skus . forEach ( sku - > {
sku . setNumber ( numberMap . get ( sku . getSkuId ( ) ) ) ;
sku . setShopId ( shop . getShopId ( ) ) ;
Integer buyNum = productIdBuyNumberMap . getOrDefault ( sku . getProductId ( ) , 0 ) ;
productIdBuyNumberMap . put ( sku . getProductId ( ) , buyNum + sku . getNumber ( ) ) ;
} ) ;
/ * for ( CartSku sku : skus ) {
/ / 秒杀活动和限时折扣活动校验
/ / checkActivity ( param , numberMap . get ( sku . getSkuId ( ) ) , sku , settlement , user , shop ) ;
/ / 设置规格属性值数组
sku . setValues ( EmptyUtils . getImages ( sku . getValue ( ) ) ) ;
} * /
for ( CartSku sku : skus ) {
shopCanUseCouponProductIdList . add ( sku . getProductId ( ) ) ;
List < ShopPlatformSeckill > shopPlatformSeckillList = productIdPlatformSeckillMap . get ( sku . getProductId ( ) ) ;
List < ShopPlatformDiscount > shopPlatformDiscountList = productIdPlatformDiscountMap . get ( sku . getProductId ( ) ) ;
List < ShopBusinessSeckill > shopBusinessSeckillList = skuIdSeckillMap . get ( sku . getSkuId ( ) ) ;
List < ShopBusinessDiscount > shopBusinessDiscountList = skuIdDiscountMap . get ( sku . getSkuId ( ) ) ;
BigDecimal num = new BigDecimal ( sku . getNumber ( ) ) ;
/ / 匹配平台秒杀
if ( CollectionUtils . isNotEmpty ( shopPlatformSeckillList ) ) {
ShopPlatformSeckill seckill = shopPlatformSeckillList . get ( 0 ) ;
usedSkuIdSet . add ( sku . getSkuId ( ) ) ;
sku . setPlatformSeckillId ( shopPlatformSeckillList . get ( 0 ) . getSeckillId ( ) ) ;
if ( sku . getOriginalPrice ( ) . compareTo ( seckill . getSeckillMoney ( ) ) > = 0 ) {
sku . setPrice ( sku . getOriginalPrice ( ) . subtract ( seckill . getSeckillMoney ( ) ) . setScale ( 2 , BigDecimal . ROUND_HALF_UP ) ) ;
}
}
if ( IntegerEnum . PRODUCT_IF_LIMIT_YES . getCode ( ) . equals ( seckill . getIfLimit ( ) ) ) {
if ( productIdBuyNumberMap . get ( sku . getProductId ( ) ) > seckill . getLimitNumber ( ) ) {
for ( Map . Entry < Long , List < ShopProductParam > > storehouseProdustsListEntry : crossShopProductParamListMap . entrySet ( ) ) {
Long storehouseId = storehouseProdustsListEntry . getKey ( ) ;
List < ShopProductParam > storehouseProdustsList = storehouseProdustsListEntry . getValue ( ) ;
for ( ShopProductParam shop : storehouseProdustsList ) {
/ / 计算某个定价id优惠了多少钱
Map < Long , DiscountDescDTO > priceDiscountMap = new HashMap < > ( ) ;
/ / 计算某个组合捆绑id优惠了多少钱
Map < Long , DiscountDescDTO > composeDiscountMap = new HashMap < > ( ) ;
/ / 满足使用优惠券条件的商品列表
List < Long > shopCanUseCouponProductIdList = new ArrayList < > ( ) ;
/ / 查询店铺信息findSettlementShopList
SettlementShop tempSettlementShop = settlementShopList . stream ( ) . filter ( item - > item . getShopId ( ) . equals ( shop . getShopId ( ) ) ) . findFirst ( ) . orElse ( null ) ;
SettlementShop settlementShop = new SettlementShop ( ) ;
BeanUtils . copyProperties ( tempSettlementShop , settlementShop ) ;
settlementShop . setShopId ( shop . getShopId ( ) ) ;
settlementShop . setStorehouseId ( storehouseId ) ;
CereShopStorehouse shopStorehouse = allStorehouseList . stream ( ) . filter ( item - > item . getStorehouseId ( ) . equals ( storehouseId ) ) . findFirst ( ) . orElse ( null ) ;
settlementShop . setStorehouseName ( shopStorehouse . getStorehouseName ( ) ) ;
if ( shopStorehouse . getKind ( ) = = 2 ) {
settlementShop . setIsCross ( 1 ) ;
} else {
settlementShop . setIsCross ( 0 ) ;
}
String uniqueIdKey = shop . getShopId ( ) + "-" + storehouseId + "-" + shop . getSkus ( ) . stream ( ) . map ( item - > item . getSkuId ( ) . toString ( ) ) . reduce ( ( x , y ) - > x + y ) . orElse ( "" ) ;
settlementShop . setUniqueId ( ( long ) uniqueIdKey . hashCode ( ) ) ;
List < CartSku > invalidSkus = new ArrayList < > ( ) ;
int invalidNumber = 0 ;
BigDecimal total = BigDecimal . ZERO ;
/ / sku后面接的 优惠信息
Map < Long , List < String > > skuDiscountInfoMap = new HashMap < > ( ) ;
settlementShop . setSkuDiscountInfoMap ( skuDiscountInfoMap ) ;
/ / 商品还可以抵扣多少积分
Map < Long , Integer > productRemainCreditMap = new HashMap < > ( ) ;
Map < Long , CartSku > map = new HashMap < > ( ) ;
if ( ! EmptyUtils . isEmpty ( shop . getSkus ( ) ) ) {
/ / 查询当前订单所购买商品的详细数据
List < CartSku > productSkus = new ArrayList < > ( ) ;
for ( ProductSku skus : shop . getSkus ( ) ) {
CartSku findCartSku = allProductSkus . stream ( ) . filter ( item - > item . getSkuId ( ) . equals ( skus . getSkuId ( ) ) ) . findFirst ( ) . orElse ( null ) ;
if ( findCartSku ! = null ) {
productSkus . add ( findCartSku ) ;
}
}
if ( ! EmptyUtils . isEmpty ( productSkus ) ) {
for ( CartSku sku : productSkus ) {
map . put ( sku . getSkuId ( ) , sku ) ;
if ( creditSwitch & & IntegerEnum . YES . getCode ( ) . equals ( sku . getIfCredit ( ) ) ) {
productRemainCreditMap . put ( sku . getProductId ( ) , sku . getCreditLimit ( ) ) ;
} else {
productRemainCreditMap . put ( sku . getProductId ( ) , 0 ) ;
}
}
}
/ / 将商品数量放到map中
Map < Long , Integer > numberMap = shop . getSkus ( ) . stream ( ) . collect ( Collectors . toMap ( ProductSku : : getSkuId , ProductSku : : getNumber ) ) ;
Map < Long , Integer > productIdBuyNumberMap = new HashMap < > ( ) ;
Set < Long > usedSkuIdSet = new HashSet < > ( ) ;
if ( ! EmptyUtils . isEmpty ( numberMap ) ) {
/ / 查询规格信息数据
List < CartSku > skus = productSkus ;
if ( ! EmptyUtils . isEmpty ( skus ) ) {
for ( CartSku sku : skus ) {
sku . setNumber ( numberMap . get ( sku . getSkuId ( ) ) ) ;
sku . setShopId ( shop . getShopId ( ) ) ;
sku . setUniqueId ( settlementShop . getUniqueId ( ) ) ;
/ / 设置商品数量
Integer buyNum = productIdBuyNumberMap . getOrDefault ( sku . getProductId ( ) , 0 ) ;
productIdBuyNumberMap . put ( sku . getProductId ( ) , buyNum + sku . getNumber ( ) ) ;
shopCanUseCouponProductIdList . add ( sku . getProductId ( ) ) ;
List < ShopPlatformSeckill > shopPlatformSeckillList = productIdPlatformSeckillMap . get ( sku . getProductId ( ) ) ;
List < ShopPlatformDiscount > shopPlatformDiscountList = productIdPlatformDiscountMap . get ( sku . getProductId ( ) ) ;
List < ShopBusinessSeckill > shopBusinessSeckillList = skuIdSeckillMap . get ( sku . getSkuId ( ) ) ;
List < ShopBusinessDiscount > shopBusinessDiscountList = skuIdDiscountMap . get ( sku . getSkuId ( ) ) ;
/ / 匹配平台秒杀
if ( CollectionUtils . isNotEmpty ( shopPlatformSeckillList ) ) {
ShopPlatformSeckill seckill = shopPlatformSeckillList . get ( 0 ) ;
usedSkuIdSet . add ( sku . getSkuId ( ) ) ;
sku . setPlatformSeckillId ( shopPlatformSeckillList . get ( 0 ) . getSeckillId ( ) ) ;
if ( sku . getOriginalPrice ( ) . compareTo ( seckill . getSeckillMoney ( ) ) > = 0 ) {
sku . setPrice ( sku . getOriginalPrice ( ) . subtract ( seckill . getSeckillMoney ( ) ) . setScale ( 2 , BigDecimal . ROUND_HALF_UP ) ) ;
if ( IntegerEnum . PRODUCT_IF_LIMIT_YES . getCode ( ) . equals ( seckill . getIfLimit ( ) ) ) {
if ( productIdBuyNumberMap . get ( sku . getProductId ( ) ) > seckill . getLimitNumber ( ) ) {
throw new CoBusinessException ( CoReturnFormat . PRODUCT_LIMIT_ERROR ) ;
}
}
if ( seckill . getNumber ( ) ! = null & & productIdBuyNumberMap . get ( sku . getProductId ( ) ) > seckill . getNumber ( ) ) {
throw new CoBusinessException ( CoReturnFormat . PRODUCT_STOCK_ERROR ) ;
}
/ / 不允许叠加优惠券
if ( IntegerEnum . NO . getCode ( ) . equals ( seckill . getIfAdd ( ) ) ) {
shopCanUseCouponProductIdList . remove ( sku . getProductId ( ) ) ;
}
}
}
/ / 匹配平台折扣
if ( CollectionUtils . isNotEmpty ( shopPlatformDiscountList ) ) {
ShopPlatformDiscount discount = shopPlatformDiscountList . get ( 0 ) ;
usedSkuIdSet . add ( sku . getSkuId ( ) ) ;
sku . setPlatformDiscountId ( shopPlatformDiscountList . get ( 0 ) . getDiscountId ( ) ) ;
sku . setPrice ( sku . getOriginalPrice ( ) . multiply ( discount . getDiscount ( ) ) . divide ( BigDecimal . TEN , 2 , BigDecimal . ROUND_HALF_UP ) ) ;
if ( IntegerEnum . PRODUCT_IF_LIMIT_YES . getCode ( ) . equals ( discount . getIfLimit ( ) ) ) {
if ( productIdBuyNumberMap . get ( sku . getProductId ( ) ) > discount . getLimitNumber ( ) ) {
throw new CoBusinessException ( CoReturnFormat . PRODUCT_LIMIT_ERROR ) ;
}
}
if ( seckill . getNumber ( ) ! = null & & productIdBuyNumberMap . get ( sku . getProductId ( ) ) > seckill . getNumber ( ) ) {
if ( discount . getNumber ( ) ! = null & & productIdBuyNumberMap . get ( sku . getProductId ( ) ) > discount . getNumber ( ) ) {
throw new CoBusinessException ( CoReturnFormat . PRODUCT_STOCK_ERROR ) ;
}
/ / 不允许叠加优惠券
if ( IntegerEnum . NO . getCode ( ) . equals ( seckill . getIfAdd ( ) ) ) {
if ( IntegerEnum . NO . getCode ( ) . equals ( discount . getIfAdd ( ) ) ) {
shopCanUseCouponProductIdList . remove ( sku . getProductId ( ) ) ;
}
}
}
/ / 匹配平台折扣
if ( CollectionUtils . isNotEmpty ( shopPlatformDiscountList ) ) {
ShopPlatformDiscount discount = shopPlatformDiscountList . get ( 0 ) ;
/ / 匹配商家秒杀
if ( CollectionUtils . isNotEmpty ( shopBusinessSeckill List ) ) {
ShopBusinessSeckill seckill = shopBusinessSeckill List . get ( 0 ) ;
usedSkuIdSet . add ( sku . getSkuId ( ) ) ;
sku . setPlatformDiscountId ( shopPlatformDiscountList . get ( 0 ) . getDiscountId ( ) ) ;
sku . setPrice ( sku . getOriginalPrice ( ) . multiply ( discount . getDiscount ( ) ) . divide ( BigDecimal . TEN , 2 , BigDecimal . ROUND_HALF_UP ) ) ;
usedSkuIdSet . add ( sku . getSkuId ( ) ) ;
sku . setShopSeckillId ( shopBusinessSeckill List . get ( 0 ) . getSeckill Id ( ) ) ;
sku . setPrice ( seckill . getSeckillPrice ( ) ) ;
if ( IntegerEnum . PRODUCT_IF_LIMIT_YES . getCode ( ) . equals ( discount . getIfLimit ( ) ) ) {
if ( productIdBuyNumberMap . get ( sku . getProductId ( ) ) > discount . getLimitNumber ( ) ) {
throw new CoBusinessException ( CoReturnFormat . PRODUCT_LIMIT_ERROR ) ;
if ( IntegerEnum . PRODUCT_IF_LIMIT_YES . getCode ( ) . equals ( seckill . getIfLimit ( ) ) ) {
if ( seckill . getLimitNumber ( ) ! = null & & productIdBuyNumberMap . get ( sku . getProductId ( ) ) > seckill . getLimitNumber ( ) ) {
throw new CoBusinessException ( CoReturnFormat . PRODUCT_LIMIT_ERROR ) ;
}
}
}
if ( discount . getNumber ( ) ! = null & & productIdBuyNumberMap . get ( sku . getProductId ( ) ) > discount . getNumber ( ) ) {
throw new CoBusinessException ( CoReturnFormat . PRODUCT_STOCK_ERROR ) ;
}
/ / 不允许叠加优惠券
if ( IntegerEnum . NO . getCode ( ) . equals ( discount . getIfAdd ( ) ) ) {
shopCanUseCouponProductIdList . remove ( sku . getProductId ( ) ) ;
}
}
/ / 匹配商家秒杀
if ( CollectionUtils . isNotEmpty ( shopBusinessSeckillList ) ) {
ShopBusinessSeckill seckill = shopBusinessSeckillList . get ( 0 ) ;
usedSkuIdSet . add ( sku . getSkuId ( ) ) ;
sku . setShopSeckillId ( shopBusinessSeckillList . get ( 0 ) . getSeckillId ( ) ) ;
sku . setPrice ( seckill . getSeckillPrice ( ) ) ;
if ( IntegerEnum . PRODUCT_IF_LIMIT_YES . getCode ( ) . equals ( seckill . getIfLimit ( ) ) ) {
if ( seckill . getLimitNumber ( ) ! = null & & productIdBuyNumberMap . get ( sku . getProductId ( ) ) > seckill . getLimitNumber ( ) ) {
throw new CoBusinessException ( CoReturnFormat . PRODUCT_LIMIT_ERROR ) ;
if ( IntegerEnum . NO . getCode ( ) . equals ( seckill . getIfAdd ( ) ) ) {
shopCanUseCouponProductIdList . remove ( sku . getProductId ( ) ) ;
}
}
if ( IntegerEnum . NO . getCode ( ) . equals ( seckill . getIfAdd ( ) ) ) {
shopCanUseCouponProductIdList . remove ( sku . getProductId ( ) ) ;
}
}
/ / 匹配商家折扣
if ( CollectionUtils . isNotEmpty ( shopBusinessDiscountList ) ) {
ShopBusinessDiscount discount = shopBusinessDiscountList . get ( 0 ) ;
/ / 匹配商家折扣
if ( CollectionUtils . isNotEmpty ( shopBusinessDiscountList ) ) {
ShopBusinessDiscount discount = shopBusinessDiscountList . get ( 0 ) ;
usedSkuIdSet . add ( sku . getSkuId ( ) ) ;
sku . setShopDiscountId ( discount . getDiscountId ( ) ) ;
sku . setPrice ( discount . getPrice ( ) ) ;
usedSkuIdSet . add ( sku . getSkuId ( ) ) ;
sku . setShopDiscountId ( discount . getDiscountId ( ) ) ;
sku . setPrice ( discount . getPrice ( ) ) ;
if ( IntegerEnum . PRODUCT_IF_LIMIT_YES . getCode ( ) . equals ( discount . getIfLimit ( ) ) ) {
if ( discount . getLimitNumber ( ) ! = null & & productIdBuyNumberMap . get ( sku . getProductId ( ) ) > discount . getLimitNumber ( ) ) {
throw new CoBusinessException ( CoReturnFormat . PRODUCT_LIMIT_ERROR ) ;
if ( IntegerEnum . PRODUCT_IF_LIMIT_YES . getCode ( ) . equals ( discount . getIfLimit ( ) ) ) {
if ( discount . getLimitNumber ( ) ! = null & & productIdBuyNumberMap . get ( sku . getProductId ( ) ) > discount . getLimitNumber ( ) ) {
throw new CoBusinessException ( CoReturnFormat . PRODUCT_LIMIT_ERROR ) ;
}
}
if ( IntegerEnum . NO . getCode ( ) . equals ( discount . getIfAdd ( ) ) ) {
shopCanUseCouponProductIdList . remove ( sku . getProductId ( ) ) ;
}
}
if ( IntegerEnum . NO . getCode ( ) . equals ( discount . getIfAdd ( ) ) ) {
shopCanUseCouponProductIdList . remove ( sku . getProductId ( ) ) ;
}
}
Integer remainCredit = productRemainCreditMap . get ( sku . getProductId ( ) ) ;
if ( totalRemainCredit > 0 & & remainCredit > 0 ) {
BigDecimal price = sku . getPrice ( ) . multiply ( new BigDecimal ( sku . getNumber ( ) ) ) ;
Integer needCredit = price . divide ( creditExchangeRate , 0 , BigDecimal . ROUND_HALF_DOWN ) . intValue ( ) ;
if ( needCredit > 0 ) {
Integer min = Math . min ( remainCredit , totalRemainCredit ) ;
if ( min > = needCredit ) {
productRemainCreditMap . put ( sku . getProductId ( ) , remainCredit - needCredit ) ;
skuCreditMap . put ( sku . getSkuId ( ) , needCredit ) ;
totalRemainCredit - = needCredit ;
} else {
productRemainCreditMap . put ( sku . getProductId ( ) , remainCredit - min ) ;
skuCreditMap . put ( sku . getSkuId ( ) , min ) ;
totalRemainCredit - = min ;
Integer remainCredit = productRemainCreditMap . get ( sku . getProductId ( ) ) ;
if ( totalRemainCredit > 0 & & remainCredit > 0 ) {
BigDecimal price = sku . getPrice ( ) . multiply ( new BigDecimal ( sku . getNumber ( ) ) ) ;
Integer needCredit = price . divide ( creditExchangeRate , 0 , BigDecimal . ROUND_HALF_DOWN ) . intValue ( ) ;
if ( needCredit > 0 ) {
Integer min = Math . min ( remainCredit , totalRemainCredit ) ;
if ( min > = needCredit ) {
productRemainCreditMap . put ( sku . getProductId ( ) , remainCredit - needCredit ) ;
skuCreditMap . put ( sku . getSkuId ( ) , needCredit ) ;
totalRemainCredit - = needCredit ;
} else {
productRemainCreditMap . put ( sku . getProductId ( ) , remainCredit - min ) ;
skuCreditMap . put ( sku . getSkuId ( ) , min ) ;
totalRemainCredit - = min ;
}
}
}
}
}
List < CartSku > skuList = skus . stream ( ) . filter ( sku - > ! usedSkuIdSet . contains ( sku . getSkuId ( ) ) ) . collect ( Collectors . toList ( ) ) ;
List < CartSku > skuList = skus . stream ( ) . filter ( sku - > ! usedSkuIdSet . contains ( sku . getSkuId ( ) ) ) . collect ( Collectors . toList ( ) ) ;
/ / 匹配定价捆绑
matchPriceCombine ( shop . getShopId ( ) , skus , skuList , settlementShop , usedSkuIdSet , priceDiscountMap ) ;
/ / 匹配定价捆绑
matchPriceCombine ( shop . getShopId ( ) , skus , skuList , settlementShop , usedSkuIdSet , priceDiscountMap ) ;
skuList = skus . stream ( ) . filter ( sku - > ! usedSkuIdSet . contains ( sku . getSkuId ( ) ) ) . collect ( Collectors . toList ( ) ) ;
skuList = skus . stream ( ) . filter ( sku - > ! usedSkuIdSet . contains ( sku . getSkuId ( ) ) ) . collect ( Collectors . toList ( ) ) ;
/ / 匹配组合捆绑
matchComposeCombine ( shop . getShopId ( ) , skuList , usedSkuIdSet , shopIdComposeMap , composeDiscountMap , numberMap ) ;
/ / 匹配组合捆绑
matchComposeCombine ( shop . getShopId ( ) , skuList , usedSkuIdSet , shopIdComposeMap , composeDiscountMap , numberMap ) ;
skuList = skus . stream ( ) . filter ( sku - > ! usedSkuIdSet . contains ( sku . getSkuId ( ) ) ) . collect ( Collectors . toList ( ) ) ;
skuList = skus . stream ( ) . filter ( sku - > ! usedSkuIdSet . contains ( sku . getSkuId ( ) ) ) . collect ( Collectors . toList ( ) ) ;
/ / 匹配场景营销
matchSceneMarket ( shop . getShopId ( ) , user , skuList , usedSkuIdSet , shopIdSceneDiscountMap , sceneMarketFreeShipingMap ) ;
/ / 匹配场景营销
matchSceneMarket ( shop . getShopId ( ) , user , skuList , usedSkuIdSet , shopIdSceneDiscountMap , sceneMarketFreeShipingMap ) ;
skuList = skuList . stream ( ) . filter ( sku - > ! usedSkuIdSet . contains ( sku . getSkuId ( ) ) ) . collect ( Collectors . toList ( ) ) ;
skuList = skuList . stream ( ) . filter ( sku - > ! usedSkuIdSet . contains ( sku . getSkuId ( ) ) ) . collect ( Collectors . toList ( ) ) ;
/ / 匹配会员价
matchMember ( shop . getShopId ( ) , user , skuList , usedSkuIdSet , memberDiscountPriceMap ) ;
/ / 匹配会员价
matchMember ( shop . getShopId ( ) , user , skuList , usedSkuIdSet , memberDiscountPriceMap ) ;
/ / 针对定价捆绑 , 如果
/ / Map < Long , List < Long > > productIdPlatformCouponIdMap = new HashMap < > ( ) ;
/ / Map < Long , List < Long > > productIdShopCouponIdMap = new HashMap < > ( ) ;
for ( CartSku sku : skus ) {
/ / 秒杀活动和限时折扣活动校验
checkActivity ( param , numberMap . get ( sku . getSkuId ( ) ) , sku , settlement , user , shop ) ;
/ / 设置规格属性值数组
sku . setValues ( EmptyUtils . getImages ( sku . getValue ( ) ) ) ;
/ / 针对定价捆绑 , 如果
for ( CartSku sku : skus ) {
/ / 秒杀活动和限时折扣活动校验
checkActivity ( param , numberMap . get ( sku . getSkuId ( ) ) , sku , settlement , user , shop ) ;
/ / 设置规格属性值数组
sku . setValues ( EmptyUtils . getImages ( sku . getValue ( ) ) ) ;
sku . setTotal ( new BigDecimal ( sku . getNumber ( ) ) . multiply ( sku . getPrice ( ) ) ) ;
sku . setSelected ( IntegerEnum . YES . getCode ( ) ) ;
/ / 定义是否需要查询优惠券标识 , 默认需要
sku . setTotal ( new BigDecimal ( sku . getNumber ( ) ) . multiply ( sku . getPrice ( ) ) ) ;
sku . setSelected ( IntegerEnum . YES . getCode ( ) ) ;
/ / 定义是否需要查询优惠券标识 , 默认需要
/ * setSettlementCoupons ( param , shop , user . getBuyerUserId ( ) , sku , settlementShop , settlement ,
settlement . getCoupons ( ) , settlementShop . getShopCoupons ( ) , productIdPlatformCouponIdMap , productIdShopCouponIdMap ) ; * /
/ / 校验库存
int stockNumber = 0 ;
/ / 校验库存
int stockNumber = 0 ;
/ * if ( ! EmptyUtils . isEmpty ( stringRedisService . get ( String . valueOf ( sku . getSkuId ( ) ) ) ) ) {
stockNumber = ( int ) stringRedisService . get ( String . valueOf ( sku . getSkuId ( ) ) ) ;
} else {
stockNumber = map . get ( sku . getSkuId ( ) ) . getStockNumber ( ) ;
} * /
stockNumber = map . get ( sku . getSkuId ( ) ) . getStockNumber ( ) ;
if ( sku . getNumber ( ) > stockNumber ) {
/ / 叠加商品件数
invalidNumber + = sku . getNumber ( ) ;
flag . set ( true ) ;
invalidSkus . add ( sku ) ;
stockNumber = map . get ( sku . getSkuId ( ) ) . getStockNumber ( ) ;
if ( sku . getNumber ( ) > stockNumber ) {
/ / 叠加商品件数
invalidNumber + = sku . getNumber ( ) ;
flag . set ( true ) ;
invalidSkus . add ( sku ) ;
}
/ / total = total . add ( sku . getTotal ( ) ) ;
}
/ / total = total . add ( sku . getTotal ( ) ) ;
}
/ / settlementShop . setSkus ( skus ) ;
settlementShop . setNumber ( skus . stream ( ) . mapToInt ( CartSku : : getNumber ) . sum ( ) ) ;
List < CartSku > sortSkuList = new ArrayList < > ( ) ;
settlementShop . setNumber ( skus . stream ( ) . mapToInt ( CartSku : : getNumber ) . sum ( ) ) ;
if ( priceDiscountMap . size ( ) > 0 ) {
for ( Long id : priceDiscountMap . keySet ( ) ) {
DiscountDescDTO value = priceDiscountMap . get ( id ) ;
List < CartSku > sortSkuList = new ArrayList < > ( ) ;
List < CartSku > tmpSkuList = skus . stream ( ) . filter ( sku - > sku . getPriceId ( ) ! = null & & sku . getPriceId ( ) . equals ( id ) ) . collect ( Collectors . toList ( ) ) ;
sortSkuList . addAll ( tmpSkuList ) ;
BigDecimal tmpTotal = BigDecimal . ZERO ;
if ( priceDiscountMap . size ( ) > 0 ) {
for ( Long id : priceDiscountMap . keySet ( ) ) {
DiscountDescDTO value = priceDiscountMap . get ( id ) ;
for ( CartSku sku : tmpSkuList ) {
total = total . add ( sku . getPrice ( ) . multiply ( new BigDecimal ( sku . getNumber ( ) ) ) ) ;
tmpTotal = tmpTotal . add ( sku . getPrice ( ) . multiply ( new BigDecimal ( sku . getNumber ( ) ) ) ) ;
List < CartSku > tmpSkuList = skus . stream ( ) . filter ( sku - > sku . getPriceId ( ) ! = null & & sku . getPriceId ( ) . equals ( id ) ) . collect ( Collectors . toList ( ) ) ;
sortSkuList . addAll ( tmpSkuList ) ;
BigDecimal tmpTotal = BigDecimal . ZERO ;
for ( CartSku sku : tmpSkuList ) {
total = total . add ( sku . getPrice ( ) . multiply ( new BigDecimal ( sku . getNumber ( ) ) ) ) ;
tmpTotal = tmpTotal . add ( sku . getPrice ( ) . multiply ( new BigDecimal ( sku . getNumber ( ) ) ) ) ;
}
shopPriceProductIdListMap . put ( shop . getShopId ( ) , tmpSkuList . stream ( ) . map ( CartSku : : getProductId ) . distinct ( ) . collect ( Collectors . toList ( ) ) ) ;
total = total . subtract ( value . getDiscountTotal ( ) ) ;
settlementShop . setPriceAfterDiscount ( tmpTotal . subtract ( value . getDiscountTotal ( ) ) ) ;
for ( CartSku sku : tmpSkuList ) {
Integer remainCredit = productRemainCreditMap . get ( sku . getProductId ( ) ) ;
if ( totalRemainCredit > 0 & & remainCredit > 0 ) {
BigDecimal percent = sku . getPrice ( ) . multiply ( new BigDecimal ( sku . getNumber ( ) ) ) . divide ( tmpTotal , 4 , BigDecimal . ROUND_HALF_UP ) ;
Integer needCredit = tmpTotal . subtract ( value . getDiscountTotal ( ) ) . multiply ( percent ) . divide ( creditExchangeRate , 0 , BigDecimal . ROUND_HALF_DOWN ) . intValue ( ) ;
if ( needCredit > 0 ) {
Integer min = Math . min ( remainCredit , totalRemainCredit ) ;
if ( min > = needCredit ) {
productRemainCreditMap . put ( sku . getProductId ( ) , remainCredit - needCredit ) ;
skuCreditMap . put ( sku . getSkuId ( ) , needCredit ) ;
totalRemainCredit - = needCredit ;
} else {
productRemainCreditMap . put ( sku . getProductId ( ) , remainCredit - min ) ;
skuCreditMap . put ( sku . getSkuId ( ) , min ) ;
totalRemainCredit - = min ;
}
}
}
}
skuDiscountInfoMap . put ( tmpSkuList . get ( tmpSkuList . size ( ) - 1 ) . getSkuId ( ) , Arrays . asList ( String . format ( "定价捆绑 %.2f元任选%d件 x %d" , value . getComposePrice ( ) , value . getComposeNum ( ) , value . getDiscountNum ( ) ) , "优惠¥" + value . getDiscountTotal ( ) ) ) ;
}
}
shopPriceProductIdListMap . put ( shop . getShopId ( ) , tmpSkuList . stream ( ) . map ( CartSku : : getProductId ) . distinct ( ) . collect ( Collectors . toList ( ) ) ) ;
if ( composeDiscountMap . size ( ) > 0 ) {
for ( Long id : composeDiscountMap . keySet ( ) ) {
DiscountDescDTO value = composeDiscountMap . get ( id ) ;
total = total . subtract ( value . getDiscountTotal ( ) ) ;
settlementShop . setPriceAfterDiscount ( tmpTotal . subtract ( value . getDiscountTotal ( ) ) ) ;
List < CartSku > tmpSkuList = skus . stream ( ) . filter ( sku - > sku . getComposeId ( ) ! = null & & sku . getComposeId ( ) . equals ( id ) ) . collect ( Collectors . toList ( ) ) ;
sortSkuList . addAll ( tmpSkuList ) ;
BigDecimal tmpTotal = BigDecimal . ZERO ;
for ( CartSku sku : tmpSkuList ) {
total = total . add ( sku . getPrice ( ) . multiply ( new BigDecimal ( sku . getNumber ( ) ) ) ) ;
tmpTotal = tmpTotal . add ( sku . getPrice ( ) . multiply ( new BigDecimal ( sku . getNumber ( ) ) ) ) ;
}
total = total . subtract ( value . getDiscountTotal ( ) ) ;
for ( CartSku sku : tmpSkuList ) {
Integer remainCredit = productRemainCreditMap . get ( sku . getProductId ( ) ) ;
if ( totalRemainCredit > 0 & & remainCredit > 0 ) {
BigDecimal percent = sku . getPrice ( ) . multiply ( new BigDecimal ( sku . getNumber ( ) ) ) . divide ( tmpTotal , 4 , BigDecimal . ROUND_HALF_UP ) ;
Integer needCredit = tmpTotal . subtract ( value . getDiscountTotal ( ) ) . multiply ( percent ) . divide ( creditExchangeRate , 0 , BigDecimal . ROUND_HALF_DOWN ) . intValue ( ) ;
if ( needCredit > 0 ) {
Integer min = Math . min ( remainCredit , totalRemainCredit ) ;
if ( min > = needCredit ) {
productRemainCreditMap . put ( sku . getProductId ( ) , remainCredit - needCredit ) ;
skuCreditMap . put ( sku . getSkuId ( ) , needCredit ) ;
totalRemainCredit - = needCredit ;
} else {
productRemainCreditMap . put ( sku . getProductId ( ) , remainCredit - min ) ;
skuCreditMap . put ( sku . getSkuId ( ) , min ) ;
totalRemainCredit - = min ;
}
}
}
}
skuDiscountInfoMap . put ( tmpSkuList . get ( tmpSkuList . size ( ) - 1 ) . getSkuId ( ) , Arrays . asList ( String . format ( "组合捆绑 x %d" , value . getDiscountNum ( ) ) , "优惠¥" + value . getDiscountTotal ( ) ) ) ;
}
}
if ( shopIdSceneDiscountMap . get ( shop . getShopId ( ) ) ! = null ) {
DiscountDescDTO value = shopIdSceneDiscountMap . get ( shop . getShopId ( ) ) ;
List < CartSku > tmpSkuList = skus . stream ( ) . filter ( sku - > sku . getSceneId ( ) ! = null ) . collect ( Collectors . toList ( ) ) ;
/ * sortSkuList . addAll ( tmpSkuList ) ;
for ( CartSku sku : tmpSkuList ) {
total = total . add ( sku . getPrice ( ) . multiply ( new BigDecimal ( sku . getNumber ( ) ) ) ) ;
}
total = total . subtract ( value . getDiscountTotal ( ) ) ; * /
BigDecimal tmpTotal = BigDecimal . ZERO ;
for ( CartSku sku : tmpSkuList ) {
tmpTotal = tmpTotal . add ( sku . getPrice ( ) . multiply ( new BigDecimal ( sku . getNumber ( ) ) ) ) ;
}
for ( CartSku sku : tmpSkuList ) {
Integer remainCredit = productRemainCreditMap . get ( sku . getProductId ( ) ) ;
@ -1992,16 +2174,15 @@ public class CereShopOrderServiceImpl implements CereShopOrderService {
}
}
skuDiscountInfoMap . put ( tmpSkuList . get ( tmpSkuList . size ( ) - 1 ) . getSkuId ( ) , Arrays . asList ( String . format ( "定价捆绑 %.2f元任选%d件 x %d" , value . getComposePrice ( ) , value . getComposeNum ( ) , value . getDiscountNum ( ) ) , "优惠¥" + value . getDiscountTotal ( ) ) ) ;
skuDiscountInfoMap . put ( tmpSkuList . get ( tmpSkuList . size ( ) - 1 ) . getSkuId ( ) , Arrays . asList ( String . format ( "场景营销 %.1f折 x %d" , value . getDiscount ( ) , value . getDiscountNum ( ) ) , "优惠¥" + value . getDiscountTotal ( ) ) ) ;
}
}
if ( composeDiscountMap . size ( ) > 0 ) {
for ( Long id : composeDiscountMap . keySet ( ) ) {
DiscountDescDTO value = composeDiscountMap . get ( id ) ;
if ( memberDiscountPriceMap . get ( shop . getShopId ( ) ) ! = null ) {
DiscountDescDTO value = memberDiscountPriceMap . get ( shop . getShopId ( ) ) ;
List < CartSku > tmpSkuList = skus . stream ( ) . filter ( sku - > sku . getComposeId ( ) ! = null & & sku . getComposeId ( ) . equals ( id ) ) . collect ( Collectors . toList ( ) ) ;
List < CartSku > tmpSkuList = skus . stream ( ) . filter ( CartSku : : isUseMember ) . collect ( Collectors . toList ( ) ) ;
sortSkuList . addAll ( tmpSkuList ) ;
BigDecimal tmpTotal = BigDecimal . ZERO ;
for ( CartSku sku : tmpSkuList ) {
@ -2030,68 +2211,18 @@ public class CereShopOrderServiceImpl implements CereShopOrderService {
}
}
skuDiscountInfoMap . put ( tmpSkuList . get ( tmpSkuList . size ( ) - 1 ) . getSkuId ( ) , Arrays . asList ( String . format ( "组合捆绑 x %d" , value . getDiscountNum ( ) ) , "优惠¥" + value . getDiscountTotal ( ) ) ) ;
}
}
if ( shopIdSceneDiscountMap . get ( shop . getShopId ( ) ) ! = null ) {
DiscountDescDTO value = shopIdSceneDiscountMap . get ( shop . getShopId ( ) ) ;
List < CartSku > tmpSkuList = skus . stream ( ) . filter ( sku - > sku . getSceneId ( ) ! = null ) . collect ( Collectors . toList ( ) ) ;
/ * sortSkuList . addAll ( tmpSkuList ) ;
for ( CartSku sku : tmpSkuList ) {
total = total . add ( sku . getPrice ( ) . multiply ( new BigDecimal ( sku . getNumber ( ) ) ) ) ;
}
total = total . subtract ( value . getDiscountTotal ( ) ) ; * /
BigDecimal tmpTotal = BigDecimal . ZERO ;
for ( CartSku sku : tmpSkuList ) {
tmpTotal = tmpTotal . add ( sku . getPrice ( ) . multiply ( new BigDecimal ( sku . getNumber ( ) ) ) ) ;
skuDiscountInfoMap . put ( tmpSkuList . get ( tmpSkuList . size ( ) - 1 ) . getSkuId ( ) , Arrays . asList ( String . format ( "会员价 x %d" , value . getDiscountNum ( ) ) , "优惠¥" + value . getDiscountTotal ( ) ) ) ;
}
for ( CartSku sku : tmpSkuList ) {
Integer remainCredit = productRemainCreditMap . get ( sku . getProductId ( ) ) ;
if ( totalRemainCredit > 0 & & remainCredit > 0 ) {
BigDecimal percent = sku . getPrice ( ) . multiply ( new BigDecimal ( sku . getNumber ( ) ) ) . divide ( tmpTotal , 4 , BigDecimal . ROUND_HALF_UP ) ;
Integer needCredit = tmpTotal . subtract ( value . getDiscountTotal ( ) ) . multiply ( percent ) . divide ( creditExchangeRate , 0 , BigDecimal . ROUND_HALF_DOWN ) . intValue ( ) ;
if ( needCredit > 0 ) {
Integer min = Math . min ( remainCredit , totalRemainCredit ) ;
if ( min > = needCredit ) {
productRemainCreditMap . put ( sku . getProductId ( ) , remainCredit - needCredit ) ;
skuCreditMap . put ( sku . getSkuId ( ) , needCredit ) ;
totalRemainCredit - = needCredit ;
} else {
productRemainCreditMap . put ( sku . getProductId ( ) , remainCredit - min ) ;
skuCreditMap . put ( sku . getSkuId ( ) , min ) ;
totalRemainCredit - = min ;
}
}
}
}
skuDiscountInfoMap . put ( tmpSkuList . get ( tmpSkuList . size ( ) - 1 ) . getSkuId ( ) , Arrays . asList ( String . format ( "场景营销 %.1f折 x %d" , value . getDiscount ( ) , value . getDiscountNum ( ) ) , "优惠¥" + value . getDiscountTotal ( ) ) ) ;
}
if ( memberDiscountPriceMap . get ( shop . getShopId ( ) ) ! = null ) {
DiscountDescDTO value = memberDiscountPriceMap . get ( shop . getShopId ( ) ) ;
List < CartSku > tmpSkuList = skus . stream ( ) . filter ( CartSku : : isUseMember ) . collect ( Collectors . toList ( ) ) ;
sortSkuList . addAll ( tmpSkuList ) ;
BigDecimal tmpTotal = BigDecimal . ZERO ;
for ( CartSku sku : tmpSkuList ) {
/ / 剩下的就是普通的商品
skus . removeAll ( sortSkuList ) ;
for ( CartSku sku : skus ) {
total = total . add ( sku . getPrice ( ) . multiply ( new BigDecimal ( sku . getNumber ( ) ) ) ) ;
tmpTotal = tmpTotal . add ( sku . getPrice ( ) . multiply ( new BigDecimal ( sku . getNumber ( ) ) ) ) ;
}
total = total . subtract ( value . getDiscountTotal ( ) ) ;
for ( CartSku sku : tmpSkuList ) {
Integer remainCredit = productRemainCreditMap . get ( sku . getProductId ( ) ) ;
if ( totalRemainCredit > 0 & & remainCredit > 0 ) {
BigDecimal pe rcent = sku . getPrice ( ) . multiply ( new BigDecimal ( sku . getNumber ( ) ) ) . divide ( tmpTotal , 4 , BigDecimal . ROUND_HALF_UP ) ;
Integer needCredit = tm pTotal . subt ract ( value . getD is countTotal ( ) ) . multiply ( p ercent ) . divide ( creditExchangeRate , 0 , BigDecimal . ROUND_HALF_DOWN ) . intValue ( ) ;
BigDecimal price = sku . getPrice ( ) . multiply ( new BigDecimal ( sku . getNumber ( ) ) ) ;
Integer needCredit = price . divide ( creditExchangeRate , 0 , BigDecimal . ROUND_HALF_DOWN ) . intValue ( ) ;
if ( needCredit > 0 ) {
Integer min = Math . min ( remainCredit , totalRemainCredit ) ;
if ( min > = needCredit ) {
@ -2106,115 +2237,67 @@ public class CereShopOrderServiceImpl implements CereShopOrderService {
}
}
}
skuDiscountInfoMap . put ( tmpSkuList . get ( tmpSkuList . size ( ) - 1 ) . getSkuId ( ) , Arrays . asList ( String . format ( "会员价 x %d" , value . getDiscountNum ( ) ) , "优惠¥" + value . getDiscountTotal ( ) ) ) ;
}
/ / 剩下的就是普通的商品
skus . removeAll ( sortSkuList ) ;
for ( CartSku sku : skus ) {
total = total . add ( sku . getPrice ( ) . multiply ( new BigDecimal ( sku . getNumber ( ) ) ) ) ;
Integer remainCredit = productRemainCreditMap . get ( sku . getProductId ( ) ) ;
if ( totalRemainCredit > 0 & & remainCredit > 0 ) {
BigDecimal price = sku . getPrice ( ) . multiply ( new BigDecimal ( sku . getNumber ( ) ) ) ;
Integer needCredit = price . divide ( creditExchangeRate , 0 , BigDecimal . ROUND_HALF_DOWN ) . intValue ( ) ;
if ( needCredit > 0 ) {
Integer min = Math . min ( remainCredit , totalRemainCredit ) ;
if ( min > = needCredit ) {
productRemainCreditMap . put ( sku . getProductId ( ) , remainCredit - needCredit ) ;
skuCreditMap . put ( sku . getSkuId ( ) , needCredit ) ;
totalRemainCredit - = needCredit ;
} else {
productRemainCreditMap . put ( sku . getProductId ( ) , remainCredit - min ) ;
skuCreditMap . put ( sku . getSkuId ( ) , min ) ;
totalRemainCredit - = min ;
}
sortSkuList . addAll ( skus ) ;
settlementShop . setSkus ( sortSkuList ) ;
if ( flag . get ( ) ) {
SettlementShop settlementShop1 = new SettlementShop ( ) ;
settlementShop1 . setShopId ( shop . getShopId ( ) ) ;
settlementShop1 . setNumber ( invalidNumber ) ;
settlementShop1 . setSkus ( invalidSkus ) ;
invalidShops . add ( settlementShop1 ) ;
} else {
/ / 查询店铺物流方案
/ / 根据仓库来计算运费
List < CereOrderLogistics > logistics = logisticsList . stream ( ) . filter ( item - > shop . getShopId ( ) . equals ( item . getShopId ( ) ) & & storehouseId . equals ( item . getStorehouseId ( ) ) ) . collect ( Collectors . toList ( ) ) ;
List < CartSku > logisticsSkuList = sortSkuList ;
if ( sceneMarketFreeShipingMap . get ( shop . getShopId ( ) ) ! = null ) {
logisticsSkuList = sortSkuList . stream ( ) . filter ( sku - > sku . getSceneId ( ) = = null ) . collect ( Collectors . toList ( ) ) ;
}
}
}
sortSkuList . addAll ( skus ) ;
settlementShop . setSkus ( sortSkuList ) ;
/ / 定价捆绑查询出的商家优惠券要求同时匹配定价捆绑活动中的所有商品
/ * if ( productIdShopCouponIdMap . size ( ) > 0 ) {
Set < Long > couponIdSet = new HashSet < > ( ) ;
for ( List < Long > couponIdList : productIdShopCouponIdMap . values ( ) ) {
couponIdSet . addAll ( couponIdList ) ;
}
Collection < Long > intersection = new HashSet < > ( couponIdSet ) ;
for ( List < Long > couponIdList : productIdShopCouponIdMap . values ( ) ) {
intersection = CollectionUtils . intersection ( intersection , couponIdList ) ;
}
Collection < Long > finalIntersection = intersection ;
settlementShop . getShopCoupons ( ) . removeIf ( obj - > couponIdSet . contains ( obj . getCouponId ( ) ) & & ! finalIntersection . contains ( obj . getCouponId ( ) ) ) ;
for ( ProductCoupon coupon : settlementShop . getShopCoupons ( ) ) {
if ( settlementShop . getPriceAfterDiscount ( ) ! = null
& & coupon . getFullMoney ( ) . compareTo ( settlementShop . getPriceAfterDiscount ( ) ) > 0
& & coupon . getIds ( ) ! = null ) {
/ / 商家券不满足 满X元优惠的条件 , 直接去掉定价捆绑商品对应的商品id列表
coupon . getIds ( ) . removeAll ( productIdShopCouponIdMap . keySet ( ) ) ;
Distribution distribution = null ;
try {
distribution = setLogisticPrice ( logistics , logisticsSkuList , settlement . getReceive ( ) , numberMap ) ;
} catch ( CoBusinessException e ) {
throw new RuntimeException ( e ) ;
}
}
/ / 进一步判断 , 如果优惠券没有包含其它商品 , 直接移除掉这张优惠券
List < Long > shopProductIdList = settlementShop . getSkus ( ) . stream ( ) . map ( CartSku : : getProductId ) . collect ( Collectors . toList ( ) ) ;
Iterator < ProductCoupon > ite = settlementShop . getShopCoupons ( ) . iterator ( ) ;
while ( ite . hasNext ( ) ) {
ProductCoupon coupon = ite . next ( ) ;
Collection < Long > interProductIdList = CollectionUtils . intersection ( coupon . getIds ( ) , shopProductIdList ) ;
if ( CollectionUtils . isEmpty ( interProductIdList ) ) {
ite . remove ( ) ;
if ( distribution = = null ) {
settlementShop . setReceiveNotMatch ( true ) ;
distribution = new Distribution ( ) ;
distribution . setDistributionName ( "全国包邮" ) ;
distribution . setDistributionPrice ( BigDecimal . ZERO ) ;
distribution . setLogisticsId ( - 1L ) ;
settlementShop . setDistribution ( distribution ) ;
} else {
settlementShop . setDistribution ( distribution ) ;
}
}
} * /
if ( flag . get ( ) ) {
SettlementShop settlementShop1 = new SettlementShop ( ) ;
settlementShop1 . setShopId ( shop . getShopId ( ) ) ;
settlementShop1 . setNumber ( invalidNumber ) ;
settlementShop1 . setSkus ( invalidSkus ) ;
invalidShops . add ( settlementShop1 ) ;
} else {
/ / 查询店铺物流方案
List < CereOrderLogistics > logistics = cereOrderLogisticsService . findLogistics ( shop . getShopId ( ) ) ;
/ / 计算物流费用 如果场景营销中有包邮 , 则把包邮的sku过滤掉
List < CartSku > logisticsSkuList = sortSkuList ;
if ( sceneMarketFreeShipingMap . get ( shop . getShopId ( ) ) ! = null ) {
logisticsSkuList = sortSkuList . stream ( ) . filter ( sku - > sku . getSceneId ( ) = = null ) . collect ( Collectors . toList ( ) ) ;
}
Distribution distribution = setLogisticPrice ( logistics , logisticsSkuList , settlement . getReceive ( ) , numberMap ) ;
if ( distribution = = null ) {
settlementShop . setReceiveNotMatch ( true ) ;
distribution = new Distribution ( ) ;
distribution . setDistributionName ( "全国包邮" ) ;
distribution . setDistributionPrice ( BigDecimal . ZERO ) ;
distribution . setLogisticsId ( - 1L ) ;
settlementShop . setDistribution ( distribution ) ;
} else {
settlementShop . setDistribution ( distribution ) ;
}
}
}
}
}
settlementShop . setTotal ( total . setScale ( 2 , BigDecimal . ROUND_HALF_UP ) ) ;
canUseCouponProductIdList . addAll ( shopCanUseCouponProductIdList ) ;
/ / 设置商家优惠券
if ( CollectionUtils . isNotEmpty ( shopCanUseCouponProductIdList ) ) {
List < ProductCoupon > couponList = cereBuyerShopCouponService . findCouponMatchCondition ( user . getBuyerUserId ( ) , settlementShop . getTotal ( ) , shopCanUseCouponProductIdList ) ;
couponList . removeIf ( pc - > ! reMatchCoupon ( pc , Collections . singletonList ( settlementShop ) , shopPriceProductIdListMap ) ) ;
couponList . forEach ( this : : assembleContent ) ;
settlementShop . setShopCoupons ( couponList ) ;
}
/ / 计算订单总价
settlementShop . setTotal ( total . setScale ( 2 , BigDecimal . ROUND_HALF_UP ) ) ;
canUseCouponProductIdList . addAll ( shopCanUseCouponProductIdList ) ;
shopSettlementList . add ( settlementShop ) ;
/ / 设置商家优惠券
if ( CollectionUtils . isNotEmpty ( shopCanUseCouponProductIdList ) ) {
List < ProductCoupon > couponList = cereBuyerShopCouponService . findCouponMatchCondition ( user . getBuyerUserId ( ) , settlementShop . getTotal ( ) , shopCanUseCouponProductIdList ) ;
couponList . removeIf ( pc - > ! reMatchCoupon ( pc , Collections . singletonList ( settlementShop ) , shopPriceProductIdListMap ) ) ;
couponList . forEach ( this : : assembleContent ) ;
settlementShop . setShopCoupons ( couponList ) ;
}
shopSettlementList . add ( settlementShop ) ;
}
}
/ / 设置客户优惠券
if ( ! canUseCouponProductIdList . isEmpty ( ) ) {
/ / 整个订单最高价 只需要查询优惠券满额上限在这个一下的就可以了
BigDecimal totalPrice = shopSettlementList . stream ( ) . map ( SettlementShop : : getTotal ) . reduce ( BigDecimal . ZERO , BigDecimal : : add ) ;
/ / 查出满足订单总额的优惠券
List < ProductCoupon > couponList = cereBuyerCouponService . findCouponMatchCondition ( user . getBuyerUserId ( ) , totalPrice , canUseCouponProductIdList ) ;
/ / 分别判断每个优惠券 , 是否完全匹配商家的定价捆绑
if ( CollectionUtils . isNotEmpty ( couponList ) ) {
@ -3081,7 +3164,6 @@ public class CereShopOrderServiceImpl implements CereShopOrderService {
CereShopOrder shopOrder = cereShopOrderDAO . findById ( param . getOrderId ( ) ) ;
if ( shopOrder ! = null ) {
payUrl . setOrderId ( param . getOrderId ( ) ) ;
/ / TODO 这里需要获取父订单Id - - - - - - pxh
payUrl . setMoney ( shopOrder . getPrice ( ) ) ;
/ / 生成收款码
String formid = shopOrder . getOrderFormid ( ) + "-" + RandomStringUtil . getRandomCode ( 3 , 0 ) + "XCX" ;