Compare commits
2 Commits
7055bb9872
...
54c0322398
Author | SHA1 | Date |
---|---|---|
|
54c0322398 | |
|
e3c33c71a0 |
|
@ -5,6 +5,7 @@ import kr.co.bootpay.Bootpay
|
|||
import kr.co.vividnext.sodalive.can.CanRepository
|
||||
import kr.co.vividnext.sodalive.can.charge.event.ChargeSpringEvent
|
||||
import kr.co.vividnext.sodalive.can.coupon.CanCouponNumberRepository
|
||||
import kr.co.vividnext.sodalive.can.coupon.CouponType
|
||||
import kr.co.vividnext.sodalive.can.payment.Payment
|
||||
import kr.co.vividnext.sodalive.can.payment.PaymentGateway
|
||||
import kr.co.vividnext.sodalive.can.payment.PaymentStatus
|
||||
|
@ -12,6 +13,11 @@ import kr.co.vividnext.sodalive.common.SodaException
|
|||
import kr.co.vividnext.sodalive.google.GooglePlayService
|
||||
import kr.co.vividnext.sodalive.member.Member
|
||||
import kr.co.vividnext.sodalive.member.MemberRepository
|
||||
import kr.co.vividnext.sodalive.point.MemberPoint
|
||||
import kr.co.vividnext.sodalive.point.MemberPointRepository
|
||||
import kr.co.vividnext.sodalive.point.PointGrantLog
|
||||
import kr.co.vividnext.sodalive.point.PointGrantLogRepository
|
||||
import kr.co.vividnext.sodalive.useraction.ActionType
|
||||
import okhttp3.MediaType.Companion.toMediaTypeOrNull
|
||||
import okhttp3.OkHttpClient
|
||||
import okhttp3.Request
|
||||
|
@ -27,6 +33,7 @@ import org.springframework.stereotype.Service
|
|||
import org.springframework.transaction.annotation.Transactional
|
||||
import java.math.BigDecimal
|
||||
import java.math.RoundingMode
|
||||
import java.time.LocalDateTime
|
||||
|
||||
@Service
|
||||
@Transactional(readOnly = true)
|
||||
|
@ -36,6 +43,9 @@ class ChargeService(
|
|||
private val memberRepository: MemberRepository,
|
||||
private val couponNumberRepository: CanCouponNumberRepository,
|
||||
|
||||
private val grantLogRepository: PointGrantLogRepository,
|
||||
private val memberPointRepository: MemberPointRepository,
|
||||
|
||||
private val objectMapper: ObjectMapper,
|
||||
private val okHttpClient: OkHttpClient,
|
||||
private val applicationEventPublisher: ApplicationEventPublisher,
|
||||
|
@ -64,23 +74,53 @@ class ChargeService(
|
|||
if (canCouponNumber.member != null) {
|
||||
throw SodaException("이미 사용한 쿠폰번호 입니다.")
|
||||
}
|
||||
|
||||
canCouponNumber.member = member
|
||||
|
||||
val coupon = canCouponNumber.canCoupon!!
|
||||
val couponCharge = Charge(0, coupon.can, status = ChargeStatus.COUPON)
|
||||
couponCharge.title = "${coupon.can} 캔"
|
||||
couponCharge.member = member
|
||||
|
||||
val payment = Payment(
|
||||
status = PaymentStatus.COMPLETE,
|
||||
paymentGateway = PaymentGateway.PG
|
||||
)
|
||||
payment.method = coupon.couponName
|
||||
couponCharge.payment = payment
|
||||
chargeRepository.save(couponCharge)
|
||||
when (coupon.couponType) {
|
||||
CouponType.CAN -> {
|
||||
val couponCharge = Charge(0, coupon.can, status = ChargeStatus.COUPON)
|
||||
couponCharge.title = "${coupon.can} 캔"
|
||||
couponCharge.member = member
|
||||
|
||||
member.charge(0, coupon.can, "pg")
|
||||
val payment = Payment(
|
||||
status = PaymentStatus.COMPLETE,
|
||||
paymentGateway = PaymentGateway.PG
|
||||
)
|
||||
payment.method = coupon.couponName
|
||||
couponCharge.payment = payment
|
||||
chargeRepository.save(couponCharge)
|
||||
|
||||
member.charge(0, coupon.can, "pg")
|
||||
}
|
||||
|
||||
CouponType.POINT -> {
|
||||
val memberId = member.id!!
|
||||
val point = coupon.can
|
||||
val actionType = ActionType.COUPON
|
||||
|
||||
grantLogRepository.save(
|
||||
PointGrantLog(
|
||||
memberId = memberId,
|
||||
point = point,
|
||||
actionType = actionType,
|
||||
policyId = null,
|
||||
orderId = null,
|
||||
couponName = coupon.couponName
|
||||
)
|
||||
)
|
||||
|
||||
memberPointRepository.save(
|
||||
MemberPoint(
|
||||
memberId = memberId,
|
||||
point = point,
|
||||
actionType = actionType,
|
||||
expiresAt = LocalDateTime.now().plusDays(3)
|
||||
)
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Transactional
|
||||
|
|
|
@ -3,13 +3,21 @@ package kr.co.vividnext.sodalive.can.coupon
|
|||
import kr.co.vividnext.sodalive.common.BaseEntity
|
||||
import java.time.LocalDateTime
|
||||
import javax.persistence.Entity
|
||||
import javax.persistence.EnumType
|
||||
import javax.persistence.Enumerated
|
||||
|
||||
@Entity
|
||||
data class CanCoupon(
|
||||
val couponName: String,
|
||||
@Enumerated(EnumType.STRING)
|
||||
val couponType: CouponType,
|
||||
val can: Int,
|
||||
val couponCount: Int,
|
||||
var validity: LocalDateTime,
|
||||
var isActive: Boolean,
|
||||
var isMultipleUse: Boolean
|
||||
) : BaseEntity()
|
||||
|
||||
enum class CouponType {
|
||||
CAN, POINT
|
||||
}
|
||||
|
|
|
@ -79,6 +79,7 @@ class CanCouponNumberQueryRepositoryImpl(private val queryFactory: JPAQueryFacto
|
|||
override fun findByCouponNumber(couponNumber: String): CanCouponNumber? {
|
||||
return queryFactory
|
||||
.selectFrom(canCouponNumber)
|
||||
.innerJoin(canCouponNumber.canCoupon, canCoupon)
|
||||
.where(canCouponNumber.couponNumber.eq(couponNumber))
|
||||
.fetchFirst()
|
||||
}
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
package kr.co.vividnext.sodalive.can.coupon
|
||||
|
||||
import com.querydsl.core.types.dsl.CaseBuilder
|
||||
import com.querydsl.core.types.dsl.DateTimePath
|
||||
import com.querydsl.core.types.dsl.Expressions
|
||||
import com.querydsl.core.types.dsl.StringTemplate
|
||||
|
@ -30,6 +31,9 @@ class CanCouponQueryRepositoryImpl(private val queryFactory: JPAQueryFactory) :
|
|||
QGetCouponListItemResponse(
|
||||
canCoupon.id,
|
||||
canCoupon.couponName,
|
||||
CaseBuilder()
|
||||
.`when`(canCoupon.couponType.eq(CouponType.POINT)).then("포인트 쿠폰")
|
||||
.otherwise("캔 쿠폰"),
|
||||
canCoupon.can,
|
||||
canCoupon.couponCount,
|
||||
Expressions.ZERO,
|
||||
|
|
|
@ -68,15 +68,12 @@ class CanCouponService(
|
|||
|
||||
fun getCouponList(offset: Long, limit: Long): GetCouponListResponse {
|
||||
val totalCount = repository.getCouponTotalCount()
|
||||
|
||||
val items = repository.getCouponList(offset = offset, limit = limit)
|
||||
.asSequence()
|
||||
.map {
|
||||
val useCouponCount = couponNumberRepository.getUseCouponCount(id = it.id)
|
||||
it.useCouponCount = useCouponCount
|
||||
it
|
||||
}
|
||||
.toList()
|
||||
|
||||
return GetCouponListResponse(totalCount, items)
|
||||
}
|
||||
|
|
|
@ -4,6 +4,7 @@ import com.fasterxml.jackson.annotation.JsonProperty
|
|||
|
||||
data class GenerateCanCouponRequest(
|
||||
@JsonProperty("couponName") val couponName: String,
|
||||
@JsonProperty("couponType") val couponType: CouponType,
|
||||
@JsonProperty("can") val can: Int,
|
||||
@JsonProperty("validity") val validity: String,
|
||||
@JsonProperty("isMultipleUse") val isMultipleUse: Boolean,
|
||||
|
|
|
@ -10,6 +10,7 @@ data class GetCouponListResponse(
|
|||
data class GetCouponListItemResponse @QueryProjection constructor(
|
||||
val id: Long,
|
||||
val couponName: String,
|
||||
val couponType: String,
|
||||
val can: Int,
|
||||
val couponCount: Int,
|
||||
var useCouponCount: Int,
|
||||
|
|
|
@ -13,5 +13,6 @@ data class PointGrantLog(
|
|||
@Enumerated(EnumType.STRING)
|
||||
val actionType: ActionType,
|
||||
val policyId: Long?,
|
||||
val orderId: Long?
|
||||
val orderId: Long?,
|
||||
val couponName: String? = null
|
||||
) : BaseEntity()
|
||||
|
|
|
@ -5,5 +5,6 @@ enum class ActionType(val displayName: String) {
|
|||
USER_AUTHENTICATION("본인인증"),
|
||||
CONTENT_COMMENT("콘텐츠 댓글"),
|
||||
ORDER_CONTENT_COMMENT("구매한 콘텐츠 댓글"),
|
||||
LIVE_CONTINUOUS_LISTEN_30("라이브 연속 청취 30분")
|
||||
LIVE_CONTINUOUS_LISTEN_30("라이브 연속 청취 30분"),
|
||||
COUPON("쿠폰")
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue