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{