Commit adba3fe8 authored by zhangfeng's avatar zhangfeng

Merge branch 'refs/heads/feature_member_score' into dev

parents 36e2eb2c 7ff95b93
...@@ -123,7 +123,9 @@ public interface WarehouseMapper extends BaseMapperX<WarehouseDO> { ...@@ -123,7 +123,9 @@ public interface WarehouseMapper extends BaseMapperX<WarehouseDO> {
@Select({ @Select({
"SELECT w.*, ", "SELECT w.*, ",
"r1.title_zh as guojiaName,", "r1.title_zh as guojiaName,",
"r2.title_zh as shiName ", "r1.title_en as guojiaNameEn,",
"r2.title_zh as shiName, ",
"r2.title_en as shiNameEn ",
"FROM ecw_warehouse w ", "FROM ecw_warehouse w ",
"LEFT JOIN ecw_region r1 ", "LEFT JOIN ecw_region r1 ",
"ON w.guojia = r1.id ", "ON w.guojia = r1.id ",
......
...@@ -9,8 +9,10 @@ import java.util.List; ...@@ -9,8 +9,10 @@ import java.util.List;
public class WarehouseTreeRegionVO extends WarehouseRespVO{ public class WarehouseTreeRegionVO extends WarehouseRespVO{
private String guojiaName ; private String guojiaName ;
private String guojiaNameEn ;
private String shiName; private String shiName;
private String shiNameEn;
private Long pid ; private Long pid ;
......
package cn.iocoder.yudao.module.member.api; package cn.iocoder.yudao.module.member.api;
import cn.iocoder.yudao.module.member.enums.ScoreRuleTypeEnum; import cn.iocoder.yudao.module.member.enums.ScoreRuleTypeEnum;
/** /**
* @author zhangfeng * @author zhangfeng
*/ */
public interface ScoreProducerApi { public interface ScoreProducerApi {
void sendOderMessage(ScoreRuleTypeEnum scoreRuleType, Long orderId); void sendOderMessage(ScoreRuleTypeEnum scoreRuleType, Long orderId);
void sendRecommendMessage(ScoreRuleTypeEnum scoreRuleType, Long userId);
void sendRegisterMessage(ScoreRuleTypeEnum scoreRuleType, Long userId); void sendRecommendMessage(ScoreRuleTypeEnum scoreRuleType, Long userId, String referralCode);
void sendRegisterMessage(ScoreRuleTypeEnum scoreRuleType, Long userId, String userNameZh, String userNameEn, String phone, Integer registerPlatform);
} }
...@@ -3,6 +3,7 @@ package cn.iocoder.yudao.module.member.enums; ...@@ -3,6 +3,7 @@ package cn.iocoder.yudao.module.member.enums;
import com.google.common.collect.Sets; import com.google.common.collect.Sets;
import java.util.Set; import java.util.Set;
import java.util.stream.Stream;
public enum ScoreSourceTypeEnum { public enum ScoreSourceTypeEnum {
MANUAL_OPERATE(1, "人工操作", null, null), MANUAL_OPERATE(1, "人工操作", null, null),
...@@ -53,4 +54,7 @@ public enum ScoreSourceTypeEnum { ...@@ -53,4 +54,7 @@ public enum ScoreSourceTypeEnum {
public static Set<ScoreSourceTypeEnum> getInvalidScoreStatusSourceType() { public static Set<ScoreSourceTypeEnum> getInvalidScoreStatusSourceType() {
return Sets.newHashSet(MANUAL_OPERATE, SYSTEM_EXPIRED); return Sets.newHashSet(MANUAL_OPERATE, SYSTEM_EXPIRED);
} }
public static ScoreSourceTypeEnum parseByValue(int value) {
return Stream.of(values()).filter(e -> e.getValue() == value).findAny().orElse(null);
}
} }
package cn.iocoder.yudao.module.member.enums; package cn.iocoder.yudao.module.member.enums;
import java.util.stream.Stream;
public enum TransportTypeEnum { public enum TransportTypeEnum {
OCEAN_LCL(1, "海运拼柜"), OCEAN_LCL(1, "海运拼柜"),
SPECIAL_LINE_AIR_FREIGHT(3, "专线空运"); SPECIAL_LINE_AIR_FREIGHT(3, "专线空运");
...@@ -20,4 +22,7 @@ public enum TransportTypeEnum { ...@@ -20,4 +22,7 @@ public enum TransportTypeEnum {
public String getName() { public String getName() {
return name; return name;
} }
public static TransportTypeEnum parseByValue(int value) {
return Stream.of(values()).filter(e -> e.getValue() == value).findAny().orElse(null);
}
} }
...@@ -59,5 +59,10 @@ ...@@ -59,5 +59,10 @@
<artifactId>yudao-module-customer-core</artifactId> <artifactId>yudao-module-customer-core</artifactId>
<version>${revision}</version> <version>${revision}</version>
</dependency> </dependency>
<dependency>
<groupId>cn.iocoder.boot</groupId>
<artifactId>yudao-module-reward-api</artifactId>
<version>${revision}</version>
</dependency>
</dependencies> </dependencies>
</project> </project>
...@@ -43,8 +43,6 @@ public class ScoreRuleController { ...@@ -43,8 +43,6 @@ public class ScoreRuleController {
@Resource @Resource
private ScoreRuleService scoreRuleService; private ScoreRuleService scoreRuleService;
@Resource @Resource
private WarehouseService warehouseService;
@Resource
private ApplicationContext applicationContext; private ApplicationContext applicationContext;
@Resource @Resource
private ScoreProducerApi scoreProducerApi; private ScoreProducerApi scoreProducerApi;
...@@ -122,10 +120,8 @@ public class ScoreRuleController { ...@@ -122,10 +120,8 @@ public class ScoreRuleController {
@GetMapping("/warehouse-tree-region-list") @GetMapping("/warehouse-tree-region-list")
@ApiOperation("获得目的国、目的城市、目的仓列表") @ApiOperation("获得目的国、目的城市、目的仓列表")
public CommonResult<List<WarehouseTreeRegionVO>> warehouseTreeRegionList() { public CommonResult<List<WarehouseTreeRegionSimpleVO>> warehouseTreeRegionList() {
List<WarehouseTreeRegionVO> listIn = warehouseService.getWarehouseTreeRegionList(1); List<WarehouseTreeRegionSimpleVO> list= scoreRuleService.getWarehouseTreeRegionListSimple();
List<WarehouseTreeRegionVO> listOut = warehouseService.getWarehouseTreeRegionList(2);
List<WarehouseTreeRegionVO> list = ListUtils.sum(listIn, listOut);
return success(list); return success(list);
} }
......
...@@ -45,5 +45,7 @@ public class AppAuthRegReqVO { ...@@ -45,5 +45,7 @@ public class AppAuthRegReqVO {
private String englishName; private String englishName;
@ApiModelProperty(value = "推荐码", required = false) @ApiModelProperty(value = "推荐码", required = false)
private String referralCode; private String referralCode;
@ApiModelProperty(value = "注册平台(2APP,3WEB)", required = true)
private Integer registerPlatform;
} }
...@@ -34,4 +34,7 @@ public class AppAuthSmsLoginReqVO { ...@@ -34,4 +34,7 @@ public class AppAuthSmsLoginReqVO {
@Pattern(regexp = "^[0-9]+$", message = "{app.auth.captcha.pattern}") @Pattern(regexp = "^[0-9]+$", message = "{app.auth.captcha.pattern}")
private String code; private String code;
@ApiModelProperty(value = "登录平台(2APP,3WEB)", required = true, example = "1")
private Integer loginPlatform;
} }
package cn.iocoder.yudao.module.member.controller.app.userScore;
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.framework.security.core.annotations.PreAuthenticated;
import cn.iocoder.yudao.module.member.api.score.MemberUserScoreApiImpl;
import cn.iocoder.yudao.module.member.controller.app.userScore.vo.AppMemberUserIdQueryVO;
import cn.iocoder.yudao.module.member.controller.app.userScore.vo.AppMemberUserScoreInfoRespVO;
import cn.iocoder.yudao.module.member.controller.app.userScore.vo.AppMemberUserScoreLogRespVO;
import cn.iocoder.yudao.module.member.service.score.MemberUserScoreService;
import cn.iocoder.yudao.module.member.service.scoreLog.MemberUserScoreLogService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import javax.annotation.Resource;
import javax.validation.Valid;
import java.util.List;
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
@Validated
@RestController
@Api(tags = "用户 APP - 会员积分")
@RequestMapping("/member/user-score")
public class AppMemberUserScoreController {
@Resource
private MemberUserScoreService userScoreService;
@Resource
private MemberUserScoreApiImpl scoreApi;
@Resource
private MemberUserScoreLogService memberUserScoreLogService;
@PostMapping("/info")
@ApiOperation("获得会员积分基本信息")
//@PreAuthenticated
public CommonResult<AppMemberUserScoreInfoRespVO> getUserScoreInfo(@Valid @RequestBody AppMemberUserIdQueryVO idQuery) {
AppMemberUserScoreInfoRespVO scoreInfo = userScoreService.getUserScoreInfo(idQuery);
return success(scoreInfo);
}
@PostMapping("/log")
@ApiOperation("获取会员积分日志列表")
//@PreAuthenticated
public CommonResult<List<AppMemberUserScoreLogRespVO>> getUserScoreLogList(@Valid @RequestBody AppMemberUserIdQueryVO query) {
return success(memberUserScoreLogService.getUserScoreLogList(query));
}
}
package cn.iocoder.yudao.module.member.controller.app.userScore.vo;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import javax.validation.constraints.NotNull;
/**
* @author zhaobiyan
*/
@Data
@ApiModel("用户 APP - 会员积分 id查询 VO")
public class AppMemberUserIdQueryVO {
@ApiModelProperty(value = "会员id")
@NotNull
private Long id;
}
\ No newline at end of file
package cn.iocoder.yudao.module.member.controller.app.userScore.vo;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
@Data
@ApiModel("用户 APP - 会员积分基本信息返回 VO")
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class AppMemberUserScoreInfoRespVO {
@ApiModelProperty(value = "会员id")
private Long id;
@ApiModelProperty(value = "当前积分")
private Integer holdScore;
@ApiModelProperty(value = "已兑换积分")
private Integer usedScore;
@ApiModelProperty(value = "历史总积分")
private Integer totalScore;
@ApiModelProperty(value = "会员等级名称")
private String levelName;
}
package cn.iocoder.yudao.module.member.controller.app.userScore.vo;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.springframework.format.annotation.DateTimeFormat;
import java.util.Date;
import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND;
@Data
@ApiModel("用户 APP - 会员积分日志返回 VO")
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class AppMemberUserScoreLogRespVO {
@ApiModelProperty(value = "积分数量")
private Integer scoreCount;
@ApiModelProperty(value = "操作类型")
private String operateType;
@ApiModelProperty(value = "积分来源")
private String sourceTypeZh;
@ApiModelProperty(value = "积分来源")
private String sourceTypeEn;
@ApiModelProperty(value = "积分规则id")
private Long ruleId;
@ApiModelProperty(value = "积分规则名称中文")
private String ruleNameZh;
@ApiModelProperty(value = "积分规则名称英文")
private String ruleNameEn;
@ApiModelProperty(value = "日志时间")
@DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND)
private Date createTime;
@ApiModelProperty(value = "描述信息中文")
private String descZh = "";
@ApiModelProperty(value = "描述信息英文")
private String descEn = "";
@ApiModelProperty(value = "礼品兑换数量")
private Integer rewardCount;
}
...@@ -95,7 +95,14 @@ public class MemberUserDO extends TenantBaseDO { ...@@ -95,7 +95,14 @@ public class MemberUserDO extends TenantBaseDO {
*/ */
private String controlPassword; private String controlPassword;
/**
* 推荐码
*/
private String referralCode; private String referralCode;
/**
* 注册平台
*/
private Integer registerPlatform;
///** ///**
// * 是否身份认证 // * 是否身份认证
......
package cn.iocoder.yudao.module.member.dal.redis;
/** /**
* 占位,后续有类后,可以删除,避免 package 无法提交到 Git 上 * Redis Key 枚举类
*/ */
package cn.iocoder.yudao.module.member.dal.redis; public interface RedisKeyConstant {
String MEMBER_USER_SCORE_RULE = "member:user:score:rule:";
}
package cn.iocoder.yudao.module.member.dal.redis.scoreRule;
import cn.iocoder.yudao.framework.common.util.json.JsonUtils;
import cn.iocoder.yudao.module.member.dal.dataobject.scoreRule.ScoreRuleDO;
import cn.iocoder.yudao.module.member.dal.redis.RedisKeyConstant;
import cn.iocoder.yudao.module.member.enums.ScoreRuleTypeEnum;
import cn.iocoder.yudao.module.member.enums.TransportTypeEnum;
import cn.iocoder.yudao.module.member.vo.scoreRule.extra.ScoreRuleOrderVExtraVO;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Repository;
import javax.annotation.Resource;
/**
* 会员积分规则 Redis DAO
*/
@Repository
public class ScoreRuleRedisDao {
@Resource
private StringRedisTemplate stringRedisTemplate;
public ScoreRuleDO getEnableScoreRule(ScoreRuleTypeEnum type, TransportTypeEnum transportType) {
// 如果transportType不为空则是订单V值类型
if (transportType == null) {
String redisKey = formatKey(type.getValue(), null);
String scoreRuleJson = stringRedisTemplate.opsForValue().get(redisKey);
if (scoreRuleJson == null) {
return null;
}
return JsonUtils.parseObject(scoreRuleJson, ScoreRuleDO.class);
} else {
String redisKey = formatKey(type.getValue(), transportType.getValue());
String scoreRuleJson = stringRedisTemplate.opsForValue().get(redisKey);
if (scoreRuleJson == null) {
return null;
}
return JsonUtils.parseObject(scoreRuleJson, ScoreRuleDO.class);
}
}
public ScoreRuleDO getEnableScoreRule(ScoreRuleTypeEnum type) {
return getEnableScoreRule(type, null);
}
public void setEnableScoreRule(ScoreRuleDO scoreRuleDO) {
// 多余字段置空
scoreRuleDO.setCreator(null);
scoreRuleDO.setUpdater(null);
scoreRuleDO.setUpdateTime(null);
scoreRuleDO.setCreateTime(null);
scoreRuleDO.setDeleted(null);
scoreRuleDO.setCoverImageEn(null);
scoreRuleDO.setCoverImageZh(null);
scoreRuleDO.setDescEn(null);
scoreRuleDO.setDescZh(null);
if (scoreRuleDO.getType() == ScoreRuleTypeEnum.ORDER_V.getValue()) {
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(), null), JsonUtils.toJsonString(scoreRuleDO));
}
public void deleteEnableScoreRule(Integer type) {
if (ScoreRuleTypeEnum.ORDER_V.getValue() == type) {
stringRedisTemplate.delete(formatKey(type, 1));
stringRedisTemplate.delete(formatKey(type, 3));
}
String redisKey = formatKey(type, null);
stringRedisTemplate.delete(redisKey);
}
private static String formatKey(Integer type, Integer transportType) {
if (transportType == null) {
return RedisKeyConstant.MEMBER_USER_SCORE_RULE + type;
}
return RedisKeyConstant.MEMBER_USER_SCORE_RULE + type + ":" + transportType;
}
}
package cn.iocoder.yudao.module.member.mq.consumer.score.core; package cn.iocoder.yudao.module.member.mq.consumer.score.core;
import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQuery; import cn.hutool.core.collection.CollUtil;
import cn.iocoder.yudao.module.member.dal.dataobject.scoreRule.ScoreRuleDO; import cn.iocoder.yudao.module.member.dal.dataobject.scoreLog.MemberUserScoreLogDO;
import cn.iocoder.yudao.module.member.enums.ScoreRuleStatusEnum; import cn.iocoder.yudao.module.member.service.scoreLog.MemberUserScoreLogService;
import cn.iocoder.yudao.module.member.enums.ScoreRuleTypeEnum;
import cn.iocoder.yudao.module.member.enums.TransportTypeEnum;
import cn.iocoder.yudao.module.member.service.scoreRule.ScoreRuleService; import cn.iocoder.yudao.module.member.service.scoreRule.ScoreRuleService;
import cn.iocoder.yudao.module.member.service.user.MemberUserService;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import java.util.Date; import java.util.List;
/** /**
* 半成品
* @author zhangfeng * @author zhangfeng
*/ */
public abstract class AbstractScoreRuleStrategy implements ScoreRuleStrategy { public abstract class AbstractScoreRuleStrategy implements ScoreRuleStrategy {
private static ScoreRuleDO orderVShipScoreRule = null;
private static ScoreRuleDO orderVFlyScoreRule = null;
private static ScoreRuleDO registerScoreRule = null;
private static ScoreRuleDO recommendScoreRule = null;
protected ScoreRuleService scoreRuleService; protected ScoreRuleService scoreRuleService;
protected MemberUserScoreLogService memberUserScoreLogService;
protected MemberUserService memberUserService;
@Autowired @Autowired
public AbstractScoreRuleStrategy(ScoreRuleService scoreRuleService) { public AbstractScoreRuleStrategy(ScoreRuleService scoreRuleService, MemberUserScoreLogService memberUserScoreLogService,MemberUserService memberUserService) {
this.scoreRuleService = scoreRuleService; this.scoreRuleService = scoreRuleService;
this.memberUserScoreLogService = memberUserScoreLogService;
this.memberUserService = memberUserService;
} }
/**
public ScoreRuleDO getEnableScoreRuleByType(ScoreRuleTypeEnum scoreRuleType) { * 计算用户在某一活动获得积分总数
ScoreRuleDO scoreRuleDO = scoreRuleService.selectOne(new LambdaQuery<ScoreRuleDO>() * @param scoreRuleId
.eq(ScoreRuleDO::getType, scoreRuleType.getValue()) * @param userId
.eq(ScoreRuleDO::getStatus, ScoreRuleStatusEnum.ENABLED.getValue())); * @return
if (scoreRuleDO != null) { */
// 校验一下活动开始结束时间 protected Integer getUserScoreTotalCount(Long scoreRuleId, Long userId) {
if (!scoreRuleDO.getEndTime().after(new Date()) || !scoreRuleDO.getStartTime().before(new Date())) { Integer userScoreTotalCount = 0;
return null; LambdaQueryWrapper<MemberUserScoreLogDO> scoreLogQueryWrapper = new LambdaQueryWrapper<>();
} else { scoreLogQueryWrapper.eq(MemberUserScoreLogDO::getMemberId, userId)
recommendScoreRule = scoreRuleDO; .eq(MemberUserScoreLogDO::getRuleId, scoreRuleId);
return recommendScoreRule; List<MemberUserScoreLogDO> memberUserScoreLogs = memberUserScoreLogService.selectList(scoreLogQueryWrapper);
if (CollUtil.isNotEmpty(memberUserScoreLogs)) {
for (MemberUserScoreLogDO memberUserScoreLog : memberUserScoreLogs) {
userScoreTotalCount += memberUserScoreLog.getScoreCount();
} }
} }
return null; return userScoreTotalCount;
}
public ScoreRuleDO getEnableScoreRuleByType(ScoreRuleTypeEnum scoreRuleType, TransportTypeEnum transportType) {
ScoreRuleDO scoreRuleDO = null;
switch (scoreRuleType) {
case ORDER_V:
scoreRuleDO = scoreRuleService.getEnabledOrderVScoreRuleByTransportType(transportType.getValue());
if (scoreRuleDO != null) {
if (!scoreRuleDO.getEndTime().after(new Date()) || !scoreRuleDO.getStartTime().before(new Date())) {
return null;
}
if (transportType == TransportTypeEnum.OCEAN_LCL) {
orderVShipScoreRule = scoreRuleDO;
return orderVShipScoreRule;
}
if (transportType == TransportTypeEnum.SPECIAL_LINE_AIR_FREIGHT) {
orderVFlyScoreRule = scoreRuleDO;
return orderVFlyScoreRule;
}
}
break;
case RECOMMEND:
case REGISTER:
return getEnableScoreRuleByType(scoreRuleType);
}
return null;
}
@Override
public void refreshScoreRule(ScoreRuleTypeEnum scoreRuleType) {
switch (scoreRuleType) {
case ORDER_V:
orderVShipScoreRule = null;
orderVFlyScoreRule = null;
break;
case RECOMMEND:
recommendScoreRule = null;
break;
case REGISTER:
registerScoreRule = null;
break;
}
} }
} }
package cn.iocoder.yudao.module.member.mq.consumer.score.core; package cn.iocoder.yudao.module.member.mq.consumer.score.core;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.collection.CollectionUtil; 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;
...@@ -12,14 +11,13 @@ import cn.iocoder.yudao.module.customer.dal.dataobject.customerContacts.Customer ...@@ -12,14 +11,13 @@ import cn.iocoder.yudao.module.customer.dal.dataobject.customerContacts.Customer
import cn.iocoder.yudao.module.customer.service.customerContacts.CustomerContactsService; 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.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.scoreLog.MemberUserScoreLogDO;
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.*; import cn.iocoder.yudao.module.member.enums.*;
import cn.iocoder.yudao.module.member.mq.message.ScoreMessage; import cn.iocoder.yudao.module.member.mq.message.ScoreMessage;
import cn.iocoder.yudao.module.member.service.scoreLog.MemberUserScoreLogService; import cn.iocoder.yudao.module.member.service.scoreLog.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.service.user.MemberUserService;
import cn.iocoder.yudao.module.member.vo.scoreRule.extra.ScoreRuleOrderVExtraVO; import cn.iocoder.yudao.module.member.vo.scoreRule.extra.ScoreRuleOrderVExtraVO;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
...@@ -27,7 +25,6 @@ import org.springframework.stereotype.Service; ...@@ -27,7 +25,6 @@ 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.Date;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Objects; import java.util.Objects;
...@@ -37,18 +34,16 @@ import java.util.Objects; ...@@ -37,18 +34,16 @@ import java.util.Objects;
*/ */
@Service @Service
@Slf4j @Slf4j
public class OderVStrategy extends AbstractScoreRuleStrategy { public class OrderVStrategy extends AbstractScoreRuleStrategy {
@Resource @Resource
private OrderApi orderApi; private OrderApi orderApi;
@Resource @Resource
private MemberUserScoreApi memberUserScoreApi; private MemberUserScoreApi memberUserScoreApi;
@Resource @Resource
private MemberUserScoreLogService memberUserScoreLogService;
@Resource
private CustomerContactsService customerContactsService; private CustomerContactsService customerContactsService;
public OderVStrategy(ScoreRuleService scoreRuleService) { public OrderVStrategy(ScoreRuleService scoreRuleService, MemberUserScoreLogService memberUserScoreLogService, MemberUserService memberUserService) {
super(scoreRuleService); super(scoreRuleService, memberUserScoreLogService, memberUserService);
} }
@Override @Override
...@@ -72,16 +67,11 @@ public class OderVStrategy extends AbstractScoreRuleStrategy { ...@@ -72,16 +67,11 @@ public class OderVStrategy extends AbstractScoreRuleStrategy {
} }
// 判断海运空运 // 判断海运空运
Integer transportId = order.getTransportId(); Integer transportId = order.getTransportId();
ScoreRuleDO scoreRuleDO = scoreRuleService.getEnabledOrderVScoreRuleByTransportType(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;
} }
// 是否过期,或者活动还没开始
if (!scoreRuleDO.getEndTime().after(new Date()) || !scoreRuleDO.getStartTime().before(new Date())) {
log.info("Order in shipping listener: The score rule has expired,scoreRuleID:{}", scoreRuleDO.getId());
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);
...@@ -156,16 +146,7 @@ public class OderVStrategy extends AbstractScoreRuleStrategy { ...@@ -156,16 +146,7 @@ public class OderVStrategy extends AbstractScoreRuleStrategy {
} }
} }
// 校验累计最高分 // 校验累计最高分
Integer userScoreTotalCount = 0; Integer userScoreTotalCount = getUserScoreTotalCount(scoreRuleDO.getId(), userId);
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()) { if (userScoreTotalCount >= scoreRuleDO.getMaxScoreTotal()) {
log.info("Order in shipping listener: The user has reached the maximum score,userId:{},scoreRuleId:{}", userId, scoreRuleDO.getId()); log.info("Order in shipping listener: The user has reached the maximum score,userId:{},scoreRuleId:{}", userId, scoreRuleDO.getId());
return; return;
...@@ -177,7 +158,6 @@ public class OderVStrategy extends AbstractScoreRuleStrategy { ...@@ -177,7 +158,6 @@ public class OderVStrategy extends AbstractScoreRuleStrategy {
try { try {
HashMap<String, Object> map = new HashMap<>(); HashMap<String, Object> map = new HashMap<>();
map.put("orderId", orderId); map.put("orderId", orderId);
// TODO:增加订单号和唯一键
memberUserScoreApi.operateScore(MemberUserScoreOperateReqDTO.builder() memberUserScoreApi.operateScore(MemberUserScoreOperateReqDTO.builder()
.memberId(userId) .memberId(userId)
.scoreCount(scoreCount) .scoreCount(scoreCount)
......
package cn.iocoder.yudao.module.member.mq.consumer.score.core; package cn.iocoder.yudao.module.member.mq.consumer.score.core;
import cn.hutool.core.collection.CollUtil;
import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQuery;
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.scoreLog.MemberUserScoreLogDO;
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.dal.dataobject.user.MemberUserDO; import cn.iocoder.yudao.module.member.dal.dataobject.user.MemberUserDO;
import cn.iocoder.yudao.module.member.enums.ScoreRuleStatusEnum;
import cn.iocoder.yudao.module.member.enums.ScoreRuleTypeEnum; import cn.iocoder.yudao.module.member.enums.ScoreRuleTypeEnum;
import cn.iocoder.yudao.module.member.enums.ScoreSourceTypeEnum; import cn.iocoder.yudao.module.member.enums.ScoreSourceTypeEnum;
import cn.iocoder.yudao.module.member.mq.message.ScoreMessage; import cn.iocoder.yudao.module.member.mq.message.ScoreMessage;
import cn.iocoder.yudao.module.member.service.scoreLog.MemberUserScoreLogService; import cn.iocoder.yudao.module.member.service.scoreLog.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.service.user.MemberUserService; import cn.iocoder.yudao.module.member.service.user.MemberUserService;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import cn.iocoder.yudao.module.member.util.ReferralCodeUtils;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import javax.annotation.Resource; import javax.annotation.Resource;
import java.util.Date;
import java.util.HashMap; import java.util.HashMap;
import java.util.List;
/** /**
* @author zhangfeng * @author zhangfeng
...@@ -33,45 +27,28 @@ public class RecommendStrategy extends AbstractScoreRuleStrategy { ...@@ -33,45 +27,28 @@ public class RecommendStrategy extends AbstractScoreRuleStrategy {
private MemberUserScoreApi memberUserScoreApi; private MemberUserScoreApi memberUserScoreApi;
@Resource @Resource
private MemberUserService memberUserService; private MemberUserService memberUserService;
@Resource
private MemberUserScoreLogService memberUserScoreLogService;
public RecommendStrategy(ScoreRuleService scoreRuleService) { public RecommendStrategy(ScoreRuleService scoreRuleService, MemberUserScoreLogService memberUserScoreLogService, MemberUserService memberUserService) {
super(scoreRuleService); super(scoreRuleService, memberUserScoreLogService, memberUserService);
} }
@Override @Override
public void addScore(ScoreMessage message) { public void addScore(ScoreMessage message) {
Long userId = message.getUserId(); // 根据推荐码获取推荐用户id
Long userId = ReferralCodeUtils.getUserId(message.getReferralCode());
log.info("Received Recommend message,userID:{}", userId); log.info("Received Recommend message,userID:{}", userId);
ScoreRuleDO scoreRuleDO = scoreRuleService.selectOne(new LambdaQuery<ScoreRuleDO>() ScoreRuleDO scoreRuleDO = scoreRuleService.getEnableScoreRuleByType(ScoreRuleTypeEnum.RECOMMEND);
.eq(ScoreRuleDO::getType, ScoreRuleTypeEnum.RECOMMEND.getValue())
.eq(ScoreRuleDO::getStatus, ScoreRuleStatusEnum.ENABLED.getValue()));
if (scoreRuleDO == null) { if (scoreRuleDO == null) {
log.info("Recommend rule is not exist,userID:{}", userId); log.info("Recommend rule is not exist,userID:{}", userId);
return; return;
} }
// 是否过期,或者活动还没开始
if (!scoreRuleDO.getEndTime().after(new Date()) || !scoreRuleDO.getStartTime().before(new Date())) {
log.info("Recommend listener: The score rule has expired,scoreRuleID:{}", scoreRuleDO.getId());
return;
}
MemberUserDO memberUserDO = memberUserService.getUser(userId); MemberUserDO memberUserDO = memberUserService.getUser(userId);
if (memberUserDO == null) { if (memberUserDO == null) {
log.info("Recommend listener: The user does not exist,userID:{}", userId); log.info("Recommend listener: The recommend user does not exist,userID:{}", userId);
return; return;
} }
// 校验累计最高分 // 校验累计最高分
Integer userScoreTotalCount = 0; Integer userScoreTotalCount = getUserScoreTotalCount(scoreRuleDO.getId(), userId);
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()) { if (userScoreTotalCount >= scoreRuleDO.getMaxScoreTotal()) {
log.info("Recommend listener: The user has reached the maximum score,userId:{},scoreRuleId:{}", userId, scoreRuleDO.getId()); log.info("Recommend listener: The user has reached the maximum score,userId:{},scoreRuleId:{}", userId, scoreRuleDO.getId());
return; return;
......
package cn.iocoder.yudao.module.member.mq.consumer.score.core; package cn.iocoder.yudao.module.member.mq.consumer.score.core;
import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQuery; import cn.iocoder.yudao.framework.common.util.json.JsonUtils;
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.dal.dataobject.user.MemberUserDO; import cn.iocoder.yudao.module.member.dal.dataobject.user.MemberUserDO;
import cn.iocoder.yudao.module.member.enums.ScoreRuleStatusEnum;
import cn.iocoder.yudao.module.member.enums.ScoreRuleTypeEnum; import cn.iocoder.yudao.module.member.enums.ScoreRuleTypeEnum;
import cn.iocoder.yudao.module.member.enums.ScoreSourceTypeEnum; import cn.iocoder.yudao.module.member.enums.ScoreSourceTypeEnum;
import cn.iocoder.yudao.module.member.mq.message.ScoreMessage; import cn.iocoder.yudao.module.member.mq.message.ScoreMessage;
import cn.iocoder.yudao.module.member.service.scoreLog.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.service.user.MemberUserService; import cn.iocoder.yudao.module.member.service.user.MemberUserService;
import cn.iocoder.yudao.module.member.vo.scoreRule.extra.ScoreRuleRegisterExtraVO;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import javax.annotation.Resource; import javax.annotation.Resource;
import java.util.Date;
import java.util.HashMap; import java.util.HashMap;
/** /**
...@@ -29,32 +29,32 @@ public class RegisterStrategy extends AbstractScoreRuleStrategy { ...@@ -29,32 +29,32 @@ public class RegisterStrategy extends AbstractScoreRuleStrategy {
@Resource @Resource
private MemberUserService memberUserService; private MemberUserService memberUserService;
public RegisterStrategy(ScoreRuleService scoreRuleService) { public RegisterStrategy(ScoreRuleService scoreRuleService, MemberUserScoreLogService memberUserScoreLogService, MemberUserService memberUserService) {
super(scoreRuleService); super(scoreRuleService, memberUserScoreLogService, memberUserService);
} }
@Override @Override
public void addScore(ScoreMessage message) { public void addScore(ScoreMessage message) {
Long userId = message.getUserId(); Long userId = message.getUserId();
log.info("Received register message,userID:{}", userId); log.info("Received register message,userID:{}", userId);
ScoreRuleDO scoreRuleDO = scoreRuleService.selectOne(new LambdaQuery<ScoreRuleDO>() ScoreRuleDO scoreRuleDO = scoreRuleService.getEnableScoreRuleByType(ScoreRuleTypeEnum.REGISTER);
.eq(ScoreRuleDO::getType, ScoreRuleTypeEnum.REGISTER.getValue())
.eq(ScoreRuleDO::getStatus, ScoreRuleStatusEnum.ENABLED.getValue()));
if (scoreRuleDO == null) { if (scoreRuleDO == null) {
log.info("Register rule is not exist,userID:{}", userId); log.info("Register rule is not exist,userID:{}", userId);
return; return;
} }
// 是否过期,或者活动还没开始
if (!scoreRuleDO.getEndTime().after(new Date()) || !scoreRuleDO.getStartTime().before(new Date())) {
log.info("Register listener: The score rule has expired,scoreRuleID:{}", scoreRuleDO.getId());
return;
}
MemberUserDO memberUserDO = memberUserService.getUser(userId); MemberUserDO memberUserDO = memberUserService.getUser(userId);
if (memberUserDO == null) { if (memberUserDO == null) {
log.info("Register listener: The user does not exist,userID:{}", userId); log.info("Register listener: The user does not exist,userID:{}", userId);
return; return;
} }
//TODO:校验注册入口,目前表没加 // 校验注册平台
ScoreRuleRegisterExtraVO scoreRuleRegisterExtraVO = JsonUtils.parseObject(scoreRuleDO.getExtra(), ScoreRuleRegisterExtraVO.class);
if (scoreRuleRegisterExtraVO != null && !"2,3".equals(scoreRuleRegisterExtraVO.getRegisterPlatform())) {
if (!scoreRuleRegisterExtraVO.getRegisterPlatform().contains(String.valueOf(message.getRegisterPlatform()))) {
log.info("Register listener: The register platform does not match,userID:{}", userId);
return;
}
}
try { try {
HashMap<String, Object> map = new HashMap<>(); HashMap<String, Object> map = new HashMap<>();
map.put("userId", userId); map.put("userId", userId);
......
...@@ -8,5 +8,4 @@ import cn.iocoder.yudao.module.member.mq.message.ScoreMessage; ...@@ -8,5 +8,4 @@ import cn.iocoder.yudao.module.member.mq.message.ScoreMessage;
public interface ScoreRuleStrategy { public interface ScoreRuleStrategy {
void addScore(ScoreMessage message); void addScore(ScoreMessage message);
ScoreRuleTypeEnum getStrategyScoreRuleType(); ScoreRuleTypeEnum getStrategyScoreRuleType();
void refreshScoreRule(ScoreRuleTypeEnum scoreRuleType);
} }
...@@ -21,7 +21,7 @@ public class ScoreMessage extends AbstractStreamMessage { ...@@ -21,7 +21,7 @@ public class ScoreMessage extends AbstractStreamMessage {
*/ */
private Long orderId; private Long orderId;
/** /**
* userID:注册,推荐必填(加分的人) * userID:注册必填
*/ */
private Long userId; private Long userId;
/** /**
...@@ -29,21 +29,25 @@ public class ScoreMessage extends AbstractStreamMessage { ...@@ -29,21 +29,25 @@ public class ScoreMessage extends AbstractStreamMessage {
*/ */
private Long recommendUserId; private Long recommendUserId;
/** /**
* 中文名:注册,推荐必填,推荐时填推荐人的信息 * 推荐码:推荐必填
*/
private String referralCode;
/**
* 中文名:注册必填
*/ */
private String userNameZh; private String userNameZh;
/** /**
* 英文名:注册,推荐必填,推荐时填推荐人的信息 * 英文名:注册必填
*/ */
private String userNameEn; private String userNameEn;
/** /**
* userID:注册,推荐必填,推荐时填推荐人的信息 * 电话:注册必填
*/ */
private String phone; private String phone;
/** /**
* 推荐码:推荐必填 * 注册平台:注册必填
*/ */
private String recommendCode; private Integer registerPlatform;
@Override @Override
public String getStreamKey() { public String getStreamKey() {
......
...@@ -8,6 +8,7 @@ import lombok.extern.slf4j.Slf4j; ...@@ -8,6 +8,7 @@ import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import javax.annotation.Resource; import javax.annotation.Resource;
/** /**
* @author zhangfeng * @author zhangfeng
*/ */
...@@ -16,6 +17,7 @@ import javax.annotation.Resource; ...@@ -16,6 +17,7 @@ import javax.annotation.Resource;
public class ScoreProducer implements ScoreProducerApi { public class ScoreProducer implements ScoreProducerApi {
@Resource @Resource
private RedisMQTemplate redisMQTemplate; private RedisMQTemplate redisMQTemplate;
@Override @Override
public void sendOderMessage(ScoreRuleTypeEnum scoreRuleType, Long orderId) { public void sendOderMessage(ScoreRuleTypeEnum scoreRuleType, Long orderId) {
ScoreMessage message = ScoreMessage.builder() ScoreMessage message = ScoreMessage.builder()
...@@ -26,12 +28,25 @@ public class ScoreProducer implements ScoreProducerApi { ...@@ -26,12 +28,25 @@ public class ScoreProducer implements ScoreProducerApi {
} }
@Override @Override
public void sendRecommendMessage(ScoreRuleTypeEnum scoreRuleType, Long userId) { public void sendRecommendMessage(ScoreRuleTypeEnum scoreRuleType, Long userId, String referralCode) {
ScoreMessage message = ScoreMessage.builder()
.scoreRuleType(scoreRuleType)
.recommendUserId(userId)
.referralCode(referralCode)
.build();
redisMQTemplate.send(message);
} }
@Override @Override
public void sendRegisterMessage(ScoreRuleTypeEnum scoreRuleType, Long userId) { public void sendRegisterMessage(ScoreRuleTypeEnum scoreRuleType, Long userId, String userNameZh, String userNameEn, String phone, Integer registerPlatform) {
ScoreMessage message = ScoreMessage.builder()
.scoreRuleType(scoreRuleType)
.userId(userId)
.userNameZh(userNameZh)
.userNameEn(userNameEn)
.phone(phone)
.registerPlatform(registerPlatform)
.build();
redisMQTemplate.send(message);
} }
} }
...@@ -13,10 +13,12 @@ import cn.iocoder.yudao.framework.security.core.authentication.MultiUsernamePass ...@@ -13,10 +13,12 @@ import cn.iocoder.yudao.framework.security.core.authentication.MultiUsernamePass
import cn.iocoder.yudao.module.ecw.api.internalMessage.ClientInternalMessageApi; import cn.iocoder.yudao.module.ecw.api.internalMessage.ClientInternalMessageApi;
import cn.iocoder.yudao.module.ecw.api.internalMessage.dto.InternalMessageCreateDto; import cn.iocoder.yudao.module.ecw.api.internalMessage.dto.InternalMessageCreateDto;
import cn.iocoder.yudao.module.ecw.api.paramValid.ParamValidatorApi; import cn.iocoder.yudao.module.ecw.api.paramValid.ParamValidatorApi;
import cn.iocoder.yudao.module.member.api.ScoreProducerApi;
import cn.iocoder.yudao.module.member.controller.app.auth.vo.*; import cn.iocoder.yudao.module.member.controller.app.auth.vo.*;
import cn.iocoder.yudao.module.member.convert.auth.AuthConvert; import cn.iocoder.yudao.module.member.convert.auth.AuthConvert;
import cn.iocoder.yudao.module.member.dal.dataobject.user.MemberUserDO; import cn.iocoder.yudao.module.member.dal.dataobject.user.MemberUserDO;
import cn.iocoder.yudao.module.member.dal.mysql.user.MemberUserMapper; import cn.iocoder.yudao.module.member.dal.mysql.user.MemberUserMapper;
import cn.iocoder.yudao.module.member.enums.ScoreRuleTypeEnum;
import cn.iocoder.yudao.module.member.enums.UserOperationLogTypeEnum; import cn.iocoder.yudao.module.member.enums.UserOperationLogTypeEnum;
import cn.iocoder.yudao.module.member.service.user.MemberUserService; import cn.iocoder.yudao.module.member.service.user.MemberUserService;
import cn.iocoder.yudao.module.member.service.userOperationLog.UserOperationLogService; import cn.iocoder.yudao.module.member.service.userOperationLog.UserOperationLogService;
...@@ -94,6 +96,8 @@ public class MemberAuthServiceImpl implements MemberAuthService { ...@@ -94,6 +96,8 @@ public class MemberAuthServiceImpl implements MemberAuthService {
@Resource @Resource
private ParamValidatorApi paramValidatorApi; private ParamValidatorApi paramValidatorApi;
@Resource
private ScoreProducerApi scoreProducerApi;
@Override @Override
public UserDetails loadUserByUsername(String mobile) throws UsernameNotFoundException { public UserDetails loadUserByUsername(String mobile) throws UsernameNotFoundException {
...@@ -111,13 +115,13 @@ public class MemberAuthServiceImpl implements MemberAuthService { ...@@ -111,13 +115,13 @@ public class MemberAuthServiceImpl implements MemberAuthService {
// 校验验证码 // 校验验证码
smsCodeApi.useSmsCode(AuthConvert.INSTANCE.convert(reqVO, SmsSceneEnum.MEMBER_REG.getScene(), userIp)); smsCodeApi.useSmsCode(AuthConvert.INSTANCE.convert(reqVO, SmsSceneEnum.MEMBER_REG.getScene(), userIp));
MemberUserDO userByMobile = userService.checkPhoneUnique(reqVO.getAreaCode(),reqVO.getMobile()); MemberUserDO userByMobile = userService.checkPhoneUnique(reqVO.getAreaCode(), reqVO.getMobile());
if (userByMobile != null) { if (userByMobile != null) {
throw exception(MEMBER_USER_MOBILE_EXIST); throw exception(MEMBER_USER_MOBILE_EXIST);
} }
// 获得获得注册用户 // 获得获得注册用户
MemberUserDO user = userService.createUser(reqVO.getMobile(), userIp, reqVO.getPassword(),reqVO.getAreaCode(), reqVO.getEnglishName(), reqVO.getReferralCode()); MemberUserDO user = userService.createUser(reqVO.getMobile(), userIp, reqVO.getPassword(), reqVO.getAreaCode(), reqVO.getEnglishName(), reqVO.getReferralCode(), reqVO.getRegisterPlatform());
Assert.notNull(user, "创建用户失败,结果为空"); Assert.notNull(user, "创建用户失败,结果为空");
//记录日志 //记录日志
...@@ -140,8 +144,8 @@ public class MemberAuthServiceImpl implements MemberAuthService { ...@@ -140,8 +144,8 @@ public class MemberAuthServiceImpl implements MemberAuthService {
@Override @Override
public boolean checkPhoneUnique(String areaCode, String mobile) { public boolean checkPhoneUnique(String areaCode, String mobile) {
MemberUserDO memberUserDO=userService.checkPhoneUnique(areaCode,mobile); MemberUserDO memberUserDO = userService.checkPhoneUnique(areaCode, mobile);
return memberUserDO!=null; return memberUserDO != null;
} }
@Override @Override
...@@ -160,7 +164,7 @@ public class MemberAuthServiceImpl implements MemberAuthService { ...@@ -160,7 +164,7 @@ public class MemberAuthServiceImpl implements MemberAuthService {
smsCodeApi.useSmsCode(AuthConvert.INSTANCE.convert(reqVO, SmsSceneEnum.MEMBER_LOGIN.getScene(), userIp)); smsCodeApi.useSmsCode(AuthConvert.INSTANCE.convert(reqVO, SmsSceneEnum.MEMBER_LOGIN.getScene(), userIp));
// 获得获得注册用户 // 获得获得注册用户
MemberUserDO user = userService.createUserIfAbsent(reqVO.getMobile(),reqVO.getAreaCode(), userIp); MemberUserDO user = userService.createUserIfAbsent(reqVO.getMobile(), reqVO.getAreaCode(), userIp, reqVO.getLoginPlatform());
Assert.notNull(user, "获取用户失败,结果为空"); Assert.notNull(user, "获取用户失败,结果为空");
// 执行登陆 // 执行登陆
...@@ -273,6 +277,9 @@ public class MemberAuthServiceImpl implements MemberAuthService { ...@@ -273,6 +277,9 @@ public class MemberAuthServiceImpl implements MemberAuthService {
loginLogApi.createLoginLog(reqDTO); loginLogApi.createLoginLog(reqDTO);
// 更新最后登录时间 // 更新最后登录时间
if (user != null && Objects.equals(LoginResultEnum.SUCCESS.getResult(), loginResult.getResult())) { if (user != null && Objects.equals(LoginResultEnum.SUCCESS.getResult(), loginResult.getResult())) {
// 注册,推荐积分规则触发判断
scoreRuleCheck(user);
userService.updateUserLogin(user.getId(), getClientIP()); userService.updateUserLogin(user.getId(), getClientIP());
} }
...@@ -452,14 +459,14 @@ public class MemberAuthServiceImpl implements MemberAuthService { ...@@ -452,14 +459,14 @@ public class MemberAuthServiceImpl implements MemberAuthService {
@Override @Override
public void sendEmailCode(Long loginUserId, AppEmailReqVO reqVO) { public void sendEmailCode(Long loginUserId, AppEmailReqVO reqVO) {
MemberUserDO userVo = userService.getUserByEmail(reqVO.getEmail()); MemberUserDO userVo = userService.getUserByEmail(reqVO.getEmail());
if(userVo!=null){ if (userVo != null) {
throw exception(USER_EMAIL_ALREADY_EXISTS); throw exception(USER_EMAIL_ALREADY_EXISTS);
} }
MemberUserDO user = userService.getUser(loginUserId); MemberUserDO user = userService.getUser(loginUserId);
Map<String,String> tempalteParam = new HashMap<>(); Map<String, String> tempalteParam = new HashMap<>();
tempalteParam.put("name",user.getEnglishName()); tempalteParam.put("name", user.getEnglishName());
//todo 生成验证码逻辑 //todo 生成验证码逻辑
tempalteParam.put("code","9999"); tempalteParam.put("code", "9999");
tempalteParam.put("date", DateUtils.getDate()); tempalteParam.put("date", DateUtils.getDate());
MailTemplateSendReqVO reqVO1 = new MailTemplateSendReqVO(); MailTemplateSendReqVO reqVO1 = new MailTemplateSendReqVO();
reqVO1.setTemplateCode("bindEmail"); reqVO1.setTemplateCode("bindEmail");
...@@ -489,11 +496,11 @@ public class MemberAuthServiceImpl implements MemberAuthService { ...@@ -489,11 +496,11 @@ public class MemberAuthServiceImpl implements MemberAuthService {
if (user == null) { if (user == null) {
throw exception(USER_NOT_EXISTS); throw exception(USER_NOT_EXISTS);
} }
if(StringUtils.isBlank(user.getPassword())){ if (StringUtils.isBlank(user.getPassword())) {
return user; return user;
} }
// 参数:未加密密码,编码后的密码 // 参数:未加密密码,编码后的密码
if (!passwordEncoder.matches(oldPassword,user.getPassword())) { if (!passwordEncoder.matches(oldPassword, user.getPassword())) {
throw exception(USER_PASSWORD_FAILED); throw exception(USER_PASSWORD_FAILED);
} }
return user; return user;
...@@ -512,11 +519,11 @@ public class MemberAuthServiceImpl implements MemberAuthService { ...@@ -512,11 +519,11 @@ public class MemberAuthServiceImpl implements MemberAuthService {
if (user == null) { if (user == null) {
throw exception(USER_NOT_EXISTS); throw exception(USER_NOT_EXISTS);
} }
if(StringUtils.isBlank(user.getControlPassword())){ if (StringUtils.isBlank(user.getControlPassword())) {
return user; return user;
} }
// 参数:未加密密码,编码后的密码 // 参数:未加密密码,编码后的密码
if (!passwordEncoder.matches(oldPassword,user.getControlPassword())) { if (!passwordEncoder.matches(oldPassword, user.getControlPassword())) {
throw exception(USER_PASSWORD_FAILED); throw exception(USER_PASSWORD_FAILED);
} }
return user; return user;
...@@ -543,4 +550,16 @@ public class MemberAuthServiceImpl implements MemberAuthService { ...@@ -543,4 +550,16 @@ public class MemberAuthServiceImpl implements MemberAuthService {
loginLogApi.createLoginLog(reqDTO); loginLogApi.createLoginLog(reqDTO);
} }
private void scoreRuleCheck(MemberUserDO user) {
// 首次登陆发获取注册积分
if (user.getLoginDate() == null) {
scoreProducerApi.sendRegisterMessage(ScoreRuleTypeEnum.REGISTER, user.getId(), user.getNickname(), user.getEnglishName(), user.getMobile(), user.getRegisterPlatform());
}
// 首次登陆且有推荐码获取推荐积分
if (user.getLoginDate() == null && user.getReferralCode() != null) {
scoreProducerApi.sendRecommendMessage(ScoreRuleTypeEnum.RECOMMEND, user.getId(), user.getReferralCode());
}
}
} }
...@@ -4,6 +4,8 @@ import java.util.*; ...@@ -4,6 +4,8 @@ import java.util.*;
import cn.iocoder.yudao.framework.mybatis.core.service.IService; import cn.iocoder.yudao.framework.mybatis.core.service.IService;
import cn.iocoder.yudao.module.member.api.score.dto.MemberUserScoreUpdateReqDTO; import cn.iocoder.yudao.module.member.api.score.dto.MemberUserScoreUpdateReqDTO;
import cn.iocoder.yudao.module.member.controller.app.userScore.vo.AppMemberUserIdQueryVO;
import cn.iocoder.yudao.module.member.controller.app.userScore.vo.AppMemberUserScoreInfoRespVO;
import cn.iocoder.yudao.module.member.vo.memberUserScore.*; import cn.iocoder.yudao.module.member.vo.memberUserScore.*;
import cn.iocoder.yudao.module.member.dal.dataobject.score.MemberUserScoreDO; import cn.iocoder.yudao.module.member.dal.dataobject.score.MemberUserScoreDO;
import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.framework.common.pojo.PageResult;
...@@ -50,4 +52,11 @@ public interface MemberUserScoreService extends IService<MemberUserScoreDO> { ...@@ -50,4 +52,11 @@ public interface MemberUserScoreService extends IService<MemberUserScoreDO> {
List<MemberUserScoreDO> getUserScoreList(MemberUserScoreQueryVO query); List<MemberUserScoreDO> getUserScoreList(MemberUserScoreQueryVO query);
void updateUserScore(MemberUserScoreUpdateReqDTO query); void updateUserScore(MemberUserScoreUpdateReqDTO query);
/**
* 获取会员积分及会员等级信息
* @param id
* @return
*/
AppMemberUserScoreInfoRespVO getUserScoreInfo(AppMemberUserIdQueryVO id);
} }
...@@ -3,12 +3,16 @@ package cn.iocoder.yudao.module.member.service.score; ...@@ -3,12 +3,16 @@ package cn.iocoder.yudao.module.member.service.score;
import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.mybatis.core.service.AbstractService; import cn.iocoder.yudao.framework.mybatis.core.service.AbstractService;
import cn.iocoder.yudao.module.member.api.score.dto.MemberUserScoreUpdateReqDTO; import cn.iocoder.yudao.module.member.api.score.dto.MemberUserScoreUpdateReqDTO;
import cn.iocoder.yudao.module.member.controller.app.userScore.vo.AppMemberUserIdQueryVO;
import cn.iocoder.yudao.module.member.controller.app.userScore.vo.AppMemberUserScoreInfoRespVO;
import cn.iocoder.yudao.module.member.dal.dataobject.score.MemberUserScoreDO; import cn.iocoder.yudao.module.member.dal.dataobject.score.MemberUserScoreDO;
import cn.iocoder.yudao.module.member.dal.mysql.memberUserScore.MemberUserScoreMapper; import cn.iocoder.yudao.module.member.dal.mysql.memberUserScore.MemberUserScoreMapper;
import cn.iocoder.yudao.module.member.enums.ScoreOperateTypeEnum; import cn.iocoder.yudao.module.member.enums.ScoreOperateTypeEnum;
import cn.iocoder.yudao.module.member.enums.ScoreSourceTypeEnum; import cn.iocoder.yudao.module.member.enums.ScoreSourceTypeEnum;
import cn.iocoder.yudao.module.member.service.level.MemberUserLevelConfigService;
import cn.iocoder.yudao.module.member.vo.memberUserScore.MemberUserScoreBackVO; import cn.iocoder.yudao.module.member.vo.memberUserScore.MemberUserScoreBackVO;
import cn.iocoder.yudao.module.member.vo.memberUserScore.MemberUserScoreQueryVO; import cn.iocoder.yudao.module.member.vo.memberUserScore.MemberUserScoreQueryVO;
import cn.iocoder.yudao.module.member.vo.userLevel.MemberUserLevelConfigBaseRespVO;
import org.springframework.context.annotation.Lazy; import org.springframework.context.annotation.Lazy;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.validation.annotation.Validated; import org.springframework.validation.annotation.Validated;
...@@ -34,6 +38,8 @@ public class MemberUserScoreServiceImpl extends AbstractService<MemberUserScoreM ...@@ -34,6 +38,8 @@ public class MemberUserScoreServiceImpl extends AbstractService<MemberUserScoreM
@Resource @Resource
private MemberUserScoreMapper userScoreMapper; private MemberUserScoreMapper userScoreMapper;
@Resource
private MemberUserLevelConfigService memberUserLevelConfigService;
@Override @Override
public void deleteUserScore(Long id) { public void deleteUserScore(Long id) {
...@@ -103,6 +109,26 @@ public class MemberUserScoreServiceImpl extends AbstractService<MemberUserScoreM ...@@ -103,6 +109,26 @@ public class MemberUserScoreServiceImpl extends AbstractService<MemberUserScoreM
} }
} }
@Override
public AppMemberUserScoreInfoRespVO getUserScoreInfo(AppMemberUserIdQueryVO id) {
MemberUserScoreDO userScoreDO = userScoreMapper.getByMemberId(id.getId());
if (userScoreDO == null) {
throw exception(MEMBER_ID_IS_NULL);
}
Integer userScoreTotal = userScoreDO.getHoldScore() + userScoreDO.getUsedScore() + userScoreDO.getExpiredScore();
AppMemberUserScoreInfoRespVO infoRespVO = AppMemberUserScoreInfoRespVO.builder()
.holdScore(userScoreDO.getHoldScore())
.id(userScoreDO.getId())
.totalScore(userScoreTotal)
.usedScore(userScoreDO.getUsedScore())
.build();
MemberUserLevelConfigBaseRespVO level = memberUserLevelConfigService.getLevelByCount(userScoreTotal);
if (level != null) {
infoRespVO.setLevelName(level.getName());
}
return infoRespVO;
}
private MemberUserScoreDO initMemberUserScore(Long memberId) { private MemberUserScoreDO initMemberUserScore(Long memberId) {
MemberUserScoreDO memberUserScoreDO = new MemberUserScoreDO(); MemberUserScoreDO memberUserScoreDO = new MemberUserScoreDO();
memberUserScoreDO.setMemberId(memberId); memberUserScoreDO.setMemberId(memberId);
......
...@@ -2,11 +2,15 @@ package cn.iocoder.yudao.module.member.service.scoreLog; ...@@ -2,11 +2,15 @@ package cn.iocoder.yudao.module.member.service.scoreLog;
import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.mybatis.core.service.IService; import cn.iocoder.yudao.framework.mybatis.core.service.IService;
import cn.iocoder.yudao.module.member.controller.app.userScore.vo.AppMemberUserIdQueryVO;
import cn.iocoder.yudao.module.member.controller.app.userScore.vo.AppMemberUserScoreLogRespVO;
import cn.iocoder.yudao.module.member.dal.dataobject.scoreLog.MemberUserScoreLogDO; import cn.iocoder.yudao.module.member.dal.dataobject.scoreLog.MemberUserScoreLogDO;
import cn.iocoder.yudao.module.member.vo.memberUserScoreLog.MemberUserScoreLogBackVO; import cn.iocoder.yudao.module.member.vo.memberUserScoreLog.MemberUserScoreLogBackVO;
import cn.iocoder.yudao.module.member.vo.memberUserScoreLog.MemberUserScoreLogCreateReq; import cn.iocoder.yudao.module.member.vo.memberUserScoreLog.MemberUserScoreLogCreateReq;
import cn.iocoder.yudao.module.member.vo.memberUserScoreLog.MemberUserScoreLogQueryVO; import cn.iocoder.yudao.module.member.vo.memberUserScoreLog.MemberUserScoreLogQueryVO;
import java.util.List;
/** /**
* 会员积分日志 Service 接口 * 会员积分日志 Service 接口
* *
...@@ -19,4 +23,6 @@ public interface MemberUserScoreLogService extends IService<MemberUserScoreLogDO ...@@ -19,4 +23,6 @@ public interface MemberUserScoreLogService extends IService<MemberUserScoreLogDO
Long createScoreLog(MemberUserScoreLogCreateReq createReq); Long createScoreLog(MemberUserScoreLogCreateReq createReq);
MemberUserScoreLogDO getByUniqueId(String uniqueId); MemberUserScoreLogDO getByUniqueId(String uniqueId);
List<AppMemberUserScoreLogRespVO> getUserScoreLogList(AppMemberUserIdQueryVO query);
} }
...@@ -3,12 +3,22 @@ package cn.iocoder.yudao.module.member.service.scoreLog; ...@@ -3,12 +3,22 @@ package cn.iocoder.yudao.module.member.service.scoreLog;
import cn.hutool.core.lang.generator.SnowflakeGenerator; import cn.hutool.core.lang.generator.SnowflakeGenerator;
import cn.hutool.json.JSONUtil; import cn.hutool.json.JSONUtil;
import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.util.json.JsonUtils;
import cn.iocoder.yudao.framework.dict.core.util.DictFrameworkUtils;
import cn.iocoder.yudao.framework.mybatis.core.service.AbstractService; import cn.iocoder.yudao.framework.mybatis.core.service.AbstractService;
import cn.iocoder.yudao.module.member.controller.app.userScore.vo.AppMemberUserIdQueryVO;
import cn.iocoder.yudao.module.member.controller.app.userScore.vo.AppMemberUserScoreLogRespVO;
import cn.iocoder.yudao.module.member.dal.dataobject.scoreLog.MemberUserScoreLogDO; import cn.iocoder.yudao.module.member.dal.dataobject.scoreLog.MemberUserScoreLogDO;
import cn.iocoder.yudao.module.member.dal.mysql.memberUserScoreLog.MemberUserScoreLogMapper; import cn.iocoder.yudao.module.member.dal.mysql.memberUserScoreLog.MemberUserScoreLogMapper;
import cn.iocoder.yudao.module.member.enums.ScoreOperateTypeEnum;
import cn.iocoder.yudao.module.member.enums.ScoreSourceTypeEnum;
import cn.iocoder.yudao.module.member.service.scoreRule.ScoreRuleService;
import cn.iocoder.yudao.module.member.vo.memberUserScoreLog.MemberUserScoreLogBackVO; import cn.iocoder.yudao.module.member.vo.memberUserScoreLog.MemberUserScoreLogBackVO;
import cn.iocoder.yudao.module.member.vo.memberUserScoreLog.MemberUserScoreLogCreateReq; import cn.iocoder.yudao.module.member.vo.memberUserScoreLog.MemberUserScoreLogCreateReq;
import cn.iocoder.yudao.module.member.vo.memberUserScoreLog.MemberUserScoreLogQueryVO; import cn.iocoder.yudao.module.member.vo.memberUserScoreLog.MemberUserScoreLogQueryVO;
import cn.iocoder.yudao.module.member.vo.scoreRule.ScoreRuleBackDetailVO;
import cn.iocoder.yudao.module.reward.api.reward.RedeemRewardApi;
import cn.iocoder.yudao.module.reward.api.reward.dto.RedeemDetailForUserDTO;
import cn.iocoder.yudao.module.system.service.dict.DictTypeService; import cn.iocoder.yudao.module.system.service.dict.DictTypeService;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers; import com.baomidou.mybatisplus.core.toolkit.Wrappers;
...@@ -16,7 +26,7 @@ import org.springframework.stereotype.Service; ...@@ -16,7 +26,7 @@ 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.*;
import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
import static cn.iocoder.yudao.module.member.enums.ErrorCodeConstants.MEMBER_ID_IS_NULL; import static cn.iocoder.yudao.module.member.enums.ErrorCodeConstants.MEMBER_ID_IS_NULL;
...@@ -32,12 +42,12 @@ public class MemberUserScoreLogServiceImpl extends AbstractService<MemberUserSco ...@@ -32,12 +42,12 @@ public class MemberUserScoreLogServiceImpl extends AbstractService<MemberUserSco
@Resource @Resource
private MemberUserScoreLogMapper userScoreLogMapper; private MemberUserScoreLogMapper userScoreLogMapper;
@Resource
private DictTypeService dictTypeService;
@Resource @Resource
private SnowflakeGenerator snowflakeGenerator; private SnowflakeGenerator snowflakeGenerator;
@Resource
private ScoreRuleService scoreRuleService;
@Resource
RedeemRewardApi redeemRewardApi;
@Override @Override
...@@ -75,4 +85,95 @@ public class MemberUserScoreLogServiceImpl extends AbstractService<MemberUserSco ...@@ -75,4 +85,95 @@ public class MemberUserScoreLogServiceImpl extends AbstractService<MemberUserSco
wrapper.eq(MemberUserScoreLogDO::getUniqueId, uniqueId); wrapper.eq(MemberUserScoreLogDO::getUniqueId, uniqueId);
return this.selectOne(wrapper); return this.selectOne(wrapper);
} }
@Override
public List<AppMemberUserScoreLogRespVO> getUserScoreLogList(AppMemberUserIdQueryVO query) {
List<MemberUserScoreLogDO> userScoreLogDOS = userScoreLogMapper.selectList("member_id", query.getId());
if (userScoreLogDOS == null || userScoreLogDOS.isEmpty()) {
return Collections.EMPTY_LIST;
}
ArrayList<AppMemberUserScoreLogRespVO> appMemberUserScoreLogRespVOS = new ArrayList<>();
for (MemberUserScoreLogDO userScoreLogDO : userScoreLogDOS) {
setScoreRuleLogDetail(userScoreLogDO, appMemberUserScoreLogRespVOS);
}
return appMemberUserScoreLogRespVOS;
}
private void setScoreRuleLogDetail(MemberUserScoreLogDO userScoreLogDO, ArrayList<AppMemberUserScoreLogRespVO> appMemberUserScoreLogRespVOS) {
AppMemberUserScoreLogRespVO appMemberUserScoreLogRespVO = new AppMemberUserScoreLogRespVO();
appMemberUserScoreLogRespVO.setScoreCount(userScoreLogDO.getScoreCount());
appMemberUserScoreLogRespVO.setOperateType(userScoreLogDO.getOperateType() == 1 ? "+" : "-");
appMemberUserScoreLogRespVO.setCreateTime(userScoreLogDO.getCreateTime());
// 增加积分日志
if (Objects.equals(userScoreLogDO.getOperateType(), ScoreOperateTypeEnum.ADD.getValue())) {
switch (userScoreLogDO.getSourceType()) {
// 人工操作
case 1:
appMemberUserScoreLogRespVO.setSourceTypeZh(DictFrameworkUtils.getDictDataFromCache("member_score_source", "1").getLabel());
appMemberUserScoreLogRespVO.setSourceTypeEn(DictFrameworkUtils.getDictDataFromCache("member_score_source", "1").getLabelEn());
appMemberUserScoreLogRespVO.setDescZh("人工积分");
appMemberUserScoreLogRespVO.setDescEn("Manually add points");
break;
// 撤销兑换
case 4:
appMemberUserScoreLogRespVO.setSourceTypeZh(DictFrameworkUtils.getDictDataFromCache("member_score_source", "4").getLabel());
appMemberUserScoreLogRespVO.setSourceTypeEn(DictFrameworkUtils.getDictDataFromCache("member_score_source", "4").getLabelEn());
// TODO:补充描述
appMemberUserScoreLogRespVO.setDescZh(DictFrameworkUtils.getDictDataFromCache("member_score_source", "4").getLabel());
appMemberUserScoreLogRespVO.setDescEn(DictFrameworkUtils.getDictDataFromCache("member_score_source", "4").getLabelEn());
break;
// 活动积分
case 5:
case 6:
case 7:
case 8:
ScoreSourceTypeEnum scoreSourceTypeEnum = ScoreSourceTypeEnum.parseByValue(userScoreLogDO.getSourceType());
appMemberUserScoreLogRespVO.setSourceTypeZh(DictFrameworkUtils.getDictDataFromCache("member_score_source", String.valueOf(scoreSourceTypeEnum.getValue())).getLabel());
appMemberUserScoreLogRespVO.setSourceTypeEn(DictFrameworkUtils.getDictDataFromCache("member_score_source", String.valueOf(scoreSourceTypeEnum.getValue())).getLabelEn());
ScoreRuleBackDetailVO scoreRule = scoreRuleService.getScoreRule(userScoreLogDO.getRuleId());
if (scoreRule != null) {
appMemberUserScoreLogRespVO.setRuleId(userScoreLogDO.getRuleId());
appMemberUserScoreLogRespVO.setRuleNameEn(scoreRule.getTitleEn());
appMemberUserScoreLogRespVO.setRuleNameZh(scoreRule.getTitleZh());
appMemberUserScoreLogRespVO.setDescEn(scoreRule.getDescEn());
appMemberUserScoreLogRespVO.setDescZh(scoreRule.getDescZh());
}
break;
}
} else {
// 减少积分日志
switch (userScoreLogDO.getSourceType()) {
// 人工操作
case 1:
appMemberUserScoreLogRespVO.setSourceTypeZh(DictFrameworkUtils.getDictDataFromCache("member_score_source", "1").getLabel());
appMemberUserScoreLogRespVO.setSourceTypeEn(DictFrameworkUtils.getDictDataFromCache("member_score_source", "1").getLabelEn());
appMemberUserScoreLogRespVO.setDescZh("人工积分");
appMemberUserScoreLogRespVO.setDescEn("Manually reduce points");
break;
// 兑换
case 2:
appMemberUserScoreLogRespVO.setSourceTypeZh(DictFrameworkUtils.getDictDataFromCache("member_score_source", "2").getLabel());
appMemberUserScoreLogRespVO.setSourceTypeEn(DictFrameworkUtils.getDictDataFromCache("member_score_source", "2").getLabelEn());
// 查询兑换记录
Map<String, Long> extParam = JsonUtils.parseObject(userScoreLogDO.getExtParam(), HashMap.class);
Long redeemId = extParam.get("redeemId");
if (redeemId != null) {
RedeemDetailForUserDTO redeemDetailForUser = redeemRewardApi.getRedeemDetailForUser(redeemId);
if (redeemDetailForUser != null) {
appMemberUserScoreLogRespVO.setRewardCount(redeemDetailForUser.getRewardCount());
appMemberUserScoreLogRespVO.setDescZh(redeemDetailForUser.getRewardNameZh());
appMemberUserScoreLogRespVO.setDescEn(redeemDetailForUser.getRewardNameEn());
}
}
break;
// 系统过期
case 3:
appMemberUserScoreLogRespVO.setSourceTypeZh(DictFrameworkUtils.getDictDataFromCache("member_score_source", "3").getLabel());
appMemberUserScoreLogRespVO.setSourceTypeEn(DictFrameworkUtils.getDictDataFromCache("member_score_source", "3").getLabelEn());
appMemberUserScoreLogRespVO.setDescZh("系统过期");
appMemberUserScoreLogRespVO.setDescEn("System expiration");
}
}
appMemberUserScoreLogRespVOS.add(appMemberUserScoreLogRespVO);
}
} }
...@@ -7,6 +7,8 @@ import cn.iocoder.yudao.framework.common.pojo.PageResult; ...@@ -7,6 +7,8 @@ import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.mybatis.core.service.IService; import cn.iocoder.yudao.framework.mybatis.core.service.IService;
import cn.iocoder.yudao.framework.mybatis.core.vo.PageVO; import cn.iocoder.yudao.framework.mybatis.core.vo.PageVO;
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.ScoreRuleTypeEnum;
import cn.iocoder.yudao.module.member.enums.TransportTypeEnum;
import cn.iocoder.yudao.module.member.vo.scoreRule.*; import cn.iocoder.yudao.module.member.vo.scoreRule.*;
/** /**
...@@ -18,6 +20,7 @@ public interface ScoreRuleService extends IService<ScoreRuleDO> { ...@@ -18,6 +20,7 @@ public interface ScoreRuleService extends IService<ScoreRuleDO> {
/** /**
* 创建积分规则 * 创建积分规则
*
* @param createReqVO 创建信息 * @param createReqVO 创建信息
* @return 编号 * @return 编号
*/ */
...@@ -25,12 +28,14 @@ public interface ScoreRuleService extends IService<ScoreRuleDO> { ...@@ -25,12 +28,14 @@ public interface ScoreRuleService extends IService<ScoreRuleDO> {
/** /**
* 更新积分规则 * 更新积分规则
*
* @param updateReqVO 更新信息 * @param updateReqVO 更新信息
*/ */
void updateScoreRule(@Valid ScoreRuleUpdateReqVO updateReqVO); void updateScoreRule(@Valid ScoreRuleUpdateReqVO updateReqVO);
/** /**
* 删除积分规则 * 删除积分规则
*
* @param id 编号 * @param id 编号
*/ */
void deleteScoreRule(Long id); void deleteScoreRule(Long id);
...@@ -62,6 +67,7 @@ public interface ScoreRuleService extends IService<ScoreRuleDO> { ...@@ -62,6 +67,7 @@ public interface ScoreRuleService extends IService<ScoreRuleDO> {
/** /**
* 获得积分规则列表, 用于 Excel 导出 * 获得积分规则列表, 用于 Excel 导出
*
* @param query 查询 * @param query 查询
* @return 积分规则列表 * @return 积分规则列表
*/ */
...@@ -69,6 +75,7 @@ public interface ScoreRuleService extends IService<ScoreRuleDO> { ...@@ -69,6 +75,7 @@ public interface ScoreRuleService extends IService<ScoreRuleDO> {
/** /**
* 积分规则启用关闭 * 积分规则启用关闭
*
* @param scoreRuleStatusReqVO 积分规则状态 * @param scoreRuleStatusReqVO 积分规则状态
* @return * @return
*/ */
...@@ -76,6 +83,7 @@ public interface ScoreRuleService extends IService<ScoreRuleDO> { ...@@ -76,6 +83,7 @@ public interface ScoreRuleService extends IService<ScoreRuleDO> {
/** /**
* 积分规则复制 * 积分规则复制
*
* @param id * @param id
* @return * @return
*/ */
...@@ -83,6 +91,7 @@ public interface ScoreRuleService extends IService<ScoreRuleDO> { ...@@ -83,6 +91,7 @@ public interface ScoreRuleService extends IService<ScoreRuleDO> {
/** /**
* 积分规则延期 * 积分规则延期
*
* @param scoreDelayReqVO 积分规则延期 * @param scoreDelayReqVO 积分规则延期
* @return * @return
*/ */
...@@ -90,8 +99,26 @@ public interface ScoreRuleService extends IService<ScoreRuleDO> { ...@@ -90,8 +99,26 @@ public interface ScoreRuleService extends IService<ScoreRuleDO> {
/** /**
* 根据运输方式获取已启用订单V值规则 * 根据运输方式获取已启用订单V值规则
*
* @param transportType * @param transportType
* @return * @return
*/ */
ScoreRuleDO getEnabledOrderVScoreRuleByTransportType(Integer transportType); ScoreRuleDO getEnabledOrderVScoreRuleByTransportType(Integer transportType);
/**
* 根据类型获取已启用积分规则
* @param scoreRuleType
* @return
*/
ScoreRuleDO getEnableScoreRuleByType(ScoreRuleTypeEnum scoreRuleType);
/**
* 根据类型获取已启用积分规则(带运输类型)
* @param scoreRuleType
* @param transportType
* @return
*/
ScoreRuleDO getEnableScoreRuleByType(ScoreRuleTypeEnum scoreRuleType, TransportTypeEnum transportType);
List<WarehouseTreeRegionSimpleVO> getWarehouseTreeRegionListSimple();
} }
...@@ -29,9 +29,10 @@ public interface MemberUserService { ...@@ -29,9 +29,10 @@ public interface MemberUserService {
* @return 用户对象 * @return 用户对象
*/ */
MemberUserDO getUserByMobile(String mobile); MemberUserDO getUserByMobile(String mobile);
MemberUserDO checkPhoneUnique(String areaCode,String mobile);
MemberUserDO getUserByMobile(String areaCode,String mobile); MemberUserDO checkPhoneUnique(String areaCode, String mobile);
MemberUserDO getUserByMobile(String areaCode, String mobile);
MemberUserDO getUserByEmail(String email); MemberUserDO getUserByEmail(String email);
...@@ -43,7 +44,7 @@ public interface MemberUserService { ...@@ -43,7 +44,7 @@ public interface MemberUserService {
* @param registerIp 注册 IP * @param registerIp 注册 IP
* @return 用户对象 * @return 用户对象
*/ */
MemberUserDO createUserIfAbsent(String mobile, String areaCode, String registerIp); MemberUserDO createUserIfAbsent(String mobile, String areaCode, String registerIp,Integer platform);
/**** /****
* 基于手机号创建用户 * 基于手机号创建用户
...@@ -53,7 +54,7 @@ public interface MemberUserService { ...@@ -53,7 +54,7 @@ public interface MemberUserService {
* @param referralCode * @param referralCode
* @return * @return
*/ */
MemberUserDO createUser(String mobile, String registerIp, String password, String areaCode, String englishName, String referralCode); MemberUserDO createUser(String mobile, String registerIp, String password, String areaCode, String englishName, String referralCode, Integer registerPlatform);
/** /**
* 更新用户的最后登陆信息 * 更新用户的最后登陆信息
...@@ -75,7 +76,7 @@ public interface MemberUserService { ...@@ -75,7 +76,7 @@ public interface MemberUserService {
* 通过用户 ID 查询用户 * 通过用户 ID 查询用户
* *
* @param id 用户ID * @param id 用户ID
* @return 用户对象信息,包括公司信息 * @return 用户对象信息, 包括公司信息
*/ */
MemberUserDO info(Long id); MemberUserDO info(Long id);
...@@ -182,18 +183,18 @@ public interface MemberUserService { ...@@ -182,18 +183,18 @@ public interface MemberUserService {
* 会员发出的订单统计 * 会员发出的订单统计
* TODO 分布式系统可能需要在分库分表时将此方法实现切换到订单模块,现在未避免循环依赖故将实现方法放在此处,也可用使用监听去实现 * TODO 分布式系统可能需要在分库分表时将此方法实现切换到订单模块,现在未避免循环依赖故将实现方法放在此处,也可用使用监听去实现
* *
* @param mobile 用户手机号 * @param mobile 用户手机号
* @param userId 用户ID * @param userId 用户ID
* @param customerContactsIds 客户联系人ids * @param customerContactsIds 客户联系人ids
* @return 会员发出的订单数量统计 * @return 会员发出的订单数量统计
*/ */
Integer appIssuedOrderCount(String mobile,Long userId,Collection<Long> customerContactsIds); Integer appIssuedOrderCount(String mobile, Long userId, Collection<Long> customerContactsIds);
/** /**
* 会员收到的订单统计 * 会员收到的订单统计
* TODO 分布式系统可能需要在分库分表时将此方法实现切换到订单模块,现在未避免循环依赖故将实现方法放在此处,也可用使用监听去实现 * TODO 分布式系统可能需要在分库分表时将此方法实现切换到订单模块,现在未避免循环依赖故将实现方法放在此处,也可用使用监听去实现
* *
* @param phone 会员电话 * @param phone 会员电话
* @param customerContactsIds 客户联系人ids * @param customerContactsIds 客户联系人ids
* @return 会员收到的订单数量统计 * @return 会员收到的订单数量统计
*/ */
...@@ -203,8 +204,8 @@ public interface MemberUserService { ...@@ -203,8 +204,8 @@ public interface MemberUserService {
* 会员收到的订单统计 * 会员收到的订单统计
* TODO 分布式系统可能需要在分库分表时将此方法实现切换到订单模块,现在未避免循环依赖故将实现方法放在此处,也可用使用监听去实现 * TODO 分布式系统可能需要在分库分表时将此方法实现切换到订单模块,现在未避免循环依赖故将实现方法放在此处,也可用使用监听去实现
* *
* @param userId 用户ID * @param userId 用户ID
* @param phone 会员电话 * @param phone 会员电话
* @param customerContactsIds 客户联系人ids * @param customerContactsIds 客户联系人ids
* @return 会员收到的订单数量统计 * @return 会员收到的订单数量统计
*/ */
......
...@@ -153,7 +153,7 @@ public class MemberUserServiceImpl implements MemberUserService { ...@@ -153,7 +153,7 @@ public class MemberUserServiceImpl implements MemberUserService {
} }
@Override @Override
public MemberUserDO createUserIfAbsent(String mobile, String areaCode, String registerIp) { public MemberUserDO createUserIfAbsent(String mobile, String areaCode, String registerIp, Integer platform) {
try { try {
String mobileCode = areaCode + StrUtil.COLON + mobile; String mobileCode = areaCode + StrUtil.COLON + mobile;
...@@ -172,7 +172,7 @@ public class MemberUserServiceImpl implements MemberUserService { ...@@ -172,7 +172,7 @@ public class MemberUserServiceImpl implements MemberUserService {
} }
String englishName = maskMobileNumber(mobile); String englishName = maskMobileNumber(mobile);
// 用户不存在,则进行创建 // 用户不存在,则进行创建
user = this.createUser(mobile, registerIp, null, areaCode, englishName, null); user = this.createUser(mobile, registerIp, null, areaCode, englishName, null, platform);
//记录日志 //记录日志
UserOperationLogCreateReqVO userOperationLogCreateReqVO = new UserOperationLogCreateReqVO(); UserOperationLogCreateReqVO userOperationLogCreateReqVO = new UserOperationLogCreateReqVO();
...@@ -202,7 +202,7 @@ public class MemberUserServiceImpl implements MemberUserService { ...@@ -202,7 +202,7 @@ public class MemberUserServiceImpl implements MemberUserService {
@Override @Override
@Transactional(rollbackFor = Exception.class) @Transactional(rollbackFor = Exception.class)
public MemberUserDO createUser(String mobile, String registerIp, String password, String areacode, String englishName, String referralCode) { public MemberUserDO createUser(String mobile, String registerIp, String password, String areacode, String englishName, String referralCode, Integer registerPlatform) {
// 生成密码 // 生成密码
/* if (StrUtil.isBlank(password)) { /* if (StrUtil.isBlank(password)) {
password = IdUtil.fastSimpleUUID(); password = IdUtil.fastSimpleUUID();
...@@ -223,6 +223,7 @@ public class MemberUserServiceImpl implements MemberUserService { ...@@ -223,6 +223,7 @@ public class MemberUserServiceImpl implements MemberUserService {
user.setNickname(englishName); user.setNickname(englishName);
user.setCode(getNextMemberCode()); user.setCode(getNextMemberCode());
user.setReferralCode(referralCode); user.setReferralCode(referralCode);
user.setRegisterPlatform(registerPlatform);
memberUserMapper.insert(user); memberUserMapper.insert(user);
//站内信 //站内信
InternalMessageCreateDto dto = InternalMessageCreateDto.builder().toIdList(Arrays.asList(user.getId())) InternalMessageCreateDto dto = InternalMessageCreateDto.builder().toIdList(Arrays.asList(user.getId()))
...@@ -564,7 +565,7 @@ public class MemberUserServiceImpl implements MemberUserService { ...@@ -564,7 +565,7 @@ public class MemberUserServiceImpl implements MemberUserService {
long limit = 500; long limit = 500;
memberUserMapper.clearMemberCode(); memberUserMapper.clearMemberCode();
redisHelper.delete("memberCode:max:number"); redisHelper.delete("memberCode:max:number");
while(true) { while (true) {
List<MemberUserDO> result = this.getByCursor(startUserId, limit); List<MemberUserDO> result = this.getByCursor(startUserId, limit);
if (CollectionUtils.isEmpty(result)) { if (CollectionUtils.isEmpty(result)) {
break; break;
......
package cn.iocoder.yudao.module.member.util;
public class ReferralCodeUtils {
/**
* 根据用户id生成推荐码
*/
public static String generateReferralCode(Long userId) {
return userId.toString();
}
/**
* 根据推荐码获取用户id
*/
public static Long getUserId(String referralCode) {
return Long.parseLong(referralCode);
}
}
...@@ -11,7 +11,7 @@ import java.util.Date; ...@@ -11,7 +11,7 @@ import java.util.Date;
import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND; import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND;
@Data @Data
@ApiModel("管理后台 - 积分规则延期 Response VO") @ApiModel("管理后台 - 积分规则延期 Request VO")
public class ScoreDelayReqVO { public class ScoreDelayReqVO {
@ApiModelProperty(value = "主键", required = true) @ApiModelProperty(value = "主键", required = true)
@NotNull(message = "主键不能为空") @NotNull(message = "主键不能为空")
......
package cn.iocoder.yudao.module.member.vo.scoreRule;
import cn.iocoder.yudao.module.depository.vo.warehouse.WarehouseRespVO;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import java.util.List;
import java.util.Objects;
@Data
public class WarehouseTreeRegionSimpleVO {
@ApiModelProperty("国家id")
private Long countryId;
@ApiModelProperty("国家中文名")
private String labelZh;
@ApiModelProperty("国家英文名")
private String labelEn;
@ApiModelProperty("城市")
private List<WarehouseCity> children;
@Data
public static class WarehouseCity {
@ApiModelProperty("城市id")
private Long cityId;
@ApiModelProperty("城市中文名")
private String labelZh;
@ApiModelProperty("城市英文名")
private String labelEn;
@ApiModelProperty("仓库")
private List<Warehouse> children;
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
WarehouseCity that = (WarehouseCity) o;
return Objects.equals(cityId, that.cityId);
}
@Override
public int hashCode() {
return Objects.hashCode(cityId);
}
}
@Data
public static class Warehouse {
@ApiModelProperty("仓库id")
private Long warehouseId;
@ApiModelProperty("仓库中文名")
private String labelZh;
@ApiModelProperty("仓库英文名")
private String labelEn;
}
}
...@@ -19,6 +19,8 @@ public class ScoreRuleOrderVExtraVO { ...@@ -19,6 +19,8 @@ public class ScoreRuleOrderVExtraVO {
private String targetCity; private String targetCity;
@ApiModelProperty(value = "提货点,可多选,逗号拼接", required = true) @ApiModelProperty(value = "提货点,可多选,逗号拼接", required = true)
private String receiveAddr; private String receiveAddr;
@ApiModelProperty(value = "提货点列表(第一级提货点,第二级国家,城市,仓库id)", required = true)
private List<List<Long>> receiveAddrList;
@ApiModelProperty(value = "渠道,运输方式选择海运时,渠道隐藏,可多选,逗号拼接") @ApiModelProperty(value = "渠道,运输方式选择海运时,渠道隐藏,可多选,逗号拼接")
private String channel; private String channel;
@ApiModelProperty(value = "积分规则列表", required = true) @ApiModelProperty(value = "积分规则列表", required = true)
......
package cn.iocoder.yudao.module.reward.api.reward; package cn.iocoder.yudao.module.reward.api.reward;
import cn.iocoder.yudao.module.reward.api.reward.dto.RedeemDetailForUserDTO;
import cn.iocoder.yudao.module.reward.api.reward.dto.RedeemRewardReqVO; import cn.iocoder.yudao.module.reward.api.reward.dto.RedeemRewardReqVO;
import cn.iocoder.yudao.module.reward.api.reward.dto.RedeemRewardRespDTO; import cn.iocoder.yudao.module.reward.api.reward.dto.RedeemRewardRespDTO;
...@@ -13,4 +14,5 @@ public interface RedeemRewardApi { ...@@ -13,4 +14,5 @@ public interface RedeemRewardApi {
RedeemRewardRespDTO redeemReward(RedeemRewardReqVO redeemRewardReqVO); RedeemRewardRespDTO redeemReward(RedeemRewardReqVO redeemRewardReqVO);
List<RedeemRewardRespDTO> redeemRewards(List<RedeemRewardReqVO> redeemRewardReqVOList); List<RedeemRewardRespDTO> redeemRewards(List<RedeemRewardReqVO> redeemRewardReqVOList);
RedeemDetailForUserDTO getRedeemDetailForUser(Long redeemId);
} }
package cn.iocoder.yudao.module.reward.api.reward.dto;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
@Data
@ApiModel("用户 APP - 礼品兑换记录 DTO")
public class RedeemDetailForUserDTO {
@ApiModelProperty(value = "礼品名称中文")
private String rewardNameZh;
@ApiModelProperty(value = "礼品名称英文")
private String rewardNameEn;
@ApiModelProperty(value = "兑换数量")
private Integer rewardCount;
}
...@@ -9,6 +9,7 @@ import cn.iocoder.yudao.module.member.api.user.MemberUserApi; ...@@ -9,6 +9,7 @@ import cn.iocoder.yudao.module.member.api.user.MemberUserApi;
import cn.iocoder.yudao.module.member.api.user.dto.UserRespDTO; import cn.iocoder.yudao.module.member.api.user.dto.UserRespDTO;
import cn.iocoder.yudao.module.member.enums.PlatformTypeEnum; import cn.iocoder.yudao.module.member.enums.PlatformTypeEnum;
import cn.iocoder.yudao.module.member.enums.ScoreSourceTypeEnum; import cn.iocoder.yudao.module.member.enums.ScoreSourceTypeEnum;
import cn.iocoder.yudao.module.reward.api.reward.dto.RedeemDetailForUserDTO;
import cn.iocoder.yudao.module.reward.api.reward.dto.RedeemRewardReqVO; import cn.iocoder.yudao.module.reward.api.reward.dto.RedeemRewardReqVO;
import cn.iocoder.yudao.module.reward.api.reward.dto.RedeemRewardRespDTO; import cn.iocoder.yudao.module.reward.api.reward.dto.RedeemRewardRespDTO;
import cn.iocoder.yudao.module.reward.dal.dataobject.redeem.RewardRedeemDO; import cn.iocoder.yudao.module.reward.dal.dataobject.redeem.RewardRedeemDO;
...@@ -188,6 +189,20 @@ public class RedeemRewardApiImpl implements RedeemRewardApi { ...@@ -188,6 +189,20 @@ public class RedeemRewardApiImpl implements RedeemRewardApi {
return null; return null;
} }
@Override
public RedeemDetailForUserDTO getRedeemDetailForUser(Long redeemId) {
RewardRedeemDO rewardRedeemDO = rewardRedeemMapper.selectById(redeemId);
if (rewardRedeemDO != null) {
RedeemDetailForUserDTO redeemDetailForUserDTO = new RedeemDetailForUserDTO();
redeemDetailForUserDTO.setRewardCount(rewardRedeemDO.getRewardCount());
RewardDO rewardDO = rewardMapper.selectById(rewardRedeemDO.getRewardId());
redeemDetailForUserDTO.setRewardNameEn(rewardDO.getTitleEn());
redeemDetailForUserDTO.setRewardNameZh(rewardDO.getTitleZh());
return redeemDetailForUserDTO;
}
return null;
}
private void verifyMemberUser(RedeemRewardReqVO redeemRewardReqVO, RewardDO rewardDO) { private void verifyMemberUser(RedeemRewardReqVO redeemRewardReqVO, RewardDO rewardDO) {
// 查询会员积分 // 查询会员积分
UserRespDTO memberUser = memberUserApi.getUser(redeemRewardReqVO.getMemberId()); UserRespDTO memberUser = memberUserApi.getUser(redeemRewardReqVO.getMemberId());
......
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