@ -81,7 +81,7 @@ const server = http.createServer(async (req, res) => {
try {
// 从数据库获取最新的合格证信息
const [ rows ] = await pool . execute (
'SELECT company as subjectName, phoneNumber as contact, productName, grossWeight as weight, commitBasis as basis, origin, issueDate, DATE_FORMAT(issueDate, "%Y-%m-%d") as date, signature FROM certificate ORDER BY id DESC LIMIT 1'
'SELECT company as subjectName, phoneNumber as contact, productName, grossWeight as weight, commitBasis as basis, origin, DATE_FORMAT(issueDate, "%Y-%m-%d") as date, signature FROM certificate ORDER BY id DESC LIMIT 1'
) ;
const certificate = rows . length > 0 ? rows [ 0 ] : null ;
@ -120,9 +120,8 @@ const server = http.createServer(async (req, res) => {
try {
// 解析表单数据
const formData = new URLSearchParams ( body ) ;
// 使用当前的北京 时间(精确到秒) 作为开具日期
// 使用当前时间作为开具日期,数据库连接已配置为北京时间
const now = new Date ( ) ;
const beijingTime = new Date ( now . getTime ( ) + 8 * 60 * 60 * 1000 ) ; // 转换为北京时间
const certificate = {
subjectName : formData . get ( 'subjectName' ) ,
@ -131,7 +130,7 @@ const server = http.createServer(async (req, res) => {
weight : formData . get ( 'weight' ) ,
basis : formData . get ( 'basis' ) ,
origin : formData . get ( 'origin' ) ,
date : beijingTime ,
date : now ,
signature : formData . get ( 'signature' )
} ;
@ -176,19 +175,21 @@ const server = http.createServer(async (req, res) => {
console . log ( '数据插入数据库成功' ) ;
// 返回成功响应,确保返回的signature是OSS URL
const responseCertificate = {
... certificate ,
signature : signatureUrl
} ;
res . writeHead ( 200 , {
'Content-Type' : 'application/json' ,
'Access-Control-Allow-Origin' : '*' ,
'Access-Control-Allow-Methods' : 'POST, GET, OPTIONS' ,
'Access-Control-Allow-Headers' : 'Content-Type'
} ) ;
res . end ( JSON . stringify ( { success : true , certificate : responseCertificate } ) ) ;
// 返回成功响应,确保返回的signature是OSS URL,日期只显示到日
const responseCertificate = {
... certificate ,
signature : signatureUrl ,
// 格式化日期为YYYY-MM-DD格式
date : certificate . date . toISOString ( ) . split ( 'T' ) [ 0 ]
} ;
res . writeHead ( 200 , {
'Content-Type' : 'application/json' ,
'Access-Control-Allow-Origin' : '*' ,
'Access-Control-Allow-Methods' : 'POST, GET, OPTIONS' ,
'Access-Control-Allow-Headers' : 'Content-Type'
} ) ;
res . end ( JSON . stringify ( { success : true , certificate : responseCertificate } ) ) ;
} catch ( error ) {
console . error ( '处理表单数据失败:' , error . message ) ;
res . writeHead ( 500 , {