|
@@ -0,0 +1,79 @@
|
|
|
+package com.github.zuihou.business.controller.refund;
|
|
|
+
|
|
|
+import cn.hutool.core.bean.BeanUtil;
|
|
|
+import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
|
+import com.github.zuihou.base.R;
|
|
|
+import com.github.zuihou.base.controller.SuperController;
|
|
|
+import com.github.zuihou.base.request.PageParams;
|
|
|
+import com.github.zuihou.business.order.entity.Order;
|
|
|
+import com.github.zuihou.business.order.service.OrderService;
|
|
|
+import com.github.zuihou.business.refund.dto.RefundRecordPageDTO;
|
|
|
+import com.github.zuihou.business.refund.dto.RefundRecordSaveDTO;
|
|
|
+import com.github.zuihou.business.refund.dto.RefundRecordUpdateDTO;
|
|
|
+import com.github.zuihou.business.refund.entity.RefundRecord;
|
|
|
+import com.github.zuihou.business.refund.service.RefundRecordService;
|
|
|
+import com.github.zuihou.business.spe.entity.Spe;
|
|
|
+import com.github.zuihou.database.mybatis.conditions.query.QueryWrap;
|
|
|
+import com.github.zuihou.log.annotation.SysLog;
|
|
|
+import com.github.zuihou.security.annotation.PreAuth;
|
|
|
+import io.swagger.annotations.Api;
|
|
|
+import io.swagger.annotations.ApiOperation;
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.validation.annotation.Validated;
|
|
|
+import org.springframework.web.bind.annotation.PostMapping;
|
|
|
+import org.springframework.web.bind.annotation.RequestBody;
|
|
|
+import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
+import org.springframework.web.bind.annotation.RestController;
|
|
|
+
|
|
|
+import java.util.List;
|
|
|
+
|
|
|
+/**
|
|
|
+ *
|
|
|
+ */
|
|
|
+@Slf4j
|
|
|
+@Validated
|
|
|
+@RestController
|
|
|
+@RequestMapping("/refundRecord")
|
|
|
+@Api(value = "RefundRecord", tags = "退款记录表")
|
|
|
+@PreAuth(replace = "refundRecord:")
|
|
|
+public class RefundRecordController extends SuperController<RefundRecordService, Long, RefundRecord, RefundRecordPageDTO, RefundRecordSaveDTO, RefundRecordUpdateDTO> {
|
|
|
+ @Autowired
|
|
|
+ private OrderService orderService;
|
|
|
+
|
|
|
+ @Override
|
|
|
+ @PostMapping({"/page"})
|
|
|
+ @ApiOperation(value = "退款记录分页列表查询", notes = "退款记录分页列表查询")
|
|
|
+ @SysLog(value = "'分页列表查询:第' + #params?.current + '页, 显示' + #params?.size + '行'", response = false)
|
|
|
+ public R<IPage<RefundRecord>> page(@RequestBody @Validated PageParams<RefundRecordPageDTO> pageParams) {
|
|
|
+ return this.success(baseService.selcetPage(pageParams));
|
|
|
+ }
|
|
|
+
|
|
|
+ @PostMapping("/save")
|
|
|
+ @SysLog(value = "新增退款", request = false)
|
|
|
+ @ApiOperation(value = "新增退款", notes = "新增退款")
|
|
|
+ public R saveRefundRecord(@RequestBody @Validated RefundRecordSaveDTO saveDTO) {
|
|
|
+ Order order = orderService.getById(saveDTO.getOrderId());
|
|
|
+ if (order == null) {
|
|
|
+ return R.fail("订单不存在");
|
|
|
+ }
|
|
|
+ if (!order.getOrderStatus().equals("4")) {
|
|
|
+ return R.fail("非异常订单不能退款");
|
|
|
+ }
|
|
|
+ if (order.getPayerTotal().compareTo(saveDTO.getRefundAmount()) < 0 ) {
|
|
|
+ return R.fail("退款金额不能大于订单支付金额");
|
|
|
+ }
|
|
|
+
|
|
|
+ QueryWrap<RefundRecord> refundRecordQueryWrap = new QueryWrap<>();
|
|
|
+ refundRecordQueryWrap.eq("order_id", saveDTO.getOrderId());
|
|
|
+ RefundRecord dbRefundRecord = baseService.getOne(refundRecordQueryWrap);
|
|
|
+ if (dbRefundRecord != null) {
|
|
|
+ return R.fail("该订单已退款");
|
|
|
+ }
|
|
|
+ RefundRecord model = BeanUtil.toBean(saveDTO, this.getEntityClass());
|
|
|
+ // 运维页面调用,全部为人工退款
|
|
|
+ model.setRefundType("1");
|
|
|
+ baseService.save(model);
|
|
|
+ return R.success();
|
|
|
+ }
|
|
|
+}
|