feat:商家设置默认使用的钱包

This commit is contained in:
dzc committed 2025-03-10 15:12:58 +08:00
1 parent c83cd8848a
commit 47fd0aec1d
3 files changed
+26 -13

No files matched your search

@@ -209,25 +209,24 @@ public class HardOrderServiceImpl extends ServiceImpl<HardOrderMapper, HardOrder
// @GlobalTransactional
@Transactional(rollbackFor = Exception.class)
public Long createOrder(HardCreateOrderDto dto) {
if (!validateCreateOrderDto(dto)) return null;
MchManageVo mch = validateCreateOrderDto(dto);
if (ObjectUtil.isEmpty(mch)) throw new RuntimeException("机器绑定的商户不存在");
// 是否需要支付
boolean isPay = isPay(dto.getOrderType(), dto.getOrderPayType());
// 是否需要支付额外金额
boolean isExtraPrice = isExtraPrice(dto.getSysType());
// 饭卡钱包
// 默认使用该商户的钱包如果没有就用饭卡钱包
WalletManageEntity wallet = null;
if (isPay) {
if (ObjectUtil.equals(dto.getOrderPayType(), HardPayTypeEnum.WALLET_QR_CODE)) {
if (ObjectUtil.isEmpty(dto.getWalletId())) throw new RuntimeException("钱包二维码支付错误");
R<WalletManageVo> walletResult = remoteWalletService.getWalletById(dto.getWalletId());
WalletManageVo walletVo = Optional.of(walletResult).map(R::getData).orElseThrow(() -> new RuntimeException("用户钱包不存在"));
if (!ObjectUtil.equals(walletVo.getWalletTypeUniqueCode(), WalletTypeEnum.EAT.getCode())) {
throw new RuntimeException("请使用钱包二维码支付");
}
wallet = walletVo;
} else {
if (ObjectUtil.isNotEmpty(mch.getDefaultWalletTypeId())) {
R<WalletManageEntity> walletResult = remoteWalletService.getWallet(dto.getUserId(), WalletTypeEnum.EAT);
wallet = Optional.of(walletResult).map(R::getData).orElseThrow(() -> new RuntimeException("用户钱包不存在"));
} else {
R<WalletManageEntity> walletResult = remoteWalletService.getWalletByWalletTypeId(dto.getUserId(), mch.getDefaultWalletTypeId());
wallet = Optional.of(walletResult).map(R::getData).orElseThrow(() -> new RuntimeException("用户钱包不存在"));
}
if (ObjectUtil.isEmpty(wallet)) {
throw new RuntimeException("用户钱包不存在");
}
}
int totalPrice = 0, extraPrice = 0, payPrice = 0;
@@ -523,7 +522,7 @@ public class HardOrderServiceImpl extends ServiceImpl<HardOrderMapper, HardOrder
return ObjectUtil.equals(hardType, HardTypeEnum.CANTEEN);
}
private boolean validateCreateOrderDto(HardCreateOrderDto dto) {
private MchManageVo validateCreateOrderDto(HardCreateOrderDto dto) {
R<MchManageVo> mch = remoteMchService.getById(dto.getMerchantId());
if (ObjectUtil.isEmpty(mch.getData())) {
throw new RuntimeException("商户不存在");
@@ -533,7 +532,7 @@ public class HardOrderServiceImpl extends ServiceImpl<HardOrderMapper, HardOrder
throw new RuntimeException("设备不存在");
}
dto.setDeptId(hard.getDeptId());
return true;
return mch.getData();
}
// 是否有二维码
@@ -24,6 +24,10 @@ public interface RemoteWalletService {
@GetMapping("/wallet-manage/get-wallet")
R<WalletManageEntity> getWallet(@RequestParam Long userId, @RequestParam WalletTypeEnum walletTypeCode);
@NoToken
@GetMapping("/wallet-manage/get-wallet-by-wallet-id")
R<WalletManageEntity> getWalletByWalletTypeId(@RequestParam Long userId, @RequestParam Long walletTypeId);
@NoToken
@GetMapping("/wallet-manage/get-wallet-by-id")
R<WalletManageVo> getWalletById(@RequestParam Long walletId);
@@ -61,6 +61,16 @@ public class WalletManageController {
return R.ok(wallet);
}
@Inner
@GetMapping("/get-wallet-by-wallet-id")
public R getWalletByWalletTypeId(@RequestParam Long userId, @RequestParam Long walletTypeId) {
WalletManageEntity wallet = walletManageService.getWallet(userId, walletTypeId);
if (ObjectUtil.isEmpty(wallet)) {
return R.failed("用户钱包不存在");
}
return R.ok(wallet);
}
@Inner
@GetMapping("/create-wallet")
public R getWallet(@RequestParam Long userId) {