Commit 03a7d578 authored by zhangfeng's avatar zhangfeng

Merge branch 'refs/heads/feature_member_score' into dev

parents 3e7053ff a7340da0
...@@ -10,9 +10,12 @@ import cn.iocoder.yudao.framework.security.core.annotations.PreAuthenticated; ...@@ -10,9 +10,12 @@ import cn.iocoder.yudao.framework.security.core.annotations.PreAuthenticated;
import cn.iocoder.yudao.module.customer.dal.dataobject.customerContacts.CustomerContactsDO; import cn.iocoder.yudao.module.customer.dal.dataobject.customerContacts.CustomerContactsDO;
import cn.iocoder.yudao.module.customer.service.customerContacts.CustomerContactsService; import cn.iocoder.yudao.module.customer.service.customerContacts.CustomerContactsService;
import cn.iocoder.yudao.module.ecw.api.paramValid.ParamValidatorApi; import cn.iocoder.yudao.module.ecw.api.paramValid.ParamValidatorApi;
import cn.iocoder.yudao.module.ecw.dal.dataobject.region.RegionDO;
import cn.iocoder.yudao.module.ecw.service.internalMessage.InternalMessageService; import cn.iocoder.yudao.module.ecw.service.internalMessage.InternalMessageService;
import cn.iocoder.yudao.module.ecw.service.internalMessage.WebInternalMessageService; import cn.iocoder.yudao.module.ecw.service.internalMessage.WebInternalMessageService;
import cn.iocoder.yudao.module.ecw.service.region.RegionService;
import cn.iocoder.yudao.module.member.controller.app.auth.vo.AppEmailUpdateReqVO; import cn.iocoder.yudao.module.member.controller.app.auth.vo.AppEmailUpdateReqVO;
import cn.iocoder.yudao.module.member.service.level.MemberUserLevelConfigService;
import cn.iocoder.yudao.module.member.vo.member.MemberUpdateReqVO; import cn.iocoder.yudao.module.member.vo.member.MemberUpdateReqVO;
import cn.iocoder.yudao.module.member.controller.app.user.vo.*; import cn.iocoder.yudao.module.member.controller.app.user.vo.*;
import cn.iocoder.yudao.module.member.convert.user.UserConvert; import cn.iocoder.yudao.module.member.convert.user.UserConvert;
...@@ -35,6 +38,8 @@ import cn.iocoder.yudao.module.member.vo.userEnterprise.UserEnterpriseCreateReqV ...@@ -35,6 +38,8 @@ import cn.iocoder.yudao.module.member.vo.userEnterprise.UserEnterpriseCreateReqV
import cn.iocoder.yudao.module.member.vo.userEnterprise.UserEnterpriseUpdateReqVO; import cn.iocoder.yudao.module.member.vo.userEnterprise.UserEnterpriseUpdateReqVO;
import cn.iocoder.yudao.module.member.vo.userEnterpriseAuth.UserEnterpriseAuthBackVO; import cn.iocoder.yudao.module.member.vo.userEnterpriseAuth.UserEnterpriseAuthBackVO;
import cn.iocoder.yudao.module.member.vo.userEnterpriseAuth.UserEnterpriseAuthCreateReqVO; import cn.iocoder.yudao.module.member.vo.userEnterpriseAuth.UserEnterpriseAuthCreateReqVO;
import cn.iocoder.yudao.module.member.vo.userLevel.MemberUserLevelConfigBaseRespVO;
import cn.iocoder.yudao.module.member.vo.userLevel.MemberUserScoreLevelVO;
import cn.iocoder.yudao.module.product.service.coupon.CouponService; import cn.iocoder.yudao.module.product.service.coupon.CouponService;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import io.swagger.annotations.Api; import io.swagger.annotations.Api;
...@@ -98,6 +103,12 @@ public class AppUserController { ...@@ -98,6 +103,12 @@ public class AppUserController {
@Resource @Resource
private PasswordEncoder passwordEncoder; private PasswordEncoder passwordEncoder;
@Resource
private MemberUserLevelConfigService memberUserLevelConfigService;
@Resource
private RegionService regionService;
@PutMapping("/update-nickname") @PutMapping("/update-nickname")
@ApiOperation("修改用户昵称") @ApiOperation("修改用户昵称")
...@@ -146,6 +157,26 @@ public class AppUserController { ...@@ -146,6 +157,26 @@ public class AppUserController {
if (passwordEncoder.matches("88888888", user.getPassword())) { if (passwordEncoder.matches("88888888", user.getPassword())) {
respVO.setIsSimplePassword(Boolean.TRUE); respVO.setIsSimplePassword(Boolean.TRUE);
} }
MemberUserLevelConfigBaseRespVO userScoreLevelVO = memberUserLevelConfigService.getLevelByCount(user.getTotalScore());
MemberUserScoreLevelVO scoreLevelVO = MemberUserScoreLevelVO.builder().memberId(user.getId())
.memberCode(user.getMemberCode())
.holdScore(user.getHoldScore())
.expiredScore(user.getExpiredScore())
.usedScore(user.getUsedScore())
.levelIcon(userScoreLevelVO.getIcon())
.levelName(userScoreLevelVO.getName())
.build();
respVO.setUserScoreLevelInfo(scoreLevelVO);
if (user.getCountry() != null) {
RegionDO region = regionService.getRegion(Long.valueOf(user.getCountry()));
respVO.setCountryTitleEn(region.getTitleEn());
respVO.setCountryTitleZh(region.getTitleZh());
}
if (user.getCity() != null) {
RegionDO region = regionService.getRegion(Long.valueOf(user.getCity()));
respVO.setCityTitleEn(region.getTitleEn());
respVO.setCityTitleZh(region.getTitleZh());
}
return success(respVO); return success(respVO);
} }
......
package cn.iocoder.yudao.module.member.controller.app.user.vo; package cn.iocoder.yudao.module.member.controller.app.user.vo;
import cn.iocoder.yudao.module.member.vo.userLevel.MemberUserScoreLevelVO;
import com.fasterxml.jackson.annotation.JsonFormat; import com.fasterxml.jackson.annotation.JsonFormat;
import io.swagger.annotations.ApiModel; import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty; import io.swagger.annotations.ApiModelProperty;
...@@ -67,4 +68,14 @@ public class AppUserInfoRespVO { ...@@ -67,4 +68,14 @@ public class AppUserInfoRespVO {
@ApiModelProperty(value = "是否简单密码", example = "false") @ApiModelProperty(value = "是否简单密码", example = "false")
private Boolean isSimplePassword = Boolean.FALSE; private Boolean isSimplePassword = Boolean.FALSE;
@ApiModelProperty(value = "会员积分信息")
private MemberUserScoreLevelVO userScoreLevelInfo;
@ApiModelProperty(value = "会员国家中文")
private String countryTitleZh;
@ApiModelProperty(value = "会员国家英文")
private String countryTitleEn;
@ApiModelProperty(value = "会员城市中文")
private String cityTitleZh;
@ApiModelProperty(value = "会员国家英文")
private String cityTitleEn;
} }
...@@ -10,6 +10,7 @@ import org.springframework.data.redis.core.StringRedisTemplate; ...@@ -10,6 +10,7 @@ import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Repository; import org.springframework.stereotype.Repository;
import javax.annotation.Resource; import javax.annotation.Resource;
import java.util.concurrent.TimeUnit;
/** /**
* 会员积分规则 Redis DAO * 会员积分规则 Redis DAO
...@@ -57,7 +58,7 @@ public class ScoreRuleRedisDao { ...@@ -57,7 +58,7 @@ public class ScoreRuleRedisDao {
ScoreRuleOrderVExtraVO scoreRuleOrderVExtraVO = JsonUtils.parseObject(scoreRuleDO.getExtra(), ScoreRuleOrderVExtraVO.class); ScoreRuleOrderVExtraVO scoreRuleOrderVExtraVO = JsonUtils.parseObject(scoreRuleDO.getExtra(), ScoreRuleOrderVExtraVO.class);
stringRedisTemplate.opsForValue().set(formatKey(scoreRuleDO.getType(), scoreRuleOrderVExtraVO.getTransportType()), JsonUtils.toJsonString(scoreRuleDO)); stringRedisTemplate.opsForValue().set(formatKey(scoreRuleDO.getType(), scoreRuleOrderVExtraVO.getTransportType()), JsonUtils.toJsonString(scoreRuleDO));
} }
stringRedisTemplate.opsForValue().set(formatKey(scoreRuleDO.getType(), null), JsonUtils.toJsonString(scoreRuleDO)); stringRedisTemplate.opsForValue().set(formatKey(scoreRuleDO.getType(), null), JsonUtils.toJsonString(scoreRuleDO),24L, TimeUnit.HOURS);
} }
public void deleteEnableScoreRule(Integer type) { public void deleteEnableScoreRule(Integer type) {
......
...@@ -4,6 +4,7 @@ import cn.hutool.core.collection.CollectionUtil; ...@@ -4,6 +4,7 @@ import cn.hutool.core.collection.CollectionUtil;
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.boot.module.order.api.OrderApi; import cn.iocoder.boot.module.order.api.OrderApi;
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.OrderObjectiveApiDO;
import cn.iocoder.boot.module.order.api.dto.OrderRespDTO; import cn.iocoder.boot.module.order.api.dto.OrderRespDTO;
import cn.iocoder.boot.module.order.enums.OrderStatusApiEnum; import cn.iocoder.boot.module.order.enums.OrderStatusApiEnum;
...@@ -20,14 +21,13 @@ import cn.iocoder.yudao.module.member.service.user.MemberUserService; ...@@ -20,14 +21,13 @@ import cn.iocoder.yudao.module.member.service.user.MemberUserService;
import cn.iocoder.yudao.module.member.vo.scoreRule.extra.ScoreRuleOrderVExtraVO; import cn.iocoder.yudao.module.member.vo.scoreRule.extra.ScoreRuleOrderVExtraVO;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.jetbrains.annotations.Nullable;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
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.HashMap; import java.util.*;
import java.util.List;
import java.util.Objects;
/** /**
* @author zhangfeng * @author zhangfeng
...@@ -40,14 +40,15 @@ public class OrderVStrategy extends AbstractScoreRuleStrategy { ...@@ -40,14 +40,15 @@ public class OrderVStrategy extends AbstractScoreRuleStrategy {
@Resource @Resource
private CustomerContactsService customerContactsService; private CustomerContactsService customerContactsService;
public OrderVStrategy(ScoreRuleService scoreRuleService, MemberUserScoreLogService memberUserScoreLogService, MemberUserService memberUserService,MemberUserScoreApi memberUserScoreApi) { public OrderVStrategy(ScoreRuleService scoreRuleService, MemberUserScoreLogService memberUserScoreLogService, MemberUserService memberUserService, MemberUserScoreApi memberUserScoreApi) {
super(scoreRuleService, memberUserScoreLogService, memberUserService,memberUserScoreApi); super(scoreRuleService, memberUserScoreLogService, memberUserService, memberUserScoreApi);
} }
@Override @Override
public void addScore(ScoreMessage message) { public void addScore(ScoreMessage message) {
log.info("Received order V message,orderID:{}", message.getOrderId()); log.info("Received order V message,orderID:{}", message.getOrderId());
Long orderId = message.getOrderId(); Long orderId = message.getOrderId();
// 获取订单信息
OrderRespDTO order; OrderRespDTO order;
try { try {
order = orderApi.getOrder(orderId, ""); order = orderApi.getOrder(orderId, "");
...@@ -63,116 +64,215 @@ public class OrderVStrategy extends AbstractScoreRuleStrategy { ...@@ -63,116 +64,215 @@ public class OrderVStrategy extends AbstractScoreRuleStrategy {
if (!Objects.equals(order.getStatus(), OrderStatusApiEnum.IN_SHIPPING.getValue())) { if (!Objects.equals(order.getStatus(), OrderStatusApiEnum.IN_SHIPPING.getValue())) {
return; return;
} }
// 判断海运空运 // 获取订单规则
Integer transportId = order.getTransportId(); Integer transportId = order.getTransportId();
ScoreRuleDO scoreRuleDO = scoreRuleService.getEnableScoreRuleByType(ScoreRuleTypeEnum.ORDER_V, TransportTypeEnum.parseByValue(transportId)); ScoreRuleDO scoreRuleDO = scoreRuleService.getEnableScoreRuleByType(ScoreRuleTypeEnum.ORDER_V, TransportTypeEnum.parseByValue(transportId));
if (Objects.isNull(scoreRuleDO)) { if (Objects.isNull(scoreRuleDO)) {
log.info("Order in shipping listener: No score rule match,orderID:{}", orderId); log.info("Order in shipping listener: No score rule match,orderID:{}", orderId);
return; return;
} }
// 目的地信息 // 规则是否包含目的地提货点
OrderObjectiveApiDO orderObjectiveDO = order.getOrderObjectiveDO(); OrderObjectiveApiDO orderObjectiveDO = order.getOrderObjectiveDO();
ScoreRuleOrderVExtraVO extraInfo = JSONUtil.toBean(scoreRuleDO.getExtra(), ScoreRuleOrderVExtraVO.class); ScoreRuleOrderVExtraVO extraInfo = JSONUtil.toBean(scoreRuleDO.getExtra(), ScoreRuleOrderVExtraVO.class);
// 提货点是否包含
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;
} }
// 获取需要添加积分的用户
List<Long> userIds = getAddScoreUser(order, extraInfo, scoreRuleDO);
if (CollectionUtil.isEmpty(userIds)) {
log.info("Order in shipping listener: The customer is not bound to the member or have default userId, customerId:{}", order.getCustomerId());
return;
}
// 计算积分 // 计算积分
List<ScoreRuleOrderVExtraVO.OrderVRule> orderVRules = extraInfo.getOrderVRule(); Integer scoreCount = getScoreCount(transportId, order.getChannelId(), extraInfo.getChannel(), extraInfo.getOrderVRule(), orderId);
if (scoreCount == 0) {
log.info("Order in shipping listener: The score count is less than or equal to 0,orderId:{}", orderId);
return;
}
// 增加积分
for (Long userId : userIds) {
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())
.releationId(String.valueOf(orderId))
.uniqueId(orderId + "_" + userId)
.extParam(map)
.build()
);
log.info("Order V rule add score success,ruleID:{},orderID:{},userID:{}", scoreRuleDO.getId(), message.getOrderId(), userId);
} catch (Exception e) {
log.error("Order in shipping listener: operateScore error", e);
}
}
}
/**
* 根据规则获得要加多少分
*
* @param transportId
* @param channelId
* @param allowChannels
* @param orderVRules
* @param orderId
* @return
*/
private Integer getScoreCount(Integer transportId, Long channelId, String allowChannels, List<ScoreRuleOrderVExtraVO.OrderVRule> orderVRules, Long orderId) {
Integer scoreCount = 0; Integer scoreCount = 0;
// TODO:体积和重量取的字段确认 List<OrderItemRespDTO> orderItems = orderApi.getOrderItemsByOrderId(orderId);
if (orderItems == null) {
log.info("Order in shipping listener: The order item is null,orderId:{}", orderId);
return 0;
}
BigDecimal totalWeight = BigDecimal.ZERO;
BigDecimal totalVolume = BigDecimal.ZERO;
for (OrderItemRespDTO orderItem : orderItems) {
totalWeight = totalWeight.add(orderItem.getChargeWeight());
totalVolume = totalVolume.add(orderItem.getChargeVolume());
}
if (transportId == TransportTypeEnum.OCEAN_LCL.getValue()) { if (transportId == TransportTypeEnum.OCEAN_LCL.getValue()) {
// 海运算重量 // 海运算体积
BigDecimal orgVWeight = order.getOrgVWeight(); scoreCount = computeScoreCount(totalVolume, orderVRules);
scoreCount = computeScoreCount(orgVWeight, orderVRules);
} else if (transportId == TransportTypeEnum.SPECIAL_LINE_AIR_FREIGHT.getValue()) { } else if (transportId == TransportTypeEnum.SPECIAL_LINE_AIR_FREIGHT.getValue()) {
// 空运校验渠道 // 空运校验渠道
// 渠道id // 渠道id
Long channelId = order.getChannelId(); String[] channels = allowChannels.split(",");
String[] channels = extraInfo.getChannel().split(",");
if (!ArrayUtil.contains(channels, channelId.toString())) { if (!ArrayUtil.contains(channels, channelId.toString())) {
return; return 0;
} }
// 空运算体积 // 空运算重量
BigDecimal orgWVolume = order.getOrgWVolume(); scoreCount = computeScoreCount(totalWeight, orderVRules);
scoreCount = computeScoreCount(orgWVolume, orderVRules);
} }
if (scoreCount <= 0) { return scoreCount;
log.info("Order in shipping listener: The score count is less than or equal to 0,orderId:{}", orderId);
return;
} }
// 会员id /**
* 获取需要加分的用户
*
* @param order
* @param extraInfo
* @param scoreRuleDO
* @return
*/
private List<Long> getAddScoreUser(OrderRespDTO order, ScoreRuleOrderVExtraVO extraInfo, ScoreRuleDO scoreRuleDO) {
ArrayList<Long> users = new ArrayList<>();
// 发货人和收货人都要判断给分
Long userId = order.getUserId(); Long userId = order.getUserId();
// 订单入口 Long consigneeId = order.getOrderConsigneeDO().getCustomerId();
String orderEntryString = extraInfo.getOrderEntry(); Long consigneeMemberId;
if (StringUtils.isBlank(orderEntryString)) { boolean isBackendOrder = userId <= 0;
log.info("Order in shipping listener: orderEntry is null,scoreRuleID:{}", scoreRuleDO.getId()); // 校验订单入口
return; if (!isOrderEntryValid(extraInfo.getOrderEntry(), isBackendOrder)) {
return null;
} }
String[] orderEntry = orderEntryString.split(","); // 如果是后台下单,重新获取用户ID
if (userId <= 0) { if (isBackendOrder) {
// 后台下单 userId = getCustomerMemberId(order.getCustomerId());
if (!ArrayUtil.contains(orderEntry, String.valueOf(PlatformTypeEnum.BACKEND.getValue()))) { if (userId == null) {
log.info("Order in shipping listener: The order is placed by the background, userId:{}", userId); userId = 0L;
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) { if (!isFirstOrderValid(userId, extraInfo)) {
userId = customerContact.getUserid(); return null;
} }
// 校验积分上限,添加加分用户列表
if (isBackendOrder && isUserScoreMaxed(userId, scoreRuleDO)) {
log.info("Order in shipping listener: The user has reached the maximum score, userId:{}, scoreRuleId:{}", userId, scoreRuleDO.getId());
} else {
addValidUser(users, userId);
} }
if (userId <= 0) { consigneeMemberId = getCustomerMemberId(consigneeId);
log.info("Order in shipping listener: The customer is not have default userId, customerId:{}", order.getCustomerId()); if (consigneeMemberId != null && consigneeMemberId > 0) {
return; if (consigneeMemberId.equals(userId)) {
log.info("Order in shipping listener: The consignee is the same as the sender, userId:{}", userId);
} else if (isBackendOrder && isUserScoreMaxed(consigneeMemberId, scoreRuleDO)) {
log.info("Order in shipping listener: The consignee has reached the maximum score, userId:{}, scoreRuleId:{}", consigneeMemberId, scoreRuleDO.getId());
} else {
users.add(consigneeMemberId);
} }
} 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;
} }
// 是否首单,首单只加一次 return users;
}
/**
* 校验订单入口是否有效
*/
private boolean isOrderEntryValid(String orderEntryString, boolean isBackendOrder) {
if (StringUtils.isBlank(orderEntryString)) {
log.info("Order in shipping listener: orderEntry is null");
return false;
}
String[] orderEntry = orderEntryString.split(",");
if (isBackendOrder) {
return ArrayUtil.contains(orderEntry, String.valueOf(PlatformTypeEnum.BACKEND.getValue()));
} else {
return ArrayUtil.contains(orderEntry, String.valueOf(PlatformTypeEnum.APP.getValue())) ||
ArrayUtil.contains(orderEntry, String.valueOf(PlatformTypeEnum.WEB.getValue()));
}
}
/**
* 校验是否为首单且首单是否有效
*/
private boolean isFirstOrderValid(Long userId, ScoreRuleOrderVExtraVO extraInfo) {
if (extraInfo.getFirstOrder() == YesOrNoTypeEnum.YES.ordinal()) { if (extraInfo.getFirstOrder() == YesOrNoTypeEnum.YES.ordinal()) {
if (userId == null || userId <= 0) {
log.info("Order in shipping listener: The user is not member,userId:{}", userId);
return false;
}
if (!orderApi.isFirstOrder(userId)) { if (!orderApi.isFirstOrder(userId)) {
log.info("Order in shipping listener: Not first orderuserId:{}", userId); log.info("Order in shipping listener: Not first order,userId:{}", userId);
return; return false;
} }
} }
// 校验累计最高分 return true;
// maxScoreTotal为0时为不限制积分
Integer userScoreTotalCount = getUserScoreTotalCount(scoreRuleDO.getId(), userId);
if (scoreRuleDO.getMaxScoreTotal() > 0 && 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 { private boolean isUserScoreMaxed(Long userId, ScoreRuleDO scoreRuleDO) {
HashMap<String, Object> map = new HashMap<>(); if (scoreRuleDO.getMaxScoreTotal() > 0) {
map.put("orderId", orderId); int userScoreTotalCount = getUserScoreTotalCount(scoreRuleDO.getId(), userId);
memberUserScoreApi.operateScore(MemberUserScoreOperateReqDTO.builder() return userScoreTotalCount >= scoreRuleDO.getMaxScoreTotal();
.memberId(userId)
.scoreCount(scoreCount)
.sourceType(ScoreSourceTypeEnum.ORDER_V)
.ruleId(scoreRuleDO.getId())
.expireDays(scoreRuleDO.getScorePeriod())
.releationId(String.valueOf(orderId))
.uniqueId(String.valueOf(orderId))
.extParam(map)
.build()
);
} catch (Exception e) {
log.error("Order in shipping listener: operateScore error", e);
} }
log.info("Order V rule add score success,ruleID:{},orderID:{},userID:{}", scoreRuleDO.getId(), message.getOrderId(), userId); return false;
}
/**
* 添加符合条件的用户到列表
*/
private void addValidUser(List<Long> users, Long userId) {
if (userId != null && userId > 0) {
users.add(userId);
}
}
/**
* 根据客户id获取会员id
*
* @param customerId
* @return
*/
private Long getCustomerMemberId(Long customerId) {
List<CustomerContactsDO> customerContacts = customerContactsService.getCustomerContactsListByCustomerId(customerId);
if (!CollectionUtil.isEmpty(customerContacts)) {
log.info("Order in shipping listener: The customer is not bound to the member, customerId:{}", customerId);
for (CustomerContactsDO customerContact : customerContacts) {
if (customerContact.getIsDefault() == 1 && customerContact.getUserid() != null) {
return customerContact.getUserid();
}
}
}
return null;
} }
@Override @Override
......
...@@ -415,16 +415,12 @@ public class ScoreRuleServiceImpl extends AbstractService<ScoreRuleMapper, Score ...@@ -415,16 +415,12 @@ public class ScoreRuleServiceImpl extends AbstractService<ScoreRuleMapper, Score
if (enableScoreRule == null) { if (enableScoreRule == null) {
return null; return null;
} }
scoreRuleRedisDao.setEnableScoreRule(enableScoreRule);
// 校验一下活动开始结束时间 // 校验一下活动开始结束时间
if (!enableScoreRule.getEndTime().after(new Date()) || !enableScoreRule.getStartTime().before(new Date())) {
return null;
} }
scoreRuleRedisDao.setEnableScoreRule(enableScoreRule);
} else {
if (!enableScoreRule.getEndTime().after(new Date()) || !enableScoreRule.getStartTime().before(new Date())) { if (!enableScoreRule.getEndTime().after(new Date()) || !enableScoreRule.getStartTime().before(new Date())) {
return null; return null;
} }
}
return enableScoreRule; return enableScoreRule;
} }
...@@ -439,15 +435,11 @@ public class ScoreRuleServiceImpl extends AbstractService<ScoreRuleMapper, Score ...@@ -439,15 +435,11 @@ public class ScoreRuleServiceImpl extends AbstractService<ScoreRuleMapper, Score
if (enableScoreRule == null) { if (enableScoreRule == null) {
return null; return null;
} }
if (!enableScoreRule.getEndTime().after(new Date()) || !enableScoreRule.getStartTime().before(new Date())) {
return null;
}
scoreRuleRedisDao.setEnableScoreRule(enableScoreRule); scoreRuleRedisDao.setEnableScoreRule(enableScoreRule);
} else { }
if (!enableScoreRule.getEndTime().after(new Date()) || !enableScoreRule.getStartTime().before(new Date())) { if (!enableScoreRule.getEndTime().after(new Date()) || !enableScoreRule.getStartTime().before(new Date())) {
return null; return null;
} }
}
return enableScoreRule; return enableScoreRule;
case RECOMMEND: case RECOMMEND:
case REGISTER: case REGISTER:
......
package cn.iocoder.boot.module.order.api; package cn.iocoder.boot.module.order.api;
import cn.iocoder.boot.module.order.api.dto.OrderItemRespDTO;
import cn.iocoder.boot.module.order.api.dto.OrderRespDTO; import cn.iocoder.boot.module.order.api.dto.OrderRespDTO;
import java.util.List;
/** /**
* 订单 api * 订单 api
*/ */
...@@ -14,4 +17,8 @@ public interface OrderApi { ...@@ -14,4 +17,8 @@ public interface OrderApi {
* 判断是否用户首单 * 判断是否用户首单
*/ */
boolean isFirstOrder(Long userId); boolean isFirstOrder(Long userId);
/**
* 根据订单id获取所有订单项
*/
List<OrderItemRespDTO> getOrderItemsByOrderId(Long orderId);
} }
package cn.iocoder.boot.module.order.api.dto;
import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import io.swagger.annotations.ApiModelProperty;
import lombok.*;
import org.apache.commons.lang3.StringUtils;
/**
* 订单收货人信息 DO
*
* @author 系统管理员
*/
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
@EqualsAndHashCode(callSuper = true)
@ToString(callSuper = true)
public class OrderConsigneeApiDO extends BaseDO {
/**
* 主键ID
*/
@TableId
private Long id;
/**
* 下单用户id
*/
private Long relationId;
/**
* 订单id
*/
private Long orderId;
/**
* 收货人姓名
*/
private String name;
/**
* 收货人姓名(英文)
*/
private String nameEn;
/**
* 手机
*/
private String phone;
/**
* 邮箱
*/
private String email;
/**
* 公司
*/
private String company;
/**
* 公司(英文)
*/
private String companyEn;
@ApiModelProperty(value = "收获方式:1 自提 2 送货上门 ")
private Integer harvestMethod;
@ApiModelProperty(value = "送货时间", required = true)
private String deliveryDate;
/**
* 地址
*/
private String address;
@ApiModelProperty(value = "国家")
private Long country;
@ApiModelProperty(value = "省")
private Long province;
@ApiModelProperty(value = "市")
private Long city;
/**
* 国家简称
*/
private String countryAbbreviation;
/**
* 国家区号
*/
private String countryCode;
/**
* 客户id
*/
private Long customerId;
/**
* 客户联系人id
*/
private Long customerContactsId;
public void setCountryCode(String countryCode) {
if (StringUtils.isNotBlank(countryCode)) {
this.countryCode = countryCode.replace("+", "");
}else {
this.countryCode = countryCode;
}
}
}
package cn.iocoder.boot.module.order.api.dto;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import java.math.BigDecimal;
@Data
@NoArgsConstructor
@AllArgsConstructor
public class OrderItemRespDTO {
@ApiModelProperty(value = "收费重量")
private BigDecimal chargeWeight;
@ApiModelProperty(value = "收费体积")
private BigDecimal chargeVolume;
}
...@@ -278,6 +278,11 @@ public class OrderRespDTO { ...@@ -278,6 +278,11 @@ public class OrderRespDTO {
@NotNull(message = "目的地信息不能为空") @NotNull(message = "目的地信息不能为空")
private OrderObjectiveApiDO orderObjectiveDO; private OrderObjectiveApiDO orderObjectiveDO;
@TableField(exist = false)
@ApiModelProperty(value = "收货人信息")
@NotNull(message = "收货人信息不能为空")
private OrderConsigneeApiDO orderConsigneeDO;
@TableField(exist = false) @TableField(exist = false)
@ApiModelProperty(value = "目的地ID") @ApiModelProperty(value = "目的地ID")
private Long objectiveId; private Long objectiveId;
......
package cn.iocoder.yudao.module.order.api; 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.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.OrderObjectiveApiDO;
import cn.iocoder.boot.module.order.api.dto.OrderRespDTO; import cn.iocoder.boot.module.order.api.dto.OrderRespDTO;
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.orderConsignee.OrderConsigneeDO;
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.dal.dataobject.orderObjective.OrderObjectiveDO;
import cn.iocoder.yudao.module.order.service.order.OrderConsigneeService;
import cn.iocoder.yudao.module.order.service.order.OrderObjectiveService; 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.OrderService;
import cn.iocoder.yudao.module.order.service.order.impl.OrderItemServiceImpl;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import org.springframework.beans.BeanUtils; import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.validation.annotation.Validated; import org.springframework.validation.annotation.Validated;
import javax.annotation.Resource; import javax.annotation.Resource;
import java.util.List;
import java.util.stream.Collectors;
@Service @Service
@Validated @Validated
...@@ -21,6 +30,10 @@ public class OrderApiImpl implements OrderApi { ...@@ -21,6 +30,10 @@ public class OrderApiImpl implements OrderApi {
private OrderService orderService; private OrderService orderService;
@Resource @Resource
private OrderObjectiveService objectiveService; private OrderObjectiveService objectiveService;
@Resource
private OrderConsigneeService orderConsigneeService;
@Resource
private OrderItemServiceImpl orderItemService;
@Override @Override
public OrderRespDTO getOrder(Long id, String orderNo) { public OrderRespDTO getOrder(Long id, String orderNo) {
...@@ -36,13 +49,22 @@ public class OrderApiImpl implements OrderApi { ...@@ -36,13 +49,22 @@ public class OrderApiImpl implements OrderApi {
OrderRespDTO orderRespDTO = new OrderRespDTO(); OrderRespDTO orderRespDTO = new OrderRespDTO();
BeanUtils.copyProperties(orderDO, orderRespDTO); BeanUtils.copyProperties(orderDO, orderRespDTO);
// 设置目的地信息
OrderObjectiveDO orderObjectiveDO = objectiveService.getByOrderId(id); OrderObjectiveDO orderObjectiveDO = objectiveService.getByOrderId(id);
if (orderObjectiveDO == null) { if (orderObjectiveDO != null) {
return orderRespDTO;
}
OrderObjectiveApiDO orderObjectiveApiDO = new OrderObjectiveApiDO(); OrderObjectiveApiDO orderObjectiveApiDO = new OrderObjectiveApiDO();
BeanUtils.copyProperties(orderObjectiveDO, orderObjectiveApiDO); BeanUtils.copyProperties(orderObjectiveDO, orderObjectiveApiDO);
orderRespDTO.setOrderObjectiveDO(orderObjectiveApiDO); orderRespDTO.setOrderObjectiveDO(orderObjectiveApiDO);
}
// 设置收货人信息
OrderConsigneeDO orderConsigneeByOrderId = orderConsigneeService.getOrderConsigneeByOrderId(id);
if (orderConsigneeByOrderId != null) {
OrderConsigneeApiDO orderConsigneeApiDO = new OrderConsigneeApiDO();
BeanUtils.copyProperties(orderConsigneeByOrderId, orderConsigneeApiDO);
orderRespDTO.setOrderConsigneeDO(orderConsigneeApiDO);
}
return orderRespDTO; return orderRespDTO;
} }
...@@ -51,4 +73,13 @@ public class OrderApiImpl implements OrderApi { ...@@ -51,4 +73,13 @@ public class OrderApiImpl implements OrderApi {
Long count = orderService.selectCount(new LambdaQueryWrapper<OrderDO>().eq(OrderDO::getUserId, userId)); Long count = orderService.selectCount(new LambdaQueryWrapper<OrderDO>().eq(OrderDO::getUserId, userId));
return count <= 0; return count <= 0;
} }
@Override
public List<OrderItemRespDTO> getOrderItemsByOrderId(Long orderId) {
List<OrderItemDO> orderItemDOS = orderItemService.selectList("order_id", orderId);
if (CollectionUtil.isNotEmpty(orderItemDOS)) {
return orderItemDOS.stream().map(orderItemDO -> new OrderItemRespDTO(orderItemDO.getChargeWeight(), orderItemDO.getChargeVolume())).collect(Collectors.toList());
}
return 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