|
|
@@ -3,18 +3,25 @@ package com.sckw.payment.service;
|
|
|
import cn.hutool.core.bean.BeanUtil;
|
|
|
import cn.hutool.core.collection.CollUtil;
|
|
|
import cn.hutool.core.util.IdUtil;
|
|
|
+import cn.hutool.core.util.NumberUtil;
|
|
|
import cn.hutool.core.util.StrUtil;
|
|
|
import com.alibaba.fastjson2.JSONObject;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
|
import com.github.pagehelper.PageHelper;
|
|
|
import com.github.pagehelper.PageInfo;
|
|
|
+import com.sckw.core.exception.BusinessException;
|
|
|
import com.sckw.core.model.enums.EntTypeEnum;
|
|
|
import com.sckw.core.model.page.PageRes;
|
|
|
+import com.sckw.core.model.vo.FileInfoVO;
|
|
|
+import com.sckw.core.web.constant.HttpStatus;
|
|
|
import com.sckw.core.web.context.LoginEntHolder;
|
|
|
import com.sckw.core.web.context.LoginUserHolder;
|
|
|
-import com.sckw.payment.api.model.dto.TradeEntInfoResVo;
|
|
|
+import com.sckw.core.web.response.BaseResult;
|
|
|
+import com.sckw.file.api.dubbo.RemoteFileService;
|
|
|
+import com.sckw.payment.api.model.TradeEntInfoResVo;
|
|
|
import com.sckw.payment.api.model.dto.common.R;
|
|
|
+import com.sckw.payment.config.ApplicationProperties;
|
|
|
import com.sckw.payment.entity.KwpWallet;
|
|
|
import com.sckw.payment.entity.KwpWalletCash;
|
|
|
import com.sckw.payment.entity.KwpWalletSplit;
|
|
|
@@ -24,6 +31,7 @@ import com.sckw.payment.enums.WalletStatusEnum;
|
|
|
import com.sckw.payment.mapper.KwpWalletCashMapper;
|
|
|
import com.sckw.payment.mapper.KwpWalletMapper;
|
|
|
import com.sckw.payment.mapper.KwpWalletSplitMapper;
|
|
|
+import com.sckw.payment.pojo.CashParaPage;
|
|
|
import com.sckw.payment.pojo.CashVo;
|
|
|
import com.sckw.payment.pojo.UpdateCash;
|
|
|
import com.sckw.payment.pojo.dto.*;
|
|
|
@@ -35,7 +43,6 @@ import com.sckw.payment.pojo.vo.req.WalletPrepaidQuery;
|
|
|
import com.sckw.payment.pojo.vo.res.WalletPayableSummary;
|
|
|
import com.sckw.payment.pojo.vo.res.WalletPrepaidSummary;
|
|
|
import com.sckw.payment.pojo.vo.res.WalletSummary;
|
|
|
-import com.sckw.payment.utils.MoneyUtil;
|
|
|
import com.sckw.redis.config.RedisLockUtil;
|
|
|
import com.sckw.system.api.RemoteSystemService;
|
|
|
import com.sckw.system.api.model.dto.res.EntCacheResDto;
|
|
|
@@ -69,9 +76,8 @@ import java.util.stream.Collectors;
|
|
|
public class WalletService {
|
|
|
private final PayXwService payXwService;
|
|
|
private final KwpWalletCashMapper kwpWalletCashMapper;
|
|
|
- // private final KwpWalletSubMapper kwpWalletSubMapper;
|
|
|
private final KwpWalletMapper kwpWalletMapper;
|
|
|
-
|
|
|
+ private final ApplicationProperties applicationProperties;
|
|
|
@DubboReference(version = "1.0.0", group = "design", check = false)
|
|
|
private RemoteSystemService remoteSystemService;
|
|
|
@Autowired
|
|
|
@@ -79,7 +85,8 @@ public class WalletService {
|
|
|
@Autowired
|
|
|
private IWalletPayableService walletPayableService;
|
|
|
private final RedisLockUtil redisLockUtil;
|
|
|
- private final FileService fileService;
|
|
|
+ @DubboReference(version = "1.0.0", group = "design", check = false)
|
|
|
+ private RemoteFileService remoteFileService;
|
|
|
@Resource
|
|
|
private KwpWalletSplitMapper kwpWalletSplitMapper;
|
|
|
|
|
|
@@ -147,18 +154,14 @@ public class WalletService {
|
|
|
|
|
|
if (Objects.nonNull(kwpWalletCash)) {
|
|
|
MultipartFile file = cashDto.getFile();
|
|
|
- R<FileDto> stringR = R.fail("");
|
|
|
- try {
|
|
|
- stringR = fileService.fileUpload(file);
|
|
|
- } catch (Exception e) {
|
|
|
- log.error("文件上传失败 {}", e.getMessage());
|
|
|
+ BaseResult<FileInfoVO> httpResult = remoteFileService.fileUpload(file);
|
|
|
+ if (HttpStatus.SUCCESS_CODE == httpResult.getCode()) {
|
|
|
+ FileInfoVO data = httpResult.getData();
|
|
|
+ kwpWalletCash.setImg(Objects.nonNull(data) ? data.getFileAbsolutePath() : "");
|
|
|
}
|
|
|
- FileDto data = stringR.getData();
|
|
|
-
|
|
|
- Long deal = MoneyUtil.bigMoney(new BigDecimal(amt));
|
|
|
- kwpWalletCash.setImg(Objects.nonNull(data) ? data.getFileAbsolutePath() : "");
|
|
|
+ BigDecimal deal = new BigDecimal(amt);
|
|
|
kwpWalletCash.setAmount(deal);
|
|
|
- kwpWalletCash.setCashAmount(kwpWalletCash.getCashAmount() - deal);
|
|
|
+ kwpWalletCash.setCashAmount(NumberUtil.sub(kwpWalletCash.getCashAmount(), deal));
|
|
|
kwpWalletCash.setStatus(1);
|
|
|
kwpWalletCashMapper.updateById(kwpWalletCash);
|
|
|
} else {
|
|
|
@@ -178,17 +181,12 @@ public class WalletService {
|
|
|
.eq(KwpWalletSplit::getStatus, 1)
|
|
|
);
|
|
|
if (Objects.nonNull(kwpWalletSplit)) {
|
|
|
- R<FileDto> stringR = R.fail("");
|
|
|
- try {
|
|
|
- if (Objects.nonNull(file) && !file.isEmpty()) {
|
|
|
- stringR = fileService.fileUpload(file);
|
|
|
- }
|
|
|
- } catch (Exception e) {
|
|
|
- log.error("清分凭证上传失败 {}", e.getMessage());
|
|
|
+ BaseResult<FileInfoVO> httpResult = remoteFileService.fileUpload(file);
|
|
|
+ if (HttpStatus.SUCCESS_CODE == httpResult.getCode()) {
|
|
|
+ FileInfoVO data = httpResult.getData();
|
|
|
+ kwpWalletSplit.setImg(Objects.nonNull(data) ? data.getFileAbsolutePath() : "");
|
|
|
}
|
|
|
- FileDto data = stringR.getData();
|
|
|
|
|
|
- kwpWalletSplit.setImg(Objects.nonNull(data) ? data.getFileAbsolutePath() : "");
|
|
|
kwpWalletSplit.setStatus(StrUtil.equals(splitDto.getStatus(), "true") ? 2 : 3);
|
|
|
kwpWalletSplitMapper.updateById(kwpWalletSplit);
|
|
|
//
|
|
|
@@ -198,9 +196,9 @@ public class WalletService {
|
|
|
|
|
|
if (Objects.nonNull(kwpWallet)) {
|
|
|
if (Objects.equals(kwpWallet.getCashFlag(), 2)) {
|
|
|
- Long amount = MoneyUtil.bigMoney(new BigDecimal(splitDto.getAmt()));
|
|
|
- long sub = kwpWallet.getCashAmount() - amount;
|
|
|
- if (sub < 0L) {
|
|
|
+ BigDecimal amount = new BigDecimal(splitDto.getAmt());
|
|
|
+ BigDecimal sub = NumberUtil.sub(kwpWallet.getCashAmount(), amount);
|
|
|
+ if (sub.compareTo(new BigDecimal("0")) < 0) {
|
|
|
log.error("提现余额不足 {} {}", kwpWallet.getCashAmount(), amount);
|
|
|
}
|
|
|
KwpWalletCash kwpWalletCash = new KwpWalletCash();
|
|
|
@@ -227,7 +225,7 @@ public class WalletService {
|
|
|
withdrawDto.setUid(kwpWallet.getUid());
|
|
|
withdrawDto.setOrderNo(kwpWalletCash.getOrderNo());
|
|
|
withdrawDto.setAmt(splitDto.getAmt());
|
|
|
- withdrawDto.setNoticeUrl("/notice/cash");
|
|
|
+ withdrawDto.setNoticeUrl(applicationProperties.getCash());
|
|
|
withdrawDto.setSummary("");
|
|
|
withdrawDto.setRemark("提现");
|
|
|
withdrawDto.setCommission("0.00");
|
|
|
@@ -253,67 +251,6 @@ public class WalletService {
|
|
|
}
|
|
|
|
|
|
|
|
|
- /**
|
|
|
- * 提现
|
|
|
- * 重新提现:只针对汇付 3.20调整为只有新网渠道,其它渠道不接入
|
|
|
- *
|
|
|
- * @return
|
|
|
- */
|
|
|
-// @Transactional(rollbackFor = Exception.class)
|
|
|
-// public Object cashOUt(CashWalletReq cashWalletReq) {
|
|
|
-// log.info("提现:{}", JSONObject.toJSONString(cashWalletReq));
|
|
|
-// Long entId = LoginUserHolder.getEntId();
|
|
|
-//
|
|
|
-// KwpWallet kwpWallet = kwpWalletMapper.selectOne(Wrappers.lambdaQuery(KwpWallet.class).eq(KwpWallet::getEntId, entId));
|
|
|
-// if (Objects.isNull(kwpWallet)) {
|
|
|
-// throw new BusinessException("企业钱包不存在");
|
|
|
-// }
|
|
|
-// Long amount = cashWalletReq.bigMoney(cashWalletReq.getMoney());
|
|
|
-// long sub = kwpWallet.getCashAmount() - amount;
|
|
|
-// if (sub < 0L) {
|
|
|
-// throw new BusinessException("提现余额不足");
|
|
|
-// }
|
|
|
-// String key = String.format(RedisConstant.CASH_LOCK, entId);
|
|
|
-//
|
|
|
-// if (redisLockUtil.tryLock(key)) {
|
|
|
-// try {
|
|
|
-// KwpWalletCash kwpWalletCash = new KwpWalletCash();
|
|
|
-// kwpWalletCash.setFromEnt(entId);
|
|
|
-// kwpWalletCash.setToEnt(0L);
|
|
|
-// kwpWalletCash.setOrderNo(IdUtil.getSnowflakeNextIdStr());
|
|
|
-// kwpWalletCash.setAction(1);
|
|
|
-// kwpWalletCash.setAmount(amount);
|
|
|
-// kwpWalletCash.setCashAmount(sub);
|
|
|
-// kwpWalletCash.setImg("");
|
|
|
-// kwpWalletCash.setRemark(cashWalletReq.getRemark());
|
|
|
-// kwpWalletCash.setStatus(3);
|
|
|
-// kwpWalletCash.setCreateBy(0L);
|
|
|
-// kwpWalletCash.setCreateTime(LocalDateTime.now());
|
|
|
-// kwpWalletCash.setUpdateBy(0L);
|
|
|
-// kwpWalletCash.setUpdateTime(LocalDateTime.now());
|
|
|
-// kwpWalletCash.setDelFlag(0);
|
|
|
-//
|
|
|
-//
|
|
|
-// WithdrawDto withdrawDto = new WithdrawDto();
|
|
|
-// R<WithdrawRes> payIndexR = payXwService.withDraw(withdrawDto);
|
|
|
-// if (!payIndexR.getStatus()) {
|
|
|
-// kwpWalletCash.setStatus(2);//提现失败
|
|
|
-// } else {
|
|
|
-// //todo 提现成功在扣减,并更新主钱包
|
|
|
-//// kwpWallet.setCashAmount(sub);
|
|
|
-//// kwpWalletMapper.updateById(kwpWallet);
|
|
|
-// }
|
|
|
-// kwpWalletCashMapper.insert(kwpWalletCash);
|
|
|
-// return kwpWalletCash.getId();
|
|
|
-// } finally {
|
|
|
-// redisLockUtil.unlock(key);
|
|
|
-// }
|
|
|
-// }
|
|
|
-// throw new BusinessException("请稍后再试");
|
|
|
-//
|
|
|
-// }
|
|
|
-
|
|
|
-
|
|
|
/**
|
|
|
* 渠道开通
|
|
|
*
|
|
|
@@ -324,7 +261,7 @@ public class WalletService {
|
|
|
Long entId = createUserReq.getEntId();
|
|
|
EntCacheResDto entCacheResDto = remoteSystemService.queryEntCacheById(entId);
|
|
|
if (Objects.isNull(entCacheResDto)) {
|
|
|
- throw new ServiceException("未找到企业信息");
|
|
|
+ throw new BusinessException("未找到企业信息");
|
|
|
}
|
|
|
List<EntCertificateResDto> certificateInfo = entCacheResDto.getCertificateInfo();
|
|
|
Map<Integer, String> certMap = new HashMap<>();
|
|
|
@@ -345,21 +282,21 @@ public class WalletService {
|
|
|
userPara.setLegalIds(certMap.get(2));
|
|
|
userPara.setLegalName(entCacheResDto.getLegalName());
|
|
|
userPara.setLegalPhone(entCacheResDto.getLegalPhone());
|
|
|
- userPara.setNoticeUrl("");//todo 填写当前服务地址,通知开户成功
|
|
|
+ userPara.setNoticeUrl(applicationProperties.getAccount());
|
|
|
R<CreateUser> createUserR = payXwService.beforeCreateUser(userPara);
|
|
|
if (createUserR.getCode() != 200) {
|
|
|
- throw new ServiceException(createUserR.getMsg());
|
|
|
+ throw new BusinessException(createUserR.getMsg());
|
|
|
}
|
|
|
KwpWallet kwpWallet = new KwpWallet();
|
|
|
kwpWallet.setEntId(entId);
|
|
|
kwpWallet.setUid(userPara.getUid());
|
|
|
kwpWallet.setEntType(Integer.valueOf(entCacheResDto.getEntTypes()));
|
|
|
- kwpWallet.setCashAmount(0L);
|
|
|
- kwpWallet.setPrepayAmount(0L);
|
|
|
- kwpWallet.setDealingAmount(0L);
|
|
|
- kwpWallet.setFreightAmount(0L);
|
|
|
- kwpWallet.setProcessingAmount(0L);
|
|
|
- kwpWallet.setPayingAmount(0L);
|
|
|
+ kwpWallet.setCashAmount(new BigDecimal("0"));
|
|
|
+ kwpWallet.setPrepayAmount(new BigDecimal("0"));
|
|
|
+ kwpWallet.setDealingAmount(new BigDecimal("0"));
|
|
|
+ kwpWallet.setFreightAmount(new BigDecimal("0"));
|
|
|
+ kwpWallet.setProcessingAmount(new BigDecimal("0"));
|
|
|
+ kwpWallet.setPayingAmount(new BigDecimal("0"));
|
|
|
kwpWallet.setChannel("xinwang");
|
|
|
kwpWallet.setStatus(1);
|
|
|
kwpWallet.setRemark("");
|
|
|
@@ -421,9 +358,23 @@ public class WalletService {
|
|
|
summary.setTradingFreightTotal(walletPayableSummary.getTradingFreightTotal());
|
|
|
summary.setPayingFreightTotal(walletPayableSummary.getPayingFreightTotal());
|
|
|
}
|
|
|
-
|
|
|
- bean.setStatusLabel(WalletStatusEnum.getByCode(one.getStatus()));
|
|
|
- bean.setCashAmount(MoneyUtil.smallMoney(one.getCashAmount()));
|
|
|
+ if (Objects.equals(one.getStatus(), 1)) {//开户中,兜底查询支付服务,判定用户是否开户成功
|
|
|
+ R<UserDetailDto> account = payXwService.account(new UserInfo(one.getUid()));
|
|
|
+ if (account.getCode() == 200) {
|
|
|
+ UserDetailDto data = account.getData();
|
|
|
+ if (Objects.nonNull(data)) {
|
|
|
+ if (Objects.equals(data.getAuditFlag(), 6)) {//开户成功
|
|
|
+ bean.setStatus(2);
|
|
|
+ one.setStatus(2);
|
|
|
+ kwpWalletMapper.updateById(one);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ bean.setStatusLabel(WalletStatusEnum.getByCode(bean.getStatus()));
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ bean.setStatusLabel(WalletStatusEnum.getByCode(one.getStatus()));
|
|
|
+ }
|
|
|
+ bean.setCashAmount(one.getCashAmount());
|
|
|
bean.setPrepayAmount(summary.getPreBalanceTotal());
|
|
|
bean.setDealingAmount(summary.getPreTradingAmountTotal());
|
|
|
bean.setFreightAmount(summary.getFreightTotal());
|
|
|
@@ -432,7 +383,7 @@ public class WalletService {
|
|
|
|
|
|
return R.ok(bean);
|
|
|
}
|
|
|
- return R.fail("暂未开通钱包");
|
|
|
+ return R.failed("暂未开通钱包");
|
|
|
}
|
|
|
|
|
|
|
|
|
@@ -445,7 +396,7 @@ public class WalletService {
|
|
|
.eq(Objects.nonNull(cashParaPage.getAction()), KwpWalletCash::getAction, cashParaPage.getAction())
|
|
|
.eq(Objects.nonNull(cashParaPage.getStatus()), KwpWalletCash::getStatus, cashParaPage.getStatus())
|
|
|
.between(Objects.nonNull(cashParaPage.getStartAmount()) && Objects.nonNull(cashParaPage.getEndAmount()),
|
|
|
- KwpWalletCash::getAmount, cashParaPage.bigMoney(cashParaPage.getStartAmount()), cashParaPage.bigMoney(cashParaPage.getEndAmount()))
|
|
|
+ KwpWalletCash::getAmount, cashParaPage.getStartAmount(), cashParaPage.getEndAmount())
|
|
|
.between(StrUtil.isNotBlank(cashParaPage.getStartCreateTime()) && StrUtil.isNotBlank(cashParaPage.getEndCreateTime()), KwpWalletCash::getCreateTime, cashParaPage.getStartCreateTime(), cashParaPage.getEndCreateTime())
|
|
|
.like(StrUtil.isNotBlank(cashParaPage.getOrderNo()), KwpWalletCash::getOrderNo, cashParaPage.getOrderNo())
|
|
|
.eq(KwpWalletCash::getDelFlag, 0)
|
|
|
@@ -455,8 +406,8 @@ public class WalletService {
|
|
|
CashVo bean = BeanUtil.toBean(d, CashVo.class);
|
|
|
bean.setActionLabel(CashActionEnum.getByCode(d.getAction()));
|
|
|
bean.setStatusLabel(CashStatusEnum.getByCode(d.getStatus()));
|
|
|
- bean.setCashAmount(MoneyUtil.smallMoney(d.getCashAmount()));
|
|
|
- bean.setAmount(MoneyUtil.smallMoney(d.getAmount()));
|
|
|
+ bean.setCashAmount(d.getCashAmount());
|
|
|
+ bean.setAmount(d.getAmount());
|
|
|
bean.setFromEntName(getFirmName(d.getFromEnt()));
|
|
|
bean.setToEntName(getFirmName(d.getToEnt()));
|
|
|
return bean;
|
|
|
@@ -470,12 +421,11 @@ public class WalletService {
|
|
|
|
|
|
KwpWallet kwpWallet = kwpWalletMapper.selectOne(Wrappers.lambdaQuery(KwpWallet.class).eq(KwpWallet::getEntId, entId));
|
|
|
if (Objects.isNull(kwpWallet)) {
|
|
|
- throw new ServiceException("企业钱包不存在");
|
|
|
+ throw new BusinessException("企业钱包不存在");
|
|
|
}
|
|
|
- Long amount = cashWalletReq.bigMoney(cashWalletReq.getMoney());
|
|
|
- long sub = kwpWallet.getCashAmount() - amount;
|
|
|
- if (sub < 0L) {
|
|
|
- throw new ServiceException("提现余额不足");
|
|
|
+ BigDecimal sub = NumberUtil.sub(kwpWallet.getCashAmount(), cashWalletReq.getMoney());
|
|
|
+ if (sub.compareTo(new BigDecimal("0")) < 0) {
|
|
|
+ throw new BusinessException("提现余额不足");
|
|
|
}
|
|
|
String key = String.format("sckw:cash:%s", entId);
|
|
|
|
|
|
@@ -487,7 +437,7 @@ public class WalletService {
|
|
|
kwpWalletCash.setToEnt(entId);
|
|
|
kwpWalletCash.setOrderNo(IdUtil.getSnowflakeNextIdStr());
|
|
|
kwpWalletCash.setAction(1);
|
|
|
- kwpWalletCash.setAmount(amount);
|
|
|
+ kwpWalletCash.setAmount(cashWalletReq.getMoney());
|
|
|
kwpWalletCash.setCashAmount(sub);
|
|
|
kwpWalletCash.setImg("");
|
|
|
kwpWalletCash.setRemark(cashWalletReq.getRemark());
|
|
|
@@ -518,7 +468,7 @@ public class WalletService {
|
|
|
redisLockUtil.unlock(key);
|
|
|
}
|
|
|
}
|
|
|
- throw new ServiceException("请稍后再试");
|
|
|
+ throw new BusinessException("请稍后再试");
|
|
|
}
|
|
|
|
|
|
public R<WalletCashVo> cashInfo() {
|
|
|
@@ -528,11 +478,11 @@ public class WalletService {
|
|
|
WalletCashVo bean = BeanUtil.toBean(one, WalletCashVo.class);
|
|
|
|
|
|
bean.setStatusLabel(WalletStatusEnum.getByCode(one.getStatus()));
|
|
|
- bean.setCashAmount(MoneyUtil.smallMoney(one.getCashAmount()));
|
|
|
+ bean.setCashAmount(one.getCashAmount());
|
|
|
|
|
|
return R.ok(bean);
|
|
|
}
|
|
|
- return R.fail("暂未开通钱包");
|
|
|
+ return R.failed("暂未开通钱包");
|
|
|
}
|
|
|
|
|
|
public List<TradeEntInfoResVo> queryEntList() {
|
|
|
@@ -542,7 +492,7 @@ public class WalletService {
|
|
|
.select(KwpWalletCash::getFromEnt));
|
|
|
if (CollUtil.isNotEmpty(kwpWalletCashes)) {
|
|
|
List<Long> collect = kwpWalletCashes.stream().map(KwpWalletCash::getFromEnt).toList();
|
|
|
- List<EntInfo> entInfos = remoteSystemService.queryEntInfos(collect);
|
|
|
+ List<EntCacheResDto> entInfos = remoteSystemService.queryEntCacheByIds(collect);
|
|
|
return entInfos.stream().map(d -> BeanUtil.toBean(d, TradeEntInfoResVo.class)).collect(Collectors.toList());
|
|
|
}
|
|
|
return CollUtil.newArrayList();
|