|
@@ -1,8 +1,12 @@
|
|
|
package com.qs.mp.channel.service.impl;
|
|
|
|
|
|
+import com.alibaba.fastjson.JSONObject;
|
|
|
import com.baomidou.mybatisplus.core.conditions.Wrapper;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
|
|
+import com.eptok.yspay.opensdkjava.fund.MercFundApi;
|
|
|
+import com.eptok.yspay.opensdkjava.pojo.vo.OnlineReqDataVo;
|
|
|
+import com.eptok.yspay.opensdkjava.util.DateUtil;
|
|
|
import com.qs.mp.channel.domain.Channel;
|
|
|
import com.qs.mp.channel.domain.ChannelBankCard;
|
|
|
import com.qs.mp.channel.domain.ChannelMoneyLog;
|
|
@@ -14,15 +18,26 @@ import com.qs.mp.channel.service.IChannelMoneyLogService;
|
|
|
import com.qs.mp.channel.service.IChannelService;
|
|
|
import com.qs.mp.channel.service.IChannelWithdrawService;
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
+import com.qs.mp.common.constant.YsPayMethodConstants;
|
|
|
+import com.qs.mp.common.constant.YsServerApiConstants;
|
|
|
+import com.qs.mp.common.domain.YsCallLog;
|
|
|
import com.qs.mp.common.enums.ChannelMoneyEnum;
|
|
|
import com.qs.mp.common.enums.ChannelWithdrawStatusEnum;
|
|
|
+import com.qs.mp.common.enums.YsCallBizTypeEnum;
|
|
|
+import com.qs.mp.common.exception.ServiceException;
|
|
|
+import com.qs.mp.common.service.IYsCallLogService;
|
|
|
import com.qs.mp.common.utils.LogUtil;
|
|
|
import com.qs.mp.common.utils.WebhookService;
|
|
|
import java.math.BigDecimal;
|
|
|
import java.math.RoundingMode;
|
|
|
import java.util.Date;
|
|
|
+import java.util.HashMap;
|
|
|
import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
+import org.slf4j.Logger;
|
|
|
+import org.slf4j.LoggerFactory;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.beans.factory.annotation.Value;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
import org.springframework.util.Assert;
|
|
@@ -38,6 +53,28 @@ import org.springframework.util.Assert;
|
|
|
@Service
|
|
|
public class ChannelWithdrawServiceImpl extends ServiceImpl<ChannelWithdrawMapper, ChannelWithdraw> implements IChannelWithdrawService {
|
|
|
|
|
|
+ private final Logger logger = LoggerFactory.getLogger(this.getClass().getSimpleName());
|
|
|
+
|
|
|
+
|
|
|
+ @Value("${ys-pay.private-key-path}")
|
|
|
+ private String privateKeyPath;
|
|
|
+
|
|
|
+ @Value("${ys-pay.public-key-path}")
|
|
|
+ private String publicKeyPath;
|
|
|
+
|
|
|
+
|
|
|
+ @Value("${ys-pay.partner-id}")
|
|
|
+ private String partnerId;
|
|
|
+
|
|
|
+ @Value("${ys-pay.private-key-pass}")
|
|
|
+ private String privateKeyPass;
|
|
|
+
|
|
|
+ @Value("${ys-pay.withdraw-notify-url}")
|
|
|
+ private String ysWithdrawNotifyUrl;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private IYsCallLogService ysCallLogService;
|
|
|
+
|
|
|
@Autowired
|
|
|
private IChannelBankCardService channelBankCardService;
|
|
|
|
|
@@ -114,7 +151,7 @@ public class ChannelWithdrawServiceImpl extends ServiceImpl<ChannelWithdrawMappe
|
|
|
.set(ChannelWithdraw::getStatus, status)
|
|
|
.set(ChannelWithdraw::getTransferTime, new Date())
|
|
|
.eq(ChannelWithdraw::getId, withdraw.getId())
|
|
|
- .eq(ChannelWithdraw::getStatus, ChannelWithdrawStatusEnum.WITHDRAWING));
|
|
|
+ .eq(ChannelWithdraw::getStatus, ChannelWithdrawStatusEnum.WITHDRAW_PROCESS));
|
|
|
Assert.isTrue(rtn, "提现申请审核通过,更新提现申请状态失败。id:" + withdraw.getId());
|
|
|
|
|
|
// 更新冻结金额
|
|
@@ -127,6 +164,66 @@ public class ChannelWithdrawServiceImpl extends ServiceImpl<ChannelWithdrawMappe
|
|
|
.eq(Channel::getChannelId, withdraw.getChannelId())
|
|
|
.eq(Channel::getFrozenMoney, channel.getFrozenMoney()));
|
|
|
Assert.isTrue(updateRtn, "提现申请审核通过,更新账号冻结金额。channelId:" + channel.getChannelId());
|
|
|
+ } else if (status == ChannelWithdrawStatusEnum.WITHDRAW_PROCESS) {
|
|
|
+ String tradeNo = DateUtil.getDateNowYmd() + DateUtil.getRandom(14);;
|
|
|
+
|
|
|
+ // 更新状态为提现处理中
|
|
|
+ boolean rtn = update(new LambdaUpdateWrapper<ChannelWithdraw>()
|
|
|
+ .set(ChannelWithdraw::getTradeNo, tradeNo)
|
|
|
+ .set(ChannelWithdraw::getStatus, status)
|
|
|
+ .eq(ChannelWithdraw::getId, withdraw.getId())
|
|
|
+ .in(ChannelWithdraw::getStatus, ChannelWithdrawStatusEnum.WITHDRAWING, ChannelWithdrawStatusEnum.YS_WITHDRAW_FAILED));
|
|
|
+ Assert.isTrue(rtn, "调用银盛提现接口失败。id:" + withdraw.getId());
|
|
|
+
|
|
|
+ // 调用银盛发起提现
|
|
|
+ OnlineReqDataVo req = new OnlineReqDataVo();
|
|
|
+
|
|
|
+ //银盛支付服务器主动通知商户网站里指定的页面http路径
|
|
|
+ req.setNotifyUrl(ysWithdrawNotifyUrl);
|
|
|
+
|
|
|
+ //商户在银盛支付平台开设的用户号[商户号],接入时需要替换成自己的
|
|
|
+ req.setPartnerId("hyfz_test2");
|
|
|
+ req.setReqUrl(YsServerApiConstants.COMMON_API);
|
|
|
+ req.setPrivateKeyFilePath(privateKeyPath);
|
|
|
+ req.setPrivateKeyPassword(privateKeyPass);
|
|
|
+ req.setYsPublicKeyFilePath(publicKeyPath);
|
|
|
+ //实时提现(一般户到银行卡)业务参数
|
|
|
+ Map<String, Object> bizContent = new HashMap<>();
|
|
|
+ //商户生成的订单号,生成规则前8位必须为交易日期,如20180525,范围跨度支持包含当天在内的前后一天
|
|
|
+ bizContent.put("out_trade_no", tradeNo);
|
|
|
+ //商户号
|
|
|
+ bizContent.put("merchant_usercode", partnerId);
|
|
|
+ //暂时只支持币种:CNY(人民币)
|
|
|
+ bizContent.put("currency", "CNY");
|
|
|
+ //提现的总金额。单位为:RMB Yuan。取值范围为[0.01,99999999.99],精确到小数点后两位。Number(10,2)指10位长度,2位精度
|
|
|
+ bizContent.put("total_amount", new BigDecimal(withdraw.getMoney()).divide(new BigDecimal(100), 2, RoundingMode.HALF_UP).toString());
|
|
|
+ //订单说明
|
|
|
+ bizContent.put("subject", "提现");
|
|
|
+ //商户日期(该参数做交易与查询时需要一致) 该日期需在当日的前后一天时间范围之内
|
|
|
+ bizContent.put("shopdate", DateUtil.getDateNowYmd());
|
|
|
+ //银行帐号
|
|
|
+ bizContent.put("bank_account_no", withdraw.getCardNo());
|
|
|
+ req.setParamData(bizContent);
|
|
|
+ String result = null;
|
|
|
+
|
|
|
+ YsCallLog ysCallLog = new YsCallLog();
|
|
|
+ try{
|
|
|
+ logger.info("实时提现(一般户到银行卡)调用sdk接口addScanMerc请求入参为:"+ JSONObject.toJSONString(req));
|
|
|
+ //根据返回结果处理自己的业务逻辑,result内容详见接口文档
|
|
|
+ result = MercFundApi.withdrawQuick(req);
|
|
|
+ ysCallLog.setResJson(result);
|
|
|
+ logger.info("实时提现(一般户到银行卡)调用sdk接口addScanMerc请求出参为:"+ result);
|
|
|
+ }catch (Exception e){
|
|
|
+ logger.info("实时提现(一般户到银行卡)失败:"+ e.getMessage());
|
|
|
+ throw new ServiceException("调用银盛发起提现失败");
|
|
|
+ }
|
|
|
+
|
|
|
+ ysCallLog.setBizId(String.valueOf(withdraw.getId()));
|
|
|
+ ysCallLog.setBizType(YsCallBizTypeEnum.WITHDRAW);
|
|
|
+ ysCallLog.setInterfaceId(YsPayMethodConstants.GENERAL_ACCOUNT_WITHDRAW_METHOD);
|
|
|
+ ysCallLog.setReqJson(JSONObject.toJSONString(bizContent));
|
|
|
+ ysCallLogService.save(ysCallLog);
|
|
|
+
|
|
|
} else if (status == ChannelWithdrawStatusEnum.FAILED) {
|
|
|
boolean rtn = update(new LambdaUpdateWrapper<ChannelWithdraw>()
|
|
|
.set(ChannelWithdraw::getStatus, status)
|