kefu/controller/preVisitorForm.go

60 lines
1.6 KiB
Go
Raw Normal View History

2024-12-10 02:50:12 +00:00
package controller
import (
"github.com/gin-gonic/gin"
"kefu/models"
"kefu/types"
"kefu/ws"
)
type preVisitorForm struct {
VisitorId string `form:"visitor_id" json:"visitor_id" uri:"visitor_id" xml:"visitor_id"`
EntId string `form:"ent_id" json:"ent_id" uri:"ent_id" xml:"ent_id"`
Name string `form:"name" json:"name" uri:"name" xml:"name"`
Tel string `form:"tel" json:"tel" uri:"tel" xml:"tel"`
Wechat string `form:"wechat" json:"wechat" uri:"wechat" xml:"wechat"`
QQ string `form:"qq" json:"qq" uri:"qq" xml:"qq"`
Email string `form:"email" json:"email" uri:"email" xml:"email"`
Remark string `form:"remark" json:"remark" uri:"remark" xml:"remark"`
}
func PostPreVisitorForm(c *gin.Context) {
var form preVisitorForm
err := c.Bind(&form)
if err != nil {
HandleError(c, types.ApiCode.FAILED, types.ApiCode.GetMessage(types.ApiCode.INVALID), err)
return
}
c.JSON(200, gin.H{
"code": types.ApiCode.SUCCESS,
})
attrInfo := models.GetVisitorAttrByVisitorId(form.VisitorId, form.EntId)
if attrInfo.ID == 0 {
models.CreateVisitorAttr(
form.EntId,
form.VisitorId,
form.Name,
form.Tel,
form.Email,
form.QQ,
form.Wechat,
form.Remark)
} else {
var attr = &models.Visitor_attr{
RealName: form.Name,
Tel: form.Tel,
Email: form.Email,
QQ: form.QQ,
Wechat: form.Wechat,
Comment: form.Remark,
}
models.SaveVisitorAttrByVisitorId(attr, form.VisitorId, form.EntId)
}
if form.Name != "" {
models.UpdateVisitorRealName(form.Name,
form.EntId,
form.VisitorId)
go ws.UpdateVisitorName(form.VisitorId, form.Name)
}
}