Commit 66882c4e by wuwenlong

order pack check dev;

parent 18424b91
......@@ -164,4 +164,11 @@ public interface ISOrderService extends IService<SOrder>
* @return
*/
boolean autoRefund(OrderRefundRequest request);
/**
* 通过用户ID查询已支付未退款的订单
* @param userId
* @return
*/
List<SOrder> payedUnrefundListByUserId(Long userId);
}
package share.system.service.impl;
import java.util.ArrayList;
import java.util.List;
import java.util.*;
import java.util.stream.Collectors;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.apache.commons.collections4.CollectionUtils;
import share.common.enums.YesNoEnum;
import share.common.utils.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import share.system.domain.SConsumer;
import share.system.domain.SOrder;
import share.system.mapper.PackMapper;
import share.system.domain.SPack;
import share.system.service.IPackService;
import share.system.service.ISOrderService;
import share.system.service.SConsumerService;
/**
* 套餐Service业务层处理
......@@ -21,7 +27,10 @@ import share.system.service.IPackService;
@Service
public class PackServiceImpl extends ServiceImpl<PackMapper, SPack> implements IPackService {
@Autowired
private PackMapper packMapper;
private SConsumerService consumerService;
@Autowired
private ISOrderService orderService;
/**
* 查询套餐
......@@ -31,7 +40,7 @@ public class PackServiceImpl extends ServiceImpl<PackMapper, SPack> implements I
*/
@Override
public SPack selectPackById(Long id) {
return packMapper.selectPackById(id);
return baseMapper.selectPackById(id);
}
/**
......@@ -42,7 +51,20 @@ public class PackServiceImpl extends ServiceImpl<PackMapper, SPack> implements I
*/
@Override
public List<SPack> selectPackList(SPack SPack) {
return packMapper.selectPackList(SPack);
List<SPack> packList = baseMapper.selectPackList(SPack);
SConsumer user = consumerService.getInfo();
List<SOrder> orderList = new ArrayList<>();
if(Objects.nonNull(user)&&Objects.nonNull(user.getId())){
orderList = orderService.payedUnrefundListByUserId(user.getId());
}
List<SOrder> finalOrderList = orderList;
return Optional.ofNullable(packList).orElse(new ArrayList<>()).stream().filter(pack -> {
if(YesNoEnum.yes.getIndex().compareTo(pack.getFirstOrderAvailable())==0
&& CollectionUtils.isNotEmpty(finalOrderList)){
return false;
}
return true;
}).collect(Collectors.toList());
}
/**
......@@ -54,7 +76,7 @@ public class PackServiceImpl extends ServiceImpl<PackMapper, SPack> implements I
@Override
public int insertPack(SPack sPack) {
sPack.setCreateTime(DateUtils.getNowDate());
return packMapper.insertPack(sPack);
return baseMapper.insertPack(sPack);
}
/**
......@@ -66,7 +88,7 @@ public class PackServiceImpl extends ServiceImpl<PackMapper, SPack> implements I
@Override
public int updatePack(SPack SPack) {
SPack.setUpdateTime(DateUtils.getNowDate());
return packMapper.updatePack(SPack);
return baseMapper.updatePack(SPack);
}
/**
......@@ -77,7 +99,7 @@ public class PackServiceImpl extends ServiceImpl<PackMapper, SPack> implements I
*/
@Override
public int deletePackByIds(Long[] ids) {
return packMapper.deletePackByIds(ids);
return baseMapper.deletePackByIds(ids);
}
/**
......@@ -88,7 +110,7 @@ public class PackServiceImpl extends ServiceImpl<PackMapper, SPack> implements I
*/
@Override
public int deletePackById(Long id) {
return packMapper.deletePackById(id);
return baseMapper.deletePackById(id);
}
@Override
......@@ -98,13 +120,26 @@ public class PackServiceImpl extends ServiceImpl<PackMapper, SPack> implements I
}
LambdaQueryWrapper<SPack> queryWrapper = new LambdaQueryWrapper();
queryWrapper.in(SPack::getId, packIds);
return packMapper.selectList(queryWrapper);
List<SPack> packList = baseMapper.selectList(queryWrapper);
SConsumer user = consumerService.getInfo();
List<SOrder> orderList = new ArrayList<>();
if(Objects.nonNull(user)&&Objects.nonNull(user.getId())){
orderList = orderService.payedUnrefundListByUserId(user.getId());
}
List<SOrder> finalOrderList = orderList;
return Optional.ofNullable(packList).orElse(new ArrayList<>()).stream().filter(pack -> {
if(YesNoEnum.yes.getIndex().compareTo(pack.getFirstOrderAvailable())==0
&& CollectionUtils.isNotEmpty(finalOrderList)){
return false;
}
return true;
}).collect(Collectors.toList());
}
@Override
public Long addPack(SPack sPack) {
sPack.setCreateTime(DateUtils.getNowDate());
packMapper.insertPack(sPack);
baseMapper.insertPack(sPack);
return sPack.getId();
}
}
......@@ -303,6 +303,8 @@ public class SOrderServiceImpl extends ServiceImpl<SOrderMapper, SOrder> impleme
checkOrderPrice(sOrder, user);
//校验订单预约时间
checkOrderDate(request);
//校验订单套餐
checkOrderPack(request,user);
OrderPayResultResponse response = new OrderPayResultResponse();
if (request.getPayFee().compareTo(BigDecimal.ZERO) <= 0) {
response.setPayType(PayTypeEnum.WECHAT.getValue());
......@@ -348,6 +350,27 @@ public class SOrderServiceImpl extends ServiceImpl<SOrderMapper, SOrder> impleme
return response;
}
private void checkOrderPack(CreateOrderRequest request, SConsumer user) {
if(Objects.nonNull(request.getPackId()) && request.getPackId()>0){
//判断是否首次订单套餐
SPack pack = packService.getById(request.getPackId());
if(Objects.isNull(pack)||Objects.isNull(pack.getId())){
throw new BaseException("下单套餐不存在!");
}
if(YesNoEnum.yes.getIndex().compareTo(pack.getFirstOrderAvailable())==0){
List<SOrder> orderList = payedUnrefundListByUserId(user.getId());
if(CollectionUtils.isNotEmpty(orderList)){
throw new BaseException("当前套餐仅首次下单可用!");
}
}
Date now = new Date();
if(now.compareTo(request.getPreStartDate())>0
|| now.compareTo(request.getPreEndDate())<0){
throw new BaseException("预约时段非套餐可用时段!");
}
}
}
private void checkOrderDate(CreateOrderRequest request) {
LambdaQueryWrapper<SOrder> queryWrapper = new LambdaQueryWrapper<>();
queryWrapper.notIn(SOrder::getRefundStatus, RefundStatusEnum.getRefundedStatus());
......@@ -730,6 +753,20 @@ public class SOrderServiceImpl extends ServiceImpl<SOrderMapper, SOrder> impleme
return execute;
}
@Override
public List<SOrder> payedUnrefundListByUserId(Long userId) {
LambdaQueryWrapper<SOrder> queryWrapper = new LambdaQueryWrapper<>();
queryWrapper.eq(SOrder::getPayStatus, YesNoEnum.yes.getIndex());
queryWrapper.eq(SOrder::getConsumerId, userId);
queryWrapper.notIn(SOrder::getRefundStatus, RefundStatusEnum.getRefundedStatus());
queryWrapper.in(SOrder::getStatus, new ArrayList<Integer>(){{
add(OrderStatusEnum.UNUSED.getCode());
add(OrderStatusEnum.INUSE.getCode());
add(OrderStatusEnum.USED.getCode());
}});
return list(queryWrapper);
}
/**
* 订单DO集合转换VO集合,按距离排序
*
......
......@@ -54,6 +54,10 @@ public class SStoreServiceImpl extends ServiceImpl<SStoreMapper, SStore> impleme
private ISCleanRecordsService cleanRecordsService;
@Autowired
private IRoomPackService roomPackService;
@Autowired
private SConsumerService consumerService;
@Autowired
private ISOrderService orderService;
/**
* 查询门店
......@@ -249,7 +253,7 @@ public class SStoreServiceImpl extends ServiceImpl<SStoreMapper, SStore> impleme
List<Long> roomIds = roomVoList.stream().map(SRoomVo::getId).collect(Collectors.toList());
List<SRoomPack> roomPacks = roomPackService.listByRoomIds(roomIds);
List<Long> packIds = roomPacks.stream().map(SRoomPack::getPackId).collect(Collectors.toList());
List<SPack> packs = packService.listByIds(packIds);
List<SPack> packs = packService.selectPackListByIds(packIds);
Map<Long,SPack> packMap = Optional.ofNullable(packs).orElse(new ArrayList<>()).stream().collect(Collectors.toMap(SPack::getId,o->o,(k1,k2)->k1));
roomVoList.stream().forEach(sRoomVo -> {
List<SPack> sPacks = new ArrayList<>();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment