9 Commits

Author SHA1 Message Date
yuzhiran 81f86d995d v1.0.18: 小程序虚拟支付上线 + 定价调整为整数
- 新增虚拟支付 (short_series_coin 代币模式,1:1 兑换)
- 后端  修复为正确 VP 格式,返回 mode 参数
- 前端 VP 调用补齐 、 格式调整
- 套餐价格调整:成长版 ¥19.9 → ¥19,冲刺版 ¥49.9 → ¥49
- 数据库定价同步更新为 1900/4900(分)
- 会员页未登录时也拉取 ,套餐对比数据由服务端返回
- 文档统一更新定价和 VP 说明
- 修正 AGENTS.md 引力值数据(250/600 → 80/200)
2026-06-22 20:29:51 +08:00
yuzhiran 1a45822a58 fix(mp): handle mini-program launch params and pre-create share code for user page
App.vue: add handleLaunchParams() to read token/shareCode from onLaunch/onShow query in MP-WEIXIN context. user.vue: pre-create share record on page load, use dynamic path with shareCode in onShareAppMessage.

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

Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai>
2026-06-22 14:23:27 +08:00
yuzhiran d74fc74f28 feat(admin): convert all timestamps to Beijing time (UTC+8) for display
Create utils/format.ts with toBeijing() helper. Replace 13 raw .slice().replace() date displays in admin.vue with centralized timezone-aware formatting.

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

Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai>
2026-06-22 12:51:58 +08:00
yuzhiran b6323f02eb feat(admin): show last login time/IP/location in user list
Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-openagent)

Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai>
2026-06-22 12:38:26 +08:00
yuzhiran 04b30d0024 feat(backend): record lastLoginAt/IP/location on every login
Add lastLoginAt, lastLoginIp, lastLoginLocation to User schema. recordLogin() method called from all 5 login flows (phone, email, wx, password, register). Exposed in safeUser so info endpoint returns login metadata.

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

Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai>
2026-06-22 12:38:07 +08:00
yuzhiran 13b2a764ef fix(admin): partial _id fuzzy search via $expr + $toString + $regexMatch 2026-06-22 12:14:31 +08:00
yuzhiran 70c4f28eb5 fix(admin): add wxOpenid to fuzzy search, enhance admin tab info
- Backend getUsers: add wxOpenid to  regex search
- Backend getAdmins: return gravity, plan, wxOpenid, email fields
- Frontend admin tab: show full user info (ID copy, email, gravity, plan)
- Frontend search result: show complete user details like user list rows
2026-06-22 12:07:52 +08:00
yuzhiran d37bbd7a61 feat(admin): fuzzy search by email/ID, display full userId in user list
- Backend: add email + _id to  filter in getUsers() for fuzzy search
- Frontend: show full MongoDB _id in user row with tap-to-copy
- Search placeholder updated to mention email/ID
2026-06-22 11:46:14 +08:00
yuzhiran 4d54c8088c fix: Mongoose 8 pre-save hook crash (next->async), v1.0.17 tag, test user
- user.schema.ts: convert pre-save from callback(next) to async - fixes
  'TypeError: next is not a function' on login (Mongoose 8 compat)
- Tag v1.0.17 for 1.0.18 build cycle
- scripts/seed-test-user.ts: utility to create test accounts
- docs: PROJECT-STATUS v4.9, AGENTS.md version bump
- Add test user test@yzrcloud.cn / 123456 (role: user)
2026-06-22 11:27:21 +08:00
20 changed files with 1093 additions and 222 deletions
+7 -6
View File
@@ -96,14 +96,15 @@ zhiyin/
- 主用不可用时自动切换(在 `ai` 模块处理) - 主用不可用时自动切换(在 `ai` 模块处理)
- 环境变量: `AI_PRIMARY_KEY`, `AI_BACKUP_KEY` - 环境变量: `AI_PRIMARY_KEY`, `AI_BACKUP_KEY`
### 支付(微信支付 v3 ### 支付(微信支付 v3 + 虚拟支付
- Native 支付(H5 扫码): `POST /payment/create-product`(按量购买引力值) - Native 支付(H5 扫码): `POST /payment/create-product`(按量购买引力值)
- JSAPI 支付(小程序内): `POST /payment/jsapi-product`(按量购买引力值) - JSAPI 支付(小程序内): `POST /payment/jsapi-product`(按量购买引力值)
- 虚拟支付(小程序内直接购买): `POST /virtual-payment/create`mode=`short_series_coin`,代币名「引力值」,1 币 = 1 元)
- 支付回调: `POST /payment/notify`@Public,验签 + 解密 + 自动到账) - 支付回调: `POST /payment/notify`@Public,验签 + 解密 + 自动到账)
- 支付结果轮询: `GET /payment/check/:outTradeNo` - 支付结果轮询: `GET /payment/check/:outTradeNo`
- 产品定价: `GET /member/plans`(含 products 字段,定义引力值单价和赠送量) - 产品定价: `GET /member/plans`(含 products 字段,定义引力值单价和赠送量)
- 需要微信商户证书文件(通过 postbuild 复制到 dist - 需要微信商户证书文件(通过 postbuild 复制到 dist
- **注意**: 当前会员体系已从按月订阅制改为按量购买引力值制(小程序内复制链接到浏览器打开购买,H5 直接扫码支付) - **注意**: 当前会员体系已从按月订阅制改为按量购买引力值制(小程序内虚拟支付直接购买,H5 扫码支付)
--- ---
@@ -202,7 +203,7 @@ cd zhiyin-app && npm run build:mp-weixin && node scripts/upload-mp.js
## 六、项目状态与开发阶段 ## 六、项目状态与开发阶段
**当前**: Phase 1.5(商业化 + 全量部署)— v1.0.17 **当前**: Phase 1.5(商业化 + 全量部署)— v1.0.18(开发中)
| 阶段 | 状态 | 关键交付 | | 阶段 | 状态 | 关键交付 |
|------|------|---------| |------|------|---------|
@@ -259,7 +260,7 @@ VITE_APP_NAME=AI磁场
| 账号 | 密码 | 角色 | 说明 | | 账号 | 密码 | 角色 | 说明 |
|------|------|------|------| |------|------|------|------|
| `13701190814@139.com` | `Zhiyin2024!` | admin | 管理员,可访问管理后台 | | `13701190814@139.com` | `Zhiyin2024!` | admin | 管理员,可访问管理后台 |
| `test@yzrcloud.cn` | `123456` | user | 测试账号 | | `test@yzrcloud.cn` | `123456` | user | 测试账号(普通用户,含 5 引力值) |
| `test@test.com` | 验证码 `123456` | admin | 旧管理员(dev 模式可用) | | `test@test.com` | 验证码 `123456` | admin | 旧管理员(dev 模式可用) |
管理后台路径:`/pages/admin/admin`,进入后自动验证管理员身份(`onMounted``doVerify`)。 管理后台路径:`/pages/admin/admin`,进入后自动验证管理员身份(`onMounted``doVerify`)。
@@ -270,7 +271,7 @@ VITE_APP_NAME=AI磁场
- 远程仓库: `http://127.0.0.1:2999/txai-dev/zhiyin.git`(本机 Gitea,带 token 认证) - 远程仓库: `http://127.0.0.1:2999/txai-dev/zhiyin.git`(本机 Gitea,带 token 认证)
- 默认分支: `master` - 默认分支: `master`
- 最新 tag: `v1.0.16`(小程序上传版本 v1.0.17 源自 git tag + 末位自增 1 - 最新 tag: `v1.0.17`(小程序上传版本 v1.0.18 源自 git tag v1.0.17 + 末位自增 1
--- ---
@@ -284,7 +285,7 @@ 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. **引力值体系**: 所有计划统一走引力值消耗(面试 5、优化 3、下载 2)。VIP 不再免额度,成长版每月 250 引力值,冲刺版每月 600 引力值,每日凌晨 2 点定时补给。免费用户注册送 5 引力值。小程序内通过分享得引力值/贡献面经/复制官网链接到浏览器打开购买三种方式获取引力值;H5 直接扫码支付按量购买(¥5/份)。 9. **引力值体系**: 所有计划统一走引力值消耗(面试 5、优化 3、下载 2)。VIP 不再免额度,成长版每月赠送 80 引力值,冲刺版每月赠送 200 引力值,每日凌晨 2 点定时补给。免费用户注册送 5 引力值。小程序内通过分享得引力值/贡献面经/虚拟支付购买三种方式获取引力值;H5 直接扫码支付按量购买(¥5/份)。
10. **api.ts 陷阱**: 对象字面量必须在 `export const apiService = {``const apiService = { ... export default apiService` 中包裹,否则 uni-app 构建报错 `Expected ";" but found ":"`。git pull 后经常丢失这行声明,需手动补回 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. **H5 构建 assets 清理**: `assets/` 中的旧 hash 文件不能随意删除——`index-*.js`(主 bundle)动态 import 了所有 page chunk,删除仍在引用的文件会导致浏览器 `NS_ERROR_CORRUPTED_CONTENT`
12. **管理后台自动验证**: `admin.vue``onMounted` 自动调用 `doVerify()`,进入后台即检测 JWT 中 `role` 是否为 `admin`,不再需要手动点击"验证管理员身份"按钮 12. **管理后台自动验证**: `admin.vue``onMounted` 自动调用 `doVerify()`,进入后台即检测 JWT 中 `role` 是否为 `admin`,不再需要手动点击"验证管理员身份"按钮
+55
View File
@@ -0,0 +1,55 @@
import { connect, disconnect } from 'mongoose'
import * as bcrypt from 'bcrypt'
import * as dotenv from 'dotenv'
import * as path from 'path'
dotenv.config({ path: path.resolve(__dirname, '../.env') })
async function main() {
const uri = process.env.MONGODB_URI
if (!uri) {
console.error('MONGODB_URI not set')
process.exit(1)
}
const conn = await connect(uri)
console.log('Connected to MongoDB')
const users = conn.connection.db!.collection('users')
const email = 'test@yzrcloud.cn'
const password = '123456'
const hashed = await bcrypt.hash(password, 10)
const existing = await users.findOne({ email })
if (existing) {
await users.updateOne(
{ email },
{ $set: { password: hashed, nickname: '测试用户', role: 'user', gravity: 5, interviewCredits: 1, remaining: 3 } }
)
console.log(`Updated test user: ${email}`)
} else {
await users.insertOne({
email,
password: hashed,
nickname: '测试用户',
role: 'user',
gravity: 5,
interviewCredits: 1,
remaining: 3,
interviewCount: 0,
plan: 'free',
createdAt: new Date(),
updatedAt: new Date(),
})
console.log(`Created test user: ${email}`)
}
await disconnect()
console.log('Done')
}
main().catch(err => {
console.error('Failed:', err)
process.exit(1)
})
@@ -85,7 +85,13 @@ export class AdminController {
filter.$or = [ filter.$or = [
{ phone: { $regex: escaped, $options: 'i' } }, { phone: { $regex: escaped, $options: 'i' } },
{ nickname: { $regex: escaped, $options: 'i' } }, { nickname: { $regex: escaped, $options: 'i' } },
{ email: { $regex: escaped, $options: 'i' } },
{ wxOpenid: { $regex: escaped, $options: 'i' } },
] ]
// 支持按 _id 模糊搜索(ObjectId → string → regex
filter.$or.push({
$expr: { $regexMatch: { input: { $toString: '$_id' }, regex: escaped, options: 'i' } },
})
} }
const skip = (Math.max(1, +page) - 1) * +limit const skip = (Math.max(1, +page) - 1) * +limit
const [users, total] = await Promise.all([ const [users, total] = await Promise.all([
@@ -245,7 +251,7 @@ export class AdminController {
@Get('admins') @Get('admins')
async getAdmins() { async getAdmins() {
const admins = await this.userModel.find({ role: 'admin' }).select('phone nickname email createdAt isSystemAdmin').lean().exec() const admins = await this.userModel.find({ role: 'admin' }).select('phone nickname email wxOpenid gravity plan role createdAt isSystemAdmin').lean().exec()
return { admins } return { admins }
} }
@@ -21,13 +21,13 @@ interface PricingConfig {
} }
const DEFAULT_PRICING: PricingConfig = { const DEFAULT_PRICING: PricingConfig = {
interview: { pricePerSession: 500, creditsPerPurchase: 1 }, interview: { pricePerSession: 600, creditsPerPurchase: 1 },
resumeOptimize: { freeLimit: 3, pricePerOptimize: 300, creditsPerPurchase: 1 }, resumeOptimize: { freeLimit: 3, pricePerOptimize: 400, creditsPerPurchase: 1 },
resumeDownload: { pricePerDownload: 200, creditsPerPurchase: 1 }, resumeDownload: { pricePerDownload: 200, creditsPerPurchase: 1 },
gravityRates: { interviewPerUse: 5, optimizePerUse: 3, downloadPerUse: 2 }, gravityRates: { interviewPerUse: 5, optimizePerUse: 3, downloadPerUse: 2 },
plans: { plans: {
growth: { price: 1990, durationDays: 30, gravityPerMonth: 250, credits: { interview: 999, resumeOptimize: 20, resumeDownload: 10 }, features: ['免费版全部权益', 'AI 数字人面试每次 3 引力值(折扣价', '详细面试报告(四维评分)', '进步轨迹雷达图 + 打卡', '每日一题推送', '参考回答思路', '公司真题库', '简历优化 20 次/月', '简历下载 10 次/月'] }, growth: { price: 1900, durationDays: 30, gravityPerMonth: 80, credits: { interview: 999, resumeOptimize: 20, resumeDownload: 10 }, features: ['免费版全部权益', 'AI 模拟面试每次消耗 5 引力值,无限次', '详细面试报告(四维评分 + 语音复盘', '进步轨迹雷达图 + 打卡日历', '每日一题推送 + 参考思路', '公司真题库', '每月赠送 80 引力值,可用于面试/优化/下载'] },
sprint: { price: 4990, durationDays: 30, gravityPerMonth: 600, credits: { interview: 999, resumeOptimize: 50, resumeDownload: 30 }, features: ['成长版全部权益', 'AI 语音分析(语气词/语速检测)', '技能缺口分析报告', '学习路径推荐', '真人导师 1v1 点评(每月 1 次)', '简历精修(每月 1 次)', '内推优先', '简历优化 50 次/月', '简历下载 30 次/月'] }, sprint: { price: 4900, durationDays: 30, gravityPerMonth: 200, credits: { interview: 999, resumeOptimize: 50, resumeDownload: 30 }, features: ['成长版全部权益', 'AI 语音深度分析(语气词/语速/停顿检测)', '技能缺口分析报告', '公司真题库精选', '每月赠送 200 引力值,可用于面试/优化/下载'] },
}, },
} }
+10 -10
View File
@@ -18,8 +18,8 @@ export class UserController {
@Public() @Public()
@Post('login') @Post('login')
@HttpCode(HttpStatus.OK) @HttpCode(HttpStatus.OK)
async login(@Body('phone') phone: string, @Body('code') code: string) { async login(@Body('phone') phone: string, @Body('code') code: string, @Req() req) {
return this.userService.loginByPhone(phone, code) return this.userService.loginByPhone(phone, code, req.ip)
} }
// 📧 邮箱验证码登录(H5 用) // 📧 邮箱验证码登录(H5 用)
@@ -41,32 +41,32 @@ export class UserController {
@Public() @Public()
@Post('email-login') @Post('email-login')
@HttpCode(HttpStatus.OK) @HttpCode(HttpStatus.OK)
async emailLogin(@Body('email') email: string, @Body('code') code: string) { async emailLogin(@Body('email') email: string, @Body('code') code: string, @Req() req) {
return this.userService.loginByEmail(email, code) return this.userService.loginByEmail(email, code, req.ip)
} }
// 密码登录 // 密码登录
@Public() @Public()
@Post('password-login') @Post('password-login')
@HttpCode(HttpStatus.OK) @HttpCode(HttpStatus.OK)
async passwordLogin(@Body('email') email: string, @Body('password') password: string) { async passwordLogin(@Body('email') email: string, @Body('password') password: string, @Req() req) {
return this.userService.loginByPassword(email, password) return this.userService.loginByPassword(email, password, req.ip)
} }
// 邮箱+密码注册 // 邮箱+密码注册
@Public() @Public()
@Post('register') @Post('register')
@HttpCode(HttpStatus.OK) @HttpCode(HttpStatus.OK)
async register(@Body('email') email: string, @Body('password') password: string) { async register(@Body('email') email: string, @Body('password') password: string, @Req() req) {
return this.userService.registerWithPassword(email, password) return this.userService.registerWithPassword(email, password, req.ip)
} }
// 微信静默登录 // 微信静默登录
@Public() @Public()
@Post('wx-login') @Post('wx-login')
@HttpCode(HttpStatus.OK) @HttpCode(HttpStatus.OK)
async wxLogin(@Body('code') code: string) { async wxLogin(@Body('code') code: string, @Req() req) {
return this.userService.loginByWx(code) return this.userService.loginByWx(code, undefined, req.ip)
} }
@Get('info') @Get('info')
+11 -3
View File
@@ -65,13 +65,21 @@ export class User {
@Prop({ default: '', select: false }) @Prop({ default: '', select: false })
password?: string password?: string
@Prop()
lastLoginAt?: Date
@Prop({ default: '' })
lastLoginIp?: string
@Prop({ default: '' })
lastLoginLocation?: string
} }
export const UserSchema = SchemaFactory.createForClass(User) export const UserSchema = SchemaFactory.createForClass(User)
UserSchema.pre('save', function (next) { UserSchema.pre('save', async function () {
if (!this.phone && !this.wxOpenid && !this.email) { if (!this.phone && !this.wxOpenid && !this.email) {
return next(new Error('用户必须至少有一个联系方式(手机号/微信/邮箱)')) throw new Error('用户必须至少有一个联系方式(手机号/微信/邮箱)')
} }
next()
}) })
+37 -5
View File
@@ -6,6 +6,18 @@ import { JwtService } from '@nestjs/jwt'
import { User, UserDocument } from './user.schema' import { User, UserDocument } from './user.schema'
import { EmailService } from '../email/email.service' import { EmailService } from '../email/email.service'
/** 通过 IP 查询粗略地理位置(ip-api.com 免费接口) */
async function lookupIpLocation(ip: string): Promise<string> {
if (!ip || ip === '127.0.0.1' || ip === '::1' || ip.startsWith('192.168.') || ip.startsWith('10.')) return ''
try {
const res = await fetch(`http://ip-api.com/json/${ip}?fields=country,regionName,city&lang=zh-CN`, { signal: AbortSignal.timeout(3000) })
if (!res.ok) return ''
const data: any = await res.json()
if (data.status !== 'success') return ''
return [data.country, data.regionName, data.city].filter(Boolean).join(' ')
} catch { return '' }
}
// In-memory stores // In-memory stores
const codeStore = new Map<string, { code: string; expiresAt: number }>() const codeStore = new Map<string, { code: string; expiresAt: number }>()
const emailCodeStore = new Map<string, { code: string; expiresAt: number }>() const emailCodeStore = new Map<string, { code: string; expiresAt: number }>()
@@ -33,7 +45,7 @@ export class UserService {
return { message: '验证码已发送' } return { message: '验证码已发送' }
} }
async loginByPhone(phone: string, code: string) { async loginByPhone(phone: string, code: string, ip?: string) {
const record = codeStore.get(phone) const record = codeStore.get(phone)
if (!record || record.code !== code) { if (!record || record.code !== code) {
throw new HttpException('验证码错误', HttpStatus.UNAUTHORIZED) throw new HttpException('验证码错误', HttpStatus.UNAUTHORIZED)
@@ -49,10 +61,11 @@ export class UserService {
user = await this.userModel.create({ phone, nickname: `用户${phone.slice(-4)}`, gravity: 5 }) user = await this.userModel.create({ phone, nickname: `用户${phone.slice(-4)}`, gravity: 5 })
} }
await this.recordLogin(user._id.toString(), ip)
return this.generateAuthResponse(user) return this.generateAuthResponse(user)
} }
async loginByWx(code: string, userId?: string) { async loginByWx(code: string, userId?: string, ip?: string) {
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) {
@@ -84,6 +97,7 @@ export class UserService {
user = await this.userModel.create({ wxOpenid: openid, nickname: '微信用户', gravity: 5 }) user = await this.userModel.create({ wxOpenid: openid, nickname: '微信用户', gravity: 5 })
} }
await this.recordLogin(user._id.toString(), ip)
return this.generateAuthResponse(user) return this.generateAuthResponse(user)
} }
@@ -139,7 +153,7 @@ export class UserService {
return { message: '验证码已发送,请查收邮件' } return { message: '验证码已发送,请查收邮件' }
} }
async loginByEmail(email: string, code: string) { async loginByEmail(email: string, code: string, ip?: string) {
const record = emailCodeStore.get(email) const record = emailCodeStore.get(email)
if (!record || record.code !== code) { if (!record || record.code !== code) {
throw new HttpException('验证码错误', HttpStatus.UNAUTHORIZED) throw new HttpException('验证码错误', HttpStatus.UNAUTHORIZED)
@@ -158,21 +172,23 @@ export class UserService {
const nick = email.split('@')[0] const nick = email.split('@')[0]
user = await this.userModel.create({ email, nickname: nick, remaining: 0, gravity: 5 }) user = await this.userModel.create({ email, nickname: nick, remaining: 0, gravity: 5 })
} }
await this.recordLogin(user._id.toString(), ip)
return { ...this.generateAuthResponse(user), isNew, hasPassword: !!user.password } return { ...this.generateAuthResponse(user), isNew, hasPassword: !!user.password }
} }
// 🔐 密码登录 // 🔐 密码登录
async loginByPassword(email: string, password: string) { async loginByPassword(email: string, password: string, ip?: string) {
const user = await this.userModel.findOne({ email }).select('+password').exec() const user = await this.userModel.findOne({ email }).select('+password').exec()
if (!user) throw new HttpException('账号不存在', HttpStatus.NOT_FOUND) if (!user) throw new HttpException('账号不存在', HttpStatus.NOT_FOUND)
if (!user.password) throw new HttpException('该账号未设置密码,请使用验证码登录', HttpStatus.UNAUTHORIZED) if (!user.password) throw new HttpException('该账号未设置密码,请使用验证码登录', HttpStatus.UNAUTHORIZED)
const match = await bcrypt.compare(password, user.password) const match = await bcrypt.compare(password, user.password)
if (!match) throw new HttpException('密码错误', HttpStatus.UNAUTHORIZED) if (!match) throw new HttpException('密码错误', HttpStatus.UNAUTHORIZED)
await this.recordLogin(user._id.toString(), ip)
return this.generateAuthResponse(user) return this.generateAuthResponse(user)
} }
// 📝 邮箱+密码注册 // 📝 邮箱+密码注册
async registerWithPassword(email: string, password: string) { async registerWithPassword(email: string, password: string, ip?: string) {
if (!email || !email.includes('@')) { if (!email || !email.includes('@')) {
throw new HttpException('请输入正确的邮箱地址', HttpStatus.BAD_REQUEST) throw new HttpException('请输入正确的邮箱地址', HttpStatus.BAD_REQUEST)
} }
@@ -187,11 +203,13 @@ export class UserService {
// 已有验证码注册的用户,补充设置密码 // 已有验证码注册的用户,补充设置密码
existing.password = await bcrypt.hash(password, 10) existing.password = await bcrypt.hash(password, 10)
await existing.save() await existing.save()
await this.recordLogin(existing._id.toString(), ip)
return this.generateAuthResponse(existing) return this.generateAuthResponse(existing)
} }
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: 0, gravity: 5 }) const user = await this.userModel.create({ email, nickname: nick, password: hashed, remaining: 0, gravity: 5 })
await this.recordLogin(user._id.toString(), ip)
return this.generateAuthResponse(user) return this.generateAuthResponse(user)
} }
@@ -219,6 +237,17 @@ export class UserService {
getModel() { return this.userModel } getModel() { return this.userModel }
/** 记录登录时间/IP/归属地 */
async recordLogin(userId: string, ip?: string) {
const update: any = { lastLoginAt: new Date() }
if (ip) {
update.lastLoginIp = ip
const location = await lookupIpLocation(ip)
if (location) update.lastLoginLocation = location
}
await this.userModel.findByIdAndUpdate(userId, { $set: update }).exec()
}
async getUsage(userId: string) { async getUsage(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)
@@ -260,6 +289,9 @@ export class UserService {
freeOptimizeUsed: user.freeOptimizeUsed ?? 0, freeOptimizeUsed: user.freeOptimizeUsed ?? 0,
shareCredits: user.shareCredits ?? 0, shareCredits: user.shareCredits ?? 0,
gravity: user.gravity ?? 0, gravity: user.gravity ?? 0,
lastLoginAt: user.lastLoginAt,
lastLoginIp: user.lastLoginIp,
lastLoginLocation: user.lastLoginLocation,
} }
} }
} }
@@ -0,0 +1,259 @@
import { Controller, Post, Get, Param, Body, Query, UseGuards, HttpException, HttpStatus, Logger, Req, HttpCode } from '@nestjs/common'
import { InjectModel } from '@nestjs/mongoose'
import { Model } from 'mongoose'
import { User, UserDocument } from '../user/user.schema'
import { PaymentOrder, PaymentOrderDocument } from '../payment/payment-order.schema'
import { JwtAuthGuard } from '../../common/guards/jwt-auth.guard'
import { CurrentUser } from '../../common/decorators/current-user.decorator'
import { VirtualPaymentService } from './virtual-payment.service'
import { PricingService } from '../schemas/pricing.service'
import { QuotaService } from '../user/quota.service'
import { Public } from '../../common/decorators/public.decorator'
@Controller('virtual-payment')
export class VirtualPaymentController {
private readonly logger = new Logger(VirtualPaymentController.name)
constructor(
@InjectModel(User.name) private userModel: Model<UserDocument>,
@InjectModel(PaymentOrder.name) private orderModel: Model<PaymentOrderDocument>,
private vpService: VirtualPaymentService,
private pricingService: PricingService,
private quotaService: QuotaService,
) {}
/**
* 创建虚拟支付订单(小程序代币充值)
* 返回前端调起 wx.requestVirtualPayment 所需的全部参数
*/
@UseGuards(JwtAuthGuard)
@Post('create')
@HttpCode(200)
async create(
@CurrentUser('userId') userId: string,
@Body('type') type: string,
@Body('quantity') quantity: number = 1,
@Body('wxCode') wxCode: string,
@Req() req: any,
) {
if (!['interview', 'optimize', 'download', 'growth', 'sprint'].includes(type)) {
throw new HttpException('无效产品类型', HttpStatus.BAD_REQUEST)
}
const user = await this.userModel.findById(userId).exec()
if (!user) throw new HttpException('用户不存在', HttpStatus.NOT_FOUND)
if (!user.wxOpenid) {
throw new HttpException({ message: '未绑定微信', needBindWx: true }, HttpStatus.BAD_REQUEST)
}
if (!wxCode) {
throw new HttpException('缺少 wxCode,请先调用 wx.login()', HttpStatus.BAD_REQUEST)
}
const isPlan = type === 'growth' || type === 'sprint'
if (isPlan && user.plan !== 'free') {
throw new HttpException('已是会员', HttpStatus.BAD_REQUEST)
}
const pricing = await this.pricingService.getConfig()
let totalFee: number
let qty = 1
let productQty = Math.max(1, Math.min(99, quantity || 1))
if (isPlan) {
const planCfg = pricing.plans[type]
if (!planCfg) throw new HttpException('套餐未配置', HttpStatus.INTERNAL_SERVER_ERROR)
totalFee = planCfg.price
} else {
const priceMap: Record<string, number> = {
interview: pricing.interview.pricePerSession,
optimize: pricing.resumeOptimize.pricePerOptimize,
download: pricing.resumeDownload.pricePerDownload,
}
qty = productQty
totalFee = priceMap[type] * qty
if (!totalFee) throw new HttpException('价格未配置', HttpStatus.INTERNAL_SERVER_ERROR)
}
const mode = 'short_series_coin'
const buyQuantity = totalFee / 100 // 控制台配 1 币 = 1 元,totalFee 单位分
const outTradeNo = `VP${type.slice(0, 2).toUpperCase()}${Date.now()}${userId.slice(-6)}`
const env = process.env.VP_SANDBOX === 'true' ? 1 : (process.env.NODE_ENV === 'production' ? 0 : 1)
const userIp = req.ip || '127.0.0.1'
// 1. 用 wx.login code 换取 session_key + openid,计算用户态签名
let openid: string
let signature: string
try {
const signData = this.vpService.buildSignData(outTradeNo, user.wxOpenid, totalFee, userIp, env, mode, buyQuantity)
const result = await this.vpService.exchangeCodeAndSign(wxCode, signData)
openid = result.openid
signature = result.signature
} catch (e: any) {
this.logger.error(`[VP] code2session 失败: userId=${userId}, wxCode=${wxCode?.slice(0, 20)}, error=${e.message}, stack=${e.stack?.slice(0, 300)}`)
throw new HttpException(`微信身份验证失败: ${e.message}`, HttpStatus.BAD_REQUEST)
}
// 校验 openid 一致
this.logger.log(`[VP] code2session 成功: userId=${userId}, wxOpenid=${user.wxOpenid}, code2session_openid=${openid}`)
if (openid !== user.wxOpenid) {
this.logger.warn(`[VP] openid 不匹配: userId=${userId}, stored=${user.wxOpenid}, got=${openid}`)
throw new HttpException('微信身份不匹配', HttpStatus.FORBIDDEN)
}
// 2. 计算支付签名 pay_sig
const signData = this.vpService.buildSignData(outTradeNo, openid, totalFee, userIp, env, mode, buyQuantity)
const paySig = this.vpService.computePaySig('requestVirtualPayment', signData, env)
// 3. 创建本地订单
let title: string
const titles: Record<string, string> = {
interview: 'AI 模拟面试',
optimize: '简历优化',
download: '简历下载',
growth: '成长版月度会员',
sprint: '冲刺版月度会员',
}
if (isPlan) {
title = titles[type]
} else {
title = qty > 1 ? `${titles[type]} ×${qty}` : titles[type]
}
await this.orderModel.create({
outTradeNo,
userId,
userPhone: user.phone || '',
amount: totalFee,
title,
status: 'pending',
channel: 'virtual',
type,
plan: isPlan ? type : 'growth',
metadata: { quantity: qty },
})
return {
outTradeNo,
env,
mode,
offerId: this.vpService.getOfferId(),
signData,
paySig,
signature,
openid,
}
}
/**
* 微信消息推送回调——虚拟支付通知
* 在小程序管理后台 → 开发 → 开发管理 → 消息推送 中配置服务器地址指向此接口
*/
@Public()
@Post('callback')
async callback(@Body() body: any, @Req() req: any) {
try {
// 微信消息体可能是 XML 或 JSON
const msg = body.xml || body
const event = msg.Event || msg.event
this.logger.log(`[vp-callback] event=${event}, body=${JSON.stringify(body).slice(0, 500)}`)
if (event === 'xpay_coin_pay_notify') {
await this.handleCoinPayNotify(msg)
} else if (event === 'xpay_goods_deliver_notify') {
await this.handleGoodsDeliverNotify(msg)
} else if (event === 'xpay_refund_notify') {
await this.handleRefundNotify(msg)
} else {
this.logger.warn(`[vp-callback] 未知事件: ${event}`)
}
return { ErrCode: 0, ErrMsg: 'success' }
} catch (e: any) {
this.logger.error(`[vp-callback] 处理失败: ${e.message}`)
return { ErrCode: -1, ErrMsg: e.message }
}
}
private async handleCoinPayNotify(msg: any) {
const outTradeNo = msg.OutTradeNo || msg.out_trade_no
if (!outTradeNo) {
this.logger.warn('[vp-callback] 代币支付通知缺少 outTradeNo')
return
}
const order = await this.orderModel.findOne({ outTradeNo }).exec()
if (!order) {
this.logger.warn(`[vp-callback] 订单不存在: ${outTradeNo}`)
return
}
if (order.status !== 'pending') {
this.logger.log(`[vp-callback] 订单已处理: ${outTradeNo} status=${order.status}`)
return
}
order.status = 'success'
order.paidAt = new Date()
order.description = `虚拟支付代币充值成功 env=${msg.Env ?? ''}`
await order.save()
const pricing = await this.pricingService.getConfig()
if (order.type === 'growth' || order.type === 'sprint') {
// 套餐激活
const planCfg = pricing.plans[order.type]
if (!planCfg) return
const expireAt = new Date()
expireAt.setDate(expireAt.getDate() + planCfg.durationDays)
await this.userModel.findByIdAndUpdate(order.userId, {
$set: {
plan: order.type,
[order.type === 'sprint' ? 'sprintExpireAt' : 'vipExpireAt']: expireAt,
...(order.type === 'sprint' ? { sprintRemaining: 10 } : {}),
},
}).exec()
await this.quotaService.setPlanQuota(order.userId, planCfg.gravityPerMonth)
this.logger.log(`[vp-callback] 套餐已激活: userId=${order.userId}, plan=${order.type}, gravityPerMonth=${planCfg.gravityPerMonth}`)
} else {
// 发放引力值(按次购买)
const gravityMap: Record<string, number> = {
interview: pricing.gravityRates.interviewPerUse,
optimize: pricing.gravityRates.optimizePerUse,
download: pricing.gravityRates.downloadPerUse,
}
const g = gravityMap[order.type]
const quantity = order.metadata?.quantity || 1
if (g) {
await this.quotaService.grantGravity(order.userId, g * quantity)
this.logger.log(`[vp-callback] 引力值已发放: userId=${order.userId}, gravity=${g * quantity}`)
}
}
}
private async handleGoodsDeliverNotify(msg: any) {
// 道具发货通知——代币模式下通常不需要额外处理
this.logger.log(`[vp-callback] 道具发货通知: outTradeNo=${msg.OutTradeNo}`)
}
private async handleRefundNotify(msg: any) {
const outTradeNo = msg.MchOrderId || msg.MchOrderNo
if (!outTradeNo) return
const order = await this.orderModel.findOne({ outTradeNo }).exec()
if (!order) return
order.status = 'refunded'
order.refundAmount = msg.RefundFee || order.amount
order.refundedAt = new Date()
await order.save()
this.logger.log(`[vp-callback] 订单已退款: ${outTradeNo}`)
}
/** 查询本地订单状态(前端轮询) */
@UseGuards(JwtAuthGuard)
@Get('check/:outTradeNo')
async checkOrder(@Param('outTradeNo') outTradeNo: string, @CurrentUser('userId') userId: string) {
const order = await this.orderModel.findOne({ outTradeNo, userId }).exec()
if (!order) throw new HttpException('订单不存在', HttpStatus.NOT_FOUND)
return { status: order.status, type: order.type, paidAt: order.paidAt }
}
}
@@ -0,0 +1,22 @@
import { Module } from '@nestjs/common'
import { MongooseModule } from '@nestjs/mongoose'
import { VirtualPaymentController } from './virtual-payment.controller'
import { VirtualPaymentService } from './virtual-payment.service'
import { User, UserSchema } from '../user/user.schema'
import { PaymentOrder, PaymentOrderSchema } from '../payment/payment-order.schema'
import { PricingModule } from '../schemas/pricing.module'
import { UserModule } from '../user/user.module'
@Module({
imports: [
MongooseModule.forFeature([
{ name: User.name, schema: UserSchema },
{ name: PaymentOrder.name, schema: PaymentOrderSchema },
]),
PricingModule,
UserModule,
],
controllers: [VirtualPaymentController],
providers: [VirtualPaymentService],
})
export class VirtualPaymentModule {}
@@ -0,0 +1,79 @@
import { Injectable, Logger, InternalServerErrorException } from '@nestjs/common'
import * as crypto from 'crypto'
import axios from 'axios'
const WX_APPID = requireEnv('WX_APPID')
const WX_SECRET = requireEnv('WX_SECRET')
const VP_APPKEY = requireEnv('VP_APPKEY')
const VP_APPKEY_SANDBOX = requireEnv('VP_APPKEY_SANDBOX')
const VP_OFFER_ID = requireEnv('VP_OFFER_ID')
function requireEnv(name: string): string {
const val = process.env[name]
if (!val) throw new InternalServerErrorException(`环境变量 ${name} 未配置`)
return val
}
@Injectable()
export class VirtualPaymentService {
private readonly logger = new Logger(VirtualPaymentService.name)
/** 计算支付签名 pay_sig */
computePaySig(uri: string, postBody: string, env: number): string {
const appKey = env === 1 ? VP_APPKEY_SANDBOX : VP_APPKEY
const data = `${uri}&${postBody}`
return crypto.createHmac('sha256', appKey).update(data).digest('hex')
}
/** 通过 wx.login code 换取 session_key 并计算用户态签名 */
async exchangeCodeAndSign(code: string, signData: string): Promise<{ openid: string; signature: string }> {
const res = await axios.get('https://api.weixin.qq.com/sns/jscode2session', {
params: { appid: WX_APPID, secret: WX_SECRET, js_code: code, grant_type: 'authorization_code' },
timeout: 10000,
})
if (res.data.errcode) {
throw new Error(`code2session 失败: ${res.data.errmsg}`)
}
const { openid, session_key } = res.data
if (!session_key) {
throw new Error('未获取到 session_key')
}
const signature = crypto.createHmac('sha256', session_key).update(signData).digest('hex')
return { openid, signature }
}
/** 构建 signData JSON 字符串(与 wx.requestVirtualPayment 要求的格式一致) */
buildSignData(outTradeNo: string, openid: string, totalFee: number, userIp: string, env: number, mode: string, buyQuantity?: number): string {
const base = {
offerId: VP_OFFER_ID,
env,
outTradeNo,
attach: outTradeNo,
currencyType: 'CNY' as const,
platform: 'android' as const,
zoneId: '',
}
if (mode === 'short_series_coin') {
// 代币充值
return JSON.stringify({
...base,
buyQuantity: buyQuantity || 1,
})
}
// short_series_goods — 道具直购
return JSON.stringify({
...base,
productId: openid,
goodsPrice: totalFee,
})
}
getOfferId(): string { return VP_OFFER_ID }
/** 验证消息推送签名(可选,依赖配置的 Token) */
verifyPushSignature(signature: string, timestamp: string, nonce: string, token: string): boolean {
const arr = [token, timestamp, nonce].sort()
const sha1 = crypto.createHash('sha1').update(arr.join('')).digest('hex')
return sha1 === signature
}
}
+2 -2
View File
@@ -162,14 +162,14 @@
- [x] 面经贡献系统 + 公司题库 - [x] 面经贡献系统 + 公司题库
- [x] 每日一题(API 读取) - [x] 每日一题(API 读取)
- [x] 手机/邮箱/密码/微信登录 - [x] 手机/邮箱/密码/微信登录
- [x] 会员系统(¥19.9 成长版) - [x] 会员系统(¥19 成长版)
- [x] 微信支付对接(Native + JSAPI - [x] 微信支付对接(Native + JSAPI
- [x] 公司真题库(用户贡献驱动) - [x] 公司真题库(用户贡献驱动)
- [x] **面试复盘(音频 ASR + AI 评析 + 口语分析)** - [x] **面试复盘(音频 ASR + AI 评析 + 口语分析)**
### P1(待实现) ### P1(待实现)
- [ ] 每日一题定时推送 - [ ] 每日一题定时推送
- [ ] 冲刺版 ¥49.9/月 - [ ] 冲刺版 ¥49/月
- [ ] AI 岗位专属题库 - [ ] AI 岗位专属题库
- [ ] 连续打卡激励(7 天解锁高级报告) - [ ] 连续打卡激励(7 天解锁高级报告)
- [ ] 生产环境部署 - [ ] 生产环境部署
+3 -3
View File
@@ -58,7 +58,7 @@
}, },
"plans": { "plans": {
"growth": { "growth": {
"price": 1990, "price": 1900,
"durationDays": 30, "durationDays": 30,
"credits": { "credits": {
"interview": 999, "interview": 999,
@@ -76,7 +76,7 @@
] ]
}, },
"sprint": { "sprint": {
"price": 4990, "price": 4900,
"durationDays": 30, "durationDays": 30,
"credits": { "credits": {
"interview": 999, "interview": 999,
@@ -267,7 +267,7 @@ Puppeteer PDF 生成 (`resume-pdf.service.ts`)
│ 首次面试免费 [✓] │ │ 首次面试免费 [✓] │
│ │ │ │
│ ─── 成长版 ─── │ │ ─── 成长版 ─── │
│ 价格 ¥ [ 19.9 ] /月 │ │ 价格 ¥ [ 19 ] /月
│ 面试额度 [ 999 ] 次 │ │ 面试额度 [ 999 ] 次 │
│ 优化额度 [ 20 ] 次 │ │ 优化额度 [ 20 ] 次 │
│ 下载额度 [ 10 ] 次 │ │ 下载额度 [ 10 ] 次 │
+8 -8
View File
@@ -65,14 +65,14 @@
| 版本 | 价格 | 核心权益 | 定位 | | 版本 | 价格 | 核心权益 | 定位 |
|------|------|------|------| |------|------|------|------|
| 免费版 | ¥0 | 日 2 次基础面试(通用题库,5 轮/次) | 引流 | | 免费版 | ¥0 | 日 2 次基础面试(通用题库,5 轮/次) | 引流 |
| **成长版** | **¥19.9/月** | 无限面试 + 高级报告 + 进步轨迹 + 真题库 | **主力** | | **成长版** | **¥19/月** | 无限面试 + 高级报告 + 进步轨迹 + 真题库 | **主力** |
> 冲刺版 ¥49.9/月(含真人导师点评 + 简历精修)待实现 > 冲刺版 ¥49/月(含真人导师点评 + 简历精修)待实现
### 3.2 收入来源 ### 3.2 收入来源
``` ```
C 端订阅收入(基本盘:¥19.9 × 付费用户数) C 端订阅收入(基本盘:¥19 × 付费用户数)
├── B 端合作(高校就业办/求职机构) ├── B 端合作(高校就业办/求职机构)
├── 内容变现(面经课程) ├── 内容变现(面经课程)
@@ -83,9 +83,9 @@ C 端订阅收入(基本盘:¥19.9 × 付费用户数)
| 阶段 | C 端 | B 端 | 月收入 | | 阶段 | C 端 | B 端 | 月收入 |
|------|------|------|--------| |------|------|------|--------|
| MVP 上线(6-8月) | 200 付费 × ¥19.9 | 0 | ¥3,980 | | MVP 上线(6-8月) | 200 付费 × ¥19 | 0 | ¥3,800 |
| 秋招旺季(9-11月) | 1000 付费 × ¥19.9 | 2 高校 ¥5000 | ¥29,900 | | 秋招旺季(9-11月) | 1000 付费 × ¥19 | 2 高校 ¥5000 | ¥24,000 |
| 稳定运营(次年) | 2000 付费 × ¥19.9 | 5 机构 + 企业 | ¥60,000+ | | 稳定运营(次年) | 2000 付费 × ¥19 | 5 机构 + 企业 | ¥48,000+ |
--- ---
@@ -103,14 +103,14 @@ C 端订阅收入(基本盘:¥19.9 × 付费用户数)
| 面经贡献系统 + 公司题库 | ✅ 完成 | | 面经贡献系统 + 公司题库 | ✅ 完成 |
| 每日一题(API) | ✅ 完成 | | 每日一题(API) | ✅ 完成 |
| 简历诊断 + 优化 | ✅ 完成 | | 简历诊断 + 优化 | ✅ 完成 |
| 会员系统(成长版 ¥19.9/月) | ✅ 完成 | | 会员系统(成长版 ¥19/月) | ✅ 完成 |
| 微信支付(Native + JSAPI | ✅ 完成 | | 微信支付(Native + JSAPI | ✅ 完成 |
### 待实现 ### 待实现
| 功能 | 计划 | | 功能 | 计划 |
|------|------| |------|------|
| 每日一题定时推送(微信订阅消息) | Phase 1 | | 每日一题定时推送(微信订阅消息) | Phase 1 |
| 冲刺版 ¥49.9/月 | Phase 1.5 | | 冲刺版 ¥49/月 | Phase 1.5 |
| 微信登录真实 appid 联调 | Phase 1 | | 微信登录真实 appid 联调 | Phase 1 |
| 生产环境部署 | Phase 1 | | 生产环境部署 | Phase 1 |
| AI 岗位专属题库 | Phase 2 | | AI 岗位专属题库 | Phase 2 |
+5 -4
View File
@@ -1,8 +1,8 @@
# 职引项目 · 状态报告 v4.8 # 职引项目 · 状态报告 v4.9
> **项目版本**: v4.8 > **项目版本**: v4.9
> **更新时间**: 2026-06-21 > **更新时间**: 2026-06-22
> **项目状态**: ✅ SEO 优化 + 微信分享全面开启 + 全量部署 > **项目状态**: ✅ Mongoose 8 兼容修复 + v1.0.17 发布
--- ---
@@ -224,6 +224,7 @@
| 日期 | 版本 | 变更内容 | 操作者 | | 日期 | 版本 | 变更内容 | 操作者 |
|------|------|----------|--------| |------|------|----------|--------|
| 2026-06-22 | **v4.9** | **Mongoose 8 兼容修复**pre-save hook 回调→async);v1.0.17 tag 发布;测试账号 test@yzrcloud.cn 重建 | AI |
| 2026-06-21 | **v4.8** | **SEO 全量优化**canonical URL、robots.txt、sitemap.xml、结构化数据);**微信分享全面开启**(13 个页面 onShareAppMessage + onShareTimeline);**版本号自动注入**Vite define __APP_VERSION__);**导航栏/Tab标题关键词优化**;manifest 描述更新;页面描述统一增强 | AI | | 2026-06-21 | **v4.8** | **SEO 全量优化**canonical URL、robots.txt、sitemap.xml、结构化数据);**微信分享全面开启**(13 个页面 onShareAppMessage + onShareTimeline);**版本号自动注入**Vite define __APP_VERSION__);**导航栏/Tab标题关键词优化**;manifest 描述更新;页面描述统一增强 | AI |
| 2026-06-21 | v4.7 | 按量购买引力值体系重构(¥5/份取代月订阅);member.vue 完全重写;微信小程序剪贴板购买链路;客服按钮;管理后台字段全面完善;代码清理;测试数据清理;后端/H5/小程序全量部署上线 | AI | | 2026-06-21 | v4.7 | 按量购买引力值体系重构(¥5/份取代月订阅);member.vue 完全重写;微信小程序剪贴板购买链路;客服按钮;管理后台字段全面完善;代码清理;测试数据清理;后端/H5/小程序全量部署上线 | AI |
| 2026-06-19 | v4.6 | 引力值体系统一:VIP 取消无限面试改为月度引力值消耗;管理后台全面完善(搜索/筛选/分页/CRUD/分析tab/岗位描述字段) | AI | | 2026-06-19 | v4.6 | 引力值体系统一:VIP 取消无限面试改为月度引力值消耗;管理后台全面完善(搜索/筛选/分页/CRUD/分析tab/岗位描述字段) | AI |
+2 -2
View File
@@ -28,7 +28,7 @@ Phase 3: 商业化 + B 端(D90+)→ 秋招爆发
## 二、Phase 0: 战略升级(✅ 已完成) ## 二、Phase 0: 战略升级(✅ 已完成)
**已完成**: **已完成**:
- [x] 定价重构:免费 + ¥19.9/月 两段式 - [x] 定价重构:免费 + ¥19/月 两段式
- [x] 三层壁垒设计(数据飞轮 + 留存入围 + 合规信任) - [x] 三层壁垒设计(数据飞轮 + 留存入围 + 合规信任)
- [x] 收入来源多元化策略 - [x] 收入来源多元化策略
- [x] 文档体系全面更新 - [x] 文档体系全面更新
@@ -54,7 +54,7 @@ Phase 3: 商业化 + B 端(D90+)→ 秋招爆发
### 3.3 会员系统重构 ### 3.3 会员系统重构
| 功能 | 描述 | 状态 | | 功能 | 描述 | 状态 |
|------|------|------| |------|------|------|
| 定价更新 | ¥19.9/月 成长版 | ✅ 完成 | | 定价更新 | ¥19/月 成长版 | ✅ 完成 |
| 会员权益对比 | 三版对比展示 | ✅ 完成 | | 会员权益对比 | 三版对比展示 | ✅ 完成 |
| 微信支付对接 | Native + JSAPI 支付 | ✅ 完成 | | 微信支付对接 | Native + JSAPI 支付 | ✅ 完成 |
+23 -2
View File
@@ -1,15 +1,24 @@
<script setup lang="ts"> <script setup lang="ts">
import { onLaunch } from '@dcloudio/uni-app' import { onLaunch, onShow } from '@dcloudio/uni-app'
onLaunch(() => { onLaunch((options) => {
// #ifdef MP-WEIXIN // #ifdef MP-WEIXIN
initPrivacy() initPrivacy()
handleLaunchParams(options?.query)
// #endif // #endif
// #ifdef H5 // #ifdef H5
handleH5UrlParams() handleH5UrlParams()
// #endif // #endif
}) })
// #ifdef MP-WEIXIN
onShow((options) => {
if (options?.query) {
handleLaunchParams(options.query)
}
})
// #endif
// #ifdef H5 // #ifdef H5
function handleH5UrlParams() { function handleH5UrlParams() {
const params = new URLSearchParams(window.location.search) const params = new URLSearchParams(window.location.search)
@@ -28,6 +37,18 @@ function handleH5UrlParams() {
// #endif // #endif
// #ifdef MP-WEIXIN // #ifdef MP-WEIXIN
function handleLaunchParams(query?: Record<string, string>) {
if (!query) return
const token = query.token
if (token) {
uni.setStorageSync('token', token)
}
const shareCode = query.share || query.shareCode
if (shareCode) {
uni.setStorageSync('shareCode', shareCode)
}
}
function initPrivacy() { function initPrivacy() {
if (wx.onNeedPrivacyAuthorization) { if (wx.onNeedPrivacyAuthorization) {
wx.onNeedPrivacyAuthorization((resolve) => { wx.onNeedPrivacyAuthorization((resolve) => {
+73 -25
View File
@@ -73,7 +73,7 @@
<!-- 用户 --> <!-- 用户 -->
<view v-if="tab === 'users'" class="section"> <view v-if="tab === 'users'" class="section">
<view class="search-bar"> <view class="search-bar">
<input v-model="userKeyword" placeholder="搜索手机号/昵称" class="search-input" @confirm="loadUsers" /> <input v-model="userKeyword" placeholder="搜索手机号/邮箱/昵称/ID" class="search-input" @confirm="loadUsers" />
<button class="search-btn" @click="loadUsers">搜索</button> <button class="search-btn" @click="loadUsers">搜索</button>
</view> </view>
<view class="user-list" v-if="!usersLoading"> <view class="user-list" v-if="!usersLoading">
@@ -87,6 +87,9 @@
<text class="meta-tag email" v-if="u.email">{{ u.email }}</text> <text class="meta-tag email" v-if="u.email">{{ u.email }}</text>
<text class="meta-tag" v-if="u.wxOpenid">openid:{{ u.wxOpenid.slice(0,12) }}..</text> <text class="meta-tag" v-if="u.wxOpenid">openid:{{ u.wxOpenid.slice(0,12) }}..</text>
</view> </view>
<view class="user-meta-row">
<text class="meta-tag id-tag" @click="copyId(u._id)">ID: {{ u._id }}</text>
</view>
<view class="user-meta-row"> <view class="user-meta-row">
<text class="meta-tag">引力:{{ u.gravity ?? 0 }}</text> <text class="meta-tag">引力:{{ u.gravity ?? 0 }}</text>
<text class="meta-tag">面试:{{ u.interviewCount ?? 0 }}</text> <text class="meta-tag">面试:{{ u.interviewCount ?? 0 }}</text>
@@ -94,10 +97,15 @@
<text class="meta-tag share" v-if="u.shareCredits > 0">分享:{{ u.shareCredits }}</text> <text class="meta-tag share" v-if="u.shareCredits > 0">分享:{{ u.shareCredits }}</text>
</view> </view>
<view class="user-meta-row time-row"> <view class="user-meta-row time-row">
<text class="time-label">注册:{{ u.createdAt?.slice(0,16).replace('T',' ') }}</text> <text class="time-label">注册:{{ toBeijing(u.createdAt) }}</text>
<text class="time-label" v-if="u.vipExpireAt">到期:{{ u.vipExpireAt?.slice(0,10) }}</text> <text class="time-label" v-if="u.vipExpireAt">到期:{{ u.vipExpireAt?.slice(0,10) }}</text>
<text class="time-label" v-if="u.sprintExpireAt">冲刺到期:{{ u.sprintExpireAt?.slice(0,10) }}</text> <text class="time-label" v-if="u.sprintExpireAt">冲刺到期:{{ u.sprintExpireAt?.slice(0,10) }}</text>
</view> </view>
<view class="user-meta-row time-row" v-if="u.lastLoginAt">
<text class="time-label">最后登录:{{ toBeijing(u.lastLoginAt) }}</text>
<text class="meta-tag" v-if="u.lastLoginIp">IP:{{ u.lastLoginIp }}</text>
<text class="meta-tag" v-if="u.lastLoginLocation">{{ u.lastLoginLocation }}</text>
</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>
<text class="user-action-btn credit" @click="openCreditModal(u)">调整额度</text> <text class="user-action-btn credit" @click="openCreditModal(u)">调整额度</text>
@@ -130,8 +138,8 @@
<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>
<view class="iv-meta"> <view class="iv-meta">
<text class="time-label">开始:{{ iv.createdAt?.slice(0,16).replace('T',' ') }}</text> <text class="time-label">开始:{{ toBeijing(iv.createdAt) }}</text>
<text class="time-label" v-if="iv.updatedAt && iv.updatedAt !== iv.createdAt">更新:{{ iv.updatedAt?.slice(0,16).replace('T',' ') }}</text> <text class="time-label" v-if="iv.updatedAt && iv.updatedAt !== iv.createdAt">更新:{{ toBeijing(iv.updatedAt) }}</text>
</view> </view>
<text class="iv-summary" v-if="iv.summary">{{ iv.summary.slice(0,60) }}{{ iv.summary.length > 60 ? '...' : '' }}</text> <text class="iv-summary" v-if="iv.summary">{{ iv.summary.slice(0,60) }}{{ iv.summary.length > 60 ? '...' : '' }}</text>
</view> </view>
@@ -160,8 +168,8 @@
<text class="resume-tag paid" v-if="r.paidDownload">付费下载</text> <text class="resume-tag paid" v-if="r.paidDownload">付费下载</text>
</view> </view>
<view class="resume-meta time-row"> <view class="resume-meta time-row">
<text class="time-label">创建:{{ r.createdAt?.slice(0,16).replace('T',' ') }}</text> <text class="time-label">创建:{{ toBeijing(r.createdAt) }}</text>
<text class="time-label" v-if="r.updatedAt && r.updatedAt !== r.createdAt">更新:{{ r.updatedAt?.slice(0,16).replace('T',' ') }}</text> <text class="time-label" v-if="r.updatedAt && r.updatedAt !== r.createdAt">更新:{{ toBeijing(r.updatedAt) }}</text>
</view> </view>
<view class="resume-actions"> <view class="resume-actions">
<text class="admin-action-btn del" @click="deleteResume(r._id, r.title)">删除</text> <text class="admin-action-btn del" @click="deleteResume(r._id, r.title)">删除</text>
@@ -200,14 +208,14 @@
<text class="meta-tag">渠道:{{ o.channel || '--' }}</text> <text class="meta-tag">渠道:{{ o.channel || '--' }}</text>
</view> </view>
<view class="order-meta-row time-row"> <view class="order-meta-row time-row">
<text class="time-label">创建:{{ o.createdAt?.slice(0,16).replace('T',' ') }}</text> <text class="time-label">创建:{{ toBeijing(o.createdAt) }}</text>
<text class="time-label" v-if="o.paidAt">支付:{{ o.paidAt?.slice(0,16).replace('T',' ') }}</text> <text class="time-label" v-if="o.paidAt">支付:{{ toBeijing(o.paidAt) }}</text>
</view> </view>
<view class="order-meta-row" v-if="o.wxTransactionId"> <view class="order-meta-row" v-if="o.wxTransactionId">
<text class="time-label">微信单号:{{ o.wxTransactionId }}</text> <text class="time-label">微信单号:{{ o.wxTransactionId }}</text>
</view> </view>
<view class="order-meta-row" v-if="o.status === 'refunded'"> <view class="order-meta-row" v-if="o.status === 'refunded'">
<text class="time-label refund-label">退款:¥{{ (o.refundAmount/100).toFixed(1) }} {{ o.refundedAt?.slice(0,16).replace('T',' ') }}</text> <text class="time-label refund-label">退款:¥{{ (o.refundAmount/100).toFixed(1) }} {{ toBeijing(o.refundedAt) }}</text>
<text class="time-label" v-if="o.refundReason">原因:{{ o.refundReason }}</text> <text class="time-label" v-if="o.refundReason">原因:{{ o.refundReason }}</text>
</view> </view>
<view class="order-actions-bar"> <view class="order-actions-bar">
@@ -297,6 +305,8 @@
<text>每月引力值</text> <text>每月引力值</text>
<input class="cfg-input" type="digit" v-model.number="pricing.plans.sprint.gravityPerMonth" /> <input class="cfg-input" type="digit" v-model.number="pricing.plans.sprint.gravityPerMonth" />
</view> </view>
<view class="cfg-row">
<text>面试额度/</text>
<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">
@@ -346,7 +356,7 @@
<text class="share-credited">有效 {{ r.creditedCount }}</text> <text class="share-credited">有效 {{ r.creditedCount }}</text>
</view> </view>
<view class="share-meta-row time-row"> <view class="share-meta-row time-row">
<text class="time-label">创建:{{ r.createdAt?.slice(0,16).replace('T',' ') }}</text> <text class="time-label">创建:{{ toBeijing(r.createdAt) }}</text>
</view> </view>
</view> </view>
</view> </view>
@@ -365,8 +375,8 @@
<text class="meta-tag" :class="v.credited ? 'badge-done' : 'badge-pend'">{{ v.credited ? '已积分' : '未积分' }}</text> <text class="meta-tag" :class="v.credited ? 'badge-done' : 'badge-pend'">{{ v.credited ? '已积分' : '未积分' }}</text>
</view> </view>
<view class="share-meta-row time-row"> <view class="share-meta-row time-row">
<text class="time-label">访问:{{ v.createdAt?.slice(0,16).replace('T',' ') }}</text> <text class="time-label">访问:{{ toBeijing(v.createdAt) }}</text>
<text class="time-label" v-if="v.creditedAt">积分:{{ v.creditedAt?.slice(0,16).replace('T',' ') }}</text> <text class="time-label" v-if="v.creditedAt">积分:{{ toBeijing(v.creditedAt) }}</text>
</view> </view>
</view> </view>
</view> </view>
@@ -488,32 +498,64 @@
</view> </view>
<view class="section-label">当前管理员</view> <view class="section-label">当前管理员</view>
<view class="user-list"> <view class="user-list">
<view class="admin-row" v-for="a in adminList" :key="a._id"> <view class="user-row" v-for="a in adminList" :key="a._id">
<text class="admin-phone">{{ a.phone || '--' }}</text> <view class="user-main">
<text class="admin-name">{{ a.nickname || '--' }}</text> <text class="user-phone">{{ a.phone || '--' }}</text>
<text class="admin-email" v-if="a.email">{{ a.email }}</text> <text class="user-name">{{ a.nickname || '--' }}</text>
<text class="user-badge-role">管理</text>
<text class="admin-badge" v-if="a.isSystemAdmin">系统</text> <text class="admin-badge" v-if="a.isSystemAdmin">系统</text>
<text class="time-label" style="margin-left:auto">设置:{{ a.createdAt?.slice(0,10) }}</text> </view>
<view class="user-meta-row">
<text class="meta-tag email" v-if="a.email">{{ a.email }}</text>
<text class="meta-tag" v-if="a.wxOpenid">openid:{{ a.wxOpenid.slice(0,12) }}..</text>
</view>
<view class="user-meta-row">
<text class="meta-tag id-tag" @click="copyId(a._id)">ID: {{ a._id }}</text>
</view>
<view class="user-meta-row">
<text class="meta-tag">引力:{{ a.gravity ?? 0 }}</text>
<text class="user-plan" :class="{ vip: a.plan === 'growth' || a.plan === 'sprint' }">{{ a.plan === 'growth' || a.plan === 'sprint' ? a.plan==='sprint'?'冲刺':'会员' : '免费' }}</text>
</view>
<view class="user-meta-row time-row">
<text class="time-label">设置:{{ toBeijing(a.createdAt) }}</text>
</view>
</view> </view>
<text class="empty-text" v-if="adminList.length === 0">暂无管理员</text> <text class="empty-text" v-if="adminList.length === 0">暂无管理员</text>
</view> </view>
<view class="section-label" v-if="searchResult">搜索结果</view> <view class="section-label" v-if="searchResult" style="margin-top:24rpx">搜索结果</view>
<view class="user-list" v-if="searchResult"> <view class="user-list" v-if="searchResult">
<view class="admin-row"> <view class="user-row">
<text class="admin-phone">{{ searchResult.phone || '--' }}</text> <view class="user-main">
<text class="admin-name">{{ searchResult.nickname || '--' }}</text> <text class="user-phone">{{ searchResult.phone || '--' }}</text>
<text class="admin-email" v-if="searchResult.email">{{ searchResult.email }}</text> <text class="user-name">{{ searchResult.nickname || '--' }}</text>
<text class="user-badge-role" v-if="searchResult.role === 'admin'">管理</text>
</view>
<view class="user-meta-row">
<text class="meta-tag email" v-if="searchResult.email">{{ searchResult.email }}</text>
<text class="meta-tag" v-if="searchResult.wxOpenid">openid:{{ searchResult.wxOpenid.slice(0,12) }}..</text>
</view>
<view class="user-meta-row">
<text class="meta-tag id-tag" @click="copyId(searchResult._id)">ID: {{ searchResult._id }}</text>
</view>
<view class="user-meta-row">
<text class="meta-tag">引力:{{ searchResult.gravity ?? 0 }}</text>
<text class="user-plan" :class="{ vip: searchResult.plan === 'growth' || searchResult.plan === 'sprint' }">{{ searchResult.plan === 'growth' || searchResult.plan === 'sprint' ? searchResult.plan==='sprint'?'冲刺':'会员' : '免费' }}</text>
</view>
<view class="user-actions" style="margin-top:8rpx">
<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>
</view>
</template> </template>
<script setup> <script setup>
import { ref, computed, onMounted, reactive } from 'vue' import { ref, computed, onMounted, reactive } from 'vue'
import { api, API_ENDPOINTS } from '../../config' import { api, API_ENDPOINTS } from '../../config'
import { toBeijing } from '../../utils/format'
const verified = ref(false) const verified = ref(false)
const adminName = ref('') const adminName = ref('')
@@ -703,6 +745,7 @@ const switchTab = (t) => {
if (t === 'pricing') loadPricing() if (t === 'pricing') loadPricing()
if (t === 'orders') loadOrders() if (t === 'orders') loadOrders()
if (t === 'analysis') loadAnalysis() if (t === 'analysis') loadAnalysis()
if (t === 'share') loadShareRecords()
} }
const loadUsers = async () => { const loadUsers = async () => {
@@ -1028,6 +1071,13 @@ const doAdjustCredits = async () => {
} catch { uni.showToast({ title: '调整失败', icon: 'none' }) } } catch { uni.showToast({ title: '调整失败', icon: 'none' }) }
} }
const copyId = (id) => {
uni.setClipboardData({
data: id,
success: () => uni.showToast({ title: 'ID 已复制', icon: 'success' }),
})
}
onMounted(() => { doVerify() }) onMounted(() => { doVerify() })
</script> </script>
@@ -1080,9 +1130,6 @@ onMounted(() => { doVerify() })
.iv-tag.score { background: #EEF2FF; color: var(--color-primary); } .iv-tag.score { background: #EEF2FF; color: var(--color-primary); }
.iv-tag.filler { background: #FFF7ED; color: #D97706; } .iv-tag.filler { background: #FFF7ED; color: #D97706; }
.section-label { font-size: 24rpx; font-weight: 600; color: var(--color-text); margin-bottom: 12rpx; margin-top: 12rpx; } .section-label { font-size: 24rpx; font-weight: 600; color: var(--color-text); margin-bottom: 12rpx; margin-top: 12rpx; }
.admin-row { background: #FFF; padding: 20rpx; border-radius: var(--radius-sm); margin-bottom: 8rpx; display: flex; flex-wrap: wrap; gap: 8rpx; align-items: center; }
.admin-phone { font-size: 24rpx; font-weight: 600; color: var(--color-text); }
.admin-name { font-size: 22rpx; color: var(--color-text-secondary); flex: 1; }
.admin-set-btn { font-size: 22rpx; color: var(--color-primary); padding: 4rpx 16rpx; border: 2rpx solid var(--color-primary); border-radius: var(--radius-round); } .admin-set-btn { font-size: 22rpx; color: var(--color-primary); padding: 4rpx 16rpx; border: 2rpx solid var(--color-primary); border-radius: var(--radius-round); }
.admin-set-btn.done { color: var(--color-success); border-color: var(--color-success); } .admin-set-btn.done { color: var(--color-success); border-color: var(--color-success); }
.admin-badge { font-size: 18rpx; background: var(--color-primary); color: #FFF; padding: 2rpx 10rpx; border-radius: var(--radius-round); } .admin-badge { font-size: 18rpx; background: var(--color-primary); color: #FFF; padding: 2rpx 10rpx; border-radius: var(--radius-round); }
@@ -1162,6 +1209,7 @@ onMounted(() => { doVerify() })
.meta-tag { font-size: 18rpx; background: #F3F4F6; color: var(--color-text-tertiary); padding: 2rpx 10rpx; border-radius: var(--radius-round); } .meta-tag { font-size: 18rpx; background: #F3F4F6; color: var(--color-text-tertiary); padding: 2rpx 10rpx; border-radius: var(--radius-round); }
.meta-tag.email { background: #EEF2FF; color: var(--color-primary); } .meta-tag.email { background: #EEF2FF; color: var(--color-primary); }
.meta-tag.share { background: #FFF7ED; color: #D97706; } .meta-tag.share { background: #FFF7ED; color: #D97706; }
.meta-tag.id-tag { background: #F5F3FF; color: #7C3AED; font-family: monospace; font-size: 16rpx; }
.meta-tag.badge-done { background: #ECFDF5; color: #059669; } .meta-tag.badge-done { background: #ECFDF5; color: #059669; }
.meta-tag.badge-pend { background: #FEF3C7; color: #D97706; } .meta-tag.badge-pend { background: #FEF3C7; color: #D97706; }
.time-row { display: flex; flex-wrap: wrap; gap: 12rpx; } .time-row { display: flex; flex-wrap: wrap; gap: 12rpx; }
+408 -113
View File
@@ -1,32 +1,35 @@
<template> <template>
<!-- #ifdef MP-WEIXIN -->
<view class="page fade-in"> <view class="page fade-in">
<view class="placeholder-wrap"> <!-- 状态栏当前方案 + 引力值 -->
<text class="placeholder-icon"></text> <view class="status-bar">
<text class="placeholder-text">功能已整合到各模块</text> <view class="status-left">
<text class="placeholder-hint">请返回使用引力值充值功能</text> <text class="status-label">当前方案</text>
<text class="placeholder-back" @click="goBack">返回首页</text> <text class="status-plan">{{ currentPlanName || '免费版' }}</text>
</view> </view>
<view class="status-right">
<text class="grav-label"> 引力值</text>
<text class="grav-num">{{ gravity }}</text>
</view> </view>
<!-- #endif -->
<!-- #ifdef H5 -->
<view class="page fade-in">
<view class="hero">
<text class="hero-icon"></text>
<text class="hero-title">补充引力值</text>
<text class="hero-desc">购买后可获得相应引力值用于面试简历优化下载</text>
</view> </view>
<view class="product-card"> <!-- 未登录提示 -->
<view class="qty-section"> <view class="login-bar" v-if="!isLoggedIn">
<text class="section-label">购买数量</text> <text class="login-text">登录后可购买引力值查看套餐</text>
<text class="login-btn" @click="goLogin">去登录</text>
</view>
<!-- 购买引力值最上面登录后可见 -->
<view class="section" v-if="isLoggedIn">
<text class="section-title"> 补充引力值</text>
<view class="buy-card">
<view class="qty-row">
<text class="qty-label">购买数量</text>
<view class="qty-controls"> <view class="qty-controls">
<text class="qty-btn" :class="{ disabled: buyQty <= 1 }" @click="changeQty(-1)"></text> <text class="qty-btn" :class="{ disabled: buyQty <= 1 }" @click="buyQty = Math.max(1, buyQty - 1)"></text>
<input class="qty-input" type="number" v-model.number="buyQty" min="1" max="99" @blur="clampQty" /> <input class="qty-input" type="number" v-model.number="buyQty" min="1" max="99" @blur="buyQty = Math.max(1, Math.min(99, buyQty || 1))" />
<text class="qty-btn" :class="{ disabled: buyQty >= 99 }" @click="changeQty(1)">+</text> <text class="qty-btn" :class="{ disabled: buyQty >= 99 }" @click="buyQty = Math.min(99, buyQty + 1)">+</text>
</view> </view>
</view> </view>
<view class="summary"> <view class="summary">
<view class="summary-row"> <view class="summary-row">
<text class="summary-label">单价</text> <text class="summary-label">单价</text>
@@ -34,115 +37,274 @@
</view> </view>
<view class="summary-row"> <view class="summary-row">
<text class="summary-label">可得引力值</text> <text class="summary-label">可得引力值</text>
<text class="summary-val highlight">{{ buyQty * gravityPerUnit }} 引力值</text> <text class="summary-val highlight">{{ buyQty * gravityPerUnit }} </text>
</view> </view>
<view class="summary-row total"> <view class="summary-row total">
<text class="summary-label">合计</text> <text class="summary-label">合计</text>
<text class="summary-val total-price">¥{{ (buyQty * unitPrice / 100).toFixed(2) }}</text> <text class="summary-val total-price">¥{{ (buyQty * unitPrice / 100).toFixed(2) }}</text>
</view> </view>
</view> </view>
<button class="buy-btn" :disabled="payLoading" @click="startGravityPay">
<button class="buy-btn" :disabled="payLoading" @click="startPay"> {{ payLoading ? '处理中...' : '立即购买' }}
<text v-if="!payLoading">立即购买</text>
<text v-else>处理中...</text>
</button> </button>
</view> </view>
</view>
<!-- 套餐对比 -->
<view class="section">
<text class="section-title">📋 套餐对比</text>
<view class="plan-list">
<view v-for="p in planList" :key="p.id" class="plan-card"
:class="{ current: p.id === plan, popular: p.popular }">
<view class="plan-header">
<text class="plan-name">{{ p.name }}</text>
<view class="plan-price">
<text class="price-num">{{ p.priceDisplay }}</text>
</view>
<view class="plan-badge" v-if="p.id === plan">
<text>当前方案</text>
</view>
</view>
<view class="plan-features">
<text class="feature" v-for="(f, i) in p.features" :key="i"> {{ f }}</text>
</view>
<view class="plan-footer" v-if="p.id !== 'free'">
<view class="plan-action owned" v-if="p.id === plan"> 已开通</view>
<view class="plan-action" v-else-if="!isLoggedIn" @click="goLogin">登录后开通</view>
<view class="plan-action" v-else-if="plan === 'free'" @click="startPlanPay(p.id)">
{{ p.priceDisplay }} 开通
</view>
<view class="plan-action" v-else @click="startPlanPay(p.id)">
升级至{{ p.name }}
</view>
</view>
</view>
</view>
</view>
<!-- 支付弹窗 --> <!-- 支付弹窗 -->
<view class="modal-overlay" v-if="showPayModal" @click="cancelPay"> <view class="modal-overlay" v-if="showPayModal" @click="cancelPay">
<view class="modal-content" @click.stop> <view class="modal-content" @click.stop>
<template v-if="payLoading"> <template v-if="payLoading">
<text class="modal-title">正在创建订单...</text> <text class="modal-title">正在创建支付...</text>
</template> </template>
<template v-else-if="payCodeUrl"> <template v-else-if="!isMp && payCodeUrl">
<text class="modal-title">微信扫码支付</text> <text class="modal-title">微信扫码支付</text>
<image class="qrcode" :src="'https://api.qrserver.com/v1/create-qr-code/?size=300x300&data=' + encodeURIComponent(payCodeUrl)" mode="widthFix" /> <canvas canvas-id="payQrcode" class="qr-canvas"></canvas>
<text class="modal-hint">使用微信扫描二维码完成支付</text> <text class="modal-hint">请用微信扫码完成支付</text>
<text class="modal-close" @click="cancelPay">取消支付</text> <text class="modal-close" @click="cancelPay">取消支付</text>
</template> </template>
<template v-else-if="paySuccess"> <template v-else-if="vpStatus">
<text class="modal-title"> 支付成功</text> <text class="modal-title" :class="vpSuccess ? '' : 'pay-error'">{{ vpSuccess ? '✅ 支付成功' : '支付失败' }}</text>
<text class="modal-hint">引力值已到账返回继续使用吧</text> <text class="modal-hint">{{ vpStatusText }}</text>
<text class="modal-close" @click="cancelPay">关闭</text> <text class="modal-close" @click="cancelPay">关闭</text>
</template> </template>
<template v-else-if="payError"> <template v-if="payError && !vpStatus">
<text class="modal-title pay-error">支付失败</text> <text class="modal-title pay-error">支付异常</text>
<text class="modal-hint">{{ payError }}</text> <text class="modal-hint">{{ payError }}</text>
<text class="modal-close" @click="cancelPay">关闭</text> <text class="modal-close" @click="cancelPay">关闭</text>
</template> </template>
</view> </view>
</view> </view>
</view> </view>
<!-- #endif -->
</template> </template>
<script setup lang="ts"> <script setup>
import { ref, computed, onMounted } from 'vue' import { ref, onMounted } from 'vue'
// #ifdef MP-WEIXIN import { onLoad, onShow } from '@dcloudio/uni-app'
import { onShareAppMessage, onShareTimeline } from '@dcloudio/uni-app'
// #endif
import { api } from '../../config' import { api } from '../../config'
// #ifdef MP-WEIXIN const isLoggedIn = ref(false)
onShareAppMessage(() => ({ title: '职引 - 引力值购买 | AI模拟面试', path: '/pages/member/member' })) const isMp = ref(false)
onShareTimeline(() => ({ title: '职引 - 引力值购买 | AI模拟面试' })) const plan = ref('free')
// #endif const currentPlanName = ref('免费版')
const gravity = ref(0)
const planList = ref([])
const goBack = () => uni.switchTab({ url: '/pages/user/user' }) // 购买引力值
// #ifdef H5
const buyQty = ref(1) const buyQty = ref(1)
const unitPrice = ref(500) const unitPrice = ref(500)
const gravityPerUnit = ref(5) const gravityPerUnit = ref(5)
const payLoading = ref(false) const payLoading = ref(false)
// 支付弹窗
const showPayModal = ref(false) const showPayModal = ref(false)
const payCodeUrl = ref('') const payCodeUrl = ref('')
const paySuccess = ref(false)
const payError = ref('') const payError = ref('')
const currentOutTradeNo = ref('')
const payingPlan = ref('')
const paySuccess = ref(false)
const vpStatus = ref(false)
const vpSuccess = ref(false)
const vpStatusText = ref('')
onMounted(async () => { // 套餐特征后备值(API 取不到时使用)
const defaultFreeFeatures = ['AI 模拟面试 1 次(体验)', '基础面试报告', '通用题库随机出题', '简历优化(限 3 次免费)']
const defaultGrowthFeatures = ['免费版全部权益', 'AI 数字人面试无限次', '详细面试报告(四维评分)', '进步轨迹雷达图 + 打卡', '每日一题', '参考回答思路', '公司真题库']
const defaultSprintFeatures = ['成长版全部权益', 'AI 语音分析(语气词/语速检测)', '技能缺口分析报告', '公司真题库精选']
const token = () => uni.getStorageSync('token') || ''
const refreshState = async () => {
// #ifdef MP-WEIXIN
isMp.value = true
// #endif
const t = token()
isLoggedIn.value = !!t
// 1. 先拉套餐配置(公开接口,未登录也拉)
try { try {
const res = await uni.request({ url: api('/member/plans'), method: 'GET' }) const pres = await uni.request({ url: api('/member/plans'), method: 'GET' })
if (res.statusCode >= 200 && res.statusCode < 300 && res.data?.products) { if (pres.statusCode >= 200 && pres.statusCode < 300 && pres.data) {
const prod = res.data.products.interview const d = pres.data
if (prod) { if (d.products?.interview) {
unitPrice.value = prod.price || 500 unitPrice.value = d.products.interview.price || 500
gravityPerUnit.value = prod.gravity || 5 gravityPerUnit.value = d.products.interview.gravity || 5
} }
planList.value = buildPlanList(d.plans)
} else {
planList.value = buildPlanList(null)
} }
} catch (e) { /* silent */ } } catch (e) { /* silent */ }
})
const changeQty = (delta: number) => { // 2. 用户信息需要登录
const next = buyQty.value + delta if (!t) return
if (next >= 1 && next <= 99) buyQty.value = next try {
} const ures = await uni.request({ url: api('/user/info'), method: 'GET', header: { 'Authorization': `Bearer ${t}` } })
const clampQty = () => { if (ures.statusCode >= 200 && ures.statusCode < 300 && ures.data) {
if (buyQty.value < 1) buyQty.value = 1 const u = ures.data
if (buyQty.value > 99) buyQty.value = 99 plan.value = u.plan || 'free'
gravity.value = u.gravity ?? 0
currentPlanName.value = ({ free: '免费版', growth: '成长版', sprint: '冲刺版' })[plan.value] || '免费版'
}
} catch (e) { /* silent */ }
} }
const startPay = async () => { const buildPlanList = (plans) => {
const token = uni.getStorageSync('token') || '' const growth = plans?.find?.(p => p.id === 'growth')
if (!token) { uni.showToast({ title: '请先登录', icon: 'none' }); return } const sprint = plans?.find?.(p => p.id === 'sprint')
return [
{
id: 'free', name: '免费版', priceDisplay: '免费',
features: defaultFreeFeatures,
popular: false,
},
{
id: 'growth', name: '成长版',
priceDisplay: growth ? `¥${(growth.price / 100).toFixed(1)}/月` : '¥19/月',
features: growth?.features || defaultGrowthFeatures,
popular: true,
},
{
id: 'sprint', name: '冲刺版',
priceDisplay: sprint ? `¥${(sprint.price / 100).toFixed(1)}/月` : '¥49/月',
features: sprint?.features || defaultSprintFeatures,
popular: false,
},
]
}
onLoad(() => { /* silent */ })
onMounted(refreshState)
onShow(refreshState)
const goLogin = () => uni.navigateTo({ url: '/pages/login/login' })
const cancelPay = () => {
showPayModal.value = false
payCodeUrl.value = ''
payLoading.value = false
payError.value = ''
paySuccess.value = false
vpStatus.value = false
vpSuccess.value = false
vpStatusText.value = ''
}
/** 购买引力值 → MP 用 VP / H5 用扫码 */
const startGravityPay = async () => {
const t = token()
if (!t) { uni.showToast({ title: '请先登录', icon: 'none' }); return }
showPayModal.value = true showPayModal.value = true
payLoading.value = true payLoading.value = true
payCodeUrl.value = ''
payError.value = '' payError.value = ''
paySuccess.value = false vpStatus.value = false
if (isMp.value) {
// 小程序:虚拟支付 VP
try {
console.log('[VP] wx.login...')
const [loginErr, loginRes] = await new Promise((resolve) => {
uni.login({
provider: 'weixin',
success: r => { console.log('[VP] wx.login 成功:', JSON.stringify(r)); resolve([null, r]) },
fail: e => { console.error('[VP] wx.login 失败:', JSON.stringify(e)); resolve([e, null]) },
})
})
if (loginErr || !loginRes?.code) {
payLoading.value = false
payError.value = '微信登录失败: ' + (loginErr?.errMsg || 'no code')
console.error('[VP] login failed', loginErr, loginRes)
uni.showToast({ title: '微信登录失败', icon: 'none' })
return
}
console.log('[VP] code:', loginRes.code.slice(0, 20) + '...')
const res = await uni.request({
url: api('/virtual-payment/create'), method: 'POST',
data: { type: 'interview', quantity: buyQty.value, wxCode: loginRes.code },
header: { 'Authorization': `Bearer ${t}`, 'Content-Type': 'application/json' },
timeout: 30000,
})
console.log('[VP] 创建订单:', res.statusCode, JSON.stringify(res.data).slice(0, 500))
payLoading.value = false
if (res.statusCode >= 200 && res.statusCode < 300 && res.data?.paySig) {
const vp = res.data
currentOutTradeNo.value = vp.outTradeNo
wx.requestVirtualPayment({
env: vp.env, mode: vp.mode, offerId: vp.offerId,
signData: vp.signData,
paySig: vp.paySig, signature: vp.signature,
success: () => {
console.log('[VP] 支付成功')
vpStatus.value = true
vpSuccess.value = true
vpStatusText.value = '引力值已到账'
uni.showToast({ title: '充值成功!', icon: 'success' })
refreshState()
},
fail: (err2) => {
console.error('[VP] 支付失败:', JSON.stringify(err2))
vpStatus.value = true
vpSuccess.value = false
vpStatusText.value = err2?.errMsg || '支付取消'
},
})
} else {
const msg = res.data?.message || res.data?.msg || `请求失败(${res.statusCode})`
payError.value = msg
console.error('[VP] 订单创建失败:', res.statusCode, JSON.stringify(res.data))
}
} catch (e) {
payLoading.value = false
payError.value = '网络错误,请重试'
console.error('[VP] 异常:', e)
}
} else {
// H5:扫码支付
try { try {
const res = await uni.request({ const res = await uni.request({
url: api('/payment/create-product'), method: 'POST', url: api('/payment/create-product'), method: 'POST',
data: { type: 'interview', quantity: buyQty.value }, data: { type: 'interview', quantity: buyQty.value },
header: { 'Authorization': `Bearer ${token}`, 'Content-Type': 'application/json' }, header: { 'Authorization': `Bearer ${t}`, 'Content-Type': 'application/json' },
}) })
payLoading.value = false payLoading.value = false
if (res.statusCode >= 200 && res.statusCode < 300 && res.data?.codeUrl) { if (res.statusCode >= 200 && res.statusCode < 300 && res.data?.codeUrl) {
payCodeUrl.value = res.data.codeUrl payCodeUrl.value = res.data.codeUrl
pollPayResult(res.data.outTradeNo) currentOutTradeNo.value = res.data.outTradeNo
pollPayResult(res.data.outTradeNo, 'growth')
} else { } else {
payError.value = res.data?.message || '创建订单失败' payError.value = res.data?.message || '创建订单失败'
} }
@@ -150,80 +312,213 @@ const startPay = async () => {
payLoading.value = false payLoading.value = false
payError.value = '网络错误,请重试' payError.value = '网络错误,请重试'
} }
}
} }
const pollPayResult = (outTradeNo: string) => { /** 套餐升级 → MP 用虚拟支付 VP / H5 用扫码支付 */
const startPlanPay = async (selectedPlan) => {
const t = token()
if (!t) { uni.showToast({ title: '请先登录', icon: 'none' }); return }
payingPlan.value = selectedPlan
showPayModal.value = true
payLoading.value = true
payError.value = ''
vpStatus.value = false
if (isMp.value) {
// 小程序:虚拟支付 VP(套餐升级)
try {
console.log('[VP-plan] wx.login...')
const [loginErr, loginRes] = await new Promise((resolve) => {
uni.login({
provider: 'weixin',
success: r => { console.log('[VP-plan] wx.login 成功:', JSON.stringify(r)); resolve([null, r]) },
fail: e => { console.error('[VP-plan] wx.login 失败:', JSON.stringify(e)); resolve([e, null]) },
})
})
if (loginErr || !loginRes?.code) {
payLoading.value = false
payError.value = '微信登录失败: ' + (loginErr?.errMsg || 'no code')
console.error('[VP-plan] login failed', loginErr, loginRes)
uni.showToast({ title: '微信登录失败', icon: 'none' })
return
}
console.log('[VP-plan] code:', loginRes.code.slice(0, 20) + '...')
const res = await uni.request({
url: api('/virtual-payment/create'), method: 'POST',
data: { type: selectedPlan, quantity: 1, wxCode: loginRes.code },
header: { 'Authorization': `Bearer ${t}`, 'Content-Type': 'application/json' },
timeout: 30000,
})
console.log('[VP-plan] 创建订单:', res.statusCode, JSON.stringify(res.data).slice(0, 500))
payLoading.value = false
if (res.statusCode >= 200 && res.statusCode < 300 && res.data?.paySig) {
const vp = res.data
currentOutTradeNo.value = vp.outTradeNo
wx.requestVirtualPayment({
env: vp.env, mode: vp.mode, offerId: vp.offerId,
signData: vp.signData,
paySig: vp.paySig, signature: vp.signature,
success: () => {
console.log('[VP-plan] 支付成功')
vpStatus.value = true
vpSuccess.value = true
vpStatusText.value = '套餐已激活'
uni.showToast({ title: '开通成功!', icon: 'success' })
plan.value = selectedPlan
currentPlanName.value = selectedPlan === 'sprint' ? '冲刺版' : '成长版'
refreshState()
},
fail: (err2) => {
console.error('[VP-plan] 支付失败:', JSON.stringify(err2))
vpStatus.value = true
vpSuccess.value = false
vpStatusText.value = err2?.errMsg || '支付取消'
},
})
} else {
const msg = res.data?.message || res.data?.msg || `请求失败(${res.statusCode})`
payError.value = msg
console.error('[VP-plan] 订单创建失败:', res.statusCode, JSON.stringify(res.data))
uni.showToast({ title: msg, icon: 'none' })
}
} catch (e) {
payLoading.value = false
payError.value = '网络错误,请重试'
console.error('[VP-plan] 异常:', e)
uni.showToast({ title: '网络错误', icon: 'none' })
}
} else {
try {
const res = await uni.request({
url: api('/payment/create'), method: 'POST',
data: { plan: selectedPlan },
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
pollPayResult(res.data.outTradeNo, selectedPlan)
} else {
payError.value = res.data?.message || '创建订单失败'
}
} catch (e) {
payLoading.value = false
payError.value = '网络错误,请重试'
}
}
}
/** 轮询订单状态 */
const pollPayResult = (outTradeNo, selectedPlan) => {
if (!outTradeNo) return if (!outTradeNo) return
const token = uni.getStorageSync('token') || ''
let attempts = 0 let attempts = 0
const poll = async () => { const poll = async () => {
attempts++ attempts++
try { try {
const res = await uni.request({ const res = await uni.request({
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.statusCode < 300 && res.data?.status === 'success') { if (res.statusCode >= 200 && res.statusCode < 300 && res.data?.status === 'success') {
paySuccess.value = true await activatePlan(outTradeNo, selectedPlan)
payCodeUrl.value = ''
return return
} }
} catch (e) { /* ignore */ } } catch (e) { /* ignore */ }
if (attempts < 30) setTimeout(poll, 2000) if (attempts < 30) setTimeout(poll, 2000)
else { payError.value = '支付结果查询超时,请联系客服' }
} }
setTimeout(poll, 2000) setTimeout(poll, 2000)
} }
const cancelPay = () => { /** 激活套餐 */
const activatePlan = async (outTradeNo, selectedPlan) => {
try {
const res = await uni.request({
url: api('/payment/activate'), method: 'POST',
data: { outTradeNo },
header: { 'Authorization': `Bearer ${token()}`, 'Content-Type': 'application/json' },
})
if (res.statusCode >= 200 && res.statusCode < 300 && res.data?.success) {
paySuccess.value = true
showPayModal.value = false showPayModal.value = false
payCodeUrl.value = '' plan.value = selectedPlan
payError.value = '' currentPlanName.value = selectedPlan === 'sprint' ? '冲刺版' : '成长版'
payLoading.value = false uni.showToast({ title: '🎉 开通成功!', icon: 'success' })
refreshState()
} else {
uni.showToast({ title: res.data?.message || '激活失败', icon: 'none' })
}
} catch (e) {
payError.value = '激活失败,请联系客服'
uni.showToast({ title: '激活失败', icon: 'none' })
}
} }
// #endif
</script> </script>
<style scoped> <style scoped>
.page { min-height: 100vh; background: var(--color-bg); } .page { min-height: 100vh; background: var(--color-bg); padding-bottom: 40rpx; }
.placeholder-wrap { display: flex; flex-direction: column; align-items: center; gap: 16rpx; padding: 80rpx 40rpx; }
.placeholder-icon { font-size: 80rpx; }
.placeholder-text { font-size: 30rpx; font-weight: 600; color: var(--color-text); }
.placeholder-hint { font-size: 24rpx; color: var(--color-text-tertiary); }
.placeholder-back { font-size: 26rpx; color: var(--color-primary); padding: 16rpx 40rpx; border-radius: var(--radius-md); background: #F3F4F6; margin-top: 24rpx; }
/* H5 购买页 */ /* 状态栏 */
.hero { display: flex; flex-direction: column; align-items: center; padding: 48rpx 32rpx 24rpx; } .status-bar { display: flex; justify-content: space-between; align-items: center; background: linear-gradient(135deg, var(--color-gradient-start), var(--color-gradient-mid)); padding: 32rpx; color: #fff; }
.hero-icon { font-size: 72rpx; } .status-left { display: flex; flex-direction: column; gap: 4rpx; }
.hero-title { font-size: 36rpx; font-weight: 700; color: var(--color-text); margin-top: 12rpx; } .status-label { font-size: 22rpx; opacity: 0.85; }
.hero-desc { font-size: 24rpx; color: var(--color-text-secondary); margin-top: 8rpx; text-align: center; } .status-plan { font-size: 34rpx; font-weight: 700; }
.status-right { display: flex; flex-direction: column; align-items: flex-end; gap: 4rpx; }
.grav-label { font-size: 22rpx; opacity: 0.85; }
.grav-num { font-size: 40rpx; font-weight: 800; }
.product-card { background: #fff; border-radius: var(--radius-lg); margin: 0 32rpx; padding: 32rpx; box-shadow: var(--shadow-sm); } /* 登录提示 */
.login-bar { display: flex; align-items: center; justify-content: space-between; margin: 24rpx 24rpx 0; background: #FEF3C7; border-radius: var(--radius-lg); padding: 20rpx 24rpx; }
.login-text { font-size: 24rpx; color: #92400E; }
.login-btn { font-size: 24rpx; color: #FFF; background: var(--color-primary); padding: 8rpx 24rpx; border-radius: var(--radius-sm); }
.qty-section { margin-bottom: 24rpx; } /* 区块 */
.section-label { font-size: 26rpx; font-weight: 600; color: var(--color-text); display: block; margin-bottom: 16rpx; } .section { padding: 0 24rpx; margin-top: 24rpx; }
.section-title { font-size: 28rpx; font-weight: 700; color: var(--color-text); display: block; margin-bottom: 16rpx; }
/* 购买区 */
.buy-card { background: #fff; border-radius: var(--radius-lg); padding: 24rpx; box-shadow: var(--shadow-sm); }
.qty-row { margin-bottom: 16rpx; }
.qty-label { font-size: 24rpx; font-weight: 600; color: var(--color-text); display: block; margin-bottom: 12rpx; }
.qty-controls { display: flex; align-items: center; justify-content: center; gap: 24rpx; } .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 { width: 60rpx; height: 60rpx; border-radius: 50%; background: #F3F4F6; display: flex; align-items: center; justify-content: center; font-size: 32rpx; font-weight: 500; color: var(--color-text); }
.qty-btn.disabled { color: #D1D5DB; background: #F9FAFB; } .qty-btn.disabled { color: #D1D5DB; background: #F9FAFB; }
.qty-input { width: 120rpx; height: 72rpx; text-align: center; font-size: 36rpx; font-weight: 700; color: var(--color-text); border: 2rpx solid #E5E7EB; border-radius: var(--radius-sm); } .qty-input { width: 120rpx; height: 64rpx; text-align: center; font-size: 32rpx; font-weight: 700; color: var(--color-text); border: 2rpx solid #E5E7EB; border-radius: var(--radius-sm); }
.summary { margin-bottom: 20rpx; }
.summary { margin-bottom: 32rpx; } .summary-row { display: flex; justify-content: space-between; padding: 8rpx 0; border-bottom: 1rpx solid #F3F4F6; }
.summary-row { display: flex; justify-content: space-between; padding: 12rpx 0; border-bottom: 1rpx solid #F3F4F6; } .summary-row.total { border-bottom: none; padding-top: 12rpx; }
.summary-row.total { border-bottom: none; padding-top: 16rpx; } .summary-label { font-size: 22rpx; color: var(--color-text-secondary); }
.summary-label { font-size: 24rpx; color: var(--color-text-secondary); } .summary-val { font-size: 24rpx; font-weight: 600; color: var(--color-text); }
.summary-val { font-size: 26rpx; font-weight: 600; color: var(--color-text); }
.summary-val.highlight { color: var(--color-primary); } .summary-val.highlight { color: var(--color-primary); }
.total-price { font-size: 36rpx; font-weight: 800; color: var(--color-primary); } .total-price { font-size: 32rpx; font-weight: 800; color: var(--color-primary); }
.buy-btn { width: 100%; height: 80rpx; background: linear-gradient(135deg, var(--color-gradient-start), var(--color-gradient-mid)); color: #fff; font-size: 28rpx; font-weight: 600; border-radius: var(--radius-lg); display: flex; align-items: center; justify-content: center; border: none; }
.buy-btn { width: 100%; height: 88rpx; background: linear-gradient(135deg, var(--color-gradient-start), var(--color-gradient-mid)); color: #fff; font-size: 30rpx; font-weight: 600; border-radius: var(--radius-lg); display: flex; align-items: center; justify-content: center; border: none; } .buy-btn:active { opacity: 0.85; }
.buy-btn:active { opacity: 0.85; transform: scale(0.98); }
.buy-btn[disabled] { opacity: 0.5; } .buy-btn[disabled] { opacity: 0.5; }
/* 支付弹窗 */ /* 套餐列表 */
.plan-list { display: flex; flex-direction: column; gap: 16rpx; }
.plan-card { background: #fff; border-radius: var(--radius-lg); padding: 24rpx; box-shadow: var(--shadow-sm); position: relative; }
.plan-card.popular { border: 2rpx solid var(--color-primary); }
.plan-card.current { background: #F0F7FF; border: 2rpx solid var(--color-primary); }
.plan-header { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: 12rpx; }
.plan-name { font-size: 30rpx; font-weight: 700; color: var(--color-text); }
.price-num { font-size: 32rpx; font-weight: 800; color: var(--color-primary); }
.plan-badge { background: var(--color-primary); color: #fff; font-size: 20rpx; padding: 4rpx 14rpx; border-radius: 20rpx; }
.plan-features { display: flex; flex-direction: column; gap: 8rpx; margin-bottom: 16rpx; }
.feature { font-size: 22rpx; color: var(--color-text-secondary); }
.plan-action { text-align: center; padding: 16rpx; border-radius: var(--radius-md); font-size: 26rpx; font-weight: 600; background: linear-gradient(135deg, var(--color-gradient-start), var(--color-gradient-mid)); color: #fff; }
.plan-action.owned { background: #ECFDF5; color: var(--color-success); }
/* 弹窗 */
.modal-overlay { position: fixed; top: 0; left: 0; right: 0; bottom: 0; background: rgba(0,0,0,0.5); display: flex; align-items: center; justify-content: center; z-index: 100; } .modal-overlay { position: fixed; top: 0; left: 0; right: 0; bottom: 0; background: rgba(0,0,0,0.5); display: flex; align-items: center; justify-content: center; z-index: 100; }
.modal-content { background: #FFF; border-radius: var(--radius-xl); padding: 40rpx 32rpx; width: 600rpx; display: flex; flex-direction: column; align-items: center; gap: 16rpx; } .modal-content { background: #FFF; border-radius: var(--radius-xl); padding: 40rpx; width: 70%; display: flex; flex-direction: column; align-items: center; gap: 20rpx; }
.modal-title { font-size: 30rpx; font-weight: 700; color: var(--color-text); } .modal-title { font-size: 28rpx; font-weight: 600; color: var(--color-text); }
.pay-error { color: var(--color-error); } .pay-error { color: var(--color-error); }
.modal-hint { font-size: 22rpx; color: #6B7280; text-align: center; } .qr-canvas { width: 400rpx; height: 400rpx; }
.modal-close { font-size: 24rpx; color: #9CA3AF; padding: 12rpx 24rpx; } .modal-hint { font-size: 22rpx; color: var(--color-text-tertiary); }
.qrcode { width: 300rpx; height: 300rpx; margin: 8rpx 0; } .modal-close { font-size: 22rpx; color: var(--color-text-tertiary); padding: 8rpx; }
</style> </style>
+28 -1
View File
@@ -175,7 +175,13 @@ import { onShow } from '@dcloudio/uni-app'
import { api } from '../../config' import { api } from '../../config'
// #ifdef MP-WEIXIN // #ifdef MP-WEIXIN
onShareAppMessage(() => ({ title: '职引 - 个人中心 | AI模拟面试', path: '/pages/user/user' })) const shareCodeRef = ref('')
onShareAppMessage(() => {
const path = shareCodeRef.value
? `/pages/user/user?share=${shareCodeRef.value}`
: '/pages/user/user'
return { title: '职引 - 个人中心 | AI模拟面试', path }
})
onShareTimeline(() => ({ title: '职引 - 个人中心 | AI模拟面试' })) onShareTimeline(() => ({ title: '职引 - 个人中心 | AI模拟面试' }))
// #endif // #endif
@@ -199,8 +205,29 @@ const refreshState = () => {
loadMemberStatus() loadMemberStatus()
checkAdmin() checkAdmin()
fetchUserInfo() fetchUserInfo()
// #ifdef MP-WEIXIN
preCreateShare()
// #endif
} }
// #ifdef MP-WEIXIN
async function preCreateShare() {
if (shareCodeRef.value) return // already have one
try {
const res = await uni.request({
url: api('/share/create'), method: 'POST',
data: { type: 'app', title: '我在AI磁场·职引练习面试', description: 'AI模拟面试+简历优化,快来一起提升吧' },
header: { Authorization: `Bearer ${token.value}` },
})
if (res.statusCode < 200 || res.statusCode >= 300) return
const data = res.data?.data || res.data
if (data.shareCode) {
shareCodeRef.value = data.shareCode
}
} catch(e) { /* silent */ }
}
// #endif
const fetchUserInfo = async () => { const fetchUserInfo = async () => {
try { try {
const res = await uni.request({ url: api('/user/info'), method: 'GET', header: { 'Authorization': `Bearer ${token.value}` } }) const res = await uni.request({ url: api('/user/info'), method: 'GET', header: { 'Authorization': `Bearer ${token.value}` } })
+17
View File
@@ -0,0 +1,17 @@
/** 将 ISO 时间字符串转为北京时间(UTC+8)显示 */
export function toBeijing(iso?: string): string {
if (!iso) return '--'
try {
return new Date(iso).toLocaleString('zh-CN', {
timeZone: 'Asia/Shanghai',
hour12: false,
year: 'numeric',
month: '2-digit',
day: '2-digit',
hour: '2-digit',
minute: '2-digit',
})
} catch {
return iso.slice(0, 16).replace('T', ' ')
}
}