Commit 6fc3b5fc by yu.sun

Merge branch 'feature/20201228_可用券信息查询NPE修复_yu.sun' into develop

# Conflicts:
#	assortment-ordercenter-sdk/pom.xml
#	assortment-ordercenter-sdk/readme.md
#	assortment-ordercenter-sdk/src/main/java/com/freemud/sdk/api/assortment/order/adapter/OrderSdkAdapter.java
#	assortment-ordercenter-sdk/src/main/java/com/freemud/sdk/api/assortment/order/enums/QueryOrderAccountType.java
#	order-application-service/pom.xml
#	order-application-service/src/main/java/cn/freemud/adapter/OrderAdapter.java
#	order-application-service/src/main/java/cn/freemud/enums/OrderAccountType.java
parents 8805e6b5 48edeb2d
......@@ -1407,6 +1407,9 @@ public class OrderSdkAdapter {
case "BUY3_SEND1":
type=35;
break;
case "COCO_PRODUCT_CASH_COUPON":
type=36;
break;
default:
break;
}
......@@ -2017,6 +2020,8 @@ public class OrderSdkAdapter {
case 99:
newOrderAccountType=OldOrderAccountType.FREIGHT_COUPON.getCode();
break;
case 36:
newOrderAccountType=OldOrderAccountType.COCO_PRODUCT_CASH_COUPON.getCode();
default:
break;
}
......
......@@ -45,7 +45,8 @@ public enum OldOrderAccountType {
PRICE_DEDUCTION_COUPON(103, "抵价券", "PRICE_DEDUCTION_COUPON"),
TOTAL_DISCOUNT(205, "优惠总金额", "TOTAL_DISCOUNT"),
GATHER_SPOT(221, "集点活动","GATHER_SPOT"),
MEMBER_PRICE_DISCOUNT(220, "会员价优惠", "MEMBER_PRICE_DISCOUNT");
MEMBER_PRICE_DISCOUNT(220, "会员价优惠", "MEMBER_PRICE_DISCOUNT"),
COCO_PRODUCT_CASH_COUPON(36, "coco商品代金券","COCO_PRODUCT_CASH_COUPON");
private Integer code;
private String desc;
......
......@@ -45,6 +45,7 @@ public enum QueryOrderAccountType {
WITH_ORDER_BUY3_SEND1_FEE("WITH_ORDER_BUY3_SEND1_FEE", "随单购买3赠1券"),
WITH_ORDER_BUY_COUPON_FEE("WITH_ORDER_BUY_COUPON_FEE", "随单购月卡"),
MCCAFE_MONTH_CARD("MCCAFE_MONTH_CARD","麦咖啡月卡"),
COCO_PRODUCT_CASH_COUPON("COCO_PRODUCT_CASH_COUPON", "coco商品代金券"),
;
private String code;
......
......@@ -87,8 +87,8 @@
<!-- 商户门店sdk -->
<dependency>
<groupId>com.freemud.application.service.sdk</groupId>
<artifactId>storecenter-sdk</artifactId>
<version>3.3.5-SNAPSHOT</version>
<artifactId>storecenter-sdk</artifactId>
</dependency>
<dependency>
<groupId>cn.freemud</groupId>
......
......@@ -1990,16 +1990,28 @@ public class OrderAdapter {
}
if (ObjectUtils.equals(ProductTypeEnum.MATERIAL_PRODUCT.getCode(), productBean.getProductType())) {
List<ProductVo> setMaterialProducts = new ArrayList<>();
if(mcCafePartnerId.equals(partnerId)) {
productBean.getMaterialProduct().forEach(product -> {
ProductVo material = convent2ProductVo(product);
setMaterialProducts.add(material);
material.setOriginalTotalAmount(new BigDecimal(material.getOriginalPrice()).multiply(new BigDecimal(productVo.getQty())).longValue());
material.setSaleTotalAmount(new BigDecimal(material.getFinalPrice()).multiply(new BigDecimal(productVo.getQty())).longValue());
setMaterialProducts.add(material);
productVo.setOriginalPrice(new BigDecimal(productVo.getOriginalPrice()).add(new BigDecimal(material.getOriginalPrice())).longValue());
productVo.setFinalPrice(new BigDecimal(productVo.getFinalPrice()).add(new BigDecimal(material.getFinalPrice())).longValue());
productVo.setOriginalTotalAmount(new BigDecimal(productVo.getOriginalTotalAmount()).add(new BigDecimal(material.getOriginalTotalAmount())).longValue());
productVo.setSaleTotalAmount(new BigDecimal(productVo.getSaleTotalAmount()).add(new BigDecimal(material.getSaleTotalAmount())).longValue());
});
}
else {
productBean.getMaterialProduct().forEach(product -> {
ProductVo material = convent2ProductVo(product);
setMaterialProducts.add(material);
productVo.setOriginalPrice(new BigDecimal(productVo.getOriginalPrice()).subtract(new BigDecimal(material.getOriginalPrice())).longValue());
productVo.setFinalPrice(new BigDecimal(productVo.getFinalPrice()).subtract(new BigDecimal(material.getFinalPrice())).longValue());
productVo.setOriginalTotalAmount(new BigDecimal(productVo.getOriginalTotalAmount()).subtract(new BigDecimal(material.getOriginalTotalAmount())).longValue());
productVo.setSaleTotalAmount(new BigDecimal(productVo.getSaleTotalAmount()).subtract(new BigDecimal(product.getSettlementPrice())).longValue());
});
}
productVo.setSetMaterialProducts(setMaterialProducts);
}
productVos.add(productVo);
......@@ -2161,6 +2173,22 @@ public class OrderAdapter {
return orderPayRefundRequest;
}
public MultiOrderRefundRequest getMultiOrderPayRefundRequest(QueryOrdersResponseDto.DataBean.OrderBean orderBean, Long refundId) {
MultiOrderRefundRequest multiQueryRequest = new MultiOrderRefundRequest();
multiQueryRequest.setStationId("1");
multiQueryRequest.setPartnerId(orderBean.getCompanyId());
multiQueryRequest.setStoreId(orderBean.getShopId());
multiQueryRequest.setFmId("");
multiQueryRequest.setRefundAmount(orderBean.getAmount());
multiQueryRequest.setRefundTradeNo(String.valueOf(refundId));
multiQueryRequest.setStoreId(orderBean.getShopId());
multiQueryRequest.setNotifyUrl(refundNotifyCallback);
multiQueryRequest.setVer("V1");
multiQueryRequest.setVer3(false);
multiQueryRequest.setOutOrderNo(orderBean.getOid());
return multiQueryRequest;
}
public CancelOrderRequest convent2CancelOrderRequest(String orderId, String partnerId, AfterSalesType afterSalesType,
String reason, String trackingNo, String refundId) {
CancelOrderRequest cancelOrderRequest = new CancelOrderRequest();
......@@ -2410,7 +2438,7 @@ public class OrderAdapter {
public CreateOrderProductRequest convent2OrderProductDemo(ShoppingCartGoodsDto.CartGoodsDetailDto cartGoodsDetailDto) {
CreateOrderProductRequest createOrderProductDemoDto = new CreateOrderProductRequest();
createOrderProductDemoDto.setProductId(cartGoodsDetailDto.getSpuId());
createOrderProductDemoDto.setProductId(StringUtils.isNotBlank(cartGoodsDetailDto.getSpuId()) ? cartGoodsDetailDto.getSpuId() : cartGoodsDetailDto.getSkuId());
createOrderProductDemoDto.setProductName(cartGoodsDetailDto.getSpuName());
createOrderProductDemoDto.setSpecification(cartGoodsDetailDto.getSkuId());
createOrderProductDemoDto.setSpecificationName(cartGoodsDetailDto.getSkuName());
......@@ -2542,6 +2570,17 @@ public class OrderAdapter {
if (ActivityTypeEnum.TYPE_23.getCode().equals(activityType)){
return OldOrderAccountType.SUPER_PURCHASE;
}
if (ActivityTypeEnum.TYPE_221.getCode().equals(activityType)){
return OldOrderAccountType.GATHER_SPOT;
}
if (ActivityTypeEnum.TYPE_221.getCode().equals(activityType)){
return OldOrderAccountType.GATHER_SPOT;
}
// coco商品代金券
if (ActivityTypeEnum.TYPE_36.getCode().equals(activityType)){
return OldOrderAccountType.COCO_PRODUCT_CASH_COUPON;
}
return OldOrderAccountType.BUYM_SENDN;
}
......
......@@ -55,7 +55,8 @@ public enum ActivityTypeEnum {
TYPE_DELIVERY(901, "配送费"),
TYPE_211(211, "套餐优惠"),
TYPE_221(221, "集点活动"),
TYPE_320(320, "会员价优惠");
TYPE_320(320, "会员价优惠"),
TYPE_36(36, "coco商品代金券");
private Integer code;
......
......@@ -28,7 +28,7 @@ public enum OrderAccountType {
CARD_ORIGINAL_AMOUNT(25, "会员卡原价"),
CARD_DISCOUNT_AMOUNT(26, "会员卡优惠金额"),
BUY3_SEND1(35, "买三赠1券"),
;
COCO_PRODUCT_CASH_COUPON(36, "coco商品代金券");
private Integer code;
private String desc;
......
......@@ -35,6 +35,7 @@ import com.freemud.application.sdk.api.ordercenter.response.orderInfo.OrderSettl
import com.freemud.application.sdk.api.service.EmailAlertService;
import com.freemud.sdk.api.assortment.order.adapter.OrderSdkAdapter;
import com.google.common.base.Throwables;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
......@@ -47,6 +48,7 @@ import java.util.function.Function;
import java.util.stream.Collectors;
@Service("cocoCouponRelationService")
@Slf4j
public class CocoCouponRelationServiceImpl implements CouponRelationService {
@Autowired
......@@ -81,8 +83,16 @@ public class CocoCouponRelationServiceImpl implements CouponRelationService {
}
// 根据商品id转map
Map<String,QueryOrdersResponseDto.DataBean.OrderBean.ProductBean> productMap = productList.stream().collect(Collectors.
toMap(QueryOrdersResponseDto.DataBean.OrderBean.ProductBean::getProductId, Function.identity(), (oldValue, newValue) -> newValue));
Map<String,QueryOrdersResponseDto.DataBean.OrderBean.ProductBean> productMap = new HashMap<>();
for(QueryOrdersResponseDto.DataBean.OrderBean.ProductBean pb : productList){
productMap.put(pb.getSpecification(),pb);
List<QueryOrdersResponseDto.DataBean.OrderBean.ProductBean> materialProducts = pb.getMaterialProduct();
if(materialProducts != null && !materialProducts.isEmpty()){
for(QueryOrdersResponseDto.DataBean.OrderBean.ProductBean materialProduct : materialProducts){
productMap.put(materialProduct.getSpecification(),materialProduct);
}
}
}
// 根据活动号分组,没有活动号的直接筛选掉
Map<String,List<OrderSettlementResp>> orderSettlementMap = orderSettlementList.stream().filter(os -> StringUtils.isNotEmpty(os.getExternalObjectId()))
......@@ -134,16 +144,19 @@ public class CocoCouponRelationServiceImpl implements CouponRelationService {
// 根据活动号转类型
Integer orderAccountType = orderSdkAdapter.getOldOrderAccountType(settlementType);
// 不是商品券、代金券、折扣券不处理
if(!OrderAccountType.COUPON.getCode().equals(orderAccountType) &&
// 不是商品券、代金券、折扣券、商品代金券不处理
if(!OrderAccountType.COCO_PRODUCT_CASH_COUPON.getCode().equals(orderAccountType) &&
!OrderAccountType.COUPON.getCode().equals(orderAccountType) &&
!OrderAccountType.PRODUCT_COUPON.getCode().equals(orderAccountType) &&
!OrderAccountType.DISCOUNT_COUPON.getCode().equals(orderAccountType)){
continue;
}
if(OrderAccountType.COUPON.getCode().equals(orderAccountType) && Objects.equals(orderSettlementInfo.get(0).getProductId(),0)){
if(OrderAccountType.COUPON.getCode().equals(orderAccountType) && "0".equals(orderSettlementInfo.get(0).getProductId())){
// 整单代金券,最后在计算
orderSettlementRemain.add(orderSettlementInfo.get(0));
continue;
}
CouponCodeVerificationTransDto couponCodeVerificationTransDto = new CouponCodeVerificationTransDto();
......@@ -160,14 +173,17 @@ public class CocoCouponRelationServiceImpl implements CouponRelationService {
}
// 商品code不为0,此时取得是具体的商品
if(!Objects.equals(osr.getProductId(),0)){
if(!"0".equals(osr.getProductId())){
// 计算商品原价
Integer num = osr.getNumber();
String productId = osr.getProductId();
QueryOrdersResponseDto.DataBean.OrderBean.ProductBean pb = productMap.get(productId);
if(pb != null){
oriAmount = oriAmount + (pb.getPrice() == null ? 0 : pb.getPrice().intValue()) * (num == null ? 0 : num);
if(pb == null){
continue;
}
oriAmount = oriAmount + (pb.getPrice() == null ? 0 : pb.getPrice().intValue()) * (num == null ? 0 : num);
orderSettlementAlready.add(osr);
// 统计商品
CouponCodeVerificationProductDto couponCodeVerificationProductDto = new CouponCodeVerificationProductDto();
......@@ -186,10 +202,6 @@ public class CocoCouponRelationServiceImpl implements CouponRelationService {
}
couponCodeVerificationTransDto.setProducts(products);
//处理第三方外卖单优惠金额信息
if(totalAmount != null && totalAmount.intValue() > 0){
totalAmount = 0 - Math.abs(totalAmount);
}
// 总优惠金额单位:分
couponCodeVerificationTransDto.setTotalAmount(totalAmount);
......@@ -215,40 +227,26 @@ public class CocoCouponRelationServiceImpl implements CouponRelationService {
// 券号
couponCodeVerificationTransFull.setCode(osr.getExternalObjectId());
// 总优惠金额单位:分
couponCodeVerificationTransFull.setTotalAmount(osr.getSettlementAmount().intValue());
couponCodeVerificationTransFull.setTotalAmount(0 - osr.getSettlementAmount().intValue());
// 订单号
couponCodeVerificationTransFull.setOrderNumber(orderBean.getOid());
List<CouponCodeVerificationProductDto> productsFull = new ArrayList<>();
Integer totalAmountFull = 0;
Integer totalAmountOriFull = 0;
for(QueryOrdersResponseDto.DataBean.OrderBean.ProductBean pb : productList){
Long alreadyNum = collect.get(osr.getProductId()) == null ? 0L : collect.get(osr.getProductId()).getSum();
Integer num = pb.getNumber();
Integer remainNum = num - alreadyNum.intValue();
if(Objects.equals(remainNum,0)){
continue;
totalAmountOriFull = buidVerificationProduct(collect,osr,pb,productsFull,totalAmountOriFull);
// 小料商品也取出来
List<QueryOrdersResponseDto.DataBean.OrderBean.ProductBean> materialProducts = pb.getMaterialProduct();
if(materialProducts != null && !materialProducts.isEmpty()){
for(QueryOrdersResponseDto.DataBean.OrderBean.ProductBean materialProduct : materialProducts){
totalAmountOriFull = buidVerificationProduct(collect,osr,materialProduct,productsFull,totalAmountOriFull);
}
}
// 统计商品
CouponCodeVerificationProductDto couponCodeVerificationProductFull = new CouponCodeVerificationProductDto();
couponCodeVerificationProductFull.setConsume_num(remainNum);
couponCodeVerificationProductFull.setPID(osr.getProductId());
couponCodeVerificationProductFull.setSeq(osr.getProductSeq());
couponCodeVerificationProductFull.setProductName(pb.getProductName());
Integer price = pb.getPrice() == null ? 0 : pb.getPrice().intValue();
couponCodeVerificationProductFull.setInitPrice(price);
couponCodeVerificationProductFull.setNowPrice(price);
couponCodeVerificationProductFull.setPayMoney(price);
productsFull.add(couponCodeVerificationProductFull);
totalAmountFull = totalAmountFull + price * remainNum;
}
couponCodeVerificationTransFull.setProducts(productsFull);
couponCodeVerificationTransFull.setAmountPaid(totalAmountFull);
couponCodeVerificationTransFull.setAmountRec(totalAmountFull);
couponCodeVerificationTransFull.setAmountPaid(totalAmountOriFull);
couponCodeVerificationTransFull.setAmountRec(totalAmountOriFull);
transactions.add(couponCodeVerificationTransFull);
}
......@@ -257,21 +255,27 @@ public class CocoCouponRelationServiceImpl implements CouponRelationService {
couponCodeVerificationDto.setTransactions(transactions);
try {
for(CouponCodeVerificationTransDto transaction : transactions){
List<CouponCodeVerificationTransDto> transactionsNew = new ArrayList<>();
transactionsNew.add(transaction);
couponCodeVerificationDto.setTransactions(transactionsNew);
//71.券核销
for (int i = 2; i >= 0; i--) {
LogUtil.info("coco核销券码开始==", JSON.toJSONString(couponCodeVerificationDto), null);
CouponCodeResponseDto couponCodeResponseDto = couponOfflineClient.verification(couponCodeVerificationDto);
LogUtil.info("coco核销券码返回==", JSON.toJSONString(couponCodeVerificationDto), null);
ThirdPartyLog.infoConvertJson(System.currentTimeMillis(), System.currentTimeMillis(), "/api", couponCodeVerificationDto, couponCodeResponseDto);
if (Objects.equals(couponCodeResponseDto.getStatusCode(), ResponseResult.SUCCESS.getCode())) {
LogUtil.info("coco CocoCouponRelationServiceImpl", JSON.toJSONString(couponCodeVerificationDto), JSON.toJSONString(couponCodeResponseDto));
log.info("coco 核销券码返回成功,couponCodeVerificationDto:{},couponCodeResponseDto:{},", JSON.toJSONString(couponCodeVerificationDto), JSON.toJSONString(couponCodeResponseDto));
break;
}
if (!Objects.equals(couponCodeResponseDto.getStatusCode(), ResponseResult.SUCCESS.getCode())) {
emailAlertService.sendEmailAlert("cooc核销券码失败", String.format("request:%s \r\nresponse:%s", JSONObject.toJSONString(couponCodeVerificationDto), JSONObject.toJSONString(couponCodeResponseDto)));
log.info("coco 核销券码返回失败,couponCodeVerificationDto:{},couponCodeResponseDto:{},", JSON.toJSONString(couponCodeVerificationDto), JSON.toJSONString(couponCodeResponseDto));
return ResponseUtil.error(ResponseResult.COUPON_VERIFICATION_FAIL);
}
}
}
} catch (Exception ex) {
emailAlertService.sendEmailAlert("coco核销券码异常", String.format("request:%s \r\nexception:%s", JSONObject.toJSONString(couponCodeVerificationDto), Throwables.getStackTraceAsString(ex)));
......@@ -279,7 +283,49 @@ public class CocoCouponRelationServiceImpl implements CouponRelationService {
return ResponseUtil.error(ResponseResult.COUPON_VERIFICATION_FAIL);
}
return ResponseUtil.success();
}
/**
* 构建整单券的商品
* @param collect
* @param osr
* @param pb
* @param productsFull
* @param totalAmountOriFull
* @return
*/
public Integer buidVerificationProduct(Map<String, IntSummaryStatistics> collect,
OrderSettlementResp osr,
QueryOrdersResponseDto.DataBean.OrderBean.ProductBean pb,
List<CouponCodeVerificationProductDto> productsFull,
Integer totalAmountOriFull){
Long alreadyNum = collect.get(pb.getSpecification()) == null ? 0L : collect.get(pb.getSpecification()).getSum();
Integer num = pb.getNumber();
Integer remainNum = num - alreadyNum.intValue();
if(Objects.equals(remainNum,0)){
return totalAmountOriFull;
}
// 统计商品
Integer price = pb.getPrice() == null ? 0 : pb.getPrice().intValue();
if(price.intValue() == 0){
return totalAmountOriFull;
}
CouponCodeVerificationProductDto couponCodeVerificationProductFull = new CouponCodeVerificationProductDto();
couponCodeVerificationProductFull.setConsume_num(remainNum);
couponCodeVerificationProductFull.setPID(pb.getProductId());
couponCodeVerificationProductFull.setSeq(pb.getSequence());
couponCodeVerificationProductFull.setProductName(pb.getProductName());
couponCodeVerificationProductFull.setInitPrice(price);
couponCodeVerificationProductFull.setNowPrice(price);
couponCodeVerificationProductFull.setPayMoney(price);
productsFull.add(couponCodeVerificationProductFull);
totalAmountOriFull = totalAmountOriFull + price * remainNum;
return totalAmountOriFull;
}
}
......@@ -474,6 +474,7 @@ public class CouponDiscountCalculation {
private Long createProductRequest(List<CartGoods> cartGoods, List<CouponProductVo> productList) {
Long totalAmount = 0L;
try {
for (CartGoods cartGood : cartGoods) {
// 剔除商品券得商品
if (StringUtils.isEmpty(cartGood.getSkuId()) && StringUtils.isEmpty(cartGood.getSpuId())) {
......@@ -501,6 +502,9 @@ public class CouponDiscountCalculation {
productList.add(product);
totalAmount = totalAmount +product.getAmount() * cartGood.getQty();
}
} catch (NumberFormatException e) {
throw new ServiceException(ResponseResult.SYSTEM_ERROR);
}
return totalAmount;
}
......
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