diff --git a/dating-agency-mall-constant/src/main/java/com/qniao/dam/domian/aggregate/pcur/constant/CardUsageTyepEnum.java b/dating-agency-mall-constant/src/main/java/com/qniao/dam/domian/aggregate/pcur/constant/CardUsageTyepEnum.java new file mode 100644 index 0000000..dec3068 --- /dev/null +++ b/dating-agency-mall-constant/src/main/java/com/qniao/dam/domian/aggregate/pcur/constant/CardUsageTyepEnum.java @@ -0,0 +1,37 @@ +package com.qniao.dam.domian.aggregate.pcur.constant; + +import com.baomidou.mybatisplus.annotation.EnumValue; +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonFormat; +import com.fasterxml.jackson.annotation.JsonValue; +import lombok.Getter; + +@Getter +@JsonFormat(shape = JsonFormat.Shape.OBJECT) +public enum CardUsageTyepEnum { + + FREE(1, "免费"), + + CARD(2, "卡片"); + + @EnumValue + @JsonValue + private final Integer value; + private final String desc; + + CardUsageTyepEnum(Integer value, String desc) { + this.value = value; + this.desc = desc; + } + + @JsonCreator + public static CardUsageTyepEnum get(Object code) { + for (CardUsageTyepEnum e : CardUsageTyepEnum.values()) { + if (e.getValue().equals(code)) { + return e; + } + } + return null; + } + +} \ No newline at end of file diff --git a/dating-agency-mall-server/src/main/java/com/qniao/dam/api/command/pcur/user/ProfileCardUsageRecordUserCommandController.java b/dating-agency-mall-server/src/main/java/com/qniao/dam/api/command/pcur/user/ProfileCardUsageRecordUserCommandController.java new file mode 100644 index 0000000..5913c2a --- /dev/null +++ b/dating-agency-mall-server/src/main/java/com/qniao/dam/api/command/pcur/user/ProfileCardUsageRecordUserCommandController.java @@ -0,0 +1,31 @@ +package com.qniao.dam.api.command.pcur.user; + +import com.qniao.dam.api.command.pcur.user.request.*; +import com.qniao.dam.api.command.pcur.user.response.UserUseProfileCardVo; +import com.qniao.dam.application.service.pcur.ProfileCardUsageRecordApplicationService; +import com.qniao.dam.domain.aggregate.pcur.entity.ProfileCardUsageRecord; +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiOperation; +import org.springframework.web.bind.annotation.*; + +import javax.annotation.Resource; +import javax.validation.Valid; + +@Api(tags = "资料卡使用记录") +@RestController +@RequestMapping("user") +public class ProfileCardUsageRecordUserCommandController { + + @Resource + private ProfileCardUsageRecordApplicationService profileCardUsageRecordApplicationService; + + @ApiOperation("用户使用资料卡") + @PostMapping("user/profile-card") + public UserUseProfileCardVo userCreateProfileCardUsageRecord(@RequestBody @Valid UserUseProfileCardDto dto, + @RequestParam("userId") Long userId) { + ProfileCardUsageRecord usageRecord = dto.trans2Domain(); + usageRecord.setUserId(userId); + return profileCardUsageRecordApplicationService.use(usageRecord); + } + +} diff --git a/dating-agency-mall-server/src/main/java/com/qniao/dam/api/command/pcur/user/request/UserUseProfileCardDto.java b/dating-agency-mall-server/src/main/java/com/qniao/dam/api/command/pcur/user/request/UserUseProfileCardDto.java new file mode 100644 index 0000000..f17a2ba --- /dev/null +++ b/dating-agency-mall-server/src/main/java/com/qniao/dam/api/command/pcur/user/request/UserUseProfileCardDto.java @@ -0,0 +1,19 @@ +package com.qniao.dam.api.command.pcur.user.request; + +import com.qniao.dam.domain.aggregate.pcur.entity.ProfileCardUsageRecord; +import com.qniao.domain.Trans2DomainAssembler; +import io.swagger.annotations.ApiModelProperty; +import com.qniao.framework.utils.TypeConvertUtils; +import lombok.Data; + +@Data +public class UserUseProfileCardDto implements Trans2DomainAssembler { + + @ApiModelProperty("目标资料标识") + private Long targetMiId; + + @Override + public ProfileCardUsageRecord trans2Domain() { + return TypeConvertUtils.convert(this, ProfileCardUsageRecord.class); + } +} diff --git a/dating-agency-mall-server/src/main/java/com/qniao/dam/api/command/pcur/user/response/UserUseProfileCardVo.java b/dating-agency-mall-server/src/main/java/com/qniao/dam/api/command/pcur/user/response/UserUseProfileCardVo.java new file mode 100644 index 0000000..58eda02 --- /dev/null +++ b/dating-agency-mall-server/src/main/java/com/qniao/dam/api/command/pcur/user/response/UserUseProfileCardVo.java @@ -0,0 +1,15 @@ +package com.qniao.dam.api.command.pcur.user.response; + +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; + +@Data +public class UserUseProfileCardVo { + + @ApiModelProperty("是否成功") + private Boolean success = false; + + @ApiModelProperty("是否实名认证") + private Boolean realNameAuthenticated = false; + +} diff --git a/dating-agency-mall-server/src/main/java/com/qniao/dam/api/command/right/user/RightUserCommandController.java b/dating-agency-mall-server/src/main/java/com/qniao/dam/api/command/right/user/RightUserCommandController.java index d2318a5..858f0f7 100644 --- a/dating-agency-mall-server/src/main/java/com/qniao/dam/api/command/right/user/RightUserCommandController.java +++ b/dating-agency-mall-server/src/main/java/com/qniao/dam/api/command/right/user/RightUserCommandController.java @@ -25,7 +25,7 @@ public class RightUserCommandController { @PostMapping("consume/right/by/sdk") @IgnoreResponseAdvice public UserConsumeRightBySdkVo userConsumeRightBySdk(@RequestBody @Valid UserConsumeRightBySdkDto dto) { - return rightApplicationService.consumeRight(dto); + return rightApplicationService.consumeRightBySdk(dto); } @ApiOperation("通过SDK退回消费过的权益") diff --git a/dating-agency-mall-server/src/main/java/com/qniao/dam/application/service/pcur/ProfileCardUsageRecordApplicationService.java b/dating-agency-mall-server/src/main/java/com/qniao/dam/application/service/pcur/ProfileCardUsageRecordApplicationService.java new file mode 100644 index 0000000..c7e887b --- /dev/null +++ b/dating-agency-mall-server/src/main/java/com/qniao/dam/application/service/pcur/ProfileCardUsageRecordApplicationService.java @@ -0,0 +1,66 @@ +package com.qniao.dam.application.service.pcur; + +import cn.hutool.core.util.StrUtil; +import com.qniao.dam.api.command.pcur.user.response.UserUseProfileCardVo; +import com.qniao.dam.application.service.right.RightApplicationService; +import com.qniao.dam.domain.aggregate.pcur.ProfileCardUsageRecordAggregate; +import com.qniao.dam.domain.aggregate.pcur.entity.ProfileCardUsageRecord; +import com.qniao.dam.domian.aggregate.pcur.constant.CardUsageTyepEnum; +import com.qniao.dam.domian.aggregate.right.constant.RightTypeEnum; +import com.qniao.dam.infrastructure.persistent.dao.domain.MarriageInformationDao; +import com.qniao.dam.infrastructure.persistent.dao.pcur.ProfileCardUsageRecordDao; +import com.qniao.dam.query.marriageinformation.MarriageInformationQueryService; +import com.qniao.dam.query.pcur.ProfileCardUsageRecordQueryService; +import com.qniao.das.domian.aggregate.marriageinformation.MarriageInformation; +import org.springframework.stereotype.Service; + +import javax.annotation.Resource; +import java.util.Objects; + +@Service +public class ProfileCardUsageRecordApplicationService { + + @Resource + private ProfileCardUsageRecordDao profileCardUsageRecordDao; + @Resource + private ProfileCardUsageRecordQueryService profileCardUsageRecordQueryService; + @Resource + private MarriageInformationQueryService marriageInformationQueryService; + @Resource + private RightApplicationService rightApplicationService; + + public UserUseProfileCardVo use(ProfileCardUsageRecord usageRecord) { + UserUseProfileCardVo vo = new UserUseProfileCardVo(); + //查看今天是否解锁过 + if (profileCardUsageRecordQueryService.existUsageRecord(usageRecord.getUserId(), usageRecord.getTargetMiId())) { + vo.setSuccess(true); + } else { + int freeCount = profileCardUsageRecordQueryService.countUsageRecord(usageRecord.getUserId(), CardUsageTyepEnum.FREE); + if (freeCount < 3) { + ProfileCardUsageRecord record = ProfileCardUsageRecord.build(usageRecord.getUserId(), usageRecord.getTargetMiId(), CardUsageTyepEnum.FREE); + profileCardUsageRecordDao.insert(record); + } else { + MarriageInformation marriageInformation = marriageInformationQueryService.queryByUserId(usageRecord.getUserId()); + vo.setRealNameAuthenticated(StrUtil.isNotBlank(marriageInformation.getIdentityCard())); + if (!vo.getRealNameAuthenticated()) { + //未实名是有3次 + vo.setSuccess(false); + } else { + if (freeCount < 20) { + ProfileCardUsageRecord record = ProfileCardUsageRecord.build(usageRecord.getUserId(), usageRecord.getTargetMiId(), CardUsageTyepEnum.FREE); + profileCardUsageRecordDao.insert(record); + } else { + //免费使用完后,看看有没有资料卡使用 + if (rightApplicationService.consumeRight(usageRecord.getUserId(), marriageInformation.getId(), RightTypeEnum.PROFILE_CARD, null)) { + ProfileCardUsageRecord record = ProfileCardUsageRecord.build(usageRecord.getUserId(), usageRecord.getTargetMiId(), CardUsageTyepEnum.CARD); + profileCardUsageRecordDao.insert(record); + } else { + vo.setSuccess(false); + } + } + } + } + } + return vo; + } +} \ No newline at end of file diff --git a/dating-agency-mall-server/src/main/java/com/qniao/dam/application/service/right/RightApplicationService.java b/dating-agency-mall-server/src/main/java/com/qniao/dam/application/service/right/RightApplicationService.java index 51e5696..12adfa9 100644 --- a/dating-agency-mall-server/src/main/java/com/qniao/dam/application/service/right/RightApplicationService.java +++ b/dating-agency-mall-server/src/main/java/com/qniao/dam/application/service/right/RightApplicationService.java @@ -3,7 +3,6 @@ package com.qniao.dam.application.service.right; import cn.hutool.core.collection.CollUtil; import cn.hutool.core.lang.Tuple; import cn.hutool.core.util.StrUtil; -import com.baomidou.mybatisplus.extension.api.R; import com.qniao.dam.api.command.right.user.request.UserConsumeRightBySdkDto; import com.qniao.dam.api.command.right.user.respose.UserConsumeRightBySdkVo; import com.qniao.dam.domain.aggregate.order.entity.Order; @@ -199,7 +198,25 @@ public class RightApplicationService { } } - public UserConsumeRightBySdkVo consumeRight(UserConsumeRightBySdkDto dto) { + public boolean consumeRight(Long userId, Long miId, RightTypeEnum rightType, Long associatedId) { + boolean status = false; + List rightList = rightQueryService.listEnableRightBy(userId, miId, rightType); + if (CollUtil.isNotEmpty(rightList)) { + //1.判断今日使用权益次数 + if (rightQueryService.checkRightUseLimit(rightList.get(0))) { + for (Right right : rightList) { + if (rightQueryService.checkEnable(right)) { + executeConsumeRight(right, associatedId); + status = true; + break; + } + } + } + } + return status; + } + + public UserConsumeRightBySdkVo consumeRightBySdk(UserConsumeRightBySdkDto dto) { UserConsumeRightBySdkVo vo = new UserConsumeRightBySdkVo(); String failReason = null; try { diff --git a/dating-agency-mall-server/src/main/java/com/qniao/dam/domain/aggregate/pcur/ProfileCardUsageRecordAggregate.java b/dating-agency-mall-server/src/main/java/com/qniao/dam/domain/aggregate/pcur/ProfileCardUsageRecordAggregate.java new file mode 100644 index 0000000..3c6a9ae --- /dev/null +++ b/dating-agency-mall-server/src/main/java/com/qniao/dam/domain/aggregate/pcur/ProfileCardUsageRecordAggregate.java @@ -0,0 +1,31 @@ +package com.qniao.dam.domain.aggregate.pcur; + +import com.qniao.dam.domain.aggregate.pcur.entity.ProfileCardUsageRecord; +import com.qniao.dam.domain.aggregate.pcur.repository.ProfileCardUsageRecordRepository; +import org.springframework.stereotype.Service; + +import javax.annotation.Resource; + +/** + * 资料卡使用记录 + * + * @date 2026/02/04 + */ +@Service +public class ProfileCardUsageRecordAggregate { + + @Resource + private ProfileCardUsageRecordRepository repository; + + public void create(ProfileCardUsageRecord entity) { + repository.save(entity); + } + + public void edit(ProfileCardUsageRecord entity) { + repository.save(entity); + } + + public void delete(Long id) { + repository.delete(id); + } +} diff --git a/dating-agency-mall-server/src/main/java/com/qniao/dam/domain/aggregate/pcur/entity/ProfileCardUsageRecord.java b/dating-agency-mall-server/src/main/java/com/qniao/dam/domain/aggregate/pcur/entity/ProfileCardUsageRecord.java new file mode 100644 index 0000000..150127f --- /dev/null +++ b/dating-agency-mall-server/src/main/java/com/qniao/dam/domain/aggregate/pcur/entity/ProfileCardUsageRecord.java @@ -0,0 +1,46 @@ +package com.qniao.dam.domain.aggregate.pcur.entity; + +import com.baomidou.mybatisplus.annotation.TableName; +import com.qniao.dam.domian.aggregate.pcur.constant.CardUsageTyepEnum; +import com.qniao.domain.ValueObject; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; +import lombok.EqualsAndHashCode; +import com.qniao.domain.Entity; + +import java.time.LocalDate; + +/** + * 资料卡使用记录 + * + * @date 2026/02/04 + */ +@Data +@EqualsAndHashCode(callSuper = true) +@TableName("da_profile_card_usage_record") +public class ProfileCardUsageRecord extends ValueObject { + + @ApiModelProperty("用户标识") + private Long userId; + + @ApiModelProperty("目标资料标识") + private Long targetMiId; + + @ApiModelProperty("使用类型") + private CardUsageTyepEnum usageType; + + @ApiModelProperty("使用日期") + private LocalDate usageDate; + + public static ProfileCardUsageRecord build(Long userId, + Long targetMiId, + CardUsageTyepEnum usageType) { + ProfileCardUsageRecord profileCardUsageRecord = new ProfileCardUsageRecord(); + profileCardUsageRecord.setUserId(userId); + profileCardUsageRecord.setTargetMiId(targetMiId); + profileCardUsageRecord.setUsageType(usageType); + profileCardUsageRecord.setUsageDate(LocalDate.now()); + return profileCardUsageRecord; + } + +} diff --git a/dating-agency-mall-server/src/main/java/com/qniao/dam/domain/aggregate/pcur/repository/ProfileCardUsageRecordRepository.java b/dating-agency-mall-server/src/main/java/com/qniao/dam/domain/aggregate/pcur/repository/ProfileCardUsageRecordRepository.java new file mode 100644 index 0000000..88ca390 --- /dev/null +++ b/dating-agency-mall-server/src/main/java/com/qniao/dam/domain/aggregate/pcur/repository/ProfileCardUsageRecordRepository.java @@ -0,0 +1,12 @@ +package com.qniao.dam.domain.aggregate.pcur.repository; + +import com.qniao.dam.domain.aggregate.pcur.entity.ProfileCardUsageRecord; +import com.qniao.domain.Repository; + +/** + * 资料卡使用记录 + * + * @date 2026/02/04 + */ +public interface ProfileCardUsageRecordRepository extends Repository { +} diff --git a/dating-agency-mall-server/src/main/java/com/qniao/dam/infrastructure/persistent/dao/pcur/ProfileCardUsageRecordDao.java b/dating-agency-mall-server/src/main/java/com/qniao/dam/infrastructure/persistent/dao/pcur/ProfileCardUsageRecordDao.java new file mode 100644 index 0000000..b70ecb1 --- /dev/null +++ b/dating-agency-mall-server/src/main/java/com/qniao/dam/infrastructure/persistent/dao/pcur/ProfileCardUsageRecordDao.java @@ -0,0 +1,12 @@ +package com.qniao.dam.infrastructure.persistent.dao.pcur; + +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import com.qniao.dam.domain.aggregate.pcur.entity.ProfileCardUsageRecord; + +/** + * 资料卡使用记录 + * + * @date 2026/02/04 + */ +public interface ProfileCardUsageRecordDao extends BaseMapper { +} diff --git a/dating-agency-mall-server/src/main/java/com/qniao/dam/infrastructure/persistent/repository/impl/ProfileCardUsageRecordRepositoryImpl.java b/dating-agency-mall-server/src/main/java/com/qniao/dam/infrastructure/persistent/repository/impl/ProfileCardUsageRecordRepositoryImpl.java new file mode 100644 index 0000000..6ba3cc4 --- /dev/null +++ b/dating-agency-mall-server/src/main/java/com/qniao/dam/infrastructure/persistent/repository/impl/ProfileCardUsageRecordRepositoryImpl.java @@ -0,0 +1,41 @@ +package com.qniao.dam.infrastructure.persistent.repository.impl; + +import com.qniao.dam.domain.aggregate.pcur.entity.ProfileCardUsageRecord; +import com.qniao.dam.domain.aggregate.pcur.repository.ProfileCardUsageRecordRepository; +import com.qniao.dam.infrastructure.persistent.dao.pcur.ProfileCardUsageRecordDao; +import org.springframework.stereotype.Service; + +import javax.annotation.Resource; +import java.util.Objects; + +/** + * 资料卡使用记录 + * + * @date 2026/02/04 + */ +@Service +public class ProfileCardUsageRecordRepositoryImpl implements ProfileCardUsageRecordRepository { + + @Resource + private ProfileCardUsageRecordDao dao; + + @Override + public ProfileCardUsageRecord load(Long id) { + return dao.selectById(id); + } + + @Override + public Long save(ProfileCardUsageRecord entity) { + if (Objects.isNull(entity) || Objects.isNull(dao.selectById(entity.getId()))) { + dao.insert(entity); + } else { + dao.updateById(entity); + } + return entity.getId(); + } + + @Override + public void delete(Long id) { + dao.deleteById(id); + } +} diff --git a/dating-agency-mall-server/src/main/java/com/qniao/dam/query/pcur/ProfileCardUsageRecordQueryService.java b/dating-agency-mall-server/src/main/java/com/qniao/dam/query/pcur/ProfileCardUsageRecordQueryService.java new file mode 100644 index 0000000..407ab92 --- /dev/null +++ b/dating-agency-mall-server/src/main/java/com/qniao/dam/query/pcur/ProfileCardUsageRecordQueryService.java @@ -0,0 +1,10 @@ +package com.qniao.dam.query.pcur; + +import com.qniao.dam.domian.aggregate.pcur.constant.CardUsageTyepEnum; + +public interface ProfileCardUsageRecordQueryService { + + boolean existUsageRecord(Long userId, Long targetMiId); + + int countUsageRecord(Long userId, CardUsageTyepEnum usageType); +} diff --git a/dating-agency-mall-server/src/main/java/com/qniao/dam/query/pcur/impl/ProfileCardUsageRecordQueryServiceImpl.java b/dating-agency-mall-server/src/main/java/com/qniao/dam/query/pcur/impl/ProfileCardUsageRecordQueryServiceImpl.java new file mode 100644 index 0000000..b2d77e4 --- /dev/null +++ b/dating-agency-mall-server/src/main/java/com/qniao/dam/query/pcur/impl/ProfileCardUsageRecordQueryServiceImpl.java @@ -0,0 +1,34 @@ +package com.qniao.dam.query.pcur.impl; + +import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; +import com.qniao.dam.domain.aggregate.pcur.entity.ProfileCardUsageRecord; +import com.qniao.dam.domian.aggregate.pcur.constant.CardUsageTyepEnum; +import com.qniao.dam.infrastructure.persistent.dao.pcur.ProfileCardUsageRecordDao; +import com.qniao.dam.query.pcur.ProfileCardUsageRecordQueryService; +import org.springframework.stereotype.Service; + +import javax.annotation.Resource; +import java.time.LocalDate; + +@Service +public class ProfileCardUsageRecordQueryServiceImpl implements ProfileCardUsageRecordQueryService { + + @Resource + private ProfileCardUsageRecordDao profileCardUsageRecordDao; + + @Override + public boolean existUsageRecord(Long userId, Long targetMiId) { + return profileCardUsageRecordDao.selectCount(new LambdaQueryWrapper() + .eq(ProfileCardUsageRecord::getUserId, userId) + .eq(ProfileCardUsageRecord::getUsageDate, LocalDate.now()) + .eq(ProfileCardUsageRecord::getTargetMiId, targetMiId)) > 0; + } + + @Override + public int countUsageRecord(Long userId, CardUsageTyepEnum usageType) { + return profileCardUsageRecordDao.selectCount(new LambdaQueryWrapper() + .eq(ProfileCardUsageRecord::getUserId, userId) + .eq(ProfileCardUsageRecord::getUsageDate, LocalDate.now()) + .eq(ProfileCardUsageRecord::getUsageType, usageType)); + } +} \ No newline at end of file