Commit f84e6c70 authored by zhangfeng's avatar zhangfeng

订单V值触发修改

parent 43b48470
package cn.iocoder.yudao.module.member.listener;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.core.util.ArrayUtil;
import cn.hutool.json.JSONUtil;
import cn.iocoder.boot.module.order.api.OrderApi;
import cn.iocoder.boot.module.order.api.dto.OrderObjectiveApiDO;
import cn.iocoder.boot.module.order.api.dto.OrderRespDTO;
import cn.iocoder.boot.module.order.enums.OrderStatusApiEnum;
import cn.iocoder.yudao.framework.apollo.core.event.OrderInShippingEvent;
import cn.iocoder.yudao.module.customer.dal.dataobject.customerContacts.CustomerContactsDO;
import cn.iocoder.yudao.module.customer.service.customerContacts.CustomerContactsService;
import cn.iocoder.yudao.module.member.api.score.MemberUserScoreApi;
import cn.iocoder.yudao.module.member.api.score.dto.MemberUserScoreOperateReqDTO;
import cn.iocoder.yudao.module.member.dal.dataobject.scoreLog.MemberUserScoreLogDO;
import cn.iocoder.yudao.module.member.dal.dataobject.scoreRule.ScoreRuleDO;
import cn.iocoder.yudao.module.member.enums.PlatformTypeEnum;
import cn.iocoder.yudao.module.member.enums.ScoreSourceTypeEnum;
import cn.iocoder.yudao.module.member.enums.TransportTypeEnum;
import cn.iocoder.yudao.module.member.enums.YesOrNoTypeEnum;
import cn.iocoder.yudao.module.member.service.scoreLog.MemberUserScoreLogService;
import cn.iocoder.yudao.module.member.service.scoreRule.ScoreRuleService;
import cn.iocoder.yudao.module.member.vo.scoreRule.extra.ScoreRuleOrderVExtraVO;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import javax.annotation.Resource;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Objects;
/**
* 弃用
*/
//@Component
@AllArgsConstructor
@Slf4j
public class OrderInShippingListener {
@Resource
private OrderApi orderApi;
@Resource
private ScoreRuleService scoreRuleService;
@Resource
private MemberUserScoreApi memberUserScoreApi;
@Resource
private MemberUserScoreLogService memberUserScoreLogService;
@Resource
private CustomerContactsService customerContactsService;
//@EventListener(OrderInShippingEvent.class)
public void listen(OrderInShippingEvent event) {
Long orderId = event.getOrderId();
String orderNo = event.getOrderNo();
OrderRespDTO order;
try {
order = orderApi.getOrder(orderId, orderNo);
} catch (Exception e) {
log.error("Order in shipping listener: Get order error,orderId:{},orderNo:{}", orderId, orderNo);
return;
}
if (Objects.isNull(order)) {
log.error("Order in shipping listener: The order does not exist,orderId:{},orderNo:{}", orderId, orderNo);
return;
}
// 订单状态应为起运
if (!Objects.equals(order.getStatus(), OrderStatusApiEnum.IN_SHIPPING.getValue())) {
return;
}
// 判断海运空运
Integer transportId = order.getTransportId();
ScoreRuleDO scoreRuleDO = scoreRuleService.getEnabledOrderVScoreRuleByTransportType(transportId);
if (Objects.isNull(scoreRuleDO)) {
log.info("Order in shipping listener: No score rule match");
return;
}
// 是否过期,或者活动还没开始
if (!scoreRuleDO.getEndTime().after(new Date()) || !scoreRuleDO.getStartTime().before(new Date())) {
log.info("Order in shipping listener: The score rule has expired");
return;
}
// 目的地信息
OrderObjectiveApiDO orderObjectiveDO = order.getOrderObjectiveDO();
ScoreRuleOrderVExtraVO extraInfo = JSONUtil.toBean(scoreRuleDO.getExtra(), ScoreRuleOrderVExtraVO.class);
// 提货点是否包含
String[] warehouseIds = extraInfo.getReceiveAddr().split(",");
if (!ArrayUtil.contains(warehouseIds, orderObjectiveDO.getObjectiveWarehouseId().toString())) {
return;
}
// 计算积分
List<ScoreRuleOrderVExtraVO.OrderVRule> orderVRules = extraInfo.getOrderVRule();
Integer scoreCount = 0;
if (transportId == TransportTypeEnum.OCEAN_LCL.getValue()) {
// 海运算重量
BigDecimal orgVWeight = order.getOrgVWeight();
scoreCount = computeScoreCount(orgVWeight, orderVRules);
} else if (transportId == TransportTypeEnum.SPECIAL_LINE_AIR_FREIGHT.getValue()) {
// 空运校验渠道
// 渠道id
Long channelId = order.getChannelId();
String[] channels = extraInfo.getChannel().split(",");
if (!ArrayUtil.contains(channels, channelId.toString())) {
return;
}
// 空运算体积
BigDecimal orgWVolume = order.getOrgWVolume();
scoreCount = computeScoreCount(orgWVolume, orderVRules);
}
if (scoreCount > scoreRuleDO.getGetScoreOnce()) {
scoreCount = scoreRuleDO.getGetScoreOnce();
} else if (scoreCount <= 0) {
log.info("Order in shipping listener: The score count is less than or equal to 0,orderId:{}", orderId);
return;
}
// 会员id
Long userId = order.getUserId();
// 订单入口
String orderEntryString = extraInfo.getOrderEntry();
if (StringUtils.isBlank(orderEntryString)) {
log.info("Order in shipping listener: orderEntry is null");
return;
}
String[] orderEntry = orderEntryString.split(",");
if (userId <= 0) {
// 后台下单
if (!ArrayUtil.contains(orderEntry, String.valueOf(PlatformTypeEnum.BACKEND.getValue()))) {
log.info("Order in shipping listener: The order is placed by the background, userId:{}", userId);
return;
}
// 查询客户绑定会员
List<CustomerContactsDO> customerContacts = customerContactsService.getCustomerContactsListByCustomerId(order.getCustomerId());
if (CollectionUtil.isEmpty(customerContacts)) {
log.info("Order in shipping listener: The customer is not bound to the member, customerId:{}", order.getCustomerId());
return;
}
for (CustomerContactsDO customerContact : customerContacts) {
if (customerContact.getIsDefault() == 1 && customerContact.getUserid() != null) {
userId = customerContact.getUserid();
}
}
if (userId <= 0) {
log.info("Order in shipping listener: The customer is not have default userId, customerId:{}", order.getCustomerId());
return;
}
} else if (!ArrayUtil.contains(orderEntry, String.valueOf(PlatformTypeEnum.APP.getValue())) && !ArrayUtil.contains(orderEntry, String.valueOf(PlatformTypeEnum.WEB.getValue()))) {
log.info("Order in shipping listener: The order is placed by the app or web, userId:{}", userId);
return;
}
// 是否首单,首单只加一次
if (extraInfo.getFirstOrder() == YesOrNoTypeEnum.YES.ordinal()) {
if (!orderApi.isFirstOrder(userId)) {
log.info("Order in shipping listener: Not first order");
return;
}
}
// 校验累计最高分
Integer userScoreTotalCount = 0;
LambdaQueryWrapper<MemberUserScoreLogDO> scoreLogQueryWrapper = new LambdaQueryWrapper<>();
scoreLogQueryWrapper.eq(MemberUserScoreLogDO::getMemberId, userId)
.eq(MemberUserScoreLogDO::getRuleId, scoreRuleDO.getId());
List<MemberUserScoreLogDO> memberUserScoreLogs = memberUserScoreLogService.selectList(scoreLogQueryWrapper);
if (CollUtil.isNotEmpty(memberUserScoreLogs)) {
for (MemberUserScoreLogDO memberUserScoreLog : memberUserScoreLogs) {
userScoreTotalCount += memberUserScoreLog.getScoreCount();
}
}
if (userScoreTotalCount >= scoreRuleDO.getMaxScoreTotal()) {
log.info("Order in shipping listener: The user has reached the maximum score,userId:{},scoreRuleId:{}", userId, scoreRuleDO.getId());
return;
}
//if (userScoreTotalCount + scoreCount > scoreRuleDO.getMaxScoreTotal()) {
// scoreCount = scoreRuleDO.getMaxScoreTotal() - userScoreTotalCount;
//}
// 增加积分
try {
HashMap<String, Object> map = new HashMap<>();
map.put("orderId", orderId);
memberUserScoreApi.operateScore(MemberUserScoreOperateReqDTO.builder()
.memberId(userId)
.scoreCount(scoreCount)
.sourceType(ScoreSourceTypeEnum.ORDER_V)
.ruleId(scoreRuleDO.getId())
.expireDays(scoreRuleDO.getScorePeriod())
.extParam(map)
.build()
);
} catch (Exception e) {
log.error("Order in shipping listener: operateScore error", e);
}
}
/**
* 根据规则计算获取积分
*
* @param weightOrVolume 重量或体积
* @param orderVRules 规则
* @return
*/
private Integer computeScoreCount(BigDecimal weightOrVolume, List<ScoreRuleOrderVExtraVO.OrderVRule> orderVRules) {
Integer scoreCount = 0;
int w = weightOrVolume.setScale(0, RoundingMode.HALF_UP).intValue();
ScoreRuleOrderVExtraVO.OrderVRule lastRule = orderVRules.get(orderVRules.size() - 1);
if (w >= lastRule.getHigh()) {
scoreCount = lastRule.getScore();
}
for (int i = orderVRules.size() - 1; i >= 0; i--) {
ScoreRuleOrderVExtraVO.OrderVRule orderVRule = orderVRules.get(i);
if (orderVRule.getLow() <= w && orderVRule.getHigh() >= w) {
scoreCount = orderVRule.getScore();
break;
}
}
return scoreCount;
}
}
......@@ -175,9 +175,9 @@ public class OrderVStrategy extends AbstractScoreRuleStrategy {
if (!isOrderEntryValid(extraInfo.getOrderEntry(), isBackendOrder)) {
return null;
}
// 如果是后台下单,重新获取用户ID
// 如果是后台下单,重新获取发货人用户ID
if (isBackendOrder) {
userId = getCustomerMemberId(order.getCustomerId());
userId = getCustomerMemberId(order.getOrderConsignorDO().getCustomerId());
if (userId == null) {
userId = 0L;
}
......
package cn.iocoder.boot.module.order.api.dto;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
/**
* 订单发货人信息 Response VO
* @author 系统管理员
*/
@Data
@ApiModel("管理后台 - 订单发货人信息 Response VO")
public class OrderConsignorApiDO {
@ApiModelProperty(value = "主键ID", required = true)
private Long id;
@ApiModelProperty(value = "下单用户id")
private Long relationId;
@ApiModelProperty(value = "订单id")
private Long orderId;
@ApiModelProperty(value = "发货人姓名")
private String name;
@ApiModelProperty(value = "发货人姓名(英文)")
private String nameEn;
@ApiModelProperty(value = "", required = true)
private Long customerId;
@ApiModelProperty(value = "", required = true)
private Long customerContactsId;
}
......@@ -44,18 +44,6 @@ public class OrderRespDTO {
* 下单会员id
*/
private Long userId;
/**
* 客户经理ID
*/
private Long salesmanId;
/**
* 部门ID
*/
private Long deptId;
/**
* 唛头
*/
private String marks;
/**
* 订单状态详情见字典
......@@ -96,165 +84,11 @@ public class OrderRespDTO {
* 是否被删掉 1 删掉;0正常
*/
private Boolean isDel;
@ApiModelProperty(value = "代收金额")
private BigDecimal collectionProxy;
@ApiModelProperty(value = "代收货币ID")
private Integer collectionProxyCurrency;
/**
* 是否代收货款收款 0为否 1为是
*/
private Boolean isCollection;
/**
* 重货体积
*/
private BigDecimal wVolume;
/**
* 泡货重量
*/
private BigDecimal vWeight;
/**
* 原应收重货体积
*/
private BigDecimal orgWVolume;
/**
* 原应收泡货重量
*/
private BigDecimal orgVWeight;
@ApiModelProperty(value = "最小计量重量")
private BigDecimal minMeteringWeight = BigDecimal.ZERO;
@ApiModelProperty(value = "最小计量体积")
private BigDecimal minMeteringVolume = BigDecimal.ZERO;
@ApiModelProperty(value = "最小计量个数")
private BigDecimal minMeteringQuantity = BigDecimal.ZERO;
/**
* 重货标准基数
*/
private BigDecimal weightUnit;
/**
* 泡货标准基数
*/
private BigDecimal volumeUnit;
@ApiModelProperty(value = "原重货标准基数")
private BigDecimal orgWeightUnit;
@ApiModelProperty(value = "原泡货标准基数")
private BigDecimal orgVolumeUnit;
@ApiModelProperty(value = "计算使用的重货标准基数")
private BigDecimal useWeightUnit;
@ApiModelProperty(value = "计算使用的泡货标准基数")
private BigDecimal useVolumeUnit;
/**
* 入仓类型
*/
private Integer warehouseType;
/**
* 备注
*/
private String remarks;
/**
* 调仓始发仓
*/
private Long adjustToStartWarehouseId;
/**
* 调仓目的仓
*/
private Long adjustToDestWarehouseId;
/**
* 目的地调仓始发仓
*/
private Long destAdjustToStartWarehouseId;
/**
* 目的地调仓目的仓
*/
private Long destAdjustToDestWarehouseId;
@ApiModelProperty(value = "入仓数量", required = true)
private Integer sumQuantity;
/**
* 入仓件数
*/
private Integer sumNum;
/**
* 自定义入仓体积
*/
private BigDecimal customSumVolume;
/**
* 入仓体积
*/
private BigDecimal sumVolume;
/**
* 自定义入仓重量
*/
private BigDecimal customSumWeight;
/**
* 入仓重量
*/
private BigDecimal sumWeight;
/**
* 重货比
*/
private BigDecimal weightRatio;
/**
* 发货人的客户id
* 订单归属客户id
*/
private Long customerId;
/**
* 完成入仓的入仓体积
*/
private BigDecimal sumVolumeFinishedWarehouseIn;
/**
* 完成入仓的入仓重量
*/
private BigDecimal sumWeightFinishedWarehouseIn;
/**
* 完成入仓的箱/件数
*/
private Integer sumCartonsNumFinishedWarehouseIn;
/**
* 完成入仓的所有箱内总货物数量
*/
private Integer sumQuantityAllFinishedWarehouseIn;
/**
* 上次打包的入仓体积
*/
@ApiModelProperty(value = "上次打包的入仓体积")
private BigDecimal sumVolumePrevPacked;
/**
* 上次打包的入仓重量
*/
@ApiModelProperty(value = "上次打包的入仓重量")
private BigDecimal sumWeightPrevPacked;
/**
* 上次打包的箱/件数
*/
@ApiModelProperty(value = "上次打包的箱数")
private Integer sumCartonsNumPrevPacked;
/**
* 上次打包的所有箱内总货物数量
*/
@ApiModelProperty(value = "上次打包的所有箱内总货物数量")
private Integer sumQuantityAllPrevPacked;
@ApiModelProperty(value = "付款人: 1 发货人 2 收货人 3 自定义")
private Integer drawee;
......@@ -264,30 +98,24 @@ public class OrderRespDTO {
@ApiModelProperty(value = "打包前入仓重量")
private BigDecimal weightBeforePack;
@ApiModelProperty(value = "打包后入仓重量")
private BigDecimal weightAfterPack;
@ApiModelProperty(value = "是否有收货人,1-是,0-否")
private Boolean hasConsignee = true;
@TableField(exist = false)
@ApiModelProperty(value = "目的地信息")
@NotNull(message = "目的地信息不能为空")
private OrderObjectiveApiDO orderObjectiveDO;
@TableField(exist = false)
@ApiModelProperty(value = "发货人信息")
private OrderConsignorApiDO orderConsignorDO;
@ApiModelProperty(value = "收货人信息")
@NotNull(message = "收货人信息不能为空")
private OrderConsigneeApiDO orderConsigneeDO;
@TableField(exist = false)
@ApiModelProperty(value = "目的地ID")
private Long objectiveId;
@TableField(exist = false)
@ApiModelProperty(value = "目的地")
private String objectiveName;
......
......@@ -2,15 +2,15 @@ package cn.iocoder.yudao.module.order.api;
import cn.hutool.core.collection.CollectionUtil;
import cn.iocoder.boot.module.order.api.OrderApi;
import cn.iocoder.boot.module.order.api.dto.OrderConsigneeApiDO;
import cn.iocoder.boot.module.order.api.dto.OrderItemRespDTO;
import cn.iocoder.boot.module.order.api.dto.OrderObjectiveApiDO;
import cn.iocoder.boot.module.order.api.dto.OrderRespDTO;
import cn.iocoder.boot.module.order.api.dto.*;
import cn.iocoder.yudao.module.order.convert.orderConsignor.OrderConsignorConvert;
import cn.iocoder.yudao.module.order.dal.dataobject.order.OrderDO;
import cn.iocoder.yudao.module.order.dal.dataobject.orderConsignee.OrderConsigneeDO;
import cn.iocoder.yudao.module.order.dal.dataobject.orderConsignor.OrderConsignorDO;
import cn.iocoder.yudao.module.order.dal.dataobject.orderItem.OrderItemDO;
import cn.iocoder.yudao.module.order.dal.dataobject.orderObjective.OrderObjectiveDO;
import cn.iocoder.yudao.module.order.service.order.OrderConsigneeService;
import cn.iocoder.yudao.module.order.service.order.OrderConsignorService;
import cn.iocoder.yudao.module.order.service.order.OrderObjectiveService;
import cn.iocoder.yudao.module.order.service.order.OrderService;
import cn.iocoder.yudao.module.order.service.order.impl.OrderItemServiceImpl;
......@@ -21,6 +21,7 @@ import org.springframework.validation.annotation.Validated;
import javax.annotation.Resource;
import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors;
@Service
......@@ -34,6 +35,8 @@ public class OrderApiImpl implements OrderApi {
private OrderConsigneeService orderConsigneeService;
@Resource
private OrderItemServiceImpl orderItemService;
@Resource
private OrderConsignorService orderConsignorService;
@Override
public OrderRespDTO getOrder(Long id, String orderNo) {
......@@ -56,7 +59,14 @@ public class OrderApiImpl implements OrderApi {
BeanUtils.copyProperties(orderObjectiveDO, orderObjectiveApiDO);
orderRespDTO.setOrderObjectiveDO(orderObjectiveApiDO);
}
// 设置发货人信息
OrderConsignorDO orderConsignorDO =
orderConsignorService.getOne(new LambdaQueryWrapper<OrderConsignorDO>().eq(OrderConsignorDO::getOrderId, orderDO.getOrderId()).orderByDesc(OrderConsignorDO::getId).last("limit 1"));
if (Objects.nonNull(orderConsignorDO)) {
OrderConsignorApiDO orderConsignorApiDO = new OrderConsignorApiDO();
BeanUtils.copyProperties(orderConsignorDO, orderConsignorApiDO);
orderRespDTO.setOrderConsignorDO(orderConsignorApiDO);
}
// 设置收货人信息
OrderConsigneeDO orderConsigneeByOrderId = orderConsigneeService.getOrderConsigneeByOrderId(orderDO.getOrderId());
if (orderConsigneeByOrderId != null) {
......
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