功能:落地待优化建议与VIP资产联动
This commit is contained in:
@@ -146,10 +146,10 @@ export interface Tag {
|
||||
|
||||
export const adminTagApi = {
|
||||
listAllTags: () => {
|
||||
return adminApi.get<Tag[]>('/tag/list/all')
|
||||
return adminApi.get<Tag[]>('/tag/list/all') as unknown as Promise<Tag[]>
|
||||
},
|
||||
listTagsByShopId: (shopId: number) => {
|
||||
return adminApi.get<Tag[]>(`/tag/list/by-shop/${shopId}`)
|
||||
return adminApi.get<Tag[]>(`/tag/list/by-shop/${shopId}`) as unknown as Promise<Tag[]>
|
||||
},
|
||||
createTag: (data: { tagName: string; textColor?: string; bgColor?: string; borderColor?: string; shopId?: number }) => {
|
||||
return adminApi.post<number>('/tag/create', data)
|
||||
@@ -185,15 +185,27 @@ export const adminArtistApi = {
|
||||
|
||||
export interface Coupon {
|
||||
id: number
|
||||
couponCode?: string
|
||||
couponName: string
|
||||
couponType: number
|
||||
couponTypeName?: string
|
||||
discountValue?: string
|
||||
minAmount?: number
|
||||
reduceAmount?: string
|
||||
totalCount?: number
|
||||
usedCount?: number
|
||||
remainingCount?: number
|
||||
startTime: string
|
||||
endTime: string
|
||||
status?: number
|
||||
statusName?: string
|
||||
shopId?: number
|
||||
shopName?: string
|
||||
couponScene?: string
|
||||
requiredVipLevel?: string
|
||||
autoMatch?: number
|
||||
availableTags?: Tag[]
|
||||
unavailableTags?: Tag[]
|
||||
createTime: string
|
||||
updateTime: string
|
||||
}
|
||||
@@ -201,7 +213,7 @@ export interface Coupon {
|
||||
export const adminCouponApi = {
|
||||
listAllCoupons: (shopId?: number) => {
|
||||
const params = shopId ? { shopId } : {}
|
||||
return adminApi.get<Coupon[]>('/coupon/list/all', { params })
|
||||
return adminApi.get<Coupon[]>('/coupon/list/all', { params }) as unknown as Promise<Coupon[]>
|
||||
},
|
||||
createCoupon: (data: any) => {
|
||||
return adminApi.post<number>('/coupon/create', data)
|
||||
@@ -213,7 +225,7 @@ export const adminCouponApi = {
|
||||
return adminApi.delete<boolean>(`/coupon/delete/${id}`)
|
||||
},
|
||||
distributeCoupon: (data: any) => {
|
||||
return adminApi.post<boolean>('/coupon/distribute', data)
|
||||
return adminApi.post<boolean>('/coupon/distribute', null, { params: data })
|
||||
}
|
||||
}
|
||||
|
||||
@@ -288,10 +300,10 @@ export interface CreateShopRequest {
|
||||
|
||||
export const adminShopApi = {
|
||||
listShops: (params: { page: number; size: number; keyword?: string; shopId?: number }) => {
|
||||
return adminApi.get<ShopListResponse>('/shops/list', { params })
|
||||
return adminApi.get<ShopListResponse>('/shops/list', { params }) as unknown as Promise<ShopListResponse>
|
||||
},
|
||||
listAllShops: () => {
|
||||
return adminApi.get<Shop[]>('/shops/list/all')
|
||||
return adminApi.get<Shop[]>('/shops/list/all') as unknown as Promise<Shop[]>
|
||||
},
|
||||
createShop: (data: CreateShopRequest) => {
|
||||
return adminApi.post<number>('/shops/create', data)
|
||||
@@ -311,12 +323,14 @@ export interface UserVO {
|
||||
nickname: string
|
||||
account: string
|
||||
avatar: string
|
||||
phone?: string
|
||||
signature?: string
|
||||
level?: string
|
||||
type: number
|
||||
vipId?: number
|
||||
createTime: string
|
||||
updateTime: string
|
||||
status?: number
|
||||
}
|
||||
|
||||
export interface PageResult<T> {
|
||||
@@ -328,10 +342,10 @@ export interface PageResult<T> {
|
||||
|
||||
export const adminUserApi = {
|
||||
listUsers: (params: { page: number; size: number; keyword?: string; type?: number; shopId?: number; status?: number }) => {
|
||||
return adminApi.get<PageResult<UserVO>>('/user/list', { params })
|
||||
return adminApi.get<PageResult<UserVO>>('/user/list', { params }) as unknown as Promise<PageResult<UserVO>>
|
||||
},
|
||||
listAllUsers: () => {
|
||||
return adminApi.get<UserVO[]>('/user/list/all')
|
||||
return adminApi.get<UserVO[]>('/user/list/all') as unknown as Promise<UserVO[]>
|
||||
},
|
||||
createUser: (data: any) => {
|
||||
return adminApi.post<number>('/user/create', data)
|
||||
@@ -349,10 +363,71 @@ export const adminUserApi = {
|
||||
return adminApi.post<string>(`/user/reset-password/${id}`)
|
||||
},
|
||||
getUserInfo: () => {
|
||||
return adminApi.get<UserVO>('/user/info')
|
||||
return adminApi.get<UserVO>('/user/info') as unknown as Promise<UserVO>
|
||||
},
|
||||
getUserAsset: (id: number) => {
|
||||
return adminApi.get<UserAssetVO>(`/user/${id}/asset`) as unknown as Promise<UserAssetVO>
|
||||
},
|
||||
getUserBalanceHistory: (id: number) => {
|
||||
return adminApi.get<UserBalanceHistoryItem[]>(`/user/${id}/balance/history`) as unknown as Promise<UserBalanceHistoryItem[]>
|
||||
},
|
||||
changeUserBalance: (id: number, data: AdminUserBalanceChangeRequest) => {
|
||||
return adminApi.post<UserAssetVO>(`/user/${id}/balance/change`, data) as unknown as Promise<UserAssetVO>
|
||||
},
|
||||
overrideUserVip: (id: number, data: AdminUserVipOverrideRequest) => {
|
||||
return adminApi.post<UserAssetVO>(`/user/${id}/vip/override`, data) as unknown as Promise<UserAssetVO>
|
||||
},
|
||||
recalculateUserVip: (id: number) => {
|
||||
return adminApi.post<UserAssetVO>(`/user/${id}/vip/recalculate`) as unknown as Promise<UserAssetVO>
|
||||
}
|
||||
}
|
||||
|
||||
export interface UserAssetVO {
|
||||
userId: number
|
||||
nickname: string
|
||||
balance: number
|
||||
totalRechargeAmount: number
|
||||
lastRechargeTime?: string
|
||||
vipInfoId?: number
|
||||
vipLevel: string
|
||||
benefitId?: number
|
||||
benefitInfo?: string
|
||||
manualOverride: boolean
|
||||
vipStartTime?: string
|
||||
vipExpireTime?: string
|
||||
}
|
||||
|
||||
export interface UserBalanceHistoryItem {
|
||||
id: number
|
||||
userId: number
|
||||
userNickname?: string
|
||||
amount: number
|
||||
type?: string
|
||||
currentBalance?: number
|
||||
beforeBalance?: number
|
||||
afterBalance?: number
|
||||
changeScene?: string
|
||||
relatedOrderId?: number
|
||||
relatedOrderNo?: string
|
||||
externalOrderNo?: string
|
||||
operatorId?: number
|
||||
remark?: string
|
||||
changeTime: string
|
||||
}
|
||||
|
||||
export interface AdminUserBalanceChangeRequest {
|
||||
amount: number
|
||||
changeScene: string
|
||||
relatedOrderId?: number
|
||||
externalOrderNo?: string
|
||||
remark?: string
|
||||
}
|
||||
|
||||
export interface AdminUserVipOverrideRequest {
|
||||
vipLevel: string
|
||||
remark?: string
|
||||
}
|
||||
|
||||
// 别名导出,兼容旧代码
|
||||
export const userApi = adminUserApi
|
||||
|
||||
|
||||
@@ -17,6 +17,9 @@ export interface Coupon {
|
||||
status: number
|
||||
statusName: string
|
||||
shopId?: number
|
||||
couponScene?: string
|
||||
requiredVipLevel?: string
|
||||
autoMatch?: number
|
||||
availableTags: Tag[]
|
||||
unavailableTags: Tag[]
|
||||
}
|
||||
@@ -41,6 +44,9 @@ export interface UserCoupon {
|
||||
statusName: string
|
||||
obtainTime: string
|
||||
useTime: string
|
||||
sourceType?: string
|
||||
requiredVipLevel?: string
|
||||
autoMatched?: boolean
|
||||
}
|
||||
|
||||
export interface CreateCouponRequest {
|
||||
@@ -53,6 +59,9 @@ export interface CreateCouponRequest {
|
||||
totalCount: number
|
||||
startTime: string
|
||||
endTime: string
|
||||
couponScene?: string
|
||||
requiredVipLevel?: string
|
||||
autoMatch?: number
|
||||
availableTagIds: number[]
|
||||
unavailableTagIds: number[]
|
||||
}
|
||||
@@ -136,11 +145,11 @@ export const couponApi = {
|
||||
},
|
||||
|
||||
// 获取作品可用的优惠券
|
||||
getAvailableCoupons: (productTags: string, productPrice: number) => {
|
||||
getAvailableCoupons: (productTags: string, productPrice: number, shopId?: number) => {
|
||||
return request({
|
||||
url: '/coupon/available',
|
||||
method: 'get',
|
||||
params: { productTags, productPrice }
|
||||
params: { productTags, productPrice, shopId }
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
@@ -133,6 +133,7 @@ api.interceptors.response.use(
|
||||
const isWhitelistedPath = (url: string) => {
|
||||
return url?.includes('/user/login') ||
|
||||
url?.includes('/user/register') ||
|
||||
url?.includes('/user/check/') ||
|
||||
url?.includes('/user/refresh-token') ||
|
||||
url?.includes('/user/send-verification-code') ||
|
||||
url?.includes('/user/phone-login') ||
|
||||
|
||||
@@ -9,6 +9,7 @@ interface OrderItem {
|
||||
|
||||
interface CreateOrderRequest {
|
||||
couponId?: number
|
||||
couponSourceType?: string
|
||||
items: OrderItem[]
|
||||
}
|
||||
|
||||
|
||||
@@ -64,6 +64,12 @@ export interface AvailabilityCheckResponse {
|
||||
message: string
|
||||
}
|
||||
|
||||
export interface LoginAccountCheckResponse {
|
||||
exists: boolean
|
||||
nickname?: string
|
||||
message: string
|
||||
}
|
||||
|
||||
export interface UpdatePhoneRequest {
|
||||
oldPhone: string
|
||||
newPhone: string
|
||||
@@ -92,6 +98,9 @@ export const userApi = {
|
||||
checkAccountAvailability: (account: string) => {
|
||||
return api.get<AvailabilityCheckResponse>(`/user/check/account/${encodeURIComponent(account)}`)
|
||||
},
|
||||
checkLoginAccountAvailability: (account: string) => {
|
||||
return api.get<LoginAccountCheckResponse>(`/user/check/login-account/${encodeURIComponent(account)}`)
|
||||
},
|
||||
checkPhoneAvailability: (phone: string) => {
|
||||
return api.get<AvailabilityCheckResponse>(`/user/check/phone/${encodeURIComponent(phone)}`)
|
||||
},
|
||||
|
||||
+248
-126
@@ -7,15 +7,15 @@
|
||||
</div>
|
||||
|
||||
<div class="tab-container">
|
||||
<div
|
||||
class="tab-item"
|
||||
<div
|
||||
class="tab-item"
|
||||
:class="{ active: activeTab === 'login' }"
|
||||
@click="activeTab = 'login'"
|
||||
>
|
||||
登录
|
||||
</div>
|
||||
<div
|
||||
class="tab-item"
|
||||
<div
|
||||
class="tab-item"
|
||||
:class="{ active: activeTab === 'register' }"
|
||||
@click="activeTab = 'register'"
|
||||
>
|
||||
@@ -26,13 +26,13 @@
|
||||
<div v-if="activeTab === 'login'" class="login-type-toggle">
|
||||
<a-radio-group v-model:value="loginType" button-style="solid">
|
||||
<a-radio-button value="password">账号密码登录</a-radio-button>
|
||||
<a-radio-button value="phone">手机验证码登录</a-radio-button>
|
||||
<a-radio-button value="phone">手机号验证码登录</a-radio-button>
|
||||
</a-radio-group>
|
||||
</div>
|
||||
|
||||
<a-form
|
||||
:model="formData"
|
||||
:rules="rules"
|
||||
:rules="currentRules"
|
||||
@finish="handleSubmit"
|
||||
layout="vertical"
|
||||
class="auth-form"
|
||||
@@ -99,8 +99,8 @@
|
||||
<LockOutlined style="color: #999" />
|
||||
</template>
|
||||
<template #suffix>
|
||||
<a-button
|
||||
type="link"
|
||||
<a-button
|
||||
type="link"
|
||||
:disabled="countdown > 0 || !formData.phone"
|
||||
@click="handleSendVerificationCode"
|
||||
>
|
||||
@@ -110,7 +110,11 @@
|
||||
</a-input>
|
||||
</a-form-item>
|
||||
|
||||
<a-form-item name="account" label="账号" v-if="activeTab === 'login' && loginType === 'password'">
|
||||
<a-form-item
|
||||
v-if="activeTab === 'login' && loginType === 'password'"
|
||||
name="account"
|
||||
label="账号"
|
||||
>
|
||||
<a-input
|
||||
v-model:value="formData.account"
|
||||
placeholder="请输入账号"
|
||||
@@ -120,9 +124,20 @@
|
||||
<UserOutlined style="color: #999" />
|
||||
</template>
|
||||
</a-input>
|
||||
<div
|
||||
v-if="loginAccountStatus"
|
||||
class="field-status"
|
||||
:class="loginAccountStatus.exists ? 'success' : 'error'"
|
||||
>
|
||||
{{ loginAccountStatus.message }}
|
||||
</div>
|
||||
</a-form-item>
|
||||
|
||||
<a-form-item name="phone" label="手机号" v-if="activeTab === 'login' && loginType === 'phone'">
|
||||
<a-form-item
|
||||
v-if="activeTab === 'login' && loginType === 'phone'"
|
||||
name="phone"
|
||||
label="手机号"
|
||||
>
|
||||
<a-input
|
||||
v-model:value="formData.phone"
|
||||
placeholder="请输入手机号"
|
||||
@@ -138,7 +153,11 @@
|
||||
</div>
|
||||
</a-form-item>
|
||||
|
||||
<a-form-item name="verificationCode" label="验证码" v-if="activeTab === 'login' && loginType === 'phone'">
|
||||
<a-form-item
|
||||
v-if="activeTab === 'login' && loginType === 'phone'"
|
||||
name="verificationCode"
|
||||
label="验证码"
|
||||
>
|
||||
<a-input
|
||||
v-model:value="formData.verificationCode"
|
||||
placeholder="请输入验证码"
|
||||
@@ -148,8 +167,8 @@
|
||||
<LockOutlined style="color: #999" />
|
||||
</template>
|
||||
<template #suffix>
|
||||
<a-button
|
||||
type="link"
|
||||
<a-button
|
||||
type="link"
|
||||
:disabled="countdown > 0 || !formData.phone"
|
||||
@click="handleSendVerificationCode"
|
||||
>
|
||||
@@ -187,7 +206,11 @@
|
||||
</a-select>
|
||||
</a-form-item>
|
||||
|
||||
<a-form-item name="password" label="密码" v-if="activeTab === 'login' && loginType === 'password' || activeTab === 'register'">
|
||||
<a-form-item
|
||||
v-if="(activeTab === 'login' && loginType === 'password') || activeTab === 'register'"
|
||||
name="password"
|
||||
label="密码"
|
||||
>
|
||||
<a-input-password
|
||||
v-model:value="formData.password"
|
||||
placeholder="请输入密码"
|
||||
@@ -218,16 +241,16 @@
|
||||
size="large"
|
||||
:loading="loadingShops"
|
||||
>
|
||||
<a-select-option
|
||||
<a-select-option
|
||||
v-if="shops.length === 0"
|
||||
disabled
|
||||
value=""
|
||||
>
|
||||
暂无店铺数据
|
||||
</a-select-option>
|
||||
<a-select-option
|
||||
v-for="shop in shops"
|
||||
:key="shop.id"
|
||||
<a-select-option
|
||||
v-for="shop in shops"
|
||||
:key="shop.id"
|
||||
:value="shop.id"
|
||||
>
|
||||
{{ shop.shopName }}
|
||||
@@ -243,10 +266,10 @@
|
||||
</a-form-item>
|
||||
|
||||
<a-form-item>
|
||||
<a-button
|
||||
type="primary"
|
||||
html-type="submit"
|
||||
size="large"
|
||||
<a-button
|
||||
type="primary"
|
||||
html-type="submit"
|
||||
size="large"
|
||||
block
|
||||
:loading="loading"
|
||||
>
|
||||
@@ -274,9 +297,8 @@
|
||||
</a-form>
|
||||
</div>
|
||||
|
||||
<!-- 忘记密码弹窗 -->
|
||||
<a-modal
|
||||
v-model:visible="forgotPasswordVisible"
|
||||
v-model:open="forgotPasswordVisible"
|
||||
title="忘记密码"
|
||||
:footer="null"
|
||||
width="90%"
|
||||
@@ -310,8 +332,8 @@
|
||||
<LockOutlined style="color: #999" />
|
||||
</template>
|
||||
<template #suffix>
|
||||
<a-button
|
||||
type="link"
|
||||
<a-button
|
||||
type="link"
|
||||
:disabled="forgotCountdown > 0 || !forgotPasswordForm.phone"
|
||||
@click="handleSendForgotCode"
|
||||
>
|
||||
@@ -334,10 +356,10 @@
|
||||
</a-form-item>
|
||||
|
||||
<a-form-item>
|
||||
<a-button
|
||||
type="primary"
|
||||
html-type="submit"
|
||||
size="large"
|
||||
<a-button
|
||||
type="primary"
|
||||
html-type="submit"
|
||||
size="large"
|
||||
block
|
||||
:loading="resettingPassword"
|
||||
>
|
||||
@@ -356,14 +378,14 @@
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { ref, reactive, onMounted } from 'vue'
|
||||
import { computed, onBeforeUnmount, onMounted, reactive, ref, watch } from 'vue'
|
||||
import { useRouter } from 'vue-router'
|
||||
import { UserOutlined, LockOutlined, WechatOutlined, QqOutlined, InfoCircleOutlined } from '@ant-design/icons-vue'
|
||||
import { InfoCircleOutlined, LockOutlined, QqOutlined, UserOutlined, WechatOutlined } from '@ant-design/icons-vue'
|
||||
import { message } from 'ant-design-vue'
|
||||
import type { Rule } from 'ant-design-vue/es/form'
|
||||
import { authApi } from '@/api/auth'
|
||||
import { shopApi } from '@/api/shop'
|
||||
import { userApi, type AvailabilityCheckResponse } from '@/api/user'
|
||||
import { userApi, type AvailabilityCheckResponse, type LoginAccountCheckResponse } from '@/api/user'
|
||||
|
||||
const router = useRouter()
|
||||
|
||||
@@ -373,6 +395,7 @@ const loading = ref(false)
|
||||
const loadingShops = ref(false)
|
||||
const shops = ref<any[]>([])
|
||||
const countdown = ref(0)
|
||||
const loginAccountStatus = ref<LoginAccountCheckResponse | null>(null)
|
||||
const registerAccountStatus = ref<AvailabilityCheckResponse | null>(null)
|
||||
const registerPhoneStatus = ref<AvailabilityCheckResponse | null>(null)
|
||||
|
||||
@@ -397,22 +420,30 @@ const formData = reactive({
|
||||
rememberMe: false
|
||||
})
|
||||
|
||||
const validatePassword = async (_rule: any, value: string) => {
|
||||
if (value.length < 6) {
|
||||
return Promise.reject('密码长度不能少于6位')
|
||||
let loginAccountCheckTimer: number | undefined
|
||||
|
||||
const phoneRegex = /^1[3-9]\d{9}$/
|
||||
const verificationCodeRegex = /^\d{6}$/
|
||||
|
||||
const validatePassword = async (_rule: Rule, value: string) => {
|
||||
if (!value || value.length < 6) {
|
||||
return Promise.reject('密码长度不能少于 6 位')
|
||||
}
|
||||
|
||||
let count = 0
|
||||
if (/\d/.test(value)) count++
|
||||
if (/[a-z]/.test(value)) count++
|
||||
if (/[A-Z]/.test(value)) count++
|
||||
if (/[!@#$%^&*()_+\-=\[\]{};':"\\|,.<>\/?]/.test(value)) count++
|
||||
if (/[!@#$%^&*()_+\-=\[\]{};':"\\|,.<>/?]/.test(value)) count++
|
||||
|
||||
if (count < 3) {
|
||||
return Promise.reject('密码必须包含数字、小写字母、大写字母和符号中的至少3种')
|
||||
return Promise.reject('密码需至少包含数字、小写字母、大写字母、符号中的 3 种')
|
||||
}
|
||||
|
||||
return Promise.resolve()
|
||||
}
|
||||
|
||||
const validateConfirmPassword = async (_rule: any, value: string) => {
|
||||
const validateConfirmPassword = async (_rule: Rule, value: string) => {
|
||||
if (!value) {
|
||||
return Promise.reject('请确认密码')
|
||||
}
|
||||
@@ -422,17 +453,17 @@ const validateConfirmPassword = async (_rule: any, value: string) => {
|
||||
return Promise.resolve()
|
||||
}
|
||||
|
||||
const rules: Record<string, Rule[]> = {
|
||||
const registerRules: Record<string, Rule[]> = {
|
||||
account: [
|
||||
{ required: true, message: '请输入账号', trigger: 'blur' }
|
||||
],
|
||||
phone: [
|
||||
{ required: true, message: '请输入手机号', trigger: 'blur' },
|
||||
{ pattern: /^1[3-9]\d{9}$/, message: '手机号格式不正确', trigger: 'blur' }
|
||||
{ pattern: phoneRegex, message: '手机号格式不正确', trigger: 'blur' }
|
||||
],
|
||||
verificationCode: [
|
||||
{ required: true, message: '请输入验证码', trigger: 'blur' },
|
||||
{ pattern: /^\d{6}$/, message: '验证码必须是6位数字', trigger: 'blur' }
|
||||
{ pattern: verificationCodeRegex, message: '验证码必须为 6 位数字', trigger: 'blur' }
|
||||
],
|
||||
password: [
|
||||
{ required: true, message: '请输入密码', trigger: 'blur' },
|
||||
@@ -444,7 +475,7 @@ const rules: Record<string, Rule[]> = {
|
||||
],
|
||||
nickname: [
|
||||
{ required: true, message: '请输入昵称', trigger: 'blur' },
|
||||
{ min: 2, max: 20, message: '昵称长度在2到20个字符', trigger: 'blur' },
|
||||
{ min: 2, max: 20, message: '昵称长度需为 2 到 20 个字符', trigger: 'blur' },
|
||||
{ pattern: /^[\u4e00-\u9fa5a-zA-Z0-9_]+$/, message: '昵称不能包含特殊符号', trigger: 'blur' }
|
||||
],
|
||||
shopId: [
|
||||
@@ -452,20 +483,47 @@ const rules: Record<string, Rule[]> = {
|
||||
]
|
||||
}
|
||||
|
||||
const forgotPasswordRules: Record<string, Rule[]> = {
|
||||
const loginPasswordRules: Record<string, Rule[]> = {
|
||||
account: [
|
||||
{ required: true, message: '请输入账号', trigger: 'blur' }
|
||||
],
|
||||
password: [
|
||||
{ required: true, message: '请输入密码', trigger: 'blur' }
|
||||
]
|
||||
}
|
||||
|
||||
const loginPhoneRules: Record<string, Rule[]> = {
|
||||
phone: [
|
||||
{ required: true, message: '请输入手机号', trigger: 'blur' },
|
||||
{ pattern: /^1[3-9]\d{9}$/, message: '手机号格式不正确', trigger: 'blur' }
|
||||
{ pattern: phoneRegex, message: '手机号格式不正确', trigger: 'blur' }
|
||||
],
|
||||
verificationCode: [
|
||||
{ required: true, message: '请输入验证码', trigger: 'blur' },
|
||||
{ pattern: /^\d{6}$/, message: '验证码必须是6位数字', trigger: 'blur' }
|
||||
{ pattern: verificationCodeRegex, message: '验证码必须为 6 位数字', trigger: 'blur' }
|
||||
]
|
||||
}
|
||||
|
||||
const forgotPasswordRules: Record<string, Rule[]> = {
|
||||
phone: [
|
||||
{ required: true, message: '请输入手机号', trigger: 'blur' },
|
||||
{ pattern: phoneRegex, message: '手机号格式不正确', trigger: 'blur' }
|
||||
],
|
||||
verificationCode: [
|
||||
{ required: true, message: '请输入验证码', trigger: 'blur' },
|
||||
{ pattern: verificationCodeRegex, message: '验证码必须为 6 位数字', trigger: 'blur' }
|
||||
],
|
||||
newPassword: [
|
||||
{ required: true, message: '请输入新密码', trigger: 'blur' }
|
||||
]
|
||||
}
|
||||
|
||||
const currentRules = computed<Record<string, Rule[]>>(() => {
|
||||
if (activeTab.value === 'register') {
|
||||
return registerRules
|
||||
}
|
||||
return loginType.value === 'phone' ? loginPhoneRules : loginPasswordRules
|
||||
})
|
||||
|
||||
const fetchShops = async () => {
|
||||
loadingShops.value = true
|
||||
try {
|
||||
@@ -479,12 +537,76 @@ const fetchShops = async () => {
|
||||
}
|
||||
}
|
||||
|
||||
const resetLoginAccountStatus = () => {
|
||||
if (loginAccountCheckTimer !== undefined) {
|
||||
window.clearTimeout(loginAccountCheckTimer)
|
||||
loginAccountCheckTimer = undefined
|
||||
}
|
||||
loginAccountStatus.value = null
|
||||
}
|
||||
|
||||
const checkLoginAccountAvailability = async (account = formData.account) => {
|
||||
const trimmedAccount = account.trim()
|
||||
if (activeTab.value !== 'login' || loginType.value !== 'password' || !trimmedAccount) {
|
||||
loginAccountStatus.value = null
|
||||
return null
|
||||
}
|
||||
|
||||
try {
|
||||
const response = await userApi.checkLoginAccountAvailability(trimmedAccount) as unknown as LoginAccountCheckResponse
|
||||
if (
|
||||
activeTab.value === 'login'
|
||||
&& loginType.value === 'password'
|
||||
&& formData.account.trim() === trimmedAccount
|
||||
) {
|
||||
loginAccountStatus.value = response
|
||||
}
|
||||
return response
|
||||
} catch (error) {
|
||||
if (formData.account.trim() === trimmedAccount) {
|
||||
loginAccountStatus.value = null
|
||||
}
|
||||
console.error('登录账号检测失败:', error)
|
||||
return null
|
||||
}
|
||||
}
|
||||
|
||||
const checkRegisterAccountAvailability = async (showWarning = true) => {
|
||||
const trimmedAccount = formData.account.trim()
|
||||
if (activeTab.value !== 'register' || !trimmedAccount) {
|
||||
registerAccountStatus.value = null
|
||||
return false
|
||||
}
|
||||
|
||||
const response = await userApi.checkAccountAvailability(trimmedAccount) as unknown as AvailabilityCheckResponse
|
||||
registerAccountStatus.value = response
|
||||
if (showWarning && !response.available) {
|
||||
message.warning(response.message)
|
||||
}
|
||||
return response.available
|
||||
}
|
||||
|
||||
const checkRegisterPhoneAvailability = async (showWarning = true) => {
|
||||
const trimmedPhone = formData.phone.trim()
|
||||
if (activeTab.value !== 'register' || !trimmedPhone) {
|
||||
registerPhoneStatus.value = null
|
||||
return false
|
||||
}
|
||||
|
||||
const response = await userApi.checkPhoneAvailability(trimmedPhone) as unknown as AvailabilityCheckResponse
|
||||
registerPhoneStatus.value = response
|
||||
if (showWarning && !response.available) {
|
||||
message.warning(response.message)
|
||||
}
|
||||
return response.available
|
||||
}
|
||||
|
||||
const handleSubmit = async () => {
|
||||
loading.value = true
|
||||
try {
|
||||
if (activeTab.value === 'login') {
|
||||
let response
|
||||
|
||||
|
||||
if (loginType.value === 'phone') {
|
||||
response = await authApi.phoneLogin({
|
||||
phone: formData.phone,
|
||||
@@ -499,51 +621,58 @@ const handleSubmit = async () => {
|
||||
shopId: formData.shopId
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
const loginData = response as any
|
||||
|
||||
if (loginData.accessToken && loginData.refreshToken) {
|
||||
localStorage.setItem('accessToken', loginData.accessToken)
|
||||
localStorage.setItem('refreshToken', loginData.refreshToken)
|
||||
localStorage.setItem('userInfo', JSON.stringify(loginData.userInfo))
|
||||
if (loginData.needSetPassword) {
|
||||
localStorage.setItem('needSetPassword', 'true')
|
||||
} else {
|
||||
localStorage.removeItem('needSetPassword')
|
||||
}
|
||||
sessionStorage.setItem('accessToken', loginData.accessToken)
|
||||
|
||||
message.success('登录成功')
|
||||
router.push('/home').catch(err => {
|
||||
console.error('跳转到首页失败:', err)
|
||||
window.location.href = '/home'
|
||||
})
|
||||
} else {
|
||||
console.error('登录响应缺少token:', loginData)
|
||||
if (!loginData.accessToken || !loginData.refreshToken) {
|
||||
console.error('登录响应缺少 token:', loginData)
|
||||
message.error('登录失败:响应数据异常')
|
||||
}
|
||||
} else {
|
||||
const accountAvailable = await checkRegisterAccountAvailability(false)
|
||||
const phoneAvailable = await checkRegisterPhoneAvailability(false)
|
||||
if (!accountAvailable || !phoneAvailable) {
|
||||
message.error('请先处理注册信息中的占用问题')
|
||||
return
|
||||
}
|
||||
|
||||
await authApi.register({
|
||||
account: formData.account,
|
||||
password: formData.password,
|
||||
nickname: formData.nickname,
|
||||
phone: formData.phone,
|
||||
verificationCode: formData.verificationCode,
|
||||
shopId: formData.shopId!
|
||||
localStorage.setItem('accessToken', loginData.accessToken)
|
||||
localStorage.setItem('refreshToken', loginData.refreshToken)
|
||||
localStorage.setItem('userInfo', JSON.stringify(loginData.userInfo))
|
||||
sessionStorage.setItem('accessToken', loginData.accessToken)
|
||||
|
||||
if (loginData.needSetPassword) {
|
||||
localStorage.setItem('needSetPassword', 'true')
|
||||
} else {
|
||||
localStorage.removeItem('needSetPassword')
|
||||
}
|
||||
|
||||
message.success('登录成功')
|
||||
router.push('/home').catch(err => {
|
||||
console.error('跳转首页失败:', err)
|
||||
window.location.href = '/home'
|
||||
})
|
||||
|
||||
message.success('注册成功,请登录')
|
||||
activeTab.value = 'login'
|
||||
return
|
||||
}
|
||||
|
||||
const accountAvailable = await checkRegisterAccountAvailability(false)
|
||||
const phoneAvailable = await checkRegisterPhoneAvailability(false)
|
||||
if (!accountAvailable || !phoneAvailable) {
|
||||
message.error('请先处理注册信息中的占用问题')
|
||||
return
|
||||
}
|
||||
|
||||
await authApi.register({
|
||||
account: formData.account,
|
||||
password: formData.password,
|
||||
nickname: formData.nickname,
|
||||
phone: formData.phone,
|
||||
verificationCode: formData.verificationCode,
|
||||
shopId: formData.shopId!
|
||||
})
|
||||
|
||||
message.success('注册成功,请登录')
|
||||
activeTab.value = 'login'
|
||||
loginType.value = 'password'
|
||||
formData.password = ''
|
||||
formData.confirmPassword = ''
|
||||
formData.verificationCode = ''
|
||||
resetLoginAccountStatus()
|
||||
} catch (error: any) {
|
||||
console.error('登录失败:', error)
|
||||
console.error(activeTab.value === 'login' ? '登录失败:' : '注册失败:', error)
|
||||
message.error(error.message || (activeTab.value === 'login' ? '登录失败' : '注册失败'))
|
||||
} finally {
|
||||
loading.value = false
|
||||
@@ -559,8 +688,6 @@ const handleSendForgotCode = async () => {
|
||||
message.error('请输入手机号')
|
||||
return
|
||||
}
|
||||
|
||||
const phoneRegex = /^1[3-9]\d{9}$/
|
||||
if (!phoneRegex.test(forgotPasswordForm.phone)) {
|
||||
message.error('手机号格式不正确')
|
||||
return
|
||||
@@ -570,10 +697,10 @@ const handleSendForgotCode = async () => {
|
||||
await authApi.sendVerificationCode({ phone: forgotPasswordForm.phone })
|
||||
message.success('验证码已发送')
|
||||
forgotCountdown.value = 60
|
||||
const timer = setInterval(() => {
|
||||
const timer = window.setInterval(() => {
|
||||
forgotCountdown.value--
|
||||
if (forgotCountdown.value <= 0) {
|
||||
clearInterval(timer)
|
||||
window.clearInterval(timer)
|
||||
}
|
||||
}, 1000)
|
||||
} catch (error: any) {
|
||||
@@ -591,7 +718,6 @@ const handleResetPassword = async () => {
|
||||
})
|
||||
message.success('密码重置成功,请使用新密码登录')
|
||||
forgotPasswordVisible.value = false
|
||||
|
||||
forgotPasswordForm.phone = ''
|
||||
forgotPasswordForm.verificationCode = ''
|
||||
forgotPasswordForm.newPassword = ''
|
||||
@@ -607,35 +733,7 @@ const handleWeChatLogin = () => {
|
||||
}
|
||||
|
||||
const handleQQLogin = () => {
|
||||
message.info('QQ登录功能开发中')
|
||||
}
|
||||
|
||||
const checkRegisterAccountAvailability = async (showSuccessMessage = true) => {
|
||||
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
|
||||
message.info('QQ 登录功能开发中')
|
||||
}
|
||||
|
||||
const handleRegisterAccountBlur = async () => {
|
||||
@@ -657,8 +755,6 @@ const handleRegisterPhoneBlur = async () => {
|
||||
registerPhoneStatus.value = null
|
||||
return
|
||||
}
|
||||
|
||||
const phoneRegex = /^1[3-9]\d{9}$/
|
||||
if (!phoneRegex.test(formData.phone)) {
|
||||
registerPhoneStatus.value = null
|
||||
return
|
||||
@@ -677,8 +773,6 @@ const handleSendVerificationCode = async () => {
|
||||
message.error('请输入手机号')
|
||||
return
|
||||
}
|
||||
|
||||
const phoneRegex = /^1[3-9]\d{9}$/
|
||||
if (!phoneRegex.test(formData.phone)) {
|
||||
message.error('手机号格式不正确')
|
||||
return
|
||||
@@ -696,10 +790,10 @@ const handleSendVerificationCode = async () => {
|
||||
await userApi.sendVerificationCode({ phone: formData.phone })
|
||||
message.success('验证码已发送')
|
||||
countdown.value = 60
|
||||
const timer = setInterval(() => {
|
||||
const timer = window.setInterval(() => {
|
||||
countdown.value--
|
||||
if (countdown.value <= 0) {
|
||||
clearInterval(timer)
|
||||
window.clearInterval(timer)
|
||||
}
|
||||
}, 1000)
|
||||
} catch (error: any) {
|
||||
@@ -716,15 +810,43 @@ const handleAdminLogin = () => {
|
||||
localStorage.removeItem('adminUserInfo')
|
||||
sessionStorage.removeItem('accessToken')
|
||||
sessionStorage.removeItem('adminAccessToken')
|
||||
|
||||
setTimeout(() => {
|
||||
|
||||
window.setTimeout(() => {
|
||||
window.location.href = '/admin/login'
|
||||
}, 100)
|
||||
}
|
||||
|
||||
watch([activeTab, loginType], () => {
|
||||
resetLoginAccountStatus()
|
||||
})
|
||||
|
||||
watch(
|
||||
() => formData.account,
|
||||
value => {
|
||||
if (activeTab.value !== 'login' || loginType.value !== 'password') {
|
||||
return
|
||||
}
|
||||
|
||||
resetLoginAccountStatus()
|
||||
const trimmedAccount = value.trim()
|
||||
if (!trimmedAccount) {
|
||||
return
|
||||
}
|
||||
|
||||
loginAccountCheckTimer = window.setTimeout(() => {
|
||||
loginAccountCheckTimer = undefined
|
||||
void checkLoginAccountAvailability(trimmedAccount)
|
||||
}, 400)
|
||||
}
|
||||
)
|
||||
|
||||
onMounted(() => {
|
||||
fetchShops()
|
||||
})
|
||||
|
||||
onBeforeUnmount(() => {
|
||||
resetLoginAccountStatus()
|
||||
})
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
|
||||
+129
-32
@@ -56,10 +56,10 @@
|
||||
</div>
|
||||
</a-card>
|
||||
|
||||
<a-card v-if="selectedCount" class="coupon-card" @click="showCouponModal = true">
|
||||
<a-card v-if="selectedCount" class="coupon-card" @click="openCouponModal">
|
||||
<div class="coupon-row">
|
||||
<span>优惠券</span>
|
||||
<span>{{ selectedCoupon?.couponName || '使用优惠券' }}</span>
|
||||
<span>{{ selectedCoupon ? formatCouponDisplay(selectedCoupon) : '使用优惠券' }}</span>
|
||||
</div>
|
||||
<div v-if="selectedCoupon" class="coupon-discount">优惠金额 -¥{{ discountAmount.toFixed(2) }}</div>
|
||||
</a-card>
|
||||
@@ -79,12 +79,15 @@
|
||||
</footer>
|
||||
|
||||
<a-modal v-model:open="showCouponModal" title="使用优惠券" @ok="applyCouponSelection" @cancel="showCouponModal = false">
|
||||
<a-radio-group v-model:value="couponSelectionId" class="coupon-options">
|
||||
<a-radio :value="0">不使用优惠券</a-radio>
|
||||
<a-radio v-for="coupon in availableCoupons" :key="coupon.id" :value="coupon.id">
|
||||
{{ coupon.couponName }}
|
||||
<a-radio-group v-model:value="couponSelectionKey" class="coupon-options">
|
||||
<a-radio :value="NO_COUPON_KEY">不使用优惠券</a-radio>
|
||||
<a-radio v-for="coupon in availableCoupons" :key="getCouponKey(coupon)" :value="getCouponKey(coupon)">
|
||||
{{ formatCouponDisplay(coupon) }}
|
||||
</a-radio>
|
||||
</a-radio-group>
|
||||
<div class="coupon-tip">
|
||||
系统只会默认预选 VIP 自动券,普通用户券需要你手动选择后才会在下单时使用。
|
||||
</div>
|
||||
</a-modal>
|
||||
|
||||
<a-modal v-model:open="showBookingModal" :title="bookingTitle" @ok="confirmBooking" @cancel="closeBookingModal">
|
||||
@@ -131,6 +134,8 @@ import { userApi } from '../api/user'
|
||||
const router = useRouter()
|
||||
const updateCartCount = inject<() => Promise<void>>('updateCartCount', async () => {})
|
||||
|
||||
const NO_COUPON_KEY = 'NONE'
|
||||
|
||||
interface ArtistOption {
|
||||
id: number
|
||||
name: string
|
||||
@@ -161,7 +166,8 @@ const cartItems = ref<CartItem[]>([])
|
||||
const imageIdCache = ref<Record<string, string>>({})
|
||||
const availableCoupons = ref<UserCoupon[]>([])
|
||||
const selectedCoupon = ref<UserCoupon | null>(null)
|
||||
const couponSelectionId = ref(0)
|
||||
const couponSelectionKey = ref(NO_COUPON_KEY)
|
||||
const couponSelectionTouched = ref(false)
|
||||
const showCouponModal = ref(false)
|
||||
const showBookingModal = ref(false)
|
||||
const currentItem = ref<CartItem | null>(null)
|
||||
@@ -170,15 +176,11 @@ const draftArtistId = ref<number>()
|
||||
const draftAppointmentTime = ref('')
|
||||
const currentShopHours = ref('')
|
||||
|
||||
const selectedCount = computed(() => cartItems.value.filter(item => item.selected).length)
|
||||
const totalQuantity = computed(() => cartItems.value.filter(item => item.selected).reduce((sum, item) => sum + item.quantity, 0))
|
||||
const subtotal = computed(() => cartItems.value.filter(item => item.selected).reduce((sum, item) => sum + item.price * item.quantity, 0))
|
||||
const discountAmount = computed(() => {
|
||||
if (!selectedCoupon.value) return 0
|
||||
if (selectedCoupon.value.couponType === 1) return subtotal.value - subtotal.value * parseFloat(selectedCoupon.value.discountValue) / 10
|
||||
if (selectedCoupon.value.couponType === 2) return parseFloat(selectedCoupon.value.reduceAmount)
|
||||
return 0
|
||||
})
|
||||
const selectedItems = computed(() => cartItems.value.filter(item => item.selected))
|
||||
const selectedCount = computed(() => selectedItems.value.length)
|
||||
const totalQuantity = computed(() => selectedItems.value.reduce((sum, item) => sum + item.quantity, 0))
|
||||
const subtotal = computed(() => selectedItems.value.reduce((sum, item) => sum + item.price * item.quantity, 0))
|
||||
const discountAmount = computed(() => calculateCouponDiscount(selectedCoupon.value, subtotal.value))
|
||||
const totalAmount = computed(() => Math.max(0, subtotal.value - discountAmount.value))
|
||||
const bookingTitle = computed(() => currentItem.value ? '为 ' + currentItem.value.productTitle + ' 选择预约信息' : '选择预约信息')
|
||||
const bookingHelperText = computed(() => {
|
||||
@@ -204,6 +206,39 @@ const minAppointmentTime = computed(() => {
|
||||
].join('')
|
||||
})
|
||||
|
||||
const getCouponKey = (coupon: UserCoupon) => `${coupon.sourceType || 'USER_COUPON'}:${coupon.id}`
|
||||
|
||||
const calculateCouponDiscount = (coupon: UserCoupon | null, amount: number) => {
|
||||
if (!coupon || amount <= 0) {
|
||||
return 0
|
||||
}
|
||||
if (coupon.couponType === 1) {
|
||||
const discountValue = Number(coupon.discountValue || 0)
|
||||
if (!discountValue) {
|
||||
return 0
|
||||
}
|
||||
return amount - amount * discountValue / 10
|
||||
}
|
||||
if (coupon.couponType === 2) {
|
||||
return Number(coupon.reduceAmount || 0)
|
||||
}
|
||||
return 0
|
||||
}
|
||||
|
||||
const formatCouponDisplay = (coupon: UserCoupon) => {
|
||||
const badge = coupon.sourceType === 'SYSTEM_VIP' ? '[VIP 自动券]' : '[用户券]'
|
||||
const benefit = coupon.couponType === 1
|
||||
? `${coupon.discountValue}折`
|
||||
: `满${coupon.minAmount}减${coupon.reduceAmount}`
|
||||
return `${badge} ${coupon.couponName} ${benefit}`
|
||||
}
|
||||
|
||||
const findBestSystemVipCoupon = (coupons: UserCoupon[]) => {
|
||||
return coupons
|
||||
.filter(coupon => coupon.sourceType === 'SYSTEM_VIP')
|
||||
.sort((left, right) => calculateCouponDiscount(right, subtotal.value) - calculateCouponDiscount(left, subtotal.value))[0] || null
|
||||
}
|
||||
|
||||
const openProduct = (item: CartItem) => {
|
||||
router.push('/product/' + item.productId)
|
||||
}
|
||||
@@ -217,6 +252,9 @@ const loadCartItems = async () => {
|
||||
productImage: '',
|
||||
appointmentTime: item.appointmentTime
|
||||
}))
|
||||
couponSelectionTouched.value = false
|
||||
couponSelectionKey.value = NO_COUPON_KEY
|
||||
selectedCoupon.value = null
|
||||
await Promise.all([loadProductImages(), loadAvailableCoupons()])
|
||||
}
|
||||
|
||||
@@ -227,7 +265,9 @@ const loadProductImages = async () => {
|
||||
if (!match?.[1]) continue
|
||||
const imageId = match[1]
|
||||
try {
|
||||
if (!imageIdCache.value[imageId]) imageIdCache.value[imageId] = await fileApi.getSignedUrl(Number(imageId)) as any
|
||||
if (!imageIdCache.value[imageId]) {
|
||||
imageIdCache.value[imageId] = await fileApi.getSignedUrl(Number(imageId)) as any
|
||||
}
|
||||
item.productImage = imageIdCache.value[imageId] || ''
|
||||
} catch {
|
||||
item.productImage = ''
|
||||
@@ -236,17 +276,56 @@ const loadProductImages = async () => {
|
||||
}
|
||||
|
||||
const loadAvailableCoupons = async () => {
|
||||
try {
|
||||
const tags = new Set<string>()
|
||||
cartItems.value.filter(item => item.selected).forEach(item => item.tagNames?.split(',').map(tag => tag.trim()).forEach(tag => tag && tags.add(tag)))
|
||||
const data = subtotal.value > 0 ? await couponApi.getAvailableCoupons(Array.from(tags).join(','), subtotal.value) as unknown as any[] : []
|
||||
availableCoupons.value = data || []
|
||||
if (selectedCoupon.value && !availableCoupons.value.some(coupon => coupon.id === selectedCoupon.value?.id)) selectedCoupon.value = null
|
||||
couponSelectionId.value = selectedCoupon.value?.id || 0
|
||||
} catch {
|
||||
const currentSelectedKey = selectedCoupon.value ? getCouponKey(selectedCoupon.value) : couponSelectionKey.value
|
||||
const selectedShopId = selectedItems.value[0]?.shopId
|
||||
|
||||
if (!selectedItems.value.length || subtotal.value <= 0) {
|
||||
availableCoupons.value = []
|
||||
selectedCoupon.value = null
|
||||
couponSelectionId.value = 0
|
||||
couponSelectionKey.value = NO_COUPON_KEY
|
||||
return
|
||||
}
|
||||
|
||||
try {
|
||||
const tags = new Set<string>()
|
||||
selectedItems.value.forEach(item => {
|
||||
item.tagNames?.split(',').map(tag => tag.trim()).forEach(tag => {
|
||||
if (tag) {
|
||||
tags.add(tag)
|
||||
}
|
||||
})
|
||||
})
|
||||
|
||||
const data = await couponApi.getAvailableCoupons(Array.from(tags).join(','), subtotal.value, selectedShopId) as unknown as UserCoupon[]
|
||||
availableCoupons.value = Array.isArray(data) ? data : []
|
||||
|
||||
const matchedCoupon = availableCoupons.value.find(coupon => getCouponKey(coupon) === currentSelectedKey) || null
|
||||
if (matchedCoupon) {
|
||||
selectedCoupon.value = matchedCoupon
|
||||
couponSelectionKey.value = getCouponKey(matchedCoupon)
|
||||
return
|
||||
}
|
||||
|
||||
if (couponSelectionTouched.value && currentSelectedKey === NO_COUPON_KEY) {
|
||||
selectedCoupon.value = null
|
||||
couponSelectionKey.value = NO_COUPON_KEY
|
||||
return
|
||||
}
|
||||
|
||||
couponSelectionTouched.value = false
|
||||
const defaultVipCoupon = findBestSystemVipCoupon(availableCoupons.value)
|
||||
if (defaultVipCoupon) {
|
||||
selectedCoupon.value = defaultVipCoupon
|
||||
couponSelectionKey.value = getCouponKey(defaultVipCoupon)
|
||||
} else {
|
||||
selectedCoupon.value = null
|
||||
couponSelectionKey.value = NO_COUPON_KEY
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('获取可用优惠券失败:', error)
|
||||
availableCoupons.value = []
|
||||
selectedCoupon.value = null
|
||||
couponSelectionKey.value = NO_COUPON_KEY
|
||||
}
|
||||
}
|
||||
|
||||
@@ -334,13 +413,23 @@ const confirmBooking = () => {
|
||||
closeBookingModal()
|
||||
}
|
||||
|
||||
const openCouponModal = () => {
|
||||
couponSelectionKey.value = selectedCoupon.value ? getCouponKey(selectedCoupon.value) : NO_COUPON_KEY
|
||||
showCouponModal.value = true
|
||||
}
|
||||
|
||||
const applyCouponSelection = () => {
|
||||
selectedCoupon.value = availableCoupons.value.find(coupon => coupon.id === couponSelectionId.value) || null
|
||||
couponSelectionTouched.value = true
|
||||
if (couponSelectionKey.value === NO_COUPON_KEY) {
|
||||
selectedCoupon.value = null
|
||||
} else {
|
||||
selectedCoupon.value = availableCoupons.value.find(coupon => getCouponKey(coupon) === couponSelectionKey.value) || null
|
||||
}
|
||||
showCouponModal.value = false
|
||||
}
|
||||
|
||||
const checkout = async () => {
|
||||
const items = cartItems.value.filter(item => item.selected)
|
||||
const items = selectedItems.value
|
||||
if (!items.length) return message.warning('请先选择要结算的作品')
|
||||
if (items.some(item => !item.artistId)) return message.warning('请先为所有项目选择美甲师')
|
||||
if (items.some(item => !item.appointmentTime)) return message.warning('请先为所有项目选择预约时间')
|
||||
@@ -351,6 +440,7 @@ const checkout = async () => {
|
||||
try {
|
||||
await orderApi.createOrder({
|
||||
couponId: selectedCoupon.value?.id,
|
||||
couponSourceType: selectedCoupon.value?.sourceType || (couponSelectionTouched.value && !selectedCoupon.value ? NO_COUPON_KEY : undefined),
|
||||
items: items.map(item => ({
|
||||
productId: item.productId,
|
||||
quantity: item.quantity,
|
||||
@@ -361,12 +451,18 @@ const checkout = async () => {
|
||||
await Promise.all([loadCartItems(), updateCartCount()])
|
||||
message.success('订单创建成功')
|
||||
router.push('/orders')
|
||||
} catch {
|
||||
message.error('创建订单失败')
|
||||
} catch (error: any) {
|
||||
console.error('创建订单失败:', error)
|
||||
message.error(error?.message || '创建订单失败')
|
||||
}
|
||||
}
|
||||
|
||||
watch(() => cartItems.value.map(item => String(item.id) + '-' + item.selected + '-' + item.quantity), loadAvailableCoupons)
|
||||
watch(
|
||||
() => cartItems.value.map(item => `${item.id}-${item.selected}-${item.quantity}`).join('|'),
|
||||
() => {
|
||||
void loadAvailableCoupons()
|
||||
}
|
||||
)
|
||||
|
||||
onMounted(async () => {
|
||||
try {
|
||||
@@ -395,7 +491,8 @@ onMounted(async () => {
|
||||
.selector .value { flex: 1; color: #1890ff; font-size: 13px; }
|
||||
.actions, .qty, .coupon-row, .summary-row { display: flex; align-items: center; justify-content: space-between; }
|
||||
.qty { gap: 8px; }
|
||||
.duration, .coupon-discount, .helper { color: #666; font-size: 12px; }
|
||||
.duration, .coupon-discount, .helper, .coupon-tip { color: #666; font-size: 12px; }
|
||||
.coupon-tip { margin-top: 12px; line-height: 1.6; }
|
||||
.summary-row.total { font-weight: 700; }
|
||||
.footer { bottom: 60px; padding: 15px; border-top: 1px solid #f0f0f0; box-shadow: 0 -2px 8px rgba(0,0,0,.06); }
|
||||
.coupon-options { display: flex; flex-direction: column; gap: 8px; }
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -541,7 +541,7 @@ const fetchCoupons = async () => {
|
||||
try {
|
||||
const response = await adminCouponApi.listAllCoupons()
|
||||
const res = typeof response === 'object' && 'data' in response ? response.data : response
|
||||
coupons.value = res || []
|
||||
coupons.value = (res as any[]) || []
|
||||
} catch (error) {
|
||||
console.error('获取优惠券列表失败', error)
|
||||
message.error('获取优惠券列表失败')
|
||||
@@ -945,4 +945,4 @@ watch(() => formState.shopId, (newShopId) => {
|
||||
.product-images :deep(.ant-image) {
|
||||
border-radius: 4px;
|
||||
}
|
||||
</style>
|
||||
</style>
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
+68
@@ -2,11 +2,16 @@ package com.xiaowang.yuminailcore.controller;
|
||||
|
||||
import com.xiaowang.yuminailcore.annotation.RequirePermission;
|
||||
import com.xiaowang.yuminailcore.common.Result;
|
||||
import com.xiaowang.yuminailcore.dto.AdminUserBalanceChangeDTO;
|
||||
import com.xiaowang.yuminailcore.dto.AdminUserVipOverrideDTO;
|
||||
import com.xiaowang.yuminailcore.dto.UserDTO;
|
||||
import com.xiaowang.yuminailcore.entity.UserDO;
|
||||
import com.xiaowang.yuminailcore.service.UserAssetService;
|
||||
import com.xiaowang.yuminailcore.service.UserService;
|
||||
import com.xiaowang.yuminailcore.support.AdminScopeHelper;
|
||||
import com.xiaowang.yuminailcore.vo.BalanceChangeDetailVO;
|
||||
import com.xiaowang.yuminailcore.vo.PageResultVO;
|
||||
import com.xiaowang.yuminailcore.vo.UserAssetVO;
|
||||
import com.xiaowang.yuminailcore.vo.UserVO;
|
||||
import lombok.Data;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
@@ -22,6 +27,7 @@ import java.util.stream.Collectors;
|
||||
public class AdminUserController {
|
||||
|
||||
private final UserService userService;
|
||||
private final UserAssetService userAssetService;
|
||||
private final AdminScopeHelper adminScopeHelper;
|
||||
|
||||
@GetMapping("/list")
|
||||
@@ -111,6 +117,59 @@ public class AdminUserController {
|
||||
return Result.success(success);
|
||||
}
|
||||
|
||||
@GetMapping("/{id}/asset")
|
||||
@RequirePermission("user:balance:view")
|
||||
public Result<UserAssetVO> getUserAsset(HttpServletRequest request, @PathVariable Long id) {
|
||||
UserDO currentUser = adminScopeHelper.getCurrentUser(request);
|
||||
UserVO targetUser = requireAccessibleUser(currentUser, id, "无权查看其他店铺用户资产");
|
||||
UserAssetVO assetVO = userAssetService.getUserAsset(targetUser.getId());
|
||||
return Result.success(assetVO);
|
||||
}
|
||||
|
||||
@GetMapping("/{id}/balance/history")
|
||||
@RequirePermission("user:balance:view")
|
||||
public Result<List<BalanceChangeDetailVO>> getUserBalanceHistory(HttpServletRequest request, @PathVariable Long id) {
|
||||
UserDO currentUser = adminScopeHelper.getCurrentUser(request);
|
||||
UserVO targetUser = requireAccessibleUser(currentUser, id, "无权查看其他店铺用户余额流水");
|
||||
List<BalanceChangeDetailVO> history = userAssetService.listBalanceHistory(targetUser.getId());
|
||||
return Result.success(history);
|
||||
}
|
||||
|
||||
@PostMapping("/{id}/balance/change")
|
||||
@RequirePermission("user:balance:manage")
|
||||
public Result<UserAssetVO> changeUserBalance(
|
||||
HttpServletRequest request,
|
||||
@PathVariable Long id,
|
||||
@RequestBody AdminUserBalanceChangeDTO balanceChangeDTO
|
||||
) {
|
||||
UserDO currentUser = adminScopeHelper.getCurrentUser(request);
|
||||
UserVO targetUser = requireAccessibleUser(currentUser, id, "无权调整其他店铺用户余额");
|
||||
UserAssetVO assetVO = userAssetService.changeBalance(currentUser.getId(), targetUser.getId(), balanceChangeDTO);
|
||||
return Result.success(assetVO);
|
||||
}
|
||||
|
||||
@PostMapping("/{id}/vip/override")
|
||||
@RequirePermission("user:vip:manage")
|
||||
public Result<UserAssetVO> overrideUserVip(
|
||||
HttpServletRequest request,
|
||||
@PathVariable Long id,
|
||||
@RequestBody AdminUserVipOverrideDTO vipOverrideDTO
|
||||
) {
|
||||
UserDO currentUser = adminScopeHelper.getCurrentUser(request);
|
||||
UserVO targetUser = requireAccessibleUser(currentUser, id, "无权调整其他店铺用户 VIP");
|
||||
UserAssetVO assetVO = userAssetService.overrideVip(currentUser.getId(), targetUser.getId(), vipOverrideDTO);
|
||||
return Result.success(assetVO);
|
||||
}
|
||||
|
||||
@PostMapping("/{id}/vip/recalculate")
|
||||
@RequirePermission("user:vip:manage")
|
||||
public Result<UserAssetVO> recalculateUserVip(HttpServletRequest request, @PathVariable Long id) {
|
||||
UserDO currentUser = adminScopeHelper.getCurrentUser(request);
|
||||
UserVO targetUser = requireAccessibleUser(currentUser, id, "无权重算其他店铺用户 VIP");
|
||||
UserAssetVO assetVO = userAssetService.recalculateVip(currentUser.getId(), targetUser.getId());
|
||||
return Result.success(assetVO);
|
||||
}
|
||||
|
||||
@GetMapping("/info")
|
||||
public Result<UserVO> getUserInfo(HttpServletRequest request) {
|
||||
Long userId = (Long) request.getAttribute("userId");
|
||||
@@ -154,6 +213,15 @@ public class AdminUserController {
|
||||
return Result.success(artists);
|
||||
}
|
||||
|
||||
private UserVO requireAccessibleUser(UserDO currentUser, Long userId, String message) {
|
||||
UserVO targetUser = userService.getUserById(userId);
|
||||
if (targetUser == null) {
|
||||
throw new RuntimeException("目标用户不存在");
|
||||
}
|
||||
adminScopeHelper.ensureShopAccessible(currentUser, targetUser.getShopId(), message);
|
||||
return targetUser;
|
||||
}
|
||||
|
||||
@Data
|
||||
public static class StatusRequest {
|
||||
private Integer status;
|
||||
|
||||
+7
-2
@@ -104,8 +104,13 @@ public class CouponController {
|
||||
* 获取商品可用的优惠券
|
||||
*/
|
||||
@GetMapping("/available")
|
||||
public Result<List<UserCouponVO>> getAvailableCoupons(@RequestParam String productTags, @RequestParam Double productPrice, @RequestAttribute("userId") Long userId) {
|
||||
List<UserCouponVO> availableCoupons = couponService.getAvailableCoupons(userId, productTags, productPrice);
|
||||
public Result<List<UserCouponVO>> getAvailableCoupons(
|
||||
@RequestParam(required = false, defaultValue = "") String productTags,
|
||||
@RequestParam Double productPrice,
|
||||
@RequestParam(required = false) Long shopId,
|
||||
@RequestAttribute("userId") Long userId
|
||||
) {
|
||||
List<UserCouponVO> availableCoupons = couponService.getAvailableCoupons(userId, productTags, productPrice, shopId);
|
||||
return Result.success(availableCoupons);
|
||||
}
|
||||
|
||||
|
||||
+1
-1
@@ -26,7 +26,7 @@ public class ProductController {
|
||||
}
|
||||
|
||||
@PutMapping("/update/{id}")
|
||||
@RequirePermission("product:update")
|
||||
@RequirePermission("product:edit")
|
||||
public Result<Boolean> updateProduct(@PathVariable Long id, @RequestBody ProductDTO productDTO) {
|
||||
boolean success = productService.updateProduct(id, productDTO);
|
||||
return Result.success(success);
|
||||
|
||||
+1
-1
@@ -27,7 +27,7 @@ public class ShopController {
|
||||
}
|
||||
|
||||
@PutMapping("/update/{id}")
|
||||
@RequirePermission("shop:update")
|
||||
@RequirePermission("shop:edit")
|
||||
public Result<Boolean> updateShop(@PathVariable Long id, @RequestBody ShopDTO shopDTO) {
|
||||
boolean success = shopService.updateShop(id, shopDTO);
|
||||
return Result.success(success);
|
||||
|
||||
@@ -150,6 +150,22 @@ public class UserController {
|
||||
return Result.success(new AvailabilityVO(available, message));
|
||||
}
|
||||
|
||||
@GetMapping("/check/login-account/{account}")
|
||||
public Result<LoginAccountAvailabilityVO> checkLoginAccountAvailability(@PathVariable String account) {
|
||||
UserDO userDO = userMapper.selectOne(
|
||||
com.baomidou.mybatisplus.core.toolkit.Wrappers.lambdaQuery(UserDO.class)
|
||||
.eq(UserDO::getAccount, account)
|
||||
.eq(UserDO::getIsDelete, 0)
|
||||
.last("limit 1")
|
||||
);
|
||||
boolean exists = userDO != null;
|
||||
String nickname = exists ? userDO.getNickname() : null;
|
||||
String message = exists
|
||||
? (nickname != null && !nickname.isEmpty() ? "找到账号,登录后将进入:" + nickname : "账号已注册")
|
||||
: "该账号未注册";
|
||||
return Result.success(new LoginAccountAvailabilityVO(exists, nickname, message));
|
||||
}
|
||||
|
||||
@GetMapping("/check/phone/{phone}")
|
||||
public Result<AvailabilityVO> checkPhoneAvailability(@PathVariable String phone) {
|
||||
UserDO userDO = userMapper.selectOne(
|
||||
@@ -416,4 +432,11 @@ public class UserController {
|
||||
private final boolean available;
|
||||
private final String message;
|
||||
}
|
||||
|
||||
@Data
|
||||
public static class LoginAccountAvailabilityVO {
|
||||
private final boolean exists;
|
||||
private final String nickname;
|
||||
private final String message;
|
||||
}
|
||||
}
|
||||
|
||||
+19
@@ -0,0 +1,19 @@
|
||||
package com.xiaowang.yuminailcore.dto;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
|
||||
@Data
|
||||
public class AdminUserBalanceChangeDTO {
|
||||
|
||||
private BigDecimal amount;
|
||||
|
||||
private String changeScene;
|
||||
|
||||
private Long relatedOrderId;
|
||||
|
||||
private String externalOrderNo;
|
||||
|
||||
private String remark;
|
||||
}
|
||||
+11
@@ -0,0 +1,11 @@
|
||||
package com.xiaowang.yuminailcore.dto;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class AdminUserVipOverrideDTO {
|
||||
|
||||
private String vipLevel;
|
||||
|
||||
private String remark;
|
||||
}
|
||||
@@ -34,6 +34,14 @@ public class BalanceChangeDetailDTO {
|
||||
* 变动后的当前余额
|
||||
*/
|
||||
private BigDecimal currentBalance;
|
||||
private BigDecimal beforeBalance;
|
||||
private BigDecimal afterBalance;
|
||||
private String changeScene;
|
||||
private Long relatedOrderId;
|
||||
private String relatedOrderNo;
|
||||
private String externalOrderNo;
|
||||
private Long operatorId;
|
||||
private String remark;
|
||||
|
||||
/**
|
||||
* 变动时间
|
||||
|
||||
@@ -3,6 +3,7 @@ package com.xiaowang.yuminailcore.dto;
|
||||
import lombok.Data;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
/**
|
||||
* 用户余额信息表 DTO
|
||||
@@ -23,4 +24,6 @@ public class BalanceDTO {
|
||||
* 当前余额
|
||||
*/
|
||||
private BigDecimal amount;
|
||||
private BigDecimal totalRechargeAmount;
|
||||
private LocalDateTime lastRechargeTime;
|
||||
}
|
||||
|
||||
@@ -61,6 +61,9 @@ public class CouponDTO {
|
||||
* 所属店铺ID
|
||||
*/
|
||||
private Long shopId;
|
||||
private String couponScene;
|
||||
private String requiredVipLevel;
|
||||
private Integer autoMatch;
|
||||
|
||||
/**
|
||||
* 可用标签ID列表
|
||||
|
||||
@@ -18,6 +18,7 @@ public class OrderDTO {
|
||||
* 优惠券ID
|
||||
*/
|
||||
private Long couponId;
|
||||
private String couponSourceType;
|
||||
|
||||
/**
|
||||
* 订单商品列表
|
||||
|
||||
@@ -2,6 +2,8 @@ package com.xiaowang.yuminailcore.dto;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
|
||||
/**
|
||||
* VIP权益信息表 DTO
|
||||
* 用于VIP权益信息的传输
|
||||
@@ -21,4 +23,7 @@ public class VipBenefitDTO {
|
||||
* 所需VIP等级
|
||||
*/
|
||||
private String requiredVipLevel;
|
||||
private Integer levelRank;
|
||||
private BigDecimal rechargeThreshold;
|
||||
private Integer status;
|
||||
}
|
||||
|
||||
@@ -14,6 +14,8 @@ import java.time.LocalDateTime;
|
||||
@Data
|
||||
public class VipInfoDTO {
|
||||
|
||||
private Long userId;
|
||||
|
||||
/**
|
||||
* VIP等级(如青铜、白银)
|
||||
*/
|
||||
@@ -38,4 +40,5 @@ public class VipInfoDTO {
|
||||
* 关联VIP权益信息表主键
|
||||
*/
|
||||
private Long benefitId;
|
||||
private Integer manualOverride;
|
||||
}
|
||||
|
||||
+24
@@ -47,6 +47,30 @@ public class BalanceChangeDetailDO extends BaseEntity {
|
||||
/**
|
||||
* 变动时间
|
||||
*/
|
||||
@TableField("before_balance")
|
||||
private BigDecimal beforeBalance;
|
||||
|
||||
@TableField("after_balance")
|
||||
private BigDecimal afterBalance;
|
||||
|
||||
@TableField("change_scene")
|
||||
private String changeScene;
|
||||
|
||||
@TableField("related_order_id")
|
||||
private Long relatedOrderId;
|
||||
|
||||
@TableField("related_order_no")
|
||||
private String relatedOrderNo;
|
||||
|
||||
@TableField("external_order_no")
|
||||
private String externalOrderNo;
|
||||
|
||||
@TableField("operator_id")
|
||||
private Long operatorId;
|
||||
|
||||
@TableField("remark")
|
||||
private String remark;
|
||||
|
||||
@TableField("change_time")
|
||||
private LocalDateTime changeTime;
|
||||
}
|
||||
|
||||
@@ -35,6 +35,12 @@ public class BalanceDO extends BaseEntity {
|
||||
/**
|
||||
* 最近一次更新时间
|
||||
*/
|
||||
@TableField("total_recharge_amount")
|
||||
private BigDecimal totalRechargeAmount;
|
||||
|
||||
@TableField("last_recharge_time")
|
||||
private LocalDateTime lastRechargeTime;
|
||||
|
||||
@TableField("last_update_time")
|
||||
private LocalDateTime lastUpdateTime;
|
||||
}
|
||||
|
||||
@@ -76,6 +76,12 @@ public class CouponDO extends BaseEntity {
|
||||
* 所属店铺ID
|
||||
*/
|
||||
private Long shopId;
|
||||
|
||||
private String couponScene;
|
||||
|
||||
private String requiredVipLevel;
|
||||
|
||||
private Integer autoMatch;
|
||||
|
||||
/**
|
||||
* 逻辑删除:0-未删,1-已删
|
||||
|
||||
@@ -15,8 +15,10 @@ public class OrderDO extends BaseEntity {
|
||||
private BigDecimal totalAmount;
|
||||
private BigDecimal actualAmount;
|
||||
private Long couponId;
|
||||
private Long userCouponId;
|
||||
private String couponSourceType;
|
||||
private Integer status;
|
||||
private LocalDateTime createTime;
|
||||
private LocalDateTime updateTime;
|
||||
private Integer isDelete;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -28,4 +28,13 @@ public class VipBenefitDO extends BaseEntity {
|
||||
*/
|
||||
@TableField("required_vip_level")
|
||||
private String requiredVipLevel;
|
||||
|
||||
@TableField("level_rank")
|
||||
private Integer levelRank;
|
||||
|
||||
@TableField("recharge_threshold")
|
||||
private java.math.BigDecimal rechargeThreshold;
|
||||
|
||||
@TableField("status")
|
||||
private Integer status;
|
||||
}
|
||||
|
||||
@@ -19,6 +19,9 @@ import java.time.LocalDateTime;
|
||||
@TableName("t_vip_info")
|
||||
public class VipInfoDO extends BaseEntity {
|
||||
|
||||
@TableField("user_id")
|
||||
private Long userId;
|
||||
|
||||
/**
|
||||
* VIP等级(如青铜、白银)
|
||||
*/
|
||||
@@ -48,4 +51,7 @@ public class VipInfoDO extends BaseEntity {
|
||||
*/
|
||||
@TableField("benefit_id")
|
||||
private Long benefitId;
|
||||
|
||||
@TableField("manual_override")
|
||||
private Integer manualOverride;
|
||||
}
|
||||
|
||||
@@ -93,7 +93,7 @@ public interface CouponService extends IService<CouponDO> {
|
||||
* @param productPrice 商品价格
|
||||
* @return 可用优惠券列表
|
||||
*/
|
||||
List<UserCouponVO> getAvailableCoupons(Long userId, String productTags, Double productPrice);
|
||||
List<UserCouponVO> getAvailableCoupons(Long userId, String productTags, Double productPrice, Long shopId);
|
||||
|
||||
/**
|
||||
* 发放优惠券
|
||||
|
||||
@@ -0,0 +1,21 @@
|
||||
package com.xiaowang.yuminailcore.service;
|
||||
|
||||
import com.xiaowang.yuminailcore.dto.AdminUserBalanceChangeDTO;
|
||||
import com.xiaowang.yuminailcore.dto.AdminUserVipOverrideDTO;
|
||||
import com.xiaowang.yuminailcore.vo.BalanceChangeDetailVO;
|
||||
import com.xiaowang.yuminailcore.vo.UserAssetVO;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface UserAssetService {
|
||||
|
||||
UserAssetVO getUserAsset(Long userId);
|
||||
|
||||
List<BalanceChangeDetailVO> listBalanceHistory(Long userId);
|
||||
|
||||
UserAssetVO changeBalance(Long operatorId, Long userId, AdminUserBalanceChangeDTO request);
|
||||
|
||||
UserAssetVO overrideVip(Long operatorId, Long userId, AdminUserVipOverrideDTO request);
|
||||
|
||||
UserAssetVO recalculateVip(Long operatorId, Long userId);
|
||||
}
|
||||
+24
@@ -33,6 +33,14 @@ public class BalanceChangeDetailServiceImpl extends ServiceImpl<BalanceChangeDet
|
||||
balanceChangeDetailDO.setAmount(balanceChangeDetailDTO.getAmount());
|
||||
balanceChangeDetailDO.setType(balanceChangeDetailDTO.getType());
|
||||
balanceChangeDetailDO.setCurrentBalance(balanceChangeDetailDTO.getCurrentBalance());
|
||||
balanceChangeDetailDO.setBeforeBalance(balanceChangeDetailDTO.getBeforeBalance());
|
||||
balanceChangeDetailDO.setAfterBalance(balanceChangeDetailDTO.getAfterBalance());
|
||||
balanceChangeDetailDO.setChangeScene(balanceChangeDetailDTO.getChangeScene());
|
||||
balanceChangeDetailDO.setRelatedOrderId(balanceChangeDetailDTO.getRelatedOrderId());
|
||||
balanceChangeDetailDO.setRelatedOrderNo(balanceChangeDetailDTO.getRelatedOrderNo());
|
||||
balanceChangeDetailDO.setExternalOrderNo(balanceChangeDetailDTO.getExternalOrderNo());
|
||||
balanceChangeDetailDO.setOperatorId(balanceChangeDetailDTO.getOperatorId());
|
||||
balanceChangeDetailDO.setRemark(balanceChangeDetailDTO.getRemark());
|
||||
balanceChangeDetailDO.setChangeTime(balanceChangeDetailDTO.getChangeTime());
|
||||
balanceChangeDetailMapper.insert(balanceChangeDetailDO);
|
||||
return balanceChangeDetailDO.getId();
|
||||
@@ -48,6 +56,14 @@ public class BalanceChangeDetailServiceImpl extends ServiceImpl<BalanceChangeDet
|
||||
balanceChangeDetailDO.setAmount(balanceChangeDetailDTO.getAmount());
|
||||
balanceChangeDetailDO.setType(balanceChangeDetailDTO.getType());
|
||||
balanceChangeDetailDO.setCurrentBalance(balanceChangeDetailDTO.getCurrentBalance());
|
||||
balanceChangeDetailDO.setBeforeBalance(balanceChangeDetailDTO.getBeforeBalance());
|
||||
balanceChangeDetailDO.setAfterBalance(balanceChangeDetailDTO.getAfterBalance());
|
||||
balanceChangeDetailDO.setChangeScene(balanceChangeDetailDTO.getChangeScene());
|
||||
balanceChangeDetailDO.setRelatedOrderId(balanceChangeDetailDTO.getRelatedOrderId());
|
||||
balanceChangeDetailDO.setRelatedOrderNo(balanceChangeDetailDTO.getRelatedOrderNo());
|
||||
balanceChangeDetailDO.setExternalOrderNo(balanceChangeDetailDTO.getExternalOrderNo());
|
||||
balanceChangeDetailDO.setOperatorId(balanceChangeDetailDTO.getOperatorId());
|
||||
balanceChangeDetailDO.setRemark(balanceChangeDetailDTO.getRemark());
|
||||
balanceChangeDetailDO.setChangeTime(balanceChangeDetailDTO.getChangeTime());
|
||||
return balanceChangeDetailMapper.updateById(balanceChangeDetailDO) > 0;
|
||||
}
|
||||
@@ -98,6 +114,14 @@ public class BalanceChangeDetailServiceImpl extends ServiceImpl<BalanceChangeDet
|
||||
balanceChangeDetailVO.setAmount(balanceChangeDetailDO.getAmount());
|
||||
balanceChangeDetailVO.setType(balanceChangeDetailDO.getType());
|
||||
balanceChangeDetailVO.setCurrentBalance(balanceChangeDetailDO.getCurrentBalance());
|
||||
balanceChangeDetailVO.setBeforeBalance(balanceChangeDetailDO.getBeforeBalance());
|
||||
balanceChangeDetailVO.setAfterBalance(balanceChangeDetailDO.getAfterBalance());
|
||||
balanceChangeDetailVO.setChangeScene(balanceChangeDetailDO.getChangeScene());
|
||||
balanceChangeDetailVO.setRelatedOrderId(balanceChangeDetailDO.getRelatedOrderId());
|
||||
balanceChangeDetailVO.setRelatedOrderNo(balanceChangeDetailDO.getRelatedOrderNo());
|
||||
balanceChangeDetailVO.setExternalOrderNo(balanceChangeDetailDO.getExternalOrderNo());
|
||||
balanceChangeDetailVO.setOperatorId(balanceChangeDetailDO.getOperatorId());
|
||||
balanceChangeDetailVO.setRemark(balanceChangeDetailDO.getRemark());
|
||||
balanceChangeDetailVO.setChangeTime(balanceChangeDetailDO.getChangeTime());
|
||||
return balanceChangeDetailVO;
|
||||
}
|
||||
|
||||
+6
@@ -32,6 +32,8 @@ public class BalanceServiceImpl extends ServiceImpl<BalanceMapper, BalanceDO> im
|
||||
BalanceDO balanceDO = new BalanceDO();
|
||||
balanceDO.setUserId(balanceDTO.getUserId());
|
||||
balanceDO.setAmount(balanceDTO.getAmount());
|
||||
balanceDO.setTotalRechargeAmount(balanceDTO.getTotalRechargeAmount());
|
||||
balanceDO.setLastRechargeTime(balanceDTO.getLastRechargeTime());
|
||||
balanceDO.setLastUpdateTime(LocalDateTime.now());
|
||||
balanceMapper.insert(balanceDO);
|
||||
return balanceDO.getId();
|
||||
@@ -45,6 +47,8 @@ public class BalanceServiceImpl extends ServiceImpl<BalanceMapper, BalanceDO> im
|
||||
}
|
||||
balanceDO.setUserId(balanceDTO.getUserId());
|
||||
balanceDO.setAmount(balanceDTO.getAmount());
|
||||
balanceDO.setTotalRechargeAmount(balanceDTO.getTotalRechargeAmount());
|
||||
balanceDO.setLastRechargeTime(balanceDTO.getLastRechargeTime());
|
||||
balanceDO.setLastUpdateTime(LocalDateTime.now());
|
||||
return balanceMapper.updateById(balanceDO) > 0;
|
||||
}
|
||||
@@ -94,6 +98,8 @@ public class BalanceServiceImpl extends ServiceImpl<BalanceMapper, BalanceDO> im
|
||||
balanceVO.setId(balanceDO.getId());
|
||||
balanceVO.setUserId(balanceDO.getUserId());
|
||||
balanceVO.setAmount(balanceDO.getAmount());
|
||||
balanceVO.setTotalRechargeAmount(balanceDO.getTotalRechargeAmount());
|
||||
balanceVO.setLastRechargeTime(balanceDO.getLastRechargeTime());
|
||||
balanceVO.setCreateTime(balanceDO.getCreateTime());
|
||||
balanceVO.setLastUpdateTime(balanceDO.getLastUpdateTime());
|
||||
return balanceVO;
|
||||
|
||||
+145
-52
@@ -8,11 +8,13 @@ import com.xiaowang.yuminailcore.dto.CouponDTO;
|
||||
import com.xiaowang.yuminailcore.entity.CouponDO;
|
||||
import com.xiaowang.yuminailcore.entity.CouponTagDO;
|
||||
import com.xiaowang.yuminailcore.entity.TagDO;
|
||||
import com.xiaowang.yuminailcore.entity.UserDO;
|
||||
import com.xiaowang.yuminailcore.entity.UserCouponDO;
|
||||
import com.xiaowang.yuminailcore.mapper.CouponMapper;
|
||||
import com.xiaowang.yuminailcore.mapper.CouponTagMapper;
|
||||
import com.xiaowang.yuminailcore.mapper.ShopMapper;
|
||||
import com.xiaowang.yuminailcore.mapper.TagMapper;
|
||||
import com.xiaowang.yuminailcore.mapper.UserMapper;
|
||||
import com.xiaowang.yuminailcore.mapper.UserCouponMapper;
|
||||
import com.xiaowang.yuminailcore.service.CouponService;
|
||||
import com.xiaowang.yuminailcore.vo.CouponVO;
|
||||
@@ -26,6 +28,7 @@ import org.springframework.transaction.annotation.Transactional;
|
||||
import java.math.BigDecimal;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@@ -35,11 +38,17 @@ import java.util.stream.Collectors;
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
public class CouponServiceImpl extends ServiceImpl<CouponMapper, CouponDO> implements CouponService {
|
||||
|
||||
private static final String COUPON_SOURCE_USER = "USER_COUPON";
|
||||
private static final String COUPON_SOURCE_SYSTEM_VIP = "SYSTEM_VIP";
|
||||
private static final String COUPON_SCENE_VIP_AUTO = "VIP_AUTO";
|
||||
private static final String VIP_LEVEL_NORMAL = "普通";
|
||||
|
||||
private final CouponTagMapper couponTagMapper;
|
||||
private final UserCouponMapper userCouponMapper;
|
||||
private final TagMapper tagMapper;
|
||||
private final ShopMapper shopMapper;
|
||||
private final UserMapper userMapper;
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
@@ -58,6 +67,9 @@ public class CouponServiceImpl extends ServiceImpl<CouponMapper, CouponDO> imple
|
||||
couponDO.setEndTime(couponDTO.getEndTime());
|
||||
couponDO.setStatus(1);
|
||||
couponDO.setShopId(shopId);
|
||||
couponDO.setCouponScene(couponDTO.getCouponScene());
|
||||
couponDO.setRequiredVipLevel(couponDTO.getRequiredVipLevel());
|
||||
couponDO.setAutoMatch(couponDTO.getAutoMatch());
|
||||
save(couponDO);
|
||||
|
||||
// 处理标签关联
|
||||
@@ -85,6 +97,9 @@ public class CouponServiceImpl extends ServiceImpl<CouponMapper, CouponDO> imple
|
||||
couponDO.setStartTime(couponDTO.getStartTime());
|
||||
couponDO.setEndTime(couponDTO.getEndTime());
|
||||
couponDO.setShopId(shopId);
|
||||
couponDO.setCouponScene(couponDTO.getCouponScene());
|
||||
couponDO.setRequiredVipLevel(couponDTO.getRequiredVipLevel());
|
||||
couponDO.setAutoMatch(couponDTO.getAutoMatch());
|
||||
updateById(couponDO);
|
||||
|
||||
// 处理标签关联
|
||||
@@ -117,10 +132,13 @@ public class CouponServiceImpl extends ServiceImpl<CouponMapper, CouponDO> imple
|
||||
@Override
|
||||
public PageResultVO<CouponVO> listCoupons(Integer page, Integer size, Long shopId) {
|
||||
Page<CouponDO> pageInfo = new Page<>(page, size);
|
||||
IPage<CouponDO> couponPage = page(pageInfo, new LambdaQueryWrapper<CouponDO>()
|
||||
LambdaQueryWrapper<CouponDO> wrapper = new LambdaQueryWrapper<CouponDO>()
|
||||
.eq(CouponDO::getIsDelete, 0)
|
||||
.orderByDesc(CouponDO::getCreateTime)
|
||||
);
|
||||
.orderByDesc(CouponDO::getCreateTime);
|
||||
if (shopId != null) {
|
||||
wrapper.eq(CouponDO::getShopId, shopId);
|
||||
}
|
||||
IPage<CouponDO> couponPage = page(pageInfo, wrapper);
|
||||
|
||||
List<CouponVO> couponVOs = couponPage.getRecords().stream()
|
||||
.map(this::convertToCouponVO)
|
||||
@@ -159,6 +177,9 @@ public class CouponServiceImpl extends ServiceImpl<CouponMapper, CouponDO> imple
|
||||
if (couponDO.getStatus() != 1) {
|
||||
return false;
|
||||
}
|
||||
if (isVipAutoCoupon(couponDO)) {
|
||||
throw new RuntimeException("VIP 自动券为系统模板券,不支持手动发放");
|
||||
}
|
||||
|
||||
// 检查是否已经分配
|
||||
UserCouponDO existing = userCouponMapper.selectOne(new LambdaQueryWrapper<UserCouponDO>()
|
||||
@@ -193,7 +214,11 @@ public class CouponServiceImpl extends ServiceImpl<CouponMapper, CouponDO> imple
|
||||
|
||||
List<UserCouponDO> userCouponDOs = userCouponMapper.selectList(queryWrapper);
|
||||
return userCouponDOs.stream()
|
||||
.map(this::convertToUserCouponVO)
|
||||
.map(userCouponDO -> {
|
||||
CouponDO couponDO = getById(userCouponDO.getCouponId());
|
||||
return couponDO == null ? null : convertToUserCouponVO(userCouponDO, couponDO);
|
||||
})
|
||||
.filter(java.util.Objects::nonNull)
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
@@ -238,48 +263,49 @@ public class CouponServiceImpl extends ServiceImpl<CouponMapper, CouponDO> imple
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<UserCouponVO> getAvailableCoupons(Long userId, String productTags, Double productPrice) {
|
||||
// 获取用户未使用的优惠券
|
||||
public List<UserCouponVO> getAvailableCoupons(Long userId, String productTags, Double productPrice, Long shopId) {
|
||||
BigDecimal orderAmount = productPrice == null ? BigDecimal.ZERO : BigDecimal.valueOf(productPrice);
|
||||
LocalDateTime now = LocalDateTime.now();
|
||||
List<UserCouponVO> availableCoupons = new ArrayList<>();
|
||||
|
||||
List<UserCouponDO> userCouponDOs = userCouponMapper.selectList(new LambdaQueryWrapper<UserCouponDO>()
|
||||
.eq(UserCouponDO::getUserId, userId)
|
||||
.eq(UserCouponDO::getStatus, 1)
|
||||
.eq(UserCouponDO::getIsDelete, 0)
|
||||
);
|
||||
|
||||
List<UserCouponVO> availableCoupons = new ArrayList<>();
|
||||
LocalDateTime now = LocalDateTime.now();
|
||||
|
||||
|
||||
for (UserCouponDO userCouponDO : userCouponDOs) {
|
||||
CouponDO couponDO = getById(userCouponDO.getCouponId());
|
||||
if (couponDO == null || couponDO.getIsDelete() == 1) {
|
||||
if (!isCouponApplicable(couponDO, now, orderAmount, productTags, shopId)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// 检查优惠券是否在有效期内
|
||||
if (now.isBefore(couponDO.getStartTime()) || now.isAfter(couponDO.getEndTime())) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// 检查优惠券是否可用
|
||||
if (couponDO.getStatus() != 1) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// 检查满减券的最低消费金额
|
||||
if (couponDO.getCouponType() == 2) {
|
||||
if (couponDO.getMinAmount().doubleValue() > productPrice) {
|
||||
availableCoupons.add(convertToUserCouponVO(userCouponDO, couponDO));
|
||||
}
|
||||
|
||||
UserDO userDO = userMapper.selectById(userId);
|
||||
String currentVipLevel = userDO != null ? userDO.getLevel() : null;
|
||||
if (currentVipLevel != null && !currentVipLevel.isBlank() && !VIP_LEVEL_NORMAL.equals(currentVipLevel)) {
|
||||
List<CouponDO> vipCoupons = list(new LambdaQueryWrapper<CouponDO>()
|
||||
.eq(CouponDO::getIsDelete, 0)
|
||||
.eq(CouponDO::getStatus, 1)
|
||||
.eq(CouponDO::getAutoMatch, 1)
|
||||
.eq(CouponDO::getCouponScene, COUPON_SCENE_VIP_AUTO)
|
||||
.eq(CouponDO::getRequiredVipLevel, currentVipLevel)
|
||||
.orderByDesc(CouponDO::getDiscountValue)
|
||||
.orderByAsc(CouponDO::getEndTime)
|
||||
);
|
||||
|
||||
for (CouponDO couponDO : vipCoupons) {
|
||||
if (!isCouponApplicable(couponDO, now, orderAmount, productTags, shopId)) {
|
||||
continue;
|
||||
}
|
||||
availableCoupons.add(convertToSystemVipCouponVO(couponDO));
|
||||
}
|
||||
|
||||
// 检查标签是否匹配
|
||||
if (!checkTagMatch(couponDO.getId(), productTags)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
availableCoupons.add(convertToUserCouponVO(userCouponDO));
|
||||
}
|
||||
|
||||
|
||||
availableCoupons.sort(Comparator
|
||||
.comparing((UserCouponVO item) -> calculateDiscountAmount(item, orderAmount)).reversed()
|
||||
.thenComparing(UserCouponVO::getEndTime, Comparator.nullsLast(LocalDateTime::compareTo)));
|
||||
return availableCoupons;
|
||||
}
|
||||
|
||||
@@ -296,6 +322,9 @@ public class CouponServiceImpl extends ServiceImpl<CouponMapper, CouponDO> imple
|
||||
if (couponDO.getStatus() != 1) {
|
||||
return false;
|
||||
}
|
||||
if (isVipAutoCoupon(couponDO)) {
|
||||
throw new RuntimeException("VIP 自动券为系统模板券,不支持手动发放");
|
||||
}
|
||||
|
||||
// 检查优惠券数量是否足够
|
||||
int totalNeeded = userIds.size() * quantity;
|
||||
@@ -480,6 +509,9 @@ public class CouponServiceImpl extends ServiceImpl<CouponMapper, CouponDO> imple
|
||||
couponVO.setEndTime(couponDO.getEndTime());
|
||||
couponVO.setStatus(couponDO.getStatus());
|
||||
couponVO.setShopId(couponDO.getShopId());
|
||||
couponVO.setCouponScene(couponDO.getCouponScene());
|
||||
couponVO.setRequiredVipLevel(couponDO.getRequiredVipLevel());
|
||||
couponVO.setAutoMatch(couponDO.getAutoMatch());
|
||||
|
||||
// 获取店铺名称
|
||||
if (couponDO.getShopId() != null) {
|
||||
@@ -535,23 +567,8 @@ public class CouponServiceImpl extends ServiceImpl<CouponMapper, CouponDO> imple
|
||||
/**
|
||||
* 转换为UserCouponVO
|
||||
*/
|
||||
private UserCouponVO convertToUserCouponVO(UserCouponDO userCouponDO) {
|
||||
UserCouponVO userCouponVO = new UserCouponVO();
|
||||
userCouponVO.setId(userCouponDO.getId());
|
||||
userCouponVO.setCouponId(userCouponDO.getCouponId());
|
||||
|
||||
CouponDO couponDO = getById(userCouponDO.getCouponId());
|
||||
if (couponDO != null) {
|
||||
userCouponVO.setCouponName(couponDO.getCouponName());
|
||||
userCouponVO.setCouponType(couponDO.getCouponType());
|
||||
userCouponVO.setCouponTypeName(couponDO.getCouponType() == 1 ? "折扣券" : "满减券");
|
||||
userCouponVO.setDiscountValue(couponDO.getDiscountValue() != null ? couponDO.getDiscountValue().toString() : "");
|
||||
userCouponVO.setMinAmount(couponDO.getMinAmount() != null ? couponDO.getMinAmount().toString() : "");
|
||||
userCouponVO.setReduceAmount(couponDO.getReduceAmount() != null ? couponDO.getReduceAmount().toString() : "");
|
||||
userCouponVO.setStartTime(couponDO.getStartTime());
|
||||
userCouponVO.setEndTime(couponDO.getEndTime());
|
||||
}
|
||||
|
||||
private UserCouponVO convertToUserCouponVO(UserCouponDO userCouponDO, CouponDO couponDO) {
|
||||
UserCouponVO userCouponVO = buildCouponOption(userCouponDO.getId(), couponDO, COUPON_SOURCE_USER, false);
|
||||
userCouponVO.setStatus(userCouponDO.getStatus());
|
||||
switch (userCouponDO.getStatus()) {
|
||||
case 1:
|
||||
@@ -566,10 +583,86 @@ public class CouponServiceImpl extends ServiceImpl<CouponMapper, CouponDO> imple
|
||||
default:
|
||||
userCouponVO.setStatusName("未知");
|
||||
}
|
||||
|
||||
userCouponVO.setObtainTime(userCouponDO.getObtainTime());
|
||||
userCouponVO.setUseTime(userCouponDO.getUseTime());
|
||||
|
||||
return userCouponVO;
|
||||
}
|
||||
|
||||
private UserCouponVO convertToSystemVipCouponVO(CouponDO couponDO) {
|
||||
UserCouponVO userCouponVO = buildCouponOption(couponDO.getId(), couponDO, COUPON_SOURCE_SYSTEM_VIP, true);
|
||||
userCouponVO.setStatus(1);
|
||||
userCouponVO.setStatusName("系统自动匹配");
|
||||
return userCouponVO;
|
||||
}
|
||||
|
||||
private UserCouponVO buildCouponOption(Long optionId, CouponDO couponDO, String sourceType, boolean autoMatched) {
|
||||
UserCouponVO userCouponVO = new UserCouponVO();
|
||||
userCouponVO.setId(optionId);
|
||||
userCouponVO.setCouponId(couponDO.getId());
|
||||
userCouponVO.setCouponName(couponDO.getCouponName());
|
||||
userCouponVO.setCouponType(couponDO.getCouponType());
|
||||
userCouponVO.setCouponTypeName(couponDO.getCouponType() == 1 ? "折扣券" : "满减券");
|
||||
userCouponVO.setDiscountValue(couponDO.getDiscountValue() != null ? couponDO.getDiscountValue().toString() : "");
|
||||
userCouponVO.setMinAmount(couponDO.getMinAmount() != null ? couponDO.getMinAmount().toString() : "");
|
||||
userCouponVO.setReduceAmount(couponDO.getReduceAmount() != null ? couponDO.getReduceAmount().toString() : "");
|
||||
userCouponVO.setStartTime(couponDO.getStartTime());
|
||||
userCouponVO.setEndTime(couponDO.getEndTime());
|
||||
userCouponVO.setSourceType(sourceType);
|
||||
userCouponVO.setRequiredVipLevel(couponDO.getRequiredVipLevel());
|
||||
userCouponVO.setAutoMatched(autoMatched);
|
||||
return userCouponVO;
|
||||
}
|
||||
|
||||
private boolean isCouponApplicable(CouponDO couponDO, LocalDateTime now, BigDecimal orderAmount, String productTags, Long shopId) {
|
||||
if (couponDO == null || Integer.valueOf(1).equals(couponDO.getIsDelete())) {
|
||||
return false;
|
||||
}
|
||||
if (couponDO.getStatus() == null || couponDO.getStatus() != 1) {
|
||||
return false;
|
||||
}
|
||||
if (couponDO.getStartTime() != null && now.isBefore(couponDO.getStartTime())) {
|
||||
return false;
|
||||
}
|
||||
if (couponDO.getEndTime() != null && now.isAfter(couponDO.getEndTime())) {
|
||||
return false;
|
||||
}
|
||||
if (!matchesShop(couponDO, shopId)) {
|
||||
return false;
|
||||
}
|
||||
if (couponDO.getCouponType() == 2
|
||||
&& couponDO.getMinAmount() != null
|
||||
&& couponDO.getMinAmount().compareTo(orderAmount) > 0) {
|
||||
return false;
|
||||
}
|
||||
return checkTagMatch(couponDO.getId(), productTags);
|
||||
}
|
||||
|
||||
private boolean matchesShop(CouponDO couponDO, Long shopId) {
|
||||
if (shopId == null || couponDO.getShopId() == null) {
|
||||
return true;
|
||||
}
|
||||
return shopId.equals(couponDO.getShopId());
|
||||
}
|
||||
|
||||
private boolean isVipAutoCoupon(CouponDO couponDO) {
|
||||
return couponDO != null
|
||||
&& Integer.valueOf(1).equals(couponDO.getAutoMatch())
|
||||
&& COUPON_SCENE_VIP_AUTO.equals(couponDO.getCouponScene());
|
||||
}
|
||||
|
||||
private BigDecimal calculateDiscountAmount(UserCouponVO couponVO, BigDecimal orderAmount) {
|
||||
if (couponVO == null || orderAmount == null || orderAmount.compareTo(BigDecimal.ZERO) <= 0) {
|
||||
return BigDecimal.ZERO;
|
||||
}
|
||||
if (couponVO.getCouponType() == 1 && couponVO.getDiscountValue() != null && !couponVO.getDiscountValue().isBlank()) {
|
||||
BigDecimal discountValue = new BigDecimal(couponVO.getDiscountValue());
|
||||
BigDecimal actualAmount = orderAmount.multiply(discountValue)
|
||||
.divide(BigDecimal.TEN, 2, BigDecimal.ROUND_HALF_UP);
|
||||
return orderAmount.subtract(actualAmount);
|
||||
}
|
||||
if (couponVO.getCouponType() == 2 && couponVO.getReduceAmount() != null && !couponVO.getReduceAmount().isBlank()) {
|
||||
return new BigDecimal(couponVO.getReduceAmount());
|
||||
}
|
||||
return BigDecimal.ZERO;
|
||||
}
|
||||
}
|
||||
|
||||
+175
-64
@@ -52,6 +52,9 @@ public class OrderServiceImpl implements OrderService {
|
||||
|
||||
private static final DateTimeFormatter ORDER_NO_TIME_FORMATTER = DateTimeFormatter.ofPattern("yyyyMMddHHmmss");
|
||||
private static final DateTimeFormatter APPOINTMENT_OUTPUT_FORMATTER = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
|
||||
private static final String COUPON_SOURCE_NONE = "NONE";
|
||||
private static final String COUPON_SOURCE_USER = "USER_COUPON";
|
||||
private static final String COUPON_SOURCE_SYSTEM_VIP = "SYSTEM_VIP";
|
||||
private static final List<DateTimeFormatter> APPOINTMENT_INPUT_FORMATTERS = Arrays.asList(
|
||||
DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"),
|
||||
DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm"),
|
||||
@@ -169,31 +172,26 @@ public class OrderServiceImpl implements OrderService {
|
||||
throw new RuntimeException("订单金额无效");
|
||||
}
|
||||
|
||||
String productTagNames = String.join(",", selectedTagNames);
|
||||
List<UserCouponVO> availableCouponOptions = couponService.getAvailableCoupons(
|
||||
userId,
|
||||
productTagNames,
|
||||
totalAmount.doubleValue(),
|
||||
shopId
|
||||
);
|
||||
|
||||
BigDecimal actualAmount = totalAmount;
|
||||
Long userCouponId = orderDTO.getCouponId();
|
||||
Long couponId = null;
|
||||
if (userCouponId != null && userCouponId > 0) {
|
||||
UserCouponDO userCoupon = userCouponMapper.selectOne(
|
||||
new QueryWrapper<UserCouponDO>()
|
||||
.eq("id", userCouponId)
|
||||
.eq("user_id", userId)
|
||||
.eq("status", 1)
|
||||
);
|
||||
Long userCouponId = null;
|
||||
String couponSourceType = null;
|
||||
|
||||
if (userCoupon == null) {
|
||||
throw new RuntimeException("优惠券不存在或已失效");
|
||||
}
|
||||
CouponSelection couponSelection = resolveRequestedCoupon(orderDTO, availableCouponOptions);
|
||||
if (couponSelection == null && !isExplicitNoCoupon(orderDTO)) {
|
||||
couponSelection = selectBestSystemVipCoupon(availableCouponOptions, totalAmount);
|
||||
}
|
||||
|
||||
String productTagNames = String.join(",", selectedTagNames);
|
||||
boolean couponAvailable = couponService.getAvailableCoupons(userId, productTagNames, totalAmount.doubleValue()).stream()
|
||||
.map(UserCouponVO::getId)
|
||||
.anyMatch(id -> userCouponId.equals(id));
|
||||
if (!couponAvailable) {
|
||||
throw new RuntimeException("当前订单不可使用所选优惠券");
|
||||
}
|
||||
|
||||
couponId = userCoupon.getCouponId();
|
||||
CouponDO coupon = couponMapper.selectById(couponId);
|
||||
if (couponSelection != null) {
|
||||
CouponDO coupon = couponMapper.selectById(couponSelection.getCouponId());
|
||||
if (coupon == null || Integer.valueOf(1).equals(coupon.getIsDelete()) || coupon.getStatus() != 1) {
|
||||
throw new RuntimeException("优惠券不存在或已失效");
|
||||
}
|
||||
@@ -201,19 +199,14 @@ public class OrderServiceImpl implements OrderService {
|
||||
throw new RuntimeException("该优惠券不适用于当前店铺");
|
||||
}
|
||||
|
||||
if (coupon.getCouponType() == 1) {
|
||||
actualAmount = totalAmount.multiply(coupon.getDiscountValue())
|
||||
.divide(BigDecimal.valueOf(10), 2, BigDecimal.ROUND_HALF_UP);
|
||||
} else if (coupon.getCouponType() == 2 && totalAmount.compareTo(coupon.getMinAmount()) >= 0) {
|
||||
actualAmount = totalAmount.subtract(coupon.getReduceAmount());
|
||||
if (actualAmount.compareTo(BigDecimal.ZERO) < 0) {
|
||||
actualAmount = BigDecimal.ZERO;
|
||||
}
|
||||
}
|
||||
actualAmount = applyCouponDiscount(totalAmount, coupon);
|
||||
couponId = coupon.getId();
|
||||
userCouponId = couponSelection.getUserCouponId();
|
||||
couponSourceType = couponSelection.getSourceType();
|
||||
|
||||
userCoupon.setStatus(2);
|
||||
userCoupon.setUseTime(LocalDateTime.now());
|
||||
userCouponMapper.updateById(userCoupon);
|
||||
if (COUPON_SOURCE_USER.equals(couponSourceType)) {
|
||||
consumeUserCoupon(userCouponId, userId);
|
||||
}
|
||||
}
|
||||
|
||||
String orderNo = "ORD" + LocalDateTime.now().format(ORDER_NO_TIME_FORMATTER)
|
||||
@@ -226,6 +219,8 @@ public class OrderServiceImpl implements OrderService {
|
||||
order.setTotalAmount(totalAmount);
|
||||
order.setActualAmount(actualAmount);
|
||||
order.setCouponId(couponId);
|
||||
order.setUserCouponId(userCouponId);
|
||||
order.setCouponSourceType(couponSourceType);
|
||||
order.setStatus(1);
|
||||
order.setIsDelete(0);
|
||||
orderMapper.insert(order);
|
||||
@@ -287,22 +282,7 @@ public class OrderServiceImpl implements OrderService {
|
||||
|
||||
order.setStatus(3);
|
||||
orderMapper.updateById(order);
|
||||
|
||||
if (order.getCouponId() != null && order.getCouponId() > 0) {
|
||||
List<UserCouponDO> userCoupons = userCouponMapper.selectList(
|
||||
new QueryWrapper<UserCouponDO>()
|
||||
.eq("user_id", userId)
|
||||
.eq("coupon_id", order.getCouponId())
|
||||
.eq("status", 2)
|
||||
);
|
||||
if (!userCoupons.isEmpty()) {
|
||||
userCoupons.sort((a, b) -> b.getUseTime().compareTo(a.getUseTime()));
|
||||
UserCouponDO userCoupon = userCoupons.get(0);
|
||||
userCoupon.setStatus(1);
|
||||
userCoupon.setUseTime(null);
|
||||
userCouponMapper.updateById(userCoupon);
|
||||
}
|
||||
}
|
||||
restoreUserCoupon(order, userId);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -321,21 +301,8 @@ public class OrderServiceImpl implements OrderService {
|
||||
|
||||
order.setStatus(status);
|
||||
orderMapper.updateById(order);
|
||||
|
||||
if (status == 3 && order.getCouponId() != null && order.getCouponId() > 0) {
|
||||
List<UserCouponDO> userCoupons = userCouponMapper.selectList(
|
||||
new QueryWrapper<UserCouponDO>()
|
||||
.eq("user_id", order.getUserId())
|
||||
.eq("coupon_id", order.getCouponId())
|
||||
.eq("status", 2)
|
||||
);
|
||||
if (!userCoupons.isEmpty()) {
|
||||
userCoupons.sort((a, b) -> b.getUseTime().compareTo(a.getUseTime()));
|
||||
UserCouponDO userCoupon = userCoupons.get(0);
|
||||
userCoupon.setStatus(1);
|
||||
userCoupon.setUseTime(null);
|
||||
userCouponMapper.updateById(userCoupon);
|
||||
}
|
||||
if (status == 3) {
|
||||
restoreUserCoupon(order, order.getUserId());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -402,6 +369,8 @@ public class OrderServiceImpl implements OrderService {
|
||||
orderVO.setTotalAmount(order.getTotalAmount());
|
||||
orderVO.setActualAmount(order.getActualAmount());
|
||||
orderVO.setCouponId(order.getCouponId());
|
||||
orderVO.setUserCouponId(order.getUserCouponId());
|
||||
orderVO.setCouponSourceType(order.getCouponSourceType());
|
||||
orderVO.setStatus(order.getStatus());
|
||||
|
||||
switch (order.getStatus()) {
|
||||
@@ -692,6 +661,148 @@ public class OrderServiceImpl implements OrderService {
|
||||
return appointmentTime.format(APPOINTMENT_OUTPUT_FORMATTER);
|
||||
}
|
||||
|
||||
private CouponSelection resolveRequestedCoupon(OrderDTO orderDTO, List<UserCouponVO> availableCoupons) {
|
||||
if (orderDTO == null || orderDTO.getCouponId() == null || orderDTO.getCouponId() <= 0) {
|
||||
return null;
|
||||
}
|
||||
|
||||
String requestedSourceType = normalizeCouponSourceType(orderDTO.getCouponSourceType());
|
||||
List<UserCouponVO> matchedCoupons = availableCoupons.stream()
|
||||
.filter(coupon -> orderDTO.getCouponId().equals(coupon.getId()))
|
||||
.filter(coupon -> requestedSourceType == null || requestedSourceType.equals(coupon.getSourceType()))
|
||||
.toList();
|
||||
|
||||
if (matchedCoupons.isEmpty()) {
|
||||
throw new RuntimeException("当前订单不可使用所选优惠券");
|
||||
}
|
||||
|
||||
UserCouponVO selectedCoupon = matchedCoupons.stream()
|
||||
.filter(coupon -> COUPON_SOURCE_USER.equals(coupon.getSourceType()))
|
||||
.findFirst()
|
||||
.orElse(matchedCoupons.get(0));
|
||||
|
||||
return new CouponSelection(
|
||||
selectedCoupon.getSourceType(),
|
||||
selectedCoupon.getCouponId(),
|
||||
COUPON_SOURCE_USER.equals(selectedCoupon.getSourceType()) ? selectedCoupon.getId() : null
|
||||
);
|
||||
}
|
||||
|
||||
private CouponSelection selectBestSystemVipCoupon(List<UserCouponVO> availableCoupons, BigDecimal totalAmount) {
|
||||
return availableCoupons.stream()
|
||||
.filter(coupon -> COUPON_SOURCE_SYSTEM_VIP.equals(coupon.getSourceType()))
|
||||
.max(Comparator.comparing(coupon -> calculateCouponDiscountAmount(coupon, totalAmount)))
|
||||
.map(coupon -> new CouponSelection(coupon.getSourceType(), coupon.getCouponId(), null))
|
||||
.orElse(null);
|
||||
}
|
||||
|
||||
private String normalizeCouponSourceType(String couponSourceType) {
|
||||
if (couponSourceType == null || couponSourceType.isBlank()) {
|
||||
return null;
|
||||
}
|
||||
return couponSourceType.trim().toUpperCase();
|
||||
}
|
||||
|
||||
private boolean isExplicitNoCoupon(OrderDTO orderDTO) {
|
||||
return orderDTO != null
|
||||
&& orderDTO.getCouponId() == null
|
||||
&& COUPON_SOURCE_NONE.equalsIgnoreCase(orderDTO.getCouponSourceType());
|
||||
}
|
||||
|
||||
private BigDecimal calculateCouponDiscountAmount(UserCouponVO coupon, BigDecimal totalAmount) {
|
||||
if (coupon == null || totalAmount == null || totalAmount.compareTo(BigDecimal.ZERO) <= 0) {
|
||||
return BigDecimal.ZERO;
|
||||
}
|
||||
|
||||
if (coupon.getCouponType() == 1 && coupon.getDiscountValue() != null && !coupon.getDiscountValue().isBlank()) {
|
||||
BigDecimal discountValue = new BigDecimal(coupon.getDiscountValue());
|
||||
BigDecimal discountedAmount = totalAmount.multiply(discountValue)
|
||||
.divide(BigDecimal.TEN, 2, BigDecimal.ROUND_HALF_UP);
|
||||
return totalAmount.subtract(discountedAmount);
|
||||
}
|
||||
|
||||
if (coupon.getCouponType() == 2 && coupon.getReduceAmount() != null && !coupon.getReduceAmount().isBlank()) {
|
||||
return new BigDecimal(coupon.getReduceAmount());
|
||||
}
|
||||
|
||||
return BigDecimal.ZERO;
|
||||
}
|
||||
|
||||
private BigDecimal applyCouponDiscount(BigDecimal totalAmount, CouponDO coupon) {
|
||||
if (coupon.getCouponType() == 1 && coupon.getDiscountValue() != null) {
|
||||
return totalAmount.multiply(coupon.getDiscountValue())
|
||||
.divide(BigDecimal.TEN, 2, BigDecimal.ROUND_HALF_UP);
|
||||
}
|
||||
if (coupon.getCouponType() == 2 && coupon.getReduceAmount() != null) {
|
||||
BigDecimal actualAmount = totalAmount.subtract(coupon.getReduceAmount());
|
||||
return actualAmount.compareTo(BigDecimal.ZERO) < 0 ? BigDecimal.ZERO : actualAmount;
|
||||
}
|
||||
return totalAmount;
|
||||
}
|
||||
|
||||
private void consumeUserCoupon(Long userCouponId, Long userId) {
|
||||
if (userCouponId == null) {
|
||||
throw new RuntimeException("用户优惠券信息缺失");
|
||||
}
|
||||
|
||||
UserCouponDO userCoupon = userCouponMapper.selectById(userCouponId);
|
||||
if (userCoupon == null || Integer.valueOf(1).equals(userCoupon.getIsDelete())) {
|
||||
throw new RuntimeException("优惠券不存在或已失效");
|
||||
}
|
||||
if (!userId.equals(userCoupon.getUserId())) {
|
||||
throw new RuntimeException("优惠券不属于当前用户");
|
||||
}
|
||||
if (userCoupon.getStatus() == null || userCoupon.getStatus() != 1) {
|
||||
throw new RuntimeException("优惠券已被使用或不可用");
|
||||
}
|
||||
|
||||
userCoupon.setStatus(2);
|
||||
userCoupon.setUseTime(LocalDateTime.now());
|
||||
userCouponMapper.updateById(userCoupon);
|
||||
}
|
||||
|
||||
private void restoreUserCoupon(OrderDO order, Long userId) {
|
||||
if (order == null
|
||||
|| !COUPON_SOURCE_USER.equals(order.getCouponSourceType())
|
||||
|| order.getUserCouponId() == null
|
||||
|| userId == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
UserCouponDO userCoupon = userCouponMapper.selectById(order.getUserCouponId());
|
||||
if (userCoupon == null || !userId.equals(userCoupon.getUserId()) || userCoupon.getStatus() == null || userCoupon.getStatus() != 2) {
|
||||
return;
|
||||
}
|
||||
|
||||
userCoupon.setStatus(1);
|
||||
userCoupon.setUseTime(null);
|
||||
userCouponMapper.updateById(userCoupon);
|
||||
}
|
||||
|
||||
private static final class CouponSelection {
|
||||
private final String sourceType;
|
||||
private final Long couponId;
|
||||
private final Long userCouponId;
|
||||
|
||||
private CouponSelection(String sourceType, Long couponId, Long userCouponId) {
|
||||
this.sourceType = sourceType;
|
||||
this.couponId = couponId;
|
||||
this.userCouponId = userCouponId;
|
||||
}
|
||||
|
||||
private String getSourceType() {
|
||||
return sourceType;
|
||||
}
|
||||
|
||||
private Long getCouponId() {
|
||||
return couponId;
|
||||
}
|
||||
|
||||
private Long getUserCouponId() {
|
||||
return userCouponId;
|
||||
}
|
||||
}
|
||||
|
||||
private static final class AppointmentSlot {
|
||||
private final String productTitle;
|
||||
private final LocalDateTime startTime;
|
||||
|
||||
+19
@@ -113,6 +113,16 @@ public class PermissionServiceImpl extends ServiceImpl<PermissionMapper, Permiss
|
||||
|
||||
@Override
|
||||
public List<PermissionVO> listUserPermissions(Long userId) {
|
||||
UserDO userDO = userMapper.selectById(userId);
|
||||
if (userDO != null && Integer.valueOf(4).equals(userDO.getType())) {
|
||||
return permissionMapper.selectList(
|
||||
Wrappers.lambdaQuery(PermissionDO.class)
|
||||
.eq(PermissionDO::getIsDelete, 0))
|
||||
.stream()
|
||||
.map(this::convertToVO)
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
List<UserPermissionDO> userPermissions = userPermissionMapper.selectList(
|
||||
Wrappers.lambdaQuery(UserPermissionDO.class)
|
||||
.eq(UserPermissionDO::getUserId, userId)
|
||||
@@ -190,6 +200,15 @@ public class PermissionServiceImpl extends ServiceImpl<PermissionMapper, Permiss
|
||||
|
||||
@Override
|
||||
public boolean hasPermission(Long userId, String permissionCode) {
|
||||
UserDO userDO = userMapper.selectById(userId);
|
||||
if (userDO != null && Integer.valueOf(4).equals(userDO.getType())) {
|
||||
return permissionMapper.selectCount(
|
||||
Wrappers.lambdaQuery(PermissionDO.class)
|
||||
.eq(PermissionDO::getPermissionCode, permissionCode)
|
||||
.eq(PermissionDO::getIsDelete, 0)
|
||||
) > 0;
|
||||
}
|
||||
|
||||
List<UserPermissionDO> userPermissions = userPermissionMapper.selectList(
|
||||
Wrappers.lambdaQuery(UserPermissionDO.class)
|
||||
.eq(UserPermissionDO::getUserId, userId)
|
||||
|
||||
+339
@@ -0,0 +1,339 @@
|
||||
package com.xiaowang.yuminailcore.service.impl;
|
||||
|
||||
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
||||
import com.xiaowang.yuminailcore.dto.AdminUserBalanceChangeDTO;
|
||||
import com.xiaowang.yuminailcore.dto.AdminUserVipOverrideDTO;
|
||||
import com.xiaowang.yuminailcore.entity.BalanceChangeDetailDO;
|
||||
import com.xiaowang.yuminailcore.entity.BalanceDO;
|
||||
import com.xiaowang.yuminailcore.entity.OrderDO;
|
||||
import com.xiaowang.yuminailcore.entity.UserDO;
|
||||
import com.xiaowang.yuminailcore.entity.VipBenefitDO;
|
||||
import com.xiaowang.yuminailcore.entity.VipInfoDO;
|
||||
import com.xiaowang.yuminailcore.mapper.BalanceChangeDetailMapper;
|
||||
import com.xiaowang.yuminailcore.mapper.BalanceMapper;
|
||||
import com.xiaowang.yuminailcore.mapper.OrderMapper;
|
||||
import com.xiaowang.yuminailcore.mapper.UserMapper;
|
||||
import com.xiaowang.yuminailcore.mapper.VipBenefitMapper;
|
||||
import com.xiaowang.yuminailcore.mapper.VipInfoMapper;
|
||||
import com.xiaowang.yuminailcore.service.UserAssetService;
|
||||
import com.xiaowang.yuminailcore.vo.BalanceChangeDetailVO;
|
||||
import com.xiaowang.yuminailcore.vo.UserAssetVO;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
public class UserAssetServiceImpl implements UserAssetService {
|
||||
|
||||
private static final String VIP_LEVEL_NORMAL = "普通";
|
||||
private static final String SCENE_RECHARGE = "RECHARGE";
|
||||
private static final String SCENE_MANUAL_ADD = "MANUAL_ADD";
|
||||
private static final String SCENE_MANUAL_DEDUCT = "MANUAL_DEDUCT";
|
||||
private static final String SCENE_ORDER_CONSUME = "ORDER_CONSUME";
|
||||
private static final String SCENE_ORDER_REFUND = "ORDER_REFUND";
|
||||
|
||||
private final BalanceMapper balanceMapper;
|
||||
private final BalanceChangeDetailMapper balanceChangeDetailMapper;
|
||||
private final VipInfoMapper vipInfoMapper;
|
||||
private final VipBenefitMapper vipBenefitMapper;
|
||||
private final UserMapper userMapper;
|
||||
private final OrderMapper orderMapper;
|
||||
|
||||
@Override
|
||||
public UserAssetVO getUserAsset(Long userId) {
|
||||
UserDO user = getAvailableUser(userId);
|
||||
BalanceDO balance = ensureBalance(userId);
|
||||
VipInfoDO vipInfo = getVipInfo(userId);
|
||||
VipBenefitDO benefit = vipInfo != null && vipInfo.getBenefitId() != null
|
||||
? vipBenefitMapper.selectById(vipInfo.getBenefitId())
|
||||
: null;
|
||||
return toAssetVO(user, balance, vipInfo, benefit);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<BalanceChangeDetailVO> listBalanceHistory(Long userId) {
|
||||
UserDO user = getAvailableUser(userId);
|
||||
return balanceChangeDetailMapper.selectList(
|
||||
Wrappers.lambdaQuery(BalanceChangeDetailDO.class)
|
||||
.eq(BalanceChangeDetailDO::getUserId, userId)
|
||||
.orderByDesc(BalanceChangeDetailDO::getChangeTime)
|
||||
.orderByDesc(BalanceChangeDetailDO::getId))
|
||||
.stream()
|
||||
.map(detail -> toBalanceHistoryVO(detail, user.getNickname()))
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public UserAssetVO changeBalance(Long operatorId, Long userId, AdminUserBalanceChangeDTO request) {
|
||||
if (request == null || request.getAmount() == null || request.getAmount().compareTo(BigDecimal.ZERO) <= 0) {
|
||||
throw new RuntimeException("变动金额必须大于 0");
|
||||
}
|
||||
if (!StringUtils.hasText(request.getChangeScene())) {
|
||||
throw new RuntimeException("变动场景不能为空");
|
||||
}
|
||||
|
||||
UserDO user = getAvailableUser(userId);
|
||||
BalanceDO balance = ensureBalance(userId);
|
||||
LocalDateTime now = LocalDateTime.now();
|
||||
|
||||
BigDecimal beforeBalance = defaultDecimal(balance.getAmount());
|
||||
BigDecimal delta = normalizeDelta(request.getAmount(), request.getChangeScene());
|
||||
BigDecimal afterBalance = beforeBalance.add(delta);
|
||||
if (afterBalance.compareTo(BigDecimal.ZERO) < 0) {
|
||||
throw new RuntimeException("余额不足,无法执行扣减");
|
||||
}
|
||||
|
||||
OrderDO relatedOrder = null;
|
||||
String relatedOrderNo = null;
|
||||
if (request.getRelatedOrderId() != null) {
|
||||
relatedOrder = orderMapper.selectById(request.getRelatedOrderId());
|
||||
if (relatedOrder == null) {
|
||||
throw new RuntimeException("关联系统订单不存在");
|
||||
}
|
||||
if (!userId.equals(relatedOrder.getUserId())) {
|
||||
throw new RuntimeException("所选订单不属于当前用户");
|
||||
}
|
||||
relatedOrderNo = relatedOrder.getOrderNo();
|
||||
}
|
||||
|
||||
if (isDeductScene(request.getChangeScene())
|
||||
&& relatedOrder == null
|
||||
&& !StringUtils.hasText(request.getExternalOrderNo())) {
|
||||
throw new RuntimeException("扣减余额时必须关联系统订单或填写外部订单号");
|
||||
}
|
||||
|
||||
balance.setAmount(afterBalance);
|
||||
balance.setLastUpdateTime(now);
|
||||
if (SCENE_RECHARGE.equals(request.getChangeScene())) {
|
||||
balance.setTotalRechargeAmount(defaultDecimal(balance.getTotalRechargeAmount()).add(request.getAmount()));
|
||||
balance.setLastRechargeTime(now);
|
||||
}
|
||||
balanceMapper.updateById(balance);
|
||||
|
||||
BalanceChangeDetailDO detail = new BalanceChangeDetailDO();
|
||||
detail.setUserId(userId);
|
||||
detail.setAmount(delta);
|
||||
detail.setType(request.getChangeScene());
|
||||
detail.setCurrentBalance(afterBalance);
|
||||
detail.setBeforeBalance(beforeBalance);
|
||||
detail.setAfterBalance(afterBalance);
|
||||
detail.setChangeScene(request.getChangeScene());
|
||||
detail.setRelatedOrderId(relatedOrder != null ? relatedOrder.getId() : null);
|
||||
detail.setRelatedOrderNo(relatedOrderNo);
|
||||
detail.setExternalOrderNo(StringUtils.hasText(request.getExternalOrderNo()) ? request.getExternalOrderNo().trim() : null);
|
||||
detail.setOperatorId(operatorId);
|
||||
detail.setRemark(StringUtils.hasText(request.getRemark()) ? request.getRemark().trim() : null);
|
||||
detail.setChangeTime(now);
|
||||
balanceChangeDetailMapper.insert(detail);
|
||||
|
||||
if (SCENE_RECHARGE.equals(request.getChangeScene())) {
|
||||
recalculateVipInternal(user, false);
|
||||
}
|
||||
|
||||
return getUserAsset(userId);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public UserAssetVO overrideVip(Long operatorId, Long userId, AdminUserVipOverrideDTO request) {
|
||||
if (request == null || !StringUtils.hasText(request.getVipLevel())) {
|
||||
throw new RuntimeException("VIP 等级不能为空");
|
||||
}
|
||||
|
||||
UserDO user = getAvailableUser(userId);
|
||||
String targetLevel = request.getVipLevel().trim();
|
||||
VipInfoDO vipInfo = getOrCreateVipInfo(userId);
|
||||
vipInfo.setActivationMethod("MANUAL_OVERRIDE");
|
||||
vipInfo.setManualOverride(1);
|
||||
vipInfo.setStartTime(LocalDateTime.now());
|
||||
|
||||
VipBenefitDO benefit = null;
|
||||
if (!VIP_LEVEL_NORMAL.equals(targetLevel)) {
|
||||
benefit = vipBenefitMapper.selectOne(
|
||||
Wrappers.lambdaQuery(VipBenefitDO.class)
|
||||
.eq(VipBenefitDO::getRequiredVipLevel, targetLevel)
|
||||
.eq(VipBenefitDO::getStatus, 1)
|
||||
.last("limit 1"));
|
||||
if (benefit == null) {
|
||||
throw new RuntimeException("目标 VIP 等级未配置有效规则");
|
||||
}
|
||||
vipInfo.setBenefitId(benefit.getId());
|
||||
} else {
|
||||
vipInfo.setBenefitId(null);
|
||||
}
|
||||
vipInfo.setVipLevel(targetLevel);
|
||||
vipInfoMapper.updateById(vipInfo);
|
||||
|
||||
updateUserVipFields(user, vipInfo, targetLevel);
|
||||
return toAssetVO(userMapper.selectById(userId), ensureBalance(userId), vipInfo, benefit);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public UserAssetVO recalculateVip(Long operatorId, Long userId) {
|
||||
UserDO user = getAvailableUser(userId);
|
||||
recalculateVipInternal(user, true);
|
||||
return getUserAsset(userId);
|
||||
}
|
||||
|
||||
private void recalculateVipInternal(UserDO user, boolean clearManualOverride) {
|
||||
BalanceDO balance = ensureBalance(user.getId());
|
||||
VipBenefitDO matchedBenefit = vipBenefitMapper.selectList(
|
||||
Wrappers.lambdaQuery(VipBenefitDO.class)
|
||||
.eq(VipBenefitDO::getStatus, 1)
|
||||
.orderByAsc(VipBenefitDO::getLevelRank)
|
||||
.orderByAsc(VipBenefitDO::getRechargeThreshold))
|
||||
.stream()
|
||||
.filter(benefit -> defaultDecimal(balance.getTotalRechargeAmount())
|
||||
.compareTo(defaultDecimal(benefit.getRechargeThreshold())) >= 0)
|
||||
.max(Comparator.comparing(VipBenefitDO::getLevelRank, Comparator.nullsLast(Integer::compareTo))
|
||||
.thenComparing(VipBenefitDO::getRechargeThreshold, Comparator.nullsLast(BigDecimal::compareTo)))
|
||||
.orElse(null);
|
||||
|
||||
VipInfoDO vipInfo = getVipInfo(user.getId());
|
||||
if (vipInfo != null && Integer.valueOf(1).equals(vipInfo.getManualOverride()) && !clearManualOverride) {
|
||||
return;
|
||||
}
|
||||
if (vipInfo == null && matchedBenefit == null) {
|
||||
updateUserVipFields(user, null, VIP_LEVEL_NORMAL);
|
||||
return;
|
||||
}
|
||||
|
||||
vipInfo = vipInfo == null ? getOrCreateVipInfo(user.getId()) : vipInfo;
|
||||
vipInfo.setActivationMethod("AUTO_RECALCULATE");
|
||||
vipInfo.setManualOverride(clearManualOverride ? 0 : vipInfo.getManualOverride());
|
||||
vipInfo.setStartTime(LocalDateTime.now());
|
||||
|
||||
String targetLevel = matchedBenefit != null ? matchedBenefit.getRequiredVipLevel() : VIP_LEVEL_NORMAL;
|
||||
vipInfo.setVipLevel(targetLevel);
|
||||
vipInfo.setBenefitId(matchedBenefit != null ? matchedBenefit.getId() : null);
|
||||
vipInfoMapper.updateById(vipInfo);
|
||||
|
||||
updateUserVipFields(user, vipInfo, targetLevel);
|
||||
}
|
||||
|
||||
private void updateUserVipFields(UserDO user, VipInfoDO vipInfo, String vipLevel) {
|
||||
user.setLevel(StringUtils.hasText(vipLevel) ? vipLevel : VIP_LEVEL_NORMAL);
|
||||
user.setVipId(VIP_LEVEL_NORMAL.equals(user.getLevel()) || vipInfo == null ? 0L : vipInfo.getId());
|
||||
user.setUpdateTime(LocalDateTime.now());
|
||||
userMapper.updateById(user);
|
||||
}
|
||||
|
||||
private BigDecimal normalizeDelta(BigDecimal amount, String changeScene) {
|
||||
if (isDeductScene(changeScene)) {
|
||||
return amount.negate();
|
||||
}
|
||||
if (SCENE_RECHARGE.equals(changeScene) || SCENE_MANUAL_ADD.equals(changeScene) || SCENE_ORDER_REFUND.equals(changeScene)) {
|
||||
return amount;
|
||||
}
|
||||
throw new RuntimeException("不支持的余额变动场景");
|
||||
}
|
||||
|
||||
private boolean isDeductScene(String changeScene) {
|
||||
return SCENE_MANUAL_DEDUCT.equals(changeScene) || SCENE_ORDER_CONSUME.equals(changeScene);
|
||||
}
|
||||
|
||||
private BalanceDO ensureBalance(Long userId) {
|
||||
BalanceDO balance = balanceMapper.selectOne(
|
||||
Wrappers.lambdaQuery(BalanceDO.class)
|
||||
.eq(BalanceDO::getUserId, userId)
|
||||
.last("limit 1"));
|
||||
if (balance != null) {
|
||||
if (balance.getAmount() == null) {
|
||||
balance.setAmount(BigDecimal.ZERO);
|
||||
}
|
||||
if (balance.getTotalRechargeAmount() == null) {
|
||||
balance.setTotalRechargeAmount(BigDecimal.ZERO);
|
||||
}
|
||||
return balance;
|
||||
}
|
||||
|
||||
balance = new BalanceDO();
|
||||
balance.setUserId(userId);
|
||||
balance.setAmount(BigDecimal.ZERO);
|
||||
balance.setTotalRechargeAmount(BigDecimal.ZERO);
|
||||
balance.setLastUpdateTime(LocalDateTime.now());
|
||||
balanceMapper.insert(balance);
|
||||
return balance;
|
||||
}
|
||||
|
||||
private VipInfoDO getVipInfo(Long userId) {
|
||||
return vipInfoMapper.selectOne(
|
||||
Wrappers.lambdaQuery(VipInfoDO.class)
|
||||
.eq(VipInfoDO::getUserId, userId)
|
||||
.last("limit 1"));
|
||||
}
|
||||
|
||||
private VipInfoDO getOrCreateVipInfo(Long userId) {
|
||||
VipInfoDO vipInfo = getVipInfo(userId);
|
||||
if (vipInfo != null) {
|
||||
return vipInfo;
|
||||
}
|
||||
vipInfo = new VipInfoDO();
|
||||
vipInfo.setUserId(userId);
|
||||
vipInfo.setVipLevel(VIP_LEVEL_NORMAL);
|
||||
vipInfo.setManualOverride(0);
|
||||
vipInfo.setActivationMethod("INIT");
|
||||
vipInfo.setStartTime(LocalDateTime.now());
|
||||
vipInfoMapper.insert(vipInfo);
|
||||
return vipInfo;
|
||||
}
|
||||
|
||||
private UserDO getAvailableUser(Long userId) {
|
||||
UserDO user = userMapper.selectById(userId);
|
||||
if (user == null || Integer.valueOf(1).equals(user.getIsDelete())) {
|
||||
throw new RuntimeException("用户不存在");
|
||||
}
|
||||
return user;
|
||||
}
|
||||
|
||||
private BigDecimal defaultDecimal(BigDecimal value) {
|
||||
return value == null ? BigDecimal.ZERO : value;
|
||||
}
|
||||
|
||||
private UserAssetVO toAssetVO(UserDO user, BalanceDO balance, VipInfoDO vipInfo, VipBenefitDO benefit) {
|
||||
UserAssetVO vo = new UserAssetVO();
|
||||
vo.setUserId(user.getId());
|
||||
vo.setNickname(user.getNickname());
|
||||
vo.setBalance(defaultDecimal(balance != null ? balance.getAmount() : null));
|
||||
vo.setTotalRechargeAmount(defaultDecimal(balance != null ? balance.getTotalRechargeAmount() : null));
|
||||
vo.setLastRechargeTime(balance != null ? balance.getLastRechargeTime() : null);
|
||||
vo.setVipInfoId(vipInfo != null ? vipInfo.getId() : null);
|
||||
vo.setVipLevel(StringUtils.hasText(user.getLevel()) ? user.getLevel() : VIP_LEVEL_NORMAL);
|
||||
vo.setBenefitId(vipInfo != null ? vipInfo.getBenefitId() : null);
|
||||
vo.setBenefitInfo(benefit != null ? benefit.getBenefitInfo() : null);
|
||||
vo.setManualOverride(vipInfo != null && Integer.valueOf(1).equals(vipInfo.getManualOverride()));
|
||||
vo.setVipStartTime(vipInfo != null ? vipInfo.getStartTime() : null);
|
||||
vo.setVipExpireTime(vipInfo != null ? vipInfo.getExpireTime() : null);
|
||||
return vo;
|
||||
}
|
||||
|
||||
private BalanceChangeDetailVO toBalanceHistoryVO(BalanceChangeDetailDO detail, String nickname) {
|
||||
BalanceChangeDetailVO vo = new BalanceChangeDetailVO();
|
||||
vo.setId(detail.getId());
|
||||
vo.setUserId(detail.getUserId());
|
||||
vo.setUserNickname(nickname);
|
||||
vo.setAmount(detail.getAmount());
|
||||
vo.setType(detail.getType());
|
||||
vo.setCurrentBalance(detail.getCurrentBalance());
|
||||
vo.setBeforeBalance(detail.getBeforeBalance());
|
||||
vo.setAfterBalance(detail.getAfterBalance());
|
||||
vo.setChangeScene(detail.getChangeScene());
|
||||
vo.setRelatedOrderId(detail.getRelatedOrderId());
|
||||
vo.setRelatedOrderNo(detail.getRelatedOrderNo());
|
||||
vo.setExternalOrderNo(detail.getExternalOrderNo());
|
||||
vo.setOperatorId(detail.getOperatorId());
|
||||
vo.setRemark(detail.getRemark());
|
||||
vo.setChangeTime(detail.getChangeTime());
|
||||
return vo;
|
||||
}
|
||||
}
|
||||
+20
-4
@@ -43,6 +43,8 @@ import java.util.stream.Collectors;
|
||||
@RequiredArgsConstructor
|
||||
public class UserServiceImpl extends ServiceImpl<UserMapper, UserDO> implements UserService {
|
||||
|
||||
private static final String VIP_LEVEL_NORMAL = "普通";
|
||||
|
||||
// 注入用户数据访问层、JWT工具类和店铺服务
|
||||
private final UserMapper userMapper;
|
||||
private final JwtUtil jwtUtil;
|
||||
@@ -87,6 +89,15 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, UserDO> implements
|
||||
// 设置默认头像
|
||||
String defaultAvatar = "https://cube.elemecdn.com/3/7c/3ea6beec64369c2642b92c6726f1epng.png";
|
||||
userDO.setAvatar(defaultAvatar);
|
||||
|
||||
if (Integer.valueOf(0).equals(userDO.getType())) {
|
||||
if (!StringUtils.hasText(userDO.getLevel())) {
|
||||
userDO.setLevel(VIP_LEVEL_NORMAL);
|
||||
}
|
||||
if (userDO.getVipId() == null) {
|
||||
userDO.setVipId(0L);
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
// 插入用户数据
|
||||
@@ -146,8 +157,9 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, UserDO> implements
|
||||
permissions = permissionMapper.selectList(
|
||||
Wrappers.lambdaQuery(PermissionDO.class)
|
||||
.eq(PermissionDO::getIsDelete, 0)
|
||||
.in(PermissionDO::getPermissionCode, "home:view", "dashboard:view", "user:view",
|
||||
"user:create", "user:edit", "user:reset_password", "user:delete",
|
||||
.in(PermissionDO::getPermissionCode, "home:view", "dashboard:view", "user:view",
|
||||
"user:create", "user:edit", "user:disable", "user:reset_password", "user:delete",
|
||||
"user:balance:view", "user:balance:manage", "user:vip:manage",
|
||||
"product:view", "product:create", "product:edit", "product:delete",
|
||||
"product:category:manage", "shop:view", "shop:create", "shop:edit",
|
||||
"shop:delete", "shop:staff:manage", "permission:view", "permission:create",
|
||||
@@ -496,7 +508,8 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, UserDO> implements
|
||||
userDO.setPhoneVerified(1);
|
||||
userDO.setNickname("用户" + phone.substring(7));
|
||||
userDO.setType(0);
|
||||
userDO.setLevel("普通");
|
||||
userDO.setLevel(VIP_LEVEL_NORMAL);
|
||||
userDO.setVipId(0L);
|
||||
userDO.setShopId(shopId);
|
||||
userDO.setIsDelete(0);
|
||||
userDO.setStatus(1);
|
||||
@@ -505,6 +518,7 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, UserDO> implements
|
||||
userDO.setPassword(ENCODED_UNSET_PASSWORD);
|
||||
|
||||
userMapper.insert(userDO);
|
||||
assignDefaultPermissions(userDO.getId(), userDO.getType());
|
||||
return userDO;
|
||||
}
|
||||
|
||||
@@ -582,12 +596,14 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, UserDO> implements
|
||||
userDO.setPhone(registerRequestDTO.getPhone());
|
||||
userDO.setPhoneVerified(1);
|
||||
userDO.setType(Integer.valueOf(0));
|
||||
userDO.setLevel("普通");
|
||||
userDO.setLevel(VIP_LEVEL_NORMAL);
|
||||
userDO.setVipId(0L);
|
||||
userDO.setIsDelete(Integer.valueOf(0));
|
||||
userDO.setCreateTime(LocalDateTime.now());
|
||||
userDO.setUpdateTime(LocalDateTime.now());
|
||||
|
||||
userMapper.insert(userDO);
|
||||
assignDefaultPermissions(userDO.getId(), userDO.getType());
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
+6
@@ -29,11 +29,13 @@ public class VipInfoServiceImpl extends ServiceImpl<VipInfoMapper, VipInfoDO> im
|
||||
@Override
|
||||
public Long createVipInfo(VipInfoDTO vipInfoDTO) {
|
||||
VipInfoDO vipInfoDO = new VipInfoDO();
|
||||
vipInfoDO.setUserId(vipInfoDTO.getUserId());
|
||||
vipInfoDO.setVipLevel(vipInfoDTO.getVipLevel());
|
||||
vipInfoDO.setStartTime(vipInfoDTO.getStartTime());
|
||||
vipInfoDO.setExpireTime(vipInfoDTO.getExpireTime());
|
||||
vipInfoDO.setActivationMethod(vipInfoDTO.getActivationMethod());
|
||||
vipInfoDO.setBenefitId(vipInfoDTO.getBenefitId());
|
||||
vipInfoDO.setManualOverride(vipInfoDTO.getManualOverride());
|
||||
vipInfoMapper.insert(vipInfoDO);
|
||||
return vipInfoDO.getId();
|
||||
}
|
||||
@@ -44,11 +46,13 @@ public class VipInfoServiceImpl extends ServiceImpl<VipInfoMapper, VipInfoDO> im
|
||||
if (vipInfoDO == null) {
|
||||
return false;
|
||||
}
|
||||
vipInfoDO.setUserId(vipInfoDTO.getUserId());
|
||||
vipInfoDO.setVipLevel(vipInfoDTO.getVipLevel());
|
||||
vipInfoDO.setStartTime(vipInfoDTO.getStartTime());
|
||||
vipInfoDO.setExpireTime(vipInfoDTO.getExpireTime());
|
||||
vipInfoDO.setActivationMethod(vipInfoDTO.getActivationMethod());
|
||||
vipInfoDO.setBenefitId(vipInfoDTO.getBenefitId());
|
||||
vipInfoDO.setManualOverride(vipInfoDTO.getManualOverride());
|
||||
return vipInfoMapper.updateById(vipInfoDO) > 0;
|
||||
}
|
||||
|
||||
@@ -94,11 +98,13 @@ public class VipInfoServiceImpl extends ServiceImpl<VipInfoMapper, VipInfoDO> im
|
||||
private VipInfoVO convertToVO(VipInfoDO vipInfoDO) {
|
||||
VipInfoVO vipInfoVO = new VipInfoVO();
|
||||
vipInfoVO.setId(vipInfoDO.getId());
|
||||
vipInfoVO.setUserId(vipInfoDO.getUserId());
|
||||
vipInfoVO.setVipLevel(vipInfoDO.getVipLevel());
|
||||
vipInfoVO.setStartTime(vipInfoDO.getStartTime());
|
||||
vipInfoVO.setExpireTime(vipInfoDO.getExpireTime());
|
||||
vipInfoVO.setActivationMethod(vipInfoDO.getActivationMethod());
|
||||
vipInfoVO.setBenefitId(vipInfoDO.getBenefitId());
|
||||
vipInfoVO.setManualOverride(vipInfoDO.getManualOverride());
|
||||
vipInfoVO.setCreateTime(vipInfoDO.getCreateTime());
|
||||
vipInfoVO.setUpdateTime(vipInfoDO.getUpdateTime());
|
||||
return vipInfoVO;
|
||||
|
||||
@@ -44,6 +44,14 @@ public class BalanceChangeDetailVO {
|
||||
* 变动后的当前余额
|
||||
*/
|
||||
private BigDecimal currentBalance;
|
||||
private BigDecimal beforeBalance;
|
||||
private BigDecimal afterBalance;
|
||||
private String changeScene;
|
||||
private Long relatedOrderId;
|
||||
private String relatedOrderNo;
|
||||
private String externalOrderNo;
|
||||
private Long operatorId;
|
||||
private String remark;
|
||||
|
||||
/**
|
||||
* 变动时间
|
||||
|
||||
@@ -34,6 +34,8 @@ public class BalanceVO {
|
||||
* 当前余额
|
||||
*/
|
||||
private BigDecimal amount;
|
||||
private BigDecimal totalRechargeAmount;
|
||||
private LocalDateTime lastRechargeTime;
|
||||
|
||||
/**
|
||||
* 余额账户创建时间
|
||||
|
||||
@@ -96,6 +96,9 @@ public class CouponVO {
|
||||
* 所属店铺名称
|
||||
*/
|
||||
private String shopName;
|
||||
private String couponScene;
|
||||
private String requiredVipLevel;
|
||||
private Integer autoMatch;
|
||||
|
||||
/**
|
||||
* 可用标签列表
|
||||
|
||||
@@ -15,9 +15,11 @@ public class OrderVO {
|
||||
private BigDecimal totalAmount;
|
||||
private BigDecimal actualAmount;
|
||||
private Long couponId;
|
||||
private Long userCouponId;
|
||||
private String couponSourceType;
|
||||
private String couponName;
|
||||
private Integer status;
|
||||
private String statusText;
|
||||
private LocalDateTime createTime;
|
||||
private List<OrderItemVO> items;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,34 @@
|
||||
package com.xiaowang.yuminailcore.vo;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
@Data
|
||||
public class UserAssetVO {
|
||||
|
||||
private Long userId;
|
||||
|
||||
private String nickname;
|
||||
|
||||
private BigDecimal balance;
|
||||
|
||||
private BigDecimal totalRechargeAmount;
|
||||
|
||||
private LocalDateTime lastRechargeTime;
|
||||
|
||||
private Long vipInfoId;
|
||||
|
||||
private String vipLevel;
|
||||
|
||||
private Long benefitId;
|
||||
|
||||
private String benefitInfo;
|
||||
|
||||
private Boolean manualOverride;
|
||||
|
||||
private LocalDateTime vipStartTime;
|
||||
|
||||
private LocalDateTime vipExpireTime;
|
||||
}
|
||||
@@ -79,4 +79,7 @@ public class UserCouponVO {
|
||||
* 使用时间
|
||||
*/
|
||||
private LocalDateTime useTime;
|
||||
private String sourceType;
|
||||
private String requiredVipLevel;
|
||||
private Boolean autoMatched;
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@ package com.xiaowang.yuminailcore.vo;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
/**
|
||||
@@ -28,6 +29,9 @@ public class VipBenefitVO {
|
||||
* 所需VIP等级
|
||||
*/
|
||||
private String requiredVipLevel;
|
||||
private Integer levelRank;
|
||||
private BigDecimal rechargeThreshold;
|
||||
private Integer status;
|
||||
|
||||
/**
|
||||
* 创建时间
|
||||
|
||||
@@ -14,6 +14,8 @@ import java.time.LocalDateTime;
|
||||
@Data
|
||||
public class VipInfoVO {
|
||||
|
||||
private Long userId;
|
||||
|
||||
/**
|
||||
* VIP信息唯一主键ID(雪花ID)
|
||||
*/
|
||||
@@ -48,6 +50,7 @@ public class VipInfoVO {
|
||||
* 权益详情
|
||||
*/
|
||||
private String benefitInfo;
|
||||
private Integer manualOverride;
|
||||
|
||||
/**
|
||||
* 创建时间
|
||||
|
||||
+501
@@ -0,0 +1,501 @@
|
||||
-- 2026-03-20 用户资产 / VIP / 优惠券 / 权限增量补丁
|
||||
-- 适用前提:已先执行 YumiNail.sql 完成基础建表
|
||||
-- 执行说明:
|
||||
-- 1. 本文件只做增量修正,不覆盖原始 YumiNail.sql
|
||||
-- 2. 可用于空库初始化后的补丁,也可用于已有库的结构与初始化对齐
|
||||
-- 3. 历史累计充值金额无法从旧表精确反推,本补丁仅把缺失值归零;如需保留历史累计充值,请按业务数据手工回填 total_recharge_amount
|
||||
|
||||
SET NAMES utf8mb4;
|
||||
|
||||
DROP PROCEDURE IF EXISTS sp_add_column_if_not_exists;
|
||||
DROP PROCEDURE IF EXISTS sp_add_index_if_not_exists;
|
||||
DROP PROCEDURE IF EXISTS sp_add_unique_index_if_not_exists;
|
||||
|
||||
DELIMITER $$
|
||||
|
||||
CREATE PROCEDURE sp_add_column_if_not_exists(
|
||||
IN p_table_name VARCHAR(64),
|
||||
IN p_column_name VARCHAR(64),
|
||||
IN p_definition TEXT
|
||||
)
|
||||
BEGIN
|
||||
IF NOT EXISTS (
|
||||
SELECT 1
|
||||
FROM information_schema.COLUMNS
|
||||
WHERE TABLE_SCHEMA = DATABASE()
|
||||
AND TABLE_NAME = p_table_name
|
||||
AND COLUMN_NAME = p_column_name
|
||||
) THEN
|
||||
SET @sql = CONCAT(
|
||||
'ALTER TABLE `', p_table_name, '` ADD COLUMN `', p_column_name, '` ',
|
||||
p_definition
|
||||
);
|
||||
PREPARE stmt FROM @sql;
|
||||
EXECUTE stmt;
|
||||
DEALLOCATE PREPARE stmt;
|
||||
END IF;
|
||||
END$$
|
||||
|
||||
CREATE PROCEDURE sp_add_index_if_not_exists(
|
||||
IN p_table_name VARCHAR(64),
|
||||
IN p_index_name VARCHAR(64),
|
||||
IN p_columns TEXT
|
||||
)
|
||||
BEGIN
|
||||
IF NOT EXISTS (
|
||||
SELECT 1
|
||||
FROM information_schema.STATISTICS
|
||||
WHERE TABLE_SCHEMA = DATABASE()
|
||||
AND TABLE_NAME = p_table_name
|
||||
AND INDEX_NAME = p_index_name
|
||||
) THEN
|
||||
SET @sql = CONCAT(
|
||||
'ALTER TABLE `', p_table_name, '` ADD INDEX `', p_index_name, '` ',
|
||||
p_columns
|
||||
);
|
||||
PREPARE stmt FROM @sql;
|
||||
EXECUTE stmt;
|
||||
DEALLOCATE PREPARE stmt;
|
||||
END IF;
|
||||
END$$
|
||||
|
||||
CREATE PROCEDURE sp_add_unique_index_if_not_exists(
|
||||
IN p_table_name VARCHAR(64),
|
||||
IN p_index_name VARCHAR(64),
|
||||
IN p_columns TEXT
|
||||
)
|
||||
BEGIN
|
||||
IF NOT EXISTS (
|
||||
SELECT 1
|
||||
FROM information_schema.STATISTICS
|
||||
WHERE TABLE_SCHEMA = DATABASE()
|
||||
AND TABLE_NAME = p_table_name
|
||||
AND INDEX_NAME = p_index_name
|
||||
) THEN
|
||||
SET @sql = CONCAT(
|
||||
'ALTER TABLE `', p_table_name, '` ADD UNIQUE INDEX `', p_index_name, '` ',
|
||||
p_columns
|
||||
);
|
||||
PREPARE stmt FROM @sql;
|
||||
EXECUTE stmt;
|
||||
DEALLOCATE PREPARE stmt;
|
||||
END IF;
|
||||
END$$
|
||||
|
||||
DELIMITER ;
|
||||
|
||||
CALL sp_add_column_if_not_exists('t_balance', 'total_recharge_amount', 'decimal(10,2) NOT NULL DEFAULT 0.00 COMMENT ''累计充值金额''');
|
||||
CALL sp_add_column_if_not_exists('t_balance', 'last_recharge_time', 'datetime NULL COMMENT ''最近一次充值时间''');
|
||||
|
||||
UPDATE t_balance
|
||||
SET total_recharge_amount = COALESCE(total_recharge_amount, 0.00)
|
||||
WHERE total_recharge_amount IS NULL;
|
||||
|
||||
CALL sp_add_column_if_not_exists('t_balance_change_detail', 'before_balance', 'decimal(10,2) NULL COMMENT ''变动前余额''');
|
||||
CALL sp_add_column_if_not_exists('t_balance_change_detail', 'after_balance', 'decimal(10,2) NULL COMMENT ''变动后余额''');
|
||||
CALL sp_add_column_if_not_exists('t_balance_change_detail', 'change_scene', 'varchar(32) NULL COMMENT ''余额变动场景''');
|
||||
CALL sp_add_column_if_not_exists('t_balance_change_detail', 'related_order_id', 'bigint unsigned NULL COMMENT ''关联系统订单ID''');
|
||||
CALL sp_add_column_if_not_exists('t_balance_change_detail', 'related_order_no', 'varchar(64) NULL COMMENT ''关联系统订单号''');
|
||||
CALL sp_add_column_if_not_exists('t_balance_change_detail', 'external_order_no', 'varchar(64) NULL COMMENT ''手工录入的外部订单号''');
|
||||
CALL sp_add_column_if_not_exists('t_balance_change_detail', 'operator_id', 'bigint unsigned NULL COMMENT ''操作人ID''');
|
||||
CALL sp_add_column_if_not_exists('t_balance_change_detail', 'remark', 'varchar(255) NULL COMMENT ''备注''');
|
||||
|
||||
UPDATE t_balance_change_detail
|
||||
SET before_balance = COALESCE(before_balance, current_balance - amount),
|
||||
after_balance = COALESCE(after_balance, current_balance),
|
||||
change_scene = COALESCE(NULLIF(change_scene, ''), type)
|
||||
WHERE before_balance IS NULL
|
||||
OR after_balance IS NULL
|
||||
OR change_scene IS NULL
|
||||
OR change_scene = '';
|
||||
|
||||
CALL sp_add_index_if_not_exists('t_balance_change_detail', 'idx_balance_detail_related_order_id', '(`related_order_id`)');
|
||||
CALL sp_add_index_if_not_exists('t_balance_change_detail', 'idx_balance_detail_operator_id', '(`operator_id`)');
|
||||
|
||||
CALL sp_add_column_if_not_exists('t_order', 'shop_id', 'bigint unsigned NULL COMMENT ''所属店铺ID''');
|
||||
CALL sp_add_column_if_not_exists('t_order', 'user_coupon_id', 'bigint unsigned NULL COMMENT ''用户券ID''');
|
||||
CALL sp_add_column_if_not_exists('t_order', 'coupon_source_type', 'varchar(32) NULL COMMENT ''优惠来源类型''');
|
||||
|
||||
UPDATE t_order
|
||||
SET coupon_id = NULL
|
||||
WHERE coupon_id = 0;
|
||||
|
||||
UPDATE t_order o
|
||||
INNER JOIN (
|
||||
SELECT oi.order_id, MIN(p.shop_id) AS resolved_shop_id
|
||||
FROM t_order_item oi
|
||||
INNER JOIN t_product p ON p.id = oi.product_id
|
||||
GROUP BY oi.order_id
|
||||
) detail_shop ON detail_shop.order_id = o.id
|
||||
SET o.shop_id = detail_shop.resolved_shop_id
|
||||
WHERE o.shop_id IS NULL;
|
||||
|
||||
UPDATE t_order
|
||||
SET coupon_source_type = 'USER_COUPON'
|
||||
WHERE coupon_source_type IS NULL
|
||||
AND coupon_id IS NOT NULL;
|
||||
|
||||
CALL sp_add_index_if_not_exists('t_order', 'idx_t_order_shop_id', '(`shop_id`)');
|
||||
CALL sp_add_index_if_not_exists('t_order', 'idx_t_order_coupon_source_type', '(`coupon_source_type`)');
|
||||
|
||||
CALL sp_add_column_if_not_exists('t_order_item', 'appointment_time', 'datetime NULL COMMENT ''预约开始时间''');
|
||||
CALL sp_add_index_if_not_exists('t_order_item', 'idx_t_order_item_artist_appointment_time', '(`artist_id`, `appointment_time`)');
|
||||
|
||||
CALL sp_add_column_if_not_exists('t_coupon', 'coupon_scene', 'varchar(32) NOT NULL DEFAULT ''NORMAL'' COMMENT ''优惠券场景''');
|
||||
CALL sp_add_column_if_not_exists('t_coupon', 'required_vip_level', 'varchar(20) NULL COMMENT ''要求的VIP等级''');
|
||||
CALL sp_add_column_if_not_exists('t_coupon', 'auto_match', 'tinyint unsigned NOT NULL DEFAULT 0 COMMENT ''是否自动匹配''');
|
||||
|
||||
UPDATE t_coupon
|
||||
SET coupon_scene = COALESCE(NULLIF(coupon_scene, ''), 'NORMAL'),
|
||||
auto_match = COALESCE(auto_match, 0)
|
||||
WHERE coupon_scene IS NULL
|
||||
OR coupon_scene = ''
|
||||
OR auto_match IS NULL;
|
||||
|
||||
CALL sp_add_index_if_not_exists('t_coupon', 'idx_t_coupon_scene_auto_match', '(`coupon_scene`, `auto_match`)');
|
||||
CALL sp_add_index_if_not_exists('t_coupon', 'idx_t_coupon_required_vip_level', '(`required_vip_level`)');
|
||||
|
||||
CALL sp_add_column_if_not_exists('t_vip_benefit', 'level_rank', 'int NOT NULL DEFAULT 0 COMMENT ''等级序号''');
|
||||
CALL sp_add_column_if_not_exists('t_vip_benefit', 'recharge_threshold', 'decimal(10,2) NOT NULL DEFAULT 0.00 COMMENT ''累计充值门槛''');
|
||||
CALL sp_add_column_if_not_exists('t_vip_benefit', 'status', 'tinyint unsigned NOT NULL DEFAULT 1 COMMENT ''状态''');
|
||||
|
||||
UPDATE t_vip_benefit
|
||||
SET level_rank = CASE required_vip_level
|
||||
WHEN '普通' THEN 0
|
||||
WHEN '青铜' THEN 1
|
||||
WHEN '白银' THEN 2
|
||||
WHEN '黄金' THEN 3
|
||||
ELSE level_rank
|
||||
END,
|
||||
recharge_threshold = CASE required_vip_level
|
||||
WHEN '普通' THEN 0.00
|
||||
WHEN '青铜' THEN 500.00
|
||||
WHEN '白银' THEN 1000.00
|
||||
WHEN '黄金' THEN 2000.00
|
||||
ELSE recharge_threshold
|
||||
END,
|
||||
status = COALESCE(status, 1)
|
||||
WHERE required_vip_level IN ('普通', '青铜', '白银', '黄金');
|
||||
|
||||
CALL sp_add_index_if_not_exists('t_vip_benefit', 'idx_t_vip_benefit_status_rank', '(`status`, `level_rank`)');
|
||||
|
||||
CALL sp_add_column_if_not_exists('t_vip_info', 'user_id', 'bigint unsigned NULL COMMENT ''所属用户ID''');
|
||||
CALL sp_add_column_if_not_exists('t_vip_info', 'manual_override', 'tinyint unsigned NOT NULL DEFAULT 0 COMMENT ''是否手工覆盖VIP等级''');
|
||||
|
||||
ALTER TABLE t_vip_info
|
||||
MODIFY COLUMN expire_time datetime NULL COMMENT 'VIP到期时间',
|
||||
MODIFY COLUMN benefit_id bigint unsigned NULL COMMENT '关联VIP权益信息表主键';
|
||||
|
||||
UPDATE t_vip_info vi
|
||||
INNER JOIN t_user u ON u.vip_id = vi.id
|
||||
SET vi.user_id = u.id
|
||||
WHERE (vi.user_id IS NULL OR vi.user_id = 0)
|
||||
AND u.vip_id IS NOT NULL
|
||||
AND u.vip_id <> 0;
|
||||
|
||||
UPDATE t_vip_info
|
||||
SET start_time = COALESCE(start_time, create_time, NOW()),
|
||||
activation_method = COALESCE(NULLIF(activation_method, ''), 'INIT'),
|
||||
manual_override = COALESCE(manual_override, 0);
|
||||
|
||||
CALL sp_add_unique_index_if_not_exists('t_vip_info', 'uk_t_vip_info_user_id', '(`user_id`)');
|
||||
CALL sp_add_index_if_not_exists('t_vip_info', 'idx_t_vip_info_manual_override', '(`manual_override`)');
|
||||
|
||||
UPDATE t_user u
|
||||
LEFT JOIN t_vip_info vi ON vi.id = u.vip_id
|
||||
SET u.level = CASE
|
||||
WHEN u.type = 0 AND u.vip_id IS NOT NULL AND u.vip_id <> 0 AND vi.vip_level IS NOT NULL THEN vi.vip_level
|
||||
WHEN u.type = 0 THEN '普通'
|
||||
ELSE u.level
|
||||
END,
|
||||
u.vip_id = CASE
|
||||
WHEN u.type = 0 AND u.vip_id IS NULL THEN 0
|
||||
ELSE u.vip_id
|
||||
END,
|
||||
u.update_time = NOW()
|
||||
WHERE u.is_delete = 0
|
||||
AND u.type = 0
|
||||
AND (u.level IS NULL OR u.level = '' OR u.vip_id IS NULL);
|
||||
|
||||
INSERT INTO t_permission (permission_code, permission_name, permission_group, description, create_time, update_time, is_delete)
|
||||
VALUES
|
||||
('home:view', '查看首页', '首页', '查看系统首页入口与概览', NOW(), NOW(), 0),
|
||||
('dashboard:view', '查看仪表盘', '仪表盘', '查看后台仪表盘统计', NOW(), NOW(), 0),
|
||||
('user:view', '查看用户', '用户管理', '查看用户列表与详情', NOW(), NOW(), 0),
|
||||
('user:create', '新增用户', '用户管理', '创建用户账号', NOW(), NOW(), 0),
|
||||
('user:edit', '编辑用户', '用户管理', '修改用户基础信息', NOW(), NOW(), 0),
|
||||
('user:disable', '启停用户', '用户管理', '启用或禁用用户账号', NOW(), NOW(), 0),
|
||||
('user:reset_password', '重置密码', '用户管理', '重置用户密码', NOW(), NOW(), 0),
|
||||
('user:delete', '删除用户', '用户管理', '删除用户账号', NOW(), NOW(), 0),
|
||||
('user:balance:view', '查看余额资产', '用户资产', '查看用户余额、累计充值与流水', NOW(), NOW(), 0),
|
||||
('user:balance:manage', '调整余额', '用户资产', '充值、手工加减余额与关联订单', NOW(), NOW(), 0),
|
||||
('user:vip:manage', '管理VIP', '用户资产', '手工设置VIP等级或恢复自动判级', NOW(), NOW(), 0),
|
||||
('product:view', '查看商品', '商品管理', '查看商品列表与详情', NOW(), NOW(), 0),
|
||||
('product:create', '新增商品', '商品管理', '创建商品', NOW(), NOW(), 0),
|
||||
('product:edit', '编辑商品', '商品管理', '编辑商品信息', NOW(), NOW(), 0),
|
||||
('product:delete', '删除商品', '商品管理', '删除商品', NOW(), NOW(), 0),
|
||||
('product:category:manage', '管理商品分类', '商品管理', '维护商品分类与归类信息', NOW(), NOW(), 0),
|
||||
('shop:view', '查看店铺', '店铺管理', '查看店铺列表与详情', NOW(), NOW(), 0),
|
||||
('shop:create', '新增店铺', '店铺管理', '创建店铺', NOW(), NOW(), 0),
|
||||
('shop:edit', '编辑店铺', '店铺管理', '编辑店铺信息', NOW(), NOW(), 0),
|
||||
('shop:delete', '删除店铺', '店铺管理', '删除店铺', NOW(), NOW(), 0),
|
||||
('shop:staff:manage', '管理员工', '店铺管理', '管理店铺员工与归属', NOW(), NOW(), 0),
|
||||
('permission:view', '查看权限', '权限管理', '查看权限清单', NOW(), NOW(), 0),
|
||||
('permission:create', '新增权限', '权限管理', '新增系统权限定义', NOW(), NOW(), 0),
|
||||
('permission:edit', '编辑权限', '权限管理', '编辑系统权限定义', NOW(), NOW(), 0),
|
||||
('permission:delete', '删除权限', '权限管理', '删除系统权限定义', NOW(), NOW(), 0),
|
||||
('permission:assign', '分配权限', '权限管理', '给用户分配后台权限', NOW(), NOW(), 0),
|
||||
('tag:view', '查看标签', '标签管理', '查看标签列表与详情', NOW(), NOW(), 0),
|
||||
('tag:create', '新增标签', '标签管理', '创建标签', NOW(), NOW(), 0),
|
||||
('tag:edit', '编辑标签', '标签管理', '编辑标签', NOW(), NOW(), 0),
|
||||
('tag:delete', '删除标签', '标签管理', '删除标签', NOW(), NOW(), 0),
|
||||
('tag:assign', '分配标签', '标签管理', '给商品或优惠券分配标签', NOW(), NOW(), 0),
|
||||
('coupon:view', '查看优惠券', '优惠券管理', '查看优惠券与发放情况', NOW(), NOW(), 0),
|
||||
('coupon:create', '新增优惠券', '优惠券管理', '创建优惠券模板', NOW(), NOW(), 0),
|
||||
('coupon:edit', '编辑优惠券', '优惠券管理', '编辑优惠券模板', NOW(), NOW(), 0),
|
||||
('coupon:delete', '删除优惠券', '优惠券管理', '删除优惠券模板', NOW(), NOW(), 0),
|
||||
('coupon:assign', '发放优惠券', '优惠券管理', '向用户发放普通优惠券', NOW(), NOW(), 0),
|
||||
('order:view', '查看订单', '订单管理', '查看订单列表与详情', NOW(), NOW(), 0),
|
||||
('order:process', '处理订单', '订单管理', '处理订单状态或由美甲师完结订单', NOW(), NOW(), 0),
|
||||
('order:edit', '编辑订单', '订单管理', '编辑订单信息的预留权限', NOW(), NOW(), 0),
|
||||
('order:delete', '删除订单', '订单管理', '删除订单的预留权限', NOW(), NOW(), 0),
|
||||
('nail_artist:view', '查看美甲师', '美甲师管理', '查看美甲师信息与排班入口', NOW(), NOW(), 0),
|
||||
('nail_artist:edit', '编辑美甲师', '美甲师管理', '编辑美甲师信息', NOW(), NOW(), 0)
|
||||
ON DUPLICATE KEY UPDATE
|
||||
permission_name = VALUES(permission_name),
|
||||
permission_group = VALUES(permission_group),
|
||||
description = VALUES(description),
|
||||
update_time = NOW(),
|
||||
is_delete = 0;
|
||||
|
||||
INSERT INTO t_user_permission (user_id, permission_id, create_time, update_time, create_by, update_by, is_delete)
|
||||
SELECT u.id, p.id, NOW(), NOW(), u.id, u.id, 0
|
||||
FROM t_user u
|
||||
INNER JOIN t_permission p ON p.is_delete = 0
|
||||
WHERE u.is_delete = 0
|
||||
AND u.type = 4
|
||||
AND NOT EXISTS (
|
||||
SELECT 1
|
||||
FROM t_user_permission up
|
||||
WHERE up.user_id = u.id
|
||||
AND up.permission_id = p.id
|
||||
);
|
||||
|
||||
INSERT INTO t_user_permission (user_id, permission_id, create_time, update_time, create_by, update_by, is_delete)
|
||||
SELECT u.id, p.id, NOW(), NOW(), u.id, u.id, 0
|
||||
FROM t_user u
|
||||
INNER JOIN t_permission p
|
||||
ON p.is_delete = 0
|
||||
AND p.permission_code IN (
|
||||
'home:view',
|
||||
'dashboard:view',
|
||||
'user:view',
|
||||
'user:create',
|
||||
'user:edit',
|
||||
'user:disable',
|
||||
'user:reset_password',
|
||||
'user:delete',
|
||||
'user:balance:view',
|
||||
'user:balance:manage',
|
||||
'user:vip:manage',
|
||||
'product:view',
|
||||
'product:create',
|
||||
'product:edit',
|
||||
'product:delete',
|
||||
'product:category:manage',
|
||||
'shop:view',
|
||||
'shop:create',
|
||||
'shop:edit',
|
||||
'shop:delete',
|
||||
'shop:staff:manage',
|
||||
'permission:view',
|
||||
'permission:create',
|
||||
'permission:edit',
|
||||
'permission:delete',
|
||||
'permission:assign',
|
||||
'tag:view',
|
||||
'tag:create',
|
||||
'tag:edit',
|
||||
'tag:delete',
|
||||
'tag:assign',
|
||||
'coupon:view',
|
||||
'coupon:create',
|
||||
'coupon:edit',
|
||||
'coupon:delete',
|
||||
'coupon:assign',
|
||||
'order:view',
|
||||
'order:edit',
|
||||
'order:delete',
|
||||
'order:process'
|
||||
)
|
||||
WHERE u.is_delete = 0
|
||||
AND u.type = 2
|
||||
AND NOT EXISTS (
|
||||
SELECT 1
|
||||
FROM t_user_permission up
|
||||
WHERE up.user_id = u.id
|
||||
AND up.permission_id = p.id
|
||||
);
|
||||
|
||||
INSERT INTO t_user_permission (user_id, permission_id, create_time, update_time, create_by, update_by, is_delete)
|
||||
SELECT u.id, p.id, NOW(), NOW(), u.id, u.id, 0
|
||||
FROM t_user u
|
||||
INNER JOIN t_permission p
|
||||
ON p.is_delete = 0
|
||||
AND p.permission_code IN (
|
||||
'home:view',
|
||||
'dashboard:view',
|
||||
'user:view',
|
||||
'user:create',
|
||||
'user:reset_password',
|
||||
'product:view',
|
||||
'product:create',
|
||||
'product:edit',
|
||||
'product:category:manage',
|
||||
'shop:view',
|
||||
'tag:view',
|
||||
'tag:create',
|
||||
'tag:edit',
|
||||
'tag:assign',
|
||||
'coupon:view',
|
||||
'coupon:assign',
|
||||
'order:view',
|
||||
'order:process'
|
||||
)
|
||||
WHERE u.is_delete = 0
|
||||
AND u.type = 3
|
||||
AND NOT EXISTS (
|
||||
SELECT 1
|
||||
FROM t_user_permission up
|
||||
WHERE up.user_id = u.id
|
||||
AND up.permission_id = p.id
|
||||
);
|
||||
|
||||
INSERT INTO t_user_permission (user_id, permission_id, create_time, update_time, create_by, update_by, is_delete)
|
||||
SELECT u.id, p.id, NOW(), NOW(), u.id, u.id, 0
|
||||
FROM t_user u
|
||||
INNER JOIN t_permission p
|
||||
ON p.is_delete = 0
|
||||
AND p.permission_code IN (
|
||||
'home:view',
|
||||
'dashboard:view',
|
||||
'product:view',
|
||||
'tag:view',
|
||||
'shop:view',
|
||||
'order:view'
|
||||
)
|
||||
WHERE u.is_delete = 0
|
||||
AND u.type = 0
|
||||
AND NOT EXISTS (
|
||||
SELECT 1
|
||||
FROM t_user_permission up
|
||||
WHERE up.user_id = u.id
|
||||
AND up.permission_id = p.id
|
||||
);
|
||||
|
||||
UPDATE t_vip_benefit
|
||||
SET benefit_info = '普通用户,无额外VIP折扣',
|
||||
level_rank = 0,
|
||||
recharge_threshold = 0.00,
|
||||
status = 1,
|
||||
update_time = NOW()
|
||||
WHERE required_vip_level = '普通';
|
||||
|
||||
INSERT INTO t_vip_benefit (benefit_info, required_vip_level, level_rank, recharge_threshold, status, create_time, update_time)
|
||||
SELECT '普通用户,无额外VIP折扣', '普通', 0, 0.00, 1, NOW(), NOW()
|
||||
WHERE NOT EXISTS (
|
||||
SELECT 1
|
||||
FROM t_vip_benefit
|
||||
WHERE required_vip_level = '普通'
|
||||
);
|
||||
|
||||
UPDATE t_vip_benefit
|
||||
SET benefit_info = '青铜VIP,系统自动匹配9.5折券',
|
||||
level_rank = 1,
|
||||
recharge_threshold = 500.00,
|
||||
status = 1,
|
||||
update_time = NOW()
|
||||
WHERE required_vip_level = '青铜';
|
||||
|
||||
INSERT INTO t_vip_benefit (benefit_info, required_vip_level, level_rank, recharge_threshold, status, create_time, update_time)
|
||||
SELECT '青铜VIP,系统自动匹配9.5折券', '青铜', 1, 500.00, 1, NOW(), NOW()
|
||||
WHERE NOT EXISTS (
|
||||
SELECT 1
|
||||
FROM t_vip_benefit
|
||||
WHERE required_vip_level = '青铜'
|
||||
);
|
||||
|
||||
UPDATE t_vip_benefit
|
||||
SET benefit_info = '白银VIP,系统自动匹配9.2折券',
|
||||
level_rank = 2,
|
||||
recharge_threshold = 1000.00,
|
||||
status = 1,
|
||||
update_time = NOW()
|
||||
WHERE required_vip_level = '白银';
|
||||
|
||||
INSERT INTO t_vip_benefit (benefit_info, required_vip_level, level_rank, recharge_threshold, status, create_time, update_time)
|
||||
SELECT '白银VIP,系统自动匹配9.2折券', '白银', 2, 1000.00, 1, NOW(), NOW()
|
||||
WHERE NOT EXISTS (
|
||||
SELECT 1
|
||||
FROM t_vip_benefit
|
||||
WHERE required_vip_level = '白银'
|
||||
);
|
||||
|
||||
UPDATE t_vip_benefit
|
||||
SET benefit_info = '黄金VIP,系统自动匹配9.0折券',
|
||||
level_rank = 3,
|
||||
recharge_threshold = 2000.00,
|
||||
status = 1,
|
||||
update_time = NOW()
|
||||
WHERE required_vip_level = '黄金';
|
||||
|
||||
INSERT INTO t_vip_benefit (benefit_info, required_vip_level, level_rank, recharge_threshold, status, create_time, update_time)
|
||||
SELECT '黄金VIP,系统自动匹配9.0折券', '黄金', 3, 2000.00, 1, NOW(), NOW()
|
||||
WHERE NOT EXISTS (
|
||||
SELECT 1
|
||||
FROM t_vip_benefit
|
||||
WHERE required_vip_level = '黄金'
|
||||
);
|
||||
|
||||
INSERT INTO t_coupon (
|
||||
coupon_code,
|
||||
coupon_name,
|
||||
coupon_type,
|
||||
discount_value,
|
||||
min_amount,
|
||||
reduce_amount,
|
||||
total_count,
|
||||
used_count,
|
||||
start_time,
|
||||
end_time,
|
||||
status,
|
||||
create_time,
|
||||
update_time,
|
||||
is_delete,
|
||||
shop_id,
|
||||
coupon_scene,
|
||||
required_vip_level,
|
||||
auto_match
|
||||
)
|
||||
VALUES
|
||||
('VIP_AUTO_BRONZE_95', '青铜VIP自动95折券', 1, 9.50, 0.00, 0.00, 999999, 0, NOW(), '2099-12-31 23:59:59', 1, NOW(), NOW(), 0, NULL, 'VIP_AUTO', '青铜', 1),
|
||||
('VIP_AUTO_SILVER_92', '白银VIP自动92折券', 1, 9.20, 0.00, 0.00, 999999, 0, NOW(), '2099-12-31 23:59:59', 1, NOW(), NOW(), 0, NULL, 'VIP_AUTO', '白银', 1),
|
||||
('VIP_AUTO_GOLD_90', '黄金VIP自动90折券', 1, 9.00, 0.00, 0.00, 999999, 0, NOW(), '2099-12-31 23:59:59', 1, NOW(), NOW(), 0, NULL, 'VIP_AUTO', '黄金', 1)
|
||||
ON DUPLICATE KEY UPDATE
|
||||
coupon_name = VALUES(coupon_name),
|
||||
coupon_type = VALUES(coupon_type),
|
||||
discount_value = VALUES(discount_value),
|
||||
min_amount = VALUES(min_amount),
|
||||
reduce_amount = VALUES(reduce_amount),
|
||||
total_count = VALUES(total_count),
|
||||
status = VALUES(status),
|
||||
is_delete = VALUES(is_delete),
|
||||
shop_id = VALUES(shop_id),
|
||||
coupon_scene = VALUES(coupon_scene),
|
||||
required_vip_level = VALUES(required_vip_level),
|
||||
auto_match = VALUES(auto_match),
|
||||
update_time = NOW();
|
||||
|
||||
DROP PROCEDURE IF EXISTS sp_add_column_if_not_exists;
|
||||
DROP PROCEDURE IF EXISTS sp_add_index_if_not_exists;
|
||||
DROP PROCEDURE IF EXISTS sp_add_unique_index_if_not_exists;
|
||||
@@ -117,6 +117,7 @@ yuminail:
|
||||
whitelist:
|
||||
- /api/user/login
|
||||
- /api/user/register
|
||||
- /api/user/check/**
|
||||
- /api/user/refresh-token
|
||||
- /api/user/send-verification-code
|
||||
- /api/user/phone-login
|
||||
|
||||
+45
-25
@@ -55,6 +55,8 @@
|
||||
- 验证token是否过期、是否为accessToken类型
|
||||
- 从token中提取用户信息并设置到请求属性中
|
||||
- 订单创建时还会校验购物车归属、同店铺/同美甲师约束、预约时间有效性、门店营业时间以及美甲师已有预约冲突
|
||||
- 用户资产相关操作改为通过 `UserAssetService` 统一事务处理,保证余额、累计充值、流水、VIP 状态一次提交
|
||||
- 订单结算会区分 `USER_COUPON` 与 `SYSTEM_VIP` 两类优惠来源;未显式选券时只自动补用最佳 VIP 自动券,不会自动消耗普通用户券
|
||||
|
||||
3. **权限控制**:
|
||||
- 后端使用@RequirePermission注解进行权限控制
|
||||
@@ -70,47 +72,65 @@
|
||||
const isWhitelistedPath = (url: string) => {
|
||||
return url?.includes('/user/login') ||
|
||||
url?.includes('/user/register') ||
|
||||
url?.includes('/user/check/') ||
|
||||
url?.includes('/user/refresh-token') ||
|
||||
url?.includes('/user/send-verification-code') ||
|
||||
url?.includes('/user/phone-login') ||
|
||||
url?.includes('/shop/list/simple') ||
|
||||
url?.includes('/admin/login')
|
||||
url?.includes('/admin/auth/login') ||
|
||||
url?.includes('/admin/auth/refresh')
|
||||
}
|
||||
```
|
||||
|
||||
### 3.2 网关白名单
|
||||
|
||||
在`YumiNail-Gateway/src/main/java/com/xiaowang/yumitailgateway/filter/AuthGlobalFilter.java`中定义:
|
||||
在`YumiNail-Gateway/src/main/resources/application.yaml`中通过配置集中维护:
|
||||
|
||||
```java
|
||||
private boolean isWhitelist(String path) {
|
||||
return path.equals("/api/user/login") ||
|
||||
path.equals("/api/user/register") ||
|
||||
path.equals("/api/user/refresh-token") ||
|
||||
path.equals("/api/shop/list/simple") ||
|
||||
path.equals("/api/admin/auth/login") ||
|
||||
path.equals("/admin/api/auth/login") ||
|
||||
path.startsWith("/api/user/get/account") ||
|
||||
path.startsWith("/api/health");
|
||||
}
|
||||
```yaml
|
||||
yuminail:
|
||||
gateway:
|
||||
whitelist:
|
||||
- /api/user/login
|
||||
- /api/user/register
|
||||
- /api/user/check/**
|
||||
- /api/user/refresh-token
|
||||
- /api/user/send-verification-code
|
||||
- /api/user/phone-login
|
||||
- /api/user/reset-password-by-phone
|
||||
- /api/shop/list/simple
|
||||
- /api/health/**
|
||||
- /api/admin/auth/login
|
||||
- /api/admin/auth/refresh
|
||||
```
|
||||
|
||||
### 3.3 核心服务白名单
|
||||
|
||||
在`YumiNail-Core/src/main/java/com/xiaowang/yuminailcore/config/AuthInterceptor.java`中定义:
|
||||
在`YumiNail-Core/src/main/java/com/xiaowang/yuminailcore/config/WebMvcConfig.java`中定义:
|
||||
|
||||
```java
|
||||
private boolean isWhitelistedPath(String path) {
|
||||
return path.contains("/user/login") ||
|
||||
path.contains("/user/register") ||
|
||||
path.contains("/user/refresh-token") ||
|
||||
path.contains("/user/get/account") ||
|
||||
path.contains("/shop/list/simple") ||
|
||||
path.contains("/admin/auth/login") ||
|
||||
path.contains("/admin/object-storage-file/upload") ||
|
||||
path.contains("/health") ||
|
||||
path.contains("/error");
|
||||
}
|
||||
registry.addInterceptor(authInterceptor)
|
||||
.addPathPatterns("/**")
|
||||
.excludePathPatterns(
|
||||
"/user/login",
|
||||
"/user/register",
|
||||
"/user/check/**",
|
||||
"/user/refresh-token",
|
||||
"/user/send-verification-code",
|
||||
"/user/phone-login",
|
||||
"/user/reset-password-by-phone",
|
||||
"/shop/list/simple",
|
||||
"/admin/auth/login",
|
||||
"/admin/auth/refresh",
|
||||
"/error",
|
||||
"/health/**"
|
||||
);
|
||||
```
|
||||
|
||||
### 3.4 白名单补充说明
|
||||
|
||||
- 账号检测链路 `GET /api/user/check/account/{account}`、`GET /api/user/check/phone/{phone}`、`GET /api/user/check/login-account/{account}` 必须同时在前端、网关、本地 Core 拦截器以及 Nacos `YumiNail-Dev` 白名单中保持一致。
|
||||
- 白名单只开放登录、注册、验证码、刷新 token、店铺简表、健康检查与账号检测接口;其余用户资产、订单、购物车、后台管理接口仍必须携带 token。
|
||||
|
||||
## 4. 权限控制体系
|
||||
|
||||
### 4.1 前端权限控制
|
||||
|
||||
@@ -0,0 +1,191 @@
|
||||
# 2026-03-20 待优化建议落地记录
|
||||
|
||||
## 本轮范围
|
||||
|
||||
本轮按 `docs/features/待优化建议.md` 与 `docs/base.md` 落地 6 项待优化建议,覆盖:
|
||||
|
||||
- 登录/注册交互与免鉴权账号检测
|
||||
- 白名单与 `401` 问题修正
|
||||
- 登录密码前端校验拆分
|
||||
- SQL 结构审查与增量补丁
|
||||
- 权限清单整理与初始化对齐
|
||||
- VIP / 余额 / 优惠券 / 订单 / 后台联动
|
||||
|
||||
## 已完成项
|
||||
|
||||
### 1. 登录/注册与白名单
|
||||
|
||||
- 登录页恢复为“输入账号后实时检测是否已注册”的体验,新增公共接口 `GET /user/check/login-account/{account}`,返回 `exists`、`nickname`、`message`。
|
||||
- 登录页密码校验改为“仅必填”,注册页继续保留复杂度与确认密码校验,避免已有弱密码用户被前端拦截。
|
||||
- 切换登录/注册、登录方式切换、清空账号时,登录检测提示态会被重置,避免旧提示残留。
|
||||
- 白名单三层已对齐:
|
||||
- 前端请求层:`Frontend/src/api/index.ts`
|
||||
- 网关配置:`YumiNail-Gateway/src/main/resources/application.yaml`
|
||||
- Core 拦截器:`YumiNail-Core/src/main/java/com/xiaowang/yuminailcore/config/WebMvcConfig.java`
|
||||
- 需要同步到 Nacos `YumiNail-Dev` 命名空间的白名单项:
|
||||
- `/api/user/check/**`
|
||||
|
||||
### 2. 用户资产、VIP 与后台管理
|
||||
|
||||
- 新增 `UserAssetService` 作为业务收口服务,统一处理充值、手工增减余额、订单消费/退款、VIP 重算。
|
||||
- 店长后台用户页增加“余额/VIP”入口,不再暴露通用 CRUD 给前端直接操作。
|
||||
- 新增后台接口:
|
||||
- `GET /admin/user/{id}/asset`
|
||||
- `GET /admin/user/{id}/balance/history`
|
||||
- `POST /admin/user/{id}/balance/change`
|
||||
- `POST /admin/user/{id}/vip/override`
|
||||
- `POST /admin/user/{id}/vip/recalculate`
|
||||
- 余额扣减场景现在强制要求“系统订单”或“外部订单号”二选一,充值/手工增加允许无订单号。
|
||||
- 手工设置 VIP 会记录 `manual_override=1`;恢复自动判级时清空 override,重新按累计充值金额判级。
|
||||
- 普通用户注册、手机号首登自动注册统一初始化为 `level=普通`、`vipId=0`。
|
||||
|
||||
### 3. 优惠券与订单结算链路
|
||||
|
||||
- 优惠券可用列表统一返回两类选项:
|
||||
- `USER_COUPON`:用户持券
|
||||
- `SYSTEM_VIP`:VIP 自动券模板
|
||||
- 购物车默认仅自动预选最佳 `SYSTEM_VIP` 券,普通用户券必须手动选中,避免无感消耗。
|
||||
- 订单创建支持 `couponSourceType`,显式区分用户券、VIP 自动券与手动“不使用优惠券”。
|
||||
- 订单取消或失败时只恢复普通用户券;VIP 自动券不落库、不恢复、下次重新实时匹配。
|
||||
- 后台优惠券管理页支持 `couponScene`、`requiredVipLevel`、`autoMatch`,并禁止对 VIP 自动券进行人工发放。
|
||||
|
||||
### 4. 权限与初始化
|
||||
|
||||
- 修正了历史命名不一致:
|
||||
- `product:update -> product:edit`
|
||||
- `shop:update -> shop:edit`
|
||||
- 新增并落地用户资产权限:
|
||||
- `user:balance:view`
|
||||
- `user:balance:manage`
|
||||
- `user:vip:manage`
|
||||
- 额外修复一个前后端权限不一致问题:
|
||||
- 后台用户列表的状态开关已增加 `user:disable` 前端门控
|
||||
- 店长默认权限补入 `user:disable`
|
||||
- 平台管理员在 `PermissionServiceImpl` 中按“拥有全部现存权限”处理,避免 `t_user_permission` 行数不完整时后台误判无权限。
|
||||
|
||||
## SQL 审查结论
|
||||
|
||||
当前 `YumiNail.sql` 的基础建表语句存在以下与现有代码不一致的点:
|
||||
|
||||
| 模块 | 当前问题 | 影响 |
|
||||
| --- | --- | --- |
|
||||
| `t_balance` | 缺少 `total_recharge_amount`、`last_recharge_time` | 无法累计充值判级,也无法展示最近充值信息 |
|
||||
| `t_balance_change_detail` | 缺少变动前后余额、场景、关联订单、操作人、备注 | 无法满足后台余额流水审计 |
|
||||
| `t_order` | 缺少 `shop_id`、`user_coupon_id`、`coupon_source_type` | 店铺维度过滤、优惠来源追踪、用户券恢复逻辑不完整 |
|
||||
| `t_order_item` | 缺少 `appointment_time` | 美甲师排班冲突校验与预约时间落库不完整 |
|
||||
| `t_coupon` | 缺少 `coupon_scene`、`required_vip_level`、`auto_match` | 无法区分普通券与 VIP 自动券 |
|
||||
| `t_vip_benefit` | 缺少 `level_rank`、`recharge_threshold`、`status` | 无法从 SQL 规则表驱动 VIP 阶梯 |
|
||||
| `t_vip_info` | 缺少 `user_id`、`manual_override`,且 `expire_time`、`benefit_id` 过严 | 无法支持“每用户一条快照”和手工/自动判级切换 |
|
||||
| 权限初始化 | `YumiNail.sql` 无权限初始化,`YumiNail-back.sql` 也缺少本轮新增权限与修正 | 空库初始化后权限与代码漂移 |
|
||||
|
||||
## 手工执行 SQL
|
||||
|
||||
- 新增补丁文件:
|
||||
- `YumiNail-Core/src/main/resources/files/2026-03-20_user_asset_vip_coupon_permission_patch.sql`
|
||||
- 执行顺序建议:
|
||||
1. 先执行基础建表 SQL:`YumiNail.sql`
|
||||
2. 再执行本补丁
|
||||
- 本补丁包含:
|
||||
- 表结构补列与索引补齐
|
||||
- 订单、VIP、余额历史数据必要回填
|
||||
- 完整权限清单 upsert
|
||||
- 按用户类型补齐既有用户默认权限
|
||||
- VIP 规则与 VIP 自动券模板初始化
|
||||
- 注意:
|
||||
- 历史累计充值金额无法从旧表精确反推,补丁只会把缺失值归零;若你需要保留老用户历史累计充值,请按业务台账手工回填 `t_balance.total_recharge_amount`
|
||||
|
||||
## 白名单复核
|
||||
|
||||
### 允许匿名访问
|
||||
|
||||
- 登录:`/api/user/login`
|
||||
- 注册:`/api/user/register`
|
||||
- 账号/手机号检测:`/api/user/check/**`
|
||||
- 刷新 token:`/api/user/refresh-token`
|
||||
- 发送验证码:`/api/user/send-verification-code`
|
||||
- 手机号验证码登录:`/api/user/phone-login`
|
||||
- 手机号重置密码:`/api/user/reset-password-by-phone`
|
||||
- 店铺简表:`/api/shop/list/simple`
|
||||
- 健康检查:`/api/health/**`
|
||||
- 后台登录/刷新:`/api/admin/auth/login`、`/api/admin/auth/refresh`
|
||||
|
||||
### 不应放开
|
||||
|
||||
- 用户资产、余额、VIP 管理接口
|
||||
- 购物车、收藏、下单、订单详情
|
||||
- 后台用户/订单/优惠券/权限/商品/店铺管理接口
|
||||
|
||||
## 权限清单
|
||||
|
||||
说明:
|
||||
|
||||
- “使用位置”以主要使用点为准,默认分为后台路由、前端按钮、后端注解、默认分配策略四类。
|
||||
- “初始化状态”表示是否已在本轮增量补丁中补齐;其中部分权限当前仅用于默认角色包或预留扩展。
|
||||
|
||||
| 权限码 | 权限名称 | 所属板块 | 主要使用位置 | 初始化状态 |
|
||||
| --- | --- | --- | --- | --- |
|
||||
| `home:view` | 查看首页 | 首页 | `UserServiceImpl` 默认分配 | 已在补丁补齐 |
|
||||
| `dashboard:view` | 查看仪表盘 | 仪表盘 | 后端 `DashboardController`;前端后台首页/路由 | 已在补丁补齐 |
|
||||
| `user:view` | 查看用户 | 用户管理 | 后端 `AdminUserController`、`UserController`;前端后台用户页/菜单 | 已在补丁补齐 |
|
||||
| `user:create` | 新增用户 | 用户管理 | 后端 `AdminUserController`、`UserController`;前端后台用户页按钮 | 已在补丁补齐 |
|
||||
| `user:edit` | 编辑用户 | 用户管理 | 后端 `AdminUserController`、`UserController`;前端后台用户页按钮 | 已在补丁补齐 |
|
||||
| `user:disable` | 启停用户 | 用户管理 | 后端 `AdminUserController`;前端后台用户状态开关 | 已在补丁补齐 |
|
||||
| `user:reset_password` | 重置密码 | 用户管理 | 后端 `AdminUserController`、`UserController`;前端后台用户页按钮 | 已在补丁补齐 |
|
||||
| `user:delete` | 删除用户 | 用户管理 | 后端 `AdminUserController`、`UserController`;前端后台用户页按钮 | 已在补丁补齐 |
|
||||
| `user:balance:view` | 查看余额资产 | 用户资产 | 后端 `AdminUserController`;前端后台用户资产面板 | 已在补丁补齐 |
|
||||
| `user:balance:manage` | 调整余额 | 用户资产 | 后端 `AdminUserController`;前端后台用户资产面板 | 已在补丁补齐 |
|
||||
| `user:vip:manage` | 管理VIP | 用户资产 | 后端 `AdminUserController`;前端后台用户资产面板 | 已在补丁补齐 |
|
||||
| `product:view` | 查看商品 | 商品管理 | 后端 `AdminProductController`;前端后台商品页/菜单 | 已在补丁补齐 |
|
||||
| `product:create` | 新增商品 | 商品管理 | 后端 `AdminProductController`、`ProductController`;前端后台商品页按钮 | 已在补丁补齐 |
|
||||
| `product:edit` | 编辑商品 | 商品管理 | 后端 `AdminProductController`、`ProductController`;前端后台商品页按钮 | 已在补丁补齐 |
|
||||
| `product:delete` | 删除商品 | 商品管理 | 后端 `AdminProductController`、`ProductController`;前端后台商品页按钮 | 已在补丁补齐 |
|
||||
| `product:category:manage` | 管理商品分类 | 商品管理 | `UserServiceImpl` 默认分配,当前代码预留 | 已在补丁补齐 |
|
||||
| `shop:view` | 查看店铺 | 店铺管理 | 后端 `AdminShopController`、`ShopController`;前端后台店铺页/菜单 | 已在补丁补齐 |
|
||||
| `shop:create` | 新增店铺 | 店铺管理 | 后端 `AdminShopController`、`ShopController`;前端后台店铺页按钮 | 已在补丁补齐 |
|
||||
| `shop:edit` | 编辑店铺 | 店铺管理 | 后端 `AdminShopController`、`ShopController`;前端后台店铺页按钮 | 已在补丁补齐 |
|
||||
| `shop:delete` | 删除店铺 | 店铺管理 | 后端 `AdminShopController`、`ShopController`;前端后台店铺页按钮 | 已在补丁补齐 |
|
||||
| `shop:staff:manage` | 管理员工 | 店铺管理 | `UserServiceImpl` 默认分配,当前代码预留 | 已在补丁补齐 |
|
||||
| `permission:view` | 查看权限 | 权限管理 | 后端 `AdminPermissionController`、`PermissionController`;前端后台权限页/菜单 | 已在补丁补齐 |
|
||||
| `permission:create` | 新增权限 | 权限管理 | 后端 `AdminPermissionController`、`PermissionController`;前端后台权限页按钮 | 已在补丁补齐 |
|
||||
| `permission:edit` | 编辑权限 | 权限管理 | 后端 `AdminPermissionController`、`PermissionController`;前端后台权限页按钮 | 已在补丁补齐 |
|
||||
| `permission:delete` | 删除权限 | 权限管理 | 后端 `AdminPermissionController`、`PermissionController`;前端后台权限页按钮 | 已在补丁补齐 |
|
||||
| `permission:assign` | 分配权限 | 权限管理 | 后端 `AdminPermissionController`、`PermissionController`、`PermissionServiceImpl`;前端权限分配页签 | 已在补丁补齐 |
|
||||
| `tag:view` | 查看标签 | 标签管理 | 后端 `AdminTagController`、`TagController`;前端后台标签页/菜单 | 已在补丁补齐 |
|
||||
| `tag:create` | 新增标签 | 标签管理 | 后端 `AdminTagController`、`TagController`;前端后台标签页按钮 | 已在补丁补齐 |
|
||||
| `tag:edit` | 编辑标签 | 标签管理 | 后端 `AdminTagController`、`TagController`;前端后台标签页按钮 | 已在补丁补齐 |
|
||||
| `tag:delete` | 删除标签 | 标签管理 | 后端 `AdminTagController`、`TagController`;前端后台标签页按钮 | 已在补丁补齐 |
|
||||
| `tag:assign` | 分配标签 | 标签管理 | `UserServiceImpl` 默认分配,当前代码预留 | 已在补丁补齐 |
|
||||
| `coupon:view` | 查看优惠券 | 优惠券管理 | 后端 `AdminCouponController`、`CouponController`;前端后台优惠券页/菜单 | 已在补丁补齐 |
|
||||
| `coupon:create` | 新增优惠券 | 优惠券管理 | 后端 `AdminCouponController`、`CouponController`;前端后台优惠券页按钮 | 已在补丁补齐 |
|
||||
| `coupon:edit` | 编辑优惠券 | 优惠券管理 | 后端 `AdminCouponController`、`CouponController`;前端后台优惠券页按钮 | 已在补丁补齐 |
|
||||
| `coupon:delete` | 删除优惠券 | 优惠券管理 | 后端 `AdminCouponController`、`CouponController`;前端后台优惠券页按钮 | 已在补丁补齐 |
|
||||
| `coupon:assign` | 发放优惠券 | 优惠券管理 | 后端 `AdminCouponController`、`CouponController`;前端后台优惠券页按钮 | 已在补丁补齐 |
|
||||
| `order:view` | 查看订单 | 订单管理 | 后端 `AdminOrderController`、`OrderController`;前端后台订单页、美甲师订单页路由 | 已在补丁补齐 |
|
||||
| `order:process` | 处理订单 | 订单管理 | 后端 `AdminOrderController`、`OrderController`;美甲师完结订单 | 已在补丁补齐 |
|
||||
| `order:edit` | 编辑订单 | 订单管理 | `UserServiceImpl` 默认分配,当前代码预留 | 已在补丁补齐 |
|
||||
| `order:delete` | 删除订单 | 订单管理 | `UserServiceImpl` 默认分配,当前代码预留 | 已在补丁补齐 |
|
||||
| `nail_artist:view` | 查看美甲师 | 美甲师管理 | 后端 `AdminNailArtistController`;前端后台美甲师页/菜单 | 已在补丁补齐 |
|
||||
| `nail_artist:edit` | 编辑美甲师 | 美甲师管理 | 后端 `AdminNailArtistController`;前端后台美甲师页按钮 | 已在补丁补齐 |
|
||||
|
||||
## 本轮验证
|
||||
|
||||
### 编译验证
|
||||
|
||||
- 前端:`Frontend` 执行 `npm run build` 通过
|
||||
- 后端:`YumiNail-Core` 执行 `mvn -q -DskipTests compile` 通过
|
||||
- 网关:`YumiNail-Gateway` 执行 `mvn -q -DskipTests compile` 通过
|
||||
|
||||
### 重点回归点
|
||||
|
||||
- 登录页账号实时检测与昵称展示
|
||||
- 注册页账号/手机号检测免鉴权
|
||||
- 登录密码校验仅保留必填
|
||||
- 购物车默认只自动命中最佳 VIP 自动券
|
||||
- 订单取消/失败只恢复普通用户券
|
||||
- 后台余额扣减必须关联系统订单或外部订单号
|
||||
- 后台用户状态开关新增 `user:disable` 权限门控
|
||||
|
||||
## 归档说明
|
||||
|
||||
- 本轮已完成的 6 项建议已从 feature 工作清单中移出,保留归档说明到:
|
||||
- `docs/features/待优化建议.md`
|
||||
@@ -3,3 +3,7 @@
|
||||
当前已归档的优化建议均已处理完成,`docs/features` 下暂无新的待优化项。
|
||||
|
||||
后续如果发现新的问题或确认新的优化方向,再补充到本文件;完成后继续移入 `docs/changes`。
|
||||
|
||||
本轮已归档到:
|
||||
|
||||
- `docs/changes/2026-03-20-待优化建议落地.md`
|
||||
|
||||
Reference in New Issue
Block a user