杂务:打包并提交当前改动
This commit is contained in:
Generated
+10
@@ -0,0 +1,10 @@
|
|||||||
|
# Default ignored files
|
||||||
|
/shelf/
|
||||||
|
/workspace.xml
|
||||||
|
# Editor-based HTTP Client requests
|
||||||
|
/httpRequests/
|
||||||
|
# Environment-dependent path to Maven home directory
|
||||||
|
/mavenHomeManager.xml
|
||||||
|
# Datasource local storage ignored files
|
||||||
|
/dataSources/
|
||||||
|
/dataSources.local.xml
|
||||||
Generated
+31
@@ -0,0 +1,31 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="CompilerConfiguration">
|
||||||
|
<annotationProcessing>
|
||||||
|
<profile default="true" name="Default" enabled="true" />
|
||||||
|
<profile name="Maven default annotation processors profile" enabled="true">
|
||||||
|
<sourceOutputDir name="target/generated-sources/annotations" />
|
||||||
|
<sourceTestOutputDir name="target/generated-test-sources/test-annotations" />
|
||||||
|
<outputRelativeToContentRoot value="true" />
|
||||||
|
<module name="MessageHub" />
|
||||||
|
<module name="YumiNail-Gateway" />
|
||||||
|
</profile>
|
||||||
|
<profile name="Annotation profile for YumiNail-Core" enabled="true">
|
||||||
|
<sourceOutputDir name="target/generated-sources/annotations" />
|
||||||
|
<sourceTestOutputDir name="target/generated-test-sources/test-annotations" />
|
||||||
|
<outputRelativeToContentRoot value="true" />
|
||||||
|
<processorPath useClasspath="false">
|
||||||
|
<entry name="D:/apache-maven-3.9.9/repository/xiaowang/org/projectlombok/lombok/1.18.30/lombok-1.18.30.jar" />
|
||||||
|
</processorPath>
|
||||||
|
<module name="YumiNail-Core" />
|
||||||
|
</profile>
|
||||||
|
</annotationProcessing>
|
||||||
|
</component>
|
||||||
|
<component name="JavacSettings">
|
||||||
|
<option name="ADDITIONAL_OPTIONS_OVERRIDE">
|
||||||
|
<module name="MessageHub" options="-parameters" />
|
||||||
|
<module name="YumiNail-Core" options="-parameters" />
|
||||||
|
<module name="YumiNail-Gateway" options="-parameters" />
|
||||||
|
</option>
|
||||||
|
</component>
|
||||||
|
</project>
|
||||||
Generated
+18
@@ -0,0 +1,18 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="DataSourceManagerImpl" format="xml" multifile-model="true">
|
||||||
|
<data-source source="LOCAL" name="数据库主机MySQL" uuid="be706182-5671-4008-8a57-d492f13218b5">
|
||||||
|
<driver-ref>mysql_aurora.aws_wrapper</driver-ref>
|
||||||
|
<synchronize>true</synchronize>
|
||||||
|
<jdbc-driver>software.amazon.jdbc.Driver</jdbc-driver>
|
||||||
|
<jdbc-url>jdbc:aws-wrapper:mysql://wcy111.top:3306</jdbc-url>
|
||||||
|
<jdbc-additional-properties>
|
||||||
|
<property name="com.intellij.clouds.kubernetes.db.host.port" />
|
||||||
|
<property name="com.intellij.clouds.kubernetes.db.enabled" value="false" />
|
||||||
|
<property name="com.intellij.clouds.kubernetes.db.resource.type" value="Deployment" />
|
||||||
|
<property name="com.intellij.clouds.kubernetes.db.container.port" />
|
||||||
|
</jdbc-additional-properties>
|
||||||
|
<working-dir>$ProjectFileDir$</working-dir>
|
||||||
|
</data-source>
|
||||||
|
</component>
|
||||||
|
</project>
|
||||||
Generated
+8
@@ -0,0 +1,8 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="Encoding">
|
||||||
|
<file url="file://$PROJECT_DIR$/MessageHub/src/main/java" charset="UTF-8" />
|
||||||
|
<file url="file://$PROJECT_DIR$/YumiNail-Core/src/main/java" charset="UTF-8" />
|
||||||
|
<file url="file://$PROJECT_DIR$/YumiNail-Gateway/src/main/java" charset="UTF-8" />
|
||||||
|
</component>
|
||||||
|
</project>
|
||||||
Generated
+25
@@ -0,0 +1,25 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="RemoteRepositoriesConfiguration">
|
||||||
|
<remote-repository>
|
||||||
|
<option name="id" value="central" />
|
||||||
|
<option name="name" value="Central Repository" />
|
||||||
|
<option name="url" value="https://repo.maven.apache.org/maven2" />
|
||||||
|
</remote-repository>
|
||||||
|
<remote-repository>
|
||||||
|
<option name="id" value="central" />
|
||||||
|
<option name="name" value="Maven Central repository" />
|
||||||
|
<option name="url" value="https://repo1.maven.org/maven2" />
|
||||||
|
</remote-repository>
|
||||||
|
<remote-repository>
|
||||||
|
<option name="id" value="jboss.community" />
|
||||||
|
<option name="name" value="JBoss Community repository" />
|
||||||
|
<option name="url" value="https://repository.jboss.org/nexus/content/repositories/public/" />
|
||||||
|
</remote-repository>
|
||||||
|
<remote-repository>
|
||||||
|
<option name="id" value="central" />
|
||||||
|
<option name="name" value="Central Repository" />
|
||||||
|
<option name="url" value="https://maven.aliyun.com/repository/public" />
|
||||||
|
</remote-repository>
|
||||||
|
</component>
|
||||||
|
</project>
|
||||||
Generated
+16
@@ -0,0 +1,16 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="ExternalStorageConfigurationManager" enabled="true" />
|
||||||
|
<component name="MavenProjectsManager">
|
||||||
|
<option name="originalFiles">
|
||||||
|
<list>
|
||||||
|
<option value="$PROJECT_DIR$/MessageHub/pom.xml" />
|
||||||
|
<option value="$PROJECT_DIR$/YumiNail-Core/pom.xml" />
|
||||||
|
<option value="$PROJECT_DIR$/YumiNail-Gateway/pom.xml" />
|
||||||
|
</list>
|
||||||
|
</option>
|
||||||
|
</component>
|
||||||
|
<component name="ProjectRootManager" version="2" languageLevel="JDK_21" default="true" project-jdk-name="21" project-jdk-type="JavaSDK">
|
||||||
|
<output url="file://$PROJECT_DIR$/out" />
|
||||||
|
</component>
|
||||||
|
</project>
|
||||||
Generated
+8
@@ -0,0 +1,8 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="ProjectModuleManager">
|
||||||
|
<modules>
|
||||||
|
<module fileurl="file://$PROJECT_DIR$/.idea/xiaowang.iml" filepath="$PROJECT_DIR$/.idea/xiaowang.iml" />
|
||||||
|
</modules>
|
||||||
|
</component>
|
||||||
|
</project>
|
||||||
Generated
+7
@@ -0,0 +1,7 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="SqlDialectMappings">
|
||||||
|
<file url="file://$PROJECT_DIR$/YumiNail-Core/src/main/resources/files/YumiNail.sql" dialect="MySQL" />
|
||||||
|
<file url="file://$PROJECT_DIR$/YumiNail-Core/src/main/resources/files/cart_order.sql" dialect="MySQL" />
|
||||||
|
</component>
|
||||||
|
</project>
|
||||||
Generated
+6
@@ -0,0 +1,6 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="VcsDirectoryMappings">
|
||||||
|
<mapping directory="" vcs="Git" />
|
||||||
|
</component>
|
||||||
|
</project>
|
||||||
Generated
+9
@@ -0,0 +1,9 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<module type="JAVA_MODULE" version="4">
|
||||||
|
<component name="NewModuleRootManager" inherit-compiler-output="true">
|
||||||
|
<exclude-output />
|
||||||
|
<content url="file://$MODULE_DIR$" />
|
||||||
|
<orderEntry type="inheritedJdk" />
|
||||||
|
<orderEntry type="sourceFolder" forTests="false" />
|
||||||
|
</component>
|
||||||
|
</module>
|
||||||
@@ -1,5 +1,6 @@
|
|||||||
import axios, { AxiosError } from 'axios'
|
import axios, { AxiosError } from 'axios'
|
||||||
import { authApi } from './auth'
|
import { authApi } from './auth'
|
||||||
|
import { adminAuthApi } from './admin'
|
||||||
import { wishlistApi } from './wishlist'
|
import { wishlistApi } from './wishlist'
|
||||||
import router from '../router'
|
import router from '../router'
|
||||||
import { message } from 'ant-design-vue'
|
import { message } from 'ant-design-vue'
|
||||||
@@ -136,7 +137,8 @@ api.interceptors.response.use(
|
|||||||
url?.includes('/user/send-verification-code') ||
|
url?.includes('/user/send-verification-code') ||
|
||||||
url?.includes('/user/phone-login') ||
|
url?.includes('/user/phone-login') ||
|
||||||
url?.includes('/shop/list/simple') ||
|
url?.includes('/shop/list/simple') ||
|
||||||
url?.includes('/admin/login')
|
url?.includes('/admin/auth/login') ||
|
||||||
|
url?.includes('/admin/auth/refresh')
|
||||||
}
|
}
|
||||||
|
|
||||||
if (error.response?.status === 401) {
|
if (error.response?.status === 401) {
|
||||||
@@ -174,7 +176,9 @@ api.interceptors.response.use(
|
|||||||
|
|
||||||
// 这里需要根据是否是后台请求调用不同的refreshToken API
|
// 这里需要根据是否是后台请求调用不同的refreshToken API
|
||||||
// 暂时使用同一个API,实际项目中可能需要分开
|
// 暂时使用同一个API,实际项目中可能需要分开
|
||||||
const response = await authApi.refreshToken({ refreshToken })
|
const response = isAdminRequest
|
||||||
|
? await adminAuthApi.refreshToken(refreshToken)
|
||||||
|
: await authApi.refreshToken({ refreshToken })
|
||||||
const newToken = (response as any).accessToken
|
const newToken = (response as any).accessToken
|
||||||
const newRefreshToken = (response as any).refreshToken
|
const newRefreshToken = (response as any).refreshToken
|
||||||
|
|
||||||
|
|||||||
@@ -22,7 +22,6 @@ export interface UpdateUserInfoRequest {
|
|||||||
nickname?: string
|
nickname?: string
|
||||||
avatar?: string
|
avatar?: string
|
||||||
signature?: string
|
signature?: string
|
||||||
phone?: string
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface ListUsersParams {
|
export interface ListUsersParams {
|
||||||
@@ -52,6 +51,7 @@ export interface UpdateUserRequest {
|
|||||||
|
|
||||||
export interface UpdatePasswordRequest {
|
export interface UpdatePasswordRequest {
|
||||||
password: string
|
password: string
|
||||||
|
verificationCode: string
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface BindPhoneRequest {
|
export interface BindPhoneRequest {
|
||||||
@@ -59,6 +59,11 @@ export interface BindPhoneRequest {
|
|||||||
verificationCode: string
|
verificationCode: string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export interface AvailabilityCheckResponse {
|
||||||
|
available: boolean
|
||||||
|
message: string
|
||||||
|
}
|
||||||
|
|
||||||
export interface UpdatePhoneRequest {
|
export interface UpdatePhoneRequest {
|
||||||
oldPhone: string
|
oldPhone: string
|
||||||
newPhone: string
|
newPhone: string
|
||||||
@@ -70,7 +75,7 @@ export const userApi = {
|
|||||||
return api.get<UserVO>('/user/info')
|
return api.get<UserVO>('/user/info')
|
||||||
},
|
},
|
||||||
updateUserInfo: (data: UpdateUserInfoRequest) => {
|
updateUserInfo: (data: UpdateUserInfoRequest) => {
|
||||||
return api.put('/user/info', data)
|
return api.put('/user/update', data)
|
||||||
},
|
},
|
||||||
updatePassword: (data: UpdatePasswordRequest) => {
|
updatePassword: (data: UpdatePasswordRequest) => {
|
||||||
return api.put('/user/password', data)
|
return api.put('/user/password', data)
|
||||||
@@ -84,6 +89,12 @@ export const userApi = {
|
|||||||
getUserByAccount: (account: string) => {
|
getUserByAccount: (account: string) => {
|
||||||
return api.get<UserVO>(`/user/get/account/${account}`)
|
return api.get<UserVO>(`/user/get/account/${account}`)
|
||||||
},
|
},
|
||||||
|
checkAccountAvailability: (account: string) => {
|
||||||
|
return api.get<AvailabilityCheckResponse>(`/user/check/account/${encodeURIComponent(account)}`)
|
||||||
|
},
|
||||||
|
checkPhoneAvailability: (phone: string) => {
|
||||||
|
return api.get<AvailabilityCheckResponse>(`/user/check/phone/${encodeURIComponent(phone)}`)
|
||||||
|
},
|
||||||
listUsersByType: (type: number) => {
|
listUsersByType: (type: number) => {
|
||||||
return api.get<UserVO[]>(`/user/list/type/${type}`)
|
return api.get<UserVO[]>(`/user/list/type/${type}`)
|
||||||
},
|
},
|
||||||
|
|||||||
Vendored
+1
@@ -49,6 +49,7 @@ declare module 'vue' {
|
|||||||
AModal: typeof import('ant-design-vue/es')['Modal']
|
AModal: typeof import('ant-design-vue/es')['Modal']
|
||||||
APageHeader: typeof import('ant-design-vue/es')['PageHeader']
|
APageHeader: typeof import('ant-design-vue/es')['PageHeader']
|
||||||
APopconfirm: typeof import('ant-design-vue/es')['Popconfirm']
|
APopconfirm: typeof import('ant-design-vue/es')['Popconfirm']
|
||||||
|
ARadio: typeof import('ant-design-vue/es')['Radio']
|
||||||
ARadioButton: typeof import('ant-design-vue/es')['RadioButton']
|
ARadioButton: typeof import('ant-design-vue/es')['RadioButton']
|
||||||
ARadioGroup: typeof import('ant-design-vue/es')['RadioGroup']
|
ARadioGroup: typeof import('ant-design-vue/es')['RadioGroup']
|
||||||
ARow: typeof import('ant-design-vue/es')['Row']
|
ARow: typeof import('ant-design-vue/es')['Row']
|
||||||
|
|||||||
@@ -61,7 +61,7 @@ const router = createRouter({
|
|||||||
path: '/artist-orders',
|
path: '/artist-orders',
|
||||||
name: 'artist-orders',
|
name: 'artist-orders',
|
||||||
component: () => import('../views/ArtistOrderView.vue'),
|
component: () => import('../views/ArtistOrderView.vue'),
|
||||||
meta: { requiresAuth: true, hideNav: true, isAdmin: false, permissionCode: 'order:artist:view' }
|
meta: { requiresAuth: true, hideNav: true, isAdmin: false, permissionCode: 'order:view' }
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
path: '/settings',
|
path: '/settings',
|
||||||
|
|||||||
@@ -490,7 +490,10 @@ const handleChangePasswordSubmit = async () => {
|
|||||||
|
|
||||||
changePasswordLoading.value = true
|
changePasswordLoading.value = true
|
||||||
try {
|
try {
|
||||||
await userApi.updatePassword({ password: changePasswordForm.password })
|
await userApi.updatePassword({
|
||||||
|
password: changePasswordForm.password,
|
||||||
|
verificationCode: changePasswordForm.verificationCode
|
||||||
|
})
|
||||||
message.success('密码修改成功')
|
message.success('密码修改成功')
|
||||||
changePasswordModalVisible.value = false
|
changePasswordModalVisible.value = false
|
||||||
// 清除需要设置密码的标识
|
// 清除需要设置密码的标识
|
||||||
@@ -522,17 +525,6 @@ const handleDeactivateAccount = async () => {
|
|||||||
cancelText: '取消',
|
cancelText: '取消',
|
||||||
onOk: async () => {
|
onOk: async () => {
|
||||||
try {
|
try {
|
||||||
// 在删除前先重命名账号和手机号,添加删除时间戳
|
|
||||||
const timestamp = new Date().getTime()
|
|
||||||
const newPhone = `${userInfo.value.phone}_deleted_${timestamp}`
|
|
||||||
|
|
||||||
try {
|
|
||||||
await userApi.updateUserInfo({ phone: newPhone })
|
|
||||||
} catch (renameError) {
|
|
||||||
console.error('重命名手机号失败:', renameError)
|
|
||||||
// 重命名失败也继续删除流程
|
|
||||||
}
|
|
||||||
|
|
||||||
await userApi.deactivateAccount()
|
await userApi.deactivateAccount()
|
||||||
message.success('账号注销成功')
|
message.success('账号注销成功')
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
|||||||
+106
-120
@@ -54,11 +54,19 @@
|
|||||||
v-model:value="formData.account"
|
v-model:value="formData.account"
|
||||||
placeholder="请输入账号"
|
placeholder="请输入账号"
|
||||||
size="large"
|
size="large"
|
||||||
|
@blur="handleRegisterAccountBlur"
|
||||||
>
|
>
|
||||||
<template #prefix>
|
<template #prefix>
|
||||||
<UserOutlined style="color: #999" />
|
<UserOutlined style="color: #999" />
|
||||||
</template>
|
</template>
|
||||||
</a-input>
|
</a-input>
|
||||||
|
<div
|
||||||
|
v-if="registerAccountStatus"
|
||||||
|
class="field-status"
|
||||||
|
:class="registerAccountStatus.available ? 'success' : 'error'"
|
||||||
|
>
|
||||||
|
{{ registerAccountStatus.message }}
|
||||||
|
</div>
|
||||||
</a-form-item>
|
</a-form-item>
|
||||||
|
|
||||||
<a-form-item v-if="activeTab === 'register'" name="phone" label="手机号">
|
<a-form-item v-if="activeTab === 'register'" name="phone" label="手机号">
|
||||||
@@ -66,11 +74,19 @@
|
|||||||
v-model:value="formData.phone"
|
v-model:value="formData.phone"
|
||||||
placeholder="请输入手机号"
|
placeholder="请输入手机号"
|
||||||
size="large"
|
size="large"
|
||||||
|
@blur="handleRegisterPhoneBlur"
|
||||||
>
|
>
|
||||||
<template #prefix>
|
<template #prefix>
|
||||||
<UserOutlined style="color: #999" />
|
<UserOutlined style="color: #999" />
|
||||||
</template>
|
</template>
|
||||||
</a-input>
|
</a-input>
|
||||||
|
<div
|
||||||
|
v-if="registerPhoneStatus"
|
||||||
|
class="field-status"
|
||||||
|
:class="registerPhoneStatus.available ? 'success' : 'error'"
|
||||||
|
>
|
||||||
|
{{ registerPhoneStatus.message }}
|
||||||
|
</div>
|
||||||
</a-form-item>
|
</a-form-item>
|
||||||
|
|
||||||
<a-form-item v-if="activeTab === 'register'" name="verificationCode" label="验证码">
|
<a-form-item v-if="activeTab === 'register'" name="verificationCode" label="验证码">
|
||||||
@@ -99,20 +115,11 @@
|
|||||||
v-model:value="formData.account"
|
v-model:value="formData.account"
|
||||||
placeholder="请输入账号"
|
placeholder="请输入账号"
|
||||||
size="large"
|
size="large"
|
||||||
@blur="handleAccountBlur"
|
|
||||||
>
|
>
|
||||||
<template #prefix>
|
<template #prefix>
|
||||||
<UserOutlined style="color: #999" />
|
<UserOutlined style="color: #999" />
|
||||||
</template>
|
</template>
|
||||||
</a-input>
|
</a-input>
|
||||||
<div v-if="accountStatus" class="account-status">
|
|
||||||
<span v-if="accountStatus.exists" class="status-success">
|
|
||||||
账号存在,昵称:{{ accountStatus.nickname }} {{ accountStatus.hasShop ? ',已绑定店铺' : ',请选择店铺' }}
|
|
||||||
</span>
|
|
||||||
<span v-else class="status-error">
|
|
||||||
账号不存在
|
|
||||||
</span>
|
|
||||||
</div>
|
|
||||||
</a-form-item>
|
</a-form-item>
|
||||||
|
|
||||||
<a-form-item name="phone" label="手机号" v-if="activeTab === 'login' && loginType === 'phone'">
|
<a-form-item name="phone" label="手机号" v-if="activeTab === 'login' && loginType === 'phone'">
|
||||||
@@ -120,7 +127,6 @@
|
|||||||
v-model:value="formData.phone"
|
v-model:value="formData.phone"
|
||||||
placeholder="请输入手机号"
|
placeholder="请输入手机号"
|
||||||
size="large"
|
size="large"
|
||||||
@blur="handlePhoneBlur"
|
|
||||||
>
|
>
|
||||||
<template #prefix>
|
<template #prefix>
|
||||||
<UserOutlined style="color: #999" />
|
<UserOutlined style="color: #999" />
|
||||||
@@ -130,14 +136,6 @@
|
|||||||
<InfoCircleOutlined style="color: #1890ff; margin-right: 4px;" />
|
<InfoCircleOutlined style="color: #1890ff; margin-right: 4px;" />
|
||||||
<span>新用户将自动注册</span>
|
<span>新用户将自动注册</span>
|
||||||
</div>
|
</div>
|
||||||
<div v-if="phoneUserStatus" class="account-status">
|
|
||||||
<span v-if="phoneUserStatus.exists" class="status-success">
|
|
||||||
{{ phoneUserStatus.hasShop ? '账号已存在,已绑定店铺' : '账号已存在,请选择店铺' }}
|
|
||||||
</span>
|
|
||||||
<span v-else class="status-error">
|
|
||||||
新用户,请选择店铺
|
|
||||||
</span>
|
|
||||||
</div>
|
|
||||||
</a-form-item>
|
</a-form-item>
|
||||||
|
|
||||||
<a-form-item name="verificationCode" label="验证码" v-if="activeTab === 'login' && loginType === 'phone'">
|
<a-form-item name="verificationCode" label="验证码" v-if="activeTab === 'login' && loginType === 'phone'">
|
||||||
@@ -162,15 +160,15 @@
|
|||||||
</a-form-item>
|
</a-form-item>
|
||||||
|
|
||||||
<a-form-item
|
<a-form-item
|
||||||
v-if="activeTab === 'login' && loginType === 'phone' && (phoneUserStatus && !phoneUserStatus.hasShop)"
|
v-if="activeTab === 'login'"
|
||||||
name="shopId"
|
label="选择店铺(可选)"
|
||||||
label="选择店铺"
|
|
||||||
>
|
>
|
||||||
<a-select
|
<a-select
|
||||||
v-model:value="formData.shopId"
|
v-model:value="formData.shopId"
|
||||||
placeholder="请选择店铺"
|
placeholder="如需绑定店铺或首次手机号登录,请选择店铺"
|
||||||
size="large"
|
size="large"
|
||||||
:loading="loadingShops"
|
:loading="loadingShops"
|
||||||
|
allow-clear
|
||||||
>
|
>
|
||||||
<a-select-option
|
<a-select-option
|
||||||
v-if="shops.length === 0"
|
v-if="shops.length === 0"
|
||||||
@@ -201,34 +199,6 @@
|
|||||||
</a-input-password>
|
</a-input-password>
|
||||||
</a-form-item>
|
</a-form-item>
|
||||||
|
|
||||||
<a-form-item
|
|
||||||
v-if="activeTab === 'login' && loginType === 'password' && (accountStatus && accountStatus.exists && !accountStatus.hasShop)"
|
|
||||||
name="shopId"
|
|
||||||
label="选择店铺"
|
|
||||||
>
|
|
||||||
<a-select
|
|
||||||
v-model:value="formData.shopId"
|
|
||||||
placeholder="请选择店铺"
|
|
||||||
size="large"
|
|
||||||
:loading="loadingShops"
|
|
||||||
>
|
|
||||||
<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 v-if="activeTab === 'register'" name="confirmPassword" label="确认密码">
|
<a-form-item v-if="activeTab === 'register'" name="confirmPassword" label="确认密码">
|
||||||
<a-input-password
|
<a-input-password
|
||||||
v-model:value="formData.confirmPassword"
|
v-model:value="formData.confirmPassword"
|
||||||
@@ -393,7 +363,7 @@ import { message } from 'ant-design-vue'
|
|||||||
import type { Rule } from 'ant-design-vue/es/form'
|
import type { Rule } from 'ant-design-vue/es/form'
|
||||||
import { authApi } from '@/api/auth'
|
import { authApi } from '@/api/auth'
|
||||||
import { shopApi } from '@/api/shop'
|
import { shopApi } from '@/api/shop'
|
||||||
import { userApi } from '@/api/user'
|
import { userApi, type AvailabilityCheckResponse } from '@/api/user'
|
||||||
|
|
||||||
const router = useRouter()
|
const router = useRouter()
|
||||||
|
|
||||||
@@ -402,9 +372,9 @@ const loginType = ref<'password' | 'phone'>('password')
|
|||||||
const loading = ref(false)
|
const loading = ref(false)
|
||||||
const loadingShops = ref(false)
|
const loadingShops = ref(false)
|
||||||
const shops = ref<any[]>([])
|
const shops = ref<any[]>([])
|
||||||
const accountStatus = ref<any>(null)
|
|
||||||
const phoneUserStatus = ref<any>(null)
|
|
||||||
const countdown = ref(0)
|
const countdown = ref(0)
|
||||||
|
const registerAccountStatus = ref<AvailabilityCheckResponse | null>(null)
|
||||||
|
const registerPhoneStatus = ref<AvailabilityCheckResponse | null>(null)
|
||||||
|
|
||||||
const forgotPasswordVisible = ref(false)
|
const forgotPasswordVisible = ref(false)
|
||||||
const forgotCountdown = ref(0)
|
const forgotCountdown = ref(0)
|
||||||
@@ -503,7 +473,7 @@ const fetchShops = async () => {
|
|||||||
shops.value = (response as unknown as any[]) || []
|
shops.value = (response as unknown as any[]) || []
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('获取店铺列表失败:', error)
|
console.error('获取店铺列表失败:', error)
|
||||||
message.error('未登录,请先登录')
|
message.warning('店铺列表加载失败,普通登录不受影响')
|
||||||
} finally {
|
} finally {
|
||||||
loadingShops.value = false
|
loadingShops.value = false
|
||||||
}
|
}
|
||||||
@@ -516,22 +486,12 @@ const handleSubmit = async () => {
|
|||||||
let response
|
let response
|
||||||
|
|
||||||
if (loginType.value === 'phone') {
|
if (loginType.value === 'phone') {
|
||||||
if (phoneUserStatus.value && !phoneUserStatus.value.hasShop && !formData.shopId) {
|
|
||||||
message.error('请选择店铺')
|
|
||||||
loading.value = false
|
|
||||||
return
|
|
||||||
}
|
|
||||||
response = await authApi.phoneLogin({
|
response = await authApi.phoneLogin({
|
||||||
phone: formData.phone,
|
phone: formData.phone,
|
||||||
verificationCode: formData.verificationCode,
|
verificationCode: formData.verificationCode,
|
||||||
shopId: formData.shopId
|
shopId: formData.shopId
|
||||||
})
|
})
|
||||||
} else {
|
} else {
|
||||||
if (accountStatus.value && accountStatus.value.exists && !accountStatus.value.hasShop && !formData.shopId) {
|
|
||||||
message.error('请选择店铺')
|
|
||||||
loading.value = false
|
|
||||||
return
|
|
||||||
}
|
|
||||||
response = await authApi.login({
|
response = await authApi.login({
|
||||||
account: formData.account,
|
account: formData.account,
|
||||||
password: formData.password,
|
password: formData.password,
|
||||||
@@ -563,6 +523,13 @@ const handleSubmit = async () => {
|
|||||||
message.error('登录失败:响应数据异常')
|
message.error('登录失败:响应数据异常')
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
const accountAvailable = await checkRegisterAccountAvailability(false)
|
||||||
|
const phoneAvailable = await checkRegisterPhoneAvailability(false)
|
||||||
|
if (!accountAvailable || !phoneAvailable) {
|
||||||
|
message.error('请先处理注册信息中的占用问题')
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
await authApi.register({
|
await authApi.register({
|
||||||
account: formData.account,
|
account: formData.account,
|
||||||
password: formData.password,
|
password: formData.password,
|
||||||
@@ -643,54 +610,65 @@ const handleQQLogin = () => {
|
|||||||
message.info('QQ登录功能开发中')
|
message.info('QQ登录功能开发中')
|
||||||
}
|
}
|
||||||
|
|
||||||
const handleAccountBlur = async () => {
|
const checkRegisterAccountAvailability = async (showSuccessMessage = true) => {
|
||||||
if (activeTab.value === 'login' && formData.account) {
|
if (activeTab.value !== 'register' || !formData.account.trim()) {
|
||||||
|
registerAccountStatus.value = null
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
const response = await userApi.checkAccountAvailability(formData.account.trim()) as unknown as AvailabilityCheckResponse
|
||||||
|
registerAccountStatus.value = response
|
||||||
|
if (showSuccessMessage && !response.available) {
|
||||||
|
message.warning(response.message)
|
||||||
|
}
|
||||||
|
return response.available
|
||||||
|
}
|
||||||
|
|
||||||
|
const checkRegisterPhoneAvailability = async (showSuccessMessage = true) => {
|
||||||
|
if (activeTab.value !== 'register' || !formData.phone.trim()) {
|
||||||
|
registerPhoneStatus.value = null
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
const response = await userApi.checkPhoneAvailability(formData.phone.trim()) as unknown as AvailabilityCheckResponse
|
||||||
|
registerPhoneStatus.value = response
|
||||||
|
if (showSuccessMessage && !response.available) {
|
||||||
|
message.warning(response.message)
|
||||||
|
}
|
||||||
|
return response.available
|
||||||
|
}
|
||||||
|
|
||||||
|
const handleRegisterAccountBlur = async () => {
|
||||||
|
if (activeTab.value !== 'register' || !formData.account.trim()) {
|
||||||
|
registerAccountStatus.value = null
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const res = await userApi.getUserByAccount(formData.account)
|
await checkRegisterAccountAvailability(false)
|
||||||
const userData = res as any
|
} catch (error: any) {
|
||||||
if (userData) {
|
registerAccountStatus.value = null
|
||||||
accountStatus.value = {
|
message.error(error.message || '账号校验失败')
|
||||||
exists: true,
|
|
||||||
nickname: userData.nickname,
|
|
||||||
hasShop: userData.shopId && userData.shopId > 0
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
accountStatus.value = {
|
|
||||||
exists: false,
|
|
||||||
hasShop: false
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} catch (error) {
|
|
||||||
accountStatus.value = {
|
|
||||||
exists: false,
|
|
||||||
hasShop: false
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const handlePhoneBlur = async () => {
|
const handleRegisterPhoneBlur = async () => {
|
||||||
if (activeTab.value === 'login' && loginType.value === 'phone' && formData.phone) {
|
if (activeTab.value !== 'register' || !formData.phone.trim()) {
|
||||||
|
registerPhoneStatus.value = null
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
const phoneRegex = /^1[3-9]\d{9}$/
|
||||||
|
if (!phoneRegex.test(formData.phone)) {
|
||||||
|
registerPhoneStatus.value = null
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const res = await userApi.getUserByAccount(formData.phone)
|
await checkRegisterPhoneAvailability(false)
|
||||||
const userData = res as any
|
} catch (error: any) {
|
||||||
if (userData) {
|
registerPhoneStatus.value = null
|
||||||
phoneUserStatus.value = {
|
message.error(error.message || '手机号校验失败')
|
||||||
exists: true,
|
|
||||||
hasShop: userData.shopId && userData.shopId > 0
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
phoneUserStatus.value = {
|
|
||||||
exists: false,
|
|
||||||
hasShop: false
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} catch (error) {
|
|
||||||
phoneUserStatus.value = {
|
|
||||||
exists: false,
|
|
||||||
hasShop: false
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -707,6 +685,14 @@ const handleSendVerificationCode = async () => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
if (activeTab.value === 'register') {
|
||||||
|
const phoneAvailable = await checkRegisterPhoneAvailability(false)
|
||||||
|
if (!phoneAvailable) {
|
||||||
|
message.warning(registerPhoneStatus.value?.message || '该手机号已被注册')
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
await userApi.sendVerificationCode({ phone: formData.phone })
|
await userApi.sendVerificationCode({ phone: formData.phone })
|
||||||
message.success('验证码已发送')
|
message.success('验证码已发送')
|
||||||
countdown.value = 60
|
countdown.value = 60
|
||||||
@@ -824,6 +810,19 @@ onMounted(() => {
|
|||||||
align-items: center;
|
align-items: center;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.field-status {
|
||||||
|
margin-top: 8px;
|
||||||
|
font-size: 12px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.field-status.success {
|
||||||
|
color: #52c41a;
|
||||||
|
}
|
||||||
|
|
||||||
|
.field-status.error {
|
||||||
|
color: #ff4d4f;
|
||||||
|
}
|
||||||
|
|
||||||
.forgot-password {
|
.forgot-password {
|
||||||
color: #667eea;
|
color: #667eea;
|
||||||
cursor: pointer;
|
cursor: pointer;
|
||||||
@@ -891,19 +890,6 @@ onMounted(() => {
|
|||||||
text-decoration: underline;
|
text-decoration: underline;
|
||||||
}
|
}
|
||||||
|
|
||||||
.account-status {
|
|
||||||
margin-top: 8px;
|
|
||||||
font-size: 12px;
|
|
||||||
}
|
|
||||||
|
|
||||||
.status-success {
|
|
||||||
color: #52c41a;
|
|
||||||
}
|
|
||||||
|
|
||||||
.status-error {
|
|
||||||
color: #f5222d;
|
|
||||||
}
|
|
||||||
|
|
||||||
.phone-login-tip {
|
.phone-login-tip {
|
||||||
margin-top: 8px;
|
margin-top: 8px;
|
||||||
font-size: 12px;
|
font-size: 12px;
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
<template>
|
<template>
|
||||||
<div class="mobile-container">
|
<div class="mobile-container">
|
||||||
<!-- 头部区域 -->
|
|
||||||
<header class="header">
|
<header class="header">
|
||||||
<a-button class="back-btn" type="text" @click="handleBackClick">
|
<a-button class="back-btn" type="text" @click="handleBackClick">
|
||||||
<LeftOutlined :style="{ fontSize: '20px' }" />
|
<LeftOutlined :style="{ fontSize: '20px' }" />
|
||||||
@@ -9,7 +8,6 @@
|
|||||||
<div class="empty"></div>
|
<div class="empty"></div>
|
||||||
</header>
|
</header>
|
||||||
|
|
||||||
<!-- 密码设置表单 -->
|
|
||||||
<div class="password-form">
|
<div class="password-form">
|
||||||
<a-card :bordered="false" class="form-card">
|
<a-card :bordered="false" class="form-card">
|
||||||
<a-form
|
<a-form
|
||||||
@@ -19,6 +17,28 @@
|
|||||||
layout="vertical"
|
layout="vertical"
|
||||||
@finish="handleSubmit"
|
@finish="handleSubmit"
|
||||||
>
|
>
|
||||||
|
<a-form-item label="手机号">
|
||||||
|
<a-input :value="userPhone || '未绑定手机号'" disabled size="large" />
|
||||||
|
</a-form-item>
|
||||||
|
|
||||||
|
<a-form-item label="验证码" name="verificationCode">
|
||||||
|
<a-input
|
||||||
|
v-model:value="formState.verificationCode"
|
||||||
|
placeholder="请输入验证码"
|
||||||
|
size="large"
|
||||||
|
>
|
||||||
|
<template #suffix>
|
||||||
|
<a-button
|
||||||
|
type="link"
|
||||||
|
:disabled="countdown > 0 || !userPhone"
|
||||||
|
@click="handleSendVerificationCode"
|
||||||
|
>
|
||||||
|
{{ countdown > 0 ? `${countdown}秒后重发` : '发送验证码' }}
|
||||||
|
</a-button>
|
||||||
|
</template>
|
||||||
|
</a-input>
|
||||||
|
</a-form-item>
|
||||||
|
|
||||||
<a-form-item label="新密码" name="password">
|
<a-form-item label="新密码" name="password">
|
||||||
<a-input-password
|
<a-input-password
|
||||||
v-model:value="formState.password"
|
v-model:value="formState.password"
|
||||||
@@ -31,7 +51,7 @@
|
|||||||
</template>
|
</template>
|
||||||
</a-input-password>
|
</a-input-password>
|
||||||
<div class="password-tip">
|
<div class="password-tip">
|
||||||
密码长度至少8位,包含字母和数字
|
密码长度至少 8 位,且需包含字母和数字
|
||||||
</div>
|
</div>
|
||||||
</a-form-item>
|
</a-form-item>
|
||||||
|
|
||||||
@@ -66,7 +86,7 @@
|
|||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import { ref, reactive } from 'vue'
|
import { computed, onMounted, onUnmounted, reactive, ref } from 'vue'
|
||||||
import { useRouter } from 'vue-router'
|
import { useRouter } from 'vue-router'
|
||||||
import { LeftOutlined, LockOutlined } from '@ant-design/icons-vue'
|
import { LeftOutlined, LockOutlined } from '@ant-design/icons-vue'
|
||||||
import { message } from 'ant-design-vue'
|
import { message } from 'ant-design-vue'
|
||||||
@@ -77,12 +97,18 @@ import { userApi } from '@/api/user'
|
|||||||
const router = useRouter()
|
const router = useRouter()
|
||||||
const formRef = ref<FormInstance>()
|
const formRef = ref<FormInstance>()
|
||||||
const loading = ref(false)
|
const loading = ref(false)
|
||||||
|
const countdown = ref(0)
|
||||||
|
const userInfo = ref<{ phone?: string } | null>(null)
|
||||||
|
let countdownTimer: ReturnType<typeof setInterval> | null = null
|
||||||
|
|
||||||
const formState = reactive({
|
const formState = reactive({
|
||||||
|
verificationCode: '',
|
||||||
password: '',
|
password: '',
|
||||||
confirmPassword: ''
|
confirmPassword: ''
|
||||||
})
|
})
|
||||||
|
|
||||||
|
const userPhone = computed(() => userInfo.value?.phone || '')
|
||||||
|
|
||||||
const validateConfirmPassword = (_rule: any, value: string) => {
|
const validateConfirmPassword = (_rule: any, value: string) => {
|
||||||
if (value !== formState.password) {
|
if (value !== formState.password) {
|
||||||
return Promise.reject(new Error('两次输入的密码不一致'))
|
return Promise.reject(new Error('两次输入的密码不一致'))
|
||||||
@@ -91,6 +117,10 @@ const validateConfirmPassword = (_rule: any, value: string) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const formRules: Record<string, Rule[]> = {
|
const formRules: Record<string, Rule[]> = {
|
||||||
|
verificationCode: [
|
||||||
|
{ required: true, message: '请输入验证码', trigger: 'blur' },
|
||||||
|
{ pattern: /^\d{6}$/, message: '验证码必须是6位数字', trigger: 'blur' }
|
||||||
|
],
|
||||||
password: [
|
password: [
|
||||||
{ required: true, message: '请输入新密码', trigger: 'blur' },
|
{ required: true, message: '请输入新密码', trigger: 'blur' },
|
||||||
{ min: 8, message: '密码长度至少8位', trigger: 'blur' },
|
{ min: 8, message: '密码长度至少8位', trigger: 'blur' },
|
||||||
@@ -102,21 +132,64 @@ const formRules: Record<string, Rule[]> = {
|
|||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const startCountdown = () => {
|
||||||
|
countdown.value = 60
|
||||||
|
if (countdownTimer) {
|
||||||
|
clearInterval(countdownTimer)
|
||||||
|
}
|
||||||
|
countdownTimer = setInterval(() => {
|
||||||
|
countdown.value -= 1
|
||||||
|
if (countdown.value <= 0 && countdownTimer) {
|
||||||
|
clearInterval(countdownTimer)
|
||||||
|
countdownTimer = null
|
||||||
|
}
|
||||||
|
}, 1000)
|
||||||
|
}
|
||||||
|
|
||||||
|
const fetchUserInfo = async () => {
|
||||||
|
try {
|
||||||
|
const res = await userApi.getUserInfo()
|
||||||
|
userInfo.value = res as unknown as { phone?: string }
|
||||||
|
} catch (error: any) {
|
||||||
|
console.error('获取用户信息失败:', error)
|
||||||
|
message.error(error.message || '获取用户信息失败')
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const handleSendVerificationCode = async () => {
|
||||||
|
if (!userPhone.value) {
|
||||||
|
message.error('请先绑定手机号')
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
await userApi.sendVerificationCode({ phone: userPhone.value })
|
||||||
|
message.success('验证码发送成功')
|
||||||
|
startCountdown()
|
||||||
|
} catch (error: any) {
|
||||||
|
console.error('发送验证码失败:', error)
|
||||||
|
message.error(error.message || '发送验证码失败')
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
const handleSubmit = async () => {
|
const handleSubmit = async () => {
|
||||||
if (!formRef.value) return
|
if (!formRef.value) return
|
||||||
|
|
||||||
try {
|
try {
|
||||||
await formRef.value.validate()
|
await formRef.value.validate()
|
||||||
loading.value = true
|
if (!userPhone.value) {
|
||||||
|
message.error('请先绑定手机号')
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
loading.value = true
|
||||||
await userApi.updatePassword({
|
await userApi.updatePassword({
|
||||||
password: formState.password
|
password: formState.password,
|
||||||
|
verificationCode: formState.verificationCode
|
||||||
})
|
})
|
||||||
|
|
||||||
message.success('密码设置成功')
|
message.success('密码设置成功')
|
||||||
// 清除需要设置密码的标识
|
|
||||||
localStorage.removeItem('needSetPassword')
|
localStorage.removeItem('needSetPassword')
|
||||||
// 跳转回个人中心
|
|
||||||
router.push('/profile')
|
router.push('/profile')
|
||||||
} catch (error: any) {
|
} catch (error: any) {
|
||||||
console.error('设置密码失败:', error)
|
console.error('设置密码失败:', error)
|
||||||
@@ -129,6 +202,16 @@ const handleSubmit = async () => {
|
|||||||
const handleBackClick = () => {
|
const handleBackClick = () => {
|
||||||
router.back()
|
router.back()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
onMounted(() => {
|
||||||
|
fetchUserInfo()
|
||||||
|
})
|
||||||
|
|
||||||
|
onUnmounted(() => {
|
||||||
|
if (countdownTimer) {
|
||||||
|
clearInterval(countdownTimer)
|
||||||
|
}
|
||||||
|
})
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<style scoped>
|
<style scoped>
|
||||||
@@ -171,23 +254,9 @@ const handleBackClick = () => {
|
|||||||
background: white;
|
background: white;
|
||||||
}
|
}
|
||||||
|
|
||||||
.form-card :deep(.ant-card-body) {
|
|
||||||
padding: 24px;
|
|
||||||
}
|
|
||||||
|
|
||||||
.password-tip {
|
.password-tip {
|
||||||
font-size: 12px;
|
|
||||||
color: #999;
|
|
||||||
margin-top: 8px;
|
margin-top: 8px;
|
||||||
}
|
color: #999;
|
||||||
|
font-size: 12px;
|
||||||
.form-card :deep(.ant-btn-primary) {
|
|
||||||
height: 48px;
|
|
||||||
border-radius: 12px;
|
|
||||||
font-size: 15px;
|
|
||||||
font-weight: 600;
|
|
||||||
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
|
|
||||||
border: none;
|
|
||||||
box-shadow: 0 4px 12px rgba(102, 126, 234, 0.3);
|
|
||||||
}
|
}
|
||||||
</style>
|
</style>
|
||||||
@@ -155,7 +155,7 @@
|
|||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import { ref, onMounted } from 'vue'
|
import { ref, onMounted, inject } from 'vue'
|
||||||
import { useRouter } from 'vue-router'
|
import { useRouter } from 'vue-router'
|
||||||
import {
|
import {
|
||||||
LeftOutlined,
|
LeftOutlined,
|
||||||
@@ -169,6 +169,7 @@ import { tagApi, type TagVO } from '@/api/tag'
|
|||||||
import { cartApi } from '@/api/cart'
|
import { cartApi } from '@/api/cart'
|
||||||
import { fileApi } from '@/api/file'
|
import { fileApi } from '@/api/file'
|
||||||
|
|
||||||
|
const updateCartCount = inject<() => Promise<void>>('updateCartCount', async () => {})
|
||||||
|
|
||||||
|
|
||||||
const router = useRouter()
|
const router = useRouter()
|
||||||
@@ -298,6 +299,7 @@ const handleProductClick = (item: any) => {
|
|||||||
const handleAddToCart = async (item: any) => {
|
const handleAddToCart = async (item: any) => {
|
||||||
try {
|
try {
|
||||||
await cartApi.addToCart({ productId: item.id, quantity: 1 })
|
await cartApi.addToCart({ productId: item.id, quantity: 1 })
|
||||||
|
await updateCartCount()
|
||||||
message.success(`已将 ${item.title || item.name || '作品'} 添加到购物车`)
|
message.success(`已将 ${item.title || item.name || '作品'} 添加到购物车`)
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
message.error('添加到购物车失败,请重试')
|
message.error('添加到购物车失败,请重试')
|
||||||
|
|||||||
@@ -46,7 +46,7 @@
|
|||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import { ref, onMounted } from 'vue'
|
import { ref, onMounted, inject } from 'vue'
|
||||||
import { ArrowLeft, Delete, StarFilled } from '@element-plus/icons-vue'
|
import { ArrowLeft, Delete, StarFilled } from '@element-plus/icons-vue'
|
||||||
import { useRouter } from 'vue-router'
|
import { useRouter } from 'vue-router'
|
||||||
import { ElMessage } from 'element-plus'
|
import { ElMessage } from 'element-plus'
|
||||||
@@ -55,6 +55,7 @@ import { cartApi } from '@/api/cart'
|
|||||||
import { fileApi } from '@/api/file'
|
import { fileApi } from '@/api/file'
|
||||||
|
|
||||||
const router = useRouter()
|
const router = useRouter()
|
||||||
|
const updateCartCount = inject<() => Promise<void>>('updateCartCount', async () => {})
|
||||||
|
|
||||||
const wishlistItems = ref<WishlistItem[]>([])
|
const wishlistItems = ref<WishlistItem[]>([])
|
||||||
const imageIdCache = ref<Record<string, string>>({})
|
const imageIdCache = ref<Record<string, string>>({})
|
||||||
@@ -113,6 +114,7 @@ const getProductImages = (product: any): string[] => {
|
|||||||
const handleAddToCart = async (productId: number) => {
|
const handleAddToCart = async (productId: number) => {
|
||||||
try {
|
try {
|
||||||
await cartApi.addToCart({ productId, quantity: 1 })
|
await cartApi.addToCart({ productId, quantity: 1 })
|
||||||
|
await updateCartCount()
|
||||||
ElMessage.success('已添加到购物车')
|
ElMessage.success('已添加到购物车')
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('添加到购物车失败:', error)
|
console.error('添加到购物车失败:', error)
|
||||||
|
|||||||
@@ -55,6 +55,11 @@ public class AuthInterceptor implements HandlerInterceptor {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (currentUser.getStatus() != null && !Integer.valueOf(1).equals(currentUser.getStatus())) {
|
||||||
|
writeJsonResponse(response, HttpServletResponse.SC_FORBIDDEN, "账号已被禁用");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
if (isAdminPath(path) && (currentUser.getType() == null || currentUser.getType() < 2)) {
|
if (isAdminPath(path) && (currentUser.getType() == null || currentUser.getType() < 2)) {
|
||||||
writeJsonResponse(response, HttpServletResponse.SC_FORBIDDEN, "无后台访问权限");
|
writeJsonResponse(response, HttpServletResponse.SC_FORBIDDEN, "无后台访问权限");
|
||||||
return false;
|
return false;
|
||||||
|
|||||||
@@ -18,11 +18,11 @@ public class WebMvcConfig implements WebMvcConfigurer {
|
|||||||
.excludePathPatterns(
|
.excludePathPatterns(
|
||||||
"/user/login",
|
"/user/login",
|
||||||
"/user/register",
|
"/user/register",
|
||||||
|
"/user/check/**",
|
||||||
"/user/refresh-token",
|
"/user/refresh-token",
|
||||||
"/user/send-verification-code",
|
"/user/send-verification-code",
|
||||||
"/user/phone-login",
|
"/user/phone-login",
|
||||||
"/user/reset-password-by-phone",
|
"/user/reset-password-by-phone",
|
||||||
"/user/get/account/**",
|
|
||||||
"/shop/list/simple",
|
"/shop/list/simple",
|
||||||
"/admin/auth/login",
|
"/admin/auth/login",
|
||||||
"/admin/auth/refresh",
|
"/admin/auth/refresh",
|
||||||
|
|||||||
+5
@@ -29,6 +29,11 @@ public class AdminAuthController {
|
|||||||
@PostMapping("/refresh")
|
@PostMapping("/refresh")
|
||||||
public Result<LoginResponseVO> refreshToken(@RequestBody RefreshTokenRequestDTO refreshTokenRequestDTO) {
|
public Result<LoginResponseVO> refreshToken(@RequestBody RefreshTokenRequestDTO refreshTokenRequestDTO) {
|
||||||
LoginResponseVO loginResponseVO = userService.refreshToken(refreshTokenRequestDTO.getRefreshToken());
|
LoginResponseVO loginResponseVO = userService.refreshToken(refreshTokenRequestDTO.getRefreshToken());
|
||||||
|
if (loginResponseVO.getUserInfo() == null
|
||||||
|
|| loginResponseVO.getUserInfo().getType() == null
|
||||||
|
|| loginResponseVO.getUserInfo().getType() < 2) {
|
||||||
|
throw new RuntimeException("您没有后台管理权限");
|
||||||
|
}
|
||||||
return Result.success(loginResponseVO);
|
return Result.success(loginResponseVO);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+72
-8
@@ -3,13 +3,19 @@ package com.xiaowang.yuminailcore.controller;
|
|||||||
import com.xiaowang.yuminailcore.annotation.RequirePermission;
|
import com.xiaowang.yuminailcore.annotation.RequirePermission;
|
||||||
import com.xiaowang.yuminailcore.common.Result;
|
import com.xiaowang.yuminailcore.common.Result;
|
||||||
import com.xiaowang.yuminailcore.dto.CouponDTO;
|
import com.xiaowang.yuminailcore.dto.CouponDTO;
|
||||||
|
import com.xiaowang.yuminailcore.entity.UserDO;
|
||||||
import com.xiaowang.yuminailcore.service.CouponService;
|
import com.xiaowang.yuminailcore.service.CouponService;
|
||||||
|
import com.xiaowang.yuminailcore.service.UserService;
|
||||||
|
import com.xiaowang.yuminailcore.support.AdminScopeHelper;
|
||||||
import com.xiaowang.yuminailcore.vo.CouponVO;
|
import com.xiaowang.yuminailcore.vo.CouponVO;
|
||||||
import com.xiaowang.yuminailcore.vo.PageResultVO;
|
import com.xiaowang.yuminailcore.vo.PageResultVO;
|
||||||
|
import com.xiaowang.yuminailcore.vo.UserVO;
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
import org.springframework.web.bind.annotation.*;
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
|
import javax.servlet.http.HttpServletRequest;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 后台优惠券管理控制器
|
* 后台优惠券管理控制器
|
||||||
@@ -20,13 +26,17 @@ import java.util.List;
|
|||||||
public class AdminCouponController {
|
public class AdminCouponController {
|
||||||
|
|
||||||
private final CouponService couponService;
|
private final CouponService couponService;
|
||||||
|
private final UserService userService;
|
||||||
|
private final AdminScopeHelper adminScopeHelper;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 创建优惠券
|
* 创建优惠券
|
||||||
*/
|
*/
|
||||||
@PostMapping("/create")
|
@PostMapping("/create")
|
||||||
@RequirePermission("coupon:create")
|
@RequirePermission("coupon:create")
|
||||||
public Result<Long> createCoupon(@RequestBody CouponDTO couponDTO, @RequestParam(required = false) Long shopId) {
|
public Result<Long> createCoupon(HttpServletRequest request, @RequestBody CouponDTO couponDTO, @RequestParam(required = false) Long shopId) {
|
||||||
|
UserDO currentUser = adminScopeHelper.getCurrentUser(request);
|
||||||
|
shopId = adminScopeHelper.resolveShopScope(currentUser, shopId != null ? shopId : couponDTO.getShopId());
|
||||||
Long couponId = couponService.createCoupon(couponDTO, shopId);
|
Long couponId = couponService.createCoupon(couponDTO, shopId);
|
||||||
return Result.success(couponId);
|
return Result.success(couponId);
|
||||||
}
|
}
|
||||||
@@ -36,7 +46,15 @@ public class AdminCouponController {
|
|||||||
*/
|
*/
|
||||||
@PutMapping("/update/{id}")
|
@PutMapping("/update/{id}")
|
||||||
@RequirePermission("coupon:edit")
|
@RequirePermission("coupon:edit")
|
||||||
public Result<Boolean> updateCoupon(@PathVariable Long id, @RequestBody CouponDTO couponDTO, @RequestParam(required = false) Long shopId) {
|
public Result<Boolean> updateCoupon(HttpServletRequest request, @PathVariable Long id, @RequestBody CouponDTO couponDTO, @RequestParam(required = false) Long shopId) {
|
||||||
|
UserDO currentUser = adminScopeHelper.getCurrentUser(request);
|
||||||
|
CouponVO couponVO = couponService.getCouponById(id);
|
||||||
|
if (couponVO == null) {
|
||||||
|
return Result.success(false);
|
||||||
|
}
|
||||||
|
adminScopeHelper.ensureShopAccessible(currentUser, couponVO.getShopId(), "无权编辑其他店铺优惠券");
|
||||||
|
Long targetShopId = shopId != null ? shopId : (couponDTO.getShopId() != null ? couponDTO.getShopId() : couponVO.getShopId());
|
||||||
|
shopId = adminScopeHelper.resolveShopScope(currentUser, targetShopId);
|
||||||
boolean success = couponService.updateCoupon(id, couponDTO, shopId);
|
boolean success = couponService.updateCoupon(id, couponDTO, shopId);
|
||||||
return Result.success(success);
|
return Result.success(success);
|
||||||
}
|
}
|
||||||
@@ -46,7 +64,14 @@ public class AdminCouponController {
|
|||||||
*/
|
*/
|
||||||
@DeleteMapping("/delete/{id}")
|
@DeleteMapping("/delete/{id}")
|
||||||
@RequirePermission("coupon:delete")
|
@RequirePermission("coupon:delete")
|
||||||
public Result<Boolean> deleteCoupon(@PathVariable Long id, @RequestParam(required = false) Long shopId) {
|
public Result<Boolean> deleteCoupon(HttpServletRequest request, @PathVariable Long id, @RequestParam(required = false) Long shopId) {
|
||||||
|
UserDO currentUser = adminScopeHelper.getCurrentUser(request);
|
||||||
|
CouponVO couponVO = couponService.getCouponById(id);
|
||||||
|
if (couponVO == null) {
|
||||||
|
return Result.success(false);
|
||||||
|
}
|
||||||
|
adminScopeHelper.ensureShopAccessible(currentUser, couponVO.getShopId(), "无权删除其他店铺优惠券");
|
||||||
|
shopId = adminScopeHelper.resolveShopScope(currentUser, couponVO.getShopId());
|
||||||
boolean success = couponService.deleteCoupon(id, shopId);
|
boolean success = couponService.deleteCoupon(id, shopId);
|
||||||
return Result.success(success);
|
return Result.success(success);
|
||||||
}
|
}
|
||||||
@@ -56,8 +81,12 @@ public class AdminCouponController {
|
|||||||
*/
|
*/
|
||||||
@GetMapping("/detail/{id}")
|
@GetMapping("/detail/{id}")
|
||||||
@RequirePermission("coupon:view")
|
@RequirePermission("coupon:view")
|
||||||
public Result<CouponVO> getCouponById(@PathVariable Long id) {
|
public Result<CouponVO> getCouponById(HttpServletRequest request, @PathVariable Long id) {
|
||||||
|
UserDO currentUser = adminScopeHelper.getCurrentUser(request);
|
||||||
CouponVO couponVO = couponService.getCouponById(id);
|
CouponVO couponVO = couponService.getCouponById(id);
|
||||||
|
if (couponVO != null) {
|
||||||
|
adminScopeHelper.ensureShopAccessible(currentUser, couponVO.getShopId(), "无权查看其他店铺优惠券");
|
||||||
|
}
|
||||||
return Result.success(couponVO);
|
return Result.success(couponVO);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -66,7 +95,9 @@ public class AdminCouponController {
|
|||||||
*/
|
*/
|
||||||
@GetMapping("/list")
|
@GetMapping("/list")
|
||||||
@RequirePermission("coupon:view")
|
@RequirePermission("coupon:view")
|
||||||
public Result<PageResultVO<CouponVO>> listCoupons(@RequestParam Integer page, @RequestParam Integer size, @RequestParam(required = false) Long shopId) {
|
public Result<PageResultVO<CouponVO>> listCoupons(HttpServletRequest request, @RequestParam Integer page, @RequestParam Integer size, @RequestParam(required = false) Long shopId) {
|
||||||
|
UserDO currentUser = adminScopeHelper.getCurrentUser(request);
|
||||||
|
shopId = adminScopeHelper.resolveShopScope(currentUser, shopId);
|
||||||
PageResultVO<CouponVO> pageResult = couponService.listCoupons(page, size, shopId);
|
PageResultVO<CouponVO> pageResult = couponService.listCoupons(page, size, shopId);
|
||||||
return Result.success(pageResult);
|
return Result.success(pageResult);
|
||||||
}
|
}
|
||||||
@@ -76,8 +107,15 @@ public class AdminCouponController {
|
|||||||
*/
|
*/
|
||||||
@GetMapping("/list/all")
|
@GetMapping("/list/all")
|
||||||
@RequirePermission("coupon:view")
|
@RequirePermission("coupon:view")
|
||||||
public Result<List<CouponVO>> listAllCoupons() {
|
public Result<List<CouponVO>> listAllCoupons(HttpServletRequest request) {
|
||||||
|
UserDO currentUser = adminScopeHelper.getCurrentUser(request);
|
||||||
|
Long shopId = adminScopeHelper.resolveShopScope(currentUser, null);
|
||||||
List<CouponVO> coupons = couponService.listAllCoupons();
|
List<CouponVO> coupons = couponService.listAllCoupons();
|
||||||
|
if (shopId != null) {
|
||||||
|
coupons = coupons.stream()
|
||||||
|
.filter(coupon -> shopId.equals(coupon.getShopId()))
|
||||||
|
.collect(Collectors.toList());
|
||||||
|
}
|
||||||
return Result.success(coupons);
|
return Result.success(coupons);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -86,7 +124,19 @@ public class AdminCouponController {
|
|||||||
*/
|
*/
|
||||||
@PostMapping("/assign")
|
@PostMapping("/assign")
|
||||||
@RequirePermission("coupon:assign")
|
@RequirePermission("coupon:assign")
|
||||||
public Result<Boolean> assignCouponToUser(@RequestParam Long userId, @RequestParam Long couponId, @RequestParam(required = false) Long shopId) {
|
public Result<Boolean> assignCouponToUser(HttpServletRequest request, @RequestParam Long userId, @RequestParam Long couponId, @RequestParam(required = false) Long shopId) {
|
||||||
|
UserDO currentUser = adminScopeHelper.getCurrentUser(request);
|
||||||
|
CouponVO couponVO = couponService.getCouponById(couponId);
|
||||||
|
if (couponVO == null) {
|
||||||
|
return Result.success(false);
|
||||||
|
}
|
||||||
|
adminScopeHelper.ensureShopAccessible(currentUser, couponVO.getShopId(), "无权发放其他店铺优惠券");
|
||||||
|
UserVO targetUser = userService.getUserById(userId);
|
||||||
|
if (targetUser == null) {
|
||||||
|
return Result.success(false);
|
||||||
|
}
|
||||||
|
adminScopeHelper.ensureShopAccessible(currentUser, targetUser.getShopId(), "无权给其他店铺用户发放优惠券");
|
||||||
|
shopId = adminScopeHelper.resolveShopScope(currentUser, couponVO.getShopId());
|
||||||
boolean success = couponService.assignCouponToUser(userId, couponId, shopId);
|
boolean success = couponService.assignCouponToUser(userId, couponId, shopId);
|
||||||
return Result.success(success);
|
return Result.success(success);
|
||||||
}
|
}
|
||||||
@@ -96,7 +146,21 @@ public class AdminCouponController {
|
|||||||
*/
|
*/
|
||||||
@PostMapping("/distribute")
|
@PostMapping("/distribute")
|
||||||
@RequirePermission("coupon:assign")
|
@RequirePermission("coupon:assign")
|
||||||
public Result<Boolean> distributeCoupon(@RequestParam Long couponId, @RequestParam List<Long> userIds, @RequestParam Integer quantity, @RequestParam(required = false) Long shopId) {
|
public Result<Boolean> distributeCoupon(HttpServletRequest request, @RequestParam Long couponId, @RequestParam List<Long> userIds, @RequestParam Integer quantity, @RequestParam(required = false) Long shopId) {
|
||||||
|
UserDO currentUser = adminScopeHelper.getCurrentUser(request);
|
||||||
|
CouponVO couponVO = couponService.getCouponById(couponId);
|
||||||
|
if (couponVO == null) {
|
||||||
|
return Result.success(false);
|
||||||
|
}
|
||||||
|
adminScopeHelper.ensureShopAccessible(currentUser, couponVO.getShopId(), "无权发放其他店铺优惠券");
|
||||||
|
for (Long userId : userIds) {
|
||||||
|
UserVO targetUser = userService.getUserById(userId);
|
||||||
|
if (targetUser == null) {
|
||||||
|
return Result.success(false);
|
||||||
|
}
|
||||||
|
adminScopeHelper.ensureShopAccessible(currentUser, targetUser.getShopId(), "无权给其他店铺用户发放优惠券");
|
||||||
|
}
|
||||||
|
shopId = adminScopeHelper.resolveShopScope(currentUser, couponVO.getShopId());
|
||||||
boolean success = couponService.distributeCoupon(couponId, userIds, quantity, shopId);
|
boolean success = couponService.distributeCoupon(couponId, userIds, quantity, shopId);
|
||||||
return Result.success(success);
|
return Result.success(success);
|
||||||
}
|
}
|
||||||
|
|||||||
+26
-4
@@ -2,12 +2,15 @@ package com.xiaowang.yuminailcore.controller;
|
|||||||
|
|
||||||
import com.xiaowang.yuminailcore.annotation.RequirePermission;
|
import com.xiaowang.yuminailcore.annotation.RequirePermission;
|
||||||
import com.xiaowang.yuminailcore.common.Result;
|
import com.xiaowang.yuminailcore.common.Result;
|
||||||
|
import com.xiaowang.yuminailcore.entity.UserDO;
|
||||||
import com.xiaowang.yuminailcore.service.OrderService;
|
import com.xiaowang.yuminailcore.service.OrderService;
|
||||||
|
import com.xiaowang.yuminailcore.support.AdminScopeHelper;
|
||||||
import com.xiaowang.yuminailcore.vo.OrderVO;
|
import com.xiaowang.yuminailcore.vo.OrderVO;
|
||||||
import com.xiaowang.yuminailcore.vo.PageResultVO;
|
import com.xiaowang.yuminailcore.vo.PageResultVO;
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
import org.springframework.web.bind.annotation.*;
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
|
import javax.servlet.http.HttpServletRequest;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -19,6 +22,7 @@ import java.util.List;
|
|||||||
public class AdminOrderController {
|
public class AdminOrderController {
|
||||||
|
|
||||||
private final OrderService orderService;
|
private final OrderService orderService;
|
||||||
|
private final AdminScopeHelper adminScopeHelper;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取订单列表(分页)
|
* 获取订单列表(分页)
|
||||||
@@ -26,15 +30,22 @@ public class AdminOrderController {
|
|||||||
@GetMapping("/list")
|
@GetMapping("/list")
|
||||||
@RequirePermission("order:view")
|
@RequirePermission("order:view")
|
||||||
public Result<PageResultVO<OrderVO>> listOrders(
|
public Result<PageResultVO<OrderVO>> listOrders(
|
||||||
|
HttpServletRequest request,
|
||||||
@RequestParam(defaultValue = "1") Integer page,
|
@RequestParam(defaultValue = "1") Integer page,
|
||||||
@RequestParam(defaultValue = "10") Integer size,
|
@RequestParam(defaultValue = "10") Integer size,
|
||||||
@RequestParam(required = false) String keyword,
|
@RequestParam(required = false) String keyword,
|
||||||
@RequestParam(required = false) Integer status
|
@RequestParam(required = false) Integer status
|
||||||
) {
|
) {
|
||||||
// 先获取所有订单,然后进行分页处理
|
UserDO currentUser = adminScopeHelper.getCurrentUser(request);
|
||||||
|
Long shopId = adminScopeHelper.resolveShopScope(currentUser, null);
|
||||||
|
|
||||||
List<OrderVO> allOrders = orderService.getAllOrders();
|
List<OrderVO> allOrders = orderService.getAllOrders();
|
||||||
|
if (shopId != null) {
|
||||||
|
allOrders = allOrders.stream()
|
||||||
|
.filter(order -> shopId.equals(order.getShopId()))
|
||||||
|
.toList();
|
||||||
|
}
|
||||||
|
|
||||||
// 根据条件过滤
|
|
||||||
if (keyword != null && !keyword.isEmpty()) {
|
if (keyword != null && !keyword.isEmpty()) {
|
||||||
allOrders = allOrders.stream()
|
allOrders = allOrders.stream()
|
||||||
.filter(order -> order.getOrderNo() != null && order.getOrderNo().contains(keyword))
|
.filter(order -> order.getOrderNo() != null && order.getOrderNo().contains(keyword))
|
||||||
@@ -46,7 +57,6 @@ public class AdminOrderController {
|
|||||||
.toList();
|
.toList();
|
||||||
}
|
}
|
||||||
|
|
||||||
// 手动分页
|
|
||||||
int total = allOrders.size();
|
int total = allOrders.size();
|
||||||
int start = (page - 1) * size;
|
int start = (page - 1) * size;
|
||||||
int end = Math.min(start + size, total);
|
int end = Math.min(start + size, total);
|
||||||
@@ -66,7 +76,19 @@ public class AdminOrderController {
|
|||||||
*/
|
*/
|
||||||
@PutMapping("/update-status/{id}")
|
@PutMapping("/update-status/{id}")
|
||||||
@RequirePermission("order:process")
|
@RequirePermission("order:process")
|
||||||
public Result<Boolean> updateOrderStatus(@PathVariable Long id, @RequestParam Integer status) {
|
public Result<Boolean> updateOrderStatus(HttpServletRequest request, @PathVariable Long id, @RequestParam Integer status) {
|
||||||
|
UserDO currentUser = adminScopeHelper.getCurrentUser(request);
|
||||||
|
Long shopId = adminScopeHelper.resolveShopScope(currentUser, null);
|
||||||
|
if (shopId != null) {
|
||||||
|
OrderVO orderVO = orderService.getAllOrders().stream()
|
||||||
|
.filter(order -> id.equals(order.getId()))
|
||||||
|
.findFirst()
|
||||||
|
.orElse(null);
|
||||||
|
if (orderVO == null) {
|
||||||
|
return Result.success(false);
|
||||||
|
}
|
||||||
|
adminScopeHelper.ensureShopAccessible(currentUser, orderVO.getShopId(), "无权处理其他店铺订单");
|
||||||
|
}
|
||||||
orderService.processOrder(id, status);
|
orderService.processOrder(id, status);
|
||||||
return Result.success(true);
|
return Result.success(true);
|
||||||
}
|
}
|
||||||
|
|||||||
+23
-4
@@ -4,7 +4,10 @@ import com.xiaowang.yuminailcore.annotation.RequirePermission;
|
|||||||
import com.xiaowang.yuminailcore.common.Result;
|
import com.xiaowang.yuminailcore.common.Result;
|
||||||
import com.xiaowang.yuminailcore.dto.PermissionDTO;
|
import com.xiaowang.yuminailcore.dto.PermissionDTO;
|
||||||
import com.xiaowang.yuminailcore.dto.UserPermissionDTO;
|
import com.xiaowang.yuminailcore.dto.UserPermissionDTO;
|
||||||
|
import com.xiaowang.yuminailcore.entity.UserDO;
|
||||||
import com.xiaowang.yuminailcore.service.PermissionService;
|
import com.xiaowang.yuminailcore.service.PermissionService;
|
||||||
|
import com.xiaowang.yuminailcore.service.UserService;
|
||||||
|
import com.xiaowang.yuminailcore.support.AdminScopeHelper;
|
||||||
import com.xiaowang.yuminailcore.vo.PermissionVO;
|
import com.xiaowang.yuminailcore.vo.PermissionVO;
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
import org.springframework.web.bind.annotation.*;
|
import org.springframework.web.bind.annotation.*;
|
||||||
@@ -18,24 +21,32 @@ import java.util.List;
|
|||||||
public class AdminPermissionController {
|
public class AdminPermissionController {
|
||||||
|
|
||||||
private final PermissionService permissionService;
|
private final PermissionService permissionService;
|
||||||
|
private final UserService userService;
|
||||||
|
private final AdminScopeHelper adminScopeHelper;
|
||||||
|
|
||||||
@PostMapping("/create")
|
@PostMapping("/create")
|
||||||
@RequirePermission("permission:create")
|
@RequirePermission("permission:create")
|
||||||
public Result<Long> createPermission(@RequestBody PermissionDTO permissionDTO) {
|
public Result<Long> createPermission(HttpServletRequest request, @RequestBody PermissionDTO permissionDTO) {
|
||||||
|
UserDO currentUser = adminScopeHelper.getCurrentUser(request);
|
||||||
|
adminScopeHelper.requirePlatformAdmin(currentUser, "只有平台管理员可以维护权限定义");
|
||||||
Long id = permissionService.createPermission(permissionDTO);
|
Long id = permissionService.createPermission(permissionDTO);
|
||||||
return Result.success(id);
|
return Result.success(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
@PutMapping("/update/{id}")
|
@PutMapping("/update/{id}")
|
||||||
@RequirePermission("permission:edit")
|
@RequirePermission("permission:edit")
|
||||||
public Result<Boolean> updatePermission(@PathVariable Long id, @RequestBody PermissionDTO permissionDTO) {
|
public Result<Boolean> updatePermission(HttpServletRequest request, @PathVariable Long id, @RequestBody PermissionDTO permissionDTO) {
|
||||||
|
UserDO currentUser = adminScopeHelper.getCurrentUser(request);
|
||||||
|
adminScopeHelper.requirePlatformAdmin(currentUser, "只有平台管理员可以维护权限定义");
|
||||||
boolean success = permissionService.updatePermission(id, permissionDTO);
|
boolean success = permissionService.updatePermission(id, permissionDTO);
|
||||||
return Result.success(success);
|
return Result.success(success);
|
||||||
}
|
}
|
||||||
|
|
||||||
@DeleteMapping("/delete/{id}")
|
@DeleteMapping("/delete/{id}")
|
||||||
@RequirePermission("permission:delete")
|
@RequirePermission("permission:delete")
|
||||||
public Result<Boolean> deletePermission(@PathVariable Long id) {
|
public Result<Boolean> deletePermission(HttpServletRequest request, @PathVariable Long id) {
|
||||||
|
UserDO currentUser = adminScopeHelper.getCurrentUser(request);
|
||||||
|
adminScopeHelper.requirePlatformAdmin(currentUser, "只有平台管理员可以维护权限定义");
|
||||||
boolean success = permissionService.deletePermission(id);
|
boolean success = permissionService.deletePermission(id);
|
||||||
return Result.success(success);
|
return Result.success(success);
|
||||||
}
|
}
|
||||||
@@ -63,7 +74,15 @@ public class AdminPermissionController {
|
|||||||
|
|
||||||
@GetMapping("/user/{userId}")
|
@GetMapping("/user/{userId}")
|
||||||
@RequirePermission("permission:view")
|
@RequirePermission("permission:view")
|
||||||
public Result<List<PermissionVO>> listUserPermissions(@PathVariable Long userId) {
|
public Result<List<PermissionVO>> listUserPermissions(HttpServletRequest request, @PathVariable Long userId) {
|
||||||
|
UserDO currentUser = adminScopeHelper.getCurrentUser(request);
|
||||||
|
if (!adminScopeHelper.isPlatformAdmin(currentUser)) {
|
||||||
|
UserDO targetUser = userService.getById(userId);
|
||||||
|
if (targetUser == null) {
|
||||||
|
throw new RuntimeException("目标用户不存在");
|
||||||
|
}
|
||||||
|
adminScopeHelper.ensureShopAccessible(currentUser, targetUser.getShopId(), "无权查看其他店铺用户权限");
|
||||||
|
}
|
||||||
List<PermissionVO> permissionVOs = permissionService.listUserPermissions(userId);
|
List<PermissionVO> permissionVOs = permissionService.listUserPermissions(userId);
|
||||||
return Result.success(permissionVOs);
|
return Result.success(permissionVOs);
|
||||||
}
|
}
|
||||||
|
|||||||
+32
-5
@@ -3,12 +3,15 @@ package com.xiaowang.yuminailcore.controller;
|
|||||||
import com.xiaowang.yuminailcore.annotation.RequirePermission;
|
import com.xiaowang.yuminailcore.annotation.RequirePermission;
|
||||||
import com.xiaowang.yuminailcore.common.Result;
|
import com.xiaowang.yuminailcore.common.Result;
|
||||||
import com.xiaowang.yuminailcore.dto.ProductDTO;
|
import com.xiaowang.yuminailcore.dto.ProductDTO;
|
||||||
|
import com.xiaowang.yuminailcore.entity.UserDO;
|
||||||
import com.xiaowang.yuminailcore.service.ProductService;
|
import com.xiaowang.yuminailcore.service.ProductService;
|
||||||
|
import com.xiaowang.yuminailcore.support.AdminScopeHelper;
|
||||||
import com.xiaowang.yuminailcore.vo.PageResultVO;
|
import com.xiaowang.yuminailcore.vo.PageResultVO;
|
||||||
import com.xiaowang.yuminailcore.vo.ProductVO;
|
import com.xiaowang.yuminailcore.vo.ProductVO;
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
import org.springframework.web.bind.annotation.*;
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
|
import javax.servlet.http.HttpServletRequest;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@RestController
|
@RestController
|
||||||
@@ -17,44 +20,68 @@ import java.util.List;
|
|||||||
public class AdminProductController {
|
public class AdminProductController {
|
||||||
|
|
||||||
private final ProductService productService;
|
private final ProductService productService;
|
||||||
|
private final AdminScopeHelper adminScopeHelper;
|
||||||
|
|
||||||
@GetMapping("/list")
|
@GetMapping("/list")
|
||||||
@RequirePermission("product:view")
|
@RequirePermission("product:view")
|
||||||
public Result<PageResultVO<ProductVO>> listProducts(
|
public Result<PageResultVO<ProductVO>> listProducts(
|
||||||
|
HttpServletRequest request,
|
||||||
@RequestParam(defaultValue = "1") Integer page,
|
@RequestParam(defaultValue = "1") Integer page,
|
||||||
@RequestParam(defaultValue = "10") Integer size,
|
@RequestParam(defaultValue = "10") Integer size,
|
||||||
@RequestParam(required = false) String keyword,
|
@RequestParam(required = false) String keyword,
|
||||||
@RequestParam(required = false) Long shopId
|
@RequestParam(required = false) Long shopId
|
||||||
) {
|
) {
|
||||||
|
UserDO currentUser = adminScopeHelper.getCurrentUser(request);
|
||||||
|
shopId = adminScopeHelper.resolveShopScope(currentUser, shopId);
|
||||||
PageResultVO<ProductVO> result = productService.pageProducts(page, size, keyword, shopId);
|
PageResultVO<ProductVO> result = productService.pageProducts(page, size, keyword, shopId);
|
||||||
return Result.success(result);
|
return Result.success(result);
|
||||||
}
|
}
|
||||||
|
|
||||||
@PostMapping("/create")
|
@PostMapping("/create")
|
||||||
@RequirePermission("product:create")
|
@RequirePermission("product:create")
|
||||||
public Result<Long> createProduct(@RequestBody ProductDTO productDTO) {
|
public Result<Long> createProduct(HttpServletRequest request, @RequestBody ProductDTO productDTO) {
|
||||||
|
UserDO currentUser = adminScopeHelper.getCurrentUser(request);
|
||||||
|
productDTO.setShopId(adminScopeHelper.resolveShopScope(currentUser, productDTO.getShopId()));
|
||||||
Long id = productService.createProduct(productDTO);
|
Long id = productService.createProduct(productDTO);
|
||||||
return Result.success(id);
|
return Result.success(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
@PutMapping("/update/{id}")
|
@PutMapping("/update/{id}")
|
||||||
@RequirePermission("product:edit")
|
@RequirePermission("product:edit")
|
||||||
public Result<Boolean> updateProduct(@PathVariable Long id, @RequestBody ProductDTO productDTO) {
|
public Result<Boolean> updateProduct(HttpServletRequest request, @PathVariable Long id, @RequestBody ProductDTO productDTO) {
|
||||||
|
UserDO currentUser = adminScopeHelper.getCurrentUser(request);
|
||||||
|
ProductVO productVO = productService.getProductById(id);
|
||||||
|
if (productVO == null) {
|
||||||
|
return Result.success(false);
|
||||||
|
}
|
||||||
|
adminScopeHelper.ensureShopAccessible(currentUser, productVO.getShopId(), "无权编辑其他店铺商品");
|
||||||
|
Long targetShopId = productDTO.getShopId() != null ? productDTO.getShopId() : productVO.getShopId();
|
||||||
|
productDTO.setShopId(adminScopeHelper.resolveShopScope(currentUser, targetShopId));
|
||||||
boolean success = productService.updateProduct(id, productDTO);
|
boolean success = productService.updateProduct(id, productDTO);
|
||||||
return Result.success(success);
|
return Result.success(success);
|
||||||
}
|
}
|
||||||
|
|
||||||
@DeleteMapping("/delete/{id}")
|
@DeleteMapping("/delete/{id}")
|
||||||
@RequirePermission("product:delete")
|
@RequirePermission("product:delete")
|
||||||
public Result<Boolean> deleteProduct(@PathVariable Long id) {
|
public Result<Boolean> deleteProduct(HttpServletRequest request, @PathVariable Long id) {
|
||||||
|
UserDO currentUser = adminScopeHelper.getCurrentUser(request);
|
||||||
|
ProductVO productVO = productService.getProductById(id);
|
||||||
|
if (productVO == null) {
|
||||||
|
return Result.success(false);
|
||||||
|
}
|
||||||
|
adminScopeHelper.ensureShopAccessible(currentUser, productVO.getShopId(), "无权删除其他店铺商品");
|
||||||
boolean success = productService.deleteProduct(id);
|
boolean success = productService.deleteProduct(id);
|
||||||
return Result.success(success);
|
return Result.success(success);
|
||||||
}
|
}
|
||||||
|
|
||||||
@GetMapping("/list/all")
|
@GetMapping("/list/all")
|
||||||
@RequirePermission("product:view")
|
@RequirePermission("product:view")
|
||||||
public Result<List<ProductVO>> listAllProducts() {
|
public Result<List<ProductVO>> listAllProducts(HttpServletRequest request) {
|
||||||
List<ProductVO> products = productService.listAllProducts();
|
UserDO currentUser = adminScopeHelper.getCurrentUser(request);
|
||||||
|
Long shopId = adminScopeHelper.resolveShopScope(currentUser, null);
|
||||||
|
List<ProductVO> products = shopId == null
|
||||||
|
? productService.listAllProducts()
|
||||||
|
: productService.listProductsByShopId(shopId);
|
||||||
return Result.success(products);
|
return Result.success(products);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+32
-6
@@ -3,12 +3,15 @@ package com.xiaowang.yuminailcore.controller;
|
|||||||
import com.xiaowang.yuminailcore.annotation.RequirePermission;
|
import com.xiaowang.yuminailcore.annotation.RequirePermission;
|
||||||
import com.xiaowang.yuminailcore.common.Result;
|
import com.xiaowang.yuminailcore.common.Result;
|
||||||
import com.xiaowang.yuminailcore.dto.ShopDTO;
|
import com.xiaowang.yuminailcore.dto.ShopDTO;
|
||||||
|
import com.xiaowang.yuminailcore.entity.UserDO;
|
||||||
import com.xiaowang.yuminailcore.service.ShopService;
|
import com.xiaowang.yuminailcore.service.ShopService;
|
||||||
|
import com.xiaowang.yuminailcore.support.AdminScopeHelper;
|
||||||
import com.xiaowang.yuminailcore.vo.PageResultVO;
|
import com.xiaowang.yuminailcore.vo.PageResultVO;
|
||||||
import com.xiaowang.yuminailcore.vo.ShopVO;
|
import com.xiaowang.yuminailcore.vo.ShopVO;
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
import org.springframework.web.bind.annotation.*;
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
|
import javax.servlet.http.HttpServletRequest;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@RestController
|
@RestController
|
||||||
@@ -17,50 +20,73 @@ import java.util.List;
|
|||||||
public class AdminShopController {
|
public class AdminShopController {
|
||||||
|
|
||||||
private final ShopService shopService;
|
private final ShopService shopService;
|
||||||
|
private final AdminScopeHelper adminScopeHelper;
|
||||||
|
|
||||||
@GetMapping("/list")
|
@GetMapping("/list")
|
||||||
@RequirePermission("shop:view")
|
@RequirePermission("shop:view")
|
||||||
public Result<PageResultVO<ShopVO>> listShops(
|
public Result<PageResultVO<ShopVO>> listShops(
|
||||||
|
HttpServletRequest request,
|
||||||
@RequestParam(defaultValue = "1") Integer page,
|
@RequestParam(defaultValue = "1") Integer page,
|
||||||
@RequestParam(defaultValue = "10") Integer size,
|
@RequestParam(defaultValue = "10") Integer size,
|
||||||
@RequestParam(required = false) String keyword,
|
@RequestParam(required = false) String keyword,
|
||||||
@RequestParam(required = false) Long shopId
|
@RequestParam(required = false) Long shopId
|
||||||
) {
|
) {
|
||||||
|
UserDO currentUser = adminScopeHelper.getCurrentUser(request);
|
||||||
|
shopId = adminScopeHelper.resolveShopScope(currentUser, shopId);
|
||||||
PageResultVO<ShopVO> result = shopService.pageShops(page, size, keyword, shopId);
|
PageResultVO<ShopVO> result = shopService.pageShops(page, size, keyword, shopId);
|
||||||
return Result.success(result);
|
return Result.success(result);
|
||||||
}
|
}
|
||||||
|
|
||||||
@PostMapping("/create")
|
@PostMapping("/create")
|
||||||
@RequirePermission("shop:create")
|
@RequirePermission("shop:create")
|
||||||
public Result<Long> createShop(@RequestBody ShopDTO shopDTO) {
|
public Result<Long> createShop(HttpServletRequest request, @RequestBody ShopDTO shopDTO) {
|
||||||
|
UserDO currentUser = adminScopeHelper.getCurrentUser(request);
|
||||||
|
adminScopeHelper.requirePlatformAdmin(currentUser, "只有平台管理员可以创建店铺");
|
||||||
Long id = shopService.createShop(shopDTO);
|
Long id = shopService.createShop(shopDTO);
|
||||||
return Result.success(id);
|
return Result.success(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
@PutMapping("/update/{id}")
|
@PutMapping("/update/{id}")
|
||||||
@RequirePermission("shop:edit")
|
@RequirePermission("shop:edit")
|
||||||
public Result<Boolean> updateShop(@PathVariable Long id, @RequestBody ShopDTO shopDTO) {
|
public Result<Boolean> updateShop(HttpServletRequest request, @PathVariable Long id, @RequestBody ShopDTO shopDTO) {
|
||||||
|
UserDO currentUser = adminScopeHelper.getCurrentUser(request);
|
||||||
|
ShopVO shopVO = shopService.getShopById(id);
|
||||||
|
if (shopVO == null) {
|
||||||
|
return Result.success(false);
|
||||||
|
}
|
||||||
|
adminScopeHelper.ensureShopAccessible(currentUser, shopVO.getId(), "无权编辑其他店铺信息");
|
||||||
boolean success = shopService.updateShop(id, shopDTO);
|
boolean success = shopService.updateShop(id, shopDTO);
|
||||||
return Result.success(success);
|
return Result.success(success);
|
||||||
}
|
}
|
||||||
|
|
||||||
@DeleteMapping("/delete/{id}")
|
@DeleteMapping("/delete/{id}")
|
||||||
@RequirePermission("shop:delete")
|
@RequirePermission("shop:delete")
|
||||||
public Result<Boolean> deleteShop(@PathVariable Long id) {
|
public Result<Boolean> deleteShop(HttpServletRequest request, @PathVariable Long id) {
|
||||||
|
UserDO currentUser = adminScopeHelper.getCurrentUser(request);
|
||||||
|
adminScopeHelper.requirePlatformAdmin(currentUser, "只有平台管理员可以删除店铺");
|
||||||
boolean success = shopService.deleteShop(id);
|
boolean success = shopService.deleteShop(id);
|
||||||
return Result.success(success);
|
return Result.success(success);
|
||||||
}
|
}
|
||||||
|
|
||||||
@GetMapping("/list/all")
|
@GetMapping("/list/all")
|
||||||
@RequirePermission("shop:view")
|
@RequirePermission("shop:view")
|
||||||
public Result<List<ShopVO>> listAllShops() {
|
public Result<List<ShopVO>> listAllShops(HttpServletRequest request) {
|
||||||
List<ShopVO> shops = shopService.listAllShops();
|
UserDO currentUser = adminScopeHelper.getCurrentUser(request);
|
||||||
|
List<ShopVO> shops;
|
||||||
|
if (adminScopeHelper.isPlatformAdmin(currentUser)) {
|
||||||
|
shops = shopService.listAllShops();
|
||||||
|
} else {
|
||||||
|
ShopVO currentShop = shopService.getShopById(adminScopeHelper.getManagedShopId(currentUser));
|
||||||
|
shops = currentShop == null ? List.of() : List.of(currentShop);
|
||||||
|
}
|
||||||
return Result.success(shops);
|
return Result.success(shops);
|
||||||
}
|
}
|
||||||
|
|
||||||
@GetMapping("/{id}")
|
@GetMapping("/{id}")
|
||||||
@RequirePermission("shop:view")
|
@RequirePermission("shop:view")
|
||||||
public Result<ShopVO> getShop(@PathVariable Long id) {
|
public Result<ShopVO> getShop(HttpServletRequest request, @PathVariable Long id) {
|
||||||
|
UserDO currentUser = adminScopeHelper.getCurrentUser(request);
|
||||||
|
adminScopeHelper.ensureShopAccessible(currentUser, id, "无权查看其他店铺信息");
|
||||||
ShopVO shop = shopService.getShopById(id);
|
ShopVO shop = shopService.getShopById(id);
|
||||||
return Result.success(shop);
|
return Result.success(shop);
|
||||||
}
|
}
|
||||||
|
|||||||
+35
-7
@@ -3,11 +3,14 @@ package com.xiaowang.yuminailcore.controller;
|
|||||||
import com.xiaowang.yuminailcore.annotation.RequirePermission;
|
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.entity.UserDO;
|
||||||
import com.xiaowang.yuminailcore.service.TagService;
|
import com.xiaowang.yuminailcore.service.TagService;
|
||||||
|
import com.xiaowang.yuminailcore.support.AdminScopeHelper;
|
||||||
import com.xiaowang.yuminailcore.vo.TagVO;
|
import com.xiaowang.yuminailcore.vo.TagVO;
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
import org.springframework.web.bind.annotation.*;
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
|
import javax.servlet.http.HttpServletRequest;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -19,13 +22,16 @@ import java.util.List;
|
|||||||
public class AdminTagController {
|
public class AdminTagController {
|
||||||
|
|
||||||
private final TagService tagService;
|
private final TagService tagService;
|
||||||
|
private final AdminScopeHelper adminScopeHelper;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 创建标签
|
* 创建标签
|
||||||
*/
|
*/
|
||||||
@PostMapping("/create")
|
@PostMapping("/create")
|
||||||
@RequirePermission("tag:create")
|
@RequirePermission("tag:create")
|
||||||
public Result<Long> createTag(@RequestBody TagDTO tagDTO) {
|
public Result<Long> createTag(HttpServletRequest request, @RequestBody TagDTO tagDTO) {
|
||||||
|
UserDO currentUser = adminScopeHelper.getCurrentUser(request);
|
||||||
|
tagDTO.setShopId(adminScopeHelper.resolveShopScope(currentUser, tagDTO.getShopId()));
|
||||||
Long id = tagService.createTag(tagDTO);
|
Long id = tagService.createTag(tagDTO);
|
||||||
return Result.success(id);
|
return Result.success(id);
|
||||||
}
|
}
|
||||||
@@ -35,7 +41,15 @@ public class AdminTagController {
|
|||||||
*/
|
*/
|
||||||
@PutMapping("/update/{id}")
|
@PutMapping("/update/{id}")
|
||||||
@RequirePermission("tag:edit")
|
@RequirePermission("tag:edit")
|
||||||
public Result<Boolean> updateTag(@PathVariable Long id, @RequestBody TagDTO tagDTO) {
|
public Result<Boolean> updateTag(HttpServletRequest request, @PathVariable Long id, @RequestBody TagDTO tagDTO) {
|
||||||
|
UserDO currentUser = adminScopeHelper.getCurrentUser(request);
|
||||||
|
TagVO tagVO = tagService.getTagById(id);
|
||||||
|
if (tagVO == null) {
|
||||||
|
return Result.success(false);
|
||||||
|
}
|
||||||
|
adminScopeHelper.ensureShopAccessible(currentUser, tagVO.getShopId(), "无权编辑其他店铺标签");
|
||||||
|
Long targetShopId = tagDTO.getShopId() != null ? tagDTO.getShopId() : tagVO.getShopId();
|
||||||
|
tagDTO.setShopId(adminScopeHelper.resolveShopScope(currentUser, targetShopId));
|
||||||
boolean success = tagService.updateTag(id, tagDTO);
|
boolean success = tagService.updateTag(id, tagDTO);
|
||||||
return Result.success(success);
|
return Result.success(success);
|
||||||
}
|
}
|
||||||
@@ -45,7 +59,13 @@ public class AdminTagController {
|
|||||||
*/
|
*/
|
||||||
@DeleteMapping("/delete/{id}")
|
@DeleteMapping("/delete/{id}")
|
||||||
@RequirePermission("tag:delete")
|
@RequirePermission("tag:delete")
|
||||||
public Result<Boolean> deleteTag(@PathVariable Long id) {
|
public Result<Boolean> deleteTag(HttpServletRequest request, @PathVariable Long id) {
|
||||||
|
UserDO currentUser = adminScopeHelper.getCurrentUser(request);
|
||||||
|
TagVO tagVO = tagService.getTagById(id);
|
||||||
|
if (tagVO == null) {
|
||||||
|
return Result.success(false);
|
||||||
|
}
|
||||||
|
adminScopeHelper.ensureShopAccessible(currentUser, tagVO.getShopId(), "无权删除其他店铺标签");
|
||||||
boolean success = tagService.deleteTag(id);
|
boolean success = tagService.deleteTag(id);
|
||||||
return Result.success(success);
|
return Result.success(success);
|
||||||
}
|
}
|
||||||
@@ -55,8 +75,12 @@ public class AdminTagController {
|
|||||||
*/
|
*/
|
||||||
@GetMapping("/get/{id}")
|
@GetMapping("/get/{id}")
|
||||||
@RequirePermission("tag:view")
|
@RequirePermission("tag:view")
|
||||||
public Result<TagVO> getTagById(@PathVariable Long id) {
|
public Result<TagVO> getTagById(HttpServletRequest request, @PathVariable Long id) {
|
||||||
|
UserDO currentUser = adminScopeHelper.getCurrentUser(request);
|
||||||
TagVO tagVO = tagService.getTagById(id);
|
TagVO tagVO = tagService.getTagById(id);
|
||||||
|
if (tagVO != null) {
|
||||||
|
adminScopeHelper.ensureShopAccessible(currentUser, tagVO.getShopId(), "无权查看其他店铺标签");
|
||||||
|
}
|
||||||
return Result.success(tagVO);
|
return Result.success(tagVO);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -65,8 +89,10 @@ public class AdminTagController {
|
|||||||
*/
|
*/
|
||||||
@GetMapping("/list/all")
|
@GetMapping("/list/all")
|
||||||
@RequirePermission("tag:view")
|
@RequirePermission("tag:view")
|
||||||
public Result<List<TagVO>> listAllTags() {
|
public Result<List<TagVO>> listAllTags(HttpServletRequest request) {
|
||||||
List<TagVO> tagVOs = tagService.listAllTags();
|
UserDO currentUser = adminScopeHelper.getCurrentUser(request);
|
||||||
|
Long shopId = adminScopeHelper.resolveShopScope(currentUser, null);
|
||||||
|
List<TagVO> tagVOs = shopId == null ? tagService.listAllTags() : tagService.listTagsByShopId(shopId);
|
||||||
return Result.success(tagVOs);
|
return Result.success(tagVOs);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -75,7 +101,9 @@ public class AdminTagController {
|
|||||||
*/
|
*/
|
||||||
@GetMapping("/list/by-shop/{shopId}")
|
@GetMapping("/list/by-shop/{shopId}")
|
||||||
@RequirePermission("tag:view")
|
@RequirePermission("tag:view")
|
||||||
public Result<List<TagVO>> listTagsByShopId(@PathVariable Long shopId) {
|
public Result<List<TagVO>> listTagsByShopId(HttpServletRequest request, @PathVariable Long shopId) {
|
||||||
|
UserDO currentUser = adminScopeHelper.getCurrentUser(request);
|
||||||
|
shopId = adminScopeHelper.resolveShopScope(currentUser, shopId);
|
||||||
List<TagVO> tagVOs = tagService.listTagsByShopId(shopId);
|
List<TagVO> tagVOs = tagService.listTagsByShopId(shopId);
|
||||||
return Result.success(tagVOs);
|
return Result.success(tagVOs);
|
||||||
}
|
}
|
||||||
|
|||||||
+55
-8
@@ -3,7 +3,9 @@ package com.xiaowang.yuminailcore.controller;
|
|||||||
import com.xiaowang.yuminailcore.annotation.RequirePermission;
|
import com.xiaowang.yuminailcore.annotation.RequirePermission;
|
||||||
import com.xiaowang.yuminailcore.common.Result;
|
import com.xiaowang.yuminailcore.common.Result;
|
||||||
import com.xiaowang.yuminailcore.dto.UserDTO;
|
import com.xiaowang.yuminailcore.dto.UserDTO;
|
||||||
|
import com.xiaowang.yuminailcore.entity.UserDO;
|
||||||
import com.xiaowang.yuminailcore.service.UserService;
|
import com.xiaowang.yuminailcore.service.UserService;
|
||||||
|
import com.xiaowang.yuminailcore.support.AdminScopeHelper;
|
||||||
import com.xiaowang.yuminailcore.vo.PageResultVO;
|
import com.xiaowang.yuminailcore.vo.PageResultVO;
|
||||||
import com.xiaowang.yuminailcore.vo.UserVO;
|
import com.xiaowang.yuminailcore.vo.UserVO;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
@@ -20,37 +22,64 @@ import java.util.stream.Collectors;
|
|||||||
public class AdminUserController {
|
public class AdminUserController {
|
||||||
|
|
||||||
private final UserService userService;
|
private final UserService userService;
|
||||||
|
private final AdminScopeHelper adminScopeHelper;
|
||||||
|
|
||||||
@GetMapping("/list")
|
@GetMapping("/list")
|
||||||
@RequirePermission("user:view")
|
@RequirePermission("user:view")
|
||||||
public Result<PageResultVO<UserVO>> listUsers(
|
public Result<PageResultVO<UserVO>> listUsers(
|
||||||
|
HttpServletRequest request,
|
||||||
@RequestParam(defaultValue = "1") Integer page,
|
@RequestParam(defaultValue = "1") Integer page,
|
||||||
@RequestParam(defaultValue = "10") Integer size,
|
@RequestParam(defaultValue = "10") Integer size,
|
||||||
@RequestParam(required = false) String keyword,
|
@RequestParam(required = false) String keyword,
|
||||||
@RequestParam(required = false) Long shopId,
|
@RequestParam(required = false) Long shopId,
|
||||||
@RequestParam(required = false) Integer type
|
@RequestParam(required = false) Integer type
|
||||||
) {
|
) {
|
||||||
|
UserDO currentUser = adminScopeHelper.getCurrentUser(request);
|
||||||
|
shopId = adminScopeHelper.resolveShopScope(currentUser, shopId);
|
||||||
PageResultVO<UserVO> result = userService.pageUsers(page, size, keyword, shopId, type);
|
PageResultVO<UserVO> result = userService.pageUsers(page, size, keyword, shopId, type);
|
||||||
return Result.success(result);
|
return Result.success(result);
|
||||||
}
|
}
|
||||||
|
|
||||||
@PostMapping("/create")
|
@PostMapping("/create")
|
||||||
@RequirePermission("user:create")
|
@RequirePermission("user:create")
|
||||||
public Result<Long> createUser(@RequestBody UserDTO userDTO) {
|
public Result<Long> createUser(HttpServletRequest request, @RequestBody UserDTO userDTO) {
|
||||||
|
UserDO currentUser = adminScopeHelper.getCurrentUser(request);
|
||||||
|
adminScopeHelper.ensureAssignableUserType(currentUser, userDTO.getType());
|
||||||
|
if (!adminScopeHelper.isPlatformAdmin(currentUser)) {
|
||||||
|
userDTO.setShopId(adminScopeHelper.getManagedShopId(currentUser));
|
||||||
|
}
|
||||||
Long id = userService.createUser(userDTO);
|
Long id = userService.createUser(userDTO);
|
||||||
return Result.success(id);
|
return Result.success(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
@PutMapping("/update/{id}")
|
@PutMapping("/update/{id}")
|
||||||
@RequirePermission("user:edit")
|
@RequirePermission("user:edit")
|
||||||
public Result<Boolean> updateUser(@PathVariable Long id, @RequestBody UserDTO userDTO) {
|
public Result<Boolean> updateUser(HttpServletRequest request, @PathVariable Long id, @RequestBody UserDTO userDTO) {
|
||||||
|
UserDO currentUser = adminScopeHelper.getCurrentUser(request);
|
||||||
|
UserVO targetUser = userService.getUserById(id);
|
||||||
|
if (targetUser == null) {
|
||||||
|
return Result.success(false);
|
||||||
|
}
|
||||||
|
adminScopeHelper.ensureShopAccessible(currentUser, targetUser.getShopId(), "无权编辑其他店铺用户");
|
||||||
|
if (userDTO.getType() != null) {
|
||||||
|
adminScopeHelper.ensureAssignableUserType(currentUser, userDTO.getType());
|
||||||
|
}
|
||||||
|
if (!adminScopeHelper.isPlatformAdmin(currentUser)) {
|
||||||
|
userDTO.setShopId(adminScopeHelper.getManagedShopId(currentUser));
|
||||||
|
}
|
||||||
boolean success = userService.updateUser(id, userDTO);
|
boolean success = userService.updateUser(id, userDTO);
|
||||||
return Result.success(success);
|
return Result.success(success);
|
||||||
}
|
}
|
||||||
|
|
||||||
@PutMapping("/status/{id}")
|
@PutMapping("/status/{id}")
|
||||||
@RequirePermission("user:disable")
|
@RequirePermission("user:disable")
|
||||||
public Result<Boolean> updateUserStatus(@PathVariable Long id, @RequestBody StatusRequest request) {
|
public Result<Boolean> updateUserStatus(HttpServletRequest httpRequest, @PathVariable Long id, @RequestBody StatusRequest request) {
|
||||||
|
UserDO currentUser = adminScopeHelper.getCurrentUser(httpRequest);
|
||||||
|
UserVO targetUser = userService.getUserById(id);
|
||||||
|
if (targetUser == null) {
|
||||||
|
return Result.success(false);
|
||||||
|
}
|
||||||
|
adminScopeHelper.ensureShopAccessible(currentUser, targetUser.getShopId(), "无权变更其他店铺用户状态");
|
||||||
boolean success = userService.updateUserStatus(id, request.getStatus());
|
boolean success = userService.updateUserStatus(id, request.getStatus());
|
||||||
return Result.success(success);
|
return Result.success(success);
|
||||||
}
|
}
|
||||||
@@ -58,6 +87,12 @@ public class AdminUserController {
|
|||||||
@PostMapping("/reset-password/{userId}")
|
@PostMapping("/reset-password/{userId}")
|
||||||
@RequirePermission("user:reset_password")
|
@RequirePermission("user:reset_password")
|
||||||
public Result<Boolean> resetPassword(HttpServletRequest request, @PathVariable Long userId) {
|
public Result<Boolean> resetPassword(HttpServletRequest request, @PathVariable Long userId) {
|
||||||
|
UserDO currentUser = adminScopeHelper.getCurrentUser(request);
|
||||||
|
UserVO targetUser = userService.getUserById(userId);
|
||||||
|
if (targetUser == null) {
|
||||||
|
return Result.success(false);
|
||||||
|
}
|
||||||
|
adminScopeHelper.ensureShopAccessible(currentUser, targetUser.getShopId(), "无权重置其他店铺用户密码");
|
||||||
Long currentUserId = (Long) request.getAttribute("userId");
|
Long currentUserId = (Long) request.getAttribute("userId");
|
||||||
boolean success = userService.resetPassword(userId, currentUserId);
|
boolean success = userService.resetPassword(userId, currentUserId);
|
||||||
return Result.success(success);
|
return Result.success(success);
|
||||||
@@ -65,7 +100,13 @@ public class AdminUserController {
|
|||||||
|
|
||||||
@DeleteMapping("/delete/{id}")
|
@DeleteMapping("/delete/{id}")
|
||||||
@RequirePermission("user:delete")
|
@RequirePermission("user:delete")
|
||||||
public Result<Boolean> deleteUser(@PathVariable Long id) {
|
public Result<Boolean> deleteUser(HttpServletRequest request, @PathVariable Long id) {
|
||||||
|
UserDO currentUser = adminScopeHelper.getCurrentUser(request);
|
||||||
|
UserVO targetUser = userService.getUserById(id);
|
||||||
|
if (targetUser == null) {
|
||||||
|
return Result.success(false);
|
||||||
|
}
|
||||||
|
adminScopeHelper.ensureShopAccessible(currentUser, targetUser.getShopId(), "无权删除其他店铺用户");
|
||||||
boolean success = userService.deleteUser(id);
|
boolean success = userService.deleteUser(id);
|
||||||
return Result.success(success);
|
return Result.success(success);
|
||||||
}
|
}
|
||||||
@@ -83,8 +124,11 @@ public class AdminUserController {
|
|||||||
*/
|
*/
|
||||||
@GetMapping("/list/all")
|
@GetMapping("/list/all")
|
||||||
@RequirePermission("user:view")
|
@RequirePermission("user:view")
|
||||||
public Result<List<UserVO>> listAllUsers() {
|
public Result<List<UserVO>> listAllUsers(HttpServletRequest request) {
|
||||||
List<UserVO> users = userService.listAllUsers();
|
UserDO currentUser = adminScopeHelper.getCurrentUser(request);
|
||||||
|
List<UserVO> users = adminScopeHelper.isPlatformAdmin(currentUser)
|
||||||
|
? userService.listAllUsers()
|
||||||
|
: userService.listUsersByShopId(adminScopeHelper.getManagedShopId(currentUser));
|
||||||
return Result.success(users);
|
return Result.success(users);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -95,13 +139,16 @@ public class AdminUserController {
|
|||||||
*/
|
*/
|
||||||
@GetMapping("/list/artists")
|
@GetMapping("/list/artists")
|
||||||
@RequirePermission("user:view")
|
@RequirePermission("user:view")
|
||||||
public Result<List<UserVO>> listArtists(@RequestParam(required = false) Long shopId) {
|
public Result<List<UserVO>> listArtists(HttpServletRequest request, @RequestParam(required = false) Long shopId) {
|
||||||
|
UserDO currentUser = adminScopeHelper.getCurrentUser(request);
|
||||||
|
shopId = adminScopeHelper.resolveShopScope(currentUser, shopId);
|
||||||
// 用户类型 3 表示美甲师
|
// 用户类型 3 表示美甲师
|
||||||
List<UserVO> artists = userService.listUsersByType(3);
|
List<UserVO> artists = userService.listUsersByType(3);
|
||||||
// 如果指定了店铺ID,则过滤该店铺的美甲师
|
// 如果指定了店铺ID,则过滤该店铺的美甲师
|
||||||
if (shopId != null) {
|
if (shopId != null) {
|
||||||
|
final Long resolvedShopId = shopId;
|
||||||
artists = artists.stream()
|
artists = artists.stream()
|
||||||
.filter(artist -> shopId.equals(artist.getShopId()))
|
.filter(artist -> resolvedShopId.equals(artist.getShopId()))
|
||||||
.collect(Collectors.toList());
|
.collect(Collectors.toList());
|
||||||
}
|
}
|
||||||
return Result.success(artists);
|
return Result.success(artists);
|
||||||
|
|||||||
+24
-8
@@ -1,6 +1,7 @@
|
|||||||
package com.xiaowang.yuminailcore.controller;
|
package com.xiaowang.yuminailcore.controller;
|
||||||
|
|
||||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||||
|
import com.xiaowang.yuminailcore.annotation.RequirePermission;
|
||||||
import com.xiaowang.yuminailcore.common.Result;
|
import com.xiaowang.yuminailcore.common.Result;
|
||||||
import com.xiaowang.yuminailcore.entity.CommentDO;
|
import com.xiaowang.yuminailcore.entity.CommentDO;
|
||||||
import com.xiaowang.yuminailcore.entity.OrderDO;
|
import com.xiaowang.yuminailcore.entity.OrderDO;
|
||||||
@@ -13,6 +14,7 @@ import com.xiaowang.yuminailcore.mapper.OrderMapper;
|
|||||||
import com.xiaowang.yuminailcore.mapper.ProductMapper;
|
import com.xiaowang.yuminailcore.mapper.ProductMapper;
|
||||||
import com.xiaowang.yuminailcore.mapper.ShopMapper;
|
import com.xiaowang.yuminailcore.mapper.ShopMapper;
|
||||||
import com.xiaowang.yuminailcore.mapper.UserMapper;
|
import com.xiaowang.yuminailcore.mapper.UserMapper;
|
||||||
|
import com.xiaowang.yuminailcore.support.AdminScopeHelper;
|
||||||
import com.xiaowang.yuminailcore.vo.DashboardStatsVO;
|
import com.xiaowang.yuminailcore.vo.DashboardStatsVO;
|
||||||
import com.xiaowang.yuminailcore.vo.HotProductVO;
|
import com.xiaowang.yuminailcore.vo.HotProductVO;
|
||||||
import com.xiaowang.yuminailcore.vo.RecentActivityVO;
|
import com.xiaowang.yuminailcore.vo.RecentActivityVO;
|
||||||
@@ -39,14 +41,15 @@ public class DashboardController {
|
|||||||
private final CommentMapper commentMapper;
|
private final CommentMapper commentMapper;
|
||||||
private final OrderMapper orderMapper;
|
private final OrderMapper orderMapper;
|
||||||
private final OrderItemMapper orderItemMapper;
|
private final OrderItemMapper orderItemMapper;
|
||||||
|
private final AdminScopeHelper adminScopeHelper;
|
||||||
|
|
||||||
@GetMapping("/stats")
|
@GetMapping("/stats")
|
||||||
|
@RequirePermission("dashboard:view")
|
||||||
public Result<DashboardStatsVO> getDashboardStats(HttpServletRequest request) {
|
public Result<DashboardStatsVO> getDashboardStats(HttpServletRequest request) {
|
||||||
DashboardStatsVO stats = new DashboardStatsVO();
|
DashboardStatsVO stats = new DashboardStatsVO();
|
||||||
|
|
||||||
// 获取当前用户信息
|
UserDO currentUser = adminScopeHelper.getCurrentUser(request);
|
||||||
Long userId = (Long) request.getAttribute("userId");
|
Long shopIdScope = null;
|
||||||
UserDO currentUser = userMapper.selectById(userId);
|
|
||||||
|
|
||||||
if (currentUser != null) {
|
if (currentUser != null) {
|
||||||
// 根据用户类型显示不同的数据
|
// 根据用户类型显示不同的数据
|
||||||
@@ -58,6 +61,7 @@ public class DashboardController {
|
|||||||
} else { // 店长或美甲师
|
} else { // 店长或美甲师
|
||||||
Long shopId = currentUser.getShopId();
|
Long shopId = currentUser.getShopId();
|
||||||
if (shopId != null) {
|
if (shopId != null) {
|
||||||
|
shopIdScope = shopId;
|
||||||
// 只显示当前店铺的数据
|
// 只显示当前店铺的数据
|
||||||
stats.setTotalUsers(userMapper.selectCount(new LambdaQueryWrapper<UserDO>().eq(UserDO::getShopId, shopId)));
|
stats.setTotalUsers(userMapper.selectCount(new LambdaQueryWrapper<UserDO>().eq(UserDO::getShopId, shopId)));
|
||||||
stats.setTotalProducts(productMapper.selectCount(new LambdaQueryWrapper<ProductDO>().eq(ProductDO::getShopId, shopId)));
|
stats.setTotalProducts(productMapper.selectCount(new LambdaQueryWrapper<ProductDO>().eq(ProductDO::getShopId, shopId)));
|
||||||
@@ -79,8 +83,8 @@ public class DashboardController {
|
|||||||
stats.setTodayOrders(0L);
|
stats.setTodayOrders(0L);
|
||||||
}
|
}
|
||||||
|
|
||||||
stats.setHotProducts(getHotProducts());
|
stats.setHotProducts(getHotProducts(shopIdScope));
|
||||||
stats.setRecentActivities(getRecentActivities());
|
stats.setRecentActivities(getRecentActivities(shopIdScope));
|
||||||
|
|
||||||
return Result.success(stats);
|
return Result.success(stats);
|
||||||
}
|
}
|
||||||
@@ -106,7 +110,7 @@ public class DashboardController {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private List<HotProductVO> getHotProducts() {
|
private List<HotProductVO> getHotProducts(Long shopId) {
|
||||||
// 通过订单商品表统计每个商品的订单数量,按订单数量排序
|
// 通过订单商品表统计每个商品的订单数量,按订单数量排序
|
||||||
// 使用SQL查询获取商品及其订单数量
|
// 使用SQL查询获取商品及其订单数量
|
||||||
List<Map<String, Object>> productOrderCounts = orderItemMapper.selectMaps(
|
List<Map<String, Object>> productOrderCounts = orderItemMapper.selectMaps(
|
||||||
@@ -124,7 +128,7 @@ public class DashboardController {
|
|||||||
Long productId = Long.valueOf(map.get("product_id").toString());
|
Long productId = Long.valueOf(map.get("product_id").toString());
|
||||||
ProductDO product = productMapper.selectById(productId);
|
ProductDO product = productMapper.selectById(productId);
|
||||||
|
|
||||||
if (product != null) {
|
if (product != null && (shopId == null || shopId.equals(product.getShopId()))) {
|
||||||
HotProductVO vo = new HotProductVO();
|
HotProductVO vo = new HotProductVO();
|
||||||
BeanUtils.copyProperties(product, vo);
|
BeanUtils.copyProperties(product, vo);
|
||||||
vo.setLikeCount(product.getLikeCount() != null ? product.getLikeCount() : 0);
|
vo.setLikeCount(product.getLikeCount() != null ? product.getLikeCount() : 0);
|
||||||
@@ -135,6 +139,9 @@ public class DashboardController {
|
|||||||
// 如果按订单数量查询没有结果,使用点赞数作为备选
|
// 如果按订单数量查询没有结果,使用点赞数作为备选
|
||||||
if (hotProducts.isEmpty()) {
|
if (hotProducts.isEmpty()) {
|
||||||
LambdaQueryWrapper<ProductDO> wrapper = new LambdaQueryWrapper<>();
|
LambdaQueryWrapper<ProductDO> wrapper = new LambdaQueryWrapper<>();
|
||||||
|
if (shopId != null) {
|
||||||
|
wrapper.eq(ProductDO::getShopId, shopId);
|
||||||
|
}
|
||||||
wrapper.orderByDesc(ProductDO::getLikeCount)
|
wrapper.orderByDesc(ProductDO::getLikeCount)
|
||||||
.last("LIMIT 5");
|
.last("LIMIT 5");
|
||||||
List<ProductDO> products = productMapper.selectList(wrapper);
|
List<ProductDO> products = productMapper.selectList(wrapper);
|
||||||
@@ -150,10 +157,13 @@ public class DashboardController {
|
|||||||
return hotProducts;
|
return hotProducts;
|
||||||
}
|
}
|
||||||
|
|
||||||
private List<RecentActivityVO> getRecentActivities() {
|
private List<RecentActivityVO> getRecentActivities(Long shopId) {
|
||||||
List<RecentActivityVO> activities = new ArrayList<>();
|
List<RecentActivityVO> activities = new ArrayList<>();
|
||||||
|
|
||||||
LambdaQueryWrapper<UserDO> userWrapper = new LambdaQueryWrapper<>();
|
LambdaQueryWrapper<UserDO> userWrapper = new LambdaQueryWrapper<>();
|
||||||
|
if (shopId != null) {
|
||||||
|
userWrapper.eq(UserDO::getShopId, shopId);
|
||||||
|
}
|
||||||
userWrapper.orderByDesc(UserDO::getCreateTime)
|
userWrapper.orderByDesc(UserDO::getCreateTime)
|
||||||
.last("LIMIT 3");
|
.last("LIMIT 3");
|
||||||
List<UserDO> recentUsers = userMapper.selectList(userWrapper);
|
List<UserDO> recentUsers = userMapper.selectList(userWrapper);
|
||||||
@@ -170,6 +180,9 @@ public class DashboardController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
LambdaQueryWrapper<ProductDO> productWrapper = new LambdaQueryWrapper<>();
|
LambdaQueryWrapper<ProductDO> productWrapper = new LambdaQueryWrapper<>();
|
||||||
|
if (shopId != null) {
|
||||||
|
productWrapper.eq(ProductDO::getShopId, shopId);
|
||||||
|
}
|
||||||
productWrapper.orderByDesc(ProductDO::getCreateTime)
|
productWrapper.orderByDesc(ProductDO::getCreateTime)
|
||||||
.last("LIMIT 2");
|
.last("LIMIT 2");
|
||||||
List<ProductDO> recentProducts = productMapper.selectList(productWrapper);
|
List<ProductDO> recentProducts = productMapper.selectList(productWrapper);
|
||||||
@@ -186,6 +199,9 @@ public class DashboardController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
LambdaQueryWrapper<CommentDO> commentWrapper = new LambdaQueryWrapper<>();
|
LambdaQueryWrapper<CommentDO> commentWrapper = new LambdaQueryWrapper<>();
|
||||||
|
if (shopId != null) {
|
||||||
|
commentWrapper.eq(CommentDO::getShopId, shopId);
|
||||||
|
}
|
||||||
commentWrapper.orderByDesc(CommentDO::getCreateTime)
|
commentWrapper.orderByDesc(CommentDO::getCreateTime)
|
||||||
.last("LIMIT 2");
|
.last("LIMIT 2");
|
||||||
List<CommentDO> recentComments = commentMapper.selectList(commentWrapper);
|
List<CommentDO> recentComments = commentMapper.selectList(commentWrapper);
|
||||||
|
|||||||
+9
@@ -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.PermissionDTO;
|
import com.xiaowang.yuminailcore.dto.PermissionDTO;
|
||||||
import com.xiaowang.yuminailcore.dto.UserPermissionDTO;
|
import com.xiaowang.yuminailcore.dto.UserPermissionDTO;
|
||||||
@@ -32,6 +33,7 @@ public class PermissionController {
|
|||||||
* @return 权限ID
|
* @return 权限ID
|
||||||
*/
|
*/
|
||||||
@PostMapping("/create")
|
@PostMapping("/create")
|
||||||
|
@RequirePermission("permission:create")
|
||||||
public Result<Long> createPermission(@RequestBody PermissionDTO permissionDTO) {
|
public Result<Long> createPermission(@RequestBody PermissionDTO permissionDTO) {
|
||||||
Long id = permissionService.createPermission(permissionDTO);
|
Long id = permissionService.createPermission(permissionDTO);
|
||||||
return Result.success(id);
|
return Result.success(id);
|
||||||
@@ -45,6 +47,7 @@ public class PermissionController {
|
|||||||
* @return 是否更新成功
|
* @return 是否更新成功
|
||||||
*/
|
*/
|
||||||
@PutMapping("/update/{id}")
|
@PutMapping("/update/{id}")
|
||||||
|
@RequirePermission("permission:edit")
|
||||||
public Result<Boolean> updatePermission(@PathVariable Long id, @RequestBody PermissionDTO permissionDTO) {
|
public Result<Boolean> updatePermission(@PathVariable Long id, @RequestBody PermissionDTO permissionDTO) {
|
||||||
boolean success = permissionService.updatePermission(id, permissionDTO);
|
boolean success = permissionService.updatePermission(id, permissionDTO);
|
||||||
return Result.success(success);
|
return Result.success(success);
|
||||||
@@ -57,6 +60,7 @@ public class PermissionController {
|
|||||||
* @return 是否删除成功
|
* @return 是否删除成功
|
||||||
*/
|
*/
|
||||||
@DeleteMapping("/delete/{id}")
|
@DeleteMapping("/delete/{id}")
|
||||||
|
@RequirePermission("permission:delete")
|
||||||
public Result<Boolean> deletePermission(@PathVariable Long id) {
|
public Result<Boolean> deletePermission(@PathVariable Long id) {
|
||||||
boolean success = permissionService.deletePermission(id);
|
boolean success = permissionService.deletePermission(id);
|
||||||
return Result.success(success);
|
return Result.success(success);
|
||||||
@@ -69,6 +73,7 @@ public class PermissionController {
|
|||||||
* @return 权限VO
|
* @return 权限VO
|
||||||
*/
|
*/
|
||||||
@GetMapping("/get/{id}")
|
@GetMapping("/get/{id}")
|
||||||
|
@RequirePermission("permission:view")
|
||||||
public Result<PermissionVO> getPermissionById(@PathVariable Long id) {
|
public Result<PermissionVO> getPermissionById(@PathVariable Long id) {
|
||||||
PermissionVO permissionVO = permissionService.getPermissionById(id);
|
PermissionVO permissionVO = permissionService.getPermissionById(id);
|
||||||
return Result.success(permissionVO);
|
return Result.success(permissionVO);
|
||||||
@@ -80,6 +85,7 @@ public class PermissionController {
|
|||||||
* @return 权限VO列表
|
* @return 权限VO列表
|
||||||
*/
|
*/
|
||||||
@GetMapping("/list/all")
|
@GetMapping("/list/all")
|
||||||
|
@RequirePermission("permission:view")
|
||||||
public Result<List<PermissionVO>> listAllPermissions() {
|
public Result<List<PermissionVO>> listAllPermissions() {
|
||||||
List<PermissionVO> permissionVOs = permissionService.listAllPermissions();
|
List<PermissionVO> permissionVOs = permissionService.listAllPermissions();
|
||||||
return Result.success(permissionVOs);
|
return Result.success(permissionVOs);
|
||||||
@@ -92,6 +98,7 @@ public class PermissionController {
|
|||||||
* @return 权限VO列表
|
* @return 权限VO列表
|
||||||
*/
|
*/
|
||||||
@GetMapping("/list/group/{permissionGroup}")
|
@GetMapping("/list/group/{permissionGroup}")
|
||||||
|
@RequirePermission("permission:view")
|
||||||
public Result<List<PermissionVO>> listPermissionsByGroup(@PathVariable String permissionGroup) {
|
public Result<List<PermissionVO>> listPermissionsByGroup(@PathVariable String permissionGroup) {
|
||||||
List<PermissionVO> permissionVOs = permissionService.listPermissionsByGroup(permissionGroup);
|
List<PermissionVO> permissionVOs = permissionService.listPermissionsByGroup(permissionGroup);
|
||||||
return Result.success(permissionVOs);
|
return Result.success(permissionVOs);
|
||||||
@@ -104,6 +111,7 @@ public class PermissionController {
|
|||||||
* @return 权限VO列表
|
* @return 权限VO列表
|
||||||
*/
|
*/
|
||||||
@GetMapping("/list/user/{userId}")
|
@GetMapping("/list/user/{userId}")
|
||||||
|
@RequirePermission("permission:view")
|
||||||
public Result<List<PermissionVO>> listUserPermissions(@PathVariable Long userId) {
|
public Result<List<PermissionVO>> listUserPermissions(@PathVariable Long userId) {
|
||||||
List<PermissionVO> permissionVOs = permissionService.listUserPermissions(userId);
|
List<PermissionVO> permissionVOs = permissionService.listUserPermissions(userId);
|
||||||
return Result.success(permissionVOs);
|
return Result.success(permissionVOs);
|
||||||
@@ -116,6 +124,7 @@ public class PermissionController {
|
|||||||
* @return 是否分配成功
|
* @return 是否分配成功
|
||||||
*/
|
*/
|
||||||
@PostMapping("/assign")
|
@PostMapping("/assign")
|
||||||
|
@RequirePermission("permission:assign")
|
||||||
public Result<Boolean> assignPermissions(HttpServletRequest request, @RequestBody UserPermissionDTO userPermissionDTO) {
|
public Result<Boolean> assignPermissions(HttpServletRequest request, @RequestBody UserPermissionDTO userPermissionDTO) {
|
||||||
Long userId = (Long) request.getAttribute("userId");
|
Long userId = (Long) request.getAttribute("userId");
|
||||||
boolean success = permissionService.assignPermissions(userPermissionDTO, userId);
|
boolean success = permissionService.assignPermissions(userPermissionDTO, userId);
|
||||||
|
|||||||
+42
-3
@@ -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.*;
|
import com.xiaowang.yuminailcore.dto.*;
|
||||||
import com.xiaowang.yuminailcore.entity.UserDO;
|
import com.xiaowang.yuminailcore.entity.UserDO;
|
||||||
@@ -42,6 +43,7 @@ public class UserController {
|
|||||||
* @return 用户ID
|
* @return 用户ID
|
||||||
*/
|
*/
|
||||||
@PostMapping("/create")
|
@PostMapping("/create")
|
||||||
|
@RequirePermission("user:create")
|
||||||
public Result<Long> createUser(@RequestBody UserDTO userDTO) {
|
public Result<Long> createUser(@RequestBody UserDTO userDTO) {
|
||||||
Long id = userService.createUser(userDTO);
|
Long id = userService.createUser(userDTO);
|
||||||
return Result.success(id);
|
return Result.success(id);
|
||||||
@@ -55,6 +57,7 @@ public class UserController {
|
|||||||
* @return 是否更新成功
|
* @return 是否更新成功
|
||||||
*/
|
*/
|
||||||
@PutMapping("/update/{id}")
|
@PutMapping("/update/{id}")
|
||||||
|
@RequirePermission("user:edit")
|
||||||
public Result<Boolean> updateUser(@PathVariable Long id, @RequestBody UserDTO userDTO) {
|
public Result<Boolean> updateUser(@PathVariable Long id, @RequestBody UserDTO userDTO) {
|
||||||
boolean success = userService.updateUser(id, userDTO);
|
boolean success = userService.updateUser(id, userDTO);
|
||||||
return Result.success(success);
|
return Result.success(success);
|
||||||
@@ -67,6 +70,7 @@ public class UserController {
|
|||||||
* @return 是否删除成功
|
* @return 是否删除成功
|
||||||
*/
|
*/
|
||||||
@DeleteMapping("/delete/{id}")
|
@DeleteMapping("/delete/{id}")
|
||||||
|
@RequirePermission("user:delete")
|
||||||
public Result<Boolean> deleteUser(@PathVariable Long id) {
|
public Result<Boolean> deleteUser(@PathVariable Long id) {
|
||||||
boolean success = userService.deleteUser(id);
|
boolean success = userService.deleteUser(id);
|
||||||
return Result.success(success);
|
return Result.success(success);
|
||||||
@@ -79,6 +83,7 @@ public class UserController {
|
|||||||
* @return 用户VO
|
* @return 用户VO
|
||||||
*/
|
*/
|
||||||
@GetMapping("/get/{id}")
|
@GetMapping("/get/{id}")
|
||||||
|
@RequirePermission("user:view")
|
||||||
public Result<UserVO> getUserById(@PathVariable Long id) {
|
public Result<UserVO> getUserById(@PathVariable Long id) {
|
||||||
UserVO userVO = userService.getUserById(id);
|
UserVO userVO = userService.getUserById(id);
|
||||||
return Result.success(userVO);
|
return Result.success(userVO);
|
||||||
@@ -90,6 +95,7 @@ public class UserController {
|
|||||||
* @return 用户VO列表
|
* @return 用户VO列表
|
||||||
*/
|
*/
|
||||||
@GetMapping("/list/all")
|
@GetMapping("/list/all")
|
||||||
|
@RequirePermission("user:view")
|
||||||
public Result<List<UserVO>> listAllUsers() {
|
public Result<List<UserVO>> listAllUsers() {
|
||||||
List<UserVO> userVOs = userService.listAllUsers();
|
List<UserVO> userVOs = userService.listAllUsers();
|
||||||
return Result.success(userVOs);
|
return Result.success(userVOs);
|
||||||
@@ -102,6 +108,7 @@ public class UserController {
|
|||||||
* @return 用户VO列表
|
* @return 用户VO列表
|
||||||
*/
|
*/
|
||||||
@GetMapping("/list/shop/{shopId}")
|
@GetMapping("/list/shop/{shopId}")
|
||||||
|
@RequirePermission("user:view")
|
||||||
public Result<List<UserVO>> listUsersByShopId(@PathVariable Long shopId) {
|
public Result<List<UserVO>> listUsersByShopId(@PathVariable Long shopId) {
|
||||||
List<UserVO> userVOs = userService.listUsersByShopId(shopId);
|
List<UserVO> userVOs = userService.listUsersByShopId(shopId);
|
||||||
return Result.success(userVOs);
|
return Result.success(userVOs);
|
||||||
@@ -126,11 +133,35 @@ public class UserController {
|
|||||||
* @return 用户VO
|
* @return 用户VO
|
||||||
*/
|
*/
|
||||||
@GetMapping("/get/account/{account}")
|
@GetMapping("/get/account/{account}")
|
||||||
|
@RequirePermission("user:view")
|
||||||
public Result<UserVO> getUserByAccount(@PathVariable String account) {
|
public Result<UserVO> getUserByAccount(@PathVariable String account) {
|
||||||
UserVO userVO = userService.getUserByAccount(account);
|
UserVO userVO = userService.getUserByAccount(account);
|
||||||
return Result.success(userVO);
|
return Result.success(userVO);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@GetMapping("/check/account/{account}")
|
||||||
|
public Result<AvailabilityVO> checkAccountAvailability(@PathVariable String account) {
|
||||||
|
UserDO userDO = userMapper.selectOne(
|
||||||
|
com.baomidou.mybatisplus.core.toolkit.Wrappers.lambdaQuery(UserDO.class)
|
||||||
|
.eq(UserDO::getAccount, account)
|
||||||
|
);
|
||||||
|
boolean available = userDO == null || Integer.valueOf(1).equals(userDO.getIsDelete());
|
||||||
|
String message = available ? "账号可用" : "账号已被注册";
|
||||||
|
return Result.success(new AvailabilityVO(available, message));
|
||||||
|
}
|
||||||
|
|
||||||
|
@GetMapping("/check/phone/{phone}")
|
||||||
|
public Result<AvailabilityVO> checkPhoneAvailability(@PathVariable String phone) {
|
||||||
|
UserDO userDO = userMapper.selectOne(
|
||||||
|
com.baomidou.mybatisplus.core.toolkit.Wrappers.lambdaQuery(UserDO.class)
|
||||||
|
.eq(UserDO::getPhone, phone)
|
||||||
|
.eq(UserDO::getIsDelete, 0)
|
||||||
|
);
|
||||||
|
boolean available = userDO == null;
|
||||||
|
String message = available ? "手机号可用" : "该手机号已被注册";
|
||||||
|
return Result.success(new AvailabilityVO(available, message));
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 用户登录
|
* 用户登录
|
||||||
*
|
*
|
||||||
@@ -235,10 +266,10 @@ public class UserController {
|
|||||||
* @param userDTO 用户DTO
|
* @param userDTO 用户DTO
|
||||||
* @return 是否更新成功
|
* @return 是否更新成功
|
||||||
*/
|
*/
|
||||||
@PutMapping("/update")
|
@PutMapping({"/update", "/info"})
|
||||||
public Result<Boolean> updateCurrentUserInfo(HttpServletRequest request, @RequestBody UserDTO userDTO) {
|
public Result<Boolean> updateCurrentUserInfo(HttpServletRequest request, @RequestBody UserDTO userDTO) {
|
||||||
Long userId = (Long) request.getAttribute("userId");
|
Long userId = (Long) request.getAttribute("userId");
|
||||||
boolean success = userService.updateUser(userId, userDTO);
|
boolean success = userService.updateCurrentUserInfo(userId, userDTO);
|
||||||
return Result.success(success);
|
return Result.success(success);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -299,6 +330,7 @@ public class UserController {
|
|||||||
* @return 是否重置成功
|
* @return 是否重置成功
|
||||||
*/
|
*/
|
||||||
@PostMapping("/reset-password/{userId}")
|
@PostMapping("/reset-password/{userId}")
|
||||||
|
@RequirePermission("user:reset_password")
|
||||||
public Result<Boolean> resetPassword(HttpServletRequest request, @PathVariable Long userId) {
|
public Result<Boolean> resetPassword(HttpServletRequest request, @PathVariable Long userId) {
|
||||||
Long currentUserId = (Long) request.getAttribute("userId");
|
Long currentUserId = (Long) request.getAttribute("userId");
|
||||||
boolean success = userService.resetPassword(userId, currentUserId);
|
boolean success = userService.resetPassword(userId, currentUserId);
|
||||||
@@ -315,7 +347,7 @@ public class UserController {
|
|||||||
@PutMapping("/password")
|
@PutMapping("/password")
|
||||||
public Result<Boolean> updatePassword(HttpServletRequest request, @RequestBody PasswordDTO passwordDTO) {
|
public Result<Boolean> updatePassword(HttpServletRequest request, @RequestBody PasswordDTO passwordDTO) {
|
||||||
Long userId = (Long) request.getAttribute("userId");
|
Long userId = (Long) request.getAttribute("userId");
|
||||||
boolean success = userService.updatePassword(userId, passwordDTO.getPassword());
|
boolean success = userService.updatePassword(userId, passwordDTO.getPassword(), passwordDTO.getVerificationCode());
|
||||||
return Result.success(success);
|
return Result.success(success);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -376,5 +408,12 @@ public class UserController {
|
|||||||
@Data
|
@Data
|
||||||
public static class PasswordDTO {
|
public static class PasswordDTO {
|
||||||
private String password;
|
private String password;
|
||||||
|
private String verificationCode;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Data
|
||||||
|
public static class AvailabilityVO {
|
||||||
|
private final boolean available;
|
||||||
|
private final String message;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
package com.xiaowang.yuminailcore.dto;
|
package com.xiaowang.yuminailcore.dto;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.annotation.JsonAlias;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -20,5 +21,6 @@ public class BindPhoneRequestDTO {
|
|||||||
/**
|
/**
|
||||||
* 验证码
|
* 验证码
|
||||||
*/
|
*/
|
||||||
private String code;
|
@JsonAlias("code")
|
||||||
|
private String verificationCode;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,9 +10,9 @@ import java.util.List;
|
|||||||
|
|
||||||
@Mapper
|
@Mapper
|
||||||
public interface CartMapper extends BaseMapper<CartDO> {
|
public interface CartMapper extends BaseMapper<CartDO> {
|
||||||
@Select("SELECT * FROM t_cart WHERE user_id = #{userId}")
|
@Select("SELECT * FROM t_cart WHERE user_id = #{userId} AND is_delete = 0")
|
||||||
List<CartDO> selectByUserId(@Param("userId") Long userId);
|
List<CartDO> selectByUserId(@Param("userId") Long userId);
|
||||||
|
|
||||||
@Select("SELECT * FROM t_cart WHERE user_id = #{userId} AND product_id = #{productId}")
|
@Select("SELECT * FROM t_cart WHERE user_id = #{userId} AND product_id = #{productId} AND is_delete = 0")
|
||||||
CartDO selectByUserIdAndProductId(@Param("userId") Long userId, @Param("productId") Long productId);
|
CartDO selectByUserIdAndProductId(@Param("userId") Long userId, @Param("productId") Long productId);
|
||||||
}
|
}
|
||||||
@@ -48,6 +48,8 @@ public interface UserService extends IService<UserDO> {
|
|||||||
|
|
||||||
UserVO getCurrentUserInfo();
|
UserVO getCurrentUserInfo();
|
||||||
|
|
||||||
|
boolean updateCurrentUserInfo(Long userId, UserDTO userDTO);
|
||||||
|
|
||||||
boolean bindPhone(Long userId, BindPhoneRequestDTO bindPhoneRequestDTO);
|
boolean bindPhone(Long userId, BindPhoneRequestDTO bindPhoneRequestDTO);
|
||||||
|
|
||||||
boolean bindEmail(Long userId, BindEmailRequestDTO bindEmailRequestDTO);
|
boolean bindEmail(Long userId, BindEmailRequestDTO bindEmailRequestDTO);
|
||||||
@@ -62,7 +64,7 @@ public interface UserService extends IService<UserDO> {
|
|||||||
|
|
||||||
boolean updateUserAvatar(Long userId, String avatarUrl);
|
boolean updateUserAvatar(Long userId, String avatarUrl);
|
||||||
|
|
||||||
boolean updatePassword(Long userId, String password);
|
boolean updatePassword(Long userId, String password, String verificationCode);
|
||||||
|
|
||||||
boolean updatePhone(Long userId, UpdatePhoneRequestDTO updatePhoneDTO);
|
boolean updatePhone(Long userId, UpdatePhoneRequestDTO updatePhoneDTO);
|
||||||
}
|
}
|
||||||
|
|||||||
+42
@@ -7,7 +7,9 @@ import com.xiaowang.yuminailcore.entity.ProductDO;
|
|||||||
import com.xiaowang.yuminailcore.mapper.CartMapper;
|
import com.xiaowang.yuminailcore.mapper.CartMapper;
|
||||||
import com.xiaowang.yuminailcore.mapper.ProductMapper;
|
import com.xiaowang.yuminailcore.mapper.ProductMapper;
|
||||||
import com.xiaowang.yuminailcore.service.CartService;
|
import com.xiaowang.yuminailcore.service.CartService;
|
||||||
|
import com.xiaowang.yuminailcore.service.TagService;
|
||||||
import com.xiaowang.yuminailcore.vo.CartVO;
|
import com.xiaowang.yuminailcore.vo.CartVO;
|
||||||
|
import com.xiaowang.yuminailcore.vo.TagVO;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
import org.springframework.transaction.annotation.Transactional;
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
|
||||||
@@ -15,6 +17,7 @@ import javax.annotation.Resource;
|
|||||||
import java.math.BigDecimal;
|
import java.math.BigDecimal;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
@Service
|
@Service
|
||||||
public class CartServiceImpl implements CartService {
|
public class CartServiceImpl implements CartService {
|
||||||
@@ -25,9 +28,14 @@ public class CartServiceImpl implements CartService {
|
|||||||
@Resource
|
@Resource
|
||||||
private ProductMapper productMapper;
|
private ProductMapper productMapper;
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
private TagService tagService;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@Transactional
|
@Transactional
|
||||||
public void addToCart(Long userId, CartDTO cartDTO) {
|
public void addToCart(Long userId, CartDTO cartDTO) {
|
||||||
|
validateQuantity(cartDTO.getQuantity());
|
||||||
|
|
||||||
// 检查商品是否存在
|
// 检查商品是否存在
|
||||||
ProductDO product = productMapper.selectById(cartDTO.getProductId());
|
ProductDO product = productMapper.selectById(cartDTO.getProductId());
|
||||||
if (product == null || product.getIsDelete() == 1) {
|
if (product == null || product.getIsDelete() == 1) {
|
||||||
@@ -77,11 +85,15 @@ public class CartServiceImpl implements CartService {
|
|||||||
@Override
|
@Override
|
||||||
@Transactional
|
@Transactional
|
||||||
public void updateCartQuantity(Long userId, CartDTO cartDTO) {
|
public void updateCartQuantity(Long userId, CartDTO cartDTO) {
|
||||||
|
validateQuantity(cartDTO.getQuantity());
|
||||||
CartDO cart = cartMapper.selectByUserIdAndProductId(userId, cartDTO.getProductId());
|
CartDO cart = cartMapper.selectByUserIdAndProductId(userId, cartDTO.getProductId());
|
||||||
if (cart != null) {
|
if (cart != null) {
|
||||||
cart.setQuantity(cartDTO.getQuantity());
|
cart.setQuantity(cartDTO.getQuantity());
|
||||||
cartMapper.updateById(cart);
|
cartMapper.updateById(cart);
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
throw new RuntimeException("购物车商品不存在");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -96,6 +108,7 @@ public class CartServiceImpl implements CartService {
|
|||||||
CartVO cartVO = new CartVO();
|
CartVO cartVO = new CartVO();
|
||||||
cartVO.setId(cart.getId());
|
cartVO.setId(cart.getId());
|
||||||
cartVO.setProductId(product.getId());
|
cartVO.setProductId(product.getId());
|
||||||
|
cartVO.setShopId(product.getShopId());
|
||||||
cartVO.setProductTitle(product.getTitle());
|
cartVO.setProductTitle(product.getTitle());
|
||||||
// 简单处理,取第一张图片
|
// 简单处理,取第一张图片
|
||||||
String imageFileIds = product.getImageFileIds();
|
String imageFileIds = product.getImageFileIds();
|
||||||
@@ -107,6 +120,9 @@ public class CartServiceImpl implements CartService {
|
|||||||
cartVO.setQuantity(cart.getQuantity());
|
cartVO.setQuantity(cart.getQuantity());
|
||||||
cartVO.setTotalPrice(product.getPrice().multiply(new BigDecimal(cart.getQuantity())));
|
cartVO.setTotalPrice(product.getPrice().multiply(new BigDecimal(cart.getQuantity())));
|
||||||
cartVO.setTags(product.getTags());
|
cartVO.setTags(product.getTags());
|
||||||
|
cartVO.setTagNames(resolveTagNames(product.getTags()));
|
||||||
|
cartVO.setApproximateDuration(product.getApproximateDuration());
|
||||||
|
cartVO.setBookableArtists(product.getBookableArtists());
|
||||||
cartVOList.add(cartVO);
|
cartVOList.add(cartVO);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -123,4 +139,30 @@ public class CartServiceImpl implements CartService {
|
|||||||
.eq("is_delete", 0);
|
.eq("is_delete", 0);
|
||||||
cartMapper.delete(wrapper);
|
cartMapper.delete(wrapper);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void validateQuantity(Integer quantity) {
|
||||||
|
if (quantity == null || quantity < 1 || quantity > 99) {
|
||||||
|
throw new RuntimeException("购物车数量必须在1到99之间");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private String resolveTagNames(String tagIds) {
|
||||||
|
if (tagIds == null || tagIds.isBlank()) {
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
|
||||||
|
return List.of(tagIds.split(";")).stream()
|
||||||
|
.map(String::trim)
|
||||||
|
.filter(tagId -> !tagId.isEmpty())
|
||||||
|
.map(tagId -> {
|
||||||
|
try {
|
||||||
|
TagVO tagVO = tagService.getTagById(Long.parseLong(tagId));
|
||||||
|
return tagVO != null ? tagVO.getTagName() : null;
|
||||||
|
} catch (NumberFormatException ex) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.filter(tagName -> tagName != null && !tagName.isBlank())
|
||||||
|
.collect(Collectors.joining(","));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
+39
@@ -6,7 +6,9 @@ import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|||||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||||
import com.xiaowang.yuminailcore.dto.ProductDTO;
|
import com.xiaowang.yuminailcore.dto.ProductDTO;
|
||||||
import com.xiaowang.yuminailcore.entity.ProductDO;
|
import com.xiaowang.yuminailcore.entity.ProductDO;
|
||||||
|
import com.xiaowang.yuminailcore.entity.UserDO;
|
||||||
import com.xiaowang.yuminailcore.mapper.ProductMapper;
|
import com.xiaowang.yuminailcore.mapper.ProductMapper;
|
||||||
|
import com.xiaowang.yuminailcore.mapper.UserMapper;
|
||||||
import com.xiaowang.yuminailcore.service.ObjectStorageFileService;
|
import com.xiaowang.yuminailcore.service.ObjectStorageFileService;
|
||||||
import com.xiaowang.yuminailcore.service.ProductService;
|
import com.xiaowang.yuminailcore.service.ProductService;
|
||||||
import com.xiaowang.yuminailcore.service.TagService;
|
import com.xiaowang.yuminailcore.service.TagService;
|
||||||
@@ -37,9 +39,11 @@ public class ProductServiceImpl extends ServiceImpl<ProductMapper, ProductDO> im
|
|||||||
private final ProductMapper productMapper;
|
private final ProductMapper productMapper;
|
||||||
private final TagService tagService;
|
private final TagService tagService;
|
||||||
private final ObjectStorageFileService objectStorageFileService;
|
private final ObjectStorageFileService objectStorageFileService;
|
||||||
|
private final UserMapper userMapper;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Long createProduct(ProductDTO productDTO) {
|
public Long createProduct(ProductDTO productDTO) {
|
||||||
|
validateBookableArtists(productDTO.getShopId(), productDTO.getBookableArtists());
|
||||||
ProductDO productDO = new ProductDO();
|
ProductDO productDO = new ProductDO();
|
||||||
productDO.setShopId(productDTO.getShopId());
|
productDO.setShopId(productDTO.getShopId());
|
||||||
productDO.setTitle(productDTO.getTitle());
|
productDO.setTitle(productDTO.getTitle());
|
||||||
@@ -61,6 +65,7 @@ public class ProductServiceImpl extends ServiceImpl<ProductMapper, ProductDO> im
|
|||||||
if (productDO == null) {
|
if (productDO == null) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
validateBookableArtists(productDTO.getShopId(), productDTO.getBookableArtists());
|
||||||
productDO.setShopId(productDTO.getShopId());
|
productDO.setShopId(productDTO.getShopId());
|
||||||
productDO.setTitle(productDTO.getTitle());
|
productDO.setTitle(productDTO.getTitle());
|
||||||
productDO.setDescription(productDTO.getDescription());
|
productDO.setDescription(productDTO.getDescription());
|
||||||
@@ -239,4 +244,38 @@ public class ProductServiceImpl extends ServiceImpl<ProductMapper, ProductDO> im
|
|||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void validateBookableArtists(Long shopId, String bookableArtists) {
|
||||||
|
if (!StringUtils.hasText(bookableArtists)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (shopId == null || shopId <= 0) {
|
||||||
|
throw new RuntimeException("配置可预约美甲师前必须先选择店铺");
|
||||||
|
}
|
||||||
|
|
||||||
|
for (String artistIdStr : bookableArtists.split(",")) {
|
||||||
|
if (!StringUtils.hasText(artistIdStr)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
Long artistId;
|
||||||
|
try {
|
||||||
|
artistId = Long.parseLong(artistIdStr.trim());
|
||||||
|
} catch (NumberFormatException ex) {
|
||||||
|
throw new RuntimeException("可预约美甲师配置格式不正确");
|
||||||
|
}
|
||||||
|
|
||||||
|
UserDO artist = userMapper.selectById(artistId);
|
||||||
|
if (artist == null || Integer.valueOf(1).equals(artist.getIsDelete())) {
|
||||||
|
throw new RuntimeException("存在无效的美甲师配置");
|
||||||
|
}
|
||||||
|
if (!Integer.valueOf(3).equals(artist.getType())) {
|
||||||
|
throw new RuntimeException("存在非美甲师账号被配置到可预约列表");
|
||||||
|
}
|
||||||
|
if (!shopId.equals(artist.getShopId())) {
|
||||||
|
throw new RuntimeException("不可跨店铺配置可预约美甲师");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+82
-44
@@ -22,7 +22,6 @@ 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.data.redis.core.RedisTemplate;
|
|
||||||
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
|
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.transaction.annotation.Transactional;
|
||||||
@@ -53,7 +52,6 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, UserDO> implements
|
|||||||
private final NailArtistInfoService nailArtistInfoService;
|
private final NailArtistInfoService nailArtistInfoService;
|
||||||
private final BCryptPasswordEncoder passwordEncoder = new BCryptPasswordEncoder();
|
private final BCryptPasswordEncoder passwordEncoder = new BCryptPasswordEncoder();
|
||||||
private final VerificationCodeService verificationCodeService;
|
private final VerificationCodeService verificationCodeService;
|
||||||
private final RedisTemplate<String, String> redisTemplate;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 创建新用户
|
* 创建新用户
|
||||||
@@ -397,9 +395,7 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, UserDO> implements
|
|||||||
.eq(UserDO::getAccount, loginRequestDTO.getAccount())
|
.eq(UserDO::getAccount, loginRequestDTO.getAccount())
|
||||||
);
|
);
|
||||||
|
|
||||||
if (userDO == null) {
|
assertUserAvailable(userDO);
|
||||||
throw new RuntimeException("用户不存在");
|
|
||||||
}
|
|
||||||
|
|
||||||
// 检查是否为未设置密码的账号
|
// 检查是否为未设置密码的账号
|
||||||
if (ENCODED_UNSET_PASSWORD.equals(userDO.getPassword())) {
|
if (ENCODED_UNSET_PASSWORD.equals(userDO.getPassword())) {
|
||||||
@@ -457,6 +453,7 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, UserDO> implements
|
|||||||
}
|
}
|
||||||
userDO = registerByPhone(phoneLoginRequestDTO.getPhone(), phoneLoginRequestDTO.getShopId());
|
userDO = registerByPhone(phoneLoginRequestDTO.getPhone(), phoneLoginRequestDTO.getShopId());
|
||||||
} else {
|
} else {
|
||||||
|
assertUserAvailable(userDO);
|
||||||
if (userDO.getShopId() == null || userDO.getShopId() == 0) {
|
if (userDO.getShopId() == null || userDO.getShopId() == 0) {
|
||||||
if (phoneLoginRequestDTO.getShopId() == null || phoneLoginRequestDTO.getShopId() == 0) {
|
if (phoneLoginRequestDTO.getShopId() == null || phoneLoginRequestDTO.getShopId() == 0) {
|
||||||
throw new RuntimeException("请选择店铺");
|
throw new RuntimeException("请选择店铺");
|
||||||
@@ -518,9 +515,7 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, UserDO> implements
|
|||||||
.eq(UserDO::getAccount, loginRequestDTO.getAccount())
|
.eq(UserDO::getAccount, loginRequestDTO.getAccount())
|
||||||
);
|
);
|
||||||
|
|
||||||
if (userDO == null) {
|
assertUserAvailable(userDO);
|
||||||
throw new RuntimeException("用户不存在");
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!passwordEncoder.matches(loginRequestDTO.getPassword(), userDO.getPassword())) {
|
if (!passwordEncoder.matches(loginRequestDTO.getPassword(), userDO.getPassword())) {
|
||||||
throw new RuntimeException("密码错误");
|
throw new RuntimeException("密码错误");
|
||||||
@@ -610,9 +605,7 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, UserDO> implements
|
|||||||
String account = jwtUtil.getAccountFromToken(refreshToken);
|
String account = jwtUtil.getAccountFromToken(refreshToken);
|
||||||
|
|
||||||
UserDO userDO = userMapper.selectById(userId);
|
UserDO userDO = userMapper.selectById(userId);
|
||||||
if (userDO == null) {
|
assertUserAvailable(userDO);
|
||||||
throw new RuntimeException("用户不存在");
|
|
||||||
}
|
|
||||||
|
|
||||||
String newAccessToken = jwtUtil.generateAccessToken(userId, account);
|
String newAccessToken = jwtUtil.generateAccessToken(userId, account);
|
||||||
String newRefreshToken = jwtUtil.generateRefreshToken(userId, account);
|
String newRefreshToken = jwtUtil.generateRefreshToken(userId, account);
|
||||||
@@ -643,12 +636,35 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, UserDO> implements
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean updateCurrentUserInfo(Long userId, UserDTO userDTO) {
|
||||||
|
UserDO userDO = userMapper.selectById(userId);
|
||||||
|
assertUserAvailable(userDO);
|
||||||
|
|
||||||
|
if (userDTO.getNickname() != null) {
|
||||||
|
userDO.setNickname(userDTO.getNickname());
|
||||||
|
}
|
||||||
|
if (userDTO.getAvatar() != null) {
|
||||||
|
if (userDTO.getAvatar().isEmpty()) {
|
||||||
|
userDO.setAvatar(null);
|
||||||
|
} else {
|
||||||
|
userDO.setAvatar(userDTO.getAvatar());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (userDTO.getSignature() != null) {
|
||||||
|
userDO.setSignature(userDTO.getSignature());
|
||||||
|
}
|
||||||
|
|
||||||
|
userDO.setUpdateTime(LocalDateTime.now());
|
||||||
|
return userMapper.updateById(userDO) > 0;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean bindPhone(Long userId, BindPhoneRequestDTO bindPhoneRequestDTO) {
|
public boolean bindPhone(Long userId, BindPhoneRequestDTO bindPhoneRequestDTO) {
|
||||||
UserDO userDO = userMapper.selectById(userId);
|
UserDO userDO = userMapper.selectById(userId);
|
||||||
if (userDO == null) {
|
assertUserAvailable(userDO);
|
||||||
throw new RuntimeException("用户不存在");
|
validateVerificationCode(bindPhoneRequestDTO.getPhone(), bindPhoneRequestDTO.getVerificationCode());
|
||||||
}
|
ensurePhoneNotUsed(bindPhoneRequestDTO.getPhone(), userId);
|
||||||
|
|
||||||
userDO.setPhone(bindPhoneRequestDTO.getPhone());
|
userDO.setPhone(bindPhoneRequestDTO.getPhone());
|
||||||
userDO.setPhoneVerified(1);
|
userDO.setPhoneVerified(1);
|
||||||
@@ -745,20 +761,20 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, UserDO> implements
|
|||||||
@Override
|
@Override
|
||||||
public boolean updateUserAvatar(Long userId, String avatarUrl) {
|
public boolean updateUserAvatar(Long userId, String avatarUrl) {
|
||||||
UserDO userDO = userMapper.selectById(userId);
|
UserDO userDO = userMapper.selectById(userId);
|
||||||
if (userDO == null) {
|
assertUserAvailable(userDO);
|
||||||
throw new RuntimeException("用户不存在");
|
|
||||||
}
|
|
||||||
userDO.setAvatar(avatarUrl);
|
userDO.setAvatar(avatarUrl);
|
||||||
userDO.setUpdateTime(LocalDateTime.now());
|
userDO.setUpdateTime(LocalDateTime.now());
|
||||||
return userMapper.updateById(userDO) > 0;
|
return userMapper.updateById(userDO) > 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean updatePassword(Long userId, String password) {
|
public boolean updatePassword(Long userId, String password, String verificationCode) {
|
||||||
UserDO userDO = userMapper.selectById(userId);
|
UserDO userDO = userMapper.selectById(userId);
|
||||||
if (userDO == null) {
|
assertUserAvailable(userDO);
|
||||||
throw new RuntimeException("用户不存在");
|
if (!StringUtils.hasText(userDO.getPhone())) {
|
||||||
|
throw new RuntimeException("请先绑定手机号");
|
||||||
}
|
}
|
||||||
|
validateVerificationCode(userDO.getPhone(), verificationCode);
|
||||||
userDO.setPassword(passwordEncoder.encode(password));
|
userDO.setPassword(passwordEncoder.encode(password));
|
||||||
userDO.setUpdateTime(LocalDateTime.now());
|
userDO.setUpdateTime(LocalDateTime.now());
|
||||||
return userMapper.updateById(userDO) > 0;
|
return userMapper.updateById(userDO) > 0;
|
||||||
@@ -770,27 +786,20 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, UserDO> implements
|
|||||||
String newPhone = updatePhoneDTO.getNewPhone();
|
String newPhone = updatePhoneDTO.getNewPhone();
|
||||||
String verificationCode = updatePhoneDTO.getVerificationCode();
|
String verificationCode = updatePhoneDTO.getVerificationCode();
|
||||||
|
|
||||||
// 验证验证码
|
|
||||||
String redisKey = "verification_code:" + newPhone;
|
|
||||||
String storedCode = redisTemplate.opsForValue().get(redisKey);
|
|
||||||
if (storedCode == null || !storedCode.equals(verificationCode)) {
|
|
||||||
throw new RuntimeException("验证码错误");
|
|
||||||
}
|
|
||||||
|
|
||||||
// 检查新手机号是否已被其他用户使用
|
|
||||||
LambdaQueryWrapper<UserDO> wrapper = Wrappers.lambdaQuery(UserDO.class);
|
|
||||||
wrapper.eq(UserDO::getPhone, newPhone);
|
|
||||||
wrapper.ne(UserDO::getId, userId);
|
|
||||||
if (userMapper.selectOne(wrapper) != null) {
|
|
||||||
throw new RuntimeException("手机号已被使用");
|
|
||||||
}
|
|
||||||
|
|
||||||
// 更新手机号
|
|
||||||
UserDO userDO = userMapper.selectById(userId);
|
UserDO userDO = userMapper.selectById(userId);
|
||||||
if (userDO == null) {
|
assertUserAvailable(userDO);
|
||||||
throw new RuntimeException("用户不存在");
|
if (!StringUtils.hasText(userDO.getPhone())) {
|
||||||
|
throw new RuntimeException("当前账号未绑定手机号");
|
||||||
}
|
}
|
||||||
|
if (!userDO.getPhone().equals(oldPhone)) {
|
||||||
|
throw new RuntimeException("原手机号不匹配");
|
||||||
|
}
|
||||||
|
|
||||||
|
validateVerificationCode(newPhone, verificationCode);
|
||||||
|
ensurePhoneNotUsed(newPhone, userId);
|
||||||
|
|
||||||
userDO.setPhone(newPhone);
|
userDO.setPhone(newPhone);
|
||||||
|
userDO.setPhoneVerified(1);
|
||||||
userDO.setUpdateTime(LocalDateTime.now());
|
userDO.setUpdateTime(LocalDateTime.now());
|
||||||
return userMapper.updateById(userDO) > 0;
|
return userMapper.updateById(userDO) > 0;
|
||||||
}
|
}
|
||||||
@@ -801,25 +810,54 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, UserDO> implements
|
|||||||
String verificationCode = resetPasswordRequestDTO.getVerificationCode();
|
String verificationCode = resetPasswordRequestDTO.getVerificationCode();
|
||||||
String newPassword = resetPasswordRequestDTO.getNewPassword();
|
String newPassword = resetPasswordRequestDTO.getNewPassword();
|
||||||
|
|
||||||
// 验证验证码
|
validateVerificationCode(phone, verificationCode);
|
||||||
String redisKey = "verification_code:" + phone;
|
|
||||||
String storedCode = redisTemplate.opsForValue().get(redisKey);
|
|
||||||
if (storedCode == null || !storedCode.equals(verificationCode)) {
|
|
||||||
throw new RuntimeException("验证码错误");
|
|
||||||
}
|
|
||||||
|
|
||||||
// 根据手机号查找用户
|
// 根据手机号查找用户
|
||||||
LambdaQueryWrapper<UserDO> wrapper = Wrappers.lambdaQuery(UserDO.class);
|
LambdaQueryWrapper<UserDO> wrapper = Wrappers.lambdaQuery(UserDO.class);
|
||||||
wrapper.eq(UserDO::getPhone, phone);
|
wrapper.eq(UserDO::getPhone, phone);
|
||||||
|
wrapper.eq(UserDO::getIsDelete, 0);
|
||||||
UserDO userDO = userMapper.selectOne(wrapper);
|
UserDO userDO = userMapper.selectOne(wrapper);
|
||||||
|
|
||||||
if (userDO == null) {
|
if (userDO == null) {
|
||||||
throw new RuntimeException("未绑定手机号,请联系店员");
|
throw new RuntimeException("未绑定手机号,请联系店员");
|
||||||
}
|
}
|
||||||
|
if (userDO.getStatus() != null && !Integer.valueOf(1).equals(userDO.getStatus())) {
|
||||||
|
throw new RuntimeException("账号已被禁用");
|
||||||
|
}
|
||||||
|
|
||||||
// 更新密码
|
// 更新密码
|
||||||
userDO.setPassword(passwordEncoder.encode(newPassword));
|
userDO.setPassword(passwordEncoder.encode(newPassword));
|
||||||
userDO.setUpdateTime(LocalDateTime.now());
|
userDO.setUpdateTime(LocalDateTime.now());
|
||||||
return userMapper.updateById(userDO) > 0;
|
return userMapper.updateById(userDO) > 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void assertUserAvailable(UserDO userDO) {
|
||||||
|
if (userDO == null || Integer.valueOf(1).equals(userDO.getIsDelete())) {
|
||||||
|
throw new RuntimeException("用户不存在");
|
||||||
|
}
|
||||||
|
if (userDO.getStatus() != null && !Integer.valueOf(1).equals(userDO.getStatus())) {
|
||||||
|
throw new RuntimeException("账号已被禁用");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void validateVerificationCode(String phone, String verificationCode) {
|
||||||
|
if (!StringUtils.hasText(phone) || !StringUtils.hasText(verificationCode)) {
|
||||||
|
throw new RuntimeException("验证码不能为空");
|
||||||
|
}
|
||||||
|
if (!verificationCodeService.verifyCode(phone, verificationCode)) {
|
||||||
|
throw new RuntimeException("验证码错误或已过期");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void ensurePhoneNotUsed(String phone, Long currentUserId) {
|
||||||
|
LambdaQueryWrapper<UserDO> wrapper = Wrappers.lambdaQuery(UserDO.class)
|
||||||
|
.eq(UserDO::getPhone, phone)
|
||||||
|
.eq(UserDO::getIsDelete, 0);
|
||||||
|
if (currentUserId != null) {
|
||||||
|
wrapper.ne(UserDO::getId, currentUserId);
|
||||||
|
}
|
||||||
|
if (userMapper.selectOne(wrapper) != null) {
|
||||||
|
throw new RuntimeException("手机号已被使用");
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+26
-2
@@ -3,12 +3,13 @@ package com.xiaowang.yuminailcore.service.impl;
|
|||||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||||
import com.xiaowang.yuminailcore.dto.WishlistDTO;
|
import com.xiaowang.yuminailcore.dto.WishlistDTO;
|
||||||
import com.xiaowang.yuminailcore.vo.ProductVO;
|
import com.xiaowang.yuminailcore.entity.ProductDO;
|
||||||
import com.xiaowang.yuminailcore.entity.WishlistDO;
|
import com.xiaowang.yuminailcore.entity.WishlistDO;
|
||||||
import com.xiaowang.yuminailcore.mapper.WishlistMapper;
|
import com.xiaowang.yuminailcore.mapper.WishlistMapper;
|
||||||
import com.xiaowang.yuminailcore.mapper.ProductMapper;
|
import com.xiaowang.yuminailcore.mapper.ProductMapper;
|
||||||
import com.xiaowang.yuminailcore.service.WishlistService;
|
import com.xiaowang.yuminailcore.service.WishlistService;
|
||||||
import com.xiaowang.yuminailcore.service.ProductService;
|
import com.xiaowang.yuminailcore.service.ProductService;
|
||||||
|
import com.xiaowang.yuminailcore.vo.ProductVO;
|
||||||
import org.springframework.beans.BeanUtils;
|
import org.springframework.beans.BeanUtils;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
@@ -29,6 +30,11 @@ public class WishlistServiceImpl extends ServiceImpl<WishlistMapper, WishlistDO>
|
|||||||
@Override
|
@Override
|
||||||
@Transactional
|
@Transactional
|
||||||
public void addToWishlist(Long userId, Long productId) {
|
public void addToWishlist(Long userId, Long productId) {
|
||||||
|
ProductDO product = getValidProduct(productId);
|
||||||
|
if (product == null) {
|
||||||
|
throw new RuntimeException("商品不存在或已下架");
|
||||||
|
}
|
||||||
|
|
||||||
LambdaQueryWrapper<WishlistDO> wrapper = new LambdaQueryWrapper<>();
|
LambdaQueryWrapper<WishlistDO> wrapper = new LambdaQueryWrapper<>();
|
||||||
wrapper.eq(WishlistDO::getUserId, userId);
|
wrapper.eq(WishlistDO::getUserId, userId);
|
||||||
wrapper.eq(WishlistDO::getProductId, productId);
|
wrapper.eq(WishlistDO::getProductId, productId);
|
||||||
@@ -51,12 +57,17 @@ public class WishlistServiceImpl extends ServiceImpl<WishlistMapper, WishlistDO>
|
|||||||
if (count(wrapper) > 0) {
|
if (count(wrapper) > 0) {
|
||||||
remove(wrapper);
|
remove(wrapper);
|
||||||
// 减少商品收藏数
|
// 减少商品收藏数
|
||||||
|
if (getValidProduct(productId) != null) {
|
||||||
productMapper.decrementCollectCount(productId);
|
productMapper.decrementCollectCount(productId);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isInWishlist(Long userId, Long productId) {
|
public boolean isInWishlist(Long userId, Long productId) {
|
||||||
|
if (getValidProduct(productId) == null) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
LambdaQueryWrapper<WishlistDO> wrapper = new LambdaQueryWrapper<>();
|
LambdaQueryWrapper<WishlistDO> wrapper = new LambdaQueryWrapper<>();
|
||||||
wrapper.eq(WishlistDO::getUserId, userId);
|
wrapper.eq(WishlistDO::getUserId, userId);
|
||||||
wrapper.eq(WishlistDO::getProductId, productId);
|
wrapper.eq(WishlistDO::getProductId, productId);
|
||||||
@@ -74,6 +85,19 @@ public class WishlistServiceImpl extends ServiceImpl<WishlistMapper, WishlistDO>
|
|||||||
ProductVO productVO = productService.getProductById(wishlistDO.getProductId());
|
ProductVO productVO = productService.getProductById(wishlistDO.getProductId());
|
||||||
wishlistDTO.setProduct(productVO);
|
wishlistDTO.setProduct(productVO);
|
||||||
return wishlistDTO;
|
return wishlistDTO;
|
||||||
}).collect(Collectors.toList());
|
}).filter(wishlistDTO -> wishlistDTO.getProduct() != null).collect(Collectors.toList());
|
||||||
|
}
|
||||||
|
|
||||||
|
private ProductDO getValidProduct(Long productId) {
|
||||||
|
if (productId == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
ProductDO product = productMapper.selectById(productId);
|
||||||
|
if (product == null || Integer.valueOf(1).equals(product.getIsDelete())) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
return product;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,89 @@
|
|||||||
|
package com.xiaowang.yuminailcore.support;
|
||||||
|
|
||||||
|
import com.xiaowang.yuminailcore.entity.UserDO;
|
||||||
|
import com.xiaowang.yuminailcore.service.UserService;
|
||||||
|
import lombok.RequiredArgsConstructor;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
import javax.servlet.http.HttpServletRequest;
|
||||||
|
|
||||||
|
@Component
|
||||||
|
@RequiredArgsConstructor
|
||||||
|
public class AdminScopeHelper {
|
||||||
|
|
||||||
|
private final UserService userService;
|
||||||
|
|
||||||
|
public UserDO getCurrentUser(HttpServletRequest request) {
|
||||||
|
Long userId = (Long) request.getAttribute("userId");
|
||||||
|
if (userId == null) {
|
||||||
|
throw new RuntimeException("未获取到当前用户信息");
|
||||||
|
}
|
||||||
|
|
||||||
|
UserDO currentUser = userService.getById(userId);
|
||||||
|
if (currentUser == null || Integer.valueOf(1).equals(currentUser.getIsDelete())) {
|
||||||
|
throw new RuntimeException("当前用户不存在或已失效");
|
||||||
|
}
|
||||||
|
|
||||||
|
return currentUser;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isPlatformAdmin(UserDO currentUser) {
|
||||||
|
return currentUser != null && Integer.valueOf(4).equals(currentUser.getType());
|
||||||
|
}
|
||||||
|
|
||||||
|
public Long getManagedShopId(UserDO currentUser) {
|
||||||
|
if (isPlatformAdmin(currentUser)) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (currentUser == null || currentUser.getShopId() == null || currentUser.getShopId() <= 0) {
|
||||||
|
throw new RuntimeException("当前账号未绑定店铺,无法访问后台业务数据");
|
||||||
|
}
|
||||||
|
|
||||||
|
return currentUser.getShopId();
|
||||||
|
}
|
||||||
|
|
||||||
|
public Long resolveShopScope(UserDO currentUser, Long requestedShopId) {
|
||||||
|
Long managedShopId = getManagedShopId(currentUser);
|
||||||
|
return managedShopId != null ? managedShopId : requestedShopId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void ensureShopAccessible(UserDO currentUser, Long targetShopId, String message) {
|
||||||
|
Long managedShopId = getManagedShopId(currentUser);
|
||||||
|
if (managedShopId != null && !managedShopId.equals(targetShopId)) {
|
||||||
|
throw new RuntimeException(message);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void requirePlatformAdmin(UserDO currentUser, String message) {
|
||||||
|
if (!isPlatformAdmin(currentUser)) {
|
||||||
|
throw new RuntimeException(message);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void ensureAssignableUserType(UserDO currentUser, Integer targetType) {
|
||||||
|
if (targetType == null) {
|
||||||
|
throw new RuntimeException("用户类型不能为空");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isPlatformAdmin(currentUser)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (Integer.valueOf(2).equals(currentUser.getType())) {
|
||||||
|
if (Integer.valueOf(0).equals(targetType) || Integer.valueOf(3).equals(targetType)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
throw new RuntimeException("店长只能创建或维护普通用户、美甲师");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (Integer.valueOf(3).equals(currentUser.getType())) {
|
||||||
|
if (Integer.valueOf(0).equals(targetType)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
throw new RuntimeException("美甲师只能创建或维护普通用户");
|
||||||
|
}
|
||||||
|
|
||||||
|
throw new RuntimeException("当前角色无权维护后台用户");
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -8,10 +8,14 @@ import java.math.BigDecimal;
|
|||||||
public class CartVO {
|
public class CartVO {
|
||||||
private Long id;
|
private Long id;
|
||||||
private Long productId;
|
private Long productId;
|
||||||
|
private Long shopId;
|
||||||
private String productTitle;
|
private String productTitle;
|
||||||
private String productImage;
|
private String productImage;
|
||||||
private BigDecimal price;
|
private BigDecimal price;
|
||||||
private Integer quantity;
|
private Integer quantity;
|
||||||
private BigDecimal totalPrice;
|
private BigDecimal totalPrice;
|
||||||
private String tags;
|
private String tags;
|
||||||
|
private String tagNames;
|
||||||
|
private String approximateDuration;
|
||||||
|
private String bookableArtists;
|
||||||
}
|
}
|
||||||
+1
-1
@@ -33,11 +33,11 @@ public class AuthGlobalFilter implements GlobalFilter, Ordered {
|
|||||||
private static final List<String> DEFAULT_WHITELIST = List.of(
|
private static final List<String> DEFAULT_WHITELIST = List.of(
|
||||||
"/api/user/login",
|
"/api/user/login",
|
||||||
"/api/user/register",
|
"/api/user/register",
|
||||||
|
"/api/user/check/**",
|
||||||
"/api/user/refresh-token",
|
"/api/user/refresh-token",
|
||||||
"/api/user/send-verification-code",
|
"/api/user/send-verification-code",
|
||||||
"/api/user/phone-login",
|
"/api/user/phone-login",
|
||||||
"/api/user/reset-password-by-phone",
|
"/api/user/reset-password-by-phone",
|
||||||
"/api/user/get/account/**",
|
|
||||||
"/api/shop/list/simple",
|
"/api/shop/list/simple",
|
||||||
"/api/admin/auth/login",
|
"/api/admin/auth/login",
|
||||||
"/api/admin/auth/refresh",
|
"/api/admin/auth/refresh",
|
||||||
|
|||||||
@@ -121,7 +121,6 @@ yuminail:
|
|||||||
- /api/user/send-verification-code
|
- /api/user/send-verification-code
|
||||||
- /api/user/phone-login
|
- /api/user/phone-login
|
||||||
- /api/user/reset-password-by-phone
|
- /api/user/reset-password-by-phone
|
||||||
- /api/user/get/account/**
|
|
||||||
- /api/shop/list/simple
|
- /api/shop/list/simple
|
||||||
- /api/health/**
|
- /api/health/**
|
||||||
- /api/error
|
- /api/error
|
||||||
|
|||||||
@@ -0,0 +1,4 @@
|
|||||||
|
1、每次必须将修改后的所有记录编写为一个md文件放在changes下
|
||||||
|
2、所有的建议放在features下面,已经完成过的移除掉放在changes下
|
||||||
|
3、有必要的话同步修改整体架构和项目架构分析
|
||||||
|
4、将每次任务的文件修改提交到git中
|
||||||
@@ -0,0 +1,107 @@
|
|||||||
|
# 2026-03-19 业务链路与后台权限整改
|
||||||
|
|
||||||
|
## 1. 本次处理范围
|
||||||
|
|
||||||
|
本轮围绕以下链路做了完整检查和修复:
|
||||||
|
|
||||||
|
- 添加购物车
|
||||||
|
- 收藏
|
||||||
|
- 订单确认
|
||||||
|
- 购物车中选择美甲师
|
||||||
|
- 美甲师查看并完成属于自己的订单
|
||||||
|
- 后台各管理板块之间的店铺隔离与权限边界
|
||||||
|
- 注册阶段账号/手机号占用校验
|
||||||
|
|
||||||
|
同时按约定整理了 `docs/features` 与 `docs/changes`:
|
||||||
|
|
||||||
|
- 原 `docs/features/优化需求.txt` 已完成并转入本记录
|
||||||
|
- 仍未落地的建议保留在 `docs/features/待优化建议.md`
|
||||||
|
|
||||||
|
## 2. 已完成项
|
||||||
|
|
||||||
|
### 2.1 购物车与收藏链路
|
||||||
|
|
||||||
|
- 购物车服务端新增数量范围校验,禁止 0、负数和异常数量。
|
||||||
|
- 购物车查询现在返回商品所属店铺、可预约美甲师、服务时长、标签名称,前端不再只拿到原始标签 ID。
|
||||||
|
- 下单成功后由服务端清理对应购物车项,避免前端二次删除失败导致脏数据。
|
||||||
|
- 收藏新增商品有效性校验,已下架/已删除商品不会继续进入收藏逻辑。
|
||||||
|
|
||||||
|
### 2.2 订单确认与美甲师订单
|
||||||
|
|
||||||
|
- 创建订单时强制校验商品仍属于当前用户购物车。
|
||||||
|
- 创建订单时强制同店铺、同美甲师结算,避免一个订单跨多店、多美甲师导致后续处理失真。
|
||||||
|
- 创建订单时补齐优惠券可用性校验,不再只看用户是否持有优惠券。
|
||||||
|
- 美甲师订单列表只返回分配给当前美甲师的项目,并按该美甲师项目重新计算显示金额。
|
||||||
|
- 新增美甲师专用“完成订单”接口,避免美甲师复用后台通用处理接口去操作他人订单。
|
||||||
|
|
||||||
|
### 2.3 前端交互修正
|
||||||
|
|
||||||
|
- 商品列表、收藏页添加购物车后会同步刷新全局购物车数量。
|
||||||
|
- 购物车结算金额改为实时按 `price * quantity` 计算,修复数量变化后小计不刷新的问题。
|
||||||
|
- 购物车只会展示当前商品可预约、且属于同店铺的美甲师,减少错误选择。
|
||||||
|
- 购物车结算前端同步校验“同店铺、同美甲师”,并将按钮文案改为“结算项目”而非误导性的“多笔订单”。
|
||||||
|
- 美甲师订单页改为调用专用完成接口。
|
||||||
|
|
||||||
|
### 2.4 后台权限与数据边界
|
||||||
|
|
||||||
|
- 新增 `AdminScopeHelper`,统一后台当前用户、平台管理员、店铺边界判断。
|
||||||
|
- 用户、商品、店铺、标签、优惠券、订单、仪表盘、权限管理等后台入口补上店铺级访问边界。
|
||||||
|
- 平台管理员可全局访问;店长/美甲师只能访问所属店铺数据。
|
||||||
|
- 权限定义的新增、编辑、删除改为仅允许平台管理员执行,店铺侧继续保留“给本店铺用户分配权限”的能力。
|
||||||
|
- 商品后台新增可预约美甲师校验,禁止把其他店铺用户配置到商品可预约列表。
|
||||||
|
- 历史 `/order/admin/*` 旧后台接口也同步补上了店铺隔离,避免前后端混用旧接口时绕过新控制器。
|
||||||
|
|
||||||
|
### 2.5 注册阶段占用校验
|
||||||
|
|
||||||
|
- 新增匿名可访问的账号可用性校验接口和手机号可用性校验接口。
|
||||||
|
- 注册页输入账号后会校验是否已被注册。
|
||||||
|
- 注册页发送验证码前会校验手机号是否已注册,并在输入框下方展示状态提示。
|
||||||
|
|
||||||
|
## 3. 涉及的主要文件
|
||||||
|
|
||||||
|
### 后端
|
||||||
|
|
||||||
|
- `YumiNail-Core/src/main/java/com/xiaowang/yuminailcore/support/AdminScopeHelper.java`
|
||||||
|
- `YumiNail-Core/src/main/java/com/xiaowang/yuminailcore/service/impl/CartServiceImpl.java`
|
||||||
|
- `YumiNail-Core/src/main/java/com/xiaowang/yuminailcore/service/impl/WishlistServiceImpl.java`
|
||||||
|
- `YumiNail-Core/src/main/java/com/xiaowang/yuminailcore/service/impl/OrderServiceImpl.java`
|
||||||
|
- `YumiNail-Core/src/main/java/com/xiaowang/yuminailcore/service/impl/ProductServiceImpl.java`
|
||||||
|
- `YumiNail-Core/src/main/java/com/xiaowang/yuminailcore/controller/OrderController.java`
|
||||||
|
- `YumiNail-Core/src/main/java/com/xiaowang/yuminailcore/controller/UserController.java`
|
||||||
|
- `YumiNail-Core/src/main/java/com/xiaowang/yuminailcore/controller/AdminUserController.java`
|
||||||
|
- `YumiNail-Core/src/main/java/com/xiaowang/yuminailcore/controller/AdminProductController.java`
|
||||||
|
- `YumiNail-Core/src/main/java/com/xiaowang/yuminailcore/controller/AdminShopController.java`
|
||||||
|
- `YumiNail-Core/src/main/java/com/xiaowang/yuminailcore/controller/AdminTagController.java`
|
||||||
|
- `YumiNail-Core/src/main/java/com/xiaowang/yuminailcore/controller/AdminCouponController.java`
|
||||||
|
- `YumiNail-Core/src/main/java/com/xiaowang/yuminailcore/controller/AdminOrderController.java`
|
||||||
|
- `YumiNail-Core/src/main/java/com/xiaowang/yuminailcore/controller/AdminPermissionController.java`
|
||||||
|
- `YumiNail-Core/src/main/java/com/xiaowang/yuminailcore/controller/DashboardController.java`
|
||||||
|
- `YumiNail-Core/src/main/java/com/xiaowang/yuminailcore/config/WebMvcConfig.java`
|
||||||
|
- `YumiNail-Gateway/src/main/java/com/xiaowang/yumitailgateway/filter/AuthGlobalFilter.java`
|
||||||
|
|
||||||
|
### 前端
|
||||||
|
|
||||||
|
- `Frontend/src/views/AuthView.vue`
|
||||||
|
- `Frontend/src/views/CartView.vue`
|
||||||
|
- `Frontend/src/views/ArtistOrderView.vue`
|
||||||
|
- `Frontend/src/views/ProductListView.vue`
|
||||||
|
- `Frontend/src/views/WishlistView.vue`
|
||||||
|
- `Frontend/src/api/user.ts`
|
||||||
|
- `Frontend/src/api/order.ts`
|
||||||
|
- `Frontend/src/router/index.ts`
|
||||||
|
|
||||||
|
### 文档
|
||||||
|
|
||||||
|
- `docs/architecture/整体架构总览.md`
|
||||||
|
- `docs/architecture/项目架构分析.md`
|
||||||
|
|
||||||
|
## 4. 验证结果
|
||||||
|
|
||||||
|
- `Frontend`:`npm run build` 通过
|
||||||
|
- `YumiNail-Core`:`mvn -q -DskipTests compile` 通过
|
||||||
|
- `YumiNail-Gateway`:`mvn -q -DskipTests compile` 通过
|
||||||
|
|
||||||
|
## 5. 备注
|
||||||
|
|
||||||
|
- 本轮没有处理你工作区里原本就存在的 `.idea/*`、`.swp`、`docs/features/...txt` 之外的无关改动。
|
||||||
|
- “购物车中选择美甲师时间”目前只完成了问题定位与架构建议,没有强行做一个落不到数据库的半成品,后续建议已保留到 `docs/features/待优化建议.md`。
|
||||||
@@ -0,0 +1,29 @@
|
|||||||
|
# 2026-03-19 全量打包与代码提交
|
||||||
|
|
||||||
|
## 1. 本次处理范围
|
||||||
|
|
||||||
|
本轮按 `docs/base.md` 要求,对当前工作区已有代码进行统一打包校验,并将本次累计修改统一提交到 git。
|
||||||
|
|
||||||
|
## 2. 本次执行内容
|
||||||
|
|
||||||
|
- 对 `Frontend` 执行生产构建
|
||||||
|
- 对 `YumiNail-Core` 执行 Maven `package`
|
||||||
|
- 对 `YumiNail-Gateway` 执行 Maven `package`
|
||||||
|
- 对 `MessageHub` 执行 Maven `package`
|
||||||
|
- 将当前工作区中的代码与文档改动统一提交到 git
|
||||||
|
|
||||||
|
## 3. SQL 说明
|
||||||
|
|
||||||
|
本轮仅执行打包与代码提交,没有新增 SQL 变更。
|
||||||
|
|
||||||
|
## 4. 打包结果
|
||||||
|
|
||||||
|
- `Frontend`:`npm run build` 通过
|
||||||
|
- `YumiNail-Core`:`mvn -q -DskipTests package` 通过
|
||||||
|
- `YumiNail-Gateway`:`mvn -q -DskipTests package` 通过
|
||||||
|
- `MessageHub`:`mvn -q -DskipTests package` 通过
|
||||||
|
|
||||||
|
## 5. 备注
|
||||||
|
|
||||||
|
- 提交时会优先纳入源码、配置、文档等项目文件
|
||||||
|
- 编辑器临时文件如 `.swp` 不属于项目代码,不建议提交
|
||||||
@@ -1,151 +0,0 @@
|
|||||||
# 优惠券功能总结
|
|
||||||
|
|
||||||
## 1. 功能概述
|
|
||||||
|
|
||||||
本系统实现了完整的优惠券功能,包括:
|
|
||||||
- 优惠券发放功能
|
|
||||||
- 优惠券标签匹配逻辑
|
|
||||||
- 前台优惠券展示页面
|
|
||||||
- 优惠券使用和管理
|
|
||||||
|
|
||||||
## 2. 表结构设计
|
|
||||||
|
|
||||||
### 2.1 核心表结构
|
|
||||||
|
|
||||||
#### t_coupon(优惠券信息表)
|
|
||||||
| 字段名 | 类型 | 描述 |
|
|
||||||
|-------|------|------|
|
|
||||||
| id | bigint unsigned | 优惠券唯一主键ID |
|
|
||||||
| coupon_code | varchar(50) | 优惠券编码 |
|
|
||||||
| coupon_name | varchar(100) | 优惠券名称 |
|
|
||||||
| coupon_type | tinyint | 优惠券类型:1-折扣券,2-满减券 |
|
|
||||||
| discount_value | decimal(10,2) | 折扣值(如9.5表示95折) |
|
|
||||||
| min_amount | decimal(10,2) | 满减券最低消费金额 |
|
|
||||||
| reduce_amount | decimal(10,2) | 满减券减免金额 |
|
|
||||||
| total_count | int unsigned | 优惠券总数量 |
|
|
||||||
| used_count | int unsigned | 已使用数量 |
|
|
||||||
| start_time | datetime | 开始时间 |
|
|
||||||
| end_time | datetime | 结束时间 |
|
|
||||||
| status | tinyint unsigned | 状态:1-可用,2-已过期,3-已用完 |
|
|
||||||
| shop_id | bigint unsigned | 所属店铺ID |
|
|
||||||
| is_delete | tinyint unsigned | 逻辑删除:0-未删,1-已删 |
|
|
||||||
|
|
||||||
#### t_user_coupon(用户优惠券关联表)
|
|
||||||
| 字段名 | 类型 | 描述 |
|
|
||||||
|-------|------|------|
|
|
||||||
| id | bigint unsigned | 用户优惠券关联唯一主键ID |
|
|
||||||
| user_id | bigint unsigned | 关联用户表主键 |
|
|
||||||
| coupon_id | bigint unsigned | 关联优惠券表主键 |
|
|
||||||
| status | tinyint unsigned | 状态:1-未使用,2-已使用,3-已过期 |
|
|
||||||
| obtain_time | datetime | 获取时间 |
|
|
||||||
| use_time | datetime | 使用时间 |
|
|
||||||
| is_delete | tinyint unsigned | 逻辑删除:0-未删,1-已删 |
|
|
||||||
|
|
||||||
#### t_coupon_tag(优惠券标签关联表)
|
|
||||||
| 字段名 | 类型 | 描述 |
|
|
||||||
|-------|------|------|
|
|
||||||
| id | bigint unsigned | 优惠券标签关联唯一主键ID |
|
|
||||||
| coupon_id | bigint unsigned | 关联优惠券表主键 |
|
|
||||||
| tag_id | bigint unsigned | 关联标签表主键 |
|
|
||||||
| is_available | tinyint unsigned | 是否可用:1-可用,0-不可用 |
|
|
||||||
| is_delete | tinyint unsigned | 逻辑删除:0-未删,1-已删 |
|
|
||||||
|
|
||||||
#### t_product(商品信息表)
|
|
||||||
| 字段名 | 类型 | 描述 |
|
|
||||||
|-------|------|------|
|
|
||||||
| id | bigint unsigned | 商品唯一主键ID |
|
|
||||||
| shop_id | bigint unsigned | 所属店铺ID |
|
|
||||||
| title | varchar(100) | 商品标题 |
|
|
||||||
| price | decimal(10,2) | 商品价格 |
|
|
||||||
| tags | varchar(512) | 标签集合,多个标签以逗号分隔 |
|
|
||||||
| is_delete | tinyint unsigned | 逻辑删除:0-未删除,1-已删除 |
|
|
||||||
|
|
||||||
#### t_tag(系统标签信息表)
|
|
||||||
| 字段名 | 类型 | 描述 |
|
|
||||||
|-------|------|------|
|
|
||||||
| id | bigint unsigned | 标签唯一主键ID |
|
|
||||||
| tag_name | varchar(50) | 标签名称 |
|
|
||||||
| is_delete | tinyint unsigned | 逻辑删除:0-未删,1-已删 |
|
|
||||||
|
|
||||||
## 3. 标签匹配逻辑
|
|
||||||
|
|
||||||
### 3.1 规则说明
|
|
||||||
|
|
||||||
优惠券的标签匹配规则如下:
|
|
||||||
1. 如果商品有3个标签,其中如果有优惠券中有不可用的标签也有可用的,那么这个商品不可用优惠券
|
|
||||||
2. 只有当商品只包含可用标签时,才可使用优惠券
|
|
||||||
3. 满减类型的优惠券自身的满减,需要达到指定的金额才可用
|
|
||||||
|
|
||||||
### 3.2 实现逻辑
|
|
||||||
|
|
||||||
在 `CouponServiceImpl.java` 中的 `checkTagMatch` 方法实现了标签匹配逻辑:
|
|
||||||
|
|
||||||
1. 解析商品标签,获取商品的标签ID列表
|
|
||||||
2. 查询优惠券的所有标签关联,分离可用标签和不可用标签
|
|
||||||
3. 检查商品标签中是否包含不可用标签,如果有则返回false
|
|
||||||
4. 如果优惠券配置了可用标签,则检查商品标签是否全部属于可用标签,如果不是则返回false
|
|
||||||
5. 否则返回true
|
|
||||||
|
|
||||||
## 4. 前端页面结构
|
|
||||||
|
|
||||||
### 4.1 页面布局
|
|
||||||
|
|
||||||
- **优惠券页面**:`/src/views/CouponView.vue`
|
|
||||||
- 独立的优惠券展示页面
|
|
||||||
- 包含优惠券状态筛选(全部、未使用、已使用、已过期)
|
|
||||||
- 展示优惠券详情,包括优惠券类型、金额、使用条件、有效期等
|
|
||||||
|
|
||||||
- **个人中心页面**:`/src/views/ProfileView.vue`
|
|
||||||
- 包含优惠券入口,点击跳转到优惠券页面
|
|
||||||
- 显示优惠券数量
|
|
||||||
|
|
||||||
### 4.2 路由配置
|
|
||||||
|
|
||||||
在 `router/index.ts` 中添加了优惠券页面路由:
|
|
||||||
|
|
||||||
```typescript
|
|
||||||
{
|
|
||||||
path: '/coupons',
|
|
||||||
name: 'coupons',
|
|
||||||
component: () => import('../views/CouponView.vue'),
|
|
||||||
meta: { requiresAuth: true, isAdmin: false }
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
## 5. 核心功能实现
|
|
||||||
|
|
||||||
### 5.1 优惠券发放
|
|
||||||
|
|
||||||
- 通过 `distributeCoupon` 方法实现批量发放优惠券
|
|
||||||
- 支持指定用户列表和发放数量
|
|
||||||
- 检查优惠券数量是否足够
|
|
||||||
- 更新优惠券使用数量
|
|
||||||
|
|
||||||
### 5.2 优惠券使用
|
|
||||||
|
|
||||||
- 通过 `useCoupon` 方法实现优惠券使用
|
|
||||||
- 检查用户优惠券是否存在、是否属于当前用户、是否未使用、是否过期
|
|
||||||
- 更新用户优惠券状态和使用时间
|
|
||||||
- 更新优惠券使用数量
|
|
||||||
|
|
||||||
### 5.3 可用优惠券查询
|
|
||||||
|
|
||||||
- 通过 `getAvailableCoupons` 方法查询用户可用的优惠券
|
|
||||||
- 检查优惠券是否在有效期内、是否可用、是否满足满减条件、标签是否匹配
|
|
||||||
|
|
||||||
## 6. 技术实现要点
|
|
||||||
|
|
||||||
1. **标签匹配逻辑**:实现了严格的标签匹配规则,确保只有符合条件的商品才能使用优惠券
|
|
||||||
2. **前端页面分离**:将优惠券展示页面从个人中心分离出来,提供独立的用户体验
|
|
||||||
3. **数据一致性**:通过事务保证优惠券发放和使用的数据一致性
|
|
||||||
4. **状态管理**:完善的优惠券状态管理,包括可用、已使用、已过期、已用完等状态
|
|
||||||
|
|
||||||
## 7. 总结
|
|
||||||
|
|
||||||
本系统的优惠券功能已经完善,包括:
|
|
||||||
- 完整的表结构设计
|
|
||||||
- 严格的标签匹配逻辑
|
|
||||||
- 独立的前端展示页面
|
|
||||||
- 完善的发放和使用流程
|
|
||||||
|
|
||||||
系统已经满足用户的需求,优惠券发放功能正常,标签匹配逻辑正确,前台优惠券展示页面独立,关联关系清晰。
|
|
||||||
Reference in New Issue
Block a user