|
|
@@ -2,6 +2,7 @@ package com.zhongshu.payment.server.core.service.impl;
|
|
|
|
|
|
import com.zhongshu.payment.client.model.WalletFlowModel;
|
|
|
import com.zhongshu.payment.client.model.WalletModel;
|
|
|
+import com.zhongshu.payment.client.model.param.AmountUpdateParam;
|
|
|
import com.zhongshu.payment.client.ret.ResultContent;
|
|
|
import com.zhongshu.payment.client.service.WalletFeignService;
|
|
|
import com.zhongshu.payment.client.types.DataState;
|
|
|
@@ -12,6 +13,7 @@ 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.WalletFlow;
|
|
|
import com.zhongshu.payment.server.core.utils.BeanUtils;
|
|
|
+import org.jetbrains.annotations.NotNull;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
@@ -34,6 +36,12 @@ public class WalletFeignServiceImpl implements WalletFeignService {
|
|
|
|
|
|
@Override
|
|
|
public WalletModel getWallet(String oid, WalletType walletType, String shopId, String userId) {
|
|
|
+
|
|
|
+ return toModel(findWallet(oid, walletType, shopId, userId));
|
|
|
+ }
|
|
|
+
|
|
|
+ @NotNull
|
|
|
+ private Wallet findWallet(String oid, @NotNull WalletType walletType, String shopId, String userId){
|
|
|
Wallet wallet = null;
|
|
|
if (walletType.equals(WalletType.User)){
|
|
|
wallet = walletDao.findByUserIdAndOid(userId, oid);
|
|
|
@@ -42,7 +50,7 @@ public class WalletFeignServiceImpl implements WalletFeignService {
|
|
|
wallet = walletDao.findByShopIdAndOid(shopId, oid);
|
|
|
}
|
|
|
if (wallet!=null){
|
|
|
- return toModel(wallet);
|
|
|
+ return wallet;
|
|
|
}
|
|
|
wallet = new Wallet();
|
|
|
wallet.setOid(oid);
|
|
|
@@ -53,69 +61,161 @@ public class WalletFeignServiceImpl implements WalletFeignService {
|
|
|
wallet.setShopId(shopId);
|
|
|
wallet.setUserId(userId);
|
|
|
walletDao.save(wallet);
|
|
|
- return toModel(wallet);
|
|
|
+ return wallet;
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+ /** 充值 */
|
|
|
@Override
|
|
|
- public ResultContent addAmount(String walletId, BigDecimal total, String outTradeNo, TradeType type, String attach) {
|
|
|
- Wallet wallet = walletDao.findTop1ById(walletId);
|
|
|
- if (wallet==null){
|
|
|
- return ResultContent.buildFail("钱包未开通");
|
|
|
- }
|
|
|
- wallet.setAmount(wallet.getAmount().add(total));
|
|
|
+ public ResultContent recharge(AmountUpdateParam param){
|
|
|
+ Wallet wallet = findWallet(param.getOid(), WalletType.User, param.getShopId(), param.getUserId());
|
|
|
+ wallet.setAmount(wallet.getAmount().add(param.getTotal()));
|
|
|
+ wallet.setTotalAmount(wallet.getTotalAmount().add(param.getTotal()));
|
|
|
walletDao.save(wallet);
|
|
|
- createWalletFlow(walletId, total, outTradeNo, type, attach);
|
|
|
+ createWalletFlow(wallet.getId(), param.getTotal(), param.getOutTradeNo(), TradeType.Charge, param.getAttach(), param.getSchoolId());
|
|
|
return ResultContent.buildSuccess();
|
|
|
}
|
|
|
|
|
|
+ /** 消费 */
|
|
|
@Override
|
|
|
- public ResultContent addTotalAmount(String walletId, BigDecimal total, String outTradeNo, TradeType type, String attach) {
|
|
|
- Wallet wallet = walletDao.findTop1ById(walletId);
|
|
|
- if (wallet==null){
|
|
|
- return ResultContent.buildFail("钱包未开通");
|
|
|
+ public ResultContent consume(AmountUpdateParam param){
|
|
|
+ Wallet userWallet = findWallet(param.getOid(), WalletType.User, param.getShopId(), param.getUserId());
|
|
|
+
|
|
|
+ if (userWallet.getAmount().compareTo(param.getTotal()) < 0 ){
|
|
|
+ return ResultContent.buildFail("可用余额不足");
|
|
|
}
|
|
|
- wallet.setTotalAmount(wallet.getTotalAmount().add(total));
|
|
|
- walletDao.save(wallet);
|
|
|
- createWalletFlow(walletId, total, outTradeNo, type, attach);
|
|
|
+ if (userWallet.getTotalAmount().compareTo(param.getTotal()) < 0 ){
|
|
|
+ return ResultContent.buildFail("总额不足");
|
|
|
+ }
|
|
|
+ userWallet.setAmount(userWallet.getAmount().subtract(param.getTotal()));
|
|
|
+ userWallet.setTotalAmount(userWallet.getTotalAmount().subtract(param.getTotal()));
|
|
|
+ walletDao.save(userWallet);
|
|
|
+ createWalletFlow(userWallet.getId(), param.getTotal(), param.getOutTradeNo(), TradeType.Pay, param.getAttach(), param.getSchoolId());
|
|
|
+
|
|
|
+ Wallet shopWallet = findWallet(param.getOid(), WalletType.Shop, param.getShopId(), param.getUserId());
|
|
|
+ shopWallet.setAmount(shopWallet.getAmount().add(param.getTotal()));
|
|
|
+ shopWallet.setTotalAmount(shopWallet.getTotalAmount().add(param.getTotal()));
|
|
|
+ walletDao.save(shopWallet);
|
|
|
+ createWalletFlow(shopWallet.getId(), param.getTotal(), param.getOutTradeNo(), TradeType.InCome, param.getAttach(), param.getSchoolId());
|
|
|
return ResultContent.buildSuccess();
|
|
|
}
|
|
|
|
|
|
- @Override
|
|
|
- public ResultContent subtractAmount(String walletId, BigDecimal total, String outTradeNo, TradeType type, String attach) {
|
|
|
- Wallet wallet = walletDao.findTop1ById(walletId);
|
|
|
- if (wallet==null){
|
|
|
- return ResultContent.buildFail("钱包未开通");
|
|
|
- }
|
|
|
- if (wallet.getAmount().compareTo(total) < 0 ){
|
|
|
- return ResultContent.buildFail("可用余额不足");
|
|
|
- }
|
|
|
- wallet.setAmount(wallet.getAmount().subtract(total));
|
|
|
- walletDao.save(wallet);
|
|
|
- createWalletFlow(walletId, total, outTradeNo, type, attach);
|
|
|
+ /** 发起退款 */
|
|
|
+ public ResultContent frozen(AmountUpdateParam param){
|
|
|
+ Wallet shopWallet = findWallet(param.getOid(), WalletType.Shop, param.getShopId(), param.getUserId());
|
|
|
+
|
|
|
+// if (shopWallet.getAmount().compareTo(param.getTotal()) < 0 ){
|
|
|
+// return ResultContent.buildFail("可用余额不足");
|
|
|
+// }
|
|
|
+// if (shopWallet.getTotalAmount().compareTo(param.getTotal()) < 0 ){
|
|
|
+// return ResultContent.buildFail("总额不足");
|
|
|
+// }
|
|
|
+
|
|
|
+
|
|
|
+ shopWallet.setAmount(shopWallet.getAmount().subtract(param.getTotal()));
|
|
|
+ walletDao.save(shopWallet);
|
|
|
+ createWalletFlow(shopWallet.getId(), param.getTotal(), param.getOutTradeNo(), TradeType.Frozen, param.getAttach(), param.getSchoolId());
|
|
|
return ResultContent.buildSuccess();
|
|
|
}
|
|
|
|
|
|
- @Override
|
|
|
- public ResultContent subtractTotalAmount(String walletId, BigDecimal total, String outTradeNo, TradeType type, String attach) {
|
|
|
- Wallet wallet = walletDao.findTop1ById(walletId);
|
|
|
- if (wallet==null){
|
|
|
- return ResultContent.buildFail("钱包未开通");
|
|
|
- }
|
|
|
- if (wallet.getTotalAmount().compareTo(total) < 0 ){
|
|
|
- return ResultContent.buildFail("总额不足");
|
|
|
+ /** 退款(审批失败) */
|
|
|
+ public ResultContent cancelFrozen(AmountUpdateParam param){
|
|
|
+ Wallet shopWallet = findWallet(param.getOid(), WalletType.Shop, param.getShopId(), param.getUserId());
|
|
|
+ shopWallet.setAmount(shopWallet.getAmount().add(param.getTotal()));
|
|
|
+ walletDao.save(shopWallet);
|
|
|
+ createWalletFlow(shopWallet.getId(), param.getTotal(), param.getOutTradeNo(), TradeType.CancelFrozen, param.getAttach(), param.getSchoolId());
|
|
|
+ return ResultContent.buildSuccess();
|
|
|
+ }
|
|
|
+
|
|
|
+ /** 退款(审批通过) */
|
|
|
+ public ResultContent refund(AmountUpdateParam param){
|
|
|
+ Wallet shopWallet = findWallet(param.getOid(), WalletType.Shop, param.getShopId(), param.getUserId());
|
|
|
+
|
|
|
+ BigDecimal amount = shopWallet.getAmount();
|
|
|
+ //加上冻结金额
|
|
|
+ BigDecimal _amount = amount.add(param.getTotal());
|
|
|
+ if (_amount.compareTo(param.getTotal()) < 0 ){
|
|
|
+ return ResultContent.buildFail("可用余额不足");
|
|
|
}
|
|
|
- wallet.setTotalAmount(wallet.getTotalAmount().subtract(total));
|
|
|
- walletDao.save(wallet);
|
|
|
- createWalletFlow(walletId, total, outTradeNo, type, attach);
|
|
|
+// shopWallet.setAmount(shopWallet.getAmount().add(param.getTotal()));
|
|
|
+ shopWallet.setTotalAmount(shopWallet.getTotalAmount().subtract(param.getTotal()));
|
|
|
+ walletDao.save(shopWallet);
|
|
|
+ createWalletFlow(shopWallet.getId(), param.getTotal(), param.getOutTradeNo(), TradeType.Refund, param.getAttach(), param.getSchoolId());
|
|
|
+
|
|
|
+ Wallet userWallet = findWallet(param.getOid(), WalletType.User, param.getShopId(), param.getUserId());
|
|
|
+ userWallet.setAmount(userWallet.getAmount().add(param.getTotal()));
|
|
|
+ userWallet.setTotalAmount(userWallet.getTotalAmount().add(param.getTotal()));
|
|
|
+ walletDao.save(userWallet);
|
|
|
+ createWalletFlow(userWallet.getId(), param.getTotal(), param.getOutTradeNo(), TradeType.Refund, param.getAttach(), param.getSchoolId());
|
|
|
return ResultContent.buildSuccess();
|
|
|
}
|
|
|
|
|
|
+ /** 用户发起提现 */
|
|
|
+
|
|
|
+ /** 用户提现(审批失败) */
|
|
|
+
|
|
|
+ /** 用户提现(审批通过) */
|
|
|
+
|
|
|
+// @Override
|
|
|
+// public ResultContent addAmount(String walletId, BigDecimal total, String outTradeNo, TradeType type, String attach) {
|
|
|
+// Wallet wallet = walletDao.findTop1ById(walletId);
|
|
|
+// if (wallet==null){
|
|
|
+// return ResultContent.buildFail("钱包未开通");
|
|
|
+// }
|
|
|
+// wallet.setAmount(wallet.getAmount().add(total));
|
|
|
+// walletDao.save(wallet);
|
|
|
+// createWalletFlow(walletId, total, outTradeNo, type, attach);
|
|
|
+// return ResultContent.buildSuccess();
|
|
|
+// }
|
|
|
+//
|
|
|
+// @Override
|
|
|
+// public ResultContent addTotalAmount(String walletId, BigDecimal total, String outTradeNo, TradeType type, String attach) {
|
|
|
+// Wallet wallet = walletDao.findTop1ById(walletId);
|
|
|
+// if (wallet==null){
|
|
|
+// return ResultContent.buildFail("钱包未开通");
|
|
|
+// }
|
|
|
+// wallet.setTotalAmount(wallet.getTotalAmount().add(total));
|
|
|
+// walletDao.save(wallet);
|
|
|
+// createWalletFlow(walletId, total, outTradeNo, type, attach);
|
|
|
+// return ResultContent.buildSuccess();
|
|
|
+// }
|
|
|
+//
|
|
|
+// @Override
|
|
|
+// public ResultContent subtractAmount(String walletId, BigDecimal total, String outTradeNo, TradeType type, String attach) {
|
|
|
+// Wallet wallet = walletDao.findTop1ById(walletId);
|
|
|
+// if (wallet==null){
|
|
|
+// return ResultContent.buildFail("钱包未开通");
|
|
|
+// }
|
|
|
+// if (wallet.getAmount().compareTo(total) < 0 ){
|
|
|
+// return ResultContent.buildFail("可用余额不足");
|
|
|
+// }
|
|
|
+// wallet.setAmount(wallet.getAmount().subtract(total));
|
|
|
+// walletDao.save(wallet);
|
|
|
+// createWalletFlow(walletId, total, outTradeNo, type, attach);
|
|
|
+// return ResultContent.buildSuccess();
|
|
|
+// }
|
|
|
+//
|
|
|
+// @Override
|
|
|
+// public ResultContent subtractTotalAmount(String walletId, BigDecimal total, String outTradeNo, TradeType type, String attach) {
|
|
|
+// Wallet wallet = walletDao.findTop1ById(walletId);
|
|
|
+// if (wallet==null){
|
|
|
+// return ResultContent.buildFail("钱包未开通");
|
|
|
+// }
|
|
|
+// if (wallet.getTotalAmount().compareTo(total) < 0 ){
|
|
|
+// return ResultContent.buildFail("总额不足");
|
|
|
+// }
|
|
|
+// wallet.setTotalAmount(wallet.getTotalAmount().subtract(total));
|
|
|
+// walletDao.save(wallet);
|
|
|
+// createWalletFlow(walletId, total, outTradeNo, type, attach);
|
|
|
+// return ResultContent.buildSuccess();
|
|
|
+// }
|
|
|
+
|
|
|
@Override
|
|
|
public List<WalletFlowModel> queryWalletFlow(String walletId) {
|
|
|
return null;
|
|
|
}
|
|
|
|
|
|
- private WalletFlow createWalletFlow(String walletId, BigDecimal total, String outTradeNo, TradeType type, String attach){
|
|
|
+ private WalletFlow createWalletFlow(String walletId, BigDecimal total, String outTradeNo, TradeType type, String attach, String schoolId){
|
|
|
WalletFlow walletFlow = new WalletFlow();
|
|
|
Wallet wallet = new Wallet();
|
|
|
wallet.setId(walletId);
|
|
|
@@ -124,6 +224,7 @@ public class WalletFeignServiceImpl implements WalletFeignService {
|
|
|
walletFlow.setOutTradeNo(outTradeNo);
|
|
|
walletFlow.setTradeType(type);
|
|
|
walletFlow.setAttach(attach);
|
|
|
+ walletFlow.setSchoolId(schoolId);
|
|
|
return walletFlowDao.save(walletFlow);
|
|
|
}
|
|
|
|