|
|
|
@@ -1498,71 +1498,80 @@ public class WxOrderServiceImpl implements WxOrderService { |
|
|
|
/// 储值卡信息添加 |
|
|
|
if (isCard) { |
|
|
|
Integer fee = 0; |
|
|
|
WxCardInfo cardInfo = new WxCardInfo(); |
|
|
|
cardInfo.setId(couponOrder.getId()); |
|
|
|
cardInfo.updateTenantInfo(order); |
|
|
|
cardInfo.setCouponId(order.getProductId()); |
|
|
|
cardInfo.setAmount(coupon.getPrice()); |
|
|
|
cardInfo.setRemainingAmount(coupon.getPrice()); |
|
|
|
cardInfo.setSaleAmount(coupon.getSalePrice()); |
|
|
|
if (null != couponPassWord) { |
|
|
|
cardInfo.setCouponPasswordId(couponPassWord.getId()); |
|
|
|
cardInfo.setCouponPassword(couponPassWord.getPassword()); |
|
|
|
//后置卡券可能没有面额 |
|
|
|
cardInfo.setAmount(couponPassWord.getPrice()); |
|
|
|
cardInfo.setRemainingAmount(couponPassWord.getPrice()); |
|
|
|
} |
|
|
|
cardInfo.setCUserId(user.getId()); |
|
|
|
cardInfo.setOwnerUserId(user.getId()); |
|
|
|
if (!coupon.checkIsFree()) { |
|
|
|
//判断该transctionId是否已经存在,如果存在,则不添加 |
|
|
|
WxCardInfo cardInfoq = new WxCardInfo(); |
|
|
|
cardInfoq.setTransactionId(payOrder.getTransactionId()); |
|
|
|
List<WxCardInfo> cardInfoList = wxCardInfoMapper.findList(cardInfoq); |
|
|
|
if (null != cardInfoList && cardInfoList.size() > 0) { |
|
|
|
//do nothing |
|
|
|
}else { |
|
|
|
WxAppinfo cAppInfo = wxAppinfoService.getCAppInfoFromRedis(cardInfo.getTenantId(), EnumAppPlat.WX); |
|
|
|
if(cAppInfo == null){ |
|
|
|
throw new MallinkException(ErrorCode.APP_ID_NOT_FOUND); |
|
|
|
} |
|
|
|
WxPayAccount payAccount = wxPayAccountService.getByIdFromRedis(cAppInfo.getPayId()); |
|
|
|
if(payAccount == null){ |
|
|
|
throw new MallinkException(ErrorCode.API_KEY_NOT_FOUND); |
|
|
|
} |
|
|
|
// 有价卡 |
|
|
|
cardInfo.setTransactionId(payOrder.getTransactionId()); |
|
|
|
WxComposeChildOrderShare share = payOrder.getChildOrderShare(order.getId()); |
|
|
|
fee = OrderHelper.getRealRateAmount(share.getRealPayMent(), payAccount); |
|
|
|
Integer shareAmount = share.getRealPayMent() - fee; |
|
|
|
cardInfo.setShareFeeAmount(shareAmount); |
|
|
|
cardInfo.setRemainingShareFeeAmount(shareAmount); |
|
|
|
cardInfo.setRateAmount(0); |
|
|
|
} |
|
|
|
} else { |
|
|
|
// 免费卡 |
|
|
|
cardInfo.setShareFeeAmount(0); |
|
|
|
cardInfo.setRemainingShareFeeAmount(0); |
|
|
|
cardInfo.setRateAmount(0); |
|
|
|
if (coupon.getPasswordSupport().equals(EnumCouponPasswordSupport.SUPPORTED.getCode())) { |
|
|
|
WxCouponPassword updateCPwd = new WxCouponPassword(); |
|
|
|
updateCPwd.setId(couponPassWord.getId()); |
|
|
|
updateCPwd.setCardId(cardInfo.getId()); |
|
|
|
updateCPwd.setStatus(EnumCouponPasswordStatus.USED.getCode()); |
|
|
|
couponPasswordMapper.updateById(updateCPwd); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
cardInfo.setServiceFeeAmount(fee); |
|
|
|
cardInfo.setCreateDate(curr); |
|
|
|
cardInfo.setUpdateDate(curr); |
|
|
|
cardInfo.setSupportTransfer(coupon.getSupportTransfer()); |
|
|
|
//检查卡是否下架,如果是,不可转赠 |
|
|
|
WxCouponChannel wxCouponChannel = wxCouponChannelMapper.selectById(order.getCouponChannelId(),order.getTenantId()); |
|
|
|
if (wxCouponChannel != null && wxCouponChannel.getStatus().equals(EnumCouponChannelStatus.STATUS_TAKE_OFFF.getCode())) { |
|
|
|
cardInfo.setSupportTransfer(EnumCouponTransfer.NO.getCode()); |
|
|
|
} |
|
|
|
wxCardInfoMapper.insert(cardInfo); |
|
|
|
WxCardInfo cardInfo = null; |
|
|
|
if (null != couponPassWord && couponPassWord.isDefaultUser()) { |
|
|
|
cardInfo = couponPassWord.getWxCardInfo(); |
|
|
|
cardInfo.setUpdateDate(curr); |
|
|
|
cardInfo.setOwnerUserId(user.getId()); |
|
|
|
cardInfo.setCUserId(user.getId()); |
|
|
|
wxCardInfoMapper.updateById(cardInfo); |
|
|
|
}else { |
|
|
|
cardInfo = new WxCardInfo(); |
|
|
|
cardInfo.setId(couponOrder.getId()); |
|
|
|
cardInfo.updateTenantInfo(order); |
|
|
|
cardInfo.setCouponId(order.getProductId()); |
|
|
|
cardInfo.setAmount(coupon.getPrice()); |
|
|
|
cardInfo.setRemainingAmount(coupon.getPrice()); |
|
|
|
cardInfo.setSaleAmount(coupon.getSalePrice()); |
|
|
|
if (null != couponPassWord) { |
|
|
|
cardInfo.setCouponPasswordId(couponPassWord.getId()); |
|
|
|
cardInfo.setCouponPassword(couponPassWord.getPassword()); |
|
|
|
//后置卡券可能没有面额 |
|
|
|
cardInfo.setAmount(couponPassWord.getPrice()); |
|
|
|
cardInfo.setRemainingAmount(couponPassWord.getPrice()); |
|
|
|
} |
|
|
|
cardInfo.setCUserId(user.getId()); |
|
|
|
cardInfo.setOwnerUserId(user.getId()); |
|
|
|
if (!coupon.checkIsFree()) { |
|
|
|
//判断该transctionId是否已经存在,如果存在,则不添加 |
|
|
|
WxCardInfo cardInfoq = new WxCardInfo(); |
|
|
|
cardInfoq.setTransactionId(payOrder.getTransactionId()); |
|
|
|
List<WxCardInfo> cardInfoList = wxCardInfoMapper.findList(cardInfoq); |
|
|
|
if (null != cardInfoList && cardInfoList.size() > 0) { |
|
|
|
//do nothing |
|
|
|
}else { |
|
|
|
WxAppinfo cAppInfo = wxAppinfoService.getCAppInfoFromRedis(cardInfo.getTenantId(), EnumAppPlat.WX); |
|
|
|
if(cAppInfo == null){ |
|
|
|
throw new MallinkException(ErrorCode.APP_ID_NOT_FOUND); |
|
|
|
} |
|
|
|
WxPayAccount payAccount = wxPayAccountService.getByIdFromRedis(cAppInfo.getPayId()); |
|
|
|
if(payAccount == null){ |
|
|
|
throw new MallinkException(ErrorCode.API_KEY_NOT_FOUND); |
|
|
|
} |
|
|
|
// 有价卡 |
|
|
|
cardInfo.setTransactionId(payOrder.getTransactionId()); |
|
|
|
WxComposeChildOrderShare share = payOrder.getChildOrderShare(order.getId()); |
|
|
|
fee = OrderHelper.getRealRateAmount(share.getRealPayMent(), payAccount); |
|
|
|
Integer shareAmount = share.getRealPayMent() - fee; |
|
|
|
cardInfo.setShareFeeAmount(shareAmount); |
|
|
|
cardInfo.setRemainingShareFeeAmount(shareAmount); |
|
|
|
cardInfo.setRateAmount(0); |
|
|
|
} |
|
|
|
} else { |
|
|
|
// 免费卡 |
|
|
|
cardInfo.setShareFeeAmount(0); |
|
|
|
cardInfo.setRemainingShareFeeAmount(0); |
|
|
|
cardInfo.setRateAmount(0); |
|
|
|
if (coupon.getPasswordSupport().equals(EnumCouponPasswordSupport.SUPPORTED.getCode())) { |
|
|
|
WxCouponPassword updateCPwd = new WxCouponPassword(); |
|
|
|
updateCPwd.setId(couponPassWord.getId()); |
|
|
|
updateCPwd.setCardId(cardInfo.getId()); |
|
|
|
updateCPwd.setStatus(EnumCouponPasswordStatus.USED.getCode()); |
|
|
|
couponPasswordMapper.updateById(updateCPwd); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
cardInfo.setServiceFeeAmount(fee); |
|
|
|
cardInfo.setCreateDate(curr); |
|
|
|
cardInfo.setUpdateDate(curr); |
|
|
|
cardInfo.setSupportTransfer(coupon.getSupportTransfer()); |
|
|
|
//检查卡是否下架,如果是,不可转赠 |
|
|
|
WxCouponChannel wxCouponChannel = wxCouponChannelMapper.selectById(order.getCouponChannelId(),order.getTenantId()); |
|
|
|
if (wxCouponChannel != null && wxCouponChannel.getStatus().equals(EnumCouponChannelStatus.STATUS_TAKE_OFFF.getCode())) { |
|
|
|
cardInfo.setSupportTransfer(EnumCouponTransfer.NO.getCode()); |
|
|
|
} |
|
|
|
wxCardInfoMapper.insert(cardInfo); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
try{ |
|
|
|
@@ -3061,8 +3070,25 @@ public class WxOrderServiceImpl implements WxOrderService { |
|
|
|
Integer shippingType, UserBasicInfoAddress address,boolean isPressOrder) { |
|
|
|
WxOrderServiceImpl proxy = (WxOrderServiceImpl) AopContext.currentProxy(); |
|
|
|
|
|
|
|
// 减库存操作 |
|
|
|
StockReduceResult stockReduceResult = proxy.stockReduce(allowUnPayOrder,user, coupon,couponChannel,couponNumber,isPressOrder); |
|
|
|
//实体卡未激活的,已经消费了,不用再扣库存 |
|
|
|
if (null != wxCouponPassword && wxCouponPassword.isDefaultUser()) { |
|
|
|
//do nothing |
|
|
|
}else { |
|
|
|
// 减库存操作 |
|
|
|
StockReduceResult stockReduceResult = proxy.stockReduce(allowUnPayOrder,user, coupon,couponChannel,couponNumber,isPressOrder); |
|
|
|
//渠道的库存和价格可以随时修改。这里需要校验一下 |
|
|
|
if (stockReduceResult.isChannelStockReduce()) { |
|
|
|
//再查询一下,此时有可能价格已经修改 |
|
|
|
WxCouponChannel wxCouponChannel = wxCouponChannelService.getById(couponChannel.getId(),coupon.getTenantId()); |
|
|
|
//如果这个时候渠道价格已经清空了 |
|
|
|
if (null == wxCouponChannel.getChannelPrice()) { |
|
|
|
throw new MallinkException(ErrorCode.ORDER_SAVE_ERR.getCode(),"["+coupon.getTitle()+"]渠道价格已变动[清空],请刷新后重新下单."); |
|
|
|
} |
|
|
|
if (wxCouponChannel.getChannelPrice().intValue() > 0 ) { |
|
|
|
throw new MallinkException(ErrorCode.ORDER_SAVE_ERR.getCode(),"["+coupon.getTitle()+"]渠道价格已非免费,请刷新后重新下单."); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
// 当积分券或者积分停车券时 则进行积分支付 |
|
|
|
Integer orderType; |
|
|
|
@@ -3073,18 +3099,6 @@ public class WxOrderServiceImpl implements WxOrderService { |
|
|
|
orderType = EnumOrderType.COUPON.getCode(); |
|
|
|
} |
|
|
|
|
|
|
|
//渠道的库存和价格可以随时修改。这里需要校验一下 |
|
|
|
if (stockReduceResult.isChannelStockReduce()) { |
|
|
|
//再查询一下,此时有可能价格已经修改 |
|
|
|
WxCouponChannel wxCouponChannel = wxCouponChannelService.getById(couponChannel.getId(),coupon.getTenantId()); |
|
|
|
//如果这个时候渠道价格已经清空了 |
|
|
|
if (null == wxCouponChannel.getChannelPrice()) { |
|
|
|
throw new MallinkException(ErrorCode.ORDER_SAVE_ERR.getCode(),"["+coupon.getTitle()+"]渠道价格已变动[清空],请刷新后重新下单."); |
|
|
|
} |
|
|
|
if (wxCouponChannel.getChannelPrice().intValue() > 0 ) { |
|
|
|
throw new MallinkException(ErrorCode.ORDER_SAVE_ERR.getCode(),"["+coupon.getTitle()+"]渠道价格已非免费,请刷新后重新下单."); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
// 4. 保存Order |
|
|
|
WxOrder record = new WxOrder(); |
|
|
|
|