|
|
@@ -1,9 +1,12 @@
|
|
|
package com.example.cinema.blImpl;
|
|
|
|
|
|
+import com.example.cinema.bl.CouponService;
|
|
|
import com.example.cinema.bl.TicketService;
|
|
|
+import com.example.cinema.data.CouponMapper;
|
|
|
import com.example.cinema.data.ScheduleMapper;
|
|
|
import com.example.cinema.data.TicketMapper;
|
|
|
import com.example.cinema.data.VIPCardMapper;
|
|
|
+import com.example.cinema.po.Coupon;
|
|
|
import com.example.cinema.po.Ticket;
|
|
|
import com.example.cinema.po.VIPCard;
|
|
|
import com.example.cinema.vo.*;
|
|
|
@@ -26,6 +29,8 @@ public class TicketServiceImpl implements TicketService {
|
|
|
VIPCardMapper vipCardMapper;
|
|
|
@Autowired
|
|
|
ScheduleMapper scheduleMapper;
|
|
|
+ @Autowired
|
|
|
+ CouponMapper couponMapper;
|
|
|
|
|
|
@Override
|
|
|
public ResponseVO addTicket(TicketForm ticketForm) {
|
|
|
@@ -49,10 +54,15 @@ public class TicketServiceImpl implements TicketService {
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public ResponseVO completeTicket(int id) {
|
|
|
+ @Transactional
|
|
|
+ public ResponseVO completeTicket(int id,int couponId) {
|
|
|
try {
|
|
|
ticketMapper.updateTicketState(id, 1);
|
|
|
- return ResponseVO.buildSuccess(ticketMapper.selectTicketById(id).getVO());
|
|
|
+ Ticket ticket=ticketMapper.selectTicketById(id);
|
|
|
+ if(couponId!=0) {
|
|
|
+ couponMapper.deleteCouponUser(couponId, ticket.getUserId());
|
|
|
+ }
|
|
|
+ return ResponseVO.buildSuccess(ticket.getVO());
|
|
|
} catch (Exception e) {
|
|
|
e.printStackTrace();
|
|
|
return ResponseVO.buildFailure("失败");
|
|
|
@@ -90,18 +100,22 @@ public class TicketServiceImpl implements TicketService {
|
|
|
|
|
|
@Override
|
|
|
@Transactional
|
|
|
- public ResponseVO completeByVIPCard(int ticketId) {
|
|
|
+ public ResponseVO completeByVIPCard(int ticketId,int couponId) {
|
|
|
try {
|
|
|
Ticket ticket=ticketMapper.selectTicketById(ticketId);
|
|
|
VIPCard vipCard = vipCardMapper.selectCardByUserId(ticket.getUserId());
|
|
|
ScheduleItem scheduleItem = scheduleMapper.selectScheduleById(ticket.getScheduleId());
|
|
|
- //todo 优惠券
|
|
|
+ //todo 优惠券门槛校验
|
|
|
double balance = vipCard.getBalance() - scheduleItem.getFare();
|
|
|
+ if(couponId!=0) {
|
|
|
+ Coupon coupon=couponMapper.selectById(couponId);
|
|
|
+ balance+=coupon.getDiscountAmount();
|
|
|
+ }
|
|
|
if (balance < 0) {
|
|
|
return ResponseVO.buildFailure("会员卡余额不足");
|
|
|
}
|
|
|
vipCardMapper.updateCardBalance(vipCard.getId(), balance);
|
|
|
- completeTicket(ticketId);
|
|
|
+ completeTicket(ticketId,couponId);
|
|
|
ticket.setState(1);
|
|
|
return ResponseVO.buildSuccess(ticket.getVO());
|
|
|
} catch (Exception e) {
|