diff --git a/FD-Core/src/main/java/com/xiaowang/fingertipdesigner/core/modules/artist/service/impl/NailArtistInfoServiceImpl.java b/FD-Core/src/main/java/com/xiaowang/fingertipdesigner/core/modules/artist/service/impl/NailArtistInfoServiceImpl.java index 61978493..997e57ea 100644 --- a/FD-Core/src/main/java/com/xiaowang/fingertipdesigner/core/modules/artist/service/impl/NailArtistInfoServiceImpl.java +++ b/FD-Core/src/main/java/com/xiaowang/fingertipdesigner/core/modules/artist/service/impl/NailArtistInfoServiceImpl.java @@ -590,7 +590,7 @@ public class NailArtistInfoServiceImpl extends ServiceImpl works = new ArrayList<>(); for (Long productId : limitedIds) { ProductDO product = productMap.get(productId); - if (product == null || isDeleted(product.getIsDelete())) { + if (product == null || isDeleted(product.getIsDelete()) || !isFrontVisible(product)) { continue; } works.add(buildWorkVO(product, fileMap)); @@ -667,7 +667,7 @@ public class NailArtistInfoServiceImpl extends ServiceImpl(); } return products.stream() - .filter(product -> product != null && product.getId() != null && !isDeleted(product.getIsDelete())) + .filter(product -> product != null && product.getId() != null && !isDeleted(product.getIsDelete()) && isFrontVisible(product)) .collect(Collectors.toMap(ProductDO::getId, product -> product, (left, right) -> left, HashMap::new)); } @@ -751,6 +751,10 @@ public class NailArtistInfoServiceImpl extends ServiceImpl ACTIVE_RESERVATION_STATUS = List.of("LOCKED", RESERVATION_PENDING_QUOTE, RESERVATION_CONFIRMED); private static final DateTimeFormatter DATE_TIME_FORMATTER = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"); @@ -136,8 +137,11 @@ public class PlanningServiceImpl implements PlanningService { if (dto == null) { throw new RuntimeException("预约信息不能为空"); } + if (Integer.valueOf(3).equals(currentUser.getType())) { + throw new RuntimeException("美甲师账号只能查看预约,不能新建预约"); + } Long shopId = requirePlanningShopId(currentUser); - ProductDO product = requireActiveProduct(dto.getProductId(), shopId); + ProductDO product = resolveAppointmentProduct(dto, shopId); UserDO artist = requireActiveArtist(dto.getArtistId(), shopId); UserDO customer = resolveCustomer(shopId, dto); @@ -583,6 +587,40 @@ public class PlanningServiceImpl implements PlanningService { return product; } + private ProductDO resolveAppointmentProduct(PlanningAppointmentCreateDTO dto, Long shopId) { + if (dto.getProductId() != null) { + return requireActiveProduct(dto.getProductId(), shopId); + } + return createManualAppointmentProduct(dto, shopId); + } + + private ProductDO createManualAppointmentProduct(PlanningAppointmentCreateDTO dto, Long shopId) { + String title = trimToNull(dto.getManualProductTitle()); + if (!hasText(title)) { + throw new RuntimeException("请选择预约项目或填写手动项目名称"); + } + BigDecimal price = dto.getManualProductPrice(); + if (price == null || price.compareTo(BigDecimal.ZERO) < 0) { + throw new RuntimeException("手动项目价格不能小于0"); + } + int durationMinutes = dto.getDurationMinutes() == null || dto.getDurationMinutes() <= 0 + ? DEFAULT_DURATION_MINUTES + : dto.getDurationMinutes(); + ProductDO product = new ProductDO(); + product.setShopId(shopId); + product.setTitle(title); + product.setPrice(price); + product.setLikeCount(0); + product.setCollectCount(0); + product.setApproximateDuration(durationMinutes + "分钟"); + product.setBookableArtists(dto.getArtistId() == null ? null : String.valueOf(dto.getArtistId())); + product.setFrontVisible(0); + product.setSourceType(PRODUCT_SOURCE_TYPE_MANAGER_APPOINTMENT); + product.setIsDelete(0); + productMapper.insert(product); + return product; + } + private UserDO requireActiveArtist(Long artistId, Long shopId) { if (artistId == null) { throw new RuntimeException("请选择美甲师"); diff --git a/FD-Core/src/main/java/com/xiaowang/fingertipdesigner/core/modules/product/controller/front/ProductController.java b/FD-Core/src/main/java/com/xiaowang/fingertipdesigner/core/modules/product/controller/front/ProductController.java index 8f954baf..d0647a3a 100644 --- a/FD-Core/src/main/java/com/xiaowang/fingertipdesigner/core/modules/product/controller/front/ProductController.java +++ b/FD-Core/src/main/java/com/xiaowang/fingertipdesigner/core/modules/product/controller/front/ProductController.java @@ -128,7 +128,7 @@ public class ProductController { * @return Result result consumed by the caller or returned to the frontend */ public Result getProductById(@PathVariable Long id) { - ProductVO productVO = productService.getProductById(id); + ProductVO productVO = productService.getPublicProductById(id); return Result.success(productVO); } @@ -141,8 +141,8 @@ public class ProductController { public Result> listAllProducts(HttpServletRequest request) { Long currentShopId = resolveOptionalCurrentShopId(request); List productVOs = currentShopId == null - ? productService.listAllProducts() - : productService.listProductsByShopId(currentShopId); + ? productService.listPublicProducts() + : productService.listPublicProductsByShopId(currentShopId); return Result.success(productVOs); } @@ -154,7 +154,7 @@ public class ProductController { * @return Result> result consumed by the caller or returned to the frontend */ public Result> listProductsByShopId(@PathVariable Long shopId) { - List productVOs = productService.listProductsByShopId(shopId); + List productVOs = productService.listPublicProductsByShopId(shopId); return Result.success(productVOs); } diff --git a/FD-Core/src/main/java/com/xiaowang/fingertipdesigner/core/modules/product/dto/ProductDTO.java b/FD-Core/src/main/java/com/xiaowang/fingertipdesigner/core/modules/product/dto/ProductDTO.java index d4e50135..fff098ab 100644 --- a/FD-Core/src/main/java/com/xiaowang/fingertipdesigner/core/modules/product/dto/ProductDTO.java +++ b/FD-Core/src/main/java/com/xiaowang/fingertipdesigner/core/modules/product/dto/ProductDTO.java @@ -78,4 +78,14 @@ public class ProductDTO { * 可用的优惠券ID集合,多个ID以逗号分隔 */ private String availableCoupons; + + /** + * 前台是否展示:0-隐藏,1-展示 + */ + private Integer frontVisible; + + /** + * 来源类型 + */ + private String sourceType; } diff --git a/FD-Core/src/main/java/com/xiaowang/fingertipdesigner/core/modules/product/entity/ProductDO.java b/FD-Core/src/main/java/com/xiaowang/fingertipdesigner/core/modules/product/entity/ProductDO.java index 3974e96a..83da02e4 100644 --- a/FD-Core/src/main/java/com/xiaowang/fingertipdesigner/core/modules/product/entity/ProductDO.java +++ b/FD-Core/src/main/java/com/xiaowang/fingertipdesigner/core/modules/product/entity/ProductDO.java @@ -99,6 +99,18 @@ public class ProductDO extends BaseEntity { @TableField("available_coupons") private String availableCoupons; + /** + * 前台是否展示:0-隐藏,1-展示 + */ + @TableField("front_visible") + private Integer frontVisible; + + /** + * 来源类型:BACKEND-后台维护,MANAGER_APPOINTMENT-管理师端手动预约 + */ + @TableField("source_type") + private String sourceType; + /** * 逻辑删除标识:0-未删除,1-已删除 */ diff --git a/FD-Core/src/main/java/com/xiaowang/fingertipdesigner/core/modules/product/service/ProductService.java b/FD-Core/src/main/java/com/xiaowang/fingertipdesigner/core/modules/product/service/ProductService.java index 92b5bbf9..681e592d 100644 --- a/FD-Core/src/main/java/com/xiaowang/fingertipdesigner/core/modules/product/service/ProductService.java +++ b/FD-Core/src/main/java/com/xiaowang/fingertipdesigner/core/modules/product/service/ProductService.java @@ -67,6 +67,8 @@ public interface ProductService extends IService { */ ProductVO getProductById(Long id); + ProductVO getPublicProductById(Long id); + /** * 查询所有商品 * @@ -74,6 +76,8 @@ public interface ProductService extends IService { */ List listAllProducts(); + List listPublicProducts(); + /** * 根据店铺ID查询商品 * @@ -82,6 +86,8 @@ public interface ProductService extends IService { */ List listProductsByShopId(Long shopId); + List listPublicProductsByShopId(Long shopId); + /** * 根据标签查询商品 * diff --git a/FD-Core/src/main/java/com/xiaowang/fingertipdesigner/core/modules/product/service/impl/ProductServiceImpl.java b/FD-Core/src/main/java/com/xiaowang/fingertipdesigner/core/modules/product/service/impl/ProductServiceImpl.java index 707addf6..aeca71d2 100644 --- a/FD-Core/src/main/java/com/xiaowang/fingertipdesigner/core/modules/product/service/impl/ProductServiceImpl.java +++ b/FD-Core/src/main/java/com/xiaowang/fingertipdesigner/core/modules/product/service/impl/ProductServiceImpl.java @@ -79,6 +79,8 @@ public class ProductServiceImpl extends ServiceImpl im private static final int MAX_PUBLIC_PAGE_SIZE = 30; private static final Pattern DURATION_PATTERN = Pattern.compile("(\\d+)"); private static final long DEFAULT_SERVICE_DURATION_MINUTES = 60L; + private static final int FRONT_VISIBLE = 1; + private static final String SOURCE_TYPE_BACKEND = "BACKEND"; /** * Variable `productMapper`: Spring-injected collaborator used by this class to finish database access, validation, or downstream calls. */ @@ -137,6 +139,8 @@ public class ProductServiceImpl extends ServiceImpl im productDO.setApproximateDuration(productDTO.getApproximateDuration()); productDO.setBookableArtists(bookableArtistSupport.filterValidBookableArtists(productDTO.getShopId(), productDTO.getBookableArtists())); productDO.setAvailableCoupons(productDTO.getAvailableCoupons()); + productDO.setFrontVisible(resolveFrontVisible(productDTO.getFrontVisible())); + productDO.setSourceType(resolveSourceType(productDTO.getSourceType())); productDO.setIsDelete(0); productMapper.insert(productDO); evictPublicProductCaches(productDO.getId()); @@ -175,6 +179,8 @@ public class ProductServiceImpl extends ServiceImpl im productDO.setApproximateDuration(productDTO.getApproximateDuration()); productDO.setBookableArtists(bookableArtistSupport.filterValidBookableArtists(productDTO.getShopId(), productDTO.getBookableArtists())); productDO.setAvailableCoupons(productDTO.getAvailableCoupons()); + productDO.setFrontVisible(resolveUpdateFrontVisible(productDO.getFrontVisible(), productDTO.getFrontVisible())); + productDO.setSourceType(resolveUpdateSourceType(productDO.getSourceType(), productDTO.getSourceType())); boolean updated = productMapper.updateById(productDO) > 0; if (updated) { /** @@ -287,6 +293,27 @@ public class ProductServiceImpl extends ServiceImpl im ); } + @Override + public ProductVO getPublicProductById(Long id) { + AppCacheProperties.CacheSpec cacheSpec = appCacheProperties.getProductDetail(); + return multiLevelCacheService.getOrLoad( + PRODUCT_DETAIL_CACHE_PREFIX + "public:" + id, + Duration.ofSeconds(cacheSpec.getLocalTtlSeconds()), + Duration.ofSeconds(cacheSpec.getRedisTtlSeconds()), + new TypeReference() { + }, + () -> { + ProductDO productDO = productMapper.selectById(id); + if (productDO == null + || Integer.valueOf(1).equals(productDO.getIsDelete()) + || !Integer.valueOf(FRONT_VISIBLE).equals(productDO.getFrontVisible())) { + return null; + } + return convertToVO(productDO); + } + ); + } + @Override /** * List records for the current query or current user scope. @@ -342,6 +369,33 @@ public class ProductServiceImpl extends ServiceImpl im ); } + @Override + public List listPublicProducts() { + AppCacheProperties.CacheSpec cacheSpec = appCacheProperties.getProductList(); + return multiLevelCacheService.getOrLoad( + PRODUCT_LIST_CACHE_PREFIX + "public:all", + Duration.ofSeconds(cacheSpec.getLocalTtlSeconds()), + Duration.ofSeconds(cacheSpec.getRedisTtlSeconds()), + new TypeReference>() { + }, + () -> toProductVOList(productMapper.selectList(buildFrontQuery(null, null, null))) + ); + } + + @Override + public List listPublicProductsByShopId(Long shopId) { + AppCacheProperties.CacheSpec cacheSpec = appCacheProperties.getProductList(); + Long scopedShopId = normalizeShopId(shopId); + return multiLevelCacheService.getOrLoad( + PRODUCT_LIST_CACHE_PREFIX + buildShopCacheSegment(scopedShopId) + "public", + Duration.ofSeconds(cacheSpec.getLocalTtlSeconds()), + Duration.ofSeconds(cacheSpec.getRedisTtlSeconds()), + new TypeReference>() { + }, + () -> toProductVOList(productMapper.selectList(buildFrontQuery(null, null, null, scopedShopId))) + ); + } + @Override /** * List records for the current query or current user scope. @@ -464,6 +518,8 @@ public class ProductServiceImpl extends ServiceImpl im productVO.setAvailableBookableArtistCount(countBookableArtists(validBookableArtists)); productVO.setBookableArtistRestricted(StringUtils.hasText(productDO.getBookableArtists())); productVO.setAvailableCoupons(productDO.getAvailableCoupons()); + productVO.setFrontVisible(productDO.getFrontVisible()); + productVO.setSourceType(productDO.getSourceType()); productVO.setCreateTime(productDO.getCreateTime()); productVO.setUpdateTime(productDO.getUpdateTime()); @@ -831,6 +887,7 @@ public class ProductServiceImpl extends ServiceImpl im } LambdaQueryWrapper wrapper = Wrappers.lambdaQuery(ProductDO.class) .eq(ProductDO::getIsDelete, 0) + .eq(ProductDO::getFrontVisible, FRONT_VISIBLE) .orderByDesc(ProductDO::getCreateTime); if (shopId != null) { wrapper.eq(ProductDO::getShopId, shopId); @@ -927,7 +984,8 @@ public class ProductServiceImpl extends ServiceImpl im */ private LambdaQueryWrapper buildFrontQuery(String keyword, String tag, Set exactTagIds, Set selectedTagIds, Long shopId) { LambdaQueryWrapper wrapper = Wrappers.lambdaQuery(ProductDO.class) - .eq(ProductDO::getIsDelete, 0); + .eq(ProductDO::getIsDelete, 0) + .eq(ProductDO::getFrontVisible, FRONT_VISIBLE); if (shopId != null) { wrapper.eq(ProductDO::getShopId, shopId); } @@ -949,6 +1007,28 @@ public class ProductServiceImpl extends ServiceImpl im return wrapper; } + private Integer resolveFrontVisible(Integer frontVisible) { + return Integer.valueOf(0).equals(frontVisible) ? 0 : FRONT_VISIBLE; + } + + private String resolveSourceType(String sourceType) { + return StringUtils.hasText(sourceType) ? sourceType.trim() : SOURCE_TYPE_BACKEND; + } + + private Integer resolveUpdateFrontVisible(Integer currentFrontVisible, Integer nextFrontVisible) { + if (nextFrontVisible != null) { + return resolveFrontVisible(nextFrontVisible); + } + return currentFrontVisible == null ? FRONT_VISIBLE : currentFrontVisible; + } + + private String resolveUpdateSourceType(String currentSourceType, String nextSourceType) { + if (StringUtils.hasText(nextSourceType)) { + return resolveSourceType(nextSourceType); + } + return StringUtils.hasText(currentSourceType) ? currentSourceType : SOURCE_TYPE_BACKEND; + } + /** * Run business method `applyKeywordFilter`. * Call guide: pass the named parameters below from the controller or caller; the method validates them and returns the business result. @@ -1214,6 +1294,7 @@ public class ProductServiceImpl extends ServiceImpl im private void evictPublicProductCaches(Long productId) { if (productId != null) { multiLevelCacheService.evict(PRODUCT_DETAIL_CACHE_PREFIX + productId); + multiLevelCacheService.evict(PRODUCT_DETAIL_CACHE_PREFIX + "public:" + productId); } multiLevelCacheService.evictByPrefix(PRODUCT_LIST_CACHE_PREFIX); multiLevelCacheService.evictByPrefix(PRODUCT_SEARCH_CACHE_PREFIX); diff --git a/FD-Core/src/main/java/com/xiaowang/fingertipdesigner/core/modules/product/vo/ProductVO.java b/FD-Core/src/main/java/com/xiaowang/fingertipdesigner/core/modules/product/vo/ProductVO.java index 550c4b3a..48302735 100644 --- a/FD-Core/src/main/java/com/xiaowang/fingertipdesigner/core/modules/product/vo/ProductVO.java +++ b/FD-Core/src/main/java/com/xiaowang/fingertipdesigner/core/modules/product/vo/ProductVO.java @@ -126,6 +126,16 @@ public class ProductVO { */ private String availableCoupons; + /** + * 前台是否展示:0-隐藏,1-展示 + */ + private Integer frontVisible; + + /** + * 来源类型 + */ + private String sourceType; + /** * 商品创建时间 */ diff --git a/FD-Core/src/test/java/com/xiaowang/fingertipdesigner/core/modules/product/controller/front/ProductControllerTest.java b/FD-Core/src/test/java/com/xiaowang/fingertipdesigner/core/modules/product/controller/front/ProductControllerTest.java index b859dc46..df9dea4f 100644 --- a/FD-Core/src/test/java/com/xiaowang/fingertipdesigner/core/modules/product/controller/front/ProductControllerTest.java +++ b/FD-Core/src/test/java/com/xiaowang/fingertipdesigner/core/modules/product/controller/front/ProductControllerTest.java @@ -46,12 +46,12 @@ class ProductControllerTest { @Test void listAllProductsShouldUseCurrentShopFromValidToken() { MockHttpServletRequest request = authenticatedShopRequest(7L, 3L); - when(productService.listProductsByShopId(3L)).thenReturn(List.of(new ProductVO())); + when(productService.listPublicProductsByShopId(3L)).thenReturn(List.of(new ProductVO())); controller.listAllProducts(request); - verify(productService).listProductsByShopId(3L); - verify(productService, never()).listAllProducts(); + verify(productService).listPublicProductsByShopId(3L); + verify(productService, never()).listPublicProducts(); } @Test @@ -68,12 +68,12 @@ class ProductControllerTest { @Test void listAllProductsShouldRemainPublicWithoutToken() { MockHttpServletRequest request = new MockHttpServletRequest(); - when(productService.listAllProducts()).thenReturn(List.of(new ProductVO())); + when(productService.listPublicProducts()).thenReturn(List.of(new ProductVO())); controller.listAllProducts(request); - verify(productService).listAllProducts(); - verify(productService, never()).listProductsByShopId(3L); + verify(productService).listPublicProducts(); + verify(productService, never()).listPublicProductsByShopId(3L); } @Test diff --git a/FD-Core/src/test/java/com/xiaowang/fingertipdesigner/core/modules/product/service/impl/ProductServiceImplTest.java b/FD-Core/src/test/java/com/xiaowang/fingertipdesigner/core/modules/product/service/impl/ProductServiceImplTest.java index c45d9ea2..17ae07cd 100644 --- a/FD-Core/src/test/java/com/xiaowang/fingertipdesigner/core/modules/product/service/impl/ProductServiceImplTest.java +++ b/FD-Core/src/test/java/com/xiaowang/fingertipdesigner/core/modules/product/service/impl/ProductServiceImplTest.java @@ -22,6 +22,7 @@ import org.mockito.junit.jupiter.MockitoExtension; import java.math.BigDecimal; import java.time.Duration; +import static org.junit.jupiter.api.Assertions.assertNull; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.anyString; @@ -95,6 +96,8 @@ class ProductServiceImplTest { org.mockito.Mockito.verify(productMapper).insert(captor.capture()); assertEquals("Short nails, daily office style", captor.getValue().getTargetAudience()); assertEquals("Avoid long hot baths within 24 hours", captor.getValue().getPrecautions()); + assertEquals(1, captor.getValue().getFrontVisible()); + assertEquals("BACKEND", captor.getValue().getSourceType()); } @Test @@ -123,4 +126,28 @@ class ProductServiceImplTest { assertEquals("Short nails, daily office style", productVO.getTargetAudience()); assertEquals("Avoid long hot baths within 24 hours", productVO.getPrecautions()); } + + @Test + void getPublicProductByIdShouldHideInvisibleProduct() { + ProductDO product = new ProductDO(); + product.setId(99L); + product.setShopId(3L); + product.setTitle("Manual appointment item"); + product.setDescription("hidden"); + product.setPrice(new BigDecimal("88.00")); + product.setFrontVisible(0); + product.setIsDelete(0); + when(productMapper.selectById(99L)).thenReturn(product); + when(multiLevelCacheService.getOrLoad( + anyString(), + any(Duration.class), + any(Duration.class), + any(), + any() + )).thenAnswer(invocation -> ((java.util.function.Supplier) invocation.getArgument(4)).get()); + + ProductVO productVO = productService.getPublicProductById(99L); + + assertNull(productVO); + } } diff --git a/FD-Frontend/src/api/admin.ts b/FD-Frontend/src/api/admin.ts index a331d2d5..700d9423 100644 --- a/FD-Frontend/src/api/admin.ts +++ b/FD-Frontend/src/api/admin.ts @@ -738,6 +738,8 @@ export interface Product { imageUrls?: string[] bookableArtists?: string availableCoupons?: string + frontVisible?: number + sourceType?: string likeCount?: number collectCount?: number createTime: string diff --git a/FD-Frontend/src/views/admin/ProductsView.vue b/FD-Frontend/src/views/admin/ProductsView.vue index ff177733..8ee3076f 100644 --- a/FD-Frontend/src/views/admin/ProductsView.vue +++ b/FD-Frontend/src/views/admin/ProductsView.vue @@ -289,6 +289,9 @@ style="width: 100%" /> + + + + + + { collectCount: 0, tags: [], approximateDuration: '', + frontVisible: 1, bookableArtists: [], availableCoupons: [] }) @@ -1147,6 +1156,7 @@ const showEditModal = async (record: Product | Record) => { const recordCollectCount = 'collectCount' in record ? record.collectCount : (record as any).collectCount const recordTags = 'tags' in record ? record.tags : (record as any).tags const recordApproximateDuration = 'approximateDuration' in record ? record.approximateDuration : (record as any).approximateDuration + const recordFrontVisible = 'frontVisible' in record ? record.frontVisible : (record as any).frontVisible const recordBookableArtists = 'bookableArtists' in record ? record.bookableArtists : (record as any).bookableArtists const recordAvailableCoupons = 'availableCoupons' in record ? record.availableCoupons : (record as any).availableCoupons @@ -1171,6 +1181,7 @@ const showEditModal = async (record: Product | Record) => { collectCount: normalizeInteractionCount(recordCollectCount), tags: tagsArray, approximateDuration: durationNumber, + frontVisible: recordFrontVisible ?? 1, bookableArtists: artistsArray, availableCoupons: couponsArray }) @@ -1207,6 +1218,7 @@ const showViewModal = async (record: Product | Record) => { const recordCollectCount = 'collectCount' in record ? record.collectCount : (record as any).collectCount const recordTags = 'tags' in record ? record.tags : (record as any).tags const recordApproximateDuration = 'approximateDuration' in record ? record.approximateDuration : (record as any).approximateDuration + const recordFrontVisible = 'frontVisible' in record ? record.frontVisible : (record as any).frontVisible const recordBookableArtists = 'bookableArtists' in record ? record.bookableArtists : (record as any).bookableArtists const recordAvailableCoupons = 'availableCoupons' in record ? record.availableCoupons : (record as any).availableCoupons @@ -1231,6 +1243,7 @@ const showViewModal = async (record: Product | Record) => { collectCount: normalizeInteractionCount(recordCollectCount), tags: tagsArray, approximateDuration: durationNumber, + frontVisible: recordFrontVisible ?? 1, bookableArtists: artistsArray, availableCoupons: couponsArray }) @@ -1275,6 +1288,7 @@ const buildDraftPayload = () => ({ collectCount: formState.collectCount, tags: [...formState.tags], approximateDuration: formState.approximateDuration, + frontVisible: formState.frontVisible, bookableArtists: [...formState.bookableArtists], availableCoupons: [...formState.availableCoupons] }, @@ -1464,6 +1478,7 @@ const handleModalOk = async () => { tags: tagsString, bookableArtists: artistsString, availableCoupons: couponsString, + frontVisible: formState.frontVisible, approximateDuration: durationString, shopId: formState.shopId || 0 } diff --git a/FD-WeChat-Fronted/admin/pages/product-form/index.js b/FD-WeChat-Fronted/admin/pages/product-form/index.js index fecb4f4e..071fdc9f 100644 --- a/FD-WeChat-Fronted/admin/pages/product-form/index.js +++ b/FD-WeChat-Fronted/admin/pages/product-form/index.js @@ -194,7 +194,11 @@ Page({ * Purpose: shopId supports index.js by holding or executing the shop id page or API role. * Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow. */ - shopId: '' + shopId: '', + /** + * 前台展示开关,手动预约项目补全前保持隐藏。 + */ + frontVisible: 1 } }, @@ -279,7 +283,11 @@ Page({ * Purpose: shopId supports index.js by holding or executing the shop id page or API role. * Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow. */ - shopId: currentProduct.shopId || '' + shopId: currentProduct.shopId || '', + /** + * 编辑时回填前台展示开关。 + */ + frontVisible: currentProduct.frontVisible === 0 ? 0 : 1 } }) } @@ -503,6 +511,13 @@ Page({ this.scheduleProductDraft() }, + handleFrontVisibleChange(event) { + this.setData({ + 'form.frontVisible': event.detail.value ? 1 : 0 + }) + this.scheduleProductDraft() + }, + /** * Purpose: handleShopChange supports index.js by holding or executing the handle shop change page or API role. * Usage: import, call, read, or update this method from the owning page/module while preserving the surrounding loading and permission flow. @@ -769,7 +784,11 @@ Page({ * Purpose: availableCoupons supports index.js by holding or executing the available coupons page or API role. * Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow. */ - availableCoupons: this._selectedCouponIds.join(',') || undefined + availableCoupons: this._selectedCouponIds.join(',') || undefined, + /** + * 后台补全后可手动发布到用户端。 + */ + frontVisible: this.data.form.frontVisible === 0 ? 0 : 1 } try { diff --git a/FD-WeChat-Fronted/admin/pages/product-form/index.wxml b/FD-WeChat-Fronted/admin/pages/product-form/index.wxml index 6c3c526c..0b9789cb 100644 --- a/FD-WeChat-Fronted/admin/pages/product-form/index.wxml +++ b/FD-WeChat-Fronted/admin/pages/product-form/index.wxml @@ -42,6 +42,12 @@ 收藏数量 + + + 前台展示 + + + 作品图片 diff --git a/FD-WeChat-Fronted/admin/pages/product-form/index.wxss b/FD-WeChat-Fronted/admin/pages/product-form/index.wxss index c7f2860b..da1707db 100644 --- a/FD-WeChat-Fronted/admin/pages/product-form/index.wxss +++ b/FD-WeChat-Fronted/admin/pages/product-form/index.wxss @@ -3,3 +3,10 @@ checkbox { transform: scale(0.75); margin-right: 8rpx; } + +.switch-field { + display: flex; + align-items: center; + justify-content: space-between; + gap: 24rpx; +} diff --git a/FM-Wechat-Fronted/api/employees.js b/FM-Wechat-Fronted/api/employees.js index d5c2b8e0..ef2a1644 100644 --- a/FM-Wechat-Fronted/api/employees.js +++ b/FM-Wechat-Fronted/api/employees.js @@ -22,6 +22,14 @@ module.exports = { }) }, + createUser(data) { + return request({ + url: '/user/create', + method: 'POST', + data + }) + }, + schedules(params) { return request({ url: '/artist-schedule/list', diff --git a/FM-Wechat-Fronted/pages/appointment-form/index.js b/FM-Wechat-Fronted/pages/appointment-form/index.js index 2fa79c22..83daf58f 100644 --- a/FM-Wechat-Fronted/pages/appointment-form/index.js +++ b/FM-Wechat-Fronted/pages/appointment-form/index.js @@ -14,6 +14,45 @@ function findArtist(artists, artistId) { return artists.find(item => String(item.id) === String(artistId)) || {} } +function canCreateAppointment() { + const app = getApp() + const userInfo = app.globalData.userInfo || {} + return Number(userInfo.type) !== 3 +} + +function parseProductTags(product) { + if (Array.isArray(product.tagList) && product.tagList.length > 0) { + return product.tagList + } + if (Array.isArray(product.tagInfos) && product.tagInfos.length > 0) { + return product.tagInfos.map(item => item.tagName).filter(Boolean) + } + return String(product.tags || '') + .split(/[;,,、]/) + .map(item => item.trim()) + .filter(Boolean) +} + +function normalizeProduct(product, artists) { + const imageUrls = Array.isArray(product.imageUrls) ? product.imageUrls : [] + const bookableArtists = String(product.bookableArtists || '') + .split(',') + .map(item => item.trim()) + .filter(Boolean) + const artistNames = bookableArtists + .map(id => findArtist(artists, id).name) + .filter(Boolean) + const durationText = product.approximateDuration || (product.serviceDurationMinutes ? `${product.serviceDurationMinutes}分钟` : '') + return { + ...product, + coverImage: imageUrls[0] || '', + tagList: parseProductTags(product).slice(0, 4), + artistText: artistNames.length > 0 ? artistNames.join('、') : '全部美甲师', + priceText: product.price || product.price === 0 ? `¥${product.price}` : '价格待定', + durationText + } +} + function isScheduleCoveringTime(schedule, form, startMinute, endMinute) { if (!schedule || String(schedule.artistId) !== String(form.artistId) || schedule.date !== form.appointmentDate) { return false @@ -34,24 +73,36 @@ Page({ appointmentDate: dateUtil.formatDate(new Date()), appointmentTime: '13:00', productId: '', + manualProductTitle: '', + manualProductPrice: '', durationMinutes: '', artistId: '', remark: '' }, products: [], + filteredProducts: [], artists: [], selectedProduct: {}, selectedArtist: {}, + productModalVisible: false, + productKeyword: '', conflictTip: '', conflictLevel: 'free', + canCreateAppointment: true, loading: false }, onLoad(options) { + const creatable = canCreateAppointment() this.setData({ + canCreateAppointment: creatable, 'form.appointmentDate': options.date || dateUtil.formatDate(new Date()), 'form.artistId': options.artistId || '' }) + if (!creatable) { + wx.showToast({ title: '美甲师账号只能查看预约', icon: 'none' }) + return + } this.loadOptions() }, @@ -69,6 +120,7 @@ Page({ this.setData({ products: fallbackProducts }) } await this.loadArtists() + this.refreshProductCards() this.checkAvailability() }, @@ -80,6 +132,7 @@ Page({ const artists = getCalendarArtists(calendar) const selectedArtist = this.data.form.artistId ? findArtist(artists, this.data.form.artistId) : {} this.setData({ artists, selectedArtist }) + this.refreshProductCards() }, onInput(event) { @@ -99,13 +152,62 @@ Page({ this.checkAvailability() }, - onProductChange(event) { - const selectedProduct = this.data.products[Number(event.detail.value)] || {} + refreshProductCards() { + const keyword = this.data.productKeyword.trim().toLowerCase() + const products = this.data.products + .map(product => normalizeProduct(product, this.data.artists)) + .filter(product => { + if (!keyword) return true + return [product.title, product.artistText, product.priceText, product.durationText, ...(product.tagList || [])] + .some(value => String(value || '').toLowerCase().includes(keyword)) + }) + this.setData({ filteredProducts: products }) + }, + + openProductModal() { + this.refreshProductCards() + this.setData({ productModalVisible: true }) + }, + + closeProductModal() { + this.setData({ productModalVisible: false }) + }, + + stopTap() { + }, + + onProductSearch(event) { + this.setData({ productKeyword: event.detail.value }) + this.refreshProductCards() + }, + + selectProduct(event) { + const selectedProduct = this.data.filteredProducts.find(item => String(item.id) === String(event.currentTarget.dataset.id)) || {} this.setData({ selectedProduct, 'form.productId': selectedProduct.id, + 'form.manualProductTitle': '', + 'form.manualProductPrice': '', 'form.durationMinutes': String(parseInt(selectedProduct.approximateDuration, 10) || this.data.form.durationMinutes || 60) }) + this.closeProductModal() + this.checkAvailability() + }, + + useManualProduct() { + const title = String(this.data.form.manualProductTitle || '').trim() + const price = Number(this.data.form.manualProductPrice) + if (!title || Number.isNaN(price) || price < 0) { + wx.showToast({ title: '请填写手动项目名称和价格', icon: 'none' }) + return + } + this.setData({ + selectedProduct: {}, + 'form.productId': '', + 'form.manualProductTitle': title, + 'form.manualProductPrice': String(price) + }) + this.closeProductModal() this.checkAvailability() }, @@ -170,8 +272,13 @@ Page({ }, async submit() { + if (!this.data.canCreateAppointment) { + wx.showToast({ title: '美甲师账号只能查看预约', icon: 'none' }) + return + } const form = this.data.form - if (!form.customerName || !form.phone || !form.productId || !form.artistId) { + const hasManualProduct = String(form.manualProductTitle || '').trim() && String(form.manualProductPrice || '').trim() + if (!form.customerName || !form.phone || (!form.productId && !hasManualProduct) || !form.artistId) { wx.showToast({ title: '请补全预约信息', icon: 'none' }) return } @@ -182,13 +289,22 @@ Page({ } this.setData({ loading: true }) try { - const result = await planningApi.createAppointment({ + const payload = { ...form, - productId: String(form.productId), artistId: String(form.artistId), durationMinutes: Number(form.durationMinutes || 0) || undefined, clientRequestId: buildClientRequestId('manager-appointment') - }) + } + if (form.productId) { + payload.productId = String(form.productId) + payload.manualProductTitle = undefined + payload.manualProductPrice = undefined + } else { + payload.productId = undefined + payload.manualProductTitle = String(form.manualProductTitle || '').trim() + payload.manualProductPrice = Number(form.manualProductPrice) + } + const result = await planningApi.createAppointment(payload) wx.redirectTo({ url: `/pages/appointment-detail/index?id=${result.orderItemId}` }) } catch (error) { wx.showToast({ title: error.message || '保存失败', icon: 'none' }) diff --git a/FM-Wechat-Fronted/pages/appointment-form/index.wxml b/FM-Wechat-Fronted/pages/appointment-form/index.wxml index c1029621..6e948a17 100644 --- a/FM-Wechat-Fronted/pages/appointment-form/index.wxml +++ b/FM-Wechat-Fronted/pages/appointment-form/index.wxml @@ -22,9 +22,10 @@ 项目内容 - - {{selectedProduct.title || '请选择项目'}} - + + {{selectedProduct.title || form.manualProductTitle || '请选择项目'}} + 手动 + 预计时长 @@ -53,7 +54,44 @@ {{conflictTip}} + + + + + 选择项目内容 + + + + + + + + 图 + + + {{item.title}} + {{item.priceText}} + + {{item.artistText}} · {{item.durationText || '时长待定'}} + + {{tag}} + + + + 暂无匹配作品 + + + 手动新增项目 + + + + + + + + + - + diff --git a/FM-Wechat-Fronted/pages/appointment-form/index.wxss b/FM-Wechat-Fronted/pages/appointment-form/index.wxss index 3eb65cc6..0a535fe3 100644 --- a/FM-Wechat-Fronted/pages/appointment-form/index.wxss +++ b/FM-Wechat-Fronted/pages/appointment-form/index.wxss @@ -3,6 +3,23 @@ font-size: 24rpx; } +.product-value { + display: flex; + align-items: center; + justify-content: space-between; + gap: 12rpx; +} + +.manual-badge { + flex: 0 0 auto; + padding: 4rpx 12rpx; + border-radius: 999rpx; + background: #fff2df; + color: #a26428; + font-size: 22rpx; + font-weight: 800; +} + .textarea-field { align-items: flex-start; } @@ -58,3 +75,202 @@ .availability-tip.danger .tip-title { color: #c36a6a; } + +.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); +} + +.product-modal { + width: 100%; + max-height: 88vh; + 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); +} + +.modal-head { + display: flex; + align-items: flex-start; + justify-content: space-between; + gap: 20rpx; + margin-bottom: 20rpx; +} + +.modal-title { + display: block; +} + +.modal-title { + color: #27211d; + font-size: 34rpx; + font-weight: 900; +} + +.modal-close { + width: 58rpx; + height: 58rpx; + margin: 0; + padding: 0; + border-radius: 50%; + background: #f2e7da; + color: #61554c; + font-size: 40rpx; + line-height: 58rpx; +} + +.product-search { + height: 74rpx; + padding: 0 24rpx; + border-radius: 18rpx; + background: #f5eee6; + color: #2a2521; + font-size: 26rpx; +} + +.product-list { + max-height: 560rpx; + margin-top: 20rpx; +} + +.product-option { + display: flex; + align-items: stretch; + gap: 18rpx; + min-height: 156rpx; + margin-bottom: 16rpx; + padding: 14rpx; + border: 2rpx solid transparent; + border-radius: 18rpx; + background: #fff; + box-shadow: 0 10rpx 24rpx rgba(92, 66, 43, 0.08); +} + +.product-option.active { + border-color: #c9874d; + background: #fff8ef; +} + +.product-cover { + flex: 0 0 auto; + width: 132rpx; + height: 132rpx; + border-radius: 14rpx; + background: #efe5da; +} + +.product-cover.placeholder { + display: flex; + align-items: center; + justify-content: center; + color: #b79b82; + font-size: 28rpx; + font-weight: 900; +} + +.product-info { + flex: 1; + min-width: 0; + display: flex; + flex-direction: column; + justify-content: center; + gap: 10rpx; +} + +.product-title-row { + display: flex; + align-items: center; + gap: 16rpx; +} + +.product-title { + flex: 1; + min-width: 0; + overflow: hidden; + color: #2a2521; + font-size: 28rpx; + font-weight: 900; + text-overflow: ellipsis; + white-space: nowrap; +} + +.product-price { + flex: 0 0 auto; + color: #c56f36; + font-size: 28rpx; + font-weight: 900; +} + +.product-meta { + overflow: hidden; + color: #8c8177; + font-size: 24rpx; + text-overflow: ellipsis; + white-space: nowrap; +} + +.tag-row { + display: flex; + flex-wrap: wrap; + gap: 8rpx; + min-height: 34rpx; +} + +.tag-pill { + max-width: 160rpx; + padding: 4rpx 12rpx; + overflow: hidden; + border-radius: 999rpx; + background: #f3e9df; + color: #826c5b; + font-size: 22rpx; + text-overflow: ellipsis; + white-space: nowrap; +} + +.product-empty { + padding: 44rpx 0; + color: #9a9288; + font-size: 26rpx; + text-align: center; +} + +.manual-panel { + margin-top: 12rpx; + padding: 20rpx; + border-radius: 18rpx; + background: #f7efe7; +} + +.manual-title { + display: block; + margin-bottom: 14rpx; + color: #4e4740; + font-size: 26rpx; + font-weight: 900; +} + +.manual-grid { + display: grid; + grid-template-columns: minmax(0, 1fr) 180rpx; + gap: 14rpx; +} + +.manual-grid input { + height: 70rpx; + padding: 0 18rpx; + border-radius: 14rpx; + background: #fffaf4; + color: #302923; + font-size: 26rpx; +} + +.manual-btn { + margin-top: 16rpx; +} diff --git a/FM-Wechat-Fronted/pages/customer-detail/index.js b/FM-Wechat-Fronted/pages/customer-detail/index.js index eb9b9079..24702ef1 100644 --- a/FM-Wechat-Fronted/pages/customer-detail/index.js +++ b/FM-Wechat-Fronted/pages/customer-detail/index.js @@ -1,6 +1,13 @@ +function canCreateAppointment() { + const app = getApp() + const userInfo = app.globalData.userInfo || {} + return Number(userInfo.type) !== 3 +} + Page({ data: { id: '', + canCreateAppointment: true, avatarText: '客', customer: { name: '王女士', phone: '138****1201' }, stats: { orderCount: 12, amount: 2860, lastTime: '06-01' }, @@ -12,10 +19,17 @@ Page({ }, onLoad(options) { - this.setData({ id: options.id || '' }) + this.setData({ + id: options.id || '', + canCreateAppointment: canCreateAppointment() + }) }, createAppointment() { + if (!this.data.canCreateAppointment) { + wx.showToast({ title: '美甲师账号只能查看预约', icon: 'none' }) + return + } wx.navigateTo({ url: '/pages/appointment-form/index' }) }, diff --git a/FM-Wechat-Fronted/pages/customer-detail/index.wxml b/FM-Wechat-Fronted/pages/customer-detail/index.wxml index 44cd988d..4cc65201 100644 --- a/FM-Wechat-Fronted/pages/customer-detail/index.wxml +++ b/FM-Wechat-Fronted/pages/customer-detail/index.wxml @@ -7,7 +7,7 @@ {{customer.phone}} - + diff --git a/FM-Wechat-Fronted/pages/employees/index.js b/FM-Wechat-Fronted/pages/employees/index.js index 3e77cf8c..0aac0929 100644 --- a/FM-Wechat-Fronted/pages/employees/index.js +++ b/FM-Wechat-Fronted/pages/employees/index.js @@ -3,7 +3,16 @@ const mock = require('../../utils/mock') Page({ data: { - employees: [] + employees: [], + createModalVisible: false, + creating: false, + createForm: { + nickname: '', + phone: '', + account: '', + password: '888888', + wechatId: '' + } }, onLoad() { @@ -39,6 +48,73 @@ Page({ }, addEmployee() { - wx.showToast({ title: '员工创建沿用后台账号', icon: 'none' }) + this.setData({ createModalVisible: true }) + }, + + closeCreateModal() { + if (this.data.creating) { + return + } + this.setData({ createModalVisible: false }) + }, + + stopTap() { + }, + + onCreateInput(event) { + const field = event.currentTarget.dataset.field + const value = event.detail.value + const updates = { + [`createForm.${field}`]: value + } + if (field === 'phone' && !this.data.createForm.account) { + updates['createForm.account'] = value + } + this.setData(updates) + }, + + resetCreateForm() { + this.setData({ + createForm: { + nickname: '', + phone: '', + account: '', + password: '888888', + wechatId: '' + } + }) + }, + + async submitEmployee() { + const form = this.data.createForm + const nickname = String(form.nickname || '').trim() + 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) { + wx.showToast({ title: '请补全美甲师信息', icon: 'none' }) + return + } + this.setData({ creating: true }) + try { + await employeesApi.createUser({ + nickname, + phone, + contactPhone: phone, + account, + password, + wechatId, + type: 3 + }) + wx.showToast({ title: '美甲师已新增', icon: 'success' }) + this.resetCreateForm() + this.setData({ createModalVisible: false }) + await this.loadEmployees() + } catch (error) { + wx.showToast({ title: error.message || '新增失败', icon: 'none' }) + } finally { + this.setData({ creating: false }) + } } }) diff --git a/FM-Wechat-Fronted/pages/employees/index.wxml b/FM-Wechat-Fronted/pages/employees/index.wxml index 35fa8129..30fa33de 100644 --- a/FM-Wechat-Fronted/pages/employees/index.wxml +++ b/FM-Wechat-Fronted/pages/employees/index.wxml @@ -16,4 +16,38 @@ + + + + + + 新增美甲师 + + + + + + 姓名 + + + + 手机号 + + + + 登录账号 + + + + 初始密码 + + + + 微信号 + + + + + + diff --git a/FM-Wechat-Fronted/pages/employees/index.wxss b/FM-Wechat-Fronted/pages/employees/index.wxss index 528f595b..91995293 100644 --- a/FM-Wechat-Fronted/pages/employees/index.wxss +++ b/FM-Wechat-Fronted/pages/employees/index.wxss @@ -64,3 +64,81 @@ height: 18rpx; border-radius: 999rpx; } + +.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); +} + +.employee-modal { + width: 100%; + 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); +} + +.modal-head { + display: flex; + align-items: flex-start; + justify-content: space-between; + gap: 20rpx; + margin-bottom: 20rpx; +} + +.modal-title { + display: block; +} + +.modal-title { + color: #27211d; + font-size: 34rpx; + font-weight: 900; +} + +.modal-close { + width: 58rpx; + height: 58rpx; + margin: 0; + padding: 0; + border-radius: 50%; + background: #f2e7da; + color: #61554c; + font-size: 40rpx; + line-height: 58rpx; +} + +.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 { + height: 58rpx; + color: #2c2722; + font-size: 28rpx; +} + +.modal-submit { + margin-top: 22rpx; +} diff --git a/FM-Wechat-Fronted/pages/planning/index.js b/FM-Wechat-Fronted/pages/planning/index.js index 56fe3902..ea0ecdfa 100644 --- a/FM-Wechat-Fronted/pages/planning/index.js +++ b/FM-Wechat-Fronted/pages/planning/index.js @@ -2,6 +2,12 @@ const planningApi = require('../../api/planning') const dateUtil = require('../../utils/date') const mock = require('../../utils/mock') +function canCreateAppointment() { + const app = getApp() + const userInfo = app.globalData.userInfo || {} + return Number(userInfo.type) !== 3 +} + Page({ data: { viewMode: 'month', @@ -40,10 +46,12 @@ Page({ dayTotal: 0, freeArtistCount: 0, pendingCount: 0, + canCreateAppointment: true, loading: false }, onLoad() { + this.setData({ canCreateAppointment: canCreateAppointment() }) this.loadCalendar() }, @@ -327,6 +335,10 @@ Page({ }, createAppointment() { + if (!this.data.canCreateAppointment) { + wx.showToast({ title: '美甲师账号只能查看预约', icon: 'none' }) + return + } wx.navigateTo({ url: `/pages/appointment-form/index?date=${this.data.currentDateText}&artistId=${this.data.selectedArtistId || ''}` }) diff --git a/FM-Wechat-Fronted/pages/planning/index.wxml b/FM-Wechat-Fronted/pages/planning/index.wxml index ca1a11da..ec7474f9 100644 --- a/FM-Wechat-Fronted/pages/planning/index.wxml +++ b/FM-Wechat-Fronted/pages/planning/index.wxml @@ -139,5 +139,5 @@ - + diff --git a/scripts/sql/migrations/预约手动项目展示控制_20260624.sql b/scripts/sql/migrations/预约手动项目展示控制_20260624.sql new file mode 100644 index 00000000..323e40d3 --- /dev/null +++ b/scripts/sql/migrations/预约手动项目展示控制_20260624.sql @@ -0,0 +1,46 @@ +USE `FingertipDesigner`; + +SET @front_visible_exists := ( + SELECT COUNT(*) + FROM INFORMATION_SCHEMA.COLUMNS + WHERE TABLE_SCHEMA = DATABASE() + AND TABLE_NAME = 't_product' + AND COLUMN_NAME = 'front_visible' +); + +SET @add_front_visible_sql := IF( + @front_visible_exists = 0, + 'ALTER TABLE `t_product` ADD COLUMN `front_visible` tinyint NOT NULL DEFAULT 1 COMMENT ''前台是否展示:0-隐藏,1-展示'' AFTER `available_coupons`', + 'SELECT 1' +); + +PREPARE add_front_visible_stmt FROM @add_front_visible_sql; +EXECUTE add_front_visible_stmt; +DEALLOCATE PREPARE add_front_visible_stmt; + +SET @source_type_exists := ( + SELECT COUNT(*) + FROM INFORMATION_SCHEMA.COLUMNS + WHERE TABLE_SCHEMA = DATABASE() + AND TABLE_NAME = 't_product' + AND COLUMN_NAME = 'source_type' +); + +SET @add_source_type_sql := IF( + @source_type_exists = 0, + 'ALTER TABLE `t_product` ADD COLUMN `source_type` varchar(64) NOT NULL DEFAULT ''BACKEND'' COMMENT ''来源类型:BACKEND-后台维护,MANAGER_APPOINTMENT-管理师端手动预约'' AFTER `front_visible`', + 'SELECT 1' +); + +PREPARE add_source_type_stmt FROM @add_source_type_sql; +EXECUTE add_source_type_stmt; +DEALLOCATE PREPARE add_source_type_stmt; + +UPDATE `t_product` +SET `front_visible` = 1 +WHERE `front_visible` IS NULL; + +UPDATE `t_product` +SET `source_type` = 'BACKEND' +WHERE `source_type` IS NULL + OR `source_type` = '';