|
|
@@ -1,17 +1,29 @@
|
|
|
package com.sckw.payment.service;
|
|
|
|
|
|
+import com.alibaba.fastjson2.JSONObject;
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
+import com.sckw.core.common.enums.NumberConstant;
|
|
|
import com.sckw.core.exception.BusinessException;
|
|
|
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.web.context.LoginUserHolder;
|
|
|
+import com.sckw.manage.api.RemoteManageService;
|
|
|
+import com.sckw.manage.api.model.dto.res.FindEntCooperateResVo;
|
|
|
import com.sckw.payment.api.model.constant.ChannelEnum;
|
|
|
-import com.sckw.payment.api.model.dto.Order;
|
|
|
-import com.sckw.payment.api.model.dto.WalletDto;
|
|
|
+import com.sckw.payment.api.model.dto.*;
|
|
|
+import com.sckw.payment.api.model.dto.common.BusinessNo;
|
|
|
import com.sckw.payment.api.model.dto.common.R;
|
|
|
import com.sckw.payment.api.model.dto.page.CashPage;
|
|
|
-import com.sckw.payment.api.model.dto.page.PrePayIndexPage;
|
|
|
+import com.sckw.payment.api.model.dto.page.PrePayWalletPage;
|
|
|
+import com.sckw.payment.dao.KwpWalletRefundMapper;
|
|
|
+import com.sckw.payment.job.AsyncPool;
|
|
|
+import com.sckw.payment.model.KwpWalletRefund;
|
|
|
+import com.sckw.payment.model.constant.RefundEnum;
|
|
|
import com.sckw.payment.model.vo.req.*;
|
|
|
import com.sckw.payment.model.vo.res.FundVo;
|
|
|
+import com.sckw.payment.model.vo.res.MorePageRes;
|
|
|
import com.sckw.payment.model.vo.res.WalletDetail;
|
|
|
import com.sckw.system.api.RemoteSystemService;
|
|
|
import com.sckw.system.api.model.dto.res.EntCacheResDto;
|
|
|
@@ -19,15 +31,17 @@ import lombok.RequiredArgsConstructor;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
import org.apache.dubbo.config.annotation.DubboReference;
|
|
|
+import org.slf4j.Logger;
|
|
|
+import org.slf4j.LoggerFactory;
|
|
|
import org.springframework.beans.BeanUtils;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
+import java.text.DecimalFormat;
|
|
|
+import java.time.LocalDateTime;
|
|
|
import java.util.ArrayList;
|
|
|
import java.util.List;
|
|
|
import java.util.Objects;
|
|
|
-import java.util.concurrent.LinkedBlockingQueue;
|
|
|
-import java.util.concurrent.ThreadPoolExecutor;
|
|
|
-import java.util.concurrent.TimeUnit;
|
|
|
+import java.util.stream.Collectors;
|
|
|
|
|
|
/**
|
|
|
* 钱包
|
|
|
@@ -41,12 +55,84 @@ import java.util.concurrent.TimeUnit;
|
|
|
public class WalletService {
|
|
|
private final PayCenterService payCenterService;
|
|
|
private final KwpWalletRelationService walletRelationService;
|
|
|
- private final ThreadPoolExecutor threadPoolExecutor = new ThreadPoolExecutor(1, 1, 2, TimeUnit.MINUTES, new LinkedBlockingQueue<>(12));
|
|
|
+ private final KwpWalletRefundMapper kwpWalletRefundMapper;
|
|
|
@DubboReference(version = "1.0.0", group = "design", check = false)
|
|
|
private RemoteSystemService remoteSystemService;
|
|
|
+ @DubboReference(version = "1.0.0", group = "design", check = false)
|
|
|
+ private RemoteManageService remoteManageService;
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 通过中台用户id转为企业名称
|
|
|
+ *
|
|
|
+ * @param id 中台用户id
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ private String getFirmName(String id) {
|
|
|
+ if (StringUtils.isBlank(id)) {
|
|
|
+ return "";
|
|
|
+ }
|
|
|
+ Long ent = walletRelationService.getEnt(id);
|
|
|
+ if (Objects.nonNull(ent)) {
|
|
|
+ EntCacheResDto entCacheResDto = remoteSystemService.queryEntCacheById(ent);
|
|
|
+ if (Objects.nonNull(entCacheResDto)) {
|
|
|
+ return entCacheResDto.getFirmName();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return "";
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 通过企业名称查询关联的中台用户id
|
|
|
+ *
|
|
|
+ * @param entName
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ private List<String> findFilter(String entName) {
|
|
|
+ if (StringUtils.isNotBlank(entName)) {
|
|
|
+ Long entId = LoginUserHolder.getEntId();
|
|
|
+ List<FindEntCooperateResVo> allCooperateEnt = remoteManageService.findAllCooperateEnt(entId);
|
|
|
+ if (!CollectionUtils.isEmpty(allCooperateEnt)) {
|
|
|
+ List<Long> collect = allCooperateEnt.stream().filter(a -> StringUtils.contains(a.getEntName(), entName)).map(FindEntCooperateResVo::getEntId).collect(Collectors.toList());
|
|
|
+ List<String> res = new ArrayList<>();
|
|
|
+ for (Long aLong : collect) {
|
|
|
+ String relation = walletRelationService.getRelation(aLong);
|
|
|
+ if (StringUtils.isNotBlank(relation) && !res.contains(relation)) {
|
|
|
+ res.add(relation);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return res;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return new ArrayList<>();
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 通过企业名称查询关联的中台用户id
|
|
|
+ *
|
|
|
+ * @param entName
|
|
|
+ * @return "uid,uid,uid"
|
|
|
+ */
|
|
|
+ private String findFilterStr(String entName) {
|
|
|
+ List<String> filter = findFilter(entName);
|
|
|
+ return StringUtils.join(filter, ",");
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 金额转元并转字符串
|
|
|
+ *
|
|
|
+ * @param money
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ private String dfMoney(Long money) {
|
|
|
+ if (Objects.isNull(money)) {
|
|
|
+ return "0.00";
|
|
|
+ }
|
|
|
+ DecimalFormat df = new DecimalFormat("0.00");
|
|
|
+ return df.format(money / 100.0D);
|
|
|
+ }
|
|
|
|
|
|
/**
|
|
|
- * 查询企业钱包总览信息
|
|
|
+ * 钱包总览信息
|
|
|
*
|
|
|
* @return
|
|
|
*/
|
|
|
@@ -56,15 +142,12 @@ public class WalletService {
|
|
|
if (StringUtils.isBlank(relation)) {
|
|
|
throw new BusinessException("暂未开通电子钱包");
|
|
|
}
|
|
|
- R<List<WalletDto>> wallet = payCenterService.wallet(relation, null, "");
|
|
|
- long sum = 0;
|
|
|
+ R<WalletOverview> wallet = payCenterService.general(relation);
|
|
|
if (wallet.getStatus()) {
|
|
|
- List<WalletDto> data = CollectionUtils.isEmpty(wallet.getData()) ? new ArrayList<>() : wallet.getData();
|
|
|
- for (WalletDto datum : data) {
|
|
|
- sum += datum.getMoney();
|
|
|
- }
|
|
|
+ WalletOverview data = wallet.getData();
|
|
|
+ return new WalletDetail(LoginUserHolder.getEntName(), String.valueOf(data.getTotalMoney()), String.valueOf(data.getTotalMoney() / 100D), data.getChannelTotal(), data.getChannels());
|
|
|
}
|
|
|
- return new WalletDetail(LoginUserHolder.getEntName(), String.valueOf(sum), String.valueOf(sum / 100.0D), 0);
|
|
|
+ return new WalletDetail(LoginUserHolder.getEntName(), "-", "-", 0, new ArrayList<>());
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -73,9 +156,13 @@ public class WalletService {
|
|
|
* @return
|
|
|
*/
|
|
|
public Object walletDetail(WalletDetailReq walletDetailReq) {
|
|
|
+ log.info("查询资金明细:{}", JSONObject.toJSONString(walletDetailReq));
|
|
|
Long entId = LoginUserHolder.getEntId();
|
|
|
- String entName = walletDetailReq.getEntName();
|
|
|
- //todo-xcq 确认下拉选规则参数
|
|
|
+ //查询我方企业开通的渠道
|
|
|
+ String relation = walletRelationService.getRelation(entId);
|
|
|
+ if (StringUtils.isBlank(relation)) {
|
|
|
+ return PageRes.handPage(walletDetailReq.getPage(), walletDetailReq.getPageSize(), new ArrayList<>());
|
|
|
+ }
|
|
|
ChannelEnum channelEnum = null;
|
|
|
if (StringUtils.isNotBlank(walletDetailReq.getChannel())) {
|
|
|
channelEnum = ChannelEnum.getByValue(walletDetailReq.getChannel());
|
|
|
@@ -83,40 +170,40 @@ public class WalletService {
|
|
|
throw new BusinessException("支付通道不存在");
|
|
|
}
|
|
|
}
|
|
|
- //查询我方企业开通的渠道
|
|
|
- String relation = walletRelationService.getRelation(entId);
|
|
|
- if (StringUtils.isBlank(relation)) {
|
|
|
- throw new BusinessException("暂未开通电子钱包");
|
|
|
- }
|
|
|
List<WalletDto> res = new ArrayList<>();
|
|
|
- List<Long> list = new ArrayList<>();
|
|
|
- //筛选企业名称
|
|
|
+ long sum = 0L;
|
|
|
+ //筛选企业
|
|
|
+ String entName = walletDetailReq.getEntName();
|
|
|
if (StringUtils.isNotBlank(entName)) {
|
|
|
- List<EntCacheResDto> entCacheResDto = remoteSystemService.queryEntCacheByName(entName);
|
|
|
+ List<String> filterList = findFilter(entName);
|
|
|
//未筛选出数据
|
|
|
- if (CollectionUtils.isEmpty(entCacheResDto)) {
|
|
|
+ if (CollectionUtils.isEmpty(filterList)) {
|
|
|
return PageRes.handPage(walletDetailReq.getPage(), walletDetailReq.getPageSize(), new ArrayList<>());
|
|
|
}
|
|
|
- list = entCacheResDto.stream().map(EntCacheResDto::getId).toList();
|
|
|
- }
|
|
|
-
|
|
|
- //搜索指定往来单位
|
|
|
- if (!CollectionUtils.isEmpty(list)) {
|
|
|
- for (Long aLong : list) {
|
|
|
- R<List<WalletDto>> wallet = payCenterService.wallet(relation, channelEnum, String.valueOf(aLong));
|
|
|
- if (wallet.getStatus()) {
|
|
|
- List<WalletDto> data = wallet.getData();
|
|
|
- res.addAll(data);
|
|
|
+ for (String filter : filterList) {
|
|
|
+ R<Wallet> walletR = payCenterService.walletSum(relation, channelEnum, filter);
|
|
|
+ if (walletR.getStatus()) {
|
|
|
+ Wallet data = walletR.getData();
|
|
|
+ sum += data.getTotalMoney();
|
|
|
+ List<WalletDto> rows = data.getRows();
|
|
|
+ if (CollectionUtils.isEmpty(rows)) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ res.addAll(rows);
|
|
|
}
|
|
|
}
|
|
|
} else {
|
|
|
//不搜索往来单位
|
|
|
- R<List<WalletDto>> wallet = payCenterService.wallet(relation, channelEnum, "");
|
|
|
+ R<Wallet> wallet = payCenterService.walletSum(relation, channelEnum, "");
|
|
|
if (wallet.getStatus()) {
|
|
|
- List<WalletDto> data = wallet.getData();
|
|
|
- res.addAll(data);
|
|
|
+ Wallet data = wallet.getData();
|
|
|
+ sum += data.getTotalMoney();
|
|
|
+ if (!CollectionUtils.isEmpty(data.getRows())) {
|
|
|
+ res.addAll(data.getRows());
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
List<FundVo> vo = new ArrayList<>();
|
|
|
FundVo fundVo;
|
|
|
|
|
|
@@ -125,9 +212,17 @@ public class WalletService {
|
|
|
fundVo = new FundVo();
|
|
|
BeanUtils.copyProperties(re, fundVo);
|
|
|
fundVo.setChannelLabel(ChannelEnum.getDesc(re.getChannel()));
|
|
|
+ fundVo.setUidName(getFirmName(re.getUid()));
|
|
|
+ fundVo.setFilterName(getFirmName(re.getFilter()));
|
|
|
+ fundVo.setMoney(dfMoney(re.getMoney()));
|
|
|
+ fundVo.setWithdrawingMoney(dfMoney(re.getWithdrawingMoney()));
|
|
|
+ fundVo.setChargingMoney(dfMoney(re.getChargingMoney()));
|
|
|
+ fundVo.setTotalMoney(dfMoney(re.getTotalMoney()));
|
|
|
+// fundVo.setRefundMoney(dfMoney(re.getMoney()));
|
|
|
vo.add(fundVo);
|
|
|
}
|
|
|
- return PageRes.handPage(walletDetailReq.getPage(), walletDetailReq.getPageSize(), vo);
|
|
|
+ DecimalFormat df = new DecimalFormat("0.00");
|
|
|
+ return new MorePageRes<>(walletDetailReq.getPage(), walletDetailReq.getPageSize(), vo, df.format(sum / 100.0D));
|
|
|
}
|
|
|
|
|
|
|
|
|
@@ -137,6 +232,7 @@ public class WalletService {
|
|
|
* @return
|
|
|
*/
|
|
|
public Object addWallet(AddWalletReq addWalletReq) {
|
|
|
+ log.info("新增账目:{}", JSONObject.toJSONString(addWalletReq));
|
|
|
Long entId1 = LoginUserHolder.getEntId();
|
|
|
String uid = walletRelationService.getRelation(entId1);
|
|
|
if (StringUtils.isBlank(uid)) {
|
|
|
@@ -147,22 +243,23 @@ public class WalletService {
|
|
|
if (StringUtils.isBlank(filter)) {
|
|
|
throw new BusinessException("合作单位暂未开通电子钱包");
|
|
|
}
|
|
|
- ChannelEnum channelEnum = ChannelEnum.getByValue(addWalletReq.getChannel());
|
|
|
+ ChannelEnum channelEnum = ChannelEnum.getByChannel(addWalletReq.getChannel());
|
|
|
if (Objects.isNull(channelEnum)) {
|
|
|
- throw new BusinessException("支付通道不能为空");
|
|
|
+ throw new BusinessException("支付通道不存在");
|
|
|
}
|
|
|
-
|
|
|
//1.开通钱包
|
|
|
R<Object> objectR = payCenterService.walletIndex(uid, channelEnum, filter, "");
|
|
|
+ log.info("新增账目-开通钱包:{}", JSONObject.toJSONString(objectR));
|
|
|
if (!objectR.getStatus()) {
|
|
|
throw new BusinessException(StringUtils.isBlank(objectR.getMsg()) ? "钱包开通失败" : objectR.getMsg());
|
|
|
}
|
|
|
- //2.发起预支付
|
|
|
- R<Order> orderR = payCenterService.advancePayApply("", channelEnum, filter, addWalletReq.bigMoney(addWalletReq.getMoney()));
|
|
|
- if (!orderR.getStatus()) {
|
|
|
- throw new BusinessException(StringUtils.isBlank(orderR.getMsg()) ? "预支付失败" : orderR.getMsg());
|
|
|
+ //2.发起充值
|
|
|
+ R<PayIndex> payIndexR = payCenterService.payIndex(uid, filter, channelEnum, addWalletReq.bigMoney(addWalletReq.getMoney()));
|
|
|
+ log.info("新增账目-发起充值:{}", JSONObject.toJSONString(payIndexR));
|
|
|
+ if (!payIndexR.getStatus()) {
|
|
|
+ throw new BusinessException(StringUtils.isBlank(payIndexR.getMsg()) ? "充值失败" : payIndexR.getMsg());
|
|
|
}
|
|
|
- return orderR.getData();
|
|
|
+ return payIndexR.getData();
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -171,6 +268,7 @@ public class WalletService {
|
|
|
* @return
|
|
|
*/
|
|
|
public Object addWalletMoney(AddWalletReq addWalletReq) {
|
|
|
+ log.info("账目充值:{}", JSONObject.toJSONString(addWalletReq));
|
|
|
Long entId1 = LoginUserHolder.getEntId();
|
|
|
String uid = walletRelationService.getRelation(entId1);
|
|
|
if (StringUtils.isBlank(uid)) {
|
|
|
@@ -183,31 +281,63 @@ public class WalletService {
|
|
|
}
|
|
|
ChannelEnum channelEnum = ChannelEnum.getByValue(addWalletReq.getChannel());
|
|
|
if (Objects.isNull(channelEnum)) {
|
|
|
- throw new BusinessException("支付通道不能为空");
|
|
|
+ throw new BusinessException("支付通道不存在");
|
|
|
}
|
|
|
- //发起预支付
|
|
|
- R<Order> orderR = payCenterService.advancePayApply(uid, channelEnum, filter, addWalletReq.bigMoney(addWalletReq.getMoney()));
|
|
|
- if (!orderR.getStatus()) {
|
|
|
- throw new BusinessException(StringUtils.isBlank(orderR.getMsg()) ? "预支付失败" : orderR.getMsg());
|
|
|
+ //发起充值
|
|
|
+ R<PayIndex> payIndexR = payCenterService.payIndex(uid, filter, channelEnum, addWalletReq.bigMoney(addWalletReq.getMoney()));
|
|
|
+ log.info("账目充值-发起充值:{}", JSONObject.toJSONString(payIndexR));
|
|
|
+ if (!payIndexR.getStatus()) {
|
|
|
+ throw new BusinessException(StringUtils.isBlank(payIndexR.getMsg()) ? "充值失败" : payIndexR.getMsg());
|
|
|
}
|
|
|
- return orderR.getData();
|
|
|
+ return payIndexR.getData();
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 提现
|
|
|
+ * 重新提现:只针对汇付
|
|
|
* 1.余额转出
|
|
|
* 2.申请提现
|
|
|
*
|
|
|
* @return
|
|
|
*/
|
|
|
public Object cashOUt(CashWalletReq cashWalletReq) {
|
|
|
+ log.info("提现:{}", JSONObject.toJSONString(cashWalletReq));
|
|
|
ChannelEnum byChannel = ChannelEnum.getByChannel(cashWalletReq.getChannel());
|
|
|
+ if (Objects.isNull(byChannel)) {
|
|
|
+ throw new BusinessException("支付通道不存在");
|
|
|
+ }
|
|
|
//余额转出
|
|
|
R<Object> transfer = payCenterService.transfer(cashWalletReq.getUid(), cashWalletReq.getFilter(), byChannel, cashWalletReq.bigMoney(cashWalletReq.getMoney()));
|
|
|
+ log.info("提现-余额转出:{}", JSONObject.toJSONString(transfer));
|
|
|
if (!transfer.getStatus()) {
|
|
|
throw new BusinessException(StringUtils.isNotBlank(transfer.getMsg()) ? transfer.getMsg() : "提现异常");
|
|
|
}
|
|
|
+ //申请提现
|
|
|
R<Order> orderR = payCenterService.withdrawTake(cashWalletReq.getUid(), byChannel, cashWalletReq.bigMoney(cashWalletReq.getMoney()), cashWalletReq.getRemark());
|
|
|
+ log.info("提现-申请提现:{}", JSONObject.toJSONString(orderR));
|
|
|
+ if (!orderR.getStatus()) {
|
|
|
+ throw new BusinessException(StringUtils.isNotBlank(orderR.getMsg()) ? orderR.getMsg() : "申请提现异常");
|
|
|
+ }
|
|
|
+ return orderR.getData();
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 重新提现
|
|
|
+ * 重新提现:只针对汇付
|
|
|
+ * 1.余额转出
|
|
|
+ * 2.申请提现
|
|
|
+ *
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public Object reCashOUt(CashWalletReq cashWalletReq) {
|
|
|
+ log.info("重新提现:{}", JSONObject.toJSONString(cashWalletReq));
|
|
|
+ ChannelEnum byChannel = ChannelEnum.getByChannel(cashWalletReq.getChannel());
|
|
|
+ if (Objects.isNull(byChannel)) {
|
|
|
+ throw new BusinessException("支付通道不存在");
|
|
|
+ }
|
|
|
+ //申请提现
|
|
|
+ R<Order> orderR = payCenterService.withdrawTake(cashWalletReq.getUid(), byChannel, cashWalletReq.bigMoney(cashWalletReq.getMoney()), cashWalletReq.getRemark());
|
|
|
+ log.info("重新提现-申请提现:{}", JSONObject.toJSONString(orderR));
|
|
|
if (!orderR.getStatus()) {
|
|
|
throw new BusinessException(StringUtils.isNotBlank(orderR.getMsg()) ? orderR.getMsg() : "申请提现异常");
|
|
|
}
|
|
|
@@ -219,8 +349,24 @@ public class WalletService {
|
|
|
*
|
|
|
* @return
|
|
|
*/
|
|
|
- public Object transfer() {
|
|
|
- return null;
|
|
|
+ public Object transfer(TransferReq transferReq) {
|
|
|
+ log.info("转账:{}", JSONObject.toJSONString(transferReq));
|
|
|
+ ChannelEnum channelEnum = ChannelEnum.getByChannel(transferReq.getChannel());
|
|
|
+ if (Objects.isNull(channelEnum)) {
|
|
|
+ throw new BusinessException("支付通道不存在");
|
|
|
+ }
|
|
|
+ List<PatchPay> list = new ArrayList<>();
|
|
|
+ PatchPay patchPay = new PatchPay();
|
|
|
+ patchPay.setUid(transferReq.getFilter());
|
|
|
+ patchPay.setMoney(transferReq.bigMoney(transferReq.getMoney()));
|
|
|
+ patchPay.setRemark(transferReq.getRemark());
|
|
|
+ list.add(patchPay);
|
|
|
+ R<BusinessNo> businessNoR1 = payCenterService.payAgentPayV2(transferReq.getUid(), transferReq.getFilter(),
|
|
|
+ channelEnum, transferReq.bigMoney(transferReq.getMoney()), list, OrderUtils.generateOrderNo("TF"), "2");
|
|
|
+ if (!businessNoR1.getStatus()) {
|
|
|
+ throw new BusinessException(StringUtils.isNotBlank(businessNoR1.getMsg()) ? businessNoR1.getMsg() : "转账失败");
|
|
|
+ }
|
|
|
+ return businessNoR1.getData();
|
|
|
}
|
|
|
|
|
|
|
|
|
@@ -230,30 +376,54 @@ public class WalletService {
|
|
|
* @return
|
|
|
*/
|
|
|
public Object cashList(CashPageReq cashPageReq) {
|
|
|
+ log.info("提现记录:{}", JSONObject.toJSONString(cashPageReq));
|
|
|
Long entId = LoginUserHolder.getEntId();
|
|
|
String uid = walletRelationService.getRelation(entId);
|
|
|
if (StringUtils.isBlank(uid)) {
|
|
|
- return null;
|
|
|
+ return PageRes.handPage(cashPageReq.getPage(), cashPageReq.getPageSize(), new ArrayList<>());
|
|
|
}
|
|
|
ChannelEnum channelEnum = null;
|
|
|
if (StringUtils.isNotBlank(cashPageReq.getChannel())) {
|
|
|
channelEnum = ChannelEnum.getByValue(cashPageReq.getChannel());
|
|
|
if (Objects.isNull(channelEnum)) {
|
|
|
- throw new BusinessException("选择渠道异常");
|
|
|
+ throw new BusinessException("支付通道不存在");
|
|
|
}
|
|
|
}
|
|
|
- String entName = cashPageReq.getEntName();
|
|
|
- if (StringUtils.isNotBlank(entName)) {
|
|
|
- //todo 转换企业名称为filter
|
|
|
-
|
|
|
- }
|
|
|
//查询中台接口
|
|
|
- R<CashPage> cashPageR = payCenterService.withdrawIndex(uid, channelEnum, cashPageReq.getPage(), cashPageReq.getPageSize());
|
|
|
+ R<CashPage> cashPageR = payCenterService.withdrawIndex(uid, channelEnum, cashPageReq.getStatus(), cashPageReq.getPage(), cashPageReq.getPageSize());
|
|
|
if (!cashPageR.getStatus()) {
|
|
|
- return null;
|
|
|
+ return new MorePageRes<>(cashPageReq.getPage(), cashPageReq.getPageSize(), 0, 0, new ArrayList<>(), "0.00");
|
|
|
}
|
|
|
+ CashPage data = cashPageR.getData();
|
|
|
//组装数据
|
|
|
- return cashPageR.getData();
|
|
|
+ return new MorePageRes<>(cashPageReq.getPage(), cashPageReq.getPageSize(), data.getTotal(), (int) (data.getTotal() / cashPageReq.getPageSize() + 1), data.getRows(), String.valueOf(Long.parseLong(data.getTotalWithdrawMoney()) / 100.0D));
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 提现分类页签统计
|
|
|
+ *
|
|
|
+ * @param cashPageReq
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public Object cashCount(CashPageReq cashPageReq) {
|
|
|
+ log.info("提现分类页签统计:{}", JSONObject.toJSONString(cashPageReq));
|
|
|
+ Long entId = LoginUserHolder.getEntId();
|
|
|
+ String uid = walletRelationService.getRelation(entId);
|
|
|
+ if (StringUtils.isBlank(uid)) {
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ ChannelEnum channelEnum = null;
|
|
|
+ if (StringUtils.isNotBlank(cashPageReq.getChannel())) {
|
|
|
+ channelEnum = ChannelEnum.getByValue(cashPageReq.getChannel());
|
|
|
+ if (Objects.isNull(channelEnum)) {
|
|
|
+ throw new BusinessException("支付通道不存在");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ R<List<CashCount>> listR = payCenterService.withdrawCategory(uid, channelEnum);
|
|
|
+ if (listR.getStatus()) {
|
|
|
+ return listR.getData();
|
|
|
+ }
|
|
|
+ return new ArrayList<>();
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -261,28 +431,93 @@ public class WalletService {
|
|
|
*
|
|
|
* @return
|
|
|
*/
|
|
|
- public Object prePayList(PrePayReq prePayReq) {
|
|
|
+ public Object prePayList(PrePayPage prePayPage) {
|
|
|
Long entId = LoginUserHolder.getEntId();
|
|
|
String uid = walletRelationService.getRelation(entId);
|
|
|
if (StringUtils.isBlank(uid)) {
|
|
|
return null;
|
|
|
}
|
|
|
ChannelEnum channelEnum = null;
|
|
|
- if (StringUtils.isNotBlank(prePayReq.getChannel())) {
|
|
|
- channelEnum = ChannelEnum.getByValue(prePayReq.getChannel());
|
|
|
+ if (StringUtils.isNotBlank(prePayPage.getChannel())) {
|
|
|
+ channelEnum = ChannelEnum.getByValue(prePayPage.getChannel());
|
|
|
if (Objects.isNull(channelEnum)) {
|
|
|
- throw new BusinessException("选择渠道异常");
|
|
|
+ throw new BusinessException("支付通道异常");
|
|
|
}
|
|
|
}
|
|
|
- String entName = prePayReq.getEntName();
|
|
|
+ String entName = prePayPage.getEntName();
|
|
|
+ String filter = "";
|
|
|
+ //筛选企业名称
|
|
|
if (StringUtils.isNotBlank(entName)) {
|
|
|
- //todo 转换企业名称为 filter
|
|
|
+ filter = findFilterStr(entName);
|
|
|
+ }
|
|
|
+ // 查询预付数据
|
|
|
+ R<PrePayWalletPage> prePayIndexPageR = payCenterService.advancePayWALLET(uid, channelEnum, filter, prePayPage.getPage(), prePayPage.getPageSize());
|
|
|
+ if (prePayIndexPageR.getStatus()) {
|
|
|
+ PrePayWalletPage data = prePayIndexPageR.getData();
|
|
|
+ return new PageRes<>(prePayPage.getPage(), prePayPage.getPageSize(), data.getTotal(), (int) (data.getTotal() / prePayPage.getPageSize() + 1), data.getRows());
|
|
|
+ }
|
|
|
+ return new PageRes<>(prePayPage.getPage(), prePayPage.getPageSize(), 0, 0, new ArrayList<>());
|
|
|
+
|
|
|
+ }
|
|
|
|
|
|
+ /**
|
|
|
+ * 预收列表
|
|
|
+ *
|
|
|
+ * @param prePayPage
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public Object preReceiveList(PrePayPage prePayPage) {
|
|
|
+ Long entId = LoginUserHolder.getEntId();
|
|
|
+ String uid = walletRelationService.getRelation(entId);
|
|
|
+ if (StringUtils.isBlank(uid)) {
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ ChannelEnum channelEnum = null;
|
|
|
+ if (StringUtils.isNotBlank(prePayPage.getChannel())) {
|
|
|
+ channelEnum = ChannelEnum.getByValue(prePayPage.getChannel());
|
|
|
+ if (Objects.isNull(channelEnum)) {
|
|
|
+ throw new BusinessException("支付通道异常");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ String entName = prePayPage.getEntName();
|
|
|
+ String filter = "";
|
|
|
+ //筛选企业名称
|
|
|
+ if (StringUtils.isNotBlank(entName)) {
|
|
|
+ filter = findFilterStr(entName);
|
|
|
}
|
|
|
- //
|
|
|
- R<PrePayIndexPage> prePayIndexPageR = payCenterService.advancePayIndex(uid, channelEnum, "", prePayReq.getPage(), prePayReq.getPageSize());
|
|
|
+ // 预收列表
|
|
|
+ R<PrePayWalletPage> prePayIndexPageR = payCenterService.advancePayReceive(uid, channelEnum, filter, prePayPage.getPage(), prePayPage.getPageSize());
|
|
|
+ if (prePayIndexPageR.getStatus()) {
|
|
|
+ PrePayWalletPage data = prePayIndexPageR.getData();
|
|
|
+ return new PageRes<>(prePayPage.getPage(), prePayPage.getPageSize(), data.getTotal(), (int) (data.getTotal() / prePayPage.getPageSize() + 1), data.getRows());
|
|
|
+ }
|
|
|
+ return new PageRes<>(prePayPage.getPage(), prePayPage.getPageSize(), 0, 0, new ArrayList<>());
|
|
|
+ }
|
|
|
|
|
|
- return null;
|
|
|
+ /**
|
|
|
+ * 预付校验
|
|
|
+ *
|
|
|
+ * @param prePayCheck
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public Object prePayCheck(PrePayCheck prePayCheck) {
|
|
|
+ String uid = walletRelationService.getRelation(LoginUserHolder.getEntId());
|
|
|
+ if (StringUtils.isBlank(uid)) {
|
|
|
+ throw new BusinessException("您暂未开通电子钱包");
|
|
|
+ }
|
|
|
+ ChannelEnum channelEnum = ChannelEnum.getByValue(prePayCheck.getChannel());
|
|
|
+ if (Objects.isNull(channelEnum)) {
|
|
|
+ throw new BusinessException("支付通道不存在");
|
|
|
+ }
|
|
|
+ R<WalletInfo> walletInfoR = payCenterService.totalInfo(uid, channelEnum, prePayCheck.getFilter());
|
|
|
+ if (!walletInfoR.getStatus()) {
|
|
|
+ throw new BusinessException(StringUtils.isNotBlank(walletInfoR.getMsg()) ? walletInfoR.getMsg() : "未找到交易方");
|
|
|
+ }
|
|
|
+ WalletInfo data = walletInfoR.getData();
|
|
|
+ if (Objects.isNull(data)) {
|
|
|
+ throw new BusinessException("不存在交易");
|
|
|
+ }
|
|
|
+ return data;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -290,8 +525,21 @@ public class WalletService {
|
|
|
*
|
|
|
* @return
|
|
|
*/
|
|
|
- public Object addPrePay() {
|
|
|
- return null;
|
|
|
+ public Object addPrePay(PrePay prePay) {
|
|
|
+ String uid = walletRelationService.getRelation(LoginUserHolder.getEntId());
|
|
|
+ if (StringUtils.isBlank(uid)) {
|
|
|
+ throw new BusinessException("您暂未开通电子钱包");
|
|
|
+ }
|
|
|
+ ChannelEnum channelEnum = ChannelEnum.getByValue(prePay.getChannel());
|
|
|
+ if (Objects.isNull(channelEnum)) {
|
|
|
+ throw new BusinessException("支付通道不存在");
|
|
|
+ }
|
|
|
+
|
|
|
+ R<Order> orderR = payCenterService.advancePayApply(prePay.getUid(), channelEnum, prePay.getFilter(), prePay.bigMoney(prePay.getMoney()));
|
|
|
+ if (!orderR.getStatus()) {
|
|
|
+ throw new BusinessException(StringUtils.isNotBlank(orderR.getMsg()) ? orderR.getMsg() : "预付失败");
|
|
|
+ }
|
|
|
+ return orderR.getData();
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -299,8 +547,21 @@ public class WalletService {
|
|
|
*
|
|
|
* @return
|
|
|
*/
|
|
|
- public Object prePayAppend() {
|
|
|
- return null;
|
|
|
+ public Object prePayAppend(PrePay prePay) {
|
|
|
+ String uid = walletRelationService.getRelation(LoginUserHolder.getEntId());
|
|
|
+ if (StringUtils.isBlank(uid)) {
|
|
|
+ throw new BusinessException("您暂未开通电子钱包");
|
|
|
+ }
|
|
|
+ ChannelEnum channelEnum = ChannelEnum.getByValue(prePay.getChannel());
|
|
|
+ if (Objects.isNull(channelEnum)) {
|
|
|
+ throw new BusinessException("支付通道不存在");
|
|
|
+ }
|
|
|
+
|
|
|
+ R<Order> orderR = payCenterService.advancePayApply(prePay.getUid(), channelEnum, prePay.getFilter(), prePay.bigMoney(prePay.getMoney()));
|
|
|
+ if (!orderR.getStatus()) {
|
|
|
+ throw new BusinessException(StringUtils.isNotBlank(orderR.getMsg()) ? orderR.getMsg() : "预付失败");
|
|
|
+ }
|
|
|
+ return orderR.getData();
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -309,16 +570,108 @@ public class WalletService {
|
|
|
* @return
|
|
|
*/
|
|
|
public Object applyRefund(RefundReq refundReq) {
|
|
|
- return null;
|
|
|
+ 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);
|
|
|
+ if (Objects.nonNull(kwpWalletRefund)) {
|
|
|
+ throw new BusinessException("存在未完成的退款订单");
|
|
|
+ }
|
|
|
+ ChannelEnum channelEnum = ChannelEnum.getByChannel(refundReq.getChannel());
|
|
|
+ if (Objects.isNull(channelEnum)) {
|
|
|
+ throw new BusinessException("支付通道不存在");
|
|
|
+ }
|
|
|
+ KwpWalletRefund kwpWalletRefundAdd = new KwpWalletRefund();
|
|
|
+ kwpWalletRefundAdd.setId(new IdWorker(NumberConstant.ONE).nextId());
|
|
|
+ kwpWalletRefundAdd.setOrderNo(OrderUtils.generateOrderNo("RF"));
|
|
|
+ kwpWalletRefundAdd.setUid(refundReq.getUid());
|
|
|
+ kwpWalletRefundAdd.setFromEnt(walletRelationService.getEnt(refundReq.getUid()));
|
|
|
+ kwpWalletRefundAdd.setFilter(refundReq.getFilter());
|
|
|
+ kwpWalletRefundAdd.setToEnt(walletRelationService.getEnt(refundReq.getFilter()));
|
|
|
+ kwpWalletRefundAdd.setChannel(refundReq.getChannel());
|
|
|
+ kwpWalletRefundAdd.setMoney(refundReq.getMoney());
|
|
|
+ kwpWalletRefundAdd.setRemark(refundReq.getRemark());
|
|
|
+ kwpWalletRefundAdd.setCreateBy(LoginUserHolder.getUserId());
|
|
|
+ kwpWalletRefundAdd.setCreateTime(LocalDateTime.now());
|
|
|
+ kwpWalletRefundAdd.setUpdateBy(LoginUserHolder.getUserId());
|
|
|
+ kwpWalletRefundAdd.setUpdateTime(LocalDateTime.now());
|
|
|
+ kwpWalletRefundAdd.setDelFlag(0);
|
|
|
+ kwpWalletRefundAdd.setStatus(RefundEnum.APPLY.getStatus());
|
|
|
+ kwpWalletRefundMapper.insert(kwpWalletRefundAdd);
|
|
|
+ return "提交成功";
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 发起退款
|
|
|
+ * 中台逻辑:
|
|
|
+ * 预付 A->B 100元
|
|
|
+ * 退款50元,调用2次清分。
|
|
|
+ * 1. 清分 A->B 50元
|
|
|
+ * 2. 清分 B->A 50元
|
|
|
*
|
|
|
* @return
|
|
|
*/
|
|
|
- public Object launchRefund() {
|
|
|
- return null;
|
|
|
+ public Object launchRefund(RefundReq 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);
|
|
|
+ if (Objects.isNull(kwpWalletRefund)) {
|
|
|
+ throw new BusinessException("未找到待完成的退款订单");
|
|
|
+ }
|
|
|
+ ChannelEnum channelEnum = ChannelEnum.getByChannel(refundReq.getChannel());
|
|
|
+ if (Objects.isNull(channelEnum)) {
|
|
|
+ throw new BusinessException("支付通道不存在");
|
|
|
+ }
|
|
|
+ // 1.记账
|
|
|
+ List<PatchPay> list = new ArrayList<>();
|
|
|
+ PatchPay patchPay = new PatchPay();
|
|
|
+ patchPay.setUid(refundReq.getFilter());
|
|
|
+ patchPay.setMoney(refundReq.bigMoney(refundReq.getMoney()));
|
|
|
+ patchPay.setRemark(refundReq.getRemark());
|
|
|
+ list.add(patchPay);
|
|
|
+ R<BusinessNo> businessNoR = payCenterService.payAgentPayV2(refundReq.getUid(), refundReq.getFilter(), channelEnum, refundReq.bigMoney(refundReq.getMoney()), list, kwpWalletRefund.getOrderNo(), "1");
|
|
|
+ if (!businessNoR.getStatus()) {
|
|
|
+ throw new BusinessException(StringUtils.isNotBlank(businessNoR.getMsg()) ? businessNoR.getMsg() : "退款失败");
|
|
|
+ }
|
|
|
+ Long userId = LoginUserHolder.getUserId();
|
|
|
+ //异步提交清分退款任务
|
|
|
+ AsyncPool.addTask(new Refund(refundReq, kwpWalletRefund, payCenterService, kwpWalletRefundMapper, userId));
|
|
|
+ return businessNoR;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 退款处理
|
|
|
+ *
|
|
|
+ * @param refundReq
|
|
|
+ * @param kwpWalletRefund
|
|
|
+ * @param payCenterService
|
|
|
+ * @param kwpWalletRefundMapper
|
|
|
+ * @param userId
|
|
|
+ */
|
|
|
+ private record Refund(RefundReq refundReq, KwpWalletRefund kwpWalletRefund, PayCenterService payCenterService,
|
|
|
+ KwpWalletRefundMapper kwpWalletRefundMapper, Long userId) implements Runnable {
|
|
|
+ private final static Logger log = LoggerFactory.getLogger(Refund.class);
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void run() {
|
|
|
+ ChannelEnum channelEnum = ChannelEnum.getByChannel(refundReq.getChannel());
|
|
|
+ List<PatchPay> list = new ArrayList<>();
|
|
|
+ PatchPay patchPay = new PatchPay();
|
|
|
+ patchPay.setUid(refundReq.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, kwpWalletRefund.getOrderNo(), "2");
|
|
|
+ if (businessNoR1.getStatus()) {
|
|
|
+ kwpWalletRefund.setActualMoney(refundReq.getMoney());
|
|
|
+ kwpWalletRefund.setUpdateBy(userId);
|
|
|
+ kwpWalletRefund.setUpdateTime(LocalDateTime.now());
|
|
|
+ kwpWalletRefund.setStatus(RefundEnum.REFUNDING.getStatus());
|
|
|
+ kwpWalletRefundMapper.updateById(kwpWalletRefund);
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
}
|