| | |
| | | import com.ruoyi.goods.domain.vo.*; |
| | | import com.ruoyi.goods.mapper.lottery.LotteryEventMapper; |
| | | import com.ruoyi.goods.service.lottery.*; |
| | | import com.ruoyi.system.api.domain.dto.IntegralChangeDto; |
| | | import com.ruoyi.system.api.domain.poji.member.Member; |
| | | import com.ruoyi.system.api.domain.poji.member.MemberGiftRecord; |
| | | import com.ruoyi.system.api.domain.poji.shop.Shop; |
| | | import com.ruoyi.system.api.service.RemoteCouponService; |
| | | import com.ruoyi.system.api.service.RemoteMemberService; |
| | | import com.ruoyi.system.api.service.RemoteShopService; |
| | | import com.ruoyi.system.api.model.AddIntegralRecordVo; |
| | | import com.ruoyi.system.api.model.AddOrderVo; |
| | | import com.ruoyi.system.api.service.*; |
| | | import org.redisson.api.RLock; |
| | | import org.redisson.api.RedissonClient; |
| | | import org.springframework.stereotype.Service; |
| | |
| | | |
| | | @Resource |
| | | private ILotteryEventQuestionsService lotteryEventQuestionsService; |
| | | |
| | | @Resource |
| | | private RemoteOrderService remoteOrderService; |
| | | |
| | | /** |
| | | * 根据id查询抽奖活动信息 |
| | |
| | | * @return |
| | | */ |
| | | @Override |
| | | public LotteryEventVo getLotteryEvent(String id) { |
| | | public LotteryEventVo getLotteryEvent(String id, String orderId) { |
| | | Long userId = SecurityUtils.getUserId(); |
| | | TLotteryEvent lotteryEvent = this.getById(id); |
| | | //构建返回结果 |
| | |
| | | vo.setId(lotteryEvent.getId()); |
| | | vo.setName(lotteryEvent.getName()); |
| | | vo.setActivityProfile(lotteryEvent.getActivityProfile()); |
| | | List<TUserLotteryEvent> userLotteryEvents = userLotteryEventService.list(new QueryWrapper<TUserLotteryEvent>().eq("lottery_event_id", id).eq("user_id", userId)); |
| | | vo.setLaveTimes(lotteryEvent.getTimes() - userLotteryEvents.size()); |
| | | //查询抽检活动奖品 |
| | | List<TLotteryEventPrize> lotteryEventPrizeList = lotteryEventPrizeService.list(new QueryWrapper<TLotteryEventPrize>().eq("lottery_event_id", id)); |
| | | vo.setPrizeList(lotteryEventPrizeList); |
| | | //答题正确率 |
| | | if (5 == lotteryEvent.getActivityType()) { |
| | | TUserLotteryEventQuestions questionsServiceOne = userLotteryEventQuestionsAnswersService.getOne(new QueryWrapper<TUserLotteryEventQuestions>().eq("lottery_event_id", id).eq("user_id", userId)); |
| | | if (null != questionsServiceOne) { |
| | | vo.setCorrectAnswerRate(questionsServiceOne.getCorrectAnswerRate()); |
| | | } |
| | | QueryWrapper<TUserLotteryEvent> wrapper = new QueryWrapper<TUserLotteryEvent>().eq("lottery_event_id", id).eq("user_id", userId); |
| | | //下单抽奖 |
| | | if(2 == lotteryEvent.getActivityType()){ |
| | | wrapper.eq("order_id", orderId); |
| | | } |
| | | List<TUserLotteryEvent> userLotteryEvents = userLotteryEventService.list(wrapper); |
| | | vo.setLaveTimes(lotteryEvent.getTimes() - userLotteryEvents.size()); |
| | | |
| | | //构建我的奖品明细 |
| | | SimpleDateFormat sdf = new SimpleDateFormat("yyyy年MM月dd日 HH:mm"); |
| | | List<UserLotteryEventVo> collect = userLotteryEvents.stream().map(s -> { |
| | |
| | | return userLotteryEventVo; |
| | | }).collect(Collectors.toList()); |
| | | vo.setYourPrizeList(collect); |
| | | |
| | | //查询抽奖活动奖品 |
| | | List<TLotteryEventPrize> lotteryEventPrizeList = lotteryEventPrizeService.list(new QueryWrapper<TLotteryEventPrize>().eq("lottery_event_id", id)); |
| | | vo.setPrizeList(lotteryEventPrizeList); |
| | | //答题正确率 |
| | | if (5 == lotteryEvent.getActivityType()) { |
| | | TUserLotteryEventQuestions questionsServiceOne = userLotteryEventQuestionsAnswersService.getOne(new QueryWrapper<TUserLotteryEventQuestions>().eq("lottery_event_id", id).eq("user_id", userId)); |
| | | if (null != questionsServiceOne) { |
| | | vo.setCorrectAnswerRate(questionsServiceOne.getCorrectAnswerRate()); |
| | | } |
| | | } |
| | | return vo; |
| | | } |
| | | |
| | |
| | | * @return |
| | | */ |
| | | @Override |
| | | public R<TLotteryEventPrize> lotteryDraw(String id) { |
| | | public R<TLotteryEventPrize> lotteryDraw(String id, String orderId) { |
| | | Long userId = SecurityUtils.getUserId(); |
| | | Member member = remoteMemberService.getMember(userId).getData(); |
| | | TLotteryEvent lotteryEvent = this.getById(id); |
| | |
| | | boolean tryLock = lock.tryLock(30, TimeUnit.SECONDS); |
| | | if (tryLock) { |
| | | //判断抽奖次数是否用完 |
| | | int count = userLotteryEventService.count(new QueryWrapper<TUserLotteryEvent>().eq("lottery_event_id", id).eq("user_id", userId)); |
| | | int count = userLotteryEventService.count(new QueryWrapper<TUserLotteryEvent>().eq("lottery_event_id", id).eq("user_id", userId).eq("order_id", orderId)); |
| | | if (lotteryEvent.getTimes() <= count) { |
| | | return R.fail("抽奖次数已用完"); |
| | | } |
| | |
| | | userLotteryEvent.setObjectId(lotteryEventPrize.getObjectId()); |
| | | userLotteryEvent.setObjectName(lotteryEventPrize.getObjectName()); |
| | | userLotteryEvent.setNumber(lotteryEventPrize.getNumber()); |
| | | userLotteryEvent.setOrderId(orderId); |
| | | //中奖优惠券 |
| | | if (1 == lotteryEventPrize.getPrizeType()) { |
| | | remoteCouponService.addMemberCoupon(lotteryEventPrize.getObjectId(), lotteryEventPrize.getNumber(), userId); |
| | | AddMemberCoupon addMemberCoupon = new AddMemberCoupon(); |
| | | addMemberCoupon.setCouponId(lotteryEventPrize.getObjectId()); |
| | | addMemberCoupon.setNumber(lotteryEventPrize.getNumber()); |
| | | addMemberCoupon.setUserId(userId); |
| | | remoteCouponService.addMemberCoupon(addMemberCoupon); |
| | | } |
| | | //中奖积分 |
| | | if (4 == lotteryEventPrize.getPrizeType()) { |
| | | remoteMemberService.addIntegralRecord(lotteryEventPrize.getNumber(), userId, id); |
| | | AddIntegralRecordVo addIntegralRecordVo = new AddIntegralRecordVo(); |
| | | addIntegralRecordVo.setIntegral(lotteryEventPrize.getNumber()); |
| | | addIntegralRecordVo.setUserId(userId); |
| | | addIntegralRecordVo.setOrderId(id); |
| | | remoteMemberService.addIntegralRecord(addIntegralRecordVo); |
| | | } |
| | | userLotteryEvent.setCreateTime(LocalDateTime.now()); |
| | | userLotteryEventService.save(userLotteryEvent); |
| | |
| | | memberGiftRecord.setGiftId(userLotteryEvent.getId()); |
| | | memberGiftRecord.setGiftFrom(1); |
| | | memberGiftRecord.setShopId(member.getRelationShopId()); |
| | | memberGiftRecord.setVerifyStatus(1); |
| | | switch (lotteryEventPrize.getPrizeType()) { |
| | | case 1: |
| | | memberGiftRecord.setGiftType(1); |
| | | memberGiftRecord.setCouponId(userLotteryEvent.getObjectId()); |
| | | memberGiftRecord.setCouponNumber(userLotteryEvent.getNumber()); |
| | | memberGiftRecord.setCouponName(userLotteryEvent.getObjectName()); |
| | | memberGiftRecord.setVerifyStatus(2); |
| | | memberGiftRecord.setVerifyTime(new Date()); |
| | | break; |
| | | case 2: |
| | | memberGiftRecord.setGiftType(2); |
| | | memberGiftRecord.setGoodsId(userLotteryEvent.getObjectId()); |
| | | memberGiftRecord.setGiftName(userLotteryEvent.getObjectName()); |
| | | memberGiftRecord.setGoodsNumber(userLotteryEvent.getNumber()); |
| | | memberGiftRecord.setGoodsName(userLotteryEvent.getObjectName()); |
| | | //添加待核销订单 |
| | | AddOrderVo orderVo = new AddOrderVo(); |
| | | orderVo.setShopId(member.getRelationShopId()); |
| | | orderVo.setUserId(member.getUserId()); |
| | | orderVo.setId(userLotteryEvent.getId()); |
| | | orderVo.setGoodsId(userLotteryEvent.getObjectId()); |
| | | orderVo.setGoodsNum(userLotteryEvent.getNumber()); |
| | | remoteOrderService.addOrder(orderVo); |
| | | break; |
| | | case 3: |
| | | memberGiftRecord.setGiftType(4); |
| | | memberGiftRecord.setGiftName(userLotteryEvent.getObjectName()); |
| | | memberGiftRecord.setGiftNumber(userLotteryEvent.getNumber()); |
| | | //添加待核销订单 |
| | | AddOrderVo orderVo1 = new AddOrderVo(); |
| | | orderVo1.setShopId(member.getRelationShopId()); |
| | | orderVo1.setUserId(member.getUserId()); |
| | | orderVo1.setId(userLotteryEvent.getId()); |
| | | orderVo1.setGoodsName(userLotteryEvent.getObjectName()); |
| | | orderVo1.setGoodsNum(userLotteryEvent.getNumber()); |
| | | remoteOrderService.addOrder(orderVo1); |
| | | break; |
| | | case 4: |
| | | memberGiftRecord.setGiftType(5); |
| | | memberGiftRecord.setIntegralNumber(userLotteryEvent.getNumber()); |
| | | memberGiftRecord.setVerifyStatus(2); |
| | | memberGiftRecord.setVerifyTime(new Date()); |
| | | break; |
| | | } |
| | | memberGiftRecord.setPrizeFrom(2); |
| | | memberGiftRecord.setCreateTime(new Date()); |
| | | memberGiftRecord.setVerifyStatus(1); |
| | | remoteMemberService.saveMemberGiftRecord(memberGiftRecord); |
| | | if(5 != lotteryEventPrize.getPrizeType()){ |
| | | remoteMemberService.saveMemberGiftRecord(memberGiftRecord); |
| | | } |
| | | return R.ok(lotteryEventPrize); |
| | | } |
| | | } catch (Exception e) { |
| | |
| | | voList.forEach(x->{ |
| | | if (null == x.getShopId()){ |
| | | x.setCreateObject("平台创建"); |
| | | |
| | | }else { |
| | | //线下抽奖,获取门店名称 |
| | | x.setActivityType(6); |
| | | if(map.containsKey(Long.valueOf(x.getShopId()))){ |
| | | x.setCreateObject(map.get(Long.valueOf(x.getShopId())).getShopName()); |
| | | }else { |
| | |
| | | } |
| | | MgtLotteryEventDetailVO vo = new MgtLotteryEventDetailVO(); |
| | | BeanUtils.copyProperties(lotteryEvent, vo); |
| | | if (lotteryEvent.getActivityType()==6) { |
| | | //线下抽奖 取商户名称 |
| | | Shop data = remoteShopService.getShop(Long.valueOf(lotteryEvent.getShopId())).getData(); |
| | | if (null != data) { |
| | | vo.setShopName(data.getShopName()); |
| | | } |
| | | } |
| | | |
| | | if(lotteryEvent.getActivityType()==5){ |
| | | //题干数据 |
| | | List<TLotteryEventQuestions> questionsList = lotteryEventQuestionsService.getBaseMapper().selectList(new LambdaQueryWrapper<TLotteryEventQuestions>().eq(TLotteryEventQuestions::getLotteryEventId, lotteryEvent.getId())); |
| | |
| | | .eq(TLotteryEventPrize::getLotteryEventId, lotteryEvent.getId()));*/ |
| | | List<TLotteryEventPrize> prizeList = lotteryEventPrizeService.getPrizeListByLotteryEventId(lotteryEvent.getId()); |
| | | vo.setLotteryEventPrizeList(prizeList); |
| | | |
| | | if(null!=lotteryEvent.getShopId()){ |
| | | //线下抽奖 取商户名称 |
| | | Shop data = remoteShopService.getShop(Long.valueOf(lotteryEvent.getShopId())).getData(); |
| | | if (null != data) { |
| | | vo.setShopName(data.getShopName()); |
| | | } |
| | | } |
| | | return R.ok(vo); |
| | | } |
| | | |