购物车和订单中心以及优惠券相关功能初版
This commit is contained in:
@@ -17,12 +17,15 @@ const adminApi = axios.create({
|
||||
|
||||
adminApi.interceptors.request.use(
|
||||
config => {
|
||||
let token = localStorage.getItem('adminAccessToken')
|
||||
if (!token) {
|
||||
token = sessionStorage.getItem('adminAccessToken')
|
||||
}
|
||||
if (token) {
|
||||
config.headers.Authorization = `Bearer ${token}`
|
||||
// 登录请求不需要携带Token
|
||||
if (!config.url?.includes('/auth/login')) {
|
||||
let token = localStorage.getItem('adminAccessToken')
|
||||
if (!token) {
|
||||
token = sessionStorage.getItem('adminAccessToken')
|
||||
}
|
||||
if (token) {
|
||||
config.headers.Authorization = `Bearer ${token}`
|
||||
}
|
||||
}
|
||||
return config
|
||||
},
|
||||
|
||||
@@ -44,6 +44,10 @@ export const authApi = {
|
||||
return api.post<LoginResponse>('/user/login', data)
|
||||
},
|
||||
|
||||
adminLogin: (data: LoginRequest) => {
|
||||
return api.post<LoginResponse>('/admin/api/auth/login', data)
|
||||
},
|
||||
|
||||
register: (data: RegisterRequest) => {
|
||||
return api.post('/user/register', data)
|
||||
},
|
||||
|
||||
@@ -0,0 +1,33 @@
|
||||
import api from './index'
|
||||
|
||||
interface CartItem {
|
||||
productId: number
|
||||
quantity: number
|
||||
}
|
||||
|
||||
export const cartApi = {
|
||||
// 添加商品到购物车
|
||||
addToCart: (item: CartItem) => {
|
||||
return api.post('/cart/add', item)
|
||||
},
|
||||
|
||||
// 从购物车移除商品
|
||||
removeFromCart: (productId: number) => {
|
||||
return api.delete(`/cart/remove/${productId}`)
|
||||
},
|
||||
|
||||
// 更新购物车商品数量
|
||||
updateCartQuantity: (item: CartItem) => {
|
||||
return api.put('/cart/update', item)
|
||||
},
|
||||
|
||||
// 获取购物车列表
|
||||
getCartList: () => {
|
||||
return api.get('/cart/list')
|
||||
},
|
||||
|
||||
// 清空购物车
|
||||
clearCart: () => {
|
||||
return api.delete('/cart/clear')
|
||||
}
|
||||
}
|
||||
@@ -102,7 +102,8 @@ api.interceptors.response.use(
|
||||
return url?.includes('/user/login') ||
|
||||
url?.includes('/user/register') ||
|
||||
url?.includes('/user/refresh-token') ||
|
||||
url?.includes('/shop/list/simple')
|
||||
url?.includes('/shop/list/simple') ||
|
||||
url?.includes('/admin/login')
|
||||
}
|
||||
|
||||
if (error.response?.status === 401) {
|
||||
|
||||
@@ -0,0 +1,39 @@
|
||||
import api from './index'
|
||||
|
||||
interface CreateOrderRequest {
|
||||
couponId?: number
|
||||
}
|
||||
|
||||
export const orderApi = {
|
||||
// 创建订单
|
||||
createOrder: (data: CreateOrderRequest) => {
|
||||
return api.post('/order/create', data)
|
||||
},
|
||||
|
||||
// 获取订单列表
|
||||
getOrderList: () => {
|
||||
return api.get('/order/list')
|
||||
},
|
||||
|
||||
// 获取订单详情
|
||||
getOrderDetail: (orderId: number) => {
|
||||
return api.get(`/order/detail/${orderId}`)
|
||||
},
|
||||
|
||||
// 取消订单
|
||||
cancelOrder: (orderId: number) => {
|
||||
return api.put(`/order/cancel/${orderId}`)
|
||||
},
|
||||
|
||||
// 后台获取所有订单
|
||||
getAllOrders: () => {
|
||||
return api.get('/order/admin/list')
|
||||
},
|
||||
|
||||
// 后台处理订单
|
||||
processOrder: (orderId: number, status: number) => {
|
||||
return api.put(`/order/admin/process/${orderId}`, {}, {
|
||||
params: { status }
|
||||
})
|
||||
}
|
||||
}
|
||||
@@ -5,16 +5,16 @@ const router = createRouter({
|
||||
routes: [
|
||||
{
|
||||
path: '/',
|
||||
name: 'home',
|
||||
component: () => import('../views/HomeView.vue'),
|
||||
meta: { requiresAuth: true, isAdmin: false }
|
||||
},
|
||||
{
|
||||
path: '/auth',
|
||||
name: 'auth',
|
||||
component: () => import('../views/AuthView.vue'),
|
||||
meta: { requiresAuth: false, hideNav: true, isAdmin: false }
|
||||
},
|
||||
{
|
||||
path: '/home',
|
||||
name: 'home',
|
||||
component: () => import('../views/HomeView.vue'),
|
||||
meta: { requiresAuth: true, isAdmin: false }
|
||||
},
|
||||
{
|
||||
path: '/products',
|
||||
name: 'products',
|
||||
@@ -123,6 +123,12 @@ const router = createRouter({
|
||||
meta: { requiresAuth: true, isAdmin: true, hideNav: true, permissionCode: 'order:view' }
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
path: '/:pathMatch(.*)*',
|
||||
name: 'not-found',
|
||||
component: () => import('../views/NotFoundView.vue'),
|
||||
meta: { requiresAuth: false, hideNav: true, isAdmin: false }
|
||||
}
|
||||
]
|
||||
})
|
||||
@@ -226,11 +232,11 @@ router.beforeEach((to, _from, next) => {
|
||||
const token = localStorage.getItem('accessToken') || sessionStorage.getItem('accessToken')
|
||||
|
||||
if (requiresAuth && !token) {
|
||||
next('/auth')
|
||||
} else if (to.path === '/auth' && token) {
|
||||
next('/')
|
||||
} else if (to.path === '/' && !token) {
|
||||
next('/auth')
|
||||
} else if (to.path === '/' && token) {
|
||||
next('/home')
|
||||
} else if (to.path === '/home' && !token) {
|
||||
next('/')
|
||||
} else {
|
||||
next()
|
||||
}
|
||||
|
||||
@@ -0,0 +1,138 @@
|
||||
<template>
|
||||
<div class="not-found-container">
|
||||
<div class="not-found-content">
|
||||
<div class="error-code">404</div>
|
||||
<h1>页面不存在</h1>
|
||||
<p>您访问的页面不存在或已被删除</p>
|
||||
<p class="redirect-message">
|
||||
将在 <span class="countdown">{{ countdown }}</span> 秒后自动跳转到首页...
|
||||
</p>
|
||||
<a-button type="primary" @click="redirectToHome">立即前往首页</a-button>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { ref, onMounted, onUnmounted } from 'vue'
|
||||
import { useRouter } from 'vue-router'
|
||||
|
||||
const router = useRouter()
|
||||
const countdown = ref(5)
|
||||
let timer: number | null = null
|
||||
|
||||
const redirectToHome = () => {
|
||||
if (timer) {
|
||||
clearInterval(timer)
|
||||
}
|
||||
router.push('/home')
|
||||
}
|
||||
|
||||
onMounted(() => {
|
||||
timer = window.setInterval(() => {
|
||||
if (countdown.value > 0) {
|
||||
countdown.value--
|
||||
} else {
|
||||
if (timer) {
|
||||
clearInterval(timer)
|
||||
}
|
||||
redirectToHome()
|
||||
}
|
||||
}, 1000)
|
||||
})
|
||||
|
||||
onUnmounted(() => {
|
||||
if (timer) {
|
||||
clearInterval(timer)
|
||||
}
|
||||
})
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
.not-found-container {
|
||||
min-height: 100vh;
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
|
||||
padding: 20px;
|
||||
}
|
||||
|
||||
.not-found-content {
|
||||
background: white;
|
||||
border-radius: 20px;
|
||||
padding: 60px 40px;
|
||||
text-align: center;
|
||||
box-shadow: 0 10px 30px rgba(0, 0, 0, 0.2);
|
||||
max-width: 500px;
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.error-code {
|
||||
font-size: 120px;
|
||||
font-weight: bold;
|
||||
color: #667eea;
|
||||
margin: 0 0 20px 0;
|
||||
line-height: 1;
|
||||
}
|
||||
|
||||
.not-found-content h1 {
|
||||
font-size: 28px;
|
||||
font-weight: 700;
|
||||
color: #333;
|
||||
margin: 0 0 16px 0;
|
||||
}
|
||||
|
||||
.not-found-content p {
|
||||
font-size: 16px;
|
||||
color: #666;
|
||||
margin: 0 0 24px 0;
|
||||
line-height: 1.6;
|
||||
}
|
||||
|
||||
.redirect-message {
|
||||
margin: 20px 0 30px 0;
|
||||
color: #999;
|
||||
font-size: 14px;
|
||||
}
|
||||
|
||||
.countdown {
|
||||
color: #667eea;
|
||||
font-weight: bold;
|
||||
font-size: 18px;
|
||||
margin: 0 4px;
|
||||
}
|
||||
|
||||
:deep(.ant-btn-primary) {
|
||||
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
|
||||
border: none;
|
||||
padding: 12px 32px;
|
||||
font-size: 16px;
|
||||
font-weight: 600;
|
||||
border-radius: 25px;
|
||||
box-shadow: 0 4px 15px rgba(102, 126, 234, 0.3);
|
||||
transition: all 0.3s ease;
|
||||
}
|
||||
|
||||
:deep(.ant-btn-primary:hover) {
|
||||
transform: translateY(-2px);
|
||||
box-shadow: 0 6px 20px rgba(102, 126, 234, 0.4);
|
||||
}
|
||||
|
||||
@media (max-width: 768px) {
|
||||
.not-found-content {
|
||||
padding: 40px 20px;
|
||||
}
|
||||
|
||||
.error-code {
|
||||
font-size: 80px;
|
||||
}
|
||||
|
||||
.not-found-content h1 {
|
||||
font-size: 24px;
|
||||
}
|
||||
|
||||
.not-found-content p {
|
||||
font-size: 14px;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
@@ -0,0 +1,333 @@
|
||||
<template>
|
||||
<div class="mobile-container">
|
||||
<!-- 头部区域 -->
|
||||
<header class="header">
|
||||
<a-button class="back-btn" type="text" @click="handleBackClick">
|
||||
<LeftOutlined :style="{ fontSize: '20px' }" />
|
||||
</a-button>
|
||||
<h1>我的订单</h1>
|
||||
<div class="placeholder"></div>
|
||||
</header>
|
||||
|
||||
<!-- 订单列表 -->
|
||||
<div class="order-section">
|
||||
<a-empty v-if="orders.length === 0" description="暂无订单">
|
||||
<a-button type="primary" @click="handleBrowseProducts">去购物</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>
|
||||
</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>
|
||||
</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>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { ref, onMounted } 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'
|
||||
|
||||
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 data = await orderApi.getOrderList()
|
||||
orders.value = data
|
||||
|
||||
// 加载商品图片的临时加签链接
|
||||
await loadProductImages(orders.value)
|
||||
} catch (error) {
|
||||
message.error('获取订单列表失败')
|
||||
} finally {
|
||||
loading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
// 加载商品图片
|
||||
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) {
|
||||
// 过滤掉HTML标签
|
||||
const cleanImageUrl = item.productImage.replace(/<[^>]*>/g, '')
|
||||
|
||||
// 从cleanImageUrl中提取图片ID
|
||||
// 假设图片URL的格式为 '/api/file/get/123'
|
||||
const match = cleanImageUrl.match(/\/api\/file\/get\/(\d+)/)
|
||||
if (match && match[1]) {
|
||||
const imageId = match[1]
|
||||
try {
|
||||
// 检查缓存
|
||||
if (!imageIdCache.value[imageId]) {
|
||||
const signedUrl = await fileApi.getSignedUrl(Number(imageId))
|
||||
imageIdCache.value[imageId] = signedUrl
|
||||
}
|
||||
// 更新商品图片为临时加签链接
|
||||
item.productImage = imageIdCache.value[imageId]
|
||||
} catch (error) {
|
||||
console.error('获取图片签名链接失败:', error)
|
||||
// 如果获取签名链接失败,清除无效的图片URL
|
||||
item.productImage = ''
|
||||
}
|
||||
} else {
|
||||
// 如果不是有效的图片URL格式,清除无效的图片URL
|
||||
item.productImage = ''
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 处理取消订单
|
||||
const handleCancelOrder = async (orderId: number) => {
|
||||
Modal.confirm({
|
||||
title: '确认取消订单',
|
||||
content: '确定要取消这个订单吗?',
|
||||
onOk: async () => {
|
||||
try {
|
||||
await orderApi.cancelOrder(orderId)
|
||||
message.success('订单已取消')
|
||||
loadOrders()
|
||||
} catch (error) {
|
||||
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()
|
||||
})
|
||||
</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;
|
||||
}
|
||||
|
||||
.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>
|
||||
@@ -42,11 +42,11 @@
|
||||
<a-card :bordered="false" class="stats-card">
|
||||
<a-row :gutter="16">
|
||||
<a-col :span="8">
|
||||
<div class="stat-item">
|
||||
<div class="stat-item" @click="router.push('/orders')" style="cursor: pointer;">
|
||||
<div class="stat-icon" style="background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);">
|
||||
<ShoppingOutlined />
|
||||
</div>
|
||||
<a-statistic title="订单" :value="12" />
|
||||
<a-statistic title="订单" :value="orderCount" />
|
||||
</div>
|
||||
</a-col>
|
||||
<a-col :span="8">
|
||||
@@ -251,6 +251,7 @@ const activeTab = ref('')
|
||||
const orders = ref<any[]>([])
|
||||
const coupons = ref<any[]>([])
|
||||
const loading = ref(false)
|
||||
const orderCount = ref(0)
|
||||
|
||||
const editForm = ref({
|
||||
nickname: '',
|
||||
@@ -396,6 +397,7 @@ const loadOrders = async () => {
|
||||
try {
|
||||
const data = await orderApi.getOrderList()
|
||||
orders.value = data
|
||||
orderCount.value = data.length
|
||||
} catch (error) {
|
||||
message.error('获取订单列表失败')
|
||||
} finally {
|
||||
@@ -497,6 +499,7 @@ const getRandomColor = () => {
|
||||
|
||||
onMounted(() => {
|
||||
fetchUserInfo()
|
||||
loadOrders()
|
||||
})
|
||||
</script>
|
||||
|
||||
|
||||
@@ -308,8 +308,9 @@ const fetchCoupons = async () => {
|
||||
loading.value = true
|
||||
try {
|
||||
const res = await adminCouponApi.listAllCoupons()
|
||||
couponList.value = res || []
|
||||
pagination.total = res.length || 0
|
||||
// 处理后端返回的分页数据结构
|
||||
couponList.value = res?.list || []
|
||||
pagination.total = res?.total || 0
|
||||
} catch (error) {
|
||||
message.error('获取优惠券列表失败')
|
||||
} finally {
|
||||
|
||||
@@ -0,0 +1,149 @@
|
||||
<template>
|
||||
<div class="orders-view">
|
||||
<h1>订单管理</h1>
|
||||
<div class="orders-table">
|
||||
<table>
|
||||
<thead>
|
||||
<tr>
|
||||
<th>订单编号</th>
|
||||
<th>用户ID</th>
|
||||
<th>总金额</th>
|
||||
<th>实际金额</th>
|
||||
<th>优惠券</th>
|
||||
<th>状态</th>
|
||||
<th>创建时间</th>
|
||||
<th>操作</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr v-for="order in orders" :key="order.id">
|
||||
<td>{{ order.orderNo }}</td>
|
||||
<td>{{ order.userId }}</td>
|
||||
<td>{{ order.totalAmount }}</td>
|
||||
<td>{{ order.actualAmount }}</td>
|
||||
<td>{{ order.couponName || '无' }}</td>
|
||||
<td>{{ order.statusText }}</td>
|
||||
<td>{{ order.createTime }}</td>
|
||||
<td>
|
||||
<div class="order-actions">
|
||||
<button v-if="order.status === 1" @click="processOrder(order.id, 2)" class="btn btn-success">
|
||||
确认完成
|
||||
</button>
|
||||
<button v-if="order.status === 1" @click="processOrder(order.id, 3)" class="btn btn-danger">
|
||||
取消订单
|
||||
</button>
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { ref, onMounted } from 'vue'
|
||||
import { orderApi } from '../../api/order'
|
||||
import { message } from 'ant-design-vue'
|
||||
|
||||
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 loadOrders = async () => {
|
||||
try {
|
||||
const data = await orderApi.getAllOrders()
|
||||
orders.value = data
|
||||
} catch (error) {
|
||||
message.error('获取订单列表失败')
|
||||
}
|
||||
}
|
||||
|
||||
const processOrder = async (orderId: number, status: number) => {
|
||||
try {
|
||||
await orderApi.processOrder(orderId, status)
|
||||
message.success('操作成功')
|
||||
loadOrders()
|
||||
} catch (error) {
|
||||
message.error('操作失败')
|
||||
}
|
||||
}
|
||||
|
||||
onMounted(() => {
|
||||
loadOrders()
|
||||
})
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
.orders-view {
|
||||
padding: 20px;
|
||||
}
|
||||
|
||||
h1 {
|
||||
margin-bottom: 20px;
|
||||
font-size: 24px;
|
||||
color: #333;
|
||||
}
|
||||
|
||||
.orders-table {
|
||||
overflow-x: auto;
|
||||
}
|
||||
|
||||
table {
|
||||
width: 100%;
|
||||
border-collapse: collapse;
|
||||
background: white;
|
||||
border-radius: 8px;
|
||||
box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
|
||||
}
|
||||
|
||||
th, td {
|
||||
padding: 12px;
|
||||
text-align: left;
|
||||
border-bottom: 1px solid #e8e8e8;
|
||||
}
|
||||
|
||||
th {
|
||||
background-color: #f5f5f5;
|
||||
font-weight: 600;
|
||||
}
|
||||
|
||||
.order-actions {
|
||||
display: flex;
|
||||
gap: 8px;
|
||||
}
|
||||
|
||||
.btn {
|
||||
padding: 6px 12px;
|
||||
border: none;
|
||||
border-radius: 4px;
|
||||
cursor: pointer;
|
||||
font-size: 14px;
|
||||
}
|
||||
|
||||
.btn-success {
|
||||
background-color: #52c41a;
|
||||
color: white;
|
||||
}
|
||||
|
||||
.btn-danger {
|
||||
background-color: #ff4d4f;
|
||||
color: white;
|
||||
}
|
||||
|
||||
.btn:hover {
|
||||
opacity: 0.8;
|
||||
}
|
||||
</style>
|
||||
@@ -217,6 +217,7 @@
|
||||
placeholder="请选择优惠券"
|
||||
style="width: 100%"
|
||||
:loading="loadingCoupons"
|
||||
:disabled="!isShopOwner()"
|
||||
>
|
||||
<a-select-option
|
||||
v-if="coupons.length === 0"
|
||||
@@ -331,6 +332,11 @@ const getCurrentUserInfo = () => {
|
||||
return null
|
||||
}
|
||||
|
||||
const isShopOwner = () => {
|
||||
const userInfo = getCurrentUserInfo()
|
||||
return userInfo && userInfo.type === 2
|
||||
}
|
||||
|
||||
const fetchShops = async () => {
|
||||
loadingShops.value = true
|
||||
try {
|
||||
@@ -397,7 +403,8 @@ const fetchCoupons = async () => {
|
||||
loadingCoupons.value = true
|
||||
try {
|
||||
const res = await adminCouponApi.listAllCoupons()
|
||||
coupons.value = res || []
|
||||
// 处理后端返回的分页数据结构
|
||||
coupons.value = res?.list || []
|
||||
} catch (error) {
|
||||
console.error('获取优惠券列表失败', error)
|
||||
message.error('获取优惠券列表失败')
|
||||
|
||||
+93
@@ -0,0 +1,93 @@
|
||||
package com.xiaowang.yuminailcore.controller;
|
||||
|
||||
import com.xiaowang.yuminailcore.annotation.RequirePermission;
|
||||
import com.xiaowang.yuminailcore.common.Result;
|
||||
import com.xiaowang.yuminailcore.dto.CouponDTO;
|
||||
import com.xiaowang.yuminailcore.service.CouponService;
|
||||
import com.xiaowang.yuminailcore.vo.CouponVO;
|
||||
import com.xiaowang.yuminailcore.vo.PageResultVO;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 后台优惠券管理控制器
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("/admin/coupon")
|
||||
@RequiredArgsConstructor
|
||||
public class AdminCouponController {
|
||||
|
||||
private final CouponService couponService;
|
||||
|
||||
/**
|
||||
* 创建优惠券
|
||||
*/
|
||||
@PostMapping("/create")
|
||||
@RequirePermission("coupon:create")
|
||||
public Result<Long> createCoupon(@RequestBody CouponDTO couponDTO, @RequestParam(required = false) Long shopId) {
|
||||
Long couponId = couponService.createCoupon(couponDTO, shopId);
|
||||
return Result.success(couponId);
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新优惠券
|
||||
*/
|
||||
@PutMapping("/update/{id}")
|
||||
@RequirePermission("coupon:edit")
|
||||
public Result<Boolean> updateCoupon(@PathVariable Long id, @RequestBody CouponDTO couponDTO, @RequestParam(required = false) Long shopId) {
|
||||
boolean success = couponService.updateCoupon(id, couponDTO, shopId);
|
||||
return Result.success(success);
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除优惠券
|
||||
*/
|
||||
@DeleteMapping("/delete/{id}")
|
||||
@RequirePermission("coupon:delete")
|
||||
public Result<Boolean> deleteCoupon(@PathVariable Long id, @RequestParam(required = false) Long shopId) {
|
||||
boolean success = couponService.deleteCoupon(id, shopId);
|
||||
return Result.success(success);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取优惠券详情
|
||||
*/
|
||||
@GetMapping("/detail/{id}")
|
||||
@RequirePermission("coupon:view")
|
||||
public Result<CouponVO> getCouponById(@PathVariable Long id) {
|
||||
CouponVO couponVO = couponService.getCouponById(id);
|
||||
return Result.success(couponVO);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取优惠券列表
|
||||
*/
|
||||
@GetMapping("/list")
|
||||
@RequirePermission("coupon:view")
|
||||
public Result<PageResultVO<CouponVO>> listCoupons(@RequestParam Integer page, @RequestParam Integer size, @RequestParam(required = false) Long shopId) {
|
||||
PageResultVO<CouponVO> pageResult = couponService.listCoupons(page, size, shopId);
|
||||
return Result.success(pageResult);
|
||||
}
|
||||
|
||||
/**
|
||||
* 为用户分配优惠券
|
||||
*/
|
||||
@PostMapping("/assign")
|
||||
@RequirePermission("coupon:assign")
|
||||
public Result<Boolean> assignCouponToUser(@RequestParam Long userId, @RequestParam Long couponId, @RequestParam(required = false) Long shopId) {
|
||||
boolean success = couponService.assignCouponToUser(userId, couponId, shopId);
|
||||
return Result.success(success);
|
||||
}
|
||||
|
||||
/**
|
||||
* 发放优惠券
|
||||
*/
|
||||
@PostMapping("/distribute")
|
||||
@RequirePermission("coupon:assign")
|
||||
public Result<Boolean> distributeCoupon(@RequestParam Long couponId, @RequestParam List<Long> userIds, @RequestParam Integer quantity, @RequestParam(required = false) Long shopId) {
|
||||
boolean success = couponService.distributeCoupon(couponId, userIds, quantity, shopId);
|
||||
return Result.success(success);
|
||||
}
|
||||
}
|
||||
+82
@@ -0,0 +1,82 @@
|
||||
package com.xiaowang.yuminailcore.controller;
|
||||
|
||||
import com.xiaowang.yuminailcore.annotation.RequirePermission;
|
||||
import com.xiaowang.yuminailcore.common.Result;
|
||||
import com.xiaowang.yuminailcore.dto.TagDTO;
|
||||
import com.xiaowang.yuminailcore.service.TagService;
|
||||
import com.xiaowang.yuminailcore.vo.TagVO;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 后台标签管理控制器
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("/admin/tag")
|
||||
@RequiredArgsConstructor
|
||||
public class AdminTagController {
|
||||
|
||||
private final TagService tagService;
|
||||
|
||||
/**
|
||||
* 创建标签
|
||||
*/
|
||||
@PostMapping("/create")
|
||||
@RequirePermission("tag:create")
|
||||
public Result<Long> createTag(@RequestBody TagDTO tagDTO) {
|
||||
Long id = tagService.createTag(tagDTO);
|
||||
return Result.success(id);
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新标签
|
||||
*/
|
||||
@PutMapping("/update/{id}")
|
||||
@RequirePermission("tag:edit")
|
||||
public Result<Boolean> updateTag(@PathVariable Long id, @RequestBody TagDTO tagDTO) {
|
||||
boolean success = tagService.updateTag(id, tagDTO);
|
||||
return Result.success(success);
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除标签
|
||||
*/
|
||||
@DeleteMapping("/delete/{id}")
|
||||
@RequirePermission("tag:delete")
|
||||
public Result<Boolean> deleteTag(@PathVariable Long id) {
|
||||
boolean success = tagService.deleteTag(id);
|
||||
return Result.success(success);
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据ID查询标签
|
||||
*/
|
||||
@GetMapping("/get/{id}")
|
||||
@RequirePermission("tag:view")
|
||||
public Result<TagVO> getTagById(@PathVariable Long id) {
|
||||
TagVO tagVO = tagService.getTagById(id);
|
||||
return Result.success(tagVO);
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询所有标签
|
||||
*/
|
||||
@GetMapping("/list/all")
|
||||
@RequirePermission("tag:view")
|
||||
public Result<List<TagVO>> listAllTags() {
|
||||
List<TagVO> tagVOs = tagService.listAllTags();
|
||||
return Result.success(tagVOs);
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据店铺ID查询标签
|
||||
*/
|
||||
@GetMapping("/list/by-shop/{shopId}")
|
||||
@RequirePermission("tag:view")
|
||||
public Result<List<TagVO>> listTagsByShopId(@PathVariable Long shopId) {
|
||||
List<TagVO> tagVOs = tagService.listTagsByShopId(shopId);
|
||||
return Result.success(tagVOs);
|
||||
}
|
||||
}
|
||||
+7
@@ -68,6 +68,13 @@ public class AdminUserController {
|
||||
return Result.success(success);
|
||||
}
|
||||
|
||||
@GetMapping("/info")
|
||||
public Result<UserVO> getUserInfo(HttpServletRequest request) {
|
||||
Long userId = (Long) request.getAttribute("userId");
|
||||
UserVO userVO = userService.getUserById(userId);
|
||||
return Result.success(userVO);
|
||||
}
|
||||
|
||||
@Data
|
||||
public static class StatusRequest {
|
||||
private Integer status;
|
||||
|
||||
@@ -0,0 +1,54 @@
|
||||
package com.xiaowang.yuminailcore.controller;
|
||||
|
||||
import com.xiaowang.yuminailcore.common.Result;
|
||||
import com.xiaowang.yuminailcore.dto.CartDTO;
|
||||
import com.xiaowang.yuminailcore.service.CartService;
|
||||
import com.xiaowang.yuminailcore.vo.CartVO;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import java.util.List;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/cart")
|
||||
public class CartController {
|
||||
|
||||
@Resource
|
||||
private CartService cartService;
|
||||
|
||||
@PostMapping("/add")
|
||||
public Result<Void> addToCart(@RequestBody CartDTO cartDTO, HttpServletRequest request) {
|
||||
Long userId = (Long) request.getAttribute("userId");
|
||||
cartService.addToCart(userId, cartDTO);
|
||||
return Result.success();
|
||||
}
|
||||
|
||||
@DeleteMapping("/remove/{productId}")
|
||||
public Result<Void> removeFromCart(@PathVariable Long productId, HttpServletRequest request) {
|
||||
Long userId = (Long) request.getAttribute("userId");
|
||||
cartService.removeFromCart(userId, productId);
|
||||
return Result.success();
|
||||
}
|
||||
|
||||
@PutMapping("/update")
|
||||
public Result<Void> updateCartQuantity(@RequestBody CartDTO cartDTO, HttpServletRequest request) {
|
||||
Long userId = (Long) request.getAttribute("userId");
|
||||
cartService.updateCartQuantity(userId, cartDTO);
|
||||
return Result.success();
|
||||
}
|
||||
|
||||
@GetMapping("/list")
|
||||
public Result<List<CartVO>> getCartList(HttpServletRequest request) {
|
||||
Long userId = (Long) request.getAttribute("userId");
|
||||
List<CartVO> cartList = cartService.getCartList(userId);
|
||||
return Result.success(cartList);
|
||||
}
|
||||
|
||||
@DeleteMapping("/clear")
|
||||
public Result<Void> clearCart(HttpServletRequest request) {
|
||||
Long userId = (Long) request.getAttribute("userId");
|
||||
cartService.clearCart(userId);
|
||||
return Result.success();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,62 @@
|
||||
package com.xiaowang.yuminailcore.controller;
|
||||
|
||||
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.vo.OrderVO;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import java.util.List;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/order")
|
||||
public class OrderController {
|
||||
|
||||
@Resource
|
||||
private OrderService orderService;
|
||||
|
||||
@PostMapping("/create")
|
||||
public Result<OrderVO> createOrder(@RequestBody OrderDTO orderDTO, HttpServletRequest request) {
|
||||
Long userId = (Long) request.getAttribute("userId");
|
||||
OrderVO orderVO = orderService.createOrder(userId, orderDTO);
|
||||
return Result.success(orderVO);
|
||||
}
|
||||
|
||||
@GetMapping("/list")
|
||||
public Result<List<OrderVO>> getOrderList(HttpServletRequest request) {
|
||||
Long userId = (Long) request.getAttribute("userId");
|
||||
List<OrderVO> orderList = orderService.getOrderList(userId);
|
||||
return Result.success(orderList);
|
||||
}
|
||||
|
||||
@GetMapping("/detail/{orderId}")
|
||||
public Result<OrderVO> getOrderDetail(@PathVariable Long orderId) {
|
||||
OrderVO orderVO = orderService.getOrderDetail(orderId);
|
||||
return Result.success(orderVO);
|
||||
}
|
||||
|
||||
@PutMapping("/cancel/{orderId}")
|
||||
public Result<Void> cancelOrder(@PathVariable Long orderId, HttpServletRequest request) {
|
||||
Long userId = (Long) request.getAttribute("userId");
|
||||
orderService.cancelOrder(orderId, userId);
|
||||
return Result.success();
|
||||
}
|
||||
|
||||
// 后台管理接口
|
||||
@RequirePermission("order:view")
|
||||
@GetMapping("/admin/list")
|
||||
public Result<List<OrderVO>> getAllOrders() {
|
||||
List<OrderVO> orderList = orderService.getAllOrders();
|
||||
return Result.success(orderList);
|
||||
}
|
||||
|
||||
@RequirePermission("order:process")
|
||||
@PutMapping("/admin/process/{orderId}")
|
||||
public Result<Void> processOrder(@PathVariable Long orderId, @RequestParam Integer status) {
|
||||
orderService.processOrder(orderId, status);
|
||||
return Result.success();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
package com.xiaowang.yuminailcore.dto;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class CartDTO {
|
||||
private Long productId;
|
||||
private Integer quantity;
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
package com.xiaowang.yuminailcore.dto;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class OrderDTO {
|
||||
private Long couponId;
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
package com.xiaowang.yuminailcore.entity;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import lombok.Data;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
@Data
|
||||
@TableName("t_cart")
|
||||
public class CartDO extends BaseEntity {
|
||||
private Long userId;
|
||||
private Long productId;
|
||||
private Integer quantity;
|
||||
private LocalDateTime createTime;
|
||||
private LocalDateTime updateTime;
|
||||
private Integer isDelete;
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
package com.xiaowang.yuminailcore.entity;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import lombok.Data;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
@Data
|
||||
@TableName("t_order")
|
||||
public class OrderDO extends BaseEntity {
|
||||
private String orderNo;
|
||||
private Long userId;
|
||||
private BigDecimal totalAmount;
|
||||
private BigDecimal actualAmount;
|
||||
private Long couponId;
|
||||
private Integer status;
|
||||
private LocalDateTime createTime;
|
||||
private LocalDateTime updateTime;
|
||||
private Integer isDelete;
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
package com.xiaowang.yuminailcore.entity;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import lombok.Data;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
@Data
|
||||
@TableName("t_order_item")
|
||||
public class OrderItemDO extends BaseEntity {
|
||||
private Long orderId;
|
||||
private Long productId;
|
||||
private Integer quantity;
|
||||
private BigDecimal price;
|
||||
private LocalDateTime createTime;
|
||||
private LocalDateTime updateTime;
|
||||
private Integer isDelete;
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
package com.xiaowang.yuminailcore.mapper;
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.xiaowang.yuminailcore.entity.CartDO;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
import org.apache.ibatis.annotations.Select;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Mapper
|
||||
public interface CartMapper extends BaseMapper<CartDO> {
|
||||
@Select("SELECT * FROM t_cart WHERE user_id = #{userId}")
|
||||
List<CartDO> selectByUserId(@Param("userId") Long userId);
|
||||
|
||||
@Select("SELECT * FROM t_cart WHERE user_id = #{userId} AND product_id = #{productId}")
|
||||
CartDO selectByUserIdAndProductId(@Param("userId") Long userId, @Param("productId") Long productId);
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
package com.xiaowang.yuminailcore.mapper;
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.xiaowang.yuminailcore.entity.OrderItemDO;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
import org.apache.ibatis.annotations.Select;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Mapper
|
||||
public interface OrderItemMapper extends BaseMapper<OrderItemDO> {
|
||||
@Select("SELECT * FROM t_order_item WHERE order_id = #{orderId}")
|
||||
List<OrderItemDO> selectByOrderId(@Param("orderId") Long orderId);
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
package com.xiaowang.yuminailcore.mapper;
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.xiaowang.yuminailcore.entity.OrderDO;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
import org.apache.ibatis.annotations.Select;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Mapper
|
||||
public interface OrderMapper extends BaseMapper<OrderDO> {
|
||||
@Select("SELECT * FROM t_order WHERE user_id = #{userId}")
|
||||
List<OrderDO> selectByUserId(@Param("userId") Long userId);
|
||||
|
||||
@Select("SELECT * FROM t_order WHERE order_no = #{orderNo}")
|
||||
OrderDO selectByOrderNo(@Param("orderNo") String orderNo);
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
package com.xiaowang.yuminailcore.service;
|
||||
|
||||
import com.xiaowang.yuminailcore.dto.CartDTO;
|
||||
import com.xiaowang.yuminailcore.vo.CartVO;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface CartService {
|
||||
void addToCart(Long userId, CartDTO cartDTO);
|
||||
void removeFromCart(Long userId, Long productId);
|
||||
void updateCartQuantity(Long userId, CartDTO cartDTO);
|
||||
List<CartVO> getCartList(Long userId);
|
||||
void clearCart(Long userId);
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
package com.xiaowang.yuminailcore.service;
|
||||
|
||||
import com.xiaowang.yuminailcore.dto.OrderDTO;
|
||||
import com.xiaowang.yuminailcore.vo.OrderVO;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface OrderService {
|
||||
OrderVO createOrder(Long userId, OrderDTO orderDTO);
|
||||
List<OrderVO> getOrderList(Long userId);
|
||||
OrderVO getOrderDetail(Long orderId);
|
||||
void cancelOrder(Long orderId, Long userId);
|
||||
void processOrder(Long orderId, Integer status);
|
||||
List<OrderVO> getAllOrders();
|
||||
}
|
||||
+112
@@ -0,0 +1,112 @@
|
||||
package com.xiaowang.yuminailcore.service.impl;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.xiaowang.yuminailcore.dto.CartDTO;
|
||||
import com.xiaowang.yuminailcore.entity.CartDO;
|
||||
import com.xiaowang.yuminailcore.entity.ProductDO;
|
||||
import com.xiaowang.yuminailcore.mapper.CartMapper;
|
||||
import com.xiaowang.yuminailcore.mapper.ProductMapper;
|
||||
import com.xiaowang.yuminailcore.service.CartService;
|
||||
import com.xiaowang.yuminailcore.vo.CartVO;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.math.BigDecimal;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@Service
|
||||
public class CartServiceImpl implements CartService {
|
||||
|
||||
@Resource
|
||||
private CartMapper cartMapper;
|
||||
|
||||
@Resource
|
||||
private ProductMapper productMapper;
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
public void addToCart(Long userId, CartDTO cartDTO) {
|
||||
// 检查商品是否存在
|
||||
ProductDO product = productMapper.selectById(cartDTO.getProductId());
|
||||
if (product == null || product.getIsDelete() == 1) {
|
||||
throw new RuntimeException("商品不存在");
|
||||
}
|
||||
|
||||
// 检查购物车中是否已有该商品
|
||||
CartDO existingCart = cartMapper.selectByUserIdAndProductId(userId, cartDTO.getProductId());
|
||||
if (existingCart != null) {
|
||||
// 更新数量
|
||||
existingCart.setQuantity(existingCart.getQuantity() + cartDTO.getQuantity());
|
||||
cartMapper.updateById(existingCart);
|
||||
} else {
|
||||
// 添加新商品到购物车
|
||||
CartDO newCart = new CartDO();
|
||||
newCart.setUserId(userId);
|
||||
newCart.setProductId(cartDTO.getProductId());
|
||||
newCart.setQuantity(cartDTO.getQuantity());
|
||||
newCart.setIsDelete(0);
|
||||
cartMapper.insert(newCart);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
public void removeFromCart(Long userId, Long productId) {
|
||||
QueryWrapper<CartDO> wrapper = new QueryWrapper<>();
|
||||
wrapper.eq("user_id", userId)
|
||||
.eq("product_id", productId)
|
||||
.eq("is_delete", 0);
|
||||
cartMapper.delete(wrapper);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
public void updateCartQuantity(Long userId, CartDTO cartDTO) {
|
||||
CartDO cart = cartMapper.selectByUserIdAndProductId(userId, cartDTO.getProductId());
|
||||
if (cart != null) {
|
||||
cart.setQuantity(cartDTO.getQuantity());
|
||||
cartMapper.updateById(cart);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<CartVO> getCartList(Long userId) {
|
||||
List<CartDO> cartList = cartMapper.selectByUserId(userId);
|
||||
List<CartVO> cartVOList = new ArrayList<>();
|
||||
|
||||
for (CartDO cart : cartList) {
|
||||
if (cart.getIsDelete() == 0) {
|
||||
ProductDO product = productMapper.selectById(cart.getProductId());
|
||||
if (product != null && product.getIsDelete() == 0) {
|
||||
CartVO cartVO = new CartVO();
|
||||
cartVO.setId(cart.getId());
|
||||
cartVO.setProductId(product.getId());
|
||||
cartVO.setProductTitle(product.getTitle());
|
||||
// 简单处理,取第一张图片
|
||||
String imageFileIds = product.getImageFileIds();
|
||||
if (imageFileIds != null && !imageFileIds.isEmpty()) {
|
||||
String firstImageId = imageFileIds.split(",")[0];
|
||||
cartVO.setProductImage("/api/file/get/" + firstImageId);
|
||||
}
|
||||
cartVO.setPrice(product.getPrice());
|
||||
cartVO.setQuantity(cart.getQuantity());
|
||||
cartVO.setTotalPrice(product.getPrice().multiply(new BigDecimal(cart.getQuantity())));
|
||||
cartVOList.add(cartVO);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return cartVOList;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
public void clearCart(Long userId) {
|
||||
QueryWrapper<CartDO> wrapper = new QueryWrapper<>();
|
||||
wrapper.eq("user_id", userId)
|
||||
.eq("is_delete", 0);
|
||||
cartMapper.delete(wrapper);
|
||||
}
|
||||
}
|
||||
+309
@@ -0,0 +1,309 @@
|
||||
package com.xiaowang.yuminailcore.service.impl;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.xiaowang.yuminailcore.dto.OrderDTO;
|
||||
import com.xiaowang.yuminailcore.entity.*;
|
||||
import com.xiaowang.yuminailcore.mapper.*;
|
||||
import com.xiaowang.yuminailcore.service.OrderService;
|
||||
import com.xiaowang.yuminailcore.vo.OrderItemVO;
|
||||
import com.xiaowang.yuminailcore.vo.OrderVO;
|
||||
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.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
@Service
|
||||
public class OrderServiceImpl implements OrderService {
|
||||
|
||||
@Resource
|
||||
private OrderMapper orderMapper;
|
||||
|
||||
@Resource
|
||||
private OrderItemMapper orderItemMapper;
|
||||
|
||||
@Resource
|
||||
private CartMapper cartMapper;
|
||||
|
||||
@Resource
|
||||
private ProductMapper productMapper;
|
||||
|
||||
@Resource
|
||||
private CouponMapper couponMapper;
|
||||
|
||||
@Resource
|
||||
private UserCouponMapper userCouponMapper;
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
public OrderVO createOrder(Long userId, OrderDTO orderDTO) {
|
||||
// 获取购物车商品
|
||||
List<CartDO> cartList = cartMapper.selectByUserId(userId);
|
||||
if (cartList.isEmpty()) {
|
||||
throw new RuntimeException("购物车为空");
|
||||
}
|
||||
|
||||
// 计算总金额
|
||||
BigDecimal totalAmount = BigDecimal.ZERO;
|
||||
List<OrderItemDO> orderItems = new ArrayList<>();
|
||||
|
||||
for (CartDO cart : cartList) {
|
||||
if (cart.getIsDelete() == 0) {
|
||||
ProductDO product = productMapper.selectById(cart.getProductId());
|
||||
if (product != null && product.getIsDelete() == 0) {
|
||||
BigDecimal itemTotal = product.getPrice().multiply(new BigDecimal(cart.getQuantity()));
|
||||
totalAmount = totalAmount.add(itemTotal);
|
||||
|
||||
// 创建订单商品
|
||||
OrderItemDO orderItem = new OrderItemDO();
|
||||
orderItem.setProductId(product.getId());
|
||||
orderItem.setQuantity(cart.getQuantity());
|
||||
orderItem.setPrice(product.getPrice());
|
||||
orderItems.add(orderItem);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (totalAmount.compareTo(BigDecimal.ZERO) == 0) {
|
||||
throw new RuntimeException("购物车商品无效");
|
||||
}
|
||||
|
||||
// 处理优惠券
|
||||
BigDecimal actualAmount = totalAmount;
|
||||
Long couponId = orderDTO.getCouponId();
|
||||
if (couponId != null && couponId > 0) {
|
||||
// 检查优惠券是否存在且可用
|
||||
UserCouponDO userCoupon = userCouponMapper.selectOne(
|
||||
new QueryWrapper<UserCouponDO>()
|
||||
.eq("user_id", userId)
|
||||
.eq("coupon_id", couponId)
|
||||
.eq("status", 1)
|
||||
);
|
||||
|
||||
if (userCoupon != null) {
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 更新优惠券状态
|
||||
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();
|
||||
|
||||
// 创建订单
|
||||
OrderDO order = new OrderDO();
|
||||
order.setOrderNo(orderNo);
|
||||
order.setUserId(userId);
|
||||
order.setTotalAmount(totalAmount);
|
||||
order.setActualAmount(actualAmount);
|
||||
order.setCouponId(couponId);
|
||||
order.setStatus(1); // 待使用
|
||||
order.setIsDelete(0);
|
||||
orderMapper.insert(order);
|
||||
|
||||
// 创建订单商品
|
||||
for (OrderItemDO item : orderItems) {
|
||||
item.setOrderId(order.getId());
|
||||
item.setIsDelete(0);
|
||||
orderItemMapper.insert(item);
|
||||
}
|
||||
|
||||
// 清空购物车
|
||||
cartMapper.delete(new QueryWrapper<CartDO>().eq("user_id", userId).eq("is_delete", 0));
|
||||
|
||||
// 构建返回对象
|
||||
return buildOrderVO(order);
|
||||
}
|
||||
|
||||
@Override
|
||||
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) {
|
||||
orderVOList.add(buildOrderVO(order));
|
||||
}
|
||||
}
|
||||
|
||||
return orderVOList;
|
||||
}
|
||||
|
||||
@Override
|
||||
public OrderVO getOrderDetail(Long orderId) {
|
||||
OrderDO order = orderMapper.selectById(orderId);
|
||||
if (order == null || order.getIsDelete() == 1) {
|
||||
throw new RuntimeException("订单不存在");
|
||||
}
|
||||
|
||||
return buildOrderVO(order);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
public void cancelOrder(Long orderId, Long userId) {
|
||||
OrderDO order = orderMapper.selectById(orderId);
|
||||
if (order == null || order.getIsDelete() == 1) {
|
||||
throw new RuntimeException("订单不存在");
|
||||
}
|
||||
|
||||
if (!order.getUserId().equals(userId)) {
|
||||
throw new RuntimeException("无权操作此订单");
|
||||
}
|
||||
|
||||
if (order.getStatus() != 1) { // 只有待使用状态可以取消
|
||||
throw new RuntimeException("订单状态不允许取消");
|
||||
}
|
||||
|
||||
// 更新订单状态
|
||||
order.setStatus(3); // 已取消
|
||||
orderMapper.updateById(order);
|
||||
|
||||
// 返还优惠券
|
||||
if (order.getCouponId() != null && order.getCouponId() > 0) {
|
||||
UserCouponDO userCoupon = userCouponMapper.selectOne(
|
||||
new QueryWrapper<UserCouponDO>()
|
||||
.eq("user_id", userId)
|
||||
.eq("coupon_id", order.getCouponId())
|
||||
.eq("status", 2)
|
||||
);
|
||||
|
||||
if (userCoupon != null) {
|
||||
userCoupon.setStatus(1); // 未使用
|
||||
userCoupon.setUseTime(null);
|
||||
userCouponMapper.updateById(userCoupon);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
public void processOrder(Long orderId, Integer status) {
|
||||
OrderDO order = orderMapper.selectById(orderId);
|
||||
if (order == null || order.getIsDelete() == 1) {
|
||||
throw new RuntimeException("订单不存在");
|
||||
}
|
||||
|
||||
if (status != 2 && status != 3) { // 只能设置为已完成或已取消
|
||||
throw new RuntimeException("无效的订单状态");
|
||||
}
|
||||
|
||||
if (order.getStatus() != 1) { // 只有待使用状态可以处理
|
||||
throw new RuntimeException("订单状态不允许处理");
|
||||
}
|
||||
|
||||
// 更新订单状态
|
||||
order.setStatus(status);
|
||||
orderMapper.updateById(order);
|
||||
|
||||
// 如果取消订单,返还优惠券
|
||||
if (status == 3 && order.getCouponId() != null && order.getCouponId() > 0) {
|
||||
UserCouponDO userCoupon = userCouponMapper.selectOne(
|
||||
new QueryWrapper<UserCouponDO>()
|
||||
.eq("user_id", order.getUserId())
|
||||
.eq("coupon_id", order.getCouponId())
|
||||
.eq("status", 2)
|
||||
);
|
||||
|
||||
if (userCoupon != null) {
|
||||
userCoupon.setStatus(1); // 未使用
|
||||
userCoupon.setUseTime(null);
|
||||
userCouponMapper.updateById(userCoupon);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@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;
|
||||
}
|
||||
|
||||
private OrderVO buildOrderVO(OrderDO order) {
|
||||
OrderVO orderVO = new OrderVO();
|
||||
orderVO.setId(order.getId());
|
||||
orderVO.setOrderNo(order.getOrderNo());
|
||||
orderVO.setTotalAmount(order.getTotalAmount());
|
||||
orderVO.setActualAmount(order.getActualAmount());
|
||||
orderVO.setCouponId(order.getCouponId());
|
||||
orderVO.setStatus(order.getStatus());
|
||||
|
||||
// 设置状态文本
|
||||
switch (order.getStatus()) {
|
||||
case 1:
|
||||
orderVO.setStatusText("待使用");
|
||||
break;
|
||||
case 2:
|
||||
orderVO.setStatusText("已完成");
|
||||
break;
|
||||
case 3:
|
||||
orderVO.setStatusText("已取消");
|
||||
break;
|
||||
}
|
||||
|
||||
// 设置优惠券名称
|
||||
if (order.getCouponId() != null && order.getCouponId() > 0) {
|
||||
CouponDO coupon = couponMapper.selectById(order.getCouponId());
|
||||
if (coupon != null) {
|
||||
orderVO.setCouponName(coupon.getCouponName());
|
||||
}
|
||||
}
|
||||
|
||||
orderVO.setCreateTime(order.getCreateTime());
|
||||
|
||||
// 设置订单商品
|
||||
List<OrderItemDO> orderItems = orderItemMapper.selectByOrderId(order.getId());
|
||||
List<OrderItemVO> orderItemVOs = new ArrayList<>();
|
||||
|
||||
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())));
|
||||
orderItemVOs.add(itemVO);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
orderVO.setItems(orderItemVOs);
|
||||
return orderVO;
|
||||
}
|
||||
}
|
||||
+6
@@ -198,6 +198,12 @@ public class PermissionServiceImpl extends ServiceImpl<PermissionMapper, Permiss
|
||||
|
||||
@Override
|
||||
public boolean hasPermission(Long userId, String permissionCode) {
|
||||
// 先检查用户是否为管理员,管理员拥有所有权限
|
||||
UserDO userDO = userMapper.selectById(userId);
|
||||
if (userDO != null && userDO.getType() == 4) {
|
||||
return true;
|
||||
}
|
||||
|
||||
List<UserPermissionDO> userPermissions = userPermissionMapper.selectList(
|
||||
Wrappers.lambdaQuery(UserPermissionDO.class)
|
||||
.eq(UserPermissionDO::getUserId, userId)
|
||||
|
||||
@@ -0,0 +1,16 @@
|
||||
package com.xiaowang.yuminailcore.vo;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
|
||||
@Data
|
||||
public class CartVO {
|
||||
private Long id;
|
||||
private Long productId;
|
||||
private String productTitle;
|
||||
private String productImage;
|
||||
private BigDecimal price;
|
||||
private Integer quantity;
|
||||
private BigDecimal totalPrice;
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
package com.xiaowang.yuminailcore.vo;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
|
||||
@Data
|
||||
public class OrderItemVO {
|
||||
private Long id;
|
||||
private Long productId;
|
||||
private String productTitle;
|
||||
private String productImage;
|
||||
private Integer quantity;
|
||||
private BigDecimal price;
|
||||
private BigDecimal totalPrice;
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
package com.xiaowang.yuminailcore.vo;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.List;
|
||||
|
||||
@Data
|
||||
public class OrderVO {
|
||||
private Long id;
|
||||
private String orderNo;
|
||||
private BigDecimal totalAmount;
|
||||
private BigDecimal actualAmount;
|
||||
private Long couponId;
|
||||
private String couponName;
|
||||
private Integer status;
|
||||
private String statusText;
|
||||
private LocalDateTime createTime;
|
||||
private List<OrderItemVO> items;
|
||||
}
|
||||
@@ -371,7 +371,13 @@ INSERT INTO t_permission (permission_code, permission_name, permission_group, de
|
||||
('permission:create', '新增权限', '权限管理', '新增系统权限', NOW(), NOW(), 0),
|
||||
('permission:edit', '编辑权限', '权限管理', '编辑系统权限', NOW(), NOW(), 0),
|
||||
('permission:delete', '删除权限', '权限管理', '删除系统权限', NOW(), NOW(), 0),
|
||||
('permission:assign', '分配权限', '权限管理', '为用户分配权限', NOW(), NOW(), 0);
|
||||
('permission:assign', '分配权限', '权限管理', '为用户分配权限', NOW(), NOW(), 0),
|
||||
|
||||
-- 标签管理权限
|
||||
('tag:view', '查看标签', '标签管理', '查看标签列表和详情', NOW(), NOW(), 0),
|
||||
('tag:create', '新增标签', '标签管理', '新增标签', NOW(), NOW(), 0),
|
||||
('tag:edit', '编辑标签', '标签管理', '编辑标签信息', NOW(), NOW(), 0),
|
||||
('tag:delete', '删除标签', '标签管理', '删除标签', NOW(), NOW(), 0);
|
||||
|
||||
|
||||
-- 为管理员(type=4)分配所有权限
|
||||
@@ -413,7 +419,11 @@ WHERE u.type = 2
|
||||
'shop:view',
|
||||
'shop:edit',
|
||||
'permission:view',
|
||||
'permission:assign'
|
||||
'permission:assign',
|
||||
'tag:view',
|
||||
'tag:create',
|
||||
'tag:edit',
|
||||
'tag:delete'
|
||||
);
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,101 @@
|
||||
-- 购物车表
|
||||
create table t_cart
|
||||
(
|
||||
id bigint unsigned auto_increment comment '购物车唯一主键ID'
|
||||
primary key comment '购物车主键索引',
|
||||
user_id bigint unsigned not null comment '关联用户表主键',
|
||||
product_id bigint unsigned not null comment '关联商品表主键',
|
||||
quantity int unsigned default 1 not null comment '商品数量',
|
||||
create_time datetime default CURRENT_TIMESTAMP not null comment '创建时间',
|
||||
update_time datetime default CURRENT_TIMESTAMP not null on update CURRENT_TIMESTAMP comment '更新时间',
|
||||
is_delete tinyint unsigned default 0 null comment '逻辑删除:0-未删,1-已删',
|
||||
constraint uk_user_product
|
||||
unique (user_id, product_id) comment '用户-商品唯一索引'
|
||||
) comment '购物车表';
|
||||
|
||||
create index idx_user_id
|
||||
on t_cart (user_id) comment '按用户查询购物车的索引';
|
||||
|
||||
-- 订单表
|
||||
create table t_order
|
||||
(
|
||||
id bigint unsigned auto_increment comment '订单唯一主键ID'
|
||||
primary key comment '订单主键索引',
|
||||
order_no varchar(50) not null comment '订单编号',
|
||||
user_id bigint unsigned not null comment '关联用户表主键',
|
||||
total_amount decimal(10, 2) not null comment '订单总金额',
|
||||
actual_amount decimal(10, 2) not null comment '实际支付金额',
|
||||
coupon_id bigint unsigned default 0 null comment '使用的优惠券ID',
|
||||
status tinyint unsigned default 1 not null comment '订单状态:1-待使用,2-已完成,3-已取消',
|
||||
create_time datetime default CURRENT_TIMESTAMP not null comment '创建时间',
|
||||
update_time datetime default CURRENT_TIMESTAMP not null on update CURRENT_TIMESTAMP comment '更新时间',
|
||||
is_delete tinyint unsigned default 0 null comment '逻辑删除:0-未删,1-已删',
|
||||
constraint uk_order_no
|
||||
unique (order_no) comment '订单编号唯一索引'
|
||||
) comment '订单表';
|
||||
|
||||
create index idx_status
|
||||
on t_order (status) comment '按状态查询订单的索引';
|
||||
|
||||
create index idx_user_id
|
||||
on t_order (user_id) comment '按用户查询订单的索引';
|
||||
|
||||
-- 订单商品表
|
||||
create table t_order_item
|
||||
(
|
||||
id bigint unsigned auto_increment comment '订单商品唯一主键ID'
|
||||
primary key comment '订单商品主键索引',
|
||||
order_id bigint unsigned not null comment '关联订单表主键',
|
||||
product_id bigint unsigned not null comment '关联商品表主键',
|
||||
quantity int unsigned not null comment '商品数量',
|
||||
price decimal(10, 2) not null comment '商品单价',
|
||||
create_time datetime default CURRENT_TIMESTAMP not null comment '创建时间',
|
||||
update_time datetime default CURRENT_TIMESTAMP not null on update CURRENT_TIMESTAMP comment '更新时间',
|
||||
is_delete tinyint unsigned default 0 null comment '逻辑删除:0-未删,1-已删'
|
||||
) comment '订单商品表';
|
||||
|
||||
create index idx_order_id
|
||||
on t_order_item (order_id) comment '按订单查询商品的索引';
|
||||
|
||||
-- 插入订单管理相关权限
|
||||
INSERT INTO t_permission (permission_code, permission_name, permission_group, description, create_time, update_time, is_delete) VALUES
|
||||
('order:view', '查看订单', '订单管理', '查看订单列表和详情', NOW(), NOW(), 0),
|
||||
('order:edit', '编辑订单', '订单管理', '编辑订单信息', NOW(), NOW(), 0),
|
||||
('order:delete', '删除订单', '订单管理', '删除订单', NOW(), NOW(), 0),
|
||||
('order:process', '处理订单', '订单管理', '处理订单状态', NOW(), NOW(), 0);
|
||||
|
||||
-- 为管理员(type=4)分配订单管理权限
|
||||
INSERT INTO t_user_permission (user_id, permission_id, create_time, update_time)
|
||||
SELECT
|
||||
u.id as user_id,
|
||||
p.id as permission_id,
|
||||
NOW() as create_time,
|
||||
NOW() as update_time
|
||||
FROM t_user u
|
||||
CROSS JOIN t_permission p
|
||||
WHERE u.type = 4
|
||||
AND p.is_delete = 0
|
||||
AND p.permission_code IN (
|
||||
'order:view',
|
||||
'order:edit',
|
||||
'order:delete',
|
||||
'order:process'
|
||||
);
|
||||
|
||||
-- 为店长(type=2)分配订单管理权限
|
||||
INSERT INTO t_user_permission (user_id, permission_id, create_time, update_time)
|
||||
SELECT
|
||||
u.id as user_id,
|
||||
p.id as permission_id,
|
||||
NOW() as create_time,
|
||||
NOW() as update_time
|
||||
FROM t_user u
|
||||
CROSS JOIN t_permission p
|
||||
WHERE u.type = 2
|
||||
AND p.is_delete = 0
|
||||
AND p.permission_code IN (
|
||||
'order:view',
|
||||
'order:edit',
|
||||
'order:delete',
|
||||
'order:process'
|
||||
);
|
||||
+1
@@ -76,6 +76,7 @@ public class AuthGlobalFilter implements GlobalFilter, Ordered {
|
||||
path.equals("/api/user/refresh-token") ||
|
||||
path.equals("/api/shop/list/simple") ||
|
||||
path.equals("/api/admin/auth/login") ||
|
||||
path.equals("/admin/api/auth/login") ||
|
||||
path.contains("/api/user/get/account");
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user