From 78698a4a6731054bd9e5bc397cf9aba4764aa763 Mon Sep 17 00:00:00 2001 From: mitao <2763622819@qq.com> Date: 星期五, 24 五月 2024 18:17:19 +0800 Subject: [PATCH] 提交【管理后台】 商城管理-团购管理-立即结束 接口 --- ruoyi-modules/ruoyi-goods/src/main/java/com/ruoyi/goods/service/impl/GoodsGroupPurchaseServiceImpl.java | 67 ++++++++++++++++++++++++++++++++- 1 files changed, 64 insertions(+), 3 deletions(-) diff --git a/ruoyi-modules/ruoyi-goods/src/main/java/com/ruoyi/goods/service/impl/GoodsGroupPurchaseServiceImpl.java b/ruoyi-modules/ruoyi-goods/src/main/java/com/ruoyi/goods/service/impl/GoodsGroupPurchaseServiceImpl.java index 3f9575c..fa87a08 100644 --- a/ruoyi-modules/ruoyi-goods/src/main/java/com/ruoyi/goods/service/impl/GoodsGroupPurchaseServiceImpl.java +++ b/ruoyi-modules/ruoyi-goods/src/main/java/com/ruoyi/goods/service/impl/GoodsGroupPurchaseServiceImpl.java @@ -2,7 +2,9 @@ import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import com.ruoyi.common.core.enums.GroupStatusEnum; import com.ruoyi.common.core.enums.ListingStatusEnum; +import com.ruoyi.common.core.enums.PaymentMethodEnum; import com.ruoyi.common.core.enums.StartStatusEnum; import com.ruoyi.common.core.exception.ServiceException; import com.ruoyi.common.core.utils.StringUtils; @@ -12,10 +14,15 @@ import com.ruoyi.goods.controller.management.DTO.GoodsGroupPurchaseQuery; import com.ruoyi.goods.controller.management.VO.GoodsGroupPurchaseVO; import com.ruoyi.goods.domain.GoodsGroupPurchase; +import com.ruoyi.goods.domain.GoodsSku; import com.ruoyi.goods.mapper.GoodsGroupPurchaseMapper; import com.ruoyi.goods.service.IGoodsGroupPurchaseService; +import com.ruoyi.goods.service.IGoodsSkuService; +import com.ruoyi.goods.service.async.AsyncMethodService; +import com.ruoyi.system.api.domain.Order; import com.ruoyi.system.api.domain.dto.ListStatusDTO; import com.ruoyi.system.api.feignClient.OrderClient; +import java.util.List; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.springframework.stereotype.Service; @@ -34,7 +41,8 @@ public class GoodsGroupPurchaseServiceImpl extends ServiceImpl<GoodsGroupPurchaseMapper, GoodsGroupPurchase> implements IGoodsGroupPurchaseService { private final OrderClient orderClient; - + private final IGoodsSkuService goodsSkuService; + private final AsyncMethodService asyncMethodService; /** * 获取团购商品列表的分页数据 * @@ -57,16 +65,39 @@ public void saveGoodsGroupPurchase(GoodsGroupPurchaseDTO dto) { GoodsGroupPurchase goodsGroupPurchase = BeanUtils.copyBean(dto, GoodsGroupPurchase.class); if (StringUtils.isNull(dto.getId())) { + if (StringUtils.isNull(dto.getGoodsSkuId())) { + throw new ServiceException("商品id不能为空"); + } this.save(goodsGroupPurchase); + GoodsSku goodsSku = goodsSkuService.getById(dto.getGoodsSkuId()); + if (StringUtils.isNull(goodsSku)) { + throw new ServiceException("商品不存在"); + } + int groupPurchaseStock = dto.getLimitNumber() * dto.getGroupSize(); + goodsSkuService.lambdaUpdate() + .set(GoodsSku::getStock, goodsSku.getStock() - groupPurchaseStock) + .ge(GoodsSku::getStock, groupPurchaseStock) + .eq(GoodsSku::getId, goodsSku.getId()); } else { GoodsGroupPurchase groupPurchase = this.getById(dto.getId()); if (StringUtils.isNull(groupPurchase)) { throw new ServiceException("团购商品不存在"); } + int originGroupStock = groupPurchase.getLimitNumber() * groupPurchase.getGroupSize(); + GoodsSku goodsSku = goodsSkuService.getById(dto.getGoodsSkuId()); + if (StringUtils.isNull(goodsSku)) { + throw new ServiceException("商品不存在"); + } + int groupPurchaseStock = dto.getLimitNumber() * dto.getGroupSize(); + int latestStock = originGroupStock - groupPurchaseStock; + goodsSkuService.lambdaUpdate() + .set(GoodsSku::getStock, + goodsSku.getStock() + latestStock) + .ge(GoodsSku::getStock, latestStock) + .eq(GoodsSku::getId, goodsSku.getId()); this.updateById(goodsGroupPurchase); + asyncMethodService.groupPurchaseScheduleTask(goodsGroupPurchase); } - //TODO 添加调度任务 处理团购商品开始结束 - } /** @@ -141,4 +172,34 @@ //TODO 通知小程序 } } + + /** + * 立即结束 + * + * @param id 团购商品id + */ + @Override + public void stopImmediately(Long id) { + GoodsGroupPurchase groupPurchase = this.getById(id); + if (StringUtils.isNull(groupPurchase)) { + throw new ServiceException("团购商品不存在"); + } + //判断商品状态,未成团则查询关联订单,进行退款;成团就直接修改状态 + if (groupPurchase.getGroupStatus().equals(GroupStatusEnum.TO_FORM_A_GROUP)) { + //查询关联订单 + List<Order> orderList = orderClient.getOrderByGroupPurchaseId(id).getData(); + for (Order order : orderList) { + if (PaymentMethodEnum.ALIPAY.equals(order.getPaymentMethod())) { + //TODO + } + if (PaymentMethodEnum.WECHAT.equals(order.getPaymentMethod())) { + //TODO + } + } + } else { + this.lambdaUpdate() + .set(GoodsGroupPurchase::getStartStatus, StartStatusEnum.ENDED) + .eq(GoodsGroupPurchase::getId, id).update(); + } + } } -- Gitblit v1.7.1