49 lines
1.1 KiB
Go
49 lines
1.1 KiB
Go
package handlers
|
|
|
|
import (
|
|
"platform/pkg/u"
|
|
"platform/web/core"
|
|
g "platform/web/globals"
|
|
m "platform/web/models"
|
|
q "platform/web/queries"
|
|
|
|
"github.com/gofiber/fiber/v2"
|
|
)
|
|
|
|
// region CreateInquiry
|
|
|
|
type CreateInquiryRequest struct {
|
|
Company string `json:"company" validate:"omitempty,max=200"`
|
|
Name string `json:"name" validate:"required,max=100"`
|
|
Phone string `json:"phone" validate:"required,max=20"`
|
|
Email string `json:"email" validate:"omitempty,email,max=100"`
|
|
Content string `json:"content" validate:"required,max=1000"`
|
|
}
|
|
|
|
func CreateInquiry(c *fiber.Ctx) error {
|
|
|
|
// 解析请求参数
|
|
req := new(CreateInquiryRequest)
|
|
err := g.Validator.ParseBody(c, req)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
// 创建咨询记录
|
|
err = q.Inquiry.Create(&m.Inquiry{
|
|
Company: u.X(req.Company),
|
|
Name: u.X(req.Name),
|
|
Phone: u.X(req.Phone),
|
|
Email: u.X(req.Email),
|
|
Content: u.X(req.Content),
|
|
Status: m.InquiryStatusPending,
|
|
})
|
|
if err != nil {
|
|
return core.NewServErr("提交咨询失败", err)
|
|
}
|
|
|
|
return c.SendStatus(fiber.StatusNoContent)
|
|
}
|
|
|
|
// endregion
|