mirror of
https://gitee.com/qqtt-ah/ecom-dmb.git
synced 2026-11-24 23:09:19 +08:00
feat(order-status): 新增PATCH接口支持自动统计和退款状态开关直接编辑;CORS允许PATCH方法
This commit is contained in:
+1
-1
@@ -33,7 +33,7 @@ public class WebConfig implements WebMvcConfigurer {
|
|||||||
public void addCorsMappings(CorsRegistry registry) {
|
public void addCorsMappings(CorsRegistry registry) {
|
||||||
registry.addMapping("/**")
|
registry.addMapping("/**")
|
||||||
.allowedOriginPatterns("*")
|
.allowedOriginPatterns("*")
|
||||||
.allowedMethods("GET", "POST", "PUT", "DELETE", "OPTIONS")
|
.allowedMethods("GET", "POST", "PUT", "PATCH", "DELETE", "OPTIONS")
|
||||||
.allowedHeaders("*")
|
.allowedHeaders("*")
|
||||||
.allowCredentials(true)
|
.allowCredentials(true)
|
||||||
.maxAge(3600);
|
.maxAge(3600);
|
||||||
|
|||||||
+10
@@ -8,6 +8,7 @@ import org.springframework.web.bind.annotation.*;
|
|||||||
import top.xyquan.ecomdmbbackend.common.annotation.RequirePermission;
|
import top.xyquan.ecomdmbbackend.common.annotation.RequirePermission;
|
||||||
import top.xyquan.ecomdmbbackend.common.response.ApiResponse;
|
import top.xyquan.ecomdmbbackend.common.response.ApiResponse;
|
||||||
import top.xyquan.ecomdmbbackend.modules.ecom.order.status.model.dto.CreateOrderStatusDTO;
|
import top.xyquan.ecomdmbbackend.modules.ecom.order.status.model.dto.CreateOrderStatusDTO;
|
||||||
|
import top.xyquan.ecomdmbbackend.modules.ecom.order.status.model.dto.PatchOrderStatusDTO;
|
||||||
import top.xyquan.ecomdmbbackend.modules.ecom.order.status.model.dto.UpdateOrderStatusDTO;
|
import top.xyquan.ecomdmbbackend.modules.ecom.order.status.model.dto.UpdateOrderStatusDTO;
|
||||||
import top.xyquan.ecomdmbbackend.modules.ecom.order.status.model.vo.OrderStatusVO;
|
import top.xyquan.ecomdmbbackend.modules.ecom.order.status.model.vo.OrderStatusVO;
|
||||||
import top.xyquan.ecomdmbbackend.modules.ecom.order.status.service.OrderStatusService;
|
import top.xyquan.ecomdmbbackend.modules.ecom.order.status.service.OrderStatusService;
|
||||||
@@ -45,6 +46,15 @@ public class OrderStatusController {
|
|||||||
return ApiResponse.success("订单状态更新成功", orderStatusVO);
|
return ApiResponse.success("订单状态更新成功", orderStatusVO);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Operation(summary = "部分更新订单状态", description = "仅更新自动统计和退款状态字段")
|
||||||
|
@PatchMapping("/update/{id}")
|
||||||
|
@RequirePermission(value = "ecom:order:manage", description = "部分更新订单状态", allowSuper = true)
|
||||||
|
public ApiResponse<OrderStatusVO> patchOrderStatus(@Valid @RequestBody PatchOrderStatusDTO patchDTO,
|
||||||
|
@Parameter(description = "订单状态ID") @PathVariable Long id) {
|
||||||
|
OrderStatusVO orderStatusVO = orderStatusService.patchOrderStatus(patchDTO, id);
|
||||||
|
return ApiResponse.success("订单状态更新成功", orderStatusVO);
|
||||||
|
}
|
||||||
|
|
||||||
@Operation(summary = "删除订单状态", description = "删除指定订单状态")
|
@Operation(summary = "删除订单状态", description = "删除指定订单状态")
|
||||||
@DeleteMapping("/delete/{id}")
|
@DeleteMapping("/delete/{id}")
|
||||||
@RequirePermission(value = "ecom:order:manage", description = "删除订单状态", allowSuper = true)
|
@RequirePermission(value = "ecom:order:manage", description = "删除订单状态", allowSuper = true)
|
||||||
|
|||||||
+24
@@ -0,0 +1,24 @@
|
|||||||
|
package top.xyquan.ecomdmbbackend.modules.ecom.order.status.model.dto;
|
||||||
|
|
||||||
|
import io.swagger.v3.oas.annotations.media.Schema;
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 部分更新订单状态DTO(仅用于PATCH)
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
@Schema(description = "部分更新订单状态DTO")
|
||||||
|
public class PatchOrderStatusDTO {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 是否自动参与统计 0不参与 1参与
|
||||||
|
*/
|
||||||
|
@Schema(description = "是否自动参与统计", example = "1")
|
||||||
|
private Integer autoStatistics;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 是否为退款状态 0否 1是
|
||||||
|
*/
|
||||||
|
@Schema(description = "是否为退款状态", example = "0")
|
||||||
|
private Integer isRefund;
|
||||||
|
}
|
||||||
+10
@@ -3,6 +3,7 @@ package top.xyquan.ecomdmbbackend.modules.ecom.order.status.service;
|
|||||||
import com.baomidou.mybatisplus.extension.service.IService;
|
import com.baomidou.mybatisplus.extension.service.IService;
|
||||||
|
|
||||||
import top.xyquan.ecomdmbbackend.modules.ecom.order.status.model.dto.CreateOrderStatusDTO;
|
import top.xyquan.ecomdmbbackend.modules.ecom.order.status.model.dto.CreateOrderStatusDTO;
|
||||||
|
import top.xyquan.ecomdmbbackend.modules.ecom.order.status.model.dto.PatchOrderStatusDTO;
|
||||||
import top.xyquan.ecomdmbbackend.modules.ecom.order.status.model.dto.UpdateOrderStatusDTO;
|
import top.xyquan.ecomdmbbackend.modules.ecom.order.status.model.dto.UpdateOrderStatusDTO;
|
||||||
import top.xyquan.ecomdmbbackend.modules.ecom.order.status.model.po.OrderStatusPO;
|
import top.xyquan.ecomdmbbackend.modules.ecom.order.status.model.po.OrderStatusPO;
|
||||||
import top.xyquan.ecomdmbbackend.modules.ecom.order.status.model.vo.OrderStatusVO;
|
import top.xyquan.ecomdmbbackend.modules.ecom.order.status.model.vo.OrderStatusVO;
|
||||||
@@ -31,6 +32,15 @@ public interface OrderStatusService extends IService<OrderStatusPO> {
|
|||||||
*/
|
*/
|
||||||
OrderStatusVO updateOrderStatus(UpdateOrderStatusDTO updateOrderStatusDTO, Long id);
|
OrderStatusVO updateOrderStatus(UpdateOrderStatusDTO updateOrderStatusDTO, Long id);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 部分更新订单状态(仅更新 autoStatistics 和 isRefund)
|
||||||
|
*
|
||||||
|
* @param patchDTO 部分更新DTO
|
||||||
|
* @param id 订单状态ID
|
||||||
|
* @return 订单状态VO
|
||||||
|
*/
|
||||||
|
OrderStatusVO patchOrderStatus(PatchOrderStatusDTO patchDTO, Long id);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 删除订单状态
|
* 删除订单状态
|
||||||
*
|
*
|
||||||
|
|||||||
+32
@@ -8,6 +8,7 @@ import org.springframework.transaction.annotation.Transactional;
|
|||||||
import top.xyquan.ecomdmbbackend.common.exception.BusinessException;
|
import top.xyquan.ecomdmbbackend.common.exception.BusinessException;
|
||||||
import top.xyquan.ecomdmbbackend.modules.ecom.order.status.mapper.OrderStatusMapper;
|
import top.xyquan.ecomdmbbackend.modules.ecom.order.status.mapper.OrderStatusMapper;
|
||||||
import top.xyquan.ecomdmbbackend.modules.ecom.order.status.model.dto.CreateOrderStatusDTO;
|
import top.xyquan.ecomdmbbackend.modules.ecom.order.status.model.dto.CreateOrderStatusDTO;
|
||||||
|
import top.xyquan.ecomdmbbackend.modules.ecom.order.status.model.dto.PatchOrderStatusDTO;
|
||||||
import top.xyquan.ecomdmbbackend.modules.ecom.order.status.model.dto.UpdateOrderStatusDTO;
|
import top.xyquan.ecomdmbbackend.modules.ecom.order.status.model.dto.UpdateOrderStatusDTO;
|
||||||
import top.xyquan.ecomdmbbackend.modules.ecom.order.status.model.po.OrderStatusPO;
|
import top.xyquan.ecomdmbbackend.modules.ecom.order.status.model.po.OrderStatusPO;
|
||||||
import top.xyquan.ecomdmbbackend.modules.ecom.order.status.model.vo.OrderStatusVO;
|
import top.xyquan.ecomdmbbackend.modules.ecom.order.status.model.vo.OrderStatusVO;
|
||||||
@@ -119,6 +120,37 @@ public class OrderStatusServiceImpl extends ServiceImpl<OrderStatusMapper, Order
|
|||||||
return convertToVO(orderStatus);
|
return convertToVO(orderStatus);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 部分更新订单状态(仅更新 autoStatistics 和 isRefund)
|
||||||
|
*
|
||||||
|
* @param patchDTO 部分更新DTO
|
||||||
|
* @param id 订单状态ID
|
||||||
|
* @return 订单状态VO
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
@Transactional
|
||||||
|
public OrderStatusVO patchOrderStatus(PatchOrderStatusDTO patchDTO, Long id) {
|
||||||
|
Long companyId = currentUserContext.getCurrentCompanyId();
|
||||||
|
|
||||||
|
// 验证订单状态是否存在
|
||||||
|
OrderStatusPO existingStatus = this.getById(id);
|
||||||
|
if (existingStatus == null || !existingStatus.getCompanyId().equals(companyId)) {
|
||||||
|
throw new BusinessException("订单状态不存在");
|
||||||
|
}
|
||||||
|
|
||||||
|
// 只更新传入的字段
|
||||||
|
if (patchDTO.getAutoStatistics() != null) {
|
||||||
|
existingStatus.setAutoStatistics(patchDTO.getAutoStatistics());
|
||||||
|
}
|
||||||
|
if (patchDTO.getIsRefund() != null) {
|
||||||
|
existingStatus.setIsRefund(patchDTO.getIsRefund());
|
||||||
|
}
|
||||||
|
existingStatus.setUpdateBy(currentUserContext.getCurrentUserId());
|
||||||
|
|
||||||
|
this.updateById(existingStatus);
|
||||||
|
return convertToVO(existingStatus);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 删除订单状态
|
* 删除订单状态
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -29,6 +29,19 @@ export async function updateOrderStatusApi(
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 部分更新订单状态(仅自动统计和退款状态)
|
||||||
|
*/
|
||||||
|
export async function patchOrderStatusApi(
|
||||||
|
id: number,
|
||||||
|
data: { autoStatistics?: number; isRefund?: number },
|
||||||
|
) {
|
||||||
|
return requestClient.request<OrderStatusVO.Info>(
|
||||||
|
`/ec/order-status/update/${id}`,
|
||||||
|
{ data, method: 'PATCH' },
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 删除订单状态
|
* 删除订单状态
|
||||||
*/
|
*/
|
||||||
|
|||||||
+50
-12
@@ -7,12 +7,13 @@ import { computed, ref } from 'vue';
|
|||||||
import { Page } from '@vben/common-ui';
|
import { Page } from '@vben/common-ui';
|
||||||
import { createIconifyIcon } from '@vben/icons';
|
import { createIconifyIcon } from '@vben/icons';
|
||||||
|
|
||||||
import { Button, message, Popconfirm, Space, Tag } from 'ant-design-vue';
|
import { Button, message, Popconfirm, Space, Switch, Tag } from 'ant-design-vue';
|
||||||
|
|
||||||
import { useVbenVxeGrid } from '#/adapter/vxe-table';
|
import { useVbenVxeGrid } from '#/adapter/vxe-table';
|
||||||
import {
|
import {
|
||||||
deleteOrderStatusApi,
|
deleteOrderStatusApi,
|
||||||
getAllOrderStatusListApi,
|
getAllOrderStatusListApi,
|
||||||
|
patchOrderStatusApi,
|
||||||
} from '#/api/ecommerce/order-status';
|
} from '#/api/ecommerce/order-status';
|
||||||
|
|
||||||
import OrderStatusFormModal from './components/OrderStatusFormModal.vue';
|
import OrderStatusFormModal from './components/OrderStatusFormModal.vue';
|
||||||
@@ -45,16 +46,17 @@ const gridOptions: VxeGridProps<any> = {
|
|||||||
minWidth: 'auto',
|
minWidth: 'auto',
|
||||||
showOverflow: 'tooltip' as const,
|
showOverflow: 'tooltip' as const,
|
||||||
},
|
},
|
||||||
{
|
|
||||||
field: 'sortOrder',
|
|
||||||
title: '排序',
|
|
||||||
minWidth: 'auto',
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
title: '自动统计',
|
title: '自动统计',
|
||||||
minWidth: 'auto',
|
minWidth: 'auto',
|
||||||
slots: { default: 'autoStatistics' },
|
slots: { default: 'autoStatistics' },
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
title: '退款状态',
|
||||||
|
minWidth: 'auto',
|
||||||
|
slots: { default: 'refundStatus' },
|
||||||
|
},
|
||||||
{
|
{
|
||||||
field: 'createTime',
|
field: 'createTime',
|
||||||
title: '创建时间',
|
title: '创建时间',
|
||||||
@@ -188,6 +190,34 @@ async function handleDelete(record: OrderStatusVO.Info) {
|
|||||||
function handleModalSuccess() {
|
function handleModalSuccess() {
|
||||||
refreshTable();
|
refreshTable();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 处理自动统计开关切换
|
||||||
|
async function handleAutoStatisticsChange(row: OrderStatusVO.Info, checked: any) {
|
||||||
|
const val = !!checked;
|
||||||
|
try {
|
||||||
|
await patchOrderStatusApi(row.id, { autoStatistics: val ? 1 : 0 });
|
||||||
|
message.success('更新成功');
|
||||||
|
refreshTable();
|
||||||
|
} catch (error) {
|
||||||
|
console.error('更新自动统计失败:', error);
|
||||||
|
message.error('更新自动统计失败');
|
||||||
|
refreshTable(); // 恢复原状态
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 处理退款状态开关切换
|
||||||
|
async function handleIsRefundChange(row: OrderStatusVO.Info, checked: any) {
|
||||||
|
const val = !!checked;
|
||||||
|
try {
|
||||||
|
await patchOrderStatusApi(row.id, { isRefund: val ? 1 : 0 });
|
||||||
|
message.success('更新成功');
|
||||||
|
refreshTable();
|
||||||
|
} catch (error) {
|
||||||
|
console.error('更新退款状态失败:', error);
|
||||||
|
message.error('更新退款状态失败');
|
||||||
|
refreshTable(); // 恢复原状态
|
||||||
|
}
|
||||||
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
@@ -225,12 +255,20 @@ function handleModalSuccess() {
|
|||||||
|
|
||||||
<!-- 自动统计列 -->
|
<!-- 自动统计列 -->
|
||||||
<template #autoStatistics="{ row }: { row: OrderStatusVO.Info }">
|
<template #autoStatistics="{ row }: { row: OrderStatusVO.Info }">
|
||||||
<Tag
|
<Switch
|
||||||
:color="row.autoStatistics === 1 ? 'green' : 'default'"
|
:checked="row.autoStatistics === 1"
|
||||||
type="outline"
|
size="small"
|
||||||
>
|
@change="(checked) => handleAutoStatisticsChange(row, checked)"
|
||||||
{{ row.autoStatistics === 1 ? '参与统计' : '不参与统计' }}
|
/>
|
||||||
</Tag>
|
</template>
|
||||||
|
|
||||||
|
<!-- 退款状态列 -->
|
||||||
|
<template #refundStatus="{ row }: { row: OrderStatusVO.Info }">
|
||||||
|
<Switch
|
||||||
|
:checked="row.isRefund === 1"
|
||||||
|
size="small"
|
||||||
|
@change="(checked) => handleIsRefundChange(row, checked)"
|
||||||
|
/>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<!-- 操作列 -->
|
<!-- 操作列 -->
|
||||||
|
|||||||
Reference in New Issue
Block a user