Commit a8976ef2 authored by zhangfeng's avatar zhangfeng

Merge branch 'refs/heads/feature_member_score_zhangfeng' into feature_member_score

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