Commit 4340589c authored by libin's avatar libin

Merge branch 'master-auto-pay' into base-modify

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