|
|
|
@@ -62,8 +62,8 @@ public class PosServiceImpl implements PosService { |
|
|
|
* @return |
|
|
|
*/ |
|
|
|
@Override |
|
|
|
public Map<String, String> checkUserPassword(Map<String, String> params) throws MallinkException { |
|
|
|
Map<String, String> retMap = new HashMap<>(); |
|
|
|
public JSONObject checkUserPassword(Map<String, String> params) throws MallinkException { |
|
|
|
JSONObject retMap = new JSONObject(); |
|
|
|
|
|
|
|
String tenantId = params.get(WxPayConstant.TENANT_ID); // 租户ID |
|
|
|
String phone = params.get(WxPayConstant.PHONE); // buUser's Phone |
|
|
|
@@ -114,13 +114,18 @@ public class PosServiceImpl implements PosService { |
|
|
|
retMap.put(WxPayConstant.MERCHANT_IMG, merchant.getImgUrl()); |
|
|
|
retMap.put(WxPayConstant.BUSER_ID, String.valueOf(user1.getId())); |
|
|
|
|
|
|
|
retMap.put(WxPayConstant.REG_QRCODE_URL, mall.getImgQrcodeWeapp()); |
|
|
|
retMap.put(WxPayConstant.POS_QRCODE_RULE, mall.getPosQrcodeRule()); |
|
|
|
JSONObject qrCodeInfo = new JSONObject(); |
|
|
|
qrCodeInfo.put(WxPayConstant.REG_QRCODE_URL, mall.getImgQrcodeWeapp()); |
|
|
|
qrCodeInfo.put(WxPayConstant.POS_QRCODE_RULE, mall.getPosQrcodeRule()); |
|
|
|
retMap.put(WxPayConstant.QRCODE, qrCodeInfo); |
|
|
|
|
|
|
|
JSONObject memInfo = new JSONObject(); |
|
|
|
memInfo.put(WxPayConstant.DISCOUNT, String.valueOf(config.getDiscount().equals(EnumPosEnableType.Enable.getCode()))); |
|
|
|
memInfo.put(WxPayConstant.COUPON, String.valueOf(config.getCoupon())); |
|
|
|
memInfo.put(WxPayConstant.COUPON_DES, EnumPosCouponEnableType.getEnum(config.getCoupon()).getMessage()); |
|
|
|
memInfo.put(WxPayConstant.CARD, String.valueOf(config.getCard().equals(EnumPosEnableType.Enable.getCode()))); |
|
|
|
retMap.put(WxPayConstant.MEM_CONFIG, memInfo); |
|
|
|
|
|
|
|
retMap.put(WxPayConstant.DISCOUNT, String.valueOf(config.getDiscount().equals(EnumPosEnableType.Enable.getCode()))); |
|
|
|
retMap.put(WxPayConstant.COUPON, String.valueOf(config.getCoupon())); |
|
|
|
retMap.put(WxPayConstant.COUPON_DES, EnumPosCouponEnableType.getEnum(config.getCoupon()).getMessage()); |
|
|
|
retMap.put(WxPayConstant.CARD, String.valueOf(config.getCard().equals(EnumPosEnableType.Enable.getCode()))); |
|
|
|
return retMap; |
|
|
|
} else { |
|
|
|
logger.error(ErrorCode.PASSWORD_ERROR.getMessage()); |
|
|
|
@@ -132,179 +137,9 @@ public class PosServiceImpl implements PosService { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* 获取商城会员设置状态 |
|
|
|
* @param params |
|
|
|
* @return |
|
|
|
*/ |
|
|
|
@Override |
|
|
|
public Map<String, String> getPosMemConfig(Map<String, String> params) throws MallinkException { |
|
|
|
Map<String, String> retMap = new HashMap<>(); |
|
|
|
|
|
|
|
String tenantId = params.get(WxPayConstant.TENANT_ID); // 租户ID |
|
|
|
|
|
|
|
if (StringUtils.isBlank(tenantId)) { |
|
|
|
errParam(WxPayConstant.TENANT_ID); |
|
|
|
} |
|
|
|
WxMall mall = mallService.getByTenantId(tenantId); |
|
|
|
if (mall == null) { |
|
|
|
logger.error(ErrorCode.MALL_INFO_NOT_FOUND.getMessage()); |
|
|
|
throw new MallinkException(ErrorCode.MALL_INFO_NOT_FOUND); |
|
|
|
} |
|
|
|
PosMallConfig config = posMallConfigService.getByTenantId(tenantId); |
|
|
|
if (config == null) { |
|
|
|
logger.error(ErrorCode.MALL_INFO_NOT_FOUND.getMessage()); |
|
|
|
throw new MallinkException(ErrorCode.MALL_INFO_NOT_FOUND); |
|
|
|
} |
|
|
|
retMap.put(WxPayConstant.TENANT_ID, mall.getTenantId()); |
|
|
|
retMap.put(WxPayConstant.MALL_NAME, mall.getName()); |
|
|
|
retMap.put(WxPayConstant.REG_QRCODE_URL, mall.getImgQrcodeWeapp()); |
|
|
|
retMap.put(WxPayConstant.POS_QRCODE_RULE, mall.getPosQrcodeRule()); |
|
|
|
|
|
|
|
retMap.put(WxPayConstant.DISCOUNT, String.valueOf(config.getDiscount().equals(EnumPosEnableType.Enable.getCode()))); |
|
|
|
retMap.put(WxPayConstant.COUPON, String.valueOf(config.getCoupon())); |
|
|
|
retMap.put(WxPayConstant.COUPON_DES, EnumPosCouponEnableType.getEnum(config.getCoupon()).getMessage()); |
|
|
|
retMap.put(WxPayConstant.CARD, String.valueOf(config.getCard().equals(EnumPosEnableType.Enable.getCode()))); |
|
|
|
return retMap; |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* 获取商城二维码 |
|
|
|
* @param params |
|
|
|
* @return |
|
|
|
*/ |
|
|
|
@Override |
|
|
|
public Map<String, String> doGetQrCode(Map<String, String> params) throws MallinkException { |
|
|
|
Map<String, String> retMap = new HashMap<>(); |
|
|
|
|
|
|
|
String tenantId = params.get(WxPayConstant.TENANT_ID); // 租户ID |
|
|
|
|
|
|
|
if (StringUtils.isBlank(tenantId)) { |
|
|
|
errParam(WxPayConstant.TENANT_ID); |
|
|
|
} |
|
|
|
WxMall mall = mallService.getByTenantId(tenantId); |
|
|
|
if (mall == null) { |
|
|
|
logger.error(ErrorCode.MALL_INFO_NOT_FOUND.getMessage()); |
|
|
|
throw new MallinkException(ErrorCode.MALL_INFO_NOT_FOUND); |
|
|
|
} |
|
|
|
retMap.put(WxPayConstant.TENANT_ID, mall.getTenantId()); |
|
|
|
retMap.put(WxPayConstant.MALL_NAME, mall.getName()); |
|
|
|
retMap.put(WxPayConstant.REG_QRCODE_URL, mall.getImgQrcodeWeapp()); |
|
|
|
retMap.put(WxPayConstant.POS_QRCODE_RULE, mall.getPosQrcodeRule()); |
|
|
|
return retMap; |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* 识别会员 |
|
|
|
* @param params |
|
|
|
* @return |
|
|
|
*/ |
|
|
|
@Override |
|
|
|
public Map<String, String> checkMember(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 posOrderIdStr = params.get(WxPayConstant.POS_ORDER_ID); // POS订单ID |
|
|
|
String posAmountStr = params.get(WxPayConstant.ORDER_AMOUNT); // POS订单金额(单位:分) |
|
|
|
|
|
|
|
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(posOrderIdStr)) { |
|
|
|
errParam(WxPayConstant.POS_ORDER_ID); |
|
|
|
} |
|
|
|
if (StringUtils.isBlank(posAmountStr)) { |
|
|
|
errParam(WxPayConstant.ORDER_AMOUNT); |
|
|
|
} |
|
|
|
|
|
|
|
// 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 = 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); |
|
|
|
|
|
|
|
// 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); |
|
|
|
} |
|
|
|
/* |
|
|
|
// 5. 会员level及折扣 |
|
|
|
JSONObject discountObj = new JSONObject(); |
|
|
|
posAmount = getMemLevelDiscount(discountObj, config.getDiscount(), tenantId, user, merchantId, posAmount.intValue()); |
|
|
|
|
|
|
|
retMap.put(WxPayConstant.MEM_ID, user.getId().toString()); |
|
|
|
retMap.put(WxPayConstant.MEM_PHONE, user.getPhone()); |
|
|
|
|
|
|
|
// 6. 优惠券列表 |
|
|
|
if (config.getCoupon().equals(EnumEnableType.Enable.getCode())) { |
|
|
|
Map<String, Object> coQ = new HashMap<>(); |
|
|
|
coQ.put("tenantId", tenantId); |
|
|
|
coQ.put("cUserId", user.getId()); |
|
|
|
coQ.put("merchantId", merchantId); |
|
|
|
coQ.put("posOrderId", posOrderId); |
|
|
|
coQ.put("posPayVerify", "1"); // 支付核销券需要 |
|
|
|
/// coQ.put("posIndepVerify", "1"); |
|
|
|
List<Map> couponOrderList = couponOrderService.findAvailCouponOrder(coQ); |
|
|
|
if (couponOrderList.size() > 0) { |
|
|
|
couponOrderList.stream().forEach( co -> { |
|
|
|
if(co.get("type").equals(EnumCouponType.COUPON_MANJIAN.getCode())) { |
|
|
|
co.put("type_title", EnumCouponType.COUPON_MANJIAN.getMessage()); |
|
|
|
} |
|
|
|
if(co.get("type").equals(EnumCouponType.COUPON_DAIJIN.getCode())) { |
|
|
|
co.put("type_title", EnumCouponType.COUPON_DAIJIN.getMessage()); |
|
|
|
} |
|
|
|
if(co.get("type").equals(EnumCouponType.COUPON_MULTIMCH.getCode())) { |
|
|
|
co.put("type_title", EnumCouponType.COUPON_MULTIMCH.getMessage()); |
|
|
|
} |
|
|
|
}); |
|
|
|
retMap.put(WxPayConstant.AVAIL_CO_LIST, |
|
|
|
JSONArray.toJSONString(couponOrderList)); |
|
|
|
} else { |
|
|
|
retMap.put(WxPayConstant.AVAIL_CO_LIST, "[]"); |
|
|
|
} |
|
|
|
} else { |
|
|
|
retMap.put(WxPayConstant.AVAIL_CO_LIST, "[]"); |
|
|
|
} |
|
|
|
*/ |
|
|
|
return retMap; |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
@Transactional(rollbackFor = Exception.class) |
|
|
|
public Map<String, String> queryAndCalcMem(Map<String, String> params) throws MallinkException { |
|
|
|
Map<String, String> dataMap = new HashMap<>(); |
|
|
|
public JSONObject queryAndCalcMem(Map<String, String> params) throws MallinkException { |
|
|
|
JSONObject dataMap = new JSONObject(); |
|
|
|
|
|
|
|
String tenantId = params.get(WxPayConstant.TENANT_ID); // 租户ID |
|
|
|
String merchantIdStr = params.get(WxPayConstant.MERCHANT_ID); // 商户ID |
|
|
|
@@ -385,7 +220,7 @@ public class PosServiceImpl implements PosService { |
|
|
|
errParam(WxPayConstant.COUPON_ORDER_LIST); |
|
|
|
} |
|
|
|
JSONArray couponOrderArr = JSON.parseArray(coListStr); |
|
|
|
if (couponOrderArr.size() > 1) { |
|
|
|
if (couponOrderArr.size() != 1) { |
|
|
|
String errMessage = "核销只能使用一张券"; |
|
|
|
logger.error(errMessage); |
|
|
|
throw new MallinkException(ErrorCode.VERIFY_ERROR.getCode(), errMessage); |
|
|
|
@@ -461,7 +296,7 @@ public class PosServiceImpl implements PosService { |
|
|
|
List<WxCouponOrderCVo> avaCoList = couponOrderMapper.findAvailCouponOrder(coQ); |
|
|
|
JSONArray selCoArr = JSONObject.parseArray(coListStr); |
|
|
|
if (config.getCoupon().equals(EnumPosCouponEnableType.SingleEnable.getCode())) { |
|
|
|
if (selCoArr.size() > 1) { |
|
|
|
if (selCoArr.size() > 1) { // 为空时,返回所有可用券列表 |
|
|
|
String errMessage = "支付只能使用一张券"; |
|
|
|
logger.error(errMessage); |
|
|
|
throw new MallinkException(ErrorCode.POS_COUPON_PAY_ERROR.getCode(), errMessage); |
|
|
|
@@ -473,9 +308,13 @@ public class PosServiceImpl implements PosService { |
|
|
|
JSONObject couponObj = calcOneCouponPay(promotionCalc, couponOrderCVo, selCoupon); |
|
|
|
couponList.add(couponObj); |
|
|
|
} catch (MallinkException e) { |
|
|
|
throw new MallinkException(e.getErrorCode(), e.getMessage()); |
|
|
|
if (selCoupon) { |
|
|
|
throw new MallinkException(e.getErrorCode(), e.getMessage()); |
|
|
|
} |
|
|
|
} catch (Exception e) { |
|
|
|
throw new MallinkException(500, e.getMessage()); |
|
|
|
if (selCoupon) { |
|
|
|
throw new MallinkException(500, e.getMessage()); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} else if (config.getCoupon().equals(EnumPosCouponEnableType.MultiEnable.getCode())) { |
|
|
|
@@ -522,7 +361,7 @@ public class PosServiceImpl implements PosService { |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* 券核销计算 |
|
|
|
* 单券核销计算 |
|
|
|
* @param promotionCalc |
|
|
|
* @param merchantId |
|
|
|
* @param couponOrderIdStr |
|
|
|
@@ -559,9 +398,65 @@ public class PosServiceImpl implements PosService { |
|
|
|
return retObj; |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* 单券核销 |
|
|
|
* @param promotionCalc |
|
|
|
* @param merchantId |
|
|
|
* @param couponOrderIdStr |
|
|
|
* @return |
|
|
|
*/ |
|
|
|
public JSONObject oneCouponVerify(PromotionCalc promotionCalc, String couponOrderIdStr, Long merchantId, Long buUserId, Long posOrderId) { |
|
|
|
JSONObject retObj = new JSONObject(); |
|
|
|
Date now = new Date(); |
|
|
|
// 1. 获取券包信息 |
|
|
|
WxCouponOrderCVo couponOrderCVo = checkAndGetCouponOrder(couponOrderIdStr, merchantId, now); |
|
|
|
|
|
|
|
// 2. 检查券类型 核销可用(4, 6, 8, 9) |
|
|
|
EnumCouponType couponType = EnumCouponType.getEnum(couponOrderCVo.getCouponType()); |
|
|
|
if (!(couponType.getCode().equals(EnumCouponType.COUPON_MULTIMCH.getCode()) || |
|
|
|
couponType.getCode().equals(EnumCouponType.COUPON_LIPIN.getCode()) || |
|
|
|
couponType.getCode().equals(EnumCouponType.COUPON_PRESS.getCode()) || |
|
|
|
couponType.getCode().equals(EnumCouponType.COUPON_GROUP.getCode())) |
|
|
|
) { |
|
|
|
logger.error(ErrorCode.VERIFY_COUPON_TYPE_NOT_SUPPORT.getMessage()); |
|
|
|
throw new MallinkException(ErrorCode.VERIFY_COUPON_TYPE_NOT_SUPPORT); |
|
|
|
} |
|
|
|
// 5. get coupon |
|
|
|
WxCoupon wxCoupon = couponMapper.selectByPrimaryKey(couponOrderCVo.getCouponId()); |
|
|
|
if (wxCoupon == null) { |
|
|
|
logger.error("券: coupon-" + wxCoupon.getId() + "不存在" + "couponOrder-" + couponOrderCVo.getId()); |
|
|
|
throw new MallinkException(ErrorCode.COUPON_ORDER_IS_NULL); |
|
|
|
} |
|
|
|
|
|
|
|
try { |
|
|
|
doVerify(retObj, EnumPosActionType.VERIFY_INDEPENT, couponOrderCVo, wxCoupon, merchantId, buUserId, posOrderId); |
|
|
|
} catch (MallinkException e) { |
|
|
|
logger.error(e.getMessage()); |
|
|
|
throw new MallinkException(e.getErrorCode(), e.getMessage()); |
|
|
|
} catch (Exception e) { |
|
|
|
logger.error(e.getMessage()); |
|
|
|
throw new MallinkException(500, e.getMessage()); |
|
|
|
} |
|
|
|
retObj.put(WxPayConstant.COUPON_ID, couponOrderIdStr); |
|
|
|
retObj.put(WxPayConstant.IS_SELECTED, EnumPosSelect.SELECTED.getCode()); |
|
|
|
retObj.put(WxPayConstant.TITLE, couponOrderCVo.getTitle()); |
|
|
|
retObj.put(WxPayConstant.COUPON_TYPE, couponType.getMessage()); |
|
|
|
retObj.put(WxPayConstant.COVER_IMG, couponOrderCVo.getCoverImg()); |
|
|
|
retObj.put(WxPayConstant.PRICE, couponOrderCVo.getPrice()); |
|
|
|
retObj.put(WxPayConstant.SALE_PRICE, couponOrderCVo.getSalePrice()); |
|
|
|
retObj.put(WxPayConstant.COUPON_DES, String.format("过期时间: %s", mydateFormat.format(couponOrderCVo.getExpiredTime()))); |
|
|
|
promotionCalc.setOrderAmount(couponOrderCVo.getPrice()); |
|
|
|
promotionCalc.setOrderAmountLeft(couponOrderCVo.getPrice()); |
|
|
|
promotionCalc.setPromotionAmount(couponOrderCVo.getPrice()); |
|
|
|
promotionCalc.setAmountLeftAfterPay(0); |
|
|
|
return retObj; |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* 券支付计算 |
|
|
|
* @param promotionCalc |
|
|
|
* @param couponOrderCVo |
|
|
|
* @param couponSelected |
|
|
|
* @return |
|
|
|
*/ |
|
|
|
private JSONObject calcOneCouponPay(PromotionCalc promotionCalc, WxCouponOrderCVo couponOrderCVo, boolean couponSelected) { |
|
|
|
@@ -617,6 +512,66 @@ public class PosServiceImpl implements PosService { |
|
|
|
return retObj; |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* 券支付计算 |
|
|
|
* @param promotionCalc |
|
|
|
* @param couponOrderCVo |
|
|
|
* @param couponSelected |
|
|
|
* @return |
|
|
|
*/ |
|
|
|
private JSONObject oneCouponPay(PromotionCalc promotionCalc, WxCouponOrderCVo couponOrderCVo, boolean couponSelected) { |
|
|
|
JSONObject retObj = new JSONObject(); |
|
|
|
Date now = new Date(); |
|
|
|
|
|
|
|
// 2. 检查券类型 支付可用(1, 2, 6), |
|
|
|
EnumCouponType couponType = EnumCouponType.getEnum(couponOrderCVo.getCouponType()); |
|
|
|
if (!(couponType.getCode().equals(EnumCouponType.COUPON_MULTIMCH.getCode()) || |
|
|
|
couponType.getCode().equals(EnumCouponType.COUPON_MANJIAN.getCode()) || |
|
|
|
couponType.getCode().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 (couponType.equals(EnumCouponType.COUPON_MANJIAN)) { |
|
|
|
if (promotionCalc.getOrderAmount() < couponOrderCVo.getUsePrice()) { |
|
|
|
logger.error(ErrorCode.VERIFY_MANJIAN_USER_PRICE_NOT_TOUCH.getMessage()); |
|
|
|
throw new MallinkException(ErrorCode.VERIFY_MANJIAN_USER_PRICE_NOT_TOUCH); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
// 4. 生成优惠券抵扣信息 |
|
|
|
retObj.put(WxPayConstant.COUPON_ID, couponOrderCVo.getId().toString()); |
|
|
|
retObj.put(WxPayConstant.TITLE, couponOrderCVo.getTitle()); |
|
|
|
retObj.put(WxPayConstant.COUPON_TYPE, couponType.getMessage()); |
|
|
|
retObj.put(WxPayConstant.COVER_IMG, couponOrderCVo.getCoverImg()); |
|
|
|
retObj.put(WxPayConstant.PRICE, couponOrderCVo.getPrice()); |
|
|
|
retObj.put(WxPayConstant.SALE_PRICE, couponOrderCVo.getSalePrice()); |
|
|
|
if (couponType.equals(EnumCouponType.COUPON_MANJIAN)) { |
|
|
|
retObj.put(WxPayConstant.USE_PRICE, couponOrderCVo.getSalePrice()); |
|
|
|
String des = String.format("%s-满%s元可用,可抵%s元, 过期时间: %s", |
|
|
|
couponType.getMessage(), couponOrderCVo.getUsePriceStr(), couponOrderCVo.getPriceStr(), |
|
|
|
mydateFormat.format(couponOrderCVo.getExpiredTime())); |
|
|
|
retObj.put(WxPayConstant.COUPON_DES, des); |
|
|
|
} else { |
|
|
|
String des = String.format("%s-可抵%s元, 过期时间: %s", |
|
|
|
couponType.getMessage(), couponOrderCVo.getPriceStr(), |
|
|
|
mydateFormat.format(couponOrderCVo.getExpiredTime())); |
|
|
|
retObj.put(WxPayConstant.COUPON_DES, des); |
|
|
|
} |
|
|
|
if (couponSelected) { |
|
|
|
retObj.put(WxPayConstant.IS_SELECTED, String.valueOf(EnumPosSelect.SELECTED.getCode())); |
|
|
|
Integer remainAmount = promotionCalc.getAmountLeftAfterPay() - couponOrderCVo.getPrice(); |
|
|
|
if (remainAmount < 0) { |
|
|
|
remainAmount = 0; |
|
|
|
} |
|
|
|
Integer discountAmount = promotionCalc.getAmountLeftAfterPay() - remainAmount; |
|
|
|
promotionCalc.setPromotionAmount(discountAmount); |
|
|
|
promotionCalc.setAmountLeftAfterPay(remainAmount); |
|
|
|
} |
|
|
|
return retObj; |
|
|
|
} |
|
|
|
|
|
|
|
private WxCouponOrderCVo checkAndGetCouponOrder(String couponOrderIdStr, Long merchantId, Date currDate) { |
|
|
|
// 1, 获取券包信息 |
|
|
|
WxCouponOrderCVo couponOrderCVo = couponOrderService.detailCUserVo(couponOrderIdStr); |
|
|
|
@@ -702,7 +657,7 @@ public class PosServiceImpl implements PosService { |
|
|
|
private JSONObject getMemLevelDiscount(PromotionCalc promotionCalc, Integer discountConfig, String tenantId, WxCUser user, Long merchantId) { |
|
|
|
JSONObject discountObj = new JSONObject(); |
|
|
|
Integer discount = 100; |
|
|
|
if (discountConfig.equals(EnumEnableType.Enable.getCode())) { |
|
|
|
if (discountConfig.equals(EnumPosEnableType.Enable.getCode())) { |
|
|
|
String level = WxLevelConfigService.DEFAULT_LEVEL; |
|
|
|
// 1. 会员级别Level |
|
|
|
List<WxLevelConfig> levelList = levelConfigService.getByTenantId(tenantId); |
|
|
|
@@ -750,112 +705,222 @@ public class PosServiceImpl implements PosService { |
|
|
|
return discountObj; |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
//@Override |
|
|
|
@Transactional(rollbackFor = Exception.class) |
|
|
|
public Map<String, String> couponOrderVerifyDo(@RequestBody Map<String, String> params, EnumPosActionType actionType) throws MallinkException { |
|
|
|
Map<String, String> retMap = new HashMap<>(); |
|
|
|
public Map<String, String> couponOrderVerify(Map<String, String> params) throws MallinkException { |
|
|
|
Map<String, String> dataMap = 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 sceneTypeStr = params.get(WxPayConstant.SCENE_TYPE); // 场景类型 |
|
|
|
String couponOrderIdStr = params.get(WxPayConstant.COUPON_ORDER_ID); // 券ID |
|
|
|
String posOrderIdStr = params.get(WxPayConstant.POS_ORDER_ID); // POS订单ID |
|
|
|
String posAmountStr = params.get(WxPayConstant.ORDER_AMOUNT); // POS订单总额(单位:分) |
|
|
|
String tenantId = params.get(WxPayConstant.TENANT_ID); // 租户ID |
|
|
|
String merchantIdStr = params.get(WxPayConstant.MERCHANT_ID); // 商户ID |
|
|
|
String buUserIdStr = params.get(WxPayConstant.BUSER_ID); // POS操作员ID |
|
|
|
String sceneTypeStr = params.get(WxPayConstant.SCENE_TYPE); // 交易场景 |
|
|
|
String orderIdStr = params.get(WxPayConstant.POS_ORDER_ID); // POS订单ID |
|
|
|
String orderCreateSN = params.get(WxPayConstant.ORDER_CREATE_SN); // POS SN号 |
|
|
|
String coListStr = params.get(WxPayConstant.COUPON_ORDER_LIST); // 优惠券列表 |
|
|
|
|
|
|
|
Integer sceneType = null; |
|
|
|
if (StringUtils.isBlank(tenantId)) { |
|
|
|
errParam(WxPayConstant.TENANT_ID); |
|
|
|
} |
|
|
|
PosMallConfig config = posMallConfigService.getByTenantId(tenantId); |
|
|
|
if (config == null) { |
|
|
|
logger.error(ErrorCode.POS_CONFIG_NOT_FOUND.getMessage()); |
|
|
|
throw new MallinkException(ErrorCode.POS_CONFIG_NOT_FOUND); |
|
|
|
} |
|
|
|
if (!config.getCoupon().equals(EnumPosEnableType.Disable.getCode())) { |
|
|
|
logger.error(ErrorCode.POS_CONFIG_MEM_COUPON_DISABLE.getMessage()); |
|
|
|
throw new MallinkException(ErrorCode.POS_CONFIG_MEM_COUPON_DISABLE); |
|
|
|
} else { |
|
|
|
dataMap.put(WxPayConstant.TENANT_ID, tenantId); |
|
|
|
} |
|
|
|
if (StringUtils.isBlank(merchantIdStr)) { |
|
|
|
errParam(WxPayConstant.MERCHANT_ID); |
|
|
|
} else { |
|
|
|
dataMap.put(WxPayConstant.MERCHANT_ID, merchantIdStr); |
|
|
|
} |
|
|
|
if (StringUtils.isBlank(buUserIdStr)) { |
|
|
|
errParam(WxPayConstant.BUSER_ID); |
|
|
|
} else { |
|
|
|
dataMap.put(WxPayConstant.BUSER_ID, buUserIdStr); |
|
|
|
} |
|
|
|
if (StringUtils.isBlank(couponOrderIdStr)) { |
|
|
|
errParam(WxPayConstant.COUPON_ORDER_ID); |
|
|
|
if (StringUtils.isBlank(sceneTypeStr)) { |
|
|
|
errParam(WxPayConstant.SCENE_TYPE); |
|
|
|
} else { |
|
|
|
dataMap.put(WxPayConstant.SCENE_TYPE, sceneTypeStr); |
|
|
|
} |
|
|
|
if (actionType.equals(EnumPosActionType.CHECK)) { |
|
|
|
if (StringUtils.isBlank(sceneTypeStr)) { |
|
|
|
errParam(WxPayConstant.SCENE_TYPE); |
|
|
|
} |
|
|
|
try { |
|
|
|
sceneType = Integer.valueOf(sceneTypeStr); |
|
|
|
} catch (NumberFormatException e) { |
|
|
|
logger.error(e.getMessage()); |
|
|
|
throw new MallinkException(ErrorCode.SYS_PARAMETER_CAST_ERROR.getCode(), e.getMessage()); |
|
|
|
} |
|
|
|
} else if (actionType.equals(EnumPosActionType.VERIFY_INDEPENT)) { |
|
|
|
sceneType = EnumPosSceneType.VERIFY.getCode(); |
|
|
|
} else if (actionType.equals(EnumPosActionType.VERIFY_PAY)) { |
|
|
|
sceneType = EnumPosSceneType.PAY.getCode(); |
|
|
|
if (StringUtils.isBlank(orderIdStr)) { |
|
|
|
errParam(WxPayConstant.POS_ORDER_ID); |
|
|
|
} else { |
|
|
|
dataMap.put(WxPayConstant.POS_ORDER_ID, orderIdStr); |
|
|
|
} |
|
|
|
if (actionType.equals(EnumPosActionType.PAY_VERIFY_PRE) || |
|
|
|
actionType.equals(EnumPosActionType.VERIFY_INDEPENT) || |
|
|
|
actionType.equals(EnumPosActionType.VERIFY_PAY)) { |
|
|
|
if (StringUtils.isBlank(posOrderIdStr)) { |
|
|
|
errParam(WxPayConstant.POS_ORDER_ID); |
|
|
|
} |
|
|
|
if (StringUtils.isBlank(orderCreateSN)) { |
|
|
|
errParam(WxPayConstant.ORDER_CREATE_SN); |
|
|
|
} else { |
|
|
|
dataMap.put(WxPayConstant.ORDER_CREATE_SN, orderCreateSN); |
|
|
|
} |
|
|
|
if (actionType.equals(EnumPosActionType.PAY_VERIFY_PRE) || |
|
|
|
actionType.equals(EnumPosActionType.VERIFY_PAY)) { |
|
|
|
if (StringUtils.isBlank(posAmountStr)) { |
|
|
|
errParam(WxPayConstant.ORDER_AMOUNT); |
|
|
|
} |
|
|
|
|
|
|
|
Integer iSceneType; |
|
|
|
try { |
|
|
|
iSceneType = Integer.valueOf(sceneTypeStr); |
|
|
|
} catch (NumberFormatException e) { |
|
|
|
logger.error(e.getMessage()); |
|
|
|
throw new MallinkException(ErrorCode.SYS_PARAMETER_CAST_ERROR); |
|
|
|
} |
|
|
|
|
|
|
|
Long merchantId, buUserId, posOrderId = 0L; |
|
|
|
Integer posAmount = 0; |
|
|
|
// 1. POS 支持 配置 |
|
|
|
PosMallConfig config = posMallConfigService.getByTenantId(tenantId); |
|
|
|
if (config == null) { |
|
|
|
logger.error(ErrorCode.POS_CONFIG_NOT_FOUND.getMessage()); |
|
|
|
throw new MallinkException(ErrorCode.POS_CONFIG_NOT_FOUND); |
|
|
|
} |
|
|
|
|
|
|
|
// 2. 商户ID, B端用户ID |
|
|
|
Long merchantId, buUserId, posOrderId; |
|
|
|
try { |
|
|
|
merchantId = Long.valueOf(merchantIdStr); |
|
|
|
buUserId = Long.valueOf(buUserIdStr); |
|
|
|
if (actionType.equals(EnumPosActionType.PAY_VERIFY_PRE) || |
|
|
|
actionType.equals(EnumPosActionType.VERIFY_INDEPENT) || |
|
|
|
actionType.equals(EnumPosActionType.VERIFY_PAY)) { |
|
|
|
posOrderId = Long.valueOf(posOrderIdStr); |
|
|
|
} |
|
|
|
if (actionType.equals(EnumPosActionType.PAY_VERIFY_PRE) || |
|
|
|
actionType.equals(EnumPosActionType.VERIFY_PAY)) { |
|
|
|
posAmount = Integer.valueOf(posAmountStr); |
|
|
|
} |
|
|
|
posOrderId = Long.valueOf(orderIdStr); |
|
|
|
} catch (NumberFormatException e) { |
|
|
|
logger.error(e.getMessage()); |
|
|
|
throw new MallinkException(ErrorCode.SYS_PARAMETER_CAST_ERROR.getCode(), e.getMessage()); |
|
|
|
throw new MallinkException(ErrorCode.SYS_PARAMETER_CAST_ERROR); |
|
|
|
} |
|
|
|
// 2. check merchant |
|
|
|
|
|
|
|
// 3. check merchant |
|
|
|
WxMerchant merchant = checkAndGetMerchant(merchantId); |
|
|
|
// 3. check buUser |
|
|
|
// 4. check buUser |
|
|
|
WxMerchantBUser buUser = checkAndGetMerchantUser(buUserId, merchantId); |
|
|
|
|
|
|
|
JSONArray coRetArr = new JSONArray(); |
|
|
|
if (couponOrderIdStr != null) { |
|
|
|
EnumPosSceneType sceneType = EnumPosSceneType.getEnum(iSceneType); |
|
|
|
JSONObject promotionData = new JSONObject(); |
|
|
|
JSONObject promotionInfo = new JSONObject(); |
|
|
|
JSONObject promotionPayment = new JSONObject(); |
|
|
|
PromotionCalc promotionCalc = new PromotionCalc(); |
|
|
|
if (sceneType.equals(EnumPosSceneType.VERIFY)) { |
|
|
|
if (config.getCoupon().equals(EnumPosCouponEnableType.Disable.getCode())) { |
|
|
|
logger.error(ErrorCode.POS_CONFIG_MEM_COUPON_DISABLE.getMessage()); |
|
|
|
throw new MallinkException(ErrorCode.POS_CONFIG_MEM_COUPON_DISABLE); |
|
|
|
} |
|
|
|
JSONObject promotionCoupon = new JSONObject(); |
|
|
|
JSONArray couponList = new JSONArray(); |
|
|
|
if (StringUtils.isBlank(coListStr)) { |
|
|
|
errParam(WxPayConstant.COUPON_ORDER_LIST); |
|
|
|
} |
|
|
|
JSONArray couponOrderArr = JSON.parseArray(coListStr); |
|
|
|
if (couponOrderArr.size() > 1) { |
|
|
|
String errMessage = "核销只能使用一张券"; |
|
|
|
logger.error(errMessage); |
|
|
|
throw new MallinkException(ErrorCode.VERIFY_ERROR.getCode(), errMessage); |
|
|
|
} |
|
|
|
String couponOrderIdStr = couponOrderArr.getString(0); |
|
|
|
if (couponOrderIdStr != null) { |
|
|
|
try { |
|
|
|
JSONObject couponPromoMap = oneCouponVerify(promotionCalc, couponOrderIdStr, merchantId, buUserId, posOrderId); |
|
|
|
couponList.add(couponPromoMap); |
|
|
|
} catch (MallinkException e) { |
|
|
|
throw new MallinkException(e.getErrorCode(), e.getMessage()); |
|
|
|
} catch (Exception e) { |
|
|
|
throw new MallinkException(500, e.getMessage()); |
|
|
|
} |
|
|
|
} |
|
|
|
promotionCoupon.put(WxPayConstant.COUPON_ORDER_LIST, couponList); |
|
|
|
// 券优惠总信息 |
|
|
|
promotionCoupon.put(WxPayConstant.COUPON_PROMOTION_AMOUNT, promotionCalc.getPromotionAmount()); |
|
|
|
promotionInfo.put(WxPayConstant.COUPON, promotionCoupon); |
|
|
|
} else if(sceneType.equals(EnumPosSceneType.PAY)) { |
|
|
|
JSONObject promotionCoupon = new JSONObject(); |
|
|
|
JSONArray couponList = new JSONArray(); |
|
|
|
|
|
|
|
String memIdStr = params.get(WxPayConstant.MEM_ID); // 会员ID |
|
|
|
String memPhoneStr = params.get(WxPayConstant.MEM_PHONE); // 会员手机 |
|
|
|
String orderAmountStr = params.get(WxPayConstant.ORDER_AMOUNT); // POS订单金额(单位:分) |
|
|
|
String orderAmountLeftStr = params.get(WxPayConstant.ORDER_AMOUNT_LEFT); // POS订单金额(单位:分) |
|
|
|
if (StringUtils.isBlank(orderAmountStr)) { |
|
|
|
errParam(WxPayConstant.ORDER_AMOUNT); |
|
|
|
} else { |
|
|
|
dataMap.put(WxPayConstant.ORDER_AMOUNT, orderAmountStr); |
|
|
|
} |
|
|
|
if (StringUtils.isBlank(orderAmountLeftStr)) { |
|
|
|
errParam(WxPayConstant.ORDER_AMOUNT_LEFT); |
|
|
|
} else { |
|
|
|
dataMap.put(WxPayConstant.ORDER_AMOUNT_LEFT, orderAmountLeftStr); |
|
|
|
} |
|
|
|
if (StringUtils.isBlank(memIdStr) && StringUtils.isBlank(memPhoneStr)) { |
|
|
|
errParam2(WxPayConstant.MEM_ID, WxPayConstant.MEM_PHONE); |
|
|
|
} |
|
|
|
// 10. 获取会员信息 |
|
|
|
WxCUser user = getMemUser(tenantId, memIdStr, memPhoneStr); |
|
|
|
if (user == null) { |
|
|
|
logger.error(ErrorCode.USER_NOT_MEMBER.getMessage()); |
|
|
|
throw new MallinkException(ErrorCode.USER_NOT_MEMBER); |
|
|
|
} |
|
|
|
if (user != null) { |
|
|
|
dataMap.put(WxPayConstant.MEM_ID, user.getId().toString()); |
|
|
|
dataMap.put(WxPayConstant.MEM_PHONE, user.getPhone()); |
|
|
|
} |
|
|
|
// 11. 订单金额 |
|
|
|
Integer orderAmount, orderAmountLeft; |
|
|
|
try { |
|
|
|
Map<String,String> oneRetMap = doVerifyActionForOneCouponOrder( |
|
|
|
actionType, sceneType, |
|
|
|
tenantId, merchantIdStr, merchantId, |
|
|
|
buUserIdStr, buUserId, |
|
|
|
posOrderIdStr, posOrderId, posAmount, |
|
|
|
couponOrderIdStr); |
|
|
|
coRetArr.add(oneRetMap); |
|
|
|
} catch (MallinkException e) { |
|
|
|
throw new MallinkException(e.getErrorCode(), e.getMessage()); |
|
|
|
orderAmount = Integer.valueOf(orderAmountStr); |
|
|
|
orderAmountLeft = Integer.valueOf(orderAmountLeftStr); |
|
|
|
} catch (NumberFormatException e) { |
|
|
|
logger.error(e.getMessage()); |
|
|
|
throw new MallinkException(ErrorCode.SYS_PARAMETER_CAST_ERROR); |
|
|
|
} |
|
|
|
promotionCalc.setOrderAmount(orderAmount); |
|
|
|
promotionCalc.setOrderAmountLeft(orderAmountLeft); |
|
|
|
promotionCalc.setPromotionAmount(0); |
|
|
|
promotionCalc.setAmountLeftAfterPay(orderAmountLeft); |
|
|
|
// 12. 会员折扣 |
|
|
|
JSONObject discountObj = getMemLevelDiscount(promotionCalc, config.getDiscount(), tenantId, user, merchantId); |
|
|
|
promotionInfo.put(WxPayConstant.MEMBER_DISCOUNT, discountObj); |
|
|
|
// 14. 获取用户可用券列表 |
|
|
|
if (!config.getCoupon().equals(EnumPosCouponEnableType.Disable.getCode())) { |
|
|
|
Map<String, Object> coQ = new HashMap<>(); |
|
|
|
coQ.put("tenantId", tenantId); |
|
|
|
coQ.put("cUserId", user.getId()); |
|
|
|
coQ.put("merchantId", merchantId); |
|
|
|
List<WxCouponOrderCVo> avaCoList = couponOrderMapper.findAvailCouponOrder(coQ); |
|
|
|
JSONArray selCoArr = JSONObject.parseArray(coListStr); |
|
|
|
if (config.getCoupon().equals(EnumPosCouponEnableType.SingleEnable.getCode())) { |
|
|
|
if (selCoArr.size() > 1) { |
|
|
|
String errMessage = "支付只能使用一张券"; |
|
|
|
logger.error(errMessage); |
|
|
|
throw new MallinkException(ErrorCode.POS_COUPON_PAY_ERROR.getCode(), errMessage); |
|
|
|
} |
|
|
|
for (int i = 0; i < avaCoList.size(); i++) { |
|
|
|
WxCouponOrderCVo couponOrderCVo = avaCoList.get(i); |
|
|
|
boolean selCoupon = isSelCoupon(selCoArr, couponOrderCVo.getId()); |
|
|
|
try { |
|
|
|
JSONObject couponObj = oneCouponPay(promotionCalc, couponOrderCVo, selCoupon); |
|
|
|
couponList.add(couponObj); |
|
|
|
} catch (MallinkException e) { |
|
|
|
throw new MallinkException(e.getErrorCode(), e.getMessage()); |
|
|
|
} catch (Exception e) { |
|
|
|
throw new MallinkException(500, e.getMessage()); |
|
|
|
} |
|
|
|
} |
|
|
|
} else if (config.getCoupon().equals(EnumPosCouponEnableType.MultiEnable.getCode())) { |
|
|
|
for (int i = 0; i < avaCoList.size(); i++) { |
|
|
|
WxCouponOrderCVo couponOrderCVo = avaCoList.get(i); |
|
|
|
boolean selCoupon = isSelCoupon(selCoArr, couponOrderCVo.getId()); |
|
|
|
try { |
|
|
|
JSONObject couponObj = calcOneCouponPay(promotionCalc, couponOrderCVo, selCoupon); |
|
|
|
couponList.add(couponObj); |
|
|
|
} catch (MallinkException e) { |
|
|
|
throw new MallinkException(e.getErrorCode(), e.getMessage()); |
|
|
|
} catch (Exception e) { |
|
|
|
throw new MallinkException(500, e.getMessage()); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
promotionCoupon.put(WxPayConstant.COUPON_ORDER_LIST, couponList); |
|
|
|
// 券优惠总信息 |
|
|
|
promotionCoupon.put(WxPayConstant.COUPON_PROMOTION_AMOUNT, promotionCalc.getPromotionAmount()); |
|
|
|
promotionInfo.put(WxPayConstant.COUPON, promotionCoupon); |
|
|
|
} |
|
|
|
retMap.put(WxPayConstant.RET, coRetArr.toJSONString()); |
|
|
|
return retMap; |
|
|
|
// 构造支付信息 |
|
|
|
promotionPayment.put(WxPayConstant.ORDER_AMOUNT, promotionCalc.getOrderAmount()); |
|
|
|
promotionPayment.put(WxPayConstant.ORDER_AMOUNT_LEFT, promotionCalc.getOrderAmountLeft()); |
|
|
|
promotionPayment.put(WxPayConstant.PROMOTION_AMOUNT, promotionCalc.getPromotionAmount()); |
|
|
|
promotionPayment.put(WxPayConstant.AMOUNT_LEFT_AFTER_PAY, promotionCalc.getAmountLeftAfterPay()); |
|
|
|
promotionData.put(WxPayConstant.PAYMENT_PREDICTION, promotionPayment); |
|
|
|
promotionData.put(WxPayConstant.PROMOTION_INFO, promotionInfo); |
|
|
|
dataMap.put(WxPayConstant.PROMOTION_DATA, JSON.toJSONString(promotionData)); |
|
|
|
return dataMap; |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
//@Override |
|
|
|
@Transactional(rollbackFor = Exception.class) |
|
|
|
public Map<String, String> couponOrderVerifyListDo(@RequestBody Map<String, String> params, EnumPosActionType actionType) throws MallinkException { |
|
|
|
Map<String, String> retMap = new HashMap<>(); |
|
|
|
@@ -1190,7 +1255,7 @@ public class PosServiceImpl implements PosService { |
|
|
|
} |
|
|
|
|
|
|
|
try { |
|
|
|
doVerify(actionType, couponOrderCVo, wxCoupon, merchantId, buUserId, posOrderId, retMap); |
|
|
|
//doVerify(actionType, couponOrderCVo, wxCoupon, merchantId, buUserId, posOrderId, retMap); |
|
|
|
Integer remainAmount = posAmount - couponOrderCVo.getPrice(); |
|
|
|
if (remainAmount < 0) { |
|
|
|
remainAmount = 0; |
|
|
|
@@ -1215,7 +1280,7 @@ public class PosServiceImpl implements PosService { |
|
|
|
throw new MallinkException(500, errMessage); |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
//@Override |
|
|
|
@Transactional(rollbackFor = Exception.class) |
|
|
|
public Map<String, String> couponOrderVerifyCancel(Map<String, String> params, EnumPosActionType actionType) { |
|
|
|
Map<String, String> retMap = new HashMap<>(); |
|
|
|
@@ -1440,8 +1505,8 @@ public class PosServiceImpl implements PosService { |
|
|
|
* @param buUserId |
|
|
|
* @param posOrderId |
|
|
|
*/ |
|
|
|
private void doVerify(EnumPosActionType actionType, WxCouponOrderCVo couponOrderCVo, WxCoupon coupon, |
|
|
|
Long merchantId, Long buUserId, Long posOrderId, Map<String, String> retMap) { |
|
|
|
private void doVerify(JSONObject retMap, EnumPosActionType actionType, WxCouponOrderCVo couponOrderCVo, WxCoupon coupon, |
|
|
|
Long merchantId, Long buUserId, Long posOrderId) { |
|
|
|
int num = 0; |
|
|
|
// 1. insert posOrderId |
|
|
|
PosCouponOrderVerify posCouponOrderVerify = new PosCouponOrderVerify(); |
|
|
|
@@ -1449,18 +1514,11 @@ public class PosServiceImpl implements PosService { |
|
|
|
posCouponOrderVerify.setCouponOrderId(couponOrderCVo.getId()); |
|
|
|
posCouponOrderVerify.setPosOrderId(posOrderId); |
|
|
|
posCouponOrderVerify.setState(EnumEnableType.Enable.getCode()); |
|
|
|
List<PosCouponOrderVerify> posCouponOrderVerifyList = posCouponOrderVerifyService.getList(posCouponOrderVerify); |
|
|
|
if (posCouponOrderVerifyList.size() == 0) { |
|
|
|
try { |
|
|
|
posCouponOrderVerifyService.saveOrUpdate(posCouponOrderVerify); |
|
|
|
} catch (Exception e) { |
|
|
|
logger.error("db failed: couponOrder-" + couponOrderCVo.getId() + ", e:" + e.getMessage()); |
|
|
|
throw new MallinkException(ErrorCode.DB_FAIL.getCode(), "DB FAILD " + e.getMessage()); |
|
|
|
} |
|
|
|
} else if (posCouponOrderVerifyList.size() == 1){ |
|
|
|
|
|
|
|
} else if (posCouponOrderVerifyList.size() > 1){ |
|
|
|
|
|
|
|
try { |
|
|
|
posCouponOrderVerifyService.saveOrUpdate(posCouponOrderVerify); |
|
|
|
} catch (Exception e) { |
|
|
|
logger.error("db failed: couponOrder-" + couponOrderCVo.getId() + ", e:" + e.getMessage()); |
|
|
|
throw new MallinkException(ErrorCode.DB_FAIL.getCode(), "DB FAILD " + e.getMessage()); |
|
|
|
} |
|
|
|
// 2. update couponOrder |
|
|
|
Date curDate = new Date(); |
|
|
|
@@ -1497,12 +1555,22 @@ public class PosServiceImpl implements PosService { |
|
|
|
try { |
|
|
|
WxOrder order = orderMapper.selectByPrimaryKey(couponOrderCVo.getOrderId()); |
|
|
|
int point = scoreRulesService.addScore2(EnumScoreType.CONSUMPTION, order, couponOrderCVo.getBusinessId()); |
|
|
|
retMap.put(WxPayConstant.POINT, String.valueOf(point)); |
|
|
|
retMap.put(WxPayConstant.POINT, point); |
|
|
|
} catch (Exception e) { |
|
|
|
logger.error("核销成长值异常:" + e.getMessage()); |
|
|
|
} |
|
|
|
|
|
|
|
// 4. 积分 |
|
|
|
int credit = posAddCredit(couponOrderCVo, coupon, merchantId, buUserId); |
|
|
|
if (credit > 0) { |
|
|
|
retMap.put(WxPayConstant.CREDIT, credit); |
|
|
|
} else { |
|
|
|
retMap.put(WxPayConstant.CREDIT, 0); |
|
|
|
} |
|
|
|
logger.info("核销已完成: " + couponOrderCVo.getId()); |
|
|
|
} |
|
|
|
|
|
|
|
private int posAddCredit(WxCouponOrderCVo couponOrderCVo, WxCoupon coupon, Long merchantId, Long buUserId) { |
|
|
|
try { |
|
|
|
//-------此处为【现金支付】记录增加积分操作------- |
|
|
|
WxCreditHistory creditHistory = new WxCreditHistory(); |
|
|
|
@@ -1519,14 +1587,14 @@ public class PosServiceImpl implements PosService { |
|
|
|
creditHistory.setMerchantId(merchantId); |
|
|
|
creditHistory = creditHistoryService.saveOrUpdate(creditHistory); |
|
|
|
if (creditHistory.getCreditNum() != null) { |
|
|
|
retMap.put(WxPayConstant.CREDIT, String.valueOf(creditHistory.getCreditNum())); |
|
|
|
return creditHistory.getCreditNum(); |
|
|
|
} else { |
|
|
|
retMap.put(WxPayConstant.CREDIT, "0"); |
|
|
|
return 0; |
|
|
|
} |
|
|
|
} catch (Exception e) { |
|
|
|
logger.error("核销积分值异常:" + e.getMessage()); |
|
|
|
} |
|
|
|
logger.info("核销已完成: " + couponOrderCVo.getId()); |
|
|
|
return 0; |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
@@ -1612,7 +1680,7 @@ public class PosServiceImpl implements PosService { |
|
|
|
logger.info("核销已取消: " + couponOrderCVo.getId()); |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
//@Override |
|
|
|
@Transactional(rollbackFor = Exception.class) |
|
|
|
public Map<String, String> cardPayPre(Map<String, String> params) throws MallinkException { |
|
|
|
Map<String, String> retMap = new HashMap<>(); |
|
|
|
@@ -1735,7 +1803,7 @@ public class PosServiceImpl implements PosService { |
|
|
|
return retMap; |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
//@Override |
|
|
|
@Transactional(rollbackFor = Exception.class) |
|
|
|
public Map<String, String> cardPayPreCancel(@RequestBody Map<String, String> params) throws MallinkException { |
|
|
|
Map<String, String> retMap = new HashMap<>(); |
|
|
|
@@ -1844,13 +1912,13 @@ public class PosServiceImpl implements PosService { |
|
|
|
return retMap; |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
//@Override |
|
|
|
@Transactional(rollbackFor = Exception.class) |
|
|
|
public Map<String, String> cardPay(Map<String, String> params) throws MallinkException { |
|
|
|
return null; |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
//@Override |
|
|
|
@Transactional(rollbackFor = Exception.class) |
|
|
|
public Map<String, String> cardPayCancel(Map<String, String> params) throws MallinkException { |
|
|
|
Map<String, String> retMap = new HashMap<>(); |
|
|
|
@@ -1967,7 +2035,7 @@ public class PosServiceImpl implements PosService { |
|
|
|
return retMap; |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
//@Override |
|
|
|
@Transactional(rollbackFor = Exception.class) |
|
|
|
public Map<String, String> posOrderSync(Map<String, String> params) throws MallinkException { |
|
|
|
Map<String, String> retMap = new HashMap<>(); |
|
|
|
|