修复一些问题以及优惠券管理功能
This commit is contained in:
+28
-10
@@ -367,6 +367,15 @@ export const adminTagApi = {
|
|||||||
},
|
},
|
||||||
listTagsByShopId: (shopId: number) => {
|
listTagsByShopId: (shopId: number) => {
|
||||||
return adminApi.get<any[]>('/tag/list/by-shop/' + shopId)
|
return adminApi.get<any[]>('/tag/list/by-shop/' + shopId)
|
||||||
|
},
|
||||||
|
createTag: (data: any) => {
|
||||||
|
return adminApi.post('/tag/create', data)
|
||||||
|
},
|
||||||
|
updateTag: (id: number, data: any) => {
|
||||||
|
return adminApi.put(`/tag/update/${id}`, data)
|
||||||
|
},
|
||||||
|
deleteTag: (id: number) => {
|
||||||
|
return adminApi.delete(`/tag/delete/${id}`)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -377,20 +386,29 @@ export const adminArtistApi = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export const adminCouponApi = {
|
export const adminCouponApi = {
|
||||||
listAllCoupons: () => {
|
listAllCoupons: (shopId?: number) => {
|
||||||
return adminApi.get<any[]>('/coupon/list', { params: { page: 1, size: 100 } })
|
return adminApi.get<any[]>('/coupon/list', { params: { page: 1, size: 100, shopId } })
|
||||||
},
|
},
|
||||||
createCoupon: (data: any) => {
|
createCoupon: (data: any, shopId: number) => {
|
||||||
return adminApi.post('/coupon/create', data)
|
return adminApi.post('/coupon/create', data, { params: { shopId } })
|
||||||
},
|
},
|
||||||
updateCoupon: (id: number, data: any) => {
|
updateCoupon: (id: number, data: any, shopId: number) => {
|
||||||
return adminApi.put(`/coupon/update/${id}`, data)
|
return adminApi.put(`/coupon/update/${id}`, data, { params: { shopId } })
|
||||||
},
|
},
|
||||||
deleteCoupon: (id: number) => {
|
deleteCoupon: (id: number, shopId: number) => {
|
||||||
return adminApi.delete(`/coupon/delete/${id}`)
|
return adminApi.delete(`/coupon/delete/${id}`, { params: { shopId } })
|
||||||
},
|
},
|
||||||
distributeCoupon: (data: { couponId: number; userIds: number[]; quantity: number }) => {
|
distributeCoupon: (data: { couponId: number; userIds: number[]; quantity: number }, shopId: number) => {
|
||||||
return adminApi.post('/coupon/distribute', data)
|
const params: any = {
|
||||||
|
couponId: data.couponId,
|
||||||
|
quantity: data.quantity,
|
||||||
|
shopId: shopId
|
||||||
|
};
|
||||||
|
// 处理userIds数组,确保它能被后端正确解析
|
||||||
|
data.userIds.forEach((userId, index) => {
|
||||||
|
params[`userIds[${index}]`] = userId;
|
||||||
|
});
|
||||||
|
return adminApi.post('/coupon/distribute', null, { params })
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -45,7 +45,7 @@ export const authApi = {
|
|||||||
},
|
},
|
||||||
|
|
||||||
adminLogin: (data: LoginRequest) => {
|
adminLogin: (data: LoginRequest) => {
|
||||||
return api.post<LoginResponse>('/admin/api/auth/login', data)
|
return api.post<LoginResponse>('/admin/auth/login', data)
|
||||||
},
|
},
|
||||||
|
|
||||||
register: (data: RegisterRequest) => {
|
register: (data: RegisterRequest) => {
|
||||||
|
|||||||
@@ -53,13 +53,13 @@ const handleTokenExpired = () => {
|
|||||||
sessionStorage.removeItem('accessToken')
|
sessionStorage.removeItem('accessToken')
|
||||||
showError('登录已过期,请重新登录')
|
showError('登录已过期,请重新登录')
|
||||||
try {
|
try {
|
||||||
router.push('/auth').catch(err => {
|
router.push('/').catch(err => {
|
||||||
console.error('跳转到登录页失败:', err)
|
console.error('跳转到登录页失败:', err)
|
||||||
window.location.href = '/auth'
|
window.location.href = '/'
|
||||||
})
|
})
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.error('跳转到登录页异常:', err)
|
console.error('跳转到登录页异常:', err)
|
||||||
window.location.href = '/auth'
|
window.location.href = '/'
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Vendored
+52
@@ -11,8 +11,60 @@ export {}
|
|||||||
/* prettier-ignore */
|
/* prettier-ignore */
|
||||||
declare module 'vue' {
|
declare module 'vue' {
|
||||||
export interface GlobalComponents {
|
export interface GlobalComponents {
|
||||||
|
AAlert: typeof import('ant-design-vue/es')['Alert']
|
||||||
|
AAvatar: typeof import('ant-design-vue/es')['Avatar']
|
||||||
|
ABadge: typeof import('ant-design-vue/es')['Badge']
|
||||||
|
AButton: typeof import('ant-design-vue/es')['Button']
|
||||||
|
ACard: typeof import('ant-design-vue/es')['Card']
|
||||||
|
ACheckbox: typeof import('ant-design-vue/es')['Checkbox']
|
||||||
|
ACheckboxGroup: typeof import('ant-design-vue/es')['CheckboxGroup']
|
||||||
|
ACol: typeof import('ant-design-vue/es')['Col']
|
||||||
|
ACollapse: typeof import('ant-design-vue/es')['Collapse']
|
||||||
|
ACollapsePanel: typeof import('ant-design-vue/es')['CollapsePanel']
|
||||||
|
ADatePicker: typeof import('ant-design-vue/es')['DatePicker']
|
||||||
|
ADescriptions: typeof import('ant-design-vue/es')['Descriptions']
|
||||||
|
ADescriptionsItem: typeof import('ant-design-vue/es')['DescriptionsItem']
|
||||||
|
ADropdown: typeof import('ant-design-vue/es')['Dropdown']
|
||||||
|
AEmpty: typeof import('ant-design-vue/es')['Empty']
|
||||||
|
AForm: typeof import('ant-design-vue/es')['Form']
|
||||||
|
AFormItem: typeof import('ant-design-vue/es')['FormItem']
|
||||||
|
AGrid: typeof import('ant-design-vue/es')['Grid']
|
||||||
|
AImage: typeof import('ant-design-vue/es')['Image']
|
||||||
|
AInput: typeof import('ant-design-vue/es')['Input']
|
||||||
|
AInputNumber: typeof import('ant-design-vue/es')['InputNumber']
|
||||||
|
AInputPassword: typeof import('ant-design-vue/es')['InputPassword']
|
||||||
|
AInputSearch: typeof import('ant-design-vue/es')['InputSearch']
|
||||||
|
ALayout: typeof import('ant-design-vue/es')['Layout']
|
||||||
|
ALayoutContent: typeof import('ant-design-vue/es')['LayoutContent']
|
||||||
|
ALayoutHeader: typeof import('ant-design-vue/es')['LayoutHeader']
|
||||||
|
ALayoutSider: typeof import('ant-design-vue/es')['LayoutSider']
|
||||||
|
AList: typeof import('ant-design-vue/es')['List']
|
||||||
|
AListItem: typeof import('ant-design-vue/es')['ListItem']
|
||||||
|
AListItemMeta: typeof import('ant-design-vue/es')['ListItemMeta']
|
||||||
|
AMenu: typeof import('ant-design-vue/es')['Menu']
|
||||||
|
AMenuDivider: typeof import('ant-design-vue/es')['MenuDivider']
|
||||||
|
AMenuItem: typeof import('ant-design-vue/es')['MenuItem']
|
||||||
|
AModal: typeof import('ant-design-vue/es')['Modal']
|
||||||
|
APageHeader: typeof import('ant-design-vue/es')['PageHeader']
|
||||||
|
APopconfirm: typeof import('ant-design-vue/es')['Popconfirm']
|
||||||
|
ARow: typeof import('ant-design-vue/es')['Row']
|
||||||
|
ASelect: typeof import('ant-design-vue/es')['Select']
|
||||||
|
ASelectOption: typeof import('ant-design-vue/es')['SelectOption']
|
||||||
|
ASpace: typeof import('ant-design-vue/es')['Space']
|
||||||
|
ASpin: typeof import('ant-design-vue/es')['Spin']
|
||||||
|
AStatistic: typeof import('ant-design-vue/es')['Statistic']
|
||||||
|
ASwitch: typeof import('ant-design-vue/es')['Switch']
|
||||||
|
ATable: typeof import('ant-design-vue/es')['Table']
|
||||||
|
ATabPane: typeof import('ant-design-vue/es')['TabPane']
|
||||||
|
ATabs: typeof import('ant-design-vue/es')['Tabs']
|
||||||
|
ATag: typeof import('ant-design-vue/es')['Tag']
|
||||||
|
ATextarea: typeof import('ant-design-vue/es')['Textarea']
|
||||||
|
ATimeline: typeof import('ant-design-vue/es')['Timeline']
|
||||||
|
ATimelineItem: typeof import('ant-design-vue/es')['TimelineItem']
|
||||||
|
AUpload: typeof import('ant-design-vue/es')['Upload']
|
||||||
BottomNav: typeof import('./components/BottomNav.vue')['default']
|
BottomNav: typeof import('./components/BottomNav.vue')['default']
|
||||||
ElButton: typeof import('element-plus/es')['ElButton']
|
ElButton: typeof import('element-plus/es')['ElButton']
|
||||||
|
ElColorPicker: typeof import('element-plus/es')['ElColorPicker']
|
||||||
ElConfigProvider: typeof import('element-plus/es')['ElConfigProvider']
|
ElConfigProvider: typeof import('element-plus/es')['ElConfigProvider']
|
||||||
ElIcon: typeof import('element-plus/es')['ElIcon']
|
ElIcon: typeof import('element-plus/es')['ElIcon']
|
||||||
ElTag: typeof import('element-plus/es')['ElTag']
|
ElTag: typeof import('element-plus/es')['ElTag']
|
||||||
|
|||||||
@@ -121,6 +121,12 @@ const router = createRouter({
|
|||||||
name: 'admin-orders',
|
name: 'admin-orders',
|
||||||
component: () => import('../views/admin/OrdersView.vue'),
|
component: () => import('../views/admin/OrdersView.vue'),
|
||||||
meta: { requiresAuth: true, isAdmin: true, hideNav: true, permissionCode: 'order:view' }
|
meta: { requiresAuth: true, isAdmin: true, hideNav: true, permissionCode: 'order:view' }
|
||||||
|
},
|
||||||
|
{
|
||||||
|
path: 'tags',
|
||||||
|
name: 'admin-tags',
|
||||||
|
component: () => import('../views/admin/TagsView.vue'),
|
||||||
|
meta: { requiresAuth: true, isAdmin: true, hideNav: true, permissionCode: 'tag:view' }
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -235,20 +235,35 @@ const handleSubmit = async () => {
|
|||||||
loading.value = true
|
loading.value = true
|
||||||
try {
|
try {
|
||||||
if (activeTab.value === 'login') {
|
if (activeTab.value === 'login') {
|
||||||
|
console.log('开始登录...')
|
||||||
const response = await authApi.login({
|
const response = await authApi.login({
|
||||||
account: formData.account,
|
account: formData.account,
|
||||||
password: formData.password,
|
password: formData.password,
|
||||||
rememberMe: formData.rememberMe
|
rememberMe: formData.rememberMe
|
||||||
})
|
})
|
||||||
|
|
||||||
const loginData = response as any
|
console.log('登录响应:', response)
|
||||||
localStorage.setItem('accessToken', loginData.accessToken)
|
|
||||||
localStorage.setItem('refreshToken', loginData.refreshToken)
|
|
||||||
localStorage.setItem('userInfo', JSON.stringify(loginData.userInfo))
|
|
||||||
sessionStorage.setItem('accessToken', loginData.accessToken)
|
|
||||||
|
|
||||||
message.success('登录成功')
|
const loginData = response as any
|
||||||
router.push('/')
|
console.log('登录数据:', loginData)
|
||||||
|
|
||||||
|
if (loginData.accessToken && loginData.refreshToken) {
|
||||||
|
localStorage.setItem('accessToken', loginData.accessToken)
|
||||||
|
localStorage.setItem('refreshToken', loginData.refreshToken)
|
||||||
|
localStorage.setItem('userInfo', JSON.stringify(loginData.userInfo))
|
||||||
|
sessionStorage.setItem('accessToken', loginData.accessToken)
|
||||||
|
|
||||||
|
console.log('Token存储成功')
|
||||||
|
message.success('登录成功')
|
||||||
|
console.log('准备跳转到首页...')
|
||||||
|
router.push('/home').catch(err => {
|
||||||
|
console.error('跳转到首页失败:', err)
|
||||||
|
window.location.href = '/home'
|
||||||
|
})
|
||||||
|
} else {
|
||||||
|
console.error('登录响应缺少token:', loginData)
|
||||||
|
message.error('登录失败:响应数据异常')
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
await authApi.register({
|
await authApi.register({
|
||||||
account: formData.account,
|
account: formData.account,
|
||||||
@@ -261,6 +276,7 @@ const handleSubmit = async () => {
|
|||||||
activeTab.value = 'login'
|
activeTab.value = 'login'
|
||||||
}
|
}
|
||||||
} catch (error: any) {
|
} catch (error: any) {
|
||||||
|
console.error('登录失败:', error)
|
||||||
message.error(error.message || (activeTab.value === 'login' ? '登录失败' : '注册失败'))
|
message.error(error.message || (activeTab.value === 'login' ? '登录失败' : '注册失败'))
|
||||||
} finally {
|
} finally {
|
||||||
loading.value = false
|
loading.value = false
|
||||||
|
|||||||
@@ -76,6 +76,23 @@
|
|||||||
</a-card>
|
</a-card>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<!-- 优惠券选择 -->
|
||||||
|
<div class="coupon-section" v-if="cartItems.length > 0 && selectedCount > 0">
|
||||||
|
<a-card class="coupon-card">
|
||||||
|
<div class="coupon-header" @click="showCouponModal = true">
|
||||||
|
<span class="coupon-title">优惠券</span>
|
||||||
|
<div class="coupon-value">
|
||||||
|
{{ selectedCoupon ? '已选择: ' + selectedCoupon.couponName : '请选择' }}
|
||||||
|
<RightOutlined :style="{ marginLeft: '4px' }" />
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="coupon-discount" v-if="selectedCoupon">
|
||||||
|
<span class="discount-label">优惠金额</span>
|
||||||
|
<span class="discount-amount">-¥{{ discountAmount.toFixed(2) }}</span>
|
||||||
|
</div>
|
||||||
|
</a-card>
|
||||||
|
</div>
|
||||||
|
|
||||||
<!-- 订单摘要 -->
|
<!-- 订单摘要 -->
|
||||||
<div class="summary" v-if="cartItems.length > 0">
|
<div class="summary" v-if="cartItems.length > 0">
|
||||||
<div class="summary-row">
|
<div class="summary-row">
|
||||||
@@ -86,9 +103,13 @@
|
|||||||
<span>小计</span>
|
<span>小计</span>
|
||||||
<span>¥{{ subtotal.toFixed(2) }}</span>
|
<span>¥{{ subtotal.toFixed(2) }}</span>
|
||||||
</div>
|
</div>
|
||||||
|
<div class="summary-row" v-if="selectedCoupon">
|
||||||
|
<span>优惠</span>
|
||||||
|
<span class="discount">-¥{{ discountAmount.toFixed(2) }}</span>
|
||||||
|
</div>
|
||||||
<div class="summary-row total">
|
<div class="summary-row total">
|
||||||
<span>总计</span>
|
<span>总计</span>
|
||||||
<span class="total-price">¥{{ subtotal.toFixed(2) }}</span>
|
<span class="total-price">¥{{ totalAmount.toFixed(2) }}</span>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
@@ -100,23 +121,64 @@
|
|||||||
block
|
block
|
||||||
@click="handleCheckout"
|
@click="handleCheckout"
|
||||||
>
|
>
|
||||||
结算 ({{ selectedCount }})
|
结算 ({{ selectedCount }}) - ¥{{ totalAmount.toFixed(2) }}
|
||||||
</a-button>
|
</a-button>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<!-- 优惠券选择弹窗 -->
|
||||||
|
<a-modal
|
||||||
|
v-model:visible="showCouponModal"
|
||||||
|
title="选择优惠券"
|
||||||
|
width="90%"
|
||||||
|
>
|
||||||
|
<div class="coupon-modal-content">
|
||||||
|
<a-empty v-if="availableCoupons.length === 0" description="暂无可用优惠券" />
|
||||||
|
<div v-else class="coupon-list">
|
||||||
|
<a-card
|
||||||
|
v-for="coupon in availableCoupons"
|
||||||
|
:key="coupon.id"
|
||||||
|
class="modal-coupon-card"
|
||||||
|
:class="{ active: selectedCoupon && selectedCoupon.id === coupon.id }"
|
||||||
|
@click="selectCoupon(coupon)"
|
||||||
|
>
|
||||||
|
<div class="coupon-content">
|
||||||
|
<div class="coupon-value">
|
||||||
|
{{ coupon.couponType === 1 ? `${coupon.discountValue}折` : `¥${coupon.reduceAmount}` }}
|
||||||
|
</div>
|
||||||
|
<div class="coupon-info">
|
||||||
|
<div class="coupon-name">{{ coupon.couponName }}</div>
|
||||||
|
<div class="coupon-condition" v-if="coupon.couponType === 2">
|
||||||
|
满{{ coupon.minAmount }}元可用
|
||||||
|
</div>
|
||||||
|
<div class="coupon-time">
|
||||||
|
{{ coupon.startTime }} 至 {{ coupon.endTime }}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="coupon-select" v-if="selectedCoupon && selectedCoupon.id === coupon.id">
|
||||||
|
<CheckCircleOutlined />
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</a-card>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</a-modal>
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import { ref, computed, onMounted } from 'vue'
|
import { ref, computed, onMounted, watch } from 'vue'
|
||||||
import { useRouter } from 'vue-router'
|
import { useRouter } from 'vue-router'
|
||||||
import {
|
import {
|
||||||
LeftOutlined,
|
LeftOutlined,
|
||||||
DeleteOutlined
|
DeleteOutlined,
|
||||||
|
RightOutlined,
|
||||||
|
CheckCircleOutlined
|
||||||
} from '@ant-design/icons-vue'
|
} from '@ant-design/icons-vue'
|
||||||
import { message } from 'ant-design-vue'
|
import { message } from 'ant-design-vue'
|
||||||
import { cartApi } from '../api/cart'
|
import { cartApi } from '../api/cart'
|
||||||
import { orderApi } from '../api/order'
|
import { orderApi } from '../api/order'
|
||||||
import { fileApi } from '../api/index'
|
import { fileApi } from '../api/index'
|
||||||
|
import { couponApi, type UserCoupon } from '../api/coupon'
|
||||||
|
|
||||||
interface CartItem {
|
interface CartItem {
|
||||||
id: number
|
id: number
|
||||||
@@ -137,6 +199,11 @@ const cartItems = ref<CartItem[]>([])
|
|||||||
// 图片缓存
|
// 图片缓存
|
||||||
const imageIdCache = ref<Record<string, string>>({})
|
const imageIdCache = ref<Record<string, string>>({})
|
||||||
|
|
||||||
|
// 优惠券相关状态
|
||||||
|
const availableCoupons = ref<UserCoupon[]>([])
|
||||||
|
const selectedCoupon = ref<UserCoupon | null>(null)
|
||||||
|
const showCouponModal = ref(false)
|
||||||
|
|
||||||
// 加载购物车数据
|
// 加载购物车数据
|
||||||
const loadCartItems = async () => {
|
const loadCartItems = async () => {
|
||||||
try {
|
try {
|
||||||
@@ -148,6 +215,9 @@ const loadCartItems = async () => {
|
|||||||
|
|
||||||
// 加载商品图片的临时加签链接
|
// 加载商品图片的临时加签链接
|
||||||
await loadProductImages(cartItems.value)
|
await loadProductImages(cartItems.value)
|
||||||
|
|
||||||
|
// 加载可用优惠券
|
||||||
|
await loadAvailableCoupons()
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
message.error('获取购物车数据失败')
|
message.error('获取购物车数据失败')
|
||||||
}
|
}
|
||||||
@@ -186,6 +256,27 @@ const loadProductImages = async (items: CartItem[]) => {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 加载可用优惠券
|
||||||
|
const loadAvailableCoupons = async () => {
|
||||||
|
try {
|
||||||
|
// 计算商品总价
|
||||||
|
const totalPrice = subtotal.value
|
||||||
|
|
||||||
|
// 收集商品标签
|
||||||
|
const productTags = cartItems.value
|
||||||
|
.filter(item => item.selected)
|
||||||
|
.map(item => item.productTitle.split(' ')[0]) // 简单处理,取商品标题的第一个词作为标签
|
||||||
|
.join(',')
|
||||||
|
|
||||||
|
if (totalPrice > 0) {
|
||||||
|
const coupons = await couponApi.getAvailableCoupons(productTags, totalPrice)
|
||||||
|
availableCoupons.value = coupons
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
console.error('获取可用优惠券失败:', error)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// 计算选中的商品数量
|
// 计算选中的商品数量
|
||||||
const selectedCount = computed(() => {
|
const selectedCount = computed(() => {
|
||||||
return cartItems.value.filter(item => item.selected).length
|
return cartItems.value.filter(item => item.selected).length
|
||||||
@@ -203,6 +294,29 @@ const subtotal = computed(() => {
|
|||||||
.reduce((sum, item) => sum + item.totalPrice, 0)
|
.reduce((sum, item) => sum + item.totalPrice, 0)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
// 计算优惠金额
|
||||||
|
const discountAmount = computed(() => {
|
||||||
|
if (!selectedCoupon.value) return 0
|
||||||
|
|
||||||
|
const total = subtotal.value
|
||||||
|
const coupon = selectedCoupon.value
|
||||||
|
|
||||||
|
if (coupon.couponType === 1) {
|
||||||
|
// 折扣券
|
||||||
|
return total - (total * parseFloat(coupon.discountValue) / 10)
|
||||||
|
} else if (coupon.couponType === 2) {
|
||||||
|
// 满减券
|
||||||
|
return parseFloat(coupon.reduceAmount)
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0
|
||||||
|
})
|
||||||
|
|
||||||
|
// 计算总金额
|
||||||
|
const totalAmount = computed(() => {
|
||||||
|
return Math.max(0, subtotal.value - discountAmount.value)
|
||||||
|
})
|
||||||
|
|
||||||
// 生成随机颜色
|
// 生成随机颜色
|
||||||
const getRandomColor = () => {
|
const getRandomColor = () => {
|
||||||
const colors = ['#ffe4d6', '#d6eaff', '#e2ffd6', '#fff2d6', '#d6ffe4', '#e4d6ff']
|
const colors = ['#ffe4d6', '#d6eaff', '#e2ffd6', '#fff2d6', '#d6ffe4', '#e4d6ff']
|
||||||
@@ -220,8 +334,10 @@ const handleEditClick = () => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 处理选择状态变化
|
// 处理选择状态变化
|
||||||
const handleSelectChange = () => {
|
const handleSelectChange = async () => {
|
||||||
console.log('选择状态改变')
|
console.log('选择状态改变')
|
||||||
|
// 重新加载可用优惠券
|
||||||
|
await loadAvailableCoupons()
|
||||||
}
|
}
|
||||||
|
|
||||||
// 处理减少数量
|
// 处理减少数量
|
||||||
@@ -230,6 +346,8 @@ const handleDecreaseQuantity = async (item: CartItem) => {
|
|||||||
item.quantity--
|
item.quantity--
|
||||||
try {
|
try {
|
||||||
await cartApi.updateCartQuantity({ productId: item.productId, quantity: item.quantity })
|
await cartApi.updateCartQuantity({ productId: item.productId, quantity: item.quantity })
|
||||||
|
// 重新加载可用优惠券
|
||||||
|
await loadAvailableCoupons()
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
message.error('更新数量失败')
|
message.error('更新数量失败')
|
||||||
item.quantity++
|
item.quantity++
|
||||||
@@ -243,6 +361,8 @@ const handleIncreaseQuantity = async (item: CartItem) => {
|
|||||||
item.quantity++
|
item.quantity++
|
||||||
try {
|
try {
|
||||||
await cartApi.updateCartQuantity({ productId: item.productId, quantity: item.quantity })
|
await cartApi.updateCartQuantity({ productId: item.productId, quantity: item.quantity })
|
||||||
|
// 重新加载可用优惠券
|
||||||
|
await loadAvailableCoupons()
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
message.error('更新数量失败')
|
message.error('更新数量失败')
|
||||||
item.quantity--
|
item.quantity--
|
||||||
@@ -258,6 +378,8 @@ const handleDeleteItem = async (item: CartItem) => {
|
|||||||
if (index > -1) {
|
if (index > -1) {
|
||||||
cartItems.value.splice(index, 1)
|
cartItems.value.splice(index, 1)
|
||||||
message.success('商品已删除')
|
message.success('商品已删除')
|
||||||
|
// 重新加载可用优惠券
|
||||||
|
await loadAvailableCoupons()
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
message.error('删除商品失败')
|
message.error('删除商品失败')
|
||||||
@@ -269,6 +391,12 @@ const handleBrowseProducts = () => {
|
|||||||
router.push('/products')
|
router.push('/products')
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 选择优惠券
|
||||||
|
const selectCoupon = (coupon: UserCoupon) => {
|
||||||
|
selectedCoupon.value = coupon
|
||||||
|
showCouponModal.value = false
|
||||||
|
}
|
||||||
|
|
||||||
// 处理结算
|
// 处理结算
|
||||||
const handleCheckout = async () => {
|
const handleCheckout = async () => {
|
||||||
const selectedItems = cartItems.value.filter(item => item.selected)
|
const selectedItems = cartItems.value.filter(item => item.selected)
|
||||||
@@ -278,7 +406,9 @@ const handleCheckout = async () => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const order = await orderApi.createOrder({})
|
const order = await orderApi.createOrder({
|
||||||
|
couponId: selectedCoupon.value ? selectedCoupon.value.id : undefined
|
||||||
|
})
|
||||||
message.success('订单创建成功')
|
message.success('订单创建成功')
|
||||||
router.push('/profile')
|
router.push('/profile')
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
@@ -286,6 +416,15 @@ const handleCheckout = async () => {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 监听选中商品变化,重新加载可用优惠券
|
||||||
|
watch(
|
||||||
|
() => cartItems.value.map(item => ({ id: item.id, selected: item.selected, quantity: item.quantity })),
|
||||||
|
async () => {
|
||||||
|
await loadAvailableCoupons()
|
||||||
|
},
|
||||||
|
{ deep: true }
|
||||||
|
)
|
||||||
|
|
||||||
// 页面加载时获取购物车数据
|
// 页面加载时获取购物车数据
|
||||||
onMounted(() => {
|
onMounted(() => {
|
||||||
loadCartItems()
|
loadCartItems()
|
||||||
@@ -473,4 +612,137 @@ onMounted(() => {
|
|||||||
font-weight: 600;
|
font-weight: 600;
|
||||||
font-size: 16px;
|
font-size: 16px;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* 优惠券样式 */
|
||||||
|
.coupon-section {
|
||||||
|
margin: 0 15px 15px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.coupon-card {
|
||||||
|
border-radius: 12px;
|
||||||
|
overflow: hidden;
|
||||||
|
}
|
||||||
|
|
||||||
|
.coupon-header {
|
||||||
|
display: flex;
|
||||||
|
justify-content: space-between;
|
||||||
|
align-items: center;
|
||||||
|
padding: 16px;
|
||||||
|
cursor: pointer;
|
||||||
|
}
|
||||||
|
|
||||||
|
.coupon-header:hover {
|
||||||
|
background-color: #f5f5f5;
|
||||||
|
}
|
||||||
|
|
||||||
|
.coupon-title {
|
||||||
|
font-size: 15px;
|
||||||
|
font-weight: 600;
|
||||||
|
color: #333;
|
||||||
|
}
|
||||||
|
|
||||||
|
.coupon-value {
|
||||||
|
font-size: 14px;
|
||||||
|
color: #1890ff;
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
gap: 4px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.coupon-discount {
|
||||||
|
padding: 12px 16px;
|
||||||
|
background-color: #f0f9ff;
|
||||||
|
border-top: 1px solid #e6f7ff;
|
||||||
|
display: flex;
|
||||||
|
justify-content: space-between;
|
||||||
|
align-items: center;
|
||||||
|
}
|
||||||
|
|
||||||
|
.discount-label {
|
||||||
|
font-size: 14px;
|
||||||
|
color: #333;
|
||||||
|
}
|
||||||
|
|
||||||
|
.discount-amount {
|
||||||
|
font-size: 16px;
|
||||||
|
font-weight: 600;
|
||||||
|
color: #1890ff;
|
||||||
|
}
|
||||||
|
|
||||||
|
.discount {
|
||||||
|
color: #1890ff;
|
||||||
|
font-weight: 600;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* 优惠券弹窗样式 */
|
||||||
|
.coupon-modal-content {
|
||||||
|
max-height: 400px;
|
||||||
|
overflow-y: auto;
|
||||||
|
}
|
||||||
|
|
||||||
|
.coupon-list {
|
||||||
|
padding: 8px 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.modal-coupon-card {
|
||||||
|
margin-bottom: 12px;
|
||||||
|
border-radius: 12px;
|
||||||
|
overflow: hidden;
|
||||||
|
cursor: pointer;
|
||||||
|
transition: all 0.3s;
|
||||||
|
}
|
||||||
|
|
||||||
|
.modal-coupon-card:hover {
|
||||||
|
box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
|
||||||
|
}
|
||||||
|
|
||||||
|
.modal-coupon-card.active {
|
||||||
|
border: 2px solid #1890ff;
|
||||||
|
}
|
||||||
|
|
||||||
|
.coupon-content {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
padding: 16px;
|
||||||
|
gap: 16px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.coupon-value {
|
||||||
|
font-size: 24px;
|
||||||
|
font-weight: 600;
|
||||||
|
color: #ff4d4f;
|
||||||
|
flex-shrink: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.coupon-info {
|
||||||
|
flex: 1;
|
||||||
|
min-width: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.coupon-name {
|
||||||
|
font-size: 15px;
|
||||||
|
font-weight: 600;
|
||||||
|
color: #333;
|
||||||
|
margin-bottom: 4px;
|
||||||
|
overflow: hidden;
|
||||||
|
text-overflow: ellipsis;
|
||||||
|
white-space: nowrap;
|
||||||
|
}
|
||||||
|
|
||||||
|
.coupon-condition {
|
||||||
|
font-size: 13px;
|
||||||
|
color: #666;
|
||||||
|
margin-bottom: 4px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.coupon-time {
|
||||||
|
font-size: 12px;
|
||||||
|
color: #999;
|
||||||
|
}
|
||||||
|
|
||||||
|
.coupon-select {
|
||||||
|
color: #1890ff;
|
||||||
|
font-size: 20px;
|
||||||
|
flex-shrink: 0;
|
||||||
|
}
|
||||||
</style>
|
</style>
|
||||||
@@ -471,7 +471,7 @@ const handleLogout = () => {
|
|||||||
localStorage.removeItem('refreshToken')
|
localStorage.removeItem('refreshToken')
|
||||||
sessionStorage.removeItem('accessToken')
|
sessionStorage.removeItem('accessToken')
|
||||||
message.success('已退出登录')
|
message.success('已退出登录')
|
||||||
router.push('/auth')
|
router.push('/')
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -91,7 +91,8 @@ import {
|
|||||||
SafetyCertificateOutlined,
|
SafetyCertificateOutlined,
|
||||||
DownOutlined,
|
DownOutlined,
|
||||||
LogoutOutlined,
|
LogoutOutlined,
|
||||||
GiftOutlined
|
GiftOutlined,
|
||||||
|
TagOutlined
|
||||||
} from '@ant-design/icons-vue'
|
} from '@ant-design/icons-vue'
|
||||||
import { message, Modal } from 'ant-design-vue'
|
import { message, Modal } from 'ant-design-vue'
|
||||||
import { userApi, type UserVO, adminAuthApi } from '@/api/admin'
|
import { userApi, type UserVO, adminAuthApi } from '@/api/admin'
|
||||||
@@ -147,6 +148,12 @@ const menuItems = [
|
|||||||
icon: SafetyCertificateOutlined,
|
icon: SafetyCertificateOutlined,
|
||||||
label: '权限管理',
|
label: '权限管理',
|
||||||
permissionCode: 'permission:view'
|
permissionCode: 'permission:view'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
key: '/admin/tags',
|
||||||
|
icon: TagOutlined,
|
||||||
|
label: '标签管理',
|
||||||
|
permissionCode: 'tag:view'
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
|
||||||
@@ -197,7 +204,7 @@ const handleLogout = () => {
|
|||||||
sessionStorage.removeItem('accessToken')
|
sessionStorage.removeItem('accessToken')
|
||||||
clearPermissions()
|
clearPermissions()
|
||||||
message.success('已退出登录')
|
message.success('已退出登录')
|
||||||
window.location.href = '/auth'
|
window.location.href = '/admin/login'
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -61,10 +61,12 @@ import { message } from 'ant-design-vue'
|
|||||||
import type { FormInstance } from 'ant-design-vue'
|
import type { FormInstance } from 'ant-design-vue'
|
||||||
import { UserOutlined, LockOutlined } from '@ant-design/icons-vue'
|
import { UserOutlined, LockOutlined } from '@ant-design/icons-vue'
|
||||||
import { adminAuthApi } from '@/api/admin'
|
import { adminAuthApi } from '@/api/admin'
|
||||||
|
import { usePermission } from '@/utils/permission'
|
||||||
|
|
||||||
const router = useRouter()
|
const router = useRouter()
|
||||||
const formRef = ref<FormInstance>()
|
const formRef = ref<FormInstance>()
|
||||||
const loading = ref(false)
|
const loading = ref(false)
|
||||||
|
const { loadUserPermissions } = usePermission()
|
||||||
|
|
||||||
const formState = reactive({
|
const formState = reactive({
|
||||||
account: '',
|
account: '',
|
||||||
@@ -102,11 +104,16 @@ const handleLogin = async () => {
|
|||||||
sessionStorage.setItem('adminAccessToken', accessToken)
|
sessionStorage.setItem('adminAccessToken', accessToken)
|
||||||
|
|
||||||
console.log('存储登录信息完成')
|
console.log('存储登录信息完成')
|
||||||
|
|
||||||
message.success('登录成功')
|
message.success('登录成功')
|
||||||
|
|
||||||
|
console.log('开始加载用户权限...')
|
||||||
|
await loadUserPermissions()
|
||||||
|
console.log('用户权限加载完成')
|
||||||
|
|
||||||
console.log('准备跳转到首页...')
|
console.log('准备跳转到首页...')
|
||||||
router.push('/admin').catch(err => {
|
router.push('/admin').catch(err => {
|
||||||
console.error('跳转到首页失败:', err)
|
console.error('跳转到首页失败:', err)
|
||||||
// 尝试使用window.location进行跳转
|
|
||||||
window.location.href = '/admin'
|
window.location.href = '/admin'
|
||||||
})
|
})
|
||||||
console.log('跳转命令已执行')
|
console.log('跳转命令已执行')
|
||||||
@@ -125,11 +132,12 @@ const goToFrontend = () => {
|
|||||||
localStorage.removeItem('accessToken')
|
localStorage.removeItem('accessToken')
|
||||||
localStorage.removeItem('refreshToken')
|
localStorage.removeItem('refreshToken')
|
||||||
localStorage.removeItem('userInfo')
|
localStorage.removeItem('userInfo')
|
||||||
|
localStorage.removeItem('userPermissions')
|
||||||
sessionStorage.removeItem('adminAccessToken')
|
sessionStorage.removeItem('adminAccessToken')
|
||||||
sessionStorage.removeItem('accessToken')
|
sessionStorage.removeItem('accessToken')
|
||||||
|
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
window.location.href = '/auth'
|
window.location.href = '/'
|
||||||
}, 100)
|
}, 100)
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|||||||
@@ -34,6 +34,9 @@
|
|||||||
{{ record.couponTypeName }}
|
{{ record.couponTypeName }}
|
||||||
</a-tag>
|
</a-tag>
|
||||||
</template>
|
</template>
|
||||||
|
<template v-else-if="column.key === 'shop'">
|
||||||
|
<span>{{ record.shopName || '未知店铺' }}</span>
|
||||||
|
</template>
|
||||||
<template v-else-if="column.key === 'value'">
|
<template v-else-if="column.key === 'value'">
|
||||||
<template v-if="record.couponType === 1">
|
<template v-if="record.couponType === 1">
|
||||||
{{ record.discountValue }}折
|
{{ record.discountValue }}折
|
||||||
@@ -49,7 +52,7 @@
|
|||||||
</template>
|
</template>
|
||||||
<template v-else-if="column.key === 'actions'">
|
<template v-else-if="column.key === 'actions'">
|
||||||
<a-space>
|
<a-space>
|
||||||
<a-button v-if="hasPermission('coupon:edit')" type="link" size="small" @click="showEditModal(record)">
|
<a-button type="link" size="small" @click="showEditModal(record)">
|
||||||
编辑
|
编辑
|
||||||
</a-button>
|
</a-button>
|
||||||
<a-button v-if="hasPermission('coupon:assign') && record.status === 1" type="link" size="small" @click="showDistributeModal(record)">
|
<a-button v-if="hasPermission('coupon:assign') && record.status === 1" type="link" size="small" @click="showDistributeModal(record)">
|
||||||
@@ -85,6 +88,30 @@
|
|||||||
<a-form-item label="优惠券名称" name="couponName">
|
<a-form-item label="优惠券名称" name="couponName">
|
||||||
<a-input v-model:value="formState.couponName" placeholder="请输入优惠券名称" />
|
<a-input v-model:value="formState.couponName" placeholder="请输入优惠券名称" />
|
||||||
</a-form-item>
|
</a-form-item>
|
||||||
|
<a-form-item label="所属店铺" name="shopId">
|
||||||
|
<a-select
|
||||||
|
v-model:value="formState.shopId"
|
||||||
|
placeholder="请选择所属店铺"
|
||||||
|
style="width: 100%"
|
||||||
|
:loading="loadingShops"
|
||||||
|
:disabled="getCurrentUserInfo()?.type === 2"
|
||||||
|
>
|
||||||
|
<a-select-option
|
||||||
|
v-if="shops.length === 0"
|
||||||
|
disabled
|
||||||
|
value=""
|
||||||
|
>
|
||||||
|
暂无店铺数据
|
||||||
|
</a-select-option>
|
||||||
|
<a-select-option
|
||||||
|
v-for="shop in shops"
|
||||||
|
:key="shop.id"
|
||||||
|
:value="shop.id"
|
||||||
|
>
|
||||||
|
{{ shop.shopName }}
|
||||||
|
</a-select-option>
|
||||||
|
</a-select>
|
||||||
|
</a-form-item>
|
||||||
<a-form-item label="优惠券类型" name="couponType">
|
<a-form-item label="优惠券类型" name="couponType">
|
||||||
<a-select v-model:value="formState.couponType" placeholder="请选择优惠券类型">
|
<a-select v-model:value="formState.couponType" placeholder="请选择优惠券类型">
|
||||||
<a-select-option :value="1">折扣券</a-select-option>
|
<a-select-option :value="1">折扣券</a-select-option>
|
||||||
@@ -180,7 +207,7 @@ import { ref, reactive, onMounted, computed } from 'vue'
|
|||||||
import { message } from 'ant-design-vue'
|
import { message } from 'ant-design-vue'
|
||||||
import type { FormInstance } from 'ant-design-vue'
|
import type { FormInstance } from 'ant-design-vue'
|
||||||
import { PlusOutlined } from '@ant-design/icons-vue'
|
import { PlusOutlined } from '@ant-design/icons-vue'
|
||||||
import { adminCouponApi, adminTagApi } from '@/api/admin'
|
import { adminCouponApi, adminTagApi, adminShopApi, type Shop } from '@/api/admin'
|
||||||
import type { Coupon } from '@/api/coupon'
|
import type { Coupon } from '@/api/coupon'
|
||||||
|
|
||||||
interface CreateCouponRequest {
|
interface CreateCouponRequest {
|
||||||
@@ -195,6 +222,7 @@ interface CreateCouponRequest {
|
|||||||
endTime: string
|
endTime: string
|
||||||
availableTagIds: number[]
|
availableTagIds: number[]
|
||||||
unavailableTagIds: number[]
|
unavailableTagIds: number[]
|
||||||
|
shopId: number
|
||||||
}
|
}
|
||||||
|
|
||||||
interface TagVO {
|
interface TagVO {
|
||||||
@@ -211,6 +239,19 @@ import { usePermission } from '@/utils/permission'
|
|||||||
|
|
||||||
const { hasPermission, loadUserPermissions } = usePermission()
|
const { hasPermission, loadUserPermissions } = usePermission()
|
||||||
|
|
||||||
|
const getCurrentUserInfo = () => {
|
||||||
|
try {
|
||||||
|
const userInfoStr = localStorage.getItem('adminUserInfo')
|
||||||
|
if (userInfoStr) {
|
||||||
|
const userInfo = JSON.parse(userInfoStr)
|
||||||
|
return userInfo
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
console.error('获取当前用户信息失败', error)
|
||||||
|
}
|
||||||
|
return null
|
||||||
|
}
|
||||||
|
|
||||||
const loading = ref(false)
|
const loading = ref(false)
|
||||||
const modalVisible = ref(false)
|
const modalVisible = ref(false)
|
||||||
const modalLoading = ref(false)
|
const modalLoading = ref(false)
|
||||||
@@ -228,6 +269,8 @@ const currentDistributeCoupon = ref<Coupon | null>(null)
|
|||||||
const couponList = ref<Coupon[]>([])
|
const couponList = ref<Coupon[]>([])
|
||||||
const tagList = ref<TagVO[]>([])
|
const tagList = ref<TagVO[]>([])
|
||||||
const userList = ref<any[]>([])
|
const userList = ref<any[]>([])
|
||||||
|
const shops = ref<Shop[]>([])
|
||||||
|
const loadingShops = ref(false)
|
||||||
|
|
||||||
const pagination = reactive({
|
const pagination = reactive({
|
||||||
current: 1,
|
current: 1,
|
||||||
@@ -249,7 +292,8 @@ const formState = reactive({
|
|||||||
startTime: new Date(),
|
startTime: new Date(),
|
||||||
endTime: new Date(new Date().getTime() + 30 * 24 * 60 * 60 * 1000),
|
endTime: new Date(new Date().getTime() + 30 * 24 * 60 * 60 * 1000),
|
||||||
availableTagIds: [] as number[],
|
availableTagIds: [] as number[],
|
||||||
unavailableTagIds: [] as number[]
|
unavailableTagIds: [] as number[],
|
||||||
|
shopId: undefined as number | undefined
|
||||||
})
|
})
|
||||||
|
|
||||||
const formRules = {
|
const formRules = {
|
||||||
@@ -261,7 +305,8 @@ const formRules = {
|
|||||||
reduceAmount: [{ required: formState.couponType === 2, message: '请输入减免金额', trigger: 'blur' }],
|
reduceAmount: [{ required: formState.couponType === 2, message: '请输入减免金额', trigger: 'blur' }],
|
||||||
totalCount: [{ required: true, message: '请输入优惠券总数量', trigger: 'blur' }],
|
totalCount: [{ required: true, message: '请输入优惠券总数量', trigger: 'blur' }],
|
||||||
startTime: [{ required: true, message: '请选择开始时间', trigger: 'change' }],
|
startTime: [{ required: true, message: '请选择开始时间', trigger: 'change' }],
|
||||||
endTime: [{ required: true, message: '请选择结束时间', trigger: 'change' }]
|
endTime: [{ required: true, message: '请选择结束时间', trigger: 'change' }],
|
||||||
|
shopId: [{ required: true, message: '请选择所属店铺', trigger: 'change' }]
|
||||||
}
|
}
|
||||||
|
|
||||||
// 发放优惠券表单状态
|
// 发放优惠券表单状态
|
||||||
@@ -280,6 +325,7 @@ const distributeFormRules = {
|
|||||||
const columns = [
|
const columns = [
|
||||||
{ title: '优惠券编码', dataIndex: 'couponCode', key: 'couponCode' },
|
{ title: '优惠券编码', dataIndex: 'couponCode', key: 'couponCode' },
|
||||||
{ title: '优惠券名称', dataIndex: 'couponName', key: 'couponName' },
|
{ title: '优惠券名称', dataIndex: 'couponName', key: 'couponName' },
|
||||||
|
{ title: '所属店铺', key: 'shop', width: 150 },
|
||||||
{ title: '类型', key: 'couponType', width: 100 },
|
{ title: '类型', key: 'couponType', width: 100 },
|
||||||
{ title: '优惠信息', key: 'value', width: 150 },
|
{ title: '优惠信息', key: 'value', width: 150 },
|
||||||
{ title: '总数量', dataIndex: 'totalCount', key: 'totalCount', width: 100 },
|
{ title: '总数量', dataIndex: 'totalCount', key: 'totalCount', width: 100 },
|
||||||
@@ -307,7 +353,9 @@ const getStatusColor = (status: number) => {
|
|||||||
const fetchCoupons = async () => {
|
const fetchCoupons = async () => {
|
||||||
loading.value = true
|
loading.value = true
|
||||||
try {
|
try {
|
||||||
const res = await adminCouponApi.listAllCoupons()
|
const currentUser = getCurrentUserInfo()
|
||||||
|
const shopId = (currentUser && currentUser.shopId) ? currentUser.shopId : undefined
|
||||||
|
const res = await adminCouponApi.listAllCoupons(shopId)
|
||||||
// 处理后端返回的分页数据结构
|
// 处理后端返回的分页数据结构
|
||||||
couponList.value = res?.list || []
|
couponList.value = res?.list || []
|
||||||
pagination.total = res?.total || 0
|
pagination.total = res?.total || 0
|
||||||
@@ -327,6 +375,18 @@ const fetchTags = async () => {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const fetchShops = async () => {
|
||||||
|
loadingShops.value = true
|
||||||
|
try {
|
||||||
|
const res = await adminShopApi.listAllShops()
|
||||||
|
shops.value = res || []
|
||||||
|
} catch (error) {
|
||||||
|
console.error('获取店铺列表失败:', error)
|
||||||
|
} finally {
|
||||||
|
loadingShops.value = false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
const handleSearch = () => {
|
const handleSearch = () => {
|
||||||
pagination.current = 1
|
pagination.current = 1
|
||||||
fetchCoupons()
|
fetchCoupons()
|
||||||
@@ -340,6 +400,8 @@ const handleTableChange = (pag: any) => {
|
|||||||
|
|
||||||
const showAddModal = () => {
|
const showAddModal = () => {
|
||||||
isEdit.value = false
|
isEdit.value = false
|
||||||
|
const currentUser = getCurrentUserInfo()
|
||||||
|
const shopId = (currentUser && currentUser.shopId) ? currentUser.shopId : undefined
|
||||||
Object.assign(formState, {
|
Object.assign(formState, {
|
||||||
couponCode: '',
|
couponCode: '',
|
||||||
couponName: '',
|
couponName: '',
|
||||||
@@ -351,28 +413,43 @@ const showAddModal = () => {
|
|||||||
startTime: undefined,
|
startTime: undefined,
|
||||||
endTime: undefined,
|
endTime: undefined,
|
||||||
availableTagIds: [],
|
availableTagIds: [],
|
||||||
unavailableTagIds: []
|
unavailableTagIds: [],
|
||||||
|
shopId: shopId
|
||||||
})
|
})
|
||||||
modalVisible.value = true
|
modalVisible.value = true
|
||||||
}
|
}
|
||||||
|
|
||||||
const showEditModal = (record: Coupon) => {
|
const showEditModal = (record: Coupon) => {
|
||||||
isEdit.value = true
|
console.log('showEditModal called with record:', record)
|
||||||
currentCoupon.value = record
|
if (!record) {
|
||||||
Object.assign(formState, {
|
message.error('优惠券数据不存在')
|
||||||
couponCode: record.couponCode,
|
return
|
||||||
couponName: record.couponName,
|
}
|
||||||
couponType: record.couponType,
|
try {
|
||||||
discountValue: record.discountValue,
|
isEdit.value = true
|
||||||
minAmount: record.minAmount,
|
currentCoupon.value = record
|
||||||
reduceAmount: record.reduceAmount,
|
console.log('Form state before:', formState)
|
||||||
totalCount: record.totalCount,
|
Object.assign(formState, {
|
||||||
startTime: undefined,
|
couponCode: record.couponCode || '',
|
||||||
endTime: undefined,
|
couponName: record.couponName || '',
|
||||||
availableTagIds: record.availableTags.map(tag => tag.id),
|
couponType: record.couponType || 1,
|
||||||
unavailableTagIds: record.unavailableTags.map(tag => tag.id)
|
discountValue: record.discountValue || 0,
|
||||||
|
minAmount: record.minAmount || 0,
|
||||||
|
reduceAmount: record.reduceAmount || 0,
|
||||||
|
totalCount: record.totalCount || 0,
|
||||||
|
startTime: record.startTime ? new Date(record.startTime) : undefined,
|
||||||
|
endTime: record.endTime ? new Date(record.endTime) : undefined,
|
||||||
|
availableTagIds: record.availableTags ? record.availableTags.map(tag => tag.id) : [],
|
||||||
|
unavailableTagIds: record.unavailableTags ? record.unavailableTags.map(tag => tag.id) : [],
|
||||||
|
shopId: record.shopId
|
||||||
})
|
})
|
||||||
modalVisible.value = true
|
console.log('Form state after:', formState)
|
||||||
|
modalVisible.value = true
|
||||||
|
console.log('Modal visible set to:', modalVisible.value)
|
||||||
|
} catch (error) {
|
||||||
|
console.error('Error in showEditModal:', error)
|
||||||
|
message.error('打开编辑模态框失败')
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const handleModalOk = async () => {
|
const handleModalOk = async () => {
|
||||||
@@ -380,6 +457,35 @@ const handleModalOk = async () => {
|
|||||||
await formRef.value?.validate()
|
await formRef.value?.validate()
|
||||||
modalLoading.value = true
|
modalLoading.value = true
|
||||||
|
|
||||||
|
const currentUser = getCurrentUserInfo()
|
||||||
|
const shopId = formState.shopId || (currentUser && currentUser.shopId)
|
||||||
|
|
||||||
|
if (!shopId) {
|
||||||
|
message.error('请选择所属店铺')
|
||||||
|
modalLoading.value = false
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// 处理日期格式
|
||||||
|
let startTimeStr = ''
|
||||||
|
let endTimeStr = ''
|
||||||
|
|
||||||
|
if (formState.startTime) {
|
||||||
|
if (formState.startTime instanceof Date) {
|
||||||
|
startTimeStr = formState.startTime.toISOString()
|
||||||
|
} else {
|
||||||
|
startTimeStr = formState.startTime
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (formState.endTime) {
|
||||||
|
if (formState.endTime instanceof Date) {
|
||||||
|
endTimeStr = formState.endTime.toISOString()
|
||||||
|
} else {
|
||||||
|
endTimeStr = formState.endTime
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
const requestData: CreateCouponRequest = {
|
const requestData: CreateCouponRequest = {
|
||||||
couponCode: formState.couponCode,
|
couponCode: formState.couponCode,
|
||||||
couponName: formState.couponName,
|
couponName: formState.couponName,
|
||||||
@@ -388,17 +494,18 @@ const handleModalOk = async () => {
|
|||||||
minAmount: formState.minAmount,
|
minAmount: formState.minAmount,
|
||||||
reduceAmount: formState.reduceAmount,
|
reduceAmount: formState.reduceAmount,
|
||||||
totalCount: formState.totalCount,
|
totalCount: formState.totalCount,
|
||||||
startTime: formState.startTime.toISOString(),
|
startTime: startTimeStr,
|
||||||
endTime: formState.endTime.toISOString(),
|
endTime: endTimeStr,
|
||||||
availableTagIds: formState.availableTagIds,
|
availableTagIds: formState.availableTagIds,
|
||||||
unavailableTagIds: formState.unavailableTagIds
|
unavailableTagIds: formState.unavailableTagIds,
|
||||||
|
shopId: shopId
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isEdit.value && currentCoupon.value) {
|
if (isEdit.value && currentCoupon.value) {
|
||||||
await adminCouponApi.updateCoupon(currentCoupon.value.id, requestData)
|
await adminCouponApi.updateCoupon(currentCoupon.value.id, requestData, shopId)
|
||||||
message.success('更新成功')
|
message.success('更新成功')
|
||||||
} else {
|
} else {
|
||||||
await adminCouponApi.createCoupon(requestData)
|
await adminCouponApi.createCoupon(requestData, shopId)
|
||||||
message.success('创建成功')
|
message.success('创建成功')
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -406,6 +513,7 @@ const handleModalOk = async () => {
|
|||||||
fetchCoupons()
|
fetchCoupons()
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error(error)
|
console.error(error)
|
||||||
|
message.error('操作失败')
|
||||||
} finally {
|
} finally {
|
||||||
modalLoading.value = false
|
modalLoading.value = false
|
||||||
}
|
}
|
||||||
@@ -422,7 +530,9 @@ const handleDelete = (record: Coupon) => {
|
|||||||
content: `确定要删除优惠券 ${record.couponName} 吗?`,
|
content: `确定要删除优惠券 ${record.couponName} 吗?`,
|
||||||
onOk: async () => {
|
onOk: async () => {
|
||||||
try {
|
try {
|
||||||
await adminCouponApi.deleteCoupon(record.id)
|
const currentUser = getCurrentUserInfo()
|
||||||
|
const shopId = (currentUser && currentUser.shopId) ? currentUser.shopId : record.shopId
|
||||||
|
await adminCouponApi.deleteCoupon(record.id, shopId)
|
||||||
message.success('删除成功')
|
message.success('删除成功')
|
||||||
fetchCoupons()
|
fetchCoupons()
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
@@ -465,12 +575,21 @@ const handleDistributeOk = async () => {
|
|||||||
|
|
||||||
if (!currentDistributeCoupon.value) return
|
if (!currentDistributeCoupon.value) return
|
||||||
|
|
||||||
|
const currentUser = getCurrentUserInfo()
|
||||||
|
const shopId = (currentUser && currentUser.shopId) ? currentUser.shopId : currentDistributeCoupon.value.shopId
|
||||||
|
|
||||||
|
if (!shopId) {
|
||||||
|
message.error('请选择所属店铺')
|
||||||
|
distributeLoading.value = false
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
// 调用发放优惠券的API
|
// 调用发放优惠券的API
|
||||||
await adminCouponApi.distributeCoupon({
|
await adminCouponApi.distributeCoupon({
|
||||||
couponId: currentDistributeCoupon.value.id,
|
couponId: currentDistributeCoupon.value.id,
|
||||||
userIds: distributeFormState.userIds,
|
userIds: distributeFormState.userIds,
|
||||||
quantity: distributeFormState.quantity
|
quantity: distributeFormState.quantity
|
||||||
})
|
}, shopId)
|
||||||
|
|
||||||
message.success('发放成功')
|
message.success('发放成功')
|
||||||
distributeModalVisible.value = false
|
distributeModalVisible.value = false
|
||||||
@@ -491,6 +610,7 @@ const handleDistributeCancel = () => {
|
|||||||
onMounted(async () => {
|
onMounted(async () => {
|
||||||
await loadUserPermissions()
|
await loadUserPermissions()
|
||||||
await fetchTags()
|
await fetchTags()
|
||||||
|
await fetchShops()
|
||||||
await fetchCoupons()
|
await fetchCoupons()
|
||||||
})
|
})
|
||||||
</script>
|
</script>
|
||||||
|
|||||||
@@ -49,7 +49,7 @@
|
|||||||
</template>
|
</template>
|
||||||
<a-grid :columns="3" :colGap="16" :rowGap="16">
|
<a-grid :columns="3" :colGap="16" :rowGap="16">
|
||||||
<a-grid-item v-for="item in quickActions" :key="item.key">
|
<a-grid-item v-for="item in quickActions" :key="item.key">
|
||||||
<a-card hoverable @click="navigateTo(item.path)">
|
<a-card hoverable @click="navigateTo(item.path, item.permissionCode)">
|
||||||
<template #cover>
|
<template #cover>
|
||||||
<div class="action-icon">
|
<div class="action-icon">
|
||||||
<component :is="item.icon" />
|
<component :is="item.icon" />
|
||||||
@@ -71,6 +71,7 @@ import { useRouter } from 'vue-router'
|
|||||||
import { DashboardOutlined, UserOutlined, ShopOutlined, SafetyCertificateOutlined, HomeOutlined } from '@ant-design/icons-vue'
|
import { DashboardOutlined, UserOutlined, ShopOutlined, SafetyCertificateOutlined, HomeOutlined } from '@ant-design/icons-vue'
|
||||||
import { userApi, type UserVO, permissionApi, type PermissionVO } from '@/api/admin'
|
import { userApi, type UserVO, permissionApi, type PermissionVO } from '@/api/admin'
|
||||||
import { DEFAULT_AVATAR } from '@/constants'
|
import { DEFAULT_AVATAR } from '@/constants'
|
||||||
|
import { message } from 'ant-design-vue'
|
||||||
|
|
||||||
const router = useRouter()
|
const router = useRouter()
|
||||||
const currentTime = ref('')
|
const currentTime = ref('')
|
||||||
@@ -105,31 +106,36 @@ const quickActions = computed(() => {
|
|||||||
key: 'dashboard',
|
key: 'dashboard',
|
||||||
title: '仪表盘',
|
title: '仪表盘',
|
||||||
path: '/admin/dashboard',
|
path: '/admin/dashboard',
|
||||||
icon: DashboardOutlined
|
icon: DashboardOutlined,
|
||||||
|
permissionCode: 'dashboard:view'
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
key: 'users',
|
key: 'users',
|
||||||
title: '用户管理',
|
title: '用户管理',
|
||||||
path: '/admin/users',
|
path: '/admin/users',
|
||||||
icon: UserOutlined
|
icon: UserOutlined,
|
||||||
|
permissionCode: 'user:view'
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
key: 'products',
|
key: 'products',
|
||||||
title: '商品管理',
|
title: '商品管理',
|
||||||
path: '/admin/products',
|
path: '/admin/products',
|
||||||
icon: ShopOutlined
|
icon: ShopOutlined,
|
||||||
|
permissionCode: 'product:view'
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
key: 'shops',
|
key: 'shops',
|
||||||
title: '店铺管理',
|
title: '店铺管理',
|
||||||
path: '/admin/shops',
|
path: '/admin/shops',
|
||||||
icon: HomeOutlined
|
icon: HomeOutlined,
|
||||||
|
permissionCode: 'shop:view'
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
key: 'permissions',
|
key: 'permissions',
|
||||||
title: '权限管理',
|
title: '权限管理',
|
||||||
path: '/admin/permissions',
|
path: '/admin/permissions',
|
||||||
icon: SafetyCertificateOutlined
|
icon: SafetyCertificateOutlined,
|
||||||
|
permissionCode: 'permission:view'
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
|
||||||
@@ -189,7 +195,15 @@ const fetchUserPermissions = async () => {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const navigateTo = (path: string) => {
|
const navigateTo = (path: string, permissionCode?: string) => {
|
||||||
|
// 检查是否需要权限
|
||||||
|
if (permissionCode) {
|
||||||
|
const hasPermission = userPermissions.value.some(p => p.permissionCode === permissionCode)
|
||||||
|
if (!hasPermission) {
|
||||||
|
message.warning('您没有该操作的权限')
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
router.push(path)
|
router.push(path)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,48 +1,49 @@
|
|||||||
<template>
|
<template>
|
||||||
<div class="orders-view">
|
<div class="orders">
|
||||||
<h1>订单管理</h1>
|
<a-page-header title="订单管理" sub-title="管理系统订单" />
|
||||||
<div class="orders-table">
|
|
||||||
<table>
|
<a-card :bordered="false">
|
||||||
<thead>
|
<template #extra>
|
||||||
<tr>
|
<a-input-search
|
||||||
<th>订单编号</th>
|
v-model:value="searchText"
|
||||||
<th>用户ID</th>
|
placeholder="搜索订单编号或用户ID"
|
||||||
<th>总金额</th>
|
style="width: 250px"
|
||||||
<th>实际金额</th>
|
@search="handleSearch"
|
||||||
<th>优惠券</th>
|
/>
|
||||||
<th>状态</th>
|
</template>
|
||||||
<th>创建时间</th>
|
|
||||||
<th>操作</th>
|
<a-table
|
||||||
</tr>
|
:columns="columns"
|
||||||
</thead>
|
:data-source="orders"
|
||||||
<tbody>
|
:loading="loading"
|
||||||
<tr v-for="order in orders" :key="order.id">
|
:pagination="pagination"
|
||||||
<td>{{ order.orderNo }}</td>
|
@change="handleTableChange"
|
||||||
<td>{{ order.userId }}</td>
|
row-key="id"
|
||||||
<td>{{ order.totalAmount }}</td>
|
>
|
||||||
<td>{{ order.actualAmount }}</td>
|
<template #bodyCell="{ column, record }">
|
||||||
<td>{{ order.couponName || '无' }}</td>
|
<template v-if="column.key === 'status'">
|
||||||
<td>{{ order.statusText }}</td>
|
<a-tag :color="getStatusColor(record.status)">
|
||||||
<td>{{ order.createTime }}</td>
|
{{ record.statusText }}
|
||||||
<td>
|
</a-tag>
|
||||||
<div class="order-actions">
|
</template>
|
||||||
<button v-if="order.status === 1" @click="processOrder(order.id, 2)" class="btn btn-success">
|
<template v-else-if="column.key === 'actions'">
|
||||||
确认完成
|
<a-space>
|
||||||
</button>
|
<a-button v-if="record.status === 1" type="primary" size="small" @click="processOrder(record.id, 2)">
|
||||||
<button v-if="order.status === 1" @click="processOrder(order.id, 3)" class="btn btn-danger">
|
确认完成
|
||||||
取消订单
|
</a-button>
|
||||||
</button>
|
<a-button v-if="record.status === 1" danger size="small" @click="processOrder(record.id, 3)">
|
||||||
</div>
|
取消订单
|
||||||
</td>
|
</a-button>
|
||||||
</tr>
|
</a-space>
|
||||||
</tbody>
|
</template>
|
||||||
</table>
|
</template>
|
||||||
</div>
|
</a-table>
|
||||||
|
</a-card>
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import { ref, onMounted } from 'vue'
|
import { ref, reactive, onMounted } from 'vue'
|
||||||
import { orderApi } from '../../api/order'
|
import { orderApi } from '../../api/order'
|
||||||
import { message } from 'ant-design-vue'
|
import { message } from 'ant-design-vue'
|
||||||
|
|
||||||
@@ -61,16 +62,72 @@ interface Order {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const orders = ref<Order[]>([])
|
const orders = ref<Order[]>([])
|
||||||
|
const loading = ref(false)
|
||||||
|
const searchText = ref('')
|
||||||
|
|
||||||
|
const pagination = reactive({
|
||||||
|
current: 1,
|
||||||
|
pageSize: 10,
|
||||||
|
total: 0,
|
||||||
|
showSizeChanger: true,
|
||||||
|
showQuickJumper: true,
|
||||||
|
showTotal: (total: number) => `共 ${total} 条`
|
||||||
|
})
|
||||||
|
|
||||||
|
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: '状态', key: 'status', width: 100 },
|
||||||
|
{ title: '创建时间', dataIndex: 'createTime', key: 'createTime' },
|
||||||
|
{ title: '操作', key: 'actions', width: 150, fixed: 'right' as const }
|
||||||
|
]
|
||||||
|
|
||||||
|
const getStatusColor = (status: number) => {
|
||||||
|
switch (status) {
|
||||||
|
case 1:
|
||||||
|
return 'orange'
|
||||||
|
case 2:
|
||||||
|
return 'green'
|
||||||
|
case 3:
|
||||||
|
return 'red'
|
||||||
|
default:
|
||||||
|
return 'default'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
const loadOrders = async () => {
|
const loadOrders = async () => {
|
||||||
|
loading.value = true
|
||||||
try {
|
try {
|
||||||
const data = await orderApi.getAllOrders()
|
const data = await orderApi.getAllOrders()
|
||||||
orders.value = data
|
orders.value = data
|
||||||
|
pagination.total = data.length
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
message.error('获取订单列表失败')
|
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 processOrder = async (orderId: number, status: number) => {
|
||||||
try {
|
try {
|
||||||
await orderApi.processOrder(orderId, status)
|
await orderApi.processOrder(orderId, status)
|
||||||
@@ -87,63 +144,20 @@ onMounted(() => {
|
|||||||
</script>
|
</script>
|
||||||
|
|
||||||
<style scoped>
|
<style scoped>
|
||||||
.orders-view {
|
.orders {
|
||||||
padding: 20px;
|
padding: 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
h1 {
|
.orders :deep(.ant-table) {
|
||||||
margin-bottom: 20px;
|
margin: 0;
|
||||||
font-size: 24px;
|
|
||||||
color: #333;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
.orders-table {
|
.orders :deep(.ant-table-thead > tr > th) {
|
||||||
overflow-x: auto;
|
background-color: #fafafa;
|
||||||
}
|
|
||||||
|
|
||||||
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;
|
font-weight: 600;
|
||||||
}
|
}
|
||||||
|
|
||||||
.order-actions {
|
.orders :deep(.ant-table-tbody > tr:hover > td) {
|
||||||
display: flex;
|
background-color: #f5f5f5;
|
||||||
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>
|
</style>
|
||||||
|
|||||||
@@ -256,7 +256,7 @@ const getUserTypeText = (type: number) => {
|
|||||||
|
|
||||||
const filteredUserList = computed(() => {
|
const filteredUserList = computed(() => {
|
||||||
if (!currentLoginUser.value) return []
|
if (!currentLoginUser.value) return []
|
||||||
return userList.value.filter(user => user.type < currentLoginUser.value!.type)
|
return userList.value.filter(user => user.type < currentLoginUser.value!.type && user.type !== 0)
|
||||||
})
|
})
|
||||||
|
|
||||||
const fetchCurrentUser = async () => {
|
const fetchCurrentUser = async () => {
|
||||||
|
|||||||
@@ -50,6 +50,9 @@
|
|||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
<template v-else-if="column.key === 'shop'">
|
||||||
|
<span>{{ getShopName(record.shopId) }}</span>
|
||||||
|
</template>
|
||||||
<template v-else-if="column.key === 'price'">
|
<template v-else-if="column.key === 'price'">
|
||||||
<span style="color: #cf1322; font-weight: 600;">
|
<span style="color: #cf1322; font-weight: 600;">
|
||||||
¥{{ record.price }}
|
¥{{ record.price }}
|
||||||
@@ -107,7 +110,7 @@
|
|||||||
placeholder="请选择店铺"
|
placeholder="请选择店铺"
|
||||||
style="width: 100%"
|
style="width: 100%"
|
||||||
:loading="loadingShops"
|
:loading="loadingShops"
|
||||||
:disabled="!isAdmin && formState.shopId"
|
:disabled="!isAdmin && !!formState.shopId"
|
||||||
>
|
>
|
||||||
<a-select-option
|
<a-select-option
|
||||||
v-if="shops.length === 0"
|
v-if="shops.length === 0"
|
||||||
@@ -308,6 +311,7 @@ const formRules = {
|
|||||||
const columns = [
|
const columns = [
|
||||||
{ title: '图片', key: 'image', width: 150 },
|
{ title: '图片', key: 'image', width: 150 },
|
||||||
{ title: '商品名称', dataIndex: 'title', key: 'title' },
|
{ title: '商品名称', dataIndex: 'title', key: 'title' },
|
||||||
|
{ title: '所属店铺', key: 'shop', width: 150 },
|
||||||
{ title: '描述', dataIndex: 'description', key: 'description' },
|
{ title: '描述', dataIndex: 'description', key: 'description' },
|
||||||
{ title: '价格', key: 'price', width: 100 },
|
{ title: '价格', key: 'price', width: 100 },
|
||||||
{ title: '预计时长', dataIndex: 'approximateDuration', key: 'approximateDuration', width: 120 },
|
{ title: '预计时长', dataIndex: 'approximateDuration', key: 'approximateDuration', width: 120 },
|
||||||
@@ -317,6 +321,11 @@ const columns = [
|
|||||||
{ title: '操作', key: 'actions', width: 150, fixed: 'right' as const }
|
{ title: '操作', key: 'actions', width: 150, fixed: 'right' as const }
|
||||||
]
|
]
|
||||||
|
|
||||||
|
const getShopName = (shopId: number): string => {
|
||||||
|
const shop = shops.value.find(s => s.id === shopId)
|
||||||
|
return shop ? shop.shopName : '未知店铺'
|
||||||
|
}
|
||||||
|
|
||||||
const getCurrentUserInfo = () => {
|
const getCurrentUserInfo = () => {
|
||||||
try {
|
try {
|
||||||
const userInfoStr = localStorage.getItem('adminUserInfo')
|
const userInfoStr = localStorage.getItem('adminUserInfo')
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import path from 'path'
|
|||||||
import AutoImport from 'unplugin-auto-import/vite'
|
import AutoImport from 'unplugin-auto-import/vite'
|
||||||
import Components from 'unplugin-vue-components/vite'
|
import Components from 'unplugin-vue-components/vite'
|
||||||
import { ElementPlusResolver } from 'unplugin-vue-components/resolvers'
|
import { ElementPlusResolver } from 'unplugin-vue-components/resolvers'
|
||||||
|
import { AntDesignVueResolver } from 'unplugin-vue-components/resolvers'
|
||||||
|
|
||||||
// https://vite.dev/config/
|
// https://vite.dev/config/
|
||||||
export default defineConfig({
|
export default defineConfig({
|
||||||
@@ -16,7 +17,7 @@ export default defineConfig({
|
|||||||
dts: 'src/auto-import.d.ts',
|
dts: 'src/auto-import.d.ts',
|
||||||
}),
|
}),
|
||||||
Components({
|
Components({
|
||||||
resolvers: [ElementPlusResolver()],
|
resolvers: [ElementPlusResolver(), AntDesignVueResolver({ importStyle: 'less' })],
|
||||||
dts: 'src/components.d.ts',
|
dts: 'src/components.d.ts',
|
||||||
}),
|
}),
|
||||||
// 添加 IP 访问控制中间件
|
// 添加 IP 访问控制中间件
|
||||||
|
|||||||
@@ -176,6 +176,12 @@
|
|||||||
<scope>runtime</scope>
|
<scope>runtime</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
|
<!-- BCrypt for password encryption -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework.security</groupId>
|
||||||
|
<artifactId>spring-security-crypto</artifactId>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
<!-- MinIO -->
|
<!-- MinIO -->
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>io.minio</groupId>
|
<groupId>io.minio</groupId>
|
||||||
|
|||||||
@@ -73,8 +73,6 @@ public class PermissionAspect {
|
|||||||
|
|
||||||
// 获取权限码
|
// 获取权限码
|
||||||
String permissionCode = requirePermission.value();
|
String permissionCode = requirePermission.value();
|
||||||
// 获取需要的用户类型
|
|
||||||
int requireUserType = requirePermission.requireUserType();
|
|
||||||
|
|
||||||
// 默认有权限
|
// 默认有权限
|
||||||
boolean hasPermission = true;
|
boolean hasPermission = true;
|
||||||
@@ -84,11 +82,6 @@ public class PermissionAspect {
|
|||||||
hasPermission = permissionService.hasPermission(userId, permissionCode);
|
hasPermission = permissionService.hasPermission(userId, permissionCode);
|
||||||
}
|
}
|
||||||
|
|
||||||
// 如果需要检查用户类型,则进行类型检查
|
|
||||||
if (hasPermission && requireUserType >= 0) {
|
|
||||||
hasPermission = permissionService.hasPermissionByType(userDO.getType(), requireUserType);
|
|
||||||
}
|
|
||||||
|
|
||||||
// 如果没有权限,返回错误
|
// 如果没有权限,返回错误
|
||||||
if (!hasPermission) {
|
if (!hasPermission) {
|
||||||
return Result.error(403, "权限不足");
|
return Result.error(403, "权限不足");
|
||||||
|
|||||||
@@ -66,6 +66,7 @@ public class AuthInterceptor implements HandlerInterceptor {
|
|||||||
path.contains("/shop/list/simple") ||
|
path.contains("/shop/list/simple") ||
|
||||||
path.contains("/admin/auth/login") ||
|
path.contains("/admin/auth/login") ||
|
||||||
path.contains("/admin/object-storage-file/upload") ||
|
path.contains("/admin/object-storage-file/upload") ||
|
||||||
path.contains("/health");
|
path.contains("/health") ||
|
||||||
|
path.contains("/error");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -16,12 +16,13 @@ public class WebMvcConfig implements WebMvcConfigurer {
|
|||||||
registry.addInterceptor(authInterceptor)
|
registry.addInterceptor(authInterceptor)
|
||||||
.addPathPatterns("/**")
|
.addPathPatterns("/**")
|
||||||
.excludePathPatterns(
|
.excludePathPatterns(
|
||||||
"/api/user/login",
|
"/user/login",
|
||||||
"/api/user/register",
|
"/user/register",
|
||||||
"/api/user/refresh-token",
|
"/user/refresh-token",
|
||||||
"/api/shop/list/simple",
|
"/user/get/account/**",
|
||||||
"/api/admin/auth/login",
|
"/shop/list/simple",
|
||||||
"/api/admin/object-storage-file/upload",
|
"/admin/auth/login",
|
||||||
|
"/admin/object-storage-file/upload",
|
||||||
"/error",
|
"/error",
|
||||||
"/health/**"
|
"/health/**"
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
package com.xiaowang.yuminailcore.controller;
|
package com.xiaowang.yuminailcore.controller;
|
||||||
|
|
||||||
|
import com.xiaowang.yuminailcore.annotation.RequirePermission;
|
||||||
import com.xiaowang.yuminailcore.common.Result;
|
import com.xiaowang.yuminailcore.common.Result;
|
||||||
import com.xiaowang.yuminailcore.dto.TagDTO;
|
import com.xiaowang.yuminailcore.dto.TagDTO;
|
||||||
import com.xiaowang.yuminailcore.vo.TagVO;
|
import com.xiaowang.yuminailcore.vo.TagVO;
|
||||||
@@ -30,6 +31,7 @@ public class TagController {
|
|||||||
* @return 标签ID
|
* @return 标签ID
|
||||||
*/
|
*/
|
||||||
@PostMapping("/create")
|
@PostMapping("/create")
|
||||||
|
@RequirePermission("tag:create")
|
||||||
public Result<Long> createTag(@RequestBody TagDTO tagDTO) {
|
public Result<Long> createTag(@RequestBody TagDTO tagDTO) {
|
||||||
Long id = tagService.createTag(tagDTO);
|
Long id = tagService.createTag(tagDTO);
|
||||||
return Result.success(id);
|
return Result.success(id);
|
||||||
@@ -43,6 +45,7 @@ public class TagController {
|
|||||||
* @return 是否更新成功
|
* @return 是否更新成功
|
||||||
*/
|
*/
|
||||||
@PutMapping("/update/{id}")
|
@PutMapping("/update/{id}")
|
||||||
|
@RequirePermission("tag:edit")
|
||||||
public Result<Boolean> updateTag(@PathVariable Long id, @RequestBody TagDTO tagDTO) {
|
public Result<Boolean> updateTag(@PathVariable Long id, @RequestBody TagDTO tagDTO) {
|
||||||
boolean success = tagService.updateTag(id, tagDTO);
|
boolean success = tagService.updateTag(id, tagDTO);
|
||||||
return Result.success(success);
|
return Result.success(success);
|
||||||
@@ -55,6 +58,7 @@ public class TagController {
|
|||||||
* @return 是否删除成功
|
* @return 是否删除成功
|
||||||
*/
|
*/
|
||||||
@DeleteMapping("/delete/{id}")
|
@DeleteMapping("/delete/{id}")
|
||||||
|
@RequirePermission("tag:delete")
|
||||||
public Result<Boolean> deleteTag(@PathVariable Long id) {
|
public Result<Boolean> deleteTag(@PathVariable Long id) {
|
||||||
boolean success = tagService.deleteTag(id);
|
boolean success = tagService.deleteTag(id);
|
||||||
return Result.success(success);
|
return Result.success(success);
|
||||||
@@ -67,6 +71,7 @@ public class TagController {
|
|||||||
* @return 标签VO
|
* @return 标签VO
|
||||||
*/
|
*/
|
||||||
@GetMapping("/get/{id}")
|
@GetMapping("/get/{id}")
|
||||||
|
@RequirePermission("tag:view")
|
||||||
public Result<TagVO> getTagById(@PathVariable Long id) {
|
public Result<TagVO> getTagById(@PathVariable Long id) {
|
||||||
TagVO tagVO = tagService.getTagById(id);
|
TagVO tagVO = tagService.getTagById(id);
|
||||||
return Result.success(tagVO);
|
return Result.success(tagVO);
|
||||||
@@ -78,6 +83,7 @@ public class TagController {
|
|||||||
* @return 标签VO列表
|
* @return 标签VO列表
|
||||||
*/
|
*/
|
||||||
@GetMapping("/list/all")
|
@GetMapping("/list/all")
|
||||||
|
@RequirePermission("tag:view")
|
||||||
public Result<List<TagVO>> listAllTags() {
|
public Result<List<TagVO>> listAllTags() {
|
||||||
List<TagVO> tagVOs = tagService.listAllTags();
|
List<TagVO> tagVOs = tagService.listAllTags();
|
||||||
return Result.success(tagVOs);
|
return Result.success(tagVOs);
|
||||||
@@ -90,6 +96,7 @@ public class TagController {
|
|||||||
* @return 标签VO列表
|
* @return 标签VO列表
|
||||||
*/
|
*/
|
||||||
@GetMapping("/list/by-shop/{shopId}")
|
@GetMapping("/list/by-shop/{shopId}")
|
||||||
|
@RequirePermission("tag:view")
|
||||||
public Result<List<TagVO>> listTagsByShopId(@PathVariable Long shopId) {
|
public Result<List<TagVO>> listTagsByShopId(@PathVariable Long shopId) {
|
||||||
List<TagVO> tagVOs = tagService.listTagsByShopId(shopId);
|
List<TagVO> tagVOs = tagService.listTagsByShopId(shopId);
|
||||||
return Result.success(tagVOs);
|
return Result.success(tagVOs);
|
||||||
@@ -102,6 +109,7 @@ public class TagController {
|
|||||||
* @return 标签VO
|
* @return 标签VO
|
||||||
*/
|
*/
|
||||||
@GetMapping("/get/tagName/{tagName}")
|
@GetMapping("/get/tagName/{tagName}")
|
||||||
|
@RequirePermission("tag:view")
|
||||||
public Result<TagVO> getTagByTagName(@PathVariable String tagName) {
|
public Result<TagVO> getTagByTagName(@PathVariable String tagName) {
|
||||||
TagVO tagVO = tagService.getTagByTagName(tagName);
|
TagVO tagVO = tagService.getTagByTagName(tagName);
|
||||||
return Result.success(tagVO);
|
return Result.success(tagVO);
|
||||||
|
|||||||
@@ -57,6 +57,11 @@ public class CouponDTO {
|
|||||||
*/
|
*/
|
||||||
private LocalDateTime endTime;
|
private LocalDateTime endTime;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 所属店铺ID
|
||||||
|
*/
|
||||||
|
private Long shopId;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 可用标签ID列表
|
* 可用标签ID列表
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -72,6 +72,11 @@ public class CouponDO extends BaseEntity {
|
|||||||
*/
|
*/
|
||||||
private Integer status;
|
private Integer status;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 所属店铺ID
|
||||||
|
*/
|
||||||
|
private Long shopId;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 逻辑删除:0-未删,1-已删
|
* 逻辑删除:0-未删,1-已删
|
||||||
*/
|
*/
|
||||||
|
|||||||
+2
-11
@@ -83,20 +83,11 @@ public interface PermissionService extends IService<PermissionDO> {
|
|||||||
boolean assignPermissions(UserPermissionDTO userPermissionDTO, Long currentUserId);
|
boolean assignPermissions(UserPermissionDTO userPermissionDTO, Long currentUserId);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 检查用户是否有指定权限
|
* 检查用户是否拥有指定权限
|
||||||
*
|
*
|
||||||
* @param userId 用户ID
|
* @param userId 用户ID
|
||||||
* @param permissionCode 权限编码
|
* @param permissionCode 权限编码
|
||||||
* @return 是否有权限
|
* @return 是否拥有权限
|
||||||
*/
|
*/
|
||||||
boolean hasPermission(Long userId, String permissionCode);
|
boolean hasPermission(Long userId, String permissionCode);
|
||||||
|
|
||||||
/**
|
|
||||||
* 根据用户类型判断是否有权限(基于用户级别)
|
|
||||||
*
|
|
||||||
* @param userType 用户类型
|
|
||||||
* @param requireType 需要的最低用户类型
|
|
||||||
* @return 是否有权限
|
|
||||||
*/
|
|
||||||
boolean hasPermissionByType(Integer userType, Integer requireType);
|
|
||||||
}
|
}
|
||||||
|
|||||||
+13
@@ -11,6 +11,7 @@ import com.xiaowang.yuminailcore.entity.TagDO;
|
|||||||
import com.xiaowang.yuminailcore.entity.UserCouponDO;
|
import com.xiaowang.yuminailcore.entity.UserCouponDO;
|
||||||
import com.xiaowang.yuminailcore.mapper.CouponMapper;
|
import com.xiaowang.yuminailcore.mapper.CouponMapper;
|
||||||
import com.xiaowang.yuminailcore.mapper.CouponTagMapper;
|
import com.xiaowang.yuminailcore.mapper.CouponTagMapper;
|
||||||
|
import com.xiaowang.yuminailcore.mapper.ShopMapper;
|
||||||
import com.xiaowang.yuminailcore.mapper.TagMapper;
|
import com.xiaowang.yuminailcore.mapper.TagMapper;
|
||||||
import com.xiaowang.yuminailcore.mapper.UserCouponMapper;
|
import com.xiaowang.yuminailcore.mapper.UserCouponMapper;
|
||||||
import com.xiaowang.yuminailcore.service.CouponService;
|
import com.xiaowang.yuminailcore.service.CouponService;
|
||||||
@@ -38,6 +39,7 @@ public class CouponServiceImpl extends ServiceImpl<CouponMapper, CouponDO> imple
|
|||||||
private final CouponTagMapper couponTagMapper;
|
private final CouponTagMapper couponTagMapper;
|
||||||
private final UserCouponMapper userCouponMapper;
|
private final UserCouponMapper userCouponMapper;
|
||||||
private final TagMapper tagMapper;
|
private final TagMapper tagMapper;
|
||||||
|
private final ShopMapper shopMapper;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@Transactional
|
@Transactional
|
||||||
@@ -55,6 +57,7 @@ public class CouponServiceImpl extends ServiceImpl<CouponMapper, CouponDO> imple
|
|||||||
couponDO.setStartTime(couponDTO.getStartTime());
|
couponDO.setStartTime(couponDTO.getStartTime());
|
||||||
couponDO.setEndTime(couponDTO.getEndTime());
|
couponDO.setEndTime(couponDTO.getEndTime());
|
||||||
couponDO.setStatus(1);
|
couponDO.setStatus(1);
|
||||||
|
couponDO.setShopId(shopId);
|
||||||
save(couponDO);
|
save(couponDO);
|
||||||
|
|
||||||
// 处理标签关联
|
// 处理标签关联
|
||||||
@@ -81,6 +84,7 @@ public class CouponServiceImpl extends ServiceImpl<CouponMapper, CouponDO> imple
|
|||||||
couponDO.setTotalCount(couponDTO.getTotalCount());
|
couponDO.setTotalCount(couponDTO.getTotalCount());
|
||||||
couponDO.setStartTime(couponDTO.getStartTime());
|
couponDO.setStartTime(couponDTO.getStartTime());
|
||||||
couponDO.setEndTime(couponDTO.getEndTime());
|
couponDO.setEndTime(couponDTO.getEndTime());
|
||||||
|
couponDO.setShopId(shopId);
|
||||||
updateById(couponDO);
|
updateById(couponDO);
|
||||||
|
|
||||||
// 处理标签关联
|
// 处理标签关联
|
||||||
@@ -408,6 +412,15 @@ public class CouponServiceImpl extends ServiceImpl<CouponMapper, CouponDO> imple
|
|||||||
couponVO.setStartTime(couponDO.getStartTime());
|
couponVO.setStartTime(couponDO.getStartTime());
|
||||||
couponVO.setEndTime(couponDO.getEndTime());
|
couponVO.setEndTime(couponDO.getEndTime());
|
||||||
couponVO.setStatus(couponDO.getStatus());
|
couponVO.setStatus(couponDO.getStatus());
|
||||||
|
couponVO.setShopId(couponDO.getShopId());
|
||||||
|
|
||||||
|
// 获取店铺名称
|
||||||
|
if (couponDO.getShopId() != null) {
|
||||||
|
com.xiaowang.yuminailcore.entity.ShopDO shopDO = shopMapper.selectById(couponDO.getShopId());
|
||||||
|
if (shopDO != null) {
|
||||||
|
couponVO.setShopName(shopDO.getShopName());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
switch (couponDO.getStatus()) {
|
switch (couponDO.getStatus()) {
|
||||||
case 1:
|
case 1:
|
||||||
|
|||||||
+6
-42
@@ -155,25 +155,17 @@ public class PermissionServiceImpl extends ServiceImpl<PermissionMapper, Permiss
|
|||||||
throw new RuntimeException("目标用户不存在");
|
throw new RuntimeException("目标用户不存在");
|
||||||
}
|
}
|
||||||
|
|
||||||
// 检查权限:只有管理员和店长可以给其他用户分配权限
|
// 检查权限:只有拥有权限分配权限的用户可以给其他用户分配权限
|
||||||
if (currentUser.getType() != 4 && currentUser.getType() != 2) {
|
if (!hasPermission(currentUserId, "permission:assign")) {
|
||||||
throw new RuntimeException("权限不足,只有管理员和店长可以分配权限");
|
throw new RuntimeException("权限不足,没有权限分配权限");
|
||||||
}
|
}
|
||||||
|
|
||||||
// 如果当前用户是店长(不是管理员),需要进一步检查
|
// 如果当前用户是店长,需要进一步检查
|
||||||
if (currentUser.getType() == 2) {
|
if (currentUser.getType() == 2) {
|
||||||
// 店长只能给属于自己店铺的美甲师分配权限
|
// 店长只能给属于自己店铺的用户分配权限
|
||||||
if (targetUser.getShopId() == null || !targetUser.getShopId().equals(currentUser.getShopId())) {
|
if (targetUser.getShopId() == null || !targetUser.getShopId().equals(currentUser.getShopId())) {
|
||||||
throw new RuntimeException("权限不足,只能给本店铺的美甲师分配权限");
|
throw new RuntimeException("权限不足,只能给本店铺的用户分配权限");
|
||||||
}
|
}
|
||||||
|
|
||||||
// 店长只能给美甲师(type=3)分配权限
|
|
||||||
if (targetUser.getType() != 3) {
|
|
||||||
throw new RuntimeException("权限不足,只能给美甲师分配权限");
|
|
||||||
}
|
|
||||||
|
|
||||||
// 这里可以添加更多逻辑,例如检查权限是否与当前店铺相关
|
|
||||||
// 由于当前权限系统没有与店铺关联,暂时跳过这一步
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// 删除旧的权限分配
|
// 删除旧的权限分配
|
||||||
@@ -198,12 +190,6 @@ public class PermissionServiceImpl extends ServiceImpl<PermissionMapper, Permiss
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean hasPermission(Long userId, String permissionCode) {
|
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(
|
List<UserPermissionDO> userPermissions = userPermissionMapper.selectList(
|
||||||
Wrappers.lambdaQuery(UserPermissionDO.class)
|
Wrappers.lambdaQuery(UserPermissionDO.class)
|
||||||
.eq(UserPermissionDO::getUserId, userId)
|
.eq(UserPermissionDO::getUserId, userId)
|
||||||
@@ -230,28 +216,6 @@ public class PermissionServiceImpl extends ServiceImpl<PermissionMapper, Permiss
|
|||||||
return permissionIds.contains(permissionDO.getId());
|
return permissionIds.contains(permissionDO.getId());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean hasPermissionByType(Integer userType, Integer requireType) {
|
|
||||||
if (userType == null || requireType == null) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
// 管理员(4)拥有最高权限
|
|
||||||
if (userType == 4) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
// 店长(2)的权限高于美甲师(3)
|
|
||||||
if (userType == 2) {
|
|
||||||
// 店长可以访问需要店长或美甲师权限的接口
|
|
||||||
return requireType == 2 || requireType == 3;
|
|
||||||
}
|
|
||||||
// 美甲师(3)只能访问需要美甲师权限的接口
|
|
||||||
if (userType == 3) {
|
|
||||||
return requireType == 3;
|
|
||||||
}
|
|
||||||
// 用户(0)只能访问需要用户权限的接口
|
|
||||||
return userType >= requireType;
|
|
||||||
}
|
|
||||||
|
|
||||||
private PermissionVO convertToVO(PermissionDO permissionDO) {
|
private PermissionVO convertToVO(PermissionDO permissionDO) {
|
||||||
PermissionVO permissionVO = new PermissionVO();
|
PermissionVO permissionVO = new PermissionVO();
|
||||||
permissionVO.setId(permissionDO.getId());
|
permissionVO.setId(permissionDO.getId());
|
||||||
|
|||||||
+93
-6
@@ -10,7 +10,11 @@ import com.xiaowang.yuminailcore.dto.LoginRequestDTO;
|
|||||||
import com.xiaowang.yuminailcore.dto.RegisterRequestDTO;
|
import com.xiaowang.yuminailcore.dto.RegisterRequestDTO;
|
||||||
import com.xiaowang.yuminailcore.dto.UserDTO;
|
import com.xiaowang.yuminailcore.dto.UserDTO;
|
||||||
import com.xiaowang.yuminailcore.entity.UserDO;
|
import com.xiaowang.yuminailcore.entity.UserDO;
|
||||||
|
import com.xiaowang.yuminailcore.entity.UserPermissionDO;
|
||||||
|
import com.xiaowang.yuminailcore.entity.PermissionDO;
|
||||||
import com.xiaowang.yuminailcore.mapper.UserMapper;
|
import com.xiaowang.yuminailcore.mapper.UserMapper;
|
||||||
|
import com.xiaowang.yuminailcore.mapper.UserPermissionMapper;
|
||||||
|
import com.xiaowang.yuminailcore.mapper.PermissionMapper;
|
||||||
import com.xiaowang.yuminailcore.service.ShopService;
|
import com.xiaowang.yuminailcore.service.ShopService;
|
||||||
import com.xiaowang.yuminailcore.service.UserService;
|
import com.xiaowang.yuminailcore.service.UserService;
|
||||||
import com.xiaowang.yuminailcore.utils.JwtUtil;
|
import com.xiaowang.yuminailcore.utils.JwtUtil;
|
||||||
@@ -19,7 +23,9 @@ import com.xiaowang.yuminailcore.vo.PageResultVO;
|
|||||||
import com.xiaowang.yuminailcore.vo.UserVO;
|
import com.xiaowang.yuminailcore.vo.UserVO;
|
||||||
import com.xiaowang.yuminailcore.vo.ShopVO;
|
import com.xiaowang.yuminailcore.vo.ShopVO;
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
|
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
import org.springframework.util.StringUtils;
|
import org.springframework.util.StringUtils;
|
||||||
|
|
||||||
import java.time.LocalDateTime;
|
import java.time.LocalDateTime;
|
||||||
@@ -41,6 +47,9 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, UserDO> implements
|
|||||||
private final UserMapper userMapper;
|
private final UserMapper userMapper;
|
||||||
private final JwtUtil jwtUtil;
|
private final JwtUtil jwtUtil;
|
||||||
private final ShopService shopService;
|
private final ShopService shopService;
|
||||||
|
private final UserPermissionMapper userPermissionMapper;
|
||||||
|
private final PermissionMapper permissionMapper;
|
||||||
|
private final BCryptPasswordEncoder passwordEncoder = new BCryptPasswordEncoder();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 创建新用户
|
* 创建新用户
|
||||||
@@ -48,6 +57,7 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, UserDO> implements
|
|||||||
* @return 新创建用户的ID
|
* @return 新创建用户的ID
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
|
@Transactional(rollbackFor = Exception.class)
|
||||||
public Long createUser(UserDTO userDTO) {
|
public Long createUser(UserDTO userDTO) {
|
||||||
// 检查账号是否已存在
|
// 检查账号是否已存在
|
||||||
UserDO existingUser = userMapper.selectOne(
|
UserDO existingUser = userMapper.selectOne(
|
||||||
@@ -64,7 +74,7 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, UserDO> implements
|
|||||||
userDO.setShopId(userDTO.getShopId());
|
userDO.setShopId(userDTO.getShopId());
|
||||||
userDO.setNickname(userDTO.getNickname());
|
userDO.setNickname(userDTO.getNickname());
|
||||||
userDO.setAccount(userDTO.getAccount());
|
userDO.setAccount(userDTO.getAccount());
|
||||||
userDO.setPassword(userDTO.getPassword());
|
userDO.setPassword(passwordEncoder.encode(userDTO.getPassword()));
|
||||||
userDO.setPhone(userDTO.getPhone());
|
userDO.setPhone(userDTO.getPhone());
|
||||||
userDO.setSignature(userDTO.getSignature());
|
userDO.setSignature(userDTO.getSignature());
|
||||||
userDO.setLevel(userDTO.getLevel());
|
userDO.setLevel(userDTO.getLevel());
|
||||||
@@ -87,8 +97,83 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, UserDO> implements
|
|||||||
throw e;
|
throw e;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 分配默认权限
|
||||||
|
assignDefaultPermissions(userDO.getId(), userDO.getType());
|
||||||
|
|
||||||
return userDO.getId();
|
return userDO.getId();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 分配默认权限
|
||||||
|
* @param userId 用户ID
|
||||||
|
* @param userType 用户类型
|
||||||
|
*/
|
||||||
|
private void assignDefaultPermissions(Long userId, Integer userType) {
|
||||||
|
List<PermissionDO> permissions = null;
|
||||||
|
|
||||||
|
if (userType == 4) { // 管理员
|
||||||
|
// 分配所有权限
|
||||||
|
permissions = permissionMapper.selectList(
|
||||||
|
Wrappers.lambdaQuery(PermissionDO.class)
|
||||||
|
.eq(PermissionDO::getIsDelete, 0)
|
||||||
|
);
|
||||||
|
} else if (userType == 2) { // 店长
|
||||||
|
// 分配店长默认权限
|
||||||
|
// 首页的全部权限
|
||||||
|
// 仪表盘的全部权限
|
||||||
|
// 当前店铺的用户管理的全部权限
|
||||||
|
// 当前店铺的商品管理的全部权限
|
||||||
|
// 当前店铺的店铺管理的全部权限
|
||||||
|
// 当前店铺的权限管理的全部权限
|
||||||
|
// 当前店铺的标签管理的全部权限
|
||||||
|
// 当前店铺的优惠券管理的全部权限
|
||||||
|
// 当前店铺的订单管理的全部权限
|
||||||
|
permissions = permissionMapper.selectList(
|
||||||
|
Wrappers.lambdaQuery(PermissionDO.class)
|
||||||
|
.eq(PermissionDO::getIsDelete, 0)
|
||||||
|
.in(PermissionDO::getPermissionCode, "home:view", "dashboard:view", "user:view",
|
||||||
|
"user:create", "user:edit", "user:reset_password", "user:delete",
|
||||||
|
"product:view", "product:create", "product:edit", "product:delete",
|
||||||
|
"product:category:manage", "shop:view", "shop:create", "shop:edit",
|
||||||
|
"shop:delete", "shop:staff:manage", "permission:view", "permission:create",
|
||||||
|
"permission:edit", "permission:delete", "permission:assign",
|
||||||
|
"tag:view", "tag:create", "tag:edit", "tag:delete", "tag:assign",
|
||||||
|
"coupon:view", "coupon:create", "coupon:edit", "coupon:delete",
|
||||||
|
"coupon:assign", "order:view", "order:edit", "order:delete",
|
||||||
|
"order:process")
|
||||||
|
);
|
||||||
|
} else if (userType == 3) { // 美甲师
|
||||||
|
// 分配美甲师默认权限
|
||||||
|
// 首页的全部权限
|
||||||
|
// 仪表盘的全部权限
|
||||||
|
// 当前店铺的用户管理的查看权限,新增权限,密码重置权限,其他无
|
||||||
|
// 当前店铺的商品管理的查看权限,新增权限,编辑权限,管理商品分类权限
|
||||||
|
// 当前店铺的店铺管理的查看权限,无其他权限
|
||||||
|
// 无当前店铺的权限管理的全部权限
|
||||||
|
// 当前店铺的标签管理的查看,新增,编辑,分配权限,无删除权限
|
||||||
|
// 当前店铺的优惠券管理的查看和分配权限,无其他权限
|
||||||
|
// 当前店铺的订单管理的查看和处理权限
|
||||||
|
permissions = permissionMapper.selectList(
|
||||||
|
Wrappers.lambdaQuery(PermissionDO.class)
|
||||||
|
.eq(PermissionDO::getIsDelete, 0)
|
||||||
|
.in(PermissionDO::getPermissionCode, "home:view", "dashboard:view", "user:view",
|
||||||
|
"user:create", "user:reset_password", "product:view", "product:create",
|
||||||
|
"product:edit", "product:category:manage", "shop:view",
|
||||||
|
"tag:view", "tag:create", "tag:edit", "tag:assign",
|
||||||
|
"coupon:view", "coupon:assign", "order:view", "order:process")
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (permissions != null && !permissions.isEmpty()) {
|
||||||
|
for (PermissionDO permission : permissions) {
|
||||||
|
UserPermissionDO userPermissionDO = new UserPermissionDO();
|
||||||
|
userPermissionDO.setUserId(userId);
|
||||||
|
userPermissionDO.setPermissionId(permission.getId());
|
||||||
|
userPermissionDO.setCreateBy(userId); // 设置创建人为当前用户
|
||||||
|
userPermissionMapper.insert(userPermissionDO);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 更新用户信息
|
* 更新用户信息
|
||||||
@@ -125,7 +210,7 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, UserDO> implements
|
|||||||
userDO.setNickname(userDTO.getNickname());
|
userDO.setNickname(userDTO.getNickname());
|
||||||
}
|
}
|
||||||
if (userDTO.getPassword() != null) {
|
if (userDTO.getPassword() != null) {
|
||||||
userDO.setPassword(userDTO.getPassword());
|
userDO.setPassword(passwordEncoder.encode(userDTO.getPassword()));
|
||||||
}
|
}
|
||||||
if (userDTO.getPhone() != null) {
|
if (userDTO.getPhone() != null) {
|
||||||
userDO.setPhone(userDTO.getPhone());
|
userDO.setPhone(userDTO.getPhone());
|
||||||
@@ -285,7 +370,7 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, UserDO> implements
|
|||||||
throw new RuntimeException("用户不存在");
|
throw new RuntimeException("用户不存在");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!userDO.getPassword().equals(loginRequestDTO.getPassword())) {
|
if (!passwordEncoder.matches(loginRequestDTO.getPassword(), userDO.getPassword())) {
|
||||||
throw new RuntimeException("密码错误");
|
throw new RuntimeException("密码错误");
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -319,7 +404,7 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, UserDO> implements
|
|||||||
throw new RuntimeException("用户不存在");
|
throw new RuntimeException("用户不存在");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!userDO.getPassword().equals(loginRequestDTO.getPassword())) {
|
if (!passwordEncoder.matches(loginRequestDTO.getPassword(), userDO.getPassword())) {
|
||||||
throw new RuntimeException("密码错误");
|
throw new RuntimeException("密码错误");
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -361,7 +446,7 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, UserDO> implements
|
|||||||
UserDO userDO = new UserDO();
|
UserDO userDO = new UserDO();
|
||||||
userDO.setShopId(registerRequestDTO.getShopId());
|
userDO.setShopId(registerRequestDTO.getShopId());
|
||||||
userDO.setAccount(registerRequestDTO.getAccount());
|
userDO.setAccount(registerRequestDTO.getAccount());
|
||||||
userDO.setPassword(registerRequestDTO.getPassword());
|
userDO.setPassword(passwordEncoder.encode(registerRequestDTO.getPassword()));
|
||||||
userDO.setNickname(registerRequestDTO.getNickname());
|
userDO.setNickname(registerRequestDTO.getNickname());
|
||||||
userDO.setType(Integer.valueOf(0));
|
userDO.setType(Integer.valueOf(0));
|
||||||
userDO.setLevel("普通");
|
userDO.setLevel("普通");
|
||||||
@@ -471,7 +556,7 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, UserDO> implements
|
|||||||
throw new RuntimeException("权限不足,只能重置比自己级别低的用户密码");
|
throw new RuntimeException("权限不足,只能重置比自己级别低的用户密码");
|
||||||
}
|
}
|
||||||
|
|
||||||
targetUser.setPassword("88888888");
|
targetUser.setPassword(passwordEncoder.encode("88888888"));
|
||||||
targetUser.setUpdateTime(LocalDateTime.now());
|
targetUser.setUpdateTime(LocalDateTime.now());
|
||||||
|
|
||||||
return userMapper.updateById(targetUser) > 0;
|
return userMapper.updateById(targetUser) > 0;
|
||||||
@@ -483,6 +568,8 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, UserDO> implements
|
|||||||
|
|
||||||
LambdaQueryWrapper<UserDO> wrapper = Wrappers.lambdaQuery(UserDO.class);
|
LambdaQueryWrapper<UserDO> wrapper = Wrappers.lambdaQuery(UserDO.class);
|
||||||
wrapper.eq(UserDO::getIsDelete, 0);
|
wrapper.eq(UserDO::getIsDelete, 0);
|
||||||
|
// 过滤掉普通用户(type为0)
|
||||||
|
wrapper.ne(UserDO::getType, 0);
|
||||||
if (StringUtils.hasText(keyword)) {
|
if (StringUtils.hasText(keyword)) {
|
||||||
wrapper.and(w -> w.like(UserDO::getAccount, keyword)
|
wrapper.and(w -> w.like(UserDO::getAccount, keyword)
|
||||||
.or().like(UserDO::getNickname, keyword)
|
.or().like(UserDO::getNickname, keyword)
|
||||||
|
|||||||
@@ -87,6 +87,16 @@ public class CouponVO {
|
|||||||
*/
|
*/
|
||||||
private String statusName;
|
private String statusName;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 所属店铺ID
|
||||||
|
*/
|
||||||
|
private Long shopId;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 所属店铺名称
|
||||||
|
*/
|
||||||
|
private String shopName;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 可用标签列表
|
* 可用标签列表
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -333,9 +333,10 @@ create index idx_vip_level
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
-- 清空现有权限数据(可选,根据需要执行)
|
-- 清空现有数据
|
||||||
DELETE FROM t_user_permission WHERE 1=1;
|
DELETE FROM t_user_permission WHERE 1=1;
|
||||||
DELETE FROM t_permission WHERE 1=1;
|
DELETE FROM t_permission WHERE 1=1;
|
||||||
|
DELETE FROM t_user WHERE 1=1;
|
||||||
|
|
||||||
-- 插入完整的系统权限
|
-- 插入完整的系统权限
|
||||||
INSERT INTO t_permission (permission_code, permission_name, permission_group, description, create_time, update_time, is_delete) VALUES
|
INSERT INTO t_permission (permission_code, permission_name, permission_group, description, create_time, update_time, is_delete) VALUES
|
||||||
@@ -377,77 +378,73 @@ INSERT INTO t_permission (permission_code, permission_name, permission_group, de
|
|||||||
('tag:view', '查看标签', '标签管理', '查看标签列表和详情', NOW(), NOW(), 0),
|
('tag:view', '查看标签', '标签管理', '查看标签列表和详情', NOW(), NOW(), 0),
|
||||||
('tag:create', '新增标签', '标签管理', '新增标签', NOW(), NOW(), 0),
|
('tag:create', '新增标签', '标签管理', '新增标签', NOW(), NOW(), 0),
|
||||||
('tag:edit', '编辑标签', '标签管理', '编辑标签信息', NOW(), NOW(), 0),
|
('tag:edit', '编辑标签', '标签管理', '编辑标签信息', NOW(), NOW(), 0),
|
||||||
('tag:delete', '删除标签', '标签管理', '删除标签', NOW(), NOW(), 0);
|
('tag:delete', '删除标签', '标签管理', '删除标签', NOW(), NOW(), 0),
|
||||||
|
('tag:assign', '分配标签', '标签管理', '为商品分配标签', NOW(), NOW(), 0),
|
||||||
|
|
||||||
|
-- 优惠券管理权限
|
||||||
|
('coupon:view', '查看优惠券', '优惠券管理', '查看优惠券列表和详情', NOW(), NOW(), 0),
|
||||||
|
('coupon:create', '新增优惠券', '优惠券管理', '新增优惠券', NOW(), NOW(), 0),
|
||||||
|
('coupon:edit', '编辑优惠券', '优惠券管理', '编辑优惠券信息', NOW(), NOW(), 0),
|
||||||
|
('coupon:delete', '删除优惠券', '优惠券管理', '删除优惠券', NOW(), NOW(), 0),
|
||||||
|
('coupon:assign', '分配优惠券', '优惠券管理', '为用户分配优惠券', NOW(), NOW(), 0),
|
||||||
|
|
||||||
-- 为管理员(type=4)分配所有权限
|
-- 订单管理权限
|
||||||
INSERT INTO t_user_permission (user_id, permission_id, create_time, update_time)
|
('order:view', '查看订单', '订单管理', '查看订单列表和详情', NOW(), NOW(), 0),
|
||||||
SELECT
|
('order:edit', '编辑订单', '订单管理', '编辑订单信息', NOW(), NOW(), 0),
|
||||||
u.id as user_id,
|
('order:delete', '删除订单', '订单管理', '删除订单', NOW(), NOW(), 0),
|
||||||
p.id as permission_id,
|
('order:process', '处理订单', '订单管理', '处理订单状态', NOW(), NOW(), 0);
|
||||||
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;
|
|
||||||
|
|
||||||
-- 为店长(type=2)分配默认权限
|
-- 初始化admin用户,密码为123456
|
||||||
INSERT INTO t_user_permission (user_id, permission_id, create_time, update_time)
|
-- 密码使用BCrypt加密,123456的加密值为:$2a$10$EixZaYVK1fsbw1ZfbX3OXePaWxn96p36WQoeG6Lruj3vjPGga31lW
|
||||||
SELECT
|
INSERT INTO t_user (id, shop_id, nickname, account, password, type, status, create_time, update_time, is_delete) VALUES
|
||||||
u.id as user_id,
|
(1, 0, '管理员', 'admin', '$2a$10$EixZaYVK1fsbw1ZfbX3OXePaWxn96p36WQoeG6Lruj3vjPGga31lW', 4, 1, NOW(), NOW(), 0);
|
||||||
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 (
|
|
||||||
'home:view',
|
|
||||||
'dashboard:view',
|
|
||||||
'user:view',
|
|
||||||
'user:create',
|
|
||||||
'user:edit',
|
|
||||||
'user:reset_password',
|
|
||||||
'user:delete',
|
|
||||||
'product:view',
|
|
||||||
'product:create',
|
|
||||||
'product:edit',
|
|
||||||
'product:delete',
|
|
||||||
'product:category:manage',
|
|
||||||
'shop:view',
|
|
||||||
'shop:edit',
|
|
||||||
'permission:view',
|
|
||||||
'permission:assign',
|
|
||||||
'tag:view',
|
|
||||||
'tag:create',
|
|
||||||
'tag:edit',
|
|
||||||
'tag:delete'
|
|
||||||
);
|
|
||||||
|
|
||||||
|
-- 为管理员分配权限
|
||||||
|
-- 首页的全部权限
|
||||||
|
-- 仪表盘的全部权限
|
||||||
|
-- 所有店铺的用户管理的全部权限
|
||||||
|
-- 所有店铺的商品管理的查看权限,无新增编辑删除管理商品分类权限
|
||||||
|
-- 所有店铺的店铺管理的全部权限
|
||||||
|
-- 所有店铺的权限管理的全部权限
|
||||||
|
-- 所有店铺的标签管理的查看权限无新增编辑删除权限
|
||||||
|
-- 所有店铺的优惠券管理的查看权限
|
||||||
|
-- 所有店铺的订单管理的查看权限
|
||||||
|
INSERT INTO t_user_permission (user_id, permission_id, create_time, update_time, create_by)
|
||||||
|
SELECT
|
||||||
|
1 as user_id,
|
||||||
|
p.id as permission_id,
|
||||||
|
NOW() as create_time,
|
||||||
|
NOW() as update_time,
|
||||||
|
1 as create_by
|
||||||
|
FROM t_permission p
|
||||||
|
WHERE p.is_delete = 0
|
||||||
|
AND p.permission_code IN (
|
||||||
|
'home:view',
|
||||||
|
'dashboard:view',
|
||||||
|
'user:view',
|
||||||
|
'user:create',
|
||||||
|
'user:edit',
|
||||||
|
'user:reset_password',
|
||||||
|
'user:delete',
|
||||||
|
'product:view',
|
||||||
|
'shop:view',
|
||||||
|
'shop:create',
|
||||||
|
'shop:edit',
|
||||||
|
'shop:delete',
|
||||||
|
'shop:staff:manage',
|
||||||
|
'permission:view',
|
||||||
|
'permission:create',
|
||||||
|
'permission:edit',
|
||||||
|
'permission:delete',
|
||||||
|
'permission:assign',
|
||||||
|
'tag:view',
|
||||||
|
'coupon:view',
|
||||||
|
'order:view'
|
||||||
|
);
|
||||||
|
|
||||||
-- 为美甲师(type=3)分配默认权限
|
-- 注意:店长和美甲师的权限需要在系统中手动分配,因为需要关联具体的店铺
|
||||||
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 = 3
|
|
||||||
AND p.is_delete = 0
|
|
||||||
AND p.permission_code IN (
|
|
||||||
'home:view',
|
|
||||||
'user:view',
|
|
||||||
'user:reset_password',
|
|
||||||
'product:view',
|
|
||||||
'product:create',
|
|
||||||
'product:edit'
|
|
||||||
);
|
|
||||||
|
|
||||||
use nailart;
|
|
||||||
-- 优惠券信息表
|
-- 优惠券信息表
|
||||||
create table t_coupon
|
create table t_coupon
|
||||||
(
|
(
|
||||||
@@ -464,6 +461,7 @@ create table t_coupon
|
|||||||
start_time datetime not null comment '开始时间',
|
start_time datetime not null comment '开始时间',
|
||||||
end_time datetime not null comment '结束时间',
|
end_time datetime not null comment '结束时间',
|
||||||
status tinyint unsigned default 1 not null comment '状态:1-可用,2-已过期,3-已用完',
|
status tinyint unsigned default 1 not null comment '状态:1-可用,2-已过期,3-已用完',
|
||||||
|
shop_id bigint unsigned not null comment '所属店铺ID',
|
||||||
create_time datetime default CURRENT_TIMESTAMP 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 '更新时间',
|
update_time datetime default CURRENT_TIMESTAMP not null on update CURRENT_TIMESTAMP comment '更新时间',
|
||||||
is_delete tinyint unsigned default 0 null comment '逻辑删除:0-未删,1-已删',
|
is_delete tinyint unsigned default 0 null comment '逻辑删除:0-未删,1-已删',
|
||||||
@@ -474,6 +472,9 @@ create table t_coupon
|
|||||||
create index idx_status
|
create index idx_status
|
||||||
on t_coupon (status) comment '按状态查询优惠券的索引';
|
on t_coupon (status) comment '按状态查询优惠券的索引';
|
||||||
|
|
||||||
|
create index idx_shop_id
|
||||||
|
on t_coupon (shop_id) comment '按店铺查询优惠券的索引';
|
||||||
|
|
||||||
-- 用户优惠券关联表
|
-- 用户优惠券关联表
|
||||||
create table t_user_coupon
|
create table t_user_coupon
|
||||||
(
|
(
|
||||||
@@ -518,54 +519,6 @@ create index idx_coupon_id
|
|||||||
create index idx_tag_id
|
create index idx_tag_id
|
||||||
on t_coupon_tag (tag_id) comment '按标签查询优惠券的索引';
|
on t_coupon_tag (tag_id) comment '按标签查询优惠券的索引';
|
||||||
|
|
||||||
-- 插入优惠券管理相关权限
|
|
||||||
INSERT INTO t_permission (permission_code, permission_name, permission_group, description, create_time, update_time, is_delete) VALUES
|
|
||||||
('coupon:view', '查看优惠券', '优惠券管理', '查看优惠券列表和详情', NOW(), NOW(), 0),
|
|
||||||
('coupon:create', '新增优惠券', '优惠券管理', '新增优惠券', NOW(), NOW(), 0),
|
|
||||||
('coupon:edit', '编辑优惠券', '优惠券管理', '编辑优惠券信息', NOW(), NOW(), 0),
|
|
||||||
('coupon:delete', '删除优惠券', '优惠券管理', '删除优惠券', NOW(), NOW(), 0),
|
|
||||||
('coupon:assign', '分配优惠券', '优惠券管理', '为用户分配优惠券', 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 (
|
|
||||||
'coupon:view',
|
|
||||||
'coupon:create',
|
|
||||||
'coupon:edit',
|
|
||||||
'coupon:delete',
|
|
||||||
'coupon:assign'
|
|
||||||
);
|
|
||||||
|
|
||||||
-- 为店长(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 (
|
|
||||||
'coupon:view',
|
|
||||||
'coupon:create',
|
|
||||||
'coupon:edit',
|
|
||||||
'coupon:delete',
|
|
||||||
'coupon:assign'
|
|
||||||
);
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
-- 购物车表
|
-- 购物车表
|
||||||
create table t_cart
|
create table t_cart
|
||||||
(
|
(
|
||||||
@@ -623,47 +576,4 @@ create table t_order_item
|
|||||||
) comment '订单商品表';
|
) comment '订单商品表';
|
||||||
|
|
||||||
create index idx_order_id
|
create index idx_order_id
|
||||||
on t_order_item (order_id) comment '按订单查询商品的索引';
|
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'
|
|
||||||
);
|
|
||||||
+2
-1
@@ -77,7 +77,8 @@ public class AuthGlobalFilter implements GlobalFilter, Ordered {
|
|||||||
path.equals("/api/shop/list/simple") ||
|
path.equals("/api/shop/list/simple") ||
|
||||||
path.equals("/api/admin/auth/login") ||
|
path.equals("/api/admin/auth/login") ||
|
||||||
path.equals("/admin/api/auth/login") ||
|
path.equals("/admin/api/auth/login") ||
|
||||||
path.contains("/api/user/get/account");
|
path.startsWith("/api/user/get/account") ||
|
||||||
|
path.startsWith("/api/health");
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Reference in New Issue
Block a user