From d7836012ac71572ac4be5d6072a4712f882dbc77 Mon Sep 17 00:00:00 2001 From: Stormeye Wu Date: Mon, 26 Aug 2019 16:13:00 +0800 Subject: [PATCH] =?UTF-8?q?[POS][=E4=BF=AE=E6=94=B9]:POS=20code=20?= =?UTF-8?q?=E6=95=B4=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/iformall/service/PosService.java | 10 + .../iformall/service/impl/PosServiceImpl.java | 465 ++++++++++-------- .../java/com/iformall/common/ErrorCode.java | 1 + .../com/iformall/enums/EnumPosPamentType.java | 41 ++ .../com/iformall/enums/EnumPosRefundType.java | 42 ++ .../java/com/iformall/pay/WxPayConstant.java | 37 ++ 6 files changed, 396 insertions(+), 200 deletions(-) create mode 100644 mallinkService/src/main/java/com/iformall/enums/EnumPosPamentType.java create mode 100644 mallinkService/src/main/java/com/iformall/enums/EnumPosRefundType.java diff --git a/mallinkPosApi/src/main/java/com/iformall/service/PosService.java b/mallinkPosApi/src/main/java/com/iformall/service/PosService.java index 51696d986..33af9520d 100644 --- a/mallinkPosApi/src/main/java/com/iformall/service/PosService.java +++ b/mallinkPosApi/src/main/java/com/iformall/service/PosService.java @@ -78,6 +78,14 @@ public interface PosService { */ Map cardPayPreCancel(Map params) throws MallinkException; + /** + * 订单同步-Neusoft-支付或者退款成功后通知富茂 + * @param params + * @return + * @throws MallinkException + */ + Map posOrderSync(Map params) throws MallinkException; + /** * 消费卡POS支付 * @param params @@ -94,4 +102,6 @@ public interface PosService { * @throws MallinkException */ Map cardPayCancel(Map params) throws MallinkException; + + } 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 5d53f3f77..f7941f207 100644 --- a/mallinkPosApi/src/main/java/com/iformall/service/impl/PosServiceImpl.java +++ b/mallinkPosApi/src/main/java/com/iformall/service/impl/PosServiceImpl.java @@ -70,19 +70,13 @@ public class PosServiceImpl implements PosService { String password = params.get(WxPayConstant.PASSWORD); // buUser's password if (StringUtils.isBlank(tenantId)) { - String errMessage = "request params[tenant_id] error."; - logger.error(errMessage); - throw new MallinkException(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(), errMessage); + errParam(WxPayConstant.TENANT_ID); } if (StringUtils.isBlank(phone)) { - String errMessage = "request params[phone] error."; - logger.error(errMessage); - throw new MallinkException(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(), errMessage); + errParam(WxPayConstant.PHONE); } if (StringUtils.isBlank(password)) { - String errMessage = "request params[password] error."; - logger.error(errMessage); - throw new MallinkException(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(), errMessage); + errParam(WxPayConstant.PASSWORD); } WxMerchantBUser user = new WxMerchantBUser(); user.setTenantId(tenantId); @@ -93,26 +87,12 @@ public class PosServiceImpl implements PosService { try { user1 = merchantBUserService.getBUserByAppId(user); } catch (Exception e) { - String errMessage = "B端用户不存在或者已被禁用, phone: " + phone + ", " +e.getMessage(); - throw new MallinkException(ErrorCode.USER_IS_EMPTY.getCode(), errMessage); + String errMessage = ErrorCode.MERCHANT_BUSER_NOT_VALID.getMessage() + "phone: " + phone + ", " +e.getMessage(); + throw new MallinkException(ErrorCode.MERCHANT_BUSER_NOT_VALID.getCode(), errMessage); } if (user1 != null) { // check merchant 状态 - WxMerchant merchant = null; - try { - merchant = merchantService.getById(user1.getMerchantId()); - } catch (Exception e) { - String errMessage = ErrorCode.DB_FAIL.getMessage() + ": " + user1.getMerchantId() + e.getMessage(); - throw new MallinkException(ErrorCode.DB_FAIL.getCode(), errMessage); - } - if (merchant == null) { - logger.error(ErrorCode.MERCHANT_INFO_NOT_FOUND.getMessage() + ": " + user1.getMerchantId()); - throw new MallinkException(ErrorCode.MERCHANT_INFO_NOT_FOUND); - } - if (merchant.getStatus().equals(EnumMerchantStatus.NOT_VALID.getCode())) { - logger.error(ErrorCode.MERCHANT_INFO_NOT_VALID.getMessage() + ": " + user1.getMerchantId()); - throw new MallinkException(ErrorCode.MERCHANT_INFO_NOT_VALID); - } + WxMerchant merchant = checkAndGetMerchant(user1.getMerchantId()); // check password if (user1.getUserPwd().equalsIgnoreCase(password)) { retMap.put(WxPayConstant.TENANT_ID, user1.getTenantId()); @@ -141,9 +121,7 @@ public class PosServiceImpl implements PosService { String tenantId = params.get(WxPayConstant.TENANT_ID); // 租户ID if (StringUtils.isBlank(tenantId)) { - String errMessage = "request params[tenant_id] error."; - logger.error(errMessage); - throw new MallinkException(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(), errMessage); + errParam(WxPayConstant.TENANT_ID); } PosMallConfig config = posMallConfigService.getByTenantId(tenantId); if (config == null) { @@ -168,9 +146,7 @@ public class PosServiceImpl implements PosService { String tenantId = params.get(WxPayConstant.TENANT_ID); // 租户ID if (StringUtils.isBlank(tenantId)) { - String errMessage = "request params[tenant_id] error."; - logger.error(errMessage); - throw new MallinkException(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(), errMessage); + errParam(WxPayConstant.TENANT_ID); } WxMall mall = mallService.getByTenantId(tenantId); if (mall == null) { @@ -199,9 +175,7 @@ public class PosServiceImpl implements PosService { String posAmountStr = params.get(WxPayConstant.POS_AMOUNT); // POS订单金额(单位:分) if (StringUtils.isBlank(tenantId)) { - String errMessage = "request params[tenant_id] error."; - logger.error(errMessage); - throw new MallinkException(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(), errMessage); + errParam(WxPayConstant.TENANT_ID); } PosMallConfig config = posMallConfigService.getByTenantId(tenantId); @@ -211,19 +185,13 @@ public class PosServiceImpl implements PosService { } if (StringUtils.isBlank(merchantIdStr)) { - String errMessage = "request params[merchant_id] error."; - logger.error(errMessage); - throw new MallinkException(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(), errMessage); + errParam(WxPayConstant.MERCHANT_ID); } if (StringUtils.isBlank(posOrderIdStr)) { - String errMessage = "request params[pos_order_id] error."; - logger.error(errMessage); - throw new MallinkException(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(), errMessage); + errParam(WxPayConstant.POS_ORDER_ID); } if (StringUtils.isBlank(posAmountStr)) { - String errMessage = "request params[pos_amount] error."; - logger.error(errMessage); - throw new MallinkException(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(), errMessage); + errParam(WxPayConstant.POS_AMOUNT); } if (StringUtils.isBlank(memIdStr) && StringUtils.isBlank(memPhoneStr)) { @@ -354,9 +322,7 @@ public class PosServiceImpl implements PosService { String posAmountStr = params.get(WxPayConstant.POS_AMOUNT); // POS订单总额(单位:分) if (StringUtils.isBlank(tenantId)) { - String errMessage = "request params[tenant_id] error."; - logger.error(errMessage); - throw new MallinkException(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(), errMessage); + errParam(WxPayConstant.TENANT_ID); } PosMallConfig config = posMallConfigService.getByTenantId(tenantId); if (config == null) { @@ -368,22 +334,17 @@ public class PosServiceImpl implements PosService { throw new MallinkException(ErrorCode.POS_CONFIG_MEM_COUPON_DISABLE); } if (StringUtils.isBlank(merchantIdStr)) { - String errMessage = "request params[merchant_id] error."; - logger.error(errMessage); - throw new MallinkException(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(), errMessage); + errParam(WxPayConstant.MERCHANT_ID); } if (StringUtils.isBlank(buUserIdStr)) { - String errMessage = "request params[bu_user_id] error."; - throw new MallinkException(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(), errMessage); + errParam(WxPayConstant.BUSER_ID); } if (StringUtils.isBlank(couponOrderIdStr)) { - String errMessage = "request params[coupon_order_id] error."; - throw new MallinkException(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(), errMessage); + errParam(WxPayConstant.COUPON_ORDER_ID); } 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); + errParam(WxPayConstant.VERIFY_TYPE); } if (!(verifyType.equalsIgnoreCase(WxPayConstant.VERIFY_TYPE_INDEPENT) || verifyType.equalsIgnoreCase(WxPayConstant.VERIFY_TYPE_PAY))) { String errMessage = "request params[verify_type] only support independent or pay."; @@ -398,15 +359,13 @@ public class PosServiceImpl implements PosService { actionType.equals(EnumVerifyActionType.VERIFY_INDEPENT) || actionType.equals(EnumVerifyActionType.VERIFY_PAY)) { if (StringUtils.isBlank(posOrderIdStr)) { - String errMessage = "request params[pos_order_id] error."; - throw new MallinkException(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(), errMessage); + errParam(WxPayConstant.POS_ORDER_ID); } } if (actionType.equals(EnumVerifyActionType.PRE_VERIFY) || actionType.equals(EnumVerifyActionType.VERIFY_PAY)) { if (StringUtils.isBlank(posAmountStr)) { - String errMessage = "request params[pos_amount] error."; - throw new MallinkException(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(), errMessage); + errParam(WxPayConstant.POS_AMOUNT); } } @@ -429,25 +388,9 @@ public class PosServiceImpl implements PosService { throw new MallinkException(ErrorCode.SYS_PARAMETER_CAST_ERROR.getCode(), e.getMessage()); } // 2. check merchant - WxMerchant merchant = merchantService.getById(merchantId); - if (merchant == null) { - logger.error(ErrorCode.MERCHANT_INFO_NOT_FOUND.getMessage() + ": " + merchantIdStr); - throw new MallinkException(ErrorCode.MERCHANT_INFO_NOT_FOUND); - } - if (merchant.getIsDel().equals(EnumDelStatus.DEL.getCode()) || merchant.getStatus().equals(EnumMerchantStatus.NOT_VALID.getCode())) { - logger.error(ErrorCode.MERCHANT_INFO_NOT_VALID.getMessage() + ": " + merchantIdStr); - throw new MallinkException(ErrorCode.MERCHANT_INFO_NOT_VALID); - } + WxMerchant merchant = checkAndGetMerchant(merchantId); // 3. check buUser - WxMerchantBUser buUser = merchantBUserService.getById(buUserId); - if (buUser == null) { - logger.error(ErrorCode.USER_IS_EMPTY.getMessage() + ": " + buUserIdStr); - throw new MallinkException(ErrorCode.USER_IS_EMPTY); - } - if (!buUser.getMerchantId().equals(merchantId)) { - logger.error(ErrorCode.VERIFY_BUSER_MERCHANT_NOT_BELONG.getMessage() + ": " + buUserIdStr); - throw new MallinkException(ErrorCode.VERIFY_BUSER_MERCHANT_NOT_BELONG); - } + WxMerchantBUser buUser = checkAndGetMerchantUser(buUserId, merchantId); JSONArray coRetArr = new JSONArray(); if (couponOrderIdStr != null) { @@ -481,9 +424,7 @@ public class PosServiceImpl implements PosService { String verifyType = WxPayConstant.VERIFY_TYPE_PAY; // 此接口只有支付使用 if (StringUtils.isBlank(tenantId)) { - String errMessage = "request params[tenant_id] error."; - logger.error(errMessage); - throw new MallinkException(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(), errMessage); + errParam(WxPayConstant.TENANT_ID); } PosMallConfig config = posMallConfigService.getByTenantId(tenantId); if (config == null) { @@ -495,26 +436,20 @@ public class PosServiceImpl implements PosService { throw new MallinkException(ErrorCode.POS_CONFIG_MEM_COUPON_DISABLE); } if (StringUtils.isBlank(merchantIdStr)) { - String errMessage = "request params[merchant_id] error."; - logger.error(errMessage); - throw new MallinkException(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(), errMessage); + errParam(WxPayConstant.MERCHANT_ID); } if (StringUtils.isBlank(buUserIdStr)) { - String errMessage = "request params[bu_user_id] error."; - throw new MallinkException(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(), errMessage); + errParam(WxPayConstant.BUSER_ID); } if (StringUtils.isBlank(selCoListStr)) { - String errMessage = "request params[sel_co_list] error."; - throw new MallinkException(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(), errMessage); + errParam(WxPayConstant.SELECTED_COUPON_ORDER_LIST); } if (actionType.equals(EnumVerifyActionType.PRE_VERIFY) || actionType.equals(EnumVerifyActionType.VERIFY_INDEPENT)) { if (StringUtils.isBlank(posOrderIdStr)) { - String errMessage = "request params[pos_order_id] error."; - throw new MallinkException(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(), errMessage); + errParam(WxPayConstant.POS_ORDER_ID); } if (StringUtils.isBlank(posAmountStr)) { - String errMessage = "request params[pos_amount] error."; - throw new MallinkException(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(), errMessage); + errParam(WxPayConstant.POS_AMOUNT); } } @@ -534,25 +469,9 @@ public class PosServiceImpl implements PosService { throw new MallinkException(ErrorCode.SYS_PARAMETER_CAST_ERROR.getCode(), e.getMessage()); } // 2. check merchant - WxMerchant merchant = merchantService.getById(merchantId); - if (merchant == null) { - logger.error(ErrorCode.MERCHANT_INFO_NOT_FOUND.getMessage() + ": " + merchantIdStr); - throw new MallinkException(ErrorCode.MERCHANT_INFO_NOT_FOUND); - } - if (merchant.getIsDel().equals(EnumDelStatus.DEL.getCode()) || merchant.getStatus().equals(EnumMerchantStatus.NOT_VALID.getCode())) { - logger.error(ErrorCode.MERCHANT_INFO_NOT_VALID.getMessage() + ": " + merchantIdStr); - throw new MallinkException(ErrorCode.MERCHANT_INFO_NOT_VALID); - } + WxMerchant merchant = checkAndGetMerchant(merchantId); // 3. check buUser - WxMerchantBUser buUser = merchantBUserService.getById(buUserId); - if (buUser == null) { - logger.error(ErrorCode.USER_IS_EMPTY.getMessage() + ": " + buUserIdStr); - throw new MallinkException(ErrorCode.USER_IS_EMPTY); - } - if (!buUser.getMerchantId().equals(merchantId)) { - logger.error(ErrorCode.VERIFY_BUSER_MERCHANT_NOT_BELONG.getMessage() + ": " + buUserIdStr); - throw new MallinkException(ErrorCode.VERIFY_BUSER_MERCHANT_NOT_BELONG); - } + WxMerchantBUser buUser = checkAndGetMerchantUser(buUserId, merchantId); JSONArray selCoArr = JSONObject.parseArray(selCoListStr); if (selCoArr.size() <= 0) { @@ -657,11 +576,10 @@ public class PosServiceImpl implements PosService { throw new MallinkException(ErrorCode.COUPON_ORDER_IS_USED); } - Long couponOrderId = couponOrderCVo.getId(); + Date now = new Date(); // 5. 检查有效期 if (couponOrderCVo.getValidStartDate() != null && couponOrderCVo.getValidEndDate() != null) { - Date now = new Date(); if (couponOrderCVo.getValidStartDate().getTime() > now.getTime()) { logger.error("此券有效期未开始:" + couponOrderIdStr); throw new MallinkException(ErrorCode.COUPON_ORDER_IS_EARLIER_THAN_VALIDDATE); @@ -671,6 +589,13 @@ public class PosServiceImpl implements PosService { 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(); @@ -854,30 +779,20 @@ public class PosServiceImpl implements PosService { String forceStr = params.get(WxPayConstant.FORCE); // 是否强制 if (StringUtils.isBlank(tenantId)) { - String errMessage = "request params[tenant_id] error."; - logger.error(errMessage); - throw new MallinkException(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(), errMessage); + errParam(WxPayConstant.TENANT_ID); } if (StringUtils.isBlank(merchantIdStr)) { - String errMessage = "request params[merchant_id] error."; - logger.error(errMessage); - throw new MallinkException(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(), errMessage); + errParam(WxPayConstant.MERCHANT_ID); } if (StringUtils.isBlank(buUserIdStr)) { - String errMessage = "request params[bu_user_id] error."; - logger.error(errMessage); - throw new MallinkException(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(), errMessage); + errParam(WxPayConstant.BUSER_ID); } if (StringUtils.isBlank(couponOrderIdStr)) { - String errMessage = "request params[coupon_order_id] error."; - logger.error(errMessage); - throw new MallinkException(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(), errMessage); + errParam(WxPayConstant.COUPON_ORDER_ID); } if (actionType.equals(EnumVerifyActionType.PRE_VERIFY) || actionType.equals(EnumVerifyActionType.VERIFY_INDEPENT)) { if (StringUtils.isBlank(posOrderIdStr)) { - String errMessage = "request params[pos_order_id] error."; - logger.error(errMessage); - throw new MallinkException(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(), errMessage); + errParam(WxPayConstant.POS_ORDER_ID); } } @@ -902,6 +817,10 @@ public class PosServiceImpl implements PosService { logger.error(ErrorCode.USER_IS_EMPTY.getMessage() + ": " + buUserIdStr); throw new MallinkException(ErrorCode.USER_IS_EMPTY); } + if (buUser.getMerchantId().equals(merchantId)) { + logger.error(ErrorCode.VERIFY_BUSER_MERCHANT_NOT_BELONG.getMessage() + ": " + buUserId); + throw new MallinkException(ErrorCode.VERIFY_BUSER_MERCHANT_NOT_BELONG); + } // 4. check couponOrderId WxCouponOrderCVo couponOrderCVo = couponOrderService.detailCUserVo(couponOrderIdStr); if (couponOrderCVo == null) { @@ -1078,7 +997,8 @@ public class PosServiceImpl implements PosService { * @param buUserId * @param posOrderId */ - private void doVerify(EnumVerifyActionType actionType, WxCouponOrderCVo couponOrderCVo, WxCoupon coupon, Long merchantId, Long buUserId, Long posOrderId, Map retMap) { + private void doVerify(EnumVerifyActionType actionType, WxCouponOrderCVo couponOrderCVo, WxCoupon coupon, + Long merchantId, Long buUserId, Long posOrderId, Map retMap) { int num = 0; // 1. insert posOrderId PosCouponOrderVerify posCouponOrderVerify = new PosCouponOrderVerify(); @@ -1135,7 +1055,7 @@ public class PosServiceImpl implements PosService { try { WxOrder order = orderMapper.selectByPrimaryKey(couponOrderCVo.getOrderId()); int point = scoreRulesService.addScore2(EnumScoreType.CONSUMPTION, order, couponOrderCVo.getBusinessId()); - retMap.put("point", String.valueOf(point)); + retMap.put(WxPayConstant.POINT, String.valueOf(point)); } catch (Exception e) { logger.error("核销成长值异常:" + e.getMessage()); } @@ -1157,7 +1077,7 @@ public class PosServiceImpl implements PosService { creditHistory.setMerchantId(merchantId); creditHistory = creditHistoryService.saveOrUpdate(creditHistory); if (creditHistory.getCreditNum() != null) { - retMap.put("credit", String.valueOf(creditHistory.getCreditNum())); + retMap.put(WxPayConstant.CREDIT, String.valueOf(creditHistory.getCreditNum())); } } catch (Exception e) { logger.error("核销积分值异常:" + e.getMessage()); @@ -1275,25 +1195,19 @@ public class PosServiceImpl implements PosService { throw new MallinkException(ErrorCode.POS_CONFIG_MEM_COUPON_DISABLE); } if (StringUtils.isBlank(merchantIdStr)) { - String errMessage = "request params[merchant_id] error."; - logger.error(errMessage); - throw new MallinkException(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(), errMessage); + errParam(WxPayConstant.MERCHANT_ID); } if (StringUtils.isBlank(buUserIdStr)) { - String errMessage = "request params[bu_user_id] error."; - throw new MallinkException(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(), errMessage); + errParam(WxPayConstant.BUSER_ID); } if (StringUtils.isBlank(posOrderIdStr)) { - String errMessage = "request params[pos_order_id] error."; - throw new MallinkException(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(), errMessage); + errParam(WxPayConstant.POS_ORDER_ID); } if (StringUtils.isBlank(posAmountStr)) { - String errMessage = "request params[pos_amount] error."; - throw new MallinkException(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(), errMessage); + errParam(WxPayConstant.POS_AMOUNT); } if (StringUtils.isBlank(cardIdStr)) { - String errMessage = "request params[card_id] error."; - throw new MallinkException(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(), errMessage); + errParam(WxPayConstant.CARD_ID); } Long merchantId, buUserId, posOrderId, cardId; @@ -1393,9 +1307,7 @@ public class PosServiceImpl implements PosService { String cardSpendIdStr = params.get(WxPayConstant.CARD_SPEND_ID); // 消费卡花费ID if (StringUtils.isBlank(tenantId)) { - String errMessage = "request params[tenant_id] error."; - logger.error(errMessage); - throw new MallinkException(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(), errMessage); + errParam(WxPayConstant.TENANT_ID); } PosMallConfig config = posMallConfigService.getByTenantId(tenantId); if (config == null) { @@ -1407,29 +1319,22 @@ public class PosServiceImpl implements PosService { throw new MallinkException(ErrorCode.POS_CONFIG_MEM_COUPON_DISABLE); } if (StringUtils.isBlank(merchantIdStr)) { - String errMessage = "request params[merchant_id] error."; - logger.error(errMessage); - throw new MallinkException(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(), errMessage); + errParam(WxPayConstant.MERCHANT_ID); } if (StringUtils.isBlank(buUserIdStr)) { - String errMessage = "request params[bu_user_id] error."; - throw new MallinkException(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(), errMessage); + errParam(WxPayConstant.BUSER_ID); } if (StringUtils.isBlank(posOrderIdStr)) { - String errMessage = "request params[pos_order_id] error."; - throw new MallinkException(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(), errMessage); + errParam(WxPayConstant.POS_ORDER_ID); } if (StringUtils.isBlank(posAmountStr)) { - String errMessage = "request params[pos_amount] error."; - throw new MallinkException(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(), errMessage); + errParam(WxPayConstant.POS_AMOUNT); } if (StringUtils.isBlank(cardIdStr)) { - String errMessage = "request params[card_id] error."; - throw new MallinkException(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(), errMessage); + errParam(WxPayConstant.CARD_ID); } if (StringUtils.isBlank(cardSpendIdStr)) { - String errMessage = "request params[card_spend_id] error."; - throw new MallinkException(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(), errMessage); + errParam(WxPayConstant.CARD_SPEND_ID); } Long merchantId, buUserId, posOrderId, cardId, cardSpendId; @@ -1458,25 +1363,9 @@ public class PosServiceImpl implements PosService { throw new MallinkException(ErrorCode.COUPON_ORDER_MERANT_IS_NULL.getCode(), errMessage); } // 2. check merchant - WxMerchant merchant = merchantService.getById(merchantId); - if (merchant == null) { - logger.error(ErrorCode.MERCHANT_INFO_NOT_FOUND.getMessage() + ": " + merchantIdStr); - throw new MallinkException(ErrorCode.MERCHANT_INFO_NOT_FOUND); - } - if (merchant.getIsDel().equals(EnumDelStatus.DEL.getCode()) || merchant.getStatus().equals(EnumMerchantStatus.NOT_VALID.getCode())) { - logger.error(ErrorCode.MERCHANT_INFO_NOT_VALID.getMessage() + ": " + merchantIdStr); - throw new MallinkException(ErrorCode.MERCHANT_INFO_NOT_VALID); - } + WxMerchant merchant = checkAndGetMerchant(merchantId); // 3. check buUser - WxMerchantBUser buUser = merchantBUserService.getById(buUserId); - if (buUser == null) { - logger.error(ErrorCode.USER_IS_EMPTY.getMessage() + ": " + buUserIdStr); - throw new MallinkException(ErrorCode.USER_IS_EMPTY); - } - if (!buUser.getMerchantId().equals(merchantId)) { - logger.error(ErrorCode.VERIFY_BUSER_MERCHANT_NOT_BELONG.getMessage() + ": " + buUserIdStr); - throw new MallinkException(ErrorCode.VERIFY_BUSER_MERCHANT_NOT_BELONG); - } + WxMerchantBUser buUser = checkAndGetMerchantUser(buUserId, merchantId); WxCouponOrder couponOrder = couponOrderService.getById(cardId); if(couponOrder == null) { @@ -1533,9 +1422,7 @@ public class PosServiceImpl implements PosService { String cardSpendIdStr = params.get(WxPayConstant.CARD_SPEND_ID); // 消费卡花费ID if (StringUtils.isBlank(tenantId)) { - String errMessage = "request params[tenant_id] error."; - logger.error(errMessage); - throw new MallinkException(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(), errMessage); + errParam(WxPayConstant.TENANT_ID); } PosMallConfig config = posMallConfigService.getByTenantId(tenantId); if (config == null) { @@ -1547,29 +1434,22 @@ public class PosServiceImpl implements PosService { throw new MallinkException(ErrorCode.POS_CONFIG_MEM_COUPON_DISABLE); } if (StringUtils.isBlank(merchantIdStr)) { - String errMessage = "request params[merchant_id] error."; - logger.error(errMessage); - throw new MallinkException(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(), errMessage); + errParam(WxPayConstant.MERCHANT_ID); } if (StringUtils.isBlank(buUserIdStr)) { - String errMessage = "request params[bu_user_id] error."; - throw new MallinkException(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(), errMessage); + errParam(WxPayConstant.BUSER_ID); } if (StringUtils.isBlank(posOrderIdStr)) { - String errMessage = "request params[pos_order_id] error."; - throw new MallinkException(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(), errMessage); + errParam(WxPayConstant.POS_ORDER_ID); } if (StringUtils.isBlank(posAmountStr)) { - String errMessage = "request params[pos_amount] error."; - throw new MallinkException(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(), errMessage); + errParam(WxPayConstant.POS_AMOUNT); } if (StringUtils.isBlank(cardIdStr)) { - String errMessage = "request params[card_id] error."; - throw new MallinkException(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(), errMessage); + errParam(WxPayConstant.CARD_ID); } if (StringUtils.isBlank(cardSpendIdStr)) { - String errMessage = "request params[card_spend_id] error."; - throw new MallinkException(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(), errMessage); + errParam(WxPayConstant.CARD_SPEND_ID); } Long merchantId, buUserId, posOrderId, cardId, cardSpendId; @@ -1608,15 +1488,7 @@ public class PosServiceImpl implements PosService { throw new MallinkException(ErrorCode.MERCHANT_INFO_NOT_VALID); } // 3. check buUser - WxMerchantBUser buUser = merchantBUserService.getById(buUserId); - if (buUser == null) { - logger.error(ErrorCode.USER_IS_EMPTY.getMessage() + ": " + buUserIdStr); - throw new MallinkException(ErrorCode.USER_IS_EMPTY); - } - if (!buUser.getMerchantId().equals(merchantId)) { - logger.error(ErrorCode.VERIFY_BUSER_MERCHANT_NOT_BELONG.getMessage() + ": " + buUserIdStr); - throw new MallinkException(ErrorCode.VERIFY_BUSER_MERCHANT_NOT_BELONG); - } + WxMerchantBUser buUser = checkAndGetMerchantUser(buUserId, merchantId); WxCouponOrder couponOrder = couponOrderService.getById(cardId); if(couponOrder == null) { @@ -1652,4 +1524,197 @@ public class PosServiceImpl implements PosService { return retMap; } + + @Override + @Transactional(rollbackFor = Exception.class) + public Map posOrderSync(Map params) throws MallinkException { + Map retMap = new HashMap<>(); + + String tenantId = params.get(WxPayConstant.NEU_TENANT_ID); // 租户ID + String merchantIdStr = params.get(WxPayConstant.NEU_MERCHANT_ID); // 商户ID + String buUserIdStr = params.get(WxPayConstant.NEU_BU_USER_ID); // POS操作员ID + String cuUserIdStr = params.get(WxPayConstant.NEU_MEM_ID); // 富茂系统会员ID + 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 posStatusStr = params.get(WxPayConstant.NEU_ORDER_STATUS); // 订单状态: 0有效,1取消,根据订单状态处理优惠券;有效:优惠券从预核销处理为核销; + + // 1. check params + if (StringUtils.isBlank(tenantId)) { + errParam(WxPayConstant.NEU_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 (StringUtils.isBlank(merchantIdStr)) { + errParam(WxPayConstant.NEU_MERCHANT_ID); + } + if (StringUtils.isBlank(buUserIdStr)) { + errParam(WxPayConstant.NEU_BU_USER_ID); + } + if (StringUtils.isBlank(cuUserIdStr)) { + errParam(WxPayConstant.NEU_MEM_ID); + } + if (StringUtils.isBlank(posOrderIdStr)) { + errParam(WxPayConstant.NEU_ORDER_ID); + } + if (StringUtils.isBlank(posOrderTimeStr)) { + errParam(WxPayConstant.NEU_ORDER_TIME); + } + if (StringUtils.isBlank(posAmountStr)) { + errParam(WxPayConstant.NEU_ORDER_AMOUNT); + } + if (StringUtils.isBlank(posStatusStr)) { + errParam(WxPayConstant.NEU_ORDER_STATUS); + } + Long merchantId, buUserId, posOrderId, cardId; + Integer posAmount = 0; + try { + merchantId = Long.valueOf(merchantIdStr); + buUserId = Long.valueOf(buUserIdStr); + 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 merchantBUser = checkAndGetMerchantUser(merchantId, buUserId); + if (posStatusStr.equalsIgnoreCase("0")) { + // TODO + // add to wx_order + String payDetail = params.get(WxPayConstant.NEU_PAY_DETAIL); + JSONObject payDetailObj = JSON.parseObject(payDetail); + JSONArray payDetailList = payDetailObj.getJSONArray(WxPayConstant.NEU_PAY_DETAIL_LIST); + for (int i=0;i