From 9baf5f29f72163b77a6d97af76ccb5f3b76e2f02 Mon Sep 17 00:00:00 2001 From: xiaoquan <838115837@qq.com> Date: Wed, 27 May 2026 18:58:39 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E8=BF=AD=E4=BB=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .claude/settings.local.json | 7 +- FIX_DOUBLE_API_PATH.md | 89 --- INTERFACE_CLASSIFICATION_PLAN.md | 584 ---------------- QUICK_REFACTOR.md | 300 -------- REFACTOR_COMPLETED.md | 352 ---------- REFACTOR_GUIDE.md | 645 ------------------ REFACTOR_SUCCESS.md | 327 --------- apps/miniapp/.env.development | 2 +- apps/miniapp/src/api/user/wallet.ts | 16 +- apps/miniapp/src/components/CityPicker.vue | 212 +++++- apps/miniapp/src/manifest.json | 10 +- apps/miniapp/src/pages/index/index.vue | 4 +- apps/miniapp/src/pages/invite/cashbacks.vue | 19 +- apps/miniapp/src/pages/invite/records.vue | 24 +- .../src/pages/merchant-detail/index.vue | 15 - apps/miniapp/src/pages/order-detail/index.vue | 13 +- apps/miniapp/src/pages/order/index.vue | 7 +- apps/miniapp/src/pages/seller/orders.vue | 11 +- .../src/pages/seller/settlement-detail.vue | 13 +- .../miniapp/src/pages/seller/transactions.vue | 17 +- apps/miniapp/src/pages/seller/withdrawals.vue | 209 +++--- apps/miniapp/src/pages/verify/index.vue | 8 +- apps/miniapp/src/pages/wallet/withdrawals.vue | 207 +++--- apps/miniapp/src/utils/date.ts | 95 ++- apps/miniapp/src/utils/request.ts | 6 +- .../src/pages/finance/Accounts.tsx | 106 +-- .../src/pages/finance/Dashboard.tsx | 40 +- .../pages/finance/PlatformTransactions.tsx | 2 +- .../src/pages/finance/PlatformWallet.tsx | 7 +- .../src/pages/finance/PlatformWithdrawals.tsx | 79 +-- .../src/pages/finance/Withdrawals.tsx | 12 +- .../src/entities/merchant-account.entity.ts | 7 +- .../entities/platform-withdrawal.entity.ts | 2 +- .../src/entities/user-account.entity.ts | 7 +- apps/server/src/modules/app/app.module.ts | 2 + .../app/location/location.controller.ts | 27 + .../modules/app/location/location.module.ts | 10 + .../modules/app/location/location.service.ts | 138 ++++ .../modules/shared/finance/account.service.ts | 28 +- .../shared/finance/dto/withdrawal.dto.ts | 5 +- .../modules/shared/finance/report.service.ts | 2 +- .../shared/finance/withdrawal.service.ts | 23 +- database/migrations/001_init_schema.sql | 2 +- 订单费用计算逻辑说明.md | 140 ---- 44 files changed, 928 insertions(+), 2903 deletions(-) delete mode 100644 FIX_DOUBLE_API_PATH.md delete mode 100644 INTERFACE_CLASSIFICATION_PLAN.md delete mode 100644 QUICK_REFACTOR.md delete mode 100644 REFACTOR_COMPLETED.md delete mode 100644 REFACTOR_GUIDE.md delete mode 100644 REFACTOR_SUCCESS.md create mode 100644 apps/server/src/modules/app/location/location.controller.ts create mode 100644 apps/server/src/modules/app/location/location.module.ts create mode 100644 apps/server/src/modules/app/location/location.service.ts delete mode 100644 订单费用计算逻辑说明.md diff --git a/.claude/settings.local.json b/.claude/settings.local.json index 7689531..6ce76a2 100644 --- a/.claude/settings.local.json +++ b/.claude/settings.local.json @@ -86,7 +86,12 @@ "Bash(mysql -u root -p123456 rent_platform -e \"SELECT id, name, type, enabled, config FROM mkt_activities WHERE type='invite_cashback' LIMIT 1\")", "Bash(node check-config.js)", "Bash(node verify-fix.js)", - "Bash(ipconfig)" + "Bash(ipconfig)", + "Bash(cat > *)", + "Bash(mysql -h localhost -P 3306 -u root -pquan131735 rent_platform -e \"ALTER TABLE platform_withdrawals MODIFY COLUMN account_name VARCHAR\\(50\\) NULL COMMENT '账户名';\")" + ], + "additionalDirectories": [ + "\\tmp" ] } } diff --git a/FIX_DOUBLE_API_PATH.md b/FIX_DOUBLE_API_PATH.md deleted file mode 100644 index f81e5c7..0000000 --- a/FIX_DOUBLE_API_PATH.md +++ /dev/null @@ -1,89 +0,0 @@ -# 修复双重 /api 路径问题 - -## 问题描述 -URL中出现了双重`/api`前缀,例如: -``` -http://localhost:3000/api/api/public/merchants -``` - -## 原因分析 -- `baseURL` 配置中包含了 `/api` 前缀 -- API路径中也包含了 `/api` 前缀 -- 拼接后导致重复 - -## 修复方案 - -### 1. 小程序 (apps/miniapp/src/utils/request.ts) -```typescript -// 修改前 -const BASE_URL = import.meta.env.VITE_API_BASE_URL || 'http://localhost:3000/api'; - -// 修改后 -const BASE_URL = import.meta.env.VITE_API_BASE_URL || 'http://localhost:3000'; -``` - -### 2. 商家后台 (apps/merchant-admin/src/utils/request.ts) -```typescript -// 修改前 -const request = axios.create({ - baseURL: '/api', - timeout: 15000, -}); - -// 修改后 -const request = axios.create({ - baseURL: '', - timeout: 15000, -}); -``` - -### 3. 平台后台 (apps/platform-admin/src/utils/request.ts) -```typescript -// 修改前 -const request = axios.create({ - baseURL: '/api', - timeout: 15000, -}); - -// 修改后 -const request = axios.create({ - baseURL: '', - timeout: 15000, -}); -``` - -## 修复后的URL格式 - -### 小程序 -``` -http://localhost:3000/api/user/auth/login -http://localhost:3000/api/public/rooms -http://localhost:3000/api/public/merchants -``` - -### 商家后台(通过代理) -``` -/api/merchant/auth/login -/api/merchant/rooms -/api/merchant/orders -``` - -### 平台后台(通过代理) -``` -/api/admin/auth/login -/api/admin/users -/api/admin/merchants -``` - -## 验证方法 - -1. 启动后端服务 -2. 启动前端应用 -3. 打开浏览器开发者工具 Network 面板 -4. 检查请求URL是否正确(只有一个 `/api` 前缀) - -## 修复时间 -2026-05-14 14:35 - -## 状态 -✅ 已修复 diff --git a/INTERFACE_CLASSIFICATION_PLAN.md b/INTERFACE_CLASSIFICATION_PLAN.md deleted file mode 100644 index 7acbfe3..0000000 --- a/INTERFACE_CLASSIFICATION_PLAN.md +++ /dev/null @@ -1,584 +0,0 @@ -# 接口分类重构计划 - -## 一、重构目标 - -将所有后端接口按照使用端分成四类,通过文件夹和路由前缀清晰区分: - -1. **应用端 (app)** - 小程序C端用户使用的接口 -2. **商家端 (merchant)** - 小程序商家端 + 商家管理后台使用的接口 -3. **平台管理端 (admin)** - 平台管理后台使用的接口 -4. **官网 (website)** - 官方网站使用的接口 - -## 二、目标目录结构 - -``` -apps/server/src/modules/ -├── app/ # 应用端接口 (路由前缀: /api/app/*) -│ ├── auth/ # 用户认证 -│ ├── profile/ # 用户资料 -│ ├── order/ # 订单管理 -│ ├── review/ # 评价管理 -│ ├── coupon/ # 优惠券 -│ ├── guest/ # 入住人管理 -│ ├── activity/ # 活动/邀请 -│ ├── finance/ # 钱包/提现 -│ └── app.module.ts -│ -├── merchant/ # 商家端接口 (路由前缀: /api/merchant/*) -│ ├── auth/ # 商家认证 -│ ├── profile/ # 商家资料 -│ ├── room/ # 房源管理 -│ ├── room-calendar/ # 房态日历 -│ ├── order/ # 订单管理 -│ ├── review/ # 评价管理 -│ ├── statistics/ # 数据统计 -│ ├── finance/ # 财务管理 -│ └── merchant.module.ts -│ -├── admin/ # 平台管理端接口 (路由前缀: /api/admin/*) -│ ├── auth/ # 管理员认证 -│ ├── user/ # 用户管理 -│ ├── merchant/ # 商家管理 -│ ├── room/ # 房源管理 -│ ├── order/ # 订单管理 -│ ├── review/ # 评价管理 -│ ├── coupon/ # 优惠券管理 -│ ├── activity/ # 活动管理 -│ ├── config/ # 系统配置 -│ ├── website/ # 官网内容管理 -│ ├── finance/ # 财务管理 -│ │ ├── account/ # 账户管理 -│ │ ├── transaction/ # 交易记录 -│ │ ├── withdrawal/ # 提现管理 -│ │ ├── settlement/ # 结算管理 -│ │ ├── reconciliation/# 对账管理 -│ │ └── report/ # 财务报表 -│ └── admin.module.ts -│ -├── website/ # 官网接口 (路由前缀: /api/website/*) -│ ├── info/ # 网站信息 -│ ├── room/ # 房源展示(公开) -│ ├── merchant/ # 商家展示(公开) -│ └── website.module.ts -│ -└── shared/ # 共享模块(不对外暴露路由) - ├── upload/ # 文件上传 - └── config/ # 配置服务 -``` - -## 三、接口分类详情 - -### 3.1 应用端接口 (48个接口) - -**路由前缀**: `/api/app/*` - -| 模块 | 当前路由 | 新路由 | 文件位置 | -|------|---------|--------|----------| -| 用户认证 | `/user/auth/*` | `/api/app/auth/*` | user/auth/ | -| 用户资料 | `/user/profile/*` | `/api/app/profile/*` | user/profile/ | -| 订单管理 | `/user/orders/*` | `/api/app/orders/*` | user/order/ | -| 评价管理 | `/user/reviews/*` | `/api/app/reviews/*` | user/review/ | -| 优惠券 | `/user/coupons/*` | `/api/app/coupons/*` | user/coupon/ | -| 入住人 | `/user/guests/*` | `/api/app/guests/*` | user/guest/ | -| 活动邀请 | `/user/activity/invite/*` | `/api/app/activity/*` | user/activity/ | -| 钱包财务 | `/user/finance/*` | `/api/app/finance/*` | user/finance/ | - -**涉及的Controller文件**: -- `user/auth/auth.controller.ts` -- `user/profile/profile.controller.ts` -- `user/order/order.controller.ts` -- `user/review/review.controller.ts` -- `user/coupon/coupon.controller.ts` -- `user/guest/guest.controller.ts` -- `user/activity/activity.controller.ts` -- `common/finance/finance-user.controller.ts` -- `common/finance/withdrawal-user.controller.ts` -- `common/coupon/coupon-user.controller.ts` - -### 3.2 商家端接口 (56个接口) - -**路由前缀**: `/api/merchant/*` - -| 模块 | 当前路由 | 新路由 | 文件位置 | -|------|---------|--------|----------| -| 商家认证 | `/merchant/auth/*` | `/api/merchant/auth/*` | merchant/auth/ | -| 商家资料 | `/merchant/profile/*` | `/api/merchant/profile/*` | merchant/profile/ | -| 房源管理 | `/merchant/rooms/*` | `/api/merchant/rooms/*` | merchant/room/ | -| 房态日历 | `/merchant/room-calendar/*` | `/api/merchant/room-calendar/*` | merchant/room-calendar/ | -| 订单管理 | `/merchant/orders/*` | `/api/merchant/orders/*` | merchant/order/ | -| 评价管理 | `/merchant/reviews/*` | `/api/merchant/reviews/*` | merchant/review/ | -| 数据统计 | `/merchant/statistics/*` | `/api/merchant/statistics/*` | merchant/statistics/ | -| 财务管理 | `/merchant/finance/*` | `/api/merchant/finance/*` | merchant/finance/ | - -**涉及的Controller文件**: -- `merchant/auth/auth.controller.ts` -- `merchant/profile/profile.controller.ts` -- `merchant/room/room.controller.ts` -- `merchant/room-calendar/room-calendar.controller.ts` -- `merchant/order/order.controller.ts` -- `merchant/review/review.controller.ts` -- `merchant/statistics/statistics.controller.ts` -- `merchant/finance/finance.controller.ts` -- `common/finance/transaction-seller.controller.ts` -- `common/finance/withdrawal-merchant.controller.ts` -- `common/finance/settlement-merchant.controller.ts` - -### 3.3 平台管理端接口 (72个接口) - -**路由前缀**: `/api/admin/*` - -| 模块 | 当前路由 | 新路由 | 文件位置 | -|------|---------|--------|----------| -| 管理员认证 | `/admin/auth/*` | `/api/admin/auth/*` | admin/auth/ | -| 用户管理 | `/admin/users/*` | `/api/admin/users/*` | admin/user/ | -| 商家管理 | `/admin/merchants/*` | `/api/admin/merchants/*` | admin/merchant/ | -| 房源管理 | `/admin/rooms/*` | `/api/admin/rooms/*` | admin/room/ | -| 订单管理 | `/admin/orders/*` | `/api/admin/orders/*` | admin/order/ | -| 评价管理 | `/admin/reviews/*` | `/api/admin/reviews/*` | admin/review/ | -| 优惠券管理 | `/admin/coupons/*` | `/api/admin/coupons/*` | admin/coupon/ | -| 活动管理 | `/admin/activity/*` | `/api/admin/activity/*` | admin/activity/ | -| 系统配置 | `/admin/config/*` | `/api/admin/config/*` | admin/config/ | -| 官网管理 | `/admin/website/info/*` | `/api/admin/website/*` | admin/website/ | -| 账户管理 | `/admin/finance/accounts/*` | `/api/admin/finance/accounts/*` | admin/finance/ | -| 交易记录 | `/admin/finance/transactions/*` | `/api/admin/finance/transactions/*` | admin/finance/ | -| 提现管理 | `/admin/finance/withdrawals/*` | `/api/admin/finance/withdrawals/*` | admin/finance/ | -| 结算管理 | `/admin/finance/settlements/*` | `/api/admin/finance/settlements/*` | admin/finance/ | -| 对账管理 | `/admin/finance/reconciliations/*` | `/api/admin/finance/reconciliations/*` | admin/finance/ | -| 财务报表 | `/admin/finance/reports/*` | `/api/admin/finance/reports/*` | admin/finance/ | - -**涉及的Controller文件**: -- `admin/auth/auth.controller.ts` -- `admin/user/user.controller.ts` -- `admin/merchant/merchant.controller.ts` -- `admin/room/room.controller.ts` -- `admin/order/order.controller.ts` -- `admin/review/review.controller.ts` -- `admin/coupon/coupon.controller.ts` -- `admin/activity/activity.controller.ts` -- `admin/config/config.controller.ts` -- `admin/website/website.controller.ts` -- `common/finance/account-admin.controller.ts` -- `common/finance/transaction-admin.controller.ts` -- `common/finance/withdrawal-admin.controller.ts` -- `common/finance/settlement-admin.controller.ts` -- `common/finance/reconciliation-admin.controller.ts` -- `common/finance/report-admin.controller.ts` -- `common/coupon/coupon-admin.controller.ts` - -### 3.4 官网接口 (12个接口) - -**路由前缀**: `/api/website/*` - -| 模块 | 当前路由 | 新路由 | 文件位置 | -|------|---------|--------|----------| -| 网站信息 | `/website/info/*` | `/api/website/info/*` | website/info/ | -| 房源展示 | `/public/rooms/*` | `/api/website/rooms/*` | website/room/ | -| 商家展示 | `/public/merchants/*` | `/api/website/merchants/*` | website/merchant/ | - -**涉及的Controller文件**: -- `website/info/info.controller.ts` -- 需要新建: `website/room/room.controller.ts` (公开房源查询) -- 需要新建: `website/merchant/merchant.controller.ts` (公开商家查询) - -## 四、执行步骤 - -### 步骤1: 重命名和移动目录 (30分钟) - -```bash -# 1. 重命名 user 为 app -cd apps/server/src/modules -mv user app - -# 2. 保持 merchant 不变 - -# 3. 保持 admin 不变 - -# 4. 保持 website 不变 - -# 5. 重命名 common 为 shared -mv common shared -``` - -### 步骤2: 移动 common 中的 controller 到对应模块 (45分钟) - -#### 2.1 移动应用端相关的 controller - -```bash -# 移动用户优惠券 -mv shared/coupon/coupon-user.controller.ts app/coupon/ -mv shared/coupon/coupon-user.service.ts app/coupon/ - -# 移动用户财务 -mv shared/finance/finance-user.controller.ts app/finance/ -mv shared/finance/withdrawal-user.controller.ts app/finance/ -``` - -#### 2.2 移动商家端相关的 controller - -```bash -# 移动商家财务 -mv shared/finance/transaction-seller.controller.ts merchant/finance/ -mv shared/finance/withdrawal-merchant.controller.ts merchant/finance/ -mv shared/finance/settlement-merchant.controller.ts merchant/finance/ -``` - -#### 2.3 移动平台管理端相关的 controller - -```bash -# 移动管理优惠券 -mv shared/coupon/coupon-admin.controller.ts admin/coupon/ - -# 移动管理财务 -mv shared/finance/account-admin.controller.ts admin/finance/ -mv shared/finance/transaction-admin.controller.ts admin/finance/ -mv shared/finance/withdrawal-admin.controller.ts admin/finance/ -mv shared/finance/settlement-admin.controller.ts admin/finance/ -mv shared/finance/reconciliation-admin.controller.ts admin/finance/ -mv shared/finance/report-admin.controller.ts admin/finance/ -``` - -### 步骤3: 修改所有 Controller 的路由前缀 (60分钟) - -使用 VS Code 全局查找替换功能 (`Ctrl+Shift+H`): - -#### 3.1 应用端路由 - -在 `apps/server/src/modules/app` 目录下: - -``` -查找: @Controller\('user/auth -替换: @Controller('api/app/auth - -查找: @Controller\('user/profile -替换: @Controller('api/app/profile - -查找: @Controller\('user/orders -替换: @Controller('api/app/orders - -查找: @Controller\('user/reviews -替换: @Controller('api/app/reviews - -查找: @Controller\('user/coupons -替换: @Controller('api/app/coupons - -查找: @Controller\('user/guests -替换: @Controller('api/app/guests - -查找: @Controller\('user/activity -替换: @Controller('api/app/activity - -查找: @Controller\('user/finance -替换: @Controller('api/app/finance - -查找: @Controller\('user -替换: @Controller('api/app -``` - -#### 3.2 商家端路由 - -在 `apps/server/src/modules/merchant` 目录下: - -``` -查找: @Controller\('merchant/auth -替换: @Controller('api/merchant/auth - -查找: @Controller\('merchant/profile -替换: @Controller('api/merchant/profile - -查找: @Controller\('merchant/rooms -替换: @Controller('api/merchant/rooms - -查找: @Controller\('merchant/room-calendar -替换: @Controller('api/merchant/room-calendar - -查找: @Controller\('merchant/orders -替换: @Controller('api/merchant/orders - -查找: @Controller\('merchant/reviews -替换: @Controller('api/merchant/reviews - -查找: @Controller\('merchant/statistics -替换: @Controller('api/merchant/statistics - -查找: @Controller\('merchant/finance -替换: @Controller('api/merchant/finance - -# 处理旧的 seller 前缀 -查找: @Controller\('seller/ -替换: @Controller('api/merchant/ -``` - -#### 3.3 平台管理端路由 - -在 `apps/server/src/modules/admin` 目录下: - -``` -查找: @Controller\('admin/ -替换: @Controller('api/admin/ -``` - -#### 3.4 官网路由 - -在 `apps/server/src/modules/website` 目录下: - -``` -查找: @Controller\('website/ -替换: @Controller('api/website/ - -查找: @Controller\('public/ -替换: @Controller('api/website/ -``` - -### 步骤4: 更新模块导入和注册 (45分钟) - -#### 4.1 更新各模块的 module.ts 文件 - -需要修改的文件: -- `app/app.module.ts` (重命名自 user.module.ts) -- `merchant/merchant.module.ts` -- `admin/admin.module.ts` -- `website/website.module.ts` - -#### 4.2 更新根模块 app.module.ts - -```typescript -import { AppModule as AppClientModule } from './modules/app/app.module'; -import { MerchantModule } from './modules/merchant/merchant.module'; -import { AdminModule } from './modules/admin/admin.module'; -import { WebsiteModule } from './modules/website/website.module'; -import { SharedModule } from './modules/shared/shared.module'; - -@Module({ - imports: [ - // ... 其他配置 - AppClientModule, - MerchantModule, - AdminModule, - WebsiteModule, - SharedModule, - ], -}) -export class AppModule {} -``` - -### 步骤5: 更新前端 API 调用路径 (90分钟) - -#### 5.1 小程序端 (apps/miniapp/src/api/) - -在整个 `apps/miniapp/src/api` 目录下执行替换: - -``` -查找: '/user/auth/ -替换: '/api/app/auth/ - -查找: '/user/profile -替换: '/api/app/profile - -查找: '/user/orders -替换: '/api/app/orders - -查找: '/user/reviews -替换: '/api/app/reviews - -查找: '/user/coupons -替换: '/api/app/coupons - -查找: '/user/guests -替换: '/api/app/guests - -查找: '/user/activity -替换: '/api/app/activity - -查找: '/user/finance -替换: '/api/app/finance - -查找: '/user -替换: '/api/app - -# 公开接口 -查找: '/public/rooms -替换: '/api/website/rooms - -查找: '/public/merchants -替换: '/api/website/merchants -``` - -#### 5.2 商家管理后台 (apps/merchant-admin/src/api/) - -在整个 `apps/merchant-admin/src/api` 目录下执行替换: - -``` -查找: '/merchant/auth/ -替换: '/api/merchant/auth/ - -查找: '/merchant/ -替换: '/api/merchant/ - -查找: '/seller/ -替换: '/api/merchant/ -``` - -#### 5.3 平台管理后台 (apps/platform-admin/src/api/) - -在整个 `apps/platform-admin/src/api` 目录下执行替换: - -``` -查找: '/admin/ -替换: '/api/admin/ -``` - -#### 5.4 官网 (apps/official-website/) - -``` -查找: '/website/ -替换: '/api/website/ - -查找: '/public/ -替换: '/api/website/ -``` - -### 步骤6: 更新 Swagger 配置 (15分钟) - -修改 `apps/server/src/main.ts`,为不同模块添加 API 标签分组: - -```typescript -const config = new DocumentBuilder() - .setTitle('酒店民宿短租预订平台 API') - .setDescription('API 文档') - .setVersion('1.0') - .addBearerAuth() - .addTag('应用端', '小程序C端用户使用的接口') - .addTag('商家端', '小程序商家端和商家管理后台使用的接口') - .addTag('平台管理端', '平台管理后台使用的接口') - .addTag('官网', '官方网站使用的接口') - .build(); -``` - -在各个 Controller 中添加对应的 `@ApiTags` 装饰器。 - -### 步骤7: 测试验证 (60分钟) - -#### 7.1 后端测试 - -```bash -# 启动后端服务 -cd apps/server -pnpm run start:dev - -# 检查控制台是否有错误 -# 访问 Swagger 文档 -# http://localhost:3000/api/docs -``` - -#### 7.2 前端测试 - -```bash -# 启动小程序 -cd apps/miniapp -pnpm run dev:mp-weixin - -# 启动商家后台 -cd apps/merchant-admin -pnpm run dev - -# 启动平台后台 -cd apps/platform-admin -pnpm run dev - -# 启动官网 -cd apps/official-website -pnpm run dev -``` - -#### 7.3 功能测试清单 - -- [ ] 应用端 - - [ ] 用户登录/注册 - - [ ] 浏览房源 - - [ ] 创建订单 - - [ ] 查看订单列表 - - [ ] 发表评价 - - [ ] 优惠券领取 - - [ ] 钱包充值/提现 - -- [ ] 商家端 - - [ ] 商家登录 - - [ ] 房源管理(增删改查) - - [ ] 订单管理 - - [ ] 数据统计 - - [ ] 财务管理 - -- [ ] 平台管理端 - - [ ] 管理员登录 - - [ ] 用户管理 - - [ ] 商家审核 - - [ ] 订单管理 - - [ ] 财务管理 - - [ ] 系统配置 - -- [ ] 官网 - - [ ] 首页展示 - - [ ] 房源浏览 - - [ ] 商家展示 - -## 五、风险控制 - -### 5.1 备份策略 - -在开始重构前,创建 Git 分支: - -```bash -git checkout -b refactor/interface-classification -git add . -git commit -m "feat: 开始接口分类重构" -``` - -### 5.2 回滚方案 - -如果出现问题,可以快速回滚: - -```bash -git checkout dev -git branch -D refactor/interface-classification -``` - -### 5.3 分阶段提交 - -建议按以下阶段提交代码: - -1. 第一次提交:目录重命名和移动 -2. 第二次提交:Controller 路由前缀修改 -3. 第三次提交:模块导入更新 -4. 第四次提交:前端 API 路径更新 -5. 第五次提交:测试通过后的最终调整 - -## 六、预计时间 - -| 步骤 | 预计时间 | 说明 | -|------|---------|------| -| 步骤1: 目录重命名移动 | 30分钟 | 使用命令行批量操作 | -| 步骤2: 移动 controller | 45分钟 | 手动移动并调整导入 | -| 步骤3: 修改路由前缀 | 60分钟 | VS Code 批量替换 | -| 步骤4: 更新模块注册 | 45分钟 | 修改 module.ts 文件 | -| 步骤5: 更新前端路径 | 90分钟 | 四个前端项目批量替换 | -| 步骤6: 更新 Swagger | 15分钟 | 添加 API 分组 | -| 步骤7: 测试验证 | 60分钟 | 全面功能测试 | -| **总计** | **5.75小时** | 约半个工作日 | - -## 七、注意事项 - -1. **路径别名**: 确保所有 `@/` 路径别名正确指向新的目录结构 -2. **导入语句**: 检查所有 import 语句是否正确 -3. **DTO 共享**: 如果有共享的 DTO,考虑放在 `shared/dto` 目录 -4. **Guard 和 Decorator**: 确保认证守卫和装饰器路径正确 -5. **测试文件**: 同步更新所有 `.spec.ts` 测试文件 -6. **环境变量**: 检查是否有硬编码的路径需要更新 -7. **文档更新**: 更新 CLAUDE.md 和其他文档中的路径说明 - -## 八、后续优化建议 - -1. **API 版本控制**: 考虑添加 `/api/v1/` 版本前缀 -2. **接口文档**: 为每个模块生成独立的 Swagger 文档 -3. **权限控制**: 基于路由前缀实现更细粒度的权限控制 -4. **监控日志**: 按模块分类记录 API 调用日志 -5. **性能优化**: 为不同端的接口设置不同的缓存策略 diff --git a/QUICK_REFACTOR.md b/QUICK_REFACTOR.md deleted file mode 100644 index e60ee02..0000000 --- a/QUICK_REFACTOR.md +++ /dev/null @@ -1,300 +0,0 @@ -# 后端模块重构 - 快速执行方案 - -## 重要提示 -由于这个重构涉及50+个文件的创建和修改,手动逐个操作非常耗时。 -建议使用以下批量操作方法快速完成。 - -## 方案一:使用 VS Code 全局查找替换(推荐) - -### 步骤1:批量修改 Controller 路由前缀 - -在 VS Code 中按 `Ctrl+Shift+H` 打开全局查找替换,在 `apps/server/src/modules` 目录下执行以下替换: - -#### 用户端路由前缀 -``` -查找: @Controller\('auth'\) -替换: @Controller('api/user/auth') -文件: **/auth/auth.controller.ts - -查找: @Controller\('user'\) -替换: @Controller('api/user/profile') -文件: **/user/profile/profile.controller.ts - -查找: @Controller\('user/guests'\) -替换: @Controller('api/user/guests') -文件: **/user/guest/guest.controller.ts - -查找: @Controller\('orders'\) -替换: @Controller('api/user/orders') -文件: **/user/order/order.controller.ts - -查找: @Controller\('reviews'\) -替换: @Controller('api/user/reviews') -文件: **/user/review/review.controller.ts - -查找: @Controller\('user/coupons'\) -替换: @Controller('api/user/coupons') -文件: **/user/coupon/coupon.controller.ts - -查找: @Controller\('user/finance'\) -替换: @Controller('api/user/finance') -文件: **/user/finance/finance.controller.ts - -查找: @Controller\('user/finance/withdrawals'\) -替换: @Controller('api/user/finance/withdrawals') -文件: **/user/finance/withdrawal.controller.ts - -查找: @Controller\('user/activity/invite'\) -替换: @Controller('api/user/activity/invite') -文件: **/user/activity/activity.controller.ts -``` - -#### 商家端路由前缀 -``` -查找: @Controller\('seller/auth'\) -替换: @Controller('api/merchant/auth') -文件: **/merchant/auth/auth.controller.ts - -查找: @Controller\('seller/merchant'\) -替换: @Controller('api/merchant/profile') -文件: **/merchant/profile/profile.controller.ts - -查找: @Controller\('seller/statistics'\) -替换: @Controller('api/merchant/statistics') -文件: **/merchant/statistics/statistics.controller.ts - -查找: @Controller\('seller/rooms'\) -替换: @Controller('api/merchant/rooms') -文件: **/merchant/room/room.controller.ts - -查找: @Controller\('seller/room-calendar'\) -替换: @Controller('api/merchant/room-calendar') -文件: **/merchant/room-calendar/room-calendar.controller.ts - -查找: @Controller\('seller/orders'\) -替换: @Controller('api/merchant/orders') -文件: **/merchant/order/order.controller.ts - -查找: @Controller\('seller/reviews'\) -替换: @Controller('api/merchant/reviews') -文件: **/merchant/review/review.controller.ts - -查找: @Controller\('merchant/finance/transactions'\) -替换: @Controller('api/merchant/finance/transactions') -文件: **/merchant/finance/transaction.controller.ts - -查找: @Controller\('merchant/finance/withdrawals'\) -替换: @Controller('api/merchant/finance/withdrawals') -文件: **/merchant/finance/withdrawal.controller.ts - -查找: @Controller\('merchant/finance/settlements'\) -替换: @Controller('api/merchant/finance/settlements') -文件: **/merchant/finance/settlement.controller.ts -``` - -#### 管理端路由前缀 -``` -查找: @Controller\('admin/auth'\) -替换: @Controller('api/admin/auth') -文件: **/admin/auth/auth.controller.ts - -查找: @Controller\('admin/users'\) -替换: @Controller('api/admin/users') -文件: **/admin/user/user.controller.ts - -查找: @Controller\('admin/merchants'\) -替换: @Controller('api/admin/merchants') -文件: **/admin/merchant/merchant.controller.ts - -查找: @Controller\('admin/rooms'\) -替换: @Controller('api/admin/rooms') -文件: **/admin/room/room.controller.ts - -查找: @Controller\('admin/orders'\) -替换: @Controller('api/admin/orders') -文件: **/admin/order/order.controller.ts - -查找: @Controller\('admin/reviews'\) -替换: @Controller('api/admin/reviews') -文件: **/admin/review/review.controller.ts - -查找: @Controller\('admin/coupons'\) -替换: @Controller('api/admin/coupons') -文件: **/admin/coupon/coupon.controller.ts - -查找: @Controller\('admin/activity'\) -替换: @Controller('api/admin/activity') -文件: **/admin/activity/activity.controller.ts - -查找: @Controller\('admin/config'\) -替换: @Controller('api/admin/config') -文件: **/admin/config/config.controller.ts - -查找: @Controller\('admin/finance/accounts'\) -替换: @Controller('api/admin/finance/accounts') -文件: **/admin/finance/account.controller.ts - -查找: @Controller\('admin/finance/transactions'\) -替换: @Controller('api/admin/finance/transactions') -文件: **/admin/finance/transaction.controller.ts - -查找: @Controller\('admin/finance/withdrawals'\) -替换: @Controller('api/admin/finance/withdrawals') -文件: **/admin/finance/withdrawal.controller.ts - -查找: @Controller\('admin/finance/settlements'\) -替换: @Controller('api/admin/finance/settlements') -文件: **/admin/finance/settlement.controller.ts - -查找: @Controller\('admin/finance/reconciliations'\) -替换: @Controller('api/admin/finance/reconciliations') -文件: **/admin/finance/reconciliation.controller.ts - -查找: @Controller\('admin/finance/reports'\) -替换: @Controller('api/admin/finance/reports') -文件: **/admin/finance/report.controller.ts -``` - -#### 公共接口路由前缀 -``` -查找: @Controller\('rooms'\) -替换: @Controller('api/public/rooms') -文件: **/shared/room/room.controller.ts - -查找: @Controller\('merchants'\) -替换: @Controller('api/public/merchants') -文件: **/shared/merchant/merchant.controller.ts - -查找: @Controller\('activity'\) -替换: @Controller('api/public/activity') -文件: **/shared/activity/activity.controller.ts -``` - -### 步骤2:修改类名避免冲突 - -在已复制的文件中,需要重命名一些类以避免冲突: - -``` -查找: export class UserService -替换: export class ProfileService -文件: **/user/profile/profile.service.ts - -查找: UserUserController -替换: ProfileController -文件: **/user/profile/profile.controller.ts - -查找: private readonly userService: UserService -替换: private readonly profileService: ProfileService -文件: **/user/profile/profile.controller.ts - -查找: this\.userService\. -替换: this.profileService. -文件: **/user/profile/profile.controller.ts -``` - -## 方案二:使用提供的完整文件 - -我已经为您准备了所有关键的模块文件,您可以直接复制使用。 - -### 关键文件列表 - -1. **用户端总模块**: `apps/server/src/modules/user/user.module.ts` -2. **商家端总模块**: `apps/server/src/modules/merchant/merchant.module.ts` -3. **管理端总模块**: `apps/server/src/modules/admin/admin.module.ts` -4. **公共模块**: `apps/server/src/modules/shared/shared.module.ts` -5. **官网模块**: `apps/server/src/modules/website/website.module.ts` -6. **根模块**: `apps/server/src/app.module.ts` -7. **官网实体**: `apps/server/src/entities/website-info.entity.ts` - -这些文件的完整代码请参考 `REFACTOR_GUIDE.md` 文档。 - -## 方案三:使用脚本批量处理 - -我已经创建了 `scripts/migrate-modules.sh` 脚本,可以批量复制和修改文件。 - -在 Git Bash 中执行: -```bash -cd d:/project/company/rent -chmod +x scripts/migrate-modules.sh -./scripts/migrate-modules.sh -``` - -## 前端 API 路径批量替换 - -### 小程序 (apps/miniapp/src/api/) - -在 `apps/miniapp/src/api` 目录下执行以下替换: - -``` -查找: '/auth/ -替换: '/api/user/auth/ - -查找: '/user/ -替换: '/api/user/profile/ - -查找: '/orders -替换: '/api/user/orders - -查找: '/reviews -替换: '/api/user/reviews - -查找: '/rooms -替换: '/api/public/rooms - -查找: '/merchants -替换: '/api/public/merchants - -查找: '/activity -替换: '/api/public/activity -``` - -### 商家后台 (apps/merchant-admin/src/api/) - -``` -查找: '/seller/auth/ -替换: '/api/merchant/auth/ - -查找: '/seller/ -替换: '/api/merchant/ - -查找: '/merchant/finance/ -替换: '/api/merchant/finance/ -``` - -### 平台后台 (apps/platform-admin/src/api/) - -``` -查找: '/admin/ -替换: '/api/admin/ -``` - -## 验证步骤 - -1. 启动后端服务:`cd apps/server && npm run start:dev` -2. 检查控制台是否有错误 -3. 访问 Swagger 文档:`http://localhost:3000/api-docs` -4. 检查所有接口路径是否正确 -5. 启动前端应用测试核心功能 - -## 回滚方案 - -如果出现问题,使用 git 回滚: -```bash -git checkout . -git clean -fd -``` - -## 预计时间 - -- 使用方案一(VS Code 批量替换):1-2小时 -- 使用方案二(复制完整文件):30分钟 -- 使用方案三(脚本自动化):10分钟 - -## 建议 - -**推荐使用方案一 + 方案二的组合**: -1. 先使用 VS Code 批量替换修改所有路由前缀(15分钟) -2. 然后创建所有模块文件(使用我提供的模板)(30分钟) -3. 最后批量替换前端 API 路径(15分钟) - -总计约1小时即可完成整个重构。 diff --git a/REFACTOR_COMPLETED.md b/REFACTOR_COMPLETED.md deleted file mode 100644 index 4990b8d..0000000 --- a/REFACTOR_COMPLETED.md +++ /dev/null @@ -1,352 +0,0 @@ -# 后端模块重构完成报告 - -## 概述 - -已成功完成后端模块的完整重构,将原有的扁平化模块结构重构为按端分组的层次化结构。 - -**重构时间**: 2026-05-14 -**涉及文件**: 150+ 个文件 -**涉及模块**: 5 个端模块,30+ 个子模块 - ---- - -## 一、新的模块结构 - -``` -apps/server/src/modules/ -├── user/ # 用户端(C端) -│ ├── auth/ # 用户认证 -│ ├── profile/ # 个人信息 -│ ├── guest/ # 入住人管理 -│ ├── order/ # 用户订单 -│ ├── review/ # 用户评价 -│ ├── coupon/ # 用户优惠券 -│ ├── finance/ # 用户财务 -│ ├── activity/ # 邀请活动 -│ └── user.module.ts # 用户端总模块 -│ -├── merchant/ # 商家端(B端) -│ ├── auth/ # 商家认证 -│ ├── profile/ # 商家信息 -│ ├── room/ # 房源管理 -│ ├── room-calendar/ # 房量房价 -│ ├── order/ # 商家订单 -│ ├── review/ # 商家评价 -│ ├── finance/ # 商家财务 -│ ├── statistics/ # 数据统计 -│ └── merchant.module.ts # 商家端总模块 -│ -├── admin/ # 平台管理端 -│ ├── auth/ # 管理员认证 -│ ├── user/ # 用户管理 -│ ├── merchant/ # 商家管理 -│ ├── room/ # 房源审核 -│ ├── order/ # 订单管理 -│ ├── review/ # 评价审核 -│ ├── coupon/ # 优惠券管理 -│ ├── activity/ # 活动管理 -│ ├── config/ # 系统配置 -│ ├── finance/ # 财务管理 -│ ├── website/ # 网站信息管理 -│ └── admin.module.ts # 管理端总模块 -│ -├── shared/ # 公共模块 -│ ├── room/ # 房源公开查询 -│ ├── merchant/ # 商家公开信息 -│ ├── activity/ # 活动公开信息 -│ ├── upload/ # 文件上传 -│ └── shared.module.ts # 公共模块总模块 -│ -└── website/ # 官网模块 - ├── info/ # 网站信息 - └── website.module.ts # 官网总模块 -``` - ---- - -## 二、路由前缀映射 - -### 用户端(User) -| 旧路由 | 新路由 | 说明 | -|--------|--------|------| -| `/auth/*` | `/api/user/auth/*` | 用户认证 | -| `/user/*` | `/api/user/profile/*` | 个人信息 | -| `/user/guests` | `/api/user/guests` | 入住人管理 | -| `/orders` | `/api/user/orders` | 用户订单 | -| `/reviews` | `/api/user/reviews` | 用户评价 | -| `/user/coupons` | `/api/user/coupons` | 用户优惠券 | -| `/user/finance` | `/api/user/finance` | 用户财务 | -| `/user/activity/invite` | `/api/user/activity/invite` | 邀请活动 | - -### 商家端(Merchant) -| 旧路由 | 新路由 | 说明 | -|--------|--------|------| -| `/seller/auth/*` | `/api/merchant/auth/*` | 商家认证 | -| `/seller/merchant` | `/api/merchant/profile` | 商家信息 | -| `/seller/statistics` | `/api/merchant/statistics` | 数据统计 | -| `/seller/rooms` | `/api/merchant/rooms` | 房源管理 | -| `/seller/room-calendar` | `/api/merchant/room-calendar` | 房量房价 | -| `/seller/orders` | `/api/merchant/orders` | 商家订单 | -| `/seller/reviews` | `/api/merchant/reviews` | 商家评价 | -| `/merchant/finance/*` | `/api/merchant/finance/*` | 商家财务 | - -### 平台管理端(Admin) -| 旧路由 | 新路由 | 说明 | -|--------|--------|------| -| `/admin/auth/*` | `/api/admin/auth/*` | 管理员认证 | -| `/admin/users` | `/api/admin/users` | 用户管理 | -| `/admin/merchants` | `/api/admin/merchants` | 商家管理 | -| `/admin/rooms` | `/api/admin/rooms` | 房源审核 | -| `/admin/orders` | `/api/admin/orders` | 订单管理 | -| `/admin/reviews` | `/api/admin/reviews` | 评价审核 | -| `/admin/coupons` | `/api/admin/coupons` | 优惠券管理 | -| `/admin/activity` | `/api/admin/activity` | 活动管理 | -| `/admin/config` | `/api/admin/config` | 系统配置 | -| `/admin/finance/*` | `/api/admin/finance/*` | 财务管理 | -| `/admin/website/info` | `/api/admin/website/info` | 网站信息 | - -### 公共接口(Public) -| 旧路由 | 新路由 | 说明 | -|--------|--------|------| -| `/rooms` | `/api/public/rooms` | 房源公开查询 | -| `/merchants` | `/api/public/merchants` | 商家公开信息 | -| `/activity` | `/api/public/activity` | 活动公开信息 | -| `/upload` | `/api/user/upload` | 用户上传 | -| `/seller/upload` | `/api/merchant/upload` | 商家上传 | -| `/admin/upload` | `/api/admin/upload` | 管理员上传 | - -### 官网接口(Website) -| 旧路由 | 新路由 | 说明 | -|--------|--------|------| -| - | `/api/website/info` | 网站信息(新增) | - ---- - -## 三、已完成的工作 - -### 1. 后端模块重构 ✅ - -#### 用户端(User) -- ✅ 创建 8 个子模块(auth, profile, guest, order, review, coupon, finance, activity) -- ✅ 更新所有 Controller 路由前缀为 `/api/user/*` -- ✅ 创建 user.module.ts 总模块 - -#### 商家端(Merchant) -- ✅ 创建 8 个子模块(auth, profile, room, room-calendar, order, review, finance, statistics) -- ✅ 更新所有 Controller 路由前缀为 `/api/merchant/*` -- ✅ 创建 merchant.module.ts 总模块 - -#### 管理端(Admin) -- ✅ 创建 11 个子模块(auth, user, merchant, room, order, review, coupon, activity, config, finance, website) -- ✅ 更新所有 Controller 路由前缀为 `/api/admin/*` -- ✅ 创建 admin.module.ts 总模块 - -#### 公共模块(Shared) -- ✅ 创建 4 个子模块(room, merchant, activity, upload) -- ✅ 更新所有 Controller 路由前缀为 `/api/public/*` 或 `/api/{role}/upload` -- ✅ 创建 shared.module.ts 总模块 - -#### 官网模块(Website) -- ✅ 创建 WebsiteInfo 实体 -- ✅ 创建 info 子模块(controller, service, module, dto) -- ✅ 公开接口:`GET /api/website/info` -- ✅ 管理接口:`GET/PUT /api/admin/website/info` -- ✅ 创建 website.module.ts 总模块 - -### 2. 根模块更新 ✅ -- ✅ 更新 app.module.ts,导入新的 5 个端模块 -- ✅ 移除旧的扁平化模块导入 - -### 3. 前端 API 路径更新 ✅ - -#### 小程序(miniapp) -- ✅ 更新 9 个 API 文件 -- ✅ 用户认证:`/auth/*` → `/api/user/auth/*` -- ✅ 个人信息:`/user/*` → `/api/user/profile/*` -- ✅ 订单评价:`/orders`, `/reviews` → `/api/user/orders`, `/api/user/reviews` -- ✅ 公共接口:`/rooms`, `/merchants`, `/activity` → `/api/public/*` - -#### 商家后台(merchant-admin) -- ✅ 更新 7 个 API 文件 -- ✅ 商家认证:`/seller/auth/*` → `/api/merchant/auth/*` -- ✅ 商家业务:`/seller/*` → `/api/merchant/*` -- ✅ 商家财务:`/merchant/finance/*` → `/api/merchant/finance/*` - -#### 平台后台(platform-admin) -- ✅ 更新 8 个 API 文件 -- ✅ 管理接口:`/admin/*` → `/api/admin/*` - ---- - -## 四、新增功能 - -### 1. 官网信息管理模块 -- **实体**: WebsiteInfo(网站信息表) -- **公开接口**: `GET /api/website/info` - 获取网站信息 -- **管理接口**: - - `GET /api/admin/website/info` - 获取网站信息 - - `PUT /api/admin/website/info` - 更新网站信息 -- **字段**: 网站名称、标题、描述、关键词、Logo、联系方式、ICP备案、版权信息、关于我们、服务协议、隐私政策等 - -### 2. 文件上传模块优化 -- 按角色分离上传接口: - - `/api/user/upload` - 用户上传(需用户认证) - - `/api/merchant/upload` - 商家上传(需商家认证) - - `/api/admin/upload` - 管理员上传(需管理员认证) - ---- - -## 五、数据库变更 - -### 新增表 -需要执行以下数据库迁移脚本创建 `website_info` 表: - -```sql -CREATE TABLE IF NOT EXISTS `website_info` ( - `id` INT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY, - `site_name` VARCHAR(100) NOT NULL COMMENT '网站名称', - `site_title` VARCHAR(200) NOT NULL COMMENT '网站标题', - `site_description` TEXT NOT NULL COMMENT '网站描述', - `site_keywords` VARCHAR(500) NOT NULL COMMENT 'SEO关键词', - `logo` VARCHAR(500) NOT NULL COMMENT 'Logo URL', - `favicon` VARCHAR(500) NOT NULL COMMENT '网站图标', - `contact_phone` VARCHAR(50) NOT NULL COMMENT '联系电话', - `contact_email` VARCHAR(100) NOT NULL COMMENT '联系邮箱', - `contact_address` VARCHAR(500) NOT NULL COMMENT '联系地址', - `icp` VARCHAR(100) NOT NULL COMMENT 'ICP备案号', - `copyright` TEXT NOT NULL COMMENT '版权信息', - `about_us` TEXT COMMENT '关于我们', - `service_agreement` TEXT COMMENT '服务协议', - `privacy_policy` TEXT COMMENT '隐私政策', - `social_links` JSON COMMENT '社交媒体链接', - `status` ENUM('active', 'inactive') DEFAULT 'active' COMMENT '状态', - `created_at` TIMESTAMP DEFAULT CURRENT_TIMESTAMP, - `updated_at` TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, - INDEX `idx_status` (`status`) -) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='网站信息表'; - --- 插入默认数据 -INSERT INTO `website_info` ( - `site_name`, `site_title`, `site_description`, `site_keywords`, - `logo`, `favicon`, `contact_phone`, `contact_email`, `contact_address`, - `icp`, `copyright`, `about_us`, `service_agreement`, `privacy_policy` -) VALUES ( - '租赁平台', '租赁平台 - 您的租赁服务专家', '提供优质的租赁服务', '租赁,房屋租赁,短租', - '', '', '400-000-0000', 'contact@example.com', '北京市朝阳区', - '京ICP备00000000号', '© 2024 租赁平台 版权所有', '关于我们的内容...', '服务协议内容...', '隐私政策内容...' -); -``` - ---- - -## 六、下一步操作 - -### 1. 数据库迁移 ⚠️ -```bash -# 执行数据库迁移脚本 -mysql -u root -p rent_platform < database/migrations/002_create_website_info.sql -``` - -### 2. 启动后端服务并测试 ⚠️ -```bash -cd apps/server -pnpm install -pnpm run start:dev -``` - -访问 Swagger 文档验证所有接口: -- http://localhost:3000/api/docs - -### 3. 测试前端应用 ⚠️ -```bash -# 启动小程序 -cd apps/miniapp -pnpm run dev:mp-weixin - -# 启动商家后台 -cd apps/merchant-admin -pnpm run dev - -# 启动平台后台 -cd apps/platform-admin -pnpm run dev -``` - -### 4. 清理旧模块(可选) -确认新模块工作正常后,可以删除以下旧模块目录: -- `apps/server/src/modules/auth/` (旧的用户认证) -- `apps/server/src/modules/seller-auth/` (旧的商家认证) -- `apps/server/src/modules/admin-auth/` (旧的管理员认证) -- `apps/server/src/modules/room/` (旧的房源模块) -- `apps/server/src/modules/room-calendar/` (旧的房量房价模块) -- `apps/server/src/modules/order/` (旧的订单模块) -- `apps/server/src/modules/review/` (旧的评价模块) -- `apps/server/src/modules/finance/` (旧的财务模块) -- `apps/server/src/modules/activity/` (旧的活动模块) -- `apps/server/src/modules/config/` (旧的配置模块) -- `apps/server/src/modules/coupon/` (旧的优惠券模块) -- `apps/server/src/modules/guest/` (旧的入住人模块) -- `apps/server/src/modules/upload/` (旧的上传模块) - ---- - -## 七、重构收益 - -### 1. 代码组织更清晰 -- 按端分组,职责明确 -- 模块层次化,易于维护 -- 新增功能时知道放在哪里 - -### 2. 路由更规范 -- 统一使用 `/api/{role}/{module}` 格式 -- 一眼就能看出接口属于哪个端 -- 便于前端团队理解和使用 - -### 3. 权限控制更明确 -- 用户端、商家端、管理端分离 -- 每个端有独立的认证和授权 -- 减少权限混乱的风险 - -### 4. 扩展性更好 -- 新增端(如供应商端)只需添加新的端模块 -- 新增功能只需在对应端下添加子模块 -- 不影响其他端的代码 - -### 5. 团队协作更高效 -- 前端团队可以按端分工 -- 后端团队可以按端分工 -- 减少代码冲突 - ---- - -## 八、注意事项 - -### 1. 兼容性 -- 旧的 API 路径已全部更新为新路径 -- 如果有外部系统调用,需要同步更新 - -### 2. 测试 -- 建议对所有核心接口进行回归测试 -- 特别关注认证、订单、支付等关键流程 - -### 3. 文档 -- Swagger 文档已自动更新 -- 建议更新项目 README 和 API 文档 - -### 4. 监控 -- 上线后密切关注错误日志 -- 关注 404 错误,可能是路径遗漏 - ---- - -## 九、联系方式 - -如有问题,请联系: -- 技术负责人:[姓名] -- 邮箱:[邮箱] -- 微信:[微信号] - ---- - -**重构完成时间**: 2026-05-14 -**文档版本**: v1.0 diff --git a/REFACTOR_GUIDE.md b/REFACTOR_GUIDE.md deleted file mode 100644 index 124967b..0000000 --- a/REFACTOR_GUIDE.md +++ /dev/null @@ -1,645 +0,0 @@ -# 后端模块重构实施指南 - -## 概述 - -本指南提供了完整的后端模块重构步骤和代码示例。重构涉及: -- 创建 50+ 个新文件 -- 修改所有 Controller 的路由前缀 -- 更新前端 API 调用路径 -- 创建新的模块组织结构 - -## 一、快速开始 - -### 方案选择 - -**方案A:手动逐步执行**(推荐,风险低) -- 按照本文档逐个模块迁移 -- 每完成一个端就测试验证 -- 适合希望完全掌控过程的团队 - -**方案B:使用自动化脚本**(快速,需要验证) -- 使用提供的 Node.js 脚本批量迁移 -- 完成后统一测试和修复 -- 适合有经验的团队 - -**方案C:AI辅助完成**(平衡) -- AI 创建关键示例和模板 -- 人工复制粘贴并调整其他模块 -- 本文档提供所有必要的模板 - -## 二、目录结构 - -``` -apps/server/src/modules/ -├── user/ # 用户端(C端) -│ ├── auth/ -│ │ ├── auth.controller.ts -│ │ ├── auth.service.ts -│ │ ├── auth.module.ts -│ │ └── dto/ -│ ├── profile/ -│ ├── guest/ -│ ├── order/ -│ ├── review/ -│ ├── coupon/ -│ ├── finance/ -│ ├── activity/ -│ └── user.module.ts # 用户端总模块 -│ -├── merchant/ # 商家端(B端) -│ ├── auth/ -│ ├── profile/ -│ ├── room/ -│ ├── room-calendar/ -│ ├── order/ -│ ├── review/ -│ ├── finance/ -│ ├── statistics/ -│ └── merchant.module.ts # 商家端总模块 -│ -├── admin/ # 平台管理端 -│ ├── auth/ -│ ├── user/ -│ ├── merchant/ -│ ├── room/ -│ ├── order/ -│ ├── review/ -│ ├── coupon/ -│ ├── activity/ -│ ├── config/ -│ ├── finance/ -│ ├── website/ -│ └── admin.module.ts # 管理端总模块 -│ -├── website/ # 官网 -│ ├── info/ -│ └── website.module.ts -│ -└── shared/ # 公共模块 - ├── room/ - ├── merchant/ - ├── activity/ - ├── upload/ - └── shared.module.ts -``` - -## 三、路由前缀映射表 - -### 用户端 -| 旧路由 | 新路由 | 说明 | -|--------|--------|------| -| `/auth/*` | `/api/user/auth/*` | 用户认证 | -| `/user/*` | `/api/user/profile/*` | 个人信息 | -| `/user/guests` | `/api/user/guests` | 入住人管理 | -| `/orders` | `/api/user/orders` | 用户订单 | -| `/reviews` | `/api/user/reviews` | 用户评价 | -| `/user/coupons` | `/api/user/coupons` | 用户优惠券 | -| `/user/finance` | `/api/user/finance` | 用户财务 | -| `/user/activity/invite` | `/api/user/activity/invite` | 邀请活动 | - -### 商家端 -| 旧路由 | 新路由 | 说明 | -|--------|--------|------| -| `/seller/auth/*` | `/api/merchant/auth/*` | 商家认证 | -| `/seller/merchant` | `/api/merchant/profile` | 商家信息 | -| `/seller/statistics` | `/api/merchant/statistics` | 数据统计 | -| `/seller/rooms` | `/api/merchant/rooms` | 房源管理 | -| `/seller/room-calendar` | `/api/merchant/room-calendar` | 房量房价 | -| `/seller/orders` | `/api/merchant/orders` | 商家订单 | -| `/seller/reviews` | `/api/merchant/reviews` | 商家评价 | -| `/merchant/finance/*` | `/api/merchant/finance/*` | 商家财务 | - -### 平台管理端 -| 旧路由 | 新路由 | 说明 | -|--------|--------|------| -| `/admin/auth/*` | `/api/admin/auth/*` | 管理员认证 | -| `/admin/users` | `/api/admin/users` | 用户管理 | -| `/admin/merchants` | `/api/admin/merchants` | 商家管理 | -| `/admin/rooms` | `/api/admin/rooms` | 房源审核 | -| `/admin/orders` | `/api/admin/orders` | 订单管理 | -| `/admin/reviews` | `/api/admin/reviews` | 评价审核 | -| `/admin/coupons` | `/api/admin/coupons` | 优惠券管理 | -| `/admin/activity` | `/api/admin/activity` | 活动管理 | -| `/admin/config` | `/api/admin/config` | 系统配置 | -| `/admin/finance/*` | `/api/admin/finance/*` | 财务管理 | - -### 公共接口 -| 旧路由 | 新路由 | 说明 | -|--------|--------|------| -| `/rooms` | `/api/public/rooms` | 房源公开查询 | -| `/merchants` | `/api/public/merchants` | 商家公开信息 | -| `/activity` | `/api/public/activity` | 活动公开信息 | -| `/upload` | `/api/user/upload` | 用户上传 | -| `/seller/upload` | `/api/merchant/upload` | 商家上传 | -| `/admin/upload` | `/api/admin/upload` | 管理员上传 | - -## 四、代码模板 - -### 1. Controller 模板(用户端认证示例) - -**文件位置**: `apps/server/src/modules/user/auth/auth.controller.ts` - -```typescript -import { Controller, Post, Body, UseGuards, Get, Req } from '@nestjs/common'; -import { ApiTags, ApiOperation, ApiBearerAuth } from '@nestjs/swagger'; -import { AuthService } from './auth.service'; -import { - LoginByPhoneDto, - LoginByPasswordDto, - RegisterDto, - SendCodeDto, - WechatLoginDto, -} from './dto/auth.dto'; -import { JwtAuthGuard } from '@/common/guards/jwt-auth.guard'; - -@ApiTags('用户认证') -@Controller('api/user/auth') // ⚠️ 关键:新的路由前缀 -export class AuthController { - constructor(private readonly authService: AuthService) {} - - @Post('send-code') - @ApiOperation({ summary: '发送验证码' }) - async sendCode(@Body() dto: SendCodeDto) { - return this.authService.sendCode(dto.phone); - } - - @Post('login/phone') - @ApiOperation({ summary: '手机号验证码登录' }) - async loginByPhone(@Body() dto: LoginByPhoneDto) { - return this.authService.loginByPhone(dto); - } - - @Post('login/password') - @ApiOperation({ summary: '账号密码登录' }) - async loginByPassword(@Body() dto: LoginByPasswordDto) { - return this.authService.loginByPassword(dto); - } - - @Post('login/wechat') - @ApiOperation({ summary: '微信授权登录' }) - async loginByWechat(@Body() dto: WechatLoginDto) { - return this.authService.loginByWechat(dto); - } - - @Post('register') - @ApiOperation({ summary: '用户注册' }) - async register(@Body() dto: RegisterDto) { - return this.authService.register(dto); - } - - @Post('refresh') - @ApiOperation({ summary: '刷新令牌' }) - async refresh(@Body('refreshToken') refreshToken: string) { - return this.authService.refresh(refreshToken); - } - - @Get('profile') - @UseGuards(JwtAuthGuard) - @ApiBearerAuth() - @ApiOperation({ summary: '获取当前用户信息' }) - async getProfile(@Req() req) { - return req.user; - } -} -``` - -### 2. Module 模板(子模块) - -**文件位置**: `apps/server/src/modules/user/auth/auth.module.ts` - -```typescript -import { Module, Global } from '@nestjs/common'; -import { JwtModule } from '@nestjs/jwt'; -import { ConfigModule, ConfigService } from '@nestjs/config'; -import { TypeOrmModule } from '@nestjs/typeorm'; -import { AuthController } from './auth.controller'; -import { AuthService } from './auth.service'; -import { User } from '@/entities/user.entity'; -import { UserAccount } from '@/entities/user-account.entity'; - -@Global() -@Module({ - imports: [ - TypeOrmModule.forFeature([User, UserAccount]), - JwtModule.registerAsync({ - imports: [ConfigModule], - useFactory: (configService: ConfigService) => ({ - secret: configService.get('jwt.secret') || 'dev_secret_key', - signOptions: { - expiresIn: configService.get('jwt.expiresIn') || '7d', - }, - }), - inject: [ConfigService], - }), - ], - controllers: [AuthController], - providers: [AuthService], - exports: [AuthService, JwtModule], -}) -export class UserAuthModule {} // ⚠️ 重命名避免冲突 -``` - -### 3. 端总模块模板 - -**文件位置**: `apps/server/src/modules/user/user.module.ts` - -```typescript -import { Module } from '@nestjs/common'; -import { UserAuthModule } from './auth/auth.module'; -import { UserProfileModule } from './profile/profile.module'; -import { UserGuestModule } from './guest/guest.module'; -import { UserOrderModule } from './order/order.module'; -import { UserReviewModule } from './review/review.module'; -import { UserCouponModule } from './coupon/coupon.module'; -import { UserFinanceModule } from './finance/finance.module'; -import { UserActivityModule } from './activity/activity.module'; - -@Module({ - imports: [ - UserAuthModule, - UserProfileModule, - UserGuestModule, - UserOrderModule, - UserReviewModule, - UserCouponModule, - UserFinanceModule, - UserActivityModule, - ], -}) -export class UserModule {} -``` - -### 4. 根模块更新 - -**文件位置**: `apps/server/src/app.module.ts` - -```typescript -import { Module } from '@nestjs/common'; -import { ConfigModule } from '@nestjs/config'; -import { TypeOrmModule } from '@nestjs/typeorm'; -import { UserModule } from './modules/user/user.module'; -import { MerchantModule } from './modules/merchant/merchant.module'; -import { AdminModule } from './modules/admin/admin.module'; -import { WebsiteModule } from './modules/website/website.module'; -import { SharedModule } from './modules/shared/shared.module'; -// ... 其他导入 - -@Module({ - imports: [ - ConfigModule.forRoot(/* ... */), - TypeOrmModule.forRoot(/* ... */), - UserModule, // 用户端 - MerchantModule, // 商家端 - AdminModule, // 管理端 - WebsiteModule, // 官网 - SharedModule, // 公共模块 - // 删除旧的模块导入 - ], -}) -export class AppModule {} -``` - -## 五、前端 API 路径更新 - -### 小程序 (miniapp) - -**文件**: `apps/miniapp/src/api/auth.ts` - -```typescript -// 旧代码 -export function login(data: any) { - return request.post('/auth/login/phone', data); -} - -// 新代码 -export function login(data: any) { - return request.post('/api/user/auth/login/phone', data); -} -``` - -### 批量替换规则(使用 VS Code 全局搜索替换) - -**用户端接口**: -- 搜索: `'/auth/` -- 替换: `'/api/user/auth/` - -- 搜索: `'/user/` -- 替换: `'/api/user/profile/` - -- 搜索: `'/orders` -- 替换: `'/api/user/orders` - -**商家端接口**: -- 搜索: `'/seller/auth/` -- 替换: `'/api/merchant/auth/` - -- 搜索: `'/seller/` -- 替换: `'/api/merchant/` - -- 搜索: `'/merchant/finance/` -- 替换: `'/api/merchant/finance/` - -**管理端接口**: -- 搜索: `'/admin/` -- 替换: `'/api/admin/` - -**公共接口**: -- 搜索: `'/rooms` -- 替换: `'/api/public/rooms` - -- 搜索: `'/merchants` -- 替换: `'/api/public/merchants` - -## 六、官网模块实现 - -### 1. 创建 WebsiteInfo 实体 - -**文件**: `apps/server/src/entities/website-info.entity.ts` - -```typescript -import { - Entity, - PrimaryGeneratedColumn, - Column, - CreateDateColumn, - UpdateDateColumn, -} from 'typeorm'; - -@Entity('website_info') -export class WebsiteInfo { - @PrimaryGeneratedColumn() - id: number; - - @Column({ name: 'site_name', length: 100 }) - siteName: string; - - @Column({ name: 'site_title', length: 200 }) - siteTitle: string; - - @Column({ name: 'site_description', type: 'text' }) - siteDescription: string; - - @Column({ name: 'site_keywords', length: 500 }) - siteKeywords: string; - - @Column({ length: 500 }) - logo: string; - - @Column({ length: 500 }) - favicon: string; - - @Column({ name: 'contact_phone', length: 50 }) - contactPhone: string; - - @Column({ name: 'contact_email', length: 100 }) - contactEmail: string; - - @Column({ name: 'contact_address', length: 500 }) - contactAddress: string; - - @Column({ length: 100 }) - icp: string; - - @Column({ type: 'text' }) - copyright: string; - - @Column({ name: 'about_us', type: 'text' }) - aboutUs: string; - - @Column({ name: 'service_agreement', type: 'text' }) - serviceAgreement: string; - - @Column({ name: 'privacy_policy', type: 'text' }) - privacyPolicy: string; - - @Column({ name: 'social_links', type: 'json', nullable: true }) - socialLinks: Record; - - @Column({ - type: 'enum', - enum: ['active', 'inactive'], - default: 'active', - }) - status: 'active' | 'inactive'; - - @CreateDateColumn({ name: 'created_at' }) - createdAt: Date; - - @UpdateDateColumn({ name: 'updated_at' }) - updatedAt: Date; -} -``` - -### 2. 数据库迁移脚本 - -**文件**: `database/migrations/002_create_website_info.sql` - -```sql -CREATE TABLE IF NOT EXISTS `website_info` ( - `id` INT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY, - `site_name` VARCHAR(100) NOT NULL COMMENT '网站名称', - `site_title` VARCHAR(200) NOT NULL COMMENT '网站标题', - `site_description` TEXT NOT NULL COMMENT '网站描述', - `site_keywords` VARCHAR(500) NOT NULL COMMENT 'SEO关键词', - `logo` VARCHAR(500) NOT NULL COMMENT 'Logo URL', - `favicon` VARCHAR(500) NOT NULL COMMENT '网站图标', - `contact_phone` VARCHAR(50) NOT NULL COMMENT '联系电话', - `contact_email` VARCHAR(100) NOT NULL COMMENT '联系邮箱', - `contact_address` VARCHAR(500) NOT NULL COMMENT '联系地址', - `icp` VARCHAR(100) NOT NULL COMMENT 'ICP备案号', - `copyright` TEXT NOT NULL COMMENT '版权信息', - `about_us` TEXT COMMENT '关于我们', - `service_agreement` TEXT COMMENT '服务协议', - `privacy_policy` TEXT COMMENT '隐私政策', - `social_links` JSON COMMENT '社交媒体链接', - `status` ENUM('active', 'inactive') DEFAULT 'active' COMMENT '状态', - `created_at` TIMESTAMP DEFAULT CURRENT_TIMESTAMP, - `updated_at` TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, - INDEX `idx_status` (`status`) -) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='网站信息表'; - --- 插入默认数据 -INSERT INTO `website_info` ( - `site_name`, `site_title`, `site_description`, `site_keywords`, - `logo`, `favicon`, `contact_phone`, `contact_email`, `contact_address`, - `icp`, `copyright`, `about_us`, `service_agreement`, `privacy_policy` -) VALUES ( - '租赁平台', '租赁平台 - 您的租赁服务专家', '提供优质的租赁服务', '租赁,房屋租赁,短租', - '', '', '400-000-0000', 'contact@example.com', '北京市朝阳区', - '京ICP备00000000号', '© 2024 租赁平台 版权所有', '关于我们的内容...', '服务协议内容...', '隐私政策内容...' -); -``` - -### 3. WebsiteInfo Service - -**文件**: `apps/server/src/modules/website/info/info.service.ts` - -```typescript -import { Injectable } from '@nestjs/common'; -import { InjectRepository } from '@nestjs/typeorm'; -import { Repository } from 'typeorm'; -import { WebsiteInfo } from '@/entities/website-info.entity'; - -@Injectable() -export class WebsiteInfoService { - constructor( - @InjectRepository(WebsiteInfo) - private websiteInfoRepo: Repository, - ) {} - - async getInfo(): Promise { - // 获取第一条记录(通常只有一条) - const info = await this.websiteInfoRepo.findOne({ - where: { status: 'active' }, - order: { id: 'ASC' }, - }); - - if (!info) { - throw new Error('网站信息未配置'); - } - - return info; - } - - async updateInfo(data: Partial): Promise { - const info = await this.getInfo(); - Object.assign(info, data); - return this.websiteInfoRepo.save(info); - } -} -``` - -### 4. WebsiteInfo Controller(公开接口) - -**文件**: `apps/server/src/modules/website/info/info.controller.ts` - -```typescript -import { Controller, Get } from '@nestjs/common'; -import { ApiTags, ApiOperation } from '@nestjs/swagger'; -import { WebsiteInfoService } from './info.service'; - -@ApiTags('网站信息') -@Controller('api/website/info') -export class WebsiteInfoController { - constructor(private readonly websiteInfoService: WebsiteInfoService) {} - - @Get() - @ApiOperation({ summary: '获取网站信息' }) - async getInfo() { - return this.websiteInfoService.getInfo(); - } -} -``` - -### 5. WebsiteInfo 管理接口 - -**文件**: `apps/server/src/modules/admin/website/website.controller.ts` - -```typescript -import { Controller, Put, Body, UseGuards } from '@nestjs/common'; -import { ApiTags, ApiOperation, ApiBearerAuth } from '@nestjs/swagger'; -import { JwtAuthGuard } from '@/common/guards/jwt-auth.guard'; -import { RolesGuard } from '@/common/guards/roles.guard'; -import { Roles } from '@/common/decorators/roles.decorator'; -import { WebsiteInfoService } from '@/modules/website/info/info.service'; - -@ApiTags('网站管理') -@Controller('api/admin/website/info') -@UseGuards(JwtAuthGuard, RolesGuard) -@Roles('admin') -@ApiBearerAuth() -export class AdminWebsiteController { - constructor(private readonly websiteInfoService: WebsiteInfoService) {} - - @Put() - @ApiOperation({ summary: '更新网站信息' }) - async updateInfo(@Body() data: any) { - return this.websiteInfoService.updateInfo(data); - } -} -``` - -## 七、执行步骤 - -### 步骤1:创建目录结构 -```bash -cd d:/project/company/rent/apps/server/src/modules -mkdir -p user/{auth,profile,guest,order,review,coupon,finance,activity} -mkdir -p merchant/{auth,profile,room,room-calendar,order,review,finance,statistics} -mkdir -p admin/{auth,user,merchant,room,order,review,coupon,activity,config,finance,website} -mkdir -p website/info -mkdir -p shared/{room,merchant,activity,upload} -``` - -### 步骤2:复制并修改文件 -对于每个模块: -1. 复制原文件到新位置 -2. 修改 Controller 的 `@Controller()` 装饰器路由前缀 -3. 如果是 Module 文件,重命名类名避免冲突(如 `AuthModule` → `UserAuthModule`) -4. 复制 Service 和 DTO 文件(通常不需要修改) - -### 步骤3:创建端总模块 -为每个端创建总模块文件(user.module.ts, merchant.module.ts, admin.module.ts等) - -### 步骤4:更新 app.module.ts -导入新的四个端模块,删除旧模块导入 - -### 步骤5:创建官网模块 -1. 创建 WebsiteInfo 实体 -2. 运行数据库迁移 -3. 创建 Service、Controller -4. 创建管理接口 - -### 步骤6:更新前端 API 路径 -使用 VS Code 全局搜索替换,按照第五节的规则批量替换 - -### 步骤7:测试验证 -1. 启动后端服务 -2. 检查 Swagger 文档 -3. 测试各端的核心接口 -4. 启动三个前端应用测试 - -### 步骤8:清理旧模块 -确认新模块工作正常后,删除旧的模块文件 - -## 八、常见问题 - -### Q1: 模块导入路径错误 -**问题**: Service 或 Entity 导入路径找不到 -**解决**: 使用绝对路径 `@/entities/...` 或 `@/modules/...` - -### Q2: 模块名称冲突 -**问题**: 多个模块都叫 `AuthModule` -**解决**: 重命名为 `UserAuthModule`, `MerchantAuthModule`, `AdminAuthModule` - -### Q3: 前端接口404 -**问题**: 前端调用新接口返回404 -**解决**: 检查是否遗漏了某些路径的替换,特别注意动态路径 - -### Q4: Guards 不生效 -**问题**: 认证守卫没有正确应用 -**解决**: 确保 JwtModule 在对应的 Auth Module 中正确导出 - -## 九、验证清单 - -- [ ] 后端服务启动无错误 -- [ ] Swagger 文档显示所有新接口 -- [ ] 用户端接口测试通过(登录、下单、支付等) -- [ ] 商家端接口测试通过(登录、房源管理、订单处理等) -- [ ] 管理端接口测试通过(登录、审核、财务管理等) -- [ ] 公共接口测试通过(房源列表、商家列表等) -- [ ] 官网接口测试通过(获取网站信息) -- [ ] 小程序正常运行 -- [ ] 商家后台正常运行 -- [ ] 平台后台正常运行 -- [ ] 旧模块已删除 -- [ ] 代码已提交到版本控制 - -## 十、回滚方案 - -如果重构出现问题需要回滚: -1. 使用 git 恢复到重构前的提交 -2. 或者保留旧模块,在 app.module.ts 中切换回旧模块 -3. 前端恢复旧的 API 路径 - -建议:在开始重构前创建一个 git 分支,确保可以随时回滚。 diff --git a/REFACTOR_SUCCESS.md b/REFACTOR_SUCCESS.md deleted file mode 100644 index 4a04bf2..0000000 --- a/REFACTOR_SUCCESS.md +++ /dev/null @@ -1,327 +0,0 @@ -# 🎉 后端模块重构成功完成 - -## 完成时间 -**2026-05-14 14:30** - -## 重构概览 - -✅ **所有编译错误已修复** -✅ **125个新模块文件已创建** -✅ **24个前端API文件已更新** -✅ **5个端模块结构已完成** - ---- - -## 一、模块结构 - -### 新的目录组织 - -``` -apps/server/src/modules/ -├── user/ # 用户端(8个子模块) -├── merchant/ # 商家端(8个子模块) -├── admin/ # 管理端(11个子模块) -├── shared/ # 公共模块(4个子模块) -└── website/ # 官网模块(1个子模块) -``` - -### 路由前缀统一 - -所有API路由已统一为 `/api/{role}/{module}` 格式: - -- **用户端**: `/api/user/*` -- **商家端**: `/api/merchant/*` -- **管理端**: `/api/admin/*` -- **公共接口**: `/api/public/*` -- **官网接口**: `/api/website/*` - ---- - -## 二、已修复的问题 - -### 1. 类型导入错误 ✅ -- 修复了 `Type` 从 `class-validator` 导入的错误 -- 正确改为从 `class-transformer` 导入 - -### 2. 实体别名映射 ✅ -所有实体文件都已正确映射: -- `FinAccount` → `Account` -- `FinTransaction` → `Transaction` -- `FinWithdrawal` → `Withdrawal` -- `FinSettlement` → `Settlement` -- `FinReconciliation` → `Reconciliation` -- `SystemConfig` → `PlatformConfig` -- `InviteActivity` → `MktActivity` -- `InviteRecord` → `MktUserInviteStats` -- `InviteCashback` → `MktInviteWithdrawal` - -### 3. 服务和DTO文件 ✅ -所有服务和DTO文件都已正确创建或复用: -- 用户端服务:activity, coupon, finance, order, review -- 商家端服务:auth, profile, room, order, review, finance, statistics -- 管理端服务:auth, user, merchant, room, order, review, coupon, activity, config, finance, website - -### 4. 导入路径修复 ✅ -- `admin/config/dto/config.dto.ts` - 使用相对路径 -- `admin/website/dto/website.dto.ts` - 使用相对路径 -- `user/guest/guest.service.ts` - 使用别名路径 - -### 5. 业务逻辑修复 ✅ -- `admin/review/review.service.ts` - 使用正确的状态值(visible/hidden) -- `admin/room/room.service.ts` - 使用正确的字段名(auditRejectReason) -- `merchant/finance/finance.controller.ts` - 正确处理null值 - ---- - -## 三、前端API路径更新 - -### 小程序(9个文件) -- ✅ auth.ts - `/auth/*` → `/api/user/auth/*` -- ✅ guest.ts - `/user/guests` → `/api/user/guests` -- ✅ coupon.ts - `/user/coupons` → `/api/user/coupons` -- ✅ wallet.ts - `/user/finance/*` → `/api/user/finance/*` -- ✅ invite.ts - `/user/activity/*` → `/api/user/activity/*` -- ✅ order.ts - `/orders` → `/api/user/orders` -- ✅ review.ts - `/reviews` → `/api/user/reviews` -- ✅ room.ts - `/rooms` → `/api/public/rooms` -- ✅ merchant.ts - `/merchants` → `/api/public/merchants` - -### 商家后台(7个文件) -- ✅ auth.ts - `/seller/auth/*` → `/api/merchant/auth/*` -- ✅ statistics.ts - `/seller/statistics` → `/api/merchant/statistics` -- ✅ room.ts - `/seller/rooms` → `/api/merchant/rooms` -- ✅ room-calendar.ts - `/seller/room-calendar` → `/api/merchant/room-calendar` -- ✅ order.ts - `/seller/orders` → `/api/merchant/orders` -- ✅ review.ts - `/seller/reviews` → `/api/merchant/reviews` -- ✅ finance.ts - `/merchant/finance/*` → `/api/merchant/finance/*` - -### 平台后台(8个文件) -- ✅ admin.ts - `/admin/*` → `/api/admin/*` -- ✅ finance.ts - `/admin/finance/*` → `/api/admin/finance/*` -- ✅ order.ts - `/admin/orders` → `/api/admin/orders` -- ✅ coupon.ts - `/admin/coupons` → `/api/admin/coupons` -- ✅ invite.ts - `/admin/activity` → `/api/admin/activity` -- ✅ room.ts - `/admin/rooms` → `/api/admin/rooms` -- ✅ config.ts - `/admin/config` → `/api/admin/config` -- ✅ review.ts - `/admin/reviews` → `/api/admin/reviews` - ---- - -## 四、下一步操作 - -### 1. 数据库迁移 ⚠️ - -执行以下SQL创建 `website_info` 表: - -```bash -mysql -u root -p rent_platform < database/migrations/002_create_website_info.sql -``` - -或手动执行: - -```sql -CREATE TABLE IF NOT EXISTS `website_info` ( - `id` INT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY, - `site_name` VARCHAR(100) NOT NULL COMMENT '网站名称', - `site_title` VARCHAR(200) NOT NULL COMMENT '网站标题', - `site_description` TEXT NOT NULL COMMENT '网站描述', - `site_keywords` VARCHAR(500) NOT NULL COMMENT 'SEO关键词', - `logo` VARCHAR(500) NOT NULL COMMENT 'Logo URL', - `favicon` VARCHAR(500) NOT NULL COMMENT '网站图标', - `contact_phone` VARCHAR(50) NOT NULL COMMENT '联系电话', - `contact_email` VARCHAR(100) NOT NULL COMMENT '联系邮箱', - `contact_address` VARCHAR(500) NOT NULL COMMENT '联系地址', - `icp` VARCHAR(100) NOT NULL COMMENT 'ICP备案号', - `copyright` TEXT NOT NULL COMMENT '版权信息', - `about_us` TEXT COMMENT '关于我们', - `service_agreement` TEXT COMMENT '服务协议', - `privacy_policy` TEXT COMMENT '隐私政策', - `social_links` JSON COMMENT '社交媒体链接', - `status` ENUM('active', 'inactive') DEFAULT 'active' COMMENT '状态', - `created_at` TIMESTAMP DEFAULT CURRENT_TIMESTAMP, - `updated_at` TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, - INDEX `idx_status` (`status`) -) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='网站信息表'; - -INSERT INTO `website_info` ( - `site_name`, `site_title`, `site_description`, `site_keywords`, - `logo`, `favicon`, `contact_phone`, `contact_email`, `contact_address`, - `icp`, `copyright`, `about_us`, `service_agreement`, `privacy_policy` -) VALUES ( - '租赁平台', '租赁平台 - 您的租赁服务专家', '提供优质的租赁服务', '租赁,房屋租赁,短租', - '', '', '400-000-0000', 'contact@example.com', '北京市朝阳区', - '京ICP备00000000号', '© 2024 租赁平台 版权所有', '关于我们的内容...', '服务协议内容...', '隐私政策内容...' -); -``` - -### 2. 启动后端服务 ⚠️ - -```bash -cd apps/server -pnpm install -pnpm run start:dev -``` - -访问 Swagger 文档验证: -- http://localhost:3000/api/docs - -### 3. 测试前端应用 ⚠️ - -```bash -# 小程序 -cd apps/miniapp -pnpm run dev:mp-weixin - -# 商家后台 -cd apps/merchant-admin -pnpm run dev - -# 平台后台 -cd apps/platform-admin -pnpm run dev -``` - -### 4. 清理旧模块(可选) - -确认新模块工作正常后,可以删除以下旧模块: - -```bash -# 备份后删除 -rm -rf apps/server/src/modules/auth -rm -rf apps/server/src/modules/seller-auth -rm -rf apps/server/src/modules/admin-auth -rm -rf apps/server/src/modules/room -rm -rf apps/server/src/modules/room-calendar -rm -rf apps/server/src/modules/order -rm -rf apps/server/src/modules/review -rm -rf apps/server/src/modules/finance -rm -rf apps/server/src/modules/activity -rm -rf apps/server/src/modules/config -rm -rf apps/server/src/modules/coupon -rm -rf apps/server/src/modules/guest -rm -rf apps/server/src/modules/upload -``` - ---- - -## 五、验证清单 - -### 后端验证 -- [ ] 后端服务启动无错误 -- [ ] Swagger 文档显示所有新接口 -- [ ] 用户端接口测试通过(登录、下单、支付等) -- [ ] 商家端接口测试通过(登录、房源管理、订单处理等) -- [ ] 管理端接口测试通过(登录、审核、财务管理等) -- [ ] 公共接口测试通过(房源列表、商家列表等) -- [ ] 官网接口测试通过(获取网站信息) - -### 前端验证 -- [ ] 小程序正常运行 -- [ ] 商家后台正常运行 -- [ ] 平台后台正常运行 -- [ ] 所有核心功能正常(登录、下单、支付、审核等) - -### 代码质量 -- [ ] TypeScript 编译无错误 ✅ -- [ ] ESLint 检查通过 -- [ ] 单元测试通过 -- [ ] 代码已提交到版本控制 - ---- - -## 六、重构收益 - -### 1. 代码组织更清晰 -- 按端分组,职责明确 -- 模块层次化,易于维护 -- 新增功能时知道放在哪里 - -### 2. 路由更规范 -- 统一使用 `/api/{role}/{module}` 格式 -- 一眼就能看出接口属于哪个端 -- 便于前端团队理解和使用 - -### 3. 权限控制更明确 -- 用户端、商家端、管理端分离 -- 每个端有独立的认证和授权 -- 减少权限混乱的风险 - -### 4. 扩展性更好 -- 新增端(如供应商端)只需添加新的端模块 -- 新增功能只需在对应端下添加子模块 -- 不影响其他端的代码 - -### 5. 团队协作更高效 -- 前端团队可以按端分工 -- 后端团队可以按端分工 -- 减少代码冲突 - ---- - -## 七、技术细节 - -### 模块导入关系 - -```typescript -// app.module.ts -@Module({ - imports: [ - UserModule, // 用户端总模块 - MerchantModule, // 商家端总模块 - AdminModule, // 管理端总模块 - SharedModule, // 公共模块总模块 - WebsiteModule, // 官网总模块 - ], -}) -export class AppModule {} -``` - -### 路由前缀示例 - -```typescript -// 用户端 -@Controller('api/user/auth') // 用户认证 -@Controller('api/user/profile') // 个人信息 -@Controller('api/user/orders') // 用户订单 - -// 商家端 -@Controller('api/merchant/auth') // 商家认证 -@Controller('api/merchant/rooms') // 房源管理 -@Controller('api/merchant/orders') // 商家订单 - -// 管理端 -@Controller('api/admin/auth') // 管理员认证 -@Controller('api/admin/users') // 用户管理 -@Controller('api/admin/merchants') // 商家管理 - -// 公共接口 -@Controller('api/public/rooms') // 房源公开查询 -@Controller('api/public/merchants') // 商家公开信息 - -// 官网接口 -@Controller('api/website/info') // 网站信息 -``` - ---- - -## 八、相关文档 - -- [REFACTOR_GUIDE.md](./REFACTOR_GUIDE.md) - 详细的重构实施指南 -- [REFACTOR_COMPLETED.md](./REFACTOR_COMPLETED.md) - 完整的重构报告 -- [QUICK_REFACTOR.md](./QUICK_REFACTOR.md) - 快速执行方案 -- [CLAUDE.md](./CLAUDE.md) - 项目指引 - ---- - -## 九、注意事项 - -1. **兼容性**: 旧的API路径已全部更新,如有外部系统调用需同步更新 -2. **测试**: 建议对所有核心接口进行回归测试 -3. **文档**: Swagger文档已自动更新 -4. **监控**: 上线后密切关注错误日志,特别是404错误 - ---- - -**重构完成**: 2026-05-14 14:30 -**编译状态**: ✅ 无错误 -**文档版本**: v1.0 diff --git a/apps/miniapp/.env.development b/apps/miniapp/.env.development index df40726..2d5bdc8 100644 --- a/apps/miniapp/.env.development +++ b/apps/miniapp/.env.development @@ -3,4 +3,4 @@ VITE_H5_API_BASE_URL=http://localhost:3000 # 小程序开发环境接口(真机调试使用局域网IP) -VITE_MP_API_BASE_URL=http://192.168.0.111:3000 +VITE_MP_API_BASE_URL=http://localhost:3000 diff --git a/apps/miniapp/src/api/user/wallet.ts b/apps/miniapp/src/api/user/wallet.ts index bcbc66b..7f0bfb0 100644 --- a/apps/miniapp/src/api/user/wallet.ts +++ b/apps/miniapp/src/api/user/wallet.ts @@ -15,7 +15,7 @@ export interface Withdrawal { accountType: 'alipay' | 'wechat'; accountName: string; accountNumber: string; - status: 'pending' | 'processing' | 'completed' | 'rejected'; + status: 'pending' | 'approved' | 'rejected' | 'paid'; remark?: string; processedAt?: string; createdAt: string; @@ -49,10 +49,18 @@ export const walletApi = { page?: number; pageSize?: number; }) { - return request<{ items: Withdrawal[]; total: number }>({ - url: '/api/app/finance/withdrawals', + // 构建查询字符串 + const query = new URLSearchParams(); + if (params?.status) query.append('status', params.status); + if (params?.page) query.append('page', params.page.toString()); + if (params?.pageSize) query.append('pageSize', params.pageSize.toString()); + + const queryString = query.toString(); + const url = queryString ? `/api/app/finance/withdrawals?${queryString}` : '/api/app/finance/withdrawals'; + + return request<{ list: Withdrawal[]; total: number }>({ + url, method: 'GET', - data: params, }); }, }; diff --git a/apps/miniapp/src/components/CityPicker.vue b/apps/miniapp/src/components/CityPicker.vue index 5b71a7f..b22c946 100644 --- a/apps/miniapp/src/components/CityPicker.vue +++ b/apps/miniapp/src/components/CityPicker.vue @@ -10,7 +10,7 @@ - 📍 + 当前定位 @@ -34,8 +34,13 @@ - - + + {{ group.letter }} + + + + + {{ group.letter }} + +