크리에이터 기준 라이브 합계 정산 API 추가

This commit is contained in:
Klaus 2024-07-06 00:15:40 +09:00
parent 80a78a036e
commit c4e58890ea
6 changed files with 135 additions and 0 deletions

View File

@ -48,4 +48,18 @@ class AdminCalculateController(private val service: AdminCalculateService) {
pageable.pageSize.toLong()
)
)
@GetMapping("/live-by-creator")
fun getCalculateLiveByCreator(
@RequestParam startDateStr: String,
@RequestParam endDateStr: String,
pageable: Pageable
) = ApiResponse.ok(
service.getCalculateLiveByCreator(
startDateStr,
endDateStr,
pageable.offset,
pageable.pageSize.toLong()
)
)
}

View File

@ -224,4 +224,44 @@ class AdminCalculateQueryRepository(private val queryFactory: JPAQueryFactory) {
.limit(limit)
.fetch()
}
fun getCalculateLiveByCreatorTotalCount(startDate: LocalDateTime, endDate: LocalDateTime): Int {
return queryFactory
.select(member.id)
.from(useCan)
.innerJoin(useCan.room, liveRoom)
.innerJoin(liveRoom.member, member)
.leftJoin(creatorSettlementRatio)
.on(member.id.eq(creatorSettlementRatio.member.id))
.groupBy(member.id)
.fetch()
.size
}
fun getCalculateLiveByCreator(
startDate: LocalDateTime,
endDate: LocalDateTime,
offset: Long,
limit: Long
): List<GetCalculateLiveByCreatorQueryData> {
return queryFactory
.select(
QGetCalculateLiveByCreatorQueryData(
member.email,
member.nickname,
useCan.can.add(useCan.rewardCan).sum(),
creatorSettlementRatio.liveSettlementRatio
)
)
.from(useCan)
.innerJoin(useCan.room, liveRoom)
.innerJoin(liveRoom.member, member)
.leftJoin(creatorSettlementRatio)
.on(member.id.eq(creatorSettlementRatio.member.id))
.groupBy(member.id)
.orderBy(useCan.can.add(useCan.rewardCan).desc())
.offset(offset)
.limit(limit)
.fetch()
}
}

View File

@ -88,4 +88,21 @@ class AdminCalculateService(private val repository: AdminCalculateQueryRepositor
return GetCreatorCalculateCommunityPostResponse(totalCount, items)
}
fun getCalculateLiveByCreator(
startDateStr: String,
endDateStr: String,
offset: Long,
limit: Long
) = run {
val startDate = startDateStr.convertLocalDateTime()
val endDate = endDateStr.convertLocalDateTime(hour = 23, minute = 59, second = 59)
val totalCount = repository.getCalculateLiveByCreatorTotalCount(startDate, endDate)
val items = repository
.getCalculateLiveByCreator(startDate, endDate, offset, limit)
.map { it.toGetCalculateLiveByCreator() }
GetCalculateLiveByCreatorResponse(totalCount, items)
}
}

View File

@ -0,0 +1,14 @@
package kr.co.vividnext.sodalive.admin.calculate
import com.fasterxml.jackson.annotation.JsonProperty
data class GetCalculateLiveByCreatorItem(
@JsonProperty("email") val email: String,
@JsonProperty("nickname") val nickname: String,
@JsonProperty("totalCan") val totalCan: Int,
@JsonProperty("totalKrw") val totalKrw: Int,
@JsonProperty("paymentFee") val paymentFee: Int,
@JsonProperty("settlementAmount") val settlementAmount: Int,
@JsonProperty("tax") val tax: Int,
@JsonProperty("depositAmount") val depositAmount: Int
)

View File

@ -0,0 +1,44 @@
package kr.co.vividnext.sodalive.admin.calculate
import com.querydsl.core.annotations.QueryProjection
import java.math.BigDecimal
import java.math.RoundingMode
data class GetCalculateLiveByCreatorQueryData @QueryProjection constructor(
val email: String,
val nickname: String,
val totalCan: Int,
val settlementRatio: Int?
) {
fun toGetCalculateLiveByCreator(): GetCalculateLiveByCreatorItem {
// 원화 = totalCoin * 100 ( 캔 1개 = 100원 )
val totalKrw = BigDecimal(totalCan).multiply(BigDecimal(100))
// 결제수수료 : 6.6%
val paymentFee = totalKrw.multiply(BigDecimal(0.066))
// 정산금액 = (원화 - 결제수수료) 의 70%
val settlementAmount = if (settlementRatio != null) {
totalKrw.subtract(paymentFee).multiply(BigDecimal(settlementRatio).divide(BigDecimal(100.0)))
} else {
totalKrw.subtract(paymentFee).multiply(BigDecimal(0.7))
}
// 원천세 = 정산금액의 3.3%
val tax = settlementAmount.multiply(BigDecimal(0.033))
// 입금액
val depositAmount = settlementAmount.subtract(tax)
return GetCalculateLiveByCreatorItem(
email = email,
nickname = nickname,
totalCan = totalCan,
totalKrw = totalKrw.toInt(),
paymentFee = paymentFee.setScale(0, RoundingMode.HALF_UP).toInt(),
settlementAmount = settlementAmount.setScale(0, RoundingMode.HALF_UP).toInt(),
tax = tax.setScale(0, RoundingMode.HALF_UP).toInt(),
depositAmount = depositAmount.setScale(0, RoundingMode.HALF_UP).toInt()
)
}
}

View File

@ -0,0 +1,6 @@
package kr.co.vividnext.sodalive.admin.calculate
data class GetCalculateLiveByCreatorResponse(
val totalCount: Int,
val items: List<GetCalculateLiveByCreatorItem>
)