|
|
|
@@ -565,7 +565,7 @@ public class WxOrderServiceImpl implements WxOrderService { |
|
|
|
* @param couponIdStr |
|
|
|
*/ |
|
|
|
@Transactional(propagation = Propagation.REQUIRED, readOnly = false, rollbackFor = {Exception.class}) |
|
|
|
public void stockReduce(WxCUserBasicInfo user, WxCoupon coupon, String couponIdStr,int number) { |
|
|
|
public void stockReduce(boolean allowUnPayOrder,WxCUserBasicInfo user, WxCoupon coupon, String couponIdStr,int number) { |
|
|
|
//如果缓存中不存在这个key,则从coupon中取 |
|
|
|
if(!redisLock.hasCouponStockCache(coupon.getId())) { |
|
|
|
//此处需要加锁,防止并发设置 |
|
|
|
@@ -606,16 +606,18 @@ public class WxOrderServiceImpl implements WxOrderService { |
|
|
|
int count = 0; |
|
|
|
// 有价券 |
|
|
|
if (coupon.getSalePrice() > 0) { |
|
|
|
// 检查是否未支付订单 |
|
|
|
try { |
|
|
|
count = getUserOrderCount(user, coupon); |
|
|
|
} catch (Exception e) { |
|
|
|
throw new MallinkException(ErrorCode.DB_FAIL.getCode(),"["+coupon.getTitle()+"]查询未支付订单失败."); |
|
|
|
} |
|
|
|
if (count > 0) { |
|
|
|
logger.error("此券有未支付的订单, couponId: " + couponIdStr + ", count: " + count); |
|
|
|
throw new MallinkException(ErrorCode.ORDER_UNPAID.getCode(),"["+coupon.getTitle()+"]您有未支付的订单."); |
|
|
|
} |
|
|
|
if (!allowUnPayOrder) { |
|
|
|
// 检查是否未支付订单 |
|
|
|
try { |
|
|
|
count = getUserOrderCount(user, coupon); |
|
|
|
} catch (Exception e) { |
|
|
|
throw new MallinkException(ErrorCode.DB_FAIL.getCode(),"["+coupon.getTitle()+"]查询未支付订单失败."); |
|
|
|
} |
|
|
|
if (count > 0) { |
|
|
|
logger.error("此券有未支付的订单, couponId: " + couponIdStr + ", count: " + count); |
|
|
|
throw new MallinkException(ErrorCode.ORDER_UNPAID.getCode(),"["+coupon.getTitle()+"]您有未支付的订单."); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
//检查拼团中的数量 |
|
|
|
try { |
|
|
|
@@ -1297,7 +1299,7 @@ public class WxOrderServiceImpl implements WxOrderService { |
|
|
|
} else { |
|
|
|
// 减库存操作 |
|
|
|
try { |
|
|
|
stockReduce(user, coupon, couponIdStr,1); |
|
|
|
stockReduce(false,user, coupon, couponIdStr,1); |
|
|
|
}catch(Exception e) { |
|
|
|
throw new MallinkException(ErrorCode.COUPON_STOCK_ERR.getCode(), e.getMessage()); |
|
|
|
} |
|
|
|
@@ -1990,7 +1992,7 @@ public class WxOrderServiceImpl implements WxOrderService { |
|
|
|
|
|
|
|
@Transactional(propagation = Propagation.REQUIRED, readOnly = false, rollbackFor = {Exception.class}) |
|
|
|
@Override |
|
|
|
public WxComposeOrder saveOrderForCoupon(EnumComposeOrder composeOrderType,WxCUserBasicInfo user,List<OrderComposeSaveDto> orderSave,EnumPayWay payWay) { |
|
|
|
public WxComposeOrder saveOrderForCoupon(boolean allowUnPayOrder,EnumComposeOrder composeOrderType,WxCUserBasicInfo user,List<OrderComposeSaveDto> orderSave,EnumPayWay payWay) { |
|
|
|
WxOrderServiceImpl proxy = (WxOrderServiceImpl) AopContext.currentProxy(); |
|
|
|
// 防止同一用户重复下单,1秒内 |
|
|
|
String key = new StringBuilder().append("saveComposeOrder:").append(user.getId()).toString(); |
|
|
|
@@ -2011,10 +2013,10 @@ public class WxOrderServiceImpl implements WxOrderService { |
|
|
|
boolean isOneNumberOneOrder = orderAdapterService.isOneNumberOneOrder(); |
|
|
|
if (isOneNumberOneOrder) { |
|
|
|
for (int j = 0; j < orderdto.getCount(); j++) { |
|
|
|
lastOrder = proxy.handleSaveOrderForCouponSingle(composeOrder, user, orderdto.getWxCoupon(), 1, orderdto, payWay); |
|
|
|
lastOrder = proxy.handleSaveOrderForCouponSingle(allowUnPayOrder,composeOrder, user, orderdto.getWxCoupon(), 1, orderdto, payWay); |
|
|
|
} |
|
|
|
}else { |
|
|
|
lastOrder = proxy.handleSaveOrderForCouponSingle(composeOrder, user, orderdto.getWxCoupon(), orderdto.getCount(), orderdto, payWay); |
|
|
|
lastOrder = proxy.handleSaveOrderForCouponSingle(allowUnPayOrder,composeOrder, user, orderdto.getWxCoupon(), orderdto.getCount(), orderdto, payWay); |
|
|
|
} |
|
|
|
} |
|
|
|
//如果没有orderId,则用lastOrder的信息 |
|
|
|
@@ -2025,13 +2027,13 @@ public class WxOrderServiceImpl implements WxOrderService { |
|
|
|
} |
|
|
|
|
|
|
|
@Transactional(propagation = Propagation.REQUIRED, readOnly = false, rollbackFor = {Exception.class}) |
|
|
|
public WxOrder handleSaveOrderForCouponSingle(WxComposeOrder composeOrder,WxCUserBasicInfo user,WxCoupon coupon,int perCouponNumber,OrderComposeSaveDto orderdto,EnumPayWay payWay) { |
|
|
|
public WxOrder handleSaveOrderForCouponSingle(boolean allowUnPayOrder,WxComposeOrder composeOrder,WxCUserBasicInfo user,WxCoupon coupon,int perCouponNumber,OrderComposeSaveDto orderdto,EnumPayWay payWay) { |
|
|
|
WxOrderServiceImpl proxy = (WxOrderServiceImpl) AopContext.currentProxy(); |
|
|
|
// 是否砍价 |
|
|
|
WxOrder order = null; |
|
|
|
if (checkCouponIsFree(coupon,orderdto.getShippingType())) { |
|
|
|
// 免费券 |
|
|
|
order = proxy.saveFreeOrderForCoupon(composeOrder,user, coupon,perCouponNumber,orderdto.getSignleOrder().getCouponChannelId(), |
|
|
|
order = proxy.saveFreeOrderForCoupon(allowUnPayOrder,composeOrder,user, coupon,perCouponNumber,orderdto.getSignleOrder().getCouponChannelId(), |
|
|
|
orderdto.getSignleOrder().getFormId(),null,payWay,orderdto.getShippingType(),orderdto.getAddress()); |
|
|
|
if (order != null) { |
|
|
|
// 6. 下订单完成,发送内部消息 |
|
|
|
@@ -2045,7 +2047,7 @@ public class WxOrderServiceImpl implements WxOrderService { |
|
|
|
} |
|
|
|
} else { |
|
|
|
// 有价券 |
|
|
|
order = proxy.saveNoFreeOrderForCoupon(composeOrder,user, orderdto.getWxCoupon(),perCouponNumber, orderdto); |
|
|
|
order = proxy.saveNoFreeOrderForCoupon(allowUnPayOrder,composeOrder,user, orderdto.getWxCoupon(),perCouponNumber, orderdto); |
|
|
|
} |
|
|
|
// couponActionLog |
|
|
|
// try { |
|
|
|
@@ -2070,13 +2072,13 @@ public class WxOrderServiceImpl implements WxOrderService { |
|
|
|
|
|
|
|
@Transactional(propagation = Propagation.REQUIRED, readOnly = false, rollbackFor = {Exception.class}) |
|
|
|
@Override |
|
|
|
public WxOrder saveFreeOrderForCoupon(WxComposeOrder composeOrder,WxCUserBasicInfo user, WxCoupon coupon,int couponNumber, |
|
|
|
public WxOrder saveFreeOrderForCoupon(boolean allowUnPayOrder,WxComposeOrder composeOrder,WxCUserBasicInfo user, WxCoupon coupon,int couponNumber, |
|
|
|
Long couponChannelId, String formId, Long couponPasswordId,EnumPayWay payWay, |
|
|
|
Integer shippingType, UserBasicInfoAddress address) { |
|
|
|
WxOrderServiceImpl proxy = (WxOrderServiceImpl) AopContext.currentProxy(); |
|
|
|
// 减库存操作 |
|
|
|
String couponIdStr = String.valueOf(coupon.getId()); |
|
|
|
proxy.stockReduce(user, coupon, couponIdStr,couponNumber); |
|
|
|
proxy.stockReduce(allowUnPayOrder,user, coupon, couponIdStr,couponNumber); |
|
|
|
|
|
|
|
// 当积分券或者积分停车券时 则进行积分支付 |
|
|
|
Integer orderType; |
|
|
|
@@ -2131,11 +2133,11 @@ public class WxOrderServiceImpl implements WxOrderService { |
|
|
|
|
|
|
|
@Override |
|
|
|
@Transactional(propagation = Propagation.REQUIRED, readOnly = false, rollbackFor = {Exception.class}) |
|
|
|
public WxOrder saveNoFreeOrderForCoupon(WxComposeOrder composeOrder,WxCUserBasicInfo user, WxCoupon coupon,int couponNumber,OrderComposeSaveDto orderdto) { |
|
|
|
public WxOrder saveNoFreeOrderForCoupon(boolean allowUnPayOrder,WxComposeOrder composeOrder,WxCUserBasicInfo user, WxCoupon coupon,int couponNumber,OrderComposeSaveDto orderdto) { |
|
|
|
WxOrderServiceImpl proxy = (WxOrderServiceImpl) AopContext.currentProxy(); |
|
|
|
String couponIdStr = String.valueOf(coupon.getId()); |
|
|
|
// 3. 减库存操作 |
|
|
|
proxy.stockReduce(user, coupon, couponIdStr,couponNumber); |
|
|
|
proxy.stockReduce(allowUnPayOrder,user, coupon, couponIdStr,couponNumber); |
|
|
|
|
|
|
|
// 3. 当积分券或者积分停车券时 则进行积分支付 |
|
|
|
Integer orderType; |
|
|
|
@@ -2210,7 +2212,7 @@ public class WxOrderServiceImpl implements WxOrderService { |
|
|
|
} |
|
|
|
// 2. 减库存操作 |
|
|
|
String couponIdStr = String.valueOf(coupon.getId()); |
|
|
|
stockReduce(user, coupon, couponIdStr,1); |
|
|
|
stockReduce(false,user, coupon, couponIdStr,1); |
|
|
|
|
|
|
|
// 3. 当积分券或者积分停车券时 则进行积分支付 |
|
|
|
Integer orderType; |
|
|
|
@@ -2469,7 +2471,7 @@ public class WxOrderServiceImpl implements WxOrderService { |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
public ResultData composeSaveOrder(EnumComposeOrder composeOrderType,List<OrderComposeSaveDto> composeOrderSaveDto,Long cUserId,EnumPayWay payWay,TenantEntity tenantEntity) { |
|
|
|
public ResultData composeSaveOrder(boolean allowUnPayOrder,EnumComposeOrder composeOrderType,List<OrderComposeSaveDto> composeOrderSaveDto,Long cUserId,EnumPayWay payWay,TenantEntity tenantEntity) { |
|
|
|
try { |
|
|
|
if (null == composeOrderSaveDto || composeOrderSaveDto.size() <= 0 ) { |
|
|
|
return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(),"无商品信息"); |
|
|
|
@@ -2493,7 +2495,7 @@ public class WxOrderServiceImpl implements WxOrderService { |
|
|
|
} |
|
|
|
WxOrderServiceImpl proxy = (WxOrderServiceImpl) AopContext.currentProxy(); |
|
|
|
try { |
|
|
|
WxComposeOrder order = proxy.saveOrderForCoupon(composeOrderType,wxCUserBasicInfo, composeOrderSaveDto, payWay); |
|
|
|
WxComposeOrder order = proxy.saveOrderForCoupon(allowUnPayOrder,composeOrderType,wxCUserBasicInfo, composeOrderSaveDto, payWay); |
|
|
|
return new ResultData(order); |
|
|
|
} catch (MallinkException e) { |
|
|
|
logger.error("saveOrderForCoupon error.",e); |
|
|
|
|