客服离线留言

pull/23/head
陶士涵 4 years ago
parent cd89760b5c
commit 5728071b37

@ -80,14 +80,18 @@ DROP TABLE IF EXISTS `welcome`|
CREATE TABLE `welcome` (
`id` int(10) unsigned NOT NULL AUTO_INCREMENT,
`user_id` varchar(100) NOT NULL DEFAULT '',
`keyword` varchar(100) NOT NULL DEFAULT '',
`content` varchar(500) NOT NULL DEFAULT '',
`is_default` tinyint(3) unsigned NOT NULL DEFAULT '0',
`ctime` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
PRIMARY KEY (`id`),
KEY `user_id` (`user_id`)
KEY `user_id` (`user_id`),
KEY `keyword` (`keyword`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8|
INSERT INTO `welcome` (`id`, `user_id`, `content`, `is_default`, `ctime`) VALUES
(1, 'kefu2', '本客服代码开源,欢迎star,开源地址:https://github.com/taoshihan1991/go-fly', 1, '2020-08-24 02:57:49')|
INSERT INTO `welcome` (`id`, `user_id`, `content`, `is_default`, `ctime`, `keyword`) VALUES
(NULL, 'kefu2', '我暂时离线,留言已转发到我的邮箱,稍后回复~', 1, '2020-08-24 02:57:49','offline')|
INSERT INTO `welcome` (`id`, `user_id`, `content`, `is_default`, `ctime`, `keyword`) VALUES
(NULL, 'kefu2', '本客服代码开源,欢迎star,开源地址:https://github.com/taoshihan1991/go-fly', 0, '2020-08-24 02:57:49','welcome')|
DROP TABLE IF EXISTS `ipblack`|
CREATE TABLE `ipblack` (

@ -215,8 +215,11 @@ func SendMessageV2(c *gin.Context) {
go SendNoticeEmail(content+"|"+vistorInfo.Name, content)
go func() {
time.Sleep(1 * time.Second)
content = "我暂时离线,留言已转发到我的邮箱,稍后回复~"
ws.VisitorMessage(vistorInfo.VisitorId, content, kefuInfo)
welcome := models.FindWelcomeByUserIdKey(kefuInfo.Name, "offline")
if welcome.Content == "" {
return
}
ws.VisitorMessage(vistorInfo.VisitorId, welcome.Content, kefuInfo)
models.CreateMessage(kefuInfo.Name, vistorInfo.VisitorId, content, "kefu")
}()
}

@ -14,7 +14,7 @@ import (
func GetNotice(c *gin.Context) {
kefuId := c.Query("kefu_id")
welcomes := models.FindWelcomesByUserId(kefuId)
welcomes := models.FindWelcomesByKeyword(kefuId, "welcome")
user := models.FindUser(kefuId)
result := make([]gin.H, 0)
for _, welcome := range welcomes {

@ -5,6 +5,7 @@ import "time"
type Welcome struct {
ID uint `gorm:"primary_key" json:"id"`
UserId string `json:"user_id"`
Keyword string `json:"keyword"`
Content string `json:"content"`
IsDefault uint `json:"is_default"`
Ctime time.Time `json:"ctime"`
@ -18,23 +19,24 @@ func CreateWelcome(userId string, content string) uint {
UserId: userId,
Content: content,
Ctime: time.Now(),
Keyword: "welcome",
}
DB.Create(w)
return w.ID
}
func UpdateWelcome(userId string,id string, content string) uint {
func UpdateWelcome(userId string, id string, content string) uint {
if userId == "" || content == "" {
return 0
}
w := &Welcome{
Content: content,
}
DB.Model(w).Where("user_id = ? and id = ?", userId,id).Update(w)
DB.Model(w).Where("user_id = ? and id = ?", userId, id).Update(w)
return w.ID
}
func FindWelcomeByUserId(userId interface{}) Welcome {
func FindWelcomeByUserIdKey(userId interface{}, keyword interface{}) Welcome {
var w Welcome
DB.Where("user_id = ? and is_default=?", userId, 1).First(&w)
DB.Where("user_id = ? and keyword=?", userId, keyword).First(&w)
return w
}
func FindWelcomesByUserId(userId interface{}) []Welcome {
@ -42,6 +44,11 @@ func FindWelcomesByUserId(userId interface{}) []Welcome {
DB.Where("user_id = ?", userId).Find(&w)
return w
}
func FindWelcomesByKeyword(userId interface{}, keyword interface{}) []Welcome {
var w []Welcome
DB.Where("user_id = ? and keyword=?", userId, keyword).Find(&w)
return w
}
func DeleteWelcome(userId interface{}, id string) {
DB.Where("user_id = ? and id = ?", userId, id).Delete(Welcome{})
}

@ -24,7 +24,7 @@
prop="id"
label="操作">
<template slot-scope="scope">
<el-button @click="deleteWelcome(scope.row.id)" type="danger" size="small" plain>删除</el-button>
<el-button v-show="scope.row.is_default==0" @click="deleteWelcome(scope.row.id)" type="danger" size="small" plain>删除</el-button>
</template>
</el-table-column>
</el-table>

Loading…
Cancel
Save