支持店务修改客户联系方式和备注

This commit is contained in:
2026-07-03 00:01:37 +08:00
parent e8c7cd3d78
commit df589d537b
10 changed files with 471 additions and 8 deletions
@@ -15,6 +15,7 @@ import com.xiaowang.jayucloud.core.modules.artist.vo.ArtistScheduleRuleSettingVO
import com.xiaowang.jayucloud.core.modules.artist.vo.ArtistScheduleRuleVO;
import com.xiaowang.jayucloud.core.modules.artist.vo.ArtistScheduleVO;
import com.xiaowang.jayucloud.core.modules.manager.dto.ManagerCustomerCreateDTO;
import com.xiaowang.jayucloud.core.modules.manager.dto.ManagerCustomerUpdateDTO;
import com.xiaowang.jayucloud.core.modules.planning.dto.PlanningAppointmentCreateDTO;
import com.xiaowang.jayucloud.core.modules.planning.dto.PlanningAppointmentMoveDTO;
import com.xiaowang.jayucloud.core.modules.planning.dto.PlanningAppointmentStatusDTO;
@@ -167,6 +168,27 @@ public class AdminManagerController {
return Result.success(userService.createUser(userDTO));
}
@PutMapping("/customers/{id}")
@RequirePermission("user:edit")
@OperationGuard(action = "manager-customer-update", ttlSeconds = 10, message = "客户信息保存处理中,请勿重复提交")
public Result<Boolean> updateCustomer(HttpServletRequest request,
@PathVariable Long id,
@Valid @RequestBody ManagerCustomerUpdateDTO dto) {
UserDO currentUser = adminScopeHelper.getCurrentUser(request);
adminScopeHelper.ensureUserAccessibleInCurrentShop(currentUser, id, "无权编辑其他店铺客户");
UserVO targetUser = userService.getUserById(id);
if (targetUser == null) {
return Result.success(false);
}
if (!Integer.valueOf(0).equals(targetUser.getType())) {
throw new RuntimeException("只能编辑客户信息");
}
UserDTO userDTO = new UserDTO();
userDTO.setContactPhone(dto.getContactPhone() == null ? "" : dto.getContactPhone().trim());
userDTO.setSignature(dto.getRemark() == null ? "" : dto.getRemark().trim());
return Result.success(userService.updateUser(id, userDTO));
}
@GetMapping("/employees")
@RequirePermission("nail_artist:view")
public Result<List<NailArtistInfoDTO>> employees(HttpServletRequest request) {
@@ -0,0 +1,15 @@
package com.xiaowang.jayucloud.core.modules.manager.dto;
import lombok.Data;
import javax.validation.constraints.Size;
@Data
public class ManagerCustomerUpdateDTO {
@Size(max = 50, message = "联系电话不能超过50个字符")
private String contactPhone;
@Size(max = 200, message = "客户备注不能超过200个字符")
private String remark;
}
@@ -13,6 +13,7 @@ import com.xiaowang.jayucloud.core.modules.artist.vo.ArtistScheduleRuleSettingVO
import com.xiaowang.jayucloud.core.modules.artist.vo.ArtistScheduleRuleVO;
import com.xiaowang.jayucloud.core.modules.artist.vo.ArtistScheduleVO;
import com.xiaowang.jayucloud.core.modules.manager.dto.ManagerCustomerCreateDTO;
import com.xiaowang.jayucloud.core.modules.manager.dto.ManagerCustomerUpdateDTO;
import com.xiaowang.jayucloud.core.modules.planning.service.PlanningService;
import com.xiaowang.jayucloud.core.modules.product.service.ProductService;
import com.xiaowang.jayucloud.core.modules.product.vo.ProductVO;
@@ -169,6 +170,51 @@ class AdminManagerControllerTest {
));
}
@Test
void updateCustomerShouldOnlySaveContactPhoneAndRemark() {
MockHttpServletRequest request = new MockHttpServletRequest();
UserDO manager = new UserDO();
manager.setType(2);
UserVO targetUser = new UserVO();
targetUser.setId(9L);
targetUser.setType(0);
ManagerCustomerUpdateDTO dto = new ManagerCustomerUpdateDTO();
dto.setContactPhone(" 13900139000 ");
dto.setRemark(" 喜欢浅色款 ");
when(adminScopeHelper.getCurrentUser(request)).thenReturn(manager);
when(userService.getUserById(9L)).thenReturn(targetUser);
when(userService.updateUser(any(), any(UserDTO.class))).thenReturn(true);
Result<Boolean> result = controller.updateCustomer(request, 9L, dto);
assertThat(result.getData()).isTrue();
verify(adminScopeHelper).ensureUserAccessibleInCurrentShop(manager, 9L, "无权编辑其他店铺客户");
verify(userService).updateUser(argThat(id -> Long.valueOf(9L).equals(id)), argThat(userDTO ->
"13900139000".equals(userDTO.getContactPhone())
&& "喜欢浅色款".equals(userDTO.getSignature())
&& userDTO.getPhone() == null
&& userDTO.getAccount() == null
&& userDTO.getShopId() == null
&& userDTO.getShopIds() == null
));
}
@Test
void updateCustomerShouldRejectNonCustomerUser() {
MockHttpServletRequest request = new MockHttpServletRequest();
UserDO manager = new UserDO();
UserVO targetUser = new UserVO();
targetUser.setType(3);
ManagerCustomerUpdateDTO dto = new ManagerCustomerUpdateDTO();
when(adminScopeHelper.getCurrentUser(request)).thenReturn(manager);
when(userService.getUserById(9L)).thenReturn(targetUser);
assertThatThrownBy(() -> controller.updateCustomer(request, 9L, dto))
.isInstanceOf(RuntimeException.class)
.hasMessage("只能编辑客户信息");
verify(userService, never()).updateUser(any(), any(UserDTO.class));
}
@Test
void saveEmployeeShouldSyncUserBasicsAndArtistInfo() {
MockHttpServletRequest request = new MockHttpServletRequest();
@@ -9,6 +9,11 @@ export interface CustomerListParams {
hasOrder?: boolean
}
export interface CustomerUpdateRequest {
contactPhone: string
remark: string
}
export const managerCustomersApi = {
list(params: CustomerListParams): Promise<CustomerPage> {
return adminApi.get('/manager/customers', { params })
@@ -18,5 +23,8 @@ export const managerCustomersApi = {
},
create(data: CustomerCreateRequest): Promise<IdType> {
return adminApi.post('/manager/customers', data)
},
update(id: IdType, data: CustomerUpdateRequest): Promise<boolean> {
return adminApi.put(`/manager/customers/${id}`, data)
}
}
+108 -4
View File
@@ -4,29 +4,54 @@
<template v-else-if="customer">
<section class="card customer-card">
<div class="avatar">{{ firstName }}</div>
<div>
<div class="customer-card__body">
<h2>{{ customer.nickname || customer.account || '未命名客户' }}</h2>
<p>{{ customer.phone || customer.contactPhone || '未填写手机号' }}</p>
<p>{{ customer.contactPhone || customer.phone || '未填写手机号' }}</p>
</div>
<button class="edit-btn" type="button" @click="openEdit">编辑</button>
</section>
<PageSection title="客户信息">
<section class="card form-card">
<div class="field"><label>登录账号</label><div class="field-value">{{ customer.account || '未设置' }}</div></div>
<div class="field"><label>联系电话</label><div class="field-value">{{ customer.contactPhone || customer.phone || '未设置' }}</div></div>
<div class="field"><label>备注</label><div class="field-value">{{ customer.signature || '未填写' }}</div></div>
<div class="field"><label>注册时间</label><div class="field-value">{{ customer.createTime || '暂无' }}</div></div>
</section>
</PageSection>
<button class="primary-btn section" type="button" @click="createAppointment">为客户预约</button>
<BaseModal
:model-value="editModalVisible"
title="编辑客户"
:close-disabled="saving"
:has-unsaved-changes="editFormChanged"
@update:model-value="updateEditModalVisible"
>
<div class="modal-form">
<div class="field">
<label>联系电话</label>
<input v-model.trim="editForm.contactPhone" inputmode="tel" placeholder="请输入联系电话" />
</div>
<div class="field">
<label>备注</label>
<textarea v-model.trim="editForm.remark" rows="4" maxlength="200" placeholder="请输入客户备注" />
</div>
<button class="primary-btn" type="button" :disabled="saving" @click="saveEdit">
{{ saving ? '保存中...' : '保存客户' }}
</button>
</div>
</BaseModal>
</template>
<EmptyState v-else title="客户不存在" />
</MobileShell>
</template>
<script setup lang="ts">
import { computed, onMounted, ref } from 'vue'
import { computed, onMounted, reactive, ref } from 'vue'
import { useRoute, useRouter } from 'vue-router'
import BaseModal from '@/components/BaseModal.vue'
import EmptyState from '@/components/EmptyState.vue'
import LoadingState from '@/components/LoadingState.vue'
import MobileShell from '@/components/MobileShell.vue'
@@ -42,25 +67,81 @@ const router = useRouter()
const toast = useToastStore()
const session = useSessionStore()
const loading = ref(false)
const saving = ref(false)
const customer = ref<UserInfo | null>(null)
const editModalVisible = ref(false)
const editForm = reactive({
contactPhone: '',
remark: ''
})
const editBaseline = reactive({
contactPhone: '',
remark: ''
})
const firstName = computed(() => String(customer.value?.nickname || customer.value?.account || '客').slice(0, 1))
const editFormChanged = computed(() => editForm.contactPhone !== editBaseline.contactPhone || editForm.remark !== editBaseline.remark)
const applyEditForm = (value: UserInfo): void => {
editForm.contactPhone = value.contactPhone || value.phone || ''
editForm.remark = value.signature || ''
editBaseline.contactPhone = editForm.contactPhone
editBaseline.remark = editForm.remark
}
const loadCustomer = async (): Promise<void> => {
loading.value = true
try {
customer.value = await managerCustomersApi.detail(String(route.params.id))
if (customer.value) {
applyEditForm(customer.value)
}
} finally {
loading.value = false
}
}
const openEdit = (): void => {
if (!customer.value) {
return
}
applyEditForm(customer.value)
editModalVisible.value = true
}
const updateEditModalVisible = (value: boolean): void => {
editModalVisible.value = value
if (!value && customer.value) {
applyEditForm(customer.value)
}
}
const saveEdit = async (): Promise<void> => {
if (!customer.value) {
return
}
saving.value = true
try {
await managerCustomersApi.update(customer.value.id, {
contactPhone: editForm.contactPhone.trim(),
remark: editForm.remark.trim()
})
toast.success('客户信息已保存')
editModalVisible.value = false
await loadCustomer()
} catch (error) {
toast.error(error instanceof Error ? error.message : '客户信息保存失败')
} finally {
saving.value = false
}
}
const createAppointment = (): void => {
if (!canCreateAppointment(session.userInfo)) {
toast.error('美甲师账号只能查看预约')
return
}
const name = encodeURIComponent(customer.value?.nickname || customer.value?.account || '')
const phone = encodeURIComponent(customer.value?.phone || customer.value?.contactPhone || '')
const phone = encodeURIComponent(customer.value?.contactPhone || customer.value?.phone || '')
void router.push(`/appointments/new?customerName=${name}&phone=${phone}`)
}
@@ -89,6 +170,11 @@ onMounted(() => {
font-weight: 900;
}
.customer-card__body {
min-width: 0;
flex: 1;
}
.customer-card h2,
.customer-card p {
margin: 0;
@@ -98,4 +184,22 @@ onMounted(() => {
margin-top: 4px;
color: var(--muted);
}
.edit-btn {
min-height: 34px;
padding: 0 12px;
border: 1px solid var(--border);
border-radius: 999px;
background: var(--card-bg);
color: var(--accent);
font-size: 13px;
font-weight: 800;
white-space: nowrap;
}
.modal-form {
display: grid;
gap: 12px;
padding: 14px;
}
</style>
+1 -1
View File
@@ -12,7 +12,7 @@
<div class="row-between">
<div>
<h2 class="list-card__title">{{ customer.nickname || customer.account || '未命名客户' }}</h2>
<div class="list-card__subtitle">{{ customer.phone || customer.contactPhone || '未填写手机号' }}</div>
<div class="list-card__subtitle">{{ customer.contactPhone || customer.phone || '未填写手机号' }}</div>
</div>
<span class="tag">{{ customer.createTime ? '已建档' : '客户' }}</span>
</div>
+8
View File
@@ -20,5 +20,13 @@ module.exports = {
method: 'POST',
data
})
},
update(id, data) {
return request({
url: `/manager/customers/${id}`,
method: 'PUT',
data
})
}
}
+59 -2
View File
@@ -14,7 +14,13 @@ Page({
customer: {},
stats: { orderCount: 0, amount: 0, lastTime: '-' },
orders: [],
loadError: ''
loadError: '',
editModalVisible: false,
saving: false,
editForm: {
contactPhone: '',
remark: ''
}
},
onLoad(options) {
@@ -43,10 +49,16 @@ Page({
const customer = {
id: detail.id,
name: detail.nickname || detail.name || detail.account || '客户',
phone: detail.contactPhone || detail.phone || '未填写'
phone: detail.contactPhone || detail.phone || '未填写',
contactPhone: detail.contactPhone || '',
remark: detail.signature || ''
}
this.setData({
customer,
editForm: {
contactPhone: customer.contactPhone || detail.phone || '',
remark: customer.remark
},
avatarText: String(customer.name || '客').slice(-1),
stats: {
orderCount: detail.orderCount || detail.totalOrderCount || 0,
@@ -66,6 +78,51 @@ Page({
}
},
openEditModal() {
const customer = this.data.customer || {}
this.setData({
editModalVisible: true,
editForm: {
contactPhone: customer.contactPhone || customer.phone || '',
remark: customer.remark || ''
}
})
},
closeEditModal() {
if (this.data.saving) {
return
}
this.setData({ editModalVisible: false })
},
stopTap() {
},
onEditInput(event) {
this.setData({
[`editForm.${event.currentTarget.dataset.field}`]: event.detail.value
})
},
async saveCustomer() {
const form = this.data.editForm || {}
this.setData({ saving: true })
try {
await customersApi.update(this.data.id, {
contactPhone: String(form.contactPhone || '').trim(),
remark: String(form.remark || '').trim()
})
wx.showToast({ title: '客户信息已保存', icon: 'success' })
this.setData({ editModalVisible: false })
await this.loadCustomer()
} catch (error) {
wx.showToast({ title: error.message || '保存失败', icon: 'none' })
} finally {
this.setData({ saving: false })
}
},
createAppointment() {
if (!this.data.canCreateAppointment) {
wx.showToast({ title: '美甲师账号只能查看预约', icon: 'none' })
@@ -13,7 +13,21 @@
<text class="customer-phone">{{customer.phone}}</text>
</view>
</view>
<button wx:if="{{canCreateAppointment}}" class="small-action" bindtap="createAppointment">新预约</button>
<view class="customer-actions">
<button class="small-action" bindtap="openEditModal">编辑</button>
<button wx:if="{{canCreateAppointment}}" class="small-action" bindtap="createAppointment">新预约</button>
</view>
</view>
<view class="card info-card">
<view class="info-row">
<text>联系电话</text>
<text>{{customer.phone}}</text>
</view>
<view class="info-row">
<text>备注</text>
<text>{{customer.remark || '未填写'}}</text>
</view>
</view>
<view class="stats">
@@ -44,5 +58,25 @@
</view>
</view>
</view>
<view wx:if="{{editModalVisible}}" class="modal-mask" bindtap="closeEditModal">
<view class="customer-modal" catchtap="stopTap">
<view class="modal-head">
<text class="modal-title">编辑客户</text>
<view class="modal-close" bindtap="closeEditModal">×</view>
</view>
<view class="form-grid">
<view class="modal-field">
<text>联系电话</text>
<input value="{{editForm.contactPhone}}" data-field="contactPhone" bindinput="onEditInput" type="text" placeholder="请输入联系电话" />
</view>
<view class="modal-field">
<text>备注</text>
<textarea value="{{editForm.remark}}" data-field="remark" bindinput="onEditInput" maxlength="200" placeholder="请输入客户备注" />
</view>
</view>
<button class="primary-btn modal-submit" loading="{{saving}}" bindtap="saveCustomer">保存客户</button>
</view>
</view>
</block>
</view>
@@ -43,6 +43,48 @@
font-size: 24rpx;
}
.customer-actions {
display: flex;
align-items: center;
flex-shrink: 0;
gap: 12rpx;
}
.info-card {
margin-top: 18rpx;
overflow: hidden;
}
.info-row {
display: flex;
align-items: flex-start;
justify-content: space-between;
gap: 24rpx;
min-height: 92rpx;
padding: 24rpx;
border-bottom: 1rpx solid #eee8df;
}
.info-row:last-child {
border-bottom: 0;
}
.info-row text:first-child {
flex-shrink: 0;
color: #625c55;
font-size: 26rpx;
font-weight: 700;
}
.info-row text:last-child {
min-width: 0;
color: #27231f;
font-size: 27rpx;
line-height: 1.45;
text-align: right;
word-break: break-all;
}
.stats {
display: grid;
grid-template-columns: repeat(3, 1fr);
@@ -94,3 +136,130 @@
max-width: 180rpx;
margin: 24rpx auto 0;
}
.modal-mask {
position: fixed;
inset: 0;
z-index: 80;
display: flex;
align-items: flex-end;
justify-content: center;
background: rgba(18, 15, 12, 0.48);
animation: maskIn 180ms ease both;
}
.customer-modal {
width: 100%;
max-height: 88vh;
overflow-y: auto;
padding: 28rpx 28rpx calc(28rpx + env(safe-area-inset-bottom));
border-radius: 28rpx 28rpx 0 0;
background: #fffaf4;
box-shadow: 0 -18rpx 40rpx rgba(41, 31, 23, 0.16);
animation: modalUp 220ms ease both;
}
.modal-head {
display: flex;
align-items: center;
justify-content: space-between;
gap: 20rpx;
margin-bottom: 20rpx;
}
.modal-title {
color: #27211d;
font-size: 34rpx;
font-weight: 900;
}
.modal-close {
position: relative;
display: flex;
align-items: center;
justify-content: center;
width: 48rpx;
min-width: 48rpx;
height: 48rpx;
border: 1rpx solid #e4d8ca;
border-radius: 50%;
background: #fffaf4;
color: transparent;
font-size: 0;
line-height: 0;
}
.modal-close::before,
.modal-close::after {
content: "";
position: absolute;
width: 22rpx;
height: 3rpx;
border-radius: 999rpx;
background: #61554c;
}
.modal-close::before {
transform: rotate(45deg);
}
.modal-close::after {
transform: rotate(-45deg);
}
.form-grid {
display: grid;
grid-template-columns: 1fr;
gap: 16rpx;
}
.modal-field {
padding: 16rpx 18rpx;
border-radius: 18rpx;
background: #f7efe7;
}
.modal-field text {
display: block;
margin-bottom: 8rpx;
color: #6c5f54;
font-size: 24rpx;
font-weight: 800;
}
.modal-field input,
.modal-field textarea {
width: 100%;
color: #2c2722;
font-size: 28rpx;
}
.modal-field input {
height: 58rpx;
}
.modal-field textarea {
min-height: 140rpx;
}
.modal-submit {
margin-top: 22rpx;
}
@keyframes maskIn {
from {
opacity: 0;
}
to {
opacity: 1;
}
}
@keyframes modalUp {
from {
transform: translateY(40rpx);
}
to {
transform: translateY(0);
}
}