Commit c5e91ee0 by gonglei

加入框架代码

1 parent 0ada508c
...@@ -16,6 +16,7 @@ import lombok.extern.slf4j.Slf4j; ...@@ -16,6 +16,7 @@ import lombok.extern.slf4j.Slf4j;
import org.springframework.data.domain.Page; import org.springframework.data.domain.Page;
import org.springframework.security.core.Authentication; import org.springframework.security.core.Authentication;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import org.summerframework.core.exception.FieldException;
import org.summerframework.orm.paging.Pagination; import org.summerframework.orm.paging.Pagination;
import java.util.List; import java.util.List;
...@@ -57,7 +58,7 @@ public class RechargeController { ...@@ -57,7 +58,7 @@ public class RechargeController {
* @return * @return
*/ */
@PostMapping("auditRecharge") @PostMapping("auditRecharge")
public Recharge auditRecharge(@Valid @RequestBody ApproveHistory approveHistory, Authentication authentication) throws WxPayException { public Recharge auditRecharge(@Valid @RequestBody ApproveHistory approveHistory, Authentication authentication) throws WxPayException, FieldException {
approveHistory.setUser((User) authentication.getPrincipal()); approveHistory.setUser((User) authentication.getPrincipal());
return transactionService.auditRecharge(approveHistory); return transactionService.auditRecharge(approveHistory);
} }
......
...@@ -245,10 +245,13 @@ public class TransactionService extends AbstractAuctionService { ...@@ -245,10 +245,13 @@ public class TransactionService extends AbstractAuctionService {
@Transactional(propagation = Propagation.REQUIRED, rollbackFor = Exception.class) @Transactional(propagation = Propagation.REQUIRED, rollbackFor = Exception.class)
public Recharge refundRecharge(long rechargeId) throws FieldException { public Recharge refundRecharge(long rechargeId) throws FieldException {
Recharge recharge = rechargeDao.findById(rechargeId).orElseThrow(); Recharge recharge = rechargeDao.findByRechargeId(rechargeId).orElseThrow();
if (recharge.getRefundState() != Deposit.RefundState.UNREFUND) { if (recharge.getRefundState() != Deposit.RefundState.UNREFUND) {
throw new FieldException("refundState", recharge, "订单已退款,不能再次退款"); throw new FieldException("refundState", recharge, "订单已退款,不能再次退款");
} }
if (recharge.getAccount().getSurplus() < recharge.getAmount()) {
throw new FieldException("amount", recharge, "账户余额不足,无法退款");
}
recharge.setAuditState(AuditState.UNAUDITED); recharge.setAuditState(AuditState.UNAUDITED);
return recharge; return recharge;
} }
...@@ -397,12 +400,15 @@ public class TransactionService extends AbstractAuctionService { ...@@ -397,12 +400,15 @@ public class TransactionService extends AbstractAuctionService {
} }
@Transactional(propagation = Propagation.REQUIRED, rollbackFor = Exception.class) @Transactional(propagation = Propagation.REQUIRED, rollbackFor = Exception.class)
public Recharge auditRecharge(ApproveHistory approveHistory) throws WxPayException { public Recharge auditRecharge(ApproveHistory approveHistory) throws WxPayException, FieldException {
Recharge recharge = rechargeDao.findById((long) approveHistory.getApproveId()).orElseThrow(() -> new ObjectNotFoundException(approveHistory.getApproveId(), Withdraw.class.getSimpleName())); Recharge recharge = rechargeDao.findById((long) approveHistory.getApproveId()).orElseThrow(() -> new ObjectNotFoundException(approveHistory.getApproveId(), Withdraw.class.getSimpleName()));
if (approveHistory.getApproveResult() == AuditState.AUDITED && recharge.getAuditState() != AuditState.AUDITED) { if (approveHistory.getApproveResult() == AuditState.AUDITED && recharge.getAuditState() != AuditState.AUDITED) {
if (!StringUtils.hasText(recharge.getOutTradeNo())) { if (!StringUtils.hasText(recharge.getOutTradeNo())) {
throw new WxPayException("退款订单号为空,此订单未支付,不能进行退款操作"); throw new WxPayException("退款订单号为空,此订单未支付,不能进行退款操作");
} }
if (recharge.getAccount().getSurplus() < recharge.getAmount()) {
throw new FieldException("amount", recharge, "账户余额不足,无法退款");
}
WxPayRefundV3Request request = new WxPayRefundV3Request(); WxPayRefundV3Request request = new WxPayRefundV3Request();
WxPayRefundV3Request.Amount amount = new WxPayRefundV3Request.Amount(); WxPayRefundV3Request.Amount amount = new WxPayRefundV3Request.Amount();
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!