{"id":20,"date":"2025-12-22T23:06:23","date_gmt":"2025-12-22T15:06:23","guid":{"rendered":"https:\/\/wjylovecx.xyz\/?p=20"},"modified":"2026-01-22T12:20:59","modified_gmt":"2026-01-22T04:20:59","slug":"2-%e5%b0%8f%e7%a8%8b%e5%ba%8f%e5%95%86%e5%93%81%e7%95%99%e8%a8%80%e6%a5%bc%e4%b8%ad%e6%a5%bc%e7%9a%84%e5%ae%9e%e7%8e%b0","status":"publish","type":"post","link":"https:\/\/wjylovecx.xyz\/?p=20","title":{"rendered":"\u5c0f\u7a0b\u5e8f\u5546\u54c1\u7559\u8a00\u697c\u4e2d\u697c\u7684\u5b9e\u73b0"},"content":{"rendered":"\n<p><strong>\u4e00\u4e2a\u5546\u54c1\u4e0b\u662f\u5426\u53ef\u4ee5\u6709\u591a\u4e2a\u72ec\u7acb\u7684\u9876\u7ea7\u7559\u8a00\uff0c\u6bcf\u4e2a\u9876\u7ea7\u7559\u8a00\u4e0b\u9762\u90fd\u6709\u81ea\u5df1\u7684\u697c\u4e2d\u697c\uff1f<\/strong><\/p>\n\n\n\n<p><strong>\u7b54\u6848\uff1a\u662f\u7684\uff01\u5b8c\u5168\u53ef\u4ee5\uff01<\/strong> \u6bcf\u4e2a\u5546\u54c1\u4e0b\u53ef\u4ee5\u6709\u591a\u4e2a\u72ec\u7acb\u7684\u9876\u7ea7\u7559\u8a00\uff0c\u6bcf\u4e2a\u9876\u7ea7\u7559\u8a00\u90fd\u662f\u4e00\u4e2a\u72ec\u7acb\u7684\u697c\u4e2d\u697c\u6811\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">\u4e00\u3001\u6570\u636e\u5e93\u793a\u4f8b\uff08\u591a\u4e2a\u9876\u7ea7\u7559\u8a00\uff09<\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code>-- \u5546\u54c11\u4e0b\u9762\u67093\u4e2a\u72ec\u7acb\u7684\u9876\u7ea7\u7559\u8a00\uff0c\u6bcf\u4e2a\u90fd\u6709\u81ea\u5df1\u7684\u697c\u4e2d\u697c\u5bf9\u8bdd\u94fe\nINSERT INTO product_comments (id, product_id, user_id, user_name, parent_id, content) VALUES\n-- ===== \u7b2c1\u4e2a\u9876\u7ea7\u7559\u8a00\uff08\u5173\u4e8e\u62cd\u7167\uff09=====\n(1, 1, 1, '\u7528\u6237A', NULL, '\u8fd9\u4e2a\u624b\u673a\u62cd\u7167\u600e\u4e48\u6837\uff1f'),      -- \u9876\u7ea7\u7559\u8a001\n(2, 1, 2, '\u7528\u6237B', 1, '\u62cd\u7167\u5f88\u6e05\u6670\uff01'),                 -- \u56de\u590d\u7559\u8a001\n(3, 1, 3, '\u7528\u6237C', 2, '\u591c\u95f4\u62cd\u7167\u5462\uff1f'),                 -- \u56de\u590d\u7559\u8a002\n(4, 1, 4, '\u7528\u6237D', 3, '\u591c\u95f4\u4e5f\u4e0d\u9519'),                  -- \u56de\u590d\u7559\u8a003\n\n-- ===== \u7b2c2\u4e2a\u9876\u7ea7\u7559\u8a00\uff08\u5173\u4e8e\u7535\u6c60\uff09=====\n(5, 1, 5, '\u7528\u6237E', NULL, '\u7535\u6c60\u7eed\u822a\u591a\u4e45\uff1f'),            -- \u9876\u7ea7\u7559\u8a002\n(6, 1, 6, '\u7528\u6237F', 5, '\u80fd\u7528\u4e00\u6574\u5929'),                  -- \u56de\u590d\u7559\u8a005\n(7, 1, 7, '\u7528\u6237G', 6, '\u73a9\u6e38\u620f\u5462\uff1f'),                  -- \u56de\u590d\u7559\u8a006\n(8, 1, 8, '\u7528\u6237H', 7, '\u73a9\u6e38\u620f\u4e5f\u591f\u7528'),                -- \u56de\u590d\u7559\u8a007\n\n-- ===== \u7b2c3\u4e2a\u9876\u7ea7\u7559\u8a00\uff08\u5173\u4e8e\u4ef7\u683c\uff09=====\n(9, 1, 9, '\u7528\u6237I', NULL, '\u4ef7\u683c\u592a\u8d35\u4e86\u5427\uff1f'),            -- \u9876\u7ea7\u7559\u8a003\n(10, 1, 10, '\u7528\u6237J', 9, '\u4f46\u6027\u80fd\u597d\u5440'),                -- \u56de\u590d\u7559\u8a009\n(11, 1, 11, '\u7528\u6237K', 10, '\u786e\u5b9e\u503c\u8fd9\u4e2a\u4ef7');              -- \u56de\u590d\u7559\u8a0010\n<\/code><\/pre>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"430\" src=\"https:\/\/wjylovecx.xyz\/wp-content\/uploads\/2025\/12\/image-1024x430.png\" alt=\"\" class=\"wp-image-39\" srcset=\"https:\/\/wjylovecx.xyz\/wp-content\/uploads\/2025\/12\/image-1024x430.png 1024w, https:\/\/wjylovecx.xyz\/wp-content\/uploads\/2025\/12\/image-300x126.png 300w, https:\/\/wjylovecx.xyz\/wp-content\/uploads\/2025\/12\/image-768x322.png 768w, https:\/\/wjylovecx.xyz\/wp-content\/uploads\/2025\/12\/image.png 1070w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\">\u4e8c\u3001\u6784\u5efa\u7684\u6811\u5f62\u7ed3\u6784<\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code>\/\/ \u67e5\u8be2\u5546\u54c11\u7684\u6240\u6709\u7559\u8a00\u540e\uff0c\u4f1a\u6784\u5efa\u51fa\u8fd9\u6837\u7684\u7ed3\u6784\uff1a\nconst commentTree = &#91;\n  {\n    id: 1,\n    content: '\u8fd9\u4e2a\u624b\u673a\u62cd\u7167\u600e\u4e48\u6837\uff1f',\n    parent_id: null,  \/\/ \u9876\u7ea7\u7559\u8a00\n    replies: &#91;        \/\/ \u7b2c1\u4e2a\u697c\u4e2d\u697c\u5bf9\u8bdd\u94fe\n      {\n        id: 2,\n        content: '\u62cd\u7167\u5f88\u6e05\u6670\uff01',\n        parent_id: 1,\n        replies: &#91;\n          {\n            id: 3,\n            content: '\u591c\u95f4\u62cd\u7167\u5462\uff1f',\n            parent_id: 2,\n            replies: &#91;\n              {\n                id: 4,\n                content: '\u591c\u95f4\u4e5f\u4e0d\u9519',\n                parent_id: 3,\n                replies: &#91;]\n              }\n            ]\n          }\n        ]\n      }\n    ]\n  },\n  {\n    id: 5,\n    content: '\u7535\u6c60\u7eed\u822a\u591a\u4e45\uff1f',\n    parent_id: null,  \/\/ \u9876\u7ea7\u7559\u8a00\n    replies: &#91;        \/\/ \u7b2c2\u4e2a\u697c\u4e2d\u697c\u5bf9\u8bdd\u94fe\n      {\n        id: 6,\n        content: '\u80fd\u7528\u4e00\u6574\u5929',\n        parent_id: 5,\n        replies: &#91;\n          {\n            id: 7,\n            content: '\u73a9\u6e38\u620f\u5462\uff1f',\n            parent_id: 6,\n            replies: &#91;\n              {\n                id: 8,\n                content: '\u73a9\u6e38\u620f\u4e5f\u591f\u7528',\n                parent_id: 7,\n                replies: &#91;]\n              }\n            ]\n          }\n        ]\n      }\n    ]\n  },\n  {\n    id: 9,\n    content: '\u4ef7\u683c\u592a\u8d35\u4e86\u5427\uff1f',\n    parent_id: null,  \/\/ \u9876\u7ea7\u7559\u8a00\n    replies: &#91;        \/\/ \u7b2c3\u4e2a\u697c\u4e2d\u697c\u5bf9\u8bdd\u94fe\n      {\n        id: 10,\n        content: '\u4f46\u6027\u80fd\u597d\u5440',\n        parent_id: 9,\n        replies: &#91;\n          {\n            id: 11,\n            content: '\u786e\u5b9e\u503c\u8fd9\u4e2a\u4ef7',\n            parent_id: 10,\n            replies: &#91;]\n          }\n        ]\n      }\n    ]\n  }\n];\n<\/code><\/pre>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"788\" height=\"678\" src=\"https:\/\/wjylovecx.xyz\/wp-content\/uploads\/2025\/12\/8d84ac97ce7e30968f26c35ce394f236.png\" alt=\"\" class=\"wp-image-41\" srcset=\"https:\/\/wjylovecx.xyz\/wp-content\/uploads\/2025\/12\/8d84ac97ce7e30968f26c35ce394f236.png 788w, https:\/\/wjylovecx.xyz\/wp-content\/uploads\/2025\/12\/8d84ac97ce7e30968f26c35ce394f236-300x258.png 300w, https:\/\/wjylovecx.xyz\/wp-content\/uploads\/2025\/12\/8d84ac97ce7e30968f26c35ce394f236-768x661.png 768w\" sizes=\"auto, (max-width: 788px) 100vw, 788px\" \/><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\">\u4e09\u3001\u524d\u7aef\u663e\u793a\u6548\u679c<\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code>=== \u5546\u54c1\uff1aiPhone 15 Pro ===\n\n\u3010\u697c\u5c421\u3011\u7528\u6237A: \u8fd9\u4e2a\u624b\u673a\u62cd\u7167\u600e\u4e48\u6837\uff1f\n\u251c\u2500\u2500 \u7528\u6237B: \u62cd\u7167\u5f88\u6e05\u6670\uff01\n\u2502   \u2514\u2500\u2500 \u7528\u6237C: \u591c\u95f4\u62cd\u7167\u5462\uff1f\n\u2502       \u2514\u2500\u2500 \u7528\u6237D: \u591c\u95f4\u4e5f\u4e0d\u9519\n\n\u3010\u697c\u5c422\u3011\u7528\u6237E: \u7535\u6c60\u7eed\u822a\u591a\u4e45\uff1f\n\u251c\u2500\u2500 \u7528\u6237F: \u80fd\u7528\u4e00\u6574\u5929\n\u2502   \u2514\u2500\u2500 \u7528\u6237G: \u73a9\u6e38\u620f\u5462\uff1f\n\u2502       \u2514\u2500\u2500 \u7528\u6237H: \u73a9\u6e38\u620f\u4e5f\u591f\u7528\n\n\u3010\u697c\u5c423\u3011\u7528\u6237I: \u4ef7\u683c\u592a\u8d35\u4e86\u5427\uff1f\n\u251c\u2500\u2500 \u7528\u6237J: \u4f46\u6027\u80fd\u597d\u5440\n\u2502   \u2514\u2500\u2500 \u7528\u6237K: \u786e\u5b9e\u503c\u8fd9\u4e2a\u4ef7\n\n\u3010\u697c\u5c424\u3011\u7528\u6237L: \u7cfb\u7edf\u6d41\u7545\u5417\uff1f\n\u2514\u2500\u2500 \u7528\u6237M: \u975e\u5e38\u6d41\u7545\n    \u2514\u2500\u2500 \u7528\u6237N: \u6253\u6e38\u620f\u5361\u5417\uff1f\n        \u2514\u2500\u2500 \u7528\u6237O: \u5b8c\u5168\u4e0d\u5361<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">\u56db\u3001\u5173\u952e\u67e5\u8be2\u4ee3\u7801<\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code>\/\/ \u83b7\u53d6\u5546\u54c1\u7684\u6240\u6709\u7559\u8a00\uff08\u5305\u542b\u591a\u4e2a\u9876\u7ea7\u7559\u8a00\uff09\nstatic async getProductCommentTree(productId, page = 1, limit = 20) {\n  \/\/ 1. \u5206\u9875\u67e5\u8be2\u9876\u7ea7\u7559\u8a00\n  const topLevelSql = `\n    SELECT * FROM product_comments \n    WHERE product_id = ? \n      AND parent_id IS NULL  -- \u53ea\u67e5\u9876\u7ea7\u7559\u8a00\n      AND status = 1\n    ORDER BY created_at DESC\n    LIMIT ? OFFSET ?\n  `;\n\n  const &#91;topLevelComments] = await db.execute(topLevelSql, &#91;productId, limit, offset]);\n\n  \/\/ 2. \u83b7\u53d6\u6240\u6709\u76f8\u5173\u7559\u8a00\n  const allCommentsSql = `\n    SELECT * FROM product_comments \n    WHERE product_id = ? AND status = 1\n    ORDER BY created_at ASC\n  `;\n  const &#91;allComments] = await db.execute(allCommentsSql, &#91;productId]);\n\n  \/\/ 3. \u4e3a\u6bcf\u4e2a\u9876\u7ea7\u7559\u8a00\u6784\u5efa\u81ea\u5df1\u7684\u697c\u4e2d\u697c\u6811\n  const commentTree = this.buildCommentTree(topLevelComments, allComments);\n\n  return commentTree;\n}<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">\u4e94\u3001\u521b\u5efa\u65b0\u9876\u7ea7\u7559\u8a00\u7684\u793a\u4f8b<\/h2>\n\n\n\n<p>\u7528\u6237\u60f3\u53d1\u8d77\u4e00\u4e2a\u65b0\u7684\u8bdd\u9898\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\/\/ API\u8c03\u7528\uff1a\u521b\u5efa\u65b0\u7684\u9876\u7ea7\u7559\u8a00\nPOST \/api\/comments\n{\n  \"product_id\": 1,\n  \"user_id\": 12,\n  \"user_name\": \"\u7528\u6237L\",\n  \"parent_id\": null,  \/\/ \u5173\u952e\uff1aparent_id\u4e3anull\u8868\u793a\u662f\u9876\u7ea7\u7559\u8a00\n  \"content\": \"\u7cfb\u7edf\u6d41\u7545\u5417\uff1f\"\n}\n\n\/\/ \u6570\u636e\u5e93\u63d2\u5165\uff1a\n\/\/ id: 12, product_id: 1, user_id: 12, parent_id: NULL, content: \"\u7cfb\u7edf\u6d41\u7545\u5417\uff1f\"<\/code><\/pre>\n\n\n\n<p>\u7136\u540e\u5176\u4ed6\u4eba\u53ef\u4ee5\u56de\u590d\u8fd9\u4e2a\u65b0\u8bdd\u9898\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\/\/ \u56de\u590d\u8fd9\u4e2a\u65b0\u8bdd\u9898\nPOST \/api\/comments\n{\n  \"product_id\": 1,\n  \"user_id\": 13,\n  \"user_name\": \"\u7528\u6237M\",\n  \"parent_id\": 12,  \/\/ \u56de\u590did=12\u7684\u7559\u8a00\n  \"content\": \"\u975e\u5e38\u6d41\u7545\"\n}\n\n\/\/ \u518d\u56de\u590d\u8fd9\u4e2a\u56de\u590d\nPOST \/api\/comments\n{\n  \"product_id\": 1,\n  \"user_id\": 14,\n  \"user_name\": \"\u7528\u6237N\",\n  \"parent_id\": 13,  \/\/ \u56de\u590did=13\u7684\u7559\u8a00\n  \"content\": \"\u6253\u6e38\u620f\u5361\u5417\uff1f\"\n}<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">\u516d\u3001\u603b\u7ed3<\/h2>\n\n\n\n<p>\u4e00\u4e2a\u5546\u54c1\u4e0b\u7684\u7559\u8a00\u7ed3\u6784\u5c31\u50cf\u8fd9\u6837\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\u5546\u54c11\n\u251c\u2500\u2500 \u9876\u7ea7\u7559\u8a001\uff08\u697c\u4e2d\u697c\u68111\uff09\n\u2502   \u251c\u2500\u2500 \u56de\u590d1-1\n\u2502   \u2502   \u2514\u2500\u2500 \u56de\u590d1-1-1\n\u2502   \u2502       \u2514\u2500\u2500 \u56de\u590d1-1-1-1\n\u2502   \u2514\u2500\u2500 \u56de\u590d1-2\n\u2502       \u2514\u2500\u2500 \u56de\u590d1-2-1\n\u251c\u2500\u2500 \u9876\u7ea7\u7559\u8a002\uff08\u697c\u4e2d\u697c\u68112\uff09\n\u2502   \u251c\u2500\u2500 \u56de\u590d2-1\n\u2502   \u2502   \u2514\u2500\u2500 \u56de\u590d2-1-1\n\u2502   \u2514\u2500\u2500 \u56de\u590d2-2\n\u2514\u2500\u2500 \u9876\u7ea7\u7559\u8a003\uff08\u697c\u4e2d\u697c\u68113\uff09\n    \u251c\u2500\u2500 \u56de\u590d3-1\n    \u2502   \u2514\u2500\u2500 \u56de\u590d3-1-1\n    \u2514\u2500\u2500 \u56de\u590d3-2\n        \u2514\u2500\u2500 \u56de\u590d3-2-1\n            \u2514\u2500\u2500 \u56de\u590d3-2-1-1<\/code><\/pre>\n\n\n\n<p><strong>\u6838\u5fc3\u7279\u70b9\uff1a<\/strong><\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li>\u4e00\u4e2a\u5546\u54c1\u53ef\u4ee5\u6709<strong>\u591a\u4e2a\u9876\u7ea7\u7559\u8a00<\/strong>\uff08\u6bcf\u4e2a\u90fd\u662f\u72ec\u7acb\u7684\u8bdd\u9898\uff09<\/li>\n\n\n\n<li>\u6bcf\u4e2a\u9876\u7ea7\u7559\u8a00\u4e0b\u9762\u53ef\u4ee5\u6709<strong>\u81ea\u5df1\u7684\u697c\u4e2d\u697c\u5bf9\u8bdd\u6811<\/strong><\/li>\n\n\n\n<li>\u697c\u4e2d\u697c\u53ef\u4ee5\u65e0\u9650\u5c42\u7ea7\u5d4c\u5957<\/li>\n\n\n\n<li>\u6bcf\u4e2a\u9876\u7ea7\u7559\u8a00\u548c\u5b83\u7684\u6240\u6709\u56de\u590d\u6784\u6210\u4e00\u4e2a\u72ec\u7acb\u7684\u6811<\/li>\n<\/ol>\n\n\n\n<p>\u6240\u4ee5\u60a8\u5b8c\u5168\u53ef\u4ee5\u5b9e\u73b0\uff1a<strong>\u5728\u4e00\u4e2a\u5546\u54c1\u9875\u9762\u4e0b\uff0c\u663e\u793a\u591a\u4e2a\u72ec\u7acb\u7684\u697c\u4e2d\u697c\u5bf9\u8bdd\uff0c\u6bcf\u4e2a\u5bf9\u8bdd\u8ba8\u8bba\u4e0d\u540c\u7684\u8bdd\u9898<\/strong>\u3002\u8fd9\u5c31\u662f\u5178\u578b\u7684\u8bba\u575b\/\u5546\u54c1\u7559\u8a00\u677f\u6a21\u5f0f\uff01<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u4e00\u4e2a\u5546\u54c1\u4e0b\u662f\u5426\u53ef\u4ee5\u6709\u591a\u4e2a\u72ec\u7acb\u7684\u9876\u7ea7\u7559\u8a00\uff0c\u6bcf\u4e2a\u9876\u7ea7\u7559\u8a00\u4e0b\u9762\u90fd\u6709\u81ea\u5df1\u7684\u697c\u4e2d\u697c\uff1f \u7b54\u6848\uff1a\u662f\u7684\uff01\u5b8c\u5168\u53ef\u4ee5\uff01 \u6bcf\u4e2a\u5546\u54c1\u4e0b [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":73,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[7],"tags":[],"class_list":["post-20","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-7"],"_links":{"self":[{"href":"https:\/\/wjylovecx.xyz\/index.php?rest_route=\/wp\/v2\/posts\/20","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/wjylovecx.xyz\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/wjylovecx.xyz\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/wjylovecx.xyz\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/wjylovecx.xyz\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=20"}],"version-history":[{"count":4,"href":"https:\/\/wjylovecx.xyz\/index.php?rest_route=\/wp\/v2\/posts\/20\/revisions"}],"predecessor-version":[{"id":53,"href":"https:\/\/wjylovecx.xyz\/index.php?rest_route=\/wp\/v2\/posts\/20\/revisions\/53"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/wjylovecx.xyz\/index.php?rest_route=\/wp\/v2\/media\/73"}],"wp:attachment":[{"href":"https:\/\/wjylovecx.xyz\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=20"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/wjylovecx.xyz\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=20"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/wjylovecx.xyz\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=20"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}