package controllers import ( "ERP_user/conf" "ERP_user/models/Account" "ERP_user/models/System" beego "github.com/beego/beego/v2/server/web" "gogs.baozhida.cn/zoie/ERP_libs/lib" "math" "time" ) type UserController struct { beego.Controller User Account.User } func (c *UserController) Prepare() { if Account.User_r != nil { c.User = *Account.User_r } } // 验证登录 func (c *UserController) Login_verification() { Admin_user := c.GetString("bzd_username") Admin_pass := c.GetString("bzd_password") err, user_r := Account.Read_User_verification(Admin_user, Admin_pass) if err != nil { c.Data["json"] = lib.JSONS{Code: 202, Msg: "用户名或密码错误!"} } else { User_tokey := Account.Add_Tokey(user_r.T_uuid) c.Ctx.SetCookie("User_tokey", User_tokey, time.Second*60*60) c.Data["json"] = lib.JSONS{Code: 200, Msg: "OK!", Data: User_tokey} System.Add_UserLogs_T(user_r.T_uuid, "用户", "用户登陆", lib.GetUserLoginInfo(c.Ctx)) } c.ServeJSON() return } // -------------------------------------------------------------------------------------------------------------- // 用户列表 func (c *UserController) List() { // 分页参数 初始化 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") T_power := c.GetString("T_power") T_dept, _ := c.GetInt("T_dept") T_dept_leader, _ := c.GetInt("T_dept_leader") T_State, _ := c.GetInt("T_State") R_List, R_cnt := Account.Read_User_List(T_name, T_power, T_dept, T_dept_leader, T_State, page, page_z) var r_jsons lib.R_JSONS r_jsons.Num = R_cnt r_jsons.Data = R_List r_jsons.Page = page r_jsons.Page_size = int(math.Ceil(float64(R_cnt) / float64(page_z))) c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: r_jsons} c.ServeJSON() return } func (c *UserController) Get() { T_uuid := c.GetString("T_uuid") user, err := Account.Read_User_ByT_uuid(T_uuid) if err != nil { c.Data["json"] = lib.JSONS{Code: 202, Msg: "T_uuid Err!"} c.ServeJSON() return } var r_jsons lib.R_JSONS r_jsons.Data = Account.UserToUser_R(user) c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: r_jsons} c.ServeJSON() return } // 个人信息 func (c *UserController) Info() { c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: Account.UserToUser_R(c.User)} c.ServeJSON() return } // 添加用户信息 func (c *UserController) Add() { T_power := c.GetString("T_power") T_name := c.GetString("T_name") T_user := c.GetString("T_user") T_pass := c.GetString("T_pass") T_dept, _ := c.GetInt("T_dept") T_post, _ := c.GetInt("T_post") T_dept_leader, _ := c.GetInt("T_dept_leader") T_sex, _ := c.GetInt("T_sex") T_id_card := c.GetString("T_id_card") T_nation := c.GetString("T_nation") T_school := c.GetString("T_school") T_major := c.GetString("T_major") T_education := c.GetString("T_education") T_phone := c.GetString("T_phone") T_marry, _ := c.GetInt("T_marry") T_spouse_name := c.GetString("T_spouse_name") T_spouse_phone := c.GetString("T_spouse_phone") T_entry_time := c.GetString("T_entry_time") T_positive_time := c.GetString("T_positive_time") T_entry_type := c.GetString("T_entry_type") T_contract_start_time := c.GetString("T_contract_start_time") T_contract_end_time := c.GetString("T_contract_end_time") T_expire, _ := c.GetInt("T_expire") T_remark := c.GetString("T_remark") var_ := Account.User{ T_power: T_power, T_name: T_name, T_user: T_user, T_pass: T_pass, T_dept: T_dept, T_post: T_post, T_dept_leader: T_dept_leader, T_sex: T_sex, T_id_card: T_id_card, T_nation: T_nation, T_school: T_school, T_major: T_major, T_education: T_education, T_phone: T_phone, T_marry: T_marry, T_spouse_name: T_spouse_name, T_spouse_phone: T_spouse_phone, T_entry_time: T_entry_time, T_positive_time: T_positive_time, T_entry_type: T_entry_type, T_contract_start_time: T_contract_start_time, T_contract_end_time: T_contract_end_time, T_expire: T_expire, T_remark: T_remark, } if len(T_power) < 1 { c.Data["json"] = lib.JSONS{Code: 204, Msg: "权限异常!"} c.ServeJSON() return } _, err := Account.Read_Power_ByT_id(T_power) if err != nil { c.Data["json"] = lib.JSONS{Code: 205, Msg: "参数异常!"} c.ServeJSON() return } if len(var_.T_name) < 3 { c.Data["json"] = lib.JSONS{Code: 206, Msg: "名字 长度太短 < 3!"} c.ServeJSON() return } if len(var_.T_user) < 3 { c.Data["json"] = lib.JSONS{Code: 207, Msg: "用户名 长度太短 < 3!"} c.ServeJSON() return } if len(var_.T_pass) < 3 { c.Data["json"] = lib.JSONS{Code: 208, Msg: "密码异常!"} c.ServeJSON() return } _, err = Account.Add_User(var_) if err != nil { c.Data["json"] = lib.JSONS{Code: 209, Msg: "添加失败!"} c.ServeJSON() return } var_.T_pass = "******" System.Add_UserLogs_T(c.User.T_uuid, "用户", "新增", var_) c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!"} c.ServeJSON() return } // 修改个人信息 func (c *UserController) Post() { T_pass := c.GetString("T_pass") user := c.User if len(T_pass) > 0 { if len(T_pass) < 8 { c.Data["json"] = lib.JSONS{Code: 206, Msg: "密码格式不正确!"} c.ServeJSON() return } user.T_pass = T_pass } if err := Account.Update_User(user, "T_pass"); err != nil { c.Data["json"] = lib.JSONS{Code: 202, Msg: "修改失败!"} c.ServeJSON() return } System.Add_UserLogs_T(c.User.T_uuid, "用户", "修改登录密码", "") c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!"} c.ServeJSON() return } // 修改用户信息 func (c *UserController) Edit() { T_uuid := c.GetString("T_uuid") T_power := c.GetString("T_power") T_name := c.GetString("T_name") T_pass := c.GetString("T_pass") T_dept, _ := c.GetInt("T_dept") T_post, _ := c.GetInt("T_post") T_dept_leader, T_dept_leader_err := c.GetInt("T_dept_leader") T_sex, T_sex_err := c.GetInt("T_sex") T_id_card := c.GetString("T_id_card") T_nation := c.GetString("T_nation") T_school := c.GetString("T_school") T_major := c.GetString("T_major") T_education := c.GetString("T_education") T_phone := c.GetString("T_phone") T_marry, T_marry_err := c.GetInt("T_marry") T_spouse_name := c.GetString("T_spouse_name") T_spouse_phone := c.GetString("T_spouse_phone") T_entry_time := c.GetString("T_entry_time") T_positive_time := c.GetString("T_positive_time") T_entry_type := c.GetString("T_entry_type") T_contract_start_time := c.GetString("T_contract_start_time") T_contract_end_time := c.GetString("T_contract_end_time") T_expire, T_expire_err := c.GetInt("T_expire") T_remark := c.GetString("T_remark") var err error var user Account.User var cols []string if len(T_uuid) > 0 { user, err = Account.Read_User_ByT_uuid(T_uuid) if err != nil { c.Data["json"] = lib.JSONS{Code: 202, Msg: "T_uuid Err!"} c.ServeJSON() return } } if len(T_name) > 0 { if len(T_name) < 2 { c.Data["json"] = lib.JSONS{Code: 204, Msg: "名字格式不正确!"} c.ServeJSON() return } user.T_name = T_name cols = append(cols, "T_name") } if len(T_pass) > 0 { if len(T_pass) < 8 { c.Data["json"] = lib.JSONS{Code: 206, Msg: "密码格式不正确!"} c.ServeJSON() return } user.T_pass = T_pass cols = append(cols, "T_pass") } if len(T_power) > 0 { _, err = Account.Read_Power_ByT_id(T_power) if err != nil { c.Data["json"] = lib.JSONS{Code: 208, Msg: "T_power Err!"} c.ServeJSON() return } user.T_power = T_power cols = append(cols, "T_power") } if T_dept > 0 { user.T_dept = T_dept cols = append(cols, "T_dept") } if T_post > 0 { user.T_post = T_post cols = append(cols, "T_post") } if T_dept_leader_err == nil { user.T_dept_leader = T_dept_leader cols = append(cols, "T_dept_leader") } if T_sex_err == nil { user.T_sex = T_sex cols = append(cols, "T_sex") } if len(T_id_card) > 0 { user.T_id_card = T_id_card cols = append(cols, "T_id_card") } if len(T_nation) > 0 { user.T_nation = T_nation cols = append(cols, "T_nation") } if len(T_school) > 0 { user.T_school = T_school cols = append(cols, "T_school") } if len(T_major) > 0 { user.T_major = T_major cols = append(cols, "T_major") } if len(T_education) > 0 { user.T_education = T_education cols = append(cols, "T_education") } if len(T_phone) > 0 { user.T_phone = T_phone cols = append(cols, "T_phone") } if T_marry_err == nil { user.T_marry = T_marry cols = append(cols, "T_marry") } if len(T_spouse_name) > 0 { user.T_spouse_name = T_spouse_name cols = append(cols, "T_spouse_name") } if len(T_spouse_phone) > 0 { user.T_spouse_phone = T_spouse_phone cols = append(cols, "T_spouse_phone") } if len(T_entry_time) > 0 { user.T_entry_time = T_entry_time cols = append(cols, "T_entry_time") } if len(T_positive_time) > 0 { user.T_positive_time = T_positive_time cols = append(cols, "T_positive_time") } if len(T_entry_type) > 0 { user.T_entry_type = T_entry_type cols = append(cols, "T_entry_type") } if len(T_contract_start_time) > 0 { user.T_contract_start_time = T_contract_start_time cols = append(cols, "T_contract_start_time") } if len(T_contract_end_time) > 0 { user.T_contract_end_time = T_contract_end_time cols = append(cols, "T_contract_end_time") } if T_expire_err == nil { user.T_expire = T_expire cols = append(cols, "T_expire") } if len(T_remark) > 0 { user.T_remark = T_remark cols = append(cols, "T_remark") } if err = Account.Update_User(user, cols...); err != nil { c.Data["json"] = lib.JSONS{Code: 208, Msg: "修改失败!"} c.ServeJSON() return } user.T_pass = "******" System.Add_UserLogs_T(c.User.T_uuid, "用户", "修改个人信息", user) c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!"} c.ServeJSON() return } // 删除用户信息 func (c *UserController) Del() { T_uuid := c.GetString("T_uuid") if len(T_uuid) == 0 { c.Data["json"] = lib.JSONS{Code: 201, Msg: "T_uuid Err!"} c.ServeJSON() return } user, err := Account.Read_User_ByT_uuid(T_uuid) if err != nil { c.Data["json"] = lib.JSONS{Code: 202, Msg: "T_uuid Err!"} c.ServeJSON() return } if user.Id == 1 { c.Data["json"] = lib.JSONS{Code: 202, Msg: "禁止删除超级管理员!"} c.ServeJSON() return } if err = Account.Delete_User(user); err != nil { c.Data["json"] = lib.JSONS{Code: 202, Msg: "删除失败!"} c.ServeJSON() return } c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!"} c.ServeJSON() return } func (c *UserController) Dept_List() { var r_jsons lib.R_JSONS list := []string{ "人事财务部", "实施", "研发部-软件组", "研发部-硬件组", } r_jsons.Data = list c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: r_jsons} c.ServeJSON() return } // 修改个人信息 func (c *UserController) Leave() { T_uuid := c.GetString("T_uuid") if len(T_uuid) == 0 { c.Data["json"] = lib.JSONS{Code: 201, Msg: "T_uuid Err!"} c.ServeJSON() return } user, err := Account.Read_User_ByT_uuid(T_uuid) if err != nil { c.Data["json"] = lib.JSONS{Code: 202, Msg: "T_uuid Err!"} c.ServeJSON() return } if user.Id == 1 { c.Data["json"] = lib.JSONS{Code: 202, Msg: "无权操作!"} c.ServeJSON() return } user.T_State = 2 if err := Account.Update_User(user, "T_State"); err != nil { c.Data["json"] = lib.JSONS{Code: 202, Msg: "修改失败!"} c.ServeJSON() return } System.Add_UserLogs_T(c.User.T_uuid, "用户", "离职", "") c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!"} c.ServeJSON() return }