列出每日访客接待情况统计

master
taoshihan 1 year ago
parent 2d0bac9d1b
commit 0f63c824fd

@ -0,0 +1,36 @@
package controller
import (
"github.com/gin-gonic/gin"
"github.com/taoshihan1991/imaptool/models"
"github.com/taoshihan1991/imaptool/tools"
"time"
)
func GetChartStatistic(c *gin.Context) {
kefuName, _ := c.Get("kefu_name")
dayNumMap := make(map[string]string)
result := models.CountVisitorsEveryDay(kefuName.(string))
for _, item := range result {
dayNumMap[item.Day] = tools.Int2Str(item.Num)
}
nowTime := time.Now()
list := make([]map[string]string, 0)
for i := 0; i > -46; i-- {
getTime := nowTime.AddDate(0, 0, i) //年,月,日 获取一天前的时间
resTime := getTime.Format("06-01-02") //获取的时间的格式
tmp := make(map[string]string)
tmp["day"] = resTime
tmp["num"] = dayNumMap[resTime]
list = append(list, tmp)
}
c.JSON(200, gin.H{
"code": 200,
"msg": "ok",
"result": list,
})
}

@ -99,3 +99,17 @@ func CountVisitorsByKefuId(kefuId string) uint {
DB.Model(&Visitor{}).Where("to_id=?", kefuId).Count(&count)
return count
}
//查询每天条数
type EveryDayNum struct {
Day string `json:"day"`
Num int64 `json:"num"`
}
func CountVisitorsEveryDay(toId string) []EveryDayNum {
var results []EveryDayNum
DB.Raw("select DATE_FORMAT(created_at,'%y-%m-%d') as day ,"+
"count(*) as num from visitor where to_id=? group by day order by day desc limit 30",
toId).Scan(&results)
return results
}

@ -3,26 +3,24 @@
当前项目仅供个人学习测试,禁止一切线上商用行为,禁止一切违法使用!!!
### <b>GOFLY</b> 基于Golang语言和MySQL实现的WEB在线客服系统。
<a href="readme.md">中文</a> |
<a href="readme_en.md">English</a> |
<a href="https://gitee.com/taoshihan/go-fly">Gitee</a>
### 前言
### 项目简介
此项目源于2019年学习golang时的练习作品主要使用了gin + jwt-go + websocket + go.uuid + gorm + cobra + VueJS + ElementUI + MySQL等技术
Golang语言开源客服系统主要使用了gin + jwt-go + websocket + go.uuid + gorm + cobra + VueJS + ElementUI + MySQL等技术
### 安装使用
#### 1. 先安装和运行mysql >=5.5版本 , 创建gofly数据库.
* 先安装和运行mysql数据库 ,版本>=5.5 ,创建数据库
create database gofly charset utf8;
```
create database gofly charset utf8mb4;
```
在config目录mysql.json中配置数据库
* 配置数据库链接信息在config目录mysql.json中
```php
{
"Server":"127.0.0.1",
@ -32,130 +30,44 @@
"Password":"go-fly"
}
```
#### 2. 源码运行
1. 基于go module使用
* 安装配置Golang运行环境请参照下面的命令去执行
```php
wget https://studygolang.com/dl/golang/go1.20.2.linux-amd64.tar.gz
tar -C /usr/local -xvf go1.20.2.linux-amd64.tar.gz
mv go1.20.2.linux-amd64.tar.gz /tmp
echo "PATH=\$PATH:/usr/local/go/bin" >> /etc/profile
echo "PATH=\$PATH:/usr/local/go/bin" >> ~/.bashrc
source /etc/profile
go version
go env -w GO111MODULE=on
go env -w GOPROXY=https://goproxy.cn,direct
```
* 下载代码
go env -w GO111MODULE=on
go env -w GOPROXY=https://goproxy.cn,direct
在任意目录 git clone https://github.com/taoshihan1991/go-fly.git
进入go-fly 目录
在任意目录 git clone https://github.com/taoshihan1991/go-fly.git
进入go-fly 目录
2. 导入数据库 go run go-fly.go install
* 导入数据库 go run go-fly.go install
3. 源码运行 go run go-fly.go server
* 源码运行 go run go-fly.go server
3. 源码打包 go build -o kefu 会生成kefu可以执行文件
* 源码打包 go build -o kefu 会生成kefu可以执行文件
* 二进制文件运行
5. 二进制文件运行
linux: ./kefu server [可选 -p 8082 -d]
windows: kefu.exe server [可选 -p 8082 -d]
6. 关闭程序
killall kefu
### nginx部署
访问https://gofly.sopans.com
* 关闭程序
1.参考支持https的部署示例 , 注意反向代理的端口号和证书地址 , 不使用https也可以访问 , 只是不会有浏览器通知弹窗
2.尽量按照下面的配置处理, 配置独立域名或者二级域名, 不建议在主域名加端口访问, 不建议主域名加目录访问
3.<del>如果遇到域名跨域错误问题, 检查下面配置中add_header Access-Control-Allow-Origin这俩header头是否添加.</del>
代码里已经解决跨域 , nginx里不要加跨域头,否则会冲突报错
killall kefu
```php
server {
listen 443 ssl http2;
ssl on;
ssl_certificate conf.d/cert/4263285_gofly.sopans.com.pem;
ssl_certificate_key conf.d/cert/4263285_gofly.sopans.com.key;
ssl_session_timeout 5m;
ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:ECDHE:ECDH:AES:HIGH:!NULL:!aNULL:!MD5:!ADH:!RC4;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
ssl_prefer_server_ciphers on;
#listen 80;
server_name gofly.sopans.com;
access_log /var/log/nginx/gofly.sopans.com.access.log main;
location /static {
root /var/www/html/go-fly;//自己的部署路径,静态文件直接nginx响应
}
location / {
proxy_pass http://127.0.0.1:8081;
proxy_http_version 1.1;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_set_header Origin "";
}
}
server{
listen 80;
server_name gofly.sopans.com;
access_log /var/log/nginx/gofly.sopans.com.access.log main;
location /static {
root /var/www/html/go-fly;//自己的部署路径,静态文件直接nginx响应
}
location / {
proxy_pass http://127.0.0.1:8081;
proxy_http_version 1.1;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_set_header Origin "";
}
}
```
### 宝塔部署
原文地址https://www.zqcnc.cn/post/99.html
#### 宝塔环境
1. 创建一个静态站点,地址为想要访问的域名
![](https://i.aweoo.com/imgs/2021/03/9662692b88b802f9.png)
2. 为该站点配置证书
![](https://i.aweoo.com/imgs/2021/03/9c2f91a215d37b2f.png)
3. 设置反向代理
![](https://i.aweoo.com/imgs/2021/03/61cdce0167949ff4.png)
4. 修改反代配置
![](https://i.aweoo.com/imgs/2021/03/2a5aa9783afa9a19.png)
**按照图示,将对应代码加入到配置文件中**
```shell
#PROXY-START/
location /
{
proxy_pass http://127.0.0.1:8081;
proxy_http_version 1.1;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header REMOTE-HOST $remote_addr;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_set_header Origin "";
add_header X-Cache $upstream_cache_status;
#Set Nginx Cache
add_header Cache-Control no-cache;
expires 12h;
}
#PROXY-END/
```
程序正常运行后监听端口8081可以直接ip+端口8081访问
也可以配置域名访问反向代理到8081端口就能隐藏端口号
### 版权声明

@ -70,7 +70,7 @@ func InitApiRouter(engine *gin.Engine) {
engine.GET("/about", controller.GetAbout)
engine.POST("/about", middleware.JwtApiMiddleware, middleware.RbacAuth, controller.PostAbout)
engine.GET("/aboutpages", middleware.JwtApiMiddleware, middleware.RbacAuth, controller.GetAbouts)
engine.GET("/notice",controller.GetNotice)
engine.GET("/notice", controller.GetNotice)
engine.POST("/ipblack", middleware.JwtApiMiddleware, middleware.Ipblack, controller.PostIpblack)
engine.DELETE("/ipblack", middleware.JwtApiMiddleware, middleware.RbacAuth, controller.DelIpblack)
engine.GET("/ipblacks_all", middleware.JwtApiMiddleware, controller.GetIpblacks)
@ -82,10 +82,16 @@ func InitApiRouter(engine *gin.Engine) {
engine.GET("/replys", middleware.JwtApiMiddleware, controller.GetReplys)
engine.POST("/reply", middleware.JwtApiMiddleware, middleware.RbacAuth, controller.PostReply)
engine.POST("/reply_content", middleware.JwtApiMiddleware, middleware.RbacAuth, controller.PostReplyContent)
engine.POST("/reply_content_save", middleware.JwtApiMiddleware, controller.PostReplyContentSave)
engine.POST("/reply_content_save", middleware.JwtApiMiddleware, controller.PostReplyContentSave)
engine.DELETE("/reply_content", middleware.JwtApiMiddleware, middleware.RbacAuth, controller.DelReplyContent)
engine.DELETE("/reply", middleware.JwtApiMiddleware, middleware.RbacAuth, controller.DelReplyGroup)
engine.POST("/reply_search", middleware.JwtApiMiddleware, controller.PostReplySearch)
//客服路由分组
kefuGroup := engine.Group("/kefu")
kefuGroup.Use(middleware.JwtApiMiddleware)
{
kefuGroup.GET("/chartStatistics", controller.GetChartStatistic)
}
//微信接口
engine.GET("/micro_program", middleware.JwtApiMiddleware, controller.GetCheckWeixinSign)
}

@ -8,15 +8,13 @@ import (
func InitViewRouter(engine *gin.Engine) {
engine.GET("/", tmpl.PageIndex)
engine.GET("/index_:lang", tmpl.PageIndex)
engine.GET("/install", tmpl.PageInstall)
engine.GET("/detail_:page",tmpl.PageDetail)
engine.GET("/login", tmpl.PageLogin)
engine.GET("/bind", tmpl.PageBind)
engine.GET("/chatIndex",tmpl.PageChat)
engine.GET("/pannel", tmpl.PagePannel)
engine.GET("/chatIndex", tmpl.PageChat)
engine.GET("/main", middleware.JwtPageMiddleware, tmpl.PageMain)
engine.GET("/chat_main", middleware.JwtPageMiddleware,middleware.DomainLimitMiddleware, tmpl.PageChatMain)
engine.GET("/setting",middleware.DomainLimitMiddleware, tmpl.PageSetting)
engine.GET("/chat_main", middleware.JwtPageMiddleware, middleware.DomainLimitMiddleware, tmpl.PageChatMain)
engine.GET("/setting", middleware.DomainLimitMiddleware, tmpl.PageSetting)
engine.GET("/setting_statistics", tmpl.PageSettingStatis)
engine.GET("/setting_indexpage", tmpl.PageSettingIndexPage)
engine.GET("/setting_indexpages", tmpl.PageSettingIndexPages)

@ -481,6 +481,10 @@ a{color: #07a9fe;text-decoration: none;}
.menuLeftItem span {
font-size: 12px;
}
.menuLeftItemLogout {
position: absolute;
bottom: 0px;
}
.mainRight {
width: calc(100% - 70px);
height: 100%;

File diff suppressed because one or more lines are too long

@ -5,9 +5,9 @@
<el-avatar class="mainLogo" title="智能客服" :size="45" src="/static/images/1.jpg"></el-avatar>
</el-badge>
</div>
<div style="display: none" class="menuLeftItem" v-on:click="openIframeUrl('/mainGuide')">
<i class="el-icon-house"></i>
<span slot="title">首页</span>
<div class="menuLeftItem" v-on:click="openIframeUrl('/pannel')">
<i class="el-icon-platform-eleme"></i>
<span slot="title">面板</span>
</div>
<div class="menuLeftItem active" v-on:click="haveNewMessage='';openIframeUrl('/chat_main')">
@ -30,15 +30,6 @@
</div>
<div style="display: none" class="menuLeftItem" v-on:click="openIframeUrl('/setting_welcome')">
<i class="el-icon-timer"></i>
<span slot="title">欢迎</span>
</div>
<div style="display: none" class="menuLeftItem" v-on:click="openIframeUrl('/setting')">
<i class="el-icon-menu"></i>
<span slot="title">菜单</span>
</div>
<div class="menuLeftItem menuLeftItemLogout" v-on:click="logout()">
<i class="el-icon-switch-button"></i>

@ -0,0 +1,15 @@
{{template "header" }}
<div id="app" style="width:100%;background: #eef0f6">
<template>
<div style="background: #fff;margin: 10px;padding: 10px" id="visitorNums">
</div>
</template>
</div>
</body>
<script src="/static/js/echarts.min.js?v=1.0.0"></script>
<script>
const ACTION="pannel";
</script>
{{template "setting_bottom" .}}

@ -10,5 +10,4 @@
</div>
</body>
{{template "setting_bottom" .}}

@ -1,6 +1,8 @@
{{define "setting_bottom"}}
<script>
var ACTION="{{.action}}";
if (typeof ACTION=="undefined"){
ACTION="{{.action}}";
}
</script>
<script>
var app=new Vue({
@ -244,6 +246,9 @@
_this.kefuInfo=result;
});
}
if(ACTION=="pannel"){
this.showStatistics();
}
},
sendAjax(url,method,params,callback){
let _this=this;
@ -471,13 +476,52 @@
}
return isLt2M;
},
//生成部署js
createDeployJs(){
let domain=window.location.host;
this.$alert(' <script type="text/javascript">\n' +
' var GOFLY_KEFU_ID="'+this.kefuForm.name+'";\n' +
' <\/script>\n'+
' <script type="text/javascript" src="http://'+domain+'/webjs"><\/script>', '');
//展示图表
showStatistics(){
let _this=this;
this.sendAjax("/kefu/chartStatistics","get",{},function(data) {
var result=data;
var days=[];
var nums=[];
if(result.length<=0){
return;
}
for(var i=result.length-1;i>=0;i--){
days.push(result[i].day);
nums.push(result[i].num)
}
// 基于准备好的dom初始化echarts实例
$(function () {
var myChart = echarts.init($('#visitorNums')[0],null, {
width: document.documentElement.clientWidth,
height: 500
});
// 指定图表的配置项和数据
var option = {
title: {
text: "每日访客接待情况"
},
tooltip: {},
legend: {
data: ['数量']
},
xAxis: {
data: days
},
yAxis: {},
series: [
{
name: 'nums',
type: 'line',
data: nums,
barCategoryGap: '40%',
}
]
};
// 使用刚指定的配置项和数据显示图表。
myChart.setOption(option);
});
});
},
GetRequest() {
var str = location.href

@ -49,8 +49,7 @@ func PageIndex(c *gin.Context) {
if noExist, _ := tools.IsFileNotExist("./install.lock"); noExist {
c.Redirect(302, "/install")
}
c.HTML(http.StatusOK, "index.html", gin.H{
})
c.HTML(http.StatusOK, "index.html", gin.H{})
}
//登陆界面
@ -73,3 +72,8 @@ func PageInstall(c *gin.Context) {
}
c.HTML(http.StatusOK, "install.html", nil)
}
//面板界面
func PagePannel(c *gin.Context) {
c.HTML(http.StatusOK, "pannel.html", nil)
}

@ -58,3 +58,6 @@ func NilChannel() {
var ch chan int
ch <- 1
}
func Int2Str(i interface{}) string {
return fmt.Sprintf("%v", i)
}

Loading…
Cancel
Save