Commit 6f25594b by 周晓航

核销 支持一单多券

Signed-off-by: 周晓航 <xiaohang.zhou@freemud.com>
parent f8b6a2d0
...@@ -3803,26 +3803,29 @@ public class OrderSdkAdapter { ...@@ -3803,26 +3803,29 @@ public class OrderSdkAdapter {
|| account.getAccountType().equals(QueryOrderAccountType.DISCOUNT_COUPON) || account.getAccountType().equals(QueryOrderAccountType.DISCOUNT_COUPON)
|| account.getAccountType().equals(QueryOrderAccountType.FREIGHT_COUPON) || account.getAccountType().equals(QueryOrderAccountType.FREIGHT_COUPON)
).collect(Collectors.toList()); ).collect(Collectors.toList());
AssortOrderLogUtil.info("优惠券转换,用于锁券操作 orderbean : accounts", orderBean, accounts);
if (CollectionUtils.isEmpty(couponList)) { if (CollectionUtils.isEmpty(couponList)) {
return null; return null;
} }
// fisherman end
if (couponList.size() > 1) { //fisherman 【01测16灰18全,【华莱士】【疑难专项】一个订单多张优惠券使用场景】 https://www.tapd.cn/43862731/prong/stories/view/1143862731001037477
// 找出 配送券 return this.commonMethodVerificationNew(couponList,orderBean,openId);
CreateOrderAccountRequest freightCouponAccountBean = couponList.stream().filter(account -> account.getAccountType().equals(QueryOrderAccountType.FREIGHT_COUPON)).findFirst().orElse(null);
TransactionVO couponCodeVerificationTransDto = null; // // fisherman end
if (!Objects.isNull(freightCouponAccountBean)) { // if (couponList.size() > 1) {
couponCodeVerificationTransDto = new TransactionVO(); // // 找出 配送券
couponCodeVerificationTransDto.setCode(freightCouponAccountBean.getAccountId()); // CreateOrderAccountRequest freightCouponAccountBean = couponList.stream().filter(account -> account.getAccountType().equals(QueryOrderAccountType.FREIGHT_COUPON)).findFirst().orElse(null);
couponCodeVerificationTransDto.setTotalAmount(freightCouponAccountBean.getPrice()); // TransactionVO couponCodeVerificationTransDto = null;
} // if (!Objects.isNull(freightCouponAccountBean)) {
// 过滤出 配送券 // couponCodeVerificationTransDto = new TransactionVO();
List<CreateOrderAccountRequest> collect = couponList.stream().filter(account -> !account.getAccountType().equals(QueryOrderAccountType.FREIGHT_COUPON)).collect(Collectors.toList()); // couponCodeVerificationTransDto.setCode(freightCouponAccountBean.getAccountId());
return commonMethodVerification(couponCodeVerificationTransDto, collect, orderBean, openId); // couponCodeVerificationTransDto.setTotalAmount(freightCouponAccountBean.getPrice());
} else { // }
return commonMethodVerification(null, couponList, orderBean, openId); // // 过滤出 配送券
} // List<CreateOrderAccountRequest> collect = couponList.stream().filter(account -> !account.getAccountType().equals(QueryOrderAccountType.FREIGHT_COUPON)).collect(Collectors.toList());
// return commonMethodVerification(couponCodeVerificationTransDto, collect, orderBean, openId);
// } else {
// return commonMethodVerification(null, couponList, orderBean, openId);
// }
} }
private CouponRequest commonMethodVerification(TransactionVO freightCouponAccountBean, private CouponRequest commonMethodVerification(TransactionVO freightCouponAccountBean,
...@@ -3889,8 +3892,7 @@ public class OrderSdkAdapter { ...@@ -3889,8 +3892,7 @@ public class OrderSdkAdapter {
return couponRequest; return couponRequest;
} }
private CouponRequest commonMethodVerificationNew(TransactionVO freightCouponAccountBean, private CouponRequest commonMethodVerificationNew(List<CreateOrderAccountRequest> collect,
List<CreateOrderAccountRequest> collect,
OrderBeanV1 orderBean, OrderBeanV1 orderBean,
String openId) { String openId) {
CouponRequest couponRequest = new CouponRequest(); CouponRequest couponRequest = new CouponRequest();
...@@ -3910,14 +3912,13 @@ public class OrderSdkAdapter { ...@@ -3910,14 +3912,13 @@ public class OrderSdkAdapter {
// 订单号 替换成唯一序号 // 订单号 替换成唯一序号
couponRequest.setTrans_id(orderBean.getOid()); couponRequest.setTrans_id(orderBean.getOid());
couponRequest.setBusiness_date(DateUtil.convert2String(new Date(), DateUtil.FORMAT_yyyyMMdd)); couponRequest.setBusiness_date(DateUtil.convert2String(new Date(), DateUtil.FORMAT_yyyyMMdd));
List<TransactionVO> transactions = this.getTransactionList(freightCouponAccountBean, collect, orderBean, openId); List<TransactionVO> transactions = this.getTransactionList( collect, orderBean, openId);
// 配送券逻辑 end // 配送券逻辑 end
couponRequest.setTransactions(transactions); couponRequest.setTransactions(transactions);
return couponRequest; return couponRequest;
} }
private List<TransactionVO> getTransactionList(TransactionVO freightCouponAccountBean, private List<TransactionVO> getTransactionList(List<CreateOrderAccountRequest> collect,
List<CreateOrderAccountRequest> collect,
OrderBeanV1 orderBean, OrderBeanV1 orderBean,
String openId) { String openId) {
List<TransactionVO> transactions = new ArrayList<>(); List<TransactionVO> transactions = new ArrayList<>();
...@@ -3955,10 +3956,6 @@ public class OrderSdkAdapter { ...@@ -3955,10 +3956,6 @@ public class OrderSdkAdapter {
} }
transactions.add(couponCodeVerificationTransDto); transactions.add(couponCodeVerificationTransDto);
}); });
// 配送券逻辑加入
if (freightCouponAccountBean != null) {
transactions.add(freightCouponAccountBean);
}
return transactions; return transactions;
} }
......
...@@ -32,8 +32,10 @@ import cn.freemud.management.entities.dto.request.order.MCCafeProductRedeemVo; ...@@ -32,8 +32,10 @@ import cn.freemud.management.entities.dto.request.order.MCCafeProductRedeemVo;
import cn.freemud.management.entities.dto.request.order.MCCafeTransactionVo; import cn.freemud.management.entities.dto.request.order.MCCafeTransactionVo;
import cn.freemud.management.entities.dto.response.coupon.McdNetBatchQueryResponse; import cn.freemud.management.entities.dto.response.coupon.McdNetBatchQueryResponse;
import cn.freemud.management.entities.dto.response.coupon.McdNetCouponProductRespDto; import cn.freemud.management.entities.dto.response.coupon.McdNetCouponProductRespDto;
import cn.freemud.management.enums.OrderSource;
import cn.freemud.service.mccafe.CouponClientService; import cn.freemud.service.mccafe.CouponClientService;
import cn.freemud.utils.BeanUtil; import cn.freemud.utils.BeanUtil;
import cn.freemud.utils.PropertyConvertUtil;
import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSON;
import com.freemud.application.sdk.api.ordercenter.entities.v1.AccountBeanV1; import com.freemud.application.sdk.api.ordercenter.entities.v1.AccountBeanV1;
import com.freemud.application.sdk.api.ordercenter.entities.v1.OrderBeanV1; import com.freemud.application.sdk.api.ordercenter.entities.v1.OrderBeanV1;
...@@ -787,4 +789,91 @@ public class CouponAdapter { ...@@ -787,4 +789,91 @@ public class CouponAdapter {
return mcCafeCouponLockRequest; return mcCafeCouponLockRequest;
} }
/**
* 新版本 支持多券 批量核销操作
* @param orderBean
* @param couponReqType
* @return
*/
public CouponCodeVerificationDto convert2CouponCodeVerificationDto(OrderBeanV1 orderBean, CouponReqType couponReqType) {
CouponCodeVerificationDto couponCodeVerificationDto = new CouponCodeVerificationDto();
couponCodeVerificationDto.setVer(Integer.valueOf(Version.VERSION_1));
couponCodeVerificationDto.setReqtype(couponReqType.getCode());
couponCodeVerificationDto.setPartnerId(orderBean.getCompanyId());
Integer orderType = orderBean.getType();
//商城单子用NewOrderType
if (Objects.equals(OrderSource.MALL.getSource(), orderBean.getSource())) {
orderType = orderBean.getNewOrderType();
}
ActivityChannelEnum activityChannelEnum = PropertyConvertUtil.orderTypeEnumConvert2ActivityChannel(orderType);
if (activityChannelEnum == null) {
activityChannelEnum = ActivityChannelEnum.pickup;
}
couponCodeVerificationDto.setChannel(activityChannelEnum.getCode());
couponCodeVerificationDto.setStation_id("-1");
couponCodeVerificationDto.setOperator_id("-1");
couponCodeVerificationDto.setStore_id(orderBean.getShopId());
couponCodeVerificationDto.setMemberId(orderBean.getUserId());
// 订单号 替换成唯一序号
couponCodeVerificationDto.setTrans_id(orderBean.getOid());
couponCodeVerificationDto.setBusiness_date(DateUtil.convert2Str(new Date(), DateUtil.FORMAT_yyyyMMdd));
List<CouponCodeVerificationTransDto> transactions = this.getTransactions(orderBean, couponCodeVerificationDto);
couponCodeVerificationDto.setTransactions(transactions);
return couponCodeVerificationDto;
}
/**
* 组装核销 参数
* @param orderBean
* @return
*/
private List<CouponCodeVerificationTransDto> getTransactions(OrderBeanV1 orderBean, CouponCodeVerificationDto couponCodeVerificationDto) {
List<AccountBeanV1> accountList = orderBean.getAccountList();
List<CouponCodeVerificationTransDto> transactions = new ArrayList<>();
long price = 0L;
for (AccountBeanV1 accountBean : accountList) {
if (OrderAccountType.verificationCoupon.contains(accountBean.getType())) {
List<CouponCodeVerificationProductDto> products = new ArrayList<>();
if (OrderAccountType.PRODUCT_COUPON.getCode().equals(accountBean.getType())) {
for (int i = 0; i < orderBean.getProductList().size(); i++) {
ProductBeanV1 productBean = orderBean.getProductList().get(i);
String pid = StringUtils.isNotBlank(productBean.getSpecification()) ? productBean.getSpecification() : productBean.getProductId();
if (!org.springframework.util.CollectionUtils.isEmpty(orderBean.getProductList().get(i).getDiscountList())) {
List<ProductDiscountV1> discounts = orderBean.getProductList().get(i).getDiscountList().stream().
filter(productDiscount -> productDiscount.getDiscountId().equals(accountBean.getAccountId())).collect(Collectors.toList());
for (ProductDiscountV1 productDiscount : discounts) {
if (productDiscount.getDiscountType() == null || productDiscount.getDiscountType() == 0) {
continue;
}
CouponCodeVerificationProductDto couponCodeVerificationProductDto = new CouponCodeVerificationProductDto();
couponCodeVerificationProductDto.setPID(pid);
couponCodeVerificationProductDto.setConsume_num(productDiscount.getDiscountQty());
couponCodeVerificationProductDto.setSeq(i + 1);
couponCodeVerificationProductDto.setRedeem_price(new BigDecimal(productBean.getPrice()));
products.add(couponCodeVerificationProductDto);
}
}
}
}
CouponCodeVerificationTransDto couponCodeVerificationTransDto = new CouponCodeVerificationTransDto();
if (!products.isEmpty()) {
couponCodeVerificationTransDto.setProducts(products);
}
couponCodeVerificationTransDto.setCode(accountBean.getAccountId());
Long discountPriceL = accountBean.getPrice();
if (discountPriceL != null) {
int abs = Math.abs(discountPriceL.intValue());
couponCodeVerificationTransDto.setTotalAmount(abs);
price += abs;
}
transactions.add(couponCodeVerificationTransDto);
}
}
// KA 【ID1032412】【订单聚合层】核销传入优惠金额之传劵优惠只设置券的优惠金额进行上报
couponCodeVerificationDto.setOrderDiscountAmount(price);
return transactions;
}
} }
...@@ -13,6 +13,7 @@ ...@@ -13,6 +13,7 @@
package cn.freemud.service.coupon.impl; package cn.freemud.service.coupon.impl;
import cn.freemud.adapter.CouponAdapter; import cn.freemud.adapter.CouponAdapter;
import cn.freemud.amp.body.OrderBody;
import cn.freemud.amqp.Header; import cn.freemud.amqp.Header;
import cn.freemud.amqp.MQAction; import cn.freemud.amqp.MQAction;
import cn.freemud.amqp.MQMessage; import cn.freemud.amqp.MQMessage;
...@@ -80,28 +81,30 @@ public class PlatformCouponRelationServiceImpl implements CouponRelationService ...@@ -80,28 +81,30 @@ public class PlatformCouponRelationServiceImpl implements CouponRelationService
@Override @Override
public BaseResponse verificationCoupon(List<AccountBeanV1> accountList, OrderBeanV1 orderBean, CouponReqType couponReqType) { public BaseResponse verificationCoupon(List<AccountBeanV1> accountList, OrderBeanV1 orderBean, CouponReqType couponReqType) {
// AppLogUtil.infoLog("fiserhman 券码核销 begin", JSON.toJSONString(accountList), JSON.toJSONString(orderBean));
if (CollectionUtils.isEmpty(accountList)) { if (CollectionUtils.isEmpty(accountList)) {
return ResponseUtil.success(); return ResponseUtil.success();
} }
// 需要判断 accountList 里面 是都 同时包含 配送券+ other券 // fisherman 【01测16灰18全,【华莱士】【疑难专项】一个订单多张优惠券使用场景】 https://www.tapd.cn/43862731/prong/stories/view/1143862731001037477
boolean isDoubleCoupon = checkAccountList(accountList); BaseResponse baseResponse = this.batchCouponHandle(orderBean, couponReqType);
if (isDoubleCoupon) { return baseResponse;
Integer code = OrderAccountType.FREIGHT_COUPON.getCode(); // // 需要判断 accountList 里面 是都 同时包含 配送券+ other券
// 运费券 塞进 核销接口里面, 这里真的是贼恶心 逻辑不敢动 // boolean isDoubleCoupon = checkAccountList(accountList);
AccountBeanV1 freightCouponAccountBean = accountList.stream().filter(accountBean -> code.equals(accountBean.getType())).findFirst().orElse(null); // if (isDoubleCoupon) {
CouponCodeVerificationTransDto couponCodeVerificationTransDto = null; // Integer code = OrderAccountType.FREIGHT_COUPON.getCode();
if (!Objects.isNull(freightCouponAccountBean)) { // // 运费券 塞进 核销接口里面, 这里真的是贼恶心 逻辑不敢动
couponCodeVerificationTransDto = new CouponCodeVerificationTransDto(); // AccountBeanV1 freightCouponAccountBean = accountList.stream().filter(accountBean -> code.equals(accountBean.getType())).findFirst().orElse(null);
couponCodeVerificationTransDto.setCode(freightCouponAccountBean.getAccountId()); // CouponCodeVerificationTransDto couponCodeVerificationTransDto = null;
couponCodeVerificationTransDto.setTotalAmount(freightCouponAccountBean.getPrice().intValue()); // if (!Objects.isNull(freightCouponAccountBean)) {
} // couponCodeVerificationTransDto = new CouponCodeVerificationTransDto();
// 过滤出配送券 // couponCodeVerificationTransDto.setCode(freightCouponAccountBean.getAccountId());
List<AccountBeanV1> collect = accountList.stream().filter(accountBean -> !code.equals(accountBean.getType())).collect(Collectors.toList()); // couponCodeVerificationTransDto.setTotalAmount(freightCouponAccountBean.getPrice().intValue());
return commonMethodVerification(couponCodeVerificationTransDto, collect, orderBean, couponReqType); // }
} else { // // 过滤出配送券
return commonMethodVerification(null, accountList, orderBean, couponReqType); // List<AccountBeanV1> collect = accountList.stream().filter(accountBean -> !code.equals(accountBean.getType())).collect(Collectors.toList());
} // return commonMethodVerification(couponCodeVerificationTransDto, collect, orderBean, couponReqType);
// } else {
// return commonMethodVerification(null, accountList, orderBean, couponReqType);
// }
} }
/** /**
...@@ -231,6 +234,47 @@ public class PlatformCouponRelationServiceImpl implements CouponRelationService ...@@ -231,6 +234,47 @@ public class PlatformCouponRelationServiceImpl implements CouponRelationService
return ResponseUtil.success(); return ResponseUtil.success();
} }
/**
* 单笔订单 多券核销
* @param orderBean
* @param couponReqType
* @return
*/
private BaseResponse batchCouponHandle(OrderBeanV1 orderBean, CouponReqType couponReqType) {
CouponCodeVerificationDto couponCodeVerificationDto = couponAdapter.convert2CouponCodeVerificationDto(orderBean, couponReqType);
if (Objects.isNull(couponCodeVerificationDto) || couponCodeVerificationDto.getTransactions().isEmpty()) {
return ResponseUtil.success();
}
couponCodeVerificationDto.setOrderTotalAmount(orderBean.getOriginalAmount() == null ? 0L : orderBean.getOriginalAmount().longValue());
couponCodeVerificationDto.setOrderPaymentAmount(orderBean.getAmount());
// 核销券新增参数:组织机构ID
couponCodeVerificationDto.setChannel_ids(storeService.getOrgIdsArr(orderBean.getCompanyId(), orderBean.getShopId()));
boolean ok = false;
Exception lastException = null;
CouponCodeResponseDto couponCodeResponseDto = null;
try {
couponCodeResponseDto = couponOfflineClient.verification(couponCodeVerificationDto);
ThirdPartyLog.infoConvertJson(System.currentTimeMillis(), System.currentTimeMillis(), "/api", couponCodeVerificationDto, couponCodeResponseDto);
if (Objects.nonNull(couponCodeResponseDto) && Objects.equals(couponCodeResponseDto.getStatusCode(), ResponseResult.SUCCESS.getCode())) {
ok = true;
}
} catch (Exception ex) {
lastException = ex;
ErrorLog.printErrorLog("verification_error", "/api", couponCodeVerificationDto, ex);
}
if (lastException != null) {
sendMessage(orderBean, LogThreadLocal.getTrackingNo(), couponCodeVerificationDto, lastException);
} else if (!ok || Objects.equals(baffleOpen, true)) {
sendMessage(orderBean, LogThreadLocal.getTrackingNo(), couponCodeVerificationDto, ok ? "模拟券核销失败" : couponCodeResponseDto);
}
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);
}
return ResponseUtil.success();
}
/** /**
* 发送消息 * 发送消息
......
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