|
|
@@ -0,0 +1,497 @@
|
|
|
+package shop.alien.storeplatform.service.impl;
|
|
|
+
|
|
|
+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.conditions.update.LambdaUpdateWrapper;
|
|
|
+import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
|
+import com.baomidou.mybatisplus.core.toolkit.ObjectUtils;
|
|
|
+import com.baomidou.mybatisplus.core.toolkit.StringUtils;
|
|
|
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
+import lombok.RequiredArgsConstructor;
|
|
|
+import org.apache.http.client.utils.DateUtils;
|
|
|
+import org.springframework.beans.BeanUtils;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
+import shop.alien.entity.store.*;
|
|
|
+import shop.alien.entity.store.dto.LifeGroupBuyDto;
|
|
|
+import shop.alien.entity.store.vo.LifeGroupBuyNameThaliVo;
|
|
|
+import shop.alien.entity.store.vo.LifeGroupBuyThaliVo;
|
|
|
+import shop.alien.entity.store.vo.StoreMenuVo;
|
|
|
+import shop.alien.entity.storePlantform.LifeGroupBuyMainPlantform;
|
|
|
+import shop.alien.entity.storePlantform.vo.LifeGroupBuyPlantformDto;
|
|
|
+import shop.alien.mapper.*;
|
|
|
+import shop.alien.mapper.storePlantform.LifeGroupBuyMainPlantformMapper;
|
|
|
+import shop.alien.storeplatform.service.LifeGroupBuyService;
|
|
|
+import shop.alien.util.common.JwtUtil;
|
|
|
+
|
|
|
+import java.math.BigDecimal;
|
|
|
+import java.util.*;
|
|
|
+import java.util.stream.Collectors;
|
|
|
+
|
|
|
+/**
|
|
|
+ * 团购服务实现
|
|
|
+ * @date 2025-11-11
|
|
|
+ */
|
|
|
+@Service
|
|
|
+@RequiredArgsConstructor
|
|
|
+public class LifeGroupBuyServiceImpl extends ServiceImpl<LifeGroupBuyMainMapper, LifeGroupBuyMain> implements LifeGroupBuyService {
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 团购主表 Mapper
|
|
|
+ */
|
|
|
+ private final LifeGroupBuyMainMapper lifeGroupBuyMainMapper;
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 团购套餐 Mapper
|
|
|
+ */
|
|
|
+ private final LifeGroupBuyThaliMapper lifeGroupBuyThaliMapper;
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 门店图片 Mapper
|
|
|
+ */
|
|
|
+ private final StoreImgMapper storeImgMapper;
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 节假日对照 Mapper
|
|
|
+ */
|
|
|
+ private final EssentialHolidayComparisonMapper essentialHolidayComparisonMapper;
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 门店菜品 Mapper
|
|
|
+ */
|
|
|
+ private final StoreMenuMapper storeMenuMapper;
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 收藏 Mapper
|
|
|
+ */
|
|
|
+ private final LifeCollectMapper lifeCollectMapper;
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 审核记录 Mapper
|
|
|
+ */
|
|
|
+ private final WebAuditMapper webAuditMapper;
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 订单 Mapper
|
|
|
+ */
|
|
|
+ private final LifeUserOrderMapper lifeUserOrderMapper;
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 团购主表 Mapper
|
|
|
+ */
|
|
|
+ private final LifeGroupBuyMainPlantformMapper lifeGroupBuyMainPlantformMapper;
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 保存团购草稿
|
|
|
+ *
|
|
|
+ * @param lifeGroupBuyDto 团购数据
|
|
|
+ * @return 是否保存成功
|
|
|
+ * @date 2025-11-11
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public boolean saveDraft(LifeGroupBuyPlantformDto lifeGroupBuyDto) {
|
|
|
+ LifeGroupBuyMainPlantform lifeGroupBuyMain = lifeGroupBuyDto.getLifeGroupBuyMain();
|
|
|
+ List<LifeGroupBuyThali> lifeGroupBuyThalis = lifeGroupBuyDto.getLifeGroupBuyThalis();
|
|
|
+
|
|
|
+
|
|
|
+ if (lifeGroupBuyMain.getEffectiveDateType() != null && lifeGroupBuyMain.getEffectiveDateType() == 1) {
|
|
|
+ List<String> expirationDate = lifeGroupBuyMain.getExpirationDate();
|
|
|
+ if (ObjectUtils.isNotEmpty(expirationDate)) {
|
|
|
+ lifeGroupBuyMain.setEffectiveDateValue(String.join(",", expirationDate));
|
|
|
+ } else {
|
|
|
+ lifeGroupBuyMain.setEffectiveDateValue("");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if (lifeGroupBuyMain.getDisableDateType() != null && lifeGroupBuyMain.getDisableDateType() == 2) {
|
|
|
+ lifeGroupBuyMain.getDisableDateList()
|
|
|
+ if (ObjectUtils.isNotEmpty()) {
|
|
|
+ lifeGroupBuyMain.setEffectiveDateValue(String.join(",", disableDateList));
|
|
|
+ } else {
|
|
|
+ lifeGroupBuyMain.setEffectiveDateValue("");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ JSONObject currentUserInfo = JwtUtil.getCurrentUserInfo();
|
|
|
+ Integer userId = null;
|
|
|
+ if (!ObjectUtils.isEmpty(currentUserInfo)) {
|
|
|
+ userId = currentUserInfo.getInteger("userId");
|
|
|
+ }
|
|
|
+ if (ObjectUtils.isEmpty(lifeGroupBuyMain.getId())) {
|
|
|
+ Integer count = lifeGroupBuyMainMapper.selectCount(new LambdaQueryWrapper<LifeGroupBuyMain>().like(LifeGroupBuyMain::getCreatedTime, DateUtils.formatDate(new Date(), "yyyy-MM-dd")).eq(LifeGroupBuyMain::getStoreId, lifeGroupBuyMain.getStoreId()));
|
|
|
+ lifeGroupBuyMain.setGroupNo("G" + DateUtils.formatDate(new Date(), "yyyyMMdd") + lifeGroupBuyMain.getStoreId() + org.apache.commons.lang3.StringUtils.leftPad(String.valueOf(count + 1), 5, "0"));
|
|
|
+ lifeGroupBuyMain.setCreatedUserId(userId);
|
|
|
+ lifeGroupBuyMainMapper.insert(lifeGroupBuyMain);
|
|
|
+ if (ObjectUtils.isNotEmpty(lifeGroupBuyThalis)) {
|
|
|
+ for (int i = 0; i < lifeGroupBuyThalis.size(); i++) {
|
|
|
+ LifeGroupBuyThali lifeGroupBuyThali = lifeGroupBuyThalis.get(i);
|
|
|
+ lifeGroupBuyThali.setParentId(lifeGroupBuyMain.getId().toString());
|
|
|
+ lifeGroupBuyThali.setDetailSort(i + 1);
|
|
|
+ lifeGroupBuyThali.setCreatedUserId(userId);
|
|
|
+ lifeGroupBuyThaliMapper.insert(lifeGroupBuyThali);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return true;
|
|
|
+ } else {
|
|
|
+ lifeGroupBuyMain.setUpdatedUserId(userId);
|
|
|
+ lifeGroupBuyMainMapper.updateById(lifeGroupBuyMain);
|
|
|
+ lifeGroupBuyThaliMapper.update(null, new LambdaUpdateWrapper<LifeGroupBuyThali>().eq(LifeGroupBuyThali::getParentId, lifeGroupBuyMain.getId()).set(LifeGroupBuyThali::getDeleteFlag, 1));
|
|
|
+ if (ObjectUtils.isNotEmpty(lifeGroupBuyThalis)) {
|
|
|
+ for (int i = 0; i < lifeGroupBuyThalis.size(); i++) {
|
|
|
+ LifeGroupBuyThali lifeGroupBuyThali = lifeGroupBuyThalis.get(i);
|
|
|
+ lifeGroupBuyThali.setParentId(lifeGroupBuyMain.getId().toString());
|
|
|
+ lifeGroupBuyThali.setDetailSort(i + 1);
|
|
|
+ lifeGroupBuyThali.setCreatedUserId(userId);
|
|
|
+ lifeGroupBuyThaliMapper.insert(lifeGroupBuyThali);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 保存团购并返回套餐信息
|
|
|
+ *
|
|
|
+ * @param lifeGroupBuyDto 团购数据
|
|
|
+ * @return 最新套餐记录
|
|
|
+ * @date 2025-11-11
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public LifeGroupBuyThali saveThali(LifeGroupBuyDto lifeGroupBuyDto) {
|
|
|
+ JSONObject currentUserInfo = JwtUtil.getCurrentUserInfo();
|
|
|
+ Integer userId = null;
|
|
|
+ if (!ObjectUtils.isEmpty(currentUserInfo)) {
|
|
|
+ userId = currentUserInfo.getInteger("userId");
|
|
|
+ }
|
|
|
+ LifeGroupBuyMain lifeGroupBuyMain = lifeGroupBuyDto.getLifeGroupBuyMain();
|
|
|
+ List<LifeGroupBuyThali> lifeGroupBuyThalis = lifeGroupBuyDto.getLifeGroupBuyThalis();
|
|
|
+ LifeGroupBuyThali lifeGroupBuyThali = null;
|
|
|
+ if (ObjectUtils.isEmpty(lifeGroupBuyMain.getId())) {
|
|
|
+ Integer count = lifeGroupBuyMainMapper.selectCount(new LambdaQueryWrapper<LifeGroupBuyMain>().like(LifeGroupBuyMain::getCreatedTime, DateUtils.formatDate(new Date(), "yyyy-MM-dd")).eq(LifeGroupBuyMain::getStoreId, lifeGroupBuyMain.getStoreId()));
|
|
|
+ lifeGroupBuyMain.setGroupNo("G" + DateUtils.formatDate(new Date(), "yyyyMMdd") + lifeGroupBuyMain.getStoreId() + org.apache.commons.lang3.StringUtils.leftPad(String.valueOf(count + 1), 5, "0"));
|
|
|
+ lifeGroupBuyMain.setCreatedUserId(userId);
|
|
|
+ lifeGroupBuyMain.setCreatedTime(new Date());
|
|
|
+ lifeGroupBuyMainMapper.insert(lifeGroupBuyMain);
|
|
|
+ if (ObjectUtils.isNotEmpty(lifeGroupBuyThalis)) {
|
|
|
+ for (int i = 0; i < lifeGroupBuyThalis.size(); i++) {
|
|
|
+ lifeGroupBuyThali = lifeGroupBuyThalis.get(i);
|
|
|
+ lifeGroupBuyThali.setParentId(lifeGroupBuyMain.getId().toString());
|
|
|
+ lifeGroupBuyThali.setDetailSort(i + 1);
|
|
|
+ lifeGroupBuyThali.setCreatedUserId(userId);
|
|
|
+ lifeGroupBuyThali.setCreatedTime(new Date());
|
|
|
+ lifeGroupBuyThaliMapper.insert(lifeGroupBuyThali);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return lifeGroupBuyThali;
|
|
|
+ } else {
|
|
|
+ lifeGroupBuyMain.setUpdatedUserId(userId);
|
|
|
+ lifeGroupBuyMain.setCreatedTime(new Date());
|
|
|
+ lifeGroupBuyMainMapper.updateById(lifeGroupBuyMain);
|
|
|
+ lifeGroupBuyThaliMapper.update(null, new LambdaUpdateWrapper<LifeGroupBuyThali>().eq(LifeGroupBuyThali::getParentId, lifeGroupBuyMain.getId()).set(LifeGroupBuyThali::getDeleteFlag, 1).set(LifeGroupBuyThali::getCreatedTime, new Date()));
|
|
|
+ if (ObjectUtils.isNotEmpty(lifeGroupBuyThalis)) {
|
|
|
+ for (int i = 0; i < lifeGroupBuyThalis.size(); i++) {
|
|
|
+ lifeGroupBuyThali = lifeGroupBuyThalis.get(i);
|
|
|
+ lifeGroupBuyThali.setParentId(lifeGroupBuyMain.getId().toString());
|
|
|
+ lifeGroupBuyThali.setDetailSort(i + 1);
|
|
|
+ lifeGroupBuyThali.setCreatedUserId(userId);
|
|
|
+ lifeGroupBuyThaliMapper.insert(lifeGroupBuyThali);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return lifeGroupBuyThali;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 查询团购套餐列表
|
|
|
+ *
|
|
|
+ * @param page 页码
|
|
|
+ * @param size 每页数量
|
|
|
+ * @param storeId 门店编号
|
|
|
+ * @param status 状态
|
|
|
+ * @param groupName 团购名称
|
|
|
+ * @param groupType 团购类型
|
|
|
+ * @return 套餐分页数据
|
|
|
+ * @date 2025-11-11
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public IPage<LifeGroupBuyThaliVo> getThaliList(int page, int size, String storeId, String status, String groupName, String groupType, String reviewType, String groupNo) {
|
|
|
+ QueryWrapper<LifeGroupBuyThaliVo> queryWrapper = new QueryWrapper<>();
|
|
|
+ queryWrapper.eq(StringUtils.isNotEmpty(storeId), "store_id", storeId);
|
|
|
+ if (StringUtils.isNotEmpty(reviewType)) {
|
|
|
+ switch (reviewType) {
|
|
|
+ case "0":
|
|
|
+ queryWrapper.eq("status", "1");
|
|
|
+ break;
|
|
|
+ case "1":
|
|
|
+ queryWrapper.in("status", Arrays.asList("2", "4", "5", "6", "7", "8"));
|
|
|
+ break;
|
|
|
+ case "2":
|
|
|
+ queryWrapper.eq("status", "3");
|
|
|
+ break;
|
|
|
+ default:
|
|
|
+ queryWrapper.eq(StringUtils.isNotEmpty(status), "status", status);
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ if ("8".equals(status)) {
|
|
|
+ queryWrapper.in(StringUtils.isNotEmpty(status), "status", Arrays.asList("2", "6"));
|
|
|
+ } else {
|
|
|
+ queryWrapper.eq(StringUtils.isNotEmpty(status), "status", status);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ queryWrapper.eq(StringUtils.isNotEmpty(groupType), "group_type", groupType);
|
|
|
+ queryWrapper.like(StringUtils.isNotEmpty(groupName), "group_name", groupName);
|
|
|
+ queryWrapper.like(StringUtils.isNotEmpty(groupNo), "group_no", groupNo);
|
|
|
+ queryWrapper.eq("delete_flag", 0);
|
|
|
+ queryWrapper.orderByDesc("created_time");
|
|
|
+ IPage<LifeGroupBuyThaliVo> lifeGroupBuyThaliVoIPage = new Page<>(page, size);
|
|
|
+ IPage<LifeGroupBuyThaliVo> voIPage = lifeGroupBuyMainMapper.selectPageByThaliVo(lifeGroupBuyThaliVoIPage, queryWrapper);
|
|
|
+ voIPage.getRecords().forEach(this::getMainImgAndDisableDate);
|
|
|
+ return voIPage;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 根据编号查询团购详情
|
|
|
+ *
|
|
|
+ * @param id 团购编号
|
|
|
+ * @param userId 用户编号
|
|
|
+ * @return 团购详情
|
|
|
+ * @date 2025-11-11
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public LifeGroupBuyThaliVo getThaliById(String id, String userId) {
|
|
|
+ LifeGroupBuyMain lifeGroupBuyMain = lifeGroupBuyMainMapper.selectById(id);
|
|
|
+ LifeGroupBuyThaliVo lifeGroupBuyThaliVo = new LifeGroupBuyThaliVo();
|
|
|
+ BeanUtils.copyProperties(lifeGroupBuyMain, lifeGroupBuyThaliVo);
|
|
|
+ List<LifeGroupBuyThali> lifeGroupBuyThalis = lifeGroupBuyThaliMapper.selectList(new LambdaQueryWrapper<LifeGroupBuyThali>().eq(LifeGroupBuyThali::getParentId, id).eq(LifeGroupBuyThali::getDeleteFlag, 0));
|
|
|
+
|
|
|
+ // 是否收藏了该团购
|
|
|
+ LifeCollect lifeCollect = lifeCollectMapper.selectOne(new QueryWrapper<LifeCollect>().eq("user_id", userId).eq("coupon_id", id));
|
|
|
+ lifeGroupBuyThaliVo.setIsCollect("0");
|
|
|
+ if (!Objects.isNull(lifeCollect)) {
|
|
|
+ lifeGroupBuyThaliVo.setIsCollect("1");
|
|
|
+ }
|
|
|
+ //美食
|
|
|
+ if (lifeGroupBuyMain.getGroupType() == 1) {
|
|
|
+ for (LifeGroupBuyThali lifeGroupBuyThali : lifeGroupBuyThalis) {
|
|
|
+ if (StringUtils.isNotEmpty(lifeGroupBuyThali.getDetailId())) {
|
|
|
+ StoreMenuVo menuInfo = storeMenuMapper.getMenuInfo(Integer.parseInt(lifeGroupBuyThali.getDetailId()));
|
|
|
+ if (ObjectUtils.isNotEmpty(menuInfo)) {
|
|
|
+ lifeGroupBuyThali.setDishName(menuInfo.getDishName());
|
|
|
+ lifeGroupBuyThali.setDishImg(menuInfo.getImgUrl());
|
|
|
+ lifeGroupBuyThali.setDishPrice(menuInfo.getDishPrice().toString());
|
|
|
+ lifeGroupBuyThali.setDishesUnit(menuInfo.getDishesUnit());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ Map<String, List<LifeGroupBuyThali>> collect = lifeGroupBuyThalis.stream().collect(Collectors.groupingBy(LifeGroupBuyThali::getGroupName));
|
|
|
+ List<LifeGroupBuyNameThaliVo> resultMap = new ArrayList<>();
|
|
|
+ List<String> keys = collect.entrySet().stream().sorted(Comparator.comparingInt(i -> i.getValue().get(0).getDetailSort())).map(Map.Entry::getKey).collect(Collectors.toList());
|
|
|
+ for (String key : keys) {
|
|
|
+ LifeGroupBuyNameThaliVo lifeGroupBuyNameThaliVo = new LifeGroupBuyNameThaliVo();
|
|
|
+ lifeGroupBuyNameThaliVo.setGroupName(key);
|
|
|
+ lifeGroupBuyNameThaliVo.setDetails(collect.get(key).stream().sorted(Comparator.comparingInt(LifeGroupBuyThali::getDetailSort)).collect(Collectors.toList()));
|
|
|
+ resultMap.add(lifeGroupBuyNameThaliVo);
|
|
|
+ }
|
|
|
+ lifeGroupBuyThaliVo.setDetails(resultMap);
|
|
|
+ getMainImgAndDisableDate(lifeGroupBuyThaliVo);
|
|
|
+
|
|
|
+ //已售数量
|
|
|
+ lifeGroupBuyThaliVo.setSaleNum(lifeUserOrderMapper.countBuyGroup(id));
|
|
|
+
|
|
|
+ return lifeGroupBuyThaliVo;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 更新团购状态
|
|
|
+ *
|
|
|
+ * @param id 团购编号
|
|
|
+ * @param status 状态值
|
|
|
+ * @param approvalComments 审核意见
|
|
|
+ * @return 是否更新成功
|
|
|
+ * @date 2025-11-11
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public boolean updateStatus(String id, String status, String approvalComments) {
|
|
|
+ LambdaUpdateWrapper<LifeGroupBuyMain> lambdaUpdateWrapper = new LambdaUpdateWrapper<>();
|
|
|
+ lambdaUpdateWrapper.eq(LifeGroupBuyMain::getId, id);
|
|
|
+ lambdaUpdateWrapper.set(LifeGroupBuyMain::getStatus, status);
|
|
|
+ lambdaUpdateWrapper.set(LifeGroupBuyMain::getApprovalComments, approvalComments);
|
|
|
+ if(status.equals("5")){
|
|
|
+ LifeGroupBuyMain lifeGroupBuyMain = lifeGroupBuyMainMapper.selectById(id);
|
|
|
+ if(lifeGroupBuyMain !=null && lifeGroupBuyMain.getStatus()==2){
|
|
|
+ lambdaUpdateWrapper.set(LifeGroupBuyMain::getStartTimeValue, new Date());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ lifeGroupBuyMainMapper.update(null,lambdaUpdateWrapper);
|
|
|
+ //处理中台审核记录
|
|
|
+ if (StringUtils.isNotEmpty(id) && StringUtils.isNotEmpty(status) && (status.equals("2") || status.equals("3"))) {
|
|
|
+ LambdaUpdateWrapper<WebAudit> wrapper = new LambdaUpdateWrapper<>();
|
|
|
+ wrapper.eq(WebAudit::getLifeGroupPackageId, id);
|
|
|
+ wrapper.set(WebAudit::getStatus, "1");
|
|
|
+ webAuditMapper.update(null, wrapper);
|
|
|
+ }
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 删除团购
|
|
|
+ *
|
|
|
+ * @param id 团购编号
|
|
|
+ * @param groupType 团购类型
|
|
|
+ * @return 是否删除成功
|
|
|
+ * @date 2025-11-11
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public boolean delThaliById(String id, String groupType) {
|
|
|
+ if ("1".equals(groupType)) {
|
|
|
+ lifeGroupBuyThaliMapper.update(null, new LambdaUpdateWrapper<LifeGroupBuyThali>().eq(LifeGroupBuyThali::getParentId, id).set(LifeGroupBuyThali::getDeleteFlag, 1));
|
|
|
+ }
|
|
|
+ lifeGroupBuyMainMapper.update(null, new LambdaUpdateWrapper<LifeGroupBuyMain>().eq(LifeGroupBuyMain::getId, id).set(LifeGroupBuyMain::getDeleteFlag, 1));
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 更新团购库存
|
|
|
+ *
|
|
|
+ * @param id 团购编号
|
|
|
+ * @param num 库存数量
|
|
|
+ * @return 是否更新成功
|
|
|
+ * @date 2025-11-11
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public boolean updateNum(String id, String num) {
|
|
|
+ //判断库存数为0 增加库存数修改状态为进行中
|
|
|
+ LambdaQueryWrapper<LifeGroupBuyMain> lambdaQueryWrapper = new LambdaQueryWrapper<>();
|
|
|
+ lambdaQueryWrapper.eq(LifeGroupBuyMain :: getId, id);
|
|
|
+ LifeGroupBuyMain lifeGroupBuyMain = lifeGroupBuyMainMapper.selectOne(lambdaQueryWrapper);
|
|
|
+
|
|
|
+ if(lifeGroupBuyMain.getInventoryNum() == 0){
|
|
|
+ LambdaUpdateWrapper<LifeGroupBuyMain> lambdaUpdateWrapper = new LambdaUpdateWrapper<>();
|
|
|
+ lambdaUpdateWrapper.eq(LifeGroupBuyMain :: getId, id);
|
|
|
+ lambdaUpdateWrapper.set(LifeGroupBuyMain :: getStatus, 5);
|
|
|
+ lambdaUpdateWrapper.set(LifeGroupBuyMain :: getInventoryNum, num);
|
|
|
+ lifeGroupBuyMainMapper.update(null, lambdaUpdateWrapper);
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ LambdaUpdateWrapper<LifeGroupBuyMain> lambdaUpdateWrapper = new LambdaUpdateWrapper<>();
|
|
|
+ lambdaUpdateWrapper.eq(LifeGroupBuyMain::getId, id);
|
|
|
+ lambdaUpdateWrapper.set(LifeGroupBuyMain::getInventoryNum, num);
|
|
|
+ lifeGroupBuyMainMapper.update(null, lambdaUpdateWrapper);
|
|
|
+ }
|
|
|
+
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 填充主图与不可用日期信息
|
|
|
+ *
|
|
|
+ * @param record 团购套餐数据
|
|
|
+ * @date 2025-11-11
|
|
|
+ */
|
|
|
+ private void getMainImgAndDisableDate(LifeGroupBuyThaliVo record) {
|
|
|
+ //图片
|
|
|
+ if (StringUtils.isNotEmpty(record.getImageId())) {
|
|
|
+ List<String> imgIds = Arrays.asList(record.getImageId().split(","));
|
|
|
+ List<StoreImg> storeImgs = storeImgMapper.selectList(new LambdaQueryWrapper<StoreImg>().in(StoreImg::getId, imgIds));
|
|
|
+ if (ObjectUtils.isNotEmpty(storeImgs)) {
|
|
|
+ /*String imgs = storeImgs.stream()
|
|
|
+ .map(StoreImg::getImgUrl)
|
|
|
+ .collect(Collectors.joining("*"));
|
|
|
+ record.setImageValueStr(imgs);*/
|
|
|
+ record.setImageValueStr(storeImgs.stream().map(StoreImg::getImgUrl).collect(Collectors.toList()));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //不可用日期
|
|
|
+ if (ObjectUtils.isNotEmpty(record.getDisableDateType())) {
|
|
|
+ if (record.getDisableDateType() == 1) {
|
|
|
+ List<String> valueList = Arrays.asList(record.getDisableDateValue().split(";"));
|
|
|
+ String holiday = "";
|
|
|
+ if (valueList.size() > 1) {
|
|
|
+ List<String> list = Arrays.asList(valueList.get(1).split(","));
|
|
|
+ List<EssentialHolidayComparison> essentialHolidayComparisons = essentialHolidayComparisonMapper.selectList(new LambdaQueryWrapper<EssentialHolidayComparison>().in(EssentialHolidayComparison::getId, list));
|
|
|
+ holiday = essentialHolidayComparisons.stream().map(EssentialHolidayComparison::getFestivalName).collect(Collectors.joining(","));
|
|
|
+ }
|
|
|
+ if (StringUtils.isNotEmpty(valueList.get(0)) && StringUtils.isNotEmpty(holiday)) {
|
|
|
+ record.setDisableDateValueStr(valueList.get(0) + ";" + holiday);
|
|
|
+ }
|
|
|
+ if (StringUtils.isEmpty(valueList.get(0))) {
|
|
|
+ record.setDisableDateValueStr(holiday);
|
|
|
+ }
|
|
|
+ if (StringUtils.isEmpty(holiday)) {
|
|
|
+ record.setDisableDateValueStr(valueList.get(0));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ //已售数量
|
|
|
+ record.setSaleNum(lifeUserOrderMapper.countBuyGroup(record.getId().toString()));
|
|
|
+
|
|
|
+ BigDecimal costPrice = lifeGroupBuyMainPlantformMapper.selectSumCostPrice(record.getId());
|
|
|
+ if (ObjectUtils.isEmpty(costPrice)) {
|
|
|
+ costPrice = BigDecimal.ZERO;;
|
|
|
+ }
|
|
|
+ record.setCostPrice(costPrice);
|
|
|
+
|
|
|
+ if (ObjectUtils.isNotEmpty(record.getPreferentialPrice())) {
|
|
|
+ record.setProfit(record.getPreferentialPrice().subtract(costPrice));
|
|
|
+ }
|
|
|
+
|
|
|
+ if (record.getStatus() == 1) {
|
|
|
+ record.setReviewType("待审核");
|
|
|
+ } else if (record.getStatus() == 2 || record.getStatus() == 4 || record.getStatus() == 5 || record.getStatus() == 6 || record.getStatus() == 7 ) {
|
|
|
+ record.setReviewType("审核通过");
|
|
|
+ } else if (record.getStatus() == 3) {
|
|
|
+ record.setReviewType("审核拒绝");
|
|
|
+
|
|
|
+ if (Objects.nonNull(record.getStatus())) {
|
|
|
+ switch (record.getStatus()) {
|
|
|
+ case 0:
|
|
|
+ record.setStatusName("草稿");
|
|
|
+ break;
|
|
|
+ case 1:
|
|
|
+ record.setStatusName("待审核");
|
|
|
+ break;
|
|
|
+ case 2:
|
|
|
+ record.setStatusName("未开始");
|
|
|
+ break;
|
|
|
+ case 3:
|
|
|
+ record.setStatusName("审核拒绝");
|
|
|
+ break;
|
|
|
+ case 4:
|
|
|
+ record.setStatusName("已售罄");
|
|
|
+ break;
|
|
|
+ case 5:
|
|
|
+ record.setStatusName("进行中");
|
|
|
+ break;
|
|
|
+ case 6:
|
|
|
+ record.setStatusName("已下架");
|
|
|
+ break;
|
|
|
+ case 7:
|
|
|
+ record.setStatusName("已结束");
|
|
|
+ break;
|
|
|
+ default:
|
|
|
+ record.setStatusName("未知状态");
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+}
|