|
|
@@ -1,21 +1,50 @@
|
|
|
package com.ydtech.modules.ttqf.service.impl;
|
|
|
|
|
|
+import cn.hutool.extra.spring.SpringUtil;
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
import com.ipaynow.jiaxin.response.BillDownloadResponse;
|
|
|
import com.ipaynow.jiaxin.response.ReceiptlDownloadResponse;
|
|
|
import com.ydtech.core.page.HttpResult;
|
|
|
+import com.ydtech.modules.admin.constants.ManagementSource;
|
|
|
+import com.ydtech.modules.admin.dao.SysAmountAuditingMapper;
|
|
|
+import com.ydtech.modules.admin.dao.SysUserAccountHistoryMapper;
|
|
|
+import com.ydtech.modules.admin.dao.SysUserBankCardMapper;
|
|
|
+import com.ydtech.modules.admin.model.po.*;
|
|
|
+import com.ydtech.modules.admin.model.vo.SysAmountAuditingVo;
|
|
|
+import com.ydtech.modules.admin.service.SysAmountAuditingHistoryService;
|
|
|
+import com.ydtech.modules.admin.service.SysAmountAuditingService;
|
|
|
+import com.ydtech.modules.admin.service.SysSwitchConfigService;
|
|
|
+import com.ydtech.modules.admin.service.SysUserAccountService;
|
|
|
+import com.ydtech.modules.lg.model.PushLgEntity;
|
|
|
+import com.ydtech.modules.ttqf.LgInformationPush;
|
|
|
import com.ydtech.modules.ttqf.PayConstantStatus;
|
|
|
import com.ydtech.modules.ttqf.RetrieveTTQFApi;
|
|
|
+import com.ydtech.modules.ttqf.TtqfDecrypt;
|
|
|
import com.ydtech.modules.ttqf.dao.PaySignCallbackMapper;
|
|
|
import com.ydtech.modules.ttqf.dao.PayTtqfLogMapper;
|
|
|
+import com.ydtech.modules.ttqf.dao.PaymentNoticeMapper;
|
|
|
import com.ydtech.modules.ttqf.entity.PaySignCallback;
|
|
|
import com.ydtech.modules.ttqf.entity.PayTtqfLog;
|
|
|
+import com.ydtech.modules.ttqf.entity.PayUserSign;
|
|
|
+import com.ydtech.modules.ttqf.entity.PaymentNoticeEntity;
|
|
|
+import com.ydtech.modules.ttqf.entity.response.TtqfResponse;
|
|
|
+import com.ydtech.modules.ttqf.entity.vo.UserWithdrawal;
|
|
|
+import com.ydtech.modules.ttqf.entity.vo.WithdrawalFRes;
|
|
|
import com.ydtech.modules.ttqf.service.PayUserSignService;
|
|
|
import com.ydtech.modules.ttqf.service.TtqfService;
|
|
|
+import com.ydtech.utils.StringUtils;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
+import org.apache.commons.lang3.ObjectUtils;
|
|
|
+import org.springframework.beans.BeanUtils;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
+import org.springframework.transaction.annotation.Transactional;
|
|
|
+
|
|
|
+import java.math.BigDecimal;
|
|
|
+import java.util.Date;
|
|
|
+import java.util.Objects;
|
|
|
|
|
|
|
|
|
@Slf4j
|
|
|
@@ -23,15 +52,38 @@ import org.springframework.stereotype.Service;
|
|
|
public class TtqfServiceImpl implements TtqfService {
|
|
|
|
|
|
@Autowired
|
|
|
- private PayTtqfLogMapper ttqfMapper;
|
|
|
+ private PayTtqfLogMapper logMapper;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private SysSwitchConfigService sysSwitchConfigService;
|
|
|
|
|
|
@Autowired
|
|
|
private PayUserSignService userSignService;
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private SysAmountAuditingService sysAmountAuditingService;
|
|
|
|
|
|
@Autowired
|
|
|
private PaySignCallbackMapper signCallbackMapper;
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private PaymentNoticeMapper noticeMapper;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private PayUserSignService signService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private SysAmountAuditingHistoryService sysAmountAuditingHistoryService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private SysUserAccountService sysUserAccountService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private SysUserAccountHistoryMapper sysUserAccountHistoryMapper;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private SysAmountAuditingMapper amountAuditingMapper;
|
|
|
+
|
|
|
@Override
|
|
|
public Object getUserPay(String userId) {
|
|
|
|
|
|
@@ -49,26 +101,109 @@ public class TtqfServiceImpl implements TtqfService {
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public JSONObject userSign(String obj) {
|
|
|
- log.info("接收用户签约回调 + userSign ================={}", obj);
|
|
|
+ public TtqfResponse userSign(String obj) {
|
|
|
+ try {
|
|
|
+ String parse = TtqfDecrypt.parse(obj);
|
|
|
+ if (!StringUtils.isEmpty(parse)){
|
|
|
+ //保存签约回调信息
|
|
|
+ PaySignCallback paySignCallback = JSONObject.parseObject(parse, PaySignCallback.class);
|
|
|
+ paySignCallback.setCreateTime(new Date());
|
|
|
+ int insert = signCallbackMapper.insert(paySignCallback);
|
|
|
+ if (0 < insert){
|
|
|
+ //用户签约回调成功之后更新为签约状态并支持线上打款 签约成功更新状态
|
|
|
+ userSignService.updateUserSign(paySignCallback);
|
|
|
+ SpringUtil.getBean(LgInformationPush.class).push(paySignCallback);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }catch (Exception r){
|
|
|
+ log.info("接收签约通知回调保存失败 + PaySignCallback ================={}", r.getMessage());
|
|
|
+ }
|
|
|
+ return TtqfResponse.ok();
|
|
|
+ }
|
|
|
|
|
|
+ @Override
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
+ public TtqfResponse paymentNotice(String obj) {
|
|
|
+ String parse = TtqfDecrypt.parse(obj);
|
|
|
+ if (!StringUtils.isEmpty(parse)){
|
|
|
+ PaymentNoticeEntity noticeEntity = JSONObject.parseObject(parse, PaymentNoticeEntity.class);
|
|
|
+ noticeEntity.setCreateTime(new Date());
|
|
|
+ noticeMapper.insert(noticeEntity);
|
|
|
+ LambdaQueryWrapper<PayTtqfLog> wrapper = new LambdaQueryWrapper<>();
|
|
|
+ wrapper.eq(PayTtqfLog::getMchOrderNo, noticeEntity.getMchOrderNo());
|
|
|
+ PayTtqfLog ttqfLog = logMapper.selectOne(wrapper);
|
|
|
+ SysAmountAuditingVo amountAuditingVo = new SysAmountAuditingVo();
|
|
|
+ amountAuditingVo.setAmount(noticeEntity.getAmount());
|
|
|
+ amountAuditingVo.setUserId(ttqfLog.getUserId());
|
|
|
+ writeRecord(amountAuditingVo,ttqfLog.getSysAmountAuditingId());
|
|
|
+ }
|
|
|
+ log.info("接收打款通知回调 + paymentNotice ================={}", parse);
|
|
|
+ return TtqfResponse.ok();
|
|
|
+ }
|
|
|
|
|
|
|
|
|
- //保存签约回调信息
|
|
|
- signCallbackMapper.insert(JSONObject.parseObject(JSONObject.toJSONString(obj), PaySignCallback.class));
|
|
|
+ public void writeRecord(SysAmountAuditingVo sysAmountAuditingVo,String id){
|
|
|
+ SysAmountAuditingEntity sysAmountAuditingEntity = sysAmountAuditingService.getById(id);
|
|
|
+ if (ObjectUtils.isEmpty(sysAmountAuditingEntity)){
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ sysAmountAuditingVo.setId(sysAmountAuditingEntity.getId());
|
|
|
+ //提现审核金额
|
|
|
+ BigDecimal amount = sysAmountAuditingVo.getAmount();
|
|
|
+ //提现人
|
|
|
+ String userId = sysAmountAuditingVo.getUserId();
|
|
|
+// SysUserAccount sysUserAccountEntity = new SysUserAccount();
|
|
|
+// 用户扣减金额
|
|
|
+ if (StringUtils.isNotEmpty(userId)) {
|
|
|
+// sysUserAccountEntity.setUserId(userId);
|
|
|
+ //提现人账户
|
|
|
+ SysUserAccount sysUserAccount = sysUserAccountService.getById(userId);
|
|
|
+ if (ObjectUtils.isNotEmpty(sysUserAccount)) {
|
|
|
+ //注释掉原先按类型提现的逻辑 ,改为不区分类型 add by hxl 2024-06-18
|
|
|
+ /**
|
|
|
+ String amountStatus = sysAmountAuditingVo.getAmountStatus();
|
|
|
+ if (StringUtils.isNotEmpty(amountStatus)) {
|
|
|
+ if ("1".equals(amountStatus)) {
|
|
|
+ sysUserAccount.setHandlingAmountAccount(amount);
|
|
|
+ sysUserAccount.setHandlingAmountPayment(sysUserAccount.getHandlingAmountPayment().subtract(amount));
|
|
|
+ // sysUserAccountEntity.setHandlingFee(afterAmount);
|
|
|
+ } else if ("2".equals(amountStatus)) {
|
|
|
+ sysUserAccount.setDocumentaryAmountAccount(amount);
|
|
|
+ sysUserAccount.setDocumentaryAmountpayment(sysUserAccount.getDocumentaryAmountpayment().subtract(amount));
|
|
|
+ // sysUserAccountEntity.setDocumentary(afterAmount);
|
|
|
+ } else {
|
|
|
+ sysUserAccount.setPromotionAmountAccount(amount);
|
|
|
+ sysUserAccount.setPromotionAmountPayment(sysUserAccount.getPromotionAmountPayment().subtract(amount));
|
|
|
+ // sysUserAccountEntity.setPromotion(afterAmount);
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ **/
|
|
|
+ //已到账金额 = 原先的到账金额+ 已到账的金额
|
|
|
+ sysUserAccount.setSumAmountAccount((sysUserAccount.getSumAmountAccount() == null ? BigDecimal.ZERO : sysUserAccount.getSumAmountAccount()).add(amount));
|
|
|
+ //支付中的金额 = 原先的支付金额 -去提现的金额
|
|
|
+ sysUserAccount.setSumAmountPayment((sysUserAccount.getSumAmountPayment() == null ? BigDecimal.ZERO : sysUserAccount.getSumAmountPayment()).subtract(amount));
|
|
|
|
|
|
- //用户签约回调成功之后更新为签约状态并支持线上打款 签约成功更新状态
|
|
|
- if (true){
|
|
|
- userSignService.updateUserSign("");
|
|
|
+ sysUserAccountService.updateById(sysUserAccount);
|
|
|
+ }
|
|
|
+ sysAmountAuditingVo.setAuditingStatus("3");
|
|
|
+ //sysAmountAuditingVo.setAuditingUserId(BaseController.getUser().getId());
|
|
|
+ sysAmountAuditingVo.setAuditingTime(new Date());
|
|
|
+ BeanUtils.copyProperties(sysAmountAuditingVo, sysAmountAuditingEntity);
|
|
|
+ sysAmountAuditingEntity.setCreateTime(null);
|
|
|
+ amountAuditingMapper.updateById(sysAmountAuditingEntity);
|
|
|
+ //通过审核表id查询历史记录表
|
|
|
+ LambdaQueryWrapper<SysUserAccountHistory> lqw = new LambdaQueryWrapper<>();
|
|
|
+ lqw.eq(SysUserAccountHistory::getAuditiingId, sysAmountAuditingEntity.getId());
|
|
|
+ lqw.eq(SysUserAccountHistory::getUserId, userId);
|
|
|
+ //插入轨迹表审核成功数据
|
|
|
+ SysUserAccountHistory sysUserAccountHistory = sysUserAccountHistoryMapper.selectOne(lqw);
|
|
|
+ //插入轨迹表
|
|
|
+ SysAmountAuditingHistory sysAmountAuditingHistory = new SysAmountAuditingHistory(null, sysAmountAuditingEntity.getId(), amount, userId, new Date(), "4", "1", sysUserAccountHistory.getId());
|
|
|
+ sysAmountAuditingHistoryService.save(sysAmountAuditingHistory);
|
|
|
}
|
|
|
- return null;
|
|
|
}
|
|
|
|
|
|
- @Override
|
|
|
- public JSONObject paymentNotice(String obj) {
|
|
|
- log.info("接收打款通知回调 + paymentNotice ================={}", obj);
|
|
|
- return null;
|
|
|
- }
|
|
|
|
|
|
@Override
|
|
|
public HttpResult billDownload(Integer type, String date) {
|
|
|
@@ -88,5 +223,93 @@ public class TtqfServiceImpl implements TtqfService {
|
|
|
return HttpResult.error(response.getBizMsg());
|
|
|
}
|
|
|
|
|
|
+ @Override
|
|
|
+ public HttpResult queryPressing(UserWithdrawal withdrawal) {
|
|
|
+ if (!sysSwitchConfigService.getBalanceExtractStatus()){
|
|
|
+ return HttpResult.ok(WithdrawalFRes.builder().bizCode("0").msg("").url("").build());
|
|
|
+ }
|
|
|
+ SysUserBankCard bankCard = SpringUtil.getBean(SysUserBankCardMapper.class).selectByIdPay(withdrawal.getUserId());
|
|
|
+ if (Objects.isNull(bankCard)){
|
|
|
+ return HttpResult.error("用户不存在,请检查");
|
|
|
+ }
|
|
|
+ if (StringUtils.isEmpty(bankCard.getIdentity())){
|
|
|
+ return HttpResult.error("用户身份证号不存在,请检查");
|
|
|
+ }
|
|
|
+ if (!ManagementSource.MS_02.getCode().equals(bankCard.getManagementSource())){
|
|
|
+ return HttpResult.ok(WithdrawalFRes.builder().bizCode("0").msg("").url("").build());
|
|
|
+ }
|
|
|
+ PayUserSign payUserSign = signService.selectOne(bankCard.getIdentity(),bankCard.getUserId());
|
|
|
+ if (!Objects.isNull(payUserSign)){
|
|
|
+ String signUrl = RetrieveTTQFApi.contractH5(bankCard.getIdentity());
|
|
|
+ if (Objects.equals(PayConstantStatus.SIGN_STATUS,payUserSign.getSign()) &&
|
|
|
+ Objects.equals(PayConstantStatus.AUTH_STATUS,payUserSign.getAuthStatus())){
|
|
|
+
|
|
|
+ return HttpResult.ok(WithdrawalFRes.builder().bizCode("3").msg("已签约").url(signUrl).build());
|
|
|
+ }
|
|
|
+ return HttpResult.ok(WithdrawalFRes.builder().bizCode("2").msg("签约中").url(signUrl).build());
|
|
|
+ }
|
|
|
+ try {
|
|
|
+ boolean sign = RetrieveTTQFApi.queryPressing(bankCard.getIdentity());
|
|
|
+ return HttpResult.ok(WithdrawalFRes.builder().bizCode(sign ? "3" : "1").url("").msg(sign ? "已签约" : "未签约").build());
|
|
|
+ }catch (Exception e){
|
|
|
+ log.info("查询签约状态异常:{}", e.getMessage());
|
|
|
+ return HttpResult.error();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public HttpResult signingAddress(UserWithdrawal withdrawal) {
|
|
|
+ SysUserBankCard bankCard = SpringUtil.getBean(SysUserBankCardMapper.class).selectByIdPay(withdrawal.getUserId());
|
|
|
+ if (Objects.isNull(bankCard)){
|
|
|
+ return HttpResult.error("用户不存在,请检查");
|
|
|
+ }
|
|
|
+ if (StringUtils.isEmpty(bankCard.getIdentity())){
|
|
|
+ return HttpResult.error("用户身份证号不存在,请检查");
|
|
|
+ }
|
|
|
+ String pres = RetrieveTTQFApi.pres(bankCard);
|
|
|
+ if (!StringUtils.isEmpty(pres)){
|
|
|
+ signService.saveUserSign(bankCard.getIdentity(),bankCard.getUserId());
|
|
|
+ }
|
|
|
+ return HttpResult.ok(WithdrawalFRes.builder().bizCode("").url(pres).msg("").build());
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
+ public HttpResult userCashOut(UserWithdrawal withdrawal) {
|
|
|
+ SysUserBankCard bankCard = SpringUtil.getBean(SysUserBankCardMapper.class).selectByIdPay(withdrawal.getUserId());
|
|
|
+ if (Objects.isNull(bankCard)){
|
|
|
+ return HttpResult.error("用户不存在,请检查");
|
|
|
+ }
|
|
|
+ if (StringUtils.isEmpty(bankCard.getIdentity())){
|
|
|
+ return HttpResult.error("用户身份证号不存在,请检查");
|
|
|
+ }
|
|
|
+ if (!ManagementSource.MS_02.getCode().equals(bankCard.getManagementSource())){
|
|
|
+ return HttpResult.error("用户不是个代,请线下申请提现");
|
|
|
+ }
|
|
|
+ boolean balance = RetrieveTTQFApi.extractBalance(bankCard, withdrawal);
|
|
|
+ if (balance){
|
|
|
+ //推送提现记录
|
|
|
+ sendCollect( bankCard, withdrawal);
|
|
|
+ }
|
|
|
+ return HttpResult.ok(balance);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ public void sendCollect(SysUserBankCard bankCard,UserWithdrawal withdrawal){
|
|
|
+ PushLgEntity lgEntity = new PushLgEntity();
|
|
|
+
|
|
|
+ SysAmountAuditingVo sysAmountAuditingVo = new SysAmountAuditingVo();
|
|
|
+ sysAmountAuditingVo.setId("");
|
|
|
+ sysAmountAuditingVo.setUserId(bankCard.getUserId());
|
|
|
+ sysAmountAuditingVo.setBankNumber(bankCard.getBankNumber());
|
|
|
+ sysAmountAuditingVo.setAmount(withdrawal.getAmount());
|
|
|
+ sysAmountAuditingVo.setCreateTime(new Date());
|
|
|
+ sysAmountAuditingVo.setAuditingStatus("");
|
|
|
+ sysAmountAuditingVo.setUserName(bankCard.getUserName());
|
|
|
+ sysAmountAuditingVo.setMobile(bankCard.getMobile());
|
|
|
+ //sendCollectUtils.sendCollect(sysAmountAuditingVo);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
|
|
|
}
|