兼容mysql5.5+

pull/23/head 0.3.1
taoshihan1991 4 years ago
parent ad34f560ed
commit e2f20a0f69

@ -5,7 +5,7 @@ CREATE TABLE `user` (
`password` varchar(50) NOT NULL DEFAULT '', `password` varchar(50) NOT NULL DEFAULT '',
`nickname` varchar(50) NOT NULL DEFAULT '', `nickname` varchar(50) NOT NULL DEFAULT '',
`created_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, `created_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
`updated_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, `updated_at` timestamp,
`deleted_at` timestamp NULL DEFAULT NULL, `deleted_at` timestamp NULL DEFAULT NULL,
`avator` varchar(100) NOT NULL DEFAULT '', `avator` varchar(100) NOT NULL DEFAULT '',
PRIMARY KEY (`id`), PRIMARY KEY (`id`),
@ -24,7 +24,7 @@ CREATE TABLE `visitor` (
`source_ip` varchar(50) NOT NULL DEFAULT '', `source_ip` varchar(50) NOT NULL DEFAULT '',
`to_id` varchar(50) NOT NULL DEFAULT '', `to_id` varchar(50) NOT NULL DEFAULT '',
`created_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, `created_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
`updated_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, `updated_at` timestamp,
`deleted_at` timestamp NULL DEFAULT NULL, `deleted_at` timestamp NULL DEFAULT NULL,
`visitor_id` varchar(100) NOT NULL DEFAULT '', `visitor_id` varchar(100) NOT NULL DEFAULT '',
`status` tinyint(4) NOT NULL DEFAULT '0', `status` tinyint(4) NOT NULL DEFAULT '0',
@ -44,7 +44,7 @@ CREATE TABLE `message` (
`visitor_id` varchar(100) NOT NULL DEFAULT '', `visitor_id` varchar(100) NOT NULL DEFAULT '',
`content` varchar(2048) NOT NULL DEFAULT '', `content` varchar(2048) NOT NULL DEFAULT '',
`created_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, `created_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
`updated_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, `updated_at` timestamp,
`deleted_at` timestamp NULL DEFAULT NULL, `deleted_at` timestamp NULL DEFAULT NULL,
`mes_type` enum('kefu','visitor') NOT NULL DEFAULT 'visitor', `mes_type` enum('kefu','visitor') NOT NULL DEFAULT 'visitor',
`status` enum('read','unread') NOT NULL DEFAULT 'unread', `status` enum('read','unread') NOT NULL DEFAULT 'unread',

@ -1,5 +1,7 @@
package models package models
import "time"
type Message struct { type Message struct {
Model Model
KefuId string `json:"kefu_id"` KefuId string `json:"kefu_id"`
@ -31,6 +33,7 @@ func CreateMessage(kefu_id string, visitor_id string, content string, mes_type s
MesType: mes_type, MesType: mes_type,
Status: "unread", Status: "unread",
} }
v.UpdatedAt = time.Now()
DB.Create(v) DB.Create(v)
} }
func FindMessageByVisitorId(visitor_id string) []Message { func FindMessageByVisitorId(visitor_id string) []Message {

@ -2,6 +2,7 @@ package models
import ( import (
_ "github.com/jinzhu/gorm/dialects/mysql" _ "github.com/jinzhu/gorm/dialects/mysql"
"time"
) )
type User struct { type User struct {
@ -21,6 +22,7 @@ func CreateUser(name string, password string, avator string, nickname string) ui
Avator: avator, Avator: avator,
Nickname: nickname, Nickname: nickname,
} }
user.UpdatedAt = time.Now()
DB.Create(user) DB.Create(user)
return user.ID return user.ID
} }
@ -30,6 +32,7 @@ func UpdateUser(id string, name string, password string, avator string, nickname
Avator: avator, Avator: avator,
Nickname: nickname, Nickname: nickname,
} }
user.UpdatedAt = time.Now()
if password != "" { if password != "" {
user.Password = password user.Password = password
} }
@ -39,12 +42,14 @@ func UpdateUserPass(name string, pass string) {
user := &User{ user := &User{
Password: pass, Password: pass,
} }
user.UpdatedAt = time.Now()
DB.Model(user).Where("name = ?", name).Update("Password", pass) DB.Model(user).Where("name = ?", name).Update("Password", pass)
} }
func UpdateUserAvator(name string, avator string) { func UpdateUserAvator(name string, avator string) {
user := &User{ user := &User{
Avator: avator, Avator: avator,
} }
user.UpdatedAt = time.Now()
DB.Model(user).Where("name = ?", name).Update("Avator", avator) DB.Model(user).Where("name = ?", name).Update("Avator", avator)
} }
func FindUser(username string) User { func FindUser(username string) User {

@ -1,5 +1,7 @@
package models package models
import "time"
type Visitor struct { type Visitor struct {
Model Model
Name string `json:"name"` Name string `json:"name"`
@ -33,6 +35,7 @@ func CreateVisitor(name, avator, sourceIp, toId, visitorId, refer, city, clientI
ClientIp: clientIp, ClientIp: clientIp,
Extra: extra, Extra: extra,
} }
v.UpdatedAt = time.Now()
DB.Create(v) DB.Create(v)
} }
func FindVisitorByVistorId(visitorId string) Visitor { func FindVisitorByVistorId(visitorId string) Visitor {
@ -77,6 +80,7 @@ func UpdateVisitor(name, avator, visitorId string, status uint, clientIp string,
Name: name, Name: name,
Avator: avator, Avator: avator,
} }
visitor.UpdatedAt = time.Now()
DB.Model(visitor).Where("visitor_id = ?", visitorId).Update(visitor) DB.Model(visitor).Where("visitor_id = ?", visitorId).Update(visitor)
} }
func UpdateVisitorKefu(visitorId string, kefuId string) { func UpdateVisitorKefu(visitorId string, kefuId string) {

@ -41,7 +41,7 @@
### 安装使用 ### 安装使用
#### 1. 先安装和运行mysql >=5.7版本 , 创建gofly数据库. #### 1. 先安装和运行mysql >=5.5版本 , 创建gofly数据库.
create database gofly charset utf8; create database gofly charset utf8;
@ -181,10 +181,25 @@ server{
} }
``` ```
### 生成文档 ### 更新日志
##### V0.3.1
1.修改在线咨询浮框样式
2.修改数据库时间字段类型,兼容mysql5.5+
##### V0.2.9
1.访客开多个窗口时 , 单点登录关闭旧ws连接
2.访客切换窗口时可以自动重连
3.访客到来时 , http接口和ws接口同时发送给客服上线信息
4.客服后台定时拉取在线访客接口
5.客服后台切换tab拉取在线访客
1. 需要先安装swag
2. 在根目录swag init -g go-fly.go
### 感谢赞助 ### 感谢赞助
2021年02月20日 广西***社 1000元 2021年02月20日 广西***社 1000元

@ -18,15 +18,15 @@
<!--对接客服代码--> <!--对接客服代码,安装完成后更改成自己的域名和IP-->
<script src="/static/js/gofly-front.js?v=1"></script> <script src="https://gofly.sopans.com/static/js/gofly-front.js?v=1"></script>
<script> <script>
var refer=document.referrer; var refer=document.referrer;
if(refer==""){ if(refer==""){
refer="无"; refer="无";
} }
GOFLY.init({ GOFLY.init({
GOFLY_URL:"", GOFLY_URL:"https://gofly.sopans.com",
GOFLY_KEFU_ID: "kefu2", GOFLY_KEFU_ID: "kefu2",
GOFLY_BTN_TEXT: "{{.OnlineChat}}", GOFLY_BTN_TEXT: "{{.OnlineChat}}",
GOFLY_LANG:"{{.Lang}}", GOFLY_LANG:"{{.Lang}}",

Loading…
Cancel
Save