|
@@ -12,6 +12,7 @@ package com.qs.mp.web.controller.api.user;
|
|
|
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
+import com.qs.mp.admin.domain.Coupon;
|
|
|
import com.qs.mp.admin.domain.Ticket;
|
|
|
import com.qs.mp.admin.domain.TicketAwardsPrize;
|
|
|
import com.qs.mp.admin.domain.TicketBox;
|
|
@@ -23,18 +24,29 @@ import com.qs.mp.admin.domain.vo.TicketVO;
|
|
|
import com.qs.mp.admin.service.ITicketAwardsPrizeService;
|
|
|
import com.qs.mp.admin.service.ITicketBoxService;
|
|
|
import com.qs.mp.admin.service.ITicketService;
|
|
|
+import com.qs.mp.channel.domain.Channel;
|
|
|
import com.qs.mp.channel.domain.ChannelAddr;
|
|
|
import com.qs.mp.channel.domain.ChannelCart;
|
|
|
+import com.qs.mp.channel.domain.ChannelOrder;
|
|
|
import com.qs.mp.channel.domain.param.ChannelOrderParam;
|
|
|
import com.qs.mp.channel.domain.vo.ChannelCartVO;
|
|
|
import com.qs.mp.channel.domain.vo.ChannelOrderSettleVO;
|
|
|
import com.qs.mp.common.core.domain.AjaxResult;
|
|
|
import com.qs.mp.common.core.page.TableDataInfo;
|
|
|
+import com.qs.mp.common.core.redis.RedisCache;
|
|
|
+import com.qs.mp.common.enums.ChannelCertifyStatusEnum;
|
|
|
import com.qs.mp.common.enums.ErrorCodeEnum;
|
|
|
import com.qs.mp.common.enums.TicketBoxStatusEnum;
|
|
|
import com.qs.mp.common.enums.TicketStatusEnum;
|
|
|
+import com.qs.mp.common.utils.LogUtil;
|
|
|
import com.qs.mp.common.utils.StringUtils;
|
|
|
+import com.qs.mp.framework.redis.RedisKey;
|
|
|
+import com.qs.mp.user.domain.UserTicketOrder;
|
|
|
import com.qs.mp.user.domain.UserTicketOrderItem;
|
|
|
+import com.qs.mp.user.domain.param.TicketOrderParam;
|
|
|
+import com.qs.mp.user.domain.vo.TicketOrderSettleVO;
|
|
|
+import com.qs.mp.user.domain.vo.UserCouponVO;
|
|
|
+import com.qs.mp.user.service.IUserCouponService;
|
|
|
import com.qs.mp.user.service.IUserHitPrizeService;
|
|
|
import com.qs.mp.user.service.IUserTicketOrderItemService;
|
|
|
import com.qs.mp.utils.SecurityUtils;
|
|
@@ -76,174 +88,90 @@ public class UserTicketOrderController extends BaseApiController {
|
|
|
@Autowired
|
|
|
private IUserHitPrizeService userHitPrizeService;
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private IUserCouponService userCouponService;
|
|
|
+
|
|
|
@Autowired
|
|
|
private MapperFacade mapperFacade;
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private RedisCache redisCache;
|
|
|
+
|
|
|
|
|
|
/**
|
|
|
* 订单结算,每次更换优惠券时需重新请求此接口
|
|
|
*/
|
|
|
@PostMapping("/order/settle")
|
|
|
@ApiOperation(value = "订单结算" , notes = "购物车里点结算或者单个盲票组商品上点立即购买")
|
|
|
- public AjaxResult settle(@Valid @RequestBody ChannelOrderParam param) {
|
|
|
- Long channelId = SecurityUtils.getLoginUser().getChannelId();
|
|
|
-
|
|
|
- ChannelOrderSettleVO orderSettleVO = new ChannelOrderSettleVO();
|
|
|
-/*
|
|
|
- // 收货地址,如果用户选了地址,则此处不做处理
|
|
|
- if (null == param.getAddrId() || 0 == param.getAddrId()) {
|
|
|
- //读取默认地址
|
|
|
- ChannelAddr addr = channelAddrService.getDefaultChannelAddr(channelId);
|
|
|
- if (null != addr) {
|
|
|
- orderSettleVO.setAddr(addr);
|
|
|
- }
|
|
|
+ public AjaxResult settle(@Valid @RequestBody TicketOrderParam param) {
|
|
|
+ if (StringUtils.isBlank(param.getTicketId()) && StringUtils.isBlank(param.getBoxId())) {
|
|
|
+ return AjaxResult.error("参数缺失");
|
|
|
}
|
|
|
+ Long userId = SecurityUtils.getLoginUser().getUserId();
|
|
|
+
|
|
|
+ TicketOrderSettleVO orderSettleVO = new TicketOrderSettleVO();
|
|
|
+
|
|
|
|
|
|
// 订单金额计算
|
|
|
Integer orderAmt = 0;
|
|
|
- Integer pkgNum = 0;
|
|
|
- if (!CollectionUtils.isEmpty(param.getCartIds())){
|
|
|
- // 购物车里下单的
|
|
|
- List<ChannelCart> channelCarts = channelCartService.listByIds(param.getCartIds());
|
|
|
- for (ChannelCart channelCart : channelCarts) {
|
|
|
- TicketBox ticketBox = ticketBoxService.getById(channelCart.getBoxId());
|
|
|
- orderAmt += ticketBox.getPkgSalePrice() * channelCart.getOrderNum();
|
|
|
- ChannelCartVO cartVO = mapperFacade.map(ticketBox, ChannelCartVO.class);
|
|
|
- cartVO.setCartId(channelCart.getCartId());
|
|
|
- cartVO.setOrderNum(channelCart.getOrderNum());
|
|
|
- orderSettleVO.getItems().add(cartVO);
|
|
|
- pkgNum += channelCart.getOrderNum();
|
|
|
- }
|
|
|
+ Integer discountAmt = 0;
|
|
|
+ String picUrl;
|
|
|
+ if (StringUtils.isNotBlank(param.getTicketId())) {
|
|
|
+ // 线下扫码购票
|
|
|
+ Ticket ticket = ticketService.getById(param.getTicketId());
|
|
|
+ TicketBox ticketBox = ticketBoxService.getById(ticket.getBoxId());
|
|
|
+ orderAmt = ticketBox.getSalePrice();
|
|
|
+ picUrl = ticketBox.getPicUrl();
|
|
|
} else {
|
|
|
+ // 线上购票
|
|
|
TicketBox ticketBox = ticketBoxService.getById(param.getBoxId());
|
|
|
- orderAmt += ticketBox.getPkgSalePrice() * param.getOrderNum();
|
|
|
- ChannelCartVO cartVO = mapperFacade.map(ticketBox, ChannelCartVO.class);
|
|
|
- cartVO.setOrderNum(param.getOrderNum());
|
|
|
- orderSettleVO.getItems().add(cartVO);
|
|
|
- pkgNum += param.getOrderNum();
|
|
|
+ orderAmt = ticketBox.getSalePrice() * param.getOrderNum();
|
|
|
+ picUrl = ticketBox.getPicUrl();
|
|
|
+ }
|
|
|
+
|
|
|
+ if (param.getAutoCoupon() == 1) {
|
|
|
+ // 系统自动选择优惠券,按照金额从大到小排序
|
|
|
+ List<UserCouponVO> userCouponList = userCouponService.listTicketOrderCoupon(userId);
|
|
|
+ for (UserCouponVO userCouponVO : userCouponList) {
|
|
|
+ if (orderAmt >= userCouponVO.getMinOrderAmt() && orderAmt >= userCouponVO.getDiscount()) {
|
|
|
+ orderSettleVO.getCouponList().add(userCouponVO);
|
|
|
+ discountAmt = userCouponVO.getDiscount();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ // 查询指定券
|
|
|
}
|
|
|
orderSettleVO.setOrderAmt(orderAmt);
|
|
|
+ orderSettleVO.setDiscountAmt(discountAmt);
|
|
|
// 当前没有运费和优惠,实付金额=订单金额
|
|
|
- orderSettleVO.setPayAmt(orderAmt);
|
|
|
- orderSettleVO.setPkgNum(pkgNum);
|
|
|
+ orderSettleVO.setPayAmt(orderAmt - discountAmt);
|
|
|
+ orderSettleVO.setOrderNum(param.getOrderNum());
|
|
|
+ orderSettleVO.setBoxId(param.getBoxId());
|
|
|
+ orderSettleVO.setTicketId(param.getTicketId());
|
|
|
+ orderSettleVO.setPicUrl(picUrl);
|
|
|
|
|
|
// 缓存订单结算对象
|
|
|
- redisCache.setCacheObject(CHANNEL_ORDER_CACHE_KEY + channelId, orderSettleVO, 10, TimeUnit.MINUTES);*/
|
|
|
+ redisCache.setCacheObject(RedisKey.build(RedisKey.USER_TICKET_ORDER_KEY, userId), orderSettleVO, 10, TimeUnit.MINUTES);
|
|
|
return AjaxResult.success(orderSettleVO);
|
|
|
}
|
|
|
|
|
|
|
|
|
/**
|
|
|
- * 查看盲票详情
|
|
|
- */
|
|
|
- @PostMapping("/mall/ticket/detail")
|
|
|
- @ApiOperation(value = "查看盲票详情" , notes = "根据盲票组ID,获取盲票信息")
|
|
|
- public AjaxResult getInfo(@RequestBody TicketBoxParam param) {
|
|
|
- if (StringUtils.isBlank(param.getBoxId())) {
|
|
|
- return AjaxResult.error("参数异常,盲票组ID缺失");
|
|
|
- }
|
|
|
- TicketBox ticketBox = ticketBoxService.getById(param.getBoxId());
|
|
|
- TicketBoxVO ticketBoxVO = mapperFacade.map(ticketBox, TicketBoxVO.class);
|
|
|
- ticketBoxVO.setPrizeList(ticketAwardsPrizeService.listPrizeVO(new QueryWrapper<TicketAwardsPrize>()
|
|
|
- .eq("t1.box_id", ticketBox.getBoxId()).orderByAsc("t1.sort").orderByDesc("t2.value")));
|
|
|
- return AjaxResult.success(ticketBoxVO);
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 扫码查看盲票幸运数字
|
|
|
- */
|
|
|
- @PostMapping("/ticket/queryLuckyNum")
|
|
|
- @ApiOperation(value = "查看盲票幸运数字" , notes = "根据盲票组ID,获取盲票幸运数字")
|
|
|
- public AjaxResult queryLuckyNum(@RequestBody TicketParam param) {
|
|
|
- Long userId = SecurityUtils.getLoginUser().getUserId();
|
|
|
- if (StringUtils.isBlank(param.getTicketId())) {
|
|
|
- return AjaxResult.error("参数异常,盲票ID缺失");
|
|
|
- }
|
|
|
-
|
|
|
- Ticket ticket = ticketService.getById(param.getTicketId());
|
|
|
- if (null == ticket) {
|
|
|
- return AjaxResult.error("参数异常,盲票不存在");
|
|
|
- }
|
|
|
-
|
|
|
- if (ticket.getStatus() == TicketStatusEnum.CASHED) {
|
|
|
- return AjaxResult.error(ErrorCodeEnum.ERROR_CODE_1017);
|
|
|
- }
|
|
|
-
|
|
|
- // 已付款的盲票,需要校验当前用户是否有权限查看
|
|
|
- if (ticket.getStatus() == TicketStatusEnum.ACTIVATED) {
|
|
|
- UserTicketOrderItem orderItem = userTicketOrderItemService.queryFinishedOrderItem(userId, param.getTicketId());
|
|
|
- if (null == orderItem) {
|
|
|
- return AjaxResult.error(ErrorCodeEnum.ERROR_CODE_1018);
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- TicketBox ticketBox = ticketBoxService.getById(ticket.getBoxId());
|
|
|
-
|
|
|
- TicketVO ticketVO = new TicketVO();
|
|
|
- ticketVO.setPrizeList(ticketAwardsPrizeService.listPrizeVO(new QueryWrapper<TicketAwardsPrize>()
|
|
|
- .eq("t1.box_id", ticketBox.getBoxId()).orderByAsc("t1.sort").orderByDesc("t2.value")));
|
|
|
- ticketVO.setTicketId(ticket.getTicketId());
|
|
|
- ticketVO.setBoxId(ticket.getBoxId());
|
|
|
- ticketVO.setTitle(ticketBox.getTitle());
|
|
|
- ticketVO.setSerialNo(ticket.getSerialNo());
|
|
|
- ticketVO.setFacePrice(ticket.getFacePrice());
|
|
|
- ticketVO.setSalePrice(ticketBox.getSalePrice());
|
|
|
- ticketVO.setPlainLuckyNum(ticket.getPlainLuckyNum());
|
|
|
- ticketVO.setStatus(ticket.getStatus().getValue());
|
|
|
-
|
|
|
- return AjaxResult.success(ticketVO);
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 查看能兑奖的奖品
|
|
|
- */
|
|
|
- @PostMapping("/ticket/queryHitPrizeList")
|
|
|
- @ApiOperation(value = "查看兑奖奖品" , notes = "根据盲票ID,查看兑奖奖品")
|
|
|
- public AjaxResult queryHitPrizeList(@RequestBody TicketParam param) {
|
|
|
- Long userId = SecurityUtils.getLoginUser().getUserId();
|
|
|
- if (StringUtils.isBlank(param.getTicketId())) {
|
|
|
- return AjaxResult.error("参数异常,盲票ID缺失");
|
|
|
- }
|
|
|
-
|
|
|
- Ticket ticket = ticketService.getById(param.getTicketId());
|
|
|
- if (null == ticket) {
|
|
|
- return AjaxResult.error("参数异常,盲票不存在");
|
|
|
- }
|
|
|
- if (ticket.getStatus() == TicketStatusEnum.CASHED) {
|
|
|
- return AjaxResult.error(ErrorCodeEnum.ERROR_CODE_1017);
|
|
|
- }
|
|
|
- if (ticket.getStatus() != TicketStatusEnum.ACTIVATED) {
|
|
|
- return AjaxResult.error(ErrorCodeEnum.ERROR_CODE_1019);
|
|
|
- }
|
|
|
-
|
|
|
- List<TicketAwardsPrize> ticketAwardsPrizes = userHitPrizeService.listPrize(ticket, userId);
|
|
|
- return AjaxResult.success(ticketAwardsPrizes);
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 兑奖
|
|
|
+ * 提交订单
|
|
|
*/
|
|
|
- @PostMapping("/ticket/cashPrize")
|
|
|
- @ApiOperation(value = "兑奖" , notes = "选择奖品兑奖")
|
|
|
- public AjaxResult cashPrize(@RequestBody TicketParam param) {
|
|
|
+ @PostMapping("/order/submit")
|
|
|
+ @ApiOperation(value = "提交订单" , notes = "在订单确认页面提交")
|
|
|
+ public AjaxResult submit(@RequestBody UserTicketOrder order) {
|
|
|
Long userId = SecurityUtils.getLoginUser().getUserId();
|
|
|
- if (StringUtils.isBlank(param.getTicketId()) || StringUtils.isBlank(param.getAwardsId())
|
|
|
- || StringUtils.isBlank(param.getPrizeId())) {
|
|
|
- return AjaxResult.error("参数缺失");
|
|
|
+ TicketOrderSettleVO orderSettleVO = redisCache.getCacheObject(RedisKey.build(RedisKey.USER_TICKET_ORDER_KEY, userId));
|
|
|
+ if (null == orderSettleVO) {
|
|
|
+ return AjaxResult.error("订单已过期,请重新下单");
|
|
|
}
|
|
|
+ //String orderId = channelOrderService.submitOrder(channelId, order.getMemo(), orderSettleVO);
|
|
|
|
|
|
- Ticket ticket = ticketService.getById(param.getTicketId());
|
|
|
- if (null == ticket) {
|
|
|
- return AjaxResult.error("参数异常,盲票不存在");
|
|
|
- }
|
|
|
- if (ticket.getStatus() == TicketStatusEnum.CASHED) {
|
|
|
- return AjaxResult.error(ErrorCodeEnum.ERROR_CODE_1017);
|
|
|
- }
|
|
|
- if (ticket.getStatus() != TicketStatusEnum.ACTIVATED) {
|
|
|
- return AjaxResult.error(ErrorCodeEnum.ERROR_CODE_1019);
|
|
|
- }
|
|
|
+ // 清除缓存的订单
|
|
|
+ redisCache.deleteObject(RedisKey.build(RedisKey.USER_TICKET_ORDER_KEY, userId));
|
|
|
|
|
|
- userHitPrizeService.cashPrize(ticket, userId, param.getAwardsId(), param.getPrizeId());
|
|
|
return AjaxResult.success();
|
|
|
}
|
|
|
|