From b3a8c7e01c53405d08ee88a80357450fa6e815ac Mon Sep 17 00:00:00 2001 From: xiaowang <2161656029@qq.com> Date: Thu, 29 Oct 2026 17:02:57 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=9D=E5=AD=98=E5=AE=A2=E6=88=B7=E4=B8=8E?= =?UTF-8?q?=E7=BE=8E=E7=94=B2=E5=B8=88=E8=A1=A8=E5=8D=95=E6=94=B9=E9=80=A0?= =?UTF-8?q?=E6=A3=80=E6=9F=A5=E7=82=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../modules/artist/dto/NailArtistInfoDTO.java | 3 + .../artist/entity/NailArtistInfoDO.java | 3 + .../impl/NailArtistInfoServiceImpl.java | 1 + .../admin/AdminManagerController.java | 2 +- .../manager/dto/ManagerCustomerCreateDTO.java | 2 + .../service/impl/PlanningServiceImpl.java | 3 +- .../salon/core/modules/user/dto/UserDTO.java | 3 + .../core/modules/user/entity/UserDO.java | 4 + .../core/modules/user/mapper/UserMapper.java | 2 +- .../modules/user/service/UserService.java | 2 + .../user/service/impl/UserServiceImpl.java | 111 ++++++++++++++---- ...联系方式去重和美甲师专属颜色_20261029.sql | 110 +++++++++++++++++ JC-Salon-WeChat/pages/customers/index.js | 11 +- JC-Salon-WeChat/pages/customers/index.test.js | 49 ++++++++ JC-Salon-WeChat/pages/customers/index.wxml | 8 +- .../pages/employee-create/index.js | 40 ++++++- .../pages/employee-create/index.test.js | 18 ++- .../pages/employee-create/index.wxml | 14 ++- .../pages/employee-create/index.wxss | 19 +++ JC-Salon-WeChat/pages/planning/index.js | 15 ++- JC-Salon-WeChat/pages/planning/index.test.js | 5 + JC-Salon-WeChat/pages/planning/index.wxml | 2 +- JC-Salon-WeChat/pages/planning/index.wxss | 50 +++++--- docs/项目变更记录.md | 8 ++ 24 files changed, 425 insertions(+), 60 deletions(-) create mode 100644 JC-Salon-Core/src/main/resources/db/migration/V8__客户联系方式去重和美甲师专属颜色_20261029.sql create mode 100644 JC-Salon-WeChat/pages/customers/index.test.js diff --git a/JC-Salon-Core/src/main/java/com/xiaowang/jayucloud/salon/core/modules/artist/dto/NailArtistInfoDTO.java b/JC-Salon-Core/src/main/java/com/xiaowang/jayucloud/salon/core/modules/artist/dto/NailArtistInfoDTO.java index 1c5ceafb..ce20916d 100644 --- a/JC-Salon-Core/src/main/java/com/xiaowang/jayucloud/salon/core/modules/artist/dto/NailArtistInfoDTO.java +++ b/JC-Salon-Core/src/main/java/com/xiaowang/jayucloud/salon/core/modules/artist/dto/NailArtistInfoDTO.java @@ -39,6 +39,9 @@ public class NailArtistInfoDTO { */ private String skills; + /** 规划页使用的专属颜色。 */ + private String color; + /** * 评分 */ diff --git a/JC-Salon-Core/src/main/java/com/xiaowang/jayucloud/salon/core/modules/artist/entity/NailArtistInfoDO.java b/JC-Salon-Core/src/main/java/com/xiaowang/jayucloud/salon/core/modules/artist/entity/NailArtistInfoDO.java index 0e4e63f7..28f6ba48 100644 --- a/JC-Salon-Core/src/main/java/com/xiaowang/jayucloud/salon/core/modules/artist/entity/NailArtistInfoDO.java +++ b/JC-Salon-Core/src/main/java/com/xiaowang/jayucloud/salon/core/modules/artist/entity/NailArtistInfoDO.java @@ -37,6 +37,9 @@ public class NailArtistInfoDO extends BaseEntity { */ private String skills; + /** 规划页使用的专属颜色。 */ + private String color; + /** * 评分 */ diff --git a/JC-Salon-Core/src/main/java/com/xiaowang/jayucloud/salon/core/modules/artist/service/impl/NailArtistInfoServiceImpl.java b/JC-Salon-Core/src/main/java/com/xiaowang/jayucloud/salon/core/modules/artist/service/impl/NailArtistInfoServiceImpl.java index bebc69c0..995cdee2 100644 --- a/JC-Salon-Core/src/main/java/com/xiaowang/jayucloud/salon/core/modules/artist/service/impl/NailArtistInfoServiceImpl.java +++ b/JC-Salon-Core/src/main/java/com/xiaowang/jayucloud/salon/core/modules/artist/service/impl/NailArtistInfoServiceImpl.java @@ -331,6 +331,7 @@ public class NailArtistInfoServiceImpl extends ServiceImpl { @Select("SELECT id FROM t_user WHERE account = #{account} AND account_hash IS NULL AND is_delete = 0 LIMIT 1") Long findLegacyIdByAccount(@Param("account") String account); - @Select("SELECT id FROM t_user WHERE phone = #{phone} AND phone_hash IS NULL AND is_delete = 0 LIMIT 1") + @Select("SELECT id FROM t_user WHERE phone = #{phone} AND phone_hash IS NULL AND is_delete = 0 AND type <> 0 LIMIT 1") Long findLegacyIdByPhone(@Param("phone") String phone); @Select("SELECT id FROM t_user WHERE contact_phone = #{phone} AND contact_phone_hash IS NULL AND is_delete = 0 LIMIT 1") diff --git a/JC-Salon-Core/src/main/java/com/xiaowang/jayucloud/salon/core/modules/user/service/UserService.java b/JC-Salon-Core/src/main/java/com/xiaowang/jayucloud/salon/core/modules/user/service/UserService.java index 18ae6605..10832d82 100644 --- a/JC-Salon-Core/src/main/java/com/xiaowang/jayucloud/salon/core/modules/user/service/UserService.java +++ b/JC-Salon-Core/src/main/java/com/xiaowang/jayucloud/salon/core/modules/user/service/UserService.java @@ -36,6 +36,8 @@ public interface UserService extends IService { Long createManagerCustomer(String nickname, String phone, Long shopId); + Long createManagerCustomer(String nickname, String wechatId, String phone, Long shopId); + List findCustomerMatches(String nickname, String phone, Long shopId); diff --git a/JC-Salon-Core/src/main/java/com/xiaowang/jayucloud/salon/core/modules/user/service/impl/UserServiceImpl.java b/JC-Salon-Core/src/main/java/com/xiaowang/jayucloud/salon/core/modules/user/service/impl/UserServiceImpl.java index 22d29e0b..547d964a 100644 --- a/JC-Salon-Core/src/main/java/com/xiaowang/jayucloud/salon/core/modules/user/service/impl/UserServiceImpl.java +++ b/JC-Salon-Core/src/main/java/com/xiaowang/jayucloud/salon/core/modules/user/service/impl/UserServiceImpl.java @@ -389,12 +389,13 @@ public class UserServiceImpl extends ServiceImpl implements List validatedShopIds = resolveValidatedShopIds(userDTO.getShopIds(), userDTO.getShopId()); Long validatedShopId = pickPrimaryShopId(validatedShopIds); Integer userType = userDTO.getType(); - String validatedPhone = validateUserPhone(userDTO.getPhone(), null, - !(allowMissingCustomerPhone && Integer.valueOf(0).equals(userType))); - if (Integer.valueOf(0).equals(userType)) { - ensureCustomerUnique(userDTO.getNickname(), validatedPhone); - } + String validatedPhone = Integer.valueOf(0).equals(userType) + ? validateCustomerPhone(userDTO.getPhone(), !(allowMissingCustomerPhone && Integer.valueOf(0).equals(userType))) + : validateUserPhone(userDTO.getPhone(), null, true); String validatedWechatId = UserProfileFieldSupport.normalizeOptionalText(userDTO.getWechatId()); + if (Integer.valueOf(0).equals(userType)) { + ensureCustomerUnique(userDTO.getNickname(), validatedWechatId, validatedPhone); + } UserProfileFieldSupport.requireWechatIdForServiceUser(userType, validatedWechatId); /** @@ -409,7 +410,8 @@ public class UserServiceImpl extends ServiceImpl implements // 创建用户实体并设置属性 UserDO userDO = new UserDO(); userDO.setShopId(validatedShopId); - userDO.setNickname(userDTO.getNickname()); + userDO.setNickname(Integer.valueOf(0).equals(userType) && userDTO.getNickname() != null + ? userDTO.getNickname().trim() : userDTO.getNickname()); userDO.setAccount(validatedAccount); String resolvedPassword = AdminDefaultPasswordSupport.resolveCreatePassword( userDTO.getPassword(), @@ -418,6 +420,9 @@ public class UserServiceImpl extends ServiceImpl implements validatePasswordStrength(resolvedPassword); userDO.setPassword(passwordEncoder.encode(resolvedPassword)); userDO.setPhone(validatedPhone); + if (Integer.valueOf(0).equals(userType)) { + userDO.setCustomerIdentityHash(customerIdentityHash(userDO.getNickname(), validatedWechatId, validatedPhone)); + } userDO.setContactPhone(UserProfileFieldSupport.normalizeOptionalText(userDTO.getContactPhone())); userDO.setBirthday(userDTO.getBirthday()); userDO.setWechatId(validatedWechatId); @@ -490,6 +495,7 @@ public class UserServiceImpl extends ServiceImpl implements nailArtistInfoDTO.setRating(DEFAULT_NAIL_ARTIST_RATING); // 默认评分为4.5 nailArtistInfoDTO.setStatus(1); // 默认状态为营业中 nailArtistInfoDTO.setPortfolio(""); // 默认作品集为空 + nailArtistInfoDTO.setColor(normalizeArtistColor(userDTO.getColor())); nailArtistInfoService.saveOrUpdateNailArtistInfo(nailArtistInfoDTO); } @@ -499,6 +505,12 @@ public class UserServiceImpl extends ServiceImpl implements @Override @Transactional(rollbackFor = Exception.class) public Long createManagerCustomer(String nickname, String phone, Long shopId) { + return createManagerCustomer(nickname, null, phone, shopId); + } + + @Override + @Transactional(rollbackFor = Exception.class) + public Long createManagerCustomer(String nickname, String wechatId, String phone, Long shopId) { if (!StringUtils.hasText(nickname)) { throw new RuntimeException("客户姓名不能为空"); } @@ -506,15 +518,15 @@ public class UserServiceImpl extends ServiceImpl implements throw new RuntimeException("请先选择店铺后再新增客户"); } String normalizedPhone = phone == null || phone.trim().isEmpty() ? null : phone.trim(); - ensureCustomerUnique(nickname, normalizedPhone); - normalizedPhone = validateUserPhone(normalizedPhone, null, false); + normalizedPhone = validateCustomerPhone(normalizedPhone, false); + String normalizedWechatId = UserProfileFieldSupport.normalizeOptionalText(wechatId); + ensureCustomerUnique(nickname, normalizedWechatId, normalizedPhone); UserDTO customer = new UserDTO(); customer.setNickname(nickname.trim()); + customer.setWechatId(normalizedWechatId); customer.setPhone(normalizedPhone); customer.setContactPhone(normalizedPhone); - customer.setAccount(normalizedPhone == null - ? "customer" + UUID.randomUUID().toString().replace("-", "") - : normalizedPhone); + customer.setAccount("customer" + UUID.randomUUID().toString().replace("-", "")); customer.setType(0); customer.setShopId(shopId); customer.setShopIds(List.of(shopId)); @@ -532,8 +544,9 @@ public class UserServiceImpl extends ServiceImpl implements .eq(UserDO::getNickname, nickname.trim()) .eq(UserDO::getType, 0) .eq(UserDO::getIsDelete, 0); - if (StringUtils.hasText(phone)) { - String normalizedPhone = phone.trim(); + String normalizedName = nickname.trim(); + String normalizedPhone = StringUtils.hasText(phone) ? phone.trim() : null; + if (normalizedPhone != null) { addPhoneMatch(wrapper, normalizedPhone); } if (shopId != null && shopId > 0) { @@ -545,7 +558,10 @@ public class UserServiceImpl extends ServiceImpl implements .or().in(UserDO::getId, shopUserIds)); } } - return userMapper.selectList(wrapper).stream().map(user -> { + return userMapper.selectList(wrapper).stream() + .filter(user -> java.util.Objects.equals(normalizedName, user.getNickname())) + .filter(user -> normalizedPhone == null || java.util.Objects.equals(normalizedPhone, decryptPhone(user.getPhone()))) + .map(user -> { UserVO customer = new UserVO(); customer.setId(user.getId()); customer.setNickname(user.getNickname()); @@ -641,7 +657,8 @@ public class UserServiceImpl extends ServiceImpl implements userDO.setShopId(validateAndNormalizeShopId(userDTO.getShopId())); } if (userDTO.getNickname() != null) { - userDO.setNickname(userDTO.getNickname()); + userDO.setNickname(Integer.valueOf(0).equals(userDO.getType()) + ? userDTO.getNickname().trim() : userDTO.getNickname()); } if (userDTO.getPassword() != null) { validatePasswordStrength(userDTO.getPassword()); @@ -710,6 +727,13 @@ public class UserServiceImpl extends ServiceImpl implements } Integer targetUserType = userDO.getType(); UserProfileFieldSupport.requireWechatIdForServiceUser(targetUserType, userDO.getWechatId()); + if (Integer.valueOf(0).equals(targetUserType)) { + String customerPhone = validateCustomerPhone(userDO.getPhone(), false); + ensureCustomerUnique(userDO.getNickname(), userDO.getWechatId(), customerPhone, id); + userDO.setCustomerIdentityHash(customerIdentityHash(userDO.getNickname(), userDO.getWechatId(), customerPhone)); + } else { + userDO.setCustomerIdentityHash(null); + } List validatedShopIds = null; boolean shopBindingChanged = userDTO.getShopIds() != null || userDTO.getShopId() != null; if (shopBindingChanged) { @@ -3229,7 +3253,11 @@ public class UserServiceImpl extends ServiceImpl implements } } - private void ensureCustomerUnique(String nickname, String phone) { + private void ensureCustomerUnique(String nickname, String wechatId, String phone) { + ensureCustomerUnique(nickname, wechatId, phone, null); + } + + private void ensureCustomerUnique(String nickname, String wechatId, String phone, Long ignoredCustomerId) { if (!StringUtils.hasText(nickname)) { throw new RuntimeException("客户姓名不能为空"); } @@ -3237,14 +3265,57 @@ public class UserServiceImpl extends ServiceImpl implements .eq(UserDO::getNickname, nickname.trim()) .eq(UserDO::getType, 0) .eq(UserDO::getIsDelete, 0); - if (StringUtils.hasText(phone)) { - addPhoneMatch(wrapper, phone); - } - if (userMapper.selectCount(wrapper) > 0) { + String normalizedWechatId = UserProfileFieldSupport.normalizeOptionalText(wechatId); + String normalizedPhone = StringUtils.hasText(phone) ? phone.trim() : null; + boolean duplicate = userMapper.selectList(wrapper).stream().anyMatch(existing -> + !java.util.Objects.equals(ignoredCustomerId, existing.getId()) + && java.util.Objects.equals(normalizedWechatId, UserProfileFieldSupport.normalizeOptionalText(existing.getWechatId())) + && java.util.Objects.equals(normalizedPhone, decryptPhone(existing.getPhone()))); + if (duplicate) { throw new RuntimeException("客户已存在,请选择已有客户"); } } + private String decryptPhone(String value) { + return StringUtils.hasText(value) ? phoneCrypto.decrypt(value).trim() : null; + } + + private String validateCustomerPhone(String phone, boolean required) { + String normalizedPhone = phone == null ? null : phone.trim(); + if (!StringUtils.hasText(normalizedPhone)) { + if (required) throw new RuntimeException("手机号不能为空"); + return null; + } + if (!normalizedPhone.matches(PHONE_REGEX)) { + throw new RuntimeException("手机号格式不正确"); + } + return normalizedPhone; + } + + private String customerIdentityHash(String nickname, String wechatId, String phone) { + String normalizedName = StringUtils.hasText(nickname) ? nickname.trim() : ""; + String normalizedWechatId = UserProfileFieldSupport.normalizeOptionalText(wechatId); + String normalizedPhone = StringUtils.hasText(phone) ? phone.trim() : null; + return phoneCrypto.index(identityPart(normalizedName) + + identityPart(normalizedWechatId == null ? "" : normalizedWechatId) + + identityPart(normalizedPhone == null ? "" : normalizedPhone)); + } + + private String identityPart(String value) { + return value.length() + ":" + value; + } + + private String normalizeArtistColor(String color) { + if (!StringUtils.hasText(color)) { + return null; + } + String value = color.trim().toUpperCase(java.util.Locale.ROOT); + if (!value.matches("#[0-9A-F]{6}")) { + throw new RuntimeException("美甲师专属颜色格式不正确"); + } + return value; + } + private void addPhoneMatch(LambdaQueryWrapper wrapper, String phone) { String hash = phoneCrypto.index(phone.trim()); List legacyIds = new ArrayList<>(); diff --git a/JC-Salon-Core/src/main/resources/db/migration/V8__客户联系方式去重和美甲师专属颜色_20261029.sql b/JC-Salon-Core/src/main/resources/db/migration/V8__客户联系方式去重和美甲师专属颜色_20261029.sql new file mode 100644 index 00000000..67f1de48 --- /dev/null +++ b/JC-Salon-Core/src/main/resources/db/migration/V8__客户联系方式去重和美甲师专属颜色_20261029.sql @@ -0,0 +1,110 @@ +-- 客户允许重名及重复手机号;仅姓名、微信号、手机号组合完全相同时拒绝创建。 +-- 美甲师专属颜色持久化到资料表,规划页与员工页面共用同一颜色。 + +DROP PROCEDURE IF EXISTS salon_v8_add_column_if_missing; +DROP PROCEDURE IF EXISTS salon_v8_add_index_if_missing; +DROP PROCEDURE IF EXISTS salon_v8_add_unique_index_if_missing; +DROP PROCEDURE IF EXISTS salon_v8_drop_index_if_exists; + +DELIMITER $$ + +CREATE PROCEDURE salon_v8_add_column_if_missing( + 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 @salon_v8_sql = CONCAT('ALTER TABLE `', p_table_name, '` ADD COLUMN `', p_column_name, '` ', p_definition); + PREPARE salon_v8_stmt FROM @salon_v8_sql; + EXECUTE salon_v8_stmt; + DEALLOCATE PREPARE salon_v8_stmt; + END IF; +END$$ + +CREATE PROCEDURE salon_v8_add_index_if_missing( + 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 @salon_v8_sql = CONCAT('ALTER TABLE `', p_table_name, '` ADD INDEX `', p_index_name, '` ', p_columns); + PREPARE salon_v8_stmt FROM @salon_v8_sql; + EXECUTE salon_v8_stmt; + DEALLOCATE PREPARE salon_v8_stmt; + END IF; +END$$ + +CREATE PROCEDURE salon_v8_add_unique_index_if_missing( + 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 @salon_v8_sql = CONCAT('ALTER TABLE `', p_table_name, '` ADD UNIQUE INDEX `', p_index_name, '` ', p_columns); + PREPARE salon_v8_stmt FROM @salon_v8_sql; + EXECUTE salon_v8_stmt; + DEALLOCATE PREPARE salon_v8_stmt; + END IF; +END$$ + +CREATE PROCEDURE salon_v8_drop_index_if_exists( + IN p_table_name VARCHAR(64), + IN p_index_name VARCHAR(64) +) +BEGIN + IF 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 @salon_v8_sql = CONCAT('ALTER TABLE `', p_table_name, '` DROP INDEX `', p_index_name, '`'); + PREPARE salon_v8_stmt FROM @salon_v8_sql; + EXECUTE salon_v8_stmt; + DEALLOCATE PREPARE salon_v8_stmt; + END IF; +END$$ + +DELIMITER ; + +CALL salon_v8_add_column_if_missing( + 't_user', 'customer_identity_hash', + 'char(64) NULL COMMENT ''客户姓名、微信号和手机号组合HMAC''' +); +CALL salon_v8_add_column_if_missing( + 't_user', 'active_customer_identity_hash', + 'char(64) GENERATED ALWAYS AS (CASE WHEN type = 0 AND COALESCE(is_delete, 0) = 0 THEN customer_identity_hash ELSE NULL END) STORED COMMENT ''有效客户组合身份索引''' +); +CALL salon_v8_add_column_if_missing( + 't_nail_artist_info', 'color', + 'varchar(7) NULL COMMENT ''美甲师规划专属颜色''' +); + +CALL salon_v8_drop_index_if_exists('t_user', 'uk_user_phone_hash'); +CALL salon_v8_add_index_if_missing('t_user', 'idx_user_phone_hash', '(`phone_hash`)'); +CALL salon_v8_add_unique_index_if_missing( + 't_user', 'uk_user_active_customer_identity_hash', '(`active_customer_identity_hash`)' +); + +DROP PROCEDURE IF EXISTS salon_v8_add_column_if_missing; +DROP PROCEDURE IF EXISTS salon_v8_add_index_if_missing; +DROP PROCEDURE IF EXISTS salon_v8_add_unique_index_if_missing; +DROP PROCEDURE IF EXISTS salon_v8_drop_index_if_exists; diff --git a/JC-Salon-WeChat/pages/customers/index.js b/JC-Salon-WeChat/pages/customers/index.js index 0d140be2..bafb92b9 100644 --- a/JC-Salon-WeChat/pages/customers/index.js +++ b/JC-Salon-WeChat/pages/customers/index.js @@ -9,6 +9,7 @@ Page({ creating: false, createForm: { nickname: '', + wechatId: '', phone: '' } }, @@ -72,6 +73,7 @@ Page({ this.setData({ createForm: { nickname: '', + wechatId: '', phone: '' } }) @@ -80,18 +82,19 @@ Page({ async submitCustomer() { const form = this.data.createForm const nickname = String(form.nickname || '').trim() + const wechatId = String(form.wechatId || '').trim() const phone = String(form.phone || '').trim() - if (!nickname || !phone) { - wx.showToast({ title: '请填写客户姓名和手机号', icon: 'none' }) + if (!nickname) { + wx.showToast({ title: '请填写客户姓名', icon: 'none' }) return } - if (!/^1[3-9]\d{9}$/.test(phone)) { + if (phone && !/^1[3-9]\d{9}$/.test(phone)) { wx.showToast({ title: '请输入正确手机号', icon: 'none' }) return } this.setData({ creating: true }) try { - await customersApi.create({ nickname, phone }) + await customersApi.create({ nickname, wechatId: wechatId || undefined, phone: phone || undefined }) wx.showToast({ title: '客户已新增', icon: 'success' }) this.resetCreateForm() this.setData({ createModalVisible: false }) diff --git a/JC-Salon-WeChat/pages/customers/index.test.js b/JC-Salon-WeChat/pages/customers/index.test.js new file mode 100644 index 00000000..adcda100 --- /dev/null +++ b/JC-Salon-WeChat/pages/customers/index.test.js @@ -0,0 +1,49 @@ +const assert = require('assert') +const customersApi = require('../../api/customers') + +let definition +global.Page = value => { definition = value } +global.wx = { + showToast: () => {}, + navigateTo: () => {} +} +require('./index') + +function createPage() { + return { + ...definition, + data: JSON.parse(JSON.stringify(definition.data)), + setData(values) { + Object.entries(values).forEach(([key, value]) => { + const parts = key.split('.') + let target = this.data + for (let index = 0; index < parts.length - 1; index += 1) target = target[parts[index]] + target[parts[parts.length - 1]] = value + }) + } + } +} + +async function run() { + const page = createPage() + let submitted + let toast + global.wx.showToast = options => { toast = options.title } + customersApi.create = async value => { submitted = value } + customersApi.list = async () => ({ list: [] }) + + page.setData({ 'createForm.nickname': '小周', 'createForm.wechatId': 'wx_zhou' }) + await page.submitCustomer() + assert.deepStrictEqual(submitted, { nickname: '小周', wechatId: 'wx_zhou', phone: undefined }) + + submitted = undefined + page.setData({ 'createForm.nickname': '', 'createForm.phone': '' }) + await page.submitCustomer() + assert.strictEqual(submitted, undefined) + assert.strictEqual(toast, '请填写客户姓名') +} + +run().catch(error => { + console.error(error) + process.exitCode = 1 +}) diff --git a/JC-Salon-WeChat/pages/customers/index.wxml b/JC-Salon-WeChat/pages/customers/index.wxml index 369c52f4..d063165a 100644 --- a/JC-Salon-WeChat/pages/customers/index.wxml +++ b/JC-Salon-WeChat/pages/customers/index.wxml @@ -34,8 +34,12 @@ - 手机号 - + 微信号 + + + + 手机号 + diff --git a/JC-Salon-WeChat/pages/employee-create/index.js b/JC-Salon-WeChat/pages/employee-create/index.js index f2565dec..c2d3fbaf 100644 --- a/JC-Salon-WeChat/pages/employee-create/index.js +++ b/JC-Salon-WeChat/pages/employee-create/index.js @@ -2,11 +2,13 @@ const employeesApi = require('../../api/employees') const { chooseImageFilePath, uploadObjectFile } = require('../../utils/upload') const DEFAULT_EMPLOYEE_PASSWORD = 'Fingertip@123' +const EMPLOYEE_COLORS = ['#7BA7C7', '#8FB89A', '#A894C7', '#D7A86E', '#D98DA5', '#79A6A3', '#B9A16B', '#9BA9C8'] Page({ data: { pickerMode: false, appointmentContext: { date: '', time: '', durationMinutes: '' }, + employeeColors: EMPLOYEE_COLORS, onboardingVisible: false, createdEmployee: null, form: { @@ -15,6 +17,7 @@ Page({ account: '', password: DEFAULT_EMPLOYEE_PASSWORD, wechatId: '', + color: '#8FB89A', avatar: '', avatarUrl: '' }, @@ -37,10 +40,15 @@ Page({ const field = event.currentTarget.dataset.field const value = event.detail.value const updates = { [`form.${field}`]: value } - if (field === 'phone' && !this.data.form.account) updates['form.account'] = value + if (field === 'account') this._accountManuallyEdited = true + if (field === 'phone' && !this._accountManuallyEdited) updates['form.account'] = value this.setData(updates) }, + selectColor(event) { + this.setData({ 'form.color': event.currentTarget.dataset.color }) + }, + async chooseAvatar() { if (this.data.avatarUploading || this.data.creating) return try { @@ -74,7 +82,7 @@ Page({ const account = String(form.account || '').trim() const password = String(form.password || '').trim() const wechatId = String(form.wechatId || '').trim() - if (!nickname || !phone || !account || !password || !wechatId) { + if (!nickname || !phone || !account || !password) { wx.showToast({ title: '请补全美甲师信息', icon: 'none' }) return } @@ -91,6 +99,7 @@ Page({ account, password, wechatId, + color: form.color, avatar: form.avatar || undefined, type: 3 }) @@ -127,7 +136,32 @@ Page({ }, skipFirstSchedule() { - this.finishCreated(!this.data.pickerMode, false) + if (this.data.savingDefaultSchedule || !this.data.createdEmployee) return + this.setData({ savingDefaultSchedule: true }) + employeesApi.saveScheduleRule({ + artistId: this.data.createdEmployee.id, + presetType: 'CUSTOM', + workDays: [1, 2, 3, 4, 5, 6, 7], + startTime: '00:00', + endTime: '23:59', + status: 1, + remark: '新建美甲师默认全天可预约,可在排班设置中调整' + }).then(() => { + this.finishCreated(!this.data.pickerMode, false) + }).catch(error => { + wx.showModal({ + title: '默认排班设置失败', + content: error.message || '未设置排班前,该美甲师暂不可预约。请重试或返回排班设置。', + confirmText: '重试', + cancelText: '稍后设置', + success: result => { + if (result.confirm) this.skipFirstSchedule() + else this.setData({ savingDefaultSchedule: false }) + } + }) + }).finally(() => { + if (this.data.onboardingVisible) this.setData({ savingDefaultSchedule: false }) + }) }, finishCreated(autoSelect, scheduleSaved) { diff --git a/JC-Salon-WeChat/pages/employee-create/index.test.js b/JC-Salon-WeChat/pages/employee-create/index.test.js index 7767ff17..8cfe1bcc 100644 --- a/JC-Salon-WeChat/pages/employee-create/index.test.js +++ b/JC-Salon-WeChat/pages/employee-create/index.test.js @@ -34,19 +34,33 @@ const page = { async function run() { page.onInput({ currentTarget: { dataset: { field: 'phone' } }, detail: { value: '13800138000' } }) assert.strictEqual(page.data.form.account, '13800138000') + page.onInput({ currentTarget: { dataset: { field: 'account' } }, detail: { value: 'staff_zhou' } }) + page.onInput({ currentTarget: { dataset: { field: 'phone' } }, detail: { value: '13900139000' } }) + assert.strictEqual(page.data.form.account, 'staff_zhou') + assert.strictEqual(page.data.form.color, '#8FB89A') Object.assign(page.data.form, { nickname: '小周', phone: '13800138000', account: '13800138000', password: 'Fingertip@123', - wechatId: 'wx_zhou' + wechatId: '' }) - employeesApi.createUser = async () => 88 + employeesApi.createUser = async payload => { + assert.strictEqual(payload.wechatId, '') + assert.strictEqual(payload.color, '#8FB89A') + return 88 + } await page.submit() assert.strictEqual(page.data.onboardingVisible, true) assert.strictEqual(emitted, undefined) page.data.pickerMode = true + employeesApi.saveScheduleRule = async payload => { + assert.deepStrictEqual(payload.workDays, [1, 2, 3, 4, 5, 6, 7]) + assert.strictEqual(payload.startTime, '00:00') + assert.strictEqual(payload.endTime, '23:59') + } page.skipFirstSchedule() + await new Promise(resolve => setImmediate(resolve)) assert.strictEqual(emitted.name, 'employeeCreated') assert.deepStrictEqual(emitted.value, { id: 88, name: '小周', title: '小周', avatar: '', autoSelect: false, scheduleSaved: false }) assert.strictEqual(navigatedBack, true) diff --git a/JC-Salon-WeChat/pages/employee-create/index.wxml b/JC-Salon-WeChat/pages/employee-create/index.wxml index 61c86396..b78e183e 100644 --- a/JC-Salon-WeChat/pages/employee-create/index.wxml +++ b/JC-Salon-WeChat/pages/employee-create/index.wxml @@ -33,8 +33,14 @@ - 微信号 - + 微信号 + + + + 专属颜色 + + + @@ -47,8 +53,8 @@ ✓ 美甲师已创建 {{pickerMode ? '设置常规排班后,可继续把当前预约分配给该美甲师。' : '为新美甲师设置首个常规排班,之后即可正常承接预约。'}} - - + + diff --git a/JC-Salon-WeChat/pages/employee-create/index.wxss b/JC-Salon-WeChat/pages/employee-create/index.wxss index 508d2455..1ec7a624 100644 --- a/JC-Salon-WeChat/pages/employee-create/index.wxss +++ b/JC-Salon-WeChat/pages/employee-create/index.wxss @@ -80,6 +80,25 @@ width: 176rpx; } +.color-options { + display: flex; + flex-wrap: wrap; + gap: 18rpx; + padding: 10rpx 0; +} + +.color-option { + width: 44rpx; + height: 44rpx; + border: 4rpx solid #fff; + border-radius: 50%; + box-shadow: 0 0 0 1rpx #d9e3dd; +} + +.color-option.selected { + box-shadow: 0 0 0 4rpx #287a62; +} + .onboarding-mask { position: fixed; z-index: 50; diff --git a/JC-Salon-WeChat/pages/planning/index.js b/JC-Salon-WeChat/pages/planning/index.js index 4d53ce0a..e5a7b426 100644 --- a/JC-Salon-WeChat/pages/planning/index.js +++ b/JC-Salon-WeChat/pages/planning/index.js @@ -466,16 +466,17 @@ Page({ }, buildDayView(calendar) { + const minuteScale = 4 const startMinute = dateUtil.minutesOfDay(calendar.businessStartTime || '10:00') const endMinute = dateUtil.minutesOfDay(calendar.businessEndTime || '22:00') - const timelineHeight = Math.max(560, endMinute - startMinute) + const timelineHeight = Math.max(560, (endMinute - startMinute) * minuteScale) const laneHeaderHeight = 54 const hours = [] for (let cursor = startMinute; cursor <= endMinute; cursor += 60) { hours.push({ value: cursor, label: dateUtil.timeFromMinutes(cursor), - top: cursor - startMinute + laneHeaderHeight + top: (cursor - startMinute) * minuteScale + laneHeaderHeight }) } const filteredArtists = this.data.selectedArtistId @@ -491,8 +492,9 @@ Page({ const itemStart = resolveAppointmentStartMinute(item) return { ...item, - top: Math.max(0, itemStart - startMinute) + laneHeaderHeight, - height: Math.max(64, item.durationMinutes || 60), + top: Math.max(0, itemStart - startMinute) * minuteScale + laneHeaderHeight, + height: Math.max(100, (item.durationMinutes || 60) * minuteScale), + compact: Number(item.durationMinutes || 60) <= 15, timeText: resolveAppointmentTimeText(item) } }) @@ -505,8 +507,9 @@ Page({ const itemStart = resolveAppointmentStartMinute(item) return { ...item, - top: Math.max(0, itemStart - startMinute) + laneHeaderHeight, - height: Math.max(64, item.durationMinutes || 60), + top: Math.max(0, itemStart - startMinute) * minuteScale + laneHeaderHeight, + height: Math.max(100, (item.durationMinutes || 60) * minuteScale), + compact: Number(item.durationMinutes || 60) <= 15, timeText: resolveAppointmentTimeText(item) } }) diff --git a/JC-Salon-WeChat/pages/planning/index.test.js b/JC-Salon-WeChat/pages/planning/index.test.js index 320e9fd1..67c7de2f 100644 --- a/JC-Salon-WeChat/pages/planning/index.test.js +++ b/JC-Salon-WeChat/pages/planning/index.test.js @@ -87,6 +87,11 @@ async function run() { assert.strictEqual(dayState.dayLanes[0].artistId, '__unassigned__') assert.strictEqual(dayState.dayLanes[0].blocks.length, 1) assert.strictEqual(dayState.unassignedCount, 1) + assert.strictEqual(dayState.timelineHeight, 2934) + assert.strictEqual(dayState.hours.find(item => item.label === '14:00').top, 1014) + assert.strictEqual(dayState.dayLanes[0].blocks[0].height, 240) + assert.match(planningWxss, /background-size:\s*100% 240rpx/) + assert.match(planningWxss, /\.control-card\s*\{[^}]*padding:\s*12rpx 16rpx;/) const requestPage = createPage({ viewMode: 'day', currentDateText: '2026-10-11' }) let calendarRequests = 0 diff --git a/JC-Salon-WeChat/pages/planning/index.wxml b/JC-Salon-WeChat/pages/planning/index.wxml index 0e373601..0950c886 100644 --- a/JC-Salon-WeChat/pages/planning/index.wxml +++ b/JC-Salon-WeChat/pages/planning/index.wxml @@ -95,7 +95,7 @@ {{item.name}} - + {{block.customerName}} {{block.timeText}} · {{block.productTitle}} {{block.statusText}} diff --git a/JC-Salon-WeChat/pages/planning/index.wxss b/JC-Salon-WeChat/pages/planning/index.wxss index 96063f4e..c1001795 100644 --- a/JC-Salon-WeChat/pages/planning/index.wxss +++ b/JC-Salon-WeChat/pages/planning/index.wxss @@ -72,7 +72,7 @@ } .control-card { - padding: 18rpx; + padding: 12rpx 16rpx; } .calendar-error-card { @@ -175,8 +175,8 @@ display: grid; grid-template-columns: repeat(3, 1fr); gap: 8rpx; - margin-top: 18rpx; - padding: 8rpx; + margin-top: 10rpx; + padding: 6rpx; border-radius: 12px; background: #f1ece4; } @@ -185,7 +185,7 @@ display: flex; align-items: center; justify-content: center; - height: 58rpx; + height: 46rpx; border-radius: 10px; color: #7d756c; font-size: 24rpx; @@ -203,7 +203,7 @@ .artist-filter { display: flex; width: 100%; - margin-top: 16rpx; + margin-top: 10rpx; white-space: nowrap; } @@ -291,13 +291,13 @@ .day-board { height: 820rpx; - margin-top: 18rpx; + margin-top: 12rpx; overflow: hidden; } .timeline-wrap { position: relative; - min-height: 720rpx; + min-height: 774rpx; } .time-axis { @@ -344,7 +344,7 @@ flex-shrink: 0; border-right: 1rpx solid #e7ece9; background-image: linear-gradient(to bottom, rgba(203, 220, 213, 0.45) 1rpx, transparent 1rpx); - background-size: 100% 60rpx; + background-size: 100% 240rpx; } .lane-head { @@ -367,9 +367,9 @@ left: 12rpx; display: flex; flex-direction: column; - gap: 4rpx; + gap: 2rpx; overflow: hidden; - padding: 12rpx 12rpx; + padding: 6rpx 10rpx; border-left: 8rpx solid #7ba7c7; border-radius: 10px; background: #fff7ee; @@ -389,28 +389,48 @@ .block-title { color: #17211f; - font-size: 24rpx; + font-size: 22rpx; font-weight: 800; } .block-meta, .block-status { color: #7e756b; - font-size: 20rpx; + font-size: 18rpx; line-height: 1.25; } .block-actions { display: flex; gap: 10rpx; - margin-top: 6rpx; + margin-top: 2rpx; color: #247b63; - font-size: 20rpx; + font-size: 18rpx; font-weight: 800; } .block-actions text { - padding: 2rpx 6rpx; + padding: 0 5rpx; +} + +.appointment-block.compact { + gap: 0; + padding: 2rpx 8rpx; +} + +.appointment-block.compact .block-title { + font-size: 20rpx; + line-height: 1.05; +} + +.appointment-block.compact .block-meta { + font-size: 16rpx; + line-height: 1.05; +} + +.appointment-block.compact .block-status, +.appointment-block.compact .block-actions { + display: none; } .lane-empty { diff --git a/docs/项目变更记录.md b/docs/项目变更记录.md index 1cf393e1..f36d38dd 100644 --- a/docs/项目变更记录.md +++ b/docs/项目变更记录.md @@ -1,5 +1,13 @@ # 项目变更记录 +## 2026-10-29 Salon 客户建档与员工默认排班优化 + +- 规划日视图时间轴放大为每分钟4rpx,使30分钟预约卡片获得完整信息高度;收紧日期控制区和视图切换区的垂直留白。 +- 客户新增姓名必填、微信号和手机号选填并按姓名/微信号/手机号排列;客户可重名或复用联系方式,仅姓名、微信号、手机号组合完全相同时禁止建档,联系方式匹配按密文解密后的精确值校验。 +- 新建美甲师表单增加专属颜色,颜色保存在员工资料并显示到规划日历;微信号选填,登录账号随手机号自动带入,手动编辑账号后不再覆盖。 +- 跳过首次排班引导时先写入每周七天00:00–23:59的常规规则,成功后才返回。 +- 新增 Flyway V8 `JC-Salon-Core/src/main/resources/db/migration/V8__客户联系方式去重和美甲师专属颜色_20261029.sql`,移除客户手机号全局唯一索引,增加客户组合身份活动记录唯一索引及员工颜色字段;不修改冻结初始化 SQL。 + ## 2026-10-26 Salon 店长注册审核模式与门店经营有效期 - 店长注册审核支持后台配置自动批准或人工复核;自动批准仅在该申请关联的门店资料内容审核通过后执行,店员原审核流程保持不变,并增加独立事务补偿检查。