From fac200d3f9b13a068042b20a0bafb241bc970be8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=99=B6=E5=A3=AB=E6=B6=B5?= <630892807@qq.com> Date: Sat, 5 Sep 2020 11:01:11 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E8=A1=A8=E7=BB=93=E6=9E=84?= =?UTF-8?q?=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- config/go-fly.sql | 12 ++++++------ models/user_roles.go | 1 + models/users.go | 2 +- 3 files changed, 8 insertions(+), 7 deletions(-) diff --git a/config/go-fly.sql b/config/go-fly.sql index 82a3eb1..3aa43ee 100644 --- a/config/go-fly.sql +++ b/config/go-fly.sql @@ -53,25 +53,25 @@ CREATE TABLE `message` ( DROP TABLE IF EXISTS `user_role`; CREATE TABLE `user_role` ( - `id` int(11) NOT NULL AUTO_INCREMENT, + `id` int(11) NOT NULL AUTO_INCREMENT, `user_id` int(11) NOT NULL DEFAULT '0', `role_id` int(11) NOT NULL DEFAULT '0', PRIMARY KEY (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8; INSERT INTO `user_role` (`id`, `user_id`, `role_id`) VALUES (1, 1, 1), -(2, 2, 2), -(3, 3, 1); +(2, 2, 2) DROP TABLE IF EXISTS `role`; CREATE TABLE `role` ( - `id` int(11) NOT NULL, + `id` int(11) unsigned NOT NULL AUTO_INCREMENT, `name` varchar(100) NOT NULL DEFAULT '', `method` varchar(100) NOT NULL DEFAULT '', - `path` varchar(2048) NOT NULL DEFAULT '' + `path` varchar(2048) NOT NULL DEFAULT '', + PRIMARY KEY (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8; INSERT INTO `role` (`id`, `name`, `method`, `path`) VALUES -(1, '普通客服', 'GET,POST', '/kefuinfo,/kefulist'), +(1, '普通客服', 'GET', '/kefuinfo,/kefulist,/roles'), (2, '管理员', '*', '*'); diff --git a/models/user_roles.go b/models/user_roles.go index a734923..d74e85a 100644 --- a/models/user_roles.go +++ b/models/user_roles.go @@ -5,6 +5,7 @@ import ( ) type User_role struct{ + ID uint `gorm:"primary_key" json:"id"` UserId string `json:"user_id"` RoleId uint `json:"role_id"` } diff --git a/models/users.go b/models/users.go index 66ca2a0..d1e479a 100644 --- a/models/users.go +++ b/models/users.go @@ -48,7 +48,7 @@ func DeleteUserById(id string){ } func FindUsers()[]User{ var users []User - DB.Select("user.*,role.name role_name").Joins("join user_role on user.id=user_role.user_id").Joins("join role on user_role.role_id=role.id").Order("user.id desc").Find(&users) + DB.Select("user.*,role.name role_name").Joins("left join user_role on user.id=user_role.user_id").Joins("left join role on user_role.role_id=role.id").Order("user.id desc").Find(&users) return users } func FindUserRole(query interface{},id interface{})User{