diff --git a/config/config.go b/config/config.go
index 5c6921d..33c7d17 100644
--- a/config/config.go
+++ b/config/config.go
@@ -16,6 +16,7 @@ const AccountConf = Dir + "account.json"
const MysqlConf = Dir + "mysql.json"
const MailConf = Dir + "mail.json"
const LangConf=Dir+"language.json"
+const MainConf = Dir + "config.json"
type Mysql struct{
Server string
Port string
@@ -27,14 +28,23 @@ type MailServer struct {
Server, Email, Password string
}
type Config struct {
- Mysql *Mysql
+ Upload string
}
func CreateConfig()*Config{
- mysql :=CreateMysql()
+ var configObj Config
c:=&Config{
- Mysql: mysql,
+ Upload: "static/upload/",
}
- return c
+ isExist, _ := tools.IsFileExist(MainConf)
+ if !isExist {
+ return c
+ }
+ info, err := ioutil.ReadFile(MainConf)
+ if err != nil {
+ return c
+ }
+ err = json.Unmarshal(info, &configObj)
+ return &configObj
}
func CreateMailServer() *MailServer {
var imap MailServer
diff --git a/config/go-fly.sql b/config/go-fly.sql
index f5be5b4..308134a 100644
--- a/config/go-fly.sql
+++ b/config/go-fly.sql
@@ -64,3 +64,13 @@ CREATE TABLE `role` (
`name` varchar(100) NOT NULL DEFAULT '',
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8
+DROP TABLE IF EXISTS `welcome`;
+CREATE TABLE `welcome` (
+ `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
+ `user_id` 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`)
+) ENGINE=InnoDB DEFAULT CHARSET=utf8
diff --git a/controller/message.go b/controller/message.go
index 012fbba..bc6ea5e 100644
--- a/controller/message.go
+++ b/controller/message.go
@@ -2,9 +2,15 @@ package controller
import (
"encoding/json"
+ "fmt"
"github.com/gin-gonic/gin"
"github.com/gorilla/websocket"
+ "github.com/taoshihan1991/imaptool/config"
"github.com/taoshihan1991/imaptool/models"
+ "github.com/taoshihan1991/imaptool/tools"
+ "os"
+ "path"
+ "strings"
"time"
)
// @Summary 发送消息接口
@@ -106,3 +112,39 @@ func SendMessage(c *gin.Context) {
"msg": "ok",
})
}
+func UploadImg(c *gin.Context){
+ config:=config.CreateConfig()
+ f, err := c.FormFile("imgfile")
+ if err != nil {
+ c.JSON(200, gin.H{
+ "code": 400,
+ "msg": "上传失败!",
+ })
+ return
+ } else {
+
+ fileExt:=strings.ToLower(path.Ext(f.Filename))
+ if fileExt!=".png"&&fileExt!=".jpg"&&fileExt!=".gif"&&fileExt!=".jpeg"{
+ c.JSON(200, gin.H{
+ "code": 400,
+ "msg": "上传失败!只允许png,jpg,gif,jpeg文件",
+ })
+ return
+ }
+ fileName:=tools.Md5(fmt.Sprintf("%s%s",f.Filename,time.Now().String()))
+ fildDir:=fmt.Sprintf("%s%d%s/",config.Upload,time.Now().Year(),time.Now().Month().String())
+ isExist,_:=tools.IsFileExist(fildDir)
+ if !isExist{
+ os.Mkdir(fildDir,os.ModePerm)
+ }
+ filepath:=fmt.Sprintf("%s%s%s",fildDir,fileName,fileExt)
+ c.SaveUploadedFile(f, filepath)
+ c.JSON(200, gin.H{
+ "code": 200,
+ "msg": "上传成功!",
+ "result":gin.H{
+ "path":filepath,
+ },
+ })
+ }
+}
diff --git a/controller/notice.go b/controller/notice.go
index e0010d1..2600cda 100644
--- a/controller/notice.go
+++ b/controller/notice.go
@@ -15,18 +15,25 @@ func GetNotice(c *gin.Context) {
kefuId:=c.Query("kefu_id")
lang,_:=c.Get("lang")
language:=config.CreateLanguage(lang.(string))
-
+ welcome:=models.FindWelcomeByUserId(kefuId)
user:=models.FindUser(kefuId)
- info:=make(map[string]interface{})
- info["nickname"]=user.Nickname
- info["avator"]=user.Avator
- info["name"]=user.Name
- info["content"]=language.Notice
- info["time"]=time.Now().Format("2006-01-02 15:04:05")
+ var content string
+ log.Println(welcome)
+ if welcome.Content!=""{
+ content=welcome.Content
+ }else {
+ content=language.Notice
+ }
c.JSON(200, gin.H{
"code": 200,
"msg": "ok",
- "result":info,
+ "result":gin.H{
+ "nickname":user.Nickname,
+ "avator":user.Avator,
+ "name":user.Name,
+ "content":content,
+ "time":time.Now().Format("2006-01-02 15:04:05"),
+ },
})
}
var upgrader = websocket.Upgrader{}
diff --git a/controller/tcp.go b/controller/tcp.go
index 9d53129..6b03cab 100644
--- a/controller/tcp.go
+++ b/controller/tcp.go
@@ -27,7 +27,8 @@ func NewTcpServer(tcpBaseServer string){
}
func PushServerTcp(str []byte){
for ip,conn:=range clientTcpList{
- _,err:=conn.Write(str)
+ line:=append(str,[]byte("\r\n")...)
+ _,err:=conn.Write(line)
log.Println(ip,err)
if err!=nil{
conn.Close()
@@ -43,6 +44,10 @@ func DeleteOnlineTcp(c *gin.Context) {
conn.Close()
delete(clientTcpList,ip)
}
+ if ip=="all"{
+ conn.Close()
+ delete(clientTcpList,ipkey)
+ }
}
c.JSON(200, gin.H{
"code": 200,
diff --git a/main.go b/main.go
index 900ac89..d8dc88c 100644
--- a/main.go
+++ b/main.go
@@ -53,6 +53,7 @@ func main() {
engine := gin.Default()
engine.LoadHTMLGlob("static/html/*")
engine.Static("/static", "./static")
+
//首页
engine.GET("/", controller.Index)
engine.GET("/index", tmpl.PageIndex)
@@ -60,6 +61,7 @@ func main() {
engine.GET("/login", tmpl.PageLogin)
//咨询界面
engine.GET("/chat_page",middleware.SetLanguage, tmpl.PageChat)
+ engine.GET("/chatIndex",middleware.SetLanguage, tmpl.PageChat)
//登陆验证
engine.POST("/check", controller.LoginCheckPass)
//框架界面
@@ -74,6 +76,8 @@ func main() {
engine.GET("/messages", controller.GetVisitorMessage)
//发送单条消息
engine.POST("/message",controller.SendMessage)
+ //上传文件
+ engine.POST("/uploadimg",controller.UploadImg)
//获取未读消息数
engine.GET("/message_status",controller.GetVisitorMessage)
//设置消息已读
diff --git a/models/welcomes.go b/models/welcomes.go
new file mode 100644
index 0000000..ea3979f
--- /dev/null
+++ b/models/welcomes.go
@@ -0,0 +1,16 @@
+package models
+
+import "time"
+
+type Welcome struct {
+ ID uint `gorm:"primary_key" json:"id"`
+ UserId string `json:"user_id"`
+ Content string `json:"content"`
+ IsDefault uint `json:"is_default"`
+ Ctime time.Time `json:"ctime"`
+}
+func FindWelcomeByUserId(userId interface{})Welcome{
+ var w Welcome
+ DB.Where("user_id = ? and is_default=?", userId,1).First(&w)
+ return w
+}
\ No newline at end of file
diff --git a/static/css/common.css b/static/css/common.css
index ada3d0a..dd49ca7 100644
--- a/static/css/common.css
+++ b/static/css/common.css
@@ -1,15 +1,21 @@
+*{padding:0;margin:0}
.floatRight{float: right;}
.clear{clear: both;}
.faceBtn, .faceBtn:after, .faceBtn {
border: 1px solid;
}
+.iconBtns{
+ border-top:1px solid #e4e4e4;
+ border-bottom:1px solid #e4e4e4;
+ padding: 2px 0;
+}
.visitorFaceBtn{
- float: right;
- margin: 16px 4px 0 0;
+ float: left;
+ margin-left: 5px;
}
.visitorFaceBox{
position: absolute;
- bottom: 70px;
+ bottom: 86px;
}
.kefuFaceBox{
position: absolute;
@@ -68,6 +74,52 @@
top: 10%;
width: 15px;
}
+.imageBtn {
+ width: 32px;
+ height: 23px;
+ overflow: hidden;
+ display: inline-block;
+ vertical-align: middle;
+ position: relative;
+ font-style: normal;
+ color: #9da0a0;
+ text-align: left;
+ text-indent: -9999px;
+ direction: ltr;
+ border: 1px solid;
+}
+.imageBtn:before {
+ content: '';
+ position: absolute;
+ width: 17px;
+ height: 16px;
+ left: -2px;
+ top: 10px;
+ -webkit-transform: rotate(45deg);
+ -moz-transform: rotate(45deg);
+ -ms-transform: rotate(45deg);
+ -o-transform: rotate(45deg);
+ transform: rotate(45deg);
+ box-shadow: inset 0 0 0 32px, 10px -6px 0 0;
+}
+.imageBtn:after {
+ content: '';
+ -webkit-border-radius: 50%;
+ -moz-border-radius: 50%;
+ -o-border-radius: 50%;
+ border-radius: 50%;
+ position: absolute;
+ width: 3px;
+ height: 3px;
+ box-shadow: inset 0 0 0 32px;
+ top: 5px;
+ right: 5px
+}
+.visitorImageBtn{
+ float: left;
+ margin-left: 20px;
+ margin-top: 2px;
+}
.faceBox{
width: 100%;
background: #fff;
diff --git a/static/html/chat_main.html b/static/html/chat_main.html
index 9d17d0b..de8df31 100644
--- a/static/html/chat_main.html
+++ b/static/html/chat_main.html
@@ -132,6 +132,7 @@
© 2020
- - -陶士涵版权所有 © 2020
+