|
|
|
@@ -1383,14 +1383,18 @@ public class WxCouponOrderServiceImpl implements WxCouponOrderService { |
|
|
|
List<WxCouponOrderBVo> bolist = handleQueryResult(cUserEntry,list,wxCouponOrder); |
|
|
|
excelService.exportCsv(bolist, null, filename, WxCouponOrderBVo.class, filename + ".csv", response, false); |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
|
|
|
|
@Override |
|
|
|
@Transactional(propagation = Propagation.REQUIRED, readOnly = false, rollbackFor = {Exception.class}) |
|
|
|
public WxCouponOrder verify(WxCouponOrder couponOrder, WxMerchantBUser bUser, EnumCouponVerifyType couponVerifyType) { |
|
|
|
public WxCouponOrder verify(WxCouponOrder couponOrder, WxMerchant merchant, EnumCouponVerifyType couponVerifyType, WxMerchantBUser bUser) { |
|
|
|
if(EnumCouponVerifyType.VERIFY_B.equals(couponVerifyType) && bUser == null){ |
|
|
|
logger.error("B端核销未传入门店"); |
|
|
|
logger.error("B端核销未传入核销人"); |
|
|
|
throw new MallinkException(ErrorCode.VERIFY_ERROR); |
|
|
|
} |
|
|
|
// if(EnumCouponVerifyType.VERIFY_C.equals(couponVerifyType) && cUser == null){ |
|
|
|
// logger.error("C端核销未传入核销人"); |
|
|
|
// throw new MallinkException(ErrorCode.VERIFY_ERROR); |
|
|
|
// } |
|
|
|
|
|
|
|
// 1. 获取券信息 |
|
|
|
WxCoupon wxCoupon = wxCouponMapper.selectById(couponOrder.getCouponId(),couponOrder.getTenantId()); |
|
|
|
@@ -1408,66 +1412,53 @@ public class WxCouponOrderServiceImpl implements WxCouponOrderService { |
|
|
|
throw new MallinkException(ErrorCode.COUPON_ORDER_IS_INVALID); |
|
|
|
} |
|
|
|
if (couponOrder.getCouponOrderStatus() == EnumCouponOrderStatus.COUPON_ORDER_USED.getCode()) { |
|
|
|
logger.error("已经核销过的券: couponOrder-" + couponOrder.getId()); |
|
|
|
logger.error("已核销: couponOrder-" + couponOrder.getId()); |
|
|
|
throw new MallinkException(ErrorCode.COUPON_ORDER_IS_USED); |
|
|
|
} |
|
|
|
if (couponOrder.getCouponOrderStatus() == EnumCouponOrderStatus.POS_PRE_VERIFY.getCode()) { |
|
|
|
logger.error("券已被预核销: couponOrder-" + couponOrder.getId()); |
|
|
|
logger.error("已预核销: couponOrder-" + couponOrder.getId()); |
|
|
|
throw new MallinkException(ErrorCode.COUPON_ORDER_IS_PRE_VERIFY); |
|
|
|
} |
|
|
|
|
|
|
|
//核销tenant |
|
|
|
//核销tenant和核销商户 |
|
|
|
TenantEntity mallTenantEntity = new TenantEntity(); |
|
|
|
if(bUser != null){ |
|
|
|
mallTenantEntity.updateTenantInfo(bUser); |
|
|
|
}else{ |
|
|
|
Long merchantId = null; |
|
|
|
if(EnumCouponVerifyType.VERIFY_B.equals(couponVerifyType)){ |
|
|
|
if(merchant != null){ |
|
|
|
mallTenantEntity.updateTenantInfo(merchant); |
|
|
|
merchantId = merchant.getId(); |
|
|
|
}else{ |
|
|
|
mallTenantEntity.updateTenantInfo(bUser); |
|
|
|
merchantId = bUser.getMerchantId(); |
|
|
|
} |
|
|
|
}else{ |
|
|
|
mallTenantEntity.updateTenantInfo(wxCoupon); |
|
|
|
} |
|
|
|
|
|
|
|
// 2. 检查适用门店 |
|
|
|
Long merchantId = null; |
|
|
|
if(EnumCouponType.COUPON_DISTRIBUTION.getCode().equals(wxCoupon.getType())){ |
|
|
|
//可配送商品 |
|
|
|
WxCouponMerchant wxCouponMerchant = new WxCouponMerchant(); |
|
|
|
wxCouponMerchant.updateTenantInfo(mallTenantEntity); |
|
|
|
wxCouponMerchant.setProductId(wxCoupon.getId()); |
|
|
|
wxCouponMerchant.setStatus(EnumCouponMerchantStatus.COUPON_MERCHANT_STATUS_VALID.getCode()); |
|
|
|
WxCouponMerchant cm = null; |
|
|
|
try{ |
|
|
|
cm = wxCouponMerchantMapper.selectOne(new QueryWrapper<>(wxCouponMerchant)); |
|
|
|
}catch (Exception e){ |
|
|
|
throw new MallinkException(ErrorCode.VERIFY_COUPON_ORDER_MERCHANT_IS_NULL); |
|
|
|
} |
|
|
|
if(cm == null){ |
|
|
|
throw new MallinkException(ErrorCode.VERIFY_COUPON_ORDER_MERCHANT_IS_NULL); |
|
|
|
} |
|
|
|
if(EnumCouponVerifyType.VERIFY_B.equals(couponVerifyType) && !verifyMerchant(bUser,cm.getMerchantId())){ |
|
|
|
throw new MallinkException(ErrorCode.VERIFY_COUPON_ORDER_MERCHANT_IS_NULL); |
|
|
|
} |
|
|
|
merchantId = cm.getMerchantId(); |
|
|
|
}else if(EnumCouponType.COUPON_GIFT.getCode().equals(wxCoupon.getType())){ |
|
|
|
if (StringUtils.isBlank(wxCoupon.getGiftList())){ |
|
|
|
logger.error("券包: coupon-" + wxCoupon.getId() + "数据异常" + "couponOrder-" + couponOrder.getId()); |
|
|
|
throw new MallinkException(ErrorCode.COUPON_ORDER_DATE_ERROR); |
|
|
|
} |
|
|
|
// if(!EnumCouponVerifyType.VERIFY_AUTO.equals(couponVerifyType)){ |
|
|
|
// throw new MallinkException(ErrorCode.VERIFY_COUPON_TYPE_NOT_SUPPORT); |
|
|
|
// } |
|
|
|
}else{ |
|
|
|
if(!EnumCouponVerifyType.VERIFY_B.equals(couponVerifyType)){ |
|
|
|
throw new MallinkException(ErrorCode.VERIFY_COUPON_TYPE_NOT_SUPPORT); |
|
|
|
} |
|
|
|
WxCouponMerchant wxCouponMerchant = new WxCouponMerchant(); |
|
|
|
wxCouponMerchant.updateTenantInfo(mallTenantEntity); |
|
|
|
wxCouponMerchant.setProductId(wxCoupon.getId()); |
|
|
|
wxCouponMerchant.setStatus(EnumCouponMerchantStatus.COUPON_MERCHANT_STATUS_VALID.getCode()); |
|
|
|
List<WxCouponMerchant> couponMerchantList = wxCouponMerchantMapper.findList(wxCouponMerchant); |
|
|
|
if (!couponMerchantList.stream().anyMatch(cm -> verifyMerchant(bUser,cm.getMerchantId()))) { |
|
|
|
logger.error("券: coupon-" + wxCoupon.getId() + "核销: couponMerchantId-" + bUser.getMerchantId()); |
|
|
|
throw new MallinkException(ErrorCode.VERIFY_COUPON_ORDER_MERCHANT_IS_NULL); |
|
|
|
} |
|
|
|
merchantId = bUser.getMerchantId(); |
|
|
|
} |
|
|
|
// 检查适用门店 |
|
|
|
if(EnumCouponType.COUPON_GIFT.getCode().equals(wxCoupon.getType())){ |
|
|
|
if (StringUtils.isBlank(wxCoupon.getGiftList())){ |
|
|
|
logger.error("券包: coupon-" + wxCoupon.getId() + "数据异常" + "couponOrder-" + couponOrder.getId()); |
|
|
|
throw new MallinkException(ErrorCode.COUPON_ORDER_DATE_ERROR); |
|
|
|
} |
|
|
|
}else { |
|
|
|
List<Long> couponMerchantIds = wxCouponMerchantMapper.findMerchantIdListByProduct(wxCoupon.getId(), mallTenantEntity.getTenantId()); |
|
|
|
if(EnumCouponType.COUPON_DISTRIBUTION.getCode().equals(wxCoupon.getType())){ |
|
|
|
if(couponMerchantIds.size() != 1){ |
|
|
|
throw new MallinkException(ErrorCode.VERIFY_COUPON_ORDER_MERCHANT_IS_NULL); |
|
|
|
} |
|
|
|
if(merchantId != null && !merchantId.equals(couponMerchantIds.get(0))){ |
|
|
|
throw new MallinkException(ErrorCode.VERIFY_COUPON_ORDER_MERCHANT_IS_NULL); |
|
|
|
} |
|
|
|
merchantId = couponMerchantIds.get(0); |
|
|
|
}else{ |
|
|
|
if(!EnumCouponVerifyType.VERIFY_B.equals(couponVerifyType)){ |
|
|
|
throw new MallinkException(ErrorCode.VERIFY_COUPON_TYPE_NOT_SUPPORT); |
|
|
|
} |
|
|
|
if(!couponMerchantIds.contains(merchantId)){ |
|
|
|
throw new MallinkException(ErrorCode.VERIFY_COUPON_ORDER_MERCHANT_IS_NULL); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
if(merchantId != null){ |
|
|
|
WxPayOrder wxPayOrderQ = new WxPayOrder(); |
|
|
|
@@ -1483,12 +1474,6 @@ public class WxCouponOrderServiceImpl implements WxCouponOrderService { |
|
|
|
throw new MallinkException(ErrorCode.VERIFY_COUPON_ORDER_MERCHANT_IS_NULL.getCode(),"当前商户没有配置分账账号。"); |
|
|
|
} |
|
|
|
} |
|
|
|
// else if(wxPayOrder != null && EnumPayMchType.DIRECT.getCode().equals(wxPayOrder.getMchType())){ |
|
|
|
// merchantId = wxPayOrder.getChildOrderShare(couponOrder.getOrderId()).getMerchantId(); |
|
|
|
// if (null == merchantId) { |
|
|
|
// throw new MallinkException(ErrorCode.VERIFY_COUPON_ORDER_MERCHANT_IS_NULL.getCode(),"订单支付信息未包含商户"); |
|
|
|
// } |
|
|
|
// } |
|
|
|
} |
|
|
|
|
|
|
|
int num = 0; |
|
|
|
@@ -1521,10 +1506,12 @@ public class WxCouponOrderServiceImpl implements WxCouponOrderService { |
|
|
|
logger.error("核销异常:updatete num " + num); |
|
|
|
throw new MallinkException(ErrorCode.VERIFY_ERROR.getCode(), "updatete num " + num); |
|
|
|
} |
|
|
|
|
|
|
|
//发券包子券 |
|
|
|
if(EnumCouponType.COUPON_GIFT.getCode().equals(wxCoupon.getType())){ |
|
|
|
try { |
|
|
|
List<Long> longs = JSON.parseArray(wxCoupon.getGiftList(), Long.class); |
|
|
|
//发券包子券 |
|
|
|
|
|
|
|
wxOrderService.sendSubCouponToUser(couponOrder,longs); |
|
|
|
} catch (MallinkException e) { |
|
|
|
throw e; |
|
|
|
@@ -1533,7 +1520,17 @@ public class WxCouponOrderServiceImpl implements WxCouponOrderService { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
if(EnumCouponType.COUPON_DOUYIN_GO_HOME.getCode().equals(wxCoupon.getType())){ |
|
|
|
//完成预约 |
|
|
|
try{ |
|
|
|
wxCouponOrderReservationService.finishReservation(couponOrder); |
|
|
|
}catch(Exception e){ |
|
|
|
throw new MallinkException(ErrorCode.VERIFY_ERROR.getCode(), "完成预约失败"); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
doAfterVerify(couponOrder, bUser, wxCoupon); |
|
|
|
|
|
|
|
return couponOrder; |
|
|
|
} |
|
|
|
|
|
|
|
@@ -1599,7 +1596,7 @@ public class WxCouponOrderServiceImpl implements WxCouponOrderService { |
|
|
|
WxCouponOrder couponOrder = null; |
|
|
|
try { |
|
|
|
wxCouponOrder.setVerifyRemark(remark); |
|
|
|
couponOrder = this.verify(wxCouponOrder, wxMerchantBUser, EnumCouponVerifyType.VERIFY_B); |
|
|
|
couponOrder = this.verify(wxCouponOrder, null, EnumCouponVerifyType.VERIFY_B,wxMerchantBUser); |
|
|
|
} catch (MallinkException e) { |
|
|
|
logger.error("核销异常: " ,e); |
|
|
|
throw new MallinkException(e.getErrorCode(), e.getMessage()); |
|
|
|
@@ -1768,13 +1765,6 @@ public class WxCouponOrderServiceImpl implements WxCouponOrderService { |
|
|
|
|
|
|
|
@Override |
|
|
|
public void actionAfterVerify(WxCouponOrder couponOrder, WxMerchant merchant) { |
|
|
|
//完成预约 |
|
|
|
try{ |
|
|
|
wxCouponOrderReservationService.finishReservation(couponOrder); |
|
|
|
}catch(Exception e){ |
|
|
|
logger.error("完成预约失败"+e.getMessage(),e); |
|
|
|
} |
|
|
|
|
|
|
|
try { |
|
|
|
boolean mulityShare = true; |
|
|
|
if(EnumComposeOrder.isSingle(couponOrder.getComposeOrderType())){ |
|
|
|
|