fix: 유저 행동 데이터 기록시 포인트 지급 조건 수정

- 지급유형(매일, 전체) 추가
- 참여가능 횟수 추가
- 주문한 콘텐츠에 댓글을 쓰면 포인트 지급을 위해 포인트 지급 이력에 orderId 추가
This commit is contained in:
2025-05-16 15:01:33 +09:00
parent 73c9a90ae3
commit f23251f5bb
7 changed files with 45 additions and 11 deletions

View File

@@ -24,23 +24,35 @@ class UserActionService(
private val coroutineScope = CoroutineScope(Dispatchers.IO)
fun recordAction(memberId: Long, actionType: ActionType, pushToken: String?) {
fun recordAction(memberId: Long, actionType: ActionType, orderId: Long? = null, pushToken: String? = null) {
coroutineScope.launch {
val now = LocalDateTime.now()
repository.save(UserActionLog(memberId, actionType))
val policy = policyRepository.findByActionTypeAndIsActiveTrue(actionType, now)
if (policy != null) {
val policyType = policy.policyType
val todayAt15 = now.toLocalDate().atTime(15, 0)
val policyTypeDailyStartDate = if (now.toLocalTime().isBefore(todayAt15.toLocalTime())) {
now.toLocalDate().minusDays(1).atTime(15, 0)
} else {
todayAt15
}
val actionCount = repository.countByMemberIdAndActionTypeAndCreatedAtBetween(
memberId = memberId,
actionType = actionType,
startDate = policy.startDate,
startDate = if (policyType == PolicyType.DAILY) policyTypeDailyStartDate else policy.startDate,
endDate = policy.endDate ?: now
)
if (actionCount < policy.threshold) return@launch
val alreadyGranted = grantLogRepository.existsByMemberIdAndPolicyId(memberId, policy.id!!)
if (alreadyGranted) return@launch
val grantedCount = grantLogRepository.countByMemberIdAndPolicyIdAndStartDate(
memberId,
policy.id!!,
startDate = if (policyType == PolicyType.DAILY) policyTypeDailyStartDate else policy.startDate
)
if (grantedCount >= policy.availableCount) return@launch
memberPointRepository.save(
MemberPoint(
@@ -56,7 +68,8 @@ class UserActionService(
memberId = memberId,
point = policy.pointAmount,
actionType = actionType,
policyId = policy.id!!
policyId = policy.id!!,
orderId = orderId
)
)