From c64755e25521d1cc5353bf862b2700a13ea42bd9 Mon Sep 17 00:00:00 2001 From: xiaowang <2161656029@qq.com> Date: Tue, 21 Jul 2026 13:49:25 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E5=BA=97=E5=8A=A1=E5=B0=8F?= =?UTF-8?q?=E7=A8=8B=E5=BA=8F=E9=A2=84=E7=BA=A6=E4=BD=9C=E5=93=81=E4=BB=B7?= =?UTF-8?q?=E6=A0=BC=E4=BA=A4=E4=BA=92?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service/impl/PlanningServiceImpl.java | 12 +++- .../service/impl/PlanningServiceImplTest.java | 59 +++++++++++++++++++ .../pages/appointment-form/index.js | 30 +++++++--- .../pages/appointment-form/index.wxml | 30 +++++----- .../pages/appointment-form/index.wxss | 56 +++++++++++++++--- memory/bugs.md | 8 +++ memory/progress.md | 19 +++--- 7 files changed, 170 insertions(+), 44 deletions(-) diff --git a/JY-Core/src/main/java/com/xiaowang/jayucloud/core/modules/planning/service/impl/PlanningServiceImpl.java b/JY-Core/src/main/java/com/xiaowang/jayucloud/core/modules/planning/service/impl/PlanningServiceImpl.java index 71fdc64b..1ea9955e 100644 --- a/JY-Core/src/main/java/com/xiaowang/jayucloud/core/modules/planning/service/impl/PlanningServiceImpl.java +++ b/JY-Core/src/main/java/com/xiaowang/jayucloud/core/modules/planning/service/impl/PlanningServiceImpl.java @@ -168,7 +168,7 @@ public class PlanningServiceImpl implements PlanningService { LocalDateTime endTime = startTime.plusMinutes(durationMinutes); ensureWithinBusinessHours(shopId, startTime, endTime); - BigDecimal unitPrice = product.getPrice() == null ? BigDecimal.ZERO : product.getPrice(); + BigDecimal unitPrice = resolveAppointmentUnitPrice(product, dto); BigDecimal amount = unitPrice.multiply(BigDecimal.valueOf(quantity)); OrderDO order = new OrderDO(); @@ -890,6 +890,16 @@ public class PlanningServiceImpl implements PlanningService { return product; } + private BigDecimal resolveAppointmentUnitPrice(ProductDO product, PlanningAppointmentCreateDTO dto) { + if (dto.getManualProductPrice() == null) { + return product.getPrice() == null ? BigDecimal.ZERO : product.getPrice(); + } + if (dto.getManualProductPrice().compareTo(BigDecimal.ZERO) < 0) { + throw new RuntimeException("本次价格不能小于0"); + } + return dto.getManualProductPrice(); + } + private int requireAppointmentDuration(Integer durationMinutes) { if (durationMinutes == null || durationMinutes <= 0) { throw new RuntimeException("预约时长不能为空且必须大于0分钟"); diff --git a/JY-Core/src/test/java/com/xiaowang/jayucloud/core/modules/planning/service/impl/PlanningServiceImplTest.java b/JY-Core/src/test/java/com/xiaowang/jayucloud/core/modules/planning/service/impl/PlanningServiceImplTest.java index 9c7719e6..acfa77a2 100644 --- a/JY-Core/src/test/java/com/xiaowang/jayucloud/core/modules/planning/service/impl/PlanningServiceImplTest.java +++ b/JY-Core/src/test/java/com/xiaowang/jayucloud/core/modules/planning/service/impl/PlanningServiceImplTest.java @@ -288,6 +288,65 @@ class PlanningServiceImplTest { assertThat(appointment.getFromMeituan()).isTrue(); } + @Test + void createAppointmentShouldUseAppointmentPriceWithoutChangingProductPrice() { + UserDO manager = user(2, 8L); + UserDO artist = user(3, 8L); + artist.setId(20L); + UserDO customer = user(0, 8L); + customer.setId(30L); + ShopDO shop = new ShopDO(); + shop.setBusinessHours("10:00-22:00"); + ProductDO product = product(100L, 8L, "90分钟"); + product.setPrice(new BigDecimal("168.00")); + PlanningAppointmentCreateDTO dto = new PlanningAppointmentCreateDTO(); + dto.setCustomerUserId(30L); + dto.setProductId(100L); + dto.setArtistId(20L); + dto.setAppointmentDate("2026-07-21"); + dto.setAppointmentTime("14:00"); + dto.setDurationMinutes(90); + dto.setManualProductPrice(new BigDecimal("188.00")); + + OrderDO[] storedOrder = new OrderDO[1]; + OrderItemDO[] storedItem = new OrderItemDO[1]; + when(adminScopeHelper.resolveShopScope(manager, null)).thenReturn(8L); + when(productMapper.selectById(100L)).thenReturn(product); + when(userMapper.selectById(20L)).thenReturn(artist); + when(userMapper.selectById(30L)).thenReturn(customer); + when(shopMapper.selectById(8L)).thenReturn(shop); + when(snowflakeIdGenerator.nextIdString()).thenReturn("202607210001"); + when(orderMapper.insert(any(OrderDO.class))).thenAnswer(invocation -> { + OrderDO order = invocation.getArgument(0); + order.setId(200L); + storedOrder[0] = order; + return 1; + }); + when(orderItemMapper.insert(any(OrderItemDO.class))).thenAnswer(invocation -> { + OrderItemDO item = invocation.getArgument(0); + item.setId(300L); + storedItem[0] = item; + return 1; + }); + when(orderItemMapper.selectById(300L)).thenAnswer(invocation -> storedItem[0]); + when(orderMapper.selectById(200L)).thenAnswer(invocation -> storedOrder[0]); + AppointmentReservationDO reservation = reservation(20L, 200L, 300L, + LocalDateTime.of(2026, 7, 21, 14, 0), + LocalDateTime.of(2026, 7, 21, 15, 30)); + when(appointmentReservationMapper.selectOne(any())).thenReturn(reservation); + when(userMapper.selectBatchIds(any())).thenReturn(List.of(customer)); + + var appointment = planningService.createAppointment(manager, dto); + + assertThat(storedOrder[0].getTotalAmount()).isEqualByComparingTo("188.00"); + assertThat(storedOrder[0].getActualAmount()).isEqualByComparingTo("188.00"); + assertThat(storedOrder[0].getPayAmount()).isEqualByComparingTo("188.00"); + assertThat(storedItem[0].getPrice()).isEqualByComparingTo("188.00"); + assertThat(product.getPrice()).isEqualByComparingTo("168.00"); + assertThat(appointment.getAmount()).isEqualByComparingTo("188.00"); + org.mockito.Mockito.verify(productMapper, org.mockito.Mockito.never()).insert(any()); + } + @Test void createAppointmentRejectsStoreRestDay() { UserDO manager = user(2, 8L); diff --git a/JY-Salon-WeChat/pages/appointment-form/index.js b/JY-Salon-WeChat/pages/appointment-form/index.js index 5317c7d2..8afa335c 100644 --- a/JY-Salon-WeChat/pages/appointment-form/index.js +++ b/JY-Salon-WeChat/pages/appointment-form/index.js @@ -233,6 +233,17 @@ function splitManualImageValues(value) { .filter(Boolean) } +function formatProductPrice(value) { + if (value === undefined || value === null || value === '') { + return '' + } + const price = Number(value) + if (!Number.isFinite(price) || price < 0) { + return '' + } + return String(price) +} + function isScheduleCoveringTime(schedule, form, startMinute, endMinute) { if (!schedule || String(schedule.artistId) !== String(form.artistId) || schedule.date !== form.appointmentDate) { return false @@ -270,7 +281,6 @@ Page({ manualProductPrice: '', manualProductDescription: '', manualProductTags: '', - manualProductTargetAudience: '', manualProductPrecautions: '', manualProductImageFileIds: '', manualProductImageUrl: '', @@ -391,10 +401,10 @@ Page({ } }, - onToggleChange(event) { + toggleFlag(event) { const field = event.currentTarget.dataset.field this.setData({ - [`form.${field}`]: !!event.detail.value + [`form.${field}`]: !this.data.form[field] }) }, @@ -523,14 +533,14 @@ Page({ selectProduct(event) { const selectedProduct = this.data.filteredProducts.find(item => String(item.id) === String(event.currentTarget.dataset.id)) || {} + const price = formatProductPrice(selectedProduct.price) this.setData({ selectedProduct, 'form.productId': selectedProduct.id, 'form.manualProductTitle': '', - 'form.manualProductPrice': '', + 'form.manualProductPrice': price, 'form.manualProductDescription': '', 'form.manualProductTags': '', - 'form.manualProductTargetAudience': '', 'form.manualProductPrecautions': '', 'form.manualProductImageFileIds': '', 'form.manualProductImageUrl': '', @@ -801,6 +811,11 @@ Page({ wx.showToast({ title: '请补全预约信息', icon: 'none' }) return } + const appointmentPrice = Number(form.manualProductPrice) + if (!Number.isFinite(appointmentPrice) || appointmentPrice < 0) { + wx.showToast({ title: '请填写本次价格', icon: 'none' }) + return + } if (!durationMinutes) { wx.showToast({ title: '请填写预约时长', icon: 'none' }) return @@ -827,14 +842,13 @@ Page({ if (form.productId) { payload.productId = String(form.productId) payload.manualProductTitle = undefined - payload.manualProductPrice = undefined + payload.manualProductPrice = appointmentPrice } else { payload.productId = undefined payload.manualProductTitle = String(form.manualProductTitle || '').trim() - payload.manualProductPrice = Number(form.manualProductPrice) + payload.manualProductPrice = appointmentPrice payload.manualProductDescription = String(form.manualProductDescription || '').trim() || undefined payload.manualProductTags = String(form.manualProductTags || '').trim() || undefined - payload.manualProductTargetAudience = String(form.manualProductTargetAudience || '').trim() || undefined payload.manualProductPrecautions = String(form.manualProductPrecautions || '').trim() || undefined payload.manualProductImageFileIds = String(form.manualProductImageFileIds || '').trim() || undefined } diff --git a/JY-Salon-WeChat/pages/appointment-form/index.wxml b/JY-Salon-WeChat/pages/appointment-form/index.wxml index 20e5c68c..a8564272 100644 --- a/JY-Salon-WeChat/pages/appointment-form/index.wxml +++ b/JY-Salon-WeChat/pages/appointment-form/index.wxml @@ -37,6 +37,11 @@ 手动 + + 本次价格 + + 元 + 预计时长 @@ -59,23 +64,17 @@ - - - 是否交定金 - - + + {{form.depositPaid ? '✓' : ''}} + 交定金 - - - 是否需要卸甲 - - + + {{form.needRemoval ? '✓' : ''}} + 需卸甲 - - - 是否来自美团 - - + + {{form.fromMeituan ? '✓' : ''}} + 美团 @@ -151,7 +150,6 @@