test #324
| @@ -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,10 +74,12 @@ class ChargeService( | ||||
|         if (canCouponNumber.member != null) { | ||||
|             throw SodaException("이미 사용한 쿠폰번호 입니다.") | ||||
|         } | ||||
|  | ||||
|         canCouponNumber.member = member | ||||
|  | ||||
|         val coupon = canCouponNumber.canCoupon!! | ||||
|  | ||||
|         when (coupon.couponType) { | ||||
|             CouponType.CAN -> { | ||||
|                 val couponCharge = Charge(0, coupon.can, status = ChargeStatus.COUPON) | ||||
|                 couponCharge.title = "${coupon.can} 캔" | ||||
|                 couponCharge.member = member | ||||
| @@ -83,6 +95,34 @@ class ChargeService( | ||||
|                 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 | ||||
|     fun charge(member: Member, request: ChargeRequest): ChargeResponse { | ||||
|         val can = canRepository.findByIdOrNull(request.canId) | ||||
|   | ||||
| @@ -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() | ||||
|   | ||||
		Reference in New Issue
	
	Block a user