Commit 6c33c84c by weijiguang

新增后台退款接口

parent 08790613
...@@ -28,14 +28,13 @@ import java.util.Objects; ...@@ -28,14 +28,13 @@ import java.util.Objects;
/** /**
* 订单退款Controller * 订单退款Controller
* *
* @author zxq * @author zxq
* @date 2022-04-28 * @date 2022-04-28
*/ */
@RestController @RestController
@RequestMapping("/system/refund") @RequestMapping("/system/refund")
public class OrderRefundController extends BaseController public class OrderRefundController extends BaseController {
{
@Autowired @Autowired
private IOrderRefundService orderRefundService; private IOrderRefundService orderRefundService;
@Autowired @Autowired
...@@ -122,11 +121,46 @@ public class OrderRefundController extends BaseController ...@@ -122,11 +121,46 @@ public class OrderRefundController extends BaseController
return ajaxResult; return ajaxResult;
} }
/**
* 新增订单退款
*/
@Log(title = "后台退款", businessType = BusinessType.INSERT)
@PostMapping("/background")
public AjaxResult background(@RequestBody OrderRefund orderRefund) {
Assert.notNull(orderRefund.getRefundAmount(), "退款金额还未传递");
orderRefund.setCreateUserName("BRAIN");
AjaxResult ajaxResult = orderRefundService.insertOrderRefund(orderRefund);
Object obejct = ajaxResult.get(AjaxResult.DATA_TAG);
if (obejct instanceof OrderRefund) {
OrderRefund orderRefund1 = (OrderRefund) obejct;
if (RefundState.PENDING.getState().equals(orderRefund1.getState())) {
int refundAmount = orderRefund1.getRefundAmount().movePointRight(2).intValue();
if (refundAmount > 0) {
int totalFee = orderRefund1.getOrder().getPaidAmount().movePointRight(2).intValue();
boolean refundSuc;
try {
String refundResult = weixinService.refund(orderRefund1.getOrderNo(), orderRefund1.getRefundNo(), totalFee, refundAmount);
refundSuc = !Objects.equals("退款失败", refundResult);
} catch (Exception e) {
refundSuc = false;
}
orderRefund1.setState(refundSuc ? RefundState.REFUNDING.getState() : RefundState.FAILURE.getState());
} else {
orderRefund1.setState(RefundState.SUCCESS.getState());
}
orderRefundService.updateOrderRefund(orderRefund1);
}
}
return ajaxResult;
}
@PostMapping("/refund") @PostMapping("/refund")
public void refund(){ public void refund() {
Order order = orderService.selectOrderById(98L); Order order = orderService.selectOrderById(98L);
int totalFee = order.getAmount().movePointRight(2).intValue(); int totalFee = order.getAmount().movePointRight(2).intValue();
weixinService.refund(order.getOrderNo(),order.getOrderNo()+"1",totalFee,totalFee); weixinService.refund(order.getOrderNo(), order.getOrderNo() + "1", totalFee, totalFee);
} }
......
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