功能:补齐订单预约时间落库

This commit is contained in:
xiaowang
2026-03-19 20:19:41 +08:00
parent 8fd549d20e
commit de50394960
16 changed files with 1150 additions and 2151 deletions
+5
View File
@@ -4,6 +4,7 @@ interface OrderItem {
productId: number
quantity: number
artistId?: number
appointmentTime?: string
}
interface CreateOrderRequest {
@@ -47,5 +48,9 @@ export const orderApi = {
// 美甲师查看自己的订单
getArtistOrders: () => {
return api.get('/order/artist/list')
},
completeArtistOrder: (orderId: number) => {
return api.put(`/order/artist/complete/${orderId}`)
}
}
+77 -287
View File
@@ -1,333 +1,123 @@
<template>
<div class="mobile-container">
<!-- 头部区域 -->
<div class="page">
<header class="header">
<a-button class="back-btn" type="text" @click="handleBackClick">
<a-button type="text" @click="router.back()">
<LeftOutlined :style="{ fontSize: '20px' }" />
</a-button>
<h1>美甲师订单</h1>
<div class="placeholder"></div>
<div class="placeholder" />
</header>
<!-- 订单列表 -->
<div class="order-section">
<a-empty v-if="orders.length === 0" description="暂无订单">
<a-button type="primary" @click="handleRefresh">刷新</a-button>
<main class="content">
<a-empty v-if="!orders.length" description="暂无订单">
<a-button type="primary" @click="loadOrders">刷新</a-button>
</a-empty>
<div v-else class="order-list">
<a-card v-for="order in orders" :key="order.id" class="order-card">
<div class="order-header">
<span class="order-no">订单号: {{ order.orderNo }}</span>
<span :class="['order-status', order.status === 1 ? 'pending' : order.status === 2 ? 'completed' : 'cancelled']">
{{ order.statusText }}
</span>
<a-card v-for="order in orders" :key="order.id" class="order-card">
<div class="order-head">
<span>订单号:{{ order.orderNo }}</span>
<span class="status" :class="statusClass(order.status)">{{ order.statusText }}</span>
</div>
<div v-for="item in order.items" :key="item.id" class="item">
<div class="thumb">
<img v-if="item.productImage" :src="item.productImage" :alt="item.productTitle" />
<span v-else>{{ item.productTitle[0] }}</span>
</div>
<div class="order-items">
<div v-for="item in order.items" :key="item.id" class="order-item">
<div class="item-image" v-if="item.productImage">
<img :src="item.productImage" :alt="item.productTitle" />
</div>
<div class="item-image" v-else :style="{ backgroundColor: getRandomColor() }">
<span>{{ item.productTitle[0] }}</span>
</div>
<div class="item-info">
<div class="item-title">{{ item.productTitle }}</div>
<div class="item-price">¥{{ item.price.toFixed(2) }} x {{ item.quantity }}</div>
<div class="item-customer">
<span>客户订单</span>
</div>
</div>
</div>
<div class="main">
<div class="title">{{ item.productTitle }}</div>
<div class="line">¥{{ item.price.toFixed(2) }} x {{ item.quantity }}</div>
<div v-if="item.appointmentTime" class="line appointment">预约时间:{{ item.appointmentTime }}</div>
</div>
<div class="order-footer">
<div class="order-total">
总计: <span class="total-price">¥{{ order.actualAmount.toFixed(2) }}</span>
</div>
<div class="order-actions">
<a-button v-if="order.status === 1" size="small" type="primary" @click="handleCompleteOrder(order.id)">
完成服务
</a-button>
</div>
</div>
</a-card>
</div>
</div>
</div>
<div class="footer">
<span>当前项目合计:¥{{ order.actualAmount.toFixed(2) }}</span>
<a-button v-if="order.status === 1" size="small" type="primary" @click="completeOrder(order.id)">
完成服务
</a-button>
</div>
</a-card>
</main>
</div>
</template>
<script setup lang="ts">
import { ref, onMounted } from 'vue'
import { onMounted, ref } from 'vue'
import { useRouter } from 'vue-router'
import { LeftOutlined } from '@ant-design/icons-vue'
import { message, Modal } from 'ant-design-vue'
import { orderApi } from '../api/order'
import { fileApi } from '../api/index'
import { orderApi } from '../api/order'
const router = useRouter()
// 订单相关状态
const orders = ref<any[]>([])
const loading = ref(false)
// 图片缓存
const imageIdCache = ref<Record<string, string>>({})
// 加载美甲师订单列表
const loadOrders = async () => {
loading.value = true
try {
const response = await orderApi.getArtistOrders() as any
orders.value = response || []
await loadProductImages(orders.value)
} catch (error) {
message.error('获取订单列表失败')
} finally {
loading.value = false
}
const statusClass = (status: number) => {
if (status === 1) return 'pending'
if (status === 2) return 'completed'
return 'cancelled'
}
// 加载作品图片
const loadProductImages = async (orders: any[]) => {
for (const order of orders) {
if (order.items && order.items.length > 0) {
for (const item of order.items) {
if (item.productImage) {
const cleanImageUrl = item.productImage.replace(/<[^>]*>/g, '')
const match = cleanImageUrl.match(/\/api\/file\/get\/(\d+)/)
if (match && match[1]) {
const imageId = match[1]
try {
if (!imageIdCache.value[imageId]) {
const response = await fileApi.getSignedUrl(Number(imageId)) as any
imageIdCache.value[imageId] = response
}
item.productImage = imageIdCache.value[imageId]
} catch (error) {
console.error('获取图片签名链接失败:', error)
item.productImage = ''
}
} else {
item.productImage = ''
}
const loadOrders = async () => {
try {
orders.value = (await orderApi.getArtistOrders() as unknown as any[]) || []
for (const order of orders.value) {
for (const item of order.items || []) {
const match = item.productImage?.replace(/<[^>]*>/g, '').match(/\/api\/file\/get\/(\d+)/)
if (!match?.[1]) continue
const imageId = match[1]
try {
if (!imageIdCache.value[imageId]) imageIdCache.value[imageId] = await fileApi.getSignedUrl(Number(imageId)) as any
item.productImage = imageIdCache.value[imageId]
} catch {
item.productImage = ''
}
}
}
} catch {
message.error('获取订单列表失败')
}
}
// 处理完成服务
const handleCompleteOrder = async (orderId: number) => {
const completeOrder = (orderId: number) => {
Modal.confirm({
title: '确认完成服务',
content: '确定要完成这个订单的服务吗?',
content: '确定要完成这个订单吗?',
onOk: async () => {
try {
await orderApi.processOrder(orderId, 2)
await orderApi.completeArtistOrder(orderId)
message.success('订单已完成')
loadOrders()
} catch (error) {
await loadOrders()
} catch {
message.error('完成订单失败')
}
}
})
}
// 处理返回按钮点击
const handleBackClick = () => {
router.back()
}
// 处理刷新
const handleRefresh = () => {
loadOrders()
}
// 生成随机颜色
const getRandomColor = () => {
const colors = ['#ffe4d6', '#d6eaff', '#e2ffd6', '#fff2d6', '#d6ffe4', '#e4d6ff']
return colors[Math.floor(Math.random() * colors.length)]
}
// 页面加载时获取订单数据
onMounted(() => {
loadOrders()
})
onMounted(loadOrders)
</script>
<style scoped>
.mobile-container {
padding-top: 60px;
min-height: 100vh;
background: #f5f5f5;
}
.header {
position: fixed;
top: 0;
left: 0;
right: 0;
z-index: 100;
display: flex;
justify-content: space-between;
align-items: center;
padding: 10px 15px;
border-bottom: 1px solid #f0f0f0;
background: white;
box-shadow: 0 2px 4px rgba(0, 0, 0, 0.05);
}
.header h1 {
font-size: 18px;
font-weight: bold;
margin: 0;
}
.back-btn,
.placeholder {
width: 40px;
height: 40px;
display: flex;
align-items: center;
justify-content: center;
}
.order-section {
padding: 15px;
padding-bottom: 20px;
}
.order-list {
display: flex;
flex-direction: column;
gap: 15px;
}
.order-card {
border-radius: 12px;
overflow: hidden;
}
.order-header {
display: flex;
justify-content: space-between;
align-items: center;
margin-bottom: 15px;
padding-bottom: 10px;
border-bottom: 1px solid #f0f0f0;
}
.order-no {
font-size: 14px;
color: #666;
}
.order-status {
font-size: 14px;
font-weight: 600;
padding: 4px 12px;
border-radius: 12px;
}
.order-status.pending {
background: #fff7e6;
color: #fa8c16;
}
.order-status.completed {
background: #f6ffed;
color: #52c41a;
}
.order-status.cancelled {
background: #fff1f0;
color: #ff4d4f;
}
.order-items {
display: flex;
flex-direction: column;
gap: 10px;
margin-bottom: 15px;
}
.order-item {
display: flex;
gap: 12px;
align-items: center;
}
.item-image {
width: 60px;
height: 60px;
border-radius: 8px;
display: flex;
justify-content: center;
align-items: center;
font-size: 24px;
font-weight: bold;
color: rgba(0,0,0,0.1);
flex-shrink: 0;
overflow: hidden;
}
.item-image img {
width: 100%;
height: 100%;
object-fit: cover;
border-radius: 8px;
}
.item-info {
flex: 1;
display: flex;
flex-direction: column;
gap: 4px;
}
.item-title {
font-size: 14px;
font-weight: 600;
color: #1a1a2e;
overflow: hidden;
text-overflow: ellipsis;
display: -webkit-box;
-webkit-line-clamp: 2;
-webkit-box-orient: vertical;
}
.item-price {
font-size: 13px;
color: #666;
}
.item-customer {
font-size: 12px;
color: #1890ff;
}
.order-footer {
display: flex;
justify-content: space-between;
align-items: center;
padding-top: 10px;
border-top: 1px solid #f0f0f0;
}
.order-total {
font-size: 14px;
color: #666;
}
.total-price {
font-size: 16px;
font-weight: 700;
color: #ff4d4f;
}
.order-actions {
display: flex;
gap: 8px;
}
.page { min-height: 100vh; padding-top: 60px; background: #f5f5f5; }
.header { position: fixed; top: 0; left: 0; right: 0; z-index: 10; display: flex; align-items: center; justify-content: space-between; padding: 10px 15px; background: #fff; border-bottom: 1px solid #f0f0f0; }
.header h1 { margin: 0; font-size: 18px; }
.placeholder { width: 40px; height: 40px; }
.content { padding: 15px; }
.order-card { margin-bottom: 12px; border-radius: 12px; }
.order-head, .footer { display: flex; align-items: center; justify-content: space-between; }
.order-head { margin-bottom: 12px; padding-bottom: 10px; border-bottom: 1px solid #f0f0f0; }
.status { padding: 4px 10px; border-radius: 999px; font-size: 12px; font-weight: 600; }
.pending { background: #fff7e6; color: #fa8c16; }
.completed { background: #f6ffed; color: #52c41a; }
.cancelled { background: #fff1f0; color: #ff4d4f; }
.item { display: flex; gap: 12px; margin-bottom: 12px; }
.thumb { width: 60px; height: 60px; border-radius: 8px; overflow: hidden; display: flex; align-items: center; justify-content: center; background: #eef3ff; }
.thumb img { width: 100%; height: 100%; object-fit: cover; }
.main { flex: 1; }
.title { font-weight: 600; }
.line { margin-top: 4px; color: #666; font-size: 13px; }
.appointment { color: #1890ff; }
</style>
File diff suppressed because it is too large Load Diff
+75 -297
View File
@@ -1,125 +1,86 @@
<template>
<div class="mobile-container">
<!-- 头部区域 -->
<div class="page">
<header class="header">
<a-button class="back-btn" type="text" @click="handleBackClick">
<a-button type="text" @click="router.back()">
<LeftOutlined :style="{ fontSize: '20px' }" />
</a-button>
<h1>我的订单</h1>
<div class="placeholder"></div>
<div class="placeholder" />
</header>
<!-- 订单列表 -->
<div class="order-section">
<a-empty v-if="orders.length === 0" description="暂无订单">
<a-button type="primary" @click="handleBrowseProducts">去购物</a-button>
<main class="content">
<a-empty v-if="!orders.length" description="暂无订单">
<a-button type="primary" @click="router.push('/products')">去逛逛</a-button>
</a-empty>
<div v-else class="order-list">
<a-card v-for="order in orders" :key="order.id" class="order-card">
<div class="order-header">
<span class="order-no">订单号: {{ order.orderNo }}</span>
<span :class="['order-status', order.status === 1 ? 'pending' : order.status === 2 ? 'completed' : 'cancelled']">
{{ order.statusText }}
</span>
<a-card v-for="order in orders" :key="order.id" class="order-card">
<div class="order-head">
<span>订单号:{{ order.orderNo }}</span>
<span class="status" :class="statusClass(order.status)">{{ order.statusText }}</span>
</div>
<div v-for="item in order.items" :key="item.id" class="item">
<div class="thumb">
<img v-if="item.productImage" :src="item.productImage" :alt="item.productTitle" />
<span v-else>{{ item.productTitle[0] }}</span>
</div>
<div class="order-items">
<div v-for="item in order.items" :key="item.id" class="order-item">
<div class="item-image" v-if="item.productImage">
<img :src="item.productImage" :alt="item.productTitle" />
</div>
<div class="item-image" v-else :style="{ backgroundColor: getRandomColor() }">
<span>{{ item.productTitle[0] }}</span>
</div>
<div class="item-info">
<div class="item-title">{{ item.productTitle }}</div>
<div class="item-price">¥{{ item.price.toFixed(2) }} x {{ item.quantity }}</div>
<div v-if="item.artistName" class="item-artist">
<img v-if="item.artistAvatar" :src="item.artistAvatar" class="artist-avatar-small" />
<span>美甲师: {{ item.artistName }}</span>
</div>
</div>
</div>
<div class="main">
<div class="title">{{ item.productTitle }}</div>
<div class="line">¥{{ item.price.toFixed(2) }} x {{ item.quantity }}</div>
<div v-if="item.artistName" class="line">美甲师:{{ item.artistName }}</div>
<div v-if="item.appointmentTime" class="line appointment">预约时间:{{ item.appointmentTime }}</div>
</div>
<div class="order-footer">
<div class="order-total">
总计: <span class="total-price">¥{{ order.actualAmount.toFixed(2) }}</span>
</div>
<div class="order-actions">
<a-button v-if="order.status === 1" size="small" danger @click="handleCancelOrder(order.id)">
取消订单
</a-button>
</div>
</div>
</a-card>
</div>
</div>
</div>
<div class="footer">
<span>总计:¥{{ order.actualAmount.toFixed(2) }}</span>
<a-button v-if="order.status === 1" size="small" danger @click="cancelOrder(order.id)">取消订单</a-button>
</div>
</a-card>
</main>
</div>
</template>
<script setup lang="ts">
import { ref, onMounted } from 'vue'
import { onMounted, ref } from 'vue'
import { useRouter } from 'vue-router'
import { LeftOutlined } from '@ant-design/icons-vue'
import { message, Modal } from 'ant-design-vue'
import { orderApi } from '../api/order'
import { fileApi } from '../api/index'
import { orderApi } from '../api/order'
const router = useRouter()
// 订单相关状态
const orders = ref<any[]>([])
const loading = ref(false)
// 图片缓存
const imageIdCache = ref<Record<string, string>>({})
// 加载订单列表
const loadOrders = async () => {
loading.value = true
try {
const response = await orderApi.getOrderList() as any
orders.value = response || []
await loadProductImages(orders.value)
} catch (error) {
message.error('获取订单列表失败')
} finally {
loading.value = false
}
const statusClass = (status: number) => {
if (status === 1) return 'pending'
if (status === 2) return 'completed'
return 'cancelled'
}
// 加载作品图片
const loadProductImages = async (orders: any[]) => {
for (const order of orders) {
if (order.items && order.items.length > 0) {
for (const item of order.items) {
if (item.productImage) {
const cleanImageUrl = item.productImage.replace(/<[^>]*>/g, '')
const match = cleanImageUrl.match(/\/api\/file\/get\/(\d+)/)
if (match && match[1]) {
const imageId = match[1]
try {
if (!imageIdCache.value[imageId]) {
const response = await fileApi.getSignedUrl(Number(imageId)) as any
imageIdCache.value[imageId] = response
}
item.productImage = imageIdCache.value[imageId]
} catch (error) {
console.error('获取图片签名链接失败:', error)
item.productImage = ''
}
} else {
item.productImage = ''
}
const loadOrders = async () => {
try {
orders.value = (await orderApi.getOrderList() as unknown as any[]) || []
for (const order of orders.value) {
for (const item of order.items || []) {
const match = item.productImage?.replace(/<[^>]*>/g, '').match(/\/api\/file\/get\/(\d+)/)
if (!match?.[1]) continue
const imageId = match[1]
try {
if (!imageIdCache.value[imageId]) imageIdCache.value[imageId] = await fileApi.getSignedUrl(Number(imageId)) as any
item.productImage = imageIdCache.value[imageId]
} catch {
item.productImage = ''
}
}
}
} catch {
message.error('获取订单列表失败')
}
}
// 处理取消订单
const handleCancelOrder = async (orderId: number) => {
const cancelOrder = (orderId: number) => {
Modal.confirm({
title: '确认取消订单',
content: '确定要取消这个订单吗?',
@@ -127,218 +88,35 @@ const handleCancelOrder = async (orderId: number) => {
try {
await orderApi.cancelOrder(orderId)
message.success('订单已取消')
loadOrders()
} catch (error) {
await loadOrders()
} catch {
message.error('取消订单失败')
}
}
})
}
// 处理返回按钮点击
const handleBackClick = () => {
router.back()
}
// 处理浏览作品
const handleBrowseProducts = () => {
router.push('/products')
}
// 生成随机颜色
const getRandomColor = () => {
const colors = ['#ffe4d6', '#d6eaff', '#e2ffd6', '#fff2d6', '#d6ffe4', '#e4d6ff']
return colors[Math.floor(Math.random() * colors.length)]
}
// 页面加载时获取订单数据
onMounted(() => {
loadOrders()
})
onMounted(loadOrders)
</script>
<style scoped>
.mobile-container {
padding-top: 60px;
min-height: 100vh;
background: #f5f5f5;
}
.header {
position: fixed;
top: 0;
left: 0;
right: 0;
z-index: 100;
display: flex;
justify-content: space-between;
align-items: center;
padding: 10px 15px;
border-bottom: 1px solid #f0f0f0;
background: white;
box-shadow: 0 2px 4px rgba(0, 0, 0, 0.05);
}
.header h1 {
font-size: 18px;
font-weight: bold;
margin: 0;
}
.back-btn,
.placeholder {
width: 40px;
height: 40px;
display: flex;
align-items: center;
justify-content: center;
}
.order-section {
padding: 15px;
padding-bottom: 20px;
}
.order-list {
display: flex;
flex-direction: column;
gap: 15px;
}
.order-card {
border-radius: 12px;
overflow: hidden;
}
.order-header {
display: flex;
justify-content: space-between;
align-items: center;
margin-bottom: 15px;
padding-bottom: 10px;
border-bottom: 1px solid #f0f0f0;
}
.order-no {
font-size: 14px;
color: #666;
}
.order-status {
font-size: 14px;
font-weight: 600;
padding: 4px 12px;
border-radius: 12px;
}
.order-status.pending {
background: #fff7e6;
color: #fa8c16;
}
.order-status.completed {
background: #f6ffed;
color: #52c41a;
}
.order-status.cancelled {
background: #fff1f0;
color: #ff4d4f;
}
.order-items {
display: flex;
flex-direction: column;
gap: 10px;
margin-bottom: 15px;
}
.order-item {
display: flex;
gap: 12px;
align-items: center;
}
.item-image {
width: 60px;
height: 60px;
border-radius: 8px;
display: flex;
justify-content: center;
align-items: center;
font-size: 24px;
font-weight: bold;
color: rgba(0,0,0,0.1);
flex-shrink: 0;
overflow: hidden;
}
.item-image img {
width: 100%;
height: 100%;
object-fit: cover;
border-radius: 8px;
}
.item-info {
flex: 1;
display: flex;
flex-direction: column;
gap: 4px;
}
.item-title {
font-size: 14px;
font-weight: 600;
color: #1a1a2e;
overflow: hidden;
text-overflow: ellipsis;
display: -webkit-box;
-webkit-line-clamp: 2;
-webkit-box-orient: vertical;
}
.item-price {
font-size: 13px;
color: #666;
}
.item-artist {
display: flex;
align-items: center;
gap: 6px;
font-size: 12px;
color: #1890ff;
}
.artist-avatar-small {
width: 20px;
height: 20px;
border-radius: 50%;
object-fit: cover;
}
.order-footer {
display: flex;
justify-content: space-between;
align-items: center;
padding-top: 10px;
border-top: 1px solid #f0f0f0;
}
.order-total {
font-size: 14px;
color: #666;
}
.total-price {
font-size: 16px;
font-weight: 700;
color: #ff4d4f;
}
.order-actions {
display: flex;
gap: 8px;
}
</style>
.page { min-height: 100vh; padding-top: 60px; background: #f5f5f5; }
.header { position: fixed; top: 0; left: 0; right: 0; z-index: 10; display: flex; align-items: center; justify-content: space-between; padding: 10px 15px; background: #fff; border-bottom: 1px solid #f0f0f0; }
.header h1 { margin: 0; font-size: 18px; }
.placeholder { width: 40px; height: 40px; }
.content { padding: 15px; }
.order-card { margin-bottom: 12px; border-radius: 12px; }
.order-head, .footer { display: flex; align-items: center; justify-content: space-between; }
.order-head { margin-bottom: 12px; padding-bottom: 10px; border-bottom: 1px solid #f0f0f0; }
.status { padding: 4px 10px; border-radius: 999px; font-size: 12px; font-weight: 600; }
.pending { background: #fff7e6; color: #fa8c16; }
.completed { background: #f6ffed; color: #52c41a; }
.cancelled { background: #fff1f0; color: #ff4d4f; }
.item { display: flex; gap: 12px; margin-bottom: 12px; }
.thumb { width: 60px; height: 60px; border-radius: 8px; overflow: hidden; display: flex; align-items: center; justify-content: center; background: #eef3ff; }
.thumb img { width: 100%; height: 100%; object-fit: cover; }
.main { flex: 1; }
.title { font-weight: 600; }
.line { margin-top: 4px; color: #666; font-size: 13px; }
.appointment { color: #1890ff; }
</style>
+61 -157
View File
@@ -1,218 +1,122 @@
<template>
<div class="orders">
<a-page-header title="订单管理" sub-title="管理系统订单" />
<a-card :bordered="false">
<template #extra>
<a-input-search
v-model:value="searchText"
placeholder="搜索订单编号或用户ID"
style="width: 250px"
@search="handleSearch"
/>
</template>
<a-table
:columns="columns"
:data-source="orders"
:loading="loading"
:pagination="pagination"
@change="handleTableChange"
row-key="id"
>
<a-card :bordered="false">
<a-table :columns="columns" :data-source="orders" :loading="loading" row-key="id">
<template #bodyCell="{ column, record }">
<template v-if="column.key === 'status'">
<a-tag :color="getStatusColor(record.status)">
{{ record.statusText }}
</a-tag>
<a-tag :color="statusColor(record.status)">{{ record.statusText }}</a-tag>
</template>
<template v-else-if="column.key === 'totalAmount'">
¥{{ record.totalAmount.toFixed(2) }}
</template>
<template v-else-if="column.key === 'actualAmount'">
¥{{ record.actualAmount.toFixed(2) }}
</template>
<template v-else-if="column.key === 'actions'">
<a-space>
<a-button type="link" size="small" @click="showOrderDetail(record)">
查看
</a-button>
<a-button v-if="record.status === 1" type="primary" size="small" @click="processOrder(record.id, 2)">
确认完成
</a-button>
<a-button v-if="record.status === 1" danger size="small" @click="processOrder(record.id, 3)">
取消订单
</a-button>
<a-button type="link" size="small" @click="currentOrder = record">查看</a-button>
<a-button v-if="record.status === 1" type="primary" size="small" @click="process(record.id, 2)">确认完成</a-button>
<a-button v-if="record.status === 1" danger size="small" @click="process(record.id, 3)">取消订单</a-button>
</a-space>
</template>
</template>
</a-table>
</a-card>
</div>
<!-- 订单详情模态框 -->
<a-modal
v-model:open="detailModalVisible"
title="订单详情"
@cancel="handleDetailModalCancel"
width="800px"
>
<div v-if="currentOrder">
<a-modal v-model:open="detailVisible" title="订单详情" width="860px" @cancel="currentOrder = null">
<template v-if="currentOrder">
<a-descriptions :column="2">
<a-descriptions-item label="订单编号">{{ currentOrder.orderNo }}</a-descriptions-item>
<a-descriptions-item label="用户ID">{{ currentOrder.userId }}</a-descriptions-item>
<a-descriptions-item label="总金额">¥{{ currentOrder.totalAmount.toFixed(2) }}</a-descriptions-item>
<a-descriptions-item label="实际金额">¥{{ currentOrder.actualAmount.toFixed(2) }}</a-descriptions-item>
<a-descriptions-item label="订单总额">¥{{ currentOrder.totalAmount.toFixed(2) }}</a-descriptions-item>
<a-descriptions-item label="实付金额">¥{{ currentOrder.actualAmount.toFixed(2) }}</a-descriptions-item>
<a-descriptions-item label="优惠券">{{ currentOrder.couponName || '无' }}</a-descriptions-item>
<a-descriptions-item label="订单状态">{{ currentOrder.statusText }}</a-descriptions-item>
<a-descriptions-item label="创建时间" :span="2">{{ currentOrder.createTime }}</a-descriptions-item>
</a-descriptions>
<a-divider>订单作品</a-divider>
<a-table :columns="orderItemColumns" :data-source="currentOrder.items" row-key="id">
<a-divider>订单项目</a-divider>
<a-table :columns="itemColumns" :data-source="currentOrder.items" row-key="id" :pagination="false">
<template #bodyCell="{ column, record }">
<template v-if="column.key === 'price'">
¥{{ record.price.toFixed(2) }}
</template>
<template v-else-if="column.key === 'totalPrice'">
¥{{ (record.price * record.quantity).toFixed(2) }}
</template>
<template v-if="column.key === 'price'">¥{{ record.price.toFixed(2) }}</template>
<template v-else-if="column.key === 'totalPrice'">¥{{ (record.price * record.quantity).toFixed(2) }}</template>
</template>
</a-table>
</div>
</template>
</a-modal>
</div>
</template>
<script setup lang="ts">
import { ref, reactive, onMounted } from 'vue'
import { orderApi } from '../../api/order'
import { computed, onMounted, ref } from 'vue'
import { message } from 'ant-design-vue'
import { orderApi } from '../../api/order'
interface Order {
id: number
orderNo: string
userId: number
totalAmount: number
actualAmount: number
couponId: number | null
couponName: string | null
status: number
statusText: string
createTime: string
items: any[]
}
const orders = ref<Order[]>([])
const orders = ref<any[]>([])
const loading = ref(false)
const searchText = ref('')
const detailModalVisible = ref(false)
const currentOrder = ref<Order | null>(null)
const pagination = reactive({
current: 1,
pageSize: 10,
total: 0,
showSizeChanger: true,
showQuickJumper: true,
showTotal: (total: number) => `共 ${total} 条`
const currentOrder = ref<any | null>(null)
const detailVisible = computed({
get: () => !!currentOrder.value,
set: value => { if (!value) currentOrder.value = null }
})
const orderItemColumns = [
{ title: '作品ID', dataIndex: 'productId', key: 'productId' },
{ title: '作品名称', dataIndex: 'productTitle', key: 'productTitle' },
{ title: '单价', key: 'price', width: 100 },
{ title: '数量', dataIndex: 'quantity', key: 'quantity', width: 100 },
{ title: '总价', key: 'totalPrice', width: 100 }
]
const columns = [
{ title: '订单编号', dataIndex: 'orderNo', key: 'orderNo' },
{ title: '用户ID', dataIndex: 'userId', key: 'userId' },
{ title: '总金额', dataIndex: 'totalAmount', key: 'totalAmount',
render: (text: number) => `¥${text.toFixed(2)}`
},
{ title: '实际金额', dataIndex: 'actualAmount', key: 'actualAmount',
render: (text: number) => `¥${text.toFixed(2)}`
},
{ title: '优惠券', dataIndex: 'couponName', key: 'couponName',
render: (text: string | null) => text || '无'
},
{ title: '用户ID', dataIndex: 'userId', key: 'userId', width: 100 },
{ title: '订单总额', key: 'totalAmount', width: 120 },
{ title: '实付金额', key: 'actualAmount', width: 120 },
{ title: '优惠券', dataIndex: 'couponName', key: 'couponName', width: 140 },
{ title: '状态', key: 'status', width: 100 },
{ title: '创建时间', dataIndex: 'createTime', key: 'createTime' },
{ title: '操作', key: 'actions', width: 150, fixed: 'right' as const }
{ title: '创建时间', dataIndex: 'createTime', key: 'createTime', width: 180 },
{ title: '操作', key: 'actions', width: 180 }
]
const getStatusColor = (status: number) => {
switch (status) {
case 1:
return 'orange'
case 2:
return 'green'
case 3:
return 'red'
default:
return 'default'
}
const itemColumns = [
{ title: '商品ID', dataIndex: 'productId', key: 'productId', width: 100 },
{ title: '商品名称', dataIndex: 'productTitle', key: 'productTitle' },
{ title: '美甲师', dataIndex: 'artistName', key: 'artistName', width: 120 },
{ title: '预约时间', dataIndex: 'appointmentTime', key: 'appointmentTime', width: 180 },
{ title: '单价', key: 'price', width: 100 },
{ title: '数量', dataIndex: 'quantity', key: 'quantity', width: 80 },
{ title: '总价', key: 'totalPrice', width: 100 }
]
const statusColor = (status: number) => {
if (status === 1) return 'orange'
if (status === 2) return 'green'
if (status === 3) return 'red'
return 'default'
}
const loadOrders = async () => {
loading.value = true
try {
const data = await orderApi.getAllOrders() as unknown as Order[]
orders.value = data
pagination.total = data.length
} catch (error) {
orders.value = await orderApi.getAllOrders() as unknown as any[]
} catch {
message.error('获取订单列表失败')
} finally {
loading.value = false
}
}
const handleSearch = () => {
pagination.current = 1
loadOrders()
}
const handleTableChange = (pag: any) => {
pagination.current = pag.current
pagination.pageSize = pag.pageSize
loadOrders()
}
const processOrder = async (orderId: number, status: number) => {
const process = async (orderId: number, status: number) => {
try {
await orderApi.processOrder(orderId, status)
message.success('操作成功')
loadOrders()
} catch (error) {
await loadOrders()
if (currentOrder.value?.id === orderId) {
currentOrder.value = orders.value.find(order => order.id === orderId) || null
}
} catch {
message.error('操作失败')
}
}
const showOrderDetail = (order: Record<string, any>) => {
currentOrder.value = order as Order
detailModalVisible.value = true
}
const handleDetailModalCancel = () => {
detailModalVisible.value = false
currentOrder.value = null
}
onMounted(() => {
loadOrders()
})
onMounted(loadOrders)
</script>
<style scoped>
.orders {
padding: 0;
}
.orders :deep(.ant-table) {
margin: 0;
}
.orders :deep(.ant-table-thead > tr > th) {
background-color: #fafafa;
font-weight: 600;
}
.orders :deep(.ant-table-tbody > tr:hover > td) {
background-color: #f5f5f5;
}
.orders { padding: 0; }
</style>
@@ -4,7 +4,9 @@ import com.xiaowang.yuminailcore.annotation.RequirePermission;
import com.xiaowang.yuminailcore.common.Result;
import com.xiaowang.yuminailcore.dto.OrderDTO;
import com.xiaowang.yuminailcore.service.OrderService;
import com.xiaowang.yuminailcore.service.UserService;
import com.xiaowang.yuminailcore.vo.OrderVO;
import com.xiaowang.yuminailcore.vo.UserVO;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
@@ -18,6 +20,9 @@ public class OrderController {
@Resource
private OrderService orderService;
@Resource
private UserService userService;
@PostMapping("/create")
public Result<OrderVO> createOrder(@RequestBody OrderDTO orderDTO, HttpServletRequest request) {
Long userId = (Long) request.getAttribute("userId");
@@ -33,8 +38,9 @@ public class OrderController {
}
@GetMapping("/detail/{orderId}")
public Result<OrderVO> getOrderDetail(@PathVariable Long orderId) {
OrderVO orderVO = orderService.getOrderDetail(orderId);
public Result<OrderVO> getOrderDetail(@PathVariable Long orderId, HttpServletRequest request) {
Long userId = (Long) request.getAttribute("userId");
OrderVO orderVO = orderService.getOrderDetail(orderId, userId);
return Result.success(orderVO);
}
@@ -48,23 +54,66 @@ public class OrderController {
// 后台管理接口
@RequirePermission("order:view")
@GetMapping("/admin/list")
public Result<List<OrderVO>> getAllOrders() {
public Result<List<OrderVO>> getAllOrders(HttpServletRequest request) {
Long userId = (Long) request.getAttribute("userId");
Integer userType = (Integer) request.getAttribute("userType");
List<OrderVO> orderList = orderService.getAllOrders();
if (!Integer.valueOf(4).equals(userType)) {
UserVO currentUser = userService.getUserById(userId);
if (currentUser == null || currentUser.getShopId() == null) {
throw new RuntimeException("当前账号未绑定店铺");
}
orderList = orderList.stream()
.filter(order -> currentUser.getShopId().equals(order.getShopId()))
.toList();
}
return Result.success(orderList);
}
@RequirePermission("order:process")
@PutMapping("/admin/process/{orderId}")
public Result<Void> processOrder(@PathVariable Long orderId, @RequestParam Integer status) {
public Result<Void> processOrder(@PathVariable Long orderId, @RequestParam Integer status, HttpServletRequest request) {
Long userId = (Long) request.getAttribute("userId");
Integer userType = (Integer) request.getAttribute("userType");
if (!Integer.valueOf(4).equals(userType)) {
UserVO currentUser = userService.getUserById(userId);
if (currentUser == null || currentUser.getShopId() == null) {
throw new RuntimeException("当前账号未绑定店铺");
}
OrderVO orderVO = orderService.getAllOrders().stream()
.filter(order -> orderId.equals(order.getId()))
.findFirst()
.orElse(null);
if (orderVO == null || !currentUser.getShopId().equals(orderVO.getShopId())) {
throw new RuntimeException("无权处理其他店铺订单");
}
}
orderService.processOrder(orderId, status);
return Result.success();
}
// 美甲师查看自己的订单
@RequirePermission("order:view")
@GetMapping("/artist/list")
public Result<List<OrderVO>> getArtistOrders(HttpServletRequest request) {
Long userId = (Long) request.getAttribute("userId");
Integer userType = (Integer) request.getAttribute("userType");
if (!Integer.valueOf(3).equals(userType)) {
throw new RuntimeException("仅美甲师可查看自己的订单");
}
List<OrderVO> orderList = orderService.getOrdersByArtistId(userId);
return Result.success(orderList);
}
}
@RequirePermission("order:process")
@PutMapping("/artist/complete/{orderId}")
public Result<Void> completeArtistOrder(@PathVariable Long orderId, HttpServletRequest request) {
Long userId = (Long) request.getAttribute("userId");
Integer userType = (Integer) request.getAttribute("userType");
if (!Integer.valueOf(3).equals(userType)) {
throw new RuntimeException("仅美甲师可完成自己的订单");
}
orderService.completeArtistOrder(orderId, userId);
return Result.success();
}
}
@@ -26,4 +26,9 @@ public class OrderItemDTO {
* 美甲师ID
*/
private Long artistId;
/**
* 预约开始时间
*/
private String appointmentTime;
}
@@ -1,5 +1,6 @@
package com.xiaowang.yuminailcore.entity;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableName;
import lombok.Data;
@@ -14,7 +15,11 @@ public class OrderItemDO extends BaseEntity {
private Integer quantity;
private BigDecimal price;
private Long artistId;
@TableField("appointment_time")
private LocalDateTime appointmentTime;
private LocalDateTime createTime;
private LocalDateTime updateTime;
private Integer isDelete;
}
}
@@ -13,6 +13,15 @@ import java.util.List;
public interface OrderItemMapper extends BaseMapper<OrderItemDO> {
@Select("SELECT * FROM t_order_item WHERE order_id = #{orderId}")
List<OrderItemDO> selectByOrderId(@Param("orderId") Long orderId);
@Select("SELECT oi.* FROM t_order_item oi " +
"INNER JOIN t_order o ON o.id = oi.order_id " +
"WHERE oi.artist_id = #{artistId} " +
"AND oi.is_delete = 0 " +
"AND o.is_delete = 0 " +
"AND o.status <> 3 " +
"AND oi.appointment_time IS NOT NULL")
List<OrderItemDO> selectActiveAppointmentItemsByArtistId(@Param("artistId") Long artistId);
@Select("SELECT COUNT(DISTINCT oi.order_id) as count FROM t_order_item oi " +
"JOIN t_product p ON oi.product_id = p.id " +
@@ -22,4 +31,4 @@ public interface OrderItemMapper extends BaseMapper<OrderItemDO> {
@Select("SELECT COUNT(DISTINCT id) as count FROM t_order WHERE create_time >= STR_TO_DATE(#{todayStart}, '%Y-%m-%d %H:%i:%s') AND is_delete = 0")
java.util.Map<String, Object> countTodayOrders(@Param("todayStart") String todayStart);
}
}
@@ -8,9 +8,10 @@ import java.util.List;
public interface OrderService {
OrderVO createOrder(Long userId, OrderDTO orderDTO);
List<OrderVO> getOrderList(Long userId);
OrderVO getOrderDetail(Long orderId);
OrderVO getOrderDetail(Long orderId, Long userId);
void cancelOrder(Long orderId, Long userId);
void processOrder(Long orderId, Integer status);
void completeArtistOrder(Long orderId, Long artistId);
List<OrderVO> getAllOrders();
List<OrderVO> getOrdersByArtistId(Long artistId);
}
}
@@ -3,24 +3,65 @@ package com.xiaowang.yuminailcore.service.impl;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.xiaowang.yuminailcore.dto.OrderDTO;
import com.xiaowang.yuminailcore.dto.OrderItemDTO;
import com.xiaowang.yuminailcore.entity.*;
import com.xiaowang.yuminailcore.mapper.*;
import com.xiaowang.yuminailcore.entity.CartDO;
import com.xiaowang.yuminailcore.entity.CouponDO;
import com.xiaowang.yuminailcore.entity.OrderDO;
import com.xiaowang.yuminailcore.entity.OrderItemDO;
import com.xiaowang.yuminailcore.entity.ProductDO;
import com.xiaowang.yuminailcore.entity.ShopDO;
import com.xiaowang.yuminailcore.entity.UserCouponDO;
import com.xiaowang.yuminailcore.entity.UserDO;
import com.xiaowang.yuminailcore.mapper.CartMapper;
import com.xiaowang.yuminailcore.mapper.CouponMapper;
import com.xiaowang.yuminailcore.mapper.OrderItemMapper;
import com.xiaowang.yuminailcore.mapper.OrderMapper;
import com.xiaowang.yuminailcore.mapper.ProductMapper;
import com.xiaowang.yuminailcore.mapper.ShopMapper;
import com.xiaowang.yuminailcore.mapper.UserCouponMapper;
import com.xiaowang.yuminailcore.mapper.UserMapper;
import com.xiaowang.yuminailcore.service.CouponService;
import com.xiaowang.yuminailcore.service.OrderService;
import com.xiaowang.yuminailcore.service.TagService;
import com.xiaowang.yuminailcore.vo.OrderItemVO;
import com.xiaowang.yuminailcore.vo.OrderVO;
import com.xiaowang.yuminailcore.vo.TagVO;
import com.xiaowang.yuminailcore.vo.UserCouponVO;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import javax.annotation.Resource;
import java.math.BigDecimal;
import java.time.LocalDateTime;
import java.time.LocalTime;
import java.time.format.DateTimeFormatter;
import java.time.format.DateTimeParseException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Comparator;
import java.util.HashMap;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.UUID;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
@Service
public class OrderServiceImpl implements OrderService {
private static final DateTimeFormatter ORDER_NO_TIME_FORMATTER = DateTimeFormatter.ofPattern("yyyyMMddHHmmss");
private static final DateTimeFormatter APPOINTMENT_OUTPUT_FORMATTER = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
private static final List<DateTimeFormatter> APPOINTMENT_INPUT_FORMATTERS = Arrays.asList(
DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"),
DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm"),
DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ss"),
DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm")
);
private static final Pattern DURATION_PATTERN = Pattern.compile("(\\d+)");
private static final Pattern BUSINESS_HOURS_PATTERN = Pattern.compile("^(\\d{1,2}:\\d{2})\\s*[-~至]\\s*(\\d{1,2}:\\d{2})$");
private static final long DEFAULT_SERVICE_DURATION_MINUTES = 60L;
@Resource
private OrderMapper orderMapper;
@@ -42,84 +83,96 @@ public class OrderServiceImpl implements OrderService {
@Resource
private UserMapper userMapper;
@Resource
private ShopMapper shopMapper;
@Resource
private CouponService couponService;
@Resource
private TagService tagService;
@Override
@Transactional
public OrderVO createOrder(Long userId, OrderDTO orderDTO) {
// 获取订单项列表
List<OrderItemDTO> orderItemDTOs = orderDTO.getItems();
if (orderItemDTOs == null || orderItemDTOs.isEmpty()) {
if (orderDTO == null || orderDTO.getItems() == null || orderDTO.getItems().isEmpty()) {
throw new RuntimeException("订单项不能为空");
}
// 计算总金额
List<OrderItemDTO> orderItemDTOs = orderDTO.getItems();
BigDecimal totalAmount = BigDecimal.ZERO;
List<OrderItemDO> orderItems = new ArrayList<>();
List<AppointmentSlot> requestedSlots = new ArrayList<>();
Map<Long, ProductDO> productCache = new HashMap<>();
Map<Long, ShopDO> shopCache = new HashMap<>();
Set<String> selectedTagNames = new LinkedHashSet<>();
Long shopId = null;
Long selectedArtistId = null;
for (OrderItemDTO orderItemDTO : orderItemDTOs) {
validateOrderQuantity(orderItemDTO.getQuantity());
ProductDO product = productMapper.selectById(orderItemDTO.getProductId());
if (product == null || product.getIsDelete() == 1) {
if (product == null || Integer.valueOf(1).equals(product.getIsDelete())) {
throw new RuntimeException("商品不存在或已下架");
}
productCache.put(product.getId(), product);
// 验证美甲师
if (orderItemDTO.getArtistId() != null) {
UserDO artist = userMapper.selectById(orderItemDTO.getArtistId());
if (artist == null || artist.getIsDelete() == 1) {
throw new RuntimeException("美甲师不存在或已删除");
}
if (artist.getType() != 3) {
throw new RuntimeException("指定的用户不是美甲师");
}
if (artist.getStatus() == 0) {
throw new RuntimeException("美甲师已被禁用");
}
// 验证商品是否可以被该美甲师预约
if (product.getBookableArtists() != null && !product.getBookableArtists().isEmpty()) {
String[] artistIds = product.getBookableArtists().split(",");
boolean isBookable = false;
for (String artistId : artistIds) {
if (artistId.trim().equals(orderItemDTO.getArtistId().toString())) {
isBookable = true;
break;
}
}
if (!isBookable) {
throw new RuntimeException("该美甲师无法预约此商品");
}
}
} else {
throw new RuntimeException("请为每个商品选择美甲师");
CartDO cartItem = cartMapper.selectByUserIdAndProductId(userId, orderItemDTO.getProductId());
if (cartItem == null) {
throw new RuntimeException("请先将商品加入购物车后再结算");
}
if (cartItem.getQuantity() == null || cartItem.getQuantity() < orderItemDTO.getQuantity()) {
throw new RuntimeException("购物车中的商品数量已变化,请刷新后重试");
}
// 设置店铺ID(从第一个商品获取)
UserDO artist = validateArtistForProduct(product, orderItemDTO.getArtistId());
if (shopId == null) {
shopId = product.getShopId();
} else if (!shopId.equals(product.getShopId())) {
throw new RuntimeException("跨店铺商品请分开下单");
}
BigDecimal itemTotal = product.getPrice().multiply(new BigDecimal(orderItemDTO.getQuantity()));
if (selectedArtistId == null) {
selectedArtistId = artist.getId();
} else if (!selectedArtistId.equals(artist.getId())) {
throw new RuntimeException("不同美甲师的项目请分开下单");
}
LocalDateTime appointmentTime = parseAppointmentTime(orderItemDTO.getAppointmentTime());
validateAppointmentTime(appointmentTime, product.getTitle());
long serviceDurationMinutes = resolveServiceDurationMinutes(product) * orderItemDTO.getQuantity();
LocalDateTime appointmentEndTime = appointmentTime.plusMinutes(serviceDurationMinutes);
validateBusinessHours(getShopFromCache(product.getShopId(), shopCache), appointmentTime, appointmentEndTime, product.getTitle());
requestedSlots.add(new AppointmentSlot(product.getTitle(), appointmentTime, appointmentEndTime));
collectTagNames(selectedTagNames, product.getTags());
BigDecimal itemTotal = product.getPrice().multiply(BigDecimal.valueOf(orderItemDTO.getQuantity()));
totalAmount = totalAmount.add(itemTotal);
// 创建订单商品
OrderItemDO orderItem = new OrderItemDO();
orderItem.setProductId(product.getId());
orderItem.setQuantity(orderItemDTO.getQuantity());
orderItem.setPrice(product.getPrice());
orderItem.setArtistId(orderItemDTO.getArtistId());
orderItem.setAppointmentTime(appointmentTime);
orderItems.add(orderItem);
}
validateRequestedSlotConflicts(requestedSlots);
validateArtistScheduleConflicts(selectedArtistId, requestedSlots, productCache);
if (totalAmount.compareTo(BigDecimal.ZERO) == 0) {
throw new RuntimeException("订单金额无效");
}
// 处理优惠券
BigDecimal actualAmount = totalAmount;
Long userCouponId = orderDTO.getCouponId();
Long couponId = null;
if (userCouponId != null && userCouponId > 0) {
// 检查优惠券是否存在且可用
UserCouponDO userCoupon = userCouponMapper.selectOne(
new QueryWrapper<UserCouponDO>()
.eq("id", userCouponId)
@@ -127,35 +180,45 @@ public class OrderServiceImpl implements OrderService {
.eq("status", 1)
);
if (userCoupon != null) {
couponId = userCoupon.getCouponId();
CouponDO coupon = couponMapper.selectById(couponId);
if (coupon != null && coupon.getStatus() == 1) {
// 计算优惠金额
if (coupon.getCouponType() == 1) { // 折扣券
actualAmount = totalAmount.multiply(coupon.getDiscountValue())
.divide(new BigDecimal(10), 2, BigDecimal.ROUND_HALF_UP);
} else if (coupon.getCouponType() == 2) { // 满减券
if (totalAmount.compareTo(coupon.getMinAmount()) >= 0) {
actualAmount = totalAmount.subtract(coupon.getReduceAmount());
if (actualAmount.compareTo(BigDecimal.ZERO) < 0) {
actualAmount = BigDecimal.ZERO;
}
}
}
if (userCoupon == null) {
throw new RuntimeException("优惠券不存在或已失效");
}
// 更新优惠券状态
userCoupon.setStatus(2); // 已使用
userCoupon.setUseTime(LocalDateTime.now());
userCouponMapper.updateById(userCoupon);
String productTagNames = String.join(",", selectedTagNames);
boolean couponAvailable = couponService.getAvailableCoupons(userId, productTagNames, totalAmount.doubleValue()).stream()
.map(UserCouponVO::getId)
.anyMatch(id -> userCouponId.equals(id));
if (!couponAvailable) {
throw new RuntimeException("当前订单不可使用所选优惠券");
}
couponId = userCoupon.getCouponId();
CouponDO coupon = couponMapper.selectById(couponId);
if (coupon == null || Integer.valueOf(1).equals(coupon.getIsDelete()) || coupon.getStatus() != 1) {
throw new RuntimeException("优惠券不存在或已失效");
}
if (shopId != null && coupon.getShopId() != null && !shopId.equals(coupon.getShopId())) {
throw new RuntimeException("该优惠券不适用于当前店铺");
}
if (coupon.getCouponType() == 1) {
actualAmount = totalAmount.multiply(coupon.getDiscountValue())
.divide(BigDecimal.valueOf(10), 2, BigDecimal.ROUND_HALF_UP);
} else if (coupon.getCouponType() == 2 && totalAmount.compareTo(coupon.getMinAmount()) >= 0) {
actualAmount = totalAmount.subtract(coupon.getReduceAmount());
if (actualAmount.compareTo(BigDecimal.ZERO) < 0) {
actualAmount = BigDecimal.ZERO;
}
}
userCoupon.setStatus(2);
userCoupon.setUseTime(LocalDateTime.now());
userCouponMapper.updateById(userCoupon);
}
// 生成订单号
String orderNo = "ORD" + LocalDateTime.now().format(java.time.format.DateTimeFormatter.ofPattern("yyyyMMddHHmmss")) + UUID.randomUUID().toString().substring(0, 8).toUpperCase();
String orderNo = "ORD" + LocalDateTime.now().format(ORDER_NO_TIME_FORMATTER)
+ UUID.randomUUID().toString().substring(0, 8).toUpperCase();
// 创建订单
OrderDO order = new OrderDO();
order.setOrderNo(orderNo);
order.setUserId(userId);
@@ -163,18 +226,24 @@ public class OrderServiceImpl implements OrderService {
order.setTotalAmount(totalAmount);
order.setActualAmount(actualAmount);
order.setCouponId(couponId);
order.setStatus(1); // 待使用
order.setStatus(1);
order.setIsDelete(0);
orderMapper.insert(order);
// 创建订单商品
for (OrderItemDO item : orderItems) {
item.setOrderId(order.getId());
item.setIsDelete(0);
orderItemMapper.insert(item);
}
// 构建返回对象
for (OrderItemDTO orderItemDTO : orderItemDTOs) {
QueryWrapper<CartDO> cartWrapper = new QueryWrapper<>();
cartWrapper.eq("user_id", userId)
.eq("product_id", orderItemDTO.getProductId())
.eq("is_delete", 0);
cartMapper.delete(cartWrapper);
}
return buildOrderVO(order);
}
@@ -182,23 +251,23 @@ public class OrderServiceImpl implements OrderService {
public List<OrderVO> getOrderList(Long userId) {
List<OrderDO> orderList = orderMapper.selectByUserId(userId);
List<OrderVO> orderVOList = new ArrayList<>();
for (OrderDO order : orderList) {
if (order.getIsDelete() == 0) {
if (!Integer.valueOf(1).equals(order.getIsDelete())) {
orderVOList.add(buildOrderVO(order));
}
}
return orderVOList;
}
@Override
public OrderVO getOrderDetail(Long orderId) {
public OrderVO getOrderDetail(Long orderId, Long userId) {
OrderDO order = orderMapper.selectById(orderId);
if (order == null || order.getIsDelete() == 1) {
if (order == null || Integer.valueOf(1).equals(order.getIsDelete())) {
throw new RuntimeException("订单不存在");
}
if (!order.getUserId().equals(userId)) {
throw new RuntimeException("无权查看此订单");
}
return buildOrderVO(order);
}
@@ -206,38 +275,30 @@ public class OrderServiceImpl implements OrderService {
@Transactional
public void cancelOrder(Long orderId, Long userId) {
OrderDO order = orderMapper.selectById(orderId);
if (order == null || order.getIsDelete() == 1) {
if (order == null || Integer.valueOf(1).equals(order.getIsDelete())) {
throw new RuntimeException("订单不存在");
}
if (!order.getUserId().equals(userId)) {
throw new RuntimeException("无权操作此订单");
}
if (order.getStatus() != 1) { // 只有待使用状态可以取消
if (order.getStatus() != 1) {
throw new RuntimeException("订单状态不允许取消");
}
// 更新订单状态
order.setStatus(3); // 已取消
order.setStatus(3);
orderMapper.updateById(order);
// 返还优惠券
if (order.getCouponId() != null && order.getCouponId() > 0) {
// 查询用户的已使用优惠券,找到与订单中couponId匹配的记录
List<UserCouponDO> userCoupons = userCouponMapper.selectList(
new QueryWrapper<UserCouponDO>()
.eq("user_id", userId)
.eq("coupon_id", order.getCouponId())
.eq("status", 2)
);
// 找到最近使用的优惠券
if (!userCoupons.isEmpty()) {
// 按使用时间倒序排序,取最近使用的
userCoupons.sort((a, b) -> b.getUseTime().compareTo(a.getUseTime()));
UserCouponDO userCoupon = userCoupons.get(0);
userCoupon.setStatus(1); // 未使用
userCoupon.setStatus(1);
userCoupon.setUseTime(null);
userCouponMapper.updateById(userCoupon);
}
@@ -248,53 +309,70 @@ public class OrderServiceImpl implements OrderService {
@Transactional
public void processOrder(Long orderId, Integer status) {
OrderDO order = orderMapper.selectById(orderId);
if (order == null || order.getIsDelete() == 1) {
if (order == null || Integer.valueOf(1).equals(order.getIsDelete())) {
throw new RuntimeException("订单不存在");
}
if (status != 2 && status != 3) { // 只能设置为已完成或已取消
if (status != 2 && status != 3) {
throw new RuntimeException("无效的订单状态");
}
if (order.getStatus() != 1) { // 只有待使用状态可以处理
if (order.getStatus() != 1) {
throw new RuntimeException("订单状态不允许处理");
}
// 更新订单状态
order.setStatus(status);
orderMapper.updateById(order);
// 如果取消订单,返还优惠券
if (status == 3 && order.getCouponId() != null && order.getCouponId() > 0) {
// 查询用户的已使用优惠券,找到与订单中couponId匹配的记录
List<UserCouponDO> userCoupons = userCouponMapper.selectList(
new QueryWrapper<UserCouponDO>()
.eq("user_id", order.getUserId())
.eq("coupon_id", order.getCouponId())
.eq("status", 2)
);
// 找到最近使用的优惠券
if (!userCoupons.isEmpty()) {
// 按使用时间倒序排序,取最近使用的
userCoupons.sort((a, b) -> b.getUseTime().compareTo(a.getUseTime()));
UserCouponDO userCoupon = userCoupons.get(0);
userCoupon.setStatus(1); // 未使用
userCoupon.setStatus(1);
userCoupon.setUseTime(null);
userCouponMapper.updateById(userCoupon);
}
}
}
@Override
@Transactional
public void completeArtistOrder(Long orderId, Long artistId) {
OrderDO order = orderMapper.selectById(orderId);
if (order == null || Integer.valueOf(1).equals(order.getIsDelete())) {
throw new RuntimeException("订单不存在");
}
if (order.getStatus() != 1) {
throw new RuntimeException("当前订单状态不允许完成");
}
List<OrderItemDO> activeItems = orderItemMapper.selectByOrderId(orderId).stream()
.filter(item -> !Integer.valueOf(1).equals(item.getIsDelete()))
.toList();
if (activeItems.isEmpty()) {
throw new RuntimeException("订单商品不存在");
}
boolean allBelongToArtist = activeItems.stream().allMatch(item -> artistId.equals(item.getArtistId()));
if (!allBelongToArtist) {
throw new RuntimeException("只能完成全部由自己承接的订单");
}
order.setStatus(2);
orderMapper.updateById(order);
}
@Override
public List<OrderVO> getAllOrders() {
List<OrderDO> orderList = orderMapper.selectList(new QueryWrapper<OrderDO>().eq("is_delete", 0));
List<OrderVO> orderVOList = new ArrayList<>();
for (OrderDO order : orderList) {
orderVOList.add(buildOrderVO(order));
}
return orderVOList;
}
@@ -302,15 +380,20 @@ public class OrderServiceImpl implements OrderService {
public List<OrderVO> getOrdersByArtistId(Long artistId) {
List<OrderDO> orderList = orderMapper.selectByArtistId(artistId);
List<OrderVO> orderVOList = new ArrayList<>();
for (OrderDO order : orderList) {
orderVOList.add(buildOrderVO(order));
OrderVO orderVO = buildOrderVO(order, artistId);
if (orderVO != null && orderVO.getItems() != null && !orderVO.getItems().isEmpty()) {
orderVOList.add(orderVO);
}
}
return orderVOList;
}
private OrderVO buildOrderVO(OrderDO order) {
return buildOrderVO(order, null);
}
private OrderVO buildOrderVO(OrderDO order, Long artistIdFilter) {
OrderVO orderVO = new OrderVO();
orderVO.setId(order.getId());
orderVO.setOrderNo(order.getOrderNo());
@@ -321,7 +404,6 @@ public class OrderServiceImpl implements OrderService {
orderVO.setCouponId(order.getCouponId());
orderVO.setStatus(order.getStatus());
// 设置状态文本
switch (order.getStatus()) {
case 1:
orderVO.setStatusText("待使用");
@@ -332,10 +414,11 @@ public class OrderServiceImpl implements OrderService {
case 3:
orderVO.setStatusText("已取消");
break;
default:
orderVO.setStatusText("未知状态");
}
// 设置优惠券名称
if (order.getCouponId() != null && order.getCouponId() > 0) {
if (artistIdFilter == null && order.getCouponId() != null && order.getCouponId() > 0) {
CouponDO coupon = couponMapper.selectById(order.getCouponId());
if (coupon != null) {
orderVO.setCouponName(coupon.getCouponName());
@@ -344,44 +427,292 @@ public class OrderServiceImpl implements OrderService {
orderVO.setCreateTime(order.getCreateTime());
// 设置订单商品
List<OrderItemDO> orderItems = orderItemMapper.selectByOrderId(order.getId());
List<OrderItemVO> orderItemVOs = new ArrayList<>();
BigDecimal filteredTotal = BigDecimal.ZERO;
List<OrderItemDO> orderItems = orderItemMapper.selectByOrderId(order.getId());
for (OrderItemDO item : orderItems) {
if (item.getIsDelete() == 0) {
ProductDO product = productMapper.selectById(item.getProductId());
if (product != null) {
OrderItemVO itemVO = new OrderItemVO();
itemVO.setId(item.getId());
itemVO.setProductId(product.getId());
itemVO.setProductTitle(product.getTitle());
// 简单处理,取第一张图片
String imageFileIds = product.getImageFileIds();
if (imageFileIds != null && !imageFileIds.isEmpty()) {
String firstImageId = imageFileIds.split(",")[0];
itemVO.setProductImage("/api/file/get/" + firstImageId);
}
itemVO.setQuantity(item.getQuantity());
itemVO.setPrice(item.getPrice());
itemVO.setTotalPrice(item.getPrice().multiply(new BigDecimal(item.getQuantity())));
// 设置美甲师信息
if (item.getArtistId() != null) {
itemVO.setArtistId(item.getArtistId());
UserDO artist = userMapper.selectById(item.getArtistId());
if (artist != null) {
itemVO.setArtistName(artist.getNickname());
itemVO.setArtistAvatar(artist.getAvatar());
}
}
orderItemVOs.add(itemVO);
if (Integer.valueOf(1).equals(item.getIsDelete())) {
continue;
}
if (artistIdFilter != null && !artistIdFilter.equals(item.getArtistId())) {
continue;
}
ProductDO product = productMapper.selectById(item.getProductId());
if (product == null) {
continue;
}
OrderItemVO itemVO = new OrderItemVO();
itemVO.setId(item.getId());
itemVO.setProductId(product.getId());
itemVO.setProductTitle(product.getTitle());
String imageFileIds = product.getImageFileIds();
if (imageFileIds != null && !imageFileIds.isEmpty()) {
String firstImageId = imageFileIds.split(",")[0];
itemVO.setProductImage("/api/file/get/" + firstImageId);
}
itemVO.setQuantity(item.getQuantity());
itemVO.setPrice(item.getPrice());
itemVO.setTotalPrice(item.getPrice().multiply(BigDecimal.valueOf(item.getQuantity())));
itemVO.setAppointmentTime(formatAppointmentTime(item.getAppointmentTime()));
filteredTotal = filteredTotal.add(itemVO.getTotalPrice());
if (item.getArtistId() != null) {
itemVO.setArtistId(item.getArtistId());
UserDO artist = userMapper.selectById(item.getArtistId());
if (artist != null) {
itemVO.setArtistName(artist.getNickname());
itemVO.setArtistAvatar(artist.getAvatar());
}
}
orderItemVOs.add(itemVO);
}
orderVO.setItems(orderItemVOs);
if (artistIdFilter != null) {
orderVO.setTotalAmount(filteredTotal);
orderVO.setActualAmount(filteredTotal);
}
return orderVO;
}
}
private void validateOrderQuantity(Integer quantity) {
if (quantity == null || quantity < 1) {
throw new RuntimeException("订单商品数量必须大于 0");
}
}
private UserDO validateArtistForProduct(ProductDO product, Long artistId) {
if (artistId == null) {
throw new RuntimeException("请为每个商品选择美甲师");
}
UserDO artist = userMapper.selectById(artistId);
if (artist == null || Integer.valueOf(1).equals(artist.getIsDelete())) {
throw new RuntimeException("美甲师不存在或已删除");
}
if (!Integer.valueOf(3).equals(artist.getType())) {
throw new RuntimeException("指定用户不是美甲师");
}
if (!Integer.valueOf(1).equals(artist.getStatus())) {
throw new RuntimeException("美甲师当前不可预约");
}
if (product.getShopId() != null && !product.getShopId().equals(artist.getShopId())) {
throw new RuntimeException("该美甲师不属于当前商品店铺");
}
if (product.getBookableArtists() != null && !product.getBookableArtists().isEmpty()) {
String[] artistIds = product.getBookableArtists().split(",");
boolean isBookable = false;
for (String currentArtistId : artistIds) {
if (currentArtistId.trim().equals(artistId.toString())) {
isBookable = true;
break;
}
}
if (!isBookable) {
throw new RuntimeException("该美甲师无法预约此商品");
}
}
return artist;
}
private void collectTagNames(Set<String> tagNames, String tags) {
if (tags == null || tags.isBlank()) {
return;
}
for (String tagId : tags.split(";")) {
if (tagId == null || tagId.isBlank()) {
continue;
}
try {
TagVO tagVO = tagService.getTagById(Long.parseLong(tagId.trim()));
if (tagVO != null && tagVO.getTagName() != null && !tagVO.getTagName().isBlank()) {
tagNames.add(tagVO.getTagName());
}
} catch (NumberFormatException ignored) {
}
}
}
private LocalDateTime parseAppointmentTime(String appointmentTime) {
if (appointmentTime == null || appointmentTime.isBlank()) {
throw new RuntimeException("请为每个商品选择预约时间");
}
String normalized = appointmentTime.trim();
for (DateTimeFormatter formatter : APPOINTMENT_INPUT_FORMATTERS) {
try {
return LocalDateTime.parse(normalized, formatter);
} catch (DateTimeParseException ignored) {
}
}
throw new RuntimeException("预约时间格式不正确");
}
private void validateAppointmentTime(LocalDateTime appointmentTime, String productTitle) {
if (!appointmentTime.isAfter(LocalDateTime.now())) {
throw new RuntimeException("商品「" + productTitle + "」的预约时间必须晚于当前时间");
}
}
private void validateBusinessHours(ShopDO shop, LocalDateTime appointmentTime, LocalDateTime appointmentEndTime, String productTitle) {
if (shop == null || shop.getBusinessHours() == null || shop.getBusinessHours().isBlank()) {
return;
}
String normalizedBusinessHours = shop.getBusinessHours()
.replace(':', ':')
.replace('-', '-')
.replace('—', '-')
.trim();
Matcher matcher = BUSINESS_HOURS_PATTERN.matcher(normalizedBusinessHours);
if (!matcher.matches()) {
return;
}
LocalTime openTime = LocalTime.parse(matcher.group(1), DateTimeFormatter.ofPattern("H:mm"));
LocalTime closeTime = LocalTime.parse(matcher.group(2), DateTimeFormatter.ofPattern("H:mm"));
if (!closeTime.isAfter(openTime)) {
return;
}
if (!appointmentTime.toLocalDate().equals(appointmentEndTime.toLocalDate())
|| appointmentTime.toLocalTime().isBefore(openTime)
|| appointmentEndTime.toLocalTime().isAfter(closeTime)) {
throw new RuntimeException("商品「" + productTitle + "」的预约时间超出门店营业时间");
}
}
private ShopDO getShopFromCache(Long shopId, Map<Long, ShopDO> shopCache) {
if (shopId == null) {
return null;
}
if (shopCache.containsKey(shopId)) {
return shopCache.get(shopId);
}
ShopDO shop = shopMapper.selectById(shopId);
if (shop != null && Integer.valueOf(1).equals(shop.getIsDelete())) {
shop = null;
}
shopCache.put(shopId, shop);
return shop;
}
private void validateRequestedSlotConflicts(List<AppointmentSlot> requestedSlots) {
if (requestedSlots.size() <= 1) {
return;
}
requestedSlots.sort(Comparator.comparing(AppointmentSlot::getStartTime));
for (int i = 1; i < requestedSlots.size(); i++) {
AppointmentSlot previous = requestedSlots.get(i - 1);
AppointmentSlot current = requestedSlots.get(i);
if (hasOverlap(previous.getStartTime(), previous.getEndTime(), current.getStartTime(), current.getEndTime())) {
throw new RuntimeException("所选预约时间存在冲突,请调整「" + previous.getProductTitle() + "」和「" + current.getProductTitle() + "」的预约时间");
}
}
}
private void validateArtistScheduleConflicts(Long artistId, List<AppointmentSlot> requestedSlots, Map<Long, ProductDO> productCache) {
if (artistId == null || requestedSlots.isEmpty()) {
return;
}
List<OrderItemDO> existingAppointments = orderItemMapper.selectActiveAppointmentItemsByArtistId(artistId);
if (existingAppointments == null || existingAppointments.isEmpty()) {
return;
}
for (OrderItemDO existingItem : existingAppointments) {
if (existingItem.getAppointmentTime() == null || Integer.valueOf(1).equals(existingItem.getIsDelete())) {
continue;
}
ProductDO existingProduct = getProductFromCache(existingItem.getProductId(), productCache);
if (existingProduct == null) {
continue;
}
long existingDurationMinutes = resolveServiceDurationMinutes(existingProduct) * Math.max(1, existingItem.getQuantity());
LocalDateTime existingEndTime = existingItem.getAppointmentTime().plusMinutes(existingDurationMinutes);
for (AppointmentSlot requestedSlot : requestedSlots) {
if (hasOverlap(existingItem.getAppointmentTime(), existingEndTime, requestedSlot.getStartTime(), requestedSlot.getEndTime())) {
throw new RuntimeException("商品「" + requestedSlot.getProductTitle() + "」的预约时间与美甲师已有预约冲突,请重新选择");
}
}
}
}
private ProductDO getProductFromCache(Long productId, Map<Long, ProductDO> productCache) {
if (productId == null) {
return null;
}
if (productCache.containsKey(productId)) {
return productCache.get(productId);
}
ProductDO product = productMapper.selectById(productId);
productCache.put(productId, product);
return product;
}
private long resolveServiceDurationMinutes(ProductDO product) {
if (product == null || product.getApproximateDuration() == null || product.getApproximateDuration().isBlank()) {
return DEFAULT_SERVICE_DURATION_MINUTES;
}
Matcher matcher = DURATION_PATTERN.matcher(product.getApproximateDuration());
if (matcher.find()) {
try {
return Math.max(1L, Long.parseLong(matcher.group(1)));
} catch (NumberFormatException ignored) {
}
}
return DEFAULT_SERVICE_DURATION_MINUTES;
}
private boolean hasOverlap(LocalDateTime startA, LocalDateTime endA, LocalDateTime startB, LocalDateTime endB) {
return startA.isBefore(endB) && startB.isBefore(endA);
}
private String formatAppointmentTime(LocalDateTime appointmentTime) {
if (appointmentTime == null) {
return null;
}
return appointmentTime.format(APPOINTMENT_OUTPUT_FORMATTER);
}
private static final class AppointmentSlot {
private final String productTitle;
private final LocalDateTime startTime;
private final LocalDateTime endTime;
private AppointmentSlot(String productTitle, LocalDateTime startTime, LocalDateTime endTime) {
this.productTitle = productTitle;
this.startTime = startTime;
this.endTime = endTime;
}
private String getProductTitle() {
return productTitle;
}
private LocalDateTime getStartTime() {
return startTime;
}
private LocalDateTime getEndTime() {
return endTime;
}
}
}
@@ -16,4 +16,5 @@ public class OrderItemVO {
private Long artistId;
private String artistName;
private String artistAvatar;
}
private String appointmentTime;
}
+3
View File
@@ -216,6 +216,9 @@ Frontend
- Gateway 与 Core 的接口路径规范还没有完全统一。
- 白名单策略分散在 Gateway、Core、前端多个位置。
- 后台管理接口虽然共用同一套权限码,但业务数据已经逐步按“平台管理员可全局、店长/美甲师仅限所属店铺”收口,后续新增后台接口时也应沿用这个租户边界。
- 购物车与订单链路已经补上“服务端校验购物车归属、同店铺/同美甲师下单、下单后由服务端清理购物车”的约束,避免继续把关键结算规则只留在前端。
- 购物车与订单链路已经补上 `t_order_item.appointment_time`,下单时会同时校验预约时间是否晚于当前时间、是否超出营业时间、是否与同美甲师已有预约冲突;如果后续要继续提升体验,再补实时排班/忙闲查询接口会更合适。
- 当前仓库里 Core 与 MessageHub 的接入方式已经存在,但架构文档需要避免把它写成强耦合依赖。
- MessageHub 的文档描述比实际代码实现更“平台化”,后续如果真要服务多个项目,建议继续按平台标准收口接口和消息契约。
+17 -6
View File
@@ -54,6 +54,7 @@
- AuthInterceptor会进一步验证token的有效性
- 验证token是否过期、是否为accessToken类型
- 从token中提取用户信息并设置到请求属性中
- 订单创建时还会校验购物车归属、同店铺/同美甲师约束、预约时间有效性、门店营业时间以及美甲师已有预约冲突
3. **权限控制**:
- 后端使用@RequirePermission注解进行权限控制
@@ -294,11 +295,14 @@ private boolean isWhitelistedPath(String path) {
- id:订单商品唯一主键ID
- order_id:关联订单表主键
- product_id:关联商品表主键
- artist_id:承接该订单项的美甲师ID
- appointment_time:预约开始时间
- quantity:商品数量
- price:商品单价
- create_time:创建时间
- update_time:更新时间
- is_delete:逻辑删除
- 当前实现额外约束:一次结算仅允许同店铺、同美甲师的商品进入同一订单,且服务端会校验预约时间不能早于当前时间、不能超出营业时间、不能与同美甲师已有订单冲突
3. **t_cart** - 购物车表
- id:购物车唯一主键ID
@@ -308,6 +312,7 @@ private boolean isWhitelistedPath(String path) {
- create_time:创建时间
- update_time:更新时间
- is_delete:逻辑删除
- 当前实现额外约束:创建订单时会校验商品仍属于当前用户购物车,并由服务端在下单成功后清理对应购物车项
#### 7.2.5 优惠券相关表
@@ -448,10 +453,11 @@ private boolean isWhitelistedPath(String path) {
1. **用户表**:uk_account(账号唯一索引)、idx_phone、idx_email、idx_shop_id、idx_type
2. **商品表**:idx_shop_id、idx_price、idx_title、idx_tags
3. **订单表**:uk_order_no(订单编号唯一索引)、idx_user_id、idx_status
4. **优惠券表**:uk_coupon_code(优惠券编码唯一索引)、idx_shop_id、idx_status
5. **评论表**:idx_user_id、idx_shop_id、idx_product_id、idx_parent_comment_id
6. **余额变动表**:idx_user_id、idx_change_time
7. **用户权限表**:uk_user_permission(用户-权限唯一索引)、idx_user_id、idx_permission_id
4. **订单商品表**:idx_order_id、idx_product_id、idx_artist_appointment_time(建议增加 `artist_id + appointment_time` 联合索引)
5. **优惠券表**:uk_coupon_code(优惠券编码唯一索引)、idx_shop_id、idx_status
6. **评论表**:idx_user_id、idx_shop_id、idx_product_id、idx_parent_comment_id
7. **余额变动表**:idx_user_id、idx_change_time
8. **用户权限表**:uk_user_permission(用户-权限唯一索引)、idx_user_id、idx_permission_id
### 7.5 初始化数据
@@ -533,7 +539,7 @@ private boolean isWhitelistedPath(String path) {
- `GET /api/shop/list/simple` - 获取店铺列表(无需登录)
- `GET /api/product/list` - 获取产品列表
- `POST /api/cart/add` - 添加购物车
- `POST /api/order/create` - 创建订单
- `POST /api/order/create` - 创建订单,并校验预约时间、营业时间与美甲师预约冲突
- `GET /api/user/profile` - 获取用户信息
### 9.3 管理相关
@@ -578,6 +584,11 @@ private boolean isWhitelistedPath(String path) {
当前店铺的标签管理的查看,新增,编辑,分配权限,无删除权限
当前店铺的优惠券管理的查看和分配权限,无其他权限
补充说明:
- 后台“查看/编辑/发放”类接口现在应默认带店铺边界,店长和美甲师只能访问所属店铺的数据。
- 权限定义本身属于全局资源,新增/修改/删除权限码应仅允许平台管理员操作,店铺侧只做用户权限分配。
- 用户:
无后台登录权限和对应的所有权限
@@ -597,4 +608,4 @@ private boolean isWhitelistedPath(String path) {
该项目采用了现代化的前后端分离架构,具有完善的认证和授权机制,以及良好的安全设计。通过多层白名单保护和双Token认证,确保了系统的安全性。同时,清晰的代码组织和合理的服务拆分,为系统的可维护性和扩展性奠定了基础。
在未来的发展中,可以通过集中管理白名单、增强权限管理、加强安全性和完善监控日志等方面进一步提升系统的可靠性和安全性。
在未来的发展中,可以通过集中管理白名单、增强权限管理、加强安全性和完善监控日志等方面进一步提升系统的可靠性和安全性。
@@ -0,0 +1,63 @@
# 2026-03-19 预约时间落库与预约校验补齐
## 1. 本次处理范围
本轮继续落地 `docs/features/待优化建议.md` 中已审核通过的“购物车中的预约时间需要真正落库”,把预约时间从前端展示态补齐到后端模型、订单落库和展示链路。
同时按 `docs/base.md` 要求完成了:
- 将本次修改整理为独立变更记录放入 `docs/changes`
- 将已完成建议从 `docs/features` 移出
- 同步更新整体架构与项目架构分析文档
## 2. 已完成项
### 2.1 后端订单链路
- `t_order_item` 对应的 DTO、实体、VO 新增 `appointmentTime`
- 创建订单时强制要求每个订单项都提供预约时间
- 服务端校验预约时间必须晚于当前时间
- 服务端根据商品预计时长校验同一订单内预约时间是否互相冲突
- 服务端按美甲师已有有效订单校验预约冲突
- 当门店营业时间能解析为标准时段时,服务端校验预约时间不得超出营业时间
- 订单详情、用户订单列表、美甲师订单列表、后台订单列表均可返回预约时间
### 2.2 前端交互链路
- 购物车页面将“选美甲师”升级为“选美甲师 + 选预约时间”
- 前端结算前校验是否已选择预约时间、是否早于当前时间
- 创建订单接口请求体补充 `appointmentTime`
- 用户端订单页、美甲师订单页、后台订单详情页补充预约时间展示
### 2.3 文档整理
- 已将该建议从 `docs/features/待优化建议.md` 中移除
- `docs/architecture/整体架构总览.md` 已更新为当前真实链路
- `docs/architecture/项目架构分析.md` 已补充订单预约字段与校验说明
## 3. 需要你手动执行的 SQL
本轮没有自动执行任何数据库变更。上线或联调前,请你手动执行下面 SQL:
```sql
ALTER TABLE t_order_item
ADD COLUMN appointment_time DATETIME NULL COMMENT '预约开始时间' AFTER artist_id;
CREATE INDEX idx_artist_appointment_time
ON t_order_item (artist_id, appointment_time);
```
说明:
- 如果库里已经存在 `appointment_time` 字段或同名索引,请按实际情况跳过
- 未执行 SQL 前,代码虽然可以编译通过,但订单预约时间无法正确落库
## 4. 验证结果
- `Frontend`:`npm run build` 通过
- `YumiNail-Core`:`mvn -q -DskipTests compile` 通过
## 5. 备注
- 当前已经补齐“预约时间真正参与下单与落库”的核心能力
- 后续如果还想进一步优化预约体验,可再评估是否增加“美甲师排班/忙闲查询”接口,但这不再属于本轮已完成问题的阻塞项
+5
View File
@@ -0,0 +1,5 @@
# 待优化建议
当前已归档的优化建议均已处理完成,`docs/features` 下暂无新的待优化项。
后续如果发现新的问题或确认新的优化方向,再补充到本文件;完成后继续移入 `docs/changes`。