Commit 150ae092 by 周晓航

bug 修复 使用多券 核销

Signed-off-by: 周晓航 <xiaohang.zhou@freemud.com>
parent de80cc8c
......@@ -13,6 +13,9 @@
package cn.freemud.enums;
import java.util.Arrays;
import java.util.List;
/**
* 应该是下面这个type对应
* @see com.freemud.sdk.api.assortment.order.enums.OldOrderAccountType
......@@ -39,6 +42,18 @@ public enum OrderAccountType {
private String desc;
/**
* 需要 核销的 券 归类
* 代金券
* 商品券
* 运费全
* 折扣券
*/
public static List<Integer> verificationCoupon = Arrays.asList(OrderAccountType.COUPON.getCode(),
OrderAccountType.PRODUCT_COUPON.getCode(),
OrderAccountType.FREIGHT_COUPON.getCode(),
OrderAccountType.DISCOUNT_COUPON.getCode());
OrderAccountType(Integer code, String desc) {
this.code = code;
this.desc = desc;
......
......@@ -40,10 +40,7 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Objects;
import java.util.*;
import java.util.stream.Collectors;
@Service("platformCouponRelationService")
......@@ -64,7 +61,7 @@ public class PlatformCouponRelationServiceImpl implements CouponRelationService
private static final String ORDER_RESOURCE_PUSH_LOG_ROUTING_KEY = "order-resource-push-log-routing-key";
@Value("${baffleOpen.verification.coupon:false}")
private Boolean baffleOpen=false;
private Boolean baffleOpen = false;
@Override
public BaseResponse verificationCoupon(List<QueryOrdersResponseDto.DataBean.OrderBean.AccountBean> accountList, QueryOrdersResponseDto.DataBean.OrderBean orderBean, CouponReqType couponReqType) {
......@@ -72,7 +69,9 @@ public class PlatformCouponRelationServiceImpl implements CouponRelationService
if (CollectionUtils.isEmpty(accountList)) {
return ResponseUtil.success();
}
if (accountList.size() > 1) {
// 需要判断 accountList 里面 是都 同时包含 配送券+ other券
boolean isDoubleCoupon = checkAccountList(accountList);
if (isDoubleCoupon) {
Integer code = OrderAccountType.FREIGHT_COUPON.getCode();
// 运费券 塞进 核销接口里面, 这里真的是贼恶心 逻辑不敢动
QueryOrdersResponseDto.DataBean.OrderBean.AccountBean freightCouponAccountBean = accountList.stream().filter(accountBean -> code.equals(accountBean.getType())).findFirst().orElse(null);
......@@ -91,6 +90,28 @@ public class PlatformCouponRelationServiceImpl implements CouponRelationService
}
/**
* 要校验一遍是否 使用了 需要核销的券 代金券 商品券 运费全 折扣券 需要核销
*
* @param accountList 这里会传递 多张券 和其他的计算 类型
* @return
*/
private boolean checkAccountList(List<QueryOrdersResponseDto.DataBean.OrderBean.AccountBean> accountList) {
// 里面只有一个值 直接使用老逻辑 不管是 什么券
if (accountList.size() == 1) {
return false;
}
// 拿出 所有的使用券信息 代金券 商品券 运费全 折扣券 需要核销
int count = 0;
for (QueryOrdersResponseDto.DataBean.OrderBean.AccountBean accountBean : accountList) {
if (OrderAccountType.verificationCoupon.contains(accountBean.getType())){
count ++;
}
}
// 说明使用了 2张以上的优惠券 需要核销
return count > 1;
}
/**
* 原有逻辑没变动的基础上 加上 配送券信息对象
*
* @param couponCodeVerificationTransDto 配送券信息对象 如果为null 就是原来的逻辑
......@@ -180,12 +201,12 @@ public class PlatformCouponRelationServiceImpl implements CouponRelationService
lastException = ex;
ErrorLog.printErrorLog("verification_error", "/api", couponCodeVerificationDto, ex);
}
if (lastException != null){
if (lastException != null) {
sendMessage(orderBean, LogThreadLocal.getTrackingNo(), couponCodeVerificationDto, lastException);
}else if (!ok || Objects.equals(baffleOpen,true)){
} else if (!ok || Objects.equals(baffleOpen, true)) {
sendMessage(orderBean, LogThreadLocal.getTrackingNo(), couponCodeVerificationDto, ok ? "模拟券核销失败" : couponCodeResponseDto);
}
if (!ok){
if (!ok) {
emailAlertService.sendEmailAlert("核销券码失败", String.format("request:%s \r\nresponse:%s", JSONObject.toJSONString(couponCodeVerificationDto), JSONObject.toJSONString(lastException == null ? couponCodeResponseDto : lastException)));
return ResponseUtil.error(ResponseResult.COUPON_VERIFICATION_FAIL);
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment