|
@@ -24,15 +24,24 @@ import com.qs.mp.common.core.domain.AjaxResult;
|
|
|
import com.qs.mp.common.core.redis.RedisCache;
|
|
|
import com.qs.mp.common.enums.BizTypeEnum;
|
|
|
import com.qs.mp.common.enums.CouponUseAreaEnum;
|
|
|
+import com.qs.mp.common.enums.PrizeStorageStatusEnum;
|
|
|
import com.qs.mp.common.exception.ServiceException;
|
|
|
import com.qs.mp.common.utils.StringUtils;
|
|
|
import com.qs.mp.framework.redis.RedisKey;
|
|
|
import com.qs.mp.pay.service.IWalletService;
|
|
|
+import com.qs.mp.user.domain.UserAddr;
|
|
|
+import com.qs.mp.user.domain.UserDeliverOrder;
|
|
|
+import com.qs.mp.user.domain.UserPrizeStorage;
|
|
|
import com.qs.mp.user.domain.UserTicketOrder;
|
|
|
+import com.qs.mp.user.domain.param.DeliverOrderParam;
|
|
|
import com.qs.mp.user.domain.param.TicketOrderParam;
|
|
|
+import com.qs.mp.user.domain.vo.DeliverOrderSettleVO;
|
|
|
import com.qs.mp.user.domain.vo.TicketOrderSettleVO;
|
|
|
import com.qs.mp.user.domain.vo.UserCouponVO;
|
|
|
+import com.qs.mp.user.service.IUserAddrService;
|
|
|
import com.qs.mp.user.service.IUserCouponService;
|
|
|
+import com.qs.mp.user.service.IUserDeliverOrderService;
|
|
|
+import com.qs.mp.user.service.IUserPrizeStorageService;
|
|
|
import com.qs.mp.user.service.IUserTicketOrderService;
|
|
|
import com.qs.mp.utils.SecurityUtils;
|
|
|
import com.qs.mp.web.controller.common.BaseApiController;
|
|
@@ -53,25 +62,18 @@ import org.springframework.web.bind.annotation.RestController;
|
|
|
|
|
|
@RestController
|
|
|
@RequestMapping("/api/v1/mp/user/deliver")
|
|
|
-@Api(tags = "用户端购买盲票接口")
|
|
|
+@Api(tags = "用户端奖品提货接口")
|
|
|
@AllArgsConstructor
|
|
|
public class UserDeliverOrderController extends BaseApiController {
|
|
|
|
|
|
-
|
|
|
- @Autowired
|
|
|
- private ITicketBoxService ticketBoxService;
|
|
|
-
|
|
|
- @Autowired
|
|
|
- private IUserTicketOrderService userTicketOrderService;
|
|
|
-
|
|
|
@Autowired
|
|
|
- private ITicketService ticketService;
|
|
|
+ private IUserPrizeStorageService userPrizeStorageService;
|
|
|
|
|
|
@Autowired
|
|
|
- private IUserCouponService userCouponService;
|
|
|
+ private IUserAddrService userAddrService;
|
|
|
|
|
|
@Autowired
|
|
|
- private ICouponTicketService couponTicketService;
|
|
|
+ private IUserDeliverOrderService userDeliverOrderService;
|
|
|
|
|
|
@Autowired
|
|
|
private IWalletService walletService;
|
|
@@ -84,88 +86,64 @@ public class UserDeliverOrderController extends BaseApiController {
|
|
|
|
|
|
|
|
|
/**
|
|
|
- * 订单结算,每次更换优惠券时需重新请求此接口
|
|
|
+ * 订单结算,每次更换地址时需重新请求此接口
|
|
|
*/
|
|
|
@PostMapping("/order/settle")
|
|
|
- @ApiOperation(value = "订单结算" , notes = "单个盲票商品上点立即购买")
|
|
|
- public AjaxResult settle(@Valid @RequestBody TicketOrderParam param) {
|
|
|
- if (StringUtils.isBlank(param.getTicketId()) && StringUtils.isBlank(param.getBoxId())) {
|
|
|
- return AjaxResult.error("参数缺失");
|
|
|
- }
|
|
|
+ @ApiOperation(value = "订单结算" , notes = "奖品库里点提货")
|
|
|
+ public AjaxResult settle(@Valid @RequestBody DeliverOrderParam param) {
|
|
|
Long userId = SecurityUtils.getLoginUser().getUserId();
|
|
|
|
|
|
- TicketOrderSettleVO orderSettleVO = new TicketOrderSettleVO();
|
|
|
+ DeliverOrderSettleVO orderSettleVO = new DeliverOrderSettleVO();
|
|
|
|
|
|
+ // 收货地址,如果用户选了地址,则此处不做处理
|
|
|
+ if (null == param.getAddrId() || 0 == param.getAddrId()) {
|
|
|
+ //读取默认地址
|
|
|
+ UserAddr addr = userAddrService.getDefaultChannelAddr(userId);
|
|
|
+ if (null != addr) {
|
|
|
+ orderSettleVO.setAddr(addr);
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
// 订单金额计算
|
|
|
Integer orderAmt = 0;
|
|
|
- Integer discountAmt = 0;
|
|
|
- TicketBox ticketBox;
|
|
|
- if (StringUtils.isNotBlank(param.getTicketId())) {
|
|
|
- // 线下扫码购票
|
|
|
- Ticket ticket = ticketService.getById(param.getTicketId());
|
|
|
- ticketBox = ticketBoxService.getById(ticket.getBoxId());
|
|
|
- orderAmt = ticketBox.getSalePrice();
|
|
|
- } else {
|
|
|
- // 线上购票
|
|
|
- ticketBox = ticketBoxService.getById(param.getBoxId());
|
|
|
- orderAmt = ticketBox.getSalePrice() * param.getOrderNum();
|
|
|
- }
|
|
|
+ Integer freightAmt = 0;
|
|
|
+
|
|
|
+ List<UserPrizeStorage> prizeStorageList = userPrizeStorageService.list(new LambdaQueryWrapper<UserPrizeStorage>()
|
|
|
+ .eq(UserPrizeStorage::getUserId, userId).eq(UserPrizeStorage::getStatus, PrizeStorageStatusEnum.NOT_DISTRIBUTED)
|
|
|
+ .in(UserPrizeStorage::getStorageId, param.getIds()));
|
|
|
|
|
|
- if (param.getAutoCoupon() == 1) {
|
|
|
- // 系统自动选择优惠券,按照金额从大到小排序
|
|
|
- List<UserCouponVO> userCouponList = userCouponService.listTicketOrderCoupon(userId);
|
|
|
- for (UserCouponVO userCouponVO : userCouponList) {
|
|
|
- if (orderAmt >= userCouponVO.getMinOrderAmt() && orderAmt >= userCouponVO.getDiscount()) {
|
|
|
- if (userCouponVO.getUseArea() == CouponUseAreaEnum.PRE_SCOPE) {
|
|
|
- // 使用范围验证
|
|
|
- List<CouponTicket> couponTicketList = couponTicketService.list(new LambdaQueryWrapper<CouponTicket>()
|
|
|
- .eq(CouponTicket::getCouponId, userCouponVO.getCouponId()).eq(CouponTicket::getBoxId, ticketBox.getBoxId()));
|
|
|
- if (CollectionUtils.isEmpty(couponTicketList)) {
|
|
|
- continue;
|
|
|
- }
|
|
|
- }
|
|
|
- orderSettleVO.getCouponList().add(userCouponVO);
|
|
|
- discountAmt = userCouponVO.getDiscount();
|
|
|
- }
|
|
|
- }
|
|
|
- } else if (!CollectionUtils.isEmpty(param.getUserCouponIds())){
|
|
|
- // 查询指定券
|
|
|
- orderSettleVO.setCouponList(userCouponService.listTicketOrderCouponByIds(param.getUserCouponIds()));
|
|
|
- }
|
|
|
|
|
|
orderSettleVO.setOrderAmt(orderAmt);
|
|
|
- orderSettleVO.setDiscountAmt(discountAmt);
|
|
|
- // 当前没有运费和优惠,实付金额=订单金额
|
|
|
- orderSettleVO.setPayAmt(orderAmt - discountAmt);
|
|
|
- orderSettleVO.setOrderNum(param.getOrderNum());
|
|
|
- orderSettleVO.setBoxId(param.getBoxId());
|
|
|
- orderSettleVO.setTicketId(param.getTicketId());
|
|
|
- orderSettleVO.setPicUrl(ticketBox.getPicUrl());
|
|
|
+ orderSettleVO.setFreightAmt(freightAmt);
|
|
|
+ orderSettleVO.setPayAmt(orderAmt + freightAmt);
|
|
|
+ orderSettleVO.setPrizeList(prizeStorageList);
|
|
|
|
|
|
// 缓存订单结算对象
|
|
|
- redisCache.setCacheObject(RedisKey.build(RedisKey.USER_TICKET_ORDER_KEY, userId), orderSettleVO, 10, TimeUnit.MINUTES);
|
|
|
+ redisCache.setCacheObject(RedisKey.build(RedisKey.USER_DELIVER_ORDER_KEY, userId), orderSettleVO, 10, TimeUnit.MINUTES);
|
|
|
return AjaxResult.success(orderSettleVO);
|
|
|
}
|
|
|
|
|
|
-
|
|
|
/**
|
|
|
* 提交订单
|
|
|
*/
|
|
|
@PostMapping("/order/submit")
|
|
|
@ApiOperation(value = "提交订单" , notes = "在订单确认页面提交")
|
|
|
- public AjaxResult submit(@RequestBody UserTicketOrder order) {
|
|
|
+ public AjaxResult submit(@RequestBody UserDeliverOrder order) {
|
|
|
Long userId = SecurityUtils.getLoginUser().getUserId();
|
|
|
- TicketOrderSettleVO orderSettleVO = redisCache.getCacheObject(RedisKey.build(RedisKey.USER_TICKET_ORDER_KEY, userId));
|
|
|
+ DeliverOrderSettleVO orderSettleVO = redisCache.getCacheObject(RedisKey.build(RedisKey.USER_DELIVER_ORDER_KEY, userId));
|
|
|
if (null == orderSettleVO) {
|
|
|
return AjaxResult.error("订单已过期,请重新下单");
|
|
|
}
|
|
|
- String orderId = userTicketOrderService.submitOrder(userId, orderSettleVO);
|
|
|
-
|
|
|
+ String orderId = userDeliverOrderService.submitOrder(userId, orderSettleVO);
|
|
|
+ JSONObject jsonObject = new JSONObject();
|
|
|
+ jsonObject.put("orderId", orderId);
|
|
|
+ if (orderSettleVO.getPayAmt() > 0) {
|
|
|
+ jsonObject.put("needPay", 1);
|
|
|
+ }
|
|
|
// 清除缓存的订单
|
|
|
redisCache.deleteObject(RedisKey.build(RedisKey.USER_TICKET_ORDER_KEY, userId));
|
|
|
|
|
|
- return AjaxResult.success(orderId);
|
|
|
+ return AjaxResult.success(jsonObject);
|
|
|
}
|
|
|
|
|
|
|
|
@@ -175,7 +153,7 @@ public class UserDeliverOrderController extends BaseApiController {
|
|
|
@PostMapping("/order/cancel")
|
|
|
@ApiOperation(value = "取消订单" , notes = "在订单列表页面取消")
|
|
|
public AjaxResult cancel(@RequestBody ChannelOrder order) {
|
|
|
- userTicketOrderService.cancelOrder(order.getOrderId());
|
|
|
+ userDeliverOrderService.cancelOrder(order.getOrderId());
|
|
|
return AjaxResult.success("取消成功");
|
|
|
}
|
|
|
|
|
@@ -186,10 +164,10 @@ public class UserDeliverOrderController extends BaseApiController {
|
|
|
@ApiOperation(value = "订单支付" , notes = "在盲票页面支付")
|
|
|
public AjaxResult pay(@Valid @RequestBody OrderPayParam param) {
|
|
|
String openId = SecurityUtils.getLoginUser().getUser().getOpenId();
|
|
|
- UserTicketOrder ticketOrder = userTicketOrderService.getById(param.getOrderId());
|
|
|
+ UserDeliverOrder deliverOrder = userDeliverOrderService.getById(param.getOrderId());
|
|
|
JSONObject jsonObject;
|
|
|
try {
|
|
|
- jsonObject = walletService.pay(BizTypeEnum.USER_ORDER, param.getOrderId(), openId, ticketOrder.getPayAmt());
|
|
|
+ jsonObject = walletService.pay(BizTypeEnum.USER_ORDER, param.getOrderId(), openId, deliverOrder.getFreightAmt());
|
|
|
}catch (ServiceException e) {
|
|
|
return AjaxResult.error(e.getMessage());
|
|
|
}
|