Commit e0f4be20 by wuwenlong

order bug fix ;

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