11
This commit is contained in:
1 parent
d6d36d689f
commit
fdf6dc8072
12 files changed
+79
-38
No files matched your search
+1
-1
@@ -53,7 +53,7 @@ public interface HardOrderService extends IService<HardOrderEntity> {
|
||||
void generateCode(HardOrderEntity order);
|
||||
|
||||
/**
|
||||
* 扣件库存
|
||||
* 扣减库存
|
||||
*/
|
||||
void fastenerInventory(HardOrderEntity order);
|
||||
|
||||
|
||||
+52
-12
@@ -10,6 +10,9 @@ import com.bsd.pjcloud.admin.api.entity.SysUser;
|
||||
import com.bsd.pjcloud.admin.api.feign.RemoteDeptService;
|
||||
import com.bsd.pjcloud.admin.api.feign.RemoteUserService;
|
||||
import com.bsd.pjcloud.admin.api.utils.DataUtil;
|
||||
import com.bsd.pjcloud.canteen.api.feign.RemoteCanteenSpuService;
|
||||
import com.bsd.pjcloud.canteen.api.feign.RemoteOnlineCanteenSpuService;
|
||||
import com.bsd.pjcloud.canteen.dto.CanteenSpuUpdateStockReqDTO;
|
||||
import com.bsd.pjcloud.common.core.constant.enums.YesNoEnum;
|
||||
import com.bsd.pjcloud.common.core.util.BeanUtils;
|
||||
import com.bsd.pjcloud.common.core.util.CollectionUtils;
|
||||
@@ -36,6 +39,9 @@ import com.bsd.pjcloud.hard.mapper.order.HardOrderMapper;
|
||||
import com.bsd.pjcloud.hard.service.HardCarService;
|
||||
import com.bsd.pjcloud.hard.service.HardManagerService;
|
||||
import com.bsd.pjcloud.hard.service.HardOrderService;
|
||||
import com.bsd.pjcloud.supermarket.api.feign.RemoteSupermarketSpuService;
|
||||
import com.bsd.pjcloud.supermarket.api.feign.RemoteSupermarketUnitSkuService;
|
||||
import com.bsd.pjcloud.supermarket.dto.SupermarketSpuUpdateStockReqDTO;
|
||||
import com.bsd.pjcloud.wallet.api.constant.WalletBizEnum;
|
||||
import com.bsd.pjcloud.wallet.api.constant.WalletCodeBizEnum;
|
||||
import com.bsd.pjcloud.wallet.api.constant.WalletTypeEnum;
|
||||
@@ -89,6 +95,9 @@ public class HardwareOrderServiceImpl extends ServiceImpl<HardOrderMapper, HardO
|
||||
private final RemoteUserService userService;
|
||||
private final RemoteDeptService deptService;
|
||||
|
||||
private final RemoteOnlineCanteenSpuService onlineCanteenSpuService;
|
||||
private final RemoteSupermarketSpuService supermarketSpuService;
|
||||
|
||||
private final HardManagerMapper hardManagerMapper;
|
||||
|
||||
@Override
|
||||
@@ -234,6 +243,7 @@ public class HardwareOrderServiceImpl extends ServiceImpl<HardOrderMapper, HardO
|
||||
}
|
||||
|
||||
@Override
|
||||
@GlobalTransactional
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public Long appCreateOrder(@Valid HardAppCreateOrderDto dto) {
|
||||
// 钱包
|
||||
@@ -284,12 +294,13 @@ public class HardwareOrderServiceImpl extends ServiceImpl<HardOrderMapper, HardO
|
||||
// 钱包扣款
|
||||
if (isPay) getSelf().fastReduceBalance(orderObj);
|
||||
// 是否需要创建二维码
|
||||
generateCode(orderObj);
|
||||
getSelf().generateCode(orderObj);
|
||||
// 扣减库存
|
||||
getSelf().fastenerInventory(orderObj);
|
||||
return orderObj.getId();
|
||||
}
|
||||
|
||||
@Override
|
||||
@GlobalTransactional
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void fastReduceBalance(HardOrderEntity order) {
|
||||
boolean isPay = isPay(HardOrderTypeEnum.valueOfByType(order.getOrderType()), HardPayTypeEnum.valueOfByType(order.getPayType()));
|
||||
@@ -298,7 +309,11 @@ public class HardwareOrderServiceImpl extends ServiceImpl<HardOrderMapper, HardO
|
||||
reduceBuild.setPrice(order.getPayPrice());
|
||||
reduceBuild.setBizId(String.valueOf(order.getId()));
|
||||
reduceBuild.setBizType(WalletBizEnum.PAYMENT);
|
||||
WalletTransactionEntity walletTransaction = walletTransactionService.reduceWalletBalance(reduceBuild).getData();
|
||||
R<WalletTransactionEntity> reduceRes = walletTransactionService.reduceWalletBalance(reduceBuild);
|
||||
if (reduceRes.getCode() != 0 || ObjectUtil.isEmpty(reduceRes.getData())) {
|
||||
throw new RuntimeException("钱包扣款错误");
|
||||
}
|
||||
WalletTransactionEntity walletTransaction = reduceRes.getData();
|
||||
if (ObjectUtil.isNotEmpty(walletTransaction)) {
|
||||
// 订单表订单状态
|
||||
Integer payPrice = isPay ? order.getTotalPrice() + order.getExtraPrice() : 0;
|
||||
@@ -307,10 +322,6 @@ public class HardwareOrderServiceImpl extends ServiceImpl<HardOrderMapper, HardO
|
||||
// 父购物车订单表订单状态
|
||||
HardParentCarEntity updateParentCar = HardParentCarEntity.builder().id(order.getParentCarId()).orderStatus(HardOrderStatusEnum.PAY.getType()).build();
|
||||
hardParentCarServiceImpl.updateById(updateParentCar);
|
||||
// 核销二维码
|
||||
cancelCode(order);
|
||||
// 扣件库存
|
||||
fastenerInventory(order);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -367,7 +378,6 @@ public class HardwareOrderServiceImpl extends ServiceImpl<HardOrderMapper, HardO
|
||||
}
|
||||
|
||||
@Override
|
||||
@GlobalTransactional
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void generateCode(HardOrderEntity order) {
|
||||
HardTypeEnum hardTypeEnum = HardTypeEnum.valueOfByType(order.getSysType());
|
||||
@@ -383,11 +393,13 @@ public class HardwareOrderServiceImpl extends ServiceImpl<HardOrderMapper, HardO
|
||||
codeType = WalletCodeBizEnum.SUPERMARKET_RESERVE;
|
||||
}
|
||||
if (ObjectUtil.isEmpty(codeType)) return;
|
||||
remoteCodeUseService.generateCode(order.getId(), order.getUserId(), codeType, 1);
|
||||
R<Boolean> res = remoteCodeUseService.generateCode(order.getId(), order.getUserId(), codeType, 1);
|
||||
if (res.getCode() != 0 || !res.getData()) {
|
||||
throw new RuntimeException("生成预约二维码错误");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@GlobalTransactional
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void fastenerInventory(HardOrderEntity order) {
|
||||
HardTypeEnum hardTypeEnum = HardTypeEnum.valueOfByType(order.getSysType());
|
||||
@@ -395,12 +407,40 @@ public class HardwareOrderServiceImpl extends ServiceImpl<HardOrderMapper, HardO
|
||||
if (!ObjectUtil.isAllNotEmpty(hardTypeEnum, orderTypeEnum)) return;
|
||||
// 食堂扣件库存
|
||||
if (ObjectUtil.equals(hardTypeEnum, HardTypeEnum.CANTEEN) && ObjectUtil.equals(orderTypeEnum, HardOrderTypeEnum.RESERVE)) {
|
||||
|
||||
// 查询购物车
|
||||
List<HardCarEntity> carList = hardCarService.getByParentCarId(order.getParentCarId());
|
||||
if (ObjectUtil.isEmpty(carList)) throw new RuntimeException("扣减库存错误,购物车不存在");
|
||||
CanteenSpuUpdateStockReqDTO dto = new CanteenSpuUpdateStockReqDTO();
|
||||
List<CanteenSpuUpdateStockReqDTO.Item> list = carList.stream().map(v -> {
|
||||
CanteenSpuUpdateStockReqDTO.Item item = new CanteenSpuUpdateStockReqDTO.Item();
|
||||
item.setId(v.getProductId());
|
||||
item.setIncrCount(v.getProductCount());
|
||||
return item;
|
||||
}).toList();
|
||||
dto.setItems(list);
|
||||
R updateSkuStockRes = onlineCanteenSpuService.updateSkuStock(dto);
|
||||
if (updateSkuStockRes.getCode() != 0) {
|
||||
throw new RuntimeException("库存不足");
|
||||
}
|
||||
return;
|
||||
}
|
||||
// 超市扣家库存
|
||||
if (ObjectUtil.equals(hardTypeEnum, HardTypeEnum.SUPERMARKET) && ObjectUtil.equals(orderTypeEnum, HardOrderTypeEnum.RESERVE)) {
|
||||
|
||||
// 查询购物车
|
||||
List<HardCarEntity> carList = hardCarService.getByParentCarId(order.getParentCarId());
|
||||
if (ObjectUtil.isEmpty(carList)) throw new RuntimeException("扣减库存错误,购物车不存在");
|
||||
SupermarketSpuUpdateStockReqDTO dto = new SupermarketSpuUpdateStockReqDTO();
|
||||
List<SupermarketSpuUpdateStockReqDTO.Item> list = carList.stream().map(v -> {
|
||||
SupermarketSpuUpdateStockReqDTO.Item item = new SupermarketSpuUpdateStockReqDTO.Item();
|
||||
item.setId(v.getProductId());
|
||||
item.setIncrCount(v.getProductCount());
|
||||
return item;
|
||||
}).toList();
|
||||
dto.setItems(list);
|
||||
R updateSkuStockRes = supermarketSpuService.updateSpuStock(dto);
|
||||
if (updateSkuStockRes.getCode() != 0) {
|
||||
throw new RuntimeException("扣件库存错误");
|
||||
}
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user