Compare commits
3 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| a1e1f0b3c3 | |||
| 2fbab1072f | |||
| c2ba810a02 |
@@ -1,10 +1,10 @@
|
|||||||
{
|
{
|
||||||
"sessionID": "ses_15492f54bffepl01q9FkaRyN28",
|
"sessionID": "ses_15492f54bffepl01q9FkaRyN28",
|
||||||
"updatedAt": "2026-06-16T01:20:56.855Z",
|
"updatedAt": "2026-06-19T07:14:26.627Z",
|
||||||
"sources": {
|
"sources": {
|
||||||
"background-task": {
|
"background-task": {
|
||||||
"state": "idle",
|
"state": "idle",
|
||||||
"updatedAt": "2026-06-16T01:20:56.855Z"
|
"updatedAt": "2026-06-19T07:14:26.627Z"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -40,7 +40,7 @@ zhiyin/
|
|||||||
| `payment` | 微信支付 v3(Native + JSAPI + 回调) |
|
| `payment` | 微信支付 v3(Native + JSAPI + 回调) |
|
||||||
| `progress` | 进步轨迹雷达图 / 打卡日历 / 行业基准 / 岗位匹配 |
|
| `progress` | 进步轨迹雷达图 / 打卡日历 / 行业基准 / 岗位匹配 |
|
||||||
| `contribution` | 面经贡献 + 公司题库(数据飞轮核心) |
|
| `contribution` | 面经贡献 + 公司题库(数据飞轮核心) |
|
||||||
| `schedule` | 定时任务:VIP 过期降级、每日一题推送、微信 token 刷新 |
|
| `schedule` | 定时任务:VIP 过期降级、每日一题推送、微信 token 刷新、月度引力值补给 |
|
||||||
| `share` | 分享链接生成 / 访问追踪 / 积分奖励 |
|
| `share` | 分享链接生成 / 访问追踪 / 积分奖励 |
|
||||||
| `tts` | 语音合成(TTS) |
|
| `tts` | 语音合成(TTS) |
|
||||||
| `admin` | 管理后台 API |
|
| `admin` | 管理后台 API |
|
||||||
@@ -105,6 +105,10 @@ zhiyin/
|
|||||||
|
|
||||||
## 三、开发命令
|
## 三、开发命令
|
||||||
|
|
||||||
|
> ⚠️ **构建铁律:必须始终使用 `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
|
```bash
|
||||||
# 路径: backend/
|
# 路径: backend/
|
||||||
@@ -130,12 +134,12 @@ npm test # 前端单元测试(vitest,7 个)
|
|||||||
### 构建检查
|
### 构建检查
|
||||||
```bash
|
```bash
|
||||||
# 后端构建(注意 OOM:需 NODE_OPTIONS="--max-old-space-size=2048")
|
# 后端构建(注意 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
|
```bash
|
||||||
cd backend && npx nest build
|
cd backend && npm run build
|
||||||
cp -rf dist/* /www/wwwroot/server/zhiyin/backend/dist/
|
cp -rf dist/* /www/wwwroot/server/zhiyin/backend/dist/
|
||||||
cp -r certs /www/wwwroot/server/zhiyin/backend/dist/src/certs
|
cp -r certs /www/wwwroot/server/zhiyin/backend/dist/src/certs
|
||||||
pm2 restart yhl-backend
|
pm2 restart yhl-backend
|
||||||
@@ -144,7 +148,7 @@ sleep 3 && curl -s http://localhost:3006/api/user/wx-login -X POST -H "Content-T
|
|||||||
|
|
||||||
### 部署前端 H5
|
### 部署前端 H5
|
||||||
```bash
|
```bash
|
||||||
cd zhiyin-app && npx uni build
|
cd zhiyin-app && npm run build:h5
|
||||||
rm -rf /www/wwwroot/zhiyin.yzrcloud.cn/assets
|
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/index.html /www/wwwroot/zhiyin.yzrcloud.cn/
|
||||||
cp -r dist/build/h5/assets /www/wwwroot/zhiyin.yzrcloud.cn/
|
cp -r dist/build/h5/assets /www/wwwroot/zhiyin.yzrcloud.cn/
|
||||||
@@ -153,9 +157,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
|
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
|
```bash
|
||||||
cd zhiyin-app && npm run build:mp-weixin && node scripts/upload-mp.js
|
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 +177,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 计划 |
|
| `VipExpiryService` | 每日 00:00 | 扫描过期 VIP 并降级为 free 计划 |
|
||||||
| `DailyQuestionPushService` | 每日 09:00 | 通过微信订阅消息推送每日一题(需配置模板 ID) |
|
| `DailyQuestionPushService` | 每日 09:00 | 通过微信订阅消息推送每日一题(需配置模板 ID) |
|
||||||
| `WechatTokenService` | 每 2 小时 | 刷新微信 access_token(缓存到 Redis) |
|
| `WechatTokenService` | 每 2 小时 | 刷新微信 access_token(缓存到 Redis) |
|
||||||
|
| `GravityTopUpService` | 每日 02:00 | 给所有未过期的成长版/冲刺版用户补给月度引力值 |
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
## 六、项目状态与开发阶段
|
## 六、项目状态与开发阶段
|
||||||
|
|
||||||
**当前**: Phase 0.5 完成,Phase 1(MVP 上线)进行中
|
**当前**: Phase 1(MVP 上线)进行中 — v1.0.16
|
||||||
|
|
||||||
| 阶段 | 状态 | 关键交付 |
|
| 阶段 | 状态 | 关键交付 |
|
||||||
|------|------|---------|
|
|------|------|---------|
|
||||||
| Phase 0: 战略升级 | ✅ 完成 | 定价重构(免费 + ¥19.9/月),三层壁垒设计 |
|
| Phase 0: 战略升级 | ✅ 完成 | 定价重构(免费 + ¥19.9/月),三层壁垒设计 |
|
||||||
| Phase 0.5: 壁垒构建 | ✅ 完成 | 数据飞轮(面经贡献+题库),留存入围(进步轨迹+打卡日历+每日一题) |
|
| Phase 0.5: 壁垒构建 | ✅ 完成 | 数据飞轮(面经贡献+题库),留存入围(进步轨迹+打卡日历+每日一题) |
|
||||||
| Phase 1: MVP 上线 | 🚧 当前 | 小程序 v1.0.11 已上传、H5 已部署、生产模式已启用、SMTP 邮箱验证码已配置 |
|
| Phase 1: MVP 上线 | 🚧 当前 | 小程序 v1.0.16 已上传、引力值体系统一(VIP 不再无限次)、管理后台完善、H5 已部署、生产模式已启用 |
|
||||||
| Phase 1.5: 商业化 | 📋 规划 | 冲刺版 ¥49.9/月、每日一题定时推送、PMF 验证 |
|
| Phase 1.5: 商业化 | 📋 规划 | 引力值运营策略、每日一题定时推送、PMF 验证 |
|
||||||
| Phase 2: 增强 + 题库 | 📋 规划 | 50+ 校招岗位、技能缺口分析、公司真题库建设 |
|
| Phase 2: 增强 + 题库 | 📋 规划 | 50+ 校招岗位、技能缺口分析、公司真题库建设 |
|
||||||
| Phase 3: 秋招冲刺 | 📋 规划 | 高校合作、B 端服务、KOC 推广 |
|
| Phase 3: 秋招冲刺 | 📋 规划 | 高校合作、B 端服务、KOC 推广 |
|
||||||
|
|
||||||
@@ -265,8 +272,9 @@ VITE_APP_NAME=AI磁场
|
|||||||
6. **API 限流**: 100 次/60 秒(在 `app.module.ts` 中配置),注意避免在定时任务和批量操作中被限
|
6. **API 限流**: 100 次/60 秒(在 `app.module.ts` 中配置),注意避免在定时任务和批量操作中被限
|
||||||
7. **验证码**: 生产模式(`NODE_ENV=production`)使用真实 SMTP 发邮件验证码;非生产模式手机验证码固定为 `123456`、邮件验证码在响应中返回 `devCode`
|
7. **验证码**: 生产模式(`NODE_ENV=production`)使用真实 SMTP 发邮件验证码;非生产模式手机验证码固定为 `123456`、邮件验证码在响应中返回 `devCode`
|
||||||
8. **MongoDB**: 8 个核心集合 + 2 个分享集合
|
8. **MongoDB**: 8 个核心集合 + 2 个分享集合
|
||||||
9. **api.ts 陷阱**: 对象字面量必须在 `export const apiService = {` 或 `const apiService = { ... export default apiService` 中包裹,否则 uni-app 构建报错 `Expected ";" but found ":"`。git pull 后经常丢失这行声明,需手动补回
|
9. **引力值体系**: 所有计划统一走引力值消耗(面试 5、优化 3、下载 2)。VIP 不再免额度,成长版每月 250 引力值,冲刺版每月 600 引力值,每日凌晨 2 点定时补给。免费用户注册送 5 引力值。
|
||||||
10. **H5 构建 assets 清理**: `assets/` 中的旧 hash 文件不能随意删除——`index-*.js`(主 bundle)动态 import 了所有 page chunk,删除仍在引用的文件会导致浏览器 `NS_ERROR_CORRUPTED_CONTENT`
|
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`
|
||||||
11. **管理后台自动验证**: `admin.vue` 中 `onMounted` 自动调用 `doVerify()`,进入后台即检测 JWT 中 `role` 是否为 `admin`,不再需要手动点击"验证管理员身份"按钮
|
11. **管理后台自动验证**: `admin.vue` 中 `onMounted` 自动调用 `doVerify()`,进入后台即检测 JWT 中 `role` 是否为 `admin`,不再需要手动点击"验证管理员身份"按钮
|
||||||
|
|
||||||
---
|
---
|
||||||
@@ -295,7 +303,7 @@ VITE_APP_NAME=AI磁场
|
|||||||
|
|
||||||
### Step 4: 测试验证
|
### Step 4: 测试验证
|
||||||
```bash
|
```bash
|
||||||
cd backend && NODE_OPTIONS="--max-old-space-size=2048" npx nest build
|
cd backend && npm run build
|
||||||
npm test -- --forceExit --detectOpenHandles
|
npm test -- --forceExit --detectOpenHandles
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|||||||
@@ -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)
|
||||||
@@ -113,7 +113,7 @@ export class AdminController {
|
|||||||
expireAt.setDate(expireAt.getDate() + (pricing.plans?.growth?.durationDays || VIP_DURATION_DAYS))
|
expireAt.setDate(expireAt.getDate() + (pricing.plans?.growth?.durationDays || VIP_DURATION_DAYS))
|
||||||
user.plan = 'growth'
|
user.plan = 'growth'
|
||||||
user.vipExpireAt = expireAt
|
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 }
|
return { success: true, plan: 'growth', expireAt }
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -122,7 +122,7 @@ export class AdminController {
|
|||||||
if (!userId || !type || amount === undefined) {
|
if (!userId || !type || amount === undefined) {
|
||||||
throw new HttpException('参数不完整', HttpStatus.BAD_REQUEST)
|
throw new HttpException('参数不完整', HttpStatus.BAD_REQUEST)
|
||||||
}
|
}
|
||||||
const validTypes = ['interviewCredits', 'resumeOptimizeCredits', 'resumeDownloadCredits', 'shareCredits']
|
const validTypes = ['interviewCredits', 'resumeOptimizeCredits', 'resumeDownloadCredits', 'shareCredits', 'gravity']
|
||||||
if (!validTypes.includes(type)) {
|
if (!validTypes.includes(type)) {
|
||||||
throw new HttpException('无效的额度类型', HttpStatus.BAD_REQUEST)
|
throw new HttpException('无效的额度类型', HttpStatus.BAD_REQUEST)
|
||||||
}
|
}
|
||||||
@@ -291,18 +291,18 @@ export class AdminController {
|
|||||||
} else {
|
} else {
|
||||||
user.vipExpireAt = expireAt
|
user.vipExpireAt = expireAt
|
||||||
}
|
}
|
||||||
await this.quotaService.setPlanQuota(order.userId, planId, credits)
|
await this.quotaService.setPlanQuota(order.userId, planCfg.gravityPerMonth)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
const pricing = await this.pricingService.getConfig()
|
const pricing = await this.pricingService.getConfig()
|
||||||
const creditMap: Record<string, number> = {
|
const gravityMap: Record<string, number> = {
|
||||||
interview: pricing.interview?.creditsPerPurchase || 1,
|
interview: pricing.gravityRates?.interviewPerUse || 5,
|
||||||
optimize: pricing.resumeOptimize?.creditsPerPurchase || 1,
|
optimize: pricing.gravityRates?.optimizePerUse || 3,
|
||||||
download: pricing.resumeDownload?.creditsPerPurchase || 1,
|
download: pricing.gravityRates?.downloadPerUse || 2,
|
||||||
}
|
}
|
||||||
const credits = creditMap[order.type]
|
const g = gravityMap[order.type]
|
||||||
if (credits) {
|
if (g) {
|
||||||
await this.quotaService.grantCredits(order.userId, order.type as any, credits)
|
await this.quotaService.grantGravity(order.userId, g)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -54,6 +54,12 @@ export class MemberController {
|
|||||||
|
|
||||||
return {
|
return {
|
||||||
interview: { dailyFreeLimit: FREE_DAILY_LIMIT, maxRoundsFree: 5, maxRoundsVip: 10 },
|
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,
|
plans,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -66,6 +72,7 @@ export class MemberController {
|
|||||||
plan: user.plan,
|
plan: user.plan,
|
||||||
planName: user.plan === 'growth' ? '成长版' : user.plan === 'sprint' ? '冲刺版' : '免费版',
|
planName: user.plan === 'growth' ? '成长版' : user.plan === 'sprint' ? '冲刺版' : '免费版',
|
||||||
remaining: user.remaining,
|
remaining: user.remaining,
|
||||||
|
gravity: user.gravity ?? 0,
|
||||||
dailyLimit: user.plan !== 'free' ? 999 : FREE_DAILY_LIMIT,
|
dailyLimit: user.plan !== 'free' ? 999 : FREE_DAILY_LIMIT,
|
||||||
vipExpireAt: user.vipExpireAt,
|
vipExpireAt: user.vipExpireAt,
|
||||||
sprintExpireAt: user.sprintExpireAt,
|
sprintExpireAt: user.sprintExpireAt,
|
||||||
@@ -101,7 +108,7 @@ export class MemberController {
|
|||||||
user.plan = 'growth'
|
user.plan = 'growth'
|
||||||
user.vipExpireAt = expireAt
|
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 }
|
return { success: true, plan: user.plan, planName: user.plan === 'growth' ? '成长版' : '冲刺版', expireAt }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -40,8 +40,8 @@ describe('PaymentController', () => {
|
|||||||
resumeOptimize: { freeLimit: 3, pricePerOptimize: 300, creditsPerPurchase: 1 },
|
resumeOptimize: { freeLimit: 3, pricePerOptimize: 300, creditsPerPurchase: 1 },
|
||||||
resumeDownload: { pricePerDownload: 200, creditsPerPurchase: 1 },
|
resumeDownload: { pricePerDownload: 200, creditsPerPurchase: 1 },
|
||||||
plans: {
|
plans: {
|
||||||
growth: { price: 1990, durationDays: 30, credits: { interview: 999, resumeOptimize: 20, resumeDownload: 10 }, features: [] },
|
growth: { price: 1990, durationDays: 30, gravityPerMonth: 250, credits: { interview: 999, resumeOptimize: 20, resumeDownload: 10 }, features: [] },
|
||||||
sprint: { price: 4990, durationDays: 30, credits: { interview: 999, resumeOptimize: 50, resumeDownload: 30 }, 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 () => {
|
it('should activate growth plan', async () => {
|
||||||
mockOrderModel.findOne.mockReturnValueOnce({ exec: jest.fn().mockResolvedValue({ outTradeNo: 'ORD123', userId: mockUserId, status: 'success', plan: 'growth', type: 'membership' }) })
|
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) })
|
mockUserModel.findById.mockReturnValueOnce({ exec: jest.fn().mockResolvedValue(mockUser) })
|
||||||
|
|
||||||
const result = await controller.activate(mockUserId, 'ORD123')
|
const result = await controller.activate(mockUserId, 'ORD123')
|
||||||
@@ -158,9 +158,8 @@ describe('PaymentController', () => {
|
|||||||
expect(result.plan).toBe('growth')
|
expect(result.plan).toBe('growth')
|
||||||
expect(mockUser.save).toHaveBeenCalled()
|
expect(mockUser.save).toHaveBeenCalled()
|
||||||
expect(mockUser.plan).toBe('growth')
|
expect(mockUser.plan).toBe('growth')
|
||||||
expect(mockUser.interviewCredits).toBe(999)
|
expect(mockUser.gravity).toBe(250)
|
||||||
expect(mockUser.resumeOptimizeCredits).toBe(20)
|
expect(mockUser.freeOptimizeUsed).toBe(3)
|
||||||
expect(mockUser.resumeDownloadCredits).toBe(10)
|
|
||||||
})
|
})
|
||||||
|
|
||||||
it('should activate sprint plan', async () => {
|
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 { InjectModel } from '@nestjs/mongoose'
|
||||||
import { Model } from 'mongoose'
|
import { Model } from 'mongoose'
|
||||||
import { User, UserDocument } from '../user/user.schema'
|
import { User, UserDocument } from '../user/user.schema'
|
||||||
@@ -25,6 +25,7 @@ export class PaymentController {
|
|||||||
/** 创建套餐订单(H5:Native 扫码支付) */
|
/** 创建套餐订单(H5:Native 扫码支付) */
|
||||||
@UseGuards(JwtAuthGuard)
|
@UseGuards(JwtAuthGuard)
|
||||||
@Post('create')
|
@Post('create')
|
||||||
|
@HttpCode(200)
|
||||||
async create(@CurrentUser('userId') userId: string, @Body('plan') plan: string = 'growth') {
|
async create(@CurrentUser('userId') userId: string, @Body('plan') plan: string = 'growth') {
|
||||||
if (!['growth', 'sprint'].includes(plan)) throw new HttpException('无效套餐', HttpStatus.BAD_REQUEST)
|
if (!['growth', 'sprint'].includes(plan)) throw new HttpException('无效套餐', HttpStatus.BAD_REQUEST)
|
||||||
const user = await this.userModel.findById(userId).exec()
|
const user = await this.userModel.findById(userId).exec()
|
||||||
@@ -49,11 +50,13 @@ export class PaymentController {
|
|||||||
async createProduct(
|
async createProduct(
|
||||||
@CurrentUser('userId') userId: string,
|
@CurrentUser('userId') userId: string,
|
||||||
@Body('type') type: string,
|
@Body('type') type: string,
|
||||||
|
@Body('quantity') quantity: number = 1,
|
||||||
@Body('metadata') metadata?: Record<string, any>,
|
@Body('metadata') metadata?: Record<string, any>,
|
||||||
) {
|
) {
|
||||||
if (!['interview', 'optimize', 'download'].includes(type)) {
|
if (!['interview', 'optimize', 'download'].includes(type)) {
|
||||||
throw new HttpException('无效产品类型', HttpStatus.BAD_REQUEST)
|
throw new HttpException('无效产品类型', HttpStatus.BAD_REQUEST)
|
||||||
}
|
}
|
||||||
|
const qty = Math.max(1, Math.min(99, quantity || 1))
|
||||||
const user = await this.userModel.findById(userId).exec()
|
const user = await this.userModel.findById(userId).exec()
|
||||||
if (!user) throw new HttpException('用户不存在', HttpStatus.NOT_FOUND)
|
if (!user) throw new HttpException('用户不存在', HttpStatus.NOT_FOUND)
|
||||||
|
|
||||||
@@ -63,40 +66,55 @@ export class PaymentController {
|
|||||||
optimize: pricing.resumeOptimize.pricePerOptimize,
|
optimize: pricing.resumeOptimize.pricePerOptimize,
|
||||||
download: pricing.resumeDownload.pricePerDownload,
|
download: pricing.resumeDownload.pricePerDownload,
|
||||||
}
|
}
|
||||||
const price = priceMap[type]
|
const price = priceMap[type] * qty
|
||||||
if (!price) throw new HttpException('价格未配置', HttpStatus.INTERNAL_SERVER_ERROR)
|
if (!priceMap[type]) throw new HttpException('价格未配置', HttpStatus.INTERNAL_SERVER_ERROR)
|
||||||
|
|
||||||
const titles: Record<string, string> = {
|
const titles: Record<string, string> = {
|
||||||
interview: 'AI 模拟面试单次',
|
interview: 'AI 模拟面试单次',
|
||||||
optimize: '简历优化单次',
|
optimize: '简历优化单次',
|
||||||
download: '简历下载',
|
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 outTradeNo = `${type.slice(0, 3).toUpperCase()}${Date.now()}${userId.slice(-6)}`
|
||||||
const result = await this.wechatPay.nativePay(title, outTradeNo, price)
|
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 支付(微信小程序) */
|
/** JSAPI 支付(微信小程序) */
|
||||||
@UseGuards(JwtAuthGuard)
|
@UseGuards(JwtAuthGuard)
|
||||||
@Post('jsapi')
|
@Post('jsapi')
|
||||||
|
@HttpCode(200)
|
||||||
async jsapi(@CurrentUser('userId') userId: string, @Body('plan') plan: string = 'growth') {
|
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)
|
if (!['growth', 'sprint'].includes(plan)) throw new HttpException('无效套餐', HttpStatus.BAD_REQUEST)
|
||||||
const user = await this.userModel.findById(userId).exec()
|
const user = await this.userModel.findById(userId).exec()
|
||||||
if (!user) throw new HttpException('用户不存在', HttpStatus.NOT_FOUND)
|
if (!user) { this.logger.warn(`[jsapi] 用户不存在 userId=${userId}`); throw new HttpException('用户不存在', HttpStatus.NOT_FOUND) }
|
||||||
if (user.plan !== 'free') throw new HttpException('已是会员', HttpStatus.BAD_REQUEST)
|
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
|
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()
|
const pricing = await this.pricingService.getConfig()
|
||||||
|
this.logger.log(`[jsapi] pricing获取成功`)
|
||||||
const planCfg = pricing.plans[plan === 'sprint' ? 'sprint' : 'growth']
|
const planCfg = pricing.plans[plan === 'sprint' ? 'sprint' : 'growth']
|
||||||
const amount = planCfg.price
|
const amount = planCfg.price
|
||||||
const title = plan === 'sprint' ? '职引冲刺版月度会员' : '职引成长版月度会员'
|
const title = plan === 'sprint' ? '职引冲刺版月度会员' : '职引成长版月度会员'
|
||||||
const outTradeNo = `${plan === 'sprint' ? 'SPR' : 'VIP'}${Date.now()}${userId.slice(-6)}`
|
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 })
|
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(
|
async jsapiProduct(
|
||||||
@CurrentUser('userId') userId: string,
|
@CurrentUser('userId') userId: string,
|
||||||
@Body('type') type: string,
|
@Body('type') type: string,
|
||||||
|
@Body('quantity') quantity: number = 1,
|
||||||
@Body('metadata') metadata?: Record<string, any>,
|
@Body('metadata') metadata?: Record<string, any>,
|
||||||
) {
|
) {
|
||||||
if (!['interview', 'optimize', 'download'].includes(type)) {
|
if (!['interview', 'optimize', 'download'].includes(type)) {
|
||||||
throw new HttpException('无效产品类型', HttpStatus.BAD_REQUEST)
|
throw new HttpException('无效产品类型', HttpStatus.BAD_REQUEST)
|
||||||
}
|
}
|
||||||
|
const qty = Math.max(1, Math.min(99, quantity || 1))
|
||||||
const user = await this.userModel.findById(userId).exec()
|
const user = await this.userModel.findById(userId).exec()
|
||||||
if (!user) throw new HttpException('用户不存在', HttpStatus.NOT_FOUND)
|
if (!user) throw new HttpException('用户不存在', HttpStatus.NOT_FOUND)
|
||||||
const openid = user.wxOpenid
|
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 pricing = await this.pricingService.getConfig()
|
||||||
const priceMap: Record<string, number> = {
|
const priceMap: Record<string, number> = {
|
||||||
@@ -125,21 +147,21 @@ export class PaymentController {
|
|||||||
optimize: pricing.resumeOptimize.pricePerOptimize,
|
optimize: pricing.resumeOptimize.pricePerOptimize,
|
||||||
download: pricing.resumeDownload.pricePerDownload,
|
download: pricing.resumeDownload.pricePerDownload,
|
||||||
}
|
}
|
||||||
const price = priceMap[type]
|
const price = priceMap[type] * qty
|
||||||
if (!price) throw new HttpException('价格未配置', HttpStatus.INTERNAL_SERVER_ERROR)
|
if (!priceMap[type]) throw new HttpException('价格未配置', HttpStatus.INTERNAL_SERVER_ERROR)
|
||||||
|
|
||||||
const titles: Record<string, string> = {
|
const titles: Record<string, string> = {
|
||||||
interview: 'AI 模拟面试单次',
|
interview: 'AI 模拟面试单次',
|
||||||
optimize: '简历优化单次',
|
optimize: '简历优化单次',
|
||||||
download: '简历下载',
|
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 outTradeNo = `${type.slice(0, 3).toUpperCase()}${Date.now()}${userId.slice(-6)}`
|
||||||
const result = await this.wechatPay.jsapiPay(title, outTradeNo, price, openid)
|
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 }
|
||||||
}
|
}
|
||||||
|
|
||||||
/** 支付回调通知 */
|
/** 支付回调通知 */
|
||||||
@@ -201,34 +223,22 @@ export class PaymentController {
|
|||||||
user.plan = 'growth'
|
user.plan = 'growth'
|
||||||
user.vipExpireAt = expireAt
|
user.vipExpireAt = expireAt
|
||||||
}
|
}
|
||||||
const credits = planCfg.credits
|
user.gravity = planCfg.gravityPerMonth
|
||||||
user.remaining = 999
|
|
||||||
user.interviewCredits = credits.interview
|
|
||||||
user.resumeOptimizeCredits = credits.resumeOptimize
|
|
||||||
user.resumeDownloadCredits = credits.resumeDownload
|
|
||||||
user.freeOptimizeUsed = 3
|
user.freeOptimizeUsed = 3
|
||||||
await user.save()
|
await user.save()
|
||||||
}
|
}
|
||||||
|
|
||||||
private async activateProduct(order: PaymentOrderDocument) {
|
private async activateProduct(order: PaymentOrderDocument) {
|
||||||
const pricing = await this.pricingService.getConfig()
|
const pricing = await this.pricingService.getConfig()
|
||||||
const creditMap: Record<string, number> = {
|
const gravityMap: Record<string, number> = {
|
||||||
interview: pricing.interview.creditsPerPurchase,
|
interview: pricing.gravityRates.interviewPerUse,
|
||||||
optimize: pricing.resumeOptimize.creditsPerPurchase,
|
optimize: pricing.gravityRates.optimizePerUse,
|
||||||
download: pricing.resumeDownload.creditsPerPurchase,
|
download: pricing.gravityRates.downloadPerUse,
|
||||||
}
|
|
||||||
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 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 请求 */
|
/** 发起 API v3 请求 */
|
||||||
private async request(method: string, apiPath: string, body?: any) {
|
private async request(method: string, apiPath: string, body?: any) {
|
||||||
const url = `${WX_API_BASE}${apiPath}`
|
const url = `${WX_API_BASE}${apiPath}`
|
||||||
|
const bodyStr = body ? JSON.stringify(body) : ''
|
||||||
|
this.logger.log(`[wxpay-request] ${method} ${apiPath} 请求体: ${bodyStr}`)
|
||||||
try {
|
try {
|
||||||
const res = await axios({
|
const res = await axios({
|
||||||
method,
|
method,
|
||||||
@@ -63,9 +65,12 @@ export class WechatPayService {
|
|||||||
},
|
},
|
||||||
data: body,
|
data: body,
|
||||||
})
|
})
|
||||||
|
this.logger.log(`[wxpay-request] ${method} ${apiPath} 成功: ${JSON.stringify(res.data)}`)
|
||||||
return res.data
|
return res.data
|
||||||
} catch (e: any) {
|
} 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
|
throw e
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -99,8 +104,15 @@ export class WechatPayService {
|
|||||||
amount: { total: amount, currency: 'CNY' },
|
amount: { total: amount, currency: 'CNY' },
|
||||||
payer: { openid },
|
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)
|
const result = await this.request('POST', '/v3/pay/transactions/jsapi', body)
|
||||||
|
this.logger.log(`[jsapiPay] 微信返回: ${JSON.stringify(result)}`)
|
||||||
const prepayId = result.prepay_id
|
const prepayId = result.prepay_id
|
||||||
|
if (!prepayId) {
|
||||||
|
this.logger.error(`[jsapiPay] 微信返回缺少prepay_id: ${JSON.stringify(result)}`)
|
||||||
|
throw new Error('微信下单失败: 缺少prepay_id')
|
||||||
|
}
|
||||||
// 生成小程序/JSAPI 调起支付参数
|
// 生成小程序/JSAPI 调起支付参数
|
||||||
const nonce = crypto.randomBytes(16).toString('hex')
|
const nonce = crypto.randomBytes(16).toString('hex')
|
||||||
const timestamp = Math.floor(Date.now() / 1000).toString()
|
const timestamp = Math.floor(Date.now() / 1000).toString()
|
||||||
|
|||||||
@@ -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,8 +3,10 @@ import { MongooseModule } from '@nestjs/mongoose'
|
|||||||
import { DailyQuestionPushService } from './daily-question-push.service'
|
import { DailyQuestionPushService } from './daily-question-push.service'
|
||||||
import { WechatTokenService } from './wechat-token.service'
|
import { WechatTokenService } from './wechat-token.service'
|
||||||
import { VipExpiryService } from './vip-expiry.service'
|
import { VipExpiryService } from './vip-expiry.service'
|
||||||
|
import { GravityTopUpService } from './gravity-top-up.service'
|
||||||
import { DailyQuestion, DailyQuestionSchema } from '../schemas/daily-question.schema'
|
import { DailyQuestion, DailyQuestionSchema } from '../schemas/daily-question.schema'
|
||||||
import { User, UserSchema } from '../user/user.schema'
|
import { User, UserSchema } from '../user/user.schema'
|
||||||
|
import { PricingService } from '../schemas/pricing.service'
|
||||||
|
|
||||||
@Module({
|
@Module({
|
||||||
imports: [
|
imports: [
|
||||||
@@ -13,6 +15,6 @@ import { User, UserSchema } from '../user/user.schema'
|
|||||||
{ name: User.name, schema: UserSchema },
|
{ name: User.name, schema: UserSchema },
|
||||||
]),
|
]),
|
||||||
],
|
],
|
||||||
providers: [WechatTokenService, DailyQuestionPushService, VipExpiryService],
|
providers: [WechatTokenService, DailyQuestionPushService, VipExpiryService, GravityTopUpService, PricingService],
|
||||||
})
|
})
|
||||||
export class ScheduleModule {}
|
export class ScheduleModule {}
|
||||||
|
|||||||
@@ -3,13 +3,20 @@ import { InjectModel } from '@nestjs/mongoose'
|
|||||||
import { Model } from 'mongoose'
|
import { Model } from 'mongoose'
|
||||||
import { SiteConfig, SiteConfigDocument } from './site-config.schema'
|
import { SiteConfig, SiteConfigDocument } from './site-config.schema'
|
||||||
|
|
||||||
|
export interface GravityRates {
|
||||||
|
interviewPerUse: number // 每次面试消耗引力值
|
||||||
|
optimizePerUse: number // 每次优化消耗引力值
|
||||||
|
downloadPerUse: number // 每次下载消耗引力值
|
||||||
|
}
|
||||||
|
|
||||||
interface PricingConfig {
|
interface PricingConfig {
|
||||||
interview: { pricePerSession: number; creditsPerPurchase: number }
|
interview: { pricePerSession: number; creditsPerPurchase: number }
|
||||||
resumeOptimize: { freeLimit: number; pricePerOptimize: number; creditsPerPurchase: number }
|
resumeOptimize: { freeLimit: number; pricePerOptimize: number; creditsPerPurchase: number }
|
||||||
resumeDownload: { pricePerDownload: number; creditsPerPurchase: number }
|
resumeDownload: { pricePerDownload: number; creditsPerPurchase: number }
|
||||||
|
gravityRates: GravityRates
|
||||||
plans: {
|
plans: {
|
||||||
growth: { 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; 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 },
|
interview: { pricePerSession: 500, creditsPerPurchase: 1 },
|
||||||
resumeOptimize: { freeLimit: 3, pricePerOptimize: 300, creditsPerPurchase: 1 },
|
resumeOptimize: { freeLimit: 3, pricePerOptimize: 300, creditsPerPurchase: 1 },
|
||||||
resumeDownload: { pricePerDownload: 200, creditsPerPurchase: 1 },
|
resumeDownload: { pricePerDownload: 200, creditsPerPurchase: 1 },
|
||||||
|
gravityRates: { interviewPerUse: 5, optimizePerUse: 3, downloadPerUse: 2 },
|
||||||
plans: {
|
plans: {
|
||||||
growth: { price: 1990, durationDays: 30, credits: { interview: 999, resumeOptimize: 20, resumeDownload: 10 }, features: ['免费版全部权益', 'AI 数字人面试无限次', '详细面试报告(四维评分)', '进步轨迹雷达图 + 打卡', '每日一题推送', '参考回答思路', '公司真题库', '简历优化 20 次/月', '简历下载 10 次/月'] },
|
growth: { price: 1990, durationDays: 30, gravityPerMonth: 250, credits: { interview: 999, resumeOptimize: 20, resumeDownload: 10 }, features: ['免费版全部权益', 'AI 数字人面试每次 3 引力值(折扣价)', '详细面试报告(四维评分)', '进步轨迹雷达图 + 打卡', '每日一题推送', '参考回答思路', '公司真题库', '简历优化 20 次/月', '简历下载 10 次/月'] },
|
||||||
sprint: { price: 4990, durationDays: 30, credits: { interview: 999, resumeOptimize: 50, resumeDownload: 30 }, features: ['成长版全部权益', 'AI 语音分析(语气词/语速检测)', '技能缺口分析报告', '学习路径推荐', '真人导师 1v1 点评(每月 1 次)', '简历精修(每月 1 次)', '内推优先', '简历优化 50 次/月', '简历下载 30 次/月'] },
|
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 },
|
interview: { ...DEFAULT_PRICING.interview, ...value?.interview },
|
||||||
resumeOptimize: { ...DEFAULT_PRICING.resumeOptimize, ...value?.resumeOptimize },
|
resumeOptimize: { ...DEFAULT_PRICING.resumeOptimize, ...value?.resumeOptimize },
|
||||||
resumeDownload: { ...DEFAULT_PRICING.resumeDownload, ...value?.resumeDownload },
|
resumeDownload: { ...DEFAULT_PRICING.resumeDownload, ...value?.resumeDownload },
|
||||||
|
gravityRates: { ...DEFAULT_PRICING.gravityRates, ...value?.gravityRates },
|
||||||
plans: {
|
plans: {
|
||||||
growth: { ...DEFAULT_PRICING.plans.growth, ...value?.plans?.growth, credits: { ...DEFAULT_PRICING.plans.growth.credits, ...value?.plans?.growth?.credits } },
|
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 } },
|
sprint: { ...DEFAULT_PRICING.plans.sprint, ...value?.plans?.sprint, credits: { ...DEFAULT_PRICING.plans.sprint.credits, ...value?.plans?.sprint?.credits } },
|
||||||
|
|||||||
@@ -83,8 +83,11 @@ export class ShareService {
|
|||||||
|
|
||||||
if (todayCredited >= DAILY_LIMIT) return { dailyLimitReached: true, visitorUserId }
|
if (todayCredited >= DAILY_LIMIT) return { dailyLimitReached: true, visitorUserId }
|
||||||
|
|
||||||
const shareCreditsResult = await this.quotaService.grantShareCredits(sharerIdStr)
|
try {
|
||||||
if (!shareCreditsResult) return { creditFailed: true, visitorUserId }
|
await this.quotaService.grantGravity(sharerIdStr, 1)
|
||||||
|
} catch (e) {
|
||||||
|
return { creditFailed: true, visitorUserId }
|
||||||
|
}
|
||||||
|
|
||||||
await this.visitModel.updateOne(
|
await this.visitModel.updateOne(
|
||||||
{ shareId: share._id, visitorId },
|
{ shareId: share._id, visitorId },
|
||||||
@@ -125,7 +128,7 @@ export class ShareService {
|
|||||||
totalVisits: visitAgg[0]?.totalVisits ?? 0,
|
totalVisits: visitAgg[0]?.totalVisits ?? 0,
|
||||||
creditedCount: visitAgg[0]?.creditedCount ?? 0,
|
creditedCount: visitAgg[0]?.creditedCount ?? 0,
|
||||||
todayCredited: todayAgg,
|
todayCredited: todayAgg,
|
||||||
shareCredits: user?.shareCredits ?? 0,
|
gravity: user?.gravity ?? 0,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ import { Injectable, HttpException, HttpStatus, Logger } from '@nestjs/common'
|
|||||||
import { InjectModel } from '@nestjs/mongoose'
|
import { InjectModel } from '@nestjs/mongoose'
|
||||||
import { Model } from 'mongoose'
|
import { Model } from 'mongoose'
|
||||||
import { User, UserDocument } from './user.schema'
|
import { User, UserDocument } from './user.schema'
|
||||||
|
import { PricingService } from '../schemas/pricing.service'
|
||||||
|
|
||||||
const FREE_OPTIMIZE_LIMIT = 3
|
const FREE_OPTIMIZE_LIMIT = 3
|
||||||
|
|
||||||
@@ -11,119 +12,143 @@ export class QuotaService {
|
|||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
@InjectModel(User.name) private userModel: Model<UserDocument>,
|
@InjectModel(User.name) private userModel: Model<UserDocument>,
|
||||||
|
private pricingService: PricingService,
|
||||||
) {}
|
) {}
|
||||||
|
|
||||||
|
/** 检查并扣除面试引力值(所有计划统一走引力值) */
|
||||||
async checkAndDeductInterview(userId: string) {
|
async checkAndDeductInterview(userId: string) {
|
||||||
const user = await this.userModel.findById(userId).exec()
|
const user = await this.userModel.findById(userId).exec()
|
||||||
if (!user) throw new HttpException('用户不存在', HttpStatus.NOT_FOUND)
|
if (!user) throw new HttpException('用户不存在', HttpStatus.NOT_FOUND)
|
||||||
if (user.plan !== 'free') return
|
|
||||||
|
|
||||||
// Backward compat: migrate remaining → interviewCredits
|
// 迁移旧字段到 gravity
|
||||||
if ((user.interviewCredits ?? 0) <= 0 && (user.remaining ?? 0) > 0) {
|
if ((user.gravity ?? 0) <= 0 && this.hasOldCredits(user)) {
|
||||||
await this.userModel.findByIdAndUpdate(userId, {
|
await this.migrateOldCredits(userId)
|
||||||
$set: { interviewCredits: user.remaining, remaining: 0 },
|
|
||||||
}).exec()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const result = await this.userModel.findOneAndUpdate(
|
const rates = (await this.pricingService.getConfig()).gravityRates
|
||||||
{ _id: userId, interviewCredits: { $gt: 0 } },
|
const cost = rates.interviewPerUse
|
||||||
{ $inc: { interviewCredits: -1, interviewCount: 1 } },
|
|
||||||
{ new: true },
|
// 用 gravity 支付,后备 shareCredits
|
||||||
).exec()
|
const result = await this.deductGravityOrFallback(userId, cost)
|
||||||
if (result) return
|
if (result) return
|
||||||
|
|
||||||
// Fallback to share credits
|
throw new HttpException('引力值不足,请充值或分享获取', HttpStatus.FORBIDDEN)
|
||||||
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)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** 检查并扣除优化引力值(所有计划统一走引力值) */
|
||||||
async checkAndDeductOptimize(userId: string) {
|
async checkAndDeductOptimize(userId: string) {
|
||||||
const user = await this.userModel.findById(userId).exec()
|
const user = await this.userModel.findById(userId).exec()
|
||||||
if (!user) throw new HttpException('用户不存在', HttpStatus.NOT_FOUND)
|
if (!user) throw new HttpException('用户不存在', HttpStatus.NOT_FOUND)
|
||||||
if (user.plan !== 'free') return
|
|
||||||
|
|
||||||
// Try paid credits first
|
// 迁移旧字段
|
||||||
const paid = await this.userModel.findOneAndUpdate(
|
if ((user.gravity ?? 0) <= 0 && this.hasOldCredits(user)) {
|
||||||
{ _id: userId, resumeOptimizeCredits: { $gt: 0 } },
|
await this.migrateOldCredits(userId)
|
||||||
{ $inc: { resumeOptimizeCredits: -1 } },
|
}
|
||||||
).exec()
|
|
||||||
if (paid) return
|
|
||||||
|
|
||||||
// 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(
|
const freeResult = await this.userModel.findOneAndUpdate(
|
||||||
{ _id: userId, freeOptimizeUsed: { $lt: FREE_OPTIMIZE_LIMIT } },
|
{ _id: userId, freeOptimizeUsed: { $lt: FREE_OPTIMIZE_LIMIT } },
|
||||||
{ $inc: { freeOptimizeUsed: 1 } },
|
{ $inc: { freeOptimizeUsed: 1 } },
|
||||||
).exec()
|
).exec()
|
||||||
if (freeResult) return
|
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(
|
const shareResult = await this.userModel.findOneAndUpdate(
|
||||||
{ _id: userId, shareCredits: { $gt: 0 } },
|
{ _id: userId, shareCredits: { $gt: 0 } },
|
||||||
{ $inc: { shareCredits: -1 } },
|
{ $inc: { shareCredits: -1 } },
|
||||||
).exec()
|
).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(
|
async grantGravity(userId: string, amount: number) {
|
||||||
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) {
|
|
||||||
if (amount <= 0) throw new HttpException('无效数量', HttpStatus.BAD_REQUEST)
|
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(
|
const result = await this.userModel.findByIdAndUpdate(
|
||||||
userId,
|
userId,
|
||||||
{ $inc: { [field]: amount } },
|
{ $inc: { gravity: amount } },
|
||||||
).exec()
|
).exec()
|
||||||
if (!result) throw new HttpException('用户不存在', HttpStatus.NOT_FOUND)
|
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, {
|
const result = await this.userModel.findByIdAndUpdate(userId, {
|
||||||
$set: {
|
$set: {
|
||||||
remaining: 999,
|
gravity: gravityAmount,
|
||||||
interviewCredits: credits.interview,
|
|
||||||
resumeOptimizeCredits: credits.resumeOptimize,
|
|
||||||
resumeDownloadCredits: credits.resumeDownload,
|
|
||||||
freeOptimizeUsed: FREE_OPTIMIZE_LIMIT,
|
freeOptimizeUsed: FREE_OPTIMIZE_LIMIT,
|
||||||
},
|
},
|
||||||
}).exec()
|
}).exec()
|
||||||
if (!result) throw new HttpException('用户不存在', HttpStatus.NOT_FOUND)
|
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()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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 { UserService } from './user.service'
|
||||||
import { Public } from '../../common/decorators/public.decorator'
|
import { Public } from '../../common/decorators/public.decorator'
|
||||||
import { CurrentUser } from '../../common/decorators/current-user.decorator'
|
import { CurrentUser } from '../../common/decorators/current-user.decorator'
|
||||||
|
import { JwtAuthGuard } from '../../common/guards/jwt-auth.guard'
|
||||||
|
|
||||||
@Controller('user')
|
@Controller('user')
|
||||||
export class UserController {
|
export class UserController {
|
||||||
@@ -29,6 +30,14 @@ export class UserController {
|
|||||||
return this.userService.sendEmailCode(email)
|
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()
|
@Public()
|
||||||
@Post('email-login')
|
@Post('email-login')
|
||||||
@HttpCode(HttpStatus.OK)
|
@HttpCode(HttpStatus.OK)
|
||||||
|
|||||||
@@ -49,7 +49,10 @@ export class User {
|
|||||||
freeOptimizeUsed: number // 已使用免费优化次数(上限 3)
|
freeOptimizeUsed: number // 已使用免费优化次数(上限 3)
|
||||||
|
|
||||||
@Prop({ default: 0 })
|
@Prop({ default: 0 })
|
||||||
shareCredits: number // 分享积分,每 3 次有效访问获 1 积分
|
gravity: number // 引力值(统一额度),面试 5、优化 3、下载 2
|
||||||
|
|
||||||
|
@Prop({ default: 0 })
|
||||||
|
shareCredits: number // 已合并到 gravity,保留字段防报错
|
||||||
|
|
||||||
@Prop({ default: 'user' })
|
@Prop({ default: 'user' })
|
||||||
role: string // 'user' | 'admin'
|
role: string // 'user' | 'admin'
|
||||||
|
|||||||
@@ -46,14 +46,13 @@ export class UserService {
|
|||||||
|
|
||||||
let user = await this.userModel.findOne({ phone }).exec()
|
let user = await this.userModel.findOne({ phone }).exec()
|
||||||
if (!user) {
|
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)
|
return this.generateAuthResponse(user)
|
||||||
}
|
}
|
||||||
|
|
||||||
async loginByWx(code: string) {
|
async loginByWx(code: string, userId?: string) {
|
||||||
// WeChat silent login - exchange code for openid
|
|
||||||
const appid = process.env.WX_APPID
|
const appid = process.env.WX_APPID
|
||||||
const secret = process.env.WX_SECRET
|
const secret = process.env.WX_SECRET
|
||||||
if (!appid || !secret) {
|
if (!appid || !secret) {
|
||||||
@@ -70,15 +69,59 @@ export class UserService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const openid = wxData.openid
|
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()
|
let user = await this.userModel.findOne({ wxOpenid: openid }).exec()
|
||||||
if (!user) {
|
if (!user) {
|
||||||
user = await this.userModel.create({ wxOpenid: openid, nickname: '微信用户' })
|
user = await this.userModel.create({ wxOpenid: openid, nickname: '微信用户', gravity: 5 })
|
||||||
}
|
}
|
||||||
|
|
||||||
return this.generateAuthResponse(user)
|
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) {
|
async sendEmailCode(email: string) {
|
||||||
if (!email || !email.includes('@')) {
|
if (!email || !email.includes('@')) {
|
||||||
throw new HttpException('请输入正确的邮箱地址', HttpStatus.BAD_REQUEST)
|
throw new HttpException('请输入正确的邮箱地址', HttpStatus.BAD_REQUEST)
|
||||||
@@ -113,7 +156,7 @@ export class UserService {
|
|||||||
if (!user) {
|
if (!user) {
|
||||||
isNew = true
|
isNew = true
|
||||||
const nick = email.split('@')[0]
|
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 }
|
return { ...this.generateAuthResponse(user), isNew, hasPassword: !!user.password }
|
||||||
}
|
}
|
||||||
@@ -148,7 +191,7 @@ export class UserService {
|
|||||||
}
|
}
|
||||||
const nick = email.split('@')[0]
|
const nick = email.split('@')[0]
|
||||||
const hashed = await bcrypt.hash(password, 10)
|
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)
|
return this.generateAuthResponse(user)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -216,6 +259,7 @@ export class UserService {
|
|||||||
resumeDownloadCredits: user.resumeDownloadCredits ?? 0,
|
resumeDownloadCredits: user.resumeDownloadCredits ?? 0,
|
||||||
freeOptimizeUsed: user.freeOptimizeUsed ?? 0,
|
freeOptimizeUsed: user.freeOptimizeUsed ?? 0,
|
||||||
shareCredits: user.shareCredits ?? 0,
|
shareCredits: user.shareCredits ?? 0,
|
||||||
|
gravity: user.gravity ?? 0,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+12
-10
@@ -1,8 +1,8 @@
|
|||||||
# 职引项目 · 状态报告 v4.5
|
# 职引项目 · 状态报告 v4.6
|
||||||
|
|
||||||
> **项目版本**: v4.5
|
> **项目版本**: v4.6
|
||||||
> **更新时间**: 2026-06-17
|
> **更新时间**: 2026-06-19
|
||||||
> **项目状态**: ✅ 面试复盘上线 + AI 择业顾问 MVP
|
> **项目状态**: ✅ 引力值体系统一 + 管理后台完善
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
@@ -76,8 +76,10 @@
|
|||||||
| 功能 | 后端 | 前端 | 状态 |
|
| 功能 | 后端 | 前端 | 状态 |
|
||||||
|------|------|------|------|
|
|------|------|------|------|
|
||||||
| 免费版额度(日2次/5轮) | ✅ | ✅ | **完成** |
|
| 免费版额度(日2次/5轮) | ✅ | ✅ | **完成** |
|
||||||
| 成长版 ¥19.9/月 | ✅ | ✅ | **完成** |
|
| 成长版 ¥19.9/月(250 引力值) | ✅ | ✅ | **完成** |
|
||||||
| 冲刺版 ¥49.9/月(含权益扣减) | ✅ | ✅ | **完成** |
|
| 冲刺版 ¥49.9/月(600 引力值) | ✅ | ✅ | **完成** |
|
||||||
|
| 引力值统一体系(取消 VIP 无限面试) | ✅ | ✅ | **完成** |
|
||||||
|
| 会员月度引力值自动配发(cron) | ✅ | N/A | **完成** |
|
||||||
| 微信支付 Native QR / JSAPI | ✅ | ✅ H5+MP | **完成** |
|
| 微信支付 Native QR / JSAPI | ✅ | ✅ H5+MP | **完成** |
|
||||||
| 支付回调/自动开会员 | ✅ | N/A | **完成** |
|
| 支付回调/自动开会员 | ✅ | N/A | **完成** |
|
||||||
| 每日一题定时推送 | ✅ | N/A | **完成**(需配置模板ID) |
|
| 每日一题定时推送 | ✅ | N/A | **完成**(需配置模板ID) |
|
||||||
@@ -174,7 +176,7 @@
|
|||||||
| `payment` | controller + service + schema | ✅ | 微信支付 v3,含证书 |
|
| `payment` | controller + service + schema | ✅ | 微信支付 v3,含证书 |
|
||||||
| `progress` | controller + schema + benchmark service | ✅ | 打卡/积分/基准/匹配 |
|
| `progress` | controller + schema + benchmark service | ✅ | 打卡/积分/基准/匹配 |
|
||||||
| `contribution` | controller + schema (×2) | ✅ | 面经 + AI 结构化 + 公司题库 |
|
| `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 评析 + 口语分析 |
|
| `interview-review` | controller + service + schema + asr service | ✅ | 面试复盘:音频 ASR + AI 评析 + 口语分析 |
|
||||||
| `career-advice` | controller + service + module | ✅ | AI 择业顾问:专业分析 + 岗位匹配 + 多轮对话 |
|
| `career-advice` | controller + service + module | ✅ | AI 择业顾问:专业分析 + 岗位匹配 + 多轮对话 |
|
||||||
| `admin` | controller + module | ✅ | 管理后台 |
|
| `admin` | controller + module | ✅ | 管理后台 |
|
||||||
@@ -200,7 +202,7 @@
|
|||||||
| 面试复盘 | review/review | ✅ 三种模式(列表/上传/报告) |
|
| 面试复盘 | review/review | ✅ 三种模式(列表/上传/报告) |
|
||||||
| 择业顾问 | career/career | ✅ AI 专业分析 + 岗位匹配 + 多轮对话 |
|
| 择业顾问 | career/career | ✅ AI 专业分析 + 岗位匹配 + 多轮对话 |
|
||||||
| 实习搜索 | internship/internship | ✅ 热门岗位 |
|
| 实习搜索 | internship/internship | ✅ 热门岗位 |
|
||||||
| 管理后台 | admin/admin | ✅ 仪表盘 |
|
| 管理后台 | admin/admin | ✅ 仪表盘/用户/面试/简历/订单/定价/分享/岗位/诊断/管理员 · 全 CRUD |
|
||||||
| 关于/协议/隐私 | about/agreement/privacy | ✅ |
|
| 关于/协议/隐私 | 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-05 | v2.0 | 战略升级:文档重构 + 新增功能启动 | 小之 |
|
||||||
| 2026-06-09 | v4.2 | 冲刺版+每日推送+支付修复+全量代码评审 | AI |
|
| 2026-06-09 | v4.2 | 冲刺版+每日推送+支付修复+全量代码评审 | AI |
|
||||||
| 2026-06-11 | v4.3 | 安全修复 5 项 + 代码质量 14 处 + 测试体系 61 项 + 护城河 P0-P5 全部验证 | AI |
|
| 2026-06-11 | v4.3 | 安全修复 5 项 + 代码质量 14 处 + 测试体系 61 项 + 护城河 P0-P5 全部验证 | AI |
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
{
|
{
|
||||||
"name": "宇之然AI磁场",
|
"name": "宇之然AI磁场",
|
||||||
"appid": "__UNI__DEV__",
|
"appid": "__UNI__DEV__",
|
||||||
"versionName": "1.0.14",
|
"versionName": "1.0.15",
|
||||||
"versionCode": "114",
|
"versionCode": "115",
|
||||||
"description": "职引 - 宇之然AI磁场旗下AI模拟面试平台,提供AI面试官模拟练习、简历智能优化、大厂面经题库,助你轻松应对校招面试。",
|
"description": "职引 - 宇之然AI磁场旗下AI模拟面试平台,提供AI面试官模拟练习、简历智能优化、大厂面经题库,助你轻松应对校招面试。",
|
||||||
"h5": {
|
"h5": {
|
||||||
"title": "职引 - AI模拟面试 | 宇之然AI磁场",
|
"title": "职引 - AI模拟面试 | 宇之然AI磁场",
|
||||||
|
|||||||
@@ -22,7 +22,8 @@
|
|||||||
<text class="tab" :class="{ active: tab === 'pricing' }" @click="switchTab('pricing')">定价</text>
|
<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 === 'share' }" @click="switchTab('share')">分享</text>
|
||||||
<text class="tab" :class="{ active: tab === 'positions' }" @click="switchTab('positions')">岗位</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>
|
</view>
|
||||||
|
|
||||||
<!-- 概览 -->
|
<!-- 概览 -->
|
||||||
@@ -66,10 +67,8 @@
|
|||||||
</view>
|
</view>
|
||||||
<view class="user-badges">
|
<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-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.gravity ?? 0 }}</text>
|
||||||
<text class="user-credit">优化:{{ u.resumeOptimizeCredits ?? 0 }}</text>
|
<text class="user-credit share" v-if="u.shareCredits > 0">分享:{{ u.shareCredits }}</text>
|
||||||
<text class="user-credit">下载:{{ u.resumeDownloadCredits ?? 0 }}</text>
|
|
||||||
<text class="user-credit share">分享:{{ u.shareCredits ?? 0 }}</text>
|
|
||||||
</view>
|
</view>
|
||||||
<view class="user-actions">
|
<view class="user-actions">
|
||||||
<text class="user-action-btn" v-if="u.plan === 'free'" @click="setVip(u._id)">设为会员</text>
|
<text class="user-action-btn" v-if="u.plan === 'free'" @click="setVip(u._id)">设为会员</text>
|
||||||
@@ -83,6 +82,12 @@
|
|||||||
|
|
||||||
<!-- 面试 -->
|
<!-- 面试 -->
|
||||||
<view v-if="tab === 'interviews'" class="section">
|
<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-list" v-if="!ivLoading">
|
||||||
<view class="iv-row" v-for="iv in interviews" :key="iv._id">
|
<view class="iv-row" v-for="iv in interviews" :key="iv._id">
|
||||||
<view class="iv-main">
|
<view class="iv-main">
|
||||||
@@ -95,13 +100,20 @@
|
|||||||
<text class="iv-tag score">得分 {{ iv.totalScore ?? '-' }}</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>
|
||||||
|
<text class="iv-time">{{ iv.createdAt?.slice(0,16).replace('T',' ') }}</text>
|
||||||
</view>
|
</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>
|
</view>
|
||||||
<text class="loading-text" v-if="ivLoading">加载中...</text>
|
<text class="loading-text" v-if="ivLoading">加载中...</text>
|
||||||
</view>
|
</view>
|
||||||
|
|
||||||
<!-- 简历 -->
|
<!-- 简历 -->
|
||||||
<view v-if="tab === 'resumes'" class="section">
|
<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-list" v-if="!resumeLoading">
|
||||||
<view class="resume-row" v-for="r in resumes" :key="r._id">
|
<view class="resume-row" v-for="r in resumes" :key="r._id">
|
||||||
<view class="resume-main">
|
<view class="resume-main">
|
||||||
@@ -114,6 +126,9 @@
|
|||||||
<text class="resume-tag paid" v-if="r.paidDownload">付费下载</text>
|
<text class="resume-tag paid" v-if="r.paidDownload">付费下载</text>
|
||||||
</view>
|
</view>
|
||||||
<text class="resume-time">{{ r.createdAt?.slice(0,10) }}</text>
|
<text class="resume-time">{{ r.createdAt?.slice(0,10) }}</text>
|
||||||
|
<view class="resume-actions">
|
||||||
|
<text class="admin-action-btn del" @click="deleteResume(r._id, r.title)">删除</text>
|
||||||
|
</view>
|
||||||
</view>
|
</view>
|
||||||
</view>
|
</view>
|
||||||
<text class="loading-text" v-if="resumeLoading">加载中...</text>
|
<text class="loading-text" v-if="resumeLoading">加载中...</text>
|
||||||
@@ -176,12 +191,32 @@
|
|||||||
</view>
|
</view>
|
||||||
</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="config-card">
|
||||||
<view class="cfg-title">成长版 ¥{{ growthPriceDisplay }}</view>
|
<view class="cfg-title">成长版 ¥{{ growthPriceDisplay }}</view>
|
||||||
<view class="cfg-row">
|
<view class="cfg-row">
|
||||||
<text>价格(元/月)</text>
|
<text>价格(元/月)</text>
|
||||||
<input class="cfg-input" type="digit" v-model.number="growthPriceTemp" />
|
<input class="cfg-input" type="digit" v-model.number="growthPriceTemp" />
|
||||||
</view>
|
</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">
|
<view class="cfg-row">
|
||||||
<text>面试额度/月</text>
|
<text>面试额度/月</text>
|
||||||
<input class="cfg-input" type="digit" v-model.number="pricing.plans.growth.credits.interview" />
|
<input class="cfg-input" type="digit" v-model.number="pricing.plans.growth.credits.interview" />
|
||||||
@@ -207,7 +242,9 @@
|
|||||||
<input class="cfg-input" type="digit" v-model.number="sprintPriceTemp" />
|
<input class="cfg-input" type="digit" v-model.number="sprintPriceTemp" />
|
||||||
</view>
|
</view>
|
||||||
<view class="cfg-row">
|
<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" />
|
<input class="cfg-input" type="digit" v-model.number="pricing.plans.sprint.credits.interview" />
|
||||||
</view>
|
</view>
|
||||||
<view class="cfg-row">
|
<view class="cfg-row">
|
||||||
@@ -300,13 +337,27 @@
|
|||||||
<text class="loading-text" v-if="posLoading">加载中...</text>
|
<text class="loading-text" v-if="posLoading">加载中...</text>
|
||||||
</view>
|
</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-mask" v-if="creditModal.show" @click="closeCreditModal">
|
||||||
<view class="modal-content" @click.stop>
|
<view class="modal-content" @click.stop>
|
||||||
<text class="modal-title">调整 {{ creditModal.user?.nickname || '用户' }} 的额度</text>
|
<text class="modal-title">调整 {{ creditModal.user?.nickname || '用户' }} 的额度</text>
|
||||||
<view class="cfg-row" v-for="t in creditTypes" :key="t.key">
|
<view class="cfg-row">
|
||||||
<text>{{ t.label }}</text>
|
<text>引力值</text>
|
||||||
<input class="cfg-input" type="digit" v-model.number="t.value" :placeholder="t.key" />
|
<input class="cfg-input" type="digit" v-model.number="creditGravity" />
|
||||||
</view>
|
</view>
|
||||||
<view class="modal-actions">
|
<view class="modal-actions">
|
||||||
<button class="modal-btn cancel" @click="closeCreditModal">取消</button>
|
<button class="modal-btn cancel" @click="closeCreditModal">取消</button>
|
||||||
@@ -333,6 +384,10 @@
|
|||||||
<text class="cfg-val">{{ posForm.active ? '启用' : '停用' }}</text>
|
<text class="cfg-val">{{ posForm.active ? '启用' : '停用' }}</text>
|
||||||
</picker>
|
</picker>
|
||||||
</view>
|
</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">
|
<view class="modal-actions">
|
||||||
<button class="modal-btn cancel" @click="closePositionModal">取消</button>
|
<button class="modal-btn cancel" @click="closePositionModal">取消</button>
|
||||||
<button class="modal-btn confirm" @click="savePosition">保存</button>
|
<button class="modal-btn confirm" @click="savePosition">保存</button>
|
||||||
@@ -386,11 +441,10 @@
|
|||||||
<text class="admin-set-btn" v-if="searchResult.role !== 'admin'" @click="setAdmin(searchResult._id)">设为管理员</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>
|
<text class="admin-set-btn done" v-else>已是管理员</text>
|
||||||
</view>
|
</view>
|
||||||
</view>
|
|
||||||
</view>
|
</view>
|
||||||
</view>
|
</view>
|
||||||
</view>
|
</view>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script setup>
|
<script setup>
|
||||||
import { ref, computed, onMounted, reactive } from 'vue'
|
import { ref, computed, onMounted, reactive } from 'vue'
|
||||||
@@ -422,9 +476,10 @@ const pricing = ref({
|
|||||||
interview: { pricePerSession: 500 },
|
interview: { pricePerSession: 500 },
|
||||||
resumeOptimize: { freeLimit: 3, pricePerOptimize: 300 },
|
resumeOptimize: { freeLimit: 3, pricePerOptimize: 300 },
|
||||||
resumeDownload: { pricePerDownload: 200 },
|
resumeDownload: { pricePerDownload: 200 },
|
||||||
|
gravityRates: { interviewPerUse: 5, optimizePerUse: 3, downloadPerUse: 2 },
|
||||||
plans: {
|
plans: {
|
||||||
growth: { price: 1990, durationDays: 30, credits: { interview: 999, resumeOptimize: 20, resumeDownload: 10 }, features: ['免费版全部权益', 'AI 数字人面试无限次'] },
|
growth: { price: 1990, durationDays: 30, gravityPerMonth: 250, credits: { interview: 999, resumeOptimize: 20, resumeDownload: 10 }, features: ['免费版全部权益', '每月 250 引力值'] },
|
||||||
sprint: { price: 4990, durationDays: 30, credits: { interview: 999, resumeOptimize: 50, resumeDownload: 30 }, features: ['成长版全部权益'] },
|
sprint: { price: 4990, durationDays: 30, gravityPerMonth: 600, credits: { interview: 999, resumeOptimize: 50, resumeDownload: 30 }, features: ['成长版全部权益', '每月 600 引力值'] },
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
const pricingLoading = ref(false)
|
const pricingLoading = ref(false)
|
||||||
@@ -432,6 +487,14 @@ const growthPriceTemp = ref(19.9)
|
|||||||
const sprintPriceTemp = ref(49.9)
|
const sprintPriceTemp = ref(49.9)
|
||||||
const growthFeaturesText = ref('')
|
const growthFeaturesText = ref('')
|
||||||
const sprintFeaturesText = 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
|
// Position management
|
||||||
const positions = ref([])
|
const positions = ref([])
|
||||||
@@ -445,6 +508,8 @@ const posForm = reactive({
|
|||||||
sort: 0,
|
sort: 0,
|
||||||
active: true,
|
active: true,
|
||||||
category: 'ai',
|
category: 'ai',
|
||||||
|
description: '',
|
||||||
|
requirements: '',
|
||||||
})
|
})
|
||||||
|
|
||||||
const growthPriceDisplay = computed(() => growthPriceTemp.value.toFixed(1))
|
const growthPriceDisplay = computed(() => growthPriceTemp.value.toFixed(1))
|
||||||
@@ -466,12 +531,6 @@ const shareLoading = ref(false)
|
|||||||
|
|
||||||
// Credit modal
|
// Credit modal
|
||||||
const creditModal = ref({ show: false, user: null })
|
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
|
// Refund modal
|
||||||
const refundModal = ref({ show: false, order: null })
|
const refundModal = ref({ show: false, order: null })
|
||||||
@@ -578,6 +637,7 @@ const switchTab = (t) => {
|
|||||||
if (t === 'admins' && adminList.value.length === 0) loadAdmins()
|
if (t === 'admins' && adminList.value.length === 0) loadAdmins()
|
||||||
if (t === 'pricing') loadPricing()
|
if (t === 'pricing') loadPricing()
|
||||||
if (t === 'orders') loadOrders()
|
if (t === 'orders') loadOrders()
|
||||||
|
if (t === 'analysis') loadAnalysis()
|
||||||
}
|
}
|
||||||
|
|
||||||
const loadUsers = async () => {
|
const loadUsers = async () => {
|
||||||
@@ -600,22 +660,55 @@ const loadMoreUsers = async () => {
|
|||||||
|
|
||||||
const loadInterviews = async () => {
|
const loadInterviews = async () => {
|
||||||
ivLoading.value = true
|
ivLoading.value = true
|
||||||
|
ivPage.value = 1
|
||||||
try {
|
try {
|
||||||
const res = await apiAdmin('/interviews?page=1&limit=20')
|
let url = '/interviews?page=1&limit=20&keyword=' + encodeURIComponent(ivKeyword.value)
|
||||||
if (res.statusCode === 200) interviews.value = res.data.interviews || []
|
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) }
|
} catch (e) { console.error(e) }
|
||||||
finally { ivLoading.value = false }
|
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 () => {
|
const loadResumes = async () => {
|
||||||
resumeLoading.value = true
|
resumeLoading.value = true
|
||||||
try {
|
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 || []
|
if (res.statusCode === 200) resumes.value = res.data.list || []
|
||||||
} catch (e) { console.error(e) }
|
} catch (e) { console.error(e) }
|
||||||
finally { resumeLoading.value = false }
|
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 () => {
|
const loadPricing = async () => {
|
||||||
pricingLoading.value = true
|
pricingLoading.value = true
|
||||||
try {
|
try {
|
||||||
@@ -631,6 +724,15 @@ const loadPricing = async () => {
|
|||||||
finally { pricingLoading.value = false }
|
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 () => {
|
const savePricing = async () => {
|
||||||
pricingLoading.value = true
|
pricingLoading.value = true
|
||||||
try {
|
try {
|
||||||
@@ -721,6 +823,8 @@ const openPositionModal = (position) => {
|
|||||||
posForm.sort = position.sort ?? 0
|
posForm.sort = position.sort ?? 0
|
||||||
posForm.active = position.active ?? true
|
posForm.active = position.active ?? true
|
||||||
posForm.category = position.category || 'traditional'
|
posForm.category = position.category || 'traditional'
|
||||||
|
posForm.description = position.description || ''
|
||||||
|
posForm.requirements = position.requirements || ''
|
||||||
posModal.value = { show: true, isNew: false }
|
posModal.value = { show: true, isNew: false }
|
||||||
} else {
|
} else {
|
||||||
posForm.name = ''
|
posForm.name = ''
|
||||||
@@ -730,6 +834,8 @@ const openPositionModal = (position) => {
|
|||||||
posForm.sort = positions.value.length + 1
|
posForm.sort = positions.value.length + 1
|
||||||
posForm.active = true
|
posForm.active = true
|
||||||
posForm.category = 'ai'
|
posForm.category = 'ai'
|
||||||
|
posForm.description = ''
|
||||||
|
posForm.requirements = ''
|
||||||
posModal.value = { show: true, isNew: true }
|
posModal.value = { show: true, isNew: true }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -835,12 +941,7 @@ const loadShareVisitors = async () => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const openCreditModal = (user) => {
|
const openCreditModal = (user) => {
|
||||||
creditTypes.value = [
|
creditGravity.value = user.gravity ?? 0
|
||||||
{ 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 },
|
|
||||||
]
|
|
||||||
creditModal.value = { show: true, user }
|
creditModal.value = { show: true, user }
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -852,12 +953,10 @@ const doAdjustCredits = async () => {
|
|||||||
const userId = creditModal.value.user?._id
|
const userId = creditModal.value.user?._id
|
||||||
if (!userId) return
|
if (!userId) return
|
||||||
try {
|
try {
|
||||||
for (const t of creditTypes.value) {
|
await apiAdmin('/user/credits', {
|
||||||
await apiAdmin('/user/credits', {
|
method: 'POST',
|
||||||
method: 'POST',
|
data: { userId, type: 'gravity', amount: creditGravity.value },
|
||||||
data: { userId, type: t.key, amount: t.value },
|
})
|
||||||
})
|
|
||||||
}
|
|
||||||
uni.showToast({ title: '调整成功', icon: 'success' })
|
uni.showToast({ title: '调整成功', icon: 'success' })
|
||||||
closeCreditModal()
|
closeCreditModal()
|
||||||
loadUsers()
|
loadUsers()
|
||||||
@@ -877,7 +976,7 @@ onMounted(() => { doVerify() })
|
|||||||
.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; }
|
.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; }
|
.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; }
|
.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); }
|
.tab { flex: 1; text-align: center; padding: 14rpx; 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; }
|
.tab.active { background: var(--color-primary); color: #FFF; font-weight: 600; }
|
||||||
.stat-cards { display: flex; gap: 16rpx; }
|
.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); }
|
.stat-card { flex: 1; background: #FFF; border-radius: var(--radius-lg); padding: 28rpx; text-align: center; box-shadow: var(--shadow-sm); }
|
||||||
@@ -988,4 +1087,8 @@ onMounted(() => { doVerify() })
|
|||||||
.pos-mgr-btn { font-size: 20rpx; padding: 4rpx 16rpx; border-radius: var(--radius-round); }
|
.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.edit { color: var(--color-primary); border: 2rpx solid var(--color-primary); }
|
||||||
.pos-mgr-btn.del { color: #EF4444; border: 2rpx solid #EF4444; }
|
.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; }
|
||||||
</style>
|
</style>
|
||||||
|
|||||||
@@ -13,7 +13,7 @@
|
|||||||
<text class="user-name">{{ userInfo.nickname || '同学' }}</text>
|
<text class="user-name">{{ userInfo.nickname || '同学' }}</text>
|
||||||
<view class="user-tags">
|
<view class="user-tags">
|
||||||
<text class="tag tag-plan">{{ userInfo.plan || '免费版' }}</text>
|
<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>
|
||||||
</view>
|
</view>
|
||||||
<text class="arrow">›</text>
|
<text class="arrow">›</text>
|
||||||
|
|||||||
@@ -66,10 +66,53 @@
|
|||||||
</view>
|
</view>
|
||||||
</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="disclaimer-bar" v-if="!isComplete">AI 生成内容仅供参考,请核实重要信息</view>
|
||||||
|
|
||||||
<view class="complete-bar" v-else>
|
<view class="complete-bar" v-else>
|
||||||
<button class="cta-btn" @click="goResult">查看面试报告</button>
|
<button class="cta-btn" @click="goResult">查看面试报告</button>
|
||||||
|
<button class="buy-btn" v-if="completedReason === 'noCredits'" @click="showPurchaseModal = true">引力值不足,补充引力值或开通会员 ›</button>
|
||||||
|
</view>
|
||||||
|
|
||||||
|
<!-- 购买弹窗(次数不足时) -->
|
||||||
|
<view class="modal-overlay" v-if="showPurchaseModal" @click="showPurchaseModal = 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="goBuyProduct">
|
||||||
|
<text class="purchase-name">补充引力值</text>
|
||||||
|
<text class="purchase-price">¥5 起</text>
|
||||||
|
<text class="purchase-desc">¥5 = 5 引力值,可面试 1 次</text>
|
||||||
|
</view>
|
||||||
|
<view class="purchase-option recommended" @click="goBuyMember">
|
||||||
|
<text class="purchase-badge">推荐</text>
|
||||||
|
<text class="purchase-name">开通成长版会员</text>
|
||||||
|
<text class="purchase-price">¥19.9<text class="purchase-unit">/月</text></text>
|
||||||
|
<text class="purchase-desc">每月 250 引力值,解锁全部权益</text>
|
||||||
|
</view>
|
||||||
|
</view>
|
||||||
|
<text class="modal-close" @click="showPurchaseModal = false">取消</text>
|
||||||
|
</view>
|
||||||
</view>
|
</view>
|
||||||
</view>
|
</view>
|
||||||
</template>
|
</template>
|
||||||
@@ -86,9 +129,14 @@ const aiLoading = ref(false)
|
|||||||
const interviewId = ref('')
|
const interviewId = ref('')
|
||||||
const answeredCount = ref(0)
|
const answeredCount = ref(0)
|
||||||
const isComplete = ref(false)
|
const isComplete = ref(false)
|
||||||
|
const completedReason = ref('')
|
||||||
const scrollToId = ref('')
|
const scrollToId = ref('')
|
||||||
const position = ref('')
|
const position = ref('')
|
||||||
const avatarMode = ref(true)
|
const avatarMode = ref(true)
|
||||||
|
const showPositionPicker = ref(false)
|
||||||
|
const showPurchaseModal = ref(false)
|
||||||
|
const positions = ref([])
|
||||||
|
const positionsLoading = ref(false)
|
||||||
const aiSpeechText = ref('')
|
const aiSpeechText = ref('')
|
||||||
const aiAudioUrl = ref('')
|
const aiAudioUrl = ref('')
|
||||||
const aiAmplitudeData = ref([])
|
const aiAmplitudeData = ref([])
|
||||||
@@ -116,9 +164,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(() => {
|
onMounted(() => {
|
||||||
timerInterval = setInterval(() => timerSeconds++, 1000)
|
timerInterval = setInterval(() => timerSeconds++, 1000)
|
||||||
if (token()) startInterview()
|
if (!position.value) {
|
||||||
|
// 未传入岗位,展示选择弹窗(无论是否登录)
|
||||||
|
loadPositions()
|
||||||
|
showPositionPicker.value = true
|
||||||
|
} else if (token()) {
|
||||||
|
startInterview()
|
||||||
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
onBeforeUnmount(() => {
|
onBeforeUnmount(() => {
|
||||||
@@ -155,6 +231,11 @@ const startInterview = async () => {
|
|||||||
const last = res.data.messages[res.data.messages.length - 1]
|
const last = res.data.messages[res.data.messages.length - 1]
|
||||||
if (last?.role === 'ai') await speakAiText(last.content)
|
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 {
|
} else {
|
||||||
const msg = res.data?.message || '创建面试失败'
|
const msg = res.data?.message || '创建面试失败'
|
||||||
messages.value.push({ role: 'ai', content: msg })
|
messages.value.push({ role: 'ai', content: msg })
|
||||||
@@ -198,8 +279,10 @@ const sendAnswer = async () => {
|
|||||||
answeredCount.value = res.data.questionCount || answeredCount.value + 1
|
answeredCount.value = res.data.questionCount || answeredCount.value + 1
|
||||||
if (res.data.totalQuestions) MAX_QUESTIONS = res.data.totalQuestions
|
if (res.data.totalQuestions) MAX_QUESTIONS = res.data.totalQuestions
|
||||||
} else if (res.statusCode === 403) {
|
} 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
|
isComplete.value = true
|
||||||
|
completedReason.value = 'noCredits'
|
||||||
} else {
|
} else {
|
||||||
messages.value.push({ role: 'ai', content: res.data?.message || '回答提交失败' })
|
messages.value.push({ role: 'ai', content: res.data?.message || '回答提交失败' })
|
||||||
}
|
}
|
||||||
@@ -240,6 +323,8 @@ function onAvatarSilent() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const goResult = () => uni.navigateTo({ url: `/pages/report/report?interviewId=${interviewId.value}` })
|
const goResult = () => uni.navigateTo({ url: `/pages/report/report?interviewId=${interviewId.value}` })
|
||||||
|
const goBuyProduct = () => uni.navigateTo({ url: '/pages/member/member?buy=interview' })
|
||||||
|
const goBuyMember = () => uni.navigateTo({ url: '/pages/member/member' })
|
||||||
const scrollToBottom = () => {
|
const scrollToBottom = () => {
|
||||||
nextTick(() => { scrollToId.value = ''; setTimeout(() => { scrollToId.value = 'msg-bottom' }, 100) })
|
nextTick(() => { scrollToId.value = ''; setTimeout(() => { scrollToId.value = 'msg-bottom' }, 100) })
|
||||||
}
|
}
|
||||||
@@ -389,7 +474,32 @@ function stopRecord() {
|
|||||||
.send-btn.disabled { background: var(--color-border); }
|
.send-btn.disabled { background: var(--color-border); }
|
||||||
.send-icon { font-size: 32rpx; color: #FFFFFF; transform: translateY(2rpx); }
|
.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; }
|
.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); }
|
.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>
|
</style>
|
||||||
|
|||||||
@@ -79,6 +79,30 @@
|
|||||||
</view>
|
</view>
|
||||||
</view>
|
</view>
|
||||||
|
|
||||||
|
<!-- 数量选择弹窗(补充引力值) -->
|
||||||
|
<view class="modal-overlay" v-if="showQuantityModal" @click="showQuantityModal = false">
|
||||||
|
<view class="modal-content" @click.stop>
|
||||||
|
<text class="modal-title">补充引力值</text>
|
||||||
|
<text class="modal-hint">购买后将获得相应引力值,可用于面试、优化、下载</text>
|
||||||
|
<view class="qty-selector">
|
||||||
|
<text class="qty-label">购买数量</text>
|
||||||
|
<view class="qty-controls">
|
||||||
|
<text class="qty-btn" :class="{ disabled: buyQuantity <= 1 }" @click="changeQty(-1)">−</text>
|
||||||
|
<input class="qty-input" type="number" v-model.number="buyQuantity" min="1" max="99" @blur="clampQty" />
|
||||||
|
<text class="qty-btn" :class="{ disabled: buyQuantity >= 99 }" @click="changeQty(1)">+</text>
|
||||||
|
</view>
|
||||||
|
</view>
|
||||||
|
<view class="qty-summary">
|
||||||
|
<text class="qty-unit-price">单价:¥{{ (unitPrice / 100).toFixed(1) }}</text>
|
||||||
|
<text class="qty-total">获 <text class="qty-total-num">{{ buyQuantity * buyGravityPerUnit }}</text> 引力值</text>
|
||||||
|
</view>
|
||||||
|
<view class="qty-actions">
|
||||||
|
<text class="qty-cancel" @click="showQuantityModal = false">取消</text>
|
||||||
|
<text class="qty-confirm" @click="confirmProductBuy">¥{{ totalPrice.toFixed(1) }} 去支付</text>
|
||||||
|
</view>
|
||||||
|
</view>
|
||||||
|
</view>
|
||||||
|
|
||||||
<!-- 支付中提示 -->
|
<!-- 支付中提示 -->
|
||||||
<view class="pay-success" v-if="paySuccess">
|
<view class="pay-success" v-if="paySuccess">
|
||||||
<text class="success-icon">🎉</text>
|
<text class="success-icon">🎉</text>
|
||||||
@@ -88,7 +112,8 @@
|
|||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script setup>
|
<script setup>
|
||||||
import { ref, onMounted, nextTick } from 'vue'
|
import { ref, computed, onMounted, nextTick } from 'vue'
|
||||||
|
import { onLoad, onShow } from '@dcloudio/uni-app'
|
||||||
import { api } from '../../config'
|
import { api } from '../../config'
|
||||||
import UQRCode from 'uqrcodejs'
|
import UQRCode from 'uqrcodejs'
|
||||||
|
|
||||||
@@ -106,19 +131,38 @@ const payingPlan = ref('')
|
|||||||
const growthPriceText = ref('¥19.9')
|
const growthPriceText = ref('¥19.9')
|
||||||
const sprintPriceText = ref('¥49.9')
|
const sprintPriceText = ref('¥49.9')
|
||||||
const currentOutTradeNo = ref('')
|
const currentOutTradeNo = ref('')
|
||||||
const freeFeatures = ref(['AI 模拟面试 1 次(体验)', '基础面试报告', '通用题库随机出题', '简历优化(限 3 次免费)'])
|
const freeFeatures = ref(['AI 模拟面试 1 次(注册送 5 引力值)', '基础面试报告', '通用题库随机出题', '简历优化(限 3 次免费)'])
|
||||||
const growthFeatures = ref(['免费版全部权益', 'AI 数字人面试无限次', '详细面试报告(四维评分)', '进步轨迹雷达图 + 打卡', '每日一题', '参考回答思路', '公司真题库'])
|
const growthFeatures = ref(['免费版全部权益', '每月 250 引力值(约 50 次面试)', '详细面试报告(四维评分)', '进步轨迹雷达图 + 打卡', '每日一题', '参考回答思路', '公司真题库'])
|
||||||
const sprintFeatures = ref(['成长版全部权益', 'AI 语音分析(语气词/语速检测)', '技能缺口分析报告', '公司真题库精选'])
|
const sprintFeatures = ref(['成长版全部权益', '每月 600 引力值(约 120 次面试)', 'AI 语音分析(语气词/语速检测)', '技能缺口分析报告', '公司真题库精选'])
|
||||||
|
const products = ref([])
|
||||||
|
const gravityRates = ref({ interviewPerUse: 5, optimizePerUse: 3, downloadPerUse: 2 })
|
||||||
|
const productPayType = ref('')
|
||||||
|
const showQuantityModal = ref(false)
|
||||||
|
const buyQuantity = ref(1)
|
||||||
|
const buyProductType = ref('')
|
||||||
|
const pendingBuy = ref('')
|
||||||
|
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 token = () => uni.getStorageSync('token') || ''
|
const token = () => uni.getStorageSync('token') || ''
|
||||||
|
|
||||||
onMounted(async () => {
|
const refreshState = async () => {
|
||||||
// #ifdef MP-WEIXIN
|
// #ifdef MP-WEIXIN
|
||||||
isMp.value = true
|
isMp.value = true
|
||||||
// #endif
|
// #endif
|
||||||
|
|
||||||
const t = token()
|
const t = token()
|
||||||
if (!t) return
|
if (!t) {
|
||||||
|
isLoggedIn.value = false
|
||||||
|
return
|
||||||
|
}
|
||||||
isLoggedIn.value = true
|
isLoggedIn.value = true
|
||||||
|
|
||||||
try {
|
try {
|
||||||
@@ -126,12 +170,12 @@ onMounted(async () => {
|
|||||||
uni.request({ url: api('/member/status'), method: 'GET', header: { 'Authorization': `Bearer ${t}` } }),
|
uni.request({ url: api('/member/status'), method: 'GET', header: { 'Authorization': `Bearer ${t}` } }),
|
||||||
uni.request({ url: api('/member/plans'), method: 'GET' }),
|
uni.request({ url: api('/member/plans'), method: 'GET' }),
|
||||||
])
|
])
|
||||||
if (sres.statusCode === 200) {
|
if (sres.statusCode >= 200 && sres.statusCode < 300) {
|
||||||
const d = sres.data
|
const d = sres.data
|
||||||
plan.value = d.plan || 'free'
|
plan.value = d.plan || 'free'
|
||||||
currentPlanName.value = d.planName || '免费版'
|
currentPlanName.value = d.planName || '免费版'
|
||||||
}
|
}
|
||||||
if (lres.statusCode === 200 && lres.data) {
|
if (lres.statusCode >= 200 && lres.statusCode < 300 && lres.data) {
|
||||||
const plans = Array.isArray(lres.data.plans) ? lres.data.plans : (Array.isArray(lres.data) ? 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 growth = plans.find((p) => p.id === 'growth')
|
||||||
const sprint = plans.find((p) => p.id === 'sprint')
|
const sprint = plans.find((p) => p.id === 'sprint')
|
||||||
@@ -144,10 +188,36 @@ onMounted(async () => {
|
|||||||
if (lres.data.price?.monthly) {
|
if (lres.data.price?.monthly) {
|
||||||
growthPriceText.value = `¥${(lres.data.price.monthly / 100).toFixed(1)}`
|
growthPriceText.value = `¥${(lres.data.price.monthly / 100).toFixed(1)}`
|
||||||
}
|
}
|
||||||
|
if (lres.data?.products) {
|
||||||
|
const prodList = []
|
||||||
|
for (const [key, val] of Object.entries(lres.data.products)) {
|
||||||
|
if (val?.price > 0) prodList.push({ type: key, ...val })
|
||||||
|
}
|
||||||
|
products.value = prodList
|
||||||
|
}
|
||||||
|
if (lres.data?.gravityRates) {
|
||||||
|
gravityRates.value = lres.data.gravityRates
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// 来自其他页面的补充次数请求 → 弹出数量选择
|
||||||
|
if (pendingBuy.value && products.value.length > 0) {
|
||||||
|
buyProductType.value = pendingBuy.value
|
||||||
|
buyQuantity.value = 1
|
||||||
|
pendingBuy.value = ''
|
||||||
|
showQuantityModal.value = true
|
||||||
}
|
}
|
||||||
} catch (e) { /* ignore */ }
|
} catch (e) { /* ignore */ }
|
||||||
|
}
|
||||||
|
|
||||||
|
onLoad((options) => {
|
||||||
|
if (options?.buy) {
|
||||||
|
pendingBuy.value = options.buy
|
||||||
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
onMounted(() => { refreshState() })
|
||||||
|
onShow(() => { refreshState() })
|
||||||
|
|
||||||
const goLogin = () => uni.navigateTo({ url: '/pages/login/login' })
|
const goLogin = () => uni.navigateTo({ url: '/pages/login/login' })
|
||||||
|
|
||||||
const cancelPay = () => {
|
const cancelPay = () => {
|
||||||
@@ -163,12 +233,7 @@ const startPay = async (selectedPlan) => {
|
|||||||
if (!t) { uni.showToast({ title: '请先登录', icon: 'none' }); return }
|
if (!t) { uni.showToast({ title: '请先登录', icon: 'none' }); return }
|
||||||
|
|
||||||
payingPlan.value = selectedPlan
|
payingPlan.value = selectedPlan
|
||||||
// #ifdef MP-WEIXIN
|
|
||||||
payingPlanName.value = selectedPlan === 'sprint' ? '冲刺版' : '成长版'
|
payingPlanName.value = selectedPlan === 'sprint' ? '冲刺版' : '成长版'
|
||||||
// #endif
|
|
||||||
// #ifndef MP-WEIXIN
|
|
||||||
payingPlanName.value = selectedPlan === 'sprint' ? '冲刺版' : '成长版'
|
|
||||||
// #endif
|
|
||||||
|
|
||||||
showPayModal.value = true
|
showPayModal.value = true
|
||||||
payLoading.value = true
|
payLoading.value = true
|
||||||
@@ -179,18 +244,50 @@ const startPay = async (selectedPlan) => {
|
|||||||
if (isMp.value) {
|
if (isMp.value) {
|
||||||
// 小程序:JSAPI 支付
|
// 小程序:JSAPI 支付
|
||||||
try {
|
try {
|
||||||
const res = await uni.request({
|
let res = await uni.request({
|
||||||
url: api('/payment/jsapi'), method: 'POST',
|
url: api('/payment/jsapi'), method: 'POST',
|
||||||
data: { plan: planLabel },
|
data: { plan: planLabel },
|
||||||
header: { 'Authorization': `Bearer ${t}`, 'Content-Type': 'application/json' },
|
header: { 'Authorization': `Bearer ${t}`, 'Content-Type': 'application/json' },
|
||||||
timeout: 30000,
|
timeout: 30000,
|
||||||
})
|
})
|
||||||
|
|
||||||
|
// 如果没有 openid,自动绑定
|
||||||
|
if (res.statusCode === 400 && res.data?.needBindWx) {
|
||||||
|
payLoading.value = false
|
||||||
|
uni.showLoading({ title: '绑定微信中...' })
|
||||||
|
try {
|
||||||
|
const loginRes = await uni.login()
|
||||||
|
if (!loginRes?.errMsg?.includes('ok')) throw new Error('获取微信凭证失败')
|
||||||
|
const bindRes = await uni.request({
|
||||||
|
url: api('/user/bind-wx'), method: 'POST',
|
||||||
|
data: { code: loginRes.code },
|
||||||
|
header: { 'Authorization': `Bearer ${t}`, 'Content-Type': 'application/json' },
|
||||||
|
})
|
||||||
|
if (bindRes.statusCode >= 200 && bindRes.statusCode < 300) {
|
||||||
|
// 绑定成功,重试支付
|
||||||
|
res = await uni.request({
|
||||||
|
url: api('/payment/jsapi'), method: 'POST',
|
||||||
|
data: { plan: planLabel },
|
||||||
|
header: { 'Authorization': `Bearer ${t}`, 'Content-Type': 'application/json' },
|
||||||
|
timeout: 30000,
|
||||||
|
})
|
||||||
|
} else {
|
||||||
|
throw new Error(bindRes.data?.message || '微信绑定失败')
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
uni.hideLoading()
|
||||||
|
payError.value = '微信绑定失败,请重试'
|
||||||
|
uni.showToast({ title: '微信绑定失败', icon: 'none' })
|
||||||
|
return
|
||||||
|
}
|
||||||
|
uni.hideLoading()
|
||||||
|
}
|
||||||
|
|
||||||
payLoading.value = false
|
payLoading.value = false
|
||||||
|
|
||||||
if (res.statusCode === 200 && res.data?.payParams) {
|
if (res.statusCode >= 200 && res.statusCode < 300 && res.data?.payParams) {
|
||||||
const pp = res.data.payParams
|
const pp = res.data.payParams
|
||||||
currentOutTradeNo.value = res.data.outTradeNo || ''
|
currentOutTradeNo.value = res.data.outTradeNo || ''
|
||||||
// 调起微信支付
|
|
||||||
uni.requestPayment({
|
uni.requestPayment({
|
||||||
provider: 'wxpay',
|
provider: 'wxpay',
|
||||||
timeStamp: pp.timeStamp,
|
timeStamp: pp.timeStamp,
|
||||||
@@ -202,7 +299,7 @@ const startPay = async (selectedPlan) => {
|
|||||||
const no = currentOutTradeNo.value || res.data.outTradeNo
|
const no = currentOutTradeNo.value || res.data.outTradeNo
|
||||||
pollPayResult(no, planLabel)
|
pollPayResult(no, planLabel)
|
||||||
},
|
},
|
||||||
fail: (err) => { payError.value = '支付取消或失败'; uni.showToast({ title: '支付取消', icon: 'none' }) },
|
fail: (err) => { payError.value = '支付未完成'; uni.showToast({ title: '支付未完成', icon: 'none' }) },
|
||||||
})
|
})
|
||||||
} else if (!res.statusCode || res.statusCode === 0) {
|
} else if (!res.statusCode || res.statusCode === 0) {
|
||||||
payLoading.value = false
|
payLoading.value = false
|
||||||
@@ -211,9 +308,12 @@ const startPay = async (selectedPlan) => {
|
|||||||
uni.showToast({ title: errMsg, icon: 'none' })
|
uni.showToast({ title: errMsg, icon: 'none' })
|
||||||
} else {
|
} else {
|
||||||
payLoading.value = false
|
payLoading.value = false
|
||||||
const errMsg = res.data?.message || '创建订单失败'
|
// DEBUG: 显示实际返回的状态和数据以便排查
|
||||||
|
const debugInfo = `[${res.statusCode}] ${JSON.stringify(res.data).substring(0, 120)}`
|
||||||
|
console.error('支付响应异常:', debugInfo)
|
||||||
|
const errMsg = res.data?.message || `创建订单失败(${debugInfo})`
|
||||||
payError.value = errMsg
|
payError.value = errMsg
|
||||||
uni.showToast({ title: errMsg, icon: 'none' })
|
uni.showToast({ title: errMsg, icon: 'none', duration: 4000 })
|
||||||
}
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
payLoading.value = false
|
payLoading.value = false
|
||||||
@@ -230,7 +330,7 @@ const startPay = async (selectedPlan) => {
|
|||||||
})
|
})
|
||||||
payLoading.value = false
|
payLoading.value = false
|
||||||
|
|
||||||
if (res.statusCode === 200 && res.data?.codeUrl) {
|
if (res.statusCode >= 200 && res.statusCode < 300 && res.data?.codeUrl) {
|
||||||
payCodeUrl.value = res.data.codeUrl
|
payCodeUrl.value = res.data.codeUrl
|
||||||
currentOutTradeNo.value = res.data.outTradeNo
|
currentOutTradeNo.value = res.data.outTradeNo
|
||||||
nextTick(() => {
|
nextTick(() => {
|
||||||
@@ -265,6 +365,117 @@ const startPay = async (selectedPlan) => {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** 数量增减 */
|
||||||
|
const changeQty = (delta) => {
|
||||||
|
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 confirmProductBuy = () => {
|
||||||
|
showQuantityModal.value = false
|
||||||
|
startProductPay(buyProductType.value, buyQuantity.value)
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 按次购买 */
|
||||||
|
const startProductPay = async (type, quantity = 1) => {
|
||||||
|
const t = token()
|
||||||
|
if (!t) { uni.showToast({ title: '请先登录', icon: 'none' }); return }
|
||||||
|
productPayType.value = type
|
||||||
|
showPayModal.value = true
|
||||||
|
payLoading.value = true
|
||||||
|
payError.value = ''
|
||||||
|
|
||||||
|
const prod = products.value.find(p => p.type === type)
|
||||||
|
const prodTitle = prod?.title || type
|
||||||
|
|
||||||
|
if (isMp.value) {
|
||||||
|
// 小程序:JSAPI 按次支付
|
||||||
|
try {
|
||||||
|
let res = await uni.request({
|
||||||
|
url: api('/payment/jsapi-product'), method: 'POST',
|
||||||
|
data: { type, quantity },
|
||||||
|
header: { 'Authorization': `Bearer ${t}`, 'Content-Type': 'application/json' },
|
||||||
|
timeout: 30000,
|
||||||
|
})
|
||||||
|
payLoading.value = false
|
||||||
|
|
||||||
|
if (res.statusCode >= 200 && res.statusCode < 300 && 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: () => {
|
||||||
|
const no = currentOutTradeNo.value || res.data.outTradeNo
|
||||||
|
pollPayResult(no, 'growth')
|
||||||
|
},
|
||||||
|
fail: (err) => { payError.value = '支付未完成'; uni.showToast({ title: '支付未完成', icon: 'none' }) },
|
||||||
|
})
|
||||||
|
} else if (!res.statusCode || res.statusCode === 0) {
|
||||||
|
payLoading.value = false
|
||||||
|
uni.showToast({ title: '网络连接失败', icon: 'none' })
|
||||||
|
} else {
|
||||||
|
payLoading.value = false
|
||||||
|
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 {
|
||||||
|
// H5:扫码支付
|
||||||
|
try {
|
||||||
|
const res = await uni.request({
|
||||||
|
url: api('/payment/create-product'), method: 'POST',
|
||||||
|
data: { type, quantity },
|
||||||
|
header: { 'Authorization': `Bearer ${t}`, '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
|
||||||
|
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, 'growth')
|
||||||
|
} else if (!res.statusCode || res.statusCode === 0) {
|
||||||
|
payLoading.value = false
|
||||||
|
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, selectedPlan) => {
|
const pollPayResult = async (outTradeNo, selectedPlan) => {
|
||||||
if (!outTradeNo) return
|
if (!outTradeNo) return
|
||||||
@@ -278,7 +489,7 @@ const pollPayResult = async (outTradeNo, selectedPlan) => {
|
|||||||
url: api(`/payment/check/${outTradeNo}`), method: 'GET',
|
url: api(`/payment/check/${outTradeNo}`), method: 'GET',
|
||||||
header: { 'Authorization': `Bearer ${token()}` },
|
header: { 'Authorization': `Bearer ${token()}` },
|
||||||
})
|
})
|
||||||
if (res.statusCode === 200 && res.data?.status === 'success') {
|
if (res.statusCode >= 200 && res.statusCode < 300 && res.data?.status === 'success') {
|
||||||
// 支付成功,激活套餐
|
// 支付成功,激活套餐
|
||||||
await activatePlan(outTradeNo, selectedPlan)
|
await activatePlan(outTradeNo, selectedPlan)
|
||||||
return
|
return
|
||||||
@@ -303,7 +514,7 @@ const activatePlan = async (outTradeNo, selectedPlan) => {
|
|||||||
data: { outTradeNo },
|
data: { outTradeNo },
|
||||||
header: { 'Authorization': `Bearer ${token()}`, 'Content-Type': 'application/json' },
|
header: { 'Authorization': `Bearer ${token()}`, 'Content-Type': 'application/json' },
|
||||||
})
|
})
|
||||||
if (res.statusCode === 200 && res.data?.success) {
|
if (res.statusCode >= 200 && res.statusCode < 300 && res.data?.success) {
|
||||||
paySuccess.value = true
|
paySuccess.value = true
|
||||||
showPayModal.value = false
|
showPayModal.value = false
|
||||||
plan.value = selectedPlan === 'sprint' ? 'sprint' : 'growth'
|
plan.value = selectedPlan === 'sprint' ? 'sprint' : 'growth'
|
||||||
@@ -354,4 +565,20 @@ const activatePlan = async (outTradeNo, selectedPlan) => {
|
|||||||
.qr-canvas { width: 400rpx; height: 400rpx; background: #FFF; border-radius: var(--radius-md); }
|
.qr-canvas { width: 400rpx; height: 400rpx; background: #FFF; border-radius: var(--radius-md); }
|
||||||
.modal-hint { font-size: 22rpx; color: var(--color-text-tertiary); }
|
.modal-hint { font-size: 22rpx; color: var(--color-text-tertiary); }
|
||||||
.modal-close { font-size: 22rpx; color: var(--color-text-tertiary); padding: 8rpx; }
|
.modal-close { font-size: 22rpx; color: var(--color-text-tertiary); padding: 8rpx; }
|
||||||
|
|
||||||
|
/* 数量选择弹窗 */
|
||||||
|
.qty-selector { width: 100%; }
|
||||||
|
.qty-label { font-size: 24rpx; color: #6B7280; margin-bottom: 16rpx; display: block; }
|
||||||
|
.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-btn:active:not(.disabled) { transform: scale(0.9); background: #E5E7EB; }
|
||||||
|
.qty-input { width: 100rpx; height: 72rpx; text-align: center; font-size: 36rpx; font-weight: 700; color: var(--color-text); border: 2rpx solid #E5E7EB; border-radius: var(--radius-sm); }
|
||||||
|
.qty-summary { width: 100%; display: flex; justify-content: space-between; align-items: center; padding: 16rpx 0; border-top: 1rpx solid #F3F4F6; }
|
||||||
|
.qty-unit-price { font-size: 22rpx; color: #6B7280; }
|
||||||
|
.qty-total { font-size: 26rpx; color: var(--color-text); font-weight: 500; }
|
||||||
|
.qty-total-num { font-size: 36rpx; font-weight: 800; color: var(--color-primary); }
|
||||||
|
.qty-actions { width: 100%; display: flex; gap: 16rpx; margin-top: 8rpx; }
|
||||||
|
.qty-cancel { flex: 1; text-align: center; padding: 20rpx; border-radius: var(--radius-md); font-size: 26rpx; color: #6B7280; border: 2rpx solid #E5E7EB; }
|
||||||
|
.qty-confirm { flex: 2; text-align: center; padding: 20rpx; border-radius: var(--radius-md); font-size: 26rpx; font-weight: 600; color: #FFF; background: linear-gradient(135deg, var(--color-gradient-start), var(--color-gradient-mid)); }
|
||||||
</style>
|
</style>
|
||||||
@@ -4,8 +4,8 @@
|
|||||||
<view class="stats-card">
|
<view class="stats-card">
|
||||||
<view class="stat-row">
|
<view class="stat-row">
|
||||||
<view class="stat-item">
|
<view class="stat-item">
|
||||||
<text class="stat-value">{{ stats.shareCredits || 0 }}</text>
|
<text class="stat-value">{{ stats.gravity ?? 0 }}</text>
|
||||||
<text class="stat-label">📦 我的积分</text>
|
<text class="stat-label">🌌 我的引力值</text>
|
||||||
</view>
|
</view>
|
||||||
</view>
|
</view>
|
||||||
<view class="stat-sub-row">
|
<view class="stat-sub-row">
|
||||||
@@ -20,12 +20,12 @@
|
|||||||
</view>
|
</view>
|
||||||
<view class="stat-arrow">→</view>
|
<view class="stat-arrow">→</view>
|
||||||
<view class="stat-sub-item">
|
<view class="stat-sub-item">
|
||||||
<text class="stat-sub-value">{{ stats.shareCredits || 0 }}</text>
|
<text class="stat-sub-value">{{ stats.gravity || 0 }}</text>
|
||||||
<text class="stat-sub-label">获得积分</text>
|
<text class="stat-sub-label">获得引力值</text>
|
||||||
</view>
|
</view>
|
||||||
</view>
|
</view>
|
||||||
<view class="hint">
|
<view class="hint">
|
||||||
💡 好友通过你的链接打开并 <text class="hint-em">登录/注册</text> 才算有效,每次有效得 1 积分
|
💡 好友通过你的链接打开并 <text class="hint-em">登录/注册</text> 才算有效,每次有效获 1 引力值(每日上限 3)
|
||||||
</view>
|
</view>
|
||||||
</view>
|
</view>
|
||||||
|
|
||||||
@@ -49,15 +49,31 @@
|
|||||||
<view class="today-bar">
|
<view class="today-bar">
|
||||||
<view class="today-bar-fill" :style="{ width: Math.min(100, (todayStats.credited / 3) * 100) + '%' }"></view>
|
<view class="today-bar-fill" :style="{ width: Math.min(100, (todayStats.credited / 3) * 100) + '%' }"></view>
|
||||||
</view>
|
</view>
|
||||||
<text class="today-hint">每日最多 3 次有效积分</text>
|
<text class="today-hint">每日最多 3 次有效引力值,分享给朋友圈可获更多</text>
|
||||||
</view>
|
</view>
|
||||||
|
|
||||||
<!-- 分享按钮 -->
|
<!-- 分享按钮 -->
|
||||||
<view class="share-actions">
|
<view class="share-actions">
|
||||||
|
<!-- #ifdef MP-WEIXIN -->
|
||||||
|
<button class="share-btn wx-share" open-type="share">
|
||||||
|
<text class="btn-icon">💬</text>
|
||||||
|
<text>分享给好友</text>
|
||||||
|
</button>
|
||||||
|
<button class="share-btn wx-share" open-type="share" data-mode="timeline">
|
||||||
|
<text class="btn-icon">🔄</text>
|
||||||
|
<text>分享朋友圈</text>
|
||||||
|
</button>
|
||||||
|
<!-- #endif -->
|
||||||
|
<!-- #ifdef H5 -->
|
||||||
<button class="share-btn wx-share" @click="shareToWechat" v-if="isWechat">
|
<button class="share-btn wx-share" @click="shareToWechat" v-if="isWechat">
|
||||||
<text class="btn-icon">💬</text>
|
<text class="btn-icon">💬</text>
|
||||||
<text>分享给微信好友</text>
|
<text>分享给微信好友</text>
|
||||||
</button>
|
</button>
|
||||||
|
<button class="share-btn wx-timeline" @click="shareToWechat" v-if="isWechat">
|
||||||
|
<text class="btn-icon">🔄</text>
|
||||||
|
<text>分享朋友圈</text>
|
||||||
|
</button>
|
||||||
|
<!-- #endif -->
|
||||||
<button class="share-btn link-share" @click="copyLink">
|
<button class="share-btn link-share" @click="copyLink">
|
||||||
<text class="btn-icon">🔗</text>
|
<text class="btn-icon">🔗</text>
|
||||||
<text>复制分享链接</text>
|
<text>复制分享链接</text>
|
||||||
@@ -113,10 +129,14 @@
|
|||||||
|
|
||||||
<script setup>
|
<script setup>
|
||||||
import { ref, computed, onMounted } from 'vue'
|
import { ref, computed, onMounted } from 'vue'
|
||||||
|
// #ifdef MP-WEIXIN
|
||||||
|
import { onShareAppMessage, onShareTimeline } from '@dcloudio/uni-app'
|
||||||
|
// #endif
|
||||||
import { api } from '../../config'
|
import { api } from '../../config'
|
||||||
|
|
||||||
const tab = ref('records')
|
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 records = ref([])
|
const records = ref([])
|
||||||
const visitors = ref([])
|
const visitors = ref([])
|
||||||
|
|
||||||
@@ -127,6 +147,18 @@ const todayStats = computed(() => ({
|
|||||||
|
|
||||||
const isWechat = ref(false)
|
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(() => {
|
onMounted(() => {
|
||||||
// #ifdef H5
|
// #ifdef H5
|
||||||
isWechat.value = navigator?.userAgent?.toLowerCase().includes('micromessenger') || false
|
isWechat.value = navigator?.userAgent?.toLowerCase().includes('micromessenger') || false
|
||||||
@@ -243,6 +275,7 @@ function formatTime(t) {
|
|||||||
.share-btn:active { transform: scale(0.96); }
|
.share-btn:active { transform: scale(0.96); }
|
||||||
.btn-icon { margin-right: 8rpx; font-size: 28rpx; }
|
.btn-icon { margin-right: 8rpx; font-size: 28rpx; }
|
||||||
.wx-share { background: #07C160; color: #FFFFFF; }
|
.wx-share { background: #07C160; color: #FFFFFF; }
|
||||||
|
.wx-timeline { background: #FF6600; color: #FFFFFF; }
|
||||||
.link-share { background: #FFFFFF; color: var(--color-text); border: 2rpx solid var(--color-border); }
|
.link-share { background: #FFFFFF; color: var(--color-text); border: 2rpx solid var(--color-border); }
|
||||||
|
|
||||||
/* Tabs */
|
/* Tabs */
|
||||||
|
|||||||
@@ -39,6 +39,20 @@
|
|||||||
</view>
|
</view>
|
||||||
</view>
|
</view>
|
||||||
|
|
||||||
|
<!-- 配额与会员信息 -->
|
||||||
|
<view class="quota-card" v-if="isLoggedIn">
|
||||||
|
<view class="quota-row">
|
||||||
|
<view class="quota-info">
|
||||||
|
<text class="quota-plan">{{ memberInfo.planName || '免费版' }}</text>
|
||||||
|
<text class="quota-count">引力值 {{ memberInfo.gravity ?? 0 }}</text>
|
||||||
|
</view>
|
||||||
|
<view class="quota-actions">
|
||||||
|
<text class="quota-btn primary" @click="goBuyCredits">补充引力值</text>
|
||||||
|
<text class="quota-btn" :class="memberInfo.plan !== 'free' ? 'owned' : ''" @click="goUpgrade">{{ memberInfo.plan !== 'free' ? '已开通' : '升级会员' }}</text>
|
||||||
|
</view>
|
||||||
|
</view>
|
||||||
|
</view>
|
||||||
|
|
||||||
<!-- 菜单列表 -->
|
<!-- 菜单列表 -->
|
||||||
<view class="menu-area">
|
<view class="menu-area">
|
||||||
<view class="menu-group">
|
<view class="menu-group">
|
||||||
@@ -102,6 +116,7 @@ const userInfo = ref({})
|
|||||||
const isAdmin = ref(false)
|
const isAdmin = ref(false)
|
||||||
const stats = ref({ interviewCount: 0, avgScore: '--', completedCount: 0 })
|
const stats = ref({ interviewCount: 0, avgScore: '--', completedCount: 0 })
|
||||||
const token = ref('')
|
const token = ref('')
|
||||||
|
const memberInfo = ref({ plan: 'free', planName: '免费版', remaining: 0, gravity: 0 })
|
||||||
|
|
||||||
const isLoggedIn = computed(() => !!token.value)
|
const isLoggedIn = computed(() => !!token.value)
|
||||||
const maskedId = computed(() => {
|
const maskedId = computed(() => {
|
||||||
@@ -114,6 +129,7 @@ const refreshState = () => {
|
|||||||
if (!token.value) return
|
if (!token.value) return
|
||||||
try { const s = uni.getStorageSync('userInfo'); if (s) userInfo.value = JSON.parse(s) } catch(e) {}
|
try { const s = uni.getStorageSync('userInfo'); if (s) userInfo.value = JSON.parse(s) } catch(e) {}
|
||||||
loadStats()
|
loadStats()
|
||||||
|
loadMemberStatus()
|
||||||
checkAdmin()
|
checkAdmin()
|
||||||
fetchUserInfo()
|
fetchUserInfo()
|
||||||
}
|
}
|
||||||
@@ -131,6 +147,16 @@ const fetchUserInfo = async () => {
|
|||||||
onMounted(refreshState)
|
onMounted(refreshState)
|
||||||
onShow(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 () => {
|
const loadStats = async () => {
|
||||||
try {
|
try {
|
||||||
const res = await uni.request({ url: api('/interview/stats/mine'), method: 'GET', header: { 'Authorization': `Bearer ${token.value}` } })
|
const res = await uni.request({ url: api('/interview/stats/mine'), method: 'GET', header: { 'Authorization': `Bearer ${token.value}` } })
|
||||||
@@ -153,6 +179,11 @@ const checkAdmin = () => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const goLogin = () => uni.navigateTo({ url: '/pages/login/login' })
|
const goLogin = () => uni.navigateTo({ url: '/pages/login/login' })
|
||||||
|
const goBuyCredits = () => uni.navigateTo({ url: '/pages/member/member?buy=interview' })
|
||||||
|
const goUpgrade = () => {
|
||||||
|
if (memberInfo.value.plan !== 'free') return // already on a paid plan
|
||||||
|
uni.navigateTo({ url: '/pages/member/member' })
|
||||||
|
}
|
||||||
const goCareer = () => uni.navigateTo({ url: '/pages/career/career' })
|
const goCareer = () => uni.navigateTo({ url: '/pages/career/career' })
|
||||||
const goHistory = () => uni.switchTab({ url: '/pages/history/history' })
|
const goHistory = () => uni.switchTab({ url: '/pages/history/history' })
|
||||||
const goReviewReview = () => uni.navigateTo({ url: '/pages/review/review' })
|
const goReviewReview = () => uni.navigateTo({ url: '/pages/review/review' })
|
||||||
@@ -197,7 +228,18 @@ const doLogout = () => {
|
|||||||
.guest-info { flex: 1; }
|
.guest-info { flex: 1; }
|
||||||
.guest-name { font-size: 30rpx; font-weight: 600; color: #FFFFFF; }
|
.guest-name { font-size: 30rpx; font-weight: 600; color: #FFFFFF; }
|
||||||
|
|
||||||
.menu-area { padding: 0 32rpx 32rpx; margin-top: -40rpx; }
|
.quota-card { margin: -48rpx 32rpx 16rpx; background: #FFFFFF; border-radius: var(--radius-lg); padding: 28rpx 24rpx; box-shadow: var(--shadow-sm); position: relative; z-index: 1; }
|
||||||
|
.quota-row { display: flex; align-items: center; justify-content: space-between; }
|
||||||
|
.quota-info { display: flex; flex-direction: column; gap: 4rpx; }
|
||||||
|
.quota-plan { font-size: 28rpx; font-weight: 700; color: var(--color-text); }
|
||||||
|
.quota-count { font-size: 22rpx; color: #6B7280; }
|
||||||
|
.quota-actions { display: flex; gap: 12rpx; }
|
||||||
|
.quota-btn { font-size: 22rpx; padding: 8rpx 20rpx; border-radius: var(--radius-sm); font-weight: 500; white-space: nowrap; }
|
||||||
|
.quota-btn.primary { background: linear-gradient(135deg, var(--color-gradient-start), var(--color-gradient-mid)); color: #FFF; }
|
||||||
|
.quota-btn.owned { background: #F3F4F6; color: #9CA3AF; }
|
||||||
|
.quota-btn:not(.primary):not(.owned) { background: #FEF3C7; color: #92400E; border: 2rpx solid #F59E0B; }
|
||||||
|
|
||||||
|
.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-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); }
|
.menu-item { display: flex; align-items: center; padding: 28rpx 32rpx; border-bottom: 1rpx solid var(--color-border); }
|
||||||
.menu-item:last-child { border-bottom: none; }
|
.menu-item:last-child { border-bottom: none; }
|
||||||
|
|||||||
Reference in New Issue
Block a user