|
|
|
@@ -1,5 +1,6 @@ |
|
|
|
package com.iformall.service.impl; |
|
|
|
|
|
|
|
import com.alibaba.fastjson.JSON; |
|
|
|
import com.alibaba.fastjson.JSONArray; |
|
|
|
import com.alibaba.fastjson.JSONObject; |
|
|
|
import com.iformall.common.ErrorCode; |
|
|
|
@@ -12,6 +13,7 @@ import com.iformall.mapper.WxCouponMapper; |
|
|
|
import com.iformall.mapper.WxCouponMerchantMapper; |
|
|
|
import com.iformall.mapper.WxCouponOrderMapper; |
|
|
|
import com.iformall.mapper.WxOrderMapper; |
|
|
|
import com.iformall.pay.WxPay; |
|
|
|
import com.iformall.pay.WxPayConstant; |
|
|
|
import com.iformall.service.*; |
|
|
|
import lombok.AllArgsConstructor; |
|
|
|
@@ -308,14 +310,14 @@ public class PosServiceImpl implements PosService { |
|
|
|
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))) { |
|
|
|
if (!(verifyType.equalsIgnoreCase(WxPayConstant.VERIFY_TYPE_INDEPENT) || verifyType.equalsIgnoreCase(WxPayConstant.VERIFY_TYPE_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; |
|
|
|
verifyType = WxPayConstant.VERIFY_TYPE_INDEPENT; |
|
|
|
} else if (actionType.equals(EnumVerifyActionType.VERIFY_PAY)) { |
|
|
|
verifyType = WxPayConstant.VERIFY_PAY; |
|
|
|
verifyType = WxPayConstant.VERIFY_TYPE_PAY; |
|
|
|
} |
|
|
|
if (actionType.equals(EnumVerifyActionType.PRE_VERIFY) || |
|
|
|
actionType.equals(EnumVerifyActionType.VERIFY_INDEPENT) || |
|
|
|
@@ -401,7 +403,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; // 此接口只有支付使用 |
|
|
|
String verifyType = WxPayConstant.VERIFY_TYPE_PAY; // 此接口只有支付使用 |
|
|
|
|
|
|
|
if (StringUtils.isBlank(tenantId)) { |
|
|
|
String errMessage = "request params[tenant_id] error."; |
|
|
|
@@ -522,7 +524,7 @@ public class PosServiceImpl implements PosService { |
|
|
|
} |
|
|
|
// 4.1 检查券类型 |
|
|
|
if (actionType.equals(EnumVerifyActionType.CHECK)) { |
|
|
|
if (verifyType.equalsIgnoreCase(WxPayConstant.VERIFY_INDEPENT)) { |
|
|
|
if (verifyType.equalsIgnoreCase(WxPayConstant.VERIFY_TYPE_INDEPENT)) { |
|
|
|
if (!(couponOrderCVo.getCouponType().equals(EnumCouponType.COUPON_MULTIMCH.getCode()) || |
|
|
|
couponOrderCVo.getCouponType().equals(EnumCouponType.COUPON_LIPIN.getCode()) || |
|
|
|
couponOrderCVo.getCouponType().equals(EnumCouponType.COUPON_PRESS.getCode()) || |
|
|
|
@@ -532,7 +534,7 @@ public class PosServiceImpl implements PosService { |
|
|
|
throw new MallinkException(ErrorCode.VERIFY_COUPON_TYPE_NOT_SUPPORT); |
|
|
|
} |
|
|
|
} |
|
|
|
if (verifyType.equalsIgnoreCase(WxPayConstant.VERIFY_PAY)) { |
|
|
|
if (verifyType.equalsIgnoreCase(WxPayConstant.VERIFY_TYPE_PAY)) { |
|
|
|
if (!(couponOrderCVo.getCouponType().equals(EnumCouponType.COUPON_MULTIMCH.getCode()) || |
|
|
|
couponOrderCVo.getCouponType().equals(EnumCouponType.COUPON_MANJIAN.getCode()) || |
|
|
|
couponOrderCVo.getCouponType().equals(EnumCouponType.COUPON_DAIJIN.getCode()) |
|
|
|
@@ -636,12 +638,12 @@ public class PosServiceImpl implements PosService { |
|
|
|
} |
|
|
|
logger.info("券可以被核销: " + couponOrderIdStr); |
|
|
|
retMap.put(WxPayConstant.ID, couponOrderIdStr); |
|
|
|
retMap.put(WxPayConstant.CHECK, "true"); |
|
|
|
retMap.put(WxPayConstant.CHECK, WxPayConstant.TRUE); |
|
|
|
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, "true"); |
|
|
|
retMap.put(WxPayConstant.CHECK, WxPayConstant.TRUE); |
|
|
|
return retMap; |
|
|
|
} |
|
|
|
} else if (actionType.equals(EnumVerifyActionType.PRE_VERIFY)) { |
|
|
|
@@ -667,7 +669,7 @@ public class PosServiceImpl implements PosService { |
|
|
|
remainAmount = 0; |
|
|
|
} |
|
|
|
retMap.put(WxPayConstant.ID, couponOrderIdStr); |
|
|
|
retMap.put(WxPayConstant.PRE_VERIFY, "true"); |
|
|
|
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; |
|
|
|
@@ -681,7 +683,7 @@ public class PosServiceImpl implements PosService { |
|
|
|
remainAmount = 0; |
|
|
|
} |
|
|
|
retMap.put(WxPayConstant.ID, couponOrderIdStr); |
|
|
|
retMap.put(WxPayConstant.PRE_VERIFY, "true"); |
|
|
|
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; |
|
|
|
@@ -733,7 +735,7 @@ public class PosServiceImpl implements PosService { |
|
|
|
remainAmount = 0; |
|
|
|
} |
|
|
|
retMap.put(WxPayConstant.ID, couponOrderIdStr); |
|
|
|
retMap.put(WxPayConstant.VERIFY, "true"); |
|
|
|
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; |
|
|
|
@@ -871,6 +873,7 @@ public class PosServiceImpl implements PosService { |
|
|
|
|
|
|
|
try { |
|
|
|
cancelVerify(couponOrderCVo, buUserId, posOrderId); |
|
|
|
retMap.put(WxPayConstant.CANCEL, WxPayConstant.TRUE); |
|
|
|
return retMap; |
|
|
|
} catch (MallinkException e) { |
|
|
|
logger.error(e.getMessage()); |
|
|
|
@@ -1153,7 +1156,7 @@ public class PosServiceImpl implements PosService { |
|
|
|
|
|
|
|
@Override |
|
|
|
@Transactional(rollbackFor = Exception.class) |
|
|
|
public Map<String, String> cardPay(@RequestBody Map<String, String> params) throws MallinkException { |
|
|
|
public Map<String, String> cardPayPre(Map<String, String> params) throws MallinkException { |
|
|
|
Map<String, String> retMap = new HashMap<>(); |
|
|
|
|
|
|
|
String tenantId = params.get(WxPayConstant.TENANT_ID); // 租户ID |
|
|
|
@@ -1173,7 +1176,7 @@ public class PosServiceImpl implements PosService { |
|
|
|
logger.error(ErrorCode.POS_CONFIG_NOT_FOUND.getMessage()); |
|
|
|
throw new MallinkException(ErrorCode.POS_CONFIG_NOT_FOUND); |
|
|
|
} |
|
|
|
if (!config.getCoupon().equals(EnumEnableType.Enable.getCode())) { |
|
|
|
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); |
|
|
|
} |
|
|
|
@@ -1195,7 +1198,7 @@ public class PosServiceImpl implements PosService { |
|
|
|
throw new MallinkException(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(), errMessage); |
|
|
|
} |
|
|
|
if (StringUtils.isBlank(cardIdStr)) { |
|
|
|
String errMessage = "request params[coupon_order_id] error."; |
|
|
|
String errMessage = "request params[card_id] error."; |
|
|
|
throw new MallinkException(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(), errMessage); |
|
|
|
} |
|
|
|
|
|
|
|
@@ -1255,15 +1258,157 @@ public class PosServiceImpl implements PosService { |
|
|
|
throw new MallinkException(ErrorCode.CARD_REMAIN_AMOUNT_IS_NOT_ENOUGH); |
|
|
|
} |
|
|
|
WxCardSpend record = new WxCardSpend(); |
|
|
|
record.setFrom(EnumCardSpendFrom.POS.getCode()); |
|
|
|
record.setTenantId(merchant.getTenantId()); |
|
|
|
record.setCardId(cardId); |
|
|
|
record.setOwnerId(couponOrder.getOwnerId()); |
|
|
|
record.setMerchantId(merchantId); |
|
|
|
record.setPosOrderId(posOrderId); |
|
|
|
record.setDeductionAmount(posAmount); |
|
|
|
|
|
|
|
try { |
|
|
|
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)); |
|
|
|
} catch (MallinkException e) { |
|
|
|
logger.error("card spend error, req 2: " + record.toString() + ", e:" + e.getMessage()); |
|
|
|
throw new MallinkException(e.getErrorCode(), e.getMessage()); |
|
|
|
} catch (Exception e) { |
|
|
|
logger.error("card spend error, req 3: " + record.toString() + ", e:" + e.getMessage()); |
|
|
|
throw new MallinkException(500, e.getMessage()); |
|
|
|
} |
|
|
|
|
|
|
|
return retMap; |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
@Transactional(rollbackFor = Exception.class) |
|
|
|
public Map<String, String> cardPayPreCancel(@RequestBody Map<String, String> params) throws MallinkException { |
|
|
|
Map<String, String> 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.POS_AMOUNT); // POS订单总额(单位:分) |
|
|
|
String cardIdStr = params.get(WxPayConstant.CARD_ID); // 消费卡ID |
|
|
|
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); |
|
|
|
} |
|
|
|
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.getCard().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)) { |
|
|
|
String errMessage = "request params[merchant_id] error."; |
|
|
|
logger.error(errMessage); |
|
|
|
throw new MallinkException(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(), errMessage); |
|
|
|
} |
|
|
|
if (StringUtils.isBlank(buUserIdStr)) { |
|
|
|
String errMessage = "request params[bu_user_id] error."; |
|
|
|
throw new MallinkException(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(), errMessage); |
|
|
|
} |
|
|
|
if (StringUtils.isBlank(posOrderIdStr)) { |
|
|
|
String errMessage = "request params[pos_order_id] error."; |
|
|
|
throw new MallinkException(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(), errMessage); |
|
|
|
} |
|
|
|
if (StringUtils.isBlank(posAmountStr)) { |
|
|
|
String errMessage = "request params[pos_amount] error."; |
|
|
|
throw new MallinkException(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(), errMessage); |
|
|
|
} |
|
|
|
if (StringUtils.isBlank(cardIdStr)) { |
|
|
|
String errMessage = "request params[card_id] error."; |
|
|
|
throw new MallinkException(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(), errMessage); |
|
|
|
} |
|
|
|
if (StringUtils.isBlank(cardSpendIdStr)) { |
|
|
|
String errMessage = "request params[card_spend_id] error."; |
|
|
|
throw new MallinkException(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(), errMessage); |
|
|
|
} |
|
|
|
|
|
|
|
Long merchantId, buUserId, posOrderId, cardId, cardSpendId; |
|
|
|
Integer posAmount = 0; |
|
|
|
try { |
|
|
|
merchantId = Long.valueOf(merchantIdStr); |
|
|
|
buUserId = Long.valueOf(buUserIdStr); |
|
|
|
posOrderId = Long.valueOf(posOrderIdStr); |
|
|
|
posAmount = Integer.valueOf(posAmountStr); |
|
|
|
cardId = Long.valueOf(cardIdStr); |
|
|
|
cardSpendId = Long.valueOf(cardSpendIdStr); |
|
|
|
} catch (NumberFormatException e) { |
|
|
|
logger.error(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 |
|
|
|
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); |
|
|
|
} |
|
|
|
// 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); |
|
|
|
} |
|
|
|
|
|
|
|
WxCouponOrder couponOrder = couponOrderService.getById(cardId); |
|
|
|
if(couponOrder == null) { |
|
|
|
logger.error("卡不存在: " + cardIdStr); |
|
|
|
throw new MallinkException(ErrorCode.CARD_IS_NOT_FOUND); |
|
|
|
} |
|
|
|
|
|
|
|
WxCardSpend record = new WxCardSpend(); |
|
|
|
record.setId(cardSpendId); |
|
|
|
record.setFrom(EnumCardSpendFrom.POS.getCode()); |
|
|
|
record.setTenantId(merchant.getTenantId()); |
|
|
|
record.setCardId(cardId); |
|
|
|
record.setOwnerId(couponOrder.getOwnerId()); |
|
|
|
record.setMerchantId(merchantId); |
|
|
|
record.setOrderId(posOrderId); |
|
|
|
record.setPosOrderId(posOrderId); |
|
|
|
record.setDeductionAmount(posAmount); |
|
|
|
record.setPayStatus(EnumCardSpendStatus.PREV_PAY.getCode()); |
|
|
|
|
|
|
|
try { |
|
|
|
//return cardSpendService.createCardSpend(record, order, couponMerchant); |
|
|
|
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)); |
|
|
|
} catch (MallinkException e) { |
|
|
|
logger.error("card spend error, req 2: " + record.toString() + ", e:" + e.getMessage()); |
|
|
|
throw new MallinkException(e.getErrorCode(), e.getMessage()); |
|
|
|
@@ -1271,13 +1416,19 @@ public class PosServiceImpl implements PosService { |
|
|
|
logger.error("card spend error, req 3: " + record.toString() + ", e:" + e.getMessage()); |
|
|
|
throw new MallinkException(500, e.getMessage()); |
|
|
|
} |
|
|
|
retMap.put(WxPayConstant.RET, ""); |
|
|
|
|
|
|
|
return retMap; |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
@Transactional(rollbackFor = Exception.class) |
|
|
|
public Map<String, String> cardPayCancel(@RequestBody Map<String, String> params) throws MallinkException { |
|
|
|
public Map<String, String> cardPay(Map<String, String> params) throws MallinkException { |
|
|
|
return null; |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
@Transactional(rollbackFor = Exception.class) |
|
|
|
public Map<String, String> cardPayCancel(Map<String, String> params) throws MallinkException { |
|
|
|
return null; |
|
|
|
} |
|
|
|
} |