|
@@ -0,0 +1,306 @@
|
|
|
+package com.qs.mp.web.controller.api.user;
|
|
|
+
|
|
|
+import cn.hutool.core.util.ObjectUtil;
|
|
|
+import com.alibaba.fastjson.JSONObject;
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
+import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
|
|
|
+import com.qs.mp.admin.domain.Ticket;
|
|
|
+import com.qs.mp.admin.domain.TicketBox;
|
|
|
+import com.qs.mp.admin.domain.TicketPackage;
|
|
|
+import com.qs.mp.admin.domain.vo.*;
|
|
|
+import com.qs.mp.admin.service.*;
|
|
|
+import com.qs.mp.channel.domain.Channel;
|
|
|
+import com.qs.mp.channel.domain.ChannelOrder;
|
|
|
+import com.qs.mp.channel.domain.param.OrderPayParam;
|
|
|
+import com.qs.mp.channel.domain.vo.PromoterVO;
|
|
|
+import com.qs.mp.channel.service.IPromoterUserService;
|
|
|
+import com.qs.mp.common.core.domain.AjaxResult;
|
|
|
+import com.qs.mp.common.core.page.TableDataInfo;
|
|
|
+import com.qs.mp.common.core.redis.DistributedLocker;
|
|
|
+import com.qs.mp.common.core.redis.RedisCache;
|
|
|
+import com.qs.mp.common.enums.*;
|
|
|
+import com.qs.mp.common.exception.ServiceException;
|
|
|
+import com.qs.mp.common.pulsar.PulsarClientService;
|
|
|
+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.framework.redis.RedisLockKey;
|
|
|
+import com.qs.mp.pay.service.IWalletService;
|
|
|
+import com.qs.mp.system.domain.SysUser;
|
|
|
+import com.qs.mp.system.service.ISysUserService;
|
|
|
+import com.qs.mp.user.domain.UserTicketOrder;
|
|
|
+import com.qs.mp.user.domain.param.GroupOrderParam;
|
|
|
+import com.qs.mp.user.domain.param.TicketOrderParam;
|
|
|
+import com.qs.mp.user.domain.vo.*;
|
|
|
+import com.qs.mp.user.service.IGroupBuyingOrderService;
|
|
|
+import com.qs.mp.user.service.IUserCouponService;
|
|
|
+import com.qs.mp.user.service.IUserGroupOrderService;
|
|
|
+import com.qs.mp.user.service.IUserTicketOrderService;
|
|
|
+import com.qs.mp.utils.SecurityUtils;
|
|
|
+import com.qs.mp.web.controller.common.BaseApiController;
|
|
|
+import io.swagger.annotations.Api;
|
|
|
+import io.swagger.annotations.ApiOperation;
|
|
|
+import io.swagger.annotations.ApiResponse;
|
|
|
+import io.swagger.annotations.ApiResponses;
|
|
|
+import lombok.AllArgsConstructor;
|
|
|
+import ma.glasnost.orika.MapperFacade;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.web.bind.annotation.PostMapping;
|
|
|
+import org.springframework.web.bind.annotation.RequestBody;
|
|
|
+import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
+import org.springframework.web.bind.annotation.RestController;
|
|
|
+
|
|
|
+import javax.validation.Valid;
|
|
|
+import java.util.*;
|
|
|
+import java.util.concurrent.TimeUnit;
|
|
|
+import java.util.stream.Collectors;
|
|
|
+
|
|
|
+
|
|
|
+@RestController
|
|
|
+@RequestMapping("/api/v1/mp/user/group/order")
|
|
|
+@Api(tags = "用户端购买盲票接口")
|
|
|
+@AllArgsConstructor
|
|
|
+public class GroupBuyingOrderController extends BaseApiController {
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private IWalletService walletService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private ISysUserService sysUserService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private MapperFacade mapperFacade;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private RedisCache redisCache;
|
|
|
+
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private IPromoterUserService promoterUserService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private IGroupBuyingGroupService groupBuyingGroupService;
|
|
|
+ @Autowired
|
|
|
+ private IGroupBuyingService groupBuyingService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private DistributedLocker distributedLocker;
|
|
|
+ @Autowired
|
|
|
+ private IUserGroupOrderService userGroupOrderService;
|
|
|
+ @Autowired
|
|
|
+ private IGroupBuyingOrderService groupBuyingOrderService;
|
|
|
+
|
|
|
+
|
|
|
+ @PostMapping("/myStartGroup")
|
|
|
+ @ApiOperation(value = "我的拼团-进行中", notes = "我的拼团-进行中")
|
|
|
+ @ApiResponses(
|
|
|
+ @ApiResponse(code = 200, message = "success", response = MyGroupBuyingGroupStartVO.class)
|
|
|
+ )
|
|
|
+ public AjaxResult myStartGroup() {
|
|
|
+ Long userId = SecurityUtils.getLoginUser().getUserId();
|
|
|
+ if (Objects.isNull(userId)) {
|
|
|
+ return AjaxResult.error("用户未登录");
|
|
|
+ }
|
|
|
+ List<GroupBuyingGroup> groupList = groupBuyingGroupService.list(new LambdaQueryWrapper<GroupBuyingGroup>()
|
|
|
+ .eq(GroupBuyingGroup::getPartinIds,userId)
|
|
|
+ .eq(GroupBuyingGroup::getGroupStatus, GroupingStatusEnum.START.getValue())
|
|
|
+ .orderByDesc(GroupBuyingGroup::getCreateTime)
|
|
|
+ );
|
|
|
+ List<MyGroupBuyingGroupStartVO> startVOS = new ArrayList<>();
|
|
|
+ if(com.baomidou.mybatisplus.core.toolkit.CollectionUtils.isNotEmpty(groupList)){
|
|
|
+ Set<Long> ids = groupList.stream().map(GroupBuyingGroup::getGroupbuyingId).collect(Collectors.toSet());
|
|
|
+ //获取拼团活动信息
|
|
|
+ List<GroupBuying> groupBuyings = groupBuyingService.list(new LambdaQueryWrapper<GroupBuying>()
|
|
|
+ .in(GroupBuying::getId,ids)
|
|
|
+ );
|
|
|
+ startVOS = groupList.stream().map(groupBuyingGroup -> {
|
|
|
+ MyGroupBuyingGroupStartVO startVO = new MyGroupBuyingGroupStartVO();
|
|
|
+ startVO.setGroupEndTime(groupBuyingGroup.getGroupEndTime());
|
|
|
+ startVO.setPartinNum(groupBuyingGroup.getPartinNum());
|
|
|
+ startVO.setGroupId(groupBuyingGroup.getId());
|
|
|
+ Optional<GroupBuying> buyingOption = groupBuyings.stream()
|
|
|
+ .filter(groupBuying -> groupBuyingGroup.getGroupbuyingId().equals(groupBuying.getId())).findFirst();
|
|
|
+ if(buyingOption.isPresent()){
|
|
|
+ startVO.setGroupSize(buyingOption.get().getGroupSize());
|
|
|
+ startVO.setPicUrl(buyingOption.get().getPicUrl());
|
|
|
+ startVO.setEndTime(buyingOption.get().getEndTime());
|
|
|
+ startVO.setTitle(buyingOption.get().getTitle());
|
|
|
+ startVO.setGroupBuyingId(buyingOption.get().getId());
|
|
|
+ }
|
|
|
+ return startVO;
|
|
|
+ }).collect(Collectors.toList());
|
|
|
+ }
|
|
|
+ return AjaxResult.success(startVOS);
|
|
|
+ }
|
|
|
+
|
|
|
+ @PostMapping("/myEndGroup")
|
|
|
+ @ApiOperation(value = "我的拼团-已开奖", notes = "我的拼团-已开奖")
|
|
|
+ @ApiResponses(
|
|
|
+ @ApiResponse(code = 200, message = "success", response = MyGroupBuyingGroupEndVO.class)
|
|
|
+ )
|
|
|
+ public AjaxResult myEndGroup(){
|
|
|
+ Long userId = SecurityUtils.getLoginUser().getUserId();
|
|
|
+ if (Objects.isNull(userId)) {
|
|
|
+ return AjaxResult.error("用户未登录");
|
|
|
+ }
|
|
|
+ List<GroupBuyingGroup> groupList = groupBuyingGroupService.list(new LambdaQueryWrapper<GroupBuyingGroup>()
|
|
|
+ .eq(GroupBuyingGroup::getPartinIds,userId)
|
|
|
+ .eq(GroupBuyingGroup::getGroupStatus,GroupingStatusEnum.END.getValue())
|
|
|
+ .orderByDesc(GroupBuyingGroup::getCreateTime)
|
|
|
+ );
|
|
|
+ List<MyGroupBuyingGroupEndVO> endVOS = new ArrayList<>();
|
|
|
+ if(CollectionUtils.isNotEmpty(groupList)){
|
|
|
+ Set<Long> ids = groupList.stream().map(GroupBuyingGroup::getGroupbuyingId).collect(Collectors.toSet());
|
|
|
+ //获取拼团活动信息
|
|
|
+ List<GroupBuying> groupBuyings = groupBuyingService.list(new LambdaQueryWrapper<GroupBuying>()
|
|
|
+ .in(GroupBuying::getId,ids)
|
|
|
+ );
|
|
|
+ endVOS = groupList.stream().map(groupBuyingGroup -> {
|
|
|
+ MyGroupBuyingGroupEndVO endVO = new MyGroupBuyingGroupEndVO();
|
|
|
+ endVO.setGroupEndTime(groupBuyingGroup.getGroupEndTime());
|
|
|
+ endVO.setGroupId(groupBuyingGroup.getId());
|
|
|
+ Optional<GroupBuying> buyingOption = groupBuyings.stream()
|
|
|
+ .filter(groupBuying -> groupBuyingGroup.getGroupbuyingId().equals(groupBuying.getId())).findFirst();
|
|
|
+ if(buyingOption.isPresent()){
|
|
|
+ endVO.setPicUrl(buyingOption.get().getPicUrl());
|
|
|
+ endVO.setTitle(buyingOption.get().getTitle());
|
|
|
+ endVO.setGroupBuyingId(buyingOption.get().getId());
|
|
|
+ }
|
|
|
+ return endVO;
|
|
|
+ }).collect(Collectors.toList());
|
|
|
+ }
|
|
|
+ return AjaxResult.success(endVOS);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 订单结算
|
|
|
+ */
|
|
|
+ @PostMapping("/order/settle")
|
|
|
+ @ApiOperation(value = "订单结算", notes = "参团立即支付")
|
|
|
+ @ApiResponses(
|
|
|
+ @ApiResponse(code = 200, message = "OK", response = TicketOrderSettleVO.class)
|
|
|
+ )
|
|
|
+ public AjaxResult settle(@Valid @RequestBody GroupOrderParam param) {
|
|
|
+ Long userId = SecurityUtils.getLoginUser().getUserId();
|
|
|
+ if (Objects.isNull(userId)) {
|
|
|
+ return AjaxResult.error("用户未登录");
|
|
|
+ }
|
|
|
+ if (ObjectUtil.isNull(param.getGroupbuyingId()) && ObjectUtil.isNull(param.getGroupId())) {
|
|
|
+ return AjaxResult.error("参数缺失");
|
|
|
+ }
|
|
|
+ GroupOrderSettleVO orderSettleVO = new GroupOrderSettleVO();
|
|
|
+ AppSourceEnum appSourceEnum = AppSourceEnum.getByValue(param.getAppSource());
|
|
|
+ orderSettleVO.setAppId(appSourceEnum.getAppId());
|
|
|
+ orderSettleVO.setGroupbuyingId(param.getGroupbuyingId());
|
|
|
+ orderSettleVO.setGroupId(param.getGroupId());
|
|
|
+ orderSettleVO.setUserId(userId);
|
|
|
+ orderSettleVO.setOrderAmt(param.getOrderAmt());
|
|
|
+ GroupBuying groupBuying = groupBuyingService.getById(orderSettleVO.getGroupbuyingId());
|
|
|
+ GroupBuyingGroup groupBuyingGroup = groupBuyingGroupService.getById(orderSettleVO.getGroupId());
|
|
|
+ //不锁次数
|
|
|
+ userGroupOrderService.checkGroup(orderSettleVO,groupBuying,groupBuyingGroup,false);
|
|
|
+ // 缓存订单结算对象
|
|
|
+ redisCache.setCacheObject(RedisKey.build(RedisKey.USER_GROUP_ORDER_KEY, userId), orderSettleVO, 10,
|
|
|
+ TimeUnit.MINUTES);
|
|
|
+ return AjaxResult.success(orderSettleVO);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 校验活动是否过期
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ private boolean checkBuying(GroupBuying groupBuying){
|
|
|
+ Date now = new Date();
|
|
|
+ Date start = groupBuying.getStartTime();
|
|
|
+ Date end = groupBuying.getEndTime();
|
|
|
+ if(now.compareTo(start) >= 0 || now.compareTo(end) <= 0){
|
|
|
+ return true;
|
|
|
+ }else {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 提交订单
|
|
|
+ */
|
|
|
+ @PostMapping("/order/submit")
|
|
|
+ @ApiOperation(value = "提交订单", notes = "在订单确认页面提交")
|
|
|
+ public AjaxResult submit(@RequestBody UserShareVO userShareVO) {
|
|
|
+ Long userId = SecurityUtils.getLoginUser().getUserId();
|
|
|
+ GroupOrderSettleVO orderSettleVO = redisCache.getCacheObject(
|
|
|
+ RedisKey.build(RedisKey.USER_GROUP_ORDER_KEY, userId));
|
|
|
+ if (null == orderSettleVO) {
|
|
|
+ return AjaxResult.error("订单已过期,请重新下单");
|
|
|
+ }
|
|
|
+
|
|
|
+ String orderId = userGroupOrderService.submitOrder(userId, orderSettleVO, userShareVO);
|
|
|
+ JSONObject jsonObject = new JSONObject();
|
|
|
+ jsonObject.put("orderId", orderId);
|
|
|
+ if (orderSettleVO.getOrderAmt() > 0) {
|
|
|
+ jsonObject.put("needPay", 1);
|
|
|
+ } else {
|
|
|
+ jsonObject.put("needPay", 0);
|
|
|
+ }
|
|
|
+ // 清除缓存的订单
|
|
|
+ redisCache.deleteObject(RedisKey.build(RedisKey.USER_GROUP_ORDER_KEY, userId));
|
|
|
+ if (orderSettleVO.getOrderAmt() > 0) {
|
|
|
+ if (AppSourceEnum.MP.getAppId().equals(orderSettleVO.getAppId())) {
|
|
|
+ return AjaxResult.error("支付系统升级中,请稍后再试");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return AjaxResult.success(jsonObject);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 订单支付
|
|
|
+ */
|
|
|
+ @PostMapping("/order/pay")
|
|
|
+ @ApiOperation(value = "订单支付", notes = "在拼团/开团页面支付")
|
|
|
+ public AjaxResult pay(@Valid @RequestBody OrderPayParam param) {
|
|
|
+ Long userId = SecurityUtils.getLoginUser().getUserId();
|
|
|
+ SysUser sysUser = sysUserService.selectUserById(userId);
|
|
|
+ String openId = "";
|
|
|
+ if (param.getPayType() == 1) {
|
|
|
+ if (StringUtils.isBlank(sysUser.getAliuserId())) {
|
|
|
+ return AjaxResult.error(ErrorCodeEnum.ERROR_CODE_1026);
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ AppSourceEnum appSourceEnum = AppSourceEnum.getByValue(param.getAppSource());
|
|
|
+ if (AppSourceEnum.MSDQ.equals(appSourceEnum)) {
|
|
|
+ if (StringUtils.isBlank(sysUser.getMsdqOpenId())) {
|
|
|
+ return AjaxResult.error(ErrorCodeEnum.ERROR_CODE_1005);
|
|
|
+ }
|
|
|
+ openId = sysUser.getMsdqOpenId();
|
|
|
+ } else {
|
|
|
+ if (StringUtils.isBlank(sysUser.getOpenId())) {
|
|
|
+ return AjaxResult.error(ErrorCodeEnum.ERROR_CODE_1005);
|
|
|
+ }
|
|
|
+ openId = sysUser.getOpenId();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ GroupBuyingOrder buyingOrder = groupBuyingOrderService.getById(param.getOrderId());
|
|
|
+ JSONObject jsonObject;
|
|
|
+ try {
|
|
|
+ if (param.getPayType() == 1) {
|
|
|
+ // 支付宝支付
|
|
|
+ jsonObject = walletService.directAliPay(BizTypeEnum.GROUP_ORDER, param.getOrderId(), sysUser.getAliuserId(),
|
|
|
+ buyingOrder.getPayAmt(), buyingOrder.getGroupbuyingTitle());
|
|
|
+ } else {
|
|
|
+ // 微信支付
|
|
|
+ jsonObject = walletService.pay(BizTypeEnum.GROUP_ORDER, param.getOrderId(), openId,
|
|
|
+ buyingOrder.getPayAmt(), buyingOrder.getGroupbuyingTitle(), param.getAppSource());
|
|
|
+ }
|
|
|
+ } catch (ServiceException e) {
|
|
|
+ LogUtil.error(logger, e, "根据拼团购买订单创建支付单失败。userId:{0},orderId:{1}",
|
|
|
+ new Object[]{userId, param.getOrderId()});
|
|
|
+ return AjaxResult.error(e.getMessage());
|
|
|
+ }
|
|
|
+ return AjaxResult.success(jsonObject);
|
|
|
+ }
|
|
|
+
|
|
|
+}
|