|
@@ -1,18 +1,16 @@
|
|
|
-package com.zhongshu.payment.server.core.service.impl;
|
|
|
|
|
|
|
+package com.zhongshu.payment.server.core.service.pay.impl.wallet;
|
|
|
|
|
|
|
|
|
|
+import com.github.microservice.net.ResultContent;
|
|
|
import com.zhongshu.payment.client.model.WalletModel;
|
|
import com.zhongshu.payment.client.model.WalletModel;
|
|
|
import com.zhongshu.payment.client.model.param.AmountUpdateParam;
|
|
import com.zhongshu.payment.client.model.param.AmountUpdateParam;
|
|
|
-import com.github.microservice.net.ResultContent;
|
|
|
|
|
|
|
+import com.zhongshu.payment.client.model.param.WalletQueryParam;
|
|
|
import com.zhongshu.payment.client.service.WalletFeignService;
|
|
import com.zhongshu.payment.client.service.WalletFeignService;
|
|
|
import com.zhongshu.payment.client.types.TradeType;
|
|
import com.zhongshu.payment.client.types.TradeType;
|
|
|
-import com.zhongshu.payment.client.types.WalletState;
|
|
|
|
|
import com.zhongshu.payment.client.types.WalletType;
|
|
import com.zhongshu.payment.client.types.WalletType;
|
|
|
import com.zhongshu.payment.server.core.dao.WalletDao;
|
|
import com.zhongshu.payment.server.core.dao.WalletDao;
|
|
|
import com.zhongshu.payment.server.core.dao.WalletFlowDao;
|
|
import com.zhongshu.payment.server.core.dao.WalletFlowDao;
|
|
|
import com.zhongshu.payment.server.core.domain.wallet.Wallet;
|
|
import com.zhongshu.payment.server.core.domain.wallet.Wallet;
|
|
|
import com.zhongshu.payment.server.core.domain.wallet.WalletFlow;
|
|
import com.zhongshu.payment.server.core.domain.wallet.WalletFlow;
|
|
|
-import com.zhongshu.payment.server.core.utils.BeanUtils;
|
|
|
|
|
-import org.jetbrains.annotations.NotNull;
|
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
@@ -32,43 +30,30 @@ public class WalletFeignServiceImpl implements WalletFeignService {
|
|
|
@Autowired
|
|
@Autowired
|
|
|
WalletFlowDao walletFlowDao;
|
|
WalletFlowDao walletFlowDao;
|
|
|
|
|
|
|
|
|
|
+ @Autowired
|
|
|
|
|
+ WalletService walletService;
|
|
|
|
|
|
|
|
@Override
|
|
@Override
|
|
|
public ResultContent<WalletModel> getWallet(String oid, WalletType walletType, String shopId, String userId) {
|
|
public ResultContent<WalletModel> getWallet(String oid, WalletType walletType, String shopId, String userId) {
|
|
|
-
|
|
|
|
|
- return ResultContent.buildContent(toModel(findWallet(oid, walletType, shopId, userId)));
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- @NotNull
|
|
|
|
|
- private Wallet findWallet(String oid, @NotNull WalletType walletType, String shopId, String userId){
|
|
|
|
|
- Wallet findWallet = null;;
|
|
|
|
|
- Wallet wallet = new Wallet();;
|
|
|
|
|
- if (walletType.equals(WalletType.User)){
|
|
|
|
|
- findWallet = walletDao.findByUserIdAndOidAndWalletType(userId, oid, walletType);
|
|
|
|
|
- wallet.setUserId(userId);
|
|
|
|
|
- }
|
|
|
|
|
- if (walletType.equals(WalletType.Shop)){
|
|
|
|
|
- findWallet = walletDao.findByShopIdAndOidAndWalletType(shopId, oid, walletType);
|
|
|
|
|
- wallet.setShopId(shopId);
|
|
|
|
|
- }
|
|
|
|
|
- if (findWallet!=null){
|
|
|
|
|
- return findWallet;
|
|
|
|
|
- }
|
|
|
|
|
- wallet.setOid(oid);
|
|
|
|
|
- wallet.setAmount(BigDecimal.ZERO);
|
|
|
|
|
- wallet.setAmount(BigDecimal.ZERO);
|
|
|
|
|
- wallet.setDataState(WalletState.Enable);
|
|
|
|
|
- wallet.setWalletType(walletType);
|
|
|
|
|
- walletDao.save(wallet);
|
|
|
|
|
- return wallet;
|
|
|
|
|
|
|
+ WalletQueryParam param = new WalletQueryParam();
|
|
|
|
|
+ param.setProjectOid(oid);
|
|
|
|
|
+ param.setWalletType(walletType);
|
|
|
|
|
+ param.setShopId(shopId);
|
|
|
|
|
+ param.setUserId(userId);
|
|
|
|
|
+ return walletService.getWallet(param);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-
|
|
|
|
|
- /** 充值 */
|
|
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 充值
|
|
|
|
|
+ */
|
|
|
@Override
|
|
@Override
|
|
|
@Transactional
|
|
@Transactional
|
|
|
- public ResultContent recharge(AmountUpdateParam param){
|
|
|
|
|
- Wallet wallet = findWallet(param.getOid(), WalletType.User, param.getShopId(), param.getUserId());
|
|
|
|
|
|
|
+ public ResultContent recharge(AmountUpdateParam param) {
|
|
|
|
|
+ WalletQueryParam queryParam = WalletQueryParam.builder().projectOid(param.getOid())
|
|
|
|
|
+ .walletType(WalletType.User)
|
|
|
|
|
+ .userId(param.getUserId())
|
|
|
|
|
+ .shopId(param.getShopId()).build();
|
|
|
|
|
+ Wallet wallet = walletService.findWallet(queryParam);
|
|
|
wallet.setAmount(wallet.getAmount().add(param.getTotal()));
|
|
wallet.setAmount(wallet.getAmount().add(param.getTotal()));
|
|
|
wallet.setTotalAmount(wallet.getTotalAmount().add(param.getTotal()));
|
|
wallet.setTotalAmount(wallet.getTotalAmount().add(param.getTotal()));
|
|
|
walletDao.save(wallet);
|
|
walletDao.save(wallet);
|
|
@@ -76,16 +61,22 @@ public class WalletFeignServiceImpl implements WalletFeignService {
|
|
|
return ResultContent.buildSuccess();
|
|
return ResultContent.buildSuccess();
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- /** 消费 */
|
|
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 消费
|
|
|
|
|
+ */
|
|
|
@Override
|
|
@Override
|
|
|
@Transactional
|
|
@Transactional
|
|
|
- public ResultContent consume(AmountUpdateParam param){
|
|
|
|
|
- Wallet userWallet = findWallet(param.getOid(), WalletType.User, param.getShopId(), param.getUserId());
|
|
|
|
|
|
|
+ public ResultContent consume(AmountUpdateParam param) {
|
|
|
|
|
+ WalletQueryParam queryParam = WalletQueryParam.builder().projectOid(param.getOid())
|
|
|
|
|
+ .walletType(WalletType.User)
|
|
|
|
|
+ .userId(param.getUserId())
|
|
|
|
|
+ .shopId(param.getShopId()).build();
|
|
|
|
|
+ Wallet userWallet = walletService.findWallet(queryParam);
|
|
|
|
|
|
|
|
- if (userWallet.getAmount().compareTo(param.getTotal()) < 0 ){
|
|
|
|
|
|
|
+ if (userWallet.getAmount().compareTo(param.getTotal()) < 0) {
|
|
|
return ResultContent.buildFail("可用余额不足");
|
|
return ResultContent.buildFail("可用余额不足");
|
|
|
}
|
|
}
|
|
|
- if (userWallet.getTotalAmount().compareTo(param.getTotal()) < 0 ){
|
|
|
|
|
|
|
+ if (userWallet.getTotalAmount().compareTo(param.getTotal()) < 0) {
|
|
|
return ResultContent.buildFail("总额不足");
|
|
return ResultContent.buildFail("总额不足");
|
|
|
}
|
|
}
|
|
|
userWallet.setAmount(userWallet.getAmount().subtract(param.getTotal()));
|
|
userWallet.setAmount(userWallet.getAmount().subtract(param.getTotal()));
|
|
@@ -93,7 +84,12 @@ public class WalletFeignServiceImpl implements WalletFeignService {
|
|
|
walletDao.save(userWallet);
|
|
walletDao.save(userWallet);
|
|
|
createWalletFlow(userWallet.getId(), param.getTotal(), param.getOutTradeNo(), TradeType.Pay, param.getAttach(), param.getSchoolId());
|
|
createWalletFlow(userWallet.getId(), param.getTotal(), param.getOutTradeNo(), TradeType.Pay, param.getAttach(), param.getSchoolId());
|
|
|
|
|
|
|
|
- Wallet shopWallet = findWallet(param.getOid(), WalletType.Shop, param.getShopId(), param.getUserId());
|
|
|
|
|
|
|
+ WalletQueryParam shopQuery = WalletQueryParam.builder().projectOid(param.getOid())
|
|
|
|
|
+ .walletType(WalletType.Shop)
|
|
|
|
|
+ .userId(param.getUserId())
|
|
|
|
|
+ .shopId(param.getShopId()).build();
|
|
|
|
|
+
|
|
|
|
|
+ Wallet shopWallet = walletService.findWallet(shopQuery);
|
|
|
shopWallet.setAmount(shopWallet.getAmount().add(param.getTotal()));
|
|
shopWallet.setAmount(shopWallet.getAmount().add(param.getTotal()));
|
|
|
shopWallet.setTotalAmount(shopWallet.getTotalAmount().add(param.getTotal()));
|
|
shopWallet.setTotalAmount(shopWallet.getTotalAmount().add(param.getTotal()));
|
|
|
walletDao.save(shopWallet);
|
|
walletDao.save(shopWallet);
|
|
@@ -130,15 +126,21 @@ public class WalletFeignServiceImpl implements WalletFeignService {
|
|
|
// return ResultContent.buildSuccess();
|
|
// return ResultContent.buildSuccess();
|
|
|
// }
|
|
// }
|
|
|
|
|
|
|
|
- /** 退款 */
|
|
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 退款
|
|
|
|
|
+ */
|
|
|
@Transactional
|
|
@Transactional
|
|
|
- public ResultContent refund(AmountUpdateParam param){
|
|
|
|
|
- Wallet shopWallet = findWallet(param.getOid(), WalletType.Shop, param.getShopId(), param.getUserId());
|
|
|
|
|
|
|
+ public ResultContent refund(AmountUpdateParam param) {
|
|
|
|
|
+ WalletQueryParam shopQuery = WalletQueryParam.builder().projectOid(param.getOid())
|
|
|
|
|
+ .walletType(WalletType.Shop)
|
|
|
|
|
+ .userId(param.getUserId())
|
|
|
|
|
+ .shopId(param.getShopId()).build();
|
|
|
|
|
+ Wallet shopWallet = walletService.findWallet(shopQuery);
|
|
|
|
|
|
|
|
BigDecimal amount = shopWallet.getAmount();
|
|
BigDecimal amount = shopWallet.getAmount();
|
|
|
// //加上冻结金额
|
|
// //加上冻结金额
|
|
|
// BigDecimal _amount = amount.add(param.getTotal());
|
|
// BigDecimal _amount = amount.add(param.getTotal());
|
|
|
- if (amount.compareTo(param.getTotal()) < 0 ){
|
|
|
|
|
|
|
+ if (amount.compareTo(param.getTotal()) < 0) {
|
|
|
return ResultContent.buildFail("可用余额不足");
|
|
return ResultContent.buildFail("可用余额不足");
|
|
|
}
|
|
}
|
|
|
shopWallet.setAmount(shopWallet.getAmount().subtract(param.getTotal()));
|
|
shopWallet.setAmount(shopWallet.getAmount().subtract(param.getTotal()));
|
|
@@ -146,7 +148,11 @@ public class WalletFeignServiceImpl implements WalletFeignService {
|
|
|
walletDao.save(shopWallet);
|
|
walletDao.save(shopWallet);
|
|
|
createWalletFlow(shopWallet.getId(), param.getTotal(), param.getOutTradeNo(), TradeType.Refund, param.getAttach(), param.getSchoolId());
|
|
createWalletFlow(shopWallet.getId(), param.getTotal(), param.getOutTradeNo(), TradeType.Refund, param.getAttach(), param.getSchoolId());
|
|
|
|
|
|
|
|
- Wallet userWallet = findWallet(param.getOid(), WalletType.User, param.getShopId(), param.getUserId());
|
|
|
|
|
|
|
+ WalletQueryParam userQuery = WalletQueryParam.builder().projectOid(param.getOid())
|
|
|
|
|
+ .walletType(WalletType.User)
|
|
|
|
|
+ .userId(param.getUserId())
|
|
|
|
|
+ .shopId(param.getShopId()).build();
|
|
|
|
|
+ Wallet userWallet = walletService.findWallet(userQuery);
|
|
|
userWallet.setAmount(userWallet.getAmount().add(param.getTotal()));
|
|
userWallet.setAmount(userWallet.getAmount().add(param.getTotal()));
|
|
|
userWallet.setTotalAmount(userWallet.getTotalAmount().add(param.getTotal()));
|
|
userWallet.setTotalAmount(userWallet.getTotalAmount().add(param.getTotal()));
|
|
|
walletDao.save(userWallet);
|
|
walletDao.save(userWallet);
|
|
@@ -154,14 +160,20 @@ public class WalletFeignServiceImpl implements WalletFeignService {
|
|
|
return ResultContent.buildSuccess();
|
|
return ResultContent.buildSuccess();
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- /** 用户发起提现 */
|
|
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 用户发起提现
|
|
|
|
|
+ */
|
|
|
@Transactional
|
|
@Transactional
|
|
|
- public ResultContent commitTake(AmountUpdateParam param){
|
|
|
|
|
- Wallet userWallet = findWallet(param.getOid(), WalletType.User, param.getShopId(), param.getUserId());
|
|
|
|
|
- if (userWallet.getAmount().compareTo(param.getTotal()) < 0 ){
|
|
|
|
|
|
|
+ public ResultContent commitTake(AmountUpdateParam param) {
|
|
|
|
|
+ WalletQueryParam userQuery = WalletQueryParam.builder().projectOid(param.getOid())
|
|
|
|
|
+ .walletType(WalletType.User)
|
|
|
|
|
+ .userId(param.getUserId())
|
|
|
|
|
+ .shopId(param.getShopId()).build();
|
|
|
|
|
+ Wallet userWallet = walletService.findWallet(userQuery);
|
|
|
|
|
+ if (userWallet.getAmount().compareTo(param.getTotal()) < 0) {
|
|
|
return ResultContent.buildFail("可用余额不足");
|
|
return ResultContent.buildFail("可用余额不足");
|
|
|
}
|
|
}
|
|
|
- if (userWallet.getTotalAmount().compareTo(param.getTotal()) < 0 ){
|
|
|
|
|
|
|
+ if (userWallet.getTotalAmount().compareTo(param.getTotal()) < 0) {
|
|
|
return ResultContent.buildFail("总额不足");
|
|
return ResultContent.buildFail("总额不足");
|
|
|
}
|
|
}
|
|
|
userWallet.setAmount(userWallet.getAmount().subtract(param.getTotal()));
|
|
userWallet.setAmount(userWallet.getAmount().subtract(param.getTotal()));
|
|
@@ -171,17 +183,27 @@ public class WalletFeignServiceImpl implements WalletFeignService {
|
|
|
return ResultContent.buildSuccess();
|
|
return ResultContent.buildSuccess();
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- /** 用户提现(审批失败) */
|
|
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 用户提现(审批失败)
|
|
|
|
|
+ */
|
|
|
@Transactional
|
|
@Transactional
|
|
|
- public ResultContent failTake(AmountUpdateParam param){
|
|
|
|
|
- Wallet userWallet = findWallet(param.getOid(), WalletType.User, param.getShopId(), param.getUserId());
|
|
|
|
|
|
|
+ public ResultContent failTake(AmountUpdateParam param) {
|
|
|
|
|
+ WalletQueryParam userQuery = WalletQueryParam.builder().projectOid(param.getOid())
|
|
|
|
|
+ .walletType(WalletType.User)
|
|
|
|
|
+ .userId(param.getUserId())
|
|
|
|
|
+ .shopId(param.getShopId()).build();
|
|
|
|
|
+
|
|
|
|
|
+ Wallet userWallet = walletService.findWallet(userQuery);
|
|
|
userWallet.setAmount(userWallet.getAmount().add(param.getTotal()));
|
|
userWallet.setAmount(userWallet.getAmount().add(param.getTotal()));
|
|
|
userWallet.setTotalAmount(userWallet.getTotalAmount().add(param.getTotal()));
|
|
userWallet.setTotalAmount(userWallet.getTotalAmount().add(param.getTotal()));
|
|
|
walletDao.save(userWallet);
|
|
walletDao.save(userWallet);
|
|
|
createWalletFlow(userWallet.getId(), param.getTotal(), param.getOutTradeNo(), TradeType.TakeReturn, param.getAttach(), param.getSchoolId());
|
|
createWalletFlow(userWallet.getId(), param.getTotal(), param.getOutTradeNo(), TradeType.TakeReturn, param.getAttach(), param.getSchoolId());
|
|
|
return ResultContent.buildSuccess();
|
|
return ResultContent.buildSuccess();
|
|
|
}
|
|
}
|
|
|
- /** 用户提现(审批通过) */
|
|
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 用户提现(审批通过)
|
|
|
|
|
+ */
|
|
|
// public ResultContent takePass(AmountUpdateParam param){
|
|
// public ResultContent takePass(AmountUpdateParam param){
|
|
|
// Wallet userWallet = findWallet(param.getOid(), WalletType.User, param.getShopId(), param.getUserId());
|
|
// Wallet userWallet = findWallet(param.getOid(), WalletType.User, param.getShopId(), param.getUserId());
|
|
|
// return ResultContent.buildSuccess();
|
|
// return ResultContent.buildSuccess();
|
|
@@ -245,8 +267,7 @@ public class WalletFeignServiceImpl implements WalletFeignService {
|
|
|
// public List<WalletFlowModel> queryWalletFlow(String walletId) {
|
|
// public List<WalletFlowModel> queryWalletFlow(String walletId) {
|
|
|
// return null;
|
|
// return null;
|
|
|
// }
|
|
// }
|
|
|
-
|
|
|
|
|
- private WalletFlow createWalletFlow(String walletId, BigDecimal total, String outTradeNo, TradeType type, Object attach, String schoolId){
|
|
|
|
|
|
|
+ private WalletFlow createWalletFlow(String walletId, BigDecimal total, String outTradeNo, TradeType type, Object attach, String schoolId) {
|
|
|
WalletFlow walletFlow = new WalletFlow();
|
|
WalletFlow walletFlow = new WalletFlow();
|
|
|
Wallet wallet = new Wallet();
|
|
Wallet wallet = new Wallet();
|
|
|
wallet.setId(walletId);
|
|
wallet.setId(walletId);
|
|
@@ -303,12 +324,4 @@ public class WalletFeignServiceImpl implements WalletFeignService {
|
|
|
// walletDao.saveAll(List.of(shopWallet, userWallet));
|
|
// walletDao.saveAll(List.of(shopWallet, userWallet));
|
|
|
// return ResultContent.buildSuccess();
|
|
// return ResultContent.buildSuccess();
|
|
|
// }
|
|
// }
|
|
|
-
|
|
|
|
|
- private WalletModel toModel(Wallet wallet){
|
|
|
|
|
- WalletModel model = new WalletModel();
|
|
|
|
|
- if (wallet!=null){
|
|
|
|
|
- BeanUtils.copyPropertiesWithoutNull(wallet, model);
|
|
|
|
|
- }
|
|
|
|
|
- return model;
|
|
|
|
|
- }
|
|
|
|
|
}
|
|
}
|