Commit 3ca4d962 by 刘鹏飞

Merge remote-tracking branch 'origin/feature/coco_new-刘鹏飞' into develop

parents 2f5633d7 8e410187
...@@ -1951,7 +1951,7 @@ public class OrderSdkAdapter { ...@@ -1951,7 +1951,7 @@ public class OrderSdkAdapter {
* *
* @return * @return
*/ */
private Integer getOldOrderAccountType(int newOrderAccountType) { public Integer getOldOrderAccountType(int newOrderAccountType) {
// 新订单服务枚举 OrderSettlementType // 新订单服务枚举 OrderSettlementType
switch (newOrderAccountType) { switch (newOrderAccountType) {
case 1: case 1:
......
...@@ -17,12 +17,35 @@ import lombok.Data; ...@@ -17,12 +17,35 @@ import lombok.Data;
*/ */
@Data @Data
public class CouponCodeBaseDto { public class CouponCodeBaseDto {
/**
* 版本号
*/
private Integer ver; private Integer ver;
// 71代表核销
/**
* 操作类型:71核销,0查询,3冲正
*/
private Integer reqtype; private Integer reqtype;
/**
* 商户号
*/
private String partnerId; private String partnerId;
/**
* 门店号
*/
private String store_id; private String store_id;
/**
* 线下pos编号, 除coco外,其他商户必填
*/
private String station_id; private String station_id;
/**
* 操作员编号,除coco外,其他商户必填
*/
private String operator_id; private String operator_id;
// 组织机构ID,(String 类型的集合) // 组织机构ID,(String 类型的集合)
......
...@@ -18,11 +18,30 @@ import java.util.List; ...@@ -18,11 +18,30 @@ import java.util.List;
*/ */
@Data @Data
public class CouponCodeVerificationDto extends CouponCodeBaseDto { public class CouponCodeVerificationDto extends CouponCodeBaseDto {
/**
* 流水号
*/
private String trans_id; private String trans_id;
/**
* 核销时间:yyyy-MM-dd
*/
private String business_date; private String business_date;
/**
* 渠道,例如:pickup,delivery
*/
private String channel; private String channel;
/**
* 会员编号
*/
private String memberId; private String memberId;
/**
* 核销交易信息
*/
private List<CouponCodeVerificationTransDto> transactions; private List<CouponCodeVerificationTransDto> transactions;
} }
...@@ -2,6 +2,8 @@ package cn.freemud.entities.dto; ...@@ -2,6 +2,8 @@ package cn.freemud.entities.dto;
import lombok.Data; import lombok.Data;
import java.math.BigDecimal;
/** /**
* All rights Reserved, Designed By www.freemud.cn * All rights Reserved, Designed By www.freemud.cn
* *
...@@ -16,8 +18,44 @@ import lombok.Data; ...@@ -16,8 +18,44 @@ import lombok.Data;
*/ */
@Data @Data
public class CouponCodeVerificationProductDto { public class CouponCodeVerificationProductDto {
private Integer seq ;
private String pID; /**
* 核销数量
*/
private Integer consume_num ; private Integer consume_num ;
/**
* 商品编号
*/
private String pID;
/**
* BigDecimal, 暂未使用
*/
private BigDecimal redeem_price;
/**
* 商品序号或者行数
*/
private Integer seq ;
/**
* 商品名称
*/
private String productName ;
/**
* 线下原价,单位:分
*/
private Integer initPrice ;
/**
* 优惠后价格,单位:分
*/
private Integer nowPrice ;
/**
* 应收金额,单位:分
*/
private Integer payMoney ;
} }
...@@ -19,8 +19,41 @@ import java.util.List; ...@@ -19,8 +19,41 @@ import java.util.List;
*/ */
@Data @Data
public class CouponCodeVerificationTransDto { public class CouponCodeVerificationTransDto {
/**
* 券号
*/
private String code; private String code;
private String ebcode; //private String ebcode;
private Integer totalAmount;
/**
* 实收金额单位:分
*/
private Integer pay_amount;
/**
* 商品信息
*/
private List<CouponCodeVerificationProductDto> products; private List<CouponCodeVerificationProductDto> products;
/**
* 总优惠金额单位:分
*/
private Integer totalAmount;
/**
* 订单号,coco核销使用
*/
private String orderNumber;
/**
* 应收金额,单位:分,coco核销使用
*/
private Integer amountRec;
/**
* 实收金额,单位:分
*/
private Integer amountPaid;
} }
...@@ -13,6 +13,7 @@ ...@@ -13,6 +13,7 @@
package cn.freemud.entities.dto; package cn.freemud.entities.dto;
import com.freemud.application.sdk.api.ordercenter.response.orderInfo.OrderCostResp; import com.freemud.application.sdk.api.ordercenter.response.orderInfo.OrderCostResp;
import com.freemud.application.sdk.api.ordercenter.response.orderInfo.OrderSettlementResp;
import com.freemud.sdk.api.assortment.order.response.order.QueryOrdersResponse; import com.freemud.sdk.api.assortment.order.response.order.QueryOrdersResponse;
import lombok.Data; import lombok.Data;
import lombok.NoArgsConstructor; import lombok.NoArgsConstructor;
...@@ -196,6 +197,8 @@ public class QueryOrdersResponseDto { ...@@ -196,6 +197,8 @@ public class QueryOrdersResponseDto {
private List<ProductBean> productList; private List<ProductBean> productList;
private List<RefundBean> refundList; private List<RefundBean> refundList;
private List<OrderSettlementResp> orderSettlementDetailList;
private AddDeliveryInfo addInfo; private AddDeliveryInfo addInfo;
private List<OrderCostResp> orderCostDetailList; private List<OrderCostResp> orderCostDetailList;
......
/**
* All rights Reserved, Designed By www.freemud.cn
*
* @Title: OrderRelationFactory
* @Description:
* @author: pengfei.liu
* @date: 2020/11/23
* @version V1.0
* @Copyright: 2020 www.freemud.cn Inc. All rights reserved.
* 注意:本内容仅限于上海非码科技内部传阅,禁止外泄以及用于其他的商业目
*/
package cn.freemud.service.coupon;
public interface CouponRelationFactory {
/**
* 获取优惠券核销参数构建实现类
* @param partnerId
* @return
*/
CouponRelationService getVerificationCouponService(String partnerId);
}
/**
* All rights Reserved, Designed By www.freemud.cn
*
* @Title: OrderRelationService
* @Description:
* @author: pengfei.liu
* @date: 2020/11/23
* @version V1.0
* @Copyright: 2020 www.freemud.cn Inc. All rights reserved.
* 注意:本内容仅限于上海非码科技内部传阅,禁止外泄以及用于其他的商业目
*/
package cn.freemud.service.coupon;
import cn.freemud.base.entity.BaseResponse;
import cn.freemud.entities.dto.QueryOrdersResponseDto;
import cn.freemud.entities.vo.CreateOrderVo;
import cn.freemud.entities.vo.QueryOrderResponseVo;
import cn.freemud.enums.CouponReqType;
import com.freemud.application.sdk.api.storecenter.response.StoreResponse;
import com.freemud.sdk.api.assortment.order.response.order.QueryOrderByIdResponse;
import java.util.List;
public interface CouponRelationService {
/**
* 获取优惠券核销参数构建实现类
* @param
*/
BaseResponse verificationCoupon(List<QueryOrdersResponseDto.DataBean.OrderBean.AccountBean> accountList,
QueryOrdersResponseDto.DataBean.OrderBean orderBean,
CouponReqType couponReqType);
}
/**
* All rights Reserved, Designed By www.freemud.cn
*
* @Title: CocoOrderRelationServiceImpl
* @Description:
* @author: pengfei.liu
* @date: 2020/11/23
* @version V1.0
* @Copyright: 2020 www.freemud.cn Inc. All rights reserved.
* 注意:本内容仅限于上海非码科技内部传阅,禁止外泄以及用于其他的商业目
*/
package cn.freemud.service.coupon.impl;
import cn.freemud.adapter.CouponAdapter;
import cn.freemud.base.constant.Version;
import cn.freemud.base.entity.BaseResponse;
import cn.freemud.base.util.DateUtil;
import cn.freemud.entities.dto.*;
import cn.freemud.enums.ActivityChannelEnum;
import cn.freemud.enums.CouponReqType;
import cn.freemud.enums.OrderAccountType;
import cn.freemud.enums.ResponseResult;
import cn.freemud.service.coupon.CouponRelationService;
import cn.freemud.service.impl.StoreServiceImpl;
import cn.freemud.service.thirdparty.CouponOfflineClient;
import cn.freemud.utils.LogUtil;
import cn.freemud.utils.PropertyConvertUtil;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.freemud.application.sdk.api.log.ApiLog;
import com.freemud.application.sdk.api.log.ErrorLog;
import com.freemud.application.sdk.api.log.ThirdPartyLog;
import com.freemud.application.sdk.api.ordercenter.response.orderInfo.OrderSettlementResp;
import com.freemud.application.sdk.api.service.EmailAlertService;
import com.freemud.sdk.api.assortment.order.adapter.OrderSdkAdapter;
import com.google.common.base.Throwables;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import cn.freemud.utils.ResponseUtil;
import java.math.BigDecimal;
import java.util.*;
import java.util.function.Function;
import java.util.stream.Collectors;
@Service("cocoCouponRelationService")
public class CocoCouponRelationServiceImpl implements CouponRelationService {
@Autowired
private CouponAdapter couponAdapter;
@Autowired
private CouponOfflineClient couponOfflineClient;
@Autowired
private EmailAlertService emailAlertService;
@Autowired
private StoreServiceImpl storeService;
@Autowired
private OrderSdkAdapter orderSdkAdapter;
@Override
public BaseResponse verificationCoupon(List<QueryOrdersResponseDto.DataBean.OrderBean.AccountBean> accountList,
QueryOrdersResponseDto.DataBean.OrderBean orderBean,
CouponReqType couponReqType) {
// 订单商品信息
List<QueryOrdersResponseDto.DataBean.OrderBean.ProductBean> productList = orderBean.getProductList();
if(CollectionUtils.isEmpty(orderBean.getProductList())){
ApiLog.info("coco订单没有商品信息不用核销优惠券",orderBean.getOid(),"");
return ResponseUtil.success();
}
// 订单促销信息
List<OrderSettlementResp> orderSettlementList = orderBean.getOrderSettlementDetailList();
if (CollectionUtils.isEmpty(orderSettlementList)) {
ApiLog.info("coco订单没有促销信息不用核销优惠券",orderBean.getOid(),"");
return ResponseUtil.success();
}
// 根据商品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,List<OrderSettlementResp>> orderSettlementMap = orderSettlementList.stream().filter(os -> StringUtils.isNotEmpty(os.getExternalObjectId()))
.collect(Collectors.groupingBy(OrderSettlementResp::getExternalObjectId));
Integer orderType = orderBean.getType();
ActivityChannelEnum activityChannelEnum = PropertyConvertUtil.orderTypeEnumConvert2ActivityChannel(orderType);
if (activityChannelEnum == null) {
activityChannelEnum = ActivityChannelEnum.pickup;
}
// 核销主体信息
CouponCodeVerificationDto couponCodeVerificationDto = new CouponCodeVerificationDto();
couponCodeVerificationDto.setVer(Integer.valueOf(Version.VERSION_1));
couponCodeVerificationDto.setReqtype(couponReqType.getCode());
couponCodeVerificationDto.setPartnerId(orderBean.getCompanyId());
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));
// 核销券新增参数:组织机构ID
couponCodeVerificationDto.setChannel_codes(storeService.getOrgIdsArr(orderBean.getCompanyId(), orderBean.getShopId()));
// 核销交易信息
List<CouponCodeVerificationTransDto> transactions = new ArrayList<>();
// 保存没有商品code的用券信息,主要是整单代金券
List<OrderSettlementResp> orderSettlementRemain = new ArrayList<>();
// 已经计算过的促销商品优惠信息
List<OrderSettlementResp> orderSettlementAlready = new ArrayList<>();
for (Map.Entry<String,List<OrderSettlementResp>> m : orderSettlementMap.entrySet()) {
// 活动相应的促销明细
List<OrderSettlementResp> orderSettlementInfo = m.getValue();
if(orderSettlementInfo == null || orderSettlementInfo.isEmpty()){
continue;
}
// 活动类型
Integer settlementType = orderSettlementInfo.get(0).getSettlementType();
// 券号
String couponCode = orderSettlementInfo.get(0).getExternalObjectId();
// 根据活动号转类型
Integer orderAccountType = orderSdkAdapter.getOldOrderAccountType(settlementType);
// 不是商品券、代金券、折扣券不处理
if(!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)){
// 整单代金券,最后在计算
orderSettlementRemain.add(orderSettlementInfo.get(0));
}
CouponCodeVerificationTransDto couponCodeVerificationTransDto = new CouponCodeVerificationTransDto();
// 券号
couponCodeVerificationTransDto.setCode(couponCode);
Integer totalAmount = 0;
Integer oriAmount = 0;
List<CouponCodeVerificationProductDto> products = new ArrayList<>();
for(OrderSettlementResp osr : orderSettlementInfo){
// 优惠金额大于0,此时取得是具体的商品优惠信息
if(osr.getSettlementAmount() != null && osr.getSettlementAmount().compareTo(new BigDecimal(0)) == 1){
totalAmount = totalAmount + (osr.getSettlementAmount() == null ? 0 : osr.getSettlementAmount().intValue());
}
// 商品code不为0,此时取得是具体的商品
if(!Objects.equals(osr.getProductId(),0)){
// 计算商品原价
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);
}
orderSettlementAlready.add(osr);
// 统计商品
CouponCodeVerificationProductDto couponCodeVerificationProductDto = new CouponCodeVerificationProductDto();
couponCodeVerificationProductDto.setConsume_num(num);
couponCodeVerificationProductDto.setPID(osr.getProductId());
couponCodeVerificationProductDto.setSeq(osr.getProductSeq());
couponCodeVerificationProductDto.setProductName(pb.getProductName());
Integer price = pb.getPrice() == null ? 0 : pb.getPrice().intValue();
couponCodeVerificationProductDto.setInitPrice(price);
couponCodeVerificationProductDto.setNowPrice(price);
couponCodeVerificationProductDto.setPayMoney(price);
products.add(couponCodeVerificationProductDto);
}
}
couponCodeVerificationTransDto.setProducts(products);
//处理第三方外卖单优惠金额信息
if(totalAmount != null && totalAmount.intValue() > 0){
totalAmount = 0 - Math.abs(totalAmount);
}
// 总优惠金额单位:分
couponCodeVerificationTransDto.setTotalAmount(totalAmount);
// 订单号
couponCodeVerificationTransDto.setOrderNumber(orderBean.getOid());
// 应收金额
couponCodeVerificationTransDto.setAmountRec(oriAmount);
// 实收金额
couponCodeVerificationTransDto.setAmountPaid(oriAmount);
transactions.add(couponCodeVerificationTransDto);
}
// 带有商品的券,计算完之后,要计算整单的优惠券,
// 整单的商品减掉单品优惠后的剩下的就都是整单券的商品
if(!orderSettlementRemain.isEmpty()){
Map<String, IntSummaryStatistics> collect = orderSettlementAlready.stream().collect(Collectors.groupingBy(OrderSettlementResp::getProductId, Collectors.summarizingInt(OrderSettlementResp::getNumber)));
for(OrderSettlementResp osr: orderSettlementRemain){
CouponCodeVerificationTransDto couponCodeVerificationTransFull = new CouponCodeVerificationTransDto();
// 券号
couponCodeVerificationTransFull.setCode(osr.getExternalObjectId());
// 总优惠金额单位:分
couponCodeVerificationTransFull.setTotalAmount(osr.getSettlementAmount().intValue());
// 订单号
couponCodeVerificationTransFull.setOrderNumber(orderBean.getOid());
List<CouponCodeVerificationProductDto> productsFull = new ArrayList<>();
Integer totalAmountFull = 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;
}
// 统计商品
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);
transactions.add(couponCodeVerificationTransFull);
}
}
couponCodeVerificationDto.setTransactions(transactions);
try {
//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));
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)));
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)));
ErrorLog.printErrorLog("coco verification_error", "/api", couponCodeVerificationDto, ex);
return ResponseUtil.error(ResponseResult.COUPON_VERIFICATION_FAIL);
}
return ResponseUtil.success();
}
}
/**
* All rights Reserved, Designed By www.freemud.cn
*
* @Title: OrderRelationFactoryImpl
* @Description:
* @author: pengfei.liu
* @date: 2020/11/23
* @version V1.0
* @Copyright: 2020 www.freemud.cn Inc. All rights reserved.
* 注意:本内容仅限于上海非码科技内部传阅,禁止外泄以及用于其他的商业目
*/
package cn.freemud.service.coupon.impl;
import cn.freemud.service.coupon.CouponRelationFactory;
import cn.freemud.service.coupon.CouponRelationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import java.util.List;
@Service
public class CounponRelationFactoryImpl implements CouponRelationFactory {
/**
* coco商户
*/
@Value("#{'${coco.partnerId}'.split(',')}")
private List<String> cocoPartnerId;
/**
* coco的订单相关
*/
@Autowired
@Qualifier("cocoCouponRelationService")
CouponRelationService cocoCouponRelationService;
/**
* 平台的订单相关
*/
@Autowired
@Qualifier("platformCouponRelationService")
CouponRelationService platformCouponRelationService;
@Override
public CouponRelationService getVerificationCouponService(String partnerId) {
if(cocoPartnerId.contains(partnerId)){
return cocoCouponRelationService;
}else{
return platformCouponRelationService;
}
}
}
/**
* All rights Reserved, Designed By www.freemud.cn
*
* @Title: PlatformOrderRelationServiceImpl
* @Description:
* @author: pengfei.liu
* @date: 2020/11/23
* @version V1.0
* @Copyright: 2020 www.freemud.cn Inc. All rights reserved.
* 注意:本内容仅限于上海非码科技内部传阅,禁止外泄以及用于其他的商业目
*/
package cn.freemud.service.coupon.impl;
import cn.freemud.adapter.CouponAdapter;
import cn.freemud.base.entity.BaseResponse;
import cn.freemud.entities.dto.CouponCodeResponseDto;
import cn.freemud.entities.dto.CouponCodeVerificationDto;
import cn.freemud.entities.dto.CouponCodeVerificationProductDto;
import cn.freemud.entities.dto.QueryOrdersResponseDto;
import cn.freemud.entities.vo.CreateOrderVo;
import cn.freemud.entities.vo.QueryOrderResponseVo;
import cn.freemud.enums.ActivityChannelEnum;
import cn.freemud.enums.CouponReqType;
import cn.freemud.enums.OrderAccountType;
import cn.freemud.enums.ResponseResult;
import cn.freemud.service.coupon.CouponRelationFactory;
import cn.freemud.service.coupon.CouponRelationService;
import cn.freemud.service.impl.StoreServiceImpl;
import cn.freemud.service.order.OrderRelationService;
import cn.freemud.service.thirdparty.CouponOfflineClient;
import cn.freemud.utils.LogUtil;
import cn.freemud.utils.PropertyConvertUtil;
import cn.freemud.utils.ResponseUtil;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.freemud.application.sdk.api.couponcenter.offline.service.OfflineCouponSdkService;
import com.freemud.application.sdk.api.log.ErrorLog;
import com.freemud.application.sdk.api.log.ThirdPartyLog;
import com.freemud.application.sdk.api.service.EmailAlertService;
import com.freemud.application.sdk.api.storecenter.response.StoreResponse;
import com.freemud.sdk.api.assortment.order.response.order.QueryOrderByIdResponse;
import com.google.common.base.Throwables;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors;
@Service("platformCouponRelationService")
public class PlatformCouponRelationServiceImpl implements CouponRelationService {
@Autowired
private CouponAdapter couponAdapter;
@Autowired
private CouponOfflineClient couponOfflineClient;
@Autowired
private EmailAlertService emailAlertService;
@Autowired
private StoreServiceImpl storeService;
@Override
public BaseResponse verificationCoupon(List<QueryOrdersResponseDto.DataBean.OrderBean.AccountBean> accountList, QueryOrdersResponseDto.DataBean.OrderBean orderBean, CouponReqType couponReqType) {
for (QueryOrdersResponseDto.DataBean.OrderBean.AccountBean accountBean : accountList) {
List<CouponCodeVerificationProductDto> products = new ArrayList<>();
//商品券核销核销参数
if (OrderAccountType.PRODUCT_COUPON.getCode().equals(accountBean.getType())) {
for (int i = 0; i < orderBean.getProductList().size(); i++) {
QueryOrdersResponseDto.DataBean.OrderBean.ProductBean 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<QueryOrdersResponseDto.DataBean.OrderBean.ProductBean.ProductDiscount> discounts = orderBean.getProductList().get(i).getDiscountList().stream().
filter(productDiscount -> productDiscount.getDiscountId().equals(accountBean.getAccountId())).collect(Collectors.toList());
for (QueryOrdersResponseDto.DataBean.OrderBean.ProductBean.ProductDiscount 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);
products.add(couponCodeVerificationProductDto);
}
}
}
}
Integer orderType = orderBean.getType();
ActivityChannelEnum activityChannelEnum = PropertyConvertUtil.orderTypeEnumConvert2ActivityChannel(orderType);
if (activityChannelEnum == null) {
activityChannelEnum = ActivityChannelEnum.pickup;
}
if (OrderAccountType.COUPON.getCode().equals(accountBean.getType())
|| OrderAccountType.PRODUCT_COUPON.getCode().equals(accountBean.getType())
|| OrderAccountType.DISCOUNT_COUPON.getCode().equals(accountBean.getType())) {
CouponCodeVerificationDto couponCodeVerificationDto = couponAdapter.convert2CouponCodeVerificationDto(activityChannelEnum, accountBean.getAccountId(), orderBean.getOid(), orderBean.getCompanyId(), orderBean.getShopId(), orderBean.getUserId(), products, accountBean.getPrice().intValue(),couponReqType);
// 核销券新增参数:组织机构ID
couponCodeVerificationDto.setChannel_codes(storeService.getOrgIdsArr(orderBean.getCompanyId(), orderBean.getShopId()));
try {
//71.券核销
for (int i = 2; i >= 0; i--) {
LogUtil.info("核销券码开始==", JSON.toJSONString(couponCodeVerificationDto), null);
CouponCodeResponseDto couponCodeResponseDto = couponOfflineClient.verification(couponCodeVerificationDto);
LogUtil.info("核销券码返回==", JSON.toJSONString(couponCodeVerificationDto), null);
ThirdPartyLog.infoConvertJson(System.currentTimeMillis(), System.currentTimeMillis(), "/api", couponCodeVerificationDto, couponCodeResponseDto);
if (Objects.equals(couponCodeResponseDto.getStatusCode(), ResponseResult.SUCCESS.getCode())) {
LogUtil.info("CouponReverseServiceImpl", JSON.toJSONString(couponCodeVerificationDto), JSON.toJSONString(couponCodeResponseDto));
break;
}
if (!Objects.equals(couponCodeResponseDto.getStatusCode(), ResponseResult.SUCCESS.getCode())) {
emailAlertService.sendEmailAlert("核销券码失败", String.format("request:%s \r\nresponse:%s", JSONObject.toJSONString(couponCodeVerificationDto), JSONObject.toJSONString(couponCodeResponseDto)));
return ResponseUtil.error(ResponseResult.COUPON_VERIFICATION_FAIL);
}
}
} catch (Exception ex) {
emailAlertService.sendEmailAlert("核销券码异常", String.format("request:%s \r\nexception:%s", JSONObject.toJSONString(couponCodeVerificationDto), Throwables.getStackTraceAsString(ex)));
ErrorLog.printErrorLog("verification_error", "/api", couponCodeVerificationDto, ex);
return ResponseUtil.error(ResponseResult.COUPON_VERIFICATION_FAIL);
}
}
}
return ResponseUtil.success();
}
}
...@@ -9,6 +9,8 @@ import cn.freemud.entities.vo.ActivityCouponBean; ...@@ -9,6 +9,8 @@ import cn.freemud.entities.vo.ActivityCouponBean;
import cn.freemud.enums.*; import cn.freemud.enums.*;
import cn.freemud.service.CouponActivityService; import cn.freemud.service.CouponActivityService;
import cn.freemud.service.StoreService; import cn.freemud.service.StoreService;
import cn.freemud.service.coupon.CouponRelationFactory;
import cn.freemud.service.coupon.CouponRelationService;
import cn.freemud.service.thirdparty.CouponClient; import cn.freemud.service.thirdparty.CouponClient;
import cn.freemud.service.thirdparty.CouponOfflineClient; import cn.freemud.service.thirdparty.CouponOfflineClient;
import cn.freemud.utils.LogUtil; import cn.freemud.utils.LogUtil;
...@@ -29,6 +31,7 @@ import com.google.gson.Gson; ...@@ -29,6 +31,7 @@ import com.google.gson.Gson;
import org.apache.commons.collections4.CollectionUtils; import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.lang.StringUtils; import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import java.util.*; import java.util.*;
...@@ -41,6 +44,12 @@ import java.util.stream.Collectors; ...@@ -41,6 +44,12 @@ import java.util.stream.Collectors;
@Service @Service
public class CouponActivityServiceImpl implements CouponActivityService { public class CouponActivityServiceImpl implements CouponActivityService {
/**
* coco商户
*/
@Value("#{'${coco.partnerId}'.split(',')}")
private List<String> cocoPartnerId;
@Autowired @Autowired
private CouponAdapter couponAdapter; private CouponAdapter couponAdapter;
@Autowired @Autowired
...@@ -52,6 +61,9 @@ public class CouponActivityServiceImpl implements CouponActivityService { ...@@ -52,6 +61,9 @@ public class CouponActivityServiceImpl implements CouponActivityService {
@Autowired @Autowired
private StoreServiceImpl storeService; private StoreServiceImpl storeService;
@Autowired
private CouponRelationFactory couponRelationFactory;
/** /**
* 核销优惠券 * 核销优惠券
* *
...@@ -63,67 +75,10 @@ public class CouponActivityServiceImpl implements CouponActivityService { ...@@ -63,67 +75,10 @@ public class CouponActivityServiceImpl implements CouponActivityService {
if (CollectionUtils.isEmpty(accountList) || CollectionUtils.isEmpty(orderBean.getProductList())) { if (CollectionUtils.isEmpty(accountList) || CollectionUtils.isEmpty(orderBean.getProductList())) {
return ResponseUtil.success(); return ResponseUtil.success();
} }
for (QueryOrdersResponseDto.DataBean.OrderBean.AccountBean accountBean : accountList) {
List<CouponCodeVerificationProductDto> products = new ArrayList<>();
//商品券核销核销参数
if (OrderAccountType.PRODUCT_COUPON.getCode().equals(accountBean.getType())) {
for (int i = 0; i < orderBean.getProductList().size(); i++) {
QueryOrdersResponseDto.DataBean.OrderBean.ProductBean 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<QueryOrdersResponseDto.DataBean.OrderBean.ProductBean.ProductDiscount> discounts = orderBean.getProductList().get(i).getDiscountList().stream().
filter(productDiscount -> productDiscount.getDiscountId().equals(accountBean.getAccountId())).collect(Collectors.toList());
for (QueryOrdersResponseDto.DataBean.OrderBean.ProductBean.ProductDiscount 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);
products.add(couponCodeVerificationProductDto);
}
}
}
}
Integer orderType = orderBean.getType(); // 平台走老的逻辑,cooc定制参数
ActivityChannelEnum activityChannelEnum = PropertyConvertUtil.orderTypeEnumConvert2ActivityChannel(orderType); CouponRelationService couponRelationService = couponRelationFactory.getVerificationCouponService(orderBean.getCompanyId());
if (activityChannelEnum == null) { return couponRelationService.verificationCoupon(accountList,orderBean,couponReqType);
activityChannelEnum = ActivityChannelEnum.pickup;
}
if (OrderAccountType.COUPON.getCode().equals(accountBean.getType())
|| OrderAccountType.PRODUCT_COUPON.getCode().equals(accountBean.getType())
|| OrderAccountType.DISCOUNT_COUPON.getCode().equals(accountBean.getType())) {
CouponCodeVerificationDto couponCodeVerificationDto = couponAdapter.convert2CouponCodeVerificationDto(activityChannelEnum, accountBean.getAccountId(), orderBean.getOid(), orderBean.getCompanyId(), orderBean.getShopId(), orderBean.getUserId(), products, accountBean.getPrice().intValue(),couponReqType);
// 核销券新增参数:组织机构ID
couponCodeVerificationDto.setChannel_codes(storeService.getOrgIdsArr(orderBean.getCompanyId(), orderBean.getShopId()));
try {
//71.券核销
for (int i = 2; i >= 0; i--) {
LogUtil.info("核销券码开始==", JSON.toJSONString(couponCodeVerificationDto), null);
CouponCodeResponseDto couponCodeResponseDto = couponOfflineClient.verification(couponCodeVerificationDto);
LogUtil.info("核销券码返回==", JSON.toJSONString(couponCodeVerificationDto), null);
ThirdPartyLog.infoConvertJson(System.currentTimeMillis(), System.currentTimeMillis(), "/api", couponCodeVerificationDto, couponCodeResponseDto);
if (Objects.equals(couponCodeResponseDto.getStatusCode(), ResponseResult.SUCCESS.getCode())) {
LogUtil.info("CouponReverseServiceImpl", JSON.toJSONString(couponCodeVerificationDto), JSON.toJSONString(couponCodeResponseDto));
break;
}
if (!Objects.equals(couponCodeResponseDto.getStatusCode(), ResponseResult.SUCCESS.getCode())) {
emailAlertService.sendEmailAlert("核销券码失败", String.format("request:%s \r\nresponse:%s", JSONObject.toJSONString(couponCodeVerificationDto), JSONObject.toJSONString(couponCodeResponseDto)));
return ResponseUtil.error(ResponseResult.COUPON_VERIFICATION_FAIL);
}
}
} catch (Exception ex) {
emailAlertService.sendEmailAlert("核销券码异常", String.format("request:%s \r\nexception:%s", JSONObject.toJSONString(couponCodeVerificationDto), Throwables.getStackTraceAsString(ex)));
ErrorLog.printErrorLog("verification_error", "/api", couponCodeVerificationDto, ex);
return ResponseUtil.error(ResponseResult.COUPON_VERIFICATION_FAIL);
}
}
}
return ResponseUtil.success();
} }
@Override @Override
......
...@@ -58,6 +58,8 @@ import cn.freemud.interceptor.ServiceException; ...@@ -58,6 +58,8 @@ import cn.freemud.interceptor.ServiceException;
import cn.freemud.management.thirdparty.MulitiPaymentClient; import cn.freemud.management.thirdparty.MulitiPaymentClient;
import cn.freemud.redis.RedisCache; import cn.freemud.redis.RedisCache;
import cn.freemud.service.*; import cn.freemud.service.*;
import cn.freemud.service.coupon.CouponRelationFactory;
import cn.freemud.service.coupon.CouponRelationService;
import cn.freemud.service.order.OrderRelationFactory; import cn.freemud.service.order.OrderRelationFactory;
import cn.freemud.service.order.OrderRelationService; import cn.freemud.service.order.OrderRelationService;
import cn.freemud.service.thirdparty.*; import cn.freemud.service.thirdparty.*;
......
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