123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193 |
- package controllers
- import (
- "bzd_server/conf"
- "bzd_server/lib"
- "bzd_server/models/Account"
- "bzd_server/models/System"
- beego "github.com/beego/beego/v2/server/web"
- "math"
- )
- type UserController struct {
- beego.Controller
- }
- // 获取-
- func (c *UserController) Get() {
- // 验证登录 User_is, User_r
- _,User_is := lib.Verification_Admin(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
- if !User_is {
- c.Data["json"] = lib.JSONS{Code: 302, Msg: "请重新登录!"}
- c.ServeJSON()
- return
- }
- Id, err := c.GetInt("Id")
- if err != nil {
- c.Data["json"] = lib.JSONS{Code: 201, Msg: "Id 错误!"}
- c.ServeJSON()
- return
- }
- r, is := Account.Read_User_ById(Id);
- if !is {
- c.Data["json"] = lib.JSONS{Code: 201, Msg: "Id 错误!"}
- c.ServeJSON()
- return
- }
- c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!",Data: r}
- c.ServeJSON()
- return
- }
- // 列表 -
- func (c *UserController) List() {
- // 验证登录 User_is, User_r
- _,User_is := lib.Verification_Admin(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
- if !User_is {
- c.Data["json"] = lib.JSONS{Code: 302, Msg: "请重新登录!"}
- c.ServeJSON()
- return
- }
- var r_jsons lib.R_JSONS
- page, _ := c.GetInt("page")
- if page < 1 {
- page = 1
- }
- page_z, _ := c.GetInt("page_z")
- if page_z < 1 {
- page_z = conf.Page_size
- }
- T_name := c.GetString("T_name")
- var cnt int64
- List, cnt := Account.Read_User_List(T_name, page, page_z)
- page_size := math.Ceil(float64(cnt) / float64(page_z))
- r_jsons.List = List
- r_jsons.Page = page
- r_jsons.Page_size = int(page_size)
- r_jsons.Pages = lib.Func_page(int64(page), int64(page_size))
- r_jsons.Num = int(cnt)
- c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: r_jsons}
- c.ServeJSON()
- return
- }
- // 添加-
- func (c *UserController) Add() {
- // 验证登录 User_is, User_r
- user_r,User_is := lib.Verification_Admin(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
- if !User_is {
- c.Data["json"] = lib.JSONS{Code: 302, Msg: "请重新登录!"}
- c.ServeJSON()
- return
- }
- T_name := c.GetString("T_name")
- T_user := c.GetString("T_user")
- T_pass := c.GetString("T_pass")
- T_passstr := c.GetString("T_passstr")
- var_ := Account.User{
- T_user: T_user,
- T_name: T_name,
- T_pass: T_pass,
- T_passstr: T_passstr,
- T_State: 1,
- }
- Id, is := Account.Add_User(var_)
- if !is {
- c.Data["json"] = lib.JSONS{Code: 301, Msg: "添加失败!"}
- c.ServeJSON()
- return
- }
- System.Add_UserLogs_T(user_r.T_uuid,"用户管理", "添加", var_)
- c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!",Data: Id}
- c.ServeJSON()
- return
- }
- // 修改-
- func (c *UserController) Up() {
- // 验证登录 User_is, User_r
- user_r,User_is := lib.Verification_Admin(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
- if !User_is {
- c.Data["json"] = lib.JSONS{Code: 302, Msg: "请重新登录!"}
- c.ServeJSON()
- return
- }
- T_name := c.GetString("T_name")
- T_pass := c.GetString("T_pass")
- T_passstr := c.GetString("T_passstr")
- T_State,T_State_err := c.GetInt("T_State")
- T_uuid := c.GetString("T_uuid")
- r, is := Account.Read_User(T_uuid);
- if !is {
- c.Data["json"] = lib.JSONS{Code: 201, Msg: "Id 错误!"}
- c.ServeJSON()
- return
- }
- // .......
- if len(T_name) > 0{
- r.T_name = T_name
- }
- if len(T_pass) > 0{
- r.T_pass = T_pass
- }
- if len(T_passstr) > 0{
- r.T_passstr = T_passstr
- }
- if T_State_err == nil {
- r.T_State = T_State
- }
- // .......
- if !Account.Update_User(r,"T_name","T_pass","T_passstr","T_State") {
- c.Data["json"] = lib.JSONS{Code: 202, Msg: "修改失败!"}
- c.ServeJSON()
- return
- }
- System.Add_UserLogs_T(user_r.T_uuid,"用户管理", "修改", r)
- c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!"}
- c.ServeJSON()
- return
- }
- // 删除-
- func (c *UserController) Del() {
- // 验证登录 User_is, User_r
- user_r,User_is := lib.Verification_Admin(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
- if !User_is {
- c.Data["json"] = lib.JSONS{Code: 302, Msg: "请重新登录!"}
- c.ServeJSON()
- return
- }
- T_uuid := c.GetString("T_uuid")
- if r, is := Account.Read_User(T_uuid); is {
- if !Account.Delete_User(r) {
- c.Data["json"] = lib.JSONS{Code: 202, Msg: "删除失败!"}
- c.ServeJSON()
- return
- }
- System.Add_UserLogs_T(user_r.T_uuid,"用户管理", "删除", r)
- }
- c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!"}
- c.ServeJSON()
- return
- }
|