|
|
@@ -9,6 +9,7 @@ import com.sckw.core.model.page.PageRes;
|
|
|
import com.sckw.core.utils.CollectionUtils;
|
|
|
import com.sckw.core.utils.IdWorker;
|
|
|
import com.sckw.core.utils.OrderUtils;
|
|
|
+import com.sckw.core.utils.StringTimeUtil;
|
|
|
import com.sckw.core.web.context.LoginUserHolder;
|
|
|
import com.sckw.manage.api.RemoteManageService;
|
|
|
import com.sckw.manage.api.model.dto.res.FindEntCooperateResVo;
|
|
|
@@ -46,6 +47,7 @@ import org.slf4j.Logger;
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
import org.springframework.beans.BeanUtils;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
+import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
import java.math.BigDecimal;
|
|
|
import java.text.DecimalFormat;
|
|
|
@@ -69,6 +71,7 @@ public class WalletService {
|
|
|
private final KwpWalletRefundMapper kwpWalletRefundMapper;
|
|
|
private final KwpWalletTransferMapper kwpWalletTransferMapper;
|
|
|
private final RedisLockUtil redisLockUtil;
|
|
|
+ private final KwpWalletRefundSubService kwpWalletRefundSubService;
|
|
|
@DubboReference(version = "1.0.0", group = "design", check = false)
|
|
|
private RemoteSystemService remoteSystemService;
|
|
|
@DubboReference(version = "1.0.0", group = "design", check = false)
|
|
|
@@ -94,6 +97,12 @@ public class WalletService {
|
|
|
return "";
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 根据中台用户id查询企业id
|
|
|
+ *
|
|
|
+ * @param id 中台用户id
|
|
|
+ * @return
|
|
|
+ */
|
|
|
private Long getEnt(String id) {
|
|
|
if (StringUtils.isBlank(id)) {
|
|
|
return null;
|
|
|
@@ -159,9 +168,15 @@ public class WalletService {
|
|
|
*/
|
|
|
private void refundMoney(PrePayWallet prePayWallet, PrePayWalletVo prePayWalletVo, boolean change) {
|
|
|
DecimalFormat df = new DecimalFormat("0.00");
|
|
|
- KwpWalletRefund kwpWalletRefund = walletOrderService.query(change, prePayWallet.getUid(), prePayWallet.getFilter(), prePayWallet.getChannel());
|
|
|
- if (Objects.nonNull(kwpWalletRefund)) {
|
|
|
- prePayWalletVo.setRefundApMoney(df.format(kwpWalletRefund.getActualMoney()));
|
|
|
+ List<KwpWalletRefund> query = walletOrderService.query(change, prePayWallet.getUid(), prePayWallet.getFilter(), prePayWallet.getChannel());
|
|
|
+ if (!CollectionUtils.isEmpty(query)) {
|
|
|
+ BigDecimal reduce = query.stream().map(KwpWalletRefund::getMoney).reduce(BigDecimal.ZERO, (o, n) -> {
|
|
|
+ if (Objects.isNull(n)) {
|
|
|
+ return o.add(new BigDecimal("0.0"));
|
|
|
+ }
|
|
|
+ return o.add(n);
|
|
|
+ });
|
|
|
+ prePayWalletVo.setRefundApMoney(df.format(reduce));
|
|
|
} else {
|
|
|
prePayWalletVo.setRefundApMoney("0.00");
|
|
|
}
|
|
|
@@ -174,9 +189,15 @@ public class WalletService {
|
|
|
*/
|
|
|
private void refundMoney2(FundVo fundVo) {
|
|
|
DecimalFormat df = new DecimalFormat("0.00");
|
|
|
- KwpWalletRefund kwpWalletRefund = walletOrderService.queryOne(fundVo.getUid(), fundVo.getFilter(), fundVo.getChannel(), RefundEnum.REFUNDING);
|
|
|
- if (Objects.nonNull(kwpWalletRefund)) {
|
|
|
- fundVo.setRefundMoney(df.format(kwpWalletRefund.getActualMoney()));
|
|
|
+ List<KwpWalletRefund> kwpWalletRefunds = walletOrderService.queryList(fundVo.getUid(), fundVo.getFilter(), fundVo.getChannel(), RefundEnum.REFUNDING);
|
|
|
+ if (!CollectionUtils.isEmpty(kwpWalletRefunds)) {
|
|
|
+ BigDecimal reduce = kwpWalletRefunds.stream().map(KwpWalletRefund::getMoney).reduce(BigDecimal.ZERO, (o, n) -> {
|
|
|
+ if (Objects.isNull(n)) {
|
|
|
+ return o.add(new BigDecimal("0.0"));
|
|
|
+ }
|
|
|
+ return o.add(n);
|
|
|
+ });
|
|
|
+ fundVo.setRefundMoney(df.format(reduce));
|
|
|
} else {
|
|
|
fundVo.setRefundMoney("0.00");
|
|
|
}
|
|
|
@@ -895,10 +916,7 @@ public class WalletService {
|
|
|
throw new BusinessException("不存在交易");
|
|
|
}
|
|
|
WalletInfoDto walletInfoDto = new WalletInfoDto();
|
|
|
- walletInfoDto.setName(data.getName());
|
|
|
- walletInfoDto.setWalletName(data.getWalletName());
|
|
|
walletInfoDto.setChannel(data.getChannel());
|
|
|
- walletInfoDto.setStatus(data.getStatus());
|
|
|
walletInfoDto.setApMoney(walletInfoDto.smallMoney(data.getApMoney()));
|
|
|
walletInfoDto.setWdMoney(walletInfoDto.smallMoney(data.getWdMoney()));
|
|
|
walletInfoDto.setMoney(walletInfoDto.smallMoney(data.getMoney()));
|
|
|
@@ -956,14 +974,37 @@ public class WalletService {
|
|
|
|
|
|
/**
|
|
|
* 申请退款
|
|
|
+ * 校验预付可用余额和退款金额,退款金额不能大于预付可用余额
|
|
|
*
|
|
|
* @return
|
|
|
*/
|
|
|
- public Object applyRefund(RefundReq refundReq) {
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
+ public Object applyRefund(ApplyRefundReq refundReq) {
|
|
|
ChannelEnum channelEnum = ChannelEnum.getByChannel(refundReq.getChannel());
|
|
|
if (Objects.isNull(channelEnum)) {
|
|
|
throw new BusinessException("支付通道不存在");
|
|
|
}
|
|
|
+ //校验余额
|
|
|
+ R<WalletInfo> walletInfoR = payCenterService.totalInfo(refundReq.getUid(), channelEnum, refundReq.getFilter());
|
|
|
+ if (!walletInfoR.getStatus()) {
|
|
|
+ throw new BusinessException(StringUtils.isNotBlank(walletInfoR.getMsg()) ? walletInfoR.getMsg() : "未找到交易方");
|
|
|
+ }
|
|
|
+ WalletInfo data = walletInfoR.getData();
|
|
|
+ if (Objects.isNull(data)) {
|
|
|
+ throw new BusinessException("不存在交易");
|
|
|
+ }
|
|
|
+ //预付可用余额 分
|
|
|
+ BigDecimal apMoney = data.getApMoney();
|
|
|
+ apMoney = Objects.isNull(apMoney) ? BigDecimal.ZERO : apMoney;
|
|
|
+ //退款金额 元
|
|
|
+ BigDecimal money = refundReq.getMoney();
|
|
|
+ //退款金额 分
|
|
|
+ BigDecimal multiply = money.multiply(new BigDecimal("100"));
|
|
|
+ if (multiply.compareTo(apMoney) > 0) {
|
|
|
+ throw new BusinessException("退款金额不能大于预付可用金额");
|
|
|
+ }
|
|
|
+
|
|
|
+ //新增退款单
|
|
|
KwpWalletRefund kwpWalletRefundAdd = new KwpWalletRefund();
|
|
|
kwpWalletRefundAdd.setId(new IdWorker(NumberConstant.ONE).nextId());
|
|
|
kwpWalletRefundAdd.setOrderNo(OrderUtils.generateOrderNo("RF"));
|
|
|
@@ -982,6 +1023,7 @@ public class WalletService {
|
|
|
kwpWalletRefundAdd.setDelFlag(0);
|
|
|
kwpWalletRefundAdd.setStatus(RefundEnum.APPLY.getStatus());
|
|
|
kwpWalletRefundMapper.insert(kwpWalletRefundAdd);
|
|
|
+ kwpWalletRefundSubService.saveRecord(kwpWalletRefundAdd.getId(), refundReq.getRemark(), RefundEnum.APPLY.getStatus());
|
|
|
return "提交成功";
|
|
|
}
|
|
|
|
|
|
@@ -995,26 +1037,31 @@ public class WalletService {
|
|
|
*
|
|
|
* @return
|
|
|
*/
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
+
|
|
|
public Object launchRefund(RefundReq refundReq) {
|
|
|
- KwpWalletRefund kwpWalletRefund = walletOrderService.queryOne(refundReq.getUid(), refundReq.getFilter(), refundReq.getChannel(), RefundEnum.APPLY);
|
|
|
+ KwpWalletRefund kwpWalletRefund = walletOrderService.queryById(refundReq.getIdLong());
|
|
|
if (Objects.isNull(kwpWalletRefund)) {
|
|
|
- throw new BusinessException("未找到待完成的退款订单");
|
|
|
+ throw new BusinessException("退款订单不存在");
|
|
|
}
|
|
|
- ChannelEnum channelEnum = ChannelEnum.getByChannel(refundReq.getChannel());
|
|
|
+ ChannelEnum channelEnum = ChannelEnum.getByChannel(kwpWalletRefund.getChannel());
|
|
|
if (Objects.isNull(channelEnum)) {
|
|
|
throw new BusinessException("支付通道不存在");
|
|
|
}
|
|
|
// 1.记账
|
|
|
List<PatchPay> list = new ArrayList<>();
|
|
|
PatchPay patchPay = new PatchPay();
|
|
|
- patchPay.setUid(refundReq.getFilter());
|
|
|
+ patchPay.setUid(kwpWalletRefund.getFilter());
|
|
|
patchPay.setMoney(refundReq.bigMoney(refundReq.getMoney()));
|
|
|
- patchPay.setRemark(refundReq.getRemark());
|
|
|
+ patchPay.setRemark(StringUtils.isBlank(refundReq.getRemark()) ? "" : refundReq.getRemark());
|
|
|
list.add(patchPay);
|
|
|
- R<BusinessNo> businessNoR = payCenterService.payAgentPayV2(refundReq.getUid(), refundReq.getFilter(), channelEnum, refundReq.bigMoney(refundReq.getMoney()), list, OrderUtils.generateOrderNo("SEQ"), "1");
|
|
|
+ R<BusinessNo> businessNoR = payCenterService.payAgentPayV2(kwpWalletRefund.getUid(), kwpWalletRefund.getFilter(), channelEnum, refundReq.bigMoney(refundReq.getMoney()), list, OrderUtils.generateOrderNo("SEQ"), "1");
|
|
|
if (!businessNoR.getStatus()) {
|
|
|
throw new BusinessException(StringUtils.isNotBlank(businessNoR.getMsg()) ? businessNoR.getMsg() : "退款失败");
|
|
|
}
|
|
|
+ //保存操作记录
|
|
|
+ kwpWalletRefundSubService.saveRecord(kwpWalletRefund.getId(), refundReq.getRemark(), RefundEnum.REFUNDING.getStatus());
|
|
|
+
|
|
|
Long userId = LoginUserHolder.getUserId();
|
|
|
//异步提交清分退款任务
|
|
|
AsyncPool.addTask(new Refund(refundReq, kwpWalletRefund, payCenterService, kwpWalletRefundMapper, userId));
|
|
|
@@ -1024,23 +1071,20 @@ public class WalletService {
|
|
|
/**
|
|
|
* 发起退款校验
|
|
|
*
|
|
|
- * @param refundReq
|
|
|
+ * @param id
|
|
|
* @return
|
|
|
*/
|
|
|
- public Object refundCheck(RefundCheckReq refundReq) {
|
|
|
- LambdaQueryWrapper<KwpWalletRefund> wrapper = new LambdaQueryWrapper<>();
|
|
|
- wrapper.eq(KwpWalletRefund::getChannel, refundReq.getChannel());
|
|
|
- wrapper.eq(KwpWalletRefund::getUid, refundReq.getUid()).eq(KwpWalletRefund::getFilter, refundReq.getFilter()).eq(KwpWalletRefund::getStatus, RefundEnum.APPLY.getStatus()).last("limit 1");
|
|
|
- KwpWalletRefund kwpWalletRefund = kwpWalletRefundMapper.selectOne(wrapper);
|
|
|
+ public WalletInfoDto refundCheck(Long id) {
|
|
|
+ KwpWalletRefund kwpWalletRefund = walletOrderService.queryById(id);
|
|
|
if (Objects.isNull(kwpWalletRefund)) {
|
|
|
- throw new BusinessException("未找到待完成的退款订单");
|
|
|
+ throw new BusinessException("退款订单不存在");
|
|
|
}
|
|
|
- ChannelEnum channelEnum = ChannelEnum.getByChannel(refundReq.getChannel());
|
|
|
+ ChannelEnum channelEnum = ChannelEnum.getByChannel(kwpWalletRefund.getChannel());
|
|
|
if (Objects.isNull(channelEnum)) {
|
|
|
throw new BusinessException("支付通道不存在");
|
|
|
}
|
|
|
//发起退款是预收业务,uid和filter是相反的,查询时需要方向查询钱包
|
|
|
- R<WalletInfo> walletInfoR = payCenterService.totalInfo(refundReq.getFilter(), channelEnum, refundReq.getUid());
|
|
|
+ R<WalletInfo> walletInfoR = payCenterService.totalInfo(kwpWalletRefund.getFilter(), channelEnum, kwpWalletRefund.getUid());
|
|
|
// 未开通钱包
|
|
|
if (!walletInfoR.getStatus()) {
|
|
|
WalletInfoDto walletInfoDto = new WalletInfoDto();
|
|
|
@@ -1055,17 +1099,27 @@ public class WalletService {
|
|
|
}
|
|
|
WalletInfoDto walletInfoDto = new WalletInfoDto();
|
|
|
walletInfoDto.setOpenFlag(true);
|
|
|
- walletInfoDto.setName(data.getName());
|
|
|
- walletInfoDto.setWalletName(data.getWalletName());
|
|
|
walletInfoDto.setChannel(data.getChannel());
|
|
|
- walletInfoDto.setStatus(data.getStatus());
|
|
|
walletInfoDto.setApMoney(walletInfoDto.smallMoney(data.getApMoney()));
|
|
|
walletInfoDto.setWdMoney(walletInfoDto.smallMoney(data.getWdMoney()));
|
|
|
walletInfoDto.setMoney(walletInfoDto.smallMoney(data.getMoney()));
|
|
|
+ //申请退款金额
|
|
|
walletInfoDto.setRefundMoney(kwpWalletRefund.getMoney());
|
|
|
+
|
|
|
+ walletInfoDto.setChannelLabel(channelEnum.getDesc());
|
|
|
+ walletInfoDto.setUid(kwpWalletRefund.getUid());
|
|
|
+ walletInfoDto.setUidName(getFirmName(kwpWalletRefund.getUid()));
|
|
|
+ walletInfoDto.setFilter(kwpWalletRefund.getFilter());
|
|
|
+ walletInfoDto.setFilterName(getFirmName(kwpWalletRefund.getFilter()));
|
|
|
return walletInfoDto;
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 预付追加校验
|
|
|
+ *
|
|
|
+ * @param appendPayCheck
|
|
|
+ * @return
|
|
|
+ */
|
|
|
public Object appendCheck(AppendPayCheck appendPayCheck) {
|
|
|
String uid = walletRelationService.getRelation(LoginUserHolder.getEntId());
|
|
|
if (StringUtils.isBlank(uid)) {
|
|
|
@@ -1086,10 +1140,7 @@ public class WalletService {
|
|
|
}
|
|
|
WalletInfoDto walletInfoDto = new WalletInfoDto();
|
|
|
walletInfoDto.setOpenFlag(true);
|
|
|
- walletInfoDto.setName(data.getName());
|
|
|
- walletInfoDto.setWalletName(data.getWalletName());
|
|
|
walletInfoDto.setChannel(data.getChannel());
|
|
|
- walletInfoDto.setStatus(data.getStatus());
|
|
|
walletInfoDto.setApMoney(walletInfoDto.smallMoney(data.getApMoney()));
|
|
|
walletInfoDto.setWdMoney(walletInfoDto.smallMoney(data.getWdMoney()));
|
|
|
walletInfoDto.setMoney(walletInfoDto.smallMoney(data.getMoney()));
|
|
|
@@ -1149,8 +1200,45 @@ public class WalletService {
|
|
|
* @param refundReq
|
|
|
* @return
|
|
|
*/
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
public String backRefund(RefundBackReq refundReq) {
|
|
|
- return null;
|
|
|
+ KwpWalletRefund kwpWalletRefund = walletOrderService.queryById(refundReq.getIdLong());
|
|
|
+ if (Objects.isNull(kwpWalletRefund)) {
|
|
|
+ throw new BusinessException("退款订单不存在");
|
|
|
+ }
|
|
|
+ if (kwpWalletRefund.getStatus() != RefundEnum.APPLY.getStatus()) {
|
|
|
+ throw new BusinessException("请勿重复提交");
|
|
|
+ }
|
|
|
+ kwpWalletRefund.setStatus(RefundEnum.BACK.getStatus());
|
|
|
+ kwpWalletRefund.setRemark(refundReq.getRemark());
|
|
|
+ kwpWalletRefund.setUpdateBy(LoginUserHolder.getUserId());
|
|
|
+ kwpWalletRefund.setUpdateTime(LocalDateTime.now());
|
|
|
+ walletOrderService.updateById(kwpWalletRefund);
|
|
|
+ //保存操作记录
|
|
|
+ kwpWalletRefundSubService.saveRecord(kwpWalletRefund.getId(), refundReq.getRemark(), RefundEnum.BACK.getStatus());
|
|
|
+ return "驳回成功";
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 查询退款列表
|
|
|
+ *
|
|
|
+ * @param refundPage
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public Object refundList(RefundPage refundPage) {
|
|
|
+ if (StringUtils.isNotBlank(refundPage.getStartCreateTime())) {
|
|
|
+ refundPage.setStartCreateTime(StringTimeUtil.fillStart(refundPage.getStartCreateTime()));
|
|
|
+ }
|
|
|
+ if (StringUtils.isNotBlank(refundPage.getEndCreateTime())) {
|
|
|
+ refundPage.setEndCreateTime(StringTimeUtil.fillEnd(refundPage.getEndCreateTime()));
|
|
|
+ }
|
|
|
+ PageRes<WalletRefundVo> walletRefundVoPageRes = walletOrderService.queryRefundList(refundPage);
|
|
|
+ List<WalletRefundVo> list = walletRefundVoPageRes.getList();
|
|
|
+ for (WalletRefundVo walletRefundVo : list) {
|
|
|
+ walletRefundVo.setUidName(getFirmName(walletRefundVo.getUid()));
|
|
|
+ walletRefundVo.setFilterName(getFirmName(walletRefundVo.getFilter()));
|
|
|
+ }
|
|
|
+ return walletRefundVoPageRes;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -1168,15 +1256,15 @@ public class WalletService {
|
|
|
|
|
|
@Override
|
|
|
public void run() {
|
|
|
- ChannelEnum channelEnum = ChannelEnum.getByChannel(refundReq.getChannel());
|
|
|
+ ChannelEnum channelEnum = ChannelEnum.getByChannel(kwpWalletRefund.getChannel());
|
|
|
List<PatchPay> list = new ArrayList<>();
|
|
|
PatchPay patchPay = new PatchPay();
|
|
|
- patchPay.setUid(refundReq.getFilter());
|
|
|
+ patchPay.setUid(kwpWalletRefund.getFilter());
|
|
|
patchPay.setMoney(refundReq.bigMoney(refundReq.getMoney()));
|
|
|
patchPay.setRemark(refundReq.getRemark());
|
|
|
list.add(patchPay);
|
|
|
log.info("异步提交清分退款任务");
|
|
|
- R<BusinessNo> businessNoR1 = payCenterService.payAgentPayV2(refundReq.getFilter(), refundReq.getUid(), channelEnum, refundReq.bigMoney(refundReq.getMoney()), list, OrderUtils.generateOrderNo("SEQ"), "2");
|
|
|
+ R<BusinessNo> businessNoR1 = payCenterService.payAgentPayV2(kwpWalletRefund.getFilter(), kwpWalletRefund.getUid(), channelEnum, refundReq.bigMoney(refundReq.getMoney()), list, OrderUtils.generateOrderNo("SEQ"), "2");
|
|
|
if (businessNoR1.getStatus()) {
|
|
|
kwpWalletRefund.setActualMoney(refundReq.getMoney());
|
|
|
kwpWalletRefund.setUpdateBy(userId);
|