diff --git a/app/constant/config.go b/app/constant/config.go index 15868a6..9216f6d 100644 --- a/app/constant/config.go +++ b/app/constant/config.go @@ -23,6 +23,10 @@ package constant +// 使用key加密规则: key=md5(KEY+message) +const GMKEY = "153dc7b62ec637173a4f3f288e252e6c" +const GMURL = "http://192.168.1.81:12001" + // 菜单类型 var MENU_TYPE_LIST = map[int]string{ 0: "菜单", diff --git a/app/controller/set_time.go b/app/controller/set_time.go new file mode 100644 index 0000000..9615876 --- /dev/null +++ b/app/controller/set_time.go @@ -0,0 +1,126 @@ +package controller + +import ( + "easygoadmin/app/constant" + "easygoadmin/app/dto" + "easygoadmin/app/model" + "easygoadmin/app/service" + "easygoadmin/utils" + "easygoadmin/utils/common" + "easygoadmin/utils/gmd5" + "encoding/json" + "fmt" + "github.com/gookit/validate" + "github.com/kataras/iris/v12" + "io/ioutil" + "net/http" + "net/url" +) + +var SetTime = new(SetTimeController) + +type SetTimeController struct{} + +func (c *SetTimeController) Index(ctx iris.Context) { + // 模板布局 + ctx.ViewLayout("public/layout.html") + // 渲染模板 + ctx.View("set_time/index.html") +} + +func (c *SetTimeController) List(ctx iris.Context) { + // 调用获取列表方法 + lists, err := service.SetTime.GetList() + if err != nil { + ctx.JSON(common.JsonResult{ + Code: -1, + Msg: err.Error(), + }) + return + } + // 返回结果集 + ctx.JSON(common.JsonResult{ + Code: 0, + Data: lists, + Msg: "操作成功", + }) +} + +func (c *SetTimeController) Set(ctx iris.Context) { + // 模板布局 + ctx.ViewLayout("public/form.html") + // 渲染模板 + ctx.View("set_time/set.html") +} + +func (c *SetTimeController) SetTime(ctx iris.Context) { + // 添加对象 + var req dto.SetTimeReq + // 参数绑定 + if err := ctx.ReadForm(&req); err != nil { + ctx.JSON(common.JsonResult{ + Code: -1, + Msg: err.Error(), + }) + return + } + // 参数校验 + v := validate.Struct(&req) + if !v.Validate() { + ctx.JSON(common.JsonResult{ + Code: -1, + Msg: v.Errors.One(), + }) + return + } + + // 调用GM服务 + time := struct { + Time string `json:"time"` + }{ + Time: req.Time, + } + message, err := json.Marshal(time) + pass, err := gmd5.Encrypt(constant.GMKEY + string(message)) + query := url.Values{} + query.Add("pass", pass) + query.Add("message", string(message)) + fmt.Println(query.Encode()) + url := constant.GMURL + "/settime?" + query.Encode() + + resp, err := http.Get(url) + if err != nil { + ctx.JSON(common.JsonResult{ + Code: -2, + Msg: err.Error(), + }) + } + defer resp.Body.Close() + + // 读取数据 + bds, err := ioutil.ReadAll(resp.Body) + if err != nil { + ctx.JSON(common.JsonResult{ + Code: -3, + Msg: err.Error(), + }) + } + var jsonResp model.JsonResp + json.Unmarshal(bds, &jsonResp) + fmt.Println(string(bds)) + if jsonResp.Code == 0 && jsonResp.Message == "success" { + // 写入数据库 + service.SetTime.Add(req, utils.Uid(ctx)) + } else { + ctx.JSON(common.JsonResult{ + Code: -4, + Msg: string(bds), + }) + } + + // 设置成功 + ctx.JSON(common.JsonResult{ + Code: 0, + Msg: "设置成功", + }) +} diff --git a/app/dto/menu.go b/app/dto/menu.go index d77dcca..1cc9b8a 100644 --- a/app/dto/menu.go +++ b/app/dto/menu.go @@ -44,6 +44,7 @@ type MenuAddReq struct { Type int `form:"type"` // 类型:0 菜单 1 节点 Permission string `form:"permission"` // 权限标识 Status string `form:"status" validate:"string"` // 状态:1正常 2禁用 + Hide string `form:"hide" validate:"string"` // 状态:1显示 2隐藏 Target int `form:"target"` // 打开方式:1内部打开 2外部打开 Note string `form:"note"` // 菜单备注 Sort int `form:"sort" validate:"int"` // 显示顺序 @@ -57,6 +58,7 @@ func (v MenuAddReq) Messages() map[string]string { "Pid.int": "请选择上级菜单.", "Type.int": "请选择菜单类型.", "Status.int": "请选择菜单状态.", + "Hide.int": "请选择菜单状显示.", "Sort.int": "排序不能为空.", } } @@ -66,12 +68,13 @@ type MenuUpdateReq struct { Id int `form:"id" validate:"int"` Name string `form:"name" validate:"required"` // 菜单标题 Icon string `form:"icon"` // 图标 - Url string `form:"url" validate:"required"` // URL地址 + Url string `form:"url"` // URL地址 Param string `form:"param"` // 参数 Pid int `form:"pid" validate:"int"` // 上级ID - Type int `form:"type"` // 类型:1模块 2导航 3菜单 4节点 + Type int `form:"type"` // 类型:0 菜单 1 节点 Permission string `form:"permission"` // 权限标识 Status string `form:"status" validate:"string"` // 状态:1正常 2禁用 + Hide string `form:"hide" validate:"string"` // 状态:1显示 2隐藏 Target int `form:"target"` // 打开方式:1内部打开 2外部打开 Note string `form:"note"` // 菜单备注 Sort int `form:"sort" validate:"int"` // 显示顺序 @@ -86,6 +89,7 @@ func (v MenuUpdateReq) Messages() map[string]string { "Pid.int": "请选择上级菜单.", "Type.int": "请选择菜单类型.", "Status.int": "请选择菜单状态.", + "Hide.int": "请选择菜单显示.", "Sort.int": "排序不能为空.", } } diff --git a/app/dto/set_time.go b/app/dto/set_time.go new file mode 100644 index 0000000..5e2b87d --- /dev/null +++ b/app/dto/set_time.go @@ -0,0 +1,18 @@ +package dto + +import ( + "github.com/gookit/validate" +) + +// 添加菜单 +type SetTimeReq struct { + Id string `form:"id"` + Time string `form:"time" validate:"required"` // 时间 +} + +// 添加菜单表单验证 +func (v SetTimeReq) Messages() map[string]string { + return validate.MS{ + "Time.required": "时间不能为空.", + } +} diff --git a/app/middleware/checkauth.go b/app/middleware/checkauth.go index ed4b622..5d40fe4 100644 --- a/app/middleware/checkauth.go +++ b/app/middleware/checkauth.go @@ -42,13 +42,13 @@ func CheckAuth(ctx iris.Context) { urlItem := []string{"/captcha", "/login"} whiteItem := []string{"/", "/main", "/index", "/userInfo", "/updatePwd", "/logout"} if !utils.InStringArray(ctx.Path(), urlItem) && !strings.Contains(ctx.Path(), "static") { - // 判断不在白名里 - if utils.IsLogin(ctx) && !utils.InStringArray(ctx.Path(), whiteItem) { + // 判断不在白名里,判断不是超级管理员 + if !service.IsSuperAdmin(ctx) && utils.IsLogin(ctx) && !utils.InStringArray(ctx.Path(), whiteItem) { // 如果登录了就检查权限 user := service.GetUserInfo(ctx) // 查询该用户的权限列表 val := utils.RedisClient.Get(utils.GetRedisUidKey(user.Id, conf.USER_MENU_LIST)).Val() - mlist := make([]model.Menu, 0, 0) + mlist := make([]model.Menu, 0) json.Unmarshal([]byte(val), &mlist) flag := false for _, v := range mlist { diff --git a/app/model/common.go b/app/model/common.go new file mode 100644 index 0000000..969ee16 --- /dev/null +++ b/app/model/common.go @@ -0,0 +1,7 @@ +package model + +type JsonResp struct { + Code int32 + Message string + Data interface{} +} diff --git a/app/model/set_time.go b/app/model/set_time.go new file mode 100644 index 0000000..f5dc7a0 --- /dev/null +++ b/app/model/set_time.go @@ -0,0 +1,38 @@ +package model + +import ( + "easygoadmin/utils" + "time" +) + +type SetTime struct { + Id int `json:"id" xorm:"not null pk autoincr comment('主键ID') INT(10)"` + Time time.Time `json:"time" xorm:"not null comment('时间') DATETIME"` + CreateUser int `json:"create_user" xorm:"not null default 0 comment('添加人') INT(10)"` + CreateTime time.Time `json:"create_time" xorm:"default 'NULL' comment('添加时间') DATETIME"` +} + +// 根据条件查询单条数据 +func (r *SetTime) Get() (bool, error) { + return utils.XormDb.Get(r) +} + +// 插入数据 +func (r *SetTime) Insert() (int64, error) { + return utils.XormDb.Insert(r) +} + +// 更新数据 +func (r *SetTime) Update() (int64, error) { + return utils.XormDb.Id(r.Id).Update(r) +} + +// 删除 +func (r *SetTime) Delete() (int64, error) { + return utils.XormDb.Id(r.Id).Delete(&Role{}) +} + +//批量删除 +func (r *SetTime) BatchDelete(ids ...int64) (int64, error) { + return utils.XormDb.In("id", ids).Delete(&Role{}) +} diff --git a/app/service/menu.go b/app/service/menu.go index 3462b5d..b36b966 100644 --- a/app/service/menu.go +++ b/app/service/menu.go @@ -27,6 +27,7 @@ import ( "easygoadmin/app/dto" "easygoadmin/app/model" "easygoadmin/app/vo" + "easygoadmin/conf" "easygoadmin/utils" "easygoadmin/utils/gconv" "easygoadmin/utils/gstr" @@ -73,6 +74,11 @@ func (s *menuService) Add(req dto.MenuAddReq, userId int) (int64, error) { } else { entity.Status = 2 } + if req.Hide == "on" { + entity.Hide = 1 + } else { + entity.Hide = 2 + } entity.Note = req.Note entity.Sort = gconv.Int(req.Sort) entity.CreateUser = userId @@ -112,6 +118,11 @@ func (s *menuService) Update(req dto.MenuUpdateReq, userId int) (int64, error) { } else { entity.Status = 2 } + if req.Hide == "on" { + entity.Hide = 1 + } else { + entity.Hide = 2 + } entity.Note = req.Note entity.Sort = gconv.Int(req.Sort) entity.UpdateUser = userId @@ -348,7 +359,7 @@ func (s *menuService) MakeList(data []*vo.MenuTreeNode) map[int]string { // 获取菜单权限列表(Tree) func (s *menuService) GetPermissionMenuTreeList(userId int) interface{} { - if userId == 1 { + if utils.InIntArray(userId, conf.SUPER_ADMIN_USER_IDS) { // 管理员(拥有全部权限) menuList, _ := Menu.GetTreeList() //fmt.Println("菜单列表", menuList) diff --git a/app/service/set_time.go b/app/service/set_time.go new file mode 100644 index 0000000..6fdd5d7 --- /dev/null +++ b/app/service/set_time.go @@ -0,0 +1,38 @@ +package service + +import ( + "easygoadmin/app/dto" + "easygoadmin/app/model" + "easygoadmin/utils" + "errors" +) + +var SetTime = new(SetTimeService) + +type SetTimeService struct{} + +func (s *SetTimeService) GetList() ([]model.SetTime, error) { + // 创建查询实例 + query := utils.XormDb.Where("1=1") + query = query.OrderBy("id desc") + // 查询列表 + var list []model.SetTime + err := query.Find(&list) + return list, err +} + +func (s *SetTimeService) Add(req dto.SetTimeReq, userId int) (int64, error) { + + // 实例化对象 + var entity model.SetTime + entity.Time = utils.TimeStringToTimeTime(req.Time) + entity.CreateUser = userId + entity.CreateTime = utils.GetNowTimeTime() + + // 插入数据 + rows, err := entity.Insert() + if err != nil || rows == 0 { + return 0, errors.New("添加失败") + } + return rows, nil +} diff --git a/app/service/user.go b/app/service/user.go index 2b85afb..7455da8 100644 --- a/app/service/user.go +++ b/app/service/user.go @@ -28,6 +28,7 @@ import ( "easygoadmin/app/dto" "easygoadmin/app/model" "easygoadmin/app/vo" + "easygoadmin/conf" "easygoadmin/utils" "easygoadmin/utils/gconv" "errors" @@ -454,3 +455,12 @@ func GetUserInfo(ctx iris.Context) *model.User { } return info } + +// 是否超级管理员 +func IsSuperAdmin(ctx iris.Context) bool { + uid := utils.Uid(ctx) + if utils.InIntArray(uid, conf.SUPER_ADMIN_USER_IDS) { + return true + } + return false +} diff --git a/conf/common.go b/conf/common.go index 743b106..29aaa6a 100644 --- a/conf/common.go +++ b/conf/common.go @@ -29,6 +29,9 @@ var ( CONFIG Config ) +// 超级管理员 +var SUPER_ADMIN_USER_IDS = []int{1} + // USER_ID 登录用户ID const USER_ID = "userId" const USER_MENU_LIST = "userMenuList" diff --git a/conf/config.yaml b/conf/config.yaml index 0161969..21f5c2e 100644 --- a/conf/config.yaml +++ b/conf/config.yaml @@ -1,10 +1,10 @@ # MySQL 连接配置 mysql: - host: '42.193.50.38' + host: '127.0.0.1' port: 3306 database: 'easygoadmin' - username: 'jerry' - password: 'jerry123' + username: 'root' + password: 'warjary0416' charset: 'utf8mb4' debug: true logLevel: debug @@ -16,11 +16,11 @@ mysql: # Redis缓存 Redis: Network: "tcp" - Addr: "42.193.50.38:9001" + Addr: "127.0.0.1:6379" Timeout: 30 MaxActive: 10 - Password: "jerry123" - Database: 1 + Password: "" + Database: 2 Prefix: "" Delim: "-" @@ -39,7 +39,7 @@ easygoadmin: # 名称 name: "游戏数据中台" # 版本号 - version: "v2.1.0" + version: "v1.0.0" # IP地址 addr: 127.0.0.1 # 端口号 diff --git a/public/static/module/easygoadmin_settime.js b/public/static/module/easygoadmin_settime.js new file mode 100644 index 0000000..6d45ed7 --- /dev/null +++ b/public/static/module/easygoadmin_settime.js @@ -0,0 +1,62 @@ +/** + * GMtool + * @author Jerry + * @since 2022/11/04 + */ +layui.use(['func', 'admin', 'common', "layer", "laydate"], function () { + + //声明变量 + var func = layui.func + , layer = layui.layer + , common = layui.common + , laydate = layui.laydate + , $ = layui.$; + + if (A == 'index') { + //【TABLE列数组】 + var cols = [ + // {type: 'checkbox', fixed: 'left'} + {field: 'id', width: 80, title: 'ID', align: 'center', sort: true, fixed: 'left'} + , {field: 'time', width: 200, title: '设置时间', align: 'center', templet: function (d) { + return "
" + layui.util.toDateString(d.time, 'yyyy-MM-dd HH:mm:ss') + "
" + } + } + , {field: 'create_user', width: 80, title: '创建人', align: 'center'} + , {field: 'create_time', width: 180, title: '添加时间', align: 'center', templet: function (d) { + return "
" + layui.util.toDateString(d.create_time, 'yyyy-MM-dd HH:mm:ss') + "
" + } + } + ]; + + //【渲染TABLE】 + func.tableIns(cols, "tableList", function (layEvent, data) { + + }); + + //【设置弹框】 + func.setWin("设置时间", 500, 350); + + $("#settime").click((function () { + + layer.open({ + type:2 + ,area: ['500px', '450px'] + ,title:'设置时间' + ,content: "/settime/set" + ,maxmin: true + ,btn: [] + ,end: function(index, layero){ + location.reload() + } + }) + })) + } + + if (A == "set") { + //日期时间选择器 + laydate.render({ + elem: '#time' + ,type: 'datetime' + }); + } +}); diff --git a/router/router.go b/router/router.go index 11a9940..14e9a6e 100644 --- a/router/router.go +++ b/router/router.go @@ -264,4 +264,21 @@ func RegisterRouter(app *iris.Application) { generate.Post("/batchGenerate", controller.Generate.BatchGenerate) } + /* GM工具 设置时间 */ + settime := app.Party("settime") + { + settime.Get("/index", controller.SetTime.Index) + settime.Post("/list", controller.SetTime.List) + settime.Get("/set", controller.SetTime.Set) + settime.Post("/settime", controller.SetTime.SetTime) + } + + ///* GM工具 发送邮件 */ + //sendmail := app.Party("sendmail") + //{ + // sendmail.Get("/index", controller.SendMail.Index) + // sendmail.Get("/list", controller.SendMail.List) + // sendmail.Post("/sendmail", controller.SendMail.SendMail) + //} + } diff --git a/utils/utils.go b/utils/utils.go index de4e0a8..ded5f64 100644 --- a/utils/utils.go +++ b/utils/utils.go @@ -263,6 +263,12 @@ func GetNowTimeTime() time.Time { return time } +// TimeStringToTimeTime 获取time.Time类型的 +func TimeStringToTimeTime(t string) time.Time { + time, _ := time.ParseInLocation("2006-01-02 15:04:05", t, time.Local) + return time +} + // GetNowDateTime 获取time.Time类型的 func GetNowDateTime() time.Time { date, _ := time.ParseInLocation("2006-01-02", GetNowDateString(), time.Local) diff --git a/view/menu/edit.html b/view/menu/edit.html index 414fd7d..6af453d 100644 --- a/view/menu/edit.html +++ b/view/menu/edit.html @@ -13,22 +13,20 @@ - -
{{select "type|1|菜单类型|name|id" .typeList .info.Type}}
+
+
{{select "pid|0|上级菜单|name|id" .menuList .info.Pid}}
-
-
@@ -46,7 +44,13 @@
- {{switch "status" "显示|隐藏" .info.Status}} + {{switch "hide" "显示|隐藏" .info.Hide}} +
+
+
+ +
+ {{switch "status" "启用|禁用" .info.Status}}
diff --git a/view/send_mail/mail.html b/view/send_mail/mail.html new file mode 100644 index 0000000..45f4edc --- /dev/null +++ b/view/send_mail/mail.html @@ -0,0 +1,13 @@ + +
+
+
+ +
+ +
+
+
+ {{submit "submit|发送奖励" 1 ""}} +
+ diff --git a/view/set_time/index.html b/view/set_time/index.html new file mode 100644 index 0000000..767e840 --- /dev/null +++ b/view/set_time/index.html @@ -0,0 +1,13 @@ + +
+
+
+ +
+
+
+ + +
diff --git a/view/set_time/set.html b/view/set_time/set.html new file mode 100644 index 0000000..624d43d --- /dev/null +++ b/view/set_time/set.html @@ -0,0 +1,9 @@ +
+
+ +
+ +
+
+ {{submit "submit|立即设置,close|关闭" 1 ""}} +
\ No newline at end of file