Commit fb253eb7 authored by zhaobiyan's avatar zhaobiyan

Merge branch 'feature_member_score' into dev

parents bba30c54 a8976ef2
......@@ -49,10 +49,10 @@
<artifactId>yudao-module-depository-core</artifactId>
<version>${revision}</version>
</dependency>
<dependency>
<groupId>cn.iocoder.boot</groupId>
<artifactId>yudao-module-order-core</artifactId>
<version>${revision}</version>
</dependency>
<!-- <dependency>-->
<!-- <groupId>cn.iocoder.boot</groupId>-->
<!-- <artifactId>yudao-module-order-core</artifactId>-->
<!-- <version>${revision}</version>-->
<!-- </dependency>-->
</dependencies>
</project>
package cn.iocoder.yudao.module.member.listener;
import cn.hutool.core.util.ArrayUtil;
import cn.hutool.json.JSONUtil;
import cn.iocoder.yudao.framework.apollo.core.event.OrderInShippingEvent;
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.scoreRule.ScoreRuleDO;
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.memberUserScoreLog.MemberUserScoreLogService;
import cn.iocoder.yudao.module.member.service.scoreRule.ScoreRuleService;
import cn.iocoder.yudao.module.member.vo.scoreRule.extra.ScoreRuleOrderVExtraVO;
import cn.iocoder.yudao.module.order.dal.dataobject.order.OrderDO;
import cn.iocoder.yudao.module.order.dal.dataobject.orderObjective.OrderObjectiveDO;
import cn.iocoder.yudao.module.order.enums.OrderStatusEnum;
import cn.iocoder.yudao.module.order.service.order.OrderService;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.event.EventListener;
import org.springframework.stereotype.Component;
import javax.annotation.Resource;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.util.Date;
import java.util.List;
import java.util.Objects;
@Component
@AllArgsConstructor
@Slf4j
public class OrderInShippingListener {
@Resource
private OrderService orderService;
@Resource
private ScoreRuleService scoreRuleService;
@Resource
private MemberUserScoreApi memberUserScoreApi;
@Resource
private MemberUserScoreLogService memberUserScoreLogService;
@EventListener(OrderInShippingEvent.class)
public void listen(OrderInShippingEvent event) {
Long orderId = event.getOrderId();
String orderNo = event.getOrderNo();
OrderDO orderDO;
if (orderId != null) {
orderDO = orderService.getById(orderId);
} else {
orderDO = orderService.selectOne(new LambdaQueryWrapper<OrderDO>().eq(OrderDO::getOrderNo, orderNo).last("limit 1"));
}
if (Objects.isNull(orderDO)) {
log.error("Order in shipping listening error: The order does not exist,orderId:{},orderNo:{}", orderId, orderNo);
}
// 目的地信息
OrderObjectiveDO orderObjectiveDO = orderDO.getOrderObjectiveDO();
// 订单状态应为起运
if (!Objects.equals(orderDO.getStatus(), OrderStatusEnum.IN_SHIPPING.getValue())) {
return;
}
// 判断海运空运
Integer transportId = orderDO.getTransportId();
ScoreRuleDO scoreRuleDO = scoreRuleService.getEnabledOrderVScoreRuleByTransportType(transportId);
if (Objects.isNull(scoreRuleDO)) {
log.info("No score rule match");
return;
}
// 是否过期
if (scoreRuleDO.getEndTime().after(new Date())) {
log.info("The score rule has expired");
return;
}
ScoreRuleOrderVExtraVO extraInfo = JSONUtil.toBean(scoreRuleDO.getExtra(), ScoreRuleOrderVExtraVO.class);
// 是否首单,首单只加一次
if (extraInfo.getFirstOrder() == YesOrNoTypeEnum.YES.ordinal()){
Long count = orderService.selectCount(new LambdaQueryWrapper<OrderDO>().eq(OrderDO::getUserId, orderDO.getUserId()));
if (count > 1) {
log.info("Not first order");
return;
}
}
// 提货点是否包含
String[] warehouseIds = extraInfo.getReceiveAddr().split(",");
if (!ArrayUtil.contains(warehouseIds, orderObjectiveDO.getObjectiveWarehouseId().toString())) {
return;
}
// 计算积分
Integer scoreCount = 0;
List<ScoreRuleOrderVExtraVO.OrderVRule> orderVRule = extraInfo.getOrderVRule();
if (transportId == TransportTypeEnum.OCEAN_LCL.getValue()) {
// 海运算重量
BigDecimal orgVWeight = orderDO.getOrgVWeight();
int w = orgVWeight.setScale(0, RoundingMode.HALF_UP).intValue();
for (ScoreRuleOrderVExtraVO.OrderVRule rule : orderVRule) {
if (rule.getLow() <= w && rule.getHigh() >= w) {
scoreCount = rule.getScore();
break;
}
}
} else if (transportId == TransportTypeEnum.SPECIAL_LINE_AIR_FREIGHT.getValue()) {
// 空运校验渠道
// 渠道id
Long channelId = orderDO.getChannelId();
String[] channels = extraInfo.getChannel().split(",");
if (!ArrayUtil.contains(channels, channelId.toString())) {
return;
}
// 空运算体积
BigDecimal orgWVolume = orderDO.getOrgWVolume();
int v = orgWVolume.setScale(0, RoundingMode.HALF_UP).intValue();
for (ScoreRuleOrderVExtraVO.OrderVRule rule : orderVRule) {
if (rule.getLow() <= v && rule.getHigh() >= v) {
scoreCount = rule.getScore();
break;
}
}
}
if (scoreCount > scoreRuleDO.getGetScoreOnce()){
scoreCount = scoreRuleDO.getGetScoreOnce();
}
// 校验累计最高分,查member_user_score_log
// 增加积分
// 会员id
Long userId = orderDO.getUserId();
memberUserScoreApi.operateScore(MemberUserScoreOperateReqDTO.builder()
.memberId(userId)
.scoreCount(scoreCount)
.sourceType(ScoreSourceTypeEnum.EXCHANGE_REWARD)
.ruleId(scoreRuleDO.getId())
.expireDays(scoreRuleDO.getScorePeriod())
.build()
);
}
}
//package cn.iocoder.yudao.module.member.listener;
//
//import cn.hutool.core.util.ArrayUtil;
//import cn.hutool.json.JSONUtil;
//import cn.iocoder.yudao.framework.apollo.core.event.OrderInShippingEvent;
//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.scoreRule.ScoreRuleDO;
//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.memberUserScoreLog.MemberUserScoreLogService;
//import cn.iocoder.yudao.module.member.service.scoreRule.ScoreRuleService;
//import cn.iocoder.yudao.module.member.vo.scoreRule.extra.ScoreRuleOrderVExtraVO;
//import cn.iocoder.yudao.module.order.dal.dataobject.order.OrderDO;
//import cn.iocoder.yudao.module.order.dal.dataobject.orderObjective.OrderObjectiveDO;
//import cn.iocoder.yudao.module.order.enums.OrderStatusEnum;
//import cn.iocoder.yudao.module.order.service.order.OrderService;
//import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
//import lombok.AllArgsConstructor;
//import lombok.extern.slf4j.Slf4j;
//import org.springframework.context.event.EventListener;
//import org.springframework.stereotype.Component;
//
//import javax.annotation.Resource;
//import java.math.BigDecimal;
//import java.math.RoundingMode;
//import java.util.Date;
//import java.util.List;
//import java.util.Objects;
//
//@Component
//@AllArgsConstructor
//@Slf4j
//public class OrderInShippingListener {
// @Resource
// private OrderService orderService;
// @Resource
// private ScoreRuleService scoreRuleService;
// @Resource
// private MemberUserScoreApi memberUserScoreApi;
// @Resource
// private MemberUserScoreLogService memberUserScoreLogService;
//
// @EventListener(OrderInShippingEvent.class)
// public void listen(OrderInShippingEvent event) {
// Long orderId = event.getOrderId();
// String orderNo = event.getOrderNo();
// OrderDO orderDO;
// if (orderId != null) {
// orderDO = orderService.getById(orderId);
// } else {
// orderDO = orderService.selectOne(new LambdaQueryWrapper<OrderDO>().eq(OrderDO::getOrderNo, orderNo).last("limit 1"));
// }
// if (Objects.isNull(orderDO)) {
// log.error("Order in shipping listening error: The order does not exist,orderId:{},orderNo:{}", orderId, orderNo);
// }
// // 目的地信息
// OrderObjectiveDO orderObjectiveDO = orderDO.getOrderObjectiveDO();
// // 订单状态应为起运
// if (!Objects.equals(orderDO.getStatus(), OrderStatusEnum.IN_SHIPPING.getValue())) {
// return;
// }
// // 判断海运空运
// Integer transportId = orderDO.getTransportId();
// ScoreRuleDO scoreRuleDO = scoreRuleService.getEnabledOrderVScoreRuleByTransportType(transportId);
// if (Objects.isNull(scoreRuleDO)) {
// log.info("No score rule match");
// return;
// }
// // 是否过期
// if (scoreRuleDO.getEndTime().after(new Date())) {
// log.info("The score rule has expired");
// return;
// }
// ScoreRuleOrderVExtraVO extraInfo = JSONUtil.toBean(scoreRuleDO.getExtra(), ScoreRuleOrderVExtraVO.class);
// // 是否首单,首单只加一次
// if (extraInfo.getFirstOrder() == YesOrNoTypeEnum.YES.ordinal()){
// Long count = orderService.selectCount(new LambdaQueryWrapper<OrderDO>().eq(OrderDO::getUserId, orderDO.getUserId()));
// if (count > 1) {
// log.info("Not first order");
// return;
// }
// }
// // 提货点是否包含
// String[] warehouseIds = extraInfo.getReceiveAddr().split(",");
// if (!ArrayUtil.contains(warehouseIds, orderObjectiveDO.getObjectiveWarehouseId().toString())) {
// return;
// }
// // 计算积分
// Integer scoreCount = 0;
// List<ScoreRuleOrderVExtraVO.OrderVRule> orderVRule = extraInfo.getOrderVRule();
// if (transportId == TransportTypeEnum.OCEAN_LCL.getValue()) {
// // 海运算重量
// BigDecimal orgVWeight = orderDO.getOrgVWeight();
// int w = orgVWeight.setScale(0, RoundingMode.HALF_UP).intValue();
// for (ScoreRuleOrderVExtraVO.OrderVRule rule : orderVRule) {
// if (rule.getLow() <= w && rule.getHigh() >= w) {
// scoreCount = rule.getScore();
// break;
// }
// }
// } else if (transportId == TransportTypeEnum.SPECIAL_LINE_AIR_FREIGHT.getValue()) {
// // 空运校验渠道
// // 渠道id
// Long channelId = orderDO.getChannelId();
// String[] channels = extraInfo.getChannel().split(",");
// if (!ArrayUtil.contains(channels, channelId.toString())) {
// return;
// }
// // 空运算体积
// BigDecimal orgWVolume = orderDO.getOrgWVolume();
// int v = orgWVolume.setScale(0, RoundingMode.HALF_UP).intValue();
// for (ScoreRuleOrderVExtraVO.OrderVRule rule : orderVRule) {
// if (rule.getLow() <= v && rule.getHigh() >= v) {
// scoreCount = rule.getScore();
// break;
// }
// }
// }
// if (scoreCount > scoreRuleDO.getGetScoreOnce()){
// scoreCount = scoreRuleDO.getGetScoreOnce();
// }
// // 校验累计最高分,查member_user_score_log
//
// // 增加积分
// // 会员id
// Long userId = orderDO.getUserId();
// memberUserScoreApi.operateScore(MemberUserScoreOperateReqDTO.builder()
// .memberId(userId)
// .scoreCount(scoreCount)
// .sourceType(ScoreSourceTypeEnum.EXCHANGE_REWARD)
// .ruleId(scoreRuleDO.getId())
// .expireDays(scoreRuleDO.getScorePeriod())
// .build()
// );
// }
//}
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