feat: 登录页密码+验证码双模式 / 首页岗位优化 / 法律页面 / 后端接口完善
- 前端:登录页重构,支持密码登录、验证码登录、注册三种模式 - 前端:首页热门岗位添加「参考示例」标签,去虚构数据 - 前端:面试页顶部优化,岗位名+状态标签展示 - 前端:新增用户协议、隐私政策页面及免责声明 - 后端:新增 POST /api/user/register 注册接口 - 后端:新增 POST /api/user/set-password 设置密码接口 - 后端:修复 user.schema.ts unique 索引导致 null 冲突问题 - 后端:新增 payment-order.schema、positions.schema、site-config.schema - 后端:package.json 新增 postbuild 脚本自动复制证书 - 管理后台:新增订单管理 Tab
This commit is contained in:
@@ -1,19 +1,21 @@
|
||||
import { Controller, Post, Body, UseGuards, HttpException, HttpStatus } from '@nestjs/common'
|
||||
import { Controller, Post, Get, Query, Body, UseGuards, HttpException, HttpStatus } from '@nestjs/common'
|
||||
import { InjectModel } from '@nestjs/mongoose'
|
||||
import { Model } from 'mongoose'
|
||||
import { User, UserDocument } from '../user/user.schema'
|
||||
import { PaymentOrder, PaymentOrderDocument } from './payment-order.schema'
|
||||
import { JwtAuthGuard } from '../../common/guards/jwt-auth.guard'
|
||||
import { CurrentUser } from '../../common/decorators/current-user.decorator'
|
||||
import { WechatPayService } from './wechat-pay.service'
|
||||
import { Public } from '../../common/decorators/public.decorator'
|
||||
|
||||
const VIP_AMOUNT = 2900 // 29 元(分)
|
||||
const VIP_AMOUNT = 1990 // 19.9 元(分)
|
||||
const VIP_DURATION_DAYS = 30
|
||||
|
||||
@Controller('payment')
|
||||
export class PaymentController {
|
||||
constructor(
|
||||
@InjectModel(User.name) private userModel: Model<UserDocument>,
|
||||
@InjectModel(PaymentOrder.name) private orderModel: Model<PaymentOrderDocument>,
|
||||
private wechatPay: WechatPayService,
|
||||
) {}
|
||||
|
||||
@@ -26,20 +28,28 @@ export class PaymentController {
|
||||
if (user.plan === 'vip') throw new HttpException('已是会员', HttpStatus.BAD_REQUEST)
|
||||
|
||||
const outTradeNo = `VIP${Date.now()}${userId.slice(-6)}`
|
||||
const result = await this.wechatPay.nativePay(
|
||||
'职引月度会员',
|
||||
const result = await this.wechatPay.nativePay('AI磁场月度会员', outTradeNo, VIP_AMOUNT)
|
||||
|
||||
// 保存订单
|
||||
await this.orderModel.create({
|
||||
outTradeNo,
|
||||
VIP_AMOUNT,
|
||||
)
|
||||
return {
|
||||
outTradeNo: result.outTradeNo,
|
||||
codeUrl: result.codeUrl, // 二维码链接
|
||||
userId,
|
||||
userPhone: user.phone || '',
|
||||
amount: VIP_AMOUNT,
|
||||
title: '职引月度会员',
|
||||
title: 'AI磁场月度会员',
|
||||
status: 'pending',
|
||||
channel: 'native',
|
||||
})
|
||||
|
||||
return {
|
||||
outTradeNo,
|
||||
codeUrl: result.codeUrl,
|
||||
amount: VIP_AMOUNT,
|
||||
title: 'AI磁场月度会员',
|
||||
}
|
||||
}
|
||||
|
||||
/** JSAPI 支付(微信小程序/公众号内使用) */
|
||||
/** JSAPI 支付(微信小程序) */
|
||||
@UseGuards(JwtAuthGuard)
|
||||
@Post('jsapi')
|
||||
async jsapi(@CurrentUser('userId') userId: string, @Body('openid') openid: string) {
|
||||
@@ -49,21 +59,45 @@ export class PaymentController {
|
||||
if (user.plan === 'vip') throw new HttpException('已是会员', HttpStatus.BAD_REQUEST)
|
||||
|
||||
const outTradeNo = `VIP${Date.now()}${userId.slice(-6)}`
|
||||
const result = await this.wechatPay.jsapiPay('职引月度会员', outTradeNo, VIP_AMOUNT, openid)
|
||||
const result = await this.wechatPay.jsapiPay('AI磁场月度会员', outTradeNo, VIP_AMOUNT, openid)
|
||||
|
||||
// 保存订单
|
||||
await this.orderModel.create({
|
||||
outTradeNo,
|
||||
userId,
|
||||
userPhone: user.phone || '',
|
||||
amount: VIP_AMOUNT,
|
||||
title: 'AI磁场月度会员',
|
||||
status: 'pending',
|
||||
channel: 'jsapi',
|
||||
})
|
||||
|
||||
return result
|
||||
}
|
||||
|
||||
/** 支付回调通知 */
|
||||
@Public()
|
||||
@Post('notify')
|
||||
async notify(@Body() body: any, @Body('headers') headers: any) {
|
||||
// 实际运行时从 request 读取 header
|
||||
async notify(@Body() body: any) {
|
||||
try {
|
||||
const decrypted = this.wechatPay.verifyAndDecrypt(body, '', '', '')
|
||||
if (!decrypted) return { code: 'FAIL', message: '验签失败' }
|
||||
// 处理成功支付
|
||||
|
||||
const outTradeNo = decrypted.out_trade_no
|
||||
const userId = outTradeNo.slice(-6) // 从订单号取 userId
|
||||
const wxTransactionId = decrypted.transaction_id
|
||||
|
||||
// 更新订单状态
|
||||
const order = await this.orderModel.findOne({ outTradeNo }).exec()
|
||||
if (order && order.status === 'pending') {
|
||||
order.status = 'success'
|
||||
order.paidAt = new Date()
|
||||
order.wxTransactionId = wxTransactionId
|
||||
order.description = `${decrypted.trade_type || ''} 支付成功`
|
||||
await order.save()
|
||||
}
|
||||
|
||||
// 开通会员
|
||||
const userId = outTradeNo.slice(-6)
|
||||
const user = await this.userModel.findOne({ _id: { $regex: userId + '$' } }).exec()
|
||||
if (user && user.plan !== 'vip') {
|
||||
const expireAt = new Date()
|
||||
@@ -79,7 +113,7 @@ export class PaymentController {
|
||||
}
|
||||
}
|
||||
|
||||
/** 查询订单 */
|
||||
/** 查询订单(微信侧) */
|
||||
@UseGuards(JwtAuthGuard)
|
||||
@Post('query')
|
||||
async query(@Body('outTradeNo') outTradeNo: string) {
|
||||
|
||||
Reference in New Issue
Block a user