13 Commits

Author SHA1 Message Date
yuzhiran 310176a11b chore: production cleanup - remove debug logs, add DB cleanup script
- App.vue: remove console.log on launch/show/hide, drop unused onShow/onHide imports
- interview.vue: remove verbose console.log('[ASR] upload response')
- login.vue: remove debug console.log('[wxLogin]') logs (keep error logs)
- scripts/cleanup-test-data.ts: new script to identify and remove test data
  while preserving admin accounts; supports --dry-run preview mode
- All 43 backend tests pass
2026-06-20 23:08:44 +08:00
yuzhiran ef4d22a633 feat(admin): enrich admin panel fields; add user index constraint and customer service
- admin controller: add updatedAt to interview/resume selects; add orderCount,
  todayOrders, totalRevenue to overview
- admin.vue: enrich all tabs with more fields
  - overview: order cards (count, revenue)
  - users: wxOpenid, email, createdAt, interviewCount, vipExpireAt, role badge
  - interviews: user email, updatedAt, summary preview
  - orders: title, type, channel, paidAt, wxTransactionId, refund info
  - resumes: user email, updatedAt
  - share: sharer phone, shareCode, isActive, visitorId(IP), creditedAt
  - admins: email, createdAt
- user.schema: add unique indexes on phone/wxOpenid/email; pre-save hook
  requiring at least one contact method
- user/about: add WeChat contact button (open-type=contact) for customer service
2026-06-20 22:38:33 +08:00
yuzhiran 8ee27fdd32 feat: refactor member to pay-per-use gravity purchase; mv webview to clipboard+browser
- member.vue: rewrite from subscription plans (free/growth/sprint) to
  H5-only pay-per-use gravity purchase with quantity selector + QR code
- user.vue: gravity card replacing quota card, add share/contribute/H5-buy
  entry points, plus gravity acquisition modal (share/contribute/buy)
- share.vue: layout fix (flex column), smarter copyLink with cached URL,
  WeChat timeline hint instead of open-type
- share.controller.ts: add GET /:shareCode redirect route (IP record + 302)
- interview.vue: guest mode fix, H5 buy modal, clipboard copy instead of
  webview for mini-program
- App.vue: handleH5UrlParams for ?token=&buy=gravity auto-login
- composables/useGravityPurchase.ts: reusable gravity purchase composable
- remove webview.vue (no longer used), replace with clipboard+browser flow
- AGENTS.md: sync all above changes, fix duplicate numbering
2026-06-20 20:49:15 +08:00
yuzhiran a1e1f0b3c3 docs: update project status to v4.6 - gravity unification, admin panel improvements 2026-06-19 22:52:57 +08:00
yuzhiran 2fbab1072f feat: unified gravity system - VIP members consume gravity instead of unlimited; add monthly gravity top-up cron 2026-06-19 22:43:52 +08:00
yuzhiran c2ba810a02 fix: use onShow lifecycle to refresh login state in member center
1. member.vue: added onShow to refresh login state when returning from login page

2. manifest.json: bump to v1.0.15

Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-openagent)

Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai>
2026-06-18 21:23:20 +08:00
yuzhiran 3f1239c35e fix: add network error detection and timeout for mini program JSAPI payment
1. member.vue: check for res.statusCode === 0 (network failure) before accessing data, add 30s timeout

2. manifest.json: bump to v1.0.14

Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-openagent)

Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai>
2026-06-18 20:54:42 +08:00
yuzhiran 1be5b34906 chore: bump version to 1.0.13
Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-openagent)

Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai>
2026-06-18 20:39:56 +08:00
yuzhiran c58bb27575 fix: admin page reactive import + member payment toast show real error
1. admin.vue: 添加缺失的reactive导入,修复管理后台只显示标题不显示功能的问题

2. member.vue: 支付失败toast改为显示后端真实错误信息,而非硬编码'创建订单失败'

Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-openagent)

Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai>
2026-06-18 20:39:49 +08:00
yuzhiran e0de29fdd0 fix: AI LLM backup model not producing content; add retry for thinking models
- Replace backup model stepfun-ai/step-3.5-flash with meta/llama-3.1-8b-instruct
  (stepfun is a thinking model that uses all tokens on reasoning and
  never outputs content, causing all 3 fallthroughs to fail)
- Add retry with doubled max_tokens when primary model returns empty
  content (deepseek-v4-flash thinking can exhaust token budget)
- Increase backup timeout to 120s and max_tokens to min 2048
- Move callApi error handling to return null instead of throw for
  cleaner fallthrough logic with timeout logging
2026-06-18 19:42:40 +08:00
yuzhiran 6a3cc8544e fix: handle WeChat Pay public key mode in callback
- verifyAndDecrypt now processes decryption even when signature
  verification fails (decryption key is separate from signature key)
- Notify handler uses returnRaw flag to always decrypt resource
- Loud log when pub_key.pem verification fails, directs admin
  to download correct public key from merchant platform
2026-06-18 19:36:19 +08:00
yuzhiran c161ffbc3c feat: payment refund support + admin payment management
- Add refund()/queryRefund()/downloadPlatformCerts() to WechatPayService
- Add refundId field to PaymentOrder schema
- Fix WeChat Pay callback to auto-download platform certs on verification failure
- Fix syncOrder to handle sprint plan properly
- Add admin refund, refund-query, order-detail endpoints
- Add refund UI (button, modal, query) to admin.vue orders tab
- Fix member.vue MP payment: pass outTradeNo instead of prepayId to pollPayResult
2026-06-18 19:33:10 +08:00
yuzhiran 7e1bf669ab fix: show toast when clicking login without agreeing to privacy terms
Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-openagent)

Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai>
2026-06-18 18:54:44 +08:00
33 changed files with 1926 additions and 625 deletions
@@ -1,10 +1,10 @@
{
"sessionID": "ses_15492f54bffepl01q9FkaRyN28",
"updatedAt": "2026-06-16T01:20:56.855Z",
"updatedAt": "2026-06-19T07:14:26.627Z",
"sources": {
"background-task": {
"state": "idle",
"updatedAt": "2026-06-16T01:20:56.855Z"
"updatedAt": "2026-06-19T07:14:26.627Z"
}
}
}
+32 -18
View File
@@ -21,9 +21,10 @@ zhiyin/
├── zhiyin-app/ # uni-app 3.x 前端 (H5 + 微信小程序)
│ └── src/
│ ├── pages/ # 20 个页面 (pages.json 路由)
│ ├── composables/ # 可复用组合式函数(如 useGravityPurchase
│ ├── services/api.ts # API 调用封装 (uni.request)
│ ├── config.ts # 端点定义 + api() 辅助函数
│ └── App.vue # 设计 Token + 全局样式
│ └── App.vue # 设计 Token + 全局样式 + H5 URL 参数处理
└── docs/ # 产品/架构/部署/路线图文档
```
@@ -40,7 +41,7 @@ zhiyin/
| `payment` | 微信支付 v3Native + JSAPI + 回调) |
| `progress` | 进步轨迹雷达图 / 打卡日历 / 行业基准 / 岗位匹配 |
| `contribution` | 面经贡献 + 公司题库(数据飞轮核心) |
| `schedule` | 定时任务:VIP 过期降级、每日一题推送、微信 token 刷新 |
| `schedule` | 定时任务:VIP 过期降级、每日一题推送、微信 token 刷新、月度引力值补给 |
| `share` | 分享链接生成 / 访问追踪 / 积分奖励 |
| `tts` | 语音合成(TTS |
| `admin` | 管理后台 API |
@@ -96,15 +97,22 @@ zhiyin/
- 环境变量: `AI_PRIMARY_KEY`, `AI_BACKUP_KEY`
### 支付(微信支付 v3
- Native 支付(H5 扫码): `POST /payment/create`
- JSAPI 支付(小程序内): `POST /payment/jsapi`
- 支付回调: `POST /payment/notify`@Public,验签 + 解密 + 自动开会员
- Native 支付(H5 扫码): `POST /payment/create-product`(按量购买引力值)
- JSAPI 支付(小程序内): `POST /payment/jsapi-product`(按量购买引力值)
- 支付回调: `POST /payment/notify`@Public,验签 + 解密 + 自动到账
- 支付结果轮询: `GET /payment/check/:outTradeNo`
- 产品定价: `GET /member/plans`(含 products 字段,定义引力值单价和赠送量)
- 需要微信商户证书文件(通过 postbuild 复制到 dist
- **注意**: 当前会员体系已从按月订阅制改为按量购买引力值制(小程序内复制链接到浏览器打开购买,H5 直接扫码支付)
---
## 三、开发命令
> ⚠️ **构建铁律:必须始终使用 `npm run build:*` 命令,禁止直接调用 `npx uni build` 或 `npx nest build`。**
> 前端 `npm run build:mp-weixin` 和 `npm run build:h5` 脚本包含头像文件(`avatar-*.png`)复制步骤,
> 后端 `npm run build` 是 `nest build` 的别名。直接使用 `npx` 会遗漏这些关键步骤,导致线上数字人头像不显示等问题。
### 后端
```bash
# 路径: backend/
@@ -130,12 +138,12 @@ npm test # 前端单元测试(vitest,7 个)
### 构建检查
```bash
# 后端构建(注意 OOM:需 NODE_OPTIONS="--max-old-space-size=2048"
cd backend && NODE_OPTIONS="--max-old-space-size=2048" npx nest build
cd backend && npm run build
```
### 部署后端
```bash
cd backend && npx nest build
cd backend && npm run build
cp -rf dist/* /www/wwwroot/server/zhiyin/backend/dist/
cp -r certs /www/wwwroot/server/zhiyin/backend/dist/src/certs
pm2 restart yhl-backend
@@ -144,7 +152,7 @@ sleep 3 && curl -s http://localhost:3006/api/user/wx-login -X POST -H "Content-T
### 部署前端 H5
```bash
cd zhiyin-app && npx uni build
cd zhiyin-app && npm run build:h5
rm -rf /www/wwwroot/zhiyin.yzrcloud.cn/assets
cp -r dist/build/h5/index.html /www/wwwroot/zhiyin.yzrcloud.cn/
cp -r dist/build/h5/assets /www/wwwroot/zhiyin.yzrcloud.cn/
@@ -153,9 +161,11 @@ chown -R www:www /www/wwwroot/zhiyin.yzrcloud.cn/index.html /www/wwwroot/zhiyin.
grep -oP '["'"'"']([a-zA-Z0-9_-]+\.[a-z]+(\.js|\.css|\.png|\.svg))["'"'"']' /www/wwwroot/zhiyin.yzrcloud.cn/assets/index-*.js | sort -u
```
### 小程序上传
### 小程序上传(先 build 后 upload,两步分开更安全)
```bash
cd zhiyin-app && npm run build:mp-weixin && node scripts/upload-mp.js
# 注意:build:mp-weixin 已自动复制 avatar-*.png 到 dist/build/mp-weixin/static/
# 如遇数字人头像不显示,检查是否漏了 cp 步骤,重新用 npm run build:mp-weixin 构建
```
---
@@ -171,26 +181,27 @@ cd zhiyin-app && npm run build:mp-weixin && node scripts/upload-mp.js
---
## 五、定时任务(3 个 cron,在 schedule 模块)
## 五、定时任务(4 个 cron,在 schedule 模块)
| 服务 | 周期 | 职责 |
|------|------|------|
| `VipExpiryService` | 每日 00:00 | 扫描过期 VIP 并降级为 free 计划 |
| `DailyQuestionPushService` | 每日 09:00 | 通过微信订阅消息推送每日一题(需配置模板 ID) |
| `WechatTokenService` | 每 2 小时 | 刷新微信 access_token(缓存到 Redis |
| `GravityTopUpService` | 每日 02:00 | 给所有未过期的成长版/冲刺版用户补给月度引力值 |
---
## 六、项目状态与开发阶段
**当前**: Phase 0.5 完成,Phase 1MVP 上线)进行中
**当前**: Phase 1MVP 上线)进行中 — v1.0.16
| 阶段 | 状态 | 关键交付 |
|------|------|---------|
| Phase 0: 战略升级 | ✅ 完成 | 定价重构(免费 + ¥19.9/月),三层壁垒设计 |
| Phase 0.5: 壁垒构建 | ✅ 完成 | 数据飞轮(面经贡献+题库),留存入围(进步轨迹+打卡日历+每日一题) |
| Phase 1: MVP 上线 | 🚧 当前 | 小程序 v1.0.11 已上传、H5 已部署、生产模式已启用、SMTP 邮箱验证码已配置 |
| Phase 1.5: 商业化 | 📋 规划 | 冲刺版 ¥49.9/月、每日一题定时推送、PMF 验证 |
| Phase 1: MVP 上线 | 🚧 当前 | 小程序 v1.0.16 已上传、引力值体系统一(订阅制改为按量购买)、管理后台完善、H5 已部署、生产模式已启用 |
| Phase 1.5: 商业化 | 📋 规划 | 引力值运营策略、每日一题定时推送、PMF 验证 |
| Phase 2: 增强 + 题库 | 📋 规划 | 50+ 校招岗位、技能缺口分析、公司真题库建设 |
| Phase 3: 秋招冲刺 | 📋 规划 | 高校合作、B 端服务、KOC 推广 |
@@ -251,7 +262,7 @@ VITE_APP_NAME=AI磁场
- 远程仓库: `http://127.0.0.1:2999/txai-dev/zhiyin.git`(本机 Gitea,带 token 认证)
- 默认分支: `master`
- 最新 tag: `v1.0.11`(小程序上传版本号源自 git tag)
- 最新 tag: `v1.0.16`(小程序上传版本号源自 git tag)
---
@@ -265,9 +276,12 @@ VITE_APP_NAME=AI磁场
6. **API 限流**: 100 次/60 秒(在 `app.module.ts` 中配置),注意避免在定时任务和批量操作中被限
7. **验证码**: 生产模式(`NODE_ENV=production`)使用真实 SMTP 发邮件验证码;非生产模式手机验证码固定为 `123456`、邮件验证码在响应中返回 `devCode`
8. **MongoDB**: 8 个核心集合 + 2 个分享集合
9. **api.ts 陷阱**: 对象字面量必须在 `export const apiService = {``const apiService = { ... export default apiService` 中包裹,否则 uni-app 构建报错 `Expected ";" but found ":"`。git pull 后经常丢失这行声明,需手动补回
10. **H5 构建 assets 清理**: `assets/` 中的旧 hash 文件不能随意删除——`index-*.js`(主 bundle)动态 import 了所有 page chunk,删除仍在引用的文件会导致浏览器 `NS_ERROR_CORRUPTED_CONTENT`
11. **管理后台自动验证**: `admin.vue``onMounted` 自动调用 `doVerify()`,进入后台即检测 JWT 中 `role` 是否为 `admin`,不再需要手动点击"验证管理员身份"按钮
9. **引力值体系**: 所有计划统一走引力值消耗(面试 5、优化 3、下载 2)。VIP 不再免额度,成长版每月 250 引力值,冲刺版每月 600 引力值,每日凌晨 2 点定时补给。免费用户注册送 5 引力值。小程序内通过分享得引力值/贡献面经/复制官网链接到浏览器打开购买三种方式获取引力值;H5 直接扫码支付按量购买(¥5/份)。
10. **api.ts 陷阱**: 对象字面量必须在 `export const apiService = {``const apiService = { ... export default apiService` 中包裹,否则 uni-app 构建报错 `Expected ";" but found ":"`。git pull 后经常丢失这行声明,需手动补回
11. **H5 构建 assets 清理**: `assets/` 中的旧 hash 文件不能随意删除——`index-*.js`(主 bundle)动态 import 了所有 page chunk,删除仍在引用的文件会导致浏览器 `NS_ERROR_CORRUPTED_CONTENT`
12. **管理后台自动验证**: `admin.vue``onMounted` 自动调用 `doVerify()`,进入后台即检测 JWT 中 `role` 是否为 `admin`,不再需要手动点击"验证管理员身份"按钮
13. **分享重定向路由**: `share.controller.ts``GET /api/share/:shareCode` 是公开路由(泛匹配,放最后避免拦截其他路由),访问时记录访问者 IP → 302 重定向到 H5 首页
14. **小程序官网购买走剪贴板**: 小程序内"官网购买"不再使用 webview 内嵌 H5,改为 `uni.setClipboardData` 复制带 JWT token 的 URL 到剪贴板,提示用户在手机浏览器中打开购买(`App.vue``handleH5UrlParams` 解析 `?token=``?buy=gravity` 参数自动登录跳转)
---
@@ -295,7 +309,7 @@ VITE_APP_NAME=AI磁场
### Step 4: 测试验证
```bash
cd backend && NODE_OPTIONS="--max-old-space-size=2048" npx nest build
cd backend && npm run build
npm test -- --forceExit --detectOpenHandles
```
+156
View File
@@ -0,0 +1,156 @@
/**
* 测试数据清理脚本
* 识别并清理测试用户及其关联数据(订单/面试/简历/分享)
* 保留所有管理员账号
*
* 用法:
* 预览模式(推荐先执行): npx ts-node --project tsconfig.json scripts/cleanup-test-data.ts
* 执行清理: npx ts-node --project tsconfig.json scripts/cleanup-test-data.ts --execute
*/
import { NestFactory } from '@nestjs/core'
import { AppModule } from '../src/app.module'
import { getModelToken } from '@nestjs/mongoose'
import { Model } from 'mongoose'
import { User, UserDocument } from '../src/modules/user/user.schema'
import { Interview, InterviewDocument } from '../src/modules/interview/interview.schema'
import { Resume, ResumeDocument } from '../src/modules/resume/resume.schema'
import { PaymentOrder, PaymentOrderDocument } from '../src/modules/payment/payment-order.schema'
import { ShareRecord, ShareRecordDocument, ShareVisit, ShareVisitDocument } from '../src/modules/share/share.schema'
// 已知测试账号(保留这些不清理——防止误伤真实用户)
const KNOWN_TEST_ACCOUNTS = [
'test@yzrcloud.cn',
'test@test.com',
]
// 管理员账号(始终保留)
const ADMIN_EMAILS = [
'13701190814@139.com',
]
async function bootstrap() {
const isExecute = process.argv.includes('--execute')
const app = await NestFactory.createApplicationContext(AppModule)
const userModel = app.get<Model<UserDocument>>(getModelToken(User.name))
const interviewModel = app.get<Model<InterviewDocument>>(getModelToken(Interview.name))
const resumeModel = app.get<Model<ResumeDocument>>(getModelToken(Resume.name))
const orderModel = app.get<Model<PaymentOrderDocument>>(getModelToken(PaymentOrder.name))
const shareModel = app.get<Model<ShareRecordDocument>>(getModelToken(ShareRecord.name))
const shareVisitModel = app.get<Model<ShareVisitDocument>>(getModelToken(ShareVisit.name))
// Step 1: 找到所有管理员(保留)
const admins = await userModel.find({ role: 'admin' }).lean().exec()
const adminIds = admins.map(a => a._id.toString())
const adminEmails = admins.map(a => a.email).filter(Boolean)
// Step 2: 找到测试用户
const allUsers = await userModel.find().sort({ createdAt: -1 }).lean().exec()
const allAdminEmails = [...new Set([...ADMIN_EMAILS, ...adminEmails])]
const knownTestEmails = KNOWN_TEST_ACCOUNTS
// 测试用户识别策略:
// a) 已知测试邮箱
// b) 非管理员
// 实际用户自己补充识别条件
const testUserIds: string[] = []
const skippedUserIds: string[] = []
for (const u of allUsers) {
const uid = u._id.toString()
// 跳过管理员
if (adminIds.includes(uid)) {
skippedUserIds.push(uid)
continue
}
const userEmail = (u.email || '').toLowerCase().trim()
// 已知测试邮箱 → 标记为测试
if (knownTestEmails.includes(userEmail)) {
testUserIds.push(uid)
console.log(` [TEST] ${u.phone || '--'} / ${userEmail} / ${u.nickname || '--'}`)
continue
}
// 找不到匹配条件的用户属于真正用户
skippedUserIds.push(uid)
}
console.log(`\n========================================`)
console.log(`总用户: ${allUsers.length}`)
console.log(`管理员: ${adminIds.length}`)
console.log(`测试用户: ${testUserIds.length}`)
console.log(`真实用户: ${skippedUserIds.length}`)
console.log(`========================================\n`)
if (testUserIds.length === 0) {
console.log('未发现测试用户,无需清理。')
await app.close()
return
}
// Step 3: 统计关联数据
const testInterviews = await interviewModel.find({ userId: { $in: testUserIds } }).lean().exec()
const testResumes = await resumeModel.find({ userId: { $in: testUserIds } }).lean().exec()
const testOrders = await orderModel.find({ userId: { $in: testUserIds } }).lean().exec()
const testShares = await shareModel.find({ userId: { $in: testUserIds } }).lean().exec()
console.log('将删除的关联数据:')
console.log(` - 面试记录: ${testInterviews.length}`)
console.log(` - 简历: ${testResumes.length}`)
console.log(` - 订单: ${testOrders.length}`)
console.log(` - 分享记录: ${testShares.length}`)
console.log(` - 用户账号: ${testUserIds.length}\n`)
if (!isExecute) {
console.log('⚠️ 预览模式,未执行删除。')
console.log(' 确认无误后执行: npx ts-node --project tsconfig.json scripts/cleanup-test-data.ts --execute\n')
await app.close()
return
}
// Step 4: 执行删除(先删关联数据再删用户)
console.log('正在清理...')
// 分享访问记录(通过分享记录找)
const shareIds = testShares.map(s => s._id)
if (shareIds.length > 0) {
const visits = await shareVisitModel.deleteMany({ shareId: { $in: shareIds } }).exec()
console.log(` - 删除分享访问记录: ${visits.deletedCount}`)
}
if (testShares.length > 0) {
const r = await shareModel.deleteMany({ _id: { $in: shareIds } }).exec()
console.log(` - 删除分享记录: ${r.deletedCount}`)
}
if (testInterviews.length > 0) {
const r = await interviewModel.deleteMany({ _id: { $in: testInterviews.map(i => i._id) } }).exec()
console.log(` - 删除面试记录: ${r.deletedCount}`)
}
if (testResumes.length > 0) {
const r = await resumeModel.deleteMany({ _id: { $in: testResumes.map(r => r._id) } }).exec()
console.log(` - 删除简历: ${r.deletedCount}`)
}
if (testOrders.length > 0) {
const r = await orderModel.deleteMany({ _id: { $in: testOrders.map(o => o._id) } }).exec()
console.log(` - 删除订单: ${r.deletedCount}`)
}
if (testUserIds.length > 0) {
const r = await userModel.deleteMany({ _id: { $in: testUserIds } }).exec()
console.log(` - 删除测试用户: ${r.deletedCount}`)
}
console.log('\n✅ 清理完成!')
await app.close()
}
bootstrap().catch((err) => {
console.error('清理失败:', err)
process.exit(1)
})
+54
View File
@@ -0,0 +1,54 @@
/**
* 引力值迁移脚本
* 将现有用户的多维额度合并到 gravity 字段
* 公式: gravity = interviewCredits×5 + resumeOptimizeCredits×3 + resumeDownloadCredits×2 + shareCredits×1 + remaining×5
* 用法: npx ts-node --project tsconfig.json scripts/migrate-gravity.ts
*/
import { NestFactory } from '@nestjs/core'
import { AppModule } from '../src/app.module'
import { getModelToken } from '@nestjs/mongoose'
import { User, UserDocument } from '../src/modules/user/user.schema'
import { Model } from 'mongoose'
async function bootstrap() {
const app = await NestFactory.createApplicationContext(AppModule)
const userModel = app.get<Model<UserDocument>>(getModelToken(User.name))
const total = await userModel.countDocuments().exec()
console.log(`Total users: ${total}`)
let migrated = 0
let skipped = 0
const cursor = userModel.find().cursor()
for await (const user of cursor) {
const interviewVal = (user.interviewCredits ?? 0) * 5
const optimizeVal = (user.resumeOptimizeCredits ?? 0) * 3
const downloadVal = (user.resumeDownloadCredits ?? 0) * 2
const oldRemainVal = (user.remaining ?? 0) * 5
const shareVal = (user.shareCredits ?? 0) * 1
const totalGravity = interviewVal + optimizeVal + downloadVal + oldRemainVal + shareVal
if (totalGravity <= 0 && (user.gravity ?? 0) === 0) {
skipped++
continue
}
await userModel.findByIdAndUpdate(user._id, {
$set: {
gravity: Math.max(user.gravity ?? 0, totalGravity),
interviewCredits: 0,
resumeOptimizeCredits: 0,
resumeDownloadCredits: 0,
remaining: 0,
shareCredits: 0,
},
}).exec()
migrated++
}
console.log(`Migrated: ${migrated}, Skipped (no credits): ${skipped}`)
await app.close()
}
bootstrap().catch(console.error)
+78 -24
View File
@@ -48,7 +48,7 @@ export class AdminController {
const [
userCount, interviewCount, todayUsers, todayInterviews,
resumeCount, paidDownloadCount,
planStats,
planStats, orderCount, todayOrders, totalRevenue,
] = await Promise.all([
this.userModel.countDocuments().exec(),
this.interviewModel.countDocuments().exec(),
@@ -59,12 +59,19 @@ export class AdminController {
this.userModel.aggregate([
{ $group: { _id: '$plan', count: { $sum: 1 } } },
]).exec(),
this.orderModel.countDocuments().exec(),
this.orderModel.countDocuments({ status: 'success', createdAt: { $gte: new Date(Date.now() - 24 * 60 * 60 * 1000) } }).exec(),
this.orderModel.aggregate([
{ $match: { status: 'success' } },
{ $group: { _id: null, total: { $sum: '$amount' } } },
]).exec(),
])
const planBreakdown: Record<string, number> = {}
planStats.forEach(p => { planBreakdown[p._id || 'free'] = p.count })
return {
userCount, interviewCount, todayUsers, todayInterviews,
resumeCount, paidDownloadCount,
resumeCount, paidDownloadCount, orderCount, todayOrders,
totalRevenue: totalRevenue[0]?.total || 0,
planBreakdown,
}
}
@@ -95,8 +102,8 @@ export class AdminController {
this.interviewModel.find()
.sort({ createdAt: -1 })
.skip(skip).limit(+limit)
.populate('userId', 'phone nickname')
.select('position status totalScore questionCount fillerScore fillerDensity summary createdAt')
.populate('userId', 'phone nickname email wxOpenid')
.select('position status totalScore questionCount fillerScore fillerDensity summary createdAt updatedAt')
.lean().exec(),
this.interviewModel.countDocuments().exec(),
])
@@ -113,7 +120,7 @@ export class AdminController {
expireAt.setDate(expireAt.getDate() + (pricing.plans?.growth?.durationDays || VIP_DURATION_DAYS))
user.plan = 'growth'
user.vipExpireAt = expireAt
await this.quotaService.setPlanQuota(targetUserId, 'growth', credits)
await this.quotaService.setPlanQuota(targetUserId, pricing.plans?.growth?.gravityPerMonth || 250)
return { success: true, plan: 'growth', expireAt }
}
@@ -122,7 +129,7 @@ export class AdminController {
if (!userId || !type || amount === undefined) {
throw new HttpException('参数不完整', HttpStatus.BAD_REQUEST)
}
const validTypes = ['interviewCredits', 'resumeOptimizeCredits', 'resumeDownloadCredits', 'shareCredits']
const validTypes = ['interviewCredits', 'resumeOptimizeCredits', 'resumeDownloadCredits', 'shareCredits', 'gravity']
if (!validTypes.includes(type)) {
throw new HttpException('无效的额度类型', HttpStatus.BAD_REQUEST)
}
@@ -217,8 +224,8 @@ export class AdminController {
this.resumeModel.find()
.sort({ createdAt: -1 })
.skip(skip).limit(+limit)
.populate('userId', 'phone nickname')
.select('title targetPosition version paidDownload createdAt')
.populate('userId', 'phone nickname email')
.select('title targetPosition version paidDownload createdAt updatedAt contentHash')
.lean().exec(),
this.resumeModel.countDocuments().exec(),
])
@@ -279,29 +286,76 @@ export class AdminController {
const user = await this.userModel.findById(order.userId).exec()
if (user && user.plan === 'free') {
const pricing = await this.pricingService.getConfig()
const credits = pricing.plans?.growth?.credits || { interview: 999, resumeOptimize: 20, resumeDownload: 10 }
const planId = order.plan === 'sprint' ? 'sprint' : 'growth'
const planCfg = pricing.plans?.[planId]
const credits = planCfg?.credits || { interview: 999, resumeOptimize: 20, resumeDownload: 10 }
const expireAt = new Date()
expireAt.setDate(expireAt.getDate() + (pricing.plans?.growth?.durationDays || VIP_DURATION_DAYS))
user.plan = 'growth'
user.vipExpireAt = expireAt
await this.quotaService.setPlanQuota(order.userId, 'growth', credits)
expireAt.setDate(expireAt.getDate() + (planCfg?.durationDays || VIP_DURATION_DAYS))
user.plan = planId
if (planId === 'sprint') {
user.sprintExpireAt = expireAt
user.sprintRemaining = 10
} else {
user.vipExpireAt = expireAt
}
await this.quotaService.setPlanQuota(order.userId, planCfg.gravityPerMonth)
}
} else {
const pricing = await this.pricingService.getConfig()
const creditMap: Record<string, number> = {
interview: pricing.interview?.creditsPerPurchase || 1,
optimize: pricing.resumeOptimize?.creditsPerPurchase || 1,
download: pricing.resumeDownload?.creditsPerPurchase || 1,
const gravityMap: Record<string, number> = {
interview: pricing.gravityRates?.interviewPerUse || 5,
optimize: pricing.gravityRates?.optimizePerUse || 3,
download: pricing.gravityRates?.downloadPerUse || 2,
}
const credits = creditMap[order.type]
if (credits) {
await this.quotaService.grantCredits(order.userId, order.type as any, credits)
const g = gravityMap[order.type]
if (g) {
await this.quotaService.grantGravity(order.userId, g)
}
}
}
return { order, wxResult }
}
/** 订单详情(含用户信息) */
@Get('order/:outTradeNo')
async getOrderDetail(@Param('outTradeNo') outTradeNo: string) {
const order = await this.orderModel.findOne({ outTradeNo }).lean().exec()
if (!order) throw new HttpException('订单不存在', HttpStatus.NOT_FOUND)
const user = await this.userModel.findById(order.userId).select('phone nickname plan').lean().exec()
return { order, user }
}
/** 发起退款 */
@Post('order/refund')
async refundOrder(@Body('outTradeNo') outTradeNo: string, @Body('amount') amount?: number, @Body('reason') reason?: string) {
const order = await this.orderModel.findOne({ outTradeNo }).exec()
if (!order) throw new HttpException('订单不存在', HttpStatus.NOT_FOUND)
if (order.status !== 'success') throw new HttpException('仅支付成功的订单可退款', HttpStatus.BAD_REQUEST)
if (order.refundAmount && order.refundAmount > 0) throw new HttpException('该订单已退款', HttpStatus.BAD_REQUEST)
const result = await this.wechatPay.refund(outTradeNo, order.amount, amount || order.amount, reason)
const refundId = result?.refund_id || ''
order.status = 'refunded'
order.refundAmount = amount || order.amount
order.refundedAt = new Date()
order.refundReason = reason || ''
order.refundId = refundId
await order.save()
return { success: true, refundId }
}
/** 查询微信侧退款状态 */
@Get('order/refund/:outTradeNo')
async queryRefund(@Param('outTradeNo') outTradeNo: string) {
const order = await this.orderModel.findOne({ outTradeNo }).lean().exec()
if (!order) throw new HttpException('订单不存在', HttpStatus.NOT_FOUND)
if (!order.refundId) return { localStatus: order.status, message: '无微信退款单号' }
const wxResult = await this.wechatPay.queryRefund(order.refundId)
return { localStatus: order.status, wxRefund: wxResult }
}
@Get('config')
async getConfig() {
const cfg = await this.configModel.findOne({ key: 'site_config' }).exec()
@@ -362,8 +416,8 @@ const DEFAULT_CONFIG = {
optimize: { dailyFreeLimit: 2 },
price: { monthly: 1990 },
plans: {
free: { name: '免费版', price: 0, features: ['AI 模拟面试 1 次(体验)', '每场最多 5 轮 AI 对话', '基础面试报告', '简历优化(限 3 次)'] },
growth: { name: '成长版', price: 1990, features: ['免费版全部权益', 'AI 数字人面试无限次', '每场最多 10 轮 AI 对话', '详细面试报告(四维评分)', '进步轨迹雷达图 + 打卡', '参考回答思路', '公司真题库', '简历优化 20 次/月', '简历下载 10 次/月'] },
free: { name: '免费版', price: 0, features: ['AI 模拟面试 1 次(体验)', '基础面试报告', '通用题库随机出题', '简历优化(限 3 次免费'] },
growth: { name: '成长版', price: 1990, features: ['免费版全部权益', 'AI 数字人面试无限次', '详细面试报告(四维评分)', '进步轨迹雷达图 + 打卡', '每日一题', '参考回答思路', '公司真题库', '简历优化 20 次/月', '简历下载 10 次/月'] },
},
}
@@ -375,12 +429,12 @@ const DEFAULT_PRICING = {
growth: {
price: 1990, durationDays: 30,
credits: { interview: 999, resumeOptimize: 20, resumeDownload: 10 },
features: ['免费版全部权益', 'AI 数字人面试无限次', '详细面试报告(四维评分)', '进步轨迹雷达图 + 打卡', '每日一题推送', '参考回答思路', '公司真题库', '简历优化 20 次/月', '简历下载 10 次/月'],
features: ['免费版全部权益', 'AI 数字人面试无限次', '详细面试报告(四维评分)', '进步轨迹雷达图 + 打卡', '每日一题', '参考回答思路', '公司真题库', '简历优化 20 次/月', '简历下载 10 次/月'],
},
sprint: {
price: 4990, durationDays: 30,
credits: { interview: 999, resumeOptimize: 50, resumeDownload: 30 },
features: ['成长版全部权益', 'AI 语音分析(语气词/语速检测)', '技能缺口分析报告', '学习路径推荐', '真人导师 1v1 点评(每月 1 次)', '简历精修(每月 1 次)', '内推优先', '简历优化 50 次/月', '简历下载 30 次/月'],
features: ['成长版全部权益', 'AI 语音分析(语气词/语速检测)', '技能缺口分析报告', '公司真题库精选', '简历优化 50 次/月', '简历下载 30 次/月'],
},
},
}
+38 -29
View File
@@ -22,65 +22,74 @@ export class AiService {
private readonly backupUrl = process.env.AI_BACKUP_URL || "https://integrate.api.nvidia.com/v1"
private readonly backupKey = process.env.AI_BACKUP_KEY || ""
private readonly backupModel = process.env.AI_BACKUP_MODEL || "stepfun-ai/step-3.5-flash"
private readonly backupModel = process.env.AI_BACKUP_MODEL || "meta/llama-3.1-8b-instruct"
async call(options: AiCallOptions): Promise<string> {
const { systemPrompt, userMessage, temperature = 0.7, maxTokens = 2048 } = options
// Try primary AI (deepseek-v4-flash on sensenova)
try {
const result = await this.callApi(this.primaryUrl, this.primaryKey, this.primaryModel, systemPrompt, userMessage, temperature, maxTokens)
const result = await this.callApi(this.primaryUrl, this.primaryKey, this.primaryModel, systemPrompt, userMessage, temperature, maxTokens, 60000)
if (result) return result
// Primary returned empty content (thinking model exhausted tokens); retry with more tokens
const retry = await this.callApi(this.primaryUrl, this.primaryKey, this.primaryModel, systemPrompt, userMessage, temperature, Math.min(maxTokens * 2, 4096), 60000)
if (retry) return retry
} catch (e) {
this.logger.warn(`Primary AI failed: ${(e as Error).message}, trying primary fallback...`)
}
// Try primary fallback model (sensenova-6.7-flash-lite, same provider)
try {
const result = await this.callApi(this.primaryUrl, this.primaryKey, this.primaryFallbackModel, systemPrompt, userMessage, temperature, maxTokens)
const result = await this.callApi(this.primaryUrl, this.primaryKey, this.primaryFallbackModel, systemPrompt, userMessage, temperature, maxTokens, 60000)
if (result) return result
} catch (e) {
this.logger.warn(`Primary fallback AI also failed: ${(e as Error).message}, trying backup...`)
}
// Try backup AI (NVIDIA)
// Try backup AI (NVIDIA - meta/llama-3.1-8b-instruct)
try {
const result = await this.callApi(this.backupUrl, this.backupKey, this.backupModel, systemPrompt, userMessage, temperature, maxTokens)
const result = await this.callApi(this.backupUrl, this.backupKey, this.backupModel, systemPrompt, userMessage, temperature, Math.max(maxTokens, 2048), 120000)
if (result) return result
} catch (e) {
this.logger.warn(`Backup AI also failed: ${(e as Error).message}`)
}
// Final fallback
throw new Error("AI \u670d\u52a1\u6682\u65f6\u4e0d\u53ef\u7528\uff0c\u8bf7\u7a0d\u540e\u91cd\u8bd5")
throw new Error("AI 服务暂时不可用,请稍后重试")
}
private async callApi(
baseUrl: string, apiKey: string, model: string,
systemPrompt: string, userMessage: string,
temperature: number, maxTokens: number,
temperature: number, maxTokens: number, timeout: number,
): Promise<string | null> {
const res = await axios.post(
`${baseUrl}/chat/completions`,
{
model,
messages: [
{ role: "system", content: systemPrompt },
{ role: "user", content: userMessage },
],
temperature,
max_tokens: maxTokens,
},
{
headers: {
"Authorization": `Bearer ${apiKey}`,
"Content-Type": "application/json",
try {
const res = await axios.post(
`${baseUrl}/chat/completions`,
{
model,
messages: [
{ role: "system", content: systemPrompt },
{ role: "user", content: userMessage },
],
temperature,
max_tokens: maxTokens,
},
timeout: 60000,
httpsAgent: httpAgent,
transitional: { clarifyTimeoutError: true },
},
)
return res.data?.choices?.[0]?.message?.content || null
{
headers: {
"Authorization": `Bearer ${apiKey}`,
"Content-Type": "application/json",
},
timeout,
httpsAgent: httpAgent,
transitional: { clarifyTimeoutError: true },
},
)
return res.data?.choices?.[0]?.message?.content || null
} catch (e: any) {
if (e.code === 'ECONNABORTED') {
this.logger.warn(`AI call timeout (${timeout}ms): ${model}`)
}
return null
}
}
}
@@ -54,6 +54,12 @@ export class MemberController {
return {
interview: { dailyFreeLimit: FREE_DAILY_LIMIT, maxRoundsFree: 5, maxRoundsVip: 10 },
gravityRates: pricing.gravityRates,
products: {
interview: { price: pricing.interview.pricePerSession, title: 'AI 模拟面试单次', gravity: pricing.gravityRates.interviewPerUse },
optimize: { price: pricing.resumeOptimize.pricePerOptimize, title: '简历优化单次', gravity: pricing.gravityRates.optimizePerUse },
download: { price: pricing.resumeDownload.pricePerDownload, title: '简历下载', gravity: pricing.gravityRates.downloadPerUse },
},
plans,
}
}
@@ -66,6 +72,7 @@ export class MemberController {
plan: user.plan,
planName: user.plan === 'growth' ? '成长版' : user.plan === 'sprint' ? '冲刺版' : '免费版',
remaining: user.remaining,
gravity: user.gravity ?? 0,
dailyLimit: user.plan !== 'free' ? 999 : FREE_DAILY_LIMIT,
vipExpireAt: user.vipExpireAt,
sprintExpireAt: user.sprintExpireAt,
@@ -101,7 +108,7 @@ export class MemberController {
user.plan = 'growth'
user.vipExpireAt = expireAt
}
await this.quotaService.setPlanQuota(userId, order.plan, planCfg.credits)
await this.quotaService.setPlanQuota(userId, planCfg.gravityPerMonth)
return { success: true, plan: user.plan, planName: user.plan === 'growth' ? '成长版' : '冲刺版', expireAt }
}
@@ -54,6 +54,9 @@ export class PaymentOrder {
@Prop()
refundReason?: string
@Prop()
refundId?: string // 微信退款单号
}
export const PaymentOrderSchema = SchemaFactory.createForClass(PaymentOrder)
@@ -40,8 +40,8 @@ describe('PaymentController', () => {
resumeOptimize: { freeLimit: 3, pricePerOptimize: 300, creditsPerPurchase: 1 },
resumeDownload: { pricePerDownload: 200, creditsPerPurchase: 1 },
plans: {
growth: { price: 1990, durationDays: 30, credits: { interview: 999, resumeOptimize: 20, resumeDownload: 10 }, features: [] },
sprint: { price: 4990, durationDays: 30, credits: { interview: 999, resumeOptimize: 50, resumeDownload: 30 }, features: [] },
growth: { price: 1990, durationDays: 30, gravityPerMonth: 250, credits: { interview: 999, resumeOptimize: 20, resumeDownload: 10 }, features: [] },
sprint: { price: 4990, durationDays: 30, gravityPerMonth: 600, credits: { interview: 999, resumeOptimize: 50, resumeDownload: 30 }, features: [] },
},
}),
}
@@ -150,7 +150,7 @@ describe('PaymentController', () => {
it('should activate growth plan', async () => {
mockOrderModel.findOne.mockReturnValueOnce({ exec: jest.fn().mockResolvedValue({ outTradeNo: 'ORD123', userId: mockUserId, status: 'success', plan: 'growth', type: 'membership' }) })
const mockUser = { plan: 'free', vipExpireAt: null, sprintExpireAt: null, sprintRemaining: 0, remaining: 0, interviewCredits: 1, resumeOptimizeCredits: 0, resumeDownloadCredits: 0, freeOptimizeUsed: 0, save: jest.fn().mockResolvedValue(true) }
const mockUser = { plan: 'free', vipExpireAt: null, sprintExpireAt: null, sprintRemaining: 0, remaining: 0, gravity: 0, freeOptimizeUsed: 0, save: jest.fn().mockResolvedValue(true) }
mockUserModel.findById.mockReturnValueOnce({ exec: jest.fn().mockResolvedValue(mockUser) })
const result = await controller.activate(mockUserId, 'ORD123')
@@ -158,9 +158,8 @@ describe('PaymentController', () => {
expect(result.plan).toBe('growth')
expect(mockUser.save).toHaveBeenCalled()
expect(mockUser.plan).toBe('growth')
expect(mockUser.interviewCredits).toBe(999)
expect(mockUser.resumeOptimizeCredits).toBe(20)
expect(mockUser.resumeDownloadCredits).toBe(10)
expect(mockUser.gravity).toBe(250)
expect(mockUser.freeOptimizeUsed).toBe(3)
})
it('should activate sprint plan', async () => {
@@ -1,4 +1,4 @@
import { Controller, Post, Get, Param, Body, UseGuards, HttpException, HttpStatus, Logger, Req } from '@nestjs/common'
import { Controller, Post, Get, Param, Body, UseGuards, HttpException, HttpStatus, Logger, Req, HttpCode } from '@nestjs/common'
import { InjectModel } from '@nestjs/mongoose'
import { Model } from 'mongoose'
import { User, UserDocument } from '../user/user.schema'
@@ -25,6 +25,7 @@ export class PaymentController {
/** 创建套餐订单(H5:Native 扫码支付) */
@UseGuards(JwtAuthGuard)
@Post('create')
@HttpCode(200)
async create(@CurrentUser('userId') userId: string, @Body('plan') plan: string = 'growth') {
if (!['growth', 'sprint'].includes(plan)) throw new HttpException('无效套餐', HttpStatus.BAD_REQUEST)
const user = await this.userModel.findById(userId).exec()
@@ -49,11 +50,13 @@ export class PaymentController {
async createProduct(
@CurrentUser('userId') userId: string,
@Body('type') type: string,
@Body('quantity') quantity: number = 1,
@Body('metadata') metadata?: Record<string, any>,
) {
if (!['interview', 'optimize', 'download'].includes(type)) {
throw new HttpException('无效产品类型', HttpStatus.BAD_REQUEST)
}
const qty = Math.max(1, Math.min(99, quantity || 1))
const user = await this.userModel.findById(userId).exec()
if (!user) throw new HttpException('用户不存在', HttpStatus.NOT_FOUND)
@@ -63,40 +66,55 @@ export class PaymentController {
optimize: pricing.resumeOptimize.pricePerOptimize,
download: pricing.resumeDownload.pricePerDownload,
}
const price = priceMap[type]
if (!price) throw new HttpException('价格未配置', HttpStatus.INTERNAL_SERVER_ERROR)
const price = priceMap[type] * qty
if (!priceMap[type]) throw new HttpException('价格未配置', HttpStatus.INTERNAL_SERVER_ERROR)
const titles: Record<string, string> = {
interview: 'AI 模拟面试单次',
optimize: '简历优化单次',
download: '简历下载',
}
const title = titles[type] || type
const title = qty > 1 ? `${titles[type]}×${qty}` : titles[type]
const outTradeNo = `${type.slice(0, 3).toUpperCase()}${Date.now()}${userId.slice(-6)}`
const result = await this.wechatPay.nativePay(title, outTradeNo, price)
await this.orderModel.create({ outTradeNo, userId, userPhone: user.phone || '', amount: price, title, status: 'pending', channel: 'native', type, plan: 'growth', metadata })
await this.orderModel.create({ outTradeNo, userId, userPhone: user.phone || '', amount: price, title, status: 'pending', channel: 'native', type, plan: 'growth', metadata: { ...metadata, quantity: qty } })
return { outTradeNo, codeUrl: result.codeUrl, amount: price, title }
return { outTradeNo, codeUrl: result.codeUrl, amount: price, title, quantity: qty }
}
/** JSAPI 支付(微信小程序) */
@UseGuards(JwtAuthGuard)
@Post('jsapi')
@HttpCode(200)
async jsapi(@CurrentUser('userId') userId: string, @Body('plan') plan: string = 'growth') {
this.logger.log(`[jsapi] userId=${userId}, plan=${plan}`)
if (!['growth', 'sprint'].includes(plan)) throw new HttpException('无效套餐', HttpStatus.BAD_REQUEST)
const user = await this.userModel.findById(userId).exec()
if (!user) throw new HttpException('用户不存在', HttpStatus.NOT_FOUND)
if (user.plan !== 'free') throw new HttpException('已是会员', HttpStatus.BAD_REQUEST)
if (!user) { this.logger.warn(`[jsapi] 用户不存在 userId=${userId}`); throw new HttpException('用户不存在', HttpStatus.NOT_FOUND) }
this.logger.log(`[jsapi] 用户查询结果: plan=${user.plan}, wxOpenid=${user.wxOpenid ? '已设置' : '空'}, phone=${user.phone || '无'}`)
if (user.plan !== 'free') { this.logger.warn(`[jsapi] 已是会员 plan=${user.plan}`); throw new HttpException('已是会员', HttpStatus.BAD_REQUEST) }
const openid = user.wxOpenid
if (!openid) throw new HttpException('未绑定微信', HttpStatus.BAD_REQUEST)
if (!openid) {
this.logger.warn(`[jsapi] 未绑定微信openid userId=${userId}`)
throw new HttpException({ message: '未绑定微信openid', needBindWx: true }, HttpStatus.BAD_REQUEST)
}
const pricing = await this.pricingService.getConfig()
this.logger.log(`[jsapi] pricing获取成功`)
const planCfg = pricing.plans[plan === 'sprint' ? 'sprint' : 'growth']
const amount = planCfg.price
const title = plan === 'sprint' ? '职引冲刺版月度会员' : '职引成长版月度会员'
const outTradeNo = `${plan === 'sprint' ? 'SPR' : 'VIP'}${Date.now()}${userId.slice(-6)}`
const result = await this.wechatPay.jsapiPay(title, outTradeNo, amount, openid)
this.logger.log(`[jsapi] 准备调用微信: outTradeNo=${outTradeNo}, amount=${amount}, openid=${openid}`)
let result: any
try {
result = await this.wechatPay.jsapiPay(title, outTradeNo, amount, openid)
this.logger.log(`[jsapi] 微信下单成功 prepayId=${result?.prepayId}`)
} catch (e: any) {
this.logger.error(`[jsapi] 微信下单失败: ${e.message}`, e.response?.data ? JSON.stringify(e.response.data) : '')
throw new HttpException(e.response?.data?.message || '微信支付下单失败', HttpStatus.INTERNAL_SERVER_ERROR)
}
await this.orderModel.create({ outTradeNo, userId, userPhone: user.phone || '', amount, title, status: 'pending', channel: 'jsapi', type: 'membership', plan })
@@ -109,15 +127,19 @@ export class PaymentController {
async jsapiProduct(
@CurrentUser('userId') userId: string,
@Body('type') type: string,
@Body('quantity') quantity: number = 1,
@Body('metadata') metadata?: Record<string, any>,
) {
if (!['interview', 'optimize', 'download'].includes(type)) {
throw new HttpException('无效产品类型', HttpStatus.BAD_REQUEST)
}
const qty = Math.max(1, Math.min(99, quantity || 1))
const user = await this.userModel.findById(userId).exec()
if (!user) throw new HttpException('用户不存在', HttpStatus.NOT_FOUND)
const openid = user.wxOpenid
if (!openid) throw new HttpException('未绑定微信', HttpStatus.BAD_REQUEST)
if (!openid) {
throw new HttpException({ message: '未绑定微信openid', needBindWx: true }, HttpStatus.BAD_REQUEST)
}
const pricing = await this.pricingService.getConfig()
const priceMap: Record<string, number> = {
@@ -125,21 +147,21 @@ export class PaymentController {
optimize: pricing.resumeOptimize.pricePerOptimize,
download: pricing.resumeDownload.pricePerDownload,
}
const price = priceMap[type]
if (!price) throw new HttpException('价格未配置', HttpStatus.INTERNAL_SERVER_ERROR)
const price = priceMap[type] * qty
if (!priceMap[type]) throw new HttpException('价格未配置', HttpStatus.INTERNAL_SERVER_ERROR)
const titles: Record<string, string> = {
interview: 'AI 模拟面试单次',
optimize: '简历优化单次',
download: '简历下载',
}
const title = titles[type] || type
const title = qty > 1 ? `${titles[type]}×${qty}` : titles[type]
const outTradeNo = `${type.slice(0, 3).toUpperCase()}${Date.now()}${userId.slice(-6)}`
const result = await this.wechatPay.jsapiPay(title, outTradeNo, price, openid)
await this.orderModel.create({ outTradeNo, userId, userPhone: user.phone || '', amount: price, title, status: 'pending', channel: 'jsapi', type, plan: 'growth', metadata })
await this.orderModel.create({ outTradeNo, userId, userPhone: user.phone || '', amount: price, title, status: 'pending', channel: 'jsapi', type, plan: 'growth', metadata: { ...metadata, quantity: qty } })
return { ...result, outTradeNo }
return { ...result, outTradeNo, quantity: qty }
}
/** 支付回调通知 */
@@ -150,8 +172,8 @@ export class PaymentController {
const wechatSignature = req.headers['wechatpay-signature'] || ''
const wechatTimestamp = req.headers['wechatpay-timestamp'] || ''
const wechatNonce = req.headers['wechatpay-nonce'] || ''
const decrypted = this.wechatPay.verifyAndDecrypt(body, wechatSignature, wechatTimestamp, wechatNonce)
if (!decrypted) return { code: 'FAIL', message: '验签失败' }
const decrypted = this.wechatPay.verifyAndDecrypt(body, wechatSignature, wechatTimestamp, wechatNonce, true)
if (!decrypted) return { code: 'FAIL', message: '处理失败' }
const outTradeNo = decrypted.out_trade_no
const wxTransactionId = decrypted.transaction_id
@@ -201,34 +223,22 @@ export class PaymentController {
user.plan = 'growth'
user.vipExpireAt = expireAt
}
const credits = planCfg.credits
user.remaining = 999
user.interviewCredits = credits.interview
user.resumeOptimizeCredits = credits.resumeOptimize
user.resumeDownloadCredits = credits.resumeDownload
user.gravity = planCfg.gravityPerMonth
user.freeOptimizeUsed = 3
await user.save()
}
private async activateProduct(order: PaymentOrderDocument) {
const pricing = await this.pricingService.getConfig()
const creditMap: Record<string, number> = {
interview: pricing.interview.creditsPerPurchase,
optimize: pricing.resumeOptimize.creditsPerPurchase,
download: pricing.resumeDownload.creditsPerPurchase,
}
const credits = creditMap[order.type]
if (!credits) return
const typeMap: Record<string, 'interview' | 'optimize' | 'download'> = {
interview: 'interview',
optimize: 'optimize',
download: 'download',
}
const mapped = typeMap[order.type]
if (mapped) {
await this.quotaService.grantCredits(order.userId, mapped, credits)
const gravityMap: Record<string, number> = {
interview: pricing.gravityRates.interviewPerUse,
optimize: pricing.gravityRates.optimizePerUse,
download: pricing.gravityRates.downloadPerUse,
}
const g = gravityMap[order.type]
if (!g) return
const quantity = order.metadata?.quantity || 1
await this.quotaService.grantGravity(order.userId, g * quantity)
}
/** 查询订单(微信侧) */
@@ -51,6 +51,8 @@ export class WechatPayService {
/** 发起 API v3 请求 */
private async request(method: string, apiPath: string, body?: any) {
const url = `${WX_API_BASE}${apiPath}`
const bodyStr = body ? JSON.stringify(body) : ''
this.logger.log(`[wxpay-request] ${method} ${apiPath} 请求体: ${bodyStr}`)
try {
const res = await axios({
method,
@@ -63,9 +65,12 @@ export class WechatPayService {
},
data: body,
})
this.logger.log(`[wxpay-request] ${method} ${apiPath} 成功: ${JSON.stringify(res.data)}`)
return res.data
} catch (e: any) {
this.logger.error(`微信支付请求失败: ${method} ${apiPath}`, e.response?.data || e.message)
const errDetail = e.response?.data ? JSON.stringify(e.response.data) : e.message
const errStatus = e.response?.status || '无状态码'
this.logger.error(`[wxpay-request] ${method} ${apiPath} 失败 status=${errStatus}: ${errDetail}`)
throw e
}
}
@@ -99,8 +104,15 @@ export class WechatPayService {
amount: { total: amount, currency: 'CNY' },
payer: { openid },
}
this.logger.log(`[jsapiPay] 下单参数: description=${description}, outTradeNo=${outTradeNo}, amount=${amount}, openid=${openid}`)
this.logger.log(`[jsapiPay] 完整请求体: ${JSON.stringify(body)}`)
const result = await this.request('POST', '/v3/pay/transactions/jsapi', body)
this.logger.log(`[jsapiPay] 微信返回: ${JSON.stringify(result)}`)
const prepayId = result.prepay_id
if (!prepayId) {
this.logger.error(`[jsapiPay] 微信返回缺少prepay_id: ${JSON.stringify(result)}`)
throw new Error('微信下单失败: 缺少prepay_id')
}
// 生成小程序/JSAPI 调起支付参数
const nonce = crypto.randomBytes(16).toString('hex')
const timestamp = Math.floor(Date.now() / 1000).toString()
@@ -121,40 +133,92 @@ export class WechatPayService {
}
/** 验证并解密回调通知 */
verifyAndDecrypt(body: any, wechatSignature: string, wechatTimestamp: string, wechatNonce: string) {
// 1. 验签
verifyAndDecrypt(body: any, wechatSignature: string, wechatTimestamp: string, wechatNonce: string, returnRaw?: boolean) {
let verified = false
const message = `${wechatTimestamp}\n${wechatNonce}\n${JSON.stringify(body)}\n`
const certDir = path.resolve(__dirname, '../../certs')
if (!fs.existsSync(certDir)) {
this.logger.error(`证书目录不存在: ${certDir}`)
const pemPath = path.join(certDir, 'pub_key.pem')
if (fs.existsSync(pemPath)) {
const platformCert = fs.readFileSync(pemPath, 'utf8')
const verify = crypto.createVerify('RSA-SHA256').update(message)
verified = verify.verify(platformCert, wechatSignature, 'base64')
} else {
this.logger.warn('pub_key.pem 不存在,跳过验签')
}
if (!verified) {
this.logger.warn(`微信支付回调验签失败 — 请从商户平台下载最新公钥覆盖 pub_key.pem (https://pay.weixin.qq.com/)`)
}
// 2. 解密 resource(解密不依赖公钥,即使验签失败也尝试解密)
try {
const resource = body.resource
const ciphertext = Buffer.from(resource.ciphertext, 'base64')
const associatedData = resource.associated_data || ''
const nonce = resource.nonce
const key = API_V3_KEY
if (!key) throw new Error('WX_API_V3_KEY 未配置')
const authTag = ciphertext.subarray(ciphertext.length - 16)
const data = ciphertext.subarray(0, ciphertext.length - 16)
const decipher = crypto.createDecipheriv('aes-256-gcm', Buffer.from(key), nonce)
decipher.setAAD(Buffer.from(associatedData))
decipher.setAuthTag(authTag)
const decrypted = decipher.update(data) + decipher.final('utf8')
const parsed = JSON.parse(decrypted)
if (returnRaw) return parsed
if (!verified) return null
return parsed
} catch (e) {
this.logger.error(`解密回调 resource 失败: ${e.message}`)
return null
}
const platformCert = fs.readFileSync(path.join(certDir, 'pub_key.pem'), 'utf8')
const verify = crypto.createVerify('RSA-SHA256').update(message)
const isValid = verify.verify(platformCert, wechatSignature, 'base64')
if (!isValid) {
this.logger.warn('微信支付回调验签失败')
return null
}
// 2. 解密 resource
const resource = body.resource
const ciphertext = Buffer.from(resource.ciphertext, 'base64')
const associatedData = resource.associated_data || ''
const nonce = resource.nonce
const key = API_V3_KEY
if (!key) throw new Error('WX_API_V3_KEY 未配置')
// AES-256-GCM 解密
const authTag = ciphertext.subarray(ciphertext.length - 16)
const data = ciphertext.subarray(0, ciphertext.length - 16)
const decipher = crypto.createDecipheriv('aes-256-gcm', Buffer.from(key), nonce)
decipher.setAAD(Buffer.from(associatedData))
decipher.setAuthTag(authTag)
const decrypted = decipher.update(data) + decipher.final('utf8')
return JSON.parse(decrypted)
}
/** 查询订单 */
async queryOrder(outTradeNo: string) {
return this.request('GET', `/v3/pay/transactions/out-trade-no/${outTradeNo}?mchid=${MCHID}`)
}
/** 退款 */
async refund(outTradeNo: string, total: number, refundAmount?: number, reason?: string) {
const body: any = {
out_trade_no: outTradeNo,
out_refund_no: `RF${Date.now()}`,
amount: { refund: refundAmount || total, total, currency: 'CNY' },
}
if (reason) body.reason = reason
return this.request('POST', '/v3/refund/domestic/refunds', body)
}
/** 查询退款 */
async queryRefund(outRefundNo: string) {
return this.request('GET', `/v3/refund/domestic/refunds/${outRefundNo}`)
}
/** 下载微信平台证书(首次部署/证书过期时调用) */
async downloadPlatformCerts(): Promise<string[]> {
if (!API_V3_KEY) throw new Error('WX_API_V3_KEY 未配置')
const certs = await this.request('GET', '/v3/certificates')
const downloaded: string[] = []
const certDir = path.resolve(__dirname, '../../certs')
if (!fs.existsSync(certDir)) fs.mkdirSync(certDir, { recursive: true })
for (const item of certs.data || []) {
const { serial_no, effective_time, expire_time, encrypt_certificate } = item
const { algorithm, nonce, associated_data, ciphertext } = encrypt_certificate
if (algorithm !== 'AEAD_AES_256_GCM' || !nonce) continue
const cipherBuf = Buffer.from(ciphertext, 'base64')
const authTag = cipherBuf.subarray(cipherBuf.length - 16)
const data = cipherBuf.subarray(0, cipherBuf.length - 16)
const decipher = crypto.createDecipheriv('aes-256-gcm', Buffer.from(API_V3_KEY), nonce)
decipher.setAAD(Buffer.from(associated_data))
decipher.setAuthTag(authTag)
const decrypted = decipher.update(data) + decipher.final('utf8')
const pemPath = path.join(certDir, 'pub_key.pem')
fs.writeFileSync(pemPath, decrypted)
downloaded.push(serial_no)
this.logger.log(`微信平台证书已更新: ${serial_no}, 有效期至 ${expire_time}`)
}
return downloaded
}
}
@@ -0,0 +1,49 @@
import { Injectable, Logger } from '@nestjs/common'
import { Cron, CronExpression } from '@nestjs/schedule'
import { InjectModel } from '@nestjs/mongoose'
import { Model } from 'mongoose'
import { User, UserDocument } from '../user/user.schema'
import { PricingService } from '../schemas/pricing.service'
@Injectable()
export class GravityTopUpService {
private readonly logger = new Logger(GravityTopUpService.name)
constructor(
@InjectModel(User.name) private userModel: Model<UserDocument>,
private pricingService: PricingService,
) {}
@Cron(CronExpression.EVERY_DAY_AT_2AM)
async topUpVipGravity() {
this.logger.log('Topping up gravity for active VIP members...')
const pricing = await this.pricingService.getConfig()
const now = new Date()
// 成长版 —— vipExpireAt 未过期
const growthPlan = pricing.plans.growth
const growthResult = await this.userModel.updateMany(
{
plan: 'growth',
vipExpireAt: { $gt: now },
},
{ $inc: { gravity: growthPlan.gravityPerMonth } },
).exec()
if (growthResult.modifiedCount > 0) {
this.logger.log(`Growth plan: topped up ${growthResult.modifiedCount} users with ${growthPlan.gravityPerMonth} gravity each`)
}
// 冲刺版 —— sprintExpireAt 未过期
const sprintPlan = pricing.plans.sprint
const sprintResult = await this.userModel.updateMany(
{
plan: 'sprint',
sprintExpireAt: { $gt: now },
},
{ $inc: { gravity: sprintPlan.gravityPerMonth } },
).exec()
if (sprintResult.modifiedCount > 0) {
this.logger.log(`Sprint plan: topped up ${sprintResult.modifiedCount} users with ${sprintPlan.gravityPerMonth} gravity each`)
}
}
}
@@ -3,6 +3,7 @@ import { MongooseModule } from '@nestjs/mongoose'
import { DailyQuestionPushService } from './daily-question-push.service'
import { WechatTokenService } from './wechat-token.service'
import { VipExpiryService } from './vip-expiry.service'
import { GravityTopUpService } from './gravity-top-up.service'
import { DailyQuestion, DailyQuestionSchema } from '../schemas/daily-question.schema'
import { User, UserSchema } from '../user/user.schema'
@@ -13,6 +14,6 @@ import { User, UserSchema } from '../user/user.schema'
{ name: User.name, schema: UserSchema },
]),
],
providers: [WechatTokenService, DailyQuestionPushService, VipExpiryService],
providers: [WechatTokenService, DailyQuestionPushService, VipExpiryService, GravityTopUpService],
})
export class ScheduleModule {}
+13 -4
View File
@@ -3,13 +3,20 @@ import { InjectModel } from '@nestjs/mongoose'
import { Model } from 'mongoose'
import { SiteConfig, SiteConfigDocument } from './site-config.schema'
export interface GravityRates {
interviewPerUse: number // 每次面试消耗引力值
optimizePerUse: number // 每次优化消耗引力值
downloadPerUse: number // 每次下载消耗引力值
}
interface PricingConfig {
interview: { pricePerSession: number; creditsPerPurchase: number }
resumeOptimize: { freeLimit: number; pricePerOptimize: number; creditsPerPurchase: number }
resumeDownload: { pricePerDownload: number; creditsPerPurchase: number }
gravityRates: GravityRates
plans: {
growth: { price: number; durationDays: number; credits: { interview: number; resumeOptimize: number; resumeDownload: number }; features: string[] }
sprint: { price: number; durationDays: number; credits: { interview: number; resumeOptimize: number; resumeDownload: number }; features: string[] }
growth: { price: number; durationDays: number; gravityPerMonth: number; credits: { interview: number; resumeOptimize: number; resumeDownload: number }; features: string[] }
sprint: { price: number; durationDays: number; gravityPerMonth: number; credits: { interview: number; resumeOptimize: number; resumeDownload: number }; features: string[] }
}
}
@@ -17,9 +24,10 @@ const DEFAULT_PRICING: PricingConfig = {
interview: { pricePerSession: 500, creditsPerPurchase: 1 },
resumeOptimize: { freeLimit: 3, pricePerOptimize: 300, creditsPerPurchase: 1 },
resumeDownload: { pricePerDownload: 200, creditsPerPurchase: 1 },
gravityRates: { interviewPerUse: 5, optimizePerUse: 3, downloadPerUse: 2 },
plans: {
growth: { price: 1990, durationDays: 30, credits: { interview: 999, resumeOptimize: 20, resumeDownload: 10 }, features: ['免费版全部权益', 'AI 数字人面试无限次', '详细面试报告(四维评分)', '进步轨迹雷达图 + 打卡', '每日一题推送', '参考回答思路', '公司真题库', '简历优化 20 次/月', '简历下载 10 次/月'] },
sprint: { price: 4990, durationDays: 30, credits: { interview: 999, resumeOptimize: 50, resumeDownload: 30 }, features: ['成长版全部权益', 'AI 语音分析(语气词/语速检测)', '技能缺口分析报告', '学习路径推荐', '真人导师 1v1 点评(每月 1 次)', '简历精修(每月 1 次)', '内推优先', '简历优化 50 次/月', '简历下载 30 次/月'] },
growth: { price: 1990, durationDays: 30, gravityPerMonth: 250, credits: { interview: 999, resumeOptimize: 20, resumeDownload: 10 }, features: ['免费版全部权益', 'AI 数字人面试每次 3 引力值(折扣价)', '详细面试报告(四维评分)', '进步轨迹雷达图 + 打卡', '每日一题推送', '参考回答思路', '公司真题库', '简历优化 20 次/月', '简历下载 10 次/月'] },
sprint: { price: 4990, durationDays: 30, gravityPerMonth: 600, credits: { interview: 999, resumeOptimize: 50, resumeDownload: 30 }, features: ['成长版全部权益', 'AI 语音分析(语气词/语速检测)', '技能缺口分析报告', '学习路径推荐', '真人导师 1v1 点评(每月 1 次)', '简历精修(每月 1 次)', '内推优先', '简历优化 50 次/月', '简历下载 30 次/月'] },
},
}
@@ -57,6 +65,7 @@ export class PricingService {
interview: { ...DEFAULT_PRICING.interview, ...value?.interview },
resumeOptimize: { ...DEFAULT_PRICING.resumeOptimize, ...value?.resumeOptimize },
resumeDownload: { ...DEFAULT_PRICING.resumeDownload, ...value?.resumeDownload },
gravityRates: { ...DEFAULT_PRICING.gravityRates, ...value?.gravityRates },
plans: {
growth: { ...DEFAULT_PRICING.plans.growth, ...value?.plans?.growth, credits: { ...DEFAULT_PRICING.plans.growth.credits, ...value?.plans?.growth?.credits } },
sprint: { ...DEFAULT_PRICING.plans.sprint, ...value?.plans?.sprint, credits: { ...DEFAULT_PRICING.plans.sprint.credits, ...value?.plans?.sprint?.credits } },
+26 -1
View File
@@ -1,9 +1,11 @@
import { Controller, Get, Post, Body, Param, Query, HttpException, HttpStatus, UseGuards } from '@nestjs/common'
import { Controller, Get, Post, Body, Param, Query, HttpException, HttpStatus, UseGuards, Req, Res } from '@nestjs/common'
import { Request, Response } from 'express'
import { JwtService } from '@nestjs/jwt'
import { ShareService } from './share.service'
import { JwtAuthGuard } from '../../common/guards/jwt-auth.guard'
import { CurrentUser } from '../../common/decorators/current-user.decorator'
import { Public } from '../../common/decorators/public.decorator'
import * as crypto from 'crypto'
@Controller('share')
export class ShareController {
@@ -66,4 +68,27 @@ export class ShareController {
) {
return this.shareService.visitors(userId, Number(page) || 1, Number(pageSize) || 20)
}
// 泛匹配路由放在最后,避免拦截 stats/records/visitors 等
@Public()
@Get(':shareCode')
async redirect(
@Param('shareCode') shareCode: string,
@Req() req: Request,
@Res() res: Response,
) {
try {
const ip = req.ip || req.socket?.remoteAddress || 'unknown'
const visitorId = crypto.createHash('md5').update(ip).digest('hex').slice(0, 16)
let visitorUserId: string | undefined
const token = req.query.token as string | undefined
if (token) {
try { const payload = this.jwtService.verify(token) as any; visitorUserId = payload.userId } catch {}
}
await this.shareService.visit(shareCode, visitorId, visitorUserId)
} catch (e) {
// 访问记录失败不影响跳转
}
res.redirect(HttpStatus.FOUND, `https://zhiyin.yzrcloud.cn/?share=${shareCode}`)
}
}
+6 -3
View File
@@ -83,8 +83,11 @@ export class ShareService {
if (todayCredited >= DAILY_LIMIT) return { dailyLimitReached: true, visitorUserId }
const shareCreditsResult = await this.quotaService.grantShareCredits(sharerIdStr)
if (!shareCreditsResult) return { creditFailed: true, visitorUserId }
try {
await this.quotaService.grantGravity(sharerIdStr, 1)
} catch (e) {
return { creditFailed: true, visitorUserId }
}
await this.visitModel.updateOne(
{ shareId: share._id, visitorId },
@@ -125,7 +128,7 @@ export class ShareService {
totalVisits: visitAgg[0]?.totalVisits ?? 0,
creditedCount: visitAgg[0]?.creditedCount ?? 0,
todayCredited: todayAgg,
shareCredits: user?.shareCredits ?? 0,
gravity: user?.gravity ?? 0,
}
}
+96 -71
View File
@@ -2,6 +2,7 @@ import { Injectable, HttpException, HttpStatus, Logger } from '@nestjs/common'
import { InjectModel } from '@nestjs/mongoose'
import { Model } from 'mongoose'
import { User, UserDocument } from './user.schema'
import { PricingService } from '../schemas/pricing.service'
const FREE_OPTIMIZE_LIMIT = 3
@@ -11,119 +12,143 @@ export class QuotaService {
constructor(
@InjectModel(User.name) private userModel: Model<UserDocument>,
private pricingService: PricingService,
) {}
/** 检查并扣除面试引力值(所有计划统一走引力值) */
async checkAndDeductInterview(userId: string) {
const user = await this.userModel.findById(userId).exec()
if (!user) throw new HttpException('用户不存在', HttpStatus.NOT_FOUND)
if (user.plan !== 'free') return
// Backward compat: migrate remaining → interviewCredits
if ((user.interviewCredits ?? 0) <= 0 && (user.remaining ?? 0) > 0) {
await this.userModel.findByIdAndUpdate(userId, {
$set: { interviewCredits: user.remaining, remaining: 0 },
}).exec()
// 迁移旧字段到 gravity
if ((user.gravity ?? 0) <= 0 && this.hasOldCredits(user)) {
await this.migrateOldCredits(userId)
}
const result = await this.userModel.findOneAndUpdate(
{ _id: userId, interviewCredits: { $gt: 0 } },
{ $inc: { interviewCredits: -1, interviewCount: 1 } },
{ new: true },
).exec()
const rates = (await this.pricingService.getConfig()).gravityRates
const cost = rates.interviewPerUse
// 用 gravity 支付,后备 shareCredits
const result = await this.deductGravityOrFallback(userId, cost)
if (result) return
// Fallback to share credits
const shareResult = await this.userModel.findOneAndUpdate(
{ _id: userId, shareCredits: { $gt: 0 } },
{ $inc: { shareCredits: -1, interviewCount: 1 } },
).exec()
if (shareResult) return
throw new HttpException('面试次数已用完,请购买面试次数或开通会员', HttpStatus.FORBIDDEN)
throw new HttpException('引力值不足,请充值或分享获取', HttpStatus.FORBIDDEN)
}
/** 检查并扣除优化引力值(所有计划统一走引力值) */
async checkAndDeductOptimize(userId: string) {
const user = await this.userModel.findById(userId).exec()
if (!user) throw new HttpException('用户不存在', HttpStatus.NOT_FOUND)
if (user.plan !== 'free') return
// Try paid credits first
const paid = await this.userModel.findOneAndUpdate(
{ _id: userId, resumeOptimizeCredits: { $gt: 0 } },
{ $inc: { resumeOptimizeCredits: -1 } },
).exec()
if (paid) return
// 迁移旧字段
if ((user.gravity ?? 0) <= 0 && this.hasOldCredits(user)) {
await this.migrateOldCredits(userId)
}
// Try old remaining credits (backward compat)
const oldRemaining = await this.userModel.findOneAndUpdate(
{ _id: userId, remaining: { $gt: 0 } },
{ $inc: { remaining: -1 } },
).exec()
if (oldRemaining) return
// Then free limit
// 免费优化次数
const freeResult = await this.userModel.findOneAndUpdate(
{ _id: userId, freeOptimizeUsed: { $lt: FREE_OPTIMIZE_LIMIT } },
{ $inc: { freeOptimizeUsed: 1 } },
).exec()
if (freeResult) return
// Fallback to share credits
const rates = (await this.pricingService.getConfig()).gravityRates
const cost = rates.optimizePerUse
const result = await this.deductGravityOrFallback(userId, cost)
if (result) return
throw new HttpException('引力值不足,请充值或分享获取', HttpStatus.FORBIDDEN)
}
/** 检查并扣除下载引力值 */
async checkAndDeductDownload(userId: string, paidDownload: boolean): Promise<boolean> {
if (paidDownload) return true
const rates = (await this.pricingService.getConfig()).gravityRates
const cost = rates.downloadPerUse
const result = await this.deductGravityOrFallback(userId, cost)
if (result) return true
return false
}
/** 从 gravity 扣除,后备从 shareCredits 扣除(兼容旧数据) */
private async deductGravityOrFallback(userId: string, cost: number): Promise<boolean> {
// 主路径:gravity
const gravResult = await this.userModel.findOneAndUpdate(
{ _id: userId, gravity: { $gte: cost } },
{ $inc: { gravity: -cost } },
).exec()
if (gravResult) return true
// 后备:旧 shareCredits
const shareResult = await this.userModel.findOneAndUpdate(
{ _id: userId, shareCredits: { $gt: 0 } },
{ $inc: { shareCredits: -1 } },
).exec()
if (shareResult) return
if (shareResult) return true
throw new HttpException('简历优化次数已用完,请购买优化次数或开通会员', HttpStatus.FORBIDDEN)
return false
}
async grantShareCredits(userId: string, amount = 1): Promise<boolean> {
const result = await this.userModel.findByIdAndUpdate(
userId,
{ $inc: { shareCredits: amount } },
).exec()
return !!result
}
async checkAndDeductDownload(userId: string, paidDownload: boolean): Promise<boolean> {
if (paidDownload) return true
const result = await this.userModel.findOneAndUpdate(
{ _id: userId, resumeDownloadCredits: { $gt: 0 } },
{ $inc: { resumeDownloadCredits: -1 } },
).exec()
return !!result
}
async grantCredits(userId: string, type: 'interview' | 'optimize' | 'download', amount: number) {
/** 增加引力值 */
async grantGravity(userId: string, amount: number) {
if (amount <= 0) throw new HttpException('无效数量', HttpStatus.BAD_REQUEST)
const fieldMap: Record<string, string> = {
interview: 'interviewCredits',
optimize: 'resumeOptimizeCredits',
download: 'resumeDownloadCredits',
}
const field = fieldMap[type]
if (!field) throw new HttpException('无效类型', HttpStatus.BAD_REQUEST)
const result = await this.userModel.findByIdAndUpdate(
userId,
{ $inc: { [field]: amount } },
{ $inc: { gravity: amount } },
).exec()
if (!result) throw new HttpException('用户不存在', HttpStatus.NOT_FOUND)
}
async setPlanQuota(userId: string, _plan: string, credits: { interview: number; resumeOptimize: number; resumeDownload: number }) {
/** 设置 VIP 套餐引力值额度 */
async setPlanQuota(userId: string, gravityAmount: number) {
const result = await this.userModel.findByIdAndUpdate(userId, {
$set: {
remaining: 999,
interviewCredits: credits.interview,
resumeOptimizeCredits: credits.resumeOptimize,
resumeDownloadCredits: credits.resumeDownload,
gravity: gravityAmount,
freeOptimizeUsed: FREE_OPTIMIZE_LIMIT,
},
}).exec()
if (!result) throw new HttpException('用户不存在', HttpStatus.NOT_FOUND)
}
/** 是否为非会员用户授予初始引力值 */
async grantFreeGravity(userId: string) {
await this.userModel.findByIdAndUpdate(userId, {
$set: { interviewCredits: 1, gravity: 5 },
}).exec()
}
/** 判断是否有旧额度需要迁移 */
private hasOldCredits(user: UserDocument): boolean {
return (user.interviewCredits ?? 0) > 0
|| (user.resumeOptimizeCredits ?? 0) > 0
|| (user.resumeDownloadCredits ?? 0) > 0
|| (user.remaining ?? 0) > 0
}
/** 迁移旧额度到 gravity */
private async migrateOldCredits(userId: string) {
const user = await this.userModel.findById(userId).exec()
if (!user) return
const interviewVal = (user.interviewCredits ?? 0) * 5
const optimizeVal = (user.resumeOptimizeCredits ?? 0) * 3
const downloadVal = (user.resumeDownloadCredits ?? 0) * 2
const oldRemainVal = (user.remaining ?? 0) * 5
const shareVal = (user.shareCredits ?? 0) * 1
const total = interviewVal + optimizeVal + downloadVal + oldRemainVal + shareVal
if (total <= 0) return
await this.userModel.findByIdAndUpdate(userId, {
$inc: { gravity: total },
$set: {
interviewCredits: 0,
resumeOptimizeCredits: 0,
resumeDownloadCredits: 0,
remaining: 0,
shareCredits: 0,
},
}).exec()
}
}
+10 -1
View File
@@ -1,7 +1,8 @@
import { Controller, Post, Get, Put, Body, Req, HttpCode, HttpStatus } from '@nestjs/common'
import { Controller, Post, Get, Put, Body, Req, HttpCode, HttpStatus, UseGuards } from '@nestjs/common'
import { UserService } from './user.service'
import { Public } from '../../common/decorators/public.decorator'
import { CurrentUser } from '../../common/decorators/current-user.decorator'
import { JwtAuthGuard } from '../../common/guards/jwt-auth.guard'
@Controller('user')
export class UserController {
@@ -29,6 +30,14 @@ export class UserController {
return this.userService.sendEmailCode(email)
}
/** 绑定微信 openid 到当前登录用户 */
@UseGuards(JwtAuthGuard)
@Post('bind-wx')
@HttpCode(HttpStatus.OK)
async bindWx(@CurrentUser('userId') userId: string, @Body('code') code: string) {
return this.userService.bindWxOpenid(userId, code)
}
@Public()
@Post('email-login')
@HttpCode(HttpStatus.OK)
+14 -4
View File
@@ -5,10 +5,10 @@ export type UserDocument = User & Document
@Schema({ timestamps: true })
export class User {
@Prop({ sparse: true })
@Prop({ unique: true, sparse: true })
phone?: string
@Prop({ sparse: true })
@Prop({ unique: true, sparse: true })
wxOpenid?: string
@Prop({ default: '' })
@@ -49,7 +49,10 @@ export class User {
freeOptimizeUsed: number // 已使用免费优化次数(上限 3
@Prop({ default: 0 })
shareCredits: number // 分享积分,每 3 次有效访问获 1 积分
gravity: number // 引力值(统一额度),面试 5、优化 3、下载 2
@Prop({ default: 0 })
shareCredits: number // 已合并到 gravity,保留字段防报错
@Prop({ default: 'user' })
role: string // 'user' | 'admin'
@@ -57,7 +60,7 @@ export class User {
@Prop({ default: false })
isSystemAdmin: boolean
@Prop({ sparse: true })
@Prop({ unique: true, sparse: true })
email?: string
@Prop({ default: '', select: false })
@@ -65,3 +68,10 @@ export class User {
}
export const UserSchema = SchemaFactory.createForClass(User)
UserSchema.pre('save', function (next) {
if (!this.phone && !this.wxOpenid && !this.email) {
return next(new Error('用户必须至少有一个联系方式(手机号/微信/邮箱)'))
}
next()
})
+50 -6
View File
@@ -46,14 +46,13 @@ export class UserService {
let user = await this.userModel.findOne({ phone }).exec()
if (!user) {
user = await this.userModel.create({ phone, nickname: `用户${phone.slice(-4)}` })
user = await this.userModel.create({ phone, nickname: `用户${phone.slice(-4)}`, gravity: 5 })
}
return this.generateAuthResponse(user)
}
async loginByWx(code: string) {
// WeChat silent login - exchange code for openid
async loginByWx(code: string, userId?: string) {
const appid = process.env.WX_APPID
const secret = process.env.WX_SECRET
if (!appid || !secret) {
@@ -70,15 +69,59 @@ export class UserService {
}
const openid = wxData.openid
if (userId) {
const user = await this.userModel.findById(userId).exec()
if (!user) throw new HttpException('用户不存在', HttpStatus.NOT_FOUND)
if (user.wxOpenid) throw new HttpException('该账号已绑定微信', HttpStatus.CONFLICT)
user.wxOpenid = openid
await user.save()
return this.generateAuthResponse(user)
}
let user = await this.userModel.findOne({ wxOpenid: openid }).exec()
if (!user) {
user = await this.userModel.create({ wxOpenid: openid, nickname: '微信用户' })
user = await this.userModel.create({ wxOpenid: openid, nickname: '微信用户', gravity: 5 })
}
return this.generateAuthResponse(user)
}
// 📧 邮箱验证码
async bindWxOpenid(userId: string, code: string) {
this.logger.log(`[bindWx] userId=${userId}, code=${code ? '已提供' : '空'}`)
const appid = process.env.WX_APPID
const secret = process.env.WX_SECRET
if (!appid || !secret) {
this.logger.error(`[bindWx] 微信配置不完整`)
throw new HttpException('微信登录未配置', HttpStatus.SERVICE_UNAVAILABLE)
}
const wxRes = await fetch(
`https://api.weixin.qq.com/sns/jscode2session?appid=${appid}&secret=${secret}&js_code=${code}&grant_type=authorization_code`,
)
const wxData: any = await wxRes.json()
this.logger.log(`[bindWx] 微信接口返回: ${JSON.stringify(wxData)}`)
if (wxData.errcode) {
this.logger.error(`[bindWx] 微信登录失败: ${wxData.errmsg}, rid: ${wxData.rid || '无'}`)
throw new HttpException(`微信登录失败: ${wxData.errmsg}`, HttpStatus.UNAUTHORIZED)
}
const openid = wxData.openid
this.logger.log(`[bindWx] 获取到openid=${openid}`)
const existing = await this.userModel.findOne({ wxOpenid: openid }).exec()
if (existing) {
this.logger.warn(`[bindWx] openid=${openid} 已绑定到其他用户 ${existing._id}`)
throw new HttpException('该微信号已绑定其他账号', HttpStatus.CONFLICT)
}
const user = await this.userModel.findByIdAndUpdate(userId, { wxOpenid: openid }, { new: true }).exec()
if (!user) { this.logger.error(`[bindWx] 用户不存在 userId=${userId}`); throw new HttpException('用户不存在', HttpStatus.NOT_FOUND) }
this.logger.log(`[bindWx] openid=${openid} 绑定到用户 ${userId} 成功`)
return { message: '微信绑定成功', wxOpenid: openid }
}
async sendEmailCode(email: string) {
if (!email || !email.includes('@')) {
throw new HttpException('请输入正确的邮箱地址', HttpStatus.BAD_REQUEST)
@@ -113,7 +156,7 @@ export class UserService {
if (!user) {
isNew = true
const nick = email.split('@')[0]
user = await this.userModel.create({ email, nickname: nick, remaining: 3 })
user = await this.userModel.create({ email, nickname: nick, remaining: 0, gravity: 5 })
}
return { ...this.generateAuthResponse(user), isNew, hasPassword: !!user.password }
}
@@ -148,7 +191,7 @@ export class UserService {
}
const nick = email.split('@')[0]
const hashed = await bcrypt.hash(password, 10)
const user = await this.userModel.create({ email, nickname: nick, password: hashed, remaining: 3 })
const user = await this.userModel.create({ email, nickname: nick, password: hashed, remaining: 0, gravity: 5 })
return this.generateAuthResponse(user)
}
@@ -216,6 +259,7 @@ export class UserService {
resumeDownloadCredits: user.resumeDownloadCredits ?? 0,
freeOptimizeUsed: user.freeOptimizeUsed ?? 0,
shareCredits: user.shareCredits ?? 0,
gravity: user.gravity ?? 0,
}
}
}
+12 -10
View File
@@ -1,8 +1,8 @@
# 职引项目 · 状态报告 v4.5
# 职引项目 · 状态报告 v4.6
> **项目版本**: v4.5
> **更新时间**: 2026-06-17
> **项目状态**: ✅ 面试复盘上线 + AI 择业顾问 MVP
> **项目版本**: v4.6
> **更新时间**: 2026-06-19
> **项目状态**: ✅ 引力值体系统一 + 管理后台完善
---
@@ -76,8 +76,10 @@
| 功能 | 后端 | 前端 | 状态 |
|------|------|------|------|
| 免费版额度(日2次/5轮) | ✅ | ✅ | **完成** |
| 成长版 ¥19.9/月 | ✅ | ✅ | **完成** |
| 冲刺版 ¥49.9/月(含权益扣减) | ✅ | ✅ | **完成** |
| 成长版 ¥19.9/月250 引力值) | ✅ | ✅ | **完成** |
| 冲刺版 ¥49.9/月600 引力值) | ✅ | ✅ | **完成** |
| 引力值统一体系(取消 VIP 无限面试) | ✅ | ✅ | **完成** |
| 会员月度引力值自动配发(cron) | ✅ | N/A | **完成** |
| 微信支付 Native QR / JSAPI | ✅ | ✅ H5+MP | **完成** |
| 支付回调/自动开会员 | ✅ | N/A | **完成** |
| 每日一题定时推送 | ✅ | N/A | **完成**(需配置模板ID |
@@ -174,7 +176,7 @@
| `payment` | controller + service + schema | ✅ | 微信支付 v3,含证书 |
| `progress` | controller + schema + benchmark service | ✅ | 打卡/积分/基准/匹配 |
| `contribution` | controller + schema (×2) | ✅ | 面经 + AI 结构化 + 公司题库 |
| `schedule` | module + service (×3) | ✅ | VIP 过期 / 每日一题 / 微信 token |
| `schedule` | module + service (×4) | ✅ | VIP 过期 / 每日一题 / 微信 token / 月度引力值补给 |
| `interview-review` | controller + service + schema + asr service | ✅ | 面试复盘:音频 ASR + AI 评析 + 口语分析 |
| `career-advice` | controller + service + module | ✅ | AI 择业顾问:专业分析 + 岗位匹配 + 多轮对话 |
| `admin` | controller + module | ✅ | 管理后台 |
@@ -200,7 +202,7 @@
| 面试复盘 | review/review | ✅ 三种模式(列表/上传/报告) |
| 择业顾问 | career/career | ✅ AI 专业分析 + 岗位匹配 + 多轮对话 |
| 实习搜索 | internship/internship | ✅ 热门岗位 |
| 管理后台 | admin/admin | ✅ 仪表盘 |
| 管理后台 | admin/admin | ✅ 仪表盘/用户/面试/简历/订单/定价/分享/岗位/诊断/管理员 · 全 CRUD |
| 关于/协议/隐私 | about/agreement/privacy | ✅ |
---
@@ -217,11 +219,11 @@
---
## 十、变更记录
| 2026-06-17 | v4.5 | AI 择业顾问 MVP:后端模块 + 前端职业分析页面 + 热门岗位联动 | AI |
| 日期 | 版本 | 变更内容 | 操作者 |
|------|------|----------|--------|
| 2026-06-02 | v1.0 | 项目状态初版 | AI |
| 2026-06-19 | v4.6 | 引力值体系统一:VIP 取消无限面试改为月度引力值消耗;管理后台全面完善(搜索/筛选/分页/CRUD/分析tab/岗位描述字段) | AI |
| 2026-06-17 | v4.5 | AI 择业顾问 MVP:后端模块 + 前端职业分析页面 + 热门岗位联动 | AI |
| 2026-06-05 | v2.0 | 战略升级:文档重构 + 新增功能启动 | 小之 |
| 2026-06-09 | v4.2 | 冲刺版+每日推送+支付修复+全量代码评审 | AI |
| 2026-06-11 | v4.3 | 安全修复 5 项 + 代码质量 14 处 + 测试体系 61 项 + 护城河 P0-P5 全部验证 | AI |
+21 -4
View File
@@ -1,13 +1,32 @@
<script setup lang="ts">
import { onLaunch, onShow, onHide } from '@dcloudio/uni-app'
import { onLaunch } from '@dcloudio/uni-app'
onLaunch(() => {
console.log('职引 App launched')
// #ifdef MP-WEIXIN
initPrivacy()
// #endif
// #ifdef H5
handleH5UrlParams()
// #endif
})
// #ifdef H5
function handleH5UrlParams() {
const params = new URLSearchParams(window.location.search)
const token = params.get('token')
const buy = params.get('buy')
if (token) {
uni.setStorageSync('token', token)
}
if (buy === 'gravity') {
// 延迟等 app 初始化完成再跳转
setTimeout(() => {
uni.navigateTo({ url: '/pages/member/member' })
}, 300)
}
}
// #endif
// #ifdef MP-WEIXIN
function initPrivacy() {
if (wx.onNeedPrivacyAuthorization) {
@@ -29,8 +48,6 @@ function initPrivacy() {
}
}
// #endif
onShow(() => { console.log('职引 App shown') })
onHide(() => { console.log('职引 App hidden') })
</script>
<style>
@@ -0,0 +1,193 @@
import { ref, computed, nextTick } from 'vue'
import { api } from '../config'
export function useGravityPurchase(onPaymentSuccess?: () => void) {
const showQuantityModal = ref(false)
const buyQuantity = ref(1)
const products = ref<any[]>([])
const buyProductType = ref('interview')
const payLoading = ref(false)
const payError = ref('')
const showPayModal = ref(false)
const payCodeUrl = ref('')
const currentOutTradeNo = ref('')
const isMp = ref(false)
const paySuccess = ref(false)
const unitPrice = computed(() => {
const p = products.value.find(p => p.type === buyProductType.value)
return p?.price || 0
})
const totalPrice = computed(() => unitPrice.value * buyQuantity.value / 100)
const buyGravityPerUnit = computed(() => {
const p = products.value.find(p => p.type === buyProductType.value)
return p?.gravity || 0
})
const changeQty = (delta: number) => {
const next = buyQuantity.value + delta
if (next >= 1 && next <= 99) buyQuantity.value = next
}
const clampQty = () => {
if (buyQuantity.value < 1) buyQuantity.value = 1
if (buyQuantity.value > 99) buyQuantity.value = 99
}
const loadProducts = async () => {
try {
const res = await uni.request({ url: api('/member/plans'), method: 'GET' })
if (res.statusCode >= 200 && res.statusCode < 300 && res.data?.products) {
const prodList: any[] = []
for (const [key, val] of Object.entries(res.data.products as Record<string, any>)) {
if (val?.price > 0) prodList.push({ type: key, ...val })
}
products.value = prodList
}
} catch (e) { /* silent */ }
}
const openGravityPurchase = async (productType = 'interview') => {
buyProductType.value = productType
buyQuantity.value = 1
// #ifdef MP-WEIXIN
isMp.value = true
// #endif
// 加载产品信息
await loadProducts()
showQuantityModal.value = true
}
const cancelPay = () => {
showPayModal.value = false
payCodeUrl.value = ''
payLoading.value = false
payError.value = ''
}
const confirmProductBuy = () => {
showQuantityModal.value = false
startProductPay(buyProductType.value, buyQuantity.value)
}
const startProductPay = async (type: string, quantity = 1) => {
const token = uni.getStorageSync('token') || ''
if (!token) {
uni.showToast({ title: '请先登录', icon: 'none' })
return
}
showPayModal.value = true
payLoading.value = true
payError.value = ''
if (isMp.value) {
try {
let res = await uni.request({
url: api('/payment/jsapi-product'), method: 'POST',
data: { type, quantity },
header: { 'Authorization': `Bearer ${token}`, 'Content-Type': 'application/json' },
timeout: 30000,
})
payLoading.value = false
if (res.statusCode >= 200 && res.statusCode < 300 && res.data?.payParams) {
const pp = res.data.payParams as any
currentOutTradeNo.value = res.data.outTradeNo || ''
uni.requestPayment({
provider: 'wxpay',
timeStamp: pp.timeStamp,
nonceStr: pp.nonceStr,
package: pp.package,
signType: pp.signType || 'RSA',
paySign: pp.paySign,
success: () => {
const no = currentOutTradeNo.value || res.data.outTradeNo
pollPayResult(no)
},
fail: () => {
payError.value = '支付未完成'
uni.showToast({ title: '支付未完成', icon: 'none' })
},
})
} else if (!res.statusCode || res.statusCode === 0) {
payError.value = '网络连接失败,请检查网络后重试'
uni.showToast({ title: '网络连接失败', icon: 'none' })
} else {
const errMsg = res.data?.message || '购买失败'
payError.value = errMsg
uni.showToast({ title: errMsg, icon: 'none' })
}
} catch (e) {
payLoading.value = false
payError.value = '网络错误,请重试'
uni.showToast({ title: '网络错误', icon: 'none' })
}
} else {
try {
const res = await uni.request({
url: api('/payment/create-product'), method: 'POST',
data: { type, quantity },
header: { 'Authorization': `Bearer ${token}`, 'Content-Type': 'application/json' },
})
payLoading.value = false
if (res.statusCode >= 200 && res.statusCode < 300 && res.data?.codeUrl) {
payCodeUrl.value = res.data.codeUrl
currentOutTradeNo.value = res.data.outTradeNo
// 页面需要自己渲染二维码(依赖 uqrcode)
pollPayResult(res.data.outTradeNo)
} else if (!res.statusCode || res.statusCode === 0) {
payError.value = '网络连接失败,请检查网络后重试'
uni.showToast({ title: '网络连接失败', icon: 'none' })
} else {
payError.value = res.data?.message || '购买失败'
uni.showToast({ title: res.data?.message || '购买失败', icon: 'none' })
}
} catch (e) {
payLoading.value = false
payError.value = '网络错误,请重试'
uni.showToast({ title: '网络错误', icon: 'none' })
}
}
}
const pollPayResult = async (outTradeNo: string) => {
if (!outTradeNo) return
const maxAttempts = 30
let attempts = 0
const token = uni.getStorageSync('token') || ''
const poll = async () => {
attempts++
try {
const res = await uni.request({
url: api(`/payment/check/${outTradeNo}`), method: 'GET',
header: { 'Authorization': `Bearer ${token}` },
})
if (res.statusCode >= 200 && res.statusCode < 300 && res.data?.status === 'success') {
paySuccess.value = true
showPayModal.value = false
uni.showToast({ title: '充值成功!', icon: 'success' })
onPaymentSuccess?.()
return
}
} catch (e) { /* ignore */ }
if (attempts < maxAttempts) {
setTimeout(poll, 2000)
} else {
payError.value = '支付结果查询超时,请联系客服'
uni.showToast({ title: '支付查询超时', icon: 'none' })
}
}
setTimeout(poll, 2000)
}
return {
showQuantityModal, buyQuantity, products, buyProductType,
unitPrice, totalPrice, buyGravityPerUnit,
payLoading, payError, showPayModal, payCodeUrl, paySuccess,
isMp,
changeQty, clampQty, loadProducts, openGravityPurchase,
confirmProductBuy, cancelPay,
}
}
+2 -2
View File
@@ -1,8 +1,8 @@
{
"name": "宇之然AI磁场",
"appid": "__UNI__DEV__",
"versionName": "1.0.12",
"versionCode": "112",
"versionName": "1.0.15",
"versionCode": "115",
"description": "职引 - 宇之然AI磁场旗下AI模拟面试平台,提供AI面试官模拟练习、简历智能优化、大厂面经题库,助你轻松应对校招面试。",
"h5": {
"title": "职引 - AI模拟面试 | 宇之然AI磁场",
+15
View File
@@ -17,6 +17,15 @@
<text class="info-value">contact@yuzhiran.com</text>
</view>
<!-- #ifdef MP-WEIXIN -->
<button class="contact-btn" open-type="contact">
<view class="contact-btn-inner">
<text class="contact-icon">💬</text>
<text class="contact-text">联系在线客服</text>
</view>
</button>
<!-- #endif -->
<view class="link-section">
<view class="link-item" @click="goAgreement">
<text class="link-text">用户协议</text>
@@ -59,4 +68,10 @@ const goPrivacy = () => uni.navigateTo({ url: '/pages/privacy/privacy' })
.disclaimer { margin-top: 40rpx; background: #FFF8E1; border-radius: var(--radius-md); padding: 24rpx; }
.disclaimer-title { font-size: 24rpx; font-weight: 700; color: #F59E0B; display: block; margin-bottom: 12rpx; }
.disclaimer-text { font-size: 22rpx; color: var(--color-text-secondary); line-height: 1.8; }
.contact-btn { width: 100%; background: #FFF; border: none; border-radius: var(--radius-md); padding: 0; margin-bottom: 12rpx; }
.contact-btn-inner { display: flex; align-items: center; gap: 16rpx; padding: 24rpx 30rpx; }
.contact-btn:active { opacity: 0.7; }
.contact-icon { font-size: 28rpx; }
.contact-text { font-size: 26rpx; color: var(--color-text); }
</style>
+335 -57
View File
@@ -22,7 +22,8 @@
<text class="tab" :class="{ active: tab === 'pricing' }" @click="switchTab('pricing')">定价</text>
<text class="tab" :class="{ active: tab === 'share' }" @click="switchTab('share')">分享</text>
<text class="tab" :class="{ active: tab === 'positions' }" @click="switchTab('positions')">岗位</text>
<text class="tab" :class="{ active: tab === 'admins' }" @click="switchTab('admins')">管理</text>
<text class="tab" :class="{ active: tab === 'analysis' }" @click="switchTab('analysis')">诊断</text>
<text class="tab" :class="{ active: tab === 'admins' }" @click="switchTab('admins')">管理员</text>
</view>
<!-- 概览 -->
@@ -44,6 +45,23 @@
<text class="stat-sub">付费下载 {{ overview.paidDownloadCount ?? 0 }}</text>
</view>
</view>
<view class="stat-cards" style="margin-top:12rpx">
<view class="stat-card">
<text class="stat-num">{{ overview.orderCount ?? 0 }}</text>
<text class="stat-label">总订单</text>
<text class="stat-sub">今日 +{{ overview.todayOrders ?? 0 }}</text>
</view>
<view class="stat-card">
<text class="stat-num">{{ overview.totalRevenue ? '¥' + (overview.totalRevenue / 100).toFixed(1) : '¥0' }}</text>
<text class="stat-label">总营收</text>
<text class="stat-sub">已支付订单合计</text>
</view>
<view class="stat-card" v-if="!(overview.orderCount)">
<text class="stat-num">--</text>
<text class="stat-label">--</text>
<text class="stat-sub" />
</view>
</view>
<view class="plan-cards">
<view class="plan-card" v-for="(cnt, plan) in overview.planBreakdown" :key="plan">
<text class="plan-num">{{ cnt }}</text>
@@ -63,13 +81,22 @@
<view class="user-main">
<text class="user-phone">{{ u.phone || '--' }}</text>
<text class="user-name">{{ u.nickname || '--' }}</text>
<text class="user-badge-role" v-if="u.role === 'admin'">管理</text>
</view>
<view class="user-badges">
<text class="user-plan" :class="{ vip: u.plan === 'growth' || u.plan === 'sprint' }">{{ u.plan === 'growth' || u.plan === 'sprint' ? '会员' : '免费' }}</text>
<text class="user-credit">面试:{{ u.interviewCredits ?? 0 }}</text>
<text class="user-credit">优化:{{ u.resumeOptimizeCredits ?? 0 }}</text>
<text class="user-credit">下载:{{ u.resumeDownloadCredits ?? 0 }}</text>
<text class="user-credit share">分享:{{ u.shareCredits ?? 0 }}</text>
<view class="user-meta-row">
<text class="meta-tag email" v-if="u.email">{{ u.email }}</text>
<text class="meta-tag" v-if="u.wxOpenid">openid:{{ u.wxOpenid.slice(0,12) }}..</text>
</view>
<view class="user-meta-row">
<text class="meta-tag">引力:{{ u.gravity ?? 0 }}</text>
<text class="meta-tag">面试:{{ u.interviewCount ?? 0 }}</text>
<text class="user-plan" :class="{ vip: u.plan === 'growth' || u.plan === 'sprint' }">{{ u.plan === 'growth' || u.plan === 'sprint' ? u.plan==='sprint'?'冲刺':'会员' : '免费' }}</text>
<text class="meta-tag share" v-if="u.shareCredits > 0">分享:{{ u.shareCredits }}</text>
</view>
<view class="user-meta-row time-row">
<text class="time-label">注册:{{ u.createdAt?.slice(0,16).replace('T',' ') }}</text>
<text class="time-label" v-if="u.vipExpireAt">到期:{{ u.vipExpireAt?.slice(0,10) }}</text>
<text class="time-label" v-if="u.sprintExpireAt">冲刺到期:{{ u.sprintExpireAt?.slice(0,10) }}</text>
</view>
<view class="user-actions">
<text class="user-action-btn" v-if="u.plan === 'free'" @click="setVip(u._id)">设为会员</text>
@@ -83,37 +110,62 @@
<!-- 面试 -->
<view v-if="tab === 'interviews'" class="section">
<view class="search-bar">
<input v-model="ivKeyword" placeholder="搜索岗位/用户名" class="search-input" @confirm="loadInterviews" />
<picker :range="['全部状态','进行中','已完成']" @change="e => { ivStatusFilter=e.detail.value; loadInterviews() }">
<text class="search-btn">{{ ['全部状态','进行中','已完成'][ivStatusFilter] }}</text>
</picker>
</view>
<view class="iv-list" v-if="!ivLoading">
<view class="iv-row" v-for="iv in interviews" :key="iv._id">
<view class="iv-main">
<text class="iv-pos">{{ iv.position }}</text>
<text class="iv-user">{{ iv.userId?.phone || iv.userId?.nickname || '--' }}</text>
<text class="iv-user email" v-if="iv.userId?.email">{{ iv.userId.email }}</text>
</view>
<view class="iv-meta">
<text class="iv-status" :class="{ done: iv.status === 'completed' }">{{ iv.status === 'completed' ? '已完成' : '进行中' }}</text>
<text class="iv-tag">{{ iv.questionCount || 0 }}</text>
<text class="iv-tag score">得分 {{ iv.totalScore ?? '-' }}</text>
<text class="iv-tag filler" v-if="iv.fillerScore != null && iv.fillerScore > 0">分析 {{ iv.fillerScore }}/{{ iv.fillerDensity ?? '-' }}</text>
<text class="iv-tag filler" v-if="iv.fillerScore != null && iv.fillerScore > 0"> {{ iv.fillerScore }}/{{ iv.fillerDensity ?? '-' }}</text>
</view>
<view class="iv-meta">
<text class="time-label">开始:{{ iv.createdAt?.slice(0,16).replace('T',' ') }}</text>
<text class="time-label" v-if="iv.updatedAt && iv.updatedAt !== iv.createdAt">更新:{{ iv.updatedAt?.slice(0,16).replace('T',' ') }}</text>
</view>
<text class="iv-summary" v-if="iv.summary">{{ iv.summary.slice(0,60) }}{{ iv.summary.length > 60 ? '...' : '' }}</text>
</view>
<text class="load-more" v-if="ivTotal > interviews.length" @click="loadMoreInterviews">加载更多</text>
<text class="empty-text" v-if="interviews.length === 0 && !ivLoading">暂无面试记录</text>
</view>
<text class="loading-text" v-if="ivLoading">加载中...</text>
</view>
<!-- 简历 -->
<view v-if="tab === 'resumes'" class="section">
<view class="search-bar">
<input v-model="resumeKeyword" placeholder="搜索简历标题" class="search-input" @confirm="loadResumes" />
<text class="search-btn" @click="loadResumes">搜索</text>
</view>
<view class="resume-list" v-if="!resumeLoading">
<view class="resume-row" v-for="r in resumes" :key="r._id">
<view class="resume-main">
<text class="resume-title">{{ r.title }}</text>
<text class="resume-user">{{ r.userId?.phone || r.userId?.nickname || '--' }}</text>
<text class="resume-user email" v-if="r.userId?.email">{{ r.userId.email }}</text>
</view>
<view class="resume-meta">
<text class="resume-tag">v{{ r.version }}</text>
<text class="resume-tag" v-if="r.targetPosition">{{ r.targetPosition }}</text>
<text class="resume-tag paid" v-if="r.paidDownload">付费下载</text>
</view>
<text class="resume-time">{{ r.createdAt?.slice(0,10) }}</text>
<view class="resume-meta time-row">
<text class="time-label">创建:{{ r.createdAt?.slice(0,16).replace('T',' ') }}</text>
<text class="time-label" v-if="r.updatedAt && r.updatedAt !== r.createdAt">更新:{{ r.updatedAt?.slice(0,16).replace('T',' ') }}</text>
</view>
<view class="resume-actions">
<text class="admin-action-btn del" @click="deleteResume(r._id, r.title)">删除</text>
</view>
</view>
</view>
<text class="loading-text" v-if="resumeLoading">加载中...</text>
@@ -133,18 +185,35 @@
<view class="order-list" v-if="!orderLoading">
<view class="order-row" v-for="o in orders" :key="o._id">
<view class="order-info">
<text class="order-id">订单号: {{ o.outTradeNo }}</text>
<text class="order-user">用户: {{ o.userPhone || o.userId.slice(-6) }}</text>
</view>
<view class="order-meta">
<text class="order-amount">¥{{ (o.amount / 100).toFixed(1) }}</text>
<view class="order-status" :class="o.status === 'success' ? 'paid' : o.status === 'refunded' ? 'refund' : 'pend'">
<text class="order-id">{{ o.outTradeNo }}</text>
<view class="order-status rp" :class="o.status === 'success' ? 'paid' : o.status === 'refunded' ? 'refund' : 'pend'">
{{ o.status === 'success' ? '已支付' : o.status === 'refunded' ? '已退款' : '待支付' }}
</view>
<text class="order-time">{{ o.createdAt ? o.createdAt.slice(0,16).replace('T',' ') : '--' }}</text>
<view class="order-actions" v-if="o.status === 'pending'">
<text class="sync-btn" @click="syncOrder(o.outTradeNo)">同步</text>
</view>
</view>
<view class="order-meta-row">
<text class="order-title">{{ o.title || '--' }}</text>
<text class="order-user">用户: {{ o.userPhone || o.userId?.slice(-6) }}</text>
</view>
<view class="order-meta-row">
<text class="order-amount">¥{{ (o.amount / 100).toFixed(1) }}</text>
<text class="meta-tag">类型:{{ o.type || '--' }}</text>
<text class="meta-tag">渠道:{{ o.channel || '--' }}</text>
</view>
<view class="order-meta-row time-row">
<text class="time-label">创建:{{ o.createdAt?.slice(0,16).replace('T',' ') }}</text>
<text class="time-label" v-if="o.paidAt">支付:{{ o.paidAt?.slice(0,16).replace('T',' ') }}</text>
</view>
<view class="order-meta-row" v-if="o.wxTransactionId">
<text class="time-label">微信单号:{{ o.wxTransactionId }}</text>
</view>
<view class="order-meta-row" v-if="o.status === 'refunded'">
<text class="time-label refund-label">退款:¥{{ (o.refundAmount/100).toFixed(1) }} {{ o.refundedAt?.slice(0,16).replace('T',' ') }}</text>
<text class="time-label" v-if="o.refundReason">原因:{{ o.refundReason }}</text>
</view>
<view class="order-actions-bar">
<text class="sync-btn" v-if="o.status === 'pending'" @click="syncOrder(o.outTradeNo)">同步</text>
<text class="refund-btn" v-if="o.status === 'success'" @click="openRefundModal(o)">退款</text>
<text class="sync-btn" v-if="o.status === 'refunded'" @click="queryRefund(o.outTradeNo)">查询</text>
</view>
</view>
<text class="load-more" v-if="ordersTotal > orders.length" @click="loadMoreOrders">加载更多</text>
@@ -174,12 +243,32 @@
</view>
</view>
<view class="config-card">
<view class="cfg-title">引力值消耗</view>
<view class="cfg-row">
<text>面试消耗引力值/</text>
<input class="cfg-input" type="digit" v-model.number="pricing.gravityRates.interviewPerUse" />
</view>
<view class="cfg-row">
<text>优化消耗引力值/</text>
<input class="cfg-input" type="digit" v-model.number="pricing.gravityRates.optimizePerUse" />
</view>
<view class="cfg-row">
<text>下载消耗引力值/</text>
<input class="cfg-input" type="digit" v-model.number="pricing.gravityRates.downloadPerUse" />
</view>
</view>
<view class="config-card">
<view class="cfg-title">成长版 ¥{{ growthPriceDisplay }}</view>
<view class="cfg-row">
<text>价格/</text>
<input class="cfg-input" type="digit" v-model.number="growthPriceTemp" />
</view>
<view class="cfg-row">
<text>每月引力值</text>
<input class="cfg-input" type="digit" v-model.number="pricing.plans.growth.gravityPerMonth" />
</view>
<view class="cfg-row">
<text>面试额度/</text>
<input class="cfg-input" type="digit" v-model.number="pricing.plans.growth.credits.interview" />
@@ -205,7 +294,9 @@
<input class="cfg-input" type="digit" v-model.number="sprintPriceTemp" />
</view>
<view class="cfg-row">
<text>面试额度/</text>
<text>每月引力值</text>
<input class="cfg-input" type="digit" v-model.number="pricing.plans.sprint.gravityPerMonth" />
</view>
<input class="cfg-input" type="digit" v-model.number="pricing.plans.sprint.credits.interview" />
</view>
<view class="cfg-row">
@@ -244,13 +335,19 @@
<view class="share-row" v-for="r in shareRecords" :key="r.shareCode">
<view class="share-main">
<text class="share-title">{{ r.title }}</text>
<text class="share-meta">{{ r.sharer?.nickname || '--' }} · {{ r.type }}</text>
<text class="share-meta">{{ r.sharer?.phone || r.sharer?.nickname || '--' }} · {{ r.type }}</text>
</view>
<view class="share-meta-row">
<text class="meta-tag">code:{{ r.shareCode }}</text>
<text class="meta-tag" :class="r.isActive ? 'badge-done' : 'badge-pend'">{{ r.isActive ? '启用' : '停用' }}</text>
</view>
<view class="share-stats">
<text>访问 {{ r.visitCount }}</text>
<text class="share-credited">有效 {{ r.creditedCount }}</text>
</view>
<text class="share-time">{{ r.createdAt?.slice(0,16).replace('T',' ') }}</text>
<view class="share-meta-row time-row">
<text class="time-label">创建:{{ r.createdAt?.slice(0,16).replace('T',' ') }}</text>
</view>
</view>
</view>
<text class="loading-text" v-if="shareLoading">加载中...</text>
@@ -260,13 +357,17 @@
<view class="share-list" v-if="!shareLoading">
<view class="share-row" v-for="(v, i) in shareVisitors" :key="i">
<view class="share-main">
<text>分享者: {{ v.sharer?.nickname || '--' }}</text>
<text class="share-meta">访客: {{ v.visitor?.nickname || '匿名' }}</text>
<text>分享者:{{ v.sharer?.phone || v.sharer?.nickname || '--' }}</text>
<text class="share-meta">访客:{{ v.visitor?.phone || v.visitor?.nickname || '匿名' }}</text>
</view>
<view class="share-stats">
<text class="badge" :class="v.credited ? 'badge-done' : 'badge-pend'">{{ v.credited ? '已积分' : '未积分' }}</text>
<view class="share-meta-row">
<text class="meta-tag">IP:{{ v.visitorId || '--' }}</text>
<text class="meta-tag" :class="v.credited ? 'badge-done' : 'badge-pend'">{{ v.credited ? '已积分' : '未积分' }}</text>
</view>
<view class="share-meta-row time-row">
<text class="time-label">访问:{{ v.createdAt?.slice(0,16).replace('T',' ') }}</text>
<text class="time-label" v-if="v.creditedAt">积分:{{ v.creditedAt?.slice(0,16).replace('T',' ') }}</text>
</view>
<text class="share-time">{{ v.createdAt?.slice(0,16).replace('T',' ') }}</text>
</view>
</view>
<text class="loading-text" v-if="shareLoading">加载中...</text>
@@ -298,13 +399,27 @@
<text class="loading-text" v-if="posLoading">加载中...</text>
</view>
<!-- 诊断分析 -->
<view v-if="tab === 'analysis'" class="section">
<view class="config-card">
<view class="cfg-title">简历诊断</view>
<view class="cfg-row"><text>总诊断次数</text><text class="cfg-val">{{ analysisStats.totalDiagnoses ?? 0 }}</text></view>
<view class="cfg-row"><text>今日诊断</text><text class="cfg-val">{{ analysisStats.todayDiagnoses ?? 0 }}</text></view>
</view>
<view class="config-card">
<view class="cfg-title">技能缺口分析</view>
<view class="cfg-row"><text>总分析次数</text><text class="cfg-val">{{ analysisStats.totalGapAnalysis ?? 0 }}</text></view>
</view>
<text class="loading-text" v-if="analysisLoading">加载中...</text>
</view>
<!-- 额度调整弹窗 -->
<view class="modal-mask" v-if="creditModal.show" @click="closeCreditModal">
<view class="modal-content" @click.stop>
<text class="modal-title">调整 {{ creditModal.user?.nickname || '用户' }} 的额度</text>
<view class="cfg-row" v-for="t in creditTypes" :key="t.key">
<text>{{ t.label }}</text>
<input class="cfg-input" type="digit" v-model.number="t.value" :placeholder="t.key" />
<view class="cfg-row">
<text>引力值</text>
<input class="cfg-input" type="digit" v-model.number="creditGravity" />
</view>
<view class="modal-actions">
<button class="modal-btn cancel" @click="closeCreditModal">取消</button>
@@ -331,6 +446,10 @@
<text class="cfg-val">{{ posForm.active ? '启用' : '停用' }}</text>
</picker>
</view>
<view class="cfg-row"><text>岗位描述</text></view>
<textarea class="cfg-textarea" v-model="posForm.description" placeholder="岗位职责描述,每行一个要点" />
<view class="cfg-row"><text>任职要求</text></view>
<textarea class="cfg-textarea" v-model="posForm.requirements" placeholder="任职资格要求,每行一个要点" />
<view class="modal-actions">
<button class="modal-btn cancel" @click="closePositionModal">取消</button>
<button class="modal-btn confirm" @click="savePosition">保存</button>
@@ -338,6 +457,29 @@
</view>
</view>
<!-- 退款弹窗 -->
<view class="modal-mask" v-if="refundModal.show" @click="closeRefundModal">
<view class="modal-content" @click.stop>
<text class="modal-title">退款 - {{ refundModal.order?.outTradeNo }}</text>
<view class="cfg-row">
<text>订单金额</text>
<text class="cfg-val">¥{{ ((refundModal.order?.amount || 0) / 100).toFixed(1) }}</text>
</view>
<view class="cfg-row">
<text>退款金额</text>
<input class="cfg-input" type="digit" v-model.number="refundAmount" :placeholder="((refundModal.order?.amount || 0) / 100).toFixed(1)" />
</view>
<view class="cfg-row">
<text>退款原因</text>
<input class="cfg-input" style="width:300rpx" v-model="refundReason" placeholder="选填" />
</view>
<view class="modal-actions">
<button class="modal-btn cancel" @click="closeRefundModal">取消</button>
<button class="modal-btn confirm" style="background:#EF4444" @click="doRefund">确认退款</button>
</view>
</view>
</view>
<!-- 管理员 -->
<view v-if="tab === 'admins'" class="section">
<view class="search-bar">
@@ -349,7 +491,9 @@
<view class="admin-row" v-for="a in adminList" :key="a._id">
<text class="admin-phone">{{ a.phone || '--' }}</text>
<text class="admin-name">{{ a.nickname || '--' }}</text>
<text class="admin-email" v-if="a.email">{{ a.email }}</text>
<text class="admin-badge" v-if="a.isSystemAdmin">系统</text>
<text class="time-label" style="margin-left:auto">设置:{{ a.createdAt?.slice(0,10) }}</text>
</view>
<text class="empty-text" v-if="adminList.length === 0">暂无管理员</text>
</view>
@@ -358,17 +502,17 @@
<view class="admin-row">
<text class="admin-phone">{{ searchResult.phone || '--' }}</text>
<text class="admin-name">{{ searchResult.nickname || '--' }}</text>
<text class="admin-email" v-if="searchResult.email">{{ searchResult.email }}</text>
<text class="admin-set-btn" v-if="searchResult.role !== 'admin'" @click="setAdmin(searchResult._id)">设为管理员</text>
<text class="admin-set-btn done" v-else>已是管理员</text>
</view>
</view>
</view>
</view>
</view>
</template>
<script setup>
import { ref, computed, onMounted } from 'vue'
import { ref, computed, onMounted, reactive } from 'vue'
import { api, API_ENDPOINTS } from '../../config'
const verified = ref(false)
@@ -397,9 +541,10 @@ const pricing = ref({
interview: { pricePerSession: 500 },
resumeOptimize: { freeLimit: 3, pricePerOptimize: 300 },
resumeDownload: { pricePerDownload: 200 },
gravityRates: { interviewPerUse: 5, optimizePerUse: 3, downloadPerUse: 2 },
plans: {
growth: { price: 1990, durationDays: 30, credits: { interview: 999, resumeOptimize: 20, resumeDownload: 10 }, features: ['免费版全部权益', 'AI 数字人面试无限次'] },
sprint: { price: 4990, durationDays: 30, credits: { interview: 999, resumeOptimize: 50, resumeDownload: 30 }, features: ['成长版全部权益'] },
growth: { price: 1990, durationDays: 30, gravityPerMonth: 250, credits: { interview: 999, resumeOptimize: 20, resumeDownload: 10 }, features: ['免费版全部权益', '每月 250 引力值'] },
sprint: { price: 4990, durationDays: 30, gravityPerMonth: 600, credits: { interview: 999, resumeOptimize: 50, resumeDownload: 30 }, features: ['成长版全部权益', '每月 600 引力值'] },
},
})
const pricingLoading = ref(false)
@@ -407,6 +552,14 @@ const growthPriceTemp = ref(19.9)
const sprintPriceTemp = ref(49.9)
const growthFeaturesText = ref('')
const sprintFeaturesText = ref('')
const ivKeyword = ref('')
const ivStatusFilter = ref(0)
const ivTotal = ref(0)
const ivPage = ref(1)
const resumeKeyword = ref('')
const creditGravity = ref(0)
const analysisStats = ref({ totalDiagnoses: 0, todayDiagnoses: 0, totalGapAnalysis: 0 })
const analysisLoading = ref(false)
// Position management
const positions = ref([])
@@ -420,6 +573,8 @@ const posForm = reactive({
sort: 0,
active: true,
category: 'ai',
description: '',
requirements: '',
})
const growthPriceDisplay = computed(() => growthPriceTemp.value.toFixed(1))
@@ -441,12 +596,67 @@ const shareLoading = ref(false)
// Credit modal
const creditModal = ref({ show: false, user: null })
const creditTypes = ref([
{ key: 'interviewCredits', label: '面试次数', value: 0 },
{ key: 'resumeOptimizeCredits', label: '优化次数', value: 0 },
{ key: 'resumeDownloadCredits', label: '下载次数', value: 0 },
{ key: 'shareCredits', label: '分享积分', value: 0 },
])
// Refund modal
const refundModal = ref({ show: false, order: null })
const refundAmount = ref(0)
const refundReason = ref('')
const openRefundModal = (order) => {
refundModal.value = { show: true, order }
refundAmount.value = order.amount / 100
refundReason.value = ''
}
const closeRefundModal = () => {
refundModal.value = { show: false, order: null }
}
const doRefund = async () => {
const order = refundModal.value.order
if (!order) return
uni.showModal({
title: '确认退款', content: `确定对订单 ${order.outTradeNo} 退款 ¥${refundAmount.value.toFixed(1)}`,
success: async (r) => {
if (!r.confirm) return
try {
const res = await apiAdmin('/order/refund', {
method: 'POST',
body: { outTradeNo: order.outTradeNo, amount: Math.round(refundAmount.value * 100), reason: refundReason.value },
})
if (res.statusCode === 200) {
uni.showToast({ title: '退款成功', icon: 'success' })
closeRefundModal()
loadOrders()
} else {
uni.showToast({ title: res.data?.message || '退款失败', icon: 'none' })
}
} catch (e) {
uni.showToast({ title: '退款失败', icon: 'none' })
}
},
})
}
const queryRefund = async (outTradeNo) => {
uni.showToast({ title: '查询中...', icon: 'none' })
try {
const res = await apiAdmin('/order/refund/' + outTradeNo)
if (res.statusCode === 200) {
const wx = res.data.wxRefund
if (wx) {
uni.showModal({
title: '退款状态',
content: `微信状态: ${wx.status || '--'}\n退款金额: ¥${(wx.amount?.refund || 0) / 100}\n建议以微信侧为准`,
})
} else {
uni.showToast({ title: '本地状态: ' + (res.data.localStatus || '--'), icon: 'none' })
}
} else {
uni.showToast({ title: '查询失败', icon: 'none' })
}
} catch { uni.showToast({ title: '查询失败', icon: 'none' }) }
}
const token = () => uni.getStorageSync('token') || ''
@@ -492,6 +702,7 @@ const switchTab = (t) => {
if (t === 'admins' && adminList.value.length === 0) loadAdmins()
if (t === 'pricing') loadPricing()
if (t === 'orders') loadOrders()
if (t === 'analysis') loadAnalysis()
}
const loadUsers = async () => {
@@ -514,22 +725,55 @@ const loadMoreUsers = async () => {
const loadInterviews = async () => {
ivLoading.value = true
ivPage.value = 1
try {
const res = await apiAdmin('/interviews?page=1&limit=20')
if (res.statusCode === 200) interviews.value = res.data.interviews || []
let url = '/interviews?page=1&limit=20&keyword=' + encodeURIComponent(ivKeyword.value)
const statusMap = ['', 'in_progress', 'completed']
if (ivStatusFilter.value > 0) url += '&status=' + statusMap[ivStatusFilter.value]
const res = await apiAdmin(url)
if (res.statusCode === 200) { interviews.value = res.data.interviews || []; ivTotal.value = res.data.total || 0 }
} catch (e) { console.error(e) }
finally { ivLoading.value = false }
}
const loadMoreInterviews = async () => {
ivPage.value++
try {
let url = '/interviews?page=' + ivPage.value + '&limit=20&keyword=' + encodeURIComponent(ivKeyword.value)
const statusMap = ['', 'in_progress', 'completed']
if (ivStatusFilter.value > 0) url += '&status=' + statusMap[ivStatusFilter.value]
const res = await apiAdmin(url)
if (res.statusCode === 200) interviews.value = [...interviews.value, ...(res.data.interviews || [])]
} catch (e) { console.error(e) }
}
const loadResumes = async () => {
resumeLoading.value = true
try {
const res = await apiAdmin('/resumes?page=1&limit=20')
let url = '/resumes?page=1&limit=20'
if (resumeKeyword.value) url += '&keyword=' + encodeURIComponent(resumeKeyword.value)
const res = await apiAdmin(url)
if (res.statusCode === 200) resumes.value = res.data.list || []
} catch (e) { console.error(e) }
finally { resumeLoading.value = false }
}
const deleteResume = (id, title) => {
uni.showModal({
title: '删除简历', content: `确定删除"${title}"`,
success: async (r) => {
if (!r.confirm) return
try {
const res = await apiAdmin('/resume/' + id, { method: 'DELETE' })
if (res.statusCode === 200) {
uni.showToast({ title: '已删除', icon: 'success' })
loadResumes()
} else throw new Error()
} catch { uni.showToast({ title: '删除失败', icon: 'none' }) }
},
})
}
const loadPricing = async () => {
pricingLoading.value = true
try {
@@ -545,6 +789,15 @@ const loadPricing = async () => {
finally { pricingLoading.value = false }
}
const loadAnalysis = async () => {
analysisLoading.value = true
try {
const res = await apiAdmin('/analysis-stats')
if (res.statusCode === 200) analysisStats.value = res.data
} catch(e) { console.error(e) }
finally { analysisLoading.value = false }
}
const savePricing = async () => {
pricingLoading.value = true
try {
@@ -635,6 +888,8 @@ const openPositionModal = (position) => {
posForm.sort = position.sort ?? 0
posForm.active = position.active ?? true
posForm.category = position.category || 'traditional'
posForm.description = position.description || ''
posForm.requirements = position.requirements || ''
posModal.value = { show: true, isNew: false }
} else {
posForm.name = ''
@@ -644,6 +899,8 @@ const openPositionModal = (position) => {
posForm.sort = positions.value.length + 1
posForm.active = true
posForm.category = 'ai'
posForm.description = ''
posForm.requirements = ''
posModal.value = { show: true, isNew: true }
}
}
@@ -749,12 +1006,7 @@ const loadShareVisitors = async () => {
}
const openCreditModal = (user) => {
creditTypes.value = [
{ key: 'interviewCredits', label: '面试次数', value: user.interviewCredits ?? 0 },
{ key: 'resumeOptimizeCredits', label: '优化次数', value: user.resumeOptimizeCredits ?? 0 },
{ key: 'resumeDownloadCredits', label: '下载次数', value: user.resumeDownloadCredits ?? 0 },
{ key: 'shareCredits', label: '分享积分', value: user.shareCredits ?? 0 },
]
creditGravity.value = user.gravity ?? 0
creditModal.value = { show: true, user }
}
@@ -766,12 +1018,10 @@ const doAdjustCredits = async () => {
const userId = creditModal.value.user?._id
if (!userId) return
try {
for (const t of creditTypes.value) {
await apiAdmin('/user/credits', {
method: 'POST',
data: { userId, type: t.key, amount: t.value },
})
}
await apiAdmin('/user/credits', {
method: 'POST',
data: { userId, type: 'gravity', amount: creditGravity.value },
})
uni.showToast({ title: '调整成功', icon: 'success' })
closeCreditModal()
loadUsers()
@@ -790,8 +1040,8 @@ onMounted(() => { doVerify() })
.admin-input { height: 72rpx; background: #FFF; border: 2rpx solid var(--color-border); border-radius: var(--radius-sm); padding: 0 20rpx; font-size: 24rpx; }
.btn-verify { height: 72rpx; background: linear-gradient(135deg, var(--color-gradient-start), var(--color-gradient-mid)); color: #FFF; border-radius: var(--radius-sm); font-size: 26rpx; border: none; }
.body { padding: 20rpx 32rpx 48rpx; margin-top: -40rpx; }
.tabs { display: flex; gap: 8rpx; background: #FFF; border-radius: var(--radius-md); padding: 6rpx; margin-bottom: 20rpx; }
.tab { flex: 1; text-align: center; padding: 14rpx; font-size: 24rpx; color: var(--color-text-secondary); border-radius: var(--radius-sm); }
.tabs { display: flex; flex-wrap: wrap; gap: 8rpx; background: #FFF; border-radius: var(--radius-md); padding: 6rpx; margin-bottom: 20rpx; }
.tab { padding: 14rpx 20rpx; font-size: 24rpx; color: var(--color-text-secondary); border-radius: var(--radius-sm); white-space: nowrap; }
.tab.active { background: var(--color-primary); color: #FFF; font-weight: 600; }
.stat-cards { display: flex; gap: 16rpx; }
.stat-card { flex: 1; background: #FFF; border-radius: var(--radius-lg); padding: 28rpx; text-align: center; box-shadow: var(--shadow-sm); }
@@ -860,6 +1110,7 @@ onMounted(() => { doVerify() })
.order-time { font-size: 20rpx; color: var(--color-text-tertiary); flex: 1; text-align: right; }
.order-actions { }
.sync-btn { font-size: 20rpx; color: var(--color-primary); padding: 4rpx 12rpx; border: 2rpx solid var(--color-primary); border-radius: var(--radius-round); }
.refund-btn { font-size: 20rpx; color: #EF4444; padding: 4rpx 12rpx; border: 2rpx solid #EF4444; border-radius: var(--radius-round); }
.config-card { background: #FFF; border-radius: var(--radius-sm); padding: 20rpx; margin-bottom: 12rpx; }
.cfg-title { font-size: 24rpx; font-weight: 600; color: var(--color-text); margin-bottom: 12rpx; }
.cfg-row { display: flex; justify-content: space-between; padding: 8rpx 0; font-size: 22rpx; color: var(--color-text-secondary); align-items: center; }
@@ -901,4 +1152,31 @@ onMounted(() => { doVerify() })
.pos-mgr-btn { font-size: 20rpx; padding: 4rpx 16rpx; border-radius: var(--radius-round); }
.pos-mgr-btn.edit { color: var(--color-primary); border: 2rpx solid var(--color-primary); }
.pos-mgr-btn.del { color: #EF4444; border: 2rpx solid #EF4444; }
.iv-time { font-size: 18rpx; color: #D1D5DB; white-space: nowrap; margin-left: auto; }
.admin-action-btn { font-size: 20rpx; padding: 4rpx 16rpx; border-radius: var(--radius-round); cursor: pointer; }
.admin-action-btn.del { color: #EF4444; border: 2rpx solid #EF4444; }
.resume-actions { display: flex; gap: 8rpx; align-items: center; }
/* ─── 新增字段样式 ───── */
.user-meta-row { display: flex; flex-wrap: wrap; gap: 6rpx; margin-bottom: 6rpx; }
.meta-tag { font-size: 18rpx; background: #F3F4F6; color: var(--color-text-tertiary); padding: 2rpx 10rpx; border-radius: var(--radius-round); }
.meta-tag.email { background: #EEF2FF; color: var(--color-primary); }
.meta-tag.share { background: #FFF7ED; color: #D97706; }
.meta-tag.badge-done { background: #ECFDF5; color: #059669; }
.meta-tag.badge-pend { background: #FEF3C7; color: #D97706; }
.time-row { display: flex; flex-wrap: wrap; gap: 12rpx; }
.time-label { font-size: 18rpx; color: #9CA3AF; }
.iv-summary { font-size: 18rpx; color: #6B7280; margin-top: 4rpx; line-height: 1.4; display: block; }
.iv-user.email { font-size: 18rpx; color: #6B7280; }
.user-badge-role { font-size: 18rpx; background: #FEF3C7; color: #D97706; padding: 0 10rpx; border-radius: var(--radius-round); font-weight: 500; }
.share-meta-row { display: flex; gap: 6rpx; margin-top: 4rpx; }
.share-meta-row.time-row { gap: 12rpx; }
.order-meta-row { display: flex; flex-wrap: wrap; gap: 8rpx; margin-bottom: 4rpx; }
.order-meta-row.time-row { gap: 12rpx; }
.order-title { font-size: 22rpx; font-weight: 500; color: var(--color-text); }
.order-status.rp { font-size: 18rpx; display: inline-block; }
.refund-label { color: #EF4444 !important; }
.order-actions-bar { display: flex; gap: 8rpx; margin-top: 6rpx; }
.admin-email { font-size: 20rpx; color: #6B7280; }
.resume-user.email { font-size: 18rpx; color: #6B7280; }
</style>
+6 -5
View File
@@ -150,7 +150,7 @@ const doAnalyze = async () => {
data: { ...profile },
header: { 'Authorization': `Bearer ${token.value}`, 'Content-Type': 'application/json' },
})
if (res.statusCode === 200) {
if (res.statusCode >= 200 && res.statusCode < 300) {
if (res.data.error) {
error.value = res.data.error
return
@@ -184,7 +184,7 @@ const doChat = async () => {
data: { message: msg, history: chatHistory.value.slice(0, -1) },
header: { 'Authorization': `Bearer ${token.value}`, 'Content-Type': 'application/json' },
})
if (res.statusCode === 200) {
if (res.statusCode >= 200 && res.statusCode < 300) {
chatHistory.value.push({ role: 'assistant', content: res.data.reply || (res.data.error || '') })
} else {
chatHistory.value.push({ role: 'assistant', content: '回复失败,请稍后重试' })
@@ -211,12 +211,13 @@ const goInterview = (position) => {
.hero-title { font-size: 40rpx; font-weight: 700; color: var(--color-text); margin-top: 16rpx; }
.hero-desc { font-size: 26rpx; color: var(--color-secondary); margin-top: 8rpx; }
.form-card { background: #fff; border-radius: var(--radius-lg); padding: 32rpx; box-shadow: var(--shadow-sm); }
.form-group { margin-bottom: 28rpx; }
.form-card { background: #fff; border-radius: var(--radius-lg); padding: 32rpx; box-shadow: var(--shadow-sm); overflow: hidden; }
.form-group { margin-bottom: 28rpx; width: 100%; }
.form-group:last-child { margin-bottom: 0; }
.form-label { font-size: 26rpx; font-weight: 600; color: var(--color-text); display: block; margin-bottom: 12rpx; }
.required { color: var(--color-error); }
.form-input { width: 100%; height: 80rpx; border: 2rpx solid var(--color-border); border-radius: var(--radius-md); padding: 0 24rpx; font-size: 26rpx; color: var(--color-text); box-sizing: border-box; background: #FAFBFC; }
.form-input { width: 100%; height: 80rpx; border: 2rpx solid var(--color-border); border-radius: var(--radius-md); padding: 0 24rpx; font-size: 26rpx; color: var(--color-text); box-sizing: border-box; background: #FAFBFC; max-width: 100%; }
picker { width: 100%; }
.select-trigger { display: flex; align-items: center; }
.form-textarea { width: 100%; height: 160rpx; border: 2rpx solid var(--color-border); border-radius: var(--radius-md); padding: 20rpx 24rpx; font-size: 26rpx; color: var(--color-text); box-sizing: border-box; background: #FAFBFC; resize: none; }
+1 -1
View File
@@ -13,7 +13,7 @@
<text class="user-name">{{ userInfo.nickname || '同学' }}</text>
<view class="user-tags">
<text class="tag tag-plan">{{ userInfo.plan || '免费版' }}</text>
<text class="tag tag-remaining">{{ userInfo.interviewCredits > 0 ? '剩余 ' + userInfo.interviewCredits + ' 次' : '已用完' }}</text>
<text class="tag tag-remaining">{{ (userInfo.gravity ?? 0) > 0 ? '引力值 ' + (userInfo.gravity ?? 0) : '引力值 0' }}</text>
</view>
</view>
<text class="arrow"></text>
+126 -5
View File
@@ -66,10 +66,47 @@
</view>
</view>
<!-- 岗位选择弹窗 -->
<view class="modal-overlay" v-if="showPositionPicker" @click="showPositionPicker = false">
<view class="modal-content" @click.stop>
<text class="modal-title">选择面试岗位</text>
<view class="pos-list">
<view class="pos-option" v-for="(pos, idx) in positions" :key="idx" @click="selectPosition(pos)">
<text class="pos-name">{{ pos.name }}</text>
<text class="pos-arrow"></text>
</view>
<view class="pos-option" v-if="positions.length === 0 && !positionsLoading">
<text class="pos-name disabled">暂无可用岗位</text>
</view>
<view class="pos-option" v-if="positionsLoading">
<text class="pos-name disabled">加载中...</text>
</view>
</view>
<text class="modal-close" @click="showPositionPicker = false">取消</text>
</view>
</view>
<view class="disclaimer-bar" v-if="!isComplete">AI 生成内容仅供参考请核实重要信息</view>
<view class="complete-bar" v-else>
<button class="cta-btn" @click="goResult">查看面试报告</button>
<button class="buy-btn" v-if="completedReason === 'noCredits'" @click="goH5Buy">引力值不足官网购买 </button>
</view>
<!-- 官网购买弹窗 -->
<view class="modal-overlay" v-if="showH5BuyModal" @click="showH5BuyModal = false">
<view class="modal-content" @click.stop>
<text class="modal-title">引力值不足</text>
<text class="modal-hint">您的引力值不足请补充后继续面试每次面试消耗 5 引力值</text>
<view class="purchase-options">
<view class="purchase-option" @click="goH5BuyAndClose">
<text class="purchase-name">官网购买引力值</text>
<text class="purchase-price">前往网页版充值</text>
<text class="purchase-desc">打开官网 H5 页面支持多种支付方式</text>
</view>
</view>
<text class="modal-close" @click="showH5BuyModal = false">取消</text>
</view>
</view>
</view>
</template>
@@ -79,16 +116,20 @@ import { ref, computed, onMounted, onBeforeUnmount, nextTick } from 'vue'
import { onLoad } from '@dcloudio/uni-app'
import { api, API_ENDPOINTS } from '../../config'
import DigitalHuman from '../../components/digital-human.vue'
const messages = ref([{ role: 'ai', content: '你好!我是 AI 面试官,请选择岗位开始模拟面试!' }])
const inputText = ref('')
const aiLoading = ref(false)
const interviewId = ref('')
const answeredCount = ref(0)
const isComplete = ref(false)
const completedReason = ref('')
const scrollToId = ref('')
const position = ref('')
const avatarMode = ref(true)
const showPositionPicker = ref(false)
const showH5BuyModal = ref(false)
const positions = ref([])
const positionsLoading = ref(false)
const aiSpeechText = ref('')
const aiAudioUrl = ref('')
const aiAmplitudeData = ref([])
@@ -116,9 +157,37 @@ onLoad((options) => {
}
})
/** 加载热门岗位列表 */
const loadPositions = async () => {
positionsLoading.value = true
try {
const res = await uni.request({ url: api('/positions/hot'), method: 'GET' })
if (res.statusCode >= 200 && res.statusCode < 300 && Array.isArray(res.data)) {
positions.value = res.data
} else if (res.data?.data && Array.isArray(res.data.data)) {
positions.value = res.data.data
}
} catch (e) { console.error('加载岗位列表失败', e) }
finally { positionsLoading.value = false }
}
/** 用户选择岗位后开始面试 */
const selectPosition = (pos) => {
position.value = pos.name
showPositionPicker.value = false
messages.value = [{ role: 'ai', content: `你好!我是你的专属 ${pos.name} 面试官,准备好了就开始吧!` }]
startInterview()
}
onMounted(() => {
timerInterval = setInterval(() => timerSeconds++, 1000)
if (token()) startInterview()
if (!position.value) {
//
loadPositions()
showPositionPicker.value = true
} else if (token()) {
startInterview()
}
})
onBeforeUnmount(() => {
@@ -155,6 +224,11 @@ const startInterview = async () => {
const last = res.data.messages[res.data.messages.length - 1]
if (last?.role === 'ai') await speakAiText(last.content)
}
} else if (res.statusCode === 403) {
const errMsg = res.data?.message || '面试次数已用完'
messages.value.push({ role: 'ai', content: errMsg + ' 👉 购买后可继续面试' })
isComplete.value = true
completedReason.value = 'noCredits'
} else {
const msg = res.data?.message || '创建面试失败'
messages.value.push({ role: 'ai', content: msg })
@@ -198,8 +272,10 @@ const sendAnswer = async () => {
answeredCount.value = res.data.questionCount || answeredCount.value + 1
if (res.data.totalQuestions) MAX_QUESTIONS = res.data.totalQuestions
} else if (res.statusCode === 403) {
messages.value.push({ role: 'ai', content: res.data?.message || '面试次数已用完' })
const errMsg = res.data?.message || '面试次数已用完'
messages.value.push({ role: 'ai', content: errMsg + ' 👉 购买后可继续面试' })
isComplete.value = true
completedReason.value = 'noCredits'
} else {
messages.value.push({ role: 'ai', content: res.data?.message || '回答提交失败' })
}
@@ -240,6 +316,27 @@ function onAvatarSilent() {
}
const goResult = () => uni.navigateTo({ url: `/pages/report/report?interviewId=${interviewId.value}` })
//
const goH5Buy = () => {
showH5BuyModal.value = true
}
const goH5BuyAndClose = () => {
showH5BuyModal.value = false
const token = uni.getStorageSync('token') || ''
const url = `https://zhiyin.yzrcloud.cn/?buy=gravity${token ? '&token=' + token : ''}`
// #ifdef MP-WEIXIN
uni.setClipboardData({
data: url,
success: () => {
uni.showToast({ title: '链接已复制,请在手机浏览器中打开', icon: 'none', duration: 3000 })
},
fail: () => {
uni.showToast({ title: '复制失败,请手动访问 zhiyin.yzrcloud.cn', icon: 'none', duration: 3000 })
},
})
// #endif
}
const scrollToBottom = () => {
nextTick(() => { scrollToId.value = ''; setTimeout(() => { scrollToId.value = 'msg-bottom' }, 100) })
}
@@ -280,7 +377,6 @@ function stopRecord() {
name: 'audio',
header: { 'Authorization': `Bearer ${token()}` },
})
console.log('[ASR] upload response:', uploadRes.statusCode, typeof uploadRes.data === 'string' ? uploadRes.data.slice(0, 200) : JSON.stringify(uploadRes.data).slice(0, 200))
if (uploadRes.statusCode === 200 && uploadRes.data) {
const data = typeof uploadRes.data === 'string' ? JSON.parse(uploadRes.data) : uploadRes.data
if (data.text) {
@@ -389,7 +485,32 @@ function stopRecord() {
.send-btn.disabled { background: var(--color-border); }
.send-icon { font-size: 32rpx; color: #FFFFFF; transform: translateY(2rpx); }
.complete-bar { background: #FFFFFF; padding: 20rpx 24rpx; padding-bottom: calc(20rpx + var(--safe-bottom)); }
.complete-bar { background: #FFFFFF; padding: 20rpx 24rpx; padding-bottom: calc(20rpx + var(--safe-bottom)); display: flex; flex-direction: column; gap: 16rpx; }
.cta-btn { width: 100%; height: 88rpx; line-height: 88rpx; background: linear-gradient(135deg, var(--color-gradient-start), var(--color-gradient-mid)); color: #FFFFFF; border-radius: var(--radius-md); font-size: 28rpx; font-weight: 600; border: none; }
.buy-btn { width: 100%; height: 72rpx; line-height: 72rpx; background: #FEF3C7; color: #92400E; border-radius: var(--radius-md); font-size: 26rpx; font-weight: 600; border: 2rpx solid #F59E0B; }
.disclaimer-bar { text-align: center; font-size: 20rpx; color: var(--color-text-tertiary); padding: 8rpx 24rpx; background: #FFFFFF; border-top: 1rpx solid var(--color-border); }
/* 岗位选择弹窗 */
.modal-overlay { position: fixed; top: 0; left: 0; right: 0; bottom: 0; background: rgba(0,0,0,0.45); z-index: 999; display: flex; align-items: center; justify-content: center; }
.modal-content { background: #FFF; border-radius: 20rpx; width: 600rpx; max-height: 70vh; display: flex; flex-direction: column; align-items: center; padding: 40rpx 32rpx 32rpx; }
.modal-title { font-size: 30rpx; font-weight: 800; color: var(--color-text); margin-bottom: 24rpx; }
.pos-list { width: 100%; max-height: 440rpx; overflow-y: auto; }
.pos-option { display: flex; align-items: center; justify-content: space-between; padding: 24rpx 16rpx; border-bottom: 1rpx solid #F3F4F6; }
.pos-option:active { background: #F9FAFB; border-radius: 12rpx; }
.pos-name { font-size: 28rpx; color: var(--color-text); }
.pos-name.disabled { color: #9CA3AF; }
.pos-arrow { font-size: 32rpx; color: #9CA3AF; }
.modal-close { margin-top: 24rpx; font-size: 26rpx; color: #9CA3AF; padding: 12rpx 32rpx; }
/* 购买弹窗 */
.modal-hint { font-size: 24rpx; color: #6B7280; text-align: center; margin-bottom: 28rpx; padding: 0 16rpx; }
.purchase-options { width: 100%; display: flex; flex-direction: column; gap: 16rpx; }
.purchase-option { background: #F9FAFB; border-radius: var(--radius-md); padding: 24rpx; border: 2rpx solid #E5E7EB; }
.purchase-option.recommended { background: #FFFBEB; border-color: #F59E0B; }
.purchase-option:active { transform: scale(0.97); }
.purchase-badge { font-size: 18rpx; color: #FFF; background: #F59E0B; padding: 2rpx 12rpx; border-radius: 6rpx; align-self: flex-start; margin-bottom: 8rpx; }
.purchase-name { font-size: 28rpx; font-weight: 700; color: var(--color-text); display: block; }
.purchase-price { font-size: 36rpx; font-weight: 800; color: var(--color-primary); margin-top: 8rpx; }
.purchase-unit { font-size: 22rpx; font-weight: 400; color: #9CA3AF; }
.purchase-desc { font-size: 22rpx; color: #6B7280; margin-top: 6rpx; }
</style>
+12 -9
View File
@@ -33,7 +33,7 @@
<text class="field-label">密码</text>
<input class="input" type="password" v-model="password" placeholder="请输入密码" @confirm="doPasswordLogin" />
</view>
<button class="login-btn" :disabled="!canPasswordLogin || pwdLoading || !agreed" @click="doPasswordLogin">
<button class="login-btn" :disabled="!canPasswordLogin || pwdLoading" @click="doPasswordLogin">
{{ pwdLoading ? '登录中...' : '登录' }}
</button>
<view class="switch-hint" @click="loginMode='code'">忘记密码使用验证码登录</view>
@@ -54,7 +54,7 @@
<text class="field-label">验证码</text>
<input class="input" type="number" maxlength="6" v-model="emailCode" placeholder="请输入6位验证码" />
</view>
<button class="login-btn" :disabled="!emailSent || !emailCode || emailLoading || !agreed" @click="doEmailLogin">
<button class="login-btn" :disabled="!emailSent || !emailCode || emailLoading" @click="doEmailLogin">
{{ emailLoading ? '登录中...' : '登录' }}
</button>
<view class="switch-hint" @click="loginMode='password'">已有密码使用密码登录</view>
@@ -77,7 +77,7 @@
<text class="field-label">确认密码</text>
<input class="input" type="password" v-model="confirmPassword" placeholder="再次输入密码" @confirm="doRegister" />
</view>
<button class="login-btn" :disabled="!canRegister || regLoading || !agreed" @click="doRegister">
<button class="login-btn" :disabled="!canRegister || regLoading" @click="doRegister">
{{ regLoading ? '注册中...' : '注册' }}
</button>
<view class="switch-hint" @click="mainTab='login'">已有账号去登录</view>
@@ -87,7 +87,7 @@
<view class="card" v-if="mainTab === 'wechat' && isMp">
<text class="card-title">微信一键登录</text>
<text class="card-sub">授权后自动创建账号</text>
<button class="login-btn wx-btn" :disabled="wxLoading || !agreed" @click="doWxLogin">{{ wxLoading ? '登录中...' : '微信一键登录' }}</button>
<button class="login-btn wx-btn" :disabled="wxLoading" @click="doWxLogin">{{ wxLoading ? '登录中...' : '微信一键登录' }}</button>
</view>
<!-- 法律声明 - 用户自主勾选同意 -->
@@ -156,6 +156,10 @@ onBeforeUnmount(() => { if (timer) { clearTimeout(timer); timer = null } })
//
const showToast = (title, icon = 'none') => uni.showToast({ title, icon })
const checkAgreed = () => {
if (!agreed.value) { showToast('请阅读并同意《用户服务协议》和《隐私政策》'); return false }
return true
}
const loginSuccess = (data) => {
uni.setStorageSync('token', data.token)
if (data.user) uni.setStorageSync('userInfo', JSON.stringify(data.user))
@@ -165,7 +169,7 @@ const loginSuccess = (data) => {
// ====== ======
const doPasswordLogin = async () => {
if (!canPasswordLogin.value) return
if (!canPasswordLogin.value || !checkAgreed()) return
pwdLoading.value = true
try {
const res = await uni.request({
@@ -227,7 +231,7 @@ const startCooldown = () => {
}
const doEmailLogin = async () => {
if (!emailCode.value) return
if (!emailCode.value || !checkAgreed()) return
emailLoading.value = true
try {
const res = await uni.request({
@@ -250,7 +254,7 @@ const doEmailLogin = async () => {
// ====== ======
const doRegister = async () => {
if (!canRegister.value) return
if (!canRegister.value || !checkAgreed()) return
regLoading.value = true
try {
const res = await uni.request({
@@ -292,10 +296,10 @@ const skipSetPwd = () => { showSetPwd.value = false }
// ====== ======
const doWxLogin = async () => {
// #ifdef MP-WEIXIN
if (!checkAgreed()) { wxLoading.value = false; return }
wxLoading.value = true
try {
const wxResp = await uni.login()
console.log('[wxLogin] uni.login success:', JSON.stringify(wxResp).slice(0, 300))
const { code, errMsg } = wxResp
if (!code) { console.error('[wxLogin] no code:', errMsg); showToast('获取微信凭证失败'); return }
const res = await uni.request({
@@ -303,7 +307,6 @@ const doWxLogin = async () => {
header: { 'Content-Type': 'application/json' },
data: { code },
})
console.log('[wxLogin] server response:', res.statusCode, JSON.stringify(res.data).slice(0, 500))
if (res.statusCode === 200 && res.data?.token) {
loginSuccess(res.data)
} else {
+142 -263
View File
@@ -1,342 +1,221 @@
<template>
<!-- #ifdef MP-WEIXIN -->
<view class="page fade-in">
<view class="placeholder-wrap">
<text class="placeholder-icon"></text>
<text class="placeholder-text">功能已整合到各模块</text>
<text class="placeholder-hint">请返回使用引力值充值功能</text>
<text class="placeholder-back" @click="goBack">返回首页</text>
</view>
</view>
<!-- #endif -->
<!-- #ifdef H5 -->
<view class="page fade-in">
<view class="hero">
<text class="hero-title">会员中心</text>
<text class="hero-sub" v-if="isLoggedIn">
当前{{ currentPlanName }}
</text>
<text class="hero-sub" v-else>选择套餐解锁全部功能</text>
<text class="hero-icon"></text>
<text class="hero-title">补充引力值</text>
<text class="hero-desc">购买后可获得相应引力值用于面试简历优化下载</text>
</view>
<view class="plans">
<!-- 免费版 -->
<view class="plan-card free" :class="{ active: plan === 'free' && isLoggedIn }">
<view class="plan-header">
<text class="plan-name">免费版</text>
<view class="plan-price"><text class="price-num">免费</text></view>
<view class="product-card">
<view class="qty-section">
<text class="section-label">购买数量</text>
<view class="qty-controls">
<text class="qty-btn" :class="{ disabled: buyQty <= 1 }" @click="changeQty(-1)"></text>
<input class="qty-input" type="number" v-model.number="buyQty" min="1" max="99" @blur="clampQty" />
<text class="qty-btn" :class="{ disabled: buyQty >= 99 }" @click="changeQty(1)">+</text>
</view>
<view class="plan-features">
<text class="feat" v-for="f in freeFeatures" :key="f"> {{ f }}</text>
</view>
<view class="plan-status" v-if="isLoggedIn && plan === 'free'">当前使用</view>
<view class="plan-status hint" v-else-if="!isLoggedIn">注册即用</view>
</view>
<!-- 成长版 -->
<view class="plan-card growth recommended" :class="{ active: plan === 'growth' && isLoggedIn }">
<view class="plan-badge"> 推荐</view>
<view class="plan-header">
<text class="plan-name">成长版</text>
<text class="plan-price"><text class="price-num">{{ growthPriceText }}</text><text class="price-unit">/</text></text>
<view class="summary">
<view class="summary-row">
<text class="summary-label">单价</text>
<text class="summary-val">¥{{ (unitPrice / 100).toFixed(1) }} / </text>
</view>
<view class="plan-features">
<text class="feat" v-for="f in growthFeatures" :key="f"> {{ f }}</text>
<view class="summary-row">
<text class="summary-label">可得引力值</text>
<text class="summary-val highlight">{{ buyQty * gravityPerUnit }} 引力值</text>
</view>
<view class="summary-row total">
<text class="summary-label">合计</text>
<text class="summary-val total-price">¥{{ (buyQty * unitPrice / 100).toFixed(2) }}</text>
</view>
<view class="plan-action" v-if="!isLoggedIn" @click="goLogin">登录后开通</view>
<view class="plan-action owned" v-else-if="plan !== 'free'"> 已开通</view>
<view class="plan-action" v-else @click="startPay('growth')">{{ growthPriceText }} 立即开通</view>
</view>
<!-- 冲刺版 -->
<view class="plan-card sprint" :class="{ active: plan === 'sprint' && isLoggedIn }">
<view class="plan-badge sprint-badge">🚀 冲刺</view>
<view class="plan-header">
<text class="plan-name">冲刺版</text>
<text class="plan-price"><text class="price-num price-sprint">{{ sprintPriceText }}</text><text class="price-unit">/</text></text>
</view>
<view class="plan-features">
<text class="feat" v-for="f in sprintFeatures" :key="f"> {{ f }}</text>
</view>
<view class="plan-action" v-if="!isLoggedIn" @click="goLogin">登录后开通</view>
<view class="plan-action owned" v-else-if="plan === 'sprint'"> 已开通</view>
<view class="plan-action" v-else-if="plan === 'growth'" @click="startPay('sprint')">升级至冲刺版</view>
<view class="plan-action" v-else @click="startPay('sprint')">{{ sprintPriceText }}/ 立即开通</view>
</view>
<button class="buy-btn" :disabled="payLoading" @click="startPay">
<text v-if="!payLoading">立即购买</text>
<text v-else>处理中...</text>
</button>
</view>
<!-- 支付弹窗 -->
<view class="modal-overlay" v-if="showPayModal" @click="cancelPay">
<view class="modal-content" @click.stop>
<template v-if="payLoading">
<text class="modal-title">正在创建支付...</text>
<text class="modal-title">正在创建订单...</text>
</template>
<template v-else-if="!isMp && payCodeUrl">
<template v-else-if="payCodeUrl">
<text class="modal-title">微信扫码支付</text>
<canvas canvas-id="payQrcode" class="qr-canvas"></canvas>
<text class="modal-hint">请用微信扫码完成支付</text>
<text class="modal-hint">支付成功后将自动跳转</text>
<image class="qrcode" :src="'https://api.qrserver.com/v1/create-qr-code/?size=300x300&data=' + encodeURIComponent(payCodeUrl)" mode="widthFix" />
<text class="modal-hint">使用微信扫描二维码完成支付</text>
<text class="modal-close" @click="cancelPay">取消支付</text>
</template>
<template v-else-if="isMp && !payLoading">
<text class="modal-title">微信支付</text>
<text class="modal-hint">即将调起微信支付...</text>
<template v-else-if="paySuccess">
<text class="modal-title"> 支付成功</text>
<text class="modal-hint">引力值已到账返回继续使用吧</text>
<text class="modal-close" @click="cancelPay">关闭</text>
</template>
<template v-if="payError">
<text class="modal-title pay-error">支付异常</text>
<template v-else-if="payError">
<text class="modal-title pay-error">支付失败</text>
<text class="modal-hint">{{ payError }}</text>
<text class="modal-close" @click="cancelPay">关闭</text>
</template>
</view>
</view>
<!-- 支付中提示 -->
<view class="pay-success" v-if="paySuccess">
<text class="success-icon">🎉</text>
<text class="success-text">开通成功{{ payingPlanName }}已生效</text>
</view>
</view>
<!-- #endif -->
</template>
<script setup>
import { ref, onMounted, nextTick } from 'vue'
<script setup lang="ts">
import { ref, computed, onMounted } from 'vue'
import { api } from '../../config'
import UQRCode from 'uqrcodejs'
const isLoggedIn = ref(false)
const isMp = ref(false)
const plan = ref('free')
const currentPlanName = ref('免费版')
const paySuccess = ref(false)
const goBack = () => uni.switchTab({ url: '/pages/user/user' })
// #ifdef H5
const buyQty = ref(1)
const unitPrice = ref(500)
const gravityPerUnit = ref(5)
const payLoading = ref(false)
const showPayModal = ref(false)
const payCodeUrl = ref('')
const payLoading = ref(false)
const paySuccess = ref(false)
const payError = ref('')
const payingPlanName = ref('')
const payingPlan = ref('')
const growthPriceText = ref('¥19.9')
const sprintPriceText = ref('¥49.9')
const currentOutTradeNo = ref('')
const freeFeatures = ref(['AI 模拟面试 1 次(体验)', '基础面试报告', '通用题库随机出题', '简历优化(限 3 次免费)'])
const growthFeatures = ref(['免费版全部权益', 'AI 数字人面试无限次', '详细面试报告(四维评分)', '进步轨迹雷达图 + 打卡', '每日一题推送', '参考回答思路', '公司真题库', '每场最多 10 轮 AI 对话'])
const sprintFeatures = ref(['成长版全部权益', 'AI 语音分析(语气词/语速检测)', '技能缺口分析报告', '学习路径推荐', '真人导师 1v1 点评(每月 1 次)', '简历精修(每月 1 次)', '内推优先', 'AI 实时提示功能'])
const token = () => uni.getStorageSync('token') || ''
onMounted(async () => {
// #ifdef MP-WEIXIN
isMp.value = true
// #endif
const t = token()
if (!t) return
isLoggedIn.value = true
try {
const [sres, lres] = await Promise.all([
uni.request({ url: api('/member/status'), method: 'GET', header: { 'Authorization': `Bearer ${t}` } }),
uni.request({ url: api('/member/plans'), method: 'GET' }),
])
if (sres.statusCode === 200) {
const d = sres.data
plan.value = d.plan || 'free'
currentPlanName.value = d.planName || '免费版'
}
if (lres.statusCode === 200 && lres.data) {
const plans = Array.isArray(lres.data.plans) ? lres.data.plans : (Array.isArray(lres.data) ? lres.data : [])
const growth = plans.find((p) => p.id === 'growth')
const sprint = plans.find((p) => p.id === 'sprint')
if (growth) {
growthPriceText.value = `¥${(growth.price / 100).toFixed(1)}`
if (growth.features?.length) growthFeatures.value = growth.features
}
if (sprint?.features?.length) sprintFeatures.value = sprint.features
if (sprint) sprintPriceText.value = `¥${(sprint.price / 100).toFixed(1)}`
if (lres.data.price?.monthly) {
growthPriceText.value = `¥${(lres.data.price.monthly / 100).toFixed(1)}`
const res = await uni.request({ url: api('/member/plans'), method: 'GET' })
if (res.statusCode >= 200 && res.statusCode < 300 && res.data?.products) {
const prod = res.data.products.interview
if (prod) {
unitPrice.value = prod.price || 500
gravityPerUnit.value = prod.gravity || 5
}
}
} catch (e) { /* ignore */ }
} catch (e) { /* silent */ }
})
const goLogin = () => uni.navigateTo({ url: '/pages/login/login' })
const cancelPay = () => {
showPayModal.value = false
payCodeUrl.value = ''
payLoading.value = false
payError.value = ''
const changeQty = (delta: number) => {
const next = buyQty.value + delta
if (next >= 1 && next <= 99) buyQty.value = next
}
const clampQty = () => {
if (buyQty.value < 1) buyQty.value = 1
if (buyQty.value > 99) buyQty.value = 99
}
/** 创建支付订单 */
const startPay = async (selectedPlan) => {
const t = token()
if (!t) { uni.showToast({ title: '请先登录', icon: 'none' }); return }
payingPlan.value = selectedPlan
// #ifdef MP-WEIXIN
payingPlanName.value = selectedPlan === 'sprint' ? '冲刺版' : '成长版'
// #endif
// #ifndef MP-WEIXIN
payingPlanName.value = selectedPlan === 'sprint' ? '冲刺版' : '成长版'
// #endif
const startPay = async () => {
const token = uni.getStorageSync('token') || ''
if (!token) { uni.showToast({ title: '请先登录', icon: 'none' }); return }
showPayModal.value = true
payLoading.value = true
payCodeUrl.value = ''
payError.value = ''
paySuccess.value = false
const planLabel = selectedPlan || 'growth'
try {
const res = await uni.request({
url: api('/payment/create-product'), method: 'POST',
data: { type: 'interview', quantity: buyQty.value },
header: { 'Authorization': `Bearer ${token}`, 'Content-Type': 'application/json' },
})
payLoading.value = false
if (isMp.value) {
// JSAPI
try {
const res = await uni.request({
url: api('/payment/jsapi'), method: 'POST',
data: { plan: planLabel },
header: { 'Authorization': `Bearer ${t}`, 'Content-Type': 'application/json' },
})
payLoading.value = false
if (res.statusCode === 200 && res.data?.payParams) {
const pp = res.data.payParams
currentOutTradeNo.value = res.data.outTradeNo || ''
//
uni.requestPayment({
provider: 'wxpay',
timeStamp: pp.timeStamp,
nonceStr: pp.nonceStr,
package: pp.package,
signType: pp.signType || 'RSA',
paySign: pp.paySign,
success: () => pollPayResult(res.data.prepayId, planLabel),
fail: (err) => { payError.value = '支付取消或失败'; uni.showToast({ title: '支付取消', icon: 'none' }) },
})
} else {
payLoading.value = false
payError.value = res.data?.message || '创建订单失败'
uni.showToast({ title: '创建订单失败', icon: 'none' })
}
} catch (e) {
payLoading.value = false
payError.value = '网络错误,请重试'
uni.showToast({ title: '网络错误', icon: 'none' })
}
} else {
// H5
try {
const res = await uni.request({
url: api('/payment/create'), method: 'POST',
data: { plan: planLabel },
header: { 'Authorization': `Bearer ${t}`, 'Content-Type': 'application/json' },
})
payLoading.value = false
if (res.statusCode === 200 && res.data?.codeUrl) {
payCodeUrl.value = res.data.codeUrl
currentOutTradeNo.value = res.data.outTradeNo
nextTick(() => {
try {
const ctx = uni.createCanvasContext('payQrcode')
const uqrcode = new UQRCode()
uqrcode.data = res.data.codeUrl
uqrcode.size = 400
uqrcode.margin = 20
uqrcode.backgroundColor = '#FFFFFF'
uqrcode.foregroundColor = '#000000'
uqrcode.make()
uqrcode.drawCanvas(ctx)
} catch(e) { console.error('二维码生成失败', e) }
})
//
pollPayResult(res.data.outTradeNo, planLabel)
} else {
payError.value = res.data?.message || '支付服务暂不可用'
uni.showToast({ title: '支付服务暂不可用', icon: 'none' })
}
} catch (e) {
payLoading.value = false
payError.value = '网络错误,请重试'
uni.showToast({ title: '网络错误', icon: 'none' })
if (res.statusCode >= 200 && res.statusCode < 300 && res.data?.codeUrl) {
payCodeUrl.value = res.data.codeUrl
pollPayResult(res.data.outTradeNo)
} else {
payError.value = res.data?.message || '创建订单失败'
}
} catch (e) {
payLoading.value = false
payError.value = '网络错误,请重试'
}
}
/** 轮询订单状态 */
const pollPayResult = async (outTradeNo, selectedPlan) => {
const pollPayResult = (outTradeNo: string) => {
if (!outTradeNo) return
const maxAttempts = 30
const token = uni.getStorageSync('token') || ''
let attempts = 0
const poll = async () => {
attempts++
try {
const res = await uni.request({
url: api(`/payment/check/${outTradeNo}`), method: 'GET',
header: { 'Authorization': `Bearer ${token()}` },
header: { 'Authorization': `Bearer ${token}` },
})
if (res.statusCode === 200 && res.data?.status === 'success') {
//
await activatePlan(outTradeNo, selectedPlan)
if (res.statusCode >= 200 && res.statusCode < 300 && res.data?.status === 'success') {
paySuccess.value = true
payCodeUrl.value = ''
return
}
} catch (e) { /* ignore */ }
if (attempts < maxAttempts) {
setTimeout(poll, 2000)
} else {
payError.value = '支付结果查询超时,请联系客服'
uni.showToast({ title: '支付查询超时', icon: 'none' })
}
if (attempts < 30) setTimeout(poll, 2000)
}
setTimeout(poll, 2000)
}
/** 激活套餐 */
const activatePlan = async (outTradeNo, selectedPlan) => {
try {
const res = await uni.request({
url: api('/payment/activate'), method: 'POST',
data: { outTradeNo },
header: { 'Authorization': `Bearer ${token()}`, 'Content-Type': 'application/json' },
})
if (res.statusCode === 200 && res.data?.success) {
paySuccess.value = true
showPayModal.value = false
plan.value = selectedPlan === 'sprint' ? 'sprint' : 'growth'
currentPlanName.value = selectedPlan === 'sprint' ? '冲刺版' : '成长版'
uni.showToast({ title: '🎉 开通成功!', icon: 'success' })
} else {
uni.showToast({ title: res.data?.message || '激活失败', icon: 'none' })
}
} catch (e) {
payError.value = '激活失败,请联系客服'
uni.showToast({ title: '激活失败', icon: 'none' })
}
const cancelPay = () => {
showPayModal.value = false
payCodeUrl.value = ''
payError.value = ''
payLoading.value = false
}
// #endif
</script>
<style scoped>
.page { min-height: 100vh; background: var(--color-bg); }
.hero { background: linear-gradient(135deg, var(--color-gradient-start), var(--color-gradient-mid), var(--color-gradient-end)); padding: 48rpx 32rpx 72rpx; border-radius: 0 0 48rpx 48rpx; }
.hero-title { font-size: 40rpx; font-weight: 700; color: #FFFFFF; }
.hero-sub { font-size: 22rpx; color: rgba(255,255,255,0.7); margin-top: 8rpx; display: block; }
.plans { padding: 0 32rpx; margin-top: -40rpx; display: flex; flex-direction: column; gap: 24rpx; }
.plan-card { background: #FFFFFF; border-radius: var(--radius-xl); padding: 32rpx; box-shadow: var(--shadow-sm); position: relative; }
.plan-card.growth { border: 2rpx solid var(--color-primary); }
.plan-card.sprint { border: 2rpx solid #F59E0B; }
.plan-card.active { border-color: var(--color-primary); }
.plan-badge { position: absolute; top: -12rpx; right: 24rpx; background: linear-gradient(135deg, var(--color-gradient-start), var(--color-gradient-mid)); color: #FFF; font-size: 20rpx; padding: 4rpx 20rpx; border-radius: var(--radius-round); font-weight: 600; }
.sprint-badge { background: linear-gradient(135deg, #F59E0B, #F97316); }
.plan-header { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: 20rpx; }
.plan-name { font-size: 30rpx; font-weight: 700; color: var(--color-text); }
.price-num { font-size: 44rpx; font-weight: 800; color: var(--color-primary); }
.price-unit { font-size: 22rpx; color: var(--color-text-tertiary); }
.price-sprint { color: #D97706; }
.plan-features { display: flex; flex-direction: column; gap: 10rpx; margin-bottom: 24rpx; }
.feat { font-size: 24rpx; color: var(--color-text-secondary); }
.plan-status { text-align: center; background: #F3F4F6; padding: 14rpx; border-radius: var(--radius-sm); font-size: 24rpx; color: var(--color-text-secondary); }
.plan-status.hint { background: transparent; color: var(--color-text-tertiary); }
.plan-action { text-align: center; background: linear-gradient(135deg, var(--color-gradient-start), var(--color-gradient-mid)); color: #FFF; padding: 20rpx; border-radius: var(--radius-md); font-size: 28rpx; font-weight: 600; }
.plan-action.owned { background: #ECFDF5; color: var(--color-success); }
.pay-success { margin: 24rpx 32rpx; background: #ECFDF5; border-radius: var(--radius-lg); padding: 32rpx; text-align: center; }
.success-icon { font-size: 48rpx; display: block; margin-bottom: 8rpx; }
.success-text { font-size: 28rpx; font-weight: 600; color: var(--color-success); }
.placeholder-wrap { display: flex; flex-direction: column; align-items: center; gap: 16rpx; padding: 80rpx 40rpx; }
.placeholder-icon { font-size: 80rpx; }
.placeholder-text { font-size: 30rpx; font-weight: 600; color: var(--color-text); }
.placeholder-hint { font-size: 24rpx; color: var(--color-text-tertiary); }
.placeholder-back { font-size: 26rpx; color: var(--color-primary); padding: 16rpx 40rpx; border-radius: var(--radius-md); background: #F3F4F6; margin-top: 24rpx; }
/* 弹窗 */
/* H5 购买页 */
.hero { display: flex; flex-direction: column; align-items: center; padding: 48rpx 32rpx 24rpx; }
.hero-icon { font-size: 72rpx; }
.hero-title { font-size: 36rpx; font-weight: 700; color: var(--color-text); margin-top: 12rpx; }
.hero-desc { font-size: 24rpx; color: var(--color-text-secondary); margin-top: 8rpx; text-align: center; }
.product-card { background: #fff; border-radius: var(--radius-lg); margin: 0 32rpx; padding: 32rpx; box-shadow: var(--shadow-sm); }
.qty-section { margin-bottom: 24rpx; }
.section-label { font-size: 26rpx; font-weight: 600; color: var(--color-text); display: block; margin-bottom: 16rpx; }
.qty-controls { display: flex; align-items: center; justify-content: center; gap: 24rpx; }
.qty-btn { width: 64rpx; height: 64rpx; border-radius: 50%; background: #F3F4F6; display: flex; align-items: center; justify-content: center; font-size: 36rpx; font-weight: 500; color: var(--color-text); }
.qty-btn.disabled { color: #D1D5DB; background: #F9FAFB; }
.qty-input { width: 120rpx; height: 72rpx; text-align: center; font-size: 36rpx; font-weight: 700; color: var(--color-text); border: 2rpx solid #E5E7EB; border-radius: var(--radius-sm); }
.summary { margin-bottom: 32rpx; }
.summary-row { display: flex; justify-content: space-between; padding: 12rpx 0; border-bottom: 1rpx solid #F3F4F6; }
.summary-row.total { border-bottom: none; padding-top: 16rpx; }
.summary-label { font-size: 24rpx; color: var(--color-text-secondary); }
.summary-val { font-size: 26rpx; font-weight: 600; color: var(--color-text); }
.summary-val.highlight { color: var(--color-primary); }
.total-price { font-size: 36rpx; font-weight: 800; color: var(--color-primary); }
.buy-btn { width: 100%; height: 88rpx; background: linear-gradient(135deg, var(--color-gradient-start), var(--color-gradient-mid)); color: #fff; font-size: 30rpx; font-weight: 600; border-radius: var(--radius-lg); display: flex; align-items: center; justify-content: center; border: none; }
.buy-btn:active { opacity: 0.85; transform: scale(0.98); }
.buy-btn[disabled] { opacity: 0.5; }
/* 支付弹窗 */
.modal-overlay { position: fixed; top: 0; left: 0; right: 0; bottom: 0; background: rgba(0,0,0,0.5); display: flex; align-items: center; justify-content: center; z-index: 100; }
.modal-content { background: #FFF; border-radius: var(--radius-xl); padding: 40rpx; width: 70%; display: flex; flex-direction: column; align-items: center; gap: 20rpx; }
.modal-title { font-size: 28rpx; font-weight: 600; color: var(--color-text); }
.modal-content { background: #FFF; border-radius: var(--radius-xl); padding: 40rpx 32rpx; width: 600rpx; display: flex; flex-direction: column; align-items: center; gap: 16rpx; }
.modal-title { font-size: 30rpx; font-weight: 700; color: var(--color-text); }
.pay-error { color: var(--color-error); }
.qr-canvas { width: 400rpx; height: 400rpx; background: #FFF; border-radius: var(--radius-md); }
.modal-hint { font-size: 22rpx; color: var(--color-text-tertiary); }
.modal-close { font-size: 22rpx; color: var(--color-text-tertiary); padding: 8rpx; }
.modal-hint { font-size: 22rpx; color: #6B7280; text-align: center; }
.modal-close { font-size: 24rpx; color: #9CA3AF; padding: 12rpx 24rpx; }
.qrcode { width: 300rpx; height: 300rpx; margin: 8rpx 0; }
</style>
+116 -25
View File
@@ -4,8 +4,8 @@
<view class="stats-card">
<view class="stat-row">
<view class="stat-item">
<text class="stat-value">{{ stats.shareCredits || 0 }}</text>
<text class="stat-label">📦 我的积分</text>
<text class="stat-value">{{ stats.gravity ?? 0 }}</text>
<text class="stat-label">🌌 我的引力值</text>
</view>
</view>
<view class="stat-sub-row">
@@ -20,12 +20,12 @@
</view>
<view class="stat-arrow"></view>
<view class="stat-sub-item">
<text class="stat-sub-value">{{ stats.shareCredits || 0 }}</text>
<text class="stat-sub-label">获得积分</text>
<text class="stat-sub-value">{{ stats.gravity || 0 }}</text>
<text class="stat-sub-label">获得引力值</text>
</view>
</view>
<view class="hint">
💡 好友通过你的链接打开并 <text class="hint-em">登录/注册</text> 才算有效每次有效 1 积分
💡 好友通过你的链接打开并 <text class="hint-em">登录/注册</text> 才算有效每次有效 1 引力值每日上限 3
</view>
</view>
@@ -49,19 +49,41 @@
<view class="today-bar">
<view class="today-bar-fill" :style="{ width: Math.min(100, (todayStats.credited / 3) * 100) + '%' }"></view>
</view>
<text class="today-hint">每日最多 3 次有效积分</text>
<text class="today-hint">每日最多 3 次有效引力值分享给朋友圈可获更多</text>
</view>
<!-- 分享按钮 -->
<view class="share-actions">
<button class="share-btn wx-share" @click="shareToWechat" v-if="isWechat">
<text class="btn-icon">💬</text>
<text>分享给微信好友</text>
</button>
<button class="share-btn link-share" @click="copyLink">
<text class="btn-icon">🔗</text>
<text>复制分享链接</text>
</button>
<!-- #ifdef MP-WEIXIN -->
<view class="share-btn-row">
<button class="share-btn wx-share" open-type="share">
<text class="btn-icon">💬</text>
<text>分享给好友</text>
</button>
<view class="share-btn wx-timeline-hint" @click="showTimelineHint">
<text class="btn-icon">🔄</text>
<text>分享朋友圈</text>
</view>
</view>
<!-- #endif -->
<!-- #ifdef H5 -->
<view class="share-btn-row">
<button class="share-btn wx-share" @click="shareToWechat" v-if="isWechat">
<text class="btn-icon">💬</text>
<text>分享给微信好友</text>
</button>
<button class="share-btn wx-timeline" @click="shareToWechat" v-if="isWechat">
<text class="btn-icon">🔄</text>
<text>分享朋友圈</text>
</button>
</view>
<!-- #endif -->
<view class="share-btn-row">
<button class="share-btn link-share" @click="copyLink">
<text class="btn-icon">🔗</text>
<text>复制分享链接</text>
</button>
</view>
</view>
<!-- Tab 切换 -->
@@ -113,10 +135,15 @@
<script setup>
import { ref, computed, onMounted } from 'vue'
// #ifdef MP-WEIXIN
import { onShareAppMessage, onShareTimeline } from '@dcloudio/uni-app'
// #endif
import { api } from '../../config'
const tab = ref('records')
const stats = ref({ totalShares: 0, totalVisits: 0, creditedCount: 0, todayCredited: 0, shareCredits: 0 })
const stats = ref({ totalShares: 0, totalVisits: 0, creditedCount: 0, todayCredited: 0, shareCredits: 0, gravity: 0 })
const shareLink = ref('')
const shareUrlCached = ref('')
const records = ref([])
const visitors = ref([])
@@ -127,6 +154,18 @@ const todayStats = computed(() => ({
const isWechat = ref(false)
// #ifdef MP-WEIXIN
onShareAppMessage(() => ({
title: 'AI磁场·职引 — AI模拟面试+简历优化',
path: '/pages/share/share',
imageUrl: 'https://zhiyinwx.yzrcloud.cn/static/share-card.png',
}))
onShareTimeline(() => ({
title: 'AI磁场·职引 — AI模拟面试+简历优化',
imageUrl: 'https://zhiyinwx.yzrcloud.cn/static/share-card.png',
}))
// #endif
onMounted(() => {
// #ifdef H5
isWechat.value = navigator?.userAgent?.toLowerCase().includes('micromessenger') || false
@@ -139,6 +178,21 @@ async function loadData() {
if (!token) { uni.showToast({ title: '请先登录', icon: 'none' }); return }
const header = { Authorization: `Bearer ${token}` }
// 使
try {
const res = await uni.request({
url: api('/share/create'), method: 'POST',
data: { type: 'app', title: '我在AI磁场·职引练习面试', description: 'AI模拟面试+简历优化,快来一起提升吧' },
header,
})
if (res.statusCode >= 200 && res.statusCode < 300) {
const data = res.data?.data || res.data
if (data.shareCode) {
shareUrlCached.value = `https://zhiyinwx.yzrcloud.cn/api/share/${data.shareCode}`
}
}
} catch (e) { /* create share is best-effort */ }
try {
const [statsRes, recordsRes, visitorsRes] = await Promise.all([
uni.request({ url: api('/share/stats'), method: 'GET', header }),
@@ -162,7 +216,7 @@ async function shareToWechat() {
data: { type: 'app', title: '我在AI磁场·职引练习面试', description: 'AI模拟面试+简历优化,快来一起提升吧' },
header: { Authorization: `Bearer ${token}` },
})
if (res.statusCode !== 200) return
if (res.statusCode < 200 || res.statusCode >= 300) return
const data = res.data
const path = data.wechatShareInfo?.path || `/pages/share/share?code=${data.shareCode}`
@@ -181,19 +235,49 @@ async function shareToWechat() {
async function copyLink() {
const token = uni.getStorageSync('token')
if (!token) return
if (!token) { uni.showToast({ title: '请先登录', icon: 'none' }); return }
if (shareUrlCached.value) {
// 使 API
uni.setClipboardData({
data: shareUrlCached.value,
success: () => { uni.showToast({ title: '链接已复制' }); loadData() },
fail: () => { uni.showToast({ title: '复制失败,请长按选择复制', icon: 'none' }) },
})
return
}
// API
try {
const res = await uni.request({
url: api('/share/create'),
method: 'POST',
url: api('/share/create'), method: 'POST',
data: { type: 'app', title: '我在AI磁场·职引练习面试', description: 'AI模拟面试+简历优化,快来一起提升吧' },
header: { Authorization: `Bearer ${token}` },
})
if (res.statusCode !== 200) return
const shareUrl = `https://zhiyinwx.yzrcloud.cn/share/${res.data.shareCode}`
uni.setClipboardData({ data: shareUrl, success: () => { uni.showToast({ title: '链接已复制' }); loadData() } })
} catch (e) { console.error(e) }
if (res.statusCode < 200 || res.statusCode >= 300) {
uni.showToast({ title: `创建失败(${res.statusCode}),请重试`, icon: 'none' })
return
}
const data = res.data?.data || res.data
if (!data.shareCode) {
uni.showToast({ title: '返回数据异常,请重试', icon: 'none' })
return
}
const shareUrl = `https://zhiyinwx.yzrcloud.cn/api/share/${data.shareCode}`
shareUrlCached.value = shareUrl
uni.setClipboardData({
data: shareUrl,
success: () => { uni.showToast({ title: '链接已复制' }); loadData() },
fail: () => { uni.showToast({ title: '复制失败,请长按选择复制', icon: 'none' }) },
})
} catch (e) {
console.error('[share] copyLink error:', e)
uni.showToast({ title: '网络错误,请重试', icon: 'none' })
}
}
function showTimelineHint() {
uni.showToast({ title: '请点击右上角 ··· 选择分享到朋友圈', icon: 'none', duration: 3000 })
}
function typeLabel(type) {
@@ -238,11 +322,18 @@ function formatTime(t) {
.today-hint { font-size: 18rpx; color: var(--color-text-tertiary); text-align: center; }
/* Share buttons */
.share-actions { padding: 0 32rpx; display: flex; gap: 20rpx; }
.share-btn { flex: 1; display: flex; align-items: center; justify-content: center; height: 88rpx; border-radius: var(--radius-md); font-size: 26rpx; font-weight: 500; border: none; }
.share-actions { padding: 0 32rpx; display: flex; flex-direction: column; gap: 16rpx; }
.share-btn-row { display: flex; gap: 20rpx; }
.share-btn {
flex: 1; display: flex; align-items: center; justify-content: center; height: 88rpx; border-radius: var(--radius-md);
font-size: 26rpx; font-weight: 500; border: none; padding: 0; white-space: nowrap;
}
.share-btn:active { transform: scale(0.96); }
.btn-icon { margin-right: 8rpx; font-size: 28rpx; }
.wx-share { background: #07C160; color: #FFFFFF; }
.wx-timeline { background: #FF6600; color: #FFFFFF; }
.wx-timeline-hint { flex: 1; display: flex; align-items: center; justify-content: center; height: 88rpx; border-radius: var(--radius-md); font-size: 26rpx; font-weight: 500; background: #FF6600; color: #FFFFFF; white-space: nowrap; }
.wx-timeline-hint:active { transform: scale(0.96); }
.link-share { background: #FFFFFF; color: var(--color-text); border: 2rpx solid var(--color-border); }
/* Tabs */
+159 -3
View File
@@ -39,6 +39,25 @@
</view>
</view>
<!-- 引力值卡片代替原配额卡片 -->
<view class="gravity-card" v-if="isLoggedIn">
<view class="gravity-card-inner">
<view class="gravity-top-row">
<view class="gravity-header">
<text class="gravity-icon"></text>
<text class="gravity-label">我的引力值</text>
</view>
<text class="gravity-num">{{ memberInfo.gravity ?? 0 }}</text>
</view>
<text class="gravity-hint">每次面试消耗 5 引力值 · 分享可获得更多</text>
<view class="gravity-actions">
<text class="gravity-btn share" @click="goSharePage">分享得引力值</text>
<text class="gravity-btn contribute" @click="goContributePage">贡献面经</text>
<text class="gravity-btn h5buy" @click="goH5Buy">官网购买</text>
</view>
</view>
</view>
<!-- 菜单列表 -->
<view class="menu-area">
<view class="menu-group">
@@ -58,23 +77,33 @@
<text class="menu-text">面试复盘</text>
<text class="menu-arrow"></text>
</view>
<!-- 会员中心菜单注释隐藏微信审核 -->
<!--
<view class="menu-item" @click="goVip">
<view class="menu-icon-wrap wrap-purple"><text class="menu-icon">💎</text></view>
<text class="menu-text">会员中心</text>
<text class="menu-arrow"></text>
</view>
-->
<view class="menu-item" @click="requireLogin(goResume, '我的简历')">
<view class="menu-icon-wrap wrap-green"><text class="menu-icon">📄</text></view>
<text class="menu-text">我的简历</text>
<text class="menu-arrow"></text>
</view>
<view class="menu-item" @click="requireLogin(goShare, '我的分享')">
<view class="menu-item" @click="requireLogin(goSharePage, '我的分享')">
<view class="menu-icon-wrap wrap-orange"><text class="menu-icon">📤</text></view>
<text class="menu-text">我的分享</text>
<text class="menu-arrow"></text>
</view>
</view>
<view class="menu-group">
<!-- #ifdef MP-WEIXIN -->
<button class="menu-item contact-btn" open-type="contact">
<view class="menu-icon-wrap wrap-gray"><text class="menu-icon">💬</text></view>
<text class="menu-text">联系客服</text>
<text class="menu-arrow"></text>
</button>
<!-- #endif -->
<view class="menu-item" @click="goAbout">
<view class="menu-icon-wrap wrap-gray"><text class="menu-icon"></text></view>
<text class="menu-text">关于</text>
@@ -90,6 +119,46 @@
<button class="logout-btn" @click="doLogout">退出登录</button>
</view>
</view>
<!-- 引力值获取方式 -->
<view class="modal-overlay" v-if="showGetGravityModal" @click="showGetGravityModal = false">
<view class="modal-content" @click.stop>
<text class="modal-title">获取引力值</text>
<text class="modal-hint">引力值可用于面试简历优化下载等</text>
<!-- 分享得引力值 -->
<view class="gp-get-method" @click="goSharePage">
<view class="gp-method-icon-wrap"><text class="gp-method-icon">🎁</text></view>
<view class="gp-method-info">
<text class="gp-method-name">分享给好友</text>
<text class="gp-method-desc">每成功邀请一位好友注册可得 5 引力值上不封顶</text>
</view>
<text class="gp-method-arrow"></text>
</view>
<!-- 贡献面经 -->
<view class="gp-get-method" @click="goContributePage">
<view class="gp-method-icon-wrap"><text class="gp-method-icon">📝</text></view>
<view class="gp-method-info">
<text class="gp-method-name">贡献面经</text>
<text class="gp-method-desc">每发布一篇面经可获得 3 引力值助力他人也提升自己</text>
</view>
<text class="gp-method-arrow"></text>
</view>
<!-- 官网购买 -->
<view class="gp-get-method" @click="goH5Buy">
<view class="gp-method-icon-wrap"><text class="gp-method-icon">🛒</text></view>
<view class="gp-method-info">
<text class="gp-method-name">官网购买</text>
<text class="gp-method-desc">通过官网网页端可购买引力值套餐支持更多支付方式</text>
</view>
<text class="gp-method-arrow"></text>
</view>
<text class="modal-close" @click="showGetGravityModal = false">关闭</text>
</view>
</view>
</view>
</template>
@@ -102,6 +171,7 @@ const userInfo = ref({})
const isAdmin = ref(false)
const stats = ref({ interviewCount: 0, avgScore: '--', completedCount: 0 })
const token = ref('')
const memberInfo = ref({ plan: 'free', planName: '免费版', remaining: 0, gravity: 0 })
const isLoggedIn = computed(() => !!token.value)
const maskedId = computed(() => {
@@ -114,6 +184,7 @@ const refreshState = () => {
if (!token.value) return
try { const s = uni.getStorageSync('userInfo'); if (s) userInfo.value = JSON.parse(s) } catch(e) {}
loadStats()
loadMemberStatus()
checkAdmin()
fetchUserInfo()
}
@@ -131,6 +202,16 @@ const fetchUserInfo = async () => {
onMounted(refreshState)
onShow(refreshState)
const loadMemberStatus = async () => {
if (!token.value) return
try {
const res = await uni.request({ url: api('/member/status'), method: 'GET', header: { 'Authorization': `Bearer ${token.value}` } })
if (res.statusCode >= 200 && res.statusCode < 300 && res.data) {
memberInfo.value = { plan: res.data.plan || 'free', planName: res.data.planName || '免费版', remaining: res.data.remaining ?? 0, gravity: res.data.gravity ?? 0 }
}
} catch(e) { /* silent */ }
}
const loadStats = async () => {
try {
const res = await uni.request({ url: api('/interview/stats/mine'), method: 'GET', header: { 'Authorization': `Bearer ${token.value}` } })
@@ -153,12 +234,36 @@ const checkAdmin = () => {
}
const goLogin = () => uni.navigateTo({ url: '/pages/login/login' })
//
const showGetGravityModal = ref(false)
const openBuyModal = () => { showGetGravityModal.value = true }
const goH5Buy = () => {
const token = uni.getStorageSync('token') || ''
const url = `https://zhiyin.yzrcloud.cn/?buy=gravity${token ? '&token=' + token : ''}`
// #ifdef H5
uni.navigateTo({ url: '/pages/member/member' })
// #endif
// #ifdef MP-WEIXIN
uni.setClipboardData({
data: url,
success: () => {
uni.showToast({ title: '链接已复制,请在手机浏览器中打开', icon: 'none', duration: 3000 })
},
fail: () => {
uni.showToast({ title: '复制失败,请手动访问 zhiyin.yzrcloud.cn', icon: 'none', duration: 3000 })
},
})
// #endif
}
const goCareer = () => uni.navigateTo({ url: '/pages/career/career' })
const goHistory = () => uni.switchTab({ url: '/pages/history/history' })
const goReviewReview = () => uni.navigateTo({ url: '/pages/review/review' })
const goVip = () => uni.navigateTo({ url: '/pages/member/member' })
const goResume = () => uni.navigateTo({ url: '/pages/resume/resume' })
const goShare = () => uni.navigateTo({ url: '/pages/share/share' })
const goSharePage = () => uni.navigateTo({ url: '/pages/share/share' })
const goContributePage = () => uni.navigateTo({ url: '/pages/contribute/contribute' })
const goAdmin = () => uni.navigateTo({ url: '/pages/admin/admin' })
const goAbout = () => uni.navigateTo({ url: '/pages/about/about' })
@@ -197,9 +302,36 @@ const doLogout = () => {
.guest-info { flex: 1; }
.guest-name { font-size: 30rpx; font-weight: 600; color: #FFFFFF; }
.menu-area { padding: 0 32rpx 32rpx; margin-top: -40rpx; }
/* 引力值卡片(代替原配额卡片) */
.gravity-card { margin: -48rpx 32rpx 16rpx; position: relative; z-index: 1; }
.gravity-card-inner {
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
border-radius: var(--radius-xl);
padding: 28rpx 24rpx 24rpx;
box-shadow: 0 8rpx 32rpx rgba(102,126,234,0.25);
}
.gravity-top-row { display: flex; align-items: baseline; justify-content: space-between; margin-bottom: 8rpx; }
.gravity-header { display: flex; align-items: center; gap: 8rpx; }
.gravity-icon { font-size: 32rpx; }
.gravity-label { font-size: 24rpx; color: rgba(255,255,255,0.8); font-weight: 500; }
.gravity-num { font-size: 48rpx; font-weight: 800; color: #FFFFFF; line-height: 1; }
.gravity-hint { font-size: 20rpx; color: rgba(255,255,255,0.6); margin-bottom: 20rpx; }
.gravity-actions { display: flex; gap: 16rpx; }
.gravity-btn {
flex: 1; text-align: center; padding: 18rpx 0; border-radius: var(--radius-md);
font-size: 26rpx; font-weight: 600; white-space: nowrap;
}
.gravity-btn.share { background: rgba(255,255,255,0.2); color: #FFFFFF; border: 2rpx solid rgba(255,255,255,0.3); }
.gravity-btn.h5buy { background: #FFFFFF; color: #667eea; }
.gravity-btn.contribute { background: rgba(255,255,255,0.15); color: #FFFFFF; border: 2rpx solid rgba(255,255,255,0.2); }
.gravity-btn:active { transform: scale(0.96); }
.menu-area { padding: 0 32rpx 32rpx; margin-top: 8rpx; }
.menu-group { background: #FFFFFF; border-radius: var(--radius-lg); overflow: hidden; margin-bottom: 24rpx; box-shadow: var(--shadow-sm); }
.menu-item { display: flex; align-items: center; padding: 28rpx 32rpx; border-bottom: 1rpx solid var(--color-border); }
.contact-btn { width: 100%; background: transparent; border: none; border-radius: 0; padding: 0; margin: 0; line-height: inherit; font-size: inherit; text-align: left; }
.contact-btn::after { border: none; }
.contact-btn:active { background: #F9FAFB; }
.menu-item:last-child { border-bottom: none; }
.menu-item:active { background: #F9FAFB; }
.menu-icon-wrap { width: 60rpx; height: 60rpx; border-radius: var(--radius-md); display: flex; align-items: center; justify-content: center; margin-right: 20rpx; flex-shrink: 0; }
@@ -216,4 +348,28 @@ const doLogout = () => {
.logout-wrap { margin-top: 8rpx; }
.logout-btn { background: #FFFFFF; color: var(--color-error); font-size: 28rpx; font-weight: 500; border-radius: var(--radius-md); height: 88rpx; line-height: 88rpx; border: 2rpx solid #FECACA; }
.logout-btn:active { background: #FEF2F2; transform: scale(0.96); }
/* 弹窗通用 */
.modal-overlay { position: fixed; top: 0; left: 0; right: 0; bottom: 0; background: rgba(0,0,0,0.5); display: flex; align-items: center; justify-content: center; z-index: 100; }
.modal-content { background: #FFF; border-radius: var(--radius-xl); padding: 40rpx 32rpx; width: 600rpx; max-height: 80vh; overflow-y: auto; display: flex; flex-direction: column; align-items: center; gap: 16rpx; }
.modal-title { font-size: 30rpx; font-weight: 700; color: var(--color-text); }
.modal-hint { font-size: 22rpx; color: #6B7280; text-align: center; }
.modal-close { font-size: 24rpx; color: #9CA3AF; padding: 12rpx 24rpx; }
/* 获取引力值弹窗 - 分享/贡献方法 */
.gp-get-method {
width: 100%; display: flex; align-items: center; gap: 16rpx;
background: #F9FAFB; border-radius: var(--radius-md); padding: 20rpx;
border: 2rpx solid #E5E7EB; margin-top: 8rpx;
}
.gp-get-method:active { transform: scale(0.97); background: #F3F4F6; }
.gp-method-icon-wrap {
width: 64rpx; height: 64rpx; border-radius: var(--radius-md);
background: #EEF2FF; display: flex; align-items: center; justify-content: center; flex-shrink: 0;
}
.gp-method-icon { font-size: 32rpx; }
.gp-method-info { flex: 1; display: flex; flex-direction: column; gap: 4rpx; }
.gp-method-name { font-size: 26rpx; font-weight: 600; color: var(--color-text); }
.gp-method-desc { font-size: 20rpx; color: #6B7280; line-height: 1.4; }
.gp-method-arrow { font-size: 32rpx; color: #D1D5DB; }
</style>