新增订单推荐人和邀请码功能,优化支付流程中的订单插入逻辑,确保订单记录准确。更新小程序支付请求,支持传递邀请码以便于分销归属和对账。同时,调整数据库结构以支持新字段,提升系统的稳定性和用户体验。
This commit is contained in:
@@ -1,11 +1,11 @@
|
||||
/**
|
||||
* 查询订单支付状态 API
|
||||
* 基于 Universal_Payment_Module v4.0 设计
|
||||
*
|
||||
* GET /api/payment/status/{orderSn}
|
||||
* 从数据库 orders 表查询真实订单状态
|
||||
*/
|
||||
|
||||
import { type NextRequest, NextResponse } from "next/server"
|
||||
import { query } from "@/lib/db"
|
||||
|
||||
export async function GET(
|
||||
request: NextRequest,
|
||||
@@ -21,23 +21,49 @@ export async function GET(
|
||||
)
|
||||
}
|
||||
|
||||
// TODO: 从数据库查询订单状态
|
||||
// const order = await OrderService.getByOrderSn(orderSn)
|
||||
|
||||
// 模拟返回数据(开发测试用)
|
||||
const mockOrder = {
|
||||
orderSn,
|
||||
status: "created", // created | paying | paid | closed | refunded
|
||||
paidAmount: null,
|
||||
paidAt: null,
|
||||
paymentMethod: null,
|
||||
tradeSn: null,
|
||||
const rows = await query(
|
||||
"SELECT order_sn, status, amount, pay_time, transaction_id, product_type FROM orders WHERE order_sn = ?",
|
||||
[orderSn]
|
||||
) as any[]
|
||||
|
||||
if (!rows || rows.length === 0) {
|
||||
return NextResponse.json({
|
||||
code: 200,
|
||||
message: "success",
|
||||
data: {
|
||||
orderSn,
|
||||
status: "created",
|
||||
paidAmount: null,
|
||||
paidAt: null,
|
||||
paymentMethod: null,
|
||||
tradeSn: null,
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
const order = rows[0]
|
||||
const statusMap: Record<string, string> = {
|
||||
created: "created",
|
||||
pending: "paying",
|
||||
paid: "paid",
|
||||
cancelled: "closed",
|
||||
refunded: "refunded",
|
||||
expired: "closed",
|
||||
}
|
||||
const frontStatus = statusMap[order.status] || order.status
|
||||
|
||||
return NextResponse.json({
|
||||
code: 200,
|
||||
message: "success",
|
||||
data: mockOrder,
|
||||
data: {
|
||||
orderSn: order.order_sn,
|
||||
status: frontStatus,
|
||||
paidAmount: order.status === "paid" ? Number(order.amount) : null,
|
||||
paidAt: order.pay_time || null,
|
||||
paymentMethod: "wechat",
|
||||
tradeSn: order.transaction_id || null,
|
||||
productType: order.product_type,
|
||||
},
|
||||
})
|
||||
} catch (error) {
|
||||
console.error("[Payment] Query status error:", error)
|
||||
|
||||
Reference in New Issue
Block a user