Commit 70e49466 authored by libin's avatar libin

提现

parent 513b1ce8
......@@ -38,6 +38,7 @@ public class BaseException extends RuntimeException {
public BaseException(String message,String subCode){
super(message);
this.status=400;
this.subCode = subCode;
}
......
......@@ -5,6 +5,7 @@ import com.github.wxiaoqi.security.common.exception.BaseException;
import com.github.wxiaoqi.security.common.msg.BaseResponse;
import com.github.wxiaoqi.security.common.msg.ObjectRestResponse;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;
......@@ -16,7 +17,7 @@ public class PlatformExceptionHandler {
public BaseResponse baseExceptionHandler(Exception e) {
if (e instanceof BaseException){
BaseException be = (BaseException) e;
return new BaseResponse(be.getStatus(), be.getMessage());
return new BaseResponse(be.getStatus(), StringUtils.isEmpty(be.getSubCode())?"NAN":be.getSubCode(), be.getMessage());
}
return new BaseResponse(400,e.getMessage());
}
......
......@@ -7,8 +7,15 @@ import com.github.wxiaoqi.security.common.constant.RestCode;
*/
public class BaseResponse {
private int status = 200;
private String subCode;
private String message = "SUCCESS";
public BaseResponse(int status,String subCode,String message) {
this.status = status;
this.subCode = subCode;
this.message = message;
}
public BaseResponse(int status, String message) {
this.status = status;
this.message = message;
......@@ -33,6 +40,14 @@ public class BaseResponse {
this.status = status;
}
public void setSubCode(String subCode) {
this.subCode = subCode;
}
public String getSubCode() {
return subCode;
}
public BaseResponse status(int status) {
this.status = status;
return this;
......
......@@ -92,8 +92,9 @@ public class MyWalletBiz extends BaseBiz<MyWalletMapper, MyWallet> implements In
private DateTimeFormatter dateTimeFormatter;
private static final Integer WITHDRAW_ONLINE_WAY=1;
private static final Integer WITHDRAW_OFFLINE_WAY=2;
private static final Integer WITHDRAW_ONLINE_WAY = 1;
private static final Integer WITHDRAW_OFFLINE_WAY = 2;
private static final Integer SUCCESS = 200;
private BCryptPasswordEncoder encoder = new BCryptPasswordEncoder(12);
......@@ -318,10 +319,9 @@ public class MyWalletBiz extends BaseBiz<MyWalletMapper, MyWallet> implements In
}
log.info("-----提现申请-----proceduReates===" + sumDto.getProceduReates() + "----commission====" + commission + "---realAmount===" + realAmount);
ObjectRestResponse<String> response = null;
//线上自动提现
if (WITHDRAW_ONLINE_WAY.equals(withdrawWay)){
String pay_no;
if (WITHDRAW_ONLINE_WAY.equals(withdrawWay)) {
String cono = OrderUtil.GetOrderNumber("");
HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
String host = StringUtils.defaultIfBlank(request.getHeader("userHost"), ClientUtil.getClientIp(request));
......@@ -334,16 +334,15 @@ public class MyWalletBiz extends BaseBiz<MyWalletMapper, MyWallet> implements In
.type(applyCathVo.getCathType())
.creatIp(host)
.build();
try {
//商户订单号
pay_no = thirdFeign.transferAccount(fundPayVo);
response = thirdFeign.transferAccount(fundPayVo);
if (response.getStatus() == SUCCESS) {
walletCath.setStauts(1);
walletCath.setCono(pay_no);
walletCath.setCono(String.valueOf(response.getData()));
walletCath.setFinishTime(Instant.now().toEpochMilli());
}catch (BaseException baex){
throw new BaseException(baex.getMessage(),400);
}catch (Exception ex){
throw new BaseException((applyCathVo.getCathType() == 0?"微信提现":applyCathVo.getCathType() == 1?"支付宝提现":"银行提现")+"转账失败",ex);
} else {
walletCath.setStauts(2);
walletCath.setReason(response.getMessage());
}
}
//提现单号
......@@ -359,8 +358,12 @@ public class MyWalletBiz extends BaseBiz<MyWalletMapper, MyWallet> implements In
walletCath.setCommission(commission);
walletCath.setRealAmount(realAmount);
myWalletCathBiz.insertSelective(walletCath);
//提现金额
BigDecimal withdrawals = new BigDecimal(0);
if (response != null && response.getStatus() == SUCCESS) {
//提现金额
BigDecimal withdrawals = realAmount.add(commission);
withdrawals = realAmount.add(commission);
balnece = balnece.subtract(withdrawals).setScale(2, RoundingMode.HALF_UP);
log.info("------钱包----withdrawals===" + withdrawals + "----balnece====" + balnece);
MyWallet myWallet = new MyWallet();
......@@ -370,8 +373,10 @@ public class MyWalletBiz extends BaseBiz<MyWalletMapper, MyWallet> implements In
myWallet.setWithdrawals(withdrawals);
myWallet.setVersion(sumDto.getVersion());
mapper.updMyWater(myWallet);
}
//线上提现
if (WITHDRAW_ONLINE_WAY.equals(applyCathVo.getCathType())){
if (WITHDRAW_ONLINE_WAY.equals(applyCathVo.getCathType()) && response != null && response.getStatus() == SUCCESS) {
MyWalletDetail detail = new MyWalletDetail();
detail.setUserId(userId);
detail.setItype(1);
......@@ -414,8 +419,9 @@ public class MyWalletBiz extends BaseBiz<MyWalletMapper, MyWallet> implements In
BigDecimal balance = cath.getBalance();
BigDecimal realAmount = cath.getRealAmount();
BigDecimal commission = cath.getCommission();
ObjectRestResponse<String> response = null;
if (status == 1) {
String cono = StringUtil.isEmpty(cath.getCono()) ? OrderUtil.GetOrderNumber(""):cath.getCono();
String cono = StringUtil.isEmpty(cath.getCono()) ? OrderUtil.GetOrderNumber("") : cath.getCono();
HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
String host = StringUtils.defaultIfBlank(request.getHeader("userHost"), ClientUtil.getClientIp(request));
FundPayVo fundPayVo = FundPayVo.builder()
......@@ -427,24 +433,25 @@ public class MyWalletBiz extends BaseBiz<MyWalletMapper, MyWallet> implements In
.type(cath.getCathType())
.creatIp(host)
.build();
try {
cono = thirdFeign.transferAccount(fundPayVo);
} catch (BaseException bex) {
if (PaySubErrorCodeEnum.PAY_NEED_ERROR.getSubCode().equals(bex.getSubCode())) {
response = thirdFeign.transferAccount(fundPayVo);
if (response.getStatus() != SUCCESS) {
if (PaySubErrorCodeEnum.PAY_NEED_ERROR.getSubCode().equals(response.getSubCode())) {
isContinuePay = true;
errorMsg = bex.getMessage();
errorMsg = response.getMessage();
cath.setCono(cono);
} else {
throw new BaseException(bex.getMessage(),400);
}
} catch (Exception ex) {
throw new BaseException(ex);
return ObjectRestResponse.createFailedResult(400, response.getMessage());
}
} else {
cath.setStauts(isContinuePay ? 0 : status);
//设置第三方单号
cath.setCono(cono);
cath.setCono(response.getData());
cath.setFinishTime(System.currentTimeMillis());
myWalletCathBiz.updateSelectiveByIdRe(cath);
}
if (SUCCESS == response.getStatus() || isContinuePay) {
myWalletCathBiz.updateSelectiveByIdRe(cath);
}
MyWalletDetail detail = new MyWalletDetail();
detail.setUserId(userId);
detail.setItype(1);
......
......@@ -82,7 +82,7 @@ public interface ThirdFeign {
/*************************************支付***************************************/
@PostMapping("/pay/app/unauth/transfer_account")
String transferAccount(@RequestBody FundPayVo fundPayVo) throws Exception;
ObjectRestResponse<String> transferAccount(@RequestBody FundPayVo fundPayVo);
@GetMapping("/info/app/unauth/getAliPayUserInfo")
......
......@@ -2,6 +2,7 @@ package com.xxfc.platform.universal.controller;
import com.alibaba.fastjson.JSONObject;
import com.github.wxiaoqi.security.auth.client.annotation.IgnoreUserToken;
import com.github.wxiaoqi.security.common.msg.ObjectRestResponse;
import com.github.wxiaoqi.security.common.rest.BaseController;
import com.xxfc.platform.universal.biz.OrderPayBiz;
import com.xxfc.platform.universal.entity.OrderPay;
......@@ -11,6 +12,7 @@ import com.xxfc.platform.universal.weixin.util.XMLUtil;
import lombok.extern.slf4j.Slf4j;
import org.jdom.JDOMException;
import org.springframework.web.bind.annotation.*;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.ByteArrayOutputStream;
......@@ -91,9 +93,10 @@ public class OrderPayController extends BaseController<OrderPayBiz,OrderPay> {
}
out.print("<xml><return_code><![CDATA[SUCCESS]]></return_code><return_msg><![CDATA[]]></return_msg></xml>");
} else
} else {
out.print("<xml><return_code><![CDATA[SUCCESS]]></return_code><return_msg><![CDATA[]]></return_msg></xml>");
}
}
@PostMapping(value = "/app/unauth/notify/alipay")
......@@ -105,8 +108,14 @@ public class OrderPayController extends BaseController<OrderPayBiz,OrderPay> {
@PostMapping("/app/unauth/transfer_account")
@IgnoreUserToken
public String transferAccount(@RequestBody FundPayVo fundPayVo) throws Exception {
return baseBiz.fundTrans(fundPayVo);
public ObjectRestResponse<String> transferAccount(@RequestBody FundPayVo fundPayVo){
try {
String pay_no = baseBiz.fundTrans(fundPayVo);
return ObjectRestResponse.succ(pay_no);
}catch (Exception ex){
return ObjectRestResponse.createFailedResult(400,ex.getMessage());
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment