@@ -23,6 +23,7 @@ import com.czg.enums.ShopUserFlowBizEnum;
import com.czg.exception.ApiNotPrintException ;
import com.czg.exception.CzgException ;
import com.czg.exception.OrderCancelException ;
import com.czg.exception.OrderValidateException ;
import com.czg.market.dto.MkDiscountActivityDTO ;
import com.czg.market.entity.MkDiscountThreshold ;
import com.czg.market.entity.MkShopCouponRecord ;
@@ -342,17 +343,17 @@ public class OrderInfoServiceImpl extends ServiceImpl<OrderInfoMapper, OrderInfo
ShopInfo shopInfo = shopInfoService . getById ( orderInfo . getShopId ( ) ) ;
AssertUtil . isNull ( shopInfo , " 生成订单失败,店铺信息不存在 " ) ;
if ( param . isVipPrice ( ) & & ! shopInfo . getIsMemberPrice ( ) . equals ( 1 ) ) {
throw new ValidateException ( " 生成订单失败,该店铺不支持使用会员价 " ) ;
throw new Order ValidateException( " 生成订单失败,该店铺不支持使用会员价 " ) ;
}
if ( param . getOrderAmount ( ) . compareTo ( BigDecimal . ZERO ) < 0 ) {
throw new ValidateException ( " 生成订单失败, 订单金额不能小于0 " ) ;
throw new Order ValidateException( " 生成订单失败, 订单金额不能小于0 " ) ;
}
log . info ( " 订单信息:{},优惠信息:{} " , JSONObject . toJSONString ( orderInfo ) , JSONObject . toJSONString ( param ) ) ;
Long shopId = orderInfo . getShopId ( ) ;
AssertUtil . isNull ( shopId , " 生成支付订单失败,订单信息异常 " ) ;
//霸王餐不参与满减
if ( param . isFreeDine ( ) & & param . getDiscountActId ( ) ! = null ) {
throw new ValidateException ( " 生成订单失败,霸王餐不能享受满减活动 " ) ;
throw new Order ValidateException( " 生成订单失败,霸王餐不能享受满减活动 " ) ;
}
MkDiscountActivityDTO discountAct = null ;
// 满减活动校验
@@ -368,30 +369,30 @@ public class OrderInfoServiceImpl extends ServiceImpl<OrderInfoMapper, OrderInfo
boolean usePointsDeduction = param . getPointsNum ( ) > 0 | | param . getPointsDiscountAmount ( ) . compareTo ( BigDecimal . ZERO ) > 0 ;
if ( usePointsDeduction ) {
if ( pointSetting = = null | | ! pointSetting . getEnableDeduction ( ) . equals ( 1 ) ) {
throw new ValidateException ( " 生成支付订单失败,该店铺未开启积分抵扣 " ) ;
throw new Order ValidateException( " 生成支付订单失败,该店铺未开启积分抵扣 " ) ;
}
if ( param . getUserId ( ) = = null ) {
throw new ValidateException ( " 生成支付订单失败,请选择用户后再使用积分抵扣 " ) ;
throw new Order ValidateException( " 生成支付订单失败,请选择用户后再使用积分抵扣 " ) ;
}
//霸王餐
if ( param . isFreeDine ( ) & & ! param . isWithPoints ( ) ) {
throw new ValidateException ( " 生成支付订单失败,霸王餐不支持积分抵扣 " ) ;
throw new Order ValidateException( " 生成支付订单失败,霸王餐不支持积分抵扣 " ) ;
}
} else {
if ( param . getPointsNum ( ) ! = 0 | | param . getPointsDiscountAmount ( ) . compareTo ( BigDecimal . ZERO ) ! = 0 ) {
throw new ValidateException ( " 生成支付订单失败,积分抵扣数量或金额不正确 " ) ;
throw new Order ValidateException( " 生成支付订单失败,积分抵扣数量或金额不正确 " ) ;
}
}
if ( param . getPointsNum ( ) > 0 & & ( ! param . isFreeDine ( ) | | param . isWithPoints ( ) ) ) {
if ( pointSetting = = null | | ! pointSetting . getEnableDeduction ( ) . equals ( 1 ) ) {
throw new ValidateException ( " 生成支付订单失败,该店铺未开启积分抵扣 " ) ;
throw new Order ValidateException( " 生成支付订单失败,该店铺未开启积分抵扣 " ) ;
}
if ( param . getUserId ( ) = = null ) {
throw new ValidateException ( " 生成支付订单失败,请选择用户后再使用积分抵扣 " ) ;
throw new Order ValidateException( " 生成支付订单失败,请选择用户后再使用积分抵扣 " ) ;
}
} else if ( param . getPointsDiscountAmount ( ) . compareTo ( BigDecimal . ZERO ) > 0 ) {
throw new ValidateException ( " 生成支付订单失败,已使用积分抵扣,积分数量不正确 " ) ;
throw new Order ValidateException( " 生成支付订单失败,已使用积分抵扣,积分数量不正确 " ) ;
}
ShopUser shopUser = null ;
if ( param . getUserId ( ) ! = null ) {
@@ -399,14 +400,14 @@ public class OrderInfoServiceImpl extends ServiceImpl<OrderInfoMapper, OrderInfo
AssertUtil . isNull ( userInfo , " 生成支付订单失败,用户信息不存在 " ) ;
shopUser = shopUserService . getShopUserInfo ( shopId , param . getUserId ( ) ) ;
if ( param . getPointsNum ( ) > 0 & & ! shopUser . getIsVip ( ) . equals ( 1 ) & & pointSetting . getDeductionGroup ( ) . contains ( " vip " ) ) {
throw new ValidateException ( " 生成支付订单失败,该店铺仅会员可使用积分抵扣 " ) ;
throw new Order ValidateException( " 生成支付订单失败,该店铺仅会员可使用积分抵扣 " ) ;
}
orderInfo . setUserId ( userInfo . getId ( ) ) ;
}
//会员价校验
if ( param . isVipPrice ( ) & & ( shopUser = = null | | shopUser . getIsMemberPrice ( ) = = null
| | shopUser . getIsMemberPrice ( ) = = 0 | | shopUser . getIsVip ( ) . equals ( 0 ) ) ) {
throw new ValidateException ( " 生成支付订单失败,仅会员可使用会员价 " ) ;
throw new Order ValidateException( " 生成支付订单失败,仅会员可使用会员价 " ) ;
}
List < OrderDetail > orderDetails = orderDetailService . queryChain ( ) . eq ( OrderDetail : : getOrderId , param . getOrderId ( ) ) . select ( ) . list ( ) ;
@@ -430,7 +431,7 @@ public class OrderInfoServiceImpl extends ServiceImpl<OrderInfoMapper, OrderInfo
param . isAllPack ( ) , param . getUserAllPack ( ) , param . isVipPrice ( ) ) ;
if ( totalAmount . getPrice ( ) . compareTo ( param . getOriginAmount ( ) ) ! = 0 ) {
log . info ( " 订单原价不正确:订单原价:{},传递为:{} " , totalAmount . getPrice ( ) , param . getOriginAmount ( ) ) ;
throw new ValidateException ( " 生成支付订单失败,订单原金额不正确 " ) ;
throw new Order ValidateException( " 生成支付订单失败,订单原金额不正确 " ) ;
}
//优惠券部分 目前规则 每个券只能用一张
@@ -450,7 +451,7 @@ public class OrderInfoServiceImpl extends ServiceImpl<OrderInfoMapper, OrderInfo
if ( param . getOriginAmount ( ) . subtract ( param . getProductCouponDiscountAmount ( ) ) . subtract ( param . getOtherCouponDiscountAmount ( ) ) . compareTo ( newTotalAmount ) ! = 0 ) {
log . info ( " 其它优惠券金额不正确:满减金额为:{},折扣金额为:{},买一赠一金额为:{},第二件半价券金额为:{} 传递为:{} " ,
fullReductionAmount . getPrice ( ) , rateAmount . getPrice ( ) , oneGiftAmount . getPrice ( ) , twoHalfAmount . getPrice ( ) , param . getOtherCouponDiscountAmount ( ) ) ;
throw new ValidateException ( " 生成支付订单失败,其它优惠券金额不正确 " ) ;
throw new Order ValidateException( " 生成支付订单失败,其它优惠券金额不正确 " ) ;
}
if ( newTotalAmount . compareTo ( BigDecimal . ZERO ) < = 0 ) {
newTotalAmount = BigDecimal . ZERO ;
@@ -477,7 +478,7 @@ public class OrderInfoServiceImpl extends ServiceImpl<OrderInfoMapper, OrderInfo
BigDecimal discountActAmount = calculateDiscountActAmount ( orderDetails , discountAct , packAmount . getPrice ( ) , orderInfo . getSeatAmount ( ) ) ;
if ( discountActAmount . compareTo ( param . getDiscountActAmount ( ) ) ! = 0 ) {
log . info ( " 满减活动金额不正确:传递为:{},计算为:{} " , param . getDiscountActAmount ( ) , discountActAmount ) ;
throw new ValidateException ( " 生成支付订单失败,满减活动金额不正确 " ) ;
throw new Order ValidateException( " 生成支付订单失败,满减活动金额不正确 " ) ;
}
newTotalAmount = newTotalAmount . subtract ( discountActAmount ) ;
@@ -491,7 +492,7 @@ public class OrderInfoServiceImpl extends ServiceImpl<OrderInfoMapper, OrderInfo
discountAmount = discountAmount . setScale ( 2 , RoundingMode . HALF_UP ) ;
if ( discountAmount . compareTo ( param . getVipDiscountAmount ( ) ) ! = 0 ) {
log . info ( " 会员整单折扣金额不正确:传递为:{},计算为:{} " , param . getVipDiscountAmount ( ) , discountAmount ) ;
throw new ValidateException ( " 生成支付订单失败,会员整单折扣金额不正确 " ) ;
throw new Order ValidateException( " 生成支付订单失败,会员整单折扣金额不正确 " ) ;
}
newTotalAmount = newTotalAmount . subtract ( discountAmount ) ;
}
@@ -499,14 +500,14 @@ public class OrderInfoServiceImpl extends ServiceImpl<OrderInfoMapper, OrderInfo
//积分抵扣 金额范围校验 抵扣金额校验
if ( param . getPointsNum ( ) > 0 ) {
if ( pointSetting . getMinPaymentAmount ( ) . compareTo ( newTotalAmount ) > 0 ) {
throw new ValidateException ( " 生成支付订单失败,未满足积分抵扣最低门槛 " ) ;
throw new Order ValidateException( " 生成支付订单失败,未满足积分抵扣最低门槛 " ) ;
}
if ( pointSetting . getMaxDeductionRatio ( ) . multiply ( newTotalAmount ) . compareTo ( param . getPointsDiscountAmount ( ) ) < 0 ) {
throw new ValidateException ( " 生成支付订单失败,积分抵扣金额已超出最大抵扣金额 " ) ;
throw new Order ValidateException( " 生成支付订单失败,积分抵扣金额已超出最大抵扣金额 " ) ;
}
BigDecimal pointAmount = new BigDecimal ( param . getPointsNum ( ) ) . divide ( new BigDecimal ( pointSetting . getEquivalentPoints ( ) ) , 2 , RoundingMode . DOWN ) ;
if ( pointAmount . compareTo ( param . getPointsDiscountAmount ( ) ) ! = 0 ) {
throw new ValidateException ( " 生成支付订单失败,积分抵扣金额不正确 " ) ;
throw new Order ValidateException( " 生成支付订单失败,积分抵扣金额不正确 " ) ;
}
newTotalAmount = newTotalAmount . subtract ( param . getPointsDiscountAmount ( ) ) ;
}
@@ -529,7 +530,7 @@ public class OrderInfoServiceImpl extends ServiceImpl<OrderInfoMapper, OrderInfo
orderInfo . getId ( ) , newTotalAmount , totalAmount . getPrice ( ) , tempAmount . getPrice ( ) , packAmount . getPrice ( ) , orderInfo . getSeatAmount ( ) ,
param . getOrderAmount ( ) , param . getProductCouponDiscountAmount ( ) , param . getOtherCouponDiscountAmount ( ) , param . getNewCustomerDiscountAmount ( ) ,
discountActAmount , param . getDiscountAmount ( ) , param . getPointsDiscountAmount ( ) , param . getRoundAmount ( ) ) ;
throw new ValidateException ( " 生成支付订单失败,支付金额不正确 " ) ;
throw new Order ValidateException( " 生成支付订单失败,支付金额不正确 " ) ;
}
orderInfo . setPackFee ( packAmount . getPrice ( ) ) ;
//生成订单 //discount_info 所有折扣 几折 折扣金额 满减金额 优惠券金额 积分抵扣金额 抹零
@@ -607,7 +608,7 @@ public class OrderInfoServiceImpl extends ServiceImpl<OrderInfoMapper, OrderInfo
couponRecordQuery . ne ( MkShopCouponRecord : : getIsDel , 1 ) ;
List < MkShopCouponRecord > list = couponRecordService . list ( couponRecordQuery ) ;
if ( CollUtil . isEmpty ( list ) | | param . getCouponList ( ) . size ( ) > list . size ( ) ) {
throw new ValidateException ( " 生成支付订单失败,优惠券不可用 " ) ;
throw new Order ValidateException( " 生成支付订单失败,优惠券不可用 " ) ;
}
Map < Integer , MkShopCouponRecord > couponRecordMap = list . stream ( ) . collect ( Collectors . toMap ( MkShopCouponRecord : : getType , t - > t ) ) ;
AtomicBoolean otherCouponShare = new AtomicBoolean ( true ) ;
@@ -636,7 +637,7 @@ public class OrderInfoServiceImpl extends ServiceImpl<OrderInfoMapper, OrderInfo
" price_asc " . equals ( coupon . getUseRule ( ) ) , prodCouponAmount ) ;
} else if ( type = = 4 | | type = = 6 ) { //4-第二件半价券, 6-买一送一券
if ( ! otherCouponShare . get ( ) ) {
throw new ValidateException ( " 生成支付订单失败,商品券与其它券不可共用 " ) ;
throw new Order ValidateException( " 生成支付订单失败,商品券与其它券不可共用 " ) ;
}
boolean isAllFoods = true ;
List < Long > couponFoodIds = new ArrayList < > ( ) ;
@@ -653,7 +654,7 @@ public class OrderInfoServiceImpl extends ServiceImpl<OrderInfoMapper, OrderInfo
}
} else if ( type = = 1 | | type = = 3 ) { //1-满减券 3-折扣券
if ( ! otherCouponShare . get ( ) ) {
throw new ValidateException ( " 生成支付订单失败,商品券与其它券不可共用 " ) ;
throw new Order ValidateException( " 生成支付订单失败,商品券与其它券不可共用 " ) ;
}
//计算门槛
boolean isAllFoods = true ;
@@ -681,7 +682,7 @@ public class OrderInfoServiceImpl extends ServiceImpl<OrderInfoMapper, OrderInfo
}
if ( prodCouponAmount . getPrice ( ) . compareTo ( param . getProductCouponDiscountAmount ( ) ) ! = 0 ) {
log . info ( " 支付计算金额不正确:商品券抵扣金额为:{},传递为:{} " , prodCouponAmount . getPrice ( ) , param . getProductCouponDiscountAmount ( ) ) ;
throw new ValidateException ( " 生成支付订单失败,商品优惠券优惠金额不正确 " ) ;
throw new Order ValidateException( " 生成支付订单失败,商品优惠券优惠金额不正确 " ) ;
}
}
@@ -939,10 +940,10 @@ public class OrderInfoServiceImpl extends ServiceImpl<OrderInfoMapper, OrderInfo
} else {
if ( orderDetail . getIsTimeDiscount ( ) = = 1 ) {
if ( limitRate = = null | | ( limitRate . getFoodType ( ) = = 2 & & CollUtil . isEmpty ( limitRate . getFoodIds ( ) ) ) ) {
throw new Czg Exception( " 限时折扣使用失败,商品范围不正确 " ) ;
throw new OrderValidate Exception( " 限时折扣使用失败,商品范围不正确 " ) ;
}
if ( limitRate . getFoodType ( ) = = 2 & & ! limitRate . getFoodIds ( ) . contains ( orderDetail . getProductId ( ) ) ) {
throw new Czg Exception( " 限时折扣使用失败,商品 " + orderDetail . getProductName ( ) + " 不享受限时折扣 " ) ;
throw new OrderValidate Exception( " 限时折扣使用失败,商品 " + orderDetail . getProductName ( ) + " 不享受限时折扣 " ) ;
}
if ( orderDetail . getPrice ( ) . compareTo ( BigDecimal . ZERO ) = = 0 ) {
orderDetail . setUnitPrice ( orderDetail . getPrice ( ) ) ;