实现用户咨询数据收集接口
This commit is contained in:
48
web/handlers/inquiry.go
Normal file
48
web/handlers/inquiry.go
Normal file
@@ -0,0 +1,48 @@
|
||||
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
|
||||
@@ -439,7 +439,7 @@ func ResourcePrice(c *fiber.Ctx) error {
|
||||
// 解析请求参数
|
||||
var req = new(CreateResourceReq)
|
||||
if err := g.Validator.ParseBody(c, req); err != nil {
|
||||
return err
|
||||
return core.NewBizErr("接口参数解析异常", err)
|
||||
}
|
||||
|
||||
// 获取套餐价格
|
||||
|
||||
Reference in New Issue
Block a user