feat:兼容食堂线上、线下商品
This commit is contained in:
1 parent
46d4757f55
commit
a369b46c9d
7 files changed
+73
-47
No files matched your search
+2
-1
@@ -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;
|
||||
|
||||
+1
-1
@@ -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);
|
||||
}
|
||||
|
||||
+8
-5
@@ -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<HardCarEntity> {
|
||||
|
||||
List<HardCarEntity> getByParentCarId(Long parentCarId);
|
||||
|
||||
List<HardCarVo> mchDetail(Long merchantId, Long userId,HardTypeEnum hardType);
|
||||
List<HardCarVo> mchDetail(Long merchantId, Long userId, HardTypeEnum hardType);
|
||||
|
||||
Integer computerCarTotalPrice(@NotNull HardTypeEnum sysType, @NotEmpty List<HardCreateCarDto> list);
|
||||
Integer computerCarTotalPrice(@NotNull HardTypeEnum sysType, @NotNull HardOrderTypeEnum orderType, @NotEmpty List<HardCreateCarDto> list);
|
||||
|
||||
HardParentCarEntity getParentCarById(Long id);
|
||||
|
||||
/**
|
||||
* 新增或者更新购物车
|
||||
*
|
||||
* @param dto
|
||||
*/
|
||||
void saveOrUpload(HardCarSaveOrUpdateDto dto);
|
||||
@@ -41,14 +43,15 @@ public interface HardCarService extends IService<HardCarEntity> {
|
||||
* @param list g购物车类表
|
||||
* @return 父购物车id
|
||||
*/
|
||||
Long createCard(Long userId, Long merchantId, HardTypeEnum sysType, List<HardCreateCarDto> list);
|
||||
Long createCard(Long userId, Long merchantId, HardTypeEnum sysType, HardOrderTypeEnum orderTYpe, List<HardCreateCarDto> list);
|
||||
|
||||
|
||||
/**
|
||||
* 生成购买商品的描述
|
||||
*
|
||||
* @param sysType 订单类型
|
||||
* @param list 购物车列表
|
||||
* @param list 购物车列表
|
||||
* @return
|
||||
*/
|
||||
String computerCarSubject(HardTypeEnum sysType, List<HardCreateCarDto> list);
|
||||
String computerCarSubject(HardTypeEnum sysType, HardOrderTypeEnum orderType, List<HardCreateCarDto> list);
|
||||
}
|
||||
+54
-32
@@ -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<HardCarMapper, HardCarEntity
|
||||
if (ObjectUtil.isNotEmpty(parentCar)) {
|
||||
baseMapper.delete(new LambdaQueryWrapper<HardCarEntity>().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<HardCreateCarDto> list) {
|
||||
public Integer computerCarTotalPrice(HardTypeEnum sysType, HardOrderTypeEnum orderType, List<HardCreateCarDto> list) {
|
||||
List<Long> productIds = list.stream().map(HardCreateCarDto::getProductId).toList();
|
||||
return switch (sysType) {
|
||||
case CANTEEN -> {
|
||||
// 查询食堂商品
|
||||
List<CanteenOnlineSpuAppVO> 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<CanteenOnlineSpuAppVO> 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<HardCarMapper, HardCarEntity
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public Long createCard(Long userId, Long merchantId, HardTypeEnum sysType, List<HardCreateCarDto> list) {
|
||||
public Long createCard(Long userId, Long merchantId, HardTypeEnum sysType, HardOrderTypeEnum orderTYpe, List<HardCreateCarDto> 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<HardCreateCarDto> productList) {
|
||||
public void appCreateCard(Long parentCarId, HardTypeEnum sysType, HardOrderTypeEnum orderType, List<HardCreateCarDto> productList) {
|
||||
List<Long> productIds = productList.stream().map(HardCreateCarDto::getProductId).toList();
|
||||
// 食堂
|
||||
if (ObjectUtil.equals(sysType, HardTypeEnum.CANTEEN)) {
|
||||
List<HardCarEntity> carObjectList = new ArrayList<>();
|
||||
List<CanteenOnlineSpuAppVO> 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<CanteenOnlineSpuAppVO> 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<HardCarMapper, HardCarEntity
|
||||
}
|
||||
|
||||
@Override
|
||||
public String computerCarSubject(HardTypeEnum sysType, List<HardCreateCarDto> list) {
|
||||
public String computerCarSubject(HardTypeEnum sysType, HardOrderTypeEnum orderType, List<HardCreateCarDto> list) {
|
||||
StringBuffer str = new StringBuffer();
|
||||
List<Long> productIds = list.stream().map(HardCreateCarDto::getProductId).toList();
|
||||
// 食堂
|
||||
if (ObjectUtil.equals(sysType, HardTypeEnum.CANTEEN)) {
|
||||
List<CanteenOnlineSpuAppVO> 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<CanteenOnlineSpuAppVO> 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<SupermarketUnitWithSpuVo> supList = supermarketUnitSkuService.getSupermarketUnits(productIds).getData();
|
||||
for (HardCreateCarDto v : list) {
|
||||
|
||||
+4
-5
@@ -171,7 +171,6 @@ public class HardwareOrderServiceImpl extends ServiceImpl<HardOrderMapper, HardO
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public Long createOrder(HardCreateOrderDto dto) {
|
||||
if (!validateCreateOrderDto(dto)) return null;
|
||||
if (!validateCodeIsCancel(dto.getOrderType(), dto.getOrderSourceTypeId())) return null;
|
||||
// 是否需要支付
|
||||
boolean isPay = isPay(dto.getOrderType(), dto.getOrderPayType());
|
||||
// 是否需要支付额外金额
|
||||
@@ -183,15 +182,15 @@ public class HardwareOrderServiceImpl extends ServiceImpl<HardOrderMapper, HardO
|
||||
wallet = Optional.of(walletResult).map(R::getData).orElseThrow(() -> 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<HardOrderMapper, HardO
|
||||
return entity;
|
||||
}).toList();
|
||||
HardTypeEnum hardType = ObjectUtil.equals(dto.getWalletType(), WalletTypeEnum.EAT) ? HardTypeEnum.CANTEEN : HardTypeEnum.SUPERMARKET;
|
||||
String subject = hardCarService.computerCarSubject(hardType, carListDto);
|
||||
String subject = hardCarService.computerCarSubject(hardType, dto.getOrderType(), carListDto);
|
||||
// 添加硬件订单
|
||||
HardOrderEntity orderObj = HardOrderEntity.builder()
|
||||
.userId(dto.getUserId())
|
||||
|
||||
+1
-1
@@ -122,7 +122,7 @@ public class MchManageController {
|
||||
@GetMapping("/{id}")
|
||||
@PreAuthorize("@pms.hasPermission('wallet_mchManage_view')")
|
||||
public R getDetail(@PathVariable("id") Long id) {
|
||||
return R.ok(mchManageService.getById(id));
|
||||
return R.ok(mchManageService.join(id));
|
||||
}
|
||||
|
||||
@Operation(summary = "新增商户管理", description = "新增商户管理")
|
||||
|
||||
+3
-2
@@ -11,6 +11,7 @@ import com.bsd.pjcloud.wallet.api.entity.MchManageEntity;
|
||||
import com.bsd.pjcloud.wallet.api.vo.MchManageVo;
|
||||
import com.bsd.pjcloud.wallet.api.vo.WalletTransactionVo;
|
||||
import com.github.yulichang.query.MPJLambdaQueryWrapper;
|
||||
import com.github.yulichang.wrapper.MPJLambdaWrapper;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
@@ -30,9 +31,9 @@ public interface MchManageMapper extends PjcloudBaseMapper<MchManageEntity> {
|
||||
}
|
||||
|
||||
default MchManageVo join(Long id) {
|
||||
MPJLambdaQueryWrapper<MchManageEntity> wrapper = new MPJLambdaQueryWrapper<MchManageEntity>()
|
||||
MPJLambdaWrapper<MchManageEntity> wrapper = new MPJLambdaWrapper<MchManageEntity>()
|
||||
.selectAll(MchManageEntity.class)
|
||||
.eq(MchManageEntity::getId, id);
|
||||
.eqIfExists(MchManageEntity::getId, id);
|
||||
return selectJoinOne(MchManageVo.class, wrapper);
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user