|
@@ -5,26 +5,28 @@ import cn.hutool.core.util.ObjectUtil;
|
|
|
import cn.hutool.core.util.StrUtil;
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
|
|
|
+import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
|
|
|
import com.github.pagehelper.PageHelper;
|
|
|
import com.github.pagehelper.PageInfo;
|
|
|
-import com.txz.mall.constants.Constants;
|
|
|
import com.txz.mall.core.AbstractService;
|
|
|
import com.txz.mall.core.ServiceException;
|
|
|
import com.txz.mall.dubbo.client.CifUserDubboServiceClient;
|
|
|
-import com.txz.mall.model.*;
|
|
|
+import com.txz.mall.model.StoreCombination;
|
|
|
+import com.txz.mall.model.StoreFlashActivity;
|
|
|
+import com.txz.mall.model.StorePink;
|
|
|
+import com.txz.mall.model.StoreProduct;
|
|
|
import com.txz.mall.service.*;
|
|
|
+import dto.GoPinkDTO;
|
|
|
import lombok.AllArgsConstructor;
|
|
|
import org.springframework.beans.BeanUtils;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
import tk.mybatis.mapper.entity.Condition;
|
|
|
import tk.mybatis.mapper.entity.Example;
|
|
|
-import vo.*;
|
|
|
+import vo.ActivityProductVO;
|
|
|
+import vo.FlashActivityVO;
|
|
|
|
|
|
-import java.util.Date;
|
|
|
-import java.util.HashSet;
|
|
|
-import java.util.List;
|
|
|
-import java.util.Set;
|
|
|
+import java.util.*;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
|
|
@@ -128,150 +130,98 @@ public class StoreCombinationServiceImpl extends AbstractService<StoreCombinatio
|
|
|
|
|
|
|
|
|
@Override
|
|
|
- public GoPinkResponse goPink(Long pinkId) {
|
|
|
- //判断拼团是否完成
|
|
|
- int isOk = 0;
|
|
|
- //判断当前用户是否在团内 0未在 1在
|
|
|
- int userBool = 0;
|
|
|
- //判断拼团是否成功 0未成功 1成功
|
|
|
- int pinkBool = 0;
|
|
|
+ public void goPink(GoPinkDTO dto) {
|
|
|
Date date = new Date();
|
|
|
-
|
|
|
- StorePink teamPink = storePinkService.findById(pinkId);
|
|
|
- if (ObjectUtil.isNull(teamPink) || teamPink.getIsRefund().equals(1)) {
|
|
|
- throw new ServiceException("对应的拼团不存在");
|
|
|
- }
|
|
|
- StoreCombination storeCombination = findById(teamPink.getCid());
|
|
|
- if (ObjectUtil.isNull(storeCombination) || storeCombination.getIsDelete().equals(1)) {
|
|
|
- throw new ServiceException("对应拼团商品不存在");
|
|
|
+ if (dto.getPinkId() == null && dto.getCid() != null) {
|
|
|
+ automaticMatch(dto);
|
|
|
}
|
|
|
+ if (dto.getPinkId() != null) {
|
|
|
+ StorePink teamPink = storePinkService.findById(dto.getPinkId());
|
|
|
+ if (ObjectUtil.isNull(teamPink) || teamPink.getIsRefund().equals(1)) {
|
|
|
+ throw new ServiceException("对应的拼团不存在");
|
|
|
+ }
|
|
|
+ Condition condition = new Condition(StoreCombination.class);
|
|
|
+ Example.Criteria criteria = condition.createCriteria();
|
|
|
+ criteria.andEqualTo("isDelete", 0);
|
|
|
+ criteria.andEqualTo("isShow", 1);
|
|
|
+ criteria.andLessThanOrEqualTo("startTime", date);
|
|
|
+ criteria.andGreaterThanOrEqualTo("stopTime", date);
|
|
|
+ List<StoreCombination> combinationList = findByCondition(condition);
|
|
|
+ if (CollUtil.isEmpty(combinationList)) {
|
|
|
+ throw new ServiceException("拼团商品不存在或未开启");
|
|
|
+ }
|
|
|
|
|
|
- // 判断拼团活动时效
|
|
|
- if (storeCombination.getIsShow().equals(0)) {
|
|
|
- throw new ServiceException("拼团活动已结束");
|
|
|
- }
|
|
|
- if (date.after(storeCombination.getStopTime())) {
|
|
|
- throw new ServiceException("拼团活动已结束");
|
|
|
- }
|
|
|
-//
|
|
|
-// User user = userService.getInfo();
|
|
|
-//
|
|
|
- GoPinkResponse goPinkResponse = new GoPinkResponse();
|
|
|
- List<StorePink> pinkList;
|
|
|
- if (teamPink.getKId().equals(0L)) {
|
|
|
- pinkList = storePinkService.getListByCidAndKid(teamPink.getCid(), teamPink.getId());
|
|
|
- pinkList.add(teamPink);
|
|
|
- } else {
|
|
|
- // 名额占用的问题 (支付成功的才算1个)
|
|
|
- pinkList = storePinkService.getListByCidAndKid(teamPink.getCid(), teamPink.getKId());
|
|
|
- pinkList.add(storePinkService.findById(teamPink.getKId()));
|
|
|
- }
|
|
|
- //拼团剩余人数
|
|
|
- int count = teamPink.getPeople() - (CollUtil.isEmpty(pinkList) ? 0 : pinkList.size());
|
|
|
+ Condition pinkCondition = new Condition(StorePink.class);
|
|
|
+ Example.Criteria pinkCriteria = pinkCondition.createCriteria();
|
|
|
+ pinkCriteria.andEqualTo("isDelete", 0);
|
|
|
+ pinkCriteria.andEqualTo("kId", dto.getPinkId());
|
|
|
+ pinkCriteria.andEqualTo("status", 1);
|
|
|
+ List<StorePink> pinkList = storePinkService.findByCondition(pinkCondition);
|
|
|
|
|
|
- if (teamPink.getStatus() == 2) {
|
|
|
- //已完成
|
|
|
- isOk = 1;
|
|
|
- pinkBool = 1;
|
|
|
- }
|
|
|
- if (teamPink.getStatus() == 1) {
|
|
|
- //进行中
|
|
|
+ //拼团剩余人数
|
|
|
+ int count = teamPink.getPeople() - (CollUtil.isEmpty(pinkList) ? 0 : pinkList.size());
|
|
|
if (count < 1) {
|
|
|
- // 拼团已完成
|
|
|
- isOk = 1;
|
|
|
- pinkBool = 1;
|
|
|
- // 拼团完成处理
|
|
|
+ throw new ServiceException("拼团已满");
|
|
|
+ }
|
|
|
+ List<Long> uidList = pinkList.stream().map(StorePink::getUid).collect(Collectors.toList());
|
|
|
+ if (uidList.contains(dto.getUserId())) {
|
|
|
+ throw new ServiceException("您已加入该拼团");
|
|
|
+ }
|
|
|
+ // 加入拼团
|
|
|
+ StorePink storePink = new StorePink();
|
|
|
+ BeanUtils.copyProperties(teamPink, storePink);
|
|
|
+ storePink.setId(null);
|
|
|
+// storePink.setOrderId(null);
|
|
|
+ storePink.setOrderIdKey(null);
|
|
|
+ storePink.setUid(dto.getUserId());
|
|
|
+ storePink.setKId(1L);
|
|
|
+ storePink.setCreateTime(date);
|
|
|
+ storePinkService.save(storePink);
|
|
|
+ if (count == 1) {
|
|
|
storePinkService.pinkSuccess(teamPink.getId());
|
|
|
}
|
|
|
}
|
|
|
+ }
|
|
|
|
|
|
- List<Long> uidList = pinkList.stream().map(StorePink::getUid).collect(Collectors.toList());
|
|
|
- uidList.add(teamPink.getUid());
|
|
|
-// if (uidList.contains(user.getUid())) {
|
|
|
-// userBool = 1;
|
|
|
-// throw new ServiceException("您已加入该拼团");
|
|
|
-// }
|
|
|
-//
|
|
|
-// // 处理用户头像昵称
|
|
|
- List<StorePinkVO> pinkResponseList = CollUtil.newArrayList();
|
|
|
- // 团长
|
|
|
- StorePinkVO storePinkTResponse = new StorePinkVO();
|
|
|
- for (StorePink pink : pinkList) {
|
|
|
- if (pink.getKId().equals(0)) {
|
|
|
- BeanUtils.copyProperties(pink, storePinkTResponse);
|
|
|
-// if (pink.getUid().equals(user.getUid())) {
|
|
|
-// storePinkTResponse.setNickname(user.getNickname());
|
|
|
-// storePinkTResponse.setAvatar(user.getAvatar());
|
|
|
-// } else {
|
|
|
-// User teamUser = userService.getById(pink.getUid());
|
|
|
-// storePinkTResponse.setNickname(teamUser.getNickname());
|
|
|
-// storePinkTResponse.setAvatar(teamUser.getAvatar());
|
|
|
-// }
|
|
|
- continue;
|
|
|
- }
|
|
|
- StorePinkVO storePinkResponse = new StorePinkVO();
|
|
|
- BeanUtils.copyProperties(pink, storePinkResponse);
|
|
|
-// User userOne = userService.getById(pink.getUid());
|
|
|
-// storePinkResponse.setNickname(userOne.getNickname());
|
|
|
-// storePinkResponse.setAvatar(userOne.getAvatar());
|
|
|
- pinkResponseList.add(storePinkResponse);
|
|
|
+ /**
|
|
|
+ * 自动匹配
|
|
|
+ */
|
|
|
+ private void automaticMatch(GoPinkDTO dto) {
|
|
|
+ // 找一个最快能成团的
|
|
|
+ Date date = new Date();
|
|
|
+ StoreCombination storeCombination = findById(dto.getCid());
|
|
|
+ if (ObjectUtil.isNull(storeCombination) || storeCombination.getIsDelete().equals(1)) {
|
|
|
+ throw new ServiceException("对应拼团商品不存在");
|
|
|
}
|
|
|
-
|
|
|
- goPinkResponse.setCount(count);
|
|
|
- goPinkResponse.setIsOk(isOk);
|
|
|
- goPinkResponse.setPinkBool(pinkBool);
|
|
|
- goPinkResponse.setUserBool(userBool);
|
|
|
- if (userBool == 1) {
|
|
|
-// pinkList.forEach(e -> {
|
|
|
-// if (e.getUid().equals(user.getUid())) {
|
|
|
-// goPinkResponse.setCurrentPinkOrder(e.getOrderId());
|
|
|
-// }
|
|
|
-// });
|
|
|
+ Condition pinkCondition = new Condition(StorePink.class);
|
|
|
+ Example.Criteria pinkCriteria = pinkCondition.createCriteria();
|
|
|
+ pinkCriteria.andEqualTo("isDelete", 0);
|
|
|
+ pinkCriteria.andEqualTo("cid", dto.getCid());
|
|
|
+ pinkCriteria.andEqualTo("status", 1);
|
|
|
+ List<StorePink> pinkList = storePinkService.findByCondition(pinkCondition);
|
|
|
+ Map<String, List<StorePink>> collect = pinkList.stream().collect(Collectors.groupingBy(StorePink::getOrderId));
|
|
|
+ // 找出最多value对应的key
|
|
|
+ List<StorePink> maxPinkList = collect.values().stream()
|
|
|
+ .max(Comparator.comparing(List::size))
|
|
|
+ .orElse(Collections.emptyList());
|
|
|
+ if (CollectionUtils.isNotEmpty(maxPinkList)) {
|
|
|
+ StorePink pink = maxPinkList.stream().filter(i -> i.getKId().equals(0L)).collect(Collectors.toList()).get(0);
|
|
|
+ int count = pink.getPeople() - (CollUtil.isEmpty(pinkList) ? 0 : pinkList.size());
|
|
|
+ if (count > 0) {
|
|
|
+ StorePink storePink = new StorePink();
|
|
|
+ BeanUtils.copyProperties(pink, storePink);
|
|
|
+ storePink.setId(null);
|
|
|
+// storePink.setOrderId(null);
|
|
|
+ storePink.setOrderIdKey(null);
|
|
|
+ storePink.setUid(dto.getUserId());
|
|
|
+ storePink.setKId(1L);
|
|
|
+ storePink.setCreateTime(date);
|
|
|
+ storePinkService.save(storePink);
|
|
|
+ if (count == 1) {
|
|
|
+ storePinkService.pinkSuccess(pink.getId());
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
- goPinkResponse.setPinkAll(pinkResponseList);
|
|
|
- goPinkResponse.setPinkT(storePinkTResponse);
|
|
|
-// goPinkResponse.setUserInfo(user);
|
|
|
-
|
|
|
- // storeCombination部分
|
|
|
- StoreCombinationVO detailResponse = new StoreCombinationVO();
|
|
|
- BeanUtils.copyProperties(storeCombination, detailResponse);
|
|
|
- detailResponse.setSpecType(false);
|
|
|
- // sku部分
|
|
|
- ProductAttr spavAttr = new ProductAttr();
|
|
|
- spavAttr.setProductId(storeCombination.getId());
|
|
|
- spavAttr.setType(Constants.PRODUCT_TYPE_PINGTUAN);
|
|
|
-// List<ProductAttr> attrList = productAttrService.getByEntity(spavAttr);
|
|
|
-// List<HashMap<String, Object>> skuAttrList = getSkuAttrList(attrList);
|
|
|
-// detailResponse.setProductAttr(skuAttrList);
|
|
|
-// if (CollUtil.isNotEmpty(attrList) && attrList.size() > 1) {
|
|
|
-// detailResponse.setSpecType(true);
|
|
|
-// }
|
|
|
-// // 单属性时讲attrValueId 赋值给外层方便前端使用
|
|
|
-// if (!detailResponse.getSpecType()) {
|
|
|
-// detailResponse.setAloneAttrValueId(attrList.get(0).getId());
|
|
|
-// }
|
|
|
-//
|
|
|
-//
|
|
|
-// ProductAttrValue spavValue = new ProductAttrValue();
|
|
|
-// spavValue.setProductId(storeCombination.getId());
|
|
|
-// spavValue.setType(Constants.PRODUCT_TYPE_PINGTUAN);
|
|
|
-// List<ProductAttrValue> valueList = productAttrValueService.getByEntity(spavValue);
|
|
|
-// // H5 端用于生成skuList
|
|
|
-// List<StoreProductAttrValueVO> sPAVResponses = new ArrayList<>();
|
|
|
-// for (ProductAttrValue storeProductAttrValue : valueList) {
|
|
|
-// StoreProductAttrValueVO atr = new StoreProductAttrValueVO();
|
|
|
-// BeanUtils.copyProperties(storeProductAttrValue, atr);
|
|
|
-// sPAVResponses.add(atr);
|
|
|
-// }
|
|
|
-// HashMap<String, Object> skuMap = new HashMap<>();
|
|
|
-// for (StoreProductAttrValueVO attrValue : sPAVResponses) {
|
|
|
-// skuMap.put(attrValue.getSuk(), attrValue);
|
|
|
-// }
|
|
|
-//
|
|
|
-// detailResponse.setProductValue(skuMap);
|
|
|
-// goPinkResponse.setStoreCombination(detailResponse);
|
|
|
-// return goPinkResponse;
|
|
|
- return null;
|
|
|
}
|
|
|
|
|
|
@Override
|