diff --git a/mallinkPosApi/src/main/java/com/iformall/controller/PosController.java b/mallinkPosApi/src/main/java/com/iformall/controller/PosController.java index 85356e073..706c75fb5 100644 --- a/mallinkPosApi/src/main/java/com/iformall/controller/PosController.java +++ b/mallinkPosApi/src/main/java/com/iformall/controller/PosController.java @@ -107,7 +107,7 @@ public class PosController extends BaseController { "\"bu_user_id\":\"string(必填)\"," + "\"coupon_order_id\":\"string(必填)\"," + "\"nonce_str\":\"string(必填)\"," + - "\"verify\":\"independent, pay(必填)\"," + + "\"verify_type\":\"independent, pay(必填)\"," + "\"pos_order_id\":\"string(选填)\"," + "\"pos_amount\":\"单位(分)(选填)\"}") @PostMapping("/checkCouponOrderForVerify") diff --git a/mallinkPosApi/src/main/java/com/iformall/service/impl/PosServiceImpl.java b/mallinkPosApi/src/main/java/com/iformall/service/impl/PosServiceImpl.java index 493b8f890..bbd8ac600 100644 --- a/mallinkPosApi/src/main/java/com/iformall/service/impl/PosServiceImpl.java +++ b/mallinkPosApi/src/main/java/com/iformall/service/impl/PosServiceImpl.java @@ -224,6 +224,7 @@ public class PosServiceImpl implements PosService { String tenantId = params.get(WxPayConstant.TENANT_ID); // 租户ID String merchantIdStr = params.get(WxPayConstant.MERCHANT_ID); // 商户ID String buUserIdStr = params.get(WxPayConstant.BUSER_ID); // POS操作员ID + String verifyType = params.get(WxPayConstant.VERIFY_TYPE); // 核销类型 String couponOrderIdStr = params.get(WxPayConstant.COUPON_ORDER_ID); // 券ID String posOrderIdStr = params.get(WxPayConstant.POS_ORDER_ID); // POS订单ID String posAmountStr = params.get(WxPayConstant.POS_AMOUNT); // POS订单总额(单位:分) @@ -246,6 +247,20 @@ public class PosServiceImpl implements PosService { String errMessage = "request params[coupon_order_id] error."; throw new MallinkException(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(), errMessage); } + if (actionType.equals(EnumVerifyActionType.CHECK)) { + if (StringUtils.isBlank(verifyType)) { + String errMessage = "request params[verify_type] error."; + throw new MallinkException(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(), errMessage); + } + if ((!verifyType.equalsIgnoreCase(WxPayConstant.VERIFY_INDEPENT) || verifyType.equalsIgnoreCase(WxPayConstant.VERIFY_PAY))) { + String errMessage = "request params[verify_type] only support independent or pay."; + throw new MallinkException(ErrorCode.SYS_PARAMETER_CAST_ERROR.getCode(), errMessage); + } + } else if (actionType.equals(EnumVerifyActionType.VERIFY_INDEPENT)) { + verifyType = WxPayConstant.VERIFY_INDEPENT; + } else if (actionType.equals(EnumVerifyActionType.VERIFY_PAY)) { + verifyType = WxPayConstant.VERIFY_PAY; + } if (actionType.equals(EnumVerifyActionType.PRE_VERIFY) || actionType.equals(EnumVerifyActionType.VERIFY_INDEPENT) || actionType.equals(EnumVerifyActionType.VERIFY_PAY)) { @@ -304,7 +319,8 @@ public class PosServiceImpl implements PosService { JSONArray coRetArr = new JSONArray(); if (couponOrderIdStr != null) { try { - Map oneRetMap = doVerifyActionForOneCouponOrder(actionType, + Map oneRetMap = doVerifyActionForOneCouponOrder( + actionType, verifyType, tenantId, merchantIdStr, merchantId, buUserIdStr, buUserId, posOrderIdStr, posOrderId, posAmount, @@ -329,6 +345,7 @@ public class PosServiceImpl implements PosService { String posOrderIdStr = params.get(WxPayConstant.POS_ORDER_ID); // POS订单ID String posAmountStr = params.get(WxPayConstant.POS_AMOUNT); // POS订单总额(单位:分) String selCoListStr = params.get(WxPayConstant.SELECTED_COUPON_ORDER_LIST); // 选中的优惠券列表 + String verifyType = WxPayConstant.VERIFY_PAY; // 此接口只有支付使用 if (StringUtils.isBlank(tenantId)) { String errMessage = "request params[tenant_id] error."; @@ -406,7 +423,8 @@ public class PosServiceImpl implements PosService { String couponOrderIdStr = selCoArr.getString(i); if (couponOrderIdStr != null) { try { - Map oneRetMap = doVerifyActionForOneCouponOrder(actionType, + Map oneRetMap = doVerifyActionForOneCouponOrder( + actionType, verifyType, tenantId, merchantIdStr, merchantId, buUserIdStr, buUserId, posOrderIdStr, posOrderId, posAmount, @@ -425,7 +443,7 @@ public class PosServiceImpl implements PosService { } private Map doVerifyActionForOneCouponOrder( - EnumVerifyActionType actionType, + EnumVerifyActionType actionType, String verifyType, String tenantId, String merchantIdStr, Long merchantId, String buUserIdStr, Long buUserId, String posOrderIdStr, Long posOrderId, Integer posAmount, @@ -484,6 +502,25 @@ public class PosServiceImpl implements PosService { throw new MallinkException(ErrorCode.COUPON_ORDER_IS_USED); } if (actionType.equals(EnumVerifyActionType.CHECK)) { + if (verifyType.equalsIgnoreCase(WxPayConstant.VERIFY_INDEPENT)) { + if (!(couponOrderCVo.getCouponType().equals(EnumCouponType.COUPON_MULTIMCH.getCode()) || + couponOrderCVo.getCouponType().equals(EnumCouponType.COUPON_LIPIN.getCode()) || + couponOrderCVo.getCouponType().equals(EnumCouponType.COUPON_PRESS.getCode()) || + couponOrderCVo.getCouponType().equals(EnumCouponType.COUPON_GROUP.getCode()) + )) { + logger.error(ErrorCode.VERIFY_COUPON_TYPE_NOT_SUPPORT.getMessage()); + throw new MallinkException(ErrorCode.VERIFY_COUPON_TYPE_NOT_SUPPORT); + } + } + if (verifyType.equalsIgnoreCase(WxPayConstant.VERIFY_PAY)) { + if (!(couponOrderCVo.getCouponType().equals(EnumCouponType.COUPON_MULTIMCH.getCode()) || + couponOrderCVo.getCouponType().equals(EnumCouponType.COUPON_MANJIAN.getCode()) || + couponOrderCVo.getCouponType().equals(EnumCouponType.COUPON_DAIJIN.getCode()) + )) { + logger.error(ErrorCode.VERIFY_COUPON_TYPE_NOT_SUPPORT.getMessage()); + throw new MallinkException(ErrorCode.VERIFY_COUPON_TYPE_NOT_SUPPORT); + } + } if (couponOrderCVo.getCouponOrderStatus().equals(EnumCouponOrderStatus.POS_PRE_VERIFY.getCode())) { logger.info("券已被预核销: " + couponOrderIdStr); if (!couponOrderCVo.getBUserId().equals(buUserId)) { @@ -523,10 +560,6 @@ public class PosServiceImpl implements PosService { return retMap; } } else if (actionType.equals(EnumVerifyActionType.PRE_VERIFY)) { - if (couponOrderCVo.getPrice() > posAmount) { - logger.error(ErrorCode.VERIFY_PRE_POS_ORDER_PRICE_ISSUE.getMessage()); - throw new MallinkException(ErrorCode.VERIFY_PRE_POS_ORDER_PRICE_ISSUE); - } if (!(couponOrderCVo.getCouponType().equals(EnumCouponType.COUPON_MULTIMCH) || couponOrderCVo.getCouponType().equals(EnumCouponType.COUPON_MANJIAN) || couponOrderCVo.getCouponType().equals(EnumCouponType.COUPON_DAIJIN) @@ -551,20 +584,28 @@ public class PosServiceImpl implements PosService { logger.error(ErrorCode.VERIFY_PRE_POS_ORDER_NOT_EQUAL.getMessage() + ": " + posOrderIdStr); throw new MallinkException(ErrorCode.VERIFY_PRE_POS_ORDER_NOT_EQUAL); } + Integer remainAmount = posAmount - couponOrderCVo.getPrice(); + if (remainAmount < 0) { + remainAmount = 0; + } retMap.put(WxPayConstant.ID, couponOrderIdStr); retMap.put(WxPayConstant.PRE_VERIFY, "true"); retMap.put(WxPayConstant.DEDUCT_AMOUNT, String.valueOf(couponOrderCVo.getPrice())); - retMap.put(WxPayConstant.REMAIN_AMOUNT, String.valueOf(posAmount - couponOrderCVo.getPrice())); + retMap.put(WxPayConstant.REMAIN_AMOUNT, String.valueOf(remainAmount)); return retMap; } if (couponOrderCVo.getCouponOrderStatus().equals(EnumCouponOrderStatus.COUPON_ORDER_USE_WAIT.getCode())) { logger.info("券可以被预核销: " + couponOrderIdStr); try { doPreVerify(couponOrderCVo, buUserId, posOrderId); + Integer remainAmount = posAmount - couponOrderCVo.getPrice(); + if (remainAmount < 0) { + remainAmount = 0; + } retMap.put(WxPayConstant.ID, couponOrderIdStr); retMap.put(WxPayConstant.PRE_VERIFY, "true"); retMap.put(WxPayConstant.DEDUCT_AMOUNT, String.valueOf(couponOrderCVo.getPrice())); - retMap.put(WxPayConstant.REMAIN_AMOUNT, String.valueOf(posAmount - couponOrderCVo.getPrice())); + retMap.put(WxPayConstant.REMAIN_AMOUNT, String.valueOf(remainAmount)); return retMap; } catch (MallinkException e) { logger.error(e.getMessage()); @@ -594,10 +635,6 @@ public class PosServiceImpl implements PosService { logger.error(ErrorCode.VERIFY_COUPON_TYPE_NOT_SUPPORT.getMessage()); throw new MallinkException(ErrorCode.VERIFY_COUPON_TYPE_NOT_SUPPORT); } - if (couponOrderCVo.getPrice() > posAmount) { - logger.error(ErrorCode.VERIFY_PRE_POS_ORDER_PRICE_ISSUE.getMessage()); - throw new MallinkException(ErrorCode.VERIFY_PRE_POS_ORDER_PRICE_ISSUE); - } } boolean blVerify = false; if (couponOrderCVo.getCouponOrderStatus().equals(EnumCouponOrderStatus.POS_PRE_VERIFY.getCode())) { @@ -625,10 +662,14 @@ public class PosServiceImpl implements PosService { if (blVerify) { try { doVerify(couponOrderCVo, wxCoupon, merchantId, buUserId, posOrderId, retMap); + Integer remainAmount = posAmount - couponOrderCVo.getPrice(); + if (remainAmount < 0) { + remainAmount = 0; + } retMap.put(WxPayConstant.ID, couponOrderIdStr); retMap.put(WxPayConstant.VERIFY, "true"); retMap.put(WxPayConstant.DEDUCT_AMOUNT, String.valueOf(couponOrderCVo.getPrice())); - retMap.put(WxPayConstant.REMAIN_AMOUNT, String.valueOf(posAmount - couponOrderCVo.getPrice())); + retMap.put(WxPayConstant.REMAIN_AMOUNT, String.valueOf(remainAmount)); return retMap; } catch (MallinkException e) { logger.error(e.getMessage()); diff --git a/mallinkService/src/main/java/com/iformall/pay/WxPayConstant.java b/mallinkService/src/main/java/com/iformall/pay/WxPayConstant.java index 6ce41df36..c50c91429 100644 --- a/mallinkService/src/main/java/com/iformall/pay/WxPayConstant.java +++ b/mallinkService/src/main/java/com/iformall/pay/WxPayConstant.java @@ -28,6 +28,8 @@ public class WxPayConstant { public final static String MEM_ID = "mem_id"; public final static String MEM_PHONE = "mem_phone"; public final static String VERIFY_TYPE = "verify_type"; + public final static String VERIFY_INDEPENT = "independent"; + public final static String VERIFY_PAY = "pay"; public final static String REG_QRCODE_URL = "qrcode_url"; public final static String POS_QRCODE_RULE = "pos_qrcode_rule";