|
|
@@ -475,22 +475,58 @@ public class WashOrderServiceImpl extends MyBaseServiceImpl<WashOrderMapper, Was
|
|
|
@Override
|
|
|
public String checkParkingCoupon(String mobilePhone) {
|
|
|
CommUtil.asserts(CommUtil.isNotEmptyAndNull(mobilePhone),"查询手机号不能为空");
|
|
|
- // 查询xx时间内该用户的是否有满足消费金额的订单,如果有,取最近一条的场站
|
|
|
var user = userService.getOne(new LambdaQueryWrapper<User>().eq(User::getMobilePhone, mobilePhone));
|
|
|
if (user == null) {
|
|
|
throw new BusinessException("请输入注册洗车小程序使用的手机号码!");
|
|
|
}
|
|
|
|
|
|
- // 优惠券有效期2小时
|
|
|
+ // 优惠券有效期2小时,先查已支付订单
|
|
|
var orderList = lambdaQuery()
|
|
|
.eq(WashOrder::getUserId, user.getId())
|
|
|
.ge(WashOrder::getEndTime, LocalDateTime.now().minusHours(2))
|
|
|
.eq(WashOrder::getPayStatus, WashOrder.PAY_STATUS_已支付)
|
|
|
.orderByDesc(WashOrder::getId).list();
|
|
|
- if(orderList.isEmpty() || (orderList.stream().collect(Collectors.summarizingInt(WashOrder::getAmount)).getSum() < WashOrder.PARKING_COUPON_MIN_AMOUNT)){
|
|
|
- throw new BusinessException("不符合优惠条件:订单完成超过2小时或洗车金额不足6元。");
|
|
|
+ if (!orderList.isEmpty() && orderList.stream().collect(Collectors.summarizingInt(WashOrder::getAmount)).getSum() >= WashOrder.PARKING_COUPON_MIN_AMOUNT) {
|
|
|
+ return KymCache.INSTANCE.getParkingQrCodeUrlByStationId(orderList.get(0).getStationId());
|
|
|
}
|
|
|
- return KymCache.INSTANCE.getParkingQrCodeUrlByStationId(orderList.get(0).getStationId());
|
|
|
+
|
|
|
+ // 未找到符合条件的已支付订单,尝试查找僵死订单并主动对账结算
|
|
|
+ var staleOrders = lambdaQuery()
|
|
|
+ .eq(WashOrder::getUserId, user.getId())
|
|
|
+ .ge(WashOrder::getStartTime, LocalDateTime.now().minusHours(2))
|
|
|
+ .eq(WashOrder::getOrderStatus, WashOrder.ORDER_STATUS_开机)
|
|
|
+ .eq(WashOrder::getPayStatus, WashOrder.PAY_STATUS_未支付)
|
|
|
+ .orderByDesc(WashOrder::getId).list();
|
|
|
+
|
|
|
+ if (!staleOrders.isEmpty()) {
|
|
|
+ boolean reconciled = false;
|
|
|
+ for (WashOrder staleOrder : staleOrders) {
|
|
|
+ try {
|
|
|
+ OrderInfo orderInfo = awoaraService.queryOrder(staleOrder.getProductKey(), staleOrder.getDeviceName(), staleOrder.getOrderId());
|
|
|
+ if (orderInfo != null && orderInfo.getClose_type() != null && !orderInfo.getClose_type().isEmpty()) {
|
|
|
+ log.info("停车券查询-订单 {} 设备已关闭,主动结算", staleOrder.getOrderId());
|
|
|
+ orderSettlementService.settleOrder(staleOrder, orderInfo);
|
|
|
+ reconciled = true;
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.warn("停车券查询-订单 {} 查询设备失败:{}", staleOrder.getOrderId(), e.getMessage());
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if (reconciled) {
|
|
|
+ // 结算后重新查询已支付订单
|
|
|
+ orderList = lambdaQuery()
|
|
|
+ .eq(WashOrder::getUserId, user.getId())
|
|
|
+ .ge(WashOrder::getEndTime, LocalDateTime.now().minusHours(2))
|
|
|
+ .eq(WashOrder::getPayStatus, WashOrder.PAY_STATUS_已支付)
|
|
|
+ .orderByDesc(WashOrder::getId).list();
|
|
|
+ if (!orderList.isEmpty() && orderList.stream().collect(Collectors.summarizingInt(WashOrder::getAmount)).getSum() >= WashOrder.PARKING_COUPON_MIN_AMOUNT) {
|
|
|
+ return KymCache.INSTANCE.getParkingQrCodeUrlByStationId(orderList.get(0).getStationId());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ throw new BusinessException("不符合优惠条件:订单完成超过2小时或洗车金额不足6元。");
|
|
|
}
|
|
|
//endregion
|
|
|
}
|