1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798 |
- package restful
- import (
- "fmt"
- "github.com/astaxie/beego/logs"
- )
- type User struct {
- Id int `xorm:"not null pk autoincr INT(10)"`
- Username string `xorm:"default '''' comment('账号') VARCHAR(50)"`
- Password string `xorm:"default '''' comment('密码') VARCHAR(50)"`
- Empid int `xorm:"default -1 INT(11)"`
- Sort int `xorm:"default 0 INT(11)"`
- Enable int `xorm:"default 1 TINYINT(4)"`
- CreatedOn int `xorm:"default NULL comment('创建时间') INT(11)"`
- ModifiedOn int `xorm:"default NULL comment('更新时间') INT(11)"`
- DeletedOn int `xorm:"default 0 comment('删除时间戳') INT(11)"`
- }
- /*
- type UserRole struct {
- Id int `xorm:"not null pk autoincr INT(10)"`
- UserId int `xorm:"default NULL comment('用户ID') INT(11)"`
- RoleId int `xorm:"default NULL comment('角色ID') INT(11)"`
- DeletedOn int `xorm:"default 0 comment('删除时间戳') INT(11)"`
- }
- type Role struct {
- Id int `xorm:"not null pk autoincr INT(10)"`
- Name string `xorm:"default '''' comment('名字') VARCHAR(50)"`
- Sort int `xorm:"default 0 INT(11)"`
- Enable int `xorm:"default 1 TINYINT(4)"`
- CreatedOn int `xorm:"default NULL comment('创建时间') INT(11)"`
- ModifiedOn int `xorm:"default NULL comment('更新时间') INT(11)"`
- DeletedOn int `xorm:"default 0 comment('删除时间戳') INT(11)"`
- }
- */
- func CheckUser(username, password string) (bool, error) {
- tqueryData, err := Dbs.Queryx("SELECT * FROM `user` WHERE `username` = ? and password = ? and `enable` >0 ", username, password)
- if err != nil {
- logs.Error(err)
- return false, err
- }
- valuesMap, err := rows2mapObjects(tqueryData)
- if err != nil || len(valuesMap) == 0 {
- logs.Error(err)
- return false, err
- }
- //if len(valuesMap) > 0 {
- //return true, nil
- //}
- return true, nil
- }
- func GetUserInfo(username string) map[string]interface{} {
- valuesMap := make([]map[string]interface{}, 1)
- valuesMap2 := make([]map[string]interface{}, 1)
- tqueryData, err := Dbs.Queryx("SELECT * FROM `user` WHERE `username` = ? and `enable` >0 ", username)
- if err != nil {
- fmt.Println(err)
- return nil
- }
- valuesMap, err = rows2mapObjects(tqueryData)
- if err != nil {
- return nil
- }
- if len(valuesMap) > 0 {
- tqueryData2, err := Dbs.Queryx("SELECT r.`name`,r.`id` FROM `user` u JOIN `user_role` ur ON u.`id`=ur.`user_id` JOIN `role` r ON r.id=ur.`role_id` WHERE r.`enable`>0 AND u.username=?", username)
- if err == nil {
- valuesMap2, err = rows2mapObjects(tqueryData2)
- if err == nil {
- valuesMap[0]["role"] = valuesMap2
- }
- }
- return valuesMap[0]
- }
- return nil
- }
- func GetUserVendor(username string) int64 {
- tqueryData, err := Dbs.Queryx(`SELECT
- ifnull(pa.vendor,0) vendor
- FROM
- emp e
- INNER JOIN USER u ON e.id = u.empid
- INNER JOIN department d ON e.deptid = d.id
- INNER join pasture pa on pa.id = d.pastureid
- WHERE
- u.username = ?`, username)
- if err == nil {
- valuesMap, err := rows2mapObjects(tqueryData)
- if err == nil {
- return valuesMap[0]["vendor"].(int64)
- }
- }
- return -1
- }
|