@ -81,10 +81,11 @@ const server = http.createServer(async (req, res) => {
try {
try {
// 从数据库获取最新的合格证信息
// 从数据库获取最新的合格证信息
const [ rows ] = await pool . execute (
const [ rows ] = await pool . execute (
'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'
'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'
) ;
) ;
const certificate = rows . length > 0 ? rows [ 0 ] : null ;
const certificate = rows . length > 0 ? rows [ 0 ] : null ;
console . log ( '从数据库获取的最新合格证信息:' , certificate ) ;
// 返回成功响应
// 返回成功响应
res . writeHead ( 200 , {
res . writeHead ( 200 , {
@ -119,6 +120,10 @@ const server = http.createServer(async (req, res) => {
try {
try {
// 解析表单数据
// 解析表单数据
const formData = new URLSearchParams ( body ) ;
const formData = new URLSearchParams ( body ) ;
// 使用当前的北京时间(精确到秒)作为开具日期
const now = new Date ( ) ;
const beijingTime = new Date ( now . getTime ( ) + 8 * 60 * 60 * 1000 ) ; // 转换为北京时间
const certificate = {
const certificate = {
subjectName : formData . get ( 'subjectName' ) ,
subjectName : formData . get ( 'subjectName' ) ,
contact : formData . get ( 'contact' ) ,
contact : formData . get ( 'contact' ) ,
@ -126,7 +131,7 @@ const server = http.createServer(async (req, res) => {
weight : formData . get ( 'weight' ) ,
weight : formData . get ( 'weight' ) ,
basis : formData . get ( 'basis' ) ,
basis : formData . get ( 'basis' ) ,
origin : formData . get ( 'origin' ) ,
origin : formData . get ( 'origin' ) ,
date : formData . get ( 'date' ) ,
date : beijingTime ,
signature : formData . get ( 'signature' )
signature : formData . get ( 'signature' )
} ;
} ;
@ -137,7 +142,7 @@ const server = http.createServer(async (req, res) => {
weight : certificate . weight ,
weight : certificate . weight ,
basis : certificate . basis ,
basis : certificate . basis ,
origin : certificate . origin ,
origin : certificate . origin ,
date : certificate . date ,
date : certificate . date . toISOString ( ) ,
hasSignature : ! ! certificate . signature
hasSignature : ! ! certificate . signature
} ) ;
} ) ;