|
|
|
@@ -295,9 +295,35 @@ public class WxCouponOrderServiceImpl implements WxCouponOrderService { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
@Transactional(propagation = Propagation.REQUIRED, readOnly = false, rollbackFor = {Exception.class}) |
|
|
|
public ResultData couponOrderVerify(WxCouponOrder wxCouponOrder, WxMerchantBUser wxMerchantBUser, WxOrder wxOrder) { |
|
|
|
if (wxCouponOrder.getCouponOrderStatus() == EnumCouponOrderStatus.COUPON_ORDER_OVER_TIME.getCode()) { |
|
|
|
logger.error("已过期: couponOrder-" + wxCouponOrder.getId()); |
|
|
|
throw new MallinkException(ErrorCode.COUPON_ORDER_IS_OVER_TIME); |
|
|
|
} |
|
|
|
if (wxCouponOrder.getCouponOrderStatus() == EnumCouponOrderStatus.COUPON_ORDER_INVALID.getCode()) { |
|
|
|
logger.error("已退款: couponOrder-" + wxCouponOrder.getId()); |
|
|
|
throw new MallinkException(ErrorCode.COUPON_ORDER_IS_INVALID); |
|
|
|
} |
|
|
|
if (wxCouponOrder.getCouponOrderStatus() == EnumCouponOrderStatus.COUPON_ORDER_USED.getCode()) { |
|
|
|
logger.error("已经核销过的券: couponOrder-" + wxCouponOrder.getId()); |
|
|
|
throw new MallinkException(ErrorCode.COUPON_ORDER_IS_USED); |
|
|
|
} |
|
|
|
try { |
|
|
|
wxCouponOrder.setCouponOrderStatus(EnumCouponOrderStatus.COUPON_ORDER_USED.getCode()); //1核销 |
|
|
|
wxCouponOrder.setBUserId(wxMerchantBUser.getBUserId()); |
|
|
|
wxCouponOrder.setUpdateDate(new Date()); |
|
|
|
wxCouponOrderMapper.updateByPrimaryKeySelective(wxCouponOrder); |
|
|
|
} catch (Exception e) { |
|
|
|
logger.error("db failed: couponOrder-" + wxCouponOrder.getId() + ", e:" + e.getMessage()); |
|
|
|
throw new MallinkException(ErrorCode.DB_FAIL.getCode(), "DB FAILD " + e.getMessage()); |
|
|
|
} |
|
|
|
|
|
|
|
return new ResultData(wxCouponOrder); |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public ResultData verify(Long couponOrderId, Long bUserId) { |
|
|
|
|
|
|
|
WxCouponOrder wxCouponOrder = wxCouponOrderMapper.selectByPrimaryKey(couponOrderId); |
|
|
|
@@ -319,42 +345,30 @@ public class WxCouponOrderServiceImpl implements WxCouponOrderService { |
|
|
|
throw new MallinkException(ErrorCode.COUPON_ORDER_IS_NULL); |
|
|
|
} |
|
|
|
|
|
|
|
if (wxCouponOrder.getCouponOrderStatus() == EnumCouponOrderStatus.COUPON_ORDER_OVER_TIME.getCode()) { |
|
|
|
logger.error("已过期: couponOrder-" + couponOrderId); |
|
|
|
throw new MallinkException(ErrorCode.COUPON_ORDER_IS_OVER_TIME); |
|
|
|
} |
|
|
|
if (wxCouponOrder.getCouponOrderStatus() == EnumCouponOrderStatus.COUPON_ORDER_INVALID.getCode()) { |
|
|
|
logger.error("已退款: couponOrder-" + couponOrderId); |
|
|
|
throw new MallinkException(ErrorCode.COUPON_ORDER_IS_INVALID); |
|
|
|
} |
|
|
|
if (wxCouponOrder.getCouponOrderStatus() == EnumCouponOrderStatus.COUPON_ORDER_USED.getCode()) { |
|
|
|
logger.error("已经核销过的券: couponOrder-" + couponOrderId); |
|
|
|
throw new MallinkException(ErrorCode.COUPON_ORDER_IS_USED); |
|
|
|
} |
|
|
|
ResultData rd = couponOrderVerify(wxCouponOrder, wxMerchantBUser, wxOrder); |
|
|
|
|
|
|
|
// 核销发券 |
|
|
|
try { |
|
|
|
wxCouponOrder.setCouponOrderStatus(EnumCouponOrderStatus.COUPON_ORDER_USED.getCode()); //1核销 |
|
|
|
wxCouponOrder.setBUserId(bUserId); |
|
|
|
wxCouponOrder.setUpdateDate(new Date()); |
|
|
|
wxCouponOrderMapper.updateByPrimaryKeySelective(wxCouponOrder); |
|
|
|
wxCouponSendService.sendCouponToUser(wxMerchantBUser.getTenantId(), wxOrder.getCUserId(), EnumCouponSendType.COUPON_VERIFY.getCode()); |
|
|
|
} catch (Exception e) { |
|
|
|
logger.error("db failed: couponOrder-" + couponOrderId + ", e:" + e.getMessage()); |
|
|
|
throw new MallinkException(ErrorCode.DB_FAIL.getCode(), "DB FAILD " + e.getMessage()); |
|
|
|
logger.error("核销发券: " + e.getMessage()); |
|
|
|
} |
|
|
|
|
|
|
|
// 核销发券 |
|
|
|
wxCouponSendService.sendCouponToUser(wxMerchantBUser.getTenantId(), wxOrder.getCUserId(), EnumCouponSendType.COUPON_VERIFY.getCode()); |
|
|
|
|
|
|
|
|
|
|
|
// 微信分账 |
|
|
|
WxPayOrder wxPayOrder = new WxPayOrder(); |
|
|
|
wxPayOrder.setOrderId(wxCouponOrder.getOrderId()); |
|
|
|
wxPayOrder.setPayOrderStatus(EnumPayStatus.PAY_WAY_SUCCESS.getCode()); |
|
|
|
wxPayOrder = wxPayOrderMapper.selectOne(wxPayOrder); |
|
|
|
if (wxPayOrder == null) |
|
|
|
throw new MallinkException(ErrorCode.PAY_ORDER_NOT_FOUND); |
|
|
|
if (wxPayOrder.getShare() == EnumPayShare.YES.getCode()) |
|
|
|
wxProfitSharingOrderService.createSharingOrder(wxPayOrder); |
|
|
|
return new ResultData(wxCouponOrder); |
|
|
|
try { |
|
|
|
WxPayOrder wxPayOrder = new WxPayOrder(); |
|
|
|
wxPayOrder.setOrderId(wxCouponOrder.getOrderId()); |
|
|
|
wxPayOrder.setPayOrderStatus(EnumPayStatus.PAY_WAY_SUCCESS.getCode()); |
|
|
|
wxPayOrder = wxPayOrderMapper.selectOne(wxPayOrder); |
|
|
|
if (wxPayOrder == null) |
|
|
|
throw new MallinkException(ErrorCode.PAY_ORDER_NOT_FOUND); |
|
|
|
if (wxPayOrder.getShare() == EnumPayShare.YES.getCode()) |
|
|
|
wxProfitSharingOrderService.createSharingOrder(wxPayOrder); |
|
|
|
} catch (Exception e) { |
|
|
|
logger.error("微信分账: " + e.getMessage()); |
|
|
|
} |
|
|
|
|
|
|
|
return rd; |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
|