Browse Source

20260318 添加到账地区与钱包的校验

milestone-20260224-现金钱包
wangguorui 3 weeks ago
parent
commit
58af4e12a1
  1. 55
      src/main/java/com/example/demo/serviceImpl/cash/CashCollectionServiceImpl.java

55
src/main/java/com/example/demo/serviceImpl/cash/CashCollectionServiceImpl.java

@ -62,7 +62,7 @@ public class CashCollectionServiceImpl implements CashCollectionService {
throw new IllegalArgumentException("精网号不能为空"); throw new IllegalArgumentException("精网号不能为空");
} }
if (cashCollection.getJwcode() < 10000000 || cashCollection.getJwcode() > 99999999) { if (cashCollection.getJwcode() < 10000000 || cashCollection.getJwcode() > 99999999) {
throw new IllegalArgumentException("精网号必须为8位");
throw new IllegalArgumentException("精网号必须为 8 位");
} }
if (cashCollection.getName() == null || cashCollection.getName().isEmpty()){ if (cashCollection.getName() == null || cashCollection.getName().isEmpty()){
throw new IllegalArgumentException("客户姓名不能为空"); throw new IllegalArgumentException("客户姓名不能为空");
@ -78,7 +78,7 @@ public class CashCollectionServiceImpl implements CashCollectionService {
throw new IllegalArgumentException("金币数量不能为空"); throw new IllegalArgumentException("金币数量不能为空");
} }
if (cashCollection.getWalletId() == null || cashCollection.getWalletId() < 1 || cashCollection.getWalletId() > 10) { if (cashCollection.getWalletId() == null || cashCollection.getWalletId() < 1 || cashCollection.getWalletId() > 10) {
throw new IllegalArgumentException("钱包ID为1~10");
throw new IllegalArgumentException("钱包 ID 1~10");
} }
} }
if (!cashCollection.getGoodsName().equals("金币充值")) { if (!cashCollection.getGoodsName().equals("金币充值")) {
@ -104,6 +104,10 @@ public class CashCollectionServiceImpl implements CashCollectionService {
if (cashCollection.getPayTime() == null) { if (cashCollection.getPayTime() == null) {
throw new IllegalArgumentException("付款时间不能为空"); throw new IllegalArgumentException("付款时间不能为空");
} }
// 校验钱包 ID 和到账地区的对应关系
validateWalletAndMarket(cashCollection.getWalletId(), cashCollection.getReceivedMarket());
//生成订单号后半部分 //生成订单号后半部分
String orderNumber = UUID.randomUUID().toString().replaceAll("-", ""); String orderNumber = UUID.randomUUID().toString().replaceAll("-", "");
CashRecord cashRecord = new CashRecord(); CashRecord cashRecord = new CashRecord();
@ -130,7 +134,7 @@ public class CashCollectionServiceImpl implements CashCollectionService {
cashRecord.setSubmitterMarket(cashCollection.getSubmitterMarket()); cashRecord.setSubmitterMarket(cashCollection.getSubmitterMarket());
cashRecord.setOrderType(1); //订单类型1-收款 cashRecord.setOrderType(1); //订单类型1-收款
cashRecord.setMarket(cashCollection.getMarket()); cashRecord.setMarket(cashCollection.getMarket());
//地区根据jwcode插入
//地区根据 jwcode 插入
//cashRecord.setMarket(cashCollectionMapper.getMarketByJwcode(cashRecord.getJwcode())); //cashRecord.setMarket(cashCollectionMapper.getMarketByJwcode(cashRecord.getJwcode()));
//插入新收款订单 //插入新收款订单
cashCollectionMapper.add(cashRecord); cashCollectionMapper.add(cashRecord);
@ -248,7 +252,7 @@ public class CashCollectionServiceImpl implements CashCollectionService {
throw new IllegalArgumentException("精网号不能为空"); throw new IllegalArgumentException("精网号不能为空");
} }
if (cashRecord.getJwcode() < 10000000 || cashRecord.getJwcode() > 99999999) { if (cashRecord.getJwcode() < 10000000 || cashRecord.getJwcode() > 99999999) {
throw new IllegalArgumentException("精网号必须为8位");
throw new IllegalArgumentException("精网号必须为 8 位");
} }
if (cashRecord.getName() == null) { if (cashRecord.getName() == null) {
throw new IllegalArgumentException("客户姓名不能为空"); throw new IllegalArgumentException("客户姓名不能为空");
@ -266,7 +270,7 @@ public class CashCollectionServiceImpl implements CashCollectionService {
throw new IllegalArgumentException("永久金币数量不能为空"); throw new IllegalArgumentException("永久金币数量不能为空");
} }
if (cashRecord.getWalletId() == null) { if (cashRecord.getWalletId() == null) {
throw new IllegalArgumentException("钱包ID不能为空");
throw new IllegalArgumentException("钱包 ID 不能为空");
} }
} }
if (!cashRecord.getGoodsName().equals("金币充值")) { if (!cashRecord.getGoodsName().equals("金币充值")) {
@ -293,11 +297,14 @@ public class CashCollectionServiceImpl implements CashCollectionService {
throw new IllegalArgumentException("付款时间不能为空"); throw new IllegalArgumentException("付款时间不能为空");
} }
// 校验钱包 ID 和到账地区的对应关系
validateWalletAndMarket(cashRecord.getWalletId(), cashRecord.getReceivedMarket());
CashRecord status = cashCollectionMapper.selectByOrderCode(cashRecord.getOrderCode()); CashRecord status = cashCollectionMapper.selectByOrderCode(cashRecord.getOrderCode());
if (!status.getStatus().equals(5)) { if (!status.getStatus().equals(5)) {
throw new IllegalArgumentException("只允许编辑已撤回订单"); throw new IllegalArgumentException("只允许编辑已撤回订单");
} }
//地区根据jwcode插入弃用插入前调用接口获取地区和姓名之后前端传入
//地区根据 jwcode 插入弃用插入前调用接口获取地区和姓名之后前端传入
//cashRecord.setMarket(cashCollectionMapper.getMarketByJwcode(cashRecord.getJwcode())); //cashRecord.setMarket(cashCollectionMapper.getMarketByJwcode(cashRecord.getJwcode()));
int rows = cashCollectionMapper.updateByOrderCode(cashRecord); int rows = cashCollectionMapper.updateByOrderCode(cashRecord);
if (rows > 0) { if (rows > 0) {
@ -665,4 +672,40 @@ public class CashCollectionServiceImpl implements CashCollectionService {
return resultPageInfo; return resultPageInfo;
} }
/**
* 校验钱包 ID 和到账地区的对应关系
* @param walletId 钱包 ID
* @param receivedMarket 到账地区 ID
*/
private void validateWalletAndMarket(Integer walletId, String receivedMarket) {
if (walletId == null) {
return; // 非金币充值不需要校验
}
Map<Integer, String> walletMarketMap = new HashMap<>();
walletMarketMap.put(2, "13"); // 香港
walletMarketMap.put(3, "4"); // 新加坡 HC
walletMarketMap.put(4, "5"); // 马来西亚
walletMarketMap.put(5, "4"); // 新加坡 CM
walletMarketMap.put(6, "24016"); // 加拿大
walletMarketMap.put(7, "24018"); // 泰国 HS
walletMarketMap.put(8, "24018"); // 泰国 HA
walletMarketMap.put(9, "24022"); // 越南 HCM
walletMarketMap.put(10, "24033");// 北京
// 钱包 ID=1 为历史钱包无限制不需要校验
if (walletId == 1) {
return;
}
String expectedMarket = walletMarketMap.get(walletId);
if (expectedMarket == null) {
throw new IllegalArgumentException("无效的钱包 ID: " + walletId);
}
if (!expectedMarket.equals(receivedMarket)) {
String marketName = marketMapper.getMarketNameById(expectedMarket);
throw new IllegalArgumentException("钱包 ID=" + walletId + " 对应的到账地区应为:" + marketName + "(" + expectedMarket + ")");
}
}
} }
Loading…
Cancel
Save