From d731489a4c26099e739dd7b3c6f619a99084bae0 Mon Sep 17 00:00:00 2001 From: Default User Date: Thu, 25 Dec 2025 11:49:53 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E6=94=B6=E8=97=8F=E9=A1=B5?= =?UTF-8?q?=E9=9D=A2=E7=82=B9=E5=87=BB=E8=B4=A7=E6=BA=90=E8=AF=A6=E6=83=85?= =?UTF-8?q?=E5=85=B3=E6=B3=A8=E4=BA=BA=E6=95=B0=E6=98=BE=E7=A4=BA=E4=B8=8D?= =?UTF-8?q?=E6=AD=A3=E7=A1=AE=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- custom-tab-bar/index.wxml | 2 +- pages/customer-service/index.wxss | 17 ++++++-- pages/goods-detail/goods-detail.js | 70 ++++++++++++++---------------- server-example/server-mysql.js | 28 +++++++++--- 4 files changed, 68 insertions(+), 49 deletions(-) diff --git a/custom-tab-bar/index.wxml b/custom-tab-bar/index.wxml index 9db4045..63e8efe 100644 --- a/custom-tab-bar/index.wxml +++ b/custom-tab-bar/index.wxml @@ -18,7 +18,7 @@ {{badges['buyer']}} - 买蛋 + 商城 diff --git a/pages/customer-service/index.wxss b/pages/customer-service/index.wxss index 8477c4a..4983e3f 100644 --- a/pages/customer-service/index.wxss +++ b/pages/customer-service/index.wxss @@ -1,8 +1,11 @@ /* pages/customer-service/index.wxss */ .container { - padding-bottom: 100rpx; + padding: 0; + margin: 0; background-color: #f8f8f8; min-height: 100vh; + width: 100%; + box-sizing: border-box; } /* 顶部导航栏 */ @@ -124,17 +127,21 @@ /* 经纪人列表 */ .broker-list { background-color: #f8f8f8; - padding: 0 30rpx; - margin-top: 280rpx; /* 为固定导航和搜索区域留出空间 */ + padding: 0; + margin: 280rpx 0 0 0; + width: 100%; + box-sizing: border-box; } .broker-item { background-color: #fff; border-radius: 24rpx; margin: 20rpx 0; - padding: 28rpx; + padding: 28rpx 30rpx; box-shadow: 0 2rpx 12rpx rgba(0, 0, 0, 0.05); transition: all 0.2s ease; + width: 100%; + box-sizing: border-box; } .broker-item:active { @@ -370,6 +377,8 @@ background-color: #fff; margin: 20rpx 0; border-radius: 24rpx; + width: 100%; + box-sizing: border-box; } .empty-state text:first-child { diff --git a/pages/goods-detail/goods-detail.js b/pages/goods-detail/goods-detail.js index ce676f7..0617a2d 100644 --- a/pages/goods-detail/goods-detail.js +++ b/pages/goods-detail/goods-detail.js @@ -183,14 +183,9 @@ Page({ // 确保商品ID的一致性 const productIdStr = String(product.productId || product.id); - // 增强的预约人数计算逻辑 - const selectedValue = product.selected; - const reservedCountValue = product.reservedCount; - const reservationCountValue = product.reservationCount; - - const finalReservationCount = selectedValue !== undefined && selectedValue !== null ? selectedValue : - (reservedCountValue !== undefined && reservedCountValue !== null ? reservedCountValue : - (reservationCountValue || 0)); + // 关键修改:直接使用API返回的reservedCount值,这个值已经是从favorites表中统计的收藏数量 + // 不再使用selected或reservationCount字段计算,确保收藏人数显示正确 + const finalReservationCount = product.reservedCount || 0; // 处理grossWeight为null或无效的情况,返回空字符串以支持文字输入 const grossWeightValue = product.grossWeight !== null && product.grossWeight !== undefined ? product.grossWeight : ''; @@ -237,35 +232,36 @@ Page({ if (!region) region = '地区未知'; // 转换商品数据格式 - const formattedGoods = { - id: productIdStr, - productId: productIdStr, - // 直接使用数据库字段名 - name: product.productName || product.name || '商品名称', - price: product.price, - minOrder: product.minOrder || product.quantity, - yolk: product.yolk, - spec: product.spec || product.specification || '暂无规格', - region: region, - // 直接使用数据库字段名,确保与表结构完全一致 - product_contact: contactName, - contact_phone: contactPhone, - // 保留原始字段引用,确保数据完整性 - imageUrls: product.imageUrls || product.images || [], - displayGrossWeight: formatGrossWeight(grossWeightValue, product.weight), - isReserved: reservedGoodsIds.some(itemId => String(itemId) === productIdStr), - reservedCount: finalReservationCount, - created_at: product.created_at || product.createdAt, - updated_at: product.updated_at || product.updatedAt, - status: product.status, - supplyStatus: supplyStatusValue, - sourceType: product.sourceType || '', - sourceTypeColor: getSourceTypeColor(product.sourceType), - // 复制原始产品对象中的所有字段,确保不丢失任何数据 - ...product, - // 合并预加载数据中的字段,优先使用预加载数据中的联系人信息 - ...(preloadedData || {}) - }; + const formattedGoods = { + id: productIdStr, + productId: productIdStr, + // 直接使用数据库字段名 + name: product.productName || product.name || '商品名称', + price: product.price, + minOrder: product.minOrder || product.quantity, + yolk: product.yolk, + spec: product.spec || product.specification || '暂无规格', + region: region, + // 直接使用数据库字段名,确保与表结构完全一致 + product_contact: contactName, + contact_phone: contactPhone, + // 保留原始字段引用,确保数据完整性 + imageUrls: product.imageUrls || product.images || [], + displayGrossWeight: formatGrossWeight(grossWeightValue, product.weight), + isReserved: reservedGoodsIds.some(itemId => String(itemId) === productIdStr), + created_at: product.created_at || product.createdAt, + updated_at: product.updated_at || product.updatedAt, + status: product.status, + supplyStatus: supplyStatusValue, + sourceType: product.sourceType || '', + sourceTypeColor: getSourceTypeColor(product.sourceType), + // 复制原始产品对象中的所有字段,确保不丢失任何数据 + ...product, + // 合并预加载数据中的字段,优先使用预加载数据中的联系人信息 + ...(preloadedData || {}), + // 确保reservedCount字段使用我们计算得到的值,放在最后以覆盖其他来源的值 + reservedCount: finalReservationCount + }; console.log('最终格式化后的数据:', { product_contact: formattedGoods.product_contact, diff --git a/server-example/server-mysql.js b/server-example/server-mysql.js index d92c922..b1205eb 100644 --- a/server-example/server-mysql.js +++ b/server-example/server-mysql.js @@ -1853,7 +1853,7 @@ app.post('/api/product/list', async (req, res) => { } // 处理商品列表中的grossWeight字段,确保是数字类型,同时反序列化imageUrls - const processedProducts = products.map(product => { + const processedProducts = await Promise.all(products.map(async product => { const productJSON = product.toJSON(); // 确保created_at字段存在并转换为ISO字符串格式 @@ -1880,8 +1880,15 @@ app.post('/api/product/list', async (req, res) => { // 确保grossWeight值是字符串类型 productJSON.grossWeight = String(grossWeightDetails.value); - // 确保reservedCount是数字类型,如果不存在则默认为0 - productJSON.reservedCount = typeof productJSON.reservedCount === 'number' ? productJSON.reservedCount : 0; + // 查询该商品的收藏人数 - 从favorites表中统计 + const favoriteCount = await Favorite.count({ + where: { + productId: productJSON.productId + } + }); + + // 使用查询到的收藏人数更新reservedCount字段 + productJSON.reservedCount = favoriteCount; // 重要修复:反序列化imageUrls字段,确保前端收到的是数组 if (productJSON.imageUrls && typeof productJSON.imageUrls === 'string') { @@ -1934,7 +1941,7 @@ app.post('/api/product/list', async (req, res) => { } return productJSON; - }); + })); // 准备响应数据 - 修改格式以匹配前端期望 const responseData = { @@ -3687,6 +3694,13 @@ app.post('/api/products/detail', async (req, res) => { }); } + // 查询收藏人数 - 从favorites表中统计该商品的收藏数量 + const favoriteCount = await Favorite.count({ + where: { + productId: productId + } + }); + // 对返回的商品数据进行处理 let updatedProduct = { ...product.toJSON() }; @@ -3730,11 +3744,11 @@ app.post('/api/products/detail', async (req, res) => { updatedProduct.grossWeight = String(grossWeightDetails.value); } - // 确保reservedCount是数字类型,如果不存在则默认为0 - updatedProduct.reservedCount = typeof updatedProduct.reservedCount === 'number' ? updatedProduct.reservedCount : 0; + // 设置收藏人数 - 从favorites表统计得到 + updatedProduct.reservedCount = favoriteCount; console.log('商品详情 - 最终返回的毛重值:', updatedProduct.grossWeight, '类型:', typeof updatedProduct.grossWeight); - console.log('商品详情 - 返回的预约人数:', updatedProduct.reservedCount, '类型:', typeof updatedProduct.reservedCount); + console.log('商品详情 - 返回的收藏人数:', updatedProduct.reservedCount, '类型:', typeof updatedProduct.reservedCount); res.json({ success: true,