diff --git a/mallinkService/src/main/java/com/simple/common/ErrorCode.java b/mallinkService/src/main/java/com/simple/common/ErrorCode.java index f465539ef..a641b5c33 100644 --- a/mallinkService/src/main/java/com/simple/common/ErrorCode.java +++ b/mallinkService/src/main/java/com/simple/common/ErrorCode.java @@ -83,9 +83,11 @@ public enum ErrorCode{ /** * 卡券 */ - COUPON_ORDER_IS_USED(4000, "卡券已核销"), - COUPON_ORDER_IS_OVER_TIME(4001, "卡券已过期"), - COUPON_ORDER_IS_INVALID(4002, "卡券已经作废"), + COUPON_ORDER_IS_NULL(4000, "卡券不存在"), + COUPON_ORDER_IS_USED(4001, "卡券已核销"), + COUPON_ORDER_IS_OVER_TIME(4002, "卡券已过期"), + COUPON_ORDER_IS_INVALID(4003, "卡券已经作废"), + /** * 微信 diff --git a/mallinkService/src/main/java/com/simple/service/impl/WxCouponOrderServiceImpl.java b/mallinkService/src/main/java/com/simple/service/impl/WxCouponOrderServiceImpl.java index 661b413a6..a67f1369c 100644 --- a/mallinkService/src/main/java/com/simple/service/impl/WxCouponOrderServiceImpl.java +++ b/mallinkService/src/main/java/com/simple/service/impl/WxCouponOrderServiceImpl.java @@ -9,10 +9,13 @@ import com.simple.common.ResultData; import com.simple.domain.po.MallUserInfo; import com.simple.domain.po.WxCouponOrder; import com.simple.domain.po.WxMerchantBUser; +import com.simple.domain.po.WxOrder; import com.simple.enums.EnumCouponOrderStatus; import com.simple.enums.EnumCouponStatus; import com.simple.exception.MallinkException; +import com.simple.mapper.WxOrderMapper; import com.simple.mapper.WxCouponOrderMapper; +import com.simple.mapper.WxMerchantBUserMapper; import com.simple.service.WxCouponOrderService; import org.apache.log4j.Logger; import org.springframework.beans.factory.annotation.Autowired; @@ -29,6 +32,12 @@ public class WxCouponOrderServiceImpl implements WxCouponOrderService { @Autowired WxCouponOrderMapper wxCouponOrderMapper; + @Autowired + WxOrderMapper wxOrderMapper; + + @Autowired + WxMerchantBUserMapper wxMerchantBUserMapper; + @Override public PageInfo listAsPage(WxCouponOrder record, Integer pageIndex, Integer pageSize) { return PageHelper.startPage(pageIndex, pageSize).doSelectPageInfo(() -> wxCouponOrderMapper.findList(record)); @@ -57,11 +66,29 @@ public class WxCouponOrderServiceImpl implements WxCouponOrderService { } - @Override @Transactional(propagation = Propagation.REQUIRED, readOnly = false, rollbackFor = {Exception.class}) public ResultData verify(Long couponOrderId, Long bUserId) { + WxCouponOrder wxCouponOrder = wxCouponOrderMapper.selectByPrimaryKey(couponOrderId); + if(wxCouponOrder == null){ + logger.error("券ID不存在:"+ couponOrderId); + throw new MallinkException(ErrorCode.COUPON_ORDER_IS_NULL); + } + + WxMerchantBUser wxMerchantBUser = wxMerchantBUserMapper.selectByPrimaryKey(bUserId.longValue()); + if(wxMerchantBUser == null){ + logger.error("核销员ID不存在:"+ bUserId); + throw new MallinkException(ErrorCode.COUPON_ORDER_IS_NULL); + } + + WxOrder wxOrder = wxOrderMapper.selectByPrimaryKey(wxCouponOrder.getOrderId()); + + if (!wxOrder.getMerchantId().equals(wxMerchantBUser.getMerchantId())){ + logger.error("券: couponMerchantId-" + wxOrder.getMerchantId()+"核销: couponMerchantId-"+wxMerchantBUser.getMerchantId()); + 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); @@ -91,8 +118,25 @@ public class WxCouponOrderServiceImpl implements WxCouponOrderService { @Override @Transactional(propagation = Propagation.REQUIRED, readOnly = false, rollbackFor = {Exception.class}) public ResultData refund(Long couponOrderId, Long bUserId) { + WxCouponOrder wxCouponOrder = wxCouponOrderMapper.selectByPrimaryKey(couponOrderId); + if(wxCouponOrder == null){ + logger.error("券ID不存在:"+ couponOrderId); + throw new MallinkException(ErrorCode.COUPON_ORDER_IS_NULL); + } + WxMerchantBUser wxMerchantBUser = wxMerchantBUserMapper.selectByPrimaryKey(bUserId.longValue()); + if(wxMerchantBUser == null){ + logger.error("操作员ID不存在:"+ bUserId); + throw new MallinkException(ErrorCode.COUPON_ORDER_IS_NULL); + } + + WxOrder wxOrder = wxOrderMapper.selectByPrimaryKey(wxCouponOrder.getOrderId()); + + if (!wxOrder.getMerchantId().equals(wxMerchantBUser.getMerchantId())){ + logger.error("券: couponMerchantId-" + wxOrder.getMerchantId()+"核销: couponMerchantId-"+wxMerchantBUser.getMerchantId()); + throw new MallinkException(ErrorCode.COUPON_ORDER_IS_NULL); + } if (wxCouponOrder.getCouponOrderStatus().equals(EnumCouponOrderStatus.COUPON_ORDER_OVER_TIME.getCode())) { logger.error("已过期: couponOrder-" + couponOrderId); throw new MallinkException(ErrorCode.COUPON_ORDER_IS_OVER_TIME);