feat:预约订单处理

This commit is contained in:
dzc committed 2025-04-23 12:20:52 +08:00
1 parent be284f19ad
commit d2b6f88b98
6 files changed
+41 -2

No files matched your search

+1
View File
@@ -375,6 +375,7 @@ CREATE TABLE hard_appt
title varchar(64) NOT NULL COMMENT '标题',
start_time time DEFAULT NULL COMMENT '开始时间',
end_time time DEFAULT NULL COMMENT '结束时间',
hour_type varchar(32) NOT NULL COMMENT '唯一标识',
sort int DEFAULT 0 NOT NULL COMMENT '排序',
status varchar(32) NOT NULL COMMENT '状态',
remark varchar(256) DEFAULT NULL COMMENT '备注',
@@ -45,4 +45,7 @@ public class HardAppCreateOrderDto {
// 饭卡id
private Long walletId;
// 预约id
private Long apptId;
}
@@ -46,6 +46,12 @@ public class HardApptEntity extends Model<HardApptEntity> {
@Schema(description = "结束时间")
private LocalTime endTime;
/**
* 预约时间段
*/
@Schema(description = "预约时间段")
private String hourType;
/**
* 排序
*/
@@ -123,6 +123,12 @@ public class HardOrderEntity extends Model<HardOrderEntity> {
@Schema(description = "用餐类型")
private String hourType;
/**
* 预约时间段id
*/
@Schema(description = "预约时间段id")
private Long apptId;
/**
* 订单设备类型
*/
@@ -161,9 +161,9 @@ public class HardOrderController {
@Operation(summary = "app创建订单", description = "app创建订单")
@GetMapping("/app/create-order")
@Idempotent(expireTime = 10, info = "正在创建订单中,请勿重复操作")
public R appCreateOrder(@RequestParam Long carParentId, @RequestParam HardTypeEnum hardType) {
public R appCreateOrder(@RequestParam Long carParentId, @RequestParam Long apptId, @RequestParam HardTypeEnum hardType) {
PjcloudUser user = SecurityUtils.getUser();
HardAppCreateOrderDto dto = HardAppCreateOrderDto.builder().carParentId(carParentId).walletType(WalletTypeEnum.EAT).hardType(hardType).userId(user.getId()).orderType(HardOrderTypeEnum.RESERVE).payType(HardPayTypeEnum.WALLET_DEFAULT).build();
HardAppCreateOrderDto dto = HardAppCreateOrderDto.builder().carParentId(carParentId).walletType(WalletTypeEnum.EAT).hardType(hardType).userId(user.getId()).orderType(HardOrderTypeEnum.RESERVE).payType(HardPayTypeEnum.WALLET_DEFAULT).apptId(apptId).build();
return R.ok(hardwareOrderService.appCreateOrder(dto));
}
@@ -4,6 +4,7 @@ import cn.hutool.core.util.ObjectUtil;
import cn.hutool.extra.spring.SpringUtil;
import cn.hutool.json.JSONUtil;
import com.alibaba.fastjson.JSON;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.bsd.pjcloud.admin.api.dto.UserInfo;
@@ -32,6 +33,7 @@ import com.bsd.pjcloud.hard.api.dto.order.HardCreateCarDto;
import com.bsd.pjcloud.hard.api.dto.order.HardOrderDto;
import com.bsd.pjcloud.hard.api.dto.order.app.HardAppCreateOrderDto;
import com.bsd.pjcloud.hard.api.dto.spu.DeductionSpuStockDto;
import com.bsd.pjcloud.hard.api.entity.HardApptEntity;
import com.bsd.pjcloud.hard.api.entity.manager.HardManagerEntity;
import com.bsd.pjcloud.hard.api.entity.order.HardCarEntity;
import com.bsd.pjcloud.hard.api.entity.order.HardOrderEntity;
@@ -98,6 +100,7 @@ public class HardOrderServiceImpl extends ServiceImpl<HardOrderMapper, HardOrder
private final HardDoorFlowService hardDoorFlowService;
private final HardBroadcastService hardBroadcastService;
private final HardSpuService hardSpuService;
private final HardApptService hardApptService;
private final RemoteMchService remoteMchService;
private final RemoteCodeUseService remoteCodeUseService;
@@ -298,6 +301,9 @@ public class HardOrderServiceImpl extends ServiceImpl<HardOrderMapper, HardOrder
// 查询用户
UserInfo userDetail = userService.getInnerByUserId(dto.getUserId()).getData();
if (ObjectUtil.isEmpty(userDetail)) throw new RuntimeException("用户不存在不存在");
// 判断是否有重复的预约订单
Long reserveCount = isHaveCanteenReserve(dto.getUserId());
if (reserveCount > 0) throw new RuntimeException("您有" + reserveCount + "笔未核销的预约订单,请先核销");
// 钱包
WalletManageEntity wallet = remoteWalletService.getWallet(dto.getUserId(), dto.getWalletType()).getData();
if (ObjectUtil.isEmpty(wallet)) throw new RuntimeException("用户钱包不存在");
@@ -347,6 +353,13 @@ public class HardOrderServiceImpl extends ServiceImpl<HardOrderMapper, HardOrder
.isOfflineOrder(YesNoEnum.NO.getCode())
.productDesc(subject)
.build();
if (ObjectUtil.equals(dto.getOrderType(), HardOrderTypeEnum.RESERVE)) {
// 查询时间段
HardApptEntity hardAppt = hardApptService.getById(dto.getApptId());
if (ObjectUtil.isEmpty(hardAppt)) throw new RuntimeException("预约时间段不存在");
orderObj.setHourType(hardAppt.getHourType());
orderObj.setApptId(hardAppt.getId());
}
if (isPay) orderObj.setWalletId(wallet.getId());
baseMapper.insert(orderObj);
// 钱包扣款
@@ -814,6 +827,16 @@ public class HardOrderServiceImpl extends ServiceImpl<HardOrderMapper, HardOrder
return HardTypeEnum.isReserve(hardTypeEnum);
}
// 用户是否有正在进行中的订餐
private Long isHaveCanteenReserve(Long userId) {
return baseMapper.selectCount(new LambdaQueryWrapper<HardOrderEntity>()
.eq(HardOrderEntity::getUserId, userId)
.eq(HardOrderEntity::getSysType, HardTypeEnum.CANTEEN.getType())
.eq(HardOrderEntity::getOrderType, HardOrderTypeEnum.RESERVE.getType())
.ne(HardOrderEntity::getOrderStatus, HardOrderStatusEnum.CANCEL.getType())
);
}
/* ************************************* end 支付相关 end ************************************* */
private HardOrderServiceImpl getSelf() {