From 78fa5ade784edcbcaa9d3b912afe0fd98653aa5d Mon Sep 17 00:00:00 2001 From: Stormeye Wu Date: Tue, 3 Sep 2019 16:31:13 +0800 Subject: [PATCH] =?UTF-8?q?[POS][=E4=BF=AE=E6=94=B9]:=E5=88=B8=E6=A0=B8?= =?UTF-8?q?=E9=94=80=E6=92=A4=E9=94=80=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../iformall/controller/PosController.java | 4 +- .../iformall/service/impl/PosServiceImpl.java | 442 +++--------------- .../java/com/iformall/common/ErrorCode.java | 2 +- 3 files changed, 78 insertions(+), 370 deletions(-) diff --git a/mallinkPosApi/src/main/java/com/iformall/controller/PosController.java b/mallinkPosApi/src/main/java/com/iformall/controller/PosController.java index 91e412902..057c0530f 100644 --- a/mallinkPosApi/src/main/java/com/iformall/controller/PosController.java +++ b/mallinkPosApi/src/main/java/com/iformall/controller/PosController.java @@ -229,7 +229,7 @@ public class PosController extends BaseController { return buildReturnMap(retObj, resKey, WxPayConstant.RET_SUCCESS, "",null); } - @ApiOperation(value = "消费卡预支付", notes = "{" + + @ApiOperation(value = "消费卡支付", notes = "{" + "\"dev_id\":\"string(必填)\"," + "\"nonce_str\":\"string(必填)\"," + "\"tenant_id\":\"string(必填)\"," + @@ -239,7 +239,7 @@ public class PosController extends BaseController { "\"pos_amount\":\"string(单位:分)(必填)\"," + "\"card_id\":\"string(必填)\" }") @PostMapping("/cardPayPre") - @SystemControllerLog(description = "消费卡预支付") + @SystemControllerLog(description = "消费卡支付") public Map cardPayPre(@RequestBody Map params) { JSONObject payContent = new JSONObject(); JSONObject retObj = new JSONObject(); 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 20c1d0c2f..9ae56169a 100644 --- a/mallinkPosApi/src/main/java/com/iformall/service/impl/PosServiceImpl.java +++ b/mallinkPosApi/src/main/java/com/iformall/service/impl/PosServiceImpl.java @@ -914,366 +914,6 @@ public class PosServiceImpl implements PosService { return dataMap; } - //@Override - @Transactional(rollbackFor = Exception.class) - public Map couponOrderVerifyListDo(@RequestBody Map params, EnumPosActionType actionType) throws MallinkException { - Map retMap = new HashMap<>(); - - 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 posOrderIdStr = params.get(WxPayConstant.POS_ORDER_ID); // POS订单ID - String posAmountStr = params.get(WxPayConstant.ORDER_AMOUNT); // POS订单总额(单位:分) - String selCoListStr = params.get(WxPayConstant.COUPON_ORDER_LIST); // 选中的优惠券列表 - Integer sceneType = EnumPosSceneType.PAY.getCode(); // 此接口只有支付使用 - - if (StringUtils.isBlank(tenantId)) { - errParam(WxPayConstant.TENANT_ID); - } - PosMallConfig config = posMallConfigService.getByTenantId(tenantId); - if (config == null) { - logger.error(ErrorCode.POS_CONFIG_NOT_FOUND.getMessage()); - throw new MallinkException(ErrorCode.POS_CONFIG_NOT_FOUND); - } - if (!config.getCoupon().equals(EnumEnableType.Enable.getCode())) { - logger.error(ErrorCode.POS_CONFIG_MEM_COUPON_DISABLE.getMessage()); - throw new MallinkException(ErrorCode.POS_CONFIG_MEM_COUPON_DISABLE); - } - if (StringUtils.isBlank(merchantIdStr)) { - errParam(WxPayConstant.MERCHANT_ID); - } - if (StringUtils.isBlank(buUserIdStr)) { - errParam(WxPayConstant.BUSER_ID); - } - if (StringUtils.isBlank(selCoListStr)) { - errParam(WxPayConstant.COUPON_ORDER_LIST); - } - if (actionType.equals(EnumPosActionType.PAY_VERIFY_PRE) || actionType.equals(EnumPosActionType.VERIFY_INDEPENT)) { - if (StringUtils.isBlank(posOrderIdStr)) { - errParam(WxPayConstant.POS_ORDER_ID); - } - if (StringUtils.isBlank(posAmountStr)) { - errParam(WxPayConstant.ORDER_AMOUNT); - } - } - - Long merchantId, buUserId, posOrderId = 0L; - Integer posAmount = 0; - try { - merchantId = Long.valueOf(merchantIdStr); - buUserId = Long.valueOf(buUserIdStr); - if (actionType.equals(EnumPosActionType.PAY_VERIFY_PRE) || - actionType.equals(EnumPosActionType.VERIFY_INDEPENT) || - actionType.equals(EnumPosActionType.VERIFY_PAY)) { - posOrderId = Long.valueOf(posOrderIdStr); - posAmount = Integer.valueOf(posAmountStr); - } - } catch (NumberFormatException e) { - logger.error(e.getMessage()); - throw new MallinkException(ErrorCode.SYS_PARAMETER_CAST_ERROR.getCode(), e.getMessage()); - } - // 2. check merchant - WxMerchant merchant = checkAndGetMerchant(merchantId); - // 3. check buUser - WxMerchantBUser buUser = checkAndGetMerchantUser(buUserId, merchantId); - - JSONArray selCoArr = JSONObject.parseArray(selCoListStr); - if (selCoArr.size() <= 0) { - String errMessage = "request params[sel_co_list] error."; - throw new MallinkException(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(), errMessage); - } - - JSONArray coRetArr = new JSONArray(); - for(int i=0;i oneRetMap = doVerifyActionForOneCouponOrder( - actionType, sceneType, - tenantId, merchantIdStr, merchantId, - buUserIdStr, buUserId, - posOrderIdStr, posOrderId, posAmount, - couponOrderIdStr); - coRetArr.add(oneRetMap); - posAmount = Integer.valueOf(oneRetMap.get(WxPayConstant.REMAIN_AMOUNT)); - } catch (MallinkException e) { - throw new MallinkException(e.getErrorCode(), e.getMessage()); - } catch (Exception e) { - throw new MallinkException(500, e.getMessage()); - } - } - } - retMap.put(WxPayConstant.RET, coRetArr.toJSONString()); - return retMap; - } - - private Map doVerifyActionForOneCouponOrder( - EnumPosActionType actionType, Integer sceneType, - String tenantId, String merchantIdStr, Long merchantId, - String buUserIdStr, Long buUserId, - String posOrderIdStr, Long posOrderId, Integer posAmount, - String couponOrderIdStr) { - Map retMap = new HashMap<>(); - // 4. check couponOrderId - WxCouponOrderCVo couponOrderCVo = couponOrderService.detailCUserVo(couponOrderIdStr); - if (couponOrderCVo == null) { - logger.error(ErrorCode.COUPON_ORDER_IS_NULL.getMessage() + ": " + couponOrderIdStr); - throw new MallinkException(ErrorCode.COUPON_ORDER_IS_NULL); - } - // 4.1 检查券类型 - if (actionType.equals(EnumPosActionType.CHECK)) { - if (sceneType.equals(EnumPosSceneType.VERIFY.getCode())) { - 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 (sceneType.equals(EnumPosSceneType.PAY.getCode())) { - 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); - } - } - } else if (actionType.equals(EnumPosActionType.PAY_VERIFY_PRE) || actionType.equals(EnumPosActionType.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.getCouponType().equals(EnumCouponType.COUPON_MANJIAN.getCode())) { - if (posAmount < couponOrderCVo.getUsePrice()) { - logger.error(ErrorCode.VERIFY_MANJIAN_USER_PRICE_NOT_TOUCH.getMessage()); - throw new MallinkException(ErrorCode.VERIFY_MANJIAN_USER_PRICE_NOT_TOUCH); - } - } - } else if (actionType.equals(EnumPosActionType.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); - } - } - - // 4.2. 券包状态检查 - if (couponOrderCVo.getCouponOrderStatus() == EnumCouponOrderStatus.COUPON_ORDER_OVER_TIME.getCode()) { - logger.error("已过期: couponOrder-" + couponOrderCVo.getId()); - throw new MallinkException(ErrorCode.COUPON_ORDER_IS_OVER_TIME); - } - if (couponOrderCVo.getCouponOrderStatus() == EnumCouponOrderStatus.COUPON_ORDER_INVALID.getCode()) { - logger.error("已作废: couponOrder-" + couponOrderCVo.getId()); - throw new MallinkException(ErrorCode.COUPON_ORDER_IS_INVALID); - } - if (couponOrderCVo.getCouponOrderStatus() == EnumCouponOrderStatus.COUPON_ORDER_USED.getCode()) { - logger.error("已经核销过的券: couponOrder-" + couponOrderCVo.getId()); - throw new MallinkException(ErrorCode.COUPON_ORDER_IS_USED); - } - - - Date now = new Date(); - // 5. 检查有效期 - if (couponOrderCVo.getValidStartDate() != null && couponOrderCVo.getValidEndDate() != null) { - if (couponOrderCVo.getValidStartDate().getTime() > now.getTime()) { - logger.error("此券有效期未开始:" + couponOrderIdStr); - throw new MallinkException(ErrorCode.COUPON_ORDER_IS_EARLIER_THAN_VALIDDATE); - } - if (couponOrderCVo.getValidEndDate().getTime() < now.getTime()) { - logger.error("此券有效期已结束:" + couponOrderIdStr); - throw new MallinkException(ErrorCode.COUPON_ORDER_IS_EARLIER_THAN_VALIDDATE); - } - } - // 5.1 券已过期 - if (couponOrderCVo.getExpiredTime().before(now)) { - logger.error("此券已过期:" + couponOrderIdStr); - throw new MallinkException(ErrorCode.COUPON_ORDER_IS_EARLIER_THAN_VALIDDATE); - } - - Long couponOrderId = couponOrderCVo.getId(); - - // 6. 检查适用门店 - WxCouponMerchant wxCouponMerchant = new WxCouponMerchant(); - wxCouponMerchant.setProductId(couponOrderCVo.getCouponId()); - wxCouponMerchant.setStatus(EnumCouponMerchantStatus.COUPON_MERCHANT_STATUS_VALID.getCode()); - List couponMerchantList = couponMerchantMapper.findList(wxCouponMerchant); - if (!couponMerchantList.stream().anyMatch(cm->cm.getMerchantId().equals(merchantId))){ - logger.error("券: coupon-" + couponOrderCVo.getCouponId() + "核销: couponMerchantId-" + merchantIdStr + " 门店不适用"); - throw new MallinkException(ErrorCode.VERIFY_COUPON_ORDER_MERCHANT_IS_NULL); - } - - if (actionType.equals(EnumPosActionType.CHECK)) { - if (couponOrderCVo.getCouponOrderStatus().equals(EnumCouponOrderStatus.POS_PRE_VERIFY.getCode())) { - logger.info("券已被预核销: " + couponOrderIdStr); - if (!couponOrderCVo.getBUserId().equals(buUserId)) { - logger.error(ErrorCode.VERIFY_PRE_BUSER_NOT_EQUAL.getMessage() + ": " + buUserIdStr); - throw new MallinkException(ErrorCode.VERIFY_PRE_BUSER_NOT_EQUAL); - } - if (StringUtils.isBlank(posOrderIdStr)) { - logger.error(ErrorCode.VERIFY_PRE_POS_ORDER_IS_EMPTY.getMessage()); - throw new MallinkException(ErrorCode.VERIFY_PRE_POS_ORDER_IS_EMPTY); - } - try { - posOrderId = Long.valueOf(posOrderIdStr); - } catch (NumberFormatException e) { - logger.error("pos_order_id转换异常"); - throw new MallinkException(ErrorCode.SYS_PARAMETER_CAST_ERROR.getCode(), - ErrorCode.SYS_PARAMETER_CAST_ERROR.getMessage() + ", pos_order_id:" + posOrderIdStr); - } - // check pos order是否一致 - PosCouponOrderVerify posCouponOrderVerifyQ = new PosCouponOrderVerify(); - posCouponOrderVerifyQ.setTenantId(tenantId); - posCouponOrderVerifyQ.setCouponOrderId(couponOrderId); - posCouponOrderVerifyQ.setPosOrderId(posOrderId); - posCouponOrderVerifyQ.setState(EnumEnableType.Enable.getCode()); - List posCouponOrderVerifyList = posCouponOrderVerifyService.getList(posCouponOrderVerifyQ); - if (posCouponOrderVerifyList.size() != 1) { - logger.error(ErrorCode.VERIFY_PRE_POS_ORDER_NOT_EQUAL.getMessage() + ": " + posOrderIdStr); - throw new MallinkException(ErrorCode.VERIFY_PRE_POS_ORDER_NOT_EQUAL); - } - logger.info("券可以被核销: " + couponOrderIdStr); - retMap.put(WxPayConstant.ID, couponOrderIdStr); - retMap.put(WxPayConstant.CHECK, WxPayConstant.TRUE); - retMap.put(WxPayConstant.MEM_ID, String.valueOf(couponOrderCVo.getCUserId())); - retMap.put(WxPayConstant.TITLE, couponOrderCVo.getTitle()); - retMap.put(WxPayConstant.COVER_IMG, couponOrderCVo.getCoverImg()); - retMap.put(WxPayConstant.EXPIRE_TIME, mydateFormat.format(couponOrderCVo.getExpiredTime())); - retMap.put(WxPayConstant.PRICE, String.valueOf(couponOrderCVo.getPrice())); - EnumCouponOrderStatus couponOrderStatus = EnumCouponOrderStatus.getEnum(couponOrderCVo.getCouponOrderStatus()); - retMap.put(WxPayConstant.STATUS, String.valueOf(couponOrderStatus.getCode())); - retMap.put(WxPayConstant.STATUS_DES, couponOrderStatus.getMessage()); - return retMap; - } else if (couponOrderCVo.getCouponOrderStatus().equals(EnumCouponOrderStatus.COUPON_ORDER_USE_WAIT.getCode())) { - logger.info("券可以被核销: " + couponOrderIdStr); - retMap.put(WxPayConstant.ID, couponOrderIdStr); - retMap.put(WxPayConstant.CHECK, WxPayConstant.TRUE); - retMap.put(WxPayConstant.MEM_ID, String.valueOf(couponOrderCVo.getCUserId())); - retMap.put(WxPayConstant.TITLE, couponOrderCVo.getTitle()); - retMap.put(WxPayConstant.COVER_IMG, couponOrderCVo.getCoverImg()); - retMap.put(WxPayConstant.EXPIRE_TIME, mydateFormat.format(couponOrderCVo.getExpiredTime())); - retMap.put(WxPayConstant.PRICE, String.valueOf(couponOrderCVo.getPrice())); - EnumCouponOrderStatus couponOrderStatus = EnumCouponOrderStatus.getEnum(couponOrderCVo.getCouponOrderStatus()); - retMap.put(WxPayConstant.STATUS, String.valueOf(couponOrderStatus.getCode())); - retMap.put(WxPayConstant.STATUS_DES, couponOrderStatus.getMessage()); - return retMap; - } - } else if (actionType.equals(EnumPosActionType.PAY_VERIFY_PRE)) { - if (couponOrderCVo.getCouponOrderStatus().equals(EnumCouponOrderStatus.POS_PRE_VERIFY.getCode())) { - logger.info("券已被预核销: " + couponOrderIdStr); - if (!couponOrderCVo.getBUserId().equals(buUserId)) { - logger.error(ErrorCode.VERIFY_PRE_BUSER_NOT_EQUAL.getMessage() + ": " + buUserIdStr); - throw new MallinkException(ErrorCode.VERIFY_PRE_BUSER_NOT_EQUAL); - } - // check pos order是否一致 - PosCouponOrderVerify posCouponOrderVerifyQ = new PosCouponOrderVerify(); - posCouponOrderVerifyQ.setTenantId(tenantId); - posCouponOrderVerifyQ.setCouponOrderId(couponOrderId); - posCouponOrderVerifyQ.setPosOrderId(posOrderId); - posCouponOrderVerifyQ.setState(EnumEnableType.Enable.getCode()); - List posCouponOrderVerifyList = posCouponOrderVerifyService.getList(posCouponOrderVerifyQ); - if (posCouponOrderVerifyList.size() != 1) { - 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, WxPayConstant.TRUE); - retMap.put(WxPayConstant.DEDUCT_AMOUNT, String.valueOf(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, WxPayConstant.TRUE); - retMap.put(WxPayConstant.DEDUCT_AMOUNT, String.valueOf(couponOrderCVo.getPrice())); - retMap.put(WxPayConstant.REMAIN_AMOUNT, String.valueOf(remainAmount)); - return retMap; - } catch (MallinkException e) { - logger.error(e.getMessage()); - throw new MallinkException(e.getErrorCode(), e.getMessage()); - } catch (Exception e) { - logger.error(e.getMessage()); - throw new MallinkException(500, e.getMessage()); - } - } - } else { - // if (actionType.equals(EnumVerifyActionType.VERIFY_INDEPENT ) ||actionType.equals(EnumVerifyActionType.VERIFY_PAY)) - boolean blVerify = false; - if (couponOrderCVo.getCouponOrderStatus().equals(EnumCouponOrderStatus.POS_PRE_VERIFY.getCode())) { - logger.info("券已被预核销: " + couponOrderIdStr); - if (!couponOrderCVo.getBUserId().equals(buUserId)) { - logger.error(ErrorCode.VERIFY_PRE_BUSER_NOT_EQUAL.getMessage() + ": " + buUserIdStr); - throw new MallinkException(ErrorCode.VERIFY_PRE_BUSER_NOT_EQUAL); - } - // check pos order是否一致 - PosCouponOrderVerify posCouponOrderVerifyQ = new PosCouponOrderVerify(); - posCouponOrderVerifyQ.setTenantId(tenantId); - posCouponOrderVerifyQ.setCouponOrderId(couponOrderId); - posCouponOrderVerifyQ.setPosOrderId(posOrderId); - posCouponOrderVerifyQ.setState(EnumEnableType.Enable.getCode()); - List posCouponOrderVerifyList = posCouponOrderVerifyService.getList(posCouponOrderVerifyQ); - if (posCouponOrderVerifyList.size() != 1) { - logger.error(ErrorCode.VERIFY_PRE_POS_ORDER_NOT_EQUAL.getMessage() + ": " + posOrderIdStr); - throw new MallinkException(ErrorCode.VERIFY_PRE_POS_ORDER_NOT_EQUAL); - } - blVerify = true; - } else if (couponOrderCVo.getCouponOrderStatus().equals(EnumCouponOrderStatus.COUPON_ORDER_USE_WAIT.getCode())) { - logger.info("券可以被核销: " + couponOrderIdStr); - blVerify = true; - } - if (blVerify) { - // 5. get coupon - WxCoupon wxCoupon = couponMapper.selectByPrimaryKey(couponOrderCVo.getCouponId()); - if (wxCoupon == null) { - logger.error("券: coupon-" + wxCoupon.getId() + "不存在" + "couponOrder-" + couponOrderCVo.getId()); - throw new MallinkException(ErrorCode.COUPON_ORDER_IS_NULL); - } - - try { - //doVerify(actionType, 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, WxPayConstant.TRUE); - retMap.put(WxPayConstant.DEDUCT_AMOUNT, String.valueOf(couponOrderCVo.getPrice())); - retMap.put(WxPayConstant.REMAIN_AMOUNT, String.valueOf(remainAmount)); - return retMap; - } catch (MallinkException e) { - logger.error(e.getMessage()); - throw new MallinkException(e.getErrorCode(), e.getMessage()); - } catch (Exception e) { - logger.error(e.getMessage()); - throw new MallinkException(500, e.getMessage()); - } - } - } - - String errMessage = "核销异常:未知的核销状态-" + couponOrderCVo.getCouponOrderStatus() + ", 核销action-" + actionType.getCode(); - logger.error(errMessage); - throw new MallinkException(500, errMessage); - } - @Override @Transactional(rollbackFor = Exception.class) public JSONObject couponOrderVerifyCancel(Map params) { @@ -1284,6 +924,7 @@ public class PosServiceImpl implements PosService { String buUserIdStr = params.get(WxPayConstant.BUSER_ID); // POS操作员ID String sceneTypeStr = params.get(WxPayConstant.SCENE_TYPE); // 交易场景 String orderIdStr = params.get(WxPayConstant.POS_ORDER_ID); // POS订单ID + String orderCreateSN = params.get(WxPayConstant.ORDER_CREATE_SN); // POS SN号 String paymentInfoStr = params.get(WxPayConstant.PAYMENT_INFO); // 优惠信息 if (StringUtils.isBlank(tenantId)) { @@ -1311,6 +952,11 @@ public class PosServiceImpl implements PosService { } else { retMap.put(WxPayConstant.POS_ORDER_ID, orderIdStr); } + if (StringUtils.isBlank(orderCreateSN)) { + errParam(WxPayConstant.ORDER_CREATE_SN); + } else { + retMap.put(WxPayConstant.ORDER_CREATE_SN, orderCreateSN); + } if (StringUtils.isBlank(paymentInfoStr)) { errParam(WxPayConstant.PAYMENT_INFO); } @@ -1376,8 +1022,8 @@ public class PosServiceImpl implements PosService { WxCouponOrder couponOrder = new WxCouponOrder(); couponOrder.setId(couponOrderCVo.getId()); // 6. 核销撤销 - if (couponOrderCVo.getCouponOrderStatus().equals(EnumCouponOrderStatus.COUPON_ORDER_USED.getCode()) && - iSceneType.equals(EnumPosSceneType.VERIFY.getCode())) { + if (iSceneType.equals(EnumPosSceneType.VERIFY.getCode()) && + couponOrderCVo.getCouponOrderStatus().equals(EnumCouponOrderStatus.COUPON_ORDER_USED.getCode())) { logger.info("券已被核销无法取消: " + couponOrderIdStr); JSONObject refundObj = new JSONObject(); String errMesg = String.format("此券核销后无法退回, 券%s抵用%s元, 购买花费%s元", @@ -1413,16 +1059,72 @@ public class PosServiceImpl implements PosService { */ } // 6. 预核销取消 - else if (couponOrderCVo.getCouponOrderStatus().equals(EnumCouponOrderStatus.POS_PRE_VERIFY.getCode()) && - iSceneType.equals(EnumPosSceneType.PAY.getCode())) { + else if (iSceneType.equals(EnumPosSceneType.PAY.getCode()) && + couponOrderCVo.getCouponOrderStatus().equals(EnumCouponOrderStatus.POS_PRE_VERIFY.getCode())) { logger.info("券已被预核销: " + couponOrderIdStr); if (!couponOrderCVo.getBUserId().equals(buUserId)) { logger.error(ErrorCode.VERIFY_PRE_BUSER_NOT_EQUAL.getMessage() + ": " + buUserIdStr); throw new MallinkException(ErrorCode.VERIFY_PRE_BUSER_NOT_EQUAL); } + String memIdStr = params.get(WxPayConstant.MEM_ID); // 会员ID + String memPhoneStr = params.get(WxPayConstant.MEM_PHONE); // 会员手机 + String orderAmountStr = params.get(WxPayConstant.ORDER_AMOUNT); // POS订单金额(单位:分) + String orderAmountLeftStr = params.get(WxPayConstant.ORDER_AMOUNT_LEFT); // POS订单金额(单位:分) + String promotionAmountStr = paymentInfo.getString(WxPayConstant.PROMOTION_AMOUNT); + String amountLeftAfterPayStr = paymentInfo.getString(WxPayConstant.AMOUNT_LEFT_AFTER_PAY); + if (StringUtils.isBlank(orderAmountStr)) { + errParam(WxPayConstant.ORDER_AMOUNT); + } else { + retMap.put(WxPayConstant.ORDER_AMOUNT, orderAmountStr); + } + if (StringUtils.isBlank(orderAmountLeftStr)) { + errParam(WxPayConstant.ORDER_AMOUNT_LEFT); + } else { + retMap.put(WxPayConstant.ORDER_AMOUNT_LEFT, orderAmountLeftStr); + } + if (StringUtils.isBlank(memIdStr) && StringUtils.isBlank(memPhoneStr)) { + errParam2(WxPayConstant.MEM_ID, WxPayConstant.MEM_PHONE); + } + if (StringUtils.isBlank(promotionAmountStr)) { + errParam(WxPayConstant.PROMOTION_AMOUNT); + } + if (StringUtils.isBlank(amountLeftAfterPayStr)) { + errParam(WxPayConstant.AMOUNT_LEFT_AFTER_PAY); + } + Integer promotionAmount, amountLeftAfterPay; + try { + promotionAmount = Integer.valueOf(promotionAmountStr); + amountLeftAfterPay = Integer.valueOf(amountLeftAfterPayStr); + } catch (NumberFormatException e) { + logger.error(e.getMessage()); + throw new MallinkException(500, e.getMessage()); + } + if (!couponOrderCVo.getPrice().equals(promotionAmount)) { + String errMesg = String.format("券%s的金额与退款金额不一致", couponOrderIdStr); + logger.error(errMesg); + throw new MallinkException(ErrorCode.POS_COUPON_REFUND_ERROR.getCode(), errMesg); + } + // 10. 获取会员信息 + WxCUser user = getMemUser(tenantId, memIdStr, memPhoneStr); + if (user == null) { + logger.error(ErrorCode.USER_NOT_MEMBER.getMessage()); + throw new MallinkException(ErrorCode.USER_NOT_MEMBER); + } + if (user != null) { + retMap.put(WxPayConstant.MEM_ID, user.getId().toString()); + retMap.put(WxPayConstant.MEM_PHONE, user.getPhone()); + } + try { cancelPreVerify(couponOrderCVo, posOrderId); - retMap.put(WxPayConstant.CANCEL, WxPayConstant.TRUE); + JSONObject refundObj = new JSONObject(); + refundObj.put(WxPayConstant.COUPON_REFUND_ID, String.valueOf(couponOrderCVo.getId())); + refundObj.put(WxPayConstant.COUPON_REFUND_RESULT, "0"); + refundObj.put(WxPayConstant.COUPON_REFUND_RESULT_MSG, "核销撤销成功"); + refundObj.put(WxPayConstant.REFUND_TIME_FROM_IFORMALL, neuDateFormat.format(new Date())); + refundObj.put(WxPayConstant.PROMOTION_AMOUNT, 0); + refundObj.put(WxPayConstant.AMOUNT_LEFT_AFTER_PAY, amountLeftAfterPay + couponOrderCVo.getPrice()); + retMap.put(WxPayConstant.COUPON_REFUND_RESULT, JSON.toJSONString(refundObj)); return retMap; } catch (MallinkException e) { logger.error(e.getMessage()); @@ -1430,9 +1132,9 @@ public class PosServiceImpl implements PosService { } } - String errMessage = "取消异常:未知的核销状态-" + couponOrderCVo.getCouponOrderStatus()+ ", 场景-" + iSceneType; + String errMessage = String.format("核销撤销异常:券%s场景%s核销状态%d,不可撤销", couponOrderIdStr, sceneTypeStr, couponOrderCVo.getCouponOrderStatus()); logger.error(errMessage); - throw new MallinkException(500, errMessage); + throw new MallinkException(ErrorCode.POS_COUPON_REFUND_ERROR.getCode(), errMessage); } /** @@ -1698,8 +1400,10 @@ 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 sceneTypeStr = params.get(WxPayConstant.SCENE_TYPE); // 交易场景 String posOrderIdStr = params.get(WxPayConstant.POS_ORDER_ID); // POS订单ID String posAmountStr = params.get(WxPayConstant.ORDER_AMOUNT); // POS订单总额(单位:分) + String posAmountLeftStr = params.get(WxPayConstant.ORDER_AMOUNT_LEFT); // POS订单总额(单位:分) String cardIdStr = params.get(WxPayConstant.CARD_ID); // 消费卡ID if (StringUtils.isBlank(tenantId)) { @@ -1936,6 +1640,7 @@ public class PosServiceImpl implements PosService { String posOrderIdStr = params.get(WxPayConstant.NEU_ORDER_ID); // POS订单ID String posOrderTimeStr = params.get(WxPayConstant.NEU_ORDER_TIME); // POS订单时间 String posAmountStr = params.get(WxPayConstant.NEU_ORDER_AMOUNT); // POS订单总额 + String orderCreateSN = params.get(WxPayConstant.ORDER_CREATE_SN); // POS SN号 String posStatusStr = params.get(WxPayConstant.NEU_ORDER_STATUS); // 订单状态: 0有效,1取消,根据订单状态处理优惠券;有效:优惠券从预核销处理为核销; // 1. check params @@ -1968,6 +1673,9 @@ public class PosServiceImpl implements PosService { if (StringUtils.isBlank(posAmountStr)) { errParam(WxPayConstant.NEU_ORDER_AMOUNT); } + if (StringUtils.isBlank(orderCreateSN)) { + errParam(WxPayConstant.NEU_ORDER_CREATE_SN); + } if (StringUtils.isBlank(posStatusStr)) { errParam(WxPayConstant.NEU_ORDER_STATUS); } diff --git a/mallinkService/src/main/java/com/iformall/common/ErrorCode.java b/mallinkService/src/main/java/com/iformall/common/ErrorCode.java index d2497ae73..5b313aea4 100644 --- a/mallinkService/src/main/java/com/iformall/common/ErrorCode.java +++ b/mallinkService/src/main/java/com/iformall/common/ErrorCode.java @@ -246,7 +246,7 @@ public enum ErrorCode{ POS_COUPON_ORDER_VERIFY_NOT_CANCEL(11104, "此券核销无法取消"), POS_COUPON_PAY_ERROR(11105, "POS券包支付异常"), POS_CAR_PAY_NOT_CANCEL(11106, "卡支付无法取消"), - + POS_COUPON_REFUND_ERROR(11105, "POS券包退款异常"), POS_CMD_FAIL(11200, "POS命令错误"),