From fc8b51f40e71aa09bb49f407c1e9f68ac94ceb58 Mon Sep 17 00:00:00 2001 From: mitao <2763622819@qq.com> Date: 星期一, 29 七月 2024 18:51:32 +0800 Subject: [PATCH] Merge remote-tracking branch 'origin/master' --- ruoyi-modules/ruoyi-auction/src/main/java/com/ruoyi/auction/service/impl/AuctionGoodsServiceImpl.java | 397 ++++++++++++++++++++++++++++++++++++++++++++++---------- 1 files changed, 325 insertions(+), 72 deletions(-) diff --git a/ruoyi-modules/ruoyi-auction/src/main/java/com/ruoyi/auction/service/impl/AuctionGoodsServiceImpl.java b/ruoyi-modules/ruoyi-auction/src/main/java/com/ruoyi/auction/service/impl/AuctionGoodsServiceImpl.java index cbd7b2a..94e674d 100644 --- a/ruoyi-modules/ruoyi-auction/src/main/java/com/ruoyi/auction/service/impl/AuctionGoodsServiceImpl.java +++ b/ruoyi-modules/ruoyi-auction/src/main/java/com/ruoyi/auction/service/impl/AuctionGoodsServiceImpl.java @@ -12,8 +12,10 @@ import com.ruoyi.auction.controller.management.vo.MgtAuctionBidRecordVO; import com.ruoyi.auction.controller.management.vo.MgtAuctionGoodsVO; import com.ruoyi.auction.domain.AuctionBidRecord; +import com.ruoyi.auction.domain.AuctionBondJl; import com.ruoyi.auction.domain.AuctionBrowseRecord; import com.ruoyi.auction.domain.MemberAuctionCollection; +import com.ruoyi.auction.mapper.AuctionBondJlMapper; import com.ruoyi.auction.mapper.AuctionGoodsMapper; import com.ruoyi.auction.service.IAuctionBidRecordService; import com.ruoyi.auction.service.IAuctionBrowseRecordService; @@ -33,6 +35,7 @@ import com.ruoyi.common.core.utils.StringUtils; import com.ruoyi.common.core.utils.page.BeanUtils; import com.ruoyi.common.core.utils.page.PageDTO; +import com.ruoyi.system.api.constants.ConfigEnum; import com.ruoyi.system.api.constants.NotificationTypeConstant; import com.ruoyi.system.api.domain.AuctionGoods; import com.ruoyi.system.api.domain.CustomConfig; @@ -45,6 +48,7 @@ import com.ruoyi.system.api.domain.MemberAddress; import com.ruoyi.system.api.domain.Order; import com.ruoyi.system.api.domain.OrderAuctionBond; +import com.ruoyi.system.api.domain.WebsocketMessageDTO; import com.ruoyi.system.api.domain.dto.AuctionGoodsListDTO; import com.ruoyi.system.api.domain.dto.AuctionGoodsListPageDTO; import com.ruoyi.system.api.domain.dto.GoodsStockUpdDTO; @@ -54,15 +58,20 @@ import com.ruoyi.system.api.domain.dto.RefundDTO; import com.ruoyi.system.api.domain.vo.AuctionGoodsListVO; import com.ruoyi.system.api.domain.vo.AuctionGoodsinfoVO; +import com.ruoyi.system.api.domain.vo.GoodsInfoTitleValueVO; +import com.ruoyi.system.api.domain.vo.getHomeGoodsSkuXxiVO; import com.ruoyi.system.api.feignClient.AuctionClient; import com.ruoyi.system.api.feignClient.GoodsSkuClient; import com.ruoyi.system.api.feignClient.MemberClient; import com.ruoyi.system.api.feignClient.OrderClient; import com.ruoyi.system.api.feignClient.SysUserClient; -import com.ruoyi.system.api.util.WebSocketUsers; import io.seata.spring.annotation.GlobalTransactional; +import java.math.BigDecimal; +import java.math.RoundingMode; import java.time.LocalDateTime; import java.util.ArrayList; +import java.util.Collections; +import java.util.Comparator; import java.util.HashSet; import java.util.List; import java.util.Map; @@ -108,6 +117,9 @@ @Resource private IAuctionBrowseRecordService iAuctionBrowseRecordService; + @Resource + private AuctionBondJlMapper auctionBondJlMapper; + /** * 获取拍卖商品列表的分页数据 * @@ -141,6 +153,7 @@ query.getListingStatus()) .eq(StringUtils.isNotNull(query.getStartStatus()), AuctionGoods::getStartStatus, query.getStartStatus()) + .orderByDesc(AuctionGoods::getCreateTime) .page(new Page<>(query.getPageCurr(), query.getPageSize())); if (StringUtils.isEmpty(page.getRecords())) { return PageDTO.empty(page); @@ -213,6 +226,15 @@ if (goodsSku.getStock() + auctionGoodsOrg.getAuctionStock() < dto.getAuctionStock()) { throw new ServiceException("商品库存不足"); } + if (!auctionGoodsOrg.getAuctionStock().equals(dto.getAuctionStock())) { + // 更新商品库存 + GoodsStockUpdDTO goodsStockUpdDTO = new GoodsStockUpdDTO(); + goodsStockUpdDTO.setGoodsSkuId(goodsSkuId); + goodsStockUpdDTO.setAuctionStock( + auctionGoodsOrg.getAuctionStock() - dto.getAuctionStock()); + goodsSkuClient.updGoodsStock(Lists.newArrayList(goodsStockUpdDTO), + SecurityConstants.INNER); + } auctionGoodsOrg.setStartingPrice(dto.getStartingPrice()); auctionGoodsOrg.setMinimumMarkupAmount(dto.getMinimumMarkupAmount()); auctionGoodsOrg.setStartTime(dto.getStartTime()); @@ -224,15 +246,8 @@ auctionGoodsOrg.setShareTitle(dto.getShareTitle()); auctionGoodsOrg.setSharePic(dto.getSharePic()); this.updateById(auctionGoodsOrg); - // 更新商品库存 - GoodsStockUpdDTO goodsStockUpdDTO = new GoodsStockUpdDTO(); - goodsStockUpdDTO.setGoodsSkuId(goodsSkuId); - goodsStockUpdDTO.setAuctionStock( - auctionGoodsOrg.getAuctionStock() - dto.getAuctionStock()); - goodsSkuClient.updGoodsStock(Lists.newArrayList(goodsStockUpdDTO), - SecurityConstants.INNER); - auctionAsyncMethodService.auctionGoodsScheduleTask(Lists.newArrayList(auctionGoods)); } + auctionAsyncMethodService.auctionGoodsScheduleTask(Lists.newArrayList(auctionGoods)); } /** @@ -265,13 +280,17 @@ .collect(Collectors.toSet()); List<Member> memberList = memberClient. getMemberListByIds(collect, SecurityConstants.INNER).getData(); - Map<Long, String> memberMap = memberList.stream() - .collect(Collectors.toMap(Member::getId, Member::getNickname)); + Map<Long, Member> memberMap = memberList.stream() + .collect(Collectors.toMap(Member::getId, e -> e)); List<MgtAuctionBidRecordVO> mgtAuctionBidRecordVOS = BeanUtils.copyList(list, MgtAuctionBidRecordVO.class); for (MgtAuctionBidRecordVO vo : mgtAuctionBidRecordVOS) { - String memberName = memberMap.get(vo.getMemberId()); - vo.setMemberName(StringUtils.isNotEmpty(memberName) ? memberName : ""); + Member member = memberMap.get(vo.getMemberId()); + if (StringUtils.isNotNull(member)) { + vo.setMemberName(member.getNickname()); + vo.setPhone(member.getPhone()); + } + } auctionGoodsVO.setRecordList(mgtAuctionBidRecordVOS); } @@ -293,36 +312,79 @@ if (StringUtils.isNull(auctionGoods)) { throw new ServiceException("拍卖商品不存在"); } + // 远程调用商品服务,获取商品信息 + GoodsSku goodsSku = goodsSkuClient.getGoodsSkuOne(auctionGoods.getGoodsSkuId(), + SecurityConstants.INNER) + .getData(); if (auctionGoods.getStartStatus().equals(AuctionStartStatusEnum.IN_AUCTION)) { // 查询出价记录 List<AuctionBidRecord> auctionBidRecords = auctionBidRecordService.getBidRecordByGoodsId( id); - Long memberId = null; + List<AuctionBidRecord> auctionBidRecordList = new ArrayList<>(); if (StringUtils.isNotEmpty(auctionBidRecords)) { - // 中标 - AuctionBidRecord auctionBidRecord = auctionBidRecords.get(0); - auctionBidRecord.setStatus(BidStatusEnum.SUCCESSFUL); - auctionBidRecordService.updateById(auctionBidRecord); - memberId = auctionBidRecord.getMemberId(); - // 创建待支付订单 - OrderDTO orderDTO = new OrderDTO(); - orderDTO.setAuctionType(AuctionOrderTypeEnum.REGULAR_ITEMS); - orderDTO.setGoodsQuantity(auctionGoods.getAuctionStock()); - orderDTO.setGoodsSkuId(auctionGoods.getGoodsSkuId()); - orderDTO.setBound(auctionGoods.getBond()); - orderDTO.setMemberId(auctionBidRecord.getMemberId()); - orderDTO.setTotalAmount(auctionBidRecord.getLastBidAmount()); - orderDTO.setOrderFrom(OrderFromEnum.AUCTION_ORDERS); - orderDTO.setOrderTime(LocalDateTime.now()); - MemberAddress data = memberClient.getMemberAddressOne( - auctionBidRecord.getMemberId(), SecurityConstants.INNER).getData(); - if (StringUtils.isNotNull(data)) { - orderDTO.setReceiverName(data.getRecipientName()); - orderDTO.setReceiverCity(data.getReceiverCity()); - orderDTO.setReceiverDetailAddress(data.getDetailedAddress()); - orderDTO.setReceiverphone(data.getRecipientPhone()); + if (auctionBidRecords.size() >= auctionGoods.getAuctionStock()) { + // 中标 + for (int i = 0; i < auctionGoods.getAuctionStock(); i++) { + AuctionBidRecord auctionBidRecord = auctionBidRecords.get(i); + auctionBidRecord.setStatus(BidStatusEnum.SUCCESSFUL); + auctionBidRecordList.add(auctionBidRecord); + } + } else { + // 中标 + for (int i = 0; i < auctionBidRecords.size(); i++) { + AuctionBidRecord auctionBidRecord = auctionBidRecords.get(i); + auctionBidRecord.setStatus(BidStatusEnum.SUCCESSFUL); + auctionBidRecordList.add(auctionBidRecord); + } + // 退回剩余库存 + GoodsStockUpdDTO goodsStockUpdDTO = new GoodsStockUpdDTO(); + goodsStockUpdDTO.setGoodsSkuId(auctionGoods.getGoodsSkuId()); + goodsStockUpdDTO.setAuctionStock( + auctionGoods.getAuctionStock() - auctionBidRecords.size()); + goodsSkuClient.updGoodsStock(Lists.newArrayList(goodsStockUpdDTO), + SecurityConstants.INNER); } - orderClient.saveOrderOne(orderDTO, SecurityConstants.INNER); + + auctionBidRecordService.updateBatchById(auctionBidRecordList); + + // 创建待支付订单 + CustomConfig moneyConfig = sysUserClient.getconfig( + ConfigEnum.MEMBER_POINTS_MONEY.getKey()).getData(); + CustomConfig pointsConfig = sysUserClient.getconfig( + ConfigEnum.MEMBER_POINTS_POINTS.getKey()).getData(); + for (AuctionBidRecord auctionBidRecord : auctionBidRecordList) { + BigDecimal lastBidAmount = auctionBidRecord.getLastBidAmount(); + BigDecimal divide = lastBidAmount.divide( + new BigDecimal(moneyConfig.getConfigValue()), 0, RoundingMode.DOWN); + int points = divide.multiply( + new BigDecimal(pointsConfig.getConfigValue())).intValue(); + OrderDTO orderDTO = new OrderDTO(); + orderDTO.setAuctionType(AuctionOrderTypeEnum.REGULAR_ITEMS); + orderDTO.setGoodsQuantity(auctionGoods.getAuctionStock()); + orderDTO.setGoodsSkuId(auctionGoods.getId()); + orderDTO.setBound(auctionGoods.getBond()); + orderDTO.setMemberId(auctionBidRecord.getMemberId()); + orderDTO.setTotalAmount(auctionBidRecord.getLastBidAmount()); + orderDTO.setOrderFrom(OrderFromEnum.AUCTION_ORDERS); + orderDTO.setOrderTime(LocalDateTime.now()); + orderDTO.setPoints(points); + orderDTO.setBound(auctionGoods.getBond()); + MemberAddress data = memberClient.getMemberAddressOne( + auctionBidRecord.getMemberId(), SecurityConstants.INNER).getData(); + if (StringUtils.isNotNull(data)) { + orderDTO.setReceiverName(data.getRecipientName()); + orderDTO.setReceiverCity(data.getReceiverCity()); + orderDTO.setReceiverDetailAddress(data.getDetailedAddress()); + orderDTO.setReceiverphone(data.getRecipientPhone()); + } + if (StringUtils.isNotNull(goodsSku)) { + orderDTO.setCoverPic(goodsSku.getCoverPic()); + orderDTO.setPrice(goodsSku.getPrice()); + orderDTO.setSkuName(goodsSku.getSkuName()); + } + orderDTO.setOrderTimeSx(auctionGoods.getEndTime()); + orderClient.saveOrderOne(orderDTO, SecurityConstants.INNER); + } } else { // 没有人出价,退回拍卖商品库存 GoodsStockUpdDTO goodsStockUpdDTO = new GoodsStockUpdDTO(); @@ -341,14 +403,19 @@ SecurityConstants.INNER).getData(); if (StringUtils.isNotEmpty(auctionBondList)) { List<RefundDTO> refundDTOList = new ArrayList<>(); + List<Long> unRefundMemberIdList = auctionBidRecordList.stream() + .map(AuctionBidRecord::getMemberId).collect( + Collectors.toList()); for (OrderAuctionBond orderAuctionBond : auctionBondList) { + // 已中标需在订单完成后退保证金 - if (orderAuctionBond.getMemberId().equals(memberId)) { + if (unRefundMemberIdList.contains(orderAuctionBond.getMemberId())) { continue; } RefundDTO refundDTO = new RefundDTO(); refundDTO.setOrderNo(orderAuctionBond.getOrderNo()); refundDTO.setAmount(orderAuctionBond.getBond()); + refundDTOList.add(refundDTO); } // 远程调用订单服务进行退款 Map<String, Object> data = orderClient.refund(refundDTOList, @@ -373,7 +440,8 @@ return null; }).filter(Objects::nonNull).collect(Collectors.toList()); // 远程调用订单服务修改订单状态 - orderClient.updateOrderAuctionBondStatus(ids, BondStatusEnum.PAID,SecurityConstants.INNER); + orderClient.updateOrderAuctionBondStatus(ids, BondStatusEnum.REFUNDED, + SecurityConstants.INNER); } } } @@ -385,11 +453,23 @@ List<GoodsSku> goodsSku = goodsSkuClient.getGoodsByName(auctionGoodsListDTO.getGoodsSkuName(), SecurityConstants.INNER) .getData(); - goodsSkuIdList = goodsSku.stream().map(GoodsSku::getId) - .collect(Collectors.toSet()); + if (goodsSku!=null){ + goodsSkuIdList = goodsSku.stream().map(GoodsSku::getId) + .collect(Collectors.toSet()); + } + } + AuctionGoodsListPageDTO auctionGoodsListPageDTO=new AuctionGoodsListPageDTO(); - auctionGoodsListPageDTO.setGoodsSkuIdList(goodsSkuIdList); + if (StringUtils.isNotEmpty(auctionGoodsListDTO.getGoodsSkuName())) { + if (goodsSkuIdList != null) { + auctionGoodsListPageDTO.setGoodsSkuIdList(goodsSkuIdList); + } else { + goodsSkuIdList = new HashSet<>(); + goodsSkuIdList.add(0L); + auctionGoodsListPageDTO.setGoodsSkuIdList(goodsSkuIdList); + } + } Page<AuctionGoodsListVO> page = new Page<>(); page.setSize(auctionGoodsListDTO.getPageSize()); @@ -434,32 +514,40 @@ auctionGoodsinfoVO.setUnit(goodsSkuOne.getUnit()); auctionGoodsinfoVO.setBond(byId.getBond()); auctionGoodsinfoVO.setDescription(goodsSkuOne.getDescription()); + auctionGoodsinfoVO.setExplain(byId.getDescription()); auctionGoodsinfoVO.setYears(goodsSkuOne.getYears()); GoodsBrand data = goodsSkuClient.getBrandOne(goodsSkuOne.getBrandId(), SecurityConstants.INNER).getData(); GoodsCategory data1 = goodsSkuClient.getCategoryOne(goodsSkuOne.getCategoryId(), SecurityConstants.INNER).getData(); GoodsSeries data2 = goodsSkuClient.getSeriesOne(goodsSkuOne.getSeriesId(), SecurityConstants.INNER).getData(); GoodsFlavorType data3 = goodsSkuClient.getFlavorTypeOne(goodsSkuOne.getFlavorTypeId(), SecurityConstants.INNER).getData(); - auctionGoodsinfoVO.setBrand(data.getBrandName()); - auctionGoodsinfoVO.setCategory(data1.getCategoryName()); + if (data!=null){ + auctionGoodsinfoVO.setBrand(data.getBrandName()); + } + if (data1!=null){ + auctionGoodsinfoVO.setCategory(data1.getCategoryName()); + } + if (data2!=null){ auctionGoodsinfoVO.setSeries(data2.getSeriesName()); - auctionGoodsinfoVO.setFlavorType(data3.getFlavorTypeName()); + } + if (data3!=null) { + auctionGoodsinfoVO.setFlavorType(data3.getFlavorTypeName()); + } auctionGoodsinfoVO.setCoverPic(goodsSkuOne.getCoverPic()); auctionGoodsinfoVO.setAlbum(goodsSkuOne.getAlbum()); - auctionGoodsinfoVO.setAuthentication(byId.getAuthentication()); + auctionGoodsinfoVO.setAuthentication(byId.getAuthentication().getCode()); auctionGoodsinfoVO.setMinimumMarkupAmount(byId.getMinimumMarkupAmount()); auctionGoodsinfoVO.setSpec(goodsSkuOne.getSpec()); auctionGoodsinfoVO.setSpecUnit(goodsSkuOne.getSpecUnit()); auctionGoodsinfoVO.setShareTitle(goodsSkuOne.getShareTitle()); - auctionGoodsinfoVO.setSpecUnit(goodsSkuOne.getSpecUnit()); auctionGoodsinfoVO.setDetail(goodsSkuOne.getDetail()); auctionGoodsinfoVO.setBond(byId.getBond()); auctionGoodsinfoVO.setYears(goodsSkuOne.getYears()); - auctionGoodsinfoVO.setSharePic(goodsSkuOne.getSharePic()); - auctionGoodsinfoVO.setShareTitle(goodsSkuOne.getShareTitle()); + auctionGoodsinfoVO.setSharePic(byId.getSharePic()); + auctionGoodsinfoVO.setShareTitle(byId.getShareTitle()); LambdaQueryWrapper<AuctionBidRecord> wrapper1= Wrappers.lambdaQuery(); - wrapper1.eq(AuctionBidRecord::getMemberId,auctionGoodsListDTO.getMemberId()); wrapper1.eq(AuctionBidRecord::getAuctionType,1); wrapper1.eq(AuctionBidRecord::getTargetId,byId.getId()); + wrapper1.eq(AuctionBidRecord::getMemberId,auctionGoodsListDTO.getMemberId()); wrapper1.eq(AuctionBidRecord::getDelFlag,0); AuctionBidRecord list1 = auctionBidRecordService.getOne(wrapper1); if (list1!=null){ @@ -493,12 +581,18 @@ }else { auctionGoodsinfoVO.setIsCollection(1); } - List<OrderAuctionBond> datas = orderClient.getAuctionGoodsOrderAuctionBondList(auctionGoodsListDTO, SecurityConstants.INNER).getData(); - if (datas.size()>0){ - auctionGoodsinfoVO.setIsApply(2); - }else{ - auctionGoodsinfoVO.setIsApply(1); - } + LambdaQueryWrapper<AuctionBondJl> wrapper8=Wrappers.lambdaQuery(); + wrapper8.eq(AuctionBondJl::getAuctionGoodsId,byId.getId()); + wrapper8.eq(AuctionBondJl::getMemberId,auctionGoodsListDTO.getMemberId()); + wrapper8.eq(AuctionBondJl::getIsState,0); + AuctionBondJl auctionBondJl = auctionBondJlMapper.selectOne(wrapper8); + if(auctionBondJl!=null){ + auctionGoodsinfoVO.setIsApply(2); + }else{ + auctionGoodsinfoVO.setIsApply(1); + } + + LocalDateTime now = LocalDateTime.now(); LocalDateTime newTime7 = now.minusDays(7); @@ -506,6 +600,7 @@ LambdaQueryWrapper<AuctionBrowseRecord> wrapper3=Wrappers.lambdaQuery(); wrapper3.eq(AuctionBrowseRecord::getDelFlag,0); wrapper3.eq(AuctionBrowseRecord::getTargetId,auctionGoodsListDTO.getGoodsSkuId()); + wrapper3.eq(AuctionBrowseRecord::getBrowseType,AuctionOrderTypeEnum.REGULAR_ITEMS); wrapper3.eq(AuctionBrowseRecord::getMemberId,auctionGoodsListDTO.getMemberId()); wrapper3.ge(AuctionBrowseRecord::getCreateTime, newTime7) .le(AuctionBrowseRecord::getCreateTime, now); @@ -518,9 +613,32 @@ iAuctionBrowseRecordService.save(auctionBrowseRecord); } + LambdaQueryWrapper<AuctionBidRecord> wrapper5= Wrappers.lambdaQuery(); + wrapper5.eq(AuctionBidRecord::getAuctionType,1); + wrapper5.eq(AuctionBidRecord::getTargetId,byId.getId()); + wrapper5.eq(AuctionBidRecord::getDelFlag,0); + wrapper5.orderByDesc(AuctionBidRecord::getLastBidAmount); + List<AuctionBidRecord> list2 = auctionBidRecordService.list(wrapper5); + if (list2.size()>0){ + auctionGoodsinfoVO.setZgBid(list2.get(0).getLastBidAmount()); + } - CustomConfig returnAddressUserName = sysUserClient.getconfig("MALL_ORDER_DESCRIPTION").getData(); - auctionGoodsinfoVO.setExplain(returnAddressUserName.getConfigValue()); + + /*CustomConfig returnAddressUserName = sysUserClient.getconfig("MALL_ORDER_DESCRIPTION").getData(); + auctionGoodsinfoVO.setExplain(returnAddressUserName.getConfigValue());*/ + + + List<getHomeGoodsSkuXxiVO> homeGoodsSkuXxiVOS=new ArrayList<>(); + List<GoodsInfoTitleValueVO> goodsInfoTitleValueVOList = goodsSkuClient.getlistByGoodsId(goodsSkuOne.getId(), SecurityConstants.INNER).getData(); + Collections.sort(goodsInfoTitleValueVOList, Comparator.comparingInt(GoodsInfoTitleValueVO::getSortNum)); + for (GoodsInfoTitleValueVO goodsInfoTitleValueVO:goodsInfoTitleValueVOList){ + getHomeGoodsSkuXxiVO getHomeGoodsSkuXxiVOs=new getHomeGoodsSkuXxiVO(); + getHomeGoodsSkuXxiVOs.setContent(goodsInfoTitleValueVO.getContent()); + getHomeGoodsSkuXxiVOs.setTitleName(goodsInfoTitleValueVO.getTitleName()); + homeGoodsSkuXxiVOS.add(getHomeGoodsSkuXxiVOs); + } + auctionGoodsinfoVO.setXxiVOS(homeGoodsSkuXxiVOS); + return auctionGoodsinfoVO; } @@ -530,8 +648,8 @@ memberAuctionSalesroomDTO.setMemberId(auctionGoodsListDTO.getMemberId()); List<OrderAuctionBond> data = orderClient.getAuctionGoodsOrderAuctionBondList(auctionGoodsListDTO, SecurityConstants.INNER).getData(); Set<Long> goodsSkuIdList = null; - if (data!=null){ - goodsSkuIdList = data.stream().map(OrderAuctionBond::getAuctionSalesroomId) + if (data.size()>0){ + goodsSkuIdList = data.stream().map(OrderAuctionBond::getAuctionGoodsId) .collect(Collectors.toSet()); }else { Set<Long> goodsSkuIdList1 =new HashSet<>(); @@ -545,13 +663,18 @@ } if (auctionGoodsListDTO.getStartStatus()!=4){ - auctionGoodsListPageDTO.setStartStatus(auctionGoodsListDTO.getStartStatus()); + if (auctionGoodsListDTO.getStartStatus()==0){ + auctionGoodsListPageDTO.setStartStatus(5); + }else{ + auctionGoodsListPageDTO.setStartStatus(auctionGoodsListDTO.getStartStatus()); + } + } Page<AuctionGoodsListVO> page = new Page<>(); page.setSize(auctionGoodsListDTO.getPageSize()); page.setCurrent(auctionGoodsListDTO.getPageCurr()); - List<AuctionGoods> auctionGoodsPgeList = auctionGoodsMapper.getAuctionGoodsPgeList(page, auctionGoodsListPageDTO); + List<AuctionGoods> auctionGoodsPgeList = auctionGoodsMapper.getAuctionGoodsPgeList1(page, auctionGoodsListPageDTO); List<AuctionGoodsListVO> auctionGoodsVOS=new ArrayList<>(); for (AuctionGoods auctionGoods:auctionGoodsPgeList){ AuctionGoodsListVO auctionGoodsVO=new AuctionGoodsListVO(); @@ -592,23 +715,152 @@ } @Override + @GlobalTransactional(rollbackFor = Exception.class) + @Transactional public void endAuctionGoods(Long id) throws JsonProcessingException { AuctionGoods auctionGoods = this.getById(id); - if (StringUtils.isNotNull(auctionGoods) && auctionGoods.getListingStatus().equals( - ListingStatusEnum.ON_SHELVES) && auctionGoods.getStartStatus() + if (StringUtils.isNotNull(auctionGoods) && auctionGoods.getStartStatus() .equals(AuctionStartStatusEnum.IN_AUCTION)) { - this.lambdaUpdate().set(AuctionGoods::getStartStatus, AuctionStartStatusEnum.ENDED) - .eq(AuctionGoods::getId, id); - // TODO 退保证金 - orderClient.returnBondByAuctionGoodsId(id, SecurityConstants.INNER); + // 远程调用商品服务,获取商品信息 + GoodsSku goodsSku = goodsSkuClient.getGoodsSkuOne(auctionGoods.getGoodsSkuId(), + SecurityConstants.INNER) + .getData(); + if (auctionGoods.getStartStatus().equals(AuctionStartStatusEnum.IN_AUCTION)) { + // 查询出价记录 + List<AuctionBidRecord> auctionBidRecords = auctionBidRecordService.getBidRecordByGoodsId( + id); + List<AuctionBidRecord> auctionBidRecordList = new ArrayList<>(); + if (StringUtils.isNotEmpty(auctionBidRecords)) { + if (auctionBidRecords.size() >= auctionGoods.getAuctionStock()) { + // 中标 + for (int i = 0; i < auctionGoods.getAuctionStock(); i++) { + AuctionBidRecord auctionBidRecord = auctionBidRecords.get(i); + auctionBidRecord.setStatus(BidStatusEnum.SUCCESSFUL); + auctionBidRecordList.add(auctionBidRecord); + } + } else { + // 中标 + for (int i = 0; i < auctionBidRecords.size(); i++) { + AuctionBidRecord auctionBidRecord = auctionBidRecords.get(i); + auctionBidRecord.setStatus(BidStatusEnum.SUCCESSFUL); + auctionBidRecordList.add(auctionBidRecord); + } + // 退回剩余库存 + GoodsStockUpdDTO goodsStockUpdDTO = new GoodsStockUpdDTO(); + goodsStockUpdDTO.setGoodsSkuId(auctionGoods.getGoodsSkuId()); + goodsStockUpdDTO.setAuctionStock( + auctionGoods.getAuctionStock() - auctionBidRecords.size()); + goodsSkuClient.updGoodsStock(Lists.newArrayList(goodsStockUpdDTO), + SecurityConstants.INNER); + } + auctionBidRecordService.updateBatchById(auctionBidRecordList); + + // 创建待支付订单 + CustomConfig moneyConfig = sysUserClient.getconfig( + ConfigEnum.MEMBER_POINTS_MONEY.getKey()).getData(); + CustomConfig pointsConfig = sysUserClient.getconfig( + ConfigEnum.MEMBER_POINTS_POINTS.getKey()).getData(); + for (AuctionBidRecord auctionBidRecord : auctionBidRecordList) { + BigDecimal lastBidAmount = auctionBidRecord.getLastBidAmount(); + BigDecimal divide = lastBidAmount.divide( + new BigDecimal(moneyConfig.getConfigValue()), 0, RoundingMode.DOWN); + int points = divide.multiply( + new BigDecimal(pointsConfig.getConfigValue())).intValue(); + OrderDTO orderDTO = new OrderDTO(); + orderDTO.setAuctionType(AuctionOrderTypeEnum.REGULAR_ITEMS); + orderDTO.setGoodsQuantity(auctionGoods.getAuctionStock()); + orderDTO.setGoodsSkuId(auctionGoods.getId()); + orderDTO.setBound(auctionGoods.getBond()); + orderDTO.setMemberId(auctionBidRecord.getMemberId()); + orderDTO.setTotalAmount(lastBidAmount); + orderDTO.setOrderFrom(OrderFromEnum.AUCTION_ORDERS); + orderDTO.setOrderTime(LocalDateTime.now()); + orderDTO.setPoints(points); + orderDTO.setBound(auctionGoods.getBond()); + MemberAddress data = memberClient.getMemberAddressOne( + auctionBidRecord.getMemberId(), SecurityConstants.INNER).getData(); + if (StringUtils.isNotNull(data)) { + orderDTO.setReceiverName(data.getRecipientName()); + orderDTO.setReceiverCity(data.getReceiverCity()); + orderDTO.setReceiverDetailAddress(data.getDetailedAddress()); + orderDTO.setReceiverphone(data.getRecipientPhone()); + } + if (StringUtils.isNotNull(goodsSku)) { + orderDTO.setCoverPic(goodsSku.getCoverPic()); + orderDTO.setPrice(goodsSku.getPrice()); + orderDTO.setSkuName(goodsSku.getSkuName()); + } + orderDTO.setOrderTimeSx(auctionGoods.getEndTime()); + orderClient.saveOrderOne(orderDTO, SecurityConstants.INNER); + } + } else { + // 没有人出价,退回拍卖商品库存 + GoodsStockUpdDTO goodsStockUpdDTO = new GoodsStockUpdDTO(); + goodsStockUpdDTO.setGoodsSkuId(auctionGoods.getGoodsSkuId()); + goodsStockUpdDTO.setAuctionStock(auctionGoods.getAuctionStock()); + goodsSkuClient.updGoodsStock(Lists.newArrayList(goodsStockUpdDTO), + SecurityConstants.INNER); + } + // 结束拍卖 + this.lambdaUpdate().set(AuctionGoods::getStartStatus, AuctionStartStatusEnum.ENDED) + .eq(AuctionGoods::getId, id).update(); + // 查询已支付保证金记录 + List<OrderAuctionBond> auctionBondList = orderClient.getOrderAuctionBondList(id, + AuctionOrderTypeEnum.REGULAR_ITEMS, + BondStatusEnum.PAID, + SecurityConstants.INNER).getData(); + if (StringUtils.isNotEmpty(auctionBondList)) { + List<RefundDTO> refundDTOList = new ArrayList<>(); + List<Long> unRefundMemberIdList = auctionBidRecordList.stream() + .map(AuctionBidRecord::getMemberId).collect( + Collectors.toList()); + for (OrderAuctionBond orderAuctionBond : auctionBondList) { + + // 已中标需在订单完成后退保证金 + if (unRefundMemberIdList.contains(orderAuctionBond.getMemberId())) { + continue; + } + RefundDTO refundDTO = new RefundDTO(); + refundDTO.setOrderNo(orderAuctionBond.getOrderNo()); + refundDTO.setAmount(orderAuctionBond.getBond()); + refundDTOList.add(refundDTO); + } + // 远程调用订单服务进行退款 + Map<String, Object> data = orderClient.refund(refundDTOList, + SecurityConstants.INNER).getData(); + // 处理退款返回结果 + List<String> successfulOrders = new ArrayList<>(); + List<String> failedOrders = new ArrayList<>(); + + data.forEach((key, value) -> { + if ((boolean) value) { + successfulOrders.add(key); + } else { + failedOrders.add(key); + } + }); + log.info("订单号:{},退款失败", failedOrders); + // 退款成功的订单修改状态 + List<Long> ids = auctionBondList.stream().map(bond -> { + if (successfulOrders.contains(bond.getOrderNo())) { + return bond.getId(); + } + return null; + }).filter(Objects::nonNull).collect(Collectors.toList()); + // 远程调用订单服务修改订单状态 + orderClient.updateOrderAuctionBondStatus(ids, BondStatusEnum.REFUNDED, + SecurityConstants.INNER); + } + } Map<String, Object> map = new ConcurrentHashMap<>(); map.put("notification_type", NotificationTypeConstant.AUCTION_GOODS); map.put("notification_time", DateUtils.dateTimeNow("yyyy-MM-dd HH:mm:ss")); map.put("target_id", id); map.put("message_type", "end"); String msg = objectMapper.writeValueAsString(map); - WebSocketUsers.sendMessageToUsersByType(ClientTypeEnum.MEMBER.getCode(), msg); + sysUserClient.pushByClientType(WebsocketMessageDTO.builder().message(msg) + .clientType(ClientTypeEnum.MEMBER).build(), SecurityConstants.INNER); log.info("===================>发送websocket通知,消息体{}", msg); } } @@ -619,15 +871,16 @@ if (StringUtils.isNotNull(auctionGoods) && auctionGoods.getListingStatus().equals( ListingStatusEnum.ON_SHELVES) && auctionGoods.getStartStatus() .equals(AuctionStartStatusEnum.IN_PREVIEW)) { - this.lambdaUpdate().set(AuctionGoods::getStartStatus, AuctionStartStatusEnum.IN_AUCTION) - .eq(AuctionGoods::getId, id); + auctionGoods.setStartStatus(AuctionStartStatusEnum.IN_AUCTION); + this.updateById(auctionGoods); Map<String, Object> map = new ConcurrentHashMap<>(); map.put("notification_type", NotificationTypeConstant.AUCTION_GOODS); map.put("notification_time", DateUtils.dateTimeNow("yyyy-MM-dd HH:mm:ss")); map.put("target_id", id); map.put("message_type", "start"); String msg = objectMapper.writeValueAsString(map); - WebSocketUsers.sendMessageToUsersByType(ClientTypeEnum.MEMBER.getCode(), msg); + sysUserClient.pushByClientType(WebsocketMessageDTO.builder().message(msg) + .clientType(ClientTypeEnum.MEMBER).build(), SecurityConstants.INNER); log.info("===================>发送websocket通知,消息体{}", msg); } } -- Gitblit v1.7.1