test #358
@@ -1,7 +1,7 @@
|
|||||||
package kr.co.vividnext.sodalive.admin.can
|
package kr.co.vividnext.sodalive.admin.can
|
||||||
|
|
||||||
data class AdminCanChargeRequest(
|
data class AdminCanChargeRequest(
|
||||||
val memberId: Long,
|
val memberIds: List<Long>,
|
||||||
val method: String,
|
val method: String,
|
||||||
val can: Int
|
val can: Int
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -40,22 +40,27 @@ class AdminCanService(
|
|||||||
|
|
||||||
@Transactional
|
@Transactional
|
||||||
fun charge(request: AdminCanChargeRequest) {
|
fun charge(request: AdminCanChargeRequest) {
|
||||||
val member = memberRepository.findByIdOrNull(request.memberId)
|
|
||||||
?: throw SodaException("잘못된 회원번호 입니다.")
|
|
||||||
|
|
||||||
if (request.can <= 0) throw SodaException("1 캔 이상 입력하세요.")
|
if (request.can <= 0) throw SodaException("1 캔 이상 입력하세요.")
|
||||||
if (request.method.isBlank()) throw SodaException("기록내용을 입력하세요.")
|
if (request.method.isBlank()) throw SodaException("기록내용을 입력하세요.")
|
||||||
|
|
||||||
val charge = Charge(0, request.can, status = ChargeStatus.ADMIN)
|
val ids = request.memberIds.distinct()
|
||||||
charge.title = "${request.can.moneyFormat()} 캔"
|
if (ids.isEmpty()) throw SodaException("회원번호를 입력하세요.")
|
||||||
charge.member = member
|
|
||||||
|
|
||||||
val payment = Payment(status = PaymentStatus.COMPLETE, paymentGateway = PaymentGateway.PG)
|
val members = memberRepository.findAllById(ids).toList()
|
||||||
payment.method = request.method
|
if (members.size != ids.size) throw SodaException("잘못된 회원번호 입니다.")
|
||||||
charge.payment = payment
|
|
||||||
|
|
||||||
chargeRepository.save(charge)
|
members.forEach { member ->
|
||||||
|
val charge = Charge(0, request.can, status = ChargeStatus.ADMIN)
|
||||||
|
charge.title = "${request.can.moneyFormat()} 캔"
|
||||||
|
charge.member = member
|
||||||
|
|
||||||
member.pgRewardCan += charge.rewardCan
|
val payment = Payment(status = PaymentStatus.COMPLETE, paymentGateway = PaymentGateway.PG)
|
||||||
|
payment.method = request.method
|
||||||
|
charge.payment = payment
|
||||||
|
|
||||||
|
chargeRepository.save(charge)
|
||||||
|
|
||||||
|
member.pgRewardCan += charge.rewardCan
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user