diff --git a/pjcloud-hardware/pjcloud-hardware-api/src/main/java/com/bsd/pjcloud/hard/api/dto/app/HardCarSaveOrUpdateDto.java b/pjcloud-hardware/pjcloud-hardware-api/src/main/java/com/bsd/pjcloud/hard/api/dto/app/HardCarSaveOrUpdateDto.java index 7157b6b71..09871d109 100644 --- a/pjcloud-hardware/pjcloud-hardware-api/src/main/java/com/bsd/pjcloud/hard/api/dto/app/HardCarSaveOrUpdateDto.java +++ b/pjcloud-hardware/pjcloud-hardware-api/src/main/java/com/bsd/pjcloud/hard/api/dto/app/HardCarSaveOrUpdateDto.java @@ -1,6 +1,7 @@ package com.bsd.pjcloud.hard.api.dto.app; import com.bsd.pjcloud.hard.api.constant.HardTypeEnum; +import com.bsd.pjcloud.hard.api.constant.order.HardOrderTypeEnum; import com.bsd.pjcloud.hard.api.dto.order.HardCreateCarDto; import io.swagger.v3.oas.annotations.media.Schema; import jakarta.validation.constraints.NotEmpty; @@ -33,7 +34,7 @@ public class HardCarSaveOrUpdateDto { private HardTypeEnum hardType; @Schema(description = "订单类型") - private String orderType; + private HardOrderTypeEnum orderType; @Schema(description = "订单类型渠道id") private Long orderSourceTypeId; diff --git a/pjcloud-hardware/pjcloud-hardware-biz/src/main/java/com/bsd/pjcloud/hard/controller/order/HardCarController.java b/pjcloud-hardware/pjcloud-hardware-biz/src/main/java/com/bsd/pjcloud/hard/controller/order/HardCarController.java index bd55aa4d4..841f2c9b5 100644 --- a/pjcloud-hardware/pjcloud-hardware-biz/src/main/java/com/bsd/pjcloud/hard/controller/order/HardCarController.java +++ b/pjcloud-hardware/pjcloud-hardware-biz/src/main/java/com/bsd/pjcloud/hard/controller/order/HardCarController.java @@ -66,7 +66,7 @@ public class HardCarController { public R saveOrUpload(@RequestBody HardCarSaveOrUpdateDto dto) { PjcloudUser user = SecurityUtils.getUser(); dto.setUserId(user.getId()); - dto.setOrderType(HardOrderTypeEnum.RESERVE.getType()); + dto.setOrderType(HardOrderTypeEnum.RESERVE); if (ObjectUtil.isEmpty(dto.getHardType())) { dto.setHardType(HardTypeEnum.SUPERMARKET); } diff --git a/pjcloud-hardware/pjcloud-hardware-biz/src/main/java/com/bsd/pjcloud/hard/service/HardCarService.java b/pjcloud-hardware/pjcloud-hardware-biz/src/main/java/com/bsd/pjcloud/hard/service/HardCarService.java index c677b4ae4..d183aa688 100644 --- a/pjcloud-hardware/pjcloud-hardware-biz/src/main/java/com/bsd/pjcloud/hard/service/HardCarService.java +++ b/pjcloud-hardware/pjcloud-hardware-biz/src/main/java/com/bsd/pjcloud/hard/service/HardCarService.java @@ -3,6 +3,7 @@ package com.bsd.pjcloud.hard.service; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.baomidou.mybatisplus.extension.service.IService; import com.bsd.pjcloud.hard.api.constant.HardTypeEnum; +import com.bsd.pjcloud.hard.api.constant.order.HardOrderTypeEnum; import com.bsd.pjcloud.hard.api.dto.app.HardCarSaveOrUpdateDto; import com.bsd.pjcloud.hard.api.dto.order.HardCarDto; import com.bsd.pjcloud.hard.api.dto.order.HardCreateCarDto; @@ -22,14 +23,15 @@ public interface HardCarService extends IService { List getByParentCarId(Long parentCarId); - List mchDetail(Long merchantId, Long userId,HardTypeEnum hardType); + List mchDetail(Long merchantId, Long userId, HardTypeEnum hardType); - Integer computerCarTotalPrice(@NotNull HardTypeEnum sysType, @NotEmpty List list); + Integer computerCarTotalPrice(@NotNull HardTypeEnum sysType, @NotNull HardOrderTypeEnum orderType, @NotEmpty List list); HardParentCarEntity getParentCarById(Long id); /** * 新增或者更新购物车 + * * @param dto */ void saveOrUpload(HardCarSaveOrUpdateDto dto); @@ -41,14 +43,15 @@ public interface HardCarService extends IService { * @param list g购物车类表 * @return 父购物车id */ - Long createCard(Long userId, Long merchantId, HardTypeEnum sysType, List list); + Long createCard(Long userId, Long merchantId, HardTypeEnum sysType, HardOrderTypeEnum orderTYpe, List list); /** * 生成购买商品的描述 + * * @param sysType 订单类型 - * @param list 购物车列表 + * @param list 购物车列表 * @return */ - String computerCarSubject(HardTypeEnum sysType, List list); + String computerCarSubject(HardTypeEnum sysType, HardOrderTypeEnum orderType, List list); } \ No newline at end of file diff --git a/pjcloud-hardware/pjcloud-hardware-biz/src/main/java/com/bsd/pjcloud/hard/service/impl/order/HardCarServiceImpl.java b/pjcloud-hardware/pjcloud-hardware-biz/src/main/java/com/bsd/pjcloud/hard/service/impl/order/HardCarServiceImpl.java index 858e0d373..8c355e1ee 100644 --- a/pjcloud-hardware/pjcloud-hardware-biz/src/main/java/com/bsd/pjcloud/hard/service/impl/order/HardCarServiceImpl.java +++ b/pjcloud-hardware/pjcloud-hardware-biz/src/main/java/com/bsd/pjcloud/hard/service/impl/order/HardCarServiceImpl.java @@ -10,6 +10,7 @@ import com.bsd.pjcloud.canteen.vo.app.CanteenOnlineSpuAppVO; import com.bsd.pjcloud.common.core.util.BeanUtils; import com.bsd.pjcloud.hard.api.constant.HardTypeEnum; import com.bsd.pjcloud.hard.api.constant.order.HardOrderStatusEnum; +import com.bsd.pjcloud.hard.api.constant.order.HardOrderTypeEnum; import com.bsd.pjcloud.hard.api.dto.app.HardCarSaveOrUpdateDto; import com.bsd.pjcloud.hard.api.dto.order.HardCarDto; import com.bsd.pjcloud.hard.api.dto.order.HardCreateCarDto; @@ -112,29 +113,36 @@ public class HardCarServiceImpl extends ServiceImpl().eq(HardCarEntity::getParentCarId, parentCar.getId())); // 添加购物车 - getSelf().appCreateCard(parentCar.getId(), dto.getHardType(), carList); + getSelf().appCreateCard(parentCar.getId(), dto.getHardType(), dto.getOrderType(), carList); return; } // 添加父订单 HardParentCarEntity parentCarObj = HardParentCarEntity.builder().userId(dto.getUserId()).merchantId(dto.getMerchantId()).hardType(dto.getHardType().getType()).orderStatus(HardOrderStatusEnum.CREATE.getType()).build(); hardParentCarMapper.insert(parentCarObj); // 添加购物车 - getSelf().appCreateCard(parentCarObj.getId(), dto.getHardType(), carList); + getSelf().appCreateCard(parentCarObj.getId(), dto.getHardType(), dto.getOrderType(), carList); } @Override - public Integer computerCarTotalPrice(HardTypeEnum sysType, List list) { + public Integer computerCarTotalPrice(HardTypeEnum sysType, HardOrderTypeEnum orderType, List list) { List productIds = list.stream().map(HardCreateCarDto::getProductId).toList(); return switch (sysType) { case CANTEEN -> { // 查询食堂商品 - List supList = onlineCanteenSpuService.getSpuListByIds(productIds).getData(); AtomicInteger canteenTotalPrice = new AtomicInteger(); - for (HardCreateCarDto v : list) { - supList.stream().filter(i -> ObjectUtil.equals(i.getId(), v.getProductId())).findFirst().ifPresent(spu -> { - int itemTotalPrice = v.getProductCount() * spu.getPrice(); - canteenTotalPrice.addAndGet(itemTotalPrice); - }); + // 线上 + if (ObjectUtil.equals(HardOrderTypeEnum.RESERVE, orderType)) { + List supList = onlineCanteenSpuService.getSpuListByIds(productIds).getData(); + for (HardCreateCarDto v : list) { + supList.stream().filter(i -> ObjectUtil.equals(i.getId(), v.getProductId())).findFirst().ifPresent(spu -> { + int itemTotalPrice = v.getProductCount() * spu.getPrice(); + canteenTotalPrice.addAndGet(itemTotalPrice); + }); + } + } + // 线下 + if (ObjectUtil.equals(HardOrderTypeEnum.BELOW, orderType)) { + } yield canteenTotalPrice.get(); } @@ -157,34 +165,39 @@ public class HardCarServiceImpl extends ServiceImpl list) { + public Long createCard(Long userId, Long merchantId, HardTypeEnum sysType, HardOrderTypeEnum orderTYpe, List list) { // 创建父订单 HardParentCarEntity parentCarObj = HardParentCarEntity.builder().userId(userId).merchantId(merchantId).hardType(sysType.getType()).orderStatus(HardOrderStatusEnum.PAY.getType()).build(); hardParentCarMapper.insert(parentCarObj); - getSelf().appCreateCard(parentCarObj.getId(), sysType, list); + getSelf().appCreateCard(parentCarObj.getId(), sysType, orderTYpe, list); return parentCarObj.getId(); } @Transactional(rollbackFor = Exception.class) - public void appCreateCard(Long parentCarId, HardTypeEnum sysType, List productList) { + public void appCreateCard(Long parentCarId, HardTypeEnum sysType, HardOrderTypeEnum orderType, List productList) { List productIds = productList.stream().map(HardCreateCarDto::getProductId).toList(); // 食堂 if (ObjectUtil.equals(sysType, HardTypeEnum.CANTEEN)) { List carObjectList = new ArrayList<>(); - List supList = onlineCanteenSpuService.getSpuListByIds(productIds).getData(); - for (HardCreateCarDto v : productList) { - HardCarEntity item = HardCarEntity.builder().parentCarId(parentCarId).build(); - supList.stream().filter(i -> ObjectUtil.equals(i.getId(), v.getProductId())).findFirst().ifPresent(spu -> { - int totalPrice = v.getProductCount() * spu.getPrice(); - item.setProductId(spu.getId()); - item.setProductName(spu.getName()); - item.setProductPrice(spu.getPrice()); - item.setProductPic(spu.getPicUrl()); - item.setTotalPrice((long) totalPrice); - item.setProductCount(v.getProductCount()); - item.setProductWeight(new BigDecimal(0)); - carObjectList.add(item); - }); + if (ObjectUtil.equals(HardOrderTypeEnum.RESERVE, orderType)) { + List supList = onlineCanteenSpuService.getSpuListByIds(productIds).getData(); + for (HardCreateCarDto v : productList) { + HardCarEntity item = HardCarEntity.builder().parentCarId(parentCarId).build(); + supList.stream().filter(i -> ObjectUtil.equals(i.getId(), v.getProductId())).findFirst().ifPresent(spu -> { + int totalPrice = v.getProductCount() * spu.getPrice(); + item.setProductId(spu.getId()); + item.setProductName(spu.getName()); + item.setProductPrice(spu.getPrice()); + item.setProductPic(spu.getPicUrl()); + item.setTotalPrice((long) totalPrice); + item.setProductCount(v.getProductCount()); + item.setProductWeight(new BigDecimal(0)); + carObjectList.add(item); + }); + } + } + if (ObjectUtil.equals(HardOrderTypeEnum.BELOW, orderType)) { + } baseMapper.insert(carObjectList); return; @@ -214,17 +227,26 @@ public class HardCarServiceImpl extends ServiceImpl list) { + public String computerCarSubject(HardTypeEnum sysType, HardOrderTypeEnum orderType, List list) { StringBuffer str = new StringBuffer(); List productIds = list.stream().map(HardCreateCarDto::getProductId).toList(); + // 食堂 if (ObjectUtil.equals(sysType, HardTypeEnum.CANTEEN)) { - List supList = onlineCanteenSpuService.getSpuListByIds(productIds).getData(); - for (HardCreateCarDto v : list) { - supList.stream().filter(i -> ObjectUtil.equals(i.getId(), v.getProductId())).findFirst().ifPresent(spu -> { - str.append(spu.getName()).append("x").append(v.getProductCount()).append(";"); - }); + // 线上 + if (ObjectUtil.equals(orderType, HardOrderTypeEnum.RESERVE)) { + List supList = onlineCanteenSpuService.getSpuListByIds(productIds).getData(); + for (HardCreateCarDto v : list) { + supList.stream().filter(i -> ObjectUtil.equals(i.getId(), v.getProductId())).findFirst().ifPresent(spu -> { + str.append(spu.getName()).append("x").append(v.getProductCount()).append(";"); + }); + } + } + // 线下 + if (ObjectUtil.equals(orderType, HardOrderTypeEnum.BELOW)) { + } } + // 超市 if (ObjectUtil.equals(sysType, HardTypeEnum.SUPERMARKET)) { List supList = supermarketUnitSkuService.getSupermarketUnits(productIds).getData(); for (HardCreateCarDto v : list) { diff --git a/pjcloud-hardware/pjcloud-hardware-biz/src/main/java/com/bsd/pjcloud/hard/service/impl/order/HardwareOrderServiceImpl.java b/pjcloud-hardware/pjcloud-hardware-biz/src/main/java/com/bsd/pjcloud/hard/service/impl/order/HardwareOrderServiceImpl.java index 967d5e51f..1515ec1d5 100644 --- a/pjcloud-hardware/pjcloud-hardware-biz/src/main/java/com/bsd/pjcloud/hard/service/impl/order/HardwareOrderServiceImpl.java +++ b/pjcloud-hardware/pjcloud-hardware-biz/src/main/java/com/bsd/pjcloud/hard/service/impl/order/HardwareOrderServiceImpl.java @@ -171,7 +171,6 @@ public class HardwareOrderServiceImpl extends ServiceImpl new RuntimeException("用户钱包不存在")); } int totalPrice = 0, extraPrice = 0, payPrice = 0; - totalPrice = hardCarService.computerCarTotalPrice(dto.getSysType(), dto.getList()); + totalPrice = hardCarService.computerCarTotalPrice(dto.getSysType(), dto.getOrderType(), dto.getList()); if (isExtraPrice) extraPrice = computeExtraPrice(totalPrice); payPrice = totalPrice + extraPrice; // 判断余额够不够支付 if (isPay && wallet.getBalance() < payPrice) throw new RuntimeException("钱包余额不足"); // 添加购物车 - Long parentCarId = hardCarService.createCard(dto.getUserId(), dto.getMerchantId(), dto.getSysType(), dto.getList()); + Long parentCarId = hardCarService.createCard(dto.getUserId(), dto.getMerchantId(), dto.getSysType(), dto.getOrderType(), dto.getList()); // 获取商品描述 - String subject = hardCarService.computerCarSubject(dto.getSysType(), dto.getList()); + String subject = hardCarService.computerCarSubject(dto.getSysType(), dto.getOrderType(), dto.getList()); // 添加硬件订单 HardOrderEntity orderObj = HardOrderEntity.builder() .androidOrderCode(dto.getAndroidOrderCode()) @@ -248,7 +247,7 @@ public class HardwareOrderServiceImpl extends ServiceImpl { } default MchManageVo join(Long id) { - MPJLambdaQueryWrapper wrapper = new MPJLambdaQueryWrapper() + MPJLambdaWrapper wrapper = new MPJLambdaWrapper() .selectAll(MchManageEntity.class) - .eq(MchManageEntity::getId, id); + .eqIfExists(MchManageEntity::getId, id); return selectJoinOne(MchManageVo.class, wrapper); }