|
@@ -142,11 +142,9 @@ public class StoreOrderServiceImpl extends AbstractService<StoreOrder> implement
|
|
|
Condition pinkCondition = new Condition(StorePink.class);
|
|
|
Example.Criteria pinkCriteria = pinkCondition.createCriteria();
|
|
|
pinkCriteria.andEqualTo("isDelete", 0);
|
|
|
- pinkCriteria.andEqualTo("kId", dto.getPinkId());
|
|
|
+ pinkCriteria.andEqualTo("orderId", dto.getOrderId());
|
|
|
pinkCriteria.andEqualTo("status", 1);
|
|
|
List<StorePink> pinkList = storePinkService.findByCondition(pinkCondition);
|
|
|
-
|
|
|
- //拼团剩余人数
|
|
|
int count = teamPink.getPeople() - (CollUtil.isEmpty(pinkList) ? 0 : pinkList.size());
|
|
|
if (count < 1) {
|
|
|
throw new ServiceException("拼团已满");
|
|
@@ -155,19 +153,28 @@ public class StoreOrderServiceImpl extends AbstractService<StoreOrder> implement
|
|
|
if (uidList.contains(dto.getUserId())) {
|
|
|
throw new ServiceException("您已加入该拼团");
|
|
|
}
|
|
|
- // 加入拼团
|
|
|
- StorePink storePink = new StorePink();
|
|
|
- BeanUtils.copyProperties(teamPink, storePink);
|
|
|
- storePink.setId(null);
|
|
|
+ joinGroup(teamPink, dto, count);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private void joinGroup(StorePink teamPink, GoPinkDTO dto, int count) {
|
|
|
+ //拼团剩余人数
|
|
|
+ Date date = new Date();
|
|
|
+ // 加入拼团
|
|
|
+ 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());
|
|
|
- }
|
|
|
+// storePink.setOrderIdKey(null);
|
|
|
+ storePink.setUid(dto.getUserId());
|
|
|
+ storePink.setIsRefund(0);
|
|
|
+ storePink.setKId(1L);
|
|
|
+// storePink.setAvatar();
|
|
|
+// storePink.setNickname();
|
|
|
+ storePink.setCreateTime(date);
|
|
|
+ storePinkService.save(storePink);
|
|
|
+ if (count == 1) {
|
|
|
+ storePinkService.pinkSuccess(teamPink.getId());
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -176,7 +183,6 @@ public class StoreOrderServiceImpl extends AbstractService<StoreOrder> implement
|
|
|
*/
|
|
|
private void automaticMatch(GoPinkDTO dto) {
|
|
|
// 找一个最快能成团的
|
|
|
- Date date = new Date();
|
|
|
StoreCombination storeCombination = storeCombinationService.findById(dto.getCid());
|
|
|
if (ObjectUtil.isNull(storeCombination) || storeCombination.getIsDelete().equals(1)) {
|
|
|
throw new ServiceException("对应拼团商品不存在");
|
|
@@ -187,26 +193,31 @@ public class StoreOrderServiceImpl extends AbstractService<StoreOrder> implement
|
|
|
pinkCriteria.andEqualTo("cid", dto.getCid());
|
|
|
pinkCriteria.andEqualTo("status", 1);
|
|
|
List<StorePink> pinkList = storePinkService.findByCondition(pinkCondition);
|
|
|
+
|
|
|
+ if (CollUtil.isEmpty(pinkList)) {
|
|
|
+ throw new ServiceException("暂时没有可加入的团");
|
|
|
+ }
|
|
|
Map<String, List<StorePink>> collect = pinkList.stream().collect(Collectors.groupingBy(StorePink::getOrderId));
|
|
|
+
|
|
|
+ List<List<StorePink>> availableGroups = collect.values().stream()
|
|
|
+ .filter(list -> !list.stream().map(StorePink::getUid).collect(Collectors.toList()).contains(dto.getUserId()))
|
|
|
+ .collect(Collectors.toList());
|
|
|
+
|
|
|
+ // 如果没有用户未参与的拼团,直接返回,让调用方处理创建新团的逻辑
|
|
|
+ if (CollUtil.isEmpty(availableGroups)) {
|
|
|
+ throw new ServiceException("所有团的均已参加");
|
|
|
+ }
|
|
|
// 找出最多value对应的key
|
|
|
- List<StorePink> maxPinkList = collect.values().stream()
|
|
|
+ List<StorePink> maxPinkList = availableGroups.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());
|
|
|
+ List<Long> uidList = maxPinkList.stream().map(StorePink::getUid).collect(Collectors.toList());
|
|
|
+ if (!uidList.contains(dto.getUserId())) {
|
|
|
+ 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) {
|
|
|
+ joinGroup(pink, dto, count);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
@@ -1144,8 +1155,8 @@ public class StoreOrderServiceImpl extends AbstractService<StoreOrder> implement
|
|
|
//
|
|
|
// StoreOrder storeOrder = findById(orderId);
|
|
|
// if (storeOrder.getPaid() == 1) {
|
|
|
- goOpen(orderId);
|
|
|
- return true;
|
|
|
+ goOpen(orderId);
|
|
|
+ return true;
|
|
|
// } else {
|
|
|
// return false;
|
|
|
// }
|