|
|
|
@@ -432,4 +432,93 @@ public class WxCouponOrderController extends BaseController { |
|
|
|
memCouponFromDspService.couponOrderFromDsp(tenantEntity, member.getPhone()); |
|
|
|
return new ResultData(); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@ApiOperation(value = "核销接口", notes = "{\"couponOrderId\":\"string\"}") |
|
|
|
@PostMapping("verify") |
|
|
|
public ResultData verify(@RequestBody Map<String, String> paramMap) { |
|
|
|
logger.info("couponOrderController.verify:" + paramMap.toString()); |
|
|
|
String couponOrderIdStr = paramMap.get("couponOrderId"); |
|
|
|
if (StringUtils.isBlank(couponOrderIdStr)) { |
|
|
|
logger.error("couponOrderId不能为空: " + paramMap.toString()); |
|
|
|
return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL); |
|
|
|
} |
|
|
|
Long couponOrderId = 0L; |
|
|
|
try { |
|
|
|
couponOrderId = Long.valueOf(couponOrderIdStr); |
|
|
|
} catch (NumberFormatException e) { |
|
|
|
couponOrderId = 0L; |
|
|
|
logger.error("couponOrderId参数不正确: " + paramMap.toString()); |
|
|
|
return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL); |
|
|
|
} |
|
|
|
|
|
|
|
WxCouponOrderCVo wxCouponOrderCVo = wxCouponOrderService.detailCUserVo(couponOrderIdStr,getTenantInfo()); |
|
|
|
|
|
|
|
if (wxCouponOrderCVo == null) |
|
|
|
return new ResultData(ErrorCode.COUPON_ORDER_IS_NULL); |
|
|
|
|
|
|
|
WxCUserBasicInfo member; |
|
|
|
try { |
|
|
|
member = getCacheMember(); |
|
|
|
} catch (Exception e) { |
|
|
|
return new ResultData(Result.ERROR,e.getMessage()); |
|
|
|
} |
|
|
|
|
|
|
|
Date now = new Date(); |
|
|
|
if (wxCouponOrderCVo.getValidType().equals(EnumCouponValidType.BETWEEN_TWO_TIME.getCode())){ |
|
|
|
// && !wxCouponOrderCVo.getType().equals(EnumCouponType.COUPON_PREORDER.getCode())) { |
|
|
|
if(wxCouponOrderCVo.getType().equals(EnumCouponType.COUPON_PREORDER.getCode())){ |
|
|
|
if (wxCouponOrderCVo.getPickStartDate().after(now)) { |
|
|
|
logger.error("此券有效期未开始:" + couponOrderIdStr); |
|
|
|
return new ResultData(ErrorCode.COUPON_ORDER_IS_EARLIER_THAN_VALIDDATE); |
|
|
|
} |
|
|
|
if (wxCouponOrderCVo.getPickEndDate().before(now)) { |
|
|
|
logger.error("此券有效期已结束:" + couponOrderIdStr); |
|
|
|
return new ResultData(ErrorCode.COUPON_ORDER_IS_LATER_THAN_VALIDDATE); |
|
|
|
} |
|
|
|
}else{ |
|
|
|
if (wxCouponOrderCVo.getValidStartDate().after(now)) { |
|
|
|
logger.error("此券有效期未开始:" + couponOrderIdStr); |
|
|
|
return new ResultData(ErrorCode.COUPON_ORDER_IS_EARLIER_THAN_VALIDDATE); |
|
|
|
} |
|
|
|
if (wxCouponOrderCVo.getValidEndDate().before(now)) { |
|
|
|
logger.error("此券有效期已结束:" + couponOrderIdStr); |
|
|
|
return new ResultData(ErrorCode.COUPON_ORDER_IS_LATER_THAN_VALIDDATE); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
} else { |
|
|
|
if (wxCouponOrderCVo.getExpiredTime().before(now)) { |
|
|
|
logger.error("此券已过期:" + couponOrderIdStr); |
|
|
|
return new ResultData(ErrorCode.COUPON_IS_EXPIRED); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
WxCouponOrder wxCouponOrder = wxCouponOrderService.getById(couponOrderId,getTenantInfo().getTenantId()); |
|
|
|
if (wxCouponOrder == null) { |
|
|
|
logger.error("券ID不存在:" + couponOrderId); |
|
|
|
return new ResultData(ErrorCode.COUPON_ORDER_IS_NULL); |
|
|
|
} |
|
|
|
if(!member.getId().equals(wxCouponOrder.getCUserId())){ |
|
|
|
logger.error("此券不属于此人:" + member.getId()); |
|
|
|
return new ResultData(ErrorCode.SYS_PARAMETER_ERROR); |
|
|
|
} |
|
|
|
WxCouponOrder couponOrder = null; |
|
|
|
try { |
|
|
|
couponOrder = wxCouponOrderService.verify(wxCouponOrder,null,EnumCouponVerifyType.VERIFY_C); |
|
|
|
} catch (MallinkException e) { |
|
|
|
logger.error("核销异常: " + e.getMessage()); |
|
|
|
return new ResultData(e.getErrorCode(), e.getMessage()); |
|
|
|
} catch (Exception e) { |
|
|
|
logger.error("核销异常: " + e.getMessage()); |
|
|
|
return new ResultData(ErrorCode.VERIFY_ERROR, e.getMessage()); |
|
|
|
} |
|
|
|
|
|
|
|
if (couponOrder != null && couponOrder.getMerchantId() != null) { |
|
|
|
wxCouponOrderService.sendInsideCouponVerifyMsg(couponOrder, couponOrderId, couponOrder.getMerchantId()); |
|
|
|
} |
|
|
|
|
|
|
|
return new ResultData(couponOrder); |
|
|
|
} |
|
|
|
|
|
|
|
} |