From 9d7bd8e9abbaa50809bdf9f218422ed438742719 Mon Sep 17 00:00:00 2001 From: Klaus Date: Sat, 29 Jun 2024 19:00:16 +0900 Subject: [PATCH 1/5] =?UTF-8?q?PG=EA=B2=B0=EC=A0=9C=20-=20=ED=97=A5?= =?UTF-8?q?=ED=86=A0=ED=8C=8C=EC=9D=B4=EB=82=B8=EC=85=9C=20=EA=B2=80?= =?UTF-8?q?=EC=A6=9D=EC=BD=94=EB=93=9C=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../sodalive/can/charge/ChargeController.kt | 6 +++ .../sodalive/can/charge/ChargeService.kt | 44 +++++++++++++++++++ .../can/charge/temp/ChargeTempService.kt | 4 +- .../sodalive/explorer/ExplorerService.kt | 5 +-- src/main/resources/application.yml | 2 + 5 files changed, 55 insertions(+), 6 deletions(-) diff --git a/src/main/kotlin/kr/co/vividnext/sodalive/can/charge/ChargeController.kt b/src/main/kotlin/kr/co/vividnext/sodalive/can/charge/ChargeController.kt index 53c0eca..cd6b8da 100644 --- a/src/main/kotlin/kr/co/vividnext/sodalive/can/charge/ChargeController.kt +++ b/src/main/kotlin/kr/co/vividnext/sodalive/can/charge/ChargeController.kt @@ -33,6 +33,12 @@ class ChargeController(private val service: ChargeService) { @AuthenticationPrincipal user: User ) = ApiResponse.ok(service.verify(user, verifyRequest)) + @PostMapping("/verify/hecto") + fun verifyHecto( + @RequestBody verifyRequest: VerifyRequest, + @AuthenticationPrincipal user: User + ) = ApiResponse.ok(service.verifyHecto(user, verifyRequest)) + @PostMapping("/apple") fun appleCharge( @RequestBody chargeRequest: AppleChargeRequest, diff --git a/src/main/kotlin/kr/co/vividnext/sodalive/can/charge/ChargeService.kt b/src/main/kotlin/kr/co/vividnext/sodalive/can/charge/ChargeService.kt index 57bf8a9..f65c389 100644 --- a/src/main/kotlin/kr/co/vividnext/sodalive/can/charge/ChargeService.kt +++ b/src/main/kotlin/kr/co/vividnext/sodalive/can/charge/ChargeService.kt @@ -45,6 +45,10 @@ class ChargeService( private val bootpayApplicationId: String, @Value("\${bootpay.private-key}") private val bootpayPrivateKey: String, + @Value("\${bootpay.hecto-application-id}") + private val bootpayHectoApplicationId: String, + @Value("\${bootpay.hecto-private-key}") + private val bootpayHectoPrivateKey: String, @Value("\${apple.iap-verify-sandbox-url}") private val appleInAppVerifySandBoxUrl: String, @Value("\${apple.iap-verify-url}") @@ -137,6 +141,46 @@ class ChargeService( } } + @Transactional + fun verifyHecto(user: User, verifyRequest: VerifyRequest) { + val charge = chargeRepository.findByIdOrNull(verifyRequest.orderId.toLong()) + ?: throw SodaException("결제정보에 오류가 있습니다.") + val member = memberRepository.findByEmail(user.username) + ?: throw SodaException("로그인 정보를 확인해주세요.") + + if (charge.payment!!.paymentGateway == PaymentGateway.PG) { + val bootpay = Bootpay(bootpayHectoApplicationId, bootpayHectoPrivateKey) + + try { + bootpay.accessToken + val verifyResult = objectMapper.convertValue( + bootpay.getReceipt(verifyRequest.receiptId), + VerifyResult::class.java + ) + + if (verifyResult.status == 1 && verifyResult.price == charge.can?.price) { + charge.payment?.receiptId = verifyResult.receiptId + charge.payment?.method = verifyResult.method + charge.payment?.status = PaymentStatus.COMPLETE + member.charge(charge.chargeCan, charge.rewardCan, "pg") + + applicationEventPublisher.publishEvent( + ChargeSpringEvent( + chargeId = charge.id!!, + memberId = member.id!! + ) + ) + } else { + throw SodaException("결제정보에 오류가 있습니다.") + } + } catch (e: Exception) { + throw SodaException("결제정보에 오류가 있습니다.") + } + } else { + throw SodaException("결제정보에 오류가 있습니다.") + } + } + @Transactional fun appleCharge(member: Member, request: AppleChargeRequest): ChargeResponse { val charge = Charge(request.chargeCan, 0) diff --git a/src/main/kotlin/kr/co/vividnext/sodalive/can/charge/temp/ChargeTempService.kt b/src/main/kotlin/kr/co/vividnext/sodalive/can/charge/temp/ChargeTempService.kt index a578dac..8e2e645 100644 --- a/src/main/kotlin/kr/co/vividnext/sodalive/can/charge/temp/ChargeTempService.kt +++ b/src/main/kotlin/kr/co/vividnext/sodalive/can/charge/temp/ChargeTempService.kt @@ -28,9 +28,9 @@ class ChargeTempService( private val objectMapper: ObjectMapper, - @Value("\${bootpay.application-id}") + @Value("\${bootpay.hecto-application-id}") private val bootpayApplicationId: String, - @Value("\${bootpay.private-key}") + @Value("\${bootpay.hecto-private-key}") private val bootpayPrivateKey: String ) { diff --git a/src/main/kotlin/kr/co/vividnext/sodalive/explorer/ExplorerService.kt b/src/main/kotlin/kr/co/vividnext/sodalive/explorer/ExplorerService.kt index 20921fb..f6c620f 100644 --- a/src/main/kotlin/kr/co/vividnext/sodalive/explorer/ExplorerService.kt +++ b/src/main/kotlin/kr/co/vividnext/sodalive/explorer/ExplorerService.kt @@ -301,11 +301,9 @@ class ExplorerService( member: Member, pageable: Pageable ): GetFollowerListResponse { - val totalCount = queryRepository - .getFollowerListTotalCount(creatorId) + val totalCount = queryRepository.getFollowerListTotalCount(creatorId) val followerList = queryRepository.getFollowerList(creatorId, pageable.offset, pageable.pageSize.toLong()) - .asSequence() .map { val isFollow = if (it.role == MemberRole.CREATOR) { queryRepository.isFollow(creatorId = it.userId, memberId = member.id!!) @@ -320,7 +318,6 @@ class ExplorerService( isFollow = isFollow ) } - .toList() return GetFollowerListResponse(totalCount = totalCount, items = followerList) } diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml index 62f24c6..6dc7c92 100644 --- a/src/main/resources/application.yml +++ b/src/main/resources/application.yml @@ -11,6 +11,8 @@ logging: bootpay: applicationId: ${BOOTPAY_APPLICATION_ID} privateKey: ${BOOTPAY_PRIVATE_KEY} + hectoApplicationId: ${BOOTPAY_APPLICATION_HECTO_ID} + hectoPrivateKey: ${BOOTPAY_PRIVATE_HECTO_KEY} apple: iapVerifyUrl: https://buy.itunes.apple.com/verifyReceipt From fded23b97d49ed500455fb61b08cff440146eab0 Mon Sep 17 00:00:00 2001 From: Klaus Date: Tue, 2 Jul 2024 14:44:36 +0900 Subject: [PATCH 2/5] =?UTF-8?q?=EB=9D=BC=EC=9D=B4=EB=B8=8C=20=EC=A0=95?= =?UTF-8?q?=EC=82=B0=20-=20float=20=EB=8C=80=EC=8B=A0=20bigdecimal?= =?UTF-8?q?=EB=A1=9C=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../calculate/GetCalculateLiveQueryData.kt | 23 ++++++++++--------- 1 file changed, 12 insertions(+), 11 deletions(-) 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 d372c7f..c1facb4 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 @@ -2,7 +2,8 @@ package kr.co.vividnext.sodalive.admin.calculate import com.querydsl.core.annotations.QueryProjection import kr.co.vividnext.sodalive.can.use.CanUsage -import kotlin.math.roundToInt +import java.math.BigDecimal +import java.math.RoundingMode data class GetCalculateLiveQueryData @QueryProjection constructor( val email: String, @@ -42,20 +43,20 @@ data class GetCalculateLiveQueryData @QueryProjection constructor( } // 원화 = totalCoin * 100 ( 캔 1개 = 100원 ) - val totalKrw = totalAmount * 100 + val totalKrw = BigDecimal(totalAmount).multiply(BigDecimal(100)) // 결제수수료 : 6.6% - val paymentFee = totalKrw * 0.066f + val paymentFee = totalKrw.multiply(BigDecimal(0.066)) // 정산금액 = (원화 - 결제수수료) 의 70% val settlementAmount = if (settlementRatio != null) { - (totalKrw.toFloat() - paymentFee) * (settlementRatio.toFloat() / 100.0f) + totalKrw.subtract(paymentFee).multiply(BigDecimal(settlementRatio).divide(BigDecimal(100))) } else { - (totalKrw.toFloat() - paymentFee) * 0.7f + totalKrw.subtract(paymentFee).multiply(BigDecimal(0.7)) } // 원천세 = 정산금액의 3.3% - val tax = settlementAmount * 0.033 + val tax = settlementAmount.multiply(BigDecimal(0.033)) // 입금액 val depositAmount = settlementAmount - tax @@ -69,11 +70,11 @@ data class GetCalculateLiveQueryData @QueryProjection constructor( canUsageStr = canUsageStr, numberOfPeople = numberOfPeople, totalAmount = totalAmount, - 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() ) } } From 2c77143fc22ec20bb955354fca8ad124a08ccc19 Mon Sep 17 00:00:00 2001 From: Klaus Date: Tue, 2 Jul 2024 16:47:31 +0900 Subject: [PATCH 3/5] =?UTF-8?q?=EC=9D=BC=EC=9E=90=EB=B3=84=20=EC=BD=98?= =?UTF-8?q?=ED=85=90=EC=B8=A0=20=EC=A0=95=EC=82=B0,=20=EC=BD=98=ED=85=90?= =?UTF-8?q?=EC=B8=A0=EB=B3=84=20=EB=88=84=EC=A0=81=20=ED=98=84=ED=99=A9,?= =?UTF-8?q?=20=ED=9B=84=EC=9B=90=EC=A0=95=EC=82=B0,=20=EC=BB=A4=EB=AE=A4?= =?UTF-8?q?=EB=8B=88=ED=8B=B0=20=EC=A0=95=EC=82=B0=20-=20float=20=EB=8C=80?= =?UTF-8?q?=EC=8B=A0=20bigdecimal=EB=A1=9C=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../AdminCalculateQueryRepository.kt | 5 ++- .../GetCalculateCommunityPostQueryData.kt | 23 ++++++------- .../GetCalculateContentDonationQueryData.kt | 23 ++++++------- .../calculate/GetCalculateContentQueryData.kt | 32 +++++++------------ .../calculate/GetCalculateLiveQueryData.kt | 10 +++--- .../GetCumulativeSalesByContentResponse.kt | 30 ++++++++++------- .../CreatorAdminCalculateQueryRepository.kt | 5 ++- 7 files changed, 68 insertions(+), 60 deletions(-) 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) From d3483c80626860252cf1cdd85a360779377ca3e4 Mon Sep 17 00:00:00 2001 From: Klaus Date: Tue, 2 Jul 2024 17:40:41 +0900 Subject: [PATCH 4/5] =?UTF-8?q?=EB=9D=BC=EC=9D=B4=EB=B8=8C=20=EC=A0=95?= =?UTF-8?q?=EC=82=B0,=20=EC=9D=BC=EC=9E=90=EB=B3=84=20=EC=BD=98=ED=85=90?= =?UTF-8?q?=EC=B8=A0=20=EC=A0=95=EC=82=B0,=20=EC=BD=98=ED=85=90=EC=B8=A0?= =?UTF-8?q?=EB=B3=84=20=EB=88=84=EC=A0=81=20=ED=98=84=ED=99=A9,=20?= =?UTF-8?q?=ED=9B=84=EC=9B=90=EC=A0=95=EC=82=B0,=20=EC=BB=A4=EB=AE=A4?= =?UTF-8?q?=EB=8B=88=ED=8B=B0=20=EC=A0=95=EC=82=B0=20-=20float=20=EB=8C=80?= =?UTF-8?q?=EC=8B=A0=20bigdecimal=EB=A1=9C=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../GetCalculateCommunityPostQueryData.kt | 21 +++++++++++++------ .../GetCalculateContentDonationQueryData.kt | 12 +++++------ .../calculate/GetCalculateContentQueryData.kt | 20 ++++++++++++------ .../calculate/GetCalculateLiveQueryData.kt | 12 +++++------ .../GetCumulativeSalesByContentResponse.kt | 13 ++++++------ 5 files changed, 47 insertions(+), 31 deletions(-) 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 409caa5..009eeb9 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 @@ -14,15 +14,24 @@ data class GetCalculateCommunityPostQueryData @QueryProjection constructor( val settlementRatio: Int? ) { fun toGetCalculateCommunityPostResponse(): GetCalculateCommunityPostResponse { - val totalKrw = BigDecimal(totalCan) * BigDecimal(100) - val paymentFee = totalKrw * BigDecimal(0.066) + // 원화 = 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 - paymentFee) * (BigDecimal(settlementRatio) / BigDecimal(100.0)) + totalKrw.subtract(paymentFee).multiply(BigDecimal(settlementRatio).divide(BigDecimal(100.0))) } else { - (totalKrw - paymentFee) * BigDecimal(0.7) + totalKrw.subtract(paymentFee).multiply(BigDecimal(0.7)) } - val tax = settlementAmount * BigDecimal(0.033) - val depositAmount = settlementAmount - tax + + // 원천세 = 정산금액의 3.3% + val tax = settlementAmount.multiply(BigDecimal(0.033)) + + // 입금액 + val depositAmount = settlementAmount.subtract(tax) return GetCalculateCommunityPostResponse( nickname = nickname, 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 480d20a..6757611 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 @@ -22,25 +22,25 @@ data class GetCalculateContentDonationQueryData @QueryProjection constructor( ) { fun toGetCalculateContentDonationResponse(): GetCalculateContentDonationResponse { // 원화 = totalCoin * 100 ( 캔 1개 = 100원 ) - val totalKrw = BigDecimal(totalCan) * BigDecimal(100) + val totalKrw = BigDecimal(totalCan).multiply(BigDecimal(100)) // 결제수수료 : 6.6% - val paymentFee = totalKrw * BigDecimal(0.066) + val paymentFee = totalKrw.multiply(BigDecimal(0.066)) // 정산금액 // 유료콘텐츠 (원화 - 결제수수료) 의 90% // 무료콘텐츠 (원화 - 결제수수료) 의 70% val settlementAmount = if (price > 0) { - (totalKrw - paymentFee) * BigDecimal(0.9) + (totalKrw - paymentFee).multiply(BigDecimal(0.9)) } else { - (totalKrw - paymentFee) * BigDecimal(0.7) + (totalKrw - paymentFee).multiply(BigDecimal(0.7)) } // 원천세 = 정산금액의 3.3% - val tax = settlementAmount * BigDecimal(0.033) + val tax = settlementAmount.multiply(BigDecimal(0.033)) // 입금액 - val depositAmount = settlementAmount - tax + val depositAmount = settlementAmount.subtract(tax) val paidOrFree = if (price > 0) { "유료" 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 de928dd..cf0a0c6 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 @@ -32,15 +32,23 @@ data class GetCalculateContentQueryData @QueryProjection constructor( "소장" } - val totalKrw = BigDecimal(totalCan) * BigDecimal(100) - val paymentFee = totalKrw * BigDecimal(0.066) + // 원화 = 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 - paymentFee) * (BigDecimal(settlementRatio) / BigDecimal(100.0)) + totalKrw.subtract(paymentFee).multiply(BigDecimal(settlementRatio).divide(BigDecimal(100.0))) } else { - (totalKrw - paymentFee) * BigDecimal(0.7) + totalKrw.subtract(paymentFee).multiply(BigDecimal(0.7)) } - val tax = settlementAmount * BigDecimal(0.033) - val depositAmount = settlementAmount - tax + + // 원천세 = 정산금액의 3.3% + val tax = settlementAmount.multiply(BigDecimal(0.033)) + + val depositAmount = settlementAmount.subtract(tax) return GetCalculateContentResponse( nickname = nickname, 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 52d5e61..41b6515 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,23 +43,23 @@ data class GetCalculateLiveQueryData @QueryProjection constructor( } // 원화 = totalCoin * 100 ( 캔 1개 = 100원 ) - val totalKrw = BigDecimal(totalAmount) * BigDecimal(100) + val totalKrw = BigDecimal(totalAmount).multiply(BigDecimal(100)) // 결제수수료 : 6.6% - val paymentFee = totalKrw * BigDecimal(0.066) + val paymentFee = totalKrw.multiply(BigDecimal(0.066)) // 정산금액 = (원화 - 결제수수료) 의 70% val settlementAmount = if (settlementRatio != null) { - (totalKrw - paymentFee) * (BigDecimal(settlementRatio) / BigDecimal(100.0)) + totalKrw.subtract(paymentFee).multiply(BigDecimal(settlementRatio).divide(BigDecimal(100.0))) } else { - (totalKrw - paymentFee) * BigDecimal(0.7) + totalKrw.subtract(paymentFee).multiply(BigDecimal(0.7)) } // 원천세 = 정산금액의 3.3% - val tax = settlementAmount * BigDecimal(0.033) + val tax = settlementAmount.multiply(BigDecimal(0.033)) // 입금액 - val depositAmount = settlementAmount - tax + val depositAmount = settlementAmount.subtract(tax) return GetCalculateLiveResponse( email = email, 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 34d7ce2..5c49858 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 @@ -32,24 +32,23 @@ data class GetCumulativeSalesByContentQueryData @QueryProjection constructor( } // 원화 = totalCoin * 100 ( 캔 1개 = 100원 ) - val totalKrw = BigDecimal(totalCan) * BigDecimal(100) + val totalKrw = BigDecimal(totalCan).multiply(BigDecimal(100)) // 결제수수료 : 6.6% - val paymentFee = totalKrw * BigDecimal(0.066) + val paymentFee = totalKrw.multiply(BigDecimal(0.066)) - // 정산금액 = (원화 - 결제수수료) 의 70% // 정산금액 = (원화 - 결제수수료) 의 70% val settlementAmount = if (settlementRatio != null) { - (totalKrw - paymentFee) * (BigDecimal(settlementRatio) / BigDecimal(100.0)) + totalKrw.subtract(paymentFee).multiply(BigDecimal(settlementRatio).divide(BigDecimal(100.0))) } else { - (totalKrw - paymentFee) * BigDecimal(0.7) + totalKrw.subtract(paymentFee).multiply(BigDecimal(0.7)) } // 원천세 = 정산금액의 3.3% - val tax = settlementAmount * BigDecimal(0.033) + val tax = settlementAmount.multiply(BigDecimal(0.033)) // 입금액 - val depositAmount = settlementAmount - tax + val depositAmount = settlementAmount.subtract(tax) return CumulativeSalesByContentItem( nickname = nickname, From 27fbfd49e2bef737dd924da1545a663d662cb7bb Mon Sep 17 00:00:00 2001 From: Klaus Date: Tue, 2 Jul 2024 17:52:45 +0900 Subject: [PATCH 5/5] =?UTF-8?q?=EB=9D=BC=EC=9D=B4=EB=B8=8C=20=EC=A0=95?= =?UTF-8?q?=EC=82=B0,=20=EC=9D=BC=EC=9E=90=EB=B3=84=20=EC=BD=98=ED=85=90?= =?UTF-8?q?=EC=B8=A0=20=EC=A0=95=EC=82=B0,=20=EC=BD=98=ED=85=90=EC=B8=A0?= =?UTF-8?q?=EB=B3=84=20=EB=88=84=EC=A0=81=20=ED=98=84=ED=99=A9,=20?= =?UTF-8?q?=ED=9B=84=EC=9B=90=EC=A0=95=EC=82=B0,=20=EC=BB=A4=EB=AE=A4?= =?UTF-8?q?=EB=8B=88=ED=8B=B0=20=EC=A0=95=EC=82=B0=20-=20float=20=EB=8C=80?= =?UTF-8?q?=EC=8B=A0=20bigdecimal=EB=A1=9C=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../admin/calculate/GetCalculateContentDonationQueryData.kt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 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 6757611..22651a8 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 @@ -31,9 +31,9 @@ data class GetCalculateContentDonationQueryData @QueryProjection constructor( // 유료콘텐츠 (원화 - 결제수수료) 의 90% // 무료콘텐츠 (원화 - 결제수수료) 의 70% val settlementAmount = if (price > 0) { - (totalKrw - paymentFee).multiply(BigDecimal(0.9)) + totalKrw.subtract(paymentFee).multiply(BigDecimal(0.9)) } else { - (totalKrw - paymentFee).multiply(BigDecimal(0.7)) + totalKrw.subtract(paymentFee).multiply(BigDecimal(0.7)) } // 원천세 = 정산금액의 3.3%