Commit c5e91ee0 by gonglei

加入框架代码

1 parent 0ada508c
......@@ -16,6 +16,7 @@ import lombok.extern.slf4j.Slf4j;
import org.springframework.data.domain.Page;
import org.springframework.security.core.Authentication;
import org.springframework.web.bind.annotation.*;
import org.summerframework.core.exception.FieldException;
import org.summerframework.orm.paging.Pagination;
import java.util.List;
......@@ -57,7 +58,7 @@ public class RechargeController {
* @return
*/
@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());
return transactionService.auditRecharge(approveHistory);
}
......
......@@ -245,10 +245,13 @@ public class TransactionService extends AbstractAuctionService {
@Transactional(propagation = Propagation.REQUIRED, rollbackFor = Exception.class)
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) {
throw new FieldException("refundState", recharge, "订单已退款,不能再次退款");
}
if (recharge.getAccount().getSurplus() < recharge.getAmount()) {
throw new FieldException("amount", recharge, "账户余额不足,无法退款");
}
recharge.setAuditState(AuditState.UNAUDITED);
return recharge;
}
......@@ -397,12 +400,15 @@ public class TransactionService extends AbstractAuctionService {
}
@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()));
if (approveHistory.getApproveResult() == AuditState.AUDITED && recharge.getAuditState() != AuditState.AUDITED) {
if (!StringUtils.hasText(recharge.getOutTradeNo())) {
throw new WxPayException("退款订单号为空,此订单未支付,不能进行退款操作");
}
if (recharge.getAccount().getSurplus() < recharge.getAmount()) {
throw new FieldException("amount", recharge, "账户余额不足,无法退款");
}
WxPayRefundV3Request request = new WxPayRefundV3Request();
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!