Commit e0f4be20 by wuwenlong

order bug fix ;

order code opt;
parent fb0c4c41
......@@ -5,8 +5,6 @@ import javax.servlet.http.HttpServletResponse;
import io.swagger.annotations.ApiOperation;
import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
......
......@@ -58,7 +58,7 @@ public class SOrderController extends BaseController
startPage();
SConsumer user = FrontTokenComponent.getWxSConsumerEntry();
sOrder.setConsumerId(user.getId());
List<SOrder> list = sOrderService.selectSOrderList(sOrder);
List<SOrderVo> list = sOrderService.selectSOrderVoList(sOrder);
return getDataTable(list);
}
......
......@@ -137,34 +137,6 @@ public class SOrder extends BaseEntity
@TableField(select = false)
private Integer isDelete;
@TableField(exist = false)
private Integer buyType;
//优惠卷名称
@TableField(exist = false)
private String couponName;
//套餐名称
@TableField(exist = false)
private String packName;
//门店名称
@TableField(exist = false)
private String storeName;
//房间名称
@TableField(exist = false)
private String roomName;
//房间图片
@TableField(exist = false)
private String roomImages;
//是否可以申请退款
@TableField(exist = false)
private Boolean isRefund;
}
......@@ -197,4 +197,12 @@ public class SOrderVo
@ApiModelProperty(name = "是否可以申请退款")
private Boolean isRefund;
//优惠卷名称
@ApiModelProperty(name = "优惠卷名称")
private String couponName;
//套餐名称
@ApiModelProperty(name = "套餐名称")
private String packName;
}
......@@ -37,6 +37,14 @@ public interface ISOrderService extends IService<SOrder>
public List<SOrder> selectSOrderList(SOrder sOrder);
/**
* 查询订单列表
*
* @param sOrder 订单
* @return 订单集合
*/
public List<SOrderVo> selectSOrderVoList(SOrder sOrder);
/**
* 新增订单
*
* @param sOrder 订单
......
......@@ -51,9 +51,6 @@ public class SOrderServiceImpl extends ServiceImpl<SOrderMapper, SOrder> impleme
private Long allowRefundTime;
@Autowired
private SOrderMapper sOrderMapper;
@Autowired
private SConsumerService sConsumerService;
@Autowired
......@@ -100,7 +97,7 @@ public class SOrderServiceImpl extends ServiceImpl<SOrderMapper, SOrder> impleme
*/
@Override
public SOrder selectSOrderById(Long id) {
return sOrderMapper.selectSOrderById(id);
return baseMapper.selectSOrderById(id);
}
/**
......@@ -111,58 +108,69 @@ public class SOrderServiceImpl extends ServiceImpl<SOrderMapper, SOrder> impleme
*/
@Override
public List<SOrder> selectSOrderList(SOrder sOrder) {
List<SOrder> sOrders = new ArrayList<>();
List<SOrder> orders = new ArrayList<>();
LambdaQueryWrapper<SOrder> queryWrapper = new LambdaQueryWrapper<>();
queryWrapper.eq(SOrder::getPayStatus, YesNoEnum.yes.getIndex());
if (ObjectUtil.isNotEmpty(sOrder.getStatus())) {
LambdaQueryWrapper<SOrder> queryWrapper = new LambdaQueryWrapper<>();
queryWrapper.eq(SOrder::getPayStatus, YesNoEnum.yes.getIndex());
if (sOrder.getStatus().equals(OrderStatusEnum.CANCEL.getCode())) {
queryWrapper.in(SOrder::getStatus, new ArrayList<Integer>() {{
add(OrderStatusEnum.CANCEL.getCode());
add(OrderStatusEnum.REFUNDING.getCode());
add(OrderStatusEnum.REFUNDED.getCode());
}});
} else if (sOrder.getStatus().equals(OrderStatusEnum.UNUSED.getCode())) {
queryWrapper.eq(SOrder::getStatus, OrderStatusEnum.UNUSED.getCode());
} else if (sOrder.getStatus().equals(OrderStatusEnum.INUSE.getCode())) {
queryWrapper.eq(SOrder::getStatus, OrderStatusEnum.INUSE.getCode());
} else if (sOrder.getStatus().equals(OrderStatusEnum.USED.getCode())) {
queryWrapper.eq(SOrder::getStatus, OrderStatusEnum.USED.getCode());
OrderStatusEnum orderStatusEnum = OrderStatusEnum.getEnumByCode(sOrder.getStatus());
switch(orderStatusEnum){
case CANCEL:
queryWrapper.in(SOrder::getStatus, new ArrayList<Integer>() {{
add(OrderStatusEnum.CANCEL.getCode());
add(OrderStatusEnum.REFUNDING.getCode());
add(OrderStatusEnum.REFUNDED.getCode());
}});
break;
case UNUSED:
case INUSE:
case USED:
queryWrapper.eq(SOrder::getStatus, sOrder.getStatus());
break;
default:
break;
}
if (ObjectUtil.isNotEmpty(sOrder.getConsumerId())) {
queryWrapper.eq(SOrder::getConsumerId, sOrder.getConsumerId());
}
sOrders = sOrderMapper.selectList(queryWrapper);
orders = baseMapper.selectList(queryWrapper);
} else {
sOrders = sOrderMapper.selectSOrderList(sOrder);
orders = baseMapper.selectSOrderList(sOrder);
}
return orders;
}
if (CollectionUtils.isNotEmpty(sOrders)) {
sOrders.stream().forEach(item -> {
if (ObjectUtil.isNotNull(item.getCouponId())) {
SConsumerCoupon byId = consumerCouponService.getById(item.getCouponId());
item.setCouponName(byId.getName());
// 判断是否可以退款
item.setIsRefund(isRefund(item, byId));
} else {
// 判断是否可以退款
item.setIsRefund(isRefund(item, null));
}
if (ObjectUtil.isNotNull(item.getPackId())) {
SPack byId = packService.getById(item.getPackId());
item.setPackName(byId.getName());
}
if (ObjectUtil.isNotNull(item.getStoreId())) {
SStore byId = storeService.getById(item.getStoreId());
item.setStoreName(byId.getName());
}
if (ObjectUtil.isNotNull(item.getRoomId())) {
SRoom byId = roomService.getById(item.getRoomId());
item.setRoomName(byId.getName());
}
});
}
return sOrders;
/**
* 查询订单列表
*
* @param sOrder 订单
* @return 订单
*/
@Override
public List<SOrderVo> selectSOrderVoList(SOrder sOrder) {
return convertDosToVos(selectSOrderList(sOrder));
}
/**
* 验证是否可以申请退款
* @param orderVo 订单信息
* @param coupon 优惠券信息
* @return
*/
private boolean isRefund(SOrderVo orderVo, SConsumerCoupon coupon) {
if (coupon != null && !PlatformTypeEnum.SELF.getCode().equals(coupon.getPlatformType())) {
return Boolean.FALSE;
} else if (orderVo != null && OrderStatusEnum.UNUSED.getCode().equals(orderVo.getStatus())){
Date startTime = orderVo.getPreStartDate();
Date nowTime = cn.hutool.core.date.DateUtil.date();
if (startTime.compareTo(nowTime) <=0) {
return Boolean.FALSE;
}
long between = cn.hutool.core.date.DateUtil.between(nowTime,
startTime, DateUnit.SECOND);
if (between > allowRefundTime && RefundStatusEnum.UNREFUND.getCode().equals(orderVo.getRefundStatus())) {
return Boolean.TRUE;
}
}
return Boolean.FALSE;
}
/**
......@@ -188,7 +196,6 @@ public class SOrderServiceImpl extends ServiceImpl<SOrderMapper, SOrder> impleme
}
return Boolean.FALSE;
}
/**
* 新增订单
*
......@@ -198,7 +205,7 @@ public class SOrderServiceImpl extends ServiceImpl<SOrderMapper, SOrder> impleme
@Override
public int insertSOrder(SOrder sOrder) {
sOrder.setCreateTime(DateUtils.getNowDate());
return sOrderMapper.insertSOrder(sOrder);
return baseMapper.insertSOrder(sOrder);
}
/**
......@@ -210,7 +217,7 @@ public class SOrderServiceImpl extends ServiceImpl<SOrderMapper, SOrder> impleme
@Override
public int updateSOrder(SOrder sOrder) {
sOrder.setUpdateTime(DateUtils.getNowDate());
return sOrderMapper.updateSOrder(sOrder);
return baseMapper.updateSOrder(sOrder);
}
/**
......@@ -221,7 +228,7 @@ public class SOrderServiceImpl extends ServiceImpl<SOrderMapper, SOrder> impleme
*/
@Override
public int deleteSOrderByIds(Long[] ids) {
return sOrderMapper.deleteSOrderByIds(ids);
return baseMapper.deleteSOrderByIds(ids);
}
/**
......@@ -232,7 +239,7 @@ public class SOrderServiceImpl extends ServiceImpl<SOrderMapper, SOrder> impleme
*/
@Override
public int deleteSOrderById(Long id) {
return sOrderMapper.deleteSOrderById(id);
return baseMapper.deleteSOrderById(id);
}
@Override
......@@ -396,15 +403,6 @@ public class SOrderServiceImpl extends ServiceImpl<SOrderMapper, SOrder> impleme
LambdaQueryWrapper<SOrder> lqw = Wrappers.lambdaQuery();
lqw.eq(SOrder::getOrderNo, orderNo);
SOrder order = getOne(lqw);
if (ObjectUtil.isNotNull(order.getCouponId())) {
SConsumerCoupon byId = consumerCouponService.getById(order.getCouponId());
order.setCouponName(byId.getName());
// 判断是否可以退款
order.setIsRefund(isRefund(order, byId));
} else {
// 判断是否可以退款
order.setIsRefund(isRefund(order, null));
}
return order;
}
......@@ -494,7 +492,7 @@ public class SOrderServiceImpl extends ServiceImpl<SOrderMapper, SOrder> impleme
LambdaQueryWrapper<SOrder> queryWrapper = new LambdaQueryWrapper<>();
queryWrapper.eq(SOrder::getPayStatus, PayStatusEnum.PAID.getCode());
queryWrapper.ne(SOrder::getRefundStatus, RefundStatusEnum.UNREFUND.getCode());
return sOrderMapper.selectList(queryWrapper);
return baseMapper.selectList(queryWrapper);
}
@Override
......@@ -524,28 +522,6 @@ public class SOrderServiceImpl extends ServiceImpl<SOrderMapper, SOrder> impleme
LambdaQueryWrapper<SOrder> queryWrapper = new LambdaQueryWrapper<>();
queryWrapper.eq(SOrder::getOrderNo, orderNo);
SOrder one = getOne(queryWrapper);
if (ObjectUtil.isNotEmpty(one.getCouponId())) {
SConsumerCoupon consumerCoupon = consumerCouponService.getById(one.getCouponId());
one.setCouponName(consumerCoupon.getName());
// 判断是否可以退款
one.setIsRefund(isRefund(one, consumerCoupon));
} else {
// 判断是否可以退款
one.setIsRefund(isRefund(one, null));
}
if (ObjectUtil.isNotEmpty(one.getPackId())) {
SPack byId = packService.getById(one.getPackId());
one.setPackName(byId.getName());
}
if (ObjectUtil.isNotEmpty(one.getStoreId())) {
SStore sStore = storeService.getById(one.getStoreId());
one.setStoreName(sStore.getName());
}
if (ObjectUtil.isNotEmpty(one.getRoomId())) {
SRoom sRoom = roomService.getById(one.getRoomId());
one.setRoomImages(sRoom.getImages());
one.setRoomName(sRoom.getName());
}
return one;
}
......@@ -564,6 +540,19 @@ public class SOrderServiceImpl extends ServiceImpl<SOrderMapper, SOrder> impleme
vo.setLatitude(store.getLatitude());
vo.setManager(store.getManager());
vo.setPhone(store.getPhone());
if (ObjectUtil.isNotEmpty(vo.getCouponId())) {
SConsumerCoupon consumerCoupon = consumerCouponService.getById(vo.getCouponId());
vo.setCouponName(consumerCoupon.getName());
// 判断是否可以退款
vo.setIsRefund(isRefund(vo, consumerCoupon));
} else {
// 判断是否可以退款
vo.setIsRefund(isRefund(vo, null));
}
if (ObjectUtil.isNotEmpty(vo.getPackId())) {
SPack byId = packService.getById(vo.getPackId());
vo.setPackName(byId.getName());
}
return vo;
}
......@@ -583,7 +572,7 @@ public class SOrderServiceImpl extends ServiceImpl<SOrderMapper, SOrder> impleme
@Override
public void paymentSuccessful(SOrder sOrder) {
sOrderMapper.updateById(sOrder);
baseMapper.updateById(sOrder);
Long couponId = sOrder.getCouponId();
if (couponId != null && couponId > 0) {
SConsumerCoupon consumerCoupon = consumerCouponService.getById(couponId);
......@@ -597,7 +586,10 @@ public class SOrderServiceImpl extends ServiceImpl<SOrderMapper, SOrder> impleme
SConsumptionRecords sConsumptionRecords = new SConsumptionRecords();
sConsumptionRecords.setConsumerId(sOrder.getConsumerId());
sConsumptionRecords.setOrderId(sOrder.getId());
sConsumptionRecords.setName(sOrder.getPackName());
if (Objects.nonNull(sOrder.getPackId())) {
SPack pack = packService.getById(sOrder.getPackId());
sConsumptionRecords.setName(Objects.nonNull(pack)?pack.getName():null);
}
sConsumptionRecords.setPrice(sOrder.getPayPrice());
sConsumptionRecordsService.insertSConsumptionRecords(sConsumptionRecords);
}
......@@ -681,8 +673,12 @@ public class SOrderServiceImpl extends ServiceImpl<SOrderMapper, SOrder> impleme
if (CollectionUtils.isNotEmpty(orderList)) {
List<Long> storeIds = orderList.stream().map(SOrder::getStoreId).collect(Collectors.toList());
List<Long> roomIds = orderList.stream().map(SOrder::getRoomId).collect(Collectors.toList());
List<Long> couponIds = orderList.stream().map(SOrder::getCouponId).collect(Collectors.toList());
List<Long> packIds = orderList.stream().map(SOrder::getPackId).collect(Collectors.toList());
List<SStore> storeList = storeService.listByIds(storeIds);
List<SRoom> roomList = roomService.listByIds(roomIds);
List<SConsumerCoupon> userCouponList = consumerCouponService.listByIds(couponIds);
List<SPack> packList = packService.listByIds(packIds);
orderList.stream().forEach(o -> {
SOrderVo vo = new SOrderVo();
BeanUtils.copyProperties(o, vo);
......@@ -697,14 +693,25 @@ public class SOrderServiceImpl extends ServiceImpl<SOrderMapper, SOrder> impleme
vo.setRoomName(room.getName());
}
});
if (ObjectUtil.isNotEmpty(o.getCouponId())) {
SConsumerCoupon consumerCoupon = consumerCouponService.getById(o.getCouponId());
// 判断是否可以退款
vo.setIsRefund(isRefund(o, consumerCoupon));
} else {
if(Objects.nonNull(vo.getCouponId())) {
userCouponList.stream().forEach(userCoupon -> {
if (userCoupon.getId().equals(vo.getCouponId())) {
// 判断是否可以退款
vo.setIsRefund(isRefund(vo, userCoupon));
}
});
}else{
// 判断是否可以退款
vo.setIsRefund(isRefund(o, null));
}
if (Objects.nonNull(vo.getPackId())) {
packList.stream().forEach(pack -> {
if (pack.getId().equals(vo.getPackId())) {
vo.setPackName(pack.getName());
}
});
}
voList.add(vo);
});
}
......@@ -716,7 +723,7 @@ public class SOrderServiceImpl extends ServiceImpl<SOrderMapper, SOrder> impleme
public String openDoor(String orderNo) {
LambdaQueryWrapper<SOrder> orderLambdaQueryWrapper = new LambdaQueryWrapper<>();
orderLambdaQueryWrapper.eq(SOrder::getOrderNo, orderNo);
SOrder sOrder = sOrderMapper.selectOne(orderLambdaQueryWrapper);
SOrder sOrder = baseMapper.selectOne(orderLambdaQueryWrapper);
if (Objects.isNull(sOrder)) {
throw new BaseException("订单不存在!");
}
......@@ -744,7 +751,7 @@ public class SOrderServiceImpl extends ServiceImpl<SOrderMapper, SOrder> impleme
map.put("expirationTime", sOrder.getStartDate().toString());
JSONObject jsonObject = new JSONObject(map);
redisUtils.set(ReceiptRdeisEnum.ORDER_NO_KEY.getValue() + sOrder.getOrderNo(), jsonObject.toString());
sOrderMapper.updateById(sOrder);
baseMapper.updateById(sOrder);
//查询非当前用户,预约时间或使用时间为当前时间的订单,如果存在,房间不可开门
}
SConsumer user = FrontTokenComponent.getWxSConsumerEntry();
......
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