|
|
@@ -924,7 +924,7 @@ public class PosServiceImpl implements PosService { |
|
|
String buUserIdStr = params.get(WxPayConstant.BUSER_ID); // POS操作员ID |
|
|
String buUserIdStr = params.get(WxPayConstant.BUSER_ID); // POS操作员ID |
|
|
String sceneTypeStr = params.get(WxPayConstant.SCENE_TYPE); // 交易场景 |
|
|
String sceneTypeStr = params.get(WxPayConstant.SCENE_TYPE); // 交易场景 |
|
|
String orderIdStr = params.get(WxPayConstant.POS_ORDER_ID); // POS订单ID |
|
|
String orderIdStr = params.get(WxPayConstant.POS_ORDER_ID); // POS订单ID |
|
|
String orderCreateSN = params.get(WxPayConstant.ORDER_CREATE_SN); // POS SN号 |
|
|
|
|
|
|
|
|
String orderCreateSN = params.get(WxPayConstant.ORDER_CREATE_SN); // POS SN号 |
|
|
String paymentInfoStr = params.get(WxPayConstant.PAYMENT_INFO); // 优惠信息 |
|
|
String paymentInfoStr = params.get(WxPayConstant.PAYMENT_INFO); // 优惠信息 |
|
|
|
|
|
|
|
|
if (StringUtils.isBlank(tenantId)) { |
|
|
if (StringUtils.isBlank(tenantId)) { |
|
|
@@ -1030,7 +1030,7 @@ public class PosServiceImpl implements PosService { |
|
|
couponOrderIdStr, couponOrderCVo.getPriceStr(), couponOrderCVo.getSalePriceStr()); |
|
|
couponOrderIdStr, couponOrderCVo.getPriceStr(), couponOrderCVo.getSalePriceStr()); |
|
|
refundObj.put(WxPayConstant.COUPON_REFUND_ID, couponOrderIdStr); |
|
|
refundObj.put(WxPayConstant.COUPON_REFUND_ID, couponOrderIdStr); |
|
|
refundObj.put(WxPayConstant.COUPON_REFUND_RESULT, "0"); |
|
|
refundObj.put(WxPayConstant.COUPON_REFUND_RESULT, "0"); |
|
|
refundObj.put(WxPayConstant.COUPON_REFUND_RESULT_MSG, errMesg); |
|
|
|
|
|
|
|
|
refundObj.put(WxPayConstant.REFUND_RESULT_MSG, errMesg); |
|
|
refundObj.put(WxPayConstant.REFUND_TIME_FROM_IFORMALL, neuDateFormat.format(new Date())); |
|
|
refundObj.put(WxPayConstant.REFUND_TIME_FROM_IFORMALL, neuDateFormat.format(new Date())); |
|
|
refundObj.put(WxPayConstant.PRICE, coupon.getPrice()); |
|
|
refundObj.put(WxPayConstant.PRICE, coupon.getPrice()); |
|
|
refundObj.put(WxPayConstant.SALE_PRICE, coupon.getSalePrice()); |
|
|
refundObj.put(WxPayConstant.SALE_PRICE, coupon.getSalePrice()); |
|
|
@@ -1120,7 +1120,7 @@ public class PosServiceImpl implements PosService { |
|
|
JSONObject refundObj = new JSONObject(); |
|
|
JSONObject refundObj = new JSONObject(); |
|
|
refundObj.put(WxPayConstant.COUPON_REFUND_ID, String.valueOf(couponOrderCVo.getId())); |
|
|
refundObj.put(WxPayConstant.COUPON_REFUND_ID, String.valueOf(couponOrderCVo.getId())); |
|
|
refundObj.put(WxPayConstant.COUPON_REFUND_RESULT, "0"); |
|
|
refundObj.put(WxPayConstant.COUPON_REFUND_RESULT, "0"); |
|
|
refundObj.put(WxPayConstant.COUPON_REFUND_RESULT_MSG, "核销撤销成功"); |
|
|
|
|
|
|
|
|
refundObj.put(WxPayConstant.REFUND_RESULT_MSG, "核销撤销成功"); |
|
|
refundObj.put(WxPayConstant.REFUND_TIME_FROM_IFORMALL, neuDateFormat.format(new Date())); |
|
|
refundObj.put(WxPayConstant.REFUND_TIME_FROM_IFORMALL, neuDateFormat.format(new Date())); |
|
|
refundObj.put(WxPayConstant.PROMOTION_AMOUNT, 0); |
|
|
refundObj.put(WxPayConstant.PROMOTION_AMOUNT, 0); |
|
|
refundObj.put(WxPayConstant.AMOUNT_LEFT_AFTER_PAY, amountLeftAfterPay + couponOrderCVo.getPrice()); |
|
|
refundObj.put(WxPayConstant.AMOUNT_LEFT_AFTER_PAY, amountLeftAfterPay + couponOrderCVo.getPrice()); |
|
|
@@ -1402,82 +1402,86 @@ public class PosServiceImpl implements PosService { |
|
|
String buUserIdStr = params.get(WxPayConstant.BUSER_ID); // POS操作员ID |
|
|
String buUserIdStr = params.get(WxPayConstant.BUSER_ID); // POS操作员ID |
|
|
String sceneTypeStr = params.get(WxPayConstant.SCENE_TYPE); // 交易场景 |
|
|
String sceneTypeStr = params.get(WxPayConstant.SCENE_TYPE); // 交易场景 |
|
|
String posOrderIdStr = params.get(WxPayConstant.POS_ORDER_ID); // POS订单ID |
|
|
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 |
|
|
|
|
|
|
|
|
String orderAmountStr = params.get(WxPayConstant.ORDER_AMOUNT); // POS订单总额(单位:分) |
|
|
|
|
|
String orderAmountLeftStr = params.get(WxPayConstant.ORDER_AMOUNT_LEFT); // 本次需要支付的订单金额(单位:分) |
|
|
|
|
|
String cardIdStr = params.get(WxPayConstant.CARD_ID); // 消费卡ID |
|
|
|
|
|
String amountByCardStr = params.get(WxPayConstant.AMOUNT_PAID_BY_CARD); // 预付卡支付金额 |
|
|
|
|
|
|
|
|
if (StringUtils.isBlank(tenantId)) { |
|
|
if (StringUtils.isBlank(tenantId)) { |
|
|
errParam(WxPayConstant.TENANT_ID); |
|
|
errParam(WxPayConstant.TENANT_ID); |
|
|
|
|
|
} else { |
|
|
|
|
|
retMap.put(WxPayConstant.TENANT_ID, tenantId); |
|
|
} |
|
|
} |
|
|
PosMallConfig config = posMallConfigService.getByTenantId(tenantId); |
|
|
PosMallConfig config = posMallConfigService.getByTenantId(tenantId); |
|
|
if (config == null) { |
|
|
if (config == null) { |
|
|
logger.error(ErrorCode.POS_CONFIG_NOT_FOUND.getMessage()); |
|
|
logger.error(ErrorCode.POS_CONFIG_NOT_FOUND.getMessage()); |
|
|
throw new MallinkException(ErrorCode.POS_CONFIG_NOT_FOUND); |
|
|
throw new MallinkException(ErrorCode.POS_CONFIG_NOT_FOUND); |
|
|
} |
|
|
} |
|
|
if (!config.getCard().equals(EnumEnableType.Enable.getCode())) { |
|
|
|
|
|
logger.error(ErrorCode.POS_CONFIG_MEM_COUPON_DISABLE.getMessage()); |
|
|
|
|
|
throw new MallinkException(ErrorCode.POS_CONFIG_MEM_COUPON_DISABLE); |
|
|
|
|
|
|
|
|
if (config.getCard().equals(EnumPosEnableType.Disable.getCode())) { |
|
|
|
|
|
logger.error(ErrorCode.POS_CONFIG_MEM_CARD_DISABLE.getMessage()); |
|
|
|
|
|
throw new MallinkException(ErrorCode.POS_CONFIG_MEM_CARD_DISABLE); |
|
|
} |
|
|
} |
|
|
if (StringUtils.isBlank(merchantIdStr)) { |
|
|
if (StringUtils.isBlank(merchantIdStr)) { |
|
|
errParam(WxPayConstant.MERCHANT_ID); |
|
|
errParam(WxPayConstant.MERCHANT_ID); |
|
|
|
|
|
} else { |
|
|
|
|
|
retMap.put(WxPayConstant.MERCHANT_ID, merchantIdStr); |
|
|
} |
|
|
} |
|
|
if (StringUtils.isBlank(buUserIdStr)) { |
|
|
if (StringUtils.isBlank(buUserIdStr)) { |
|
|
errParam(WxPayConstant.BUSER_ID); |
|
|
errParam(WxPayConstant.BUSER_ID); |
|
|
|
|
|
} else { |
|
|
|
|
|
retMap.put(WxPayConstant.BUSER_ID, buUserIdStr); |
|
|
|
|
|
} |
|
|
|
|
|
if (StringUtils.isBlank(sceneTypeStr)) { |
|
|
|
|
|
errParam(WxPayConstant.SCENE_TYPE); |
|
|
|
|
|
} else { |
|
|
|
|
|
retMap.put(WxPayConstant.SCENE_TYPE, sceneTypeStr); |
|
|
|
|
|
} |
|
|
|
|
|
if (!sceneTypeStr.equals(EnumPosSceneType.PAY.getCode().toString())) { |
|
|
|
|
|
logger.error(ErrorCode.POS_CARD_ONLY_SUPPORT_PAY.getMessage()); |
|
|
|
|
|
throw new MallinkException(ErrorCode.POS_CARD_ONLY_SUPPORT_PAY); |
|
|
} |
|
|
} |
|
|
if (StringUtils.isBlank(posOrderIdStr)) { |
|
|
if (StringUtils.isBlank(posOrderIdStr)) { |
|
|
errParam(WxPayConstant.POS_ORDER_ID); |
|
|
errParam(WxPayConstant.POS_ORDER_ID); |
|
|
|
|
|
} else { |
|
|
|
|
|
retMap.put(WxPayConstant.POS_ORDER_ID, posOrderIdStr); |
|
|
} |
|
|
} |
|
|
if (StringUtils.isBlank(posAmountStr)) { |
|
|
|
|
|
|
|
|
if (StringUtils.isBlank(orderAmountStr)) { |
|
|
errParam(WxPayConstant.ORDER_AMOUNT); |
|
|
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(cardIdStr)) { |
|
|
if (StringUtils.isBlank(cardIdStr)) { |
|
|
errParam(WxPayConstant.CARD_ID); |
|
|
errParam(WxPayConstant.CARD_ID); |
|
|
|
|
|
} else { |
|
|
|
|
|
retMap.put(WxPayConstant.CARD_ID, cardIdStr); |
|
|
|
|
|
} |
|
|
|
|
|
if (StringUtils.isBlank(amountByCardStr)) { |
|
|
|
|
|
errParam(WxPayConstant.AMOUNT_PAID_BY_CARD); |
|
|
|
|
|
} else { |
|
|
|
|
|
retMap.put(WxPayConstant.AMOUNT_PAID_BY_CARD, amountByCardStr); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
Long merchantId, buUserId, posOrderId, cardId; |
|
|
Long merchantId, buUserId, posOrderId, cardId; |
|
|
Integer posAmount = 0; |
|
|
|
|
|
|
|
|
Integer amountByCard = 0; |
|
|
try { |
|
|
try { |
|
|
merchantId = Long.valueOf(merchantIdStr); |
|
|
merchantId = Long.valueOf(merchantIdStr); |
|
|
buUserId = Long.valueOf(buUserIdStr); |
|
|
buUserId = Long.valueOf(buUserIdStr); |
|
|
posOrderId = Long.valueOf(posOrderIdStr); |
|
|
posOrderId = Long.valueOf(posOrderIdStr); |
|
|
posAmount = Integer.valueOf(posAmountStr); |
|
|
|
|
|
|
|
|
amountByCard = Integer.valueOf(amountByCardStr); |
|
|
cardId = Long.valueOf(cardIdStr); |
|
|
cardId = Long.valueOf(cardIdStr); |
|
|
} catch (NumberFormatException e) { |
|
|
} catch (NumberFormatException e) { |
|
|
logger.error(e.getMessage()); |
|
|
logger.error(e.getMessage()); |
|
|
throw new MallinkException(ErrorCode.SYS_PARAMETER_CAST_ERROR.getCode(), e.getMessage()); |
|
|
throw new MallinkException(ErrorCode.SYS_PARAMETER_CAST_ERROR.getCode(), e.getMessage()); |
|
|
} |
|
|
} |
|
|
WxCardInfo cardInfo = cardInfoService.getById(cardId); |
|
|
|
|
|
if(cardInfo == null) { |
|
|
|
|
|
String errMessage = "卡不存在: " + cardIdStr; |
|
|
|
|
|
logger.error(errMessage); |
|
|
|
|
|
throw new MallinkException(ErrorCode.CARD_IS_NOT_FOUND.getCode(), errMessage); |
|
|
|
|
|
} |
|
|
|
|
|
WxCouponMerchant couponMerchant = cardSpendService.checkMerchantInCoupon(cardInfo, merchantId); |
|
|
|
|
|
if(couponMerchant == null) { |
|
|
|
|
|
String errMessage = "商户不支持此卡 " + cardIdStr; |
|
|
|
|
|
logger.error(errMessage); |
|
|
|
|
|
throw new MallinkException(ErrorCode.COUPON_ORDER_MERANT_IS_NULL.getCode(), errMessage); |
|
|
|
|
|
} |
|
|
|
|
|
// 2. check merchant |
|
|
// 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 |
|
|
// 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); |
|
|
WxCouponOrder couponOrder = couponOrderService.getById(cardId); |
|
|
if(couponOrder == null) { |
|
|
if(couponOrder == null) { |
|
|
@@ -1485,10 +1489,13 @@ public class PosServiceImpl implements PosService { |
|
|
throw new MallinkException(ErrorCode.CARD_IS_NOT_FOUND); |
|
|
throw new MallinkException(ErrorCode.CARD_IS_NOT_FOUND); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
if(posAmount > cardInfo.getRemainingAmount()) { |
|
|
|
|
|
|
|
|
WxCardInfo cardInfo = checkAndGetCardinfo(cardId, merchantId); |
|
|
|
|
|
|
|
|
|
|
|
if(amountByCard > cardInfo.getRemainingAmount()) { |
|
|
logger.error("卡余额不足: " + cardIdStr); |
|
|
logger.error("卡余额不足: " + cardIdStr); |
|
|
throw new MallinkException(ErrorCode.CARD_REMAIN_AMOUNT_IS_NOT_ENOUGH); |
|
|
throw new MallinkException(ErrorCode.CARD_REMAIN_AMOUNT_IS_NOT_ENOUGH); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
WxCardSpend record = new WxCardSpend(); |
|
|
WxCardSpend record = new WxCardSpend(); |
|
|
record.setPayFrom(EnumCardSpendFrom.POS.getCode()); |
|
|
record.setPayFrom(EnumCardSpendFrom.POS.getCode()); |
|
|
record.setTenantId(merchant.getTenantId()); |
|
|
record.setTenantId(merchant.getTenantId()); |
|
|
@@ -1496,16 +1503,18 @@ public class PosServiceImpl implements PosService { |
|
|
record.setOwnerId(couponOrder.getOwnerId()); |
|
|
record.setOwnerId(couponOrder.getOwnerId()); |
|
|
record.setMerchantId(merchantId); |
|
|
record.setMerchantId(merchantId); |
|
|
record.setPosOrderId(posOrderId); |
|
|
record.setPosOrderId(posOrderId); |
|
|
record.setDeductionAmount(posAmount); |
|
|
|
|
|
|
|
|
record.setDeductionAmount(amountByCard); |
|
|
|
|
|
|
|
|
try { |
|
|
try { |
|
|
WxCardSpend cardSpend = cardSpendService.cardSpendForPosPrePay(record); |
|
|
WxCardSpend cardSpend = cardSpendService.cardSpendForPosPrePay(record); |
|
|
JSONObject retObj = new JSONObject(); |
|
|
|
|
|
retObj.put(WxPayConstant.ID, cardSpend.getId()); |
|
|
|
|
|
retObj.put(WxPayConstant.DEDUCT_AMOUNT, posAmount); |
|
|
|
|
|
retObj.put(WxPayConstant.REMAIN_AMOUNT, cardSpend.getCardRemainAmount()); |
|
|
|
|
|
retObj.put(WxPayConstant.PRE_PAY, WxPayConstant.TRUE); |
|
|
|
|
|
retMap.put(WxPayConstant.RET, JSON.toJSONString(retObj)); |
|
|
|
|
|
|
|
|
JSONObject cardPaymentObj = new JSONObject(); |
|
|
|
|
|
cardPaymentObj.put(WxPayConstant.CARD_ID, cardId); |
|
|
|
|
|
cardPaymentObj.put(WxPayConstant.CARD_AMOUNT_BEFORE_PAY, cardSpend.getCardBeforeAmount()); |
|
|
|
|
|
cardPaymentObj.put(WxPayConstant.PAYMENT_AMOUNT, cardSpend.getPayment()); |
|
|
|
|
|
cardPaymentObj.put(WxPayConstant.CARD_AMOUNT_AFTER_PAY, cardSpend.getCardRemainAmount()); |
|
|
|
|
|
cardPaymentObj.put(WxPayConstant.CARD_SPEND_ID, cardSpend.getId().toString()); |
|
|
|
|
|
cardPaymentObj.put(WxPayConstant.CARD_SPEND_TIME, neuDateFormat.format(cardSpend.getCreateDate())); |
|
|
|
|
|
retMap.put(WxPayConstant.CARD_PAYMENT_DATA, JSON.toJSONString(cardPaymentObj)); |
|
|
} catch (MallinkException e) { |
|
|
} catch (MallinkException e) { |
|
|
logger.error("card spend error, req 2: " + record.toString() + ", e:" + e.getMessage()); |
|
|
logger.error("card spend error, req 2: " + record.toString() + ", e:" + e.getMessage()); |
|
|
throw new MallinkException(e.getErrorCode(), e.getMessage()); |
|
|
throw new MallinkException(e.getErrorCode(), e.getMessage()); |
|
|
@@ -1525,67 +1534,105 @@ public class PosServiceImpl implements PosService { |
|
|
String tenantId = params.get(WxPayConstant.TENANT_ID); // 租户ID |
|
|
String tenantId = params.get(WxPayConstant.TENANT_ID); // 租户ID |
|
|
String merchantIdStr = params.get(WxPayConstant.MERCHANT_ID); // 商户ID |
|
|
String merchantIdStr = params.get(WxPayConstant.MERCHANT_ID); // 商户ID |
|
|
String buUserIdStr = params.get(WxPayConstant.BUSER_ID); // POS操作员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 cardIdStr = params.get(WxPayConstant.CARD_ID); // 消费卡ID |
|
|
|
|
|
String cardSpendIdStr = params.get(WxPayConstant.CARD_SPEND_ID); // 消费卡花费ID |
|
|
|
|
|
|
|
|
String sceneTypeStr = params.get(WxPayConstant.SCENE_TYPE); // 交易场景 |
|
|
|
|
|
String orderIdStr = params.get(WxPayConstant.POS_ORDER_ID); // POS订单ID |
|
|
|
|
|
String orderAmountStr = params.get(WxPayConstant.ORDER_AMOUNT); // POS订单总额(单位:分) |
|
|
|
|
|
String orderAmountLeftStr = params.get(WxPayConstant.ORDER_AMOUNT_LEFT); // 本次需要支付的剩余金额 |
|
|
|
|
|
String orderCreateSN = params.get(WxPayConstant.ORDER_CREATE_SN); // POS SN号 |
|
|
|
|
|
String paymentInfoStr = params.get(WxPayConstant.PAYMENT_INFO); // 优惠信息 |
|
|
|
|
|
|
|
|
if (StringUtils.isBlank(tenantId)) { |
|
|
if (StringUtils.isBlank(tenantId)) { |
|
|
errParam(WxPayConstant.TENANT_ID); |
|
|
errParam(WxPayConstant.TENANT_ID); |
|
|
|
|
|
} else { |
|
|
|
|
|
retMap.put(WxPayConstant.TENANT_ID, tenantId); |
|
|
} |
|
|
} |
|
|
PosMallConfig config = posMallConfigService.getByTenantId(tenantId); |
|
|
PosMallConfig config = posMallConfigService.getByTenantId(tenantId); |
|
|
if (config == null) { |
|
|
if (config == null) { |
|
|
logger.error(ErrorCode.POS_CONFIG_NOT_FOUND.getMessage()); |
|
|
logger.error(ErrorCode.POS_CONFIG_NOT_FOUND.getMessage()); |
|
|
throw new MallinkException(ErrorCode.POS_CONFIG_NOT_FOUND); |
|
|
throw new MallinkException(ErrorCode.POS_CONFIG_NOT_FOUND); |
|
|
} |
|
|
} |
|
|
if (!config.getCard().equals(EnumEnableType.Enable.getCode())) { |
|
|
|
|
|
logger.error(ErrorCode.POS_CONFIG_MEM_COUPON_DISABLE.getMessage()); |
|
|
|
|
|
throw new MallinkException(ErrorCode.POS_CONFIG_MEM_COUPON_DISABLE); |
|
|
|
|
|
|
|
|
if (config.getCard().equals(EnumPosEnableType.Disable.getCode())) { |
|
|
|
|
|
logger.error(ErrorCode.POS_CONFIG_MEM_CARD_DISABLE.getMessage()); |
|
|
|
|
|
throw new MallinkException(ErrorCode.POS_CONFIG_MEM_CARD_DISABLE); |
|
|
} |
|
|
} |
|
|
if (StringUtils.isBlank(merchantIdStr)) { |
|
|
if (StringUtils.isBlank(merchantIdStr)) { |
|
|
errParam(WxPayConstant.MERCHANT_ID); |
|
|
errParam(WxPayConstant.MERCHANT_ID); |
|
|
|
|
|
} else { |
|
|
|
|
|
retMap.put(WxPayConstant.MERCHANT_ID, merchantIdStr); |
|
|
} |
|
|
} |
|
|
if (StringUtils.isBlank(buUserIdStr)) { |
|
|
if (StringUtils.isBlank(buUserIdStr)) { |
|
|
errParam(WxPayConstant.BUSER_ID); |
|
|
errParam(WxPayConstant.BUSER_ID); |
|
|
|
|
|
} else { |
|
|
|
|
|
retMap.put(WxPayConstant.BUSER_ID, buUserIdStr); |
|
|
} |
|
|
} |
|
|
if (StringUtils.isBlank(posOrderIdStr)) { |
|
|
|
|
|
|
|
|
if (StringUtils.isBlank(sceneTypeStr)) { |
|
|
|
|
|
errParam(WxPayConstant.SCENE_TYPE); |
|
|
|
|
|
} else { |
|
|
|
|
|
retMap.put(WxPayConstant.SCENE_TYPE, sceneTypeStr); |
|
|
|
|
|
} |
|
|
|
|
|
if (!sceneTypeStr.equals(EnumPosSceneType.PAY.getCode().toString())) { |
|
|
|
|
|
logger.error(ErrorCode.POS_CARD_ONLY_SUPPORT_PAY.getMessage()); |
|
|
|
|
|
throw new MallinkException(ErrorCode.POS_CARD_ONLY_SUPPORT_PAY); |
|
|
|
|
|
} |
|
|
|
|
|
if (StringUtils.isBlank(orderIdStr)) { |
|
|
errParam(WxPayConstant.POS_ORDER_ID); |
|
|
errParam(WxPayConstant.POS_ORDER_ID); |
|
|
|
|
|
} else { |
|
|
|
|
|
retMap.put(WxPayConstant.POS_ORDER_ID, orderIdStr); |
|
|
} |
|
|
} |
|
|
if (StringUtils.isBlank(posAmountStr)) { |
|
|
|
|
|
|
|
|
if (StringUtils.isBlank(orderAmountStr)) { |
|
|
errParam(WxPayConstant.ORDER_AMOUNT); |
|
|
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, orderCreateSN); |
|
|
|
|
|
} |
|
|
|
|
|
if (StringUtils.isBlank(orderCreateSN)) { |
|
|
|
|
|
errParam(WxPayConstant.ORDER_CREATE_SN); |
|
|
|
|
|
} else { |
|
|
|
|
|
retMap.put(WxPayConstant.ORDER_CREATE_SN, orderAmountLeftStr); |
|
|
|
|
|
} |
|
|
|
|
|
if (StringUtils.isBlank(paymentInfoStr)) { |
|
|
|
|
|
errParam(WxPayConstant.PAYMENT_INFO); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
JSONObject paymentInfo = JSON.parseObject(paymentInfoStr); |
|
|
|
|
|
if (paymentInfo == null) { |
|
|
|
|
|
errParam(WxPayConstant.PAYMENT_INFO); |
|
|
|
|
|
} |
|
|
|
|
|
String cardIdStr = paymentInfo.getString(WxPayConstant.CARD_ID); |
|
|
if (StringUtils.isBlank(cardIdStr)) { |
|
|
if (StringUtils.isBlank(cardIdStr)) { |
|
|
errParam(WxPayConstant.CARD_ID); |
|
|
|
|
|
|
|
|
errParam(WxPayConstant.PAYMENT_INFO); |
|
|
} |
|
|
} |
|
|
|
|
|
String cardSpendIdStr = paymentInfo.getString(WxPayConstant.CARD_SPEND_ID); |
|
|
if (StringUtils.isBlank(cardSpendIdStr)) { |
|
|
if (StringUtils.isBlank(cardSpendIdStr)) { |
|
|
errParam(WxPayConstant.CARD_SPEND_ID); |
|
|
|
|
|
|
|
|
errParam(WxPayConstant.PAYMENT_INFO); |
|
|
|
|
|
} |
|
|
|
|
|
String amountPaidByCardStr = paymentInfo.getString(WxPayConstant.AMOUNT_PAID_BY_CARD); |
|
|
|
|
|
if (StringUtils.isBlank(amountPaidByCardStr)) { |
|
|
|
|
|
errParam(WxPayConstant.PAYMENT_INFO); |
|
|
|
|
|
} |
|
|
|
|
|
String amountLeftAfterPayStr = paymentInfo.getString(WxPayConstant.AMOUNT_LEFT_AFTER_PAY); |
|
|
|
|
|
if (StringUtils.isBlank(amountLeftAfterPayStr)) { |
|
|
|
|
|
errParam(WxPayConstant.PAYMENT_INFO); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
Long merchantId, buUserId, posOrderId, cardId, cardSpendId; |
|
|
Long merchantId, buUserId, posOrderId, cardId, cardSpendId; |
|
|
Integer posAmount = 0; |
|
|
|
|
|
|
|
|
Integer amountPaidByCard, amountLeftAfterPay; |
|
|
try { |
|
|
try { |
|
|
merchantId = Long.valueOf(merchantIdStr); |
|
|
merchantId = Long.valueOf(merchantIdStr); |
|
|
buUserId = Long.valueOf(buUserIdStr); |
|
|
buUserId = Long.valueOf(buUserIdStr); |
|
|
posOrderId = Long.valueOf(posOrderIdStr); |
|
|
|
|
|
posAmount = Integer.valueOf(posAmountStr); |
|
|
|
|
|
|
|
|
posOrderId = Long.valueOf(orderIdStr); |
|
|
cardId = Long.valueOf(cardIdStr); |
|
|
cardId = Long.valueOf(cardIdStr); |
|
|
cardSpendId = Long.valueOf(cardSpendIdStr); |
|
|
cardSpendId = Long.valueOf(cardSpendIdStr); |
|
|
|
|
|
amountPaidByCard = Integer.valueOf(amountLeftAfterPayStr); |
|
|
|
|
|
amountLeftAfterPay = Integer.valueOf(amountLeftAfterPayStr); |
|
|
} catch (NumberFormatException e) { |
|
|
} catch (NumberFormatException e) { |
|
|
logger.error(e.getMessage()); |
|
|
logger.error(e.getMessage()); |
|
|
throw new MallinkException(ErrorCode.SYS_PARAMETER_CAST_ERROR.getCode(), e.getMessage()); |
|
|
throw new MallinkException(ErrorCode.SYS_PARAMETER_CAST_ERROR.getCode(), e.getMessage()); |
|
|
} |
|
|
} |
|
|
WxCardInfo cardInfo = cardInfoService.getById(cardId); |
|
|
|
|
|
if(cardInfo == null) { |
|
|
|
|
|
String errMessage = "卡不存在: " + cardIdStr; |
|
|
|
|
|
logger.error(errMessage); |
|
|
|
|
|
throw new MallinkException(ErrorCode.CARD_IS_NOT_FOUND.getCode(), errMessage); |
|
|
|
|
|
} |
|
|
|
|
|
WxCouponMerchant couponMerchant = cardSpendService.checkMerchantInCoupon(cardInfo, merchantId); |
|
|
|
|
|
if(couponMerchant == null) { |
|
|
|
|
|
String errMessage = "商户不支持此卡 " + cardIdStr; |
|
|
|
|
|
logger.error(errMessage); |
|
|
|
|
|
throw new MallinkException(ErrorCode.COUPON_ORDER_MERANT_IS_NULL.getCode(), errMessage); |
|
|
|
|
|
} |
|
|
|
|
|
// 2. check merchant |
|
|
// 2. check merchant |
|
|
WxMerchant merchant = checkAndGetMerchant(merchantId); |
|
|
WxMerchant merchant = checkAndGetMerchant(merchantId); |
|
|
// 3. check buUser |
|
|
// 3. check buUser |
|
|
@@ -1597,24 +1644,28 @@ public class PosServiceImpl implements PosService { |
|
|
throw new MallinkException(ErrorCode.CARD_IS_NOT_FOUND); |
|
|
throw new MallinkException(ErrorCode.CARD_IS_NOT_FOUND); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
WxCardInfo cardInfo = checkAndGetCardinfo(cardId, merchantId); |
|
|
|
|
|
|
|
|
WxCardSpend record = cardSpendService.getById(cardSpendId); |
|
|
WxCardSpend record = cardSpendService.getById(cardSpendId); |
|
|
if (record == null) { |
|
|
if (record == null) { |
|
|
logger.error(ErrorCode.CARD_SPEND_IS_NOT_FOUND.getMessage() + ": " + cardSpendIdStr); |
|
|
logger.error(ErrorCode.CARD_SPEND_IS_NOT_FOUND.getMessage() + ": " + cardSpendIdStr); |
|
|
throw new MallinkException(ErrorCode.CARD_SPEND_IS_NOT_FOUND); |
|
|
throw new MallinkException(ErrorCode.CARD_SPEND_IS_NOT_FOUND); |
|
|
} |
|
|
} |
|
|
if (record.getPayStatus().equals(EnumCardSpendStatus.PREV_PAY.getCode())) { |
|
|
|
|
|
logger.error(ErrorCode.POS_CAR_PAY_NOT_CANCEL.getMessage()); |
|
|
|
|
|
throw new MallinkException(ErrorCode.POS_CAR_PAY_NOT_CANCEL); |
|
|
|
|
|
|
|
|
if (!record.getPayStatus().equals(EnumCardSpendStatus.PREV_PAY.getCode())) { |
|
|
|
|
|
logger.error(ErrorCode.POS_CARD_PAY_NOT_CANCEL.getMessage()); |
|
|
|
|
|
throw new MallinkException(ErrorCode.POS_CARD_PAY_NOT_CANCEL); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
try { |
|
|
try { |
|
|
WxCardInfo updateCardInfo = cardSpendService.cardSpendForPosPrePayCancel(cardInfo, record); |
|
|
WxCardInfo updateCardInfo = cardSpendService.cardSpendForPosPrePayCancel(cardInfo, record); |
|
|
JSONObject retObj = new JSONObject(); |
|
|
|
|
|
retObj.put(WxPayConstant.CARD_ID, cardId); |
|
|
|
|
|
retObj.put(WxPayConstant.ORG_REMAIN_AMOUNT, cardInfo.getRemainingAmount()); |
|
|
|
|
|
retObj.put(WxPayConstant.REMAIN_AMOUNT, updateCardInfo.getRemainingAmount()); |
|
|
|
|
|
retObj.put(WxPayConstant.CANCEL, WxPayConstant.TRUE); |
|
|
|
|
|
retMap.put(WxPayConstant.RET, JSON.toJSONString(retObj)); |
|
|
|
|
|
|
|
|
JSONObject refundObj = new JSONObject(); |
|
|
|
|
|
refundObj.put(WxPayConstant.CARD_ID, cardIdStr); |
|
|
|
|
|
refundObj.put(WxPayConstant.CARD_REFUND_RESULT, "0"); |
|
|
|
|
|
refundObj.put(WxPayConstant.REFUND_RESULT_MSG, "卡支付撤销成功"); |
|
|
|
|
|
refundObj.put(WxPayConstant.REFUND_TIME_FROM_IFORMALL, neuDateFormat.format(new Date())); |
|
|
|
|
|
refundObj.put(WxPayConstant.AMOUNT_PAID_BY_CARD, 0); |
|
|
|
|
|
refundObj.put(WxPayConstant.AMOUNT_LEFT_AFTER_PAY, amountLeftAfterPay + record.getDeductionAmount()); |
|
|
|
|
|
retMap.put(WxPayConstant.CARD_REFUND_RESULT, JSON.toJSONString(refundObj)); |
|
|
} catch (MallinkException e) { |
|
|
} catch (MallinkException e) { |
|
|
logger.error("card spend error, req 2: " + record.toString() + ", e:" + e.getMessage()); |
|
|
logger.error("card spend error, req 2: " + record.toString() + ", e:" + e.getMessage()); |
|
|
throw new MallinkException(e.getErrorCode(), e.getMessage()); |
|
|
throw new MallinkException(e.getErrorCode(), e.getMessage()); |
|
|
@@ -1626,6 +1677,23 @@ public class PosServiceImpl implements PosService { |
|
|
return retMap; |
|
|
return retMap; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private WxCardInfo checkAndGetCardinfo(Long cardId, Long merchantId) { |
|
|
|
|
|
WxCardInfo cardInfo = cardInfoService.getById(cardId); |
|
|
|
|
|
if(cardInfo == null) { |
|
|
|
|
|
String errMessage = "卡不存在: " + cardId; |
|
|
|
|
|
logger.error(errMessage); |
|
|
|
|
|
throw new MallinkException(ErrorCode.CARD_IS_NOT_FOUND.getCode(), errMessage); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
WxCouponMerchant couponMerchant = cardSpendService.checkMerchantInCoupon(cardInfo, merchantId); |
|
|
|
|
|
if(couponMerchant == null) { |
|
|
|
|
|
String errMessage = "商户不支持此卡 " + cardId; |
|
|
|
|
|
logger.error(errMessage); |
|
|
|
|
|
throw new MallinkException(ErrorCode.COUPON_ORDER_MERANT_IS_NULL.getCode(), errMessage); |
|
|
|
|
|
} |
|
|
|
|
|
return cardInfo; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
@Override |
|
|
@Override |
|
|
@Transactional(rollbackFor = Exception.class) |
|
|
@Transactional(rollbackFor = Exception.class) |
|
|
public JSONObject posOrderSync(Map<String, String> params) throws MallinkException { |
|
|
public JSONObject posOrderSync(Map<String, String> params) throws MallinkException { |
|
|
|