Răsfoiți Sursa

提现相关

Evan 2 ani în urmă
părinte
comite
18b4d2fc49

+ 5 - 1
mp-admin/src/main/java/com/qs/mp/web/controller/api/admin/ChannelWithdrawMgrController.java

@@ -108,9 +108,13 @@ public class ChannelWithdrawMgrController extends BaseApiController {
       return error(ErrorCodeEnum.ERROR_CODE_1001);
     }
     ChannelWithdraw channelWithdraw = channelWithdrawService.getById(withdraw.getId());
-    if (channelWithdraw.getStatus() != ChannelWithdrawStatusEnum.WITHDRAWING) {
+    if (channelWithdraw.getStatus() != ChannelWithdrawStatusEnum.WITHDRAWING
+        && channelWithdraw.getStatus() != ChannelWithdrawStatusEnum.YS_WITHDRAW_FAILED) {
       return error("提现申请状态异常,不是提现中");
     }
+    if (ChannelWithdrawStatusEnum.FINISHED.equals(withdraw.getStatus())) {
+      withdraw.setStatus(ChannelWithdrawStatusEnum.WITHDRAW_PROCESS);
+    }
     channelWithdrawService.verify(channelWithdraw, withdraw.getStatus(), withdraw.getVerifyContent());
     return AjaxResult.success("操作成功");
   }

+ 19 - 17
mp-admin/src/main/java/com/qs/mp/web/controller/api/callback/YsPayCallBackController.java

@@ -74,11 +74,6 @@ public class YsPayCallBackController {
     @Value("${ys-pay.div-notify-url}")
     private String ysDivNotifyUrl;
 
-    @Value("${ys-pay.master-seller-id}")
-    private String masterSellerId;
-
-    @Value("${ys-pay.child-seller-id}")
-    private String childSellerId;
 
     @Autowired
     private IPayOrderService payOrderService;
@@ -326,10 +321,18 @@ public class YsPayCallBackController {
         logger.info("提现回调的数据 = " + JSONObject.toJSONString(params));
         String tradeNo = params.get("out_trade_no");
 
+        ChannelWithdraw channelWithdraw = channelWithdrawService.getOne(new LambdaQueryWrapper<ChannelWithdraw>()
+            .eq(ChannelWithdraw::getTradeNo, tradeNo));
+        if (channelWithdraw == null) {
+            logger.error("提现记录不存在,不处理回调,tradeNo:" + tradeNo);
+            responseWrite(response, "fail");
+            return;
+        }
+
         // 记录回调数据
-        // TODO: 类型,一般账户 和 待结算账户
+        // 类型,一般账户 和 待结算账户
         YsCallLog ysCallLog = ysCallLogService.getOne(new LambdaQueryWrapper<YsCallLog>()
-            .eq(YsCallLog::getBizId, tradeNo)
+            .eq(YsCallLog::getBizId, channelWithdraw.getId())
             .eq(YsCallLog::getBizType, YsCallBizTypeEnum.WITHDRAW));
         if (ysCallLog != null) {
             ysCallLogService.update(new LambdaUpdateWrapper<YsCallLog>()
@@ -337,9 +340,6 @@ public class YsPayCallBackController {
                 .eq(YsCallLog::getId, ysCallLog.getId()));
         }
 
-        ChannelWithdraw channelWithdraw = channelWithdrawService.getOne(new LambdaQueryWrapper<ChannelWithdraw>()
-            .eq(ChannelWithdraw::getTradeNo, tradeNo));
-
 
         if (!ChannelWithdrawStatusEnum.WITHDRAW_PROCESS.equals(channelWithdraw.getStatus())) {
             logger.error("提现状态不是银盛提现处理中,不处理回调,tradeNo:" + tradeNo);
@@ -358,14 +358,16 @@ public class YsPayCallBackController {
             return;
         }
 
+        // 处理提现成功后的逻辑
+        channelWithdrawService.verify(channelWithdraw, ChannelWithdrawStatusEnum.FINISHED,"");
         // 提现成功,状态修改
-        boolean res = channelWithdrawService.update(new LambdaUpdateWrapper<ChannelWithdraw>()
-            .set(ChannelWithdraw::getStatus, ChannelWithdrawStatusEnum.FINISHED)
-            .eq(ChannelWithdraw::getId, channelWithdraw.getId())
-            .eq(ChannelWithdraw::getStatus, ChannelWithdrawStatusEnum.WITHDRAW_PROCESS));
-        if (!res) {
-            logger.error("更新提现记录状态失败,tradeNo:{}", tradeNo);
-        }
+//        boolean res = channelWithdrawService.update(new LambdaUpdateWrapper<ChannelWithdraw>()
+//            .set(ChannelWithdraw::getStatus, ChannelWithdrawStatusEnum.FINISHED)
+//            .eq(ChannelWithdraw::getId, channelWithdraw.getId())
+//            .eq(ChannelWithdraw::getStatus, ChannelWithdrawStatusEnum.WITHDRAW_PROCESS));
+//        if (!res) {
+//            logger.error("更新提现记录状态失败,tradeNo:{}", tradeNo);
+//        }
         responseWrite(response, "success");
     }
 

+ 98 - 1
mp-service/src/main/java/com/qs/mp/channel/service/impl/ChannelWithdrawServiceImpl.java

@@ -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)