diff --git a/src/main/kotlin/kr/co/vividnext/sodalive/admin/calculate/AdminCalculateQueryRepository.kt b/src/main/kotlin/kr/co/vividnext/sodalive/admin/calculate/AdminCalculateQueryRepository.kt index ac92331..a4d25f3 100644 --- a/src/main/kotlin/kr/co/vividnext/sodalive/admin/calculate/AdminCalculateQueryRepository.kt +++ b/src/main/kotlin/kr/co/vividnext/sodalive/admin/calculate/AdminCalculateQueryRepository.kt @@ -122,12 +122,15 @@ class AdminCalculateQueryRepository(private val queryFactory: JPAQueryFactory) { order.type, order.can, order.id.count(), - order.can.sum() + order.can.sum(), + creatorSettlementRatio.contentSettlementRatio ) ) .from(order) .innerJoin(order.audioContent, audioContent) .innerJoin(audioContent.member, member) + .leftJoin(creatorSettlementRatio) + .on(member.id.eq(creatorSettlementRatio.member.id)) .where(order.isActive.isTrue) .groupBy(member.id, audioContent.id, order.type, order.can) .offset(offset) diff --git a/src/main/kotlin/kr/co/vividnext/sodalive/admin/calculate/GetCalculateCommunityPostQueryData.kt b/src/main/kotlin/kr/co/vividnext/sodalive/admin/calculate/GetCalculateCommunityPostQueryData.kt index 4bd63db..409caa5 100644 --- a/src/main/kotlin/kr/co/vividnext/sodalive/admin/calculate/GetCalculateCommunityPostQueryData.kt +++ b/src/main/kotlin/kr/co/vividnext/sodalive/admin/calculate/GetCalculateCommunityPostQueryData.kt @@ -1,7 +1,8 @@ package kr.co.vividnext.sodalive.admin.calculate import com.querydsl.core.annotations.QueryProjection -import kotlin.math.roundToInt +import java.math.BigDecimal +import java.math.RoundingMode data class GetCalculateCommunityPostQueryData @QueryProjection constructor( val nickname: String, @@ -13,14 +14,14 @@ data class GetCalculateCommunityPostQueryData @QueryProjection constructor( val settlementRatio: Int? ) { fun toGetCalculateCommunityPostResponse(): GetCalculateCommunityPostResponse { - val totalKrw = totalCan * 100 - val paymentFee = totalKrw * 0.066f + val totalKrw = BigDecimal(totalCan) * BigDecimal(100) + val paymentFee = totalKrw * BigDecimal(0.066) val settlementAmount = if (settlementRatio != null) { - (totalKrw.toFloat() - paymentFee) * (settlementRatio.toFloat() / 100.0f) + (totalKrw - paymentFee) * (BigDecimal(settlementRatio) / BigDecimal(100.0)) } else { - (totalKrw.toFloat() - paymentFee) * 0.7f + (totalKrw - paymentFee) * BigDecimal(0.7) } - val tax = settlementAmount * 0.033 + val tax = settlementAmount * BigDecimal(0.033) val depositAmount = settlementAmount - tax return GetCalculateCommunityPostResponse( @@ -30,11 +31,11 @@ data class GetCalculateCommunityPostQueryData @QueryProjection constructor( can = can, numberOfPurchase = numberOfPurchase.toInt(), totalCan = totalCan, - totalKrw = totalKrw, - paymentFee = paymentFee.roundToInt(), - settlementAmount = settlementAmount.roundToInt(), - tax = tax.roundToInt(), - depositAmount = depositAmount.roundToInt() + 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() ) } } diff --git a/src/main/kotlin/kr/co/vividnext/sodalive/admin/calculate/GetCalculateContentDonationQueryData.kt b/src/main/kotlin/kr/co/vividnext/sodalive/admin/calculate/GetCalculateContentDonationQueryData.kt index 77ed086..480d20a 100644 --- a/src/main/kotlin/kr/co/vividnext/sodalive/admin/calculate/GetCalculateContentDonationQueryData.kt +++ b/src/main/kotlin/kr/co/vividnext/sodalive/admin/calculate/GetCalculateContentDonationQueryData.kt @@ -1,7 +1,8 @@ package kr.co.vividnext.sodalive.admin.calculate import com.querydsl.core.annotations.QueryProjection -import kotlin.math.roundToInt +import java.math.BigDecimal +import java.math.RoundingMode data class GetCalculateContentDonationQueryData @QueryProjection constructor( // 등록 크리에이터 닉네임 @@ -21,22 +22,22 @@ data class GetCalculateContentDonationQueryData @QueryProjection constructor( ) { fun toGetCalculateContentDonationResponse(): GetCalculateContentDonationResponse { // 원화 = totalCoin * 100 ( 캔 1개 = 100원 ) - val totalKrw = totalCan * 100 + val totalKrw = BigDecimal(totalCan) * BigDecimal(100) // 결제수수료 : 6.6% - val paymentFee = totalKrw * 0.066f + val paymentFee = totalKrw * BigDecimal(0.066) // 정산금액 // 유료콘텐츠 (원화 - 결제수수료) 의 90% // 무료콘텐츠 (원화 - 결제수수료) 의 70% val settlementAmount = if (price > 0) { - (totalKrw.toFloat() - paymentFee) * 0.9 + (totalKrw - paymentFee) * BigDecimal(0.9) } else { - (totalKrw.toFloat() - paymentFee) * 0.7 + (totalKrw - paymentFee) * BigDecimal(0.7) } // 원천세 = 정산금액의 3.3% - val tax = settlementAmount * 0.033 + val tax = settlementAmount * BigDecimal(0.033) // 입금액 val depositAmount = settlementAmount - tax @@ -55,11 +56,11 @@ data class GetCalculateContentDonationQueryData @QueryProjection constructor( donationDate = donationDate, numberOfDonation = numberOfDonation.toInt(), totalCan = totalCan, - totalKrw = totalKrw, - paymentFee = paymentFee.roundToInt(), - settlementAmount = settlementAmount.roundToInt(), - tax = tax.roundToInt(), - depositAmount = depositAmount.roundToInt() + 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() ) } } diff --git a/src/main/kotlin/kr/co/vividnext/sodalive/admin/calculate/GetCalculateContentQueryData.kt b/src/main/kotlin/kr/co/vividnext/sodalive/admin/calculate/GetCalculateContentQueryData.kt index b886d53..de928dd 100644 --- a/src/main/kotlin/kr/co/vividnext/sodalive/admin/calculate/GetCalculateContentQueryData.kt +++ b/src/main/kotlin/kr/co/vividnext/sodalive/admin/calculate/GetCalculateContentQueryData.kt @@ -2,7 +2,8 @@ package kr.co.vividnext.sodalive.admin.calculate import com.querydsl.core.annotations.QueryProjection import kr.co.vividnext.sodalive.content.order.OrderType -import kotlin.math.roundToInt +import java.math.BigDecimal +import java.math.RoundingMode data class GetCalculateContentQueryData @QueryProjection constructor( // 등록 크리에이터 닉네임 @@ -31,23 +32,14 @@ data class GetCalculateContentQueryData @QueryProjection constructor( "소장" } - // 원화 = totalCoin * 100 ( 캔 1개 = 100원 ) - val totalKrw = totalCan * 100 - - // 결제수수료 : 6.6% - val paymentFee = totalKrw * 0.066f - - // 정산금액 = (원화 - 결제수수료) 의 70% + val totalKrw = BigDecimal(totalCan) * BigDecimal(100) + val paymentFee = totalKrw * BigDecimal(0.066) val settlementAmount = if (settlementRatio != null) { - (totalKrw.toFloat() - paymentFee) * (settlementRatio.toFloat() / 100.0f) + (totalKrw - paymentFee) * (BigDecimal(settlementRatio) / BigDecimal(100.0)) } else { - (totalKrw.toFloat() - paymentFee) * 0.7f + (totalKrw - paymentFee) * BigDecimal(0.7) } - - // 원천세 = 정산금액의 3.3% - val tax = settlementAmount * 0.033 - - // 입금액 + val tax = settlementAmount * BigDecimal(0.033) val depositAmount = settlementAmount - tax return GetCalculateContentResponse( @@ -59,11 +51,11 @@ data class GetCalculateContentQueryData @QueryProjection constructor( orderPrice = orderPrice, numberOfPeople = numberOfPeople.toInt(), totalCan = totalCan, - totalKrw = totalKrw, - paymentFee = paymentFee.roundToInt(), - settlementAmount = settlementAmount.roundToInt(), - tax = tax.roundToInt(), - depositAmount = depositAmount.roundToInt() + 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() ) } } diff --git a/src/main/kotlin/kr/co/vividnext/sodalive/admin/calculate/GetCalculateLiveQueryData.kt b/src/main/kotlin/kr/co/vividnext/sodalive/admin/calculate/GetCalculateLiveQueryData.kt index c1facb4..52d5e61 100644 --- a/src/main/kotlin/kr/co/vividnext/sodalive/admin/calculate/GetCalculateLiveQueryData.kt +++ b/src/main/kotlin/kr/co/vividnext/sodalive/admin/calculate/GetCalculateLiveQueryData.kt @@ -43,20 +43,20 @@ data class GetCalculateLiveQueryData @QueryProjection constructor( } // 원화 = totalCoin * 100 ( 캔 1개 = 100원 ) - val totalKrw = BigDecimal(totalAmount).multiply(BigDecimal(100)) + val totalKrw = BigDecimal(totalAmount) * BigDecimal(100) // 결제수수료 : 6.6% - val paymentFee = totalKrw.multiply(BigDecimal(0.066)) + val paymentFee = totalKrw * BigDecimal(0.066) // 정산금액 = (원화 - 결제수수료) 의 70% val settlementAmount = if (settlementRatio != null) { - totalKrw.subtract(paymentFee).multiply(BigDecimal(settlementRatio).divide(BigDecimal(100))) + (totalKrw - paymentFee) * (BigDecimal(settlementRatio) / BigDecimal(100.0)) } else { - totalKrw.subtract(paymentFee).multiply(BigDecimal(0.7)) + (totalKrw - paymentFee) * BigDecimal(0.7) } // 원천세 = 정산금액의 3.3% - val tax = settlementAmount.multiply(BigDecimal(0.033)) + val tax = settlementAmount * BigDecimal(0.033) // 입금액 val depositAmount = settlementAmount - tax diff --git a/src/main/kotlin/kr/co/vividnext/sodalive/admin/calculate/GetCumulativeSalesByContentResponse.kt b/src/main/kotlin/kr/co/vividnext/sodalive/admin/calculate/GetCumulativeSalesByContentResponse.kt index ac2a48c..34d7ce2 100644 --- a/src/main/kotlin/kr/co/vividnext/sodalive/admin/calculate/GetCumulativeSalesByContentResponse.kt +++ b/src/main/kotlin/kr/co/vividnext/sodalive/admin/calculate/GetCumulativeSalesByContentResponse.kt @@ -3,7 +3,8 @@ package kr.co.vividnext.sodalive.admin.calculate import com.fasterxml.jackson.annotation.JsonProperty import com.querydsl.core.annotations.QueryProjection import kr.co.vividnext.sodalive.content.order.OrderType -import kotlin.math.roundToInt +import java.math.BigDecimal +import java.math.RoundingMode data class GetCumulativeSalesByContentQueryData @QueryProjection constructor( // 등록 크리에이터 닉네임 @@ -19,7 +20,9 @@ data class GetCumulativeSalesByContentQueryData @QueryProjection constructor( // 인원 val numberOfPeople: Long, // 합계 - val totalCan: Int + val totalCan: Int, + // 정산비율 + val settlementRatio: Int? ) { fun toCumulativeSalesByContentItem(): CumulativeSalesByContentItem { val orderTypeStr = if (orderType == OrderType.RENTAL) { @@ -29,16 +32,21 @@ data class GetCumulativeSalesByContentQueryData @QueryProjection constructor( } // 원화 = totalCoin * 100 ( 캔 1개 = 100원 ) - val totalKrw = totalCan * 100 + val totalKrw = BigDecimal(totalCan) * BigDecimal(100) // 결제수수료 : 6.6% - val paymentFee = totalKrw * 0.066f + val paymentFee = totalKrw * BigDecimal(0.066) // 정산금액 = (원화 - 결제수수료) 의 70% - val settlementAmount = (totalKrw.toFloat() - paymentFee) * 0.7 + // 정산금액 = (원화 - 결제수수료) 의 70% + val settlementAmount = if (settlementRatio != null) { + (totalKrw - paymentFee) * (BigDecimal(settlementRatio) / BigDecimal(100.0)) + } else { + (totalKrw - paymentFee) * BigDecimal(0.7) + } // 원천세 = 정산금액의 3.3% - val tax = settlementAmount * 0.033 + val tax = settlementAmount * BigDecimal(0.033) // 입금액 val depositAmount = settlementAmount - tax @@ -51,11 +59,11 @@ data class GetCumulativeSalesByContentQueryData @QueryProjection constructor( orderPrice = orderPrice, numberOfPeople = numberOfPeople.toInt(), totalCan = totalCan, - totalKrw = totalKrw, - paymentFee = paymentFee.roundToInt(), - settlementAmount = settlementAmount.roundToInt(), - tax = tax.roundToInt(), - depositAmount = depositAmount.roundToInt() + 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() ) } } diff --git a/src/main/kotlin/kr/co/vividnext/sodalive/creator/admin/calculate/CreatorAdminCalculateQueryRepository.kt b/src/main/kotlin/kr/co/vividnext/sodalive/creator/admin/calculate/CreatorAdminCalculateQueryRepository.kt index 7f56747..590e27a 100644 --- a/src/main/kotlin/kr/co/vividnext/sodalive/creator/admin/calculate/CreatorAdminCalculateQueryRepository.kt +++ b/src/main/kotlin/kr/co/vividnext/sodalive/creator/admin/calculate/CreatorAdminCalculateQueryRepository.kt @@ -176,12 +176,15 @@ class CreatorAdminCalculateQueryRepository(private val queryFactory: JPAQueryFac order.type, order.can, order.id.count(), - order.can.sum() + order.can.sum(), + creatorSettlementRatio.contentSettlementRatio ) ) .from(order) .innerJoin(order.audioContent, audioContent) .innerJoin(audioContent.member, member) + .leftJoin(creatorSettlementRatio) + .on(member.id.eq(creatorSettlementRatio.member.id)) .where( audioContent.member.id.eq(memberId) .and(order.isActive.isTrue)