|
|
@ -87,7 +87,8 @@ public class RefundServiceImpl implements RefundService, ApplicationEventPublish
|
|
|
|
throw new RefundExistException();
|
|
|
|
throw new RefundExistException();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (apply.isEmpty()) {
|
|
|
|
if (apply.isEmpty()) {
|
|
|
|
order.put("available", BigDecimal.valueOf(order.getDoubleValue("customer_payment_amount")).subtract(BigDecimal.valueOf(order.getDoubleValue("refund_fee"))).doubleValue());
|
|
|
|
order.put("available", BigDecimal.valueOf(order.getDoubleValue("customer_payment_amount"))
|
|
|
|
|
|
|
|
.subtract(BigDecimal.valueOf(order.getDoubleValue("refund_fee"))).doubleValue());
|
|
|
|
return order;
|
|
|
|
return order;
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
if (account != null) {
|
|
|
|
if (account != null) {
|
|
|
@ -118,7 +119,8 @@ public class RefundServiceImpl implements RefundService, ApplicationEventPublish
|
|
|
|
if (undoRefundOrder != null) {
|
|
|
|
if (undoRefundOrder != null) {
|
|
|
|
throw new BadRequestException("该笔订单有退款正在处理,请稍后再试!");
|
|
|
|
throw new BadRequestException("该笔订单有退款正在处理,请稍后再试!");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
order.put("available", BigDecimal.valueOf(order.getDoubleValue("customer_payment_amount")).subtract(BigDecimal.valueOf(order.getDoubleValue("refund_fee"))).doubleValue());
|
|
|
|
order.put("available", BigDecimal.valueOf(order.getDoubleValue("customer_payment_amount"))
|
|
|
|
|
|
|
|
.subtract(BigDecimal.valueOf(order.getDoubleValue("refund_fee"))).doubleValue());
|
|
|
|
return order;
|
|
|
|
return order;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -143,12 +145,13 @@ public class RefundServiceImpl implements RefundService, ApplicationEventPublish
|
|
|
|
int clientId = order.getIntValue("client_id");
|
|
|
|
int clientId = order.getIntValue("client_id");
|
|
|
|
String currency = order.getString("currency");
|
|
|
|
String currency = order.getString("currency");
|
|
|
|
|
|
|
|
|
|
|
|
//增加角色审核
|
|
|
|
// 增加角色审核
|
|
|
|
JSONObject client = clientManager.getClientInfo(clientId);
|
|
|
|
JSONObject client = clientManager.getClientInfo(clientId);
|
|
|
|
Assert.notNull(client, "client not exists");
|
|
|
|
Assert.notNull(client, "client not exists");
|
|
|
|
JSONObject clientConfig = clientConfigService.find(clientId);
|
|
|
|
JSONObject clientConfig = clientConfigService.find(clientId);
|
|
|
|
OperatorType type = account != null ? OperatorType.PARTNER : OperatorType.MANAGER;
|
|
|
|
OperatorType type = account != null ? OperatorType.PARTNER : OperatorType.MANAGER;
|
|
|
|
boolean requireAudit = type == OperatorType.PARTNER && PartnerRole.getRole(account.getIntValue("role")) == PartnerRole.CASHIER && clientConfig.getBooleanValue("enable_refund_auth");
|
|
|
|
boolean requireAudit = type == OperatorType.PARTNER && PartnerRole.getRole(account.getIntValue("role")) == PartnerRole.CASHIER
|
|
|
|
|
|
|
|
&& clientConfig.getBooleanValue("enable_refund_auth");
|
|
|
|
logger.debug("applyer type=" + type + "; require audit=" + requireAudit);
|
|
|
|
logger.debug("applyer type=" + type + "; require audit=" + requireAudit);
|
|
|
|
|
|
|
|
|
|
|
|
paymentApi.clientRefundBalanceCheck(clientId, orderId, currency, feeAmount);
|
|
|
|
paymentApi.clientRefundBalanceCheck(clientId, orderId, currency, feeAmount);
|
|
|
@ -189,9 +192,9 @@ public class RefundServiceImpl implements RefundService, ApplicationEventPublish
|
|
|
|
|
|
|
|
|
|
|
|
BigDecimal realAmount = original ? fee : CurrencyAmountUtils.toAmount(fee, order.getString("currency"));
|
|
|
|
BigDecimal realAmount = original ? fee : CurrencyAmountUtils.toAmount(fee, order.getString("currency"));
|
|
|
|
JSONObject refundConfig = checkRefundAuditFlag();
|
|
|
|
JSONObject refundConfig = checkRefundAuditFlag();
|
|
|
|
if (partnerAccount!=null && refundConfig != null && refundConfig.size() > 0 && refundConfig.getBoolean("refundAudit")) {
|
|
|
|
if (partnerAccount != null && refundConfig != null && refundConfig.size() > 0 && refundConfig.getBoolean("refundAudit")) {
|
|
|
|
if (realAmount.compareTo(refundConfig.getBigDecimal("refundAuditAmount")) > 0) {
|
|
|
|
if (realAmount.compareTo(refundConfig.getBigDecimal("refundAuditAmount")) > 0) {
|
|
|
|
//订单需要审核
|
|
|
|
// 订单需要审核
|
|
|
|
boolean casherRefund = reviewNewRefundOrder(orderId, realAmount, remark, partnerAccount, manager);
|
|
|
|
boolean casherRefund = reviewNewRefundOrder(orderId, realAmount, remark, partnerAccount, manager);
|
|
|
|
if (casherRefund) {
|
|
|
|
if (casherRefund) {
|
|
|
|
return executeRefund(orderId, realAmount, remark, partnerAccount, manager, order, client);
|
|
|
|
return executeRefund(orderId, realAmount, remark, partnerAccount, manager, order, client);
|
|
|
@ -204,7 +207,8 @@ public class RefundServiceImpl implements RefundService, ApplicationEventPublish
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private JSONObject executeRefund(String orderId, BigDecimal amount, String remark, JSONObject partnerAccount, JSONObject manager, JSONObject order, JSONObject client) {
|
|
|
|
private JSONObject executeRefund(String orderId, BigDecimal amount, String remark, JSONObject partnerAccount, JSONObject manager, JSONObject order,
|
|
|
|
|
|
|
|
JSONObject client) {
|
|
|
|
checkOrderUseCustomerCoupon(order, amount);
|
|
|
|
checkOrderUseCustomerCoupon(order, amount);
|
|
|
|
JSONObject clientConfig = clientConfigService.find(client.getIntValue("client_id"));
|
|
|
|
JSONObject clientConfig = clientConfigService.find(client.getIntValue("client_id"));
|
|
|
|
OperatorType type = partnerAccount != null ? OperatorType.PARTNER : OperatorType.MANAGER;
|
|
|
|
OperatorType type = partnerAccount != null ? OperatorType.PARTNER : OperatorType.MANAGER;
|
|
|
@ -220,12 +224,13 @@ public class RefundServiceImpl implements RefundService, ApplicationEventPublish
|
|
|
|
operator.put("operator_id", manager.getIntValue("manager_id"));
|
|
|
|
operator.put("operator_id", manager.getIntValue("manager_id"));
|
|
|
|
operator.put("operator", manager.getString("display_name"));
|
|
|
|
operator.put("operator", manager.getString("display_name"));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
boolean requireAudit = type == OperatorType.PARTNER && PartnerRole.getRole(partnerAccount.getIntValue("role")) == PartnerRole.CASHIER && clientConfig.getBooleanValue("enable_refund_auth");
|
|
|
|
boolean requireAudit = type == OperatorType.PARTNER && PartnerRole.getRole(partnerAccount.getIntValue("role")) == PartnerRole.CASHIER
|
|
|
|
|
|
|
|
&& clientConfig.getBooleanValue("enable_refund_auth");
|
|
|
|
logger.debug("applyer type=" + type + "; require audit=" + requireAudit);
|
|
|
|
logger.debug("applyer type=" + type + "; require audit=" + requireAudit);
|
|
|
|
return paymentApi.refundOrder(orderId, null, amount, remark, operator, type, requireAudit);
|
|
|
|
return paymentApi.refundOrder(orderId, null, amount, remark, operator, type, requireAudit);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//订单使用积分商城优惠券,仅支持全额退款
|
|
|
|
// 订单使用积分商城优惠券,仅支持全额退款
|
|
|
|
private void checkOrderUseCustomerCoupon(JSONObject order, BigDecimal feeAmount) {
|
|
|
|
private void checkOrderUseCustomerCoupon(JSONObject order, BigDecimal feeAmount) {
|
|
|
|
JSONObject couponLogs = couponAccuessLogMapper.findUsedCouponByOrderId(order.getString("order_id"));
|
|
|
|
JSONObject couponLogs = couponAccuessLogMapper.findUsedCouponByOrderId(order.getString("order_id"));
|
|
|
|
if (couponLogs != null) {
|
|
|
|
if (couponLogs != null) {
|
|
|
@ -237,7 +242,7 @@ public class RefundServiceImpl implements RefundService, ApplicationEventPublish
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
// @Transactional
|
|
|
|
// @Transactional
|
|
|
|
public JSONObject newReviewRefundOrder(String orderId, BigDecimal fee, boolean original, String remark, JSONObject manager) {
|
|
|
|
public JSONObject newReviewRefundOrder(String orderId, BigDecimal fee, boolean original, String remark, JSONObject manager) {
|
|
|
|
JSONObject reviewOrder = refundReviewMapper.findUnResolveByOrderId(orderId);
|
|
|
|
JSONObject reviewOrder = refundReviewMapper.findUnResolveByOrderId(orderId);
|
|
|
|
reviewOrder.put("status", 1);
|
|
|
|
reviewOrder.put("status", 1);
|
|
|
@ -338,7 +343,8 @@ public class RefundServiceImpl implements RefundService, ApplicationEventPublish
|
|
|
|
|
|
|
|
|
|
|
|
private void submitRefund(JSONObject account, JSONObject audition) {
|
|
|
|
private void submitRefund(JSONObject account, JSONObject audition) {
|
|
|
|
JSONObject refundLog = refundMapper.find(audition.getString("refund_id"));
|
|
|
|
JSONObject refundLog = refundMapper.find(audition.getString("refund_id"));
|
|
|
|
boolean platformAuditFlag = auditRefundAndCommitToPlatform(refundLog.getBigDecimal("amount"), audition.getString("remark"), refundLog.getString("order_id"), account);
|
|
|
|
boolean platformAuditFlag = auditRefundAndCommitToPlatform(refundLog.getBigDecimal("amount"), audition.getString("remark"),
|
|
|
|
|
|
|
|
refundLog.getString("order_id"), account);
|
|
|
|
if (!platformAuditFlag) {
|
|
|
|
if (!platformAuditFlag) {
|
|
|
|
paymentApi.submitRefund(audition.getString("refund_id"));
|
|
|
|
paymentApi.submitRefund(audition.getString("refund_id"));
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -347,13 +353,12 @@ public class RefundServiceImpl implements RefundService, ApplicationEventPublish
|
|
|
|
private boolean auditRefundAndCommitToPlatform(BigDecimal amount, String remark, String orderId, JSONObject account) {
|
|
|
|
private boolean auditRefundAndCommitToPlatform(BigDecimal amount, String remark, String orderId, JSONObject account) {
|
|
|
|
if (amount.compareTo(BigDecimal.ZERO) > 0) {
|
|
|
|
if (amount.compareTo(BigDecimal.ZERO) > 0) {
|
|
|
|
JSONObject refundConfig = checkRefundAuditFlag();
|
|
|
|
JSONObject refundConfig = checkRefundAuditFlag();
|
|
|
|
if (refundConfig != null && refundConfig.getBoolean("refundAudit") &&
|
|
|
|
if (refundConfig != null && refundConfig.getBoolean("refundAudit") && amount.compareTo(refundConfig.getBigDecimal("refundAuditAmount")) >= 0) {
|
|
|
|
amount.compareTo(refundConfig.getBigDecimal("refundAuditAmount")) >= 0) {
|
|
|
|
// 订单需要审核
|
|
|
|
//订单需要审核
|
|
|
|
|
|
|
|
reviewNewRefundOrder(orderId, amount, remark, account, null);
|
|
|
|
reviewNewRefundOrder(orderId, amount, remark, account, null);
|
|
|
|
return true;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
//退款
|
|
|
|
// 退款
|
|
|
|
return false;
|
|
|
|
return false;
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
throw new BadRequestException("Refund amount can not be 0");
|
|
|
|
throw new BadRequestException("Refund amount can not be 0");
|
|
|
@ -411,7 +416,8 @@ public class RefundServiceImpl implements RefundService, ApplicationEventPublish
|
|
|
|
}
|
|
|
|
}
|
|
|
|
review.put("bd_name", bdNameStr.deleteCharAt(bdNameStr.length() - 1).toString());
|
|
|
|
review.put("bd_name", bdNameStr.deleteCharAt(bdNameStr.length() - 1).toString());
|
|
|
|
JSONObject order = orderMapper.find(review.getString("order_id"));
|
|
|
|
JSONObject order = orderMapper.find(review.getString("order_id"));
|
|
|
|
review.put("available", BigDecimal.valueOf(order.getDoubleValue("customer_payment_amount")).subtract(BigDecimal.valueOf(order.getDoubleValue("refund_fee"))).doubleValue());
|
|
|
|
review.put("available", BigDecimal.valueOf(order.getDoubleValue("customer_payment_amount"))
|
|
|
|
|
|
|
|
.subtract(BigDecimal.valueOf(order.getDoubleValue("refund_fee"))).doubleValue());
|
|
|
|
review.put("create_time", order.getDate("create_time"));
|
|
|
|
review.put("create_time", order.getDate("create_time"));
|
|
|
|
review.put("channel", order.getString("channel"));
|
|
|
|
review.put("channel", order.getString("channel"));
|
|
|
|
return review;
|
|
|
|
return review;
|
|
|
@ -427,6 +433,15 @@ public class RefundServiceImpl implements RefundService, ApplicationEventPublish
|
|
|
|
return refundConfig;
|
|
|
|
return refundConfig;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
|
|
|
public JSONObject listUnionAllApply(JSONObject params, PageBounds pagination) {
|
|
|
|
|
|
|
|
if(params.get("cleint_id")==null && params.get("client_ids")==null){
|
|
|
|
|
|
|
|
return null;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return PageListUtils.buildPageListResult(refundMapper.listUnionAllApply(params, pagination));
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public void setApplicationEventPublisher(ApplicationEventPublisher applicationEventPublisher) {
|
|
|
|
public void setApplicationEventPublisher(ApplicationEventPublisher applicationEventPublisher) {
|
|
|
|
this.publisher = applicationEventPublisher;
|
|
|
|
this.publisher = applicationEventPublisher;
|
|
|
|