|
|
|
@@ -58,8 +58,6 @@ public class PosServiceImpl implements PosService { |
|
|
|
private final WxCouponMapper couponMapper; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
* 门店用户登录检查 |
|
|
|
* @param params |
|
|
|
@@ -209,6 +207,7 @@ public class PosServiceImpl implements PosService { |
|
|
|
|
|
|
|
String tenantId = params.get(WxPayConstant.TENANT_ID); // 租户ID |
|
|
|
String merchantIdStr = params.get(WxPayConstant.MERCHANT_ID); // 商户ID |
|
|
|
String buUserIdStr = params.get(WxPayConstant.BUSER_ID); // POS操作员ID |
|
|
|
String memIdStr = params.get(WxPayConstant.MEM_ID); // 会员ID |
|
|
|
String memPhoneStr = params.get(WxPayConstant.MEM_PHONE); // 会员手机 |
|
|
|
String posOrderIdStr = params.get(WxPayConstant.POS_ORDER_ID); // POS订单ID |
|
|
|
@@ -234,83 +233,54 @@ public class PosServiceImpl implements PosService { |
|
|
|
errParam(WxPayConstant.POS_AMOUNT); |
|
|
|
} |
|
|
|
|
|
|
|
if (StringUtils.isBlank(memIdStr) && StringUtils.isBlank(memPhoneStr)) { |
|
|
|
String errMessage = "please give one value for mem_id or mem_phone"; |
|
|
|
logger.error(errMessage); |
|
|
|
throw new MallinkException(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(), errMessage); |
|
|
|
} |
|
|
|
WxCUser user = null; |
|
|
|
if (StringUtils.isNotBlank(memIdStr)) { |
|
|
|
Long memId; |
|
|
|
try { |
|
|
|
memId = Long.valueOf(memIdStr); |
|
|
|
} catch (NumberFormatException e) { |
|
|
|
logger.error(e.getMessage()); |
|
|
|
throw new MallinkException(ErrorCode.SYS_PARAMETER_CAST_ERROR.getCode(), e.getMessage()); |
|
|
|
} |
|
|
|
|
|
|
|
user = cUserService.getById(memId); |
|
|
|
} |
|
|
|
if (StringUtils.isNotBlank(memPhoneStr)) { |
|
|
|
WxCUser q = new WxCUser(); |
|
|
|
q.setTenantId(tenantId); |
|
|
|
q.setPhone(memPhoneStr); |
|
|
|
user = cUserService.getByObject(q); |
|
|
|
} |
|
|
|
|
|
|
|
if (user == null) { |
|
|
|
logger.error(ErrorCode.USER_NOT_MEMBER.getMessage()); |
|
|
|
throw new MallinkException(ErrorCode.USER_NOT_MEMBER); |
|
|
|
} |
|
|
|
|
|
|
|
Long merchantId, posOrderId; |
|
|
|
Integer posAmount = 0; |
|
|
|
// 1. 商户ID, B端用户ID |
|
|
|
Long merchantId, buUserId, posOrderId; |
|
|
|
Long posAmount = 0L; |
|
|
|
try { |
|
|
|
merchantId = Long.valueOf(merchantIdStr); |
|
|
|
buUserId = Long.valueOf(buUserIdStr); |
|
|
|
posOrderId = Long.valueOf(posOrderIdStr); |
|
|
|
posAmount = Integer.valueOf(posAmountStr); |
|
|
|
posAmount = Long.valueOf(posAmountStr); |
|
|
|
} catch (NumberFormatException e) { |
|
|
|
logger.error(e.getMessage()); |
|
|
|
throw new MallinkException(ErrorCode.SYS_PARAMETER_CAST_ERROR); |
|
|
|
} |
|
|
|
|
|
|
|
Integer discount = 100; |
|
|
|
if (config.getDiscount().equals(EnumEnableType.Enable.getCode())) { |
|
|
|
|
|
|
|
// Level, 折扣 |
|
|
|
List<WxLevelConfig> levelList = levelConfigService.getByTenantId(tenantId); |
|
|
|
|
|
|
|
String level = WxLevelConfigService.DEFAULT_LEVEL; |
|
|
|
Long levelId = 0L; |
|
|
|
for (WxLevelConfig levelConfig : levelList) { |
|
|
|
if (user.getScore() >= levelConfig.getPoints()) { |
|
|
|
if (levelConfig.getDiscountEnable().equals(EnumLevelConfigDiscountStatus.ENABLE.getCode())) |
|
|
|
levelId = levelConfig.getId(); |
|
|
|
level = levelConfig.getLevel(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
WxLevelMerchant levelMerchant = new WxLevelMerchant(); |
|
|
|
levelMerchant.setTenantId(tenantId); |
|
|
|
levelMerchant.setLevelId(levelId); |
|
|
|
levelMerchant.setMerchantId(merchantId); |
|
|
|
List<WxLevelMerchantCVo> levelMerchantList = levelConfigService.findListCVo(levelMerchant); |
|
|
|
if (levelMerchantList.size() >= 1) { |
|
|
|
WxLevelMerchantCVo levelMerchantCVo = levelMerchantList.get(0); |
|
|
|
if (levelMerchantCVo != null) { |
|
|
|
discount = levelMerchantCVo.getDiscount(); |
|
|
|
} |
|
|
|
} |
|
|
|
// 2. check merchant |
|
|
|
WxMerchant merchant = checkAndGetMerchant(merchantId); |
|
|
|
// 3. check buUser |
|
|
|
WxMerchantBUser buUser = checkAndGetMerchantUser(buUserId, merchantId); |
|
|
|
|
|
|
|
retMap.put(WxPayConstant.MEM_LEVEL, level); |
|
|
|
// 3. 会员ID |
|
|
|
if (StringUtils.isBlank(memIdStr) && StringUtils.isBlank(memPhoneStr)) { |
|
|
|
errParam2(WxPayConstant.MEM_ID, WxPayConstant.MEM_PHONE); |
|
|
|
} |
|
|
|
// 4. 获取会员信息 |
|
|
|
WxCUser user = getMemUser(tenantId, memIdStr, memPhoneStr); |
|
|
|
if (user == null) { |
|
|
|
logger.error(ErrorCode.USER_NOT_MEMBER.getMessage()); |
|
|
|
throw new MallinkException(ErrorCode.USER_NOT_MEMBER); |
|
|
|
} |
|
|
|
|
|
|
|
retMap.put(WxPayConstant.MEM_DISCOUNT, discount.toString()); |
|
|
|
// 5. 会员level及折扣 |
|
|
|
Integer discount = 100; |
|
|
|
if (config.getDiscount().equals(EnumEnableType.Enable.getCode())) { |
|
|
|
discount = getMemLevelDiscount(retMap, tenantId, user, merchantId); |
|
|
|
} else { |
|
|
|
retMap.put(WxPayConstant.MEM_DISCOUNT_RATE, discount.toString()); |
|
|
|
} |
|
|
|
|
|
|
|
Double remainAmountD = posAmount * 1.0D * discount / 100; |
|
|
|
long remainAmount = Math.round(remainAmountD); |
|
|
|
Long remainAmount = Math.round(remainAmountD); |
|
|
|
Long discountAmount = posAmount - remainAmount; |
|
|
|
|
|
|
|
// 优惠券列表 |
|
|
|
retMap.put(WxPayConstant.MEM_ID, user.getId().toString()); |
|
|
|
retMap.put(WxPayConstant.MEM_PHONE, user.getPhone()); |
|
|
|
retMap.put(WxPayConstant.ORG_AMOUNT, posAmountStr); |
|
|
|
retMap.put(WxPayConstant.DISCOUNT_AMOUNT, String.valueOf(discountAmount)); |
|
|
|
retMap.put(WxPayConstant.REMAIN_AMOUNT, String.valueOf(remainAmount)); |
|
|
|
|
|
|
|
// 6. 优惠券列表 |
|
|
|
if (config.getCoupon().equals(EnumEnableType.Enable.getCode())) { |
|
|
|
Map<String, Object> coQ = new HashMap<>(); |
|
|
|
coQ.put("tenantId", tenantId); |
|
|
|
@@ -340,17 +310,244 @@ public class PosServiceImpl implements PosService { |
|
|
|
} else { |
|
|
|
retMap.put(WxPayConstant.AVAIL_CO_LIST, "[]"); |
|
|
|
} |
|
|
|
return retMap; |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
@Transactional(rollbackFor = Exception.class) |
|
|
|
public Map<String, String> calcMem(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 memIdStr = params.get(WxPayConstant.MEM_ID); // 会员ID |
|
|
|
String memPhoneStr = params.get(WxPayConstant.MEM_PHONE); // 会员手机 |
|
|
|
String posAmountStr = params.get(WxPayConstant.POS_AMOUNT); // POS订单金额(单位:分) |
|
|
|
String selCoListStr = params.get(WxPayConstant.SELECTED_COUPON_ORDER_LIST); // 选中的优惠券列表 |
|
|
|
|
|
|
|
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 (StringUtils.isBlank(merchantIdStr)) { |
|
|
|
errParam(WxPayConstant.MERCHANT_ID); |
|
|
|
} |
|
|
|
if (StringUtils.isBlank(posAmountStr)) { |
|
|
|
errParam(WxPayConstant.POS_AMOUNT); |
|
|
|
} |
|
|
|
if (StringUtils.isBlank(selCoListStr)) { |
|
|
|
errParam(WxPayConstant.SELECTED_COUPON_ORDER_LIST); |
|
|
|
} |
|
|
|
if (StringUtils.isBlank(memIdStr) && StringUtils.isBlank(memPhoneStr)) { |
|
|
|
errParam2(WxPayConstant.MEM_ID, WxPayConstant.MEM_PHONE); |
|
|
|
} |
|
|
|
// 1. 商户ID, B端用户ID |
|
|
|
Long merchantId, buUserId, posOrderId; |
|
|
|
Long posAmount = 0L; |
|
|
|
try { |
|
|
|
merchantId = Long.valueOf(merchantIdStr); |
|
|
|
buUserId = Long.valueOf(buUserIdStr); |
|
|
|
posAmount = Long.valueOf(posAmountStr); |
|
|
|
} catch (NumberFormatException e) { |
|
|
|
logger.error(e.getMessage()); |
|
|
|
throw new MallinkException(ErrorCode.SYS_PARAMETER_CAST_ERROR); |
|
|
|
} |
|
|
|
|
|
|
|
// 2. check merchant |
|
|
|
WxMerchant merchant = checkAndGetMerchant(merchantId); |
|
|
|
// 3. check buUser |
|
|
|
WxMerchantBUser buUser = checkAndGetMerchantUser(buUserId, merchantId); |
|
|
|
|
|
|
|
// 4. 获取会员信息 |
|
|
|
WxCUser user = getMemUser(tenantId, memIdStr, memPhoneStr); |
|
|
|
if (user == null) { |
|
|
|
logger.error(ErrorCode.USER_NOT_MEMBER.getMessage()); |
|
|
|
throw new MallinkException(ErrorCode.USER_NOT_MEMBER); |
|
|
|
} |
|
|
|
|
|
|
|
// 5. 获取折扣率 |
|
|
|
Integer discount = 100; |
|
|
|
if (config.getDiscount().equals(EnumEnableType.Enable.getCode())) { |
|
|
|
discount = getMemLevelDiscount(retMap, tenantId, user, merchantId); |
|
|
|
} else { |
|
|
|
retMap.put(WxPayConstant.MEM_DISCOUNT_RATE, discount.toString()); |
|
|
|
} |
|
|
|
// 6. 计算折扣及剩余支付金额(四舍五入) |
|
|
|
Double remainAmountD = posAmount * 1.0D * discount / 100; |
|
|
|
Long remainAmount = Math.round(remainAmountD); |
|
|
|
Long discountAmount = posAmount - remainAmount; |
|
|
|
|
|
|
|
retMap.put(WxPayConstant.MEM_ID, user.getId().toString()); |
|
|
|
retMap.put(WxPayConstant.MEM_PHONE, user.getPhone()); |
|
|
|
retMap.put(WxPayConstant.ORG_AMOUNT, posAmountStr); |
|
|
|
retMap.put(WxPayConstant.DISCOUNT_AMOUNT, String.valueOf(discountAmount)); |
|
|
|
|
|
|
|
// 7. 计算券抵扣及剩余支付金额(四舍五入) |
|
|
|
JSONArray selCoArr = JSONObject.parseArray(selCoListStr); |
|
|
|
if (selCoArr.size() <= 0) { |
|
|
|
errParam(WxPayConstant.SELECTED_COUPON_ORDER_LIST); |
|
|
|
} |
|
|
|
JSONArray coRetArr = new JSONArray(); |
|
|
|
for(int i=0;i<selCoArr.size();i++) { |
|
|
|
String couponOrderIdStr = selCoArr.getString(i); |
|
|
|
if (couponOrderIdStr != null) { |
|
|
|
try { |
|
|
|
Map<String, String> oneRetMap = calcOneCouponVerify(merchantId, posAmount, couponOrderIdStr); |
|
|
|
coRetArr.add(oneRetMap); |
|
|
|
posAmount = Long.valueOf(oneRetMap.get(WxPayConstant.REMAIN_AMOUNT)); |
|
|
|
if (posAmount.equals(0L)) { |
|
|
|
break; |
|
|
|
} |
|
|
|
} catch (MallinkException e) { |
|
|
|
throw new MallinkException(e.getErrorCode(), e.getMessage()); |
|
|
|
} catch (Exception e) { |
|
|
|
throw new MallinkException(500, e.getMessage()); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
retMap.put(WxPayConstant.MEM_COUPONS, coRetArr.toJSONString()); |
|
|
|
retMap.put(WxPayConstant.REMAIN_AMOUNT, String.valueOf(posAmount)); |
|
|
|
return retMap; |
|
|
|
} |
|
|
|
|
|
|
|
private Map<String, String> calcOneCouponVerify(Long merchantId, Long posAmount, String couponOrderIdStr) { |
|
|
|
Map<String, String> retMap = new HashMap<>(); |
|
|
|
// 1. 获取券包信息 |
|
|
|
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); |
|
|
|
} |
|
|
|
// 2. 检查券类型 |
|
|
|
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); |
|
|
|
} |
|
|
|
|
|
|
|
// 3. 券包状态检查 |
|
|
|
if (couponOrderCVo.getCouponOrderStatus() == EnumCouponOrderStatus.COUPON_ORDER_OVER_TIME.getCode()) { |
|
|
|
logger.error("已过期: couponOrder-" + couponOrderIdStr); |
|
|
|
throw new MallinkException(ErrorCode.COUPON_ORDER_IS_OVER_TIME); |
|
|
|
} |
|
|
|
if (couponOrderCVo.getCouponOrderStatus() == EnumCouponOrderStatus.COUPON_ORDER_INVALID.getCode()) { |
|
|
|
logger.error("已作废: couponOrder-" + couponOrderIdStr); |
|
|
|
throw new MallinkException(ErrorCode.COUPON_ORDER_IS_INVALID); |
|
|
|
} |
|
|
|
if (couponOrderCVo.getCouponOrderStatus() == EnumCouponOrderStatus.COUPON_ORDER_USED.getCode()) { |
|
|
|
logger.error("已经核销过的券: couponOrder-" + couponOrderIdStr); |
|
|
|
throw new MallinkException(ErrorCode.COUPON_ORDER_IS_USED); |
|
|
|
} |
|
|
|
|
|
|
|
Date now = new Date(); |
|
|
|
// 4. 检查有效期 |
|
|
|
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 券已过期 |
|
|
|
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<WxCouponMerchant> couponMerchantList = couponMerchantMapper.findList(wxCouponMerchant); |
|
|
|
if (!couponMerchantList.stream().anyMatch(cm->cm.getMerchantId().equals(merchantId))){ |
|
|
|
logger.error("券: coupon-" + couponOrderCVo.getCouponId() + "核销: couponMerchantId-" + merchantId + " 门店不适用"); |
|
|
|
throw new MallinkException(ErrorCode.VERIFY_COUPON_ORDER_MERCHANT_IS_NULL); |
|
|
|
} |
|
|
|
|
|
|
|
Long remainAmount = posAmount - couponOrderCVo.getPrice(); |
|
|
|
if (remainAmount < 0L) { |
|
|
|
remainAmount = 0L; |
|
|
|
} |
|
|
|
Long discountAmount = posAmount - remainAmount; |
|
|
|
retMap.put(WxPayConstant.ID, couponOrderIdStr); |
|
|
|
retMap.put(WxPayConstant.PRICE, String.valueOf(couponOrderCVo.getPrice())); |
|
|
|
retMap.put(WxPayConstant.DEDUCT_AMOUNT, String.valueOf(discountAmount)); |
|
|
|
retMap.put(WxPayConstant.REMAIN_AMOUNT, String.valueOf(remainAmount)); |
|
|
|
return retMap; |
|
|
|
} |
|
|
|
|
|
|
|
private WxCUser getMemUser(String tenantId, String memIdStr, String memPhoneStr) { |
|
|
|
WxCUser user = null; |
|
|
|
if (StringUtils.isNotBlank(memIdStr)) { |
|
|
|
Long memId; |
|
|
|
try { |
|
|
|
memId = Long.valueOf(memIdStr); |
|
|
|
} catch (NumberFormatException e) { |
|
|
|
logger.error(e.getMessage()); |
|
|
|
throw new MallinkException(ErrorCode.SYS_PARAMETER_CAST_ERROR.getCode(), e.getMessage()); |
|
|
|
} |
|
|
|
|
|
|
|
user = cUserService.getById(memId); |
|
|
|
} |
|
|
|
if (StringUtils.isNotBlank(memPhoneStr)) { |
|
|
|
WxCUser q = new WxCUser(); |
|
|
|
q.setTenantId(tenantId); |
|
|
|
q.setPhone(memPhoneStr); |
|
|
|
user = cUserService.getByObject(q); |
|
|
|
} |
|
|
|
return user; |
|
|
|
} |
|
|
|
|
|
|
|
private Integer getMemLevelDiscount(Map<String, String> retMap, String tenantId, WxCUser user, Long merchantId) { |
|
|
|
Integer discount = 100; |
|
|
|
String level = WxLevelConfigService.DEFAULT_LEVEL; |
|
|
|
// Level, 折扣 |
|
|
|
List<WxLevelConfig> levelList = levelConfigService.getByTenantId(tenantId); |
|
|
|
Long levelId = 0L; |
|
|
|
for (WxLevelConfig levelConfig : levelList) { |
|
|
|
if (user.getScore() >= levelConfig.getPoints()) { |
|
|
|
if (levelConfig.getDiscountEnable().equals(EnumLevelConfigDiscountStatus.ENABLE.getCode())) |
|
|
|
levelId = levelConfig.getId(); |
|
|
|
level = levelConfig.getLevel(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
WxLevelMerchant levelMerchant = new WxLevelMerchant(); |
|
|
|
levelMerchant.setTenantId(tenantId); |
|
|
|
levelMerchant.setLevelId(levelId); |
|
|
|
levelMerchant.setMerchantId(merchantId); |
|
|
|
List<WxLevelMerchantCVo> levelMerchantList = levelConfigService.findListCVo(levelMerchant); |
|
|
|
if (levelMerchantList.size() >= 1) { |
|
|
|
WxLevelMerchantCVo levelMerchantCVo = levelMerchantList.get(0); |
|
|
|
if (levelMerchantCVo != null) { |
|
|
|
discount = levelMerchantCVo.getDiscount(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
retMap.put(WxPayConstant.MEM_LEVEL, level); |
|
|
|
retMap.put(WxPayConstant.MEM_DISCOUNT_RATE, discount.toString()); |
|
|
|
return discount; |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
@Transactional(rollbackFor = Exception.class) |
|
|
|
public Map<String, String> couponOrderVerifyDo(@RequestBody Map<String, String> params, EnumVerifyActionType actionType) throws MallinkException { |
|
|
|
public Map<String, String> couponOrderVerifyDo(@RequestBody Map<String, String> params, EnumPosActionType actionType) throws MallinkException { |
|
|
|
Map<String, String> retMap = new HashMap<>(); |
|
|
|
|
|
|
|
String tenantId = params.get(WxPayConstant.TENANT_ID); // 租户ID |
|
|
|
@@ -383,7 +580,7 @@ public class PosServiceImpl implements PosService { |
|
|
|
if (StringUtils.isBlank(couponOrderIdStr)) { |
|
|
|
errParam(WxPayConstant.COUPON_ORDER_ID); |
|
|
|
} |
|
|
|
if (actionType.equals(EnumVerifyActionType.CHECK)) { |
|
|
|
if (actionType.equals(EnumPosActionType.CHECK)) { |
|
|
|
if (StringUtils.isBlank(sceneTypeStr)) { |
|
|
|
errParam(WxPayConstant.SCENE_TYPE); |
|
|
|
} |
|
|
|
@@ -393,20 +590,20 @@ public class PosServiceImpl implements PosService { |
|
|
|
logger.error(e.getMessage()); |
|
|
|
throw new MallinkException(ErrorCode.SYS_PARAMETER_CAST_ERROR.getCode(), e.getMessage()); |
|
|
|
} |
|
|
|
} else if (actionType.equals(EnumVerifyActionType.VERIFY_INDEPENT)) { |
|
|
|
} else if (actionType.equals(EnumPosActionType.VERIFY_INDEPENT)) { |
|
|
|
sceneType = EnumPosSceneType.VERIFY.getCode(); |
|
|
|
} else if (actionType.equals(EnumVerifyActionType.VERIFY_PAY)) { |
|
|
|
} else if (actionType.equals(EnumPosActionType.VERIFY_PAY)) { |
|
|
|
sceneType = EnumPosSceneType.PAY.getCode(); |
|
|
|
} |
|
|
|
if (actionType.equals(EnumVerifyActionType.PRE_VERIFY) || |
|
|
|
actionType.equals(EnumVerifyActionType.VERIFY_INDEPENT) || |
|
|
|
actionType.equals(EnumVerifyActionType.VERIFY_PAY)) { |
|
|
|
if (actionType.equals(EnumPosActionType.PRE_VERIFY) || |
|
|
|
actionType.equals(EnumPosActionType.VERIFY_INDEPENT) || |
|
|
|
actionType.equals(EnumPosActionType.VERIFY_PAY)) { |
|
|
|
if (StringUtils.isBlank(posOrderIdStr)) { |
|
|
|
errParam(WxPayConstant.POS_ORDER_ID); |
|
|
|
} |
|
|
|
} |
|
|
|
if (actionType.equals(EnumVerifyActionType.PRE_VERIFY) || |
|
|
|
actionType.equals(EnumVerifyActionType.VERIFY_PAY)) { |
|
|
|
if (actionType.equals(EnumPosActionType.PRE_VERIFY) || |
|
|
|
actionType.equals(EnumPosActionType.VERIFY_PAY)) { |
|
|
|
if (StringUtils.isBlank(posAmountStr)) { |
|
|
|
errParam(WxPayConstant.POS_AMOUNT); |
|
|
|
} |
|
|
|
@@ -417,13 +614,13 @@ public class PosServiceImpl implements PosService { |
|
|
|
try { |
|
|
|
merchantId = Long.valueOf(merchantIdStr); |
|
|
|
buUserId = Long.valueOf(buUserIdStr); |
|
|
|
if (actionType.equals(EnumVerifyActionType.PRE_VERIFY) || |
|
|
|
actionType.equals(EnumVerifyActionType.VERIFY_INDEPENT) || |
|
|
|
actionType.equals(EnumVerifyActionType.VERIFY_PAY)) { |
|
|
|
if (actionType.equals(EnumPosActionType.PRE_VERIFY) || |
|
|
|
actionType.equals(EnumPosActionType.VERIFY_INDEPENT) || |
|
|
|
actionType.equals(EnumPosActionType.VERIFY_PAY)) { |
|
|
|
posOrderId = Long.valueOf(posOrderIdStr); |
|
|
|
} |
|
|
|
if (actionType.equals(EnumVerifyActionType.PRE_VERIFY) || |
|
|
|
actionType.equals(EnumVerifyActionType.VERIFY_PAY)) { |
|
|
|
if (actionType.equals(EnumPosActionType.PRE_VERIFY) || |
|
|
|
actionType.equals(EnumPosActionType.VERIFY_PAY)) { |
|
|
|
posAmount = Integer.valueOf(posAmountStr); |
|
|
|
} |
|
|
|
} catch (NumberFormatException e) { |
|
|
|
@@ -455,7 +652,7 @@ public class PosServiceImpl implements PosService { |
|
|
|
|
|
|
|
@Override |
|
|
|
@Transactional(rollbackFor = Exception.class) |
|
|
|
public Map<String, String> couponOrderVerifyListDo(@RequestBody Map<String, String> params, EnumVerifyActionType actionType) throws MallinkException { |
|
|
|
public Map<String, String> couponOrderVerifyListDo(@RequestBody Map<String, String> params, EnumPosActionType actionType) throws MallinkException { |
|
|
|
Map<String, String> retMap = new HashMap<>(); |
|
|
|
|
|
|
|
String tenantId = params.get(WxPayConstant.TENANT_ID); // 租户ID |
|
|
|
@@ -487,7 +684,7 @@ public class PosServiceImpl implements PosService { |
|
|
|
if (StringUtils.isBlank(selCoListStr)) { |
|
|
|
errParam(WxPayConstant.SELECTED_COUPON_ORDER_LIST); |
|
|
|
} |
|
|
|
if (actionType.equals(EnumVerifyActionType.PRE_VERIFY) || actionType.equals(EnumVerifyActionType.VERIFY_INDEPENT)) { |
|
|
|
if (actionType.equals(EnumPosActionType.PRE_VERIFY) || actionType.equals(EnumPosActionType.VERIFY_INDEPENT)) { |
|
|
|
if (StringUtils.isBlank(posOrderIdStr)) { |
|
|
|
errParam(WxPayConstant.POS_ORDER_ID); |
|
|
|
} |
|
|
|
@@ -501,9 +698,9 @@ public class PosServiceImpl implements PosService { |
|
|
|
try { |
|
|
|
merchantId = Long.valueOf(merchantIdStr); |
|
|
|
buUserId = Long.valueOf(buUserIdStr); |
|
|
|
if (actionType.equals(EnumVerifyActionType.PRE_VERIFY) || |
|
|
|
actionType.equals(EnumVerifyActionType.VERIFY_INDEPENT) || |
|
|
|
actionType.equals(EnumVerifyActionType.VERIFY_PAY)) { |
|
|
|
if (actionType.equals(EnumPosActionType.PRE_VERIFY) || |
|
|
|
actionType.equals(EnumPosActionType.VERIFY_INDEPENT) || |
|
|
|
actionType.equals(EnumPosActionType.VERIFY_PAY)) { |
|
|
|
posOrderId = Long.valueOf(posOrderIdStr); |
|
|
|
posAmount = Integer.valueOf(posAmountStr); |
|
|
|
} |
|
|
|
@@ -547,7 +744,7 @@ public class PosServiceImpl implements PosService { |
|
|
|
} |
|
|
|
|
|
|
|
private Map<String, String> doVerifyActionForOneCouponOrder( |
|
|
|
EnumVerifyActionType actionType, Integer sceneType, |
|
|
|
EnumPosActionType actionType, Integer sceneType, |
|
|
|
String tenantId, String merchantIdStr, Long merchantId, |
|
|
|
String buUserIdStr, Long buUserId, |
|
|
|
String posOrderIdStr, Long posOrderId, Integer posAmount, |
|
|
|
@@ -560,7 +757,7 @@ public class PosServiceImpl implements PosService { |
|
|
|
throw new MallinkException(ErrorCode.COUPON_ORDER_IS_NULL); |
|
|
|
} |
|
|
|
// 4.1 检查券类型 |
|
|
|
if (actionType.equals(EnumVerifyActionType.CHECK)) { |
|
|
|
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()) || |
|
|
|
@@ -580,7 +777,7 @@ public class PosServiceImpl implements PosService { |
|
|
|
throw new MallinkException(ErrorCode.VERIFY_COUPON_TYPE_NOT_SUPPORT); |
|
|
|
} |
|
|
|
} |
|
|
|
} else if (actionType.equals(EnumVerifyActionType.PRE_VERIFY) || actionType.equals(EnumVerifyActionType.VERIFY_PAY)) { |
|
|
|
} else if (actionType.equals(EnumPosActionType.PRE_VERIFY) || 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()) |
|
|
|
@@ -594,7 +791,7 @@ public class PosServiceImpl implements PosService { |
|
|
|
throw new MallinkException(ErrorCode.VERIFY_MANJIAN_USER_PRICE_NOT_TOUCH); |
|
|
|
} |
|
|
|
} |
|
|
|
} else if (actionType.equals(EnumVerifyActionType.VERIFY_INDEPENT)) { |
|
|
|
} 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()) || |
|
|
|
@@ -650,7 +847,7 @@ public class PosServiceImpl implements PosService { |
|
|
|
throw new MallinkException(ErrorCode.VERIFY_COUPON_ORDER_MERCHANT_IS_NULL); |
|
|
|
} |
|
|
|
|
|
|
|
if (actionType.equals(EnumVerifyActionType.CHECK)) { |
|
|
|
if (actionType.equals(EnumPosActionType.CHECK)) { |
|
|
|
if (couponOrderCVo.getCouponOrderStatus().equals(EnumCouponOrderStatus.POS_PRE_VERIFY.getCode())) { |
|
|
|
logger.info("券已被预核销: " + couponOrderIdStr); |
|
|
|
if (!couponOrderCVo.getBUserId().equals(buUserId)) { |
|
|
|
@@ -701,7 +898,7 @@ public class PosServiceImpl implements PosService { |
|
|
|
retMap.put(WxPayConstant.STATUS, EnumCouponOrderStatus.getEnum(couponOrderCVo.getCouponOrderStatus()).getMessage()); |
|
|
|
return retMap; |
|
|
|
} |
|
|
|
} else if (actionType.equals(EnumVerifyActionType.PRE_VERIFY)) { |
|
|
|
} else if (actionType.equals(EnumPosActionType.PRE_VERIFY)) { |
|
|
|
if (couponOrderCVo.getCouponOrderStatus().equals(EnumCouponOrderStatus.POS_PRE_VERIFY.getCode())) { |
|
|
|
logger.info("券已被预核销: " + couponOrderIdStr); |
|
|
|
if (!couponOrderCVo.getBUserId().equals(buUserId)) { |
|
|
|
@@ -811,7 +1008,7 @@ public class PosServiceImpl implements PosService { |
|
|
|
|
|
|
|
@Override |
|
|
|
@Transactional(rollbackFor = Exception.class) |
|
|
|
public Map<String, String> couponOrderVerifyCancel(Map<String, String> params, EnumVerifyActionType actionType) { |
|
|
|
public Map<String, String> couponOrderVerifyCancel(Map<String, String> params, EnumPosActionType actionType) { |
|
|
|
Map<String, String> retMap = new HashMap<>(); |
|
|
|
|
|
|
|
String tenantId = params.get(WxPayConstant.TENANT_ID); // 租户ID |
|
|
|
@@ -833,7 +1030,7 @@ public class PosServiceImpl implements PosService { |
|
|
|
if (StringUtils.isBlank(couponOrderIdStr)) { |
|
|
|
errParam(WxPayConstant.COUPON_ORDER_ID); |
|
|
|
} |
|
|
|
if (actionType.equals(EnumVerifyActionType.PRE_VERIFY) || actionType.equals(EnumVerifyActionType.VERIFY_INDEPENT)) { |
|
|
|
if (actionType.equals(EnumPosActionType.PRE_VERIFY) || actionType.equals(EnumPosActionType.VERIFY_INDEPENT)) { |
|
|
|
if (StringUtils.isBlank(posOrderIdStr)) { |
|
|
|
errParam(WxPayConstant.POS_ORDER_ID); |
|
|
|
} |
|
|
|
@@ -896,7 +1093,7 @@ public class PosServiceImpl implements PosService { |
|
|
|
|
|
|
|
// 预核销取消 |
|
|
|
if (couponOrderCVo.getCouponOrderStatus().equals(EnumCouponOrderStatus.POS_PRE_VERIFY.getCode()) && |
|
|
|
actionType.equals(EnumVerifyActionType.PRE_VERIFY_CANCEL)) { |
|
|
|
actionType.equals(EnumPosActionType.PRE_VERIFY_CANCEL)) { |
|
|
|
logger.info("券已被预核销: " + couponOrderIdStr); |
|
|
|
if (!couponOrderCVo.getBUserId().equals(buUserId)) { |
|
|
|
logger.error(ErrorCode.VERIFY_PRE_BUSER_NOT_EQUAL.getMessage() + ": " + buUserIdStr); |
|
|
|
@@ -913,7 +1110,7 @@ public class PosServiceImpl implements PosService { |
|
|
|
} |
|
|
|
// 核销取消 |
|
|
|
if (couponOrderCVo.getCouponOrderStatus().equals(EnumCouponOrderStatus.COUPON_ORDER_USED.getCode()) && |
|
|
|
actionType.equals(EnumVerifyActionType.VERIFY_CANCEL)) { |
|
|
|
actionType.equals(EnumPosActionType.VERIFY_CANCEL)) { |
|
|
|
logger.info("券已被核销: " + couponOrderIdStr); |
|
|
|
boolean force = false; |
|
|
|
if (StringUtils.isNotBlank(forceStr)) { |
|
|
|
@@ -1040,7 +1237,7 @@ public class PosServiceImpl implements PosService { |
|
|
|
* @param buUserId |
|
|
|
* @param posOrderId |
|
|
|
*/ |
|
|
|
private void doVerify(EnumVerifyActionType actionType, WxCouponOrderCVo couponOrderCVo, WxCoupon coupon, |
|
|
|
private void doVerify(EnumPosActionType actionType, WxCouponOrderCVo couponOrderCVo, WxCoupon coupon, |
|
|
|
Long merchantId, Long buUserId, Long posOrderId, Map<String, String> retMap) { |
|
|
|
int num = 0; |
|
|
|
// 1. insert posOrderId |
|
|
|
@@ -1068,13 +1265,13 @@ public class PosServiceImpl implements PosService { |
|
|
|
couponOrder.setId(couponOrderCVo.getId()); |
|
|
|
couponOrder.setTenantId(couponOrderCVo.getTenantId()); |
|
|
|
couponOrder.setCouponOrderStatus(EnumCouponOrderStatus.COUPON_ORDER_USED.getCode()); //1核销 |
|
|
|
if (actionType.equals(EnumVerifyActionType.VERIFY_INDEPENT)) { |
|
|
|
if (actionType.equals(EnumPosActionType.VERIFY_INDEPENT)) { |
|
|
|
couponOrder.setVerifyType(EnumCouponVerifyType.VERIFY_POS_INDEPENDENT.getCode()); |
|
|
|
} else { |
|
|
|
couponOrder.setVerifyType(EnumCouponVerifyType.VERIFY_POS_PAY.getCode()); |
|
|
|
} |
|
|
|
if (couponOrderCVo.getCouponOrderStatus().equals(EnumCouponOrderStatus.POS_PRE_VERIFY.getCode()) && |
|
|
|
actionType.equals(EnumVerifyActionType.VERIFY_PAY)) { |
|
|
|
actionType.equals(EnumPosActionType.VERIFY_PAY)) { |
|
|
|
couponOrder.setBUserId(buUserId); |
|
|
|
} |
|
|
|
couponOrder.setUpdateDate(new Date()); |
|
|
|
@@ -1922,10 +2119,6 @@ public class PosServiceImpl implements PosService { |
|
|
|
logger.error(ErrorCode.VERIFY_BUSER_MERCHANT_NOT_BELONG.getMessage() + ": " + buUserId); |
|
|
|
throw new MallinkException(ErrorCode.VERIFY_BUSER_MERCHANT_NOT_BELONG); |
|
|
|
} |
|
|
|
if (buUser.getStatus().equals(EnumMerchantStatus.NOT_VALID.getCode())) { |
|
|
|
logger.error(ErrorCode.MERCHANT_BUSER_NOT_VALID.getMessage() + ": " + buUserId); |
|
|
|
throw new MallinkException(ErrorCode.MERCHANT_BUSER_NOT_VALID); |
|
|
|
} |
|
|
|
return buUser; |
|
|
|
} |
|
|
|
|
|
|
|
@@ -1940,6 +2133,18 @@ public class PosServiceImpl implements PosService { |
|
|
|
throw new MallinkException(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(), errMessage); |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* 输入参数错误 |
|
|
|
* @param param1Str |
|
|
|
* @param param2Str |
|
|
|
* @throws MallinkException |
|
|
|
*/ |
|
|
|
private void errParam2(String param1Str, String param2Str) throws MallinkException { |
|
|
|
String errMessage = String.format("please give one value for %s or %s", param1Str, param2Str); |
|
|
|
logger.error(errMessage); |
|
|
|
throw new MallinkException(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(), errMessage); |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* POS订单添加 |
|
|
|
* @return |
|
|
|
|