feat:app创建线上超市预定订单

This commit is contained in:
dzc committed 2025-06-16 11:16:24 +08:00
1 parent 261b9564e0
commit 2d0151b1c3
3 files changed
+93 -2

No files matched your search

@@ -161,7 +161,7 @@ public class HardOrderController {
return R.ok(hardwareOrderService.join(id));
}
@Operation(summary = "app创建订单", description = "app创建订单")
@Operation(summary = "app创建食堂预定订单", description = "app创建食堂预定订单")
@GetMapping("/app/create-order")
@Idempotent(expireTime = 3, info = "正在创建订单中,请勿重复操作")
public R appCreateOrder(@RequestParam Long carParentId, @RequestParam Long apptId, @RequestParam HardTypeEnum hardType) {
@@ -170,6 +170,23 @@ public class HardOrderController {
return R.ok(hardwareOrderService.appCreateOrder(dto));
}
@Operation(summary = "app创建线上超市预定订单", description = "app创建线上超市预定订单")
@GetMapping("/app/create-supermarket-order")
@Idempotent(expireTime = 3, info = "正在创建订单中,请勿重复操作")
public R appCreateSupermarketReserveOrder(@RequestParam Long carParentId, @RequestParam HardTypeEnum hardType) {
PjcloudUser user = SecurityUtils.getUser();
HardAppCreateOrderDto dto = HardAppCreateOrderDto.builder()
.carParentId(carParentId).walletType(WalletTypeEnum.EAT)
.hardType(hardType)
.userId(user.getId())
.walletType(WalletTypeEnum.PAY)
.orderType(HardOrderTypeEnum.RESERVE)
.payType(HardPayTypeEnum.WALLET_DEFAULT)
.hardType(HardTypeEnum.SUPERMARKET)
.build();
return R.ok(hardwareOrderService.appCreateSupermarketReserveOrder(dto));
}
@Operation(summary = "app创建订单扫一扫", description = "app创建订单扫一扫")
@PostMapping("/app/create-order-scan-qrcode")
@Idempotent(expireTime = 5, info = "正在创建订单中,请勿重复操作")
@@ -43,10 +43,15 @@ public interface HardOrderService extends IService<HardOrderEntity> {
Long createOrder(HardCreateOrderDto dto);
/**
* 创建app订单
* app创建食堂预定订单
*/
Long appCreateOrder(@Valid HardAppCreateOrderDto dto);
/**
* app创建线上超市预定订单
*/
Long appCreateSupermarketReserveOrder(HardAppCreateOrderDto dto);
/**
* 创建app订单
*/
@@ -412,6 +412,75 @@ public class HardOrderServiceImpl extends ServiceImpl<HardOrderMapper, HardOrder
return orderObj.getId();
}
/**
* app创建线上超市预定订单
*/
@Override
@Transactional(rollbackFor = Exception.class)
public Long appCreateSupermarketReserveOrder(HardAppCreateOrderDto dto) {
// 查询用户
UserInfo userDetail = userService.getInnerByUserId(dto.getUserId()).getData();
if (ObjectUtil.isEmpty(userDetail)) throw new RuntimeException("用户不存在不存在");
// 钱包
WalletManageEntity wallet = remoteWalletService.getWallet(dto.getUserId(), dto.getWalletType()).getData();
if (ObjectUtil.isEmpty(wallet)) throw new RuntimeException("用户钱包不存在");
// 查询父订单
HardParentCarEntity parentCar = hardCarService.getParentCarById(dto.getCarParentId());
if (ObjectUtil.isEmpty(parentCar)) throw new RuntimeException("购物车不存在");
// 查询商户
MchManageVo hardManager = remoteMchService.getById(parentCar.getMerchantId()).getData();
if (ObjectUtil.isEmpty(hardManager)) throw new RuntimeException("商户不存在");
// 查询父购物车
List<HardCarEntity> carList = hardCarService.getByParentCarId(dto.getCarParentId());
if (ObjectUtil.isEmpty(carList)) throw new RuntimeException("购物车不存在");
Integer balance = wallet.getBalance();
int totalPrice = (int) carList.stream().mapToLong(HardCarEntity::getTotalPrice).sum();
if (balance < totalPrice) {
throw new RuntimeException("钱包余额不足");
}
// 获取商品描述
List<HardCreateCarDto> carListDto = carList.stream().map(v -> {
HardCreateCarDto entity = new HardCreateCarDto();
entity.setParentCarId(dto.getCarParentId());
entity.setProductId(v.getProductId());
entity.setProductWeight(v.getProductWeight());
entity.setProductCount(v.getProductCount());
return entity;
}).toList();
HardTypeEnum hardType = ObjectUtil.equals(dto.getWalletType(), WalletTypeEnum.EAT) ? HardTypeEnum.CANTEEN : HardTypeEnum.SUPERMARKET;
String subject = hardCarService.computerCarSubject(hardType, dto.getOrderType(), carListDto);
// 添加硬件订单
HardOrderEntity orderObj = HardOrderEntity.builder()
.userId(dto.getUserId())
.userDeptId(userDetail.getSysUser().getDeptId())
.parentCarId(dto.getCarParentId())
.sysType(dto.getHardType().getType())
.orderStatus(HardOrderStatusEnum.CREATE.getType())
.merchantId(parentCar.getMerchantId())
.merchantType(hardManager.getTypes())
.merchantDeptId(hardManager.getDeptId())
.orderType(dto.getOrderType().getType())
.payType(dto.getPayType().getType())
.orderSourceTypeId(dto.getOrderSourceTypeId())
.totalPrice(totalPrice)
.extraPrice(0)
.payPrice(totalPrice)
.isOfflineOrder(YesNoEnum.NO.getCode())
.productDesc(subject)
.walletId(wallet.getId())
.build();
baseMapper.insert(orderObj);
// 钱包扣款
getSelf().fastReduceBalance(orderObj);
// 创建二维码
getSelf().generateCode(orderObj);
// 发送mq消息
getSelf().createOrderAfterSendMqMsg(orderObj.getId(), userDetail);
// 扣减库存
getSelf().fastenerInventory(orderObj, YesNoEnum.YES);
return orderObj.getId();
}
@Override
// @GlobalTransactional
@Transactional(rollbackFor = Exception.class)