完善店务端员工新增和删除

This commit is contained in:
2026-07-15 17:33:34 +08:00
parent ad1ae376f8
commit 00a435ecfb
12 changed files with 288 additions and 12 deletions
@@ -38,6 +38,7 @@ import com.xiaowang.jayucloud.core.modules.user.vo.UserVO;
import lombok.RequiredArgsConstructor;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
@@ -259,9 +260,34 @@ public class AdminManagerController {
dto.setShopId(managedShopId);
dto.setShopIds(List.of(managedShopId));
}
if (!StringUtils.hasText(dto.getWechatId())) {
dto.setWechatId(dto.getPhone());
}
return Result.success(userService.createUser(dto));
}
@DeleteMapping("/employees/{userId}")
@RequirePermission("user:unbind")
@OperationGuard(action = "manager-employee-delete", ttlSeconds = 10, message = "员工删除处理中,请勿重复点击")
public Result<Boolean> deleteEmployee(HttpServletRequest request,
@PathVariable Long userId) {
UserDO currentUser = adminScopeHelper.getCurrentUser(request);
UserVO targetUser = userService.getUserById(userId);
if (targetUser == null) {
return Result.success(false);
}
if (!adminScopeHelper.isPlatformAdmin(currentUser)) {
adminScopeHelper.ensureUserAccessibleInCurrentShop(currentUser, userId, "无权删除其他店铺员工");
}
adminScopeHelper.ensureAssignableUserType(currentUser, targetUser.getType());
if (!Integer.valueOf(3).equals(targetUser.getType())) {
throw new RuntimeException("只能删除员工");
}
Long shopId = adminScopeHelper.resolveShopScope(currentUser, null);
adminScopeHelper.requireShopContext(currentUser, "请先选择店铺后再删除员工");
return Result.success(userService.unbindUserInShopWithOperator(userId, shopId, currentUser.getType()));
}
@GetMapping("/employees/schedules")
@RequirePermission("schedule:view")
public Result<List<ArtistScheduleVO>> schedules(HttpServletRequest request,
@@ -141,6 +141,29 @@ class AdminManagerControllerTest {
verify(adminScopeHelper).ensureAssignableUserType(manager, 3);
}
@Test
void createEmployeeUserShouldDefaultWechatToPhoneWithoutChangingAccount() {
MockHttpServletRequest request = new MockHttpServletRequest();
UserDO manager = new UserDO();
manager.setType(2);
manager.setShopId(8L);
UserDTO dto = new UserDTO();
dto.setPhone("13800138000");
dto.setAccount("artist001");
dto.setWechatId(" ");
when(adminScopeHelper.getCurrentUser(request)).thenReturn(manager);
when(adminScopeHelper.isPlatformAdmin(manager)).thenReturn(false);
when(adminScopeHelper.getManagedShopId(manager)).thenReturn(8L);
when(userService.createUser(dto)).thenReturn(104L);
Result<Long> result = controller.createEmployeeUser(request, dto);
assertThat(result.getData()).isEqualTo(104L);
assertThat(dto.getWechatId()).isEqualTo("13800138000");
assertThat(dto.getAccount()).isEqualTo("artist001");
verify(userService).createUser(dto);
}
@Test
void createCustomerShouldForceNormalUserInCurrentShop() {
MockHttpServletRequest request = new MockHttpServletRequest();
@@ -321,6 +344,49 @@ class AdminManagerControllerTest {
verify(userService, never()).resetManagedEmployeePassword(any(), any());
}
@Test
void deleteEmployeeShouldUnbindCurrentShopWithoutDeletingAccount() {
MockHttpServletRequest request = new MockHttpServletRequest();
UserDO manager = new UserDO();
manager.setType(2);
manager.setShopId(8L);
UserVO targetUser = new UserVO();
targetUser.setId(7L);
targetUser.setType(3);
when(adminScopeHelper.getCurrentUser(request)).thenReturn(manager);
when(adminScopeHelper.isPlatformAdmin(manager)).thenReturn(false);
when(adminScopeHelper.resolveShopScope(manager, null)).thenReturn(8L);
when(userService.getUserById(7L)).thenReturn(targetUser);
when(userService.unbindUserInShopWithOperator(7L, 8L, 2)).thenReturn(true);
Result<Boolean> result = controller.deleteEmployee(request, 7L);
assertThat(result.getData()).isTrue();
verify(adminScopeHelper).ensureUserAccessibleInCurrentShop(manager, 7L, "无权删除其他店铺员工");
verify(adminScopeHelper).ensureAssignableUserType(manager, 3);
verify(userService).unbindUserInShopWithOperator(7L, 8L, 2);
verify(userService, never()).deleteUser(any());
}
@Test
void deleteEmployeeShouldRejectNonEmployee() {
MockHttpServletRequest request = new MockHttpServletRequest();
UserDO manager = new UserDO();
manager.setType(2);
UserVO targetUser = new UserVO();
targetUser.setId(7L);
targetUser.setType(0);
when(adminScopeHelper.getCurrentUser(request)).thenReturn(manager);
when(adminScopeHelper.isPlatformAdmin(manager)).thenReturn(false);
when(userService.getUserById(7L)).thenReturn(targetUser);
assertThatThrownBy(() -> controller.deleteEmployee(request, 7L))
.isInstanceOf(RuntimeException.class)
.hasMessage("只能删除员工");
verify(userService, never()).unbindUserInShopWithOperator(any(), any(), any());
verify(userService, never()).deleteUser(any());
}
@Test
void saveScheduleShouldResolveShopScopeBeforeSaving() {
MockHttpServletRequest request = new MockHttpServletRequest();
@@ -25,6 +25,9 @@ export const managerEmployeesApi = {
createUser(data: EmployeeCreateRequest): Promise<IdType> {
return adminApi.post('/manager/employees/users', data)
},
deleteUser(userId: IdType): Promise<boolean> {
return adminApi.delete(`/manager/employees/${userId}`)
},
schedules(params: { artistId?: IdType; startDate?: string; endDate?: string }): Promise<ArtistSchedule[]> {
return adminApi.get('/manager/employees/schedules', { params })
},
@@ -33,6 +33,25 @@
<span>›</span>
</button>
</section>
<section class="card delete-panel section">
<div>
<strong>删除员工</strong>
<p>删除后该员工会从当前店铺员工列表移除,登录账号仍会保留。</p>
</div>
<button class="danger-btn" type="button" :disabled="deletingEmployee" @click="requestDeleteEmployee">
{{ deletingEmployee ? '删除中...' : '删除员工' }}
</button>
</section>
<div v-if="deleteConfirmVisible" class="reset-confirm delete-confirm">
<p>确定要删除该员工吗?该操作只移除当前店铺员工关系,不会删除登录账号。</p>
<div class="reset-confirm__actions">
<button class="secondary-btn" type="button" :disabled="deletingEmployee" @click="deleteConfirmVisible = false">取消</button>
<button class="danger-btn" type="button" :disabled="deletingEmployee" @click="confirmDeleteEmployee">
{{ deletingEmployee ? '删除中...' : '确认删除' }}
</button>
</div>
</div>
</template>
<EmptyState v-else title="员工不存在" />
@@ -139,7 +158,9 @@ const loading = ref(false)
const saving = ref(false)
const avatarUploading = ref(false)
const resettingPassword = ref(false)
const deletingEmployee = ref(false)
const resetConfirmVisible = ref(false)
const deleteConfirmVisible = ref(false)
const employee = ref<Artist | null>(null)
const editModalVisible = ref(false)
const employeeId = computed(() => String(route.params.id))
@@ -162,7 +183,7 @@ const buildEmptyEditForm = (): EditEmployeeForm => ({
const editForm = reactive<EditEmployeeForm>(buildEmptyEditForm())
const originalEditForm = ref<EditEmployeeForm>(buildEmptyEditForm())
const editFormChanged = computed(() => !sameEditForm(editForm, originalEditForm.value))
const closeDisabled = computed(() => saving.value || avatarUploading.value || resettingPassword.value)
const closeDisabled = computed(() => saving.value || avatarUploading.value || resettingPassword.value || deletingEmployee.value)
function buildEditFormFromEmployee(value: Artist): EditEmployeeForm {
return {
@@ -374,6 +395,30 @@ const confirmResetPassword = async (): Promise<void> => {
}
}
const requestDeleteEmployee = (): void => {
deleteConfirmVisible.value = true
}
const confirmDeleteEmployee = async (): Promise<void> => {
if (!employee.value) {
return
}
deletingEmployee.value = true
try {
const success = await managerEmployeesApi.deleteUser(employee.value.userId || employeeId.value)
if (!success) {
throw new Error('员工不存在或已被删除')
}
deleteConfirmVisible.value = false
toast.success('员工已删除')
await router.replace('/employees')
} catch (error) {
toast.error(errorMessage(error as { message?: string } | null, '员工删除失败,请稍后重试'))
} finally {
deletingEmployee.value = false
}
}
onMounted(async () => {
await loadEmployee()
restoreEditDraft()
@@ -486,6 +531,37 @@ watch(editModalVisible, syncEditDraft)
border-bottom: 0;
}
.delete-panel {
display: flex;
align-items: center;
justify-content: space-between;
flex-wrap: wrap;
gap: 12px;
padding: 14px;
}
.delete-panel strong,
.delete-panel p {
margin: 0;
}
.delete-panel strong {
display: block;
color: var(--ink);
font-size: 14px;
}
.delete-panel p {
margin-top: 4px;
color: var(--muted);
font-size: 12px;
line-height: 1.5;
}
.delete-confirm {
margin-top: 12px;
}
.modal-form {
display: grid;
gap: 12px;
+12 -7
View File
@@ -145,19 +145,24 @@ const openCreate = (): void => {
}
const createEmployee = async (): Promise<void> => {
if (!createForm.nickname || !createForm.phone || !createForm.account || !createForm.password || !createForm.wechatId) {
const nickname = createForm.nickname.trim()
const phone = createForm.phone.trim()
const account = createForm.account.trim()
const password = createForm.password
const wechatId = createForm.wechatId.trim() || phone
if (!nickname || !phone || !account || !password) {
toast.error('请补全美甲师信息')
return
}
creating.value = true
try {
await managerEmployeesApi.createUser({
nickname: createForm.nickname,
phone: createForm.phone,
account: createForm.account,
password: createForm.password,
contactPhone: createForm.phone,
wechatId: createForm.wechatId
nickname,
phone,
account,
password,
contactPhone: phone,
wechatId
})
toast.success('美甲师已新增')
updateCreateModalVisible(false)
+7
View File
@@ -30,6 +30,13 @@ module.exports = {
})
},
deleteUser(userId) {
return request({
url: `/manager/employees/${userId}`,
method: 'DELETE'
})
},
schedules(params) {
return request({
url: '/manager/employees/schedules',
+40 -1
View File
@@ -6,7 +6,8 @@ Page({
data: {
id: '',
employee: {},
loadError: ''
loadError: '',
deletingEmployee: false
},
onLoad(options) {
@@ -44,6 +45,44 @@ Page({
wx.navigateTo({ url: `${event.currentTarget.dataset.url}?id=${this.data.id}` })
},
requestDeleteEmployee() {
if (this.data.deletingEmployee) {
return
}
wx.showModal({
title: '删除员工',
content: '确定要删除该员工吗?该操作只移除当前店铺员工关系,不会删除登录账号。',
confirmText: '删除',
confirmColor: '#BF4949',
success: (result) => {
if (result.confirm) {
this.confirmDeleteEmployee()
}
}
})
},
async confirmDeleteEmployee() {
if (!this.data.id) {
return
}
this.setData({ deletingEmployee: true })
try {
const success = await employeesApi.deleteUser(this.data.id)
if (!success) {
throw new Error('员工不存在或已被删除')
}
wx.showToast({ title: '员工已删除', icon: 'success' })
setTimeout(() => {
wx.navigateBack()
}, 600)
} catch (error) {
wx.showToast({ title: error.message || '员工删除失败', icon: 'none' })
} finally {
this.setData({ deletingEmployee: false })
}
},
back() {
wx.navigateBack()
}
@@ -38,4 +38,12 @@
<view class="card menu-card" data-url="/pages/employee-orders/index" bindtap="go">订单记录</view>
</view>
</view>
<view wx:if="{{!loadError}}" class="card delete-card">
<view>
<text class="delete-title">删除员工</text>
<text class="delete-desc">删除后该员工会从当前店铺员工列表移除,登录账号仍会保留。</text>
</view>
<button class="delete-btn" loading="{{deletingEmployee}}" bindtap="requestDeleteEmployee">删除员工</button>
</view>
</view>
@@ -83,3 +83,42 @@
font-size: 30rpx;
font-weight: 800;
}
.delete-card {
display: flex;
align-items: center;
justify-content: space-between;
gap: 20rpx;
margin-top: 24rpx;
padding: 24rpx;
}
.delete-title,
.delete-desc {
display: block;
}
.delete-title {
color: #302c27;
font-size: 28rpx;
font-weight: 800;
}
.delete-desc {
margin-top: 8rpx;
color: #91897f;
font-size: 22rpx;
line-height: 1.5;
}
.delete-btn {
flex: 0 0 auto;
min-width: 172rpx;
margin: 0;
border: 0;
border-radius: 999rpx;
background: #BF4949;
color: #fff;
font-size: 24rpx;
font-weight: 800;
}
+2 -2
View File
@@ -137,8 +137,8 @@ Page({
const phone = String(form.phone || '').trim()
const account = String(form.account || '').trim()
const password = String(form.password || '').trim()
const wechatId = String(form.wechatId || '').trim()
if (!nickname || !phone || !account || !password || !wechatId) {
const wechatId = String(form.wechatId || '').trim() || phone
if (!nickname || !phone || !account || !password) {
wx.showToast({ title: '请补全美甲师信息', icon: 'none' })
return
}
+1 -1
View File
@@ -60,7 +60,7 @@
<input value="{{createForm.password}}" data-field="password" bindinput="onCreateInput" password placeholder="请输入密码" />
</view>
<view class="modal-field">
<text class="required-label">微信号</text>
<text>微信号</text>
<input value="{{createForm.wechatId}}" data-field="wechatId" bindinput="onCreateInput" placeholder="请输入微信号" />
</view>
</view>
+7
View File
@@ -20,3 +20,10 @@
- 原因:Markdown 表格常把安全字段和凭据字段放在同一行。
- 处理方式:只搜索明确安全的项目文档;涉及资产、服务器、中间件清单时用白名单字段解析,不打印整行。
- 以后避免:提交和汇报中只保留配置项、位置、状态和脱敏验证结果,不记录明文凭据。
## GitNexus run.cjs 查询短语在 Windows 下可能拆参
- 问题:`node .gitnexus/run.cjs query "manager employees"` 在 PowerShell 中可能被底层 runner 拆成多个参数,报 `too many arguments for 'query'`。
- 原因:`.gitnexus/run.cjs` 在 Windows 上通过 shell 启动实际 CLI,短语参数会跨多层解析,引用不一定能按预期保留。
- 处理方式:查询、影响分析等非 analyze 命令优先直接调用全局 `gitnexus -r JayuCloud ...`,例如 `gitnexus query -r JayuCloud "manager employees"`。
- 以后避免:只有刷新索引继续使用 `node .gitnexus/run.cjs analyze`;带自由文本参数的 GitNexus 命令用直接 `gitnexus` 形式,并显式传 `-r JayuCloud`。