提交正式官网
This commit is contained in:
@@ -0,0 +1,61 @@
|
||||
import { nowStr } from '~/server/utils/auth'
|
||||
import { execute } from '~/server/utils/mysql'
|
||||
import { notifyAssessmentSubmission } from '~/server/utils/form-notification'
|
||||
import { fail, ok } from '~/server/utils/response'
|
||||
|
||||
export default defineEventHandler(async (event) => {
|
||||
const body = await readBody<{
|
||||
lang?: string
|
||||
firstName?: string
|
||||
lastName?: string
|
||||
email?: string
|
||||
condition?: string
|
||||
reports?: string
|
||||
message?: string
|
||||
}>(event)
|
||||
|
||||
const lang = body.lang === 'zh' ? 'zh' : 'en'
|
||||
const firstName = body.firstName?.trim()
|
||||
const email = body.email?.trim()
|
||||
const condition = body.condition?.trim()
|
||||
|
||||
if (!firstName) return fail('请填写患者名')
|
||||
if (!email) return fail('请填写联系邮箱')
|
||||
if (!condition) return fail('请填写主要病情/诊断')
|
||||
|
||||
const emailPattern = /^[^\s@]+@[^\s@]+\.[^\s@]+$/
|
||||
if (!emailPattern.test(email)) return fail('邮箱格式不正确')
|
||||
|
||||
const createdAt = nowStr()
|
||||
|
||||
await execute(
|
||||
`INSERT INTO assessment_submissions
|
||||
(lang, first_name, last_name, email, condition_text, reports, message, status, created_at)
|
||||
VALUES (?, ?, ?, ?, ?, ?, ?, 'unread', ?)`,
|
||||
[
|
||||
lang,
|
||||
firstName,
|
||||
body.lastName?.trim() || null,
|
||||
email,
|
||||
condition,
|
||||
body.reports || null,
|
||||
body.message?.trim() || null,
|
||||
createdAt,
|
||||
]
|
||||
)
|
||||
|
||||
void notifyAssessmentSubmission({
|
||||
lang,
|
||||
firstName,
|
||||
lastName: body.lastName?.trim() || null,
|
||||
email,
|
||||
condition,
|
||||
reports: body.reports || null,
|
||||
message: body.message?.trim() || null,
|
||||
createdAt,
|
||||
}).catch((error) => {
|
||||
console.error('[mail] 免费评估表通知发送失败:', error)
|
||||
})
|
||||
|
||||
return ok(null, '提交成功')
|
||||
})
|
||||
@@ -0,0 +1,62 @@
|
||||
import { nowStr } from '~/server/utils/auth'
|
||||
import { execute } from '~/server/utils/mysql'
|
||||
import { notifyPartnerSubmission } from '~/server/utils/form-notification'
|
||||
import { fail, ok } from '~/server/utils/response'
|
||||
|
||||
export default defineEventHandler(async (event) => {
|
||||
const body = await readBody<{
|
||||
lang?: string
|
||||
firstName?: string
|
||||
lastName?: string
|
||||
companyName?: string
|
||||
country?: string
|
||||
email?: string
|
||||
category?: string
|
||||
collaborate?: string
|
||||
}>(event)
|
||||
|
||||
const lang = body.lang === 'zh' ? 'zh' : 'en'
|
||||
const firstName = body.firstName?.trim()
|
||||
const lastName = body.lastName?.trim()
|
||||
const companyName = body.companyName?.trim()
|
||||
const country = body.country?.trim()
|
||||
const email = body.email?.trim()
|
||||
const category = body.category?.trim()
|
||||
const collaborate = body.collaborate?.trim()
|
||||
|
||||
if (!firstName) return fail('请填写名')
|
||||
if (!lastName) return fail('请填写姓')
|
||||
if (!companyName) return fail('请填写公司名称')
|
||||
if (!country) return fail('请填写国家/地区')
|
||||
if (!email) return fail('请填写电子邮箱')
|
||||
if (!category) return fail('请选择合作类别')
|
||||
if (!collaborate) return fail('请填写合作说明')
|
||||
|
||||
const emailPattern = /^[^\s@]+@[^\s@]+\.[^\s@]+$/
|
||||
if (!emailPattern.test(email)) return fail('邮箱格式不正确')
|
||||
|
||||
const createdAt = nowStr()
|
||||
|
||||
await execute(
|
||||
`INSERT INTO partner_submissions
|
||||
(lang, first_name, last_name, company_name, country, email, category, collaborate, status, created_at)
|
||||
VALUES (?, ?, ?, ?, ?, ?, ?, ?, 'unread', ?)`,
|
||||
[lang, firstName, lastName, companyName, country, email, category, collaborate, createdAt]
|
||||
)
|
||||
|
||||
void notifyPartnerSubmission({
|
||||
lang,
|
||||
firstName,
|
||||
lastName,
|
||||
companyName,
|
||||
country,
|
||||
email,
|
||||
category,
|
||||
collaborate,
|
||||
createdAt,
|
||||
}).catch((error) => {
|
||||
console.error('[mail] 合作申请通知发送失败:', error)
|
||||
})
|
||||
|
||||
return ok(null, '提交成功')
|
||||
})
|
||||
Reference in New Issue
Block a user