diff --git a/config/go-fly.sql b/config/go-fly.sql index 4f04119..b6e77d1 100644 --- a/config/go-fly.sql +++ b/config/go-fly.sql @@ -172,4 +172,13 @@ CREATE TABLE `language` ( INSERT INTO `language` (`id`, `country`, `short_key`) VALUES (1, '中文简体', 'zh-cn')| INSERT INTO `language` (`id`, `country`, `short_key`) VALUES (2, '正體中文', 'zh-tw')| INSERT INTO `language` (`id`, `country`, `short_key`) VALUES (3, 'English', 'en_us')| -INSERT INTO `language` (`id`, `country`, `short_key`) VALUES (4, '日本語', 'ja_jp') \ No newline at end of file +INSERT INTO `language` (`id`, `country`, `short_key`) VALUES (4, '日本語', 'ja_jp')| +DROP TABLE IF EXISTS `user_client`| +CREATE TABLE `user_client` ( + `id` int(11) NOT NULL AUTO_INCREMENT, + `kefu` varchar(100) NOT NULL DEFAULT '', + `client_id` varchar(100) NOT NULL DEFAULT '', + `created_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, + UNIQUE KEY `idx_user` (`kefu`,`client_id`), + PRIMARY KEY (`id`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8| \ No newline at end of file diff --git a/controller/kefu.go b/controller/kefu.go index 498db9a..93e15bb 100644 --- a/controller/kefu.go +++ b/controller/kefu.go @@ -58,6 +58,24 @@ func PostKefuPass(c *gin.Context) { "result": "", }) } +func PostKefuClient(c *gin.Context) { + kefuName, _ := c.Get("kefu_name") + clientId := c.PostForm("client_id") + + if clientId == "" { + c.JSON(200, gin.H{ + "code": 400, + "msg": "client_id不能为空", + }) + return + } + models.CreateUserClient(kefuName.(string), clientId) + c.JSON(200, gin.H{ + "code": 200, + "msg": "ok", + "result": "", + }) +} func GetKefuInfo(c *gin.Context) { kefuId, _ := c.Get("kefu_id") user := models.FindUserById(kefuId) diff --git a/models/user_client.go b/models/user_client.go new file mode 100644 index 0000000..d02b320 --- /dev/null +++ b/models/user_client.go @@ -0,0 +1,20 @@ +package models + +import "time" + +type User_client struct { + ID uint `gorm:"primary_key" json:"id"` + Kefu string `json:"kefu"` + Client_id string `json:"client_id"` + Created_at string `json:"created_at"` +} + +func CreateUserClient(kefu, clientId string) uint { + u := &User_client{ + Kefu: kefu, + Client_id: clientId, + Created_at: time.Now().Format("2006-01-02 15:04:05"), + } + DB.Create(u) + return u.ID +} diff --git a/router/api.go b/router/api.go index 4220c9a..8af7f4c 100644 --- a/router/api.go +++ b/router/api.go @@ -47,6 +47,7 @@ func InitApiRouter(engine *gin.Engine) { engine.POST("/message_status", controller.GetVisitorMessage) //获取客服信息 + engine.POST("/kefuinfo_client", middleware.JwtApiMiddleware, controller.PostKefuClient) engine.GET("/kefuinfo", middleware.JwtApiMiddleware, middleware.RbacAuth, controller.GetKefuInfo) engine.GET("/kefuinfo_setting", middleware.JwtApiMiddleware, middleware.RbacAuth, controller.GetKefuInfoSetting) engine.POST("/kefuinfo", middleware.JwtApiMiddleware, middleware.RbacAuth, controller.PostKefuInfo)