|
@@ -10,18 +10,23 @@ import com.alipay.api.response.AlipayTradeCreateResponse;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
|
|
import com.eptok.yspay.opensdkjava.common.Constants;
|
|
|
+import com.eptok.yspay.opensdkjava.fund.MercFundApi;
|
|
|
import com.eptok.yspay.opensdkjava.orderpay.AppPayApi;
|
|
|
+import com.eptok.yspay.opensdkjava.pojo.vo.OnlineReqDataVo;
|
|
|
import com.eptok.yspay.opensdkjava.util.DateUtil;
|
|
|
import com.eptok.yspay.opensdkjava.util.HttpClientUtil;
|
|
|
import com.eptok.yspay.opensdkjava.util.StringUtil;
|
|
|
import com.eptok.yspay.opensdkjava.util.YsOnlineSignUtils;
|
|
|
+import com.qs.mp.channel.domain.ChannelWithdraw;
|
|
|
import com.qs.mp.channel.service.IChannelOrderService;
|
|
|
+import com.qs.mp.channel.service.IChannelWithdrawService;
|
|
|
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.AppSourceEnum;
|
|
|
import com.qs.mp.common.enums.AsyncTaskTypeEnum;
|
|
|
import com.qs.mp.common.enums.BizTypeEnum;
|
|
|
+import com.qs.mp.common.enums.ChannelWithdrawStatusEnum;
|
|
|
import com.qs.mp.common.enums.MqTopicType;
|
|
|
import com.qs.mp.common.enums.PayOrderStatusEnum;
|
|
|
import com.qs.mp.common.enums.YsCallBizTypeEnum;
|
|
@@ -55,6 +60,7 @@ import org.springframework.stereotype.Component;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
import java.util.Objects;
|
|
|
+import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
/**
|
|
|
* @auther duota
|
|
@@ -87,6 +93,9 @@ public class WalletServiceImpl implements IWalletService {
|
|
|
@Autowired
|
|
|
private IAsyncTaskService asyncTaskService;
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private IChannelWithdrawService channelWithdrawService;
|
|
|
+
|
|
|
@Autowired
|
|
|
private IYsCallLogService ysCallLogService;
|
|
|
|
|
@@ -167,6 +176,9 @@ public class WalletServiceImpl implements IWalletService {
|
|
|
@Value("${ys-pay.pay-notify-url}")
|
|
|
private String ysPayNotifyUrl;
|
|
|
|
|
|
+ @Value("${ys-pay.withdraw-notify-url}")
|
|
|
+ private String ysWithdrawNotifyUrl;
|
|
|
+
|
|
|
@Override
|
|
|
public JSONObject h5Pay(BizTypeEnum bizType, String bizId, int money, String orderRemark) {
|
|
|
Map<String, String> params = new HashMap<>();
|
|
@@ -451,6 +463,86 @@ public class WalletServiceImpl implements IWalletService {
|
|
|
}
|
|
|
|
|
|
|
|
|
+ @Override
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
+ public boolean withdrawal(String bizId) {
|
|
|
+ ChannelWithdraw channelWithdraw = channelWithdrawService.getById(bizId);
|
|
|
+
|
|
|
+ if (!ChannelWithdrawStatusEnum.WITHDRAWING.equals(channelWithdraw.getStatus())) {
|
|
|
+ throw new ServiceException("提现状态不正确");
|
|
|
+ }
|
|
|
+
|
|
|
+ String tradeNo = DateUtil.getDateNowYmd() + DateUtil.getRandom(14);
|
|
|
+
|
|
|
+ boolean res = channelWithdrawService.update(new LambdaUpdateWrapper<ChannelWithdraw>()
|
|
|
+ .set(ChannelWithdraw::getTradeNo, tradeNo)
|
|
|
+ .set(ChannelWithdraw::getStatus, ChannelWithdrawStatusEnum.WITHDRAW_PROCESS)
|
|
|
+ .eq(ChannelWithdraw::getId, channelWithdraw.getId())
|
|
|
+ .eq(ChannelWithdraw::getStatus, ChannelWithdrawStatusEnum.WITHDRAWING));
|
|
|
+ if (!res) {
|
|
|
+ throw new ServiceException("提现状态更新失败");
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ OnlineReqDataVo req = new OnlineReqDataVo();
|
|
|
+ req.setReqUrl(YsServerApiConstants.COMMON_API);
|
|
|
+ req.setPrivateKeyFilePath(privateKeyPath);
|
|
|
+ req.setYsPublicKeyFilePath(publicKeyPath);
|
|
|
+ req.setPrivateKeyPassword(privateKeyPass);
|
|
|
+ req.setNotifyUrl(ysWithdrawNotifyUrl);
|
|
|
+ req.setPartnerId(partnerId);
|
|
|
+
|
|
|
+ //实时提现(一般户到银行卡)业务参数
|
|
|
+ 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(channelWithdraw.getMoney()).divide(new BigDecimal(100), 2, RoundingMode.HALF_UP).toString());
|
|
|
+ //订单说明
|
|
|
+ bizContent.put("subject", "提现备注");
|
|
|
+ //商户日期(该参数做交易与查询时需要一致) 该日期需在当日的前后一天时间范围之内
|
|
|
+ bizContent.put("shopdate", DateUtil.getDateNowYmd());
|
|
|
+ //银行帐号
|
|
|
+ bizContent.put("bank_account_no", channelWithdraw.getCardNo());
|
|
|
+ req.setParamData(bizContent);
|
|
|
+ String result = null;
|
|
|
+ try{
|
|
|
+ logger.info("实时提现(一般户到银行卡)调用sdk接口addScanMerc请求入参为:"+ JSONObject.toJSONString(req));
|
|
|
+ //根据返回结果处理自己的业务逻辑,result内容详见接口文档
|
|
|
+ result = MercFundApi.withdrawQuick(req);
|
|
|
+ }catch (Exception e){
|
|
|
+ logger.info("实时提现(一般户到银行卡)失败:"+ e.getMessage());
|
|
|
+ }
|
|
|
+
|
|
|
+ logger.info("提现提交result = " + result);
|
|
|
+
|
|
|
+ // 保存调用日志
|
|
|
+ YsCallLog ysCallLog = new YsCallLog();
|
|
|
+ ysCallLog.setInterfaceId(YsPayMethodConstants.SETTLED_ACCOUNT_WITHDRAW_METHOD);
|
|
|
+ ysCallLog.setBizId(tradeNo);
|
|
|
+ ysCallLog.setBizType(YsCallBizTypeEnum.WITHDRAW);
|
|
|
+ ysCallLog.setReqJson(JSONObject.toJSONString(bizContent));
|
|
|
+ ysCallLog.setResJson(result);
|
|
|
+ ysCallLogService.save(ysCallLog);
|
|
|
+
|
|
|
+ if (StringUtils.isBlank(result)) {
|
|
|
+ throw new ServiceException("提现交易处理失败");
|
|
|
+ }
|
|
|
+
|
|
|
+ JSONObject response = JSONObject.parseObject(result);
|
|
|
+ String tradeStatus = (String) response.get("trade_status");
|
|
|
+ if (StringUtils.isBlank(tradeStatus) &&
|
|
|
+ (!"TRADE_ACCEPT_SUCCESS".equals(tradeStatus) || !"TRADE_SUCCESS".equals(tradeStatus))) {
|
|
|
+ logger.error("提现交易处理失败,result = " + result);
|
|
|
+ throw new ServiceException("提现交易处理失败");
|
|
|
+ }
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+
|
|
|
@Override
|
|
|
public void payOrderStatusHandle(PayOrder payOrder) {
|
|
|
String orderNo = payOrder.getOrderId();
|