修复表结构问题

pull/30/head
陶士涵 4 years ago
parent f3a6d08f53
commit fac200d3f9

@ -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, '管理员', '*', '*');

@ -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"`
}

@ -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{

Loading…
Cancel
Save