12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418 |
- package controllers
- import (
- "Cold_Api/conf"
- "Cold_Api/controllers/lib"
- "Cold_Api/models/Admin"
- "Cold_Api/models/System"
- "crypto/md5"
- "encoding/hex"
- "fmt"
- beego "github.com/beego/beego/v2/server/web"
- uuid "github.com/satori/go.uuid"
- "math"
- "strconv"
- "time"
- )
- type UserController struct {
- beego.Controller
- }
- // 管理员
- func (c *UserController) Admin_html() {
- // 验证登录
- b_, admin_r := lib.Verification(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
- if !b_ {
- c.Ctx.Redirect(302, "Login")
- return
- }
- if admin_r.Id != 1 {
- c.Ctx.Redirect(302, "Login")
- return
- }
- fmt.Println("登录OK")
- page, _ := c.GetInt("page")
- println(page)
- if page < 1 {
- page = 1
- }
- c.Data["Admin_Power"], _ = Admin.Read_AdminPower_ById(admin_r.Admin_power)
- Name := c.GetString("Name")
- c.Data["Name"] = Name
- c.Data["Power_List"] = Admin.Read_Power_List_ALL_Power_Administration(1)
- var cnt int64
- c.Data["List"], cnt = Admin.Read_Admin_List_ALL_Admin_master(page, Name, 0)
- fmt.Println("cnt:", cnt)
- page_size := math.Ceil(float64(cnt) / float64(conf.Page_size))
- c.Data["Page"] = page
- c.Data["Page_size"] = page_size
- c.Data["Pages"] = lib.Func_page(int64(page), int64(page_size))
- c.Data["cnt"] = cnt
- c.TplName = "User/Admin.html"
- }
- // 检查 Tokey 是否过期
- func (c *UserController) InspectTokey() {
- // 验证登录
- b_ := lib.Verification_Tokey(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
- if !b_ {
- c.Data["json"] = lib.JSONS{Code: 301, Msg: "请退出重新登录!"}
- c.ServeJSON()
- return
- }
- c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!"}
- c.ServeJSON()
- return
- }
- func (c *UserController) Admin_() {
- // 验证登录
- b_, admin_r := lib.Verification(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
- if !b_ {
- c.Ctx.Redirect(302, "Login")
- return
- }
- if admin_r.Id != 1 {
- c.Ctx.Redirect(302, "Login")
- return
- }
- if admin_r.Admin_master != 0 {
- c.Ctx.Redirect(302, "Login")
- return
- }
- id, _ := c.GetInt("id")
- c.Data["id"] = id
- c.Data["Power_List"] = Admin.Read_Power_List_ALL_Power_Administration(1)
- Admin_uuid := c.GetString("Admin_uuid")
- c.Data["Admin_uuid"] = Admin_uuid
- if len(Admin_uuid) > 0 {
- c.Data["Date"], _ = Admin.Read_Admin_ByUuid(Admin_uuid)
- }
- c.TplName = "User/Admin-.html"
- }
- func (c *UserController) Admin_Post() {
- // 验证登录
- b_, admin_r := lib.Verification(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
- if !b_ {
- c.Ctx.Redirect(302, "Login")
- return
- }
- if admin_r.Id != 1 {
- c.Ctx.Redirect(302, "Login")
- return
- }
- if admin_r.Admin_master != 0 {
- c.Ctx.Redirect(302, "Login")
- return
- }
- Admin_uuid := c.GetString("Admin_uuid")
- Admin_name := c.GetString("Admin_name")
- Admin_user := c.GetString("Admin_user")
- Admin_telephone := c.GetString("Admin_telephone")
- Admin_mail := c.GetString("Admin_mail")
- Admin_text := c.GetString("Admin_text")
- Admin_gender, _ := c.GetInt("Admin_gender")
- Admin_power, _ := c.GetInt("Admin_power")
- var_ := Admin.Admin{
- Admin_uuid: uuid.NewV4().String(),
- Admin_name: Admin_name,
- Admin_master: admin_r.Admin_master,
- Admin_user: Admin_user,
- Admin_telephone: Admin_telephone,
- Admin_mail: Admin_mail,
- Admin_text: Admin_text,
- Admin_gender: Admin_gender,
- Admin_power: Admin_power,
- Admin_panel_plan: "",
- Admin_panel_data: "",
- T_State: 1,
- }
- if len(Admin_uuid) > 0 {
- var_.Admin_uuid = Admin_uuid
- err := Admin.Update_Admin_ById_Basics(var_)
- if err != nil {
- c.Data["json"] = lib.JSONS{Code: 302, Msg: "修改失败!"}
- c.ServeJSON()
- return
- }
- } else {
- s_pass := uuid.NewV4().String()[:6]
- h := md5.New()
- h.Write([]byte(s_pass))
- s := hex.EncodeToString(h.Sum(nil))
- fmt.Println(s)
- var_.Admin_pass = s
- var_.Admin_master = 0
- err, _ := Admin.Read_Admin_Admin_user(Admin_user)
- if err == nil {
- c.Data["json"] = lib.JSONS{Code: 302, Msg: "账户重复!"}
- c.ServeJSON()
- return
- }
- _, err = Admin.Add_Admin(var_)
- if err != nil {
- c.Data["json"] = lib.JSONS{Code: 301, Msg: "添加失败!"}
- c.ServeJSON()
- return
- }
- var_.Admin_pass = "***********"
- System.Add_UserLogs_T(admin_r.Admin_uuid, "管理员", "管理员操作", var_)
- c.Data["json"] = lib.JSONS{Code: 210, Msg: "ok!", Data: s_pass}
- c.ServeJSON()
- return
- }
- var_.Admin_pass = "***********"
- System.Add_UserLogs_T(admin_r.Admin_uuid, "管理员", "管理员操作", var_)
- c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!"}
- c.ServeJSON()
- return
- }
- func (c *UserController) Admin_Del() {
- // 验证登录
- b_, admin_r := lib.Verification(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
- if !b_ {
- c.Ctx.Redirect(302, "Login")
- return
- }
- if admin_r.Id != 1 {
- c.Ctx.Redirect(302, "Login")
- return
- }
- if admin_r.Admin_master != 0 {
- c.Ctx.Redirect(302, "Login")
- return
- }
- Admin_uuid := c.GetString("Admin_uuid")
- if len(Admin_uuid) > 0 {
- admin_r_lod, err := Admin.Read_Admin_ByUuid(Admin_uuid)
- if err != nil {
- c.Data["json"] = lib.JSONS{Code: 201, Msg: "e!"}
- c.ServeJSON()
- return
- }
- if admin_r_lod.Admin_master < admin_r.Admin_master {
- c.Data["json"] = lib.JSONS{Code: 202, Msg: "e!"}
- c.ServeJSON()
- return
- }
- admin_r_lod.T_State = 0
- Admin.Update_Admin(admin_r_lod, "T_State")
- //Admin.Update_Delete_Admin_ByAdmin_uuid(Admin_uuid)
- } else {
- c.Data["json"] = lib.JSONS{Code: 203, Msg: "e!"}
- c.ServeJSON()
- return
- }
- System.Add_UserLogs(admin_r.Admin_uuid, "管理员", "管理员删除", Admin_uuid)
- c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!"}
- c.ServeJSON()
- return
- }
- func (c *UserController) User_Entry() {
- // 验证登录
- b_, admin_r := lib.Verification(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
- if !b_ {
- c.Ctx.Redirect(302, "Login")
- return
- }
- //if(admin_r.Admin_master != 0){
- // c.Ctx.Redirect(302, "Login")
- // return
- //}
- Admin_uuid := c.GetString("Admin_uuid")
- if len(Admin_uuid) > 0 {
- admin_r_a, err := Admin.Read_Admin_ByUuid(Admin_uuid)
- if err != nil {
- c.Data["json"] = lib.JSONS{Code: 201, Msg: "e!"}
- c.ServeJSON()
- return
- }
- if admin_r.Id != admin_r_a.Admin_master {
- c.Data["json"] = lib.JSONS{Code: 202, Msg: "e!"}
- c.ServeJSON()
- return
- }
- User_tokey := Admin.Add_Tokey_Set(admin_r_a.Admin_uuid)
- c.Ctx.SetCookie("User_tokey", User_tokey, time.Second*60*60)
- } else {
- c.Data["json"] = lib.JSONS{Code: 203, Msg: "e!"}
- c.ServeJSON()
- return
- }
- System.Add_UserLogs(admin_r.Admin_uuid, "用户管理", "无钥匙进入", Admin_uuid)
- c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!"}
- c.ServeJSON()
- return
- }
- func (c *UserController) V2_User_Entry() {
- // 验证登录
- b_, admin_r := lib.Verification(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
- if !b_ {
- c.Data["json"] = lib.JSONS{Code: 201, Msg: "User_tokey Err!"}
- c.ServeJSON()
- return
- }
- if admin_r.Admin_power > 6 {
- c.Data["json"] = lib.JSONS{Code: 201, Msg: "没有权限!"}
- c.ServeJSON()
- return
- }
- Admin_uuid := c.GetString("T_uuid")
- if len(Admin_uuid) > 0 {
- admin_r_a, err := Admin.Read_Admin_ByUuid(Admin_uuid)
- if err != nil {
- c.Data["json"] = lib.JSONS{Code: 201, Msg: "e!"}
- c.ServeJSON()
- return
- }
- if admin_r.Id != admin_r_a.Admin_master {
- c.Data["json"] = lib.JSONS{Code: 202, Msg: "e!"}
- c.ServeJSON()
- return
- }
- User_tokey := Admin.Add_Tokey_Set(admin_r_a.Admin_uuid)
- System.Add_UserLogs(admin_r.Admin_uuid, "用户管理", "无钥匙进入", Admin_uuid)
- c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: User_tokey}
- c.ServeJSON()
- return
- } else {
- c.Data["json"] = lib.JSONS{Code: 203, Msg: "e!"}
- c.ServeJSON()
- return
- }
- }
- // 用户管理
- func (c *UserController) User_html() {
- // 验证登录
- b_, admin_r := lib.Verification(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
- if !b_ {
- c.Ctx.Redirect(302, "Login")
- return
- }
- page, _ := c.GetInt("page")
- println(page)
- if page < 1 {
- page = 1
- }
- Name := c.GetString("Name")
- c.Data["Name"] = Name
- c.Data["Power_List"] = Admin.Read_Power_List_ALL_Power_Administration(0)
- Adminpower, _ := Admin.Read_AdminPower_ById(admin_r.Admin_power)
- var cnt int64
- if Adminpower.Power_User_r != 1 {
- c.Ctx.Redirect(302, "Login")
- return
- }
- c.Data["List"], cnt = Admin.Read_Admin_List_ALL_User(page, Name, admin_r.Id)
- fmt.Println("cnt:", cnt)
- page_size := math.Ceil(float64(cnt) / float64(conf.Page_size))
- c.Data["Page"] = page
- c.Data["Page_size"] = page_size
- c.Data["Pages"] = lib.Func_page(int64(page), int64(page_size))
- c.Data["cnt"] = cnt
- c.TplName = "User/User.html"
- }
- // 用户管理
- func (c *UserController) V2_User_List() {
- // 验证登录
- b_, admin_r := lib.Verification(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
- if !b_ {
- c.Data["json"] = lib.JSONS{Code: 201, Msg: "User_tokey Err!"}
- c.ServeJSON()
- return
- }
- type R_JSONS struct {
- //必须的大写开头
- Data []Admin.Admin
- Num int64
- Page int
- Page_size int
- }
- var r_jsons R_JSONS
- page, _ := c.GetInt("page")
- println(page)
- if page < 1 {
- page = 1
- }
- page_z, _ := c.GetInt("page_z")
- if page_z < 1 {
- page_z = conf.Page_size
- }
- Name := c.GetString("T_name")
- r_jsons.Data, r_jsons.Num = Admin.Read_v2_Admin_List(admin_r.Id, Name, page, page_z)
- r_jsons.Page = page
- r_jsons.Page_size = int(math.Ceil(float64(r_jsons.Num) / float64(page_z)))
- c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: r_jsons}
- c.ServeJSON()
- return
- }
- func (c *UserController) User_() {
- // 验证登录
- b_, _ := lib.Verification(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
- if !b_ {
- c.Ctx.Redirect(302, "Login")
- return
- }
- id, _ := c.GetInt("id")
- c.Data["id"] = id
- c.Data["Power_List"] = Admin.Read_Power_List_ALL_Power_Administration(0)
- Admin_uuid := c.GetString("Admin_uuid")
- c.Data["Admin_uuid"] = Admin_uuid
- if len(Admin_uuid) > 0 {
- c.Data["Date"], _ = Admin.Read_Admin_ByUuid(Admin_uuid)
- }
- c.TplName = "User/User-.html"
- }
- func (c *UserController) User_Info() {
- // 验证登录
- b_, admin_r := lib.Verification(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
- if !b_ {
- c.Ctx.Redirect(302, "Login")
- return
- }
- c.Data["id"] = admin_r.Id
- c.Data["Date"] = admin_r
- c.TplName = "User/User-Info.html"
- }
- func (c *UserController) User_Info_() {
- // 验证登录
- b_, admin_r := lib.Verification(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
- if !b_ {
- c.Ctx.Redirect(302, "Login")
- return
- }
- c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: admin_r}
- c.ServeJSON()
- return
- }
- func (c *UserController) User_Get() {
- // 验证登录
- b_, admin_r := lib.Verification(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
- if !b_ {
- c.Ctx.Redirect(302, "Login")
- return
- }
- type Admin_ struct {
- Admin_uuid string
- Admin_power int // 权限
- Admin_name string //
- Admin_telephone string // 电话
- Admin_mail string // 邮箱
- Admin_gender int // 性别 0未知 1男 2女
- Admin_text string // 详情
- Admin_rh int // 显示湿度
- }
- Admin_r := Admin_{}
- Admin_r.Admin_rh = admin_r.Admin_rh
- Admin_r.Admin_uuid = admin_r.Admin_uuid
- Admin_r.Admin_power = admin_r.Admin_power
- Admin_r.Admin_name = admin_r.Admin_name
- Admin_r.Admin_telephone = admin_r.Admin_telephone
- Admin_r.Admin_mail = admin_r.Admin_mail
- Admin_r.Admin_gender = admin_r.Admin_gender
- Admin_r.Admin_text = admin_r.Admin_text
- c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: Admin_r}
- c.ServeJSON()
- return
- }
- func (c *UserController) User_v2_Get() {
- // 验证登录
- b_, admin_r := lib.Verification(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
- if !b_ {
- c.Data["json"] = lib.JSONS{Code: 201, Msg: "User_tokey Err!"}
- c.ServeJSON()
- return
- }
- type User_ struct {
- User_uuid string
- User_name string //
- User_power int //
- User_telephone string // 电话
- User_mail string // 邮箱
- User_gender int // 性别 0未知 1男 2女
- User_text string // 详情
- User_rh int // 显示湿度
- User_Power Admin.AdminPower // 权限
- }
- User_uuid := c.GetString("User_uuid")
- if len(User_uuid) < 8 {
- c.Data["json"] = lib.JSONS{Code: 202, Msg: "User_uuid Err!"}
- c.ServeJSON()
- return
- }
- admin_r, err := Admin.Read_Admin_ByUuid(User_uuid)
- if err != nil {
- c.Data["json"] = lib.JSONS{Code: 203, Msg: "User_uuid Err!"}
- c.ServeJSON()
- return
- }
- Admin_r := User_{}
- Admin_r.User_rh = admin_r.Admin_rh
- Admin_r.User_uuid = admin_r.Admin_uuid
- Admin_r.User_power = admin_r.Admin_power
- Admin_r.User_name = admin_r.Admin_name
- Admin_r.User_telephone = admin_r.Admin_telephone
- Admin_r.User_mail = admin_r.Admin_mail
- Admin_r.User_gender = admin_r.Admin_gender
- Admin_r.User_text = admin_r.Admin_text
- c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: Admin_r}
- c.ServeJSON()
- return
- }
- func (c *UserController) User_v2_Info() {
- // 验证登录
- b_, admin_r := lib.Verification(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
- if !b_ {
- c.Data["json"] = lib.JSONS{Code: 201, Msg: "User_tokey Err!"}
- c.ServeJSON()
- return
- }
- type User_ struct {
- User_uuid string
- User_name string //
- User_telephone string // 电话
- User_mail string // 邮箱
- User_gender int // 性别 0未知 1男 2女
- User_text string // 详情
- User_rh int // 显示湿度
- User_Power Admin.AdminPower // 权限
- }
- Admin_r := User_{}
- Admin_r.User_rh = admin_r.Admin_rh
- Admin_r.User_uuid = admin_r.Admin_uuid
- Admin_r.User_name = admin_r.Admin_name
- Admin_r.User_telephone = admin_r.Admin_telephone
- Admin_r.User_mail = admin_r.Admin_mail
- Admin_r.User_gender = admin_r.Admin_gender
- Admin_r.User_text = admin_r.Admin_text
- Admin_r.User_Power, _ = Admin.Read_AdminPower_ById(admin_r.Admin_power)
- c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: Admin_r}
- c.ServeJSON()
- return
- }
- func (c *UserController) User_Post() {
- // 验证登录
- b_, admin_r := lib.Verification(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
- if !b_ {
- c.Data["json"] = lib.JSONS{Code: 201, Msg: "User_tokey Err!"}
- c.ServeJSON()
- return
- }
- //Adminpower,_ := Admin.Read_AdminPower_ById(admin_r.Admin_power)
- //
- //if Adminpower.Power_User_r != 1 {
- // c.Data["json"] = lib.JSONS{Code: 307, Msg: "Adminpower.Power_User_r!"}
- // c.ServeJSON()
- // return
- //}
- Admin_uuid := c.GetString("Admin_uuid")
- Admin_name := c.GetString("Admin_name")
- Admin_user := c.GetString("Admin_user")
- Admin_pass := c.GetString("Admin_pass")
- Admin_telephone := c.GetString("Admin_telephone")
- Admin_mail := c.GetString("Admin_mail")
- Admin_text := c.GetString("Admin_text")
- Admin_gender, _ := c.GetInt("Admin_gender")
- Admin_power, _ := c.GetInt("Admin_power")
- var_ := Admin.Admin{
- Admin_uuid: uuid.NewV4().String(),
- Admin_name: Admin_name,
- Admin_master: admin_r.Id,
- Admin_user: Admin_user,
- Admin_telephone: Admin_telephone,
- Admin_mail: Admin_mail,
- Admin_text: Admin_text,
- Admin_pass: Admin_pass,
- Admin_gender: Admin_gender,
- Admin_power: Admin_power,
- T_State: 1,
- }
- if len(Admin_pass) > 0 && len(Admin_pass) < 7 {
- c.Data["json"] = lib.JSONS{Code: 302, Msg: "Admin_pass Err!"}
- c.ServeJSON()
- return
- }
- if len(Admin_uuid) > 0 {
- var_.Admin_uuid = Admin_uuid
- err, _ := Admin.ReadLogin_verification(var_.Admin_user, var_.Admin_pass)
- if err == nil {
- c.Data["json"] = lib.JSONS{Code: 307, Msg: "ReadLogin_verification !"}
- c.ServeJSON()
- return
- }
- err, r_u := Admin.Read_Admin_ByAdmin_uuid(Admin_uuid)
- if err != nil {
- c.Data["json"] = lib.JSONS{Code: 302, Msg: "修改失败!"}
- c.ServeJSON()
- return
- }
- // 修改密码只有本人
- if len(Admin_pass) > 0 && r_u.Id != admin_r.Id {
- c.Data["json"] = lib.JSONS{Code: 302, Msg: "r_u != admin_r!"}
- c.ServeJSON()
- return
- }
- err = Admin.Update_Admin_ById_Basics(var_)
- if err != nil {
- c.Data["json"] = lib.JSONS{Code: 302, Msg: "修改失败!"}
- c.ServeJSON()
- return
- }
- } else {
- s_pass := uuid.NewV4().String()[:6]
- h := md5.New()
- h.Write([]byte(s_pass))
- s := hex.EncodeToString(h.Sum(nil))
- fmt.Println(s)
- var_.Admin_pass = s
- // 是否 内部人员
- //Adminpower,_ := Admin.Read_AdminPower_ById(admin_r.Admin_power)
- //if Adminpower.Power_Administration == 1 {
- // var_.Admin_master = 1
- //}
- err, _ := Admin.Read_Admin_Admin_user(Admin_user)
- if err == nil {
- c.Data["json"] = lib.JSONS{Code: 302, Msg: "账户重复!"}
- c.ServeJSON()
- return
- }
- _, err = Admin.Add_Admin(var_)
- if err != nil {
- c.Data["json"] = lib.JSONS{Code: 301, Msg: "添加失败!"}
- c.ServeJSON()
- return
- }
- var_.Admin_pass = "****************"
- System.Add_UserLogs_T(admin_r.Admin_uuid, "用户管理", "操作", var_)
- c.Data["json"] = lib.JSONS{Code: 210, Msg: "ok!", Data: s_pass}
- c.ServeJSON()
- return
- }
- var_.Admin_pass = "****************"
- System.Add_UserLogs_T(admin_r.Admin_uuid, "用户管理", "操作", var_)
- c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!"}
- c.ServeJSON()
- return
- }
- func (c *UserController) User_v2_Add() {
- // 验证登录
- b_, admin_r := lib.Verification(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
- if !b_ {
- c.Data["json"] = lib.JSONS{Code: 201, Msg: "User_tokey Err!"}
- c.ServeJSON()
- return
- }
- Admin_power, _ := c.GetInt("T_power")
- Admin_name := c.GetString("T_name")
- Admin_user := c.GetString("T_user")
- Admin_pass := c.GetString("T_pass")
- Admin_telephone := c.GetString("T_phone")
- Admin_mail := c.GetString("T_mail")
- Admin_text := c.GetString("T_text")
- var_ := Admin.Admin{
- Admin_uuid: uuid.NewV4().String(),
- Admin_name: Admin_name,
- Admin_master: admin_r.Id,
- Admin_user: Admin_user,
- Admin_telephone: Admin_telephone,
- Admin_mail: Admin_mail,
- Admin_text: Admin_text,
- Admin_pass: Admin_pass,
- Admin_power: Admin_power,
- T_State: 1,
- }
- if len(Admin_pass) > 0 && len(Admin_pass) < 7 {
- c.Data["json"] = lib.JSONS{Code: 302, Msg: "Admin_pass Err!"}
- c.ServeJSON()
- return
- }
- if admin_r.Admin_power > Admin_power {
- c.Data["json"] = lib.JSONS{Code: 202, Msg: "你没有权限 配置 权限!"}
- c.ServeJSON()
- return
- }
- if len(Admin_pass) < 8 {
- c.Data["json"] = lib.JSONS{Code: 202, Msg: "密码异常!"}
- c.ServeJSON()
- return
- }
- err, _ := Admin.Read_Admin_Admin_user(Admin_user)
- if err == nil {
- c.Data["json"] = lib.JSONS{Code: 302, Msg: "账户重复!"}
- c.ServeJSON()
- return
- }
- _, err = Admin.Add_Admin(var_)
- if err != nil {
- c.Data["json"] = lib.JSONS{Code: 301, Msg: "添加失败!"}
- c.ServeJSON()
- return
- }
- var_.Admin_pass = "****************"
- System.Add_UserLogs_T(admin_r.Admin_uuid, "用户管理", "添加操作", var_)
- c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!"}
- c.ServeJSON()
- return
- }
- func (c *UserController) User_v2_Edit() {
- // 验证登录
- b_, admin_r := lib.Verification(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
- if !b_ {
- c.Data["json"] = lib.JSONS{Code: 201, Msg: "User_tokey Err!"}
- c.ServeJSON()
- return
- }
- Admin_name := c.GetString("T_name")
- Admin_pass := c.GetString("T_pass")
- Admin_telephone := c.GetString("T_phone")
- Admin_mail := c.GetString("T_mail")
- Admin_text := c.GetString("T_text")
- if len(Admin_name) > 0 {
- admin_r.Admin_name = Admin_name
- }
- if len(Admin_pass) > 0 {
- admin_r.Admin_pass = Admin_pass
- }
- if len(Admin_telephone) > 0 {
- admin_r.Admin_telephone = Admin_telephone
- }
- if len(Admin_mail) > 0 {
- admin_r.Admin_mail = Admin_mail
- }
- if len(Admin_text) > 0 {
- admin_r.Admin_text = Admin_text
- }
- if len(Admin_pass) > 0 && len(Admin_pass) < 7 {
- c.Data["json"] = lib.JSONS{Code: 203, Msg: "Admin_pass Err!"}
- c.ServeJSON()
- return
- }
- is := Admin.Update_Admin(admin_r, "Admin_name", "Admin_pass", "Admin_telephone", "Admin_mail", "Admin_text")
- if !is {
- c.Data["json"] = lib.JSONS{Code: 204, Msg: "修改失败!"}
- c.ServeJSON()
- return
- }
- admin_r.Admin_pass = "****************"
- System.Add_UserLogs_T(admin_r.Admin_uuid, "用户管理", "操作", admin_r)
- c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!"}
- c.ServeJSON()
- return
- }
- func (c *UserController) User_v2_AEdit() {
- // 验证登录
- b_, admin_r := lib.Verification(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
- if !b_ {
- c.Data["json"] = lib.JSONS{Code: 201, Msg: "User_tokey Err!"}
- c.ServeJSON()
- return
- }
- if admin_r.Admin_power > 6 {
- c.Data["json"] = lib.JSONS{Code: 204, Msg: "没有权限!"}
- c.ServeJSON()
- return
- }
- Admin_uuid := c.GetString("T_uuid")
- Admin_user := c.GetString("T_user")
- Admin_name := c.GetString("T_name")
- Admin_pass := c.GetString("T_pass")
- Admin_telephone := c.GetString("T_phone")
- Admin_mail := c.GetString("T_mail")
- Admin_text := c.GetString("T_text")
- Admin_power, _ := c.GetInt("T_power")
- if len(Admin_uuid) < 5 {
- c.Data["json"] = lib.JSONS{Code: 302, Msg: "Admin_uuid Err!"}
- c.ServeJSON()
- return
- }
- // 权限超出
- if admin_r.Admin_power > Admin_power {
- c.Data["json"] = lib.JSONS{Code: 202, Msg: "你没有权限 配置 权限!"}
- c.ServeJSON()
- return
- }
- err, r_u := Admin.Read_Admin_ByAdmin_uuid(Admin_uuid)
- if err != nil {
- c.Data["json"] = lib.JSONS{Code: 302, Msg: "修改失败!"}
- c.ServeJSON()
- return
- }
- // 用户名重复
- if len(Admin_user) > 0 {
- err, y_user := Admin.Read_Admin_Admin_user(Admin_user)
- if err == nil {
- if y_user.Id != r_u.Id {
- c.Data["json"] = lib.JSONS{Code: 302, Msg: "用户名重复!"}
- c.ServeJSON()
- return
- }
- }
- r_u.Admin_user = Admin_user
- }
- if len(Admin_name) > 0 {
- r_u.Admin_name = Admin_name
- }
- if len(Admin_pass) > 0 {
- r_u.Admin_pass = Admin_pass
- }
- if Admin_power > 0 {
- r_u.Admin_power = Admin_power
- }
- if len(Admin_telephone) > 0 {
- r_u.Admin_telephone = Admin_telephone
- }
- if len(Admin_mail) > 0 {
- r_u.Admin_mail = Admin_mail
- }
- if len(Admin_text) > 0 {
- r_u.Admin_text = Admin_text
- }
- is := Admin.Update_Admin(r_u, "Admin_user", "Admin_name", "Admin_pass", "Admin_telephone", "Admin_mail", "Admin_text", "Admin_power")
- if !is {
- c.Data["json"] = lib.JSONS{Code: 204, Msg: "修改失败!"}
- c.ServeJSON()
- return
- }
- r_u.Admin_pass = "****************"
- System.Add_UserLogs_T(admin_r.Admin_uuid, "用户管理", "操作", r_u)
- c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!"}
- c.ServeJSON()
- return
- }
- func (c *UserController) User_Del() {
- // 验证登录
- b_, admin_r := lib.Verification(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
- if !b_ {
- c.Ctx.Redirect(302, "Login")
- return
- }
- if admin_r.Admin_power > 6 {
- c.Data["json"] = lib.JSONS{Code: 204, Msg: "没有权限!"}
- c.ServeJSON()
- return
- }
- Admin_uuid := c.GetString("Admin_uuid")
- if len(Admin_uuid) > 0 {
- admin_r_lod, err := Admin.Read_Admin_ByUuid(Admin_uuid)
- if err != nil {
- c.Data["json"] = lib.JSONS{Code: 201, Msg: "e!"}
- c.ServeJSON()
- return
- }
- if admin_r_lod.Admin_master < admin_r.Admin_master {
- c.Data["json"] = lib.JSONS{Code: 202, Msg: "e!"}
- c.ServeJSON()
- return
- }
- admin_r_lod.T_State = 0
- Admin.Update_Admin(admin_r_lod, "T_State")
- //Admin.Update_Delete_Admin_ByAdmin_uuid(Admin_uuid)
- } else {
- c.Data["json"] = lib.JSONS{Code: 203, Msg: "e!"}
- c.ServeJSON()
- return
- }
- System.Add_UserLogs_T(admin_r.Admin_uuid, "用户管理", "删除", Admin_uuid)
- c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!"}
- c.ServeJSON()
- return
- }
- func (c *UserController) V2_User_Del() {
- // 验证登录
- b_, admin_r := lib.Verification(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
- if !b_ {
- c.Data["json"] = lib.JSONS{Code: 201, Msg: "User_tokey Err!"}
- c.ServeJSON()
- return
- }
- if admin_r.Admin_power > 6 {
- c.Data["json"] = lib.JSONS{Code: 204, Msg: "没有权限!"}
- c.ServeJSON()
- return
- }
- Admin_uuid := c.GetString("T_uuid")
- if len(Admin_uuid) > 0 {
- admin_r_lod, err := Admin.Read_Admin_ByUuid(Admin_uuid)
- if err != nil {
- c.Data["json"] = lib.JSONS{Code: 204, Msg: "e!"}
- c.ServeJSON()
- return
- }
- if admin_r_lod.Admin_master < admin_r.Admin_master {
- c.Data["json"] = lib.JSONS{Code: 202, Msg: "e!"}
- c.ServeJSON()
- return
- }
- admin_r_lod.T_State = 0
- Admin.Update_Admin(admin_r_lod, "T_State")
- //Admin.Update_Delete_Admin_ByAdmin_uuid(Admin_uuid)
- } else {
- c.Data["json"] = lib.JSONS{Code: 203, Msg: "e!"}
- c.ServeJSON()
- return
- }
- System.Add_UserLogs_T(admin_r.Admin_uuid, "用户管理", "删除", Admin_uuid)
- c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!"}
- c.ServeJSON()
- return
- }
- // 权限管理
- func (c *UserController) Power_html() {
- // 验证登录
- b_, admin_r := lib.Verification(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
- if !b_ {
- c.Ctx.Redirect(302, "Login")
- return
- }
- if admin_r.Id != 1 {
- c.Ctx.Redirect(302, "Login")
- return
- }
- if admin_r.Admin_master != 0 {
- c.Ctx.Redirect(302, "Login")
- return
- }
- c.Data["Admin_Power"], _ = Admin.Read_AdminPower_ById(admin_r.Admin_power)
- fmt.Println("登录OK")
- page, _ := c.GetInt("page")
- println(page)
- if page < 1 {
- page = 1
- }
- Name := c.GetString("Name")
- c.Data["Name"] = Name
- var cnt int64
- c.Data["List"], cnt = Admin.Read_Power_List_ALL(Name, page, 9999)
- fmt.Println("cnt:", cnt)
- page_size := math.Ceil(float64(cnt) / float64(conf.Page_size))
- c.Data["Page"] = page
- c.Data["Page_size"] = page_size
- c.Data["Pages"] = lib.Func_page(int64(page), int64(page_size))
- c.Data["cnt"] = cnt
- c.TplName = "User/Power.html"
- }
- // 权限管理
- func (c *UserController) Power_List() {
- // 验证登录
- b_, _ := lib.Verification(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
- if !b_ {
- c.Data["json"] = lib.JSONS{Code: 201, Msg: "User_tokey Err!"}
- c.ServeJSON()
- return
- }
- //
- //if admin_r.Admin_master != 0 {
- // c.Data["json"] = lib.JSONS{Code: 202, Msg: "没有权限!"}
- // c.ServeJSON()
- // return
- //}
- type R_JSONS struct {
- //必须的大写开头
- Data []Admin.AdminPower
- Num int64
- Page int
- Page_size int
- }
- var r_jsons R_JSONS
- page, _ := c.GetInt("page")
- println(page)
- if page < 1 {
- page = 1
- }
- page_z, _ := c.GetInt("page_z")
- if page_z < 1 {
- page_z = conf.Page_size
- }
- Name := c.GetString("T_name")
- r_jsons.Data, r_jsons.Num = Admin.Read_Power_List_ALL(Name, page, page_z)
- r_jsons.Page = page
- r_jsons.Page_size = int(math.Ceil(float64(r_jsons.Num) / float64(page_z)))
- c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: r_jsons}
- c.ServeJSON()
- return
- }
- func (c *UserController) Power_() {
- // 验证登录
- b_, admin_r := lib.Verification(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
- if !b_ {
- c.Ctx.Redirect(302, "Login")
- return
- }
- if admin_r.Id != 1 {
- c.Ctx.Redirect(302, "Login")
- return
- }
- if admin_r.Admin_master != 0 {
- c.Ctx.Redirect(302, "Login")
- return
- }
- id, _ := c.GetInt("id")
- c.Data["id"] = id
- if id > 0 {
- c.Data["Date"], _ = Admin.Read_AdminPower_ById(id)
- }
- c.TplName = "User/Power-.html"
- }
- func (c *UserController) Power_Get() {
- // 验证登录
- b_, admin_r := lib.Verification(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
- if !b_ {
- c.Data["json"] = lib.JSONS{Code: 201, Msg: "User_tokey Err!"}
- c.ServeJSON()
- return
- }
- if admin_r.Id != 1 {
- c.Data["json"] = lib.JSONS{Code: 202, Msg: "没有权限!"}
- c.ServeJSON()
- return
- }
- if admin_r.Admin_master != 0 {
- c.Data["json"] = lib.JSONS{Code: 202, Msg: "没有权限!"}
- c.ServeJSON()
- return
- }
- id, _ := c.GetInt("T_id")
- if id == 0 {
- c.Data["json"] = lib.JSONS{Code: 202, Msg: "T_id Err!"}
- c.ServeJSON()
- return
- }
- Data, _ := Admin.Read_AdminPower_ById(id)
- c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: Data}
- c.ServeJSON()
- return
- }
- func (c *UserController) Power_Post() {
- var err error
- // 验证登录
- b_, admin_r := lib.Verification(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
- if !b_ {
- c.Ctx.Redirect(302, "Login")
- return
- }
- if admin_r.Id != 1 {
- c.Ctx.Redirect(302, "Login")
- return
- }
- if admin_r.Admin_master != 0 {
- c.Ctx.Redirect(302, "Login")
- return
- }
- id, _ := c.GetInt("id")
- c.Data["id"] = id
- Power_name := c.GetString("Power_name")
- Power_Administration, _ := c.GetInt("Power_Administration")
- Power_User_r, _ := c.GetInt("Power_User_r")
- Power_User_entry, _ := c.GetInt("Power_User_entry")
- Power_Device_r, _ := c.GetInt("Power_Device_r")
- Power_Device_a, _ := c.GetInt("Power_Device_a")
- Power_Device_Parameter_e, _ := c.GetInt("Power_Device_Parameter_e")
- Power_DeviceSensor_Parameter_e, _ := c.GetInt("Power_DeviceSensor_Parameter_e")
- Power_Device_Bind_e, _ := c.GetInt("Power_Device_Bind_e")
- Power_DeviceSensor_Compensate_e, _ := c.GetInt("Power_DeviceSensor_Compensate_e")
- Power_DeviceSensor_Class, _ := c.GetInt("Power_DeviceSensor_Class")
- Power_DataScreen_r, _ := c.GetInt("Power_DataScreen_r")
- Logs_Sys_r, _ := c.GetInt("Logs_Sys_r")
- Logs_User_r, _ := c.GetInt("Logs_User_r")
- var_ := Admin.AdminPower{
- Power_name: Power_name,
- Power_Administration: Power_Administration,
- Power_User_r: Power_User_r,
- Power_User_entry: Power_User_entry,
- Power_Device_r: Power_Device_r,
- Power_Device_a: Power_Device_a,
- Power_Device_Parameter_e: Power_Device_Parameter_e,
- Power_DeviceSensor_Parameter_e: Power_DeviceSensor_Parameter_e,
- Power_Device_Bind_e: Power_Device_Bind_e,
- Power_DeviceSensor_Class: Power_DeviceSensor_Class,
- Power_DeviceSensor_Compensate_e: Power_DeviceSensor_Compensate_e,
- Power_DataScreen_r: Power_DataScreen_r,
- Logs_Sys_r: Logs_Sys_r,
- Logs_User_r: Logs_User_r,
- T_State: 1,
- }
- if id > 0 {
- var_.Id = id
- fmt.Println("Power_DataScreen_r:", var_.Power_DataScreen_r)
- err = Admin.Update_AdminPower_ById_Basics(var_)
- if err != nil {
- c.Data["json"] = lib.JSONS{Code: 302, Msg: "修改失败!"}
- c.ServeJSON()
- return
- }
- } else {
- _, err = Admin.Add_AdminPower(var_)
- if err != nil {
- c.Data["json"] = lib.JSONS{Code: 301, Msg: "添加失败!"}
- c.ServeJSON()
- return
- }
- }
- System.Add_UserLogs_T(admin_r.Admin_uuid, "权限管理", "权限操作", var_)
- c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!"}
- c.ServeJSON()
- return
- }
- func (c *UserController) Power_Del() {
- // 验证登录
- b_, admin_r := lib.Verification(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
- if !b_ {
- c.Ctx.Redirect(302, "Login")
- return
- }
- if admin_r.Id != 1 {
- c.Ctx.Redirect(302, "Login")
- return
- }
- if admin_r.Admin_master != 0 {
- c.Data["json"] = lib.JSONS{Code: 203, Msg: "没有权限!"}
- c.ServeJSON()
- return
- }
- id, _ := c.GetInt("Id")
- c.Data["id"] = id
- if id > 0 {
- admin_r_lod, err := Admin.Read_AdminPower_ById(id)
- if err != nil {
- c.Data["json"] = lib.JSONS{Code: 201, Msg: "e!"}
- c.ServeJSON()
- return
- }
- Admin_List_ALL_AdminPower := Admin.Read_Admin_List_ALL_AdminPower(admin_r_lod.Id)
- if len(Admin_List_ALL_AdminPower) > 0 {
- S_Msg := "无法删除!【"
- for _, v := range Admin_List_ALL_AdminPower {
- S_Msg += v.Admin_name + ","
- }
- c.Data["json"] = lib.JSONS{Code: 205, Msg: S_Msg + "】 属于该权限!删除这些账号后即可删除! "}
- c.ServeJSON()
- return
- }
- Admin.Update_Delete_AdminPower_Byid(admin_r_lod.Id)
- } else {
- c.Data["json"] = lib.JSONS{Code: 204, Msg: "e!"}
- c.ServeJSON()
- return
- }
- System.Add_UserLogs(admin_r.Admin_uuid, "权限管理", "权限删除", strconv.Itoa(id))
- c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!"}
- c.ServeJSON()
- return
- }
- func (c *UserController) Power_v2_Add() {
- // 验证登录
- b_, admin_r := lib.Verification(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
- if !b_ {
- c.Data["json"] = lib.JSONS{Code: 201, Msg: "User_tokey Err!"}
- c.ServeJSON()
- return
- }
- if admin_r.Id != 1 {
- c.Data["json"] = lib.JSONS{Code: 202, Msg: "没有权限!"}
- c.ServeJSON()
- return
- }
- if admin_r.Admin_master != 0 {
- c.Data["json"] = lib.JSONS{Code: 202, Msg: "没有权限!"}
- c.ServeJSON()
- return
- }
- Power_name := c.GetString("Power_name")
- Power_Administration, _ := c.GetInt("Power_Administration")
- Power_User_r, _ := c.GetInt("Power_User_r")
- Power_User_entry, _ := c.GetInt("Power_User_entry")
- Power_Device_r, _ := c.GetInt("Power_Device_r")
- Power_Device_a, _ := c.GetInt("Power_Device_a")
- Power_Device_Parameter_e, _ := c.GetInt("Power_Device_Parameter_e")
- Power_DeviceSensor_Parameter_e, _ := c.GetInt("Power_DeviceSensor_Parameter_e")
- Power_Device_Bind_e, _ := c.GetInt("Power_Device_Bind_e")
- Power_DeviceSensor_Compensate_e, _ := c.GetInt("Power_DeviceSensor_Compensate_e")
- Power_DeviceSensor_Class, _ := c.GetInt("Power_DeviceSensor_Class")
- Power_DataScreen_r, _ := c.GetInt("Power_DataScreen_r")
- Logs_Sys_r, _ := c.GetInt("Logs_Sys_r")
- Logs_User_r, _ := c.GetInt("Logs_User_r")
- var_ := Admin.AdminPower{
- Power_name: Power_name,
- Power_Administration: Power_Administration,
- Power_User_r: Power_User_r,
- Power_User_entry: Power_User_entry,
- Power_Device_r: Power_Device_r,
- Power_Device_a: Power_Device_a,
- Power_Device_Parameter_e: Power_Device_Parameter_e,
- Power_DeviceSensor_Parameter_e: Power_DeviceSensor_Parameter_e,
- Power_Device_Bind_e: Power_Device_Bind_e,
- Power_DeviceSensor_Class: Power_DeviceSensor_Class,
- Power_DeviceSensor_Compensate_e: Power_DeviceSensor_Compensate_e,
- Power_DataScreen_r: Power_DataScreen_r,
- Logs_Sys_r: Logs_Sys_r,
- Logs_User_r: Logs_User_r,
- T_State: 1,
- }
- _, err := Admin.Add_AdminPower(var_)
- if err != nil {
- c.Data["json"] = lib.JSONS{Code: 301, Msg: "添加失败!"}
- c.ServeJSON()
- return
- }
- System.Add_UserLogs_T(admin_r.Admin_uuid, "权限管理", "权限操作", var_)
- c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!"}
- c.ServeJSON()
- return
- }
- func (c *UserController) Power_v2_Edit() {
- // 验证登录
- b_, admin_r := lib.Verification(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
- if !b_ {
- c.Data["json"] = lib.JSONS{Code: 201, Msg: "User_tokey Err!"}
- c.ServeJSON()
- return
- }
- if admin_r.Id != 1 {
- c.Data["json"] = lib.JSONS{Code: 202, Msg: "没有权限!"}
- c.ServeJSON()
- return
- }
- if admin_r.Admin_master != 0 {
- c.Data["json"] = lib.JSONS{Code: 202, Msg: "没有权限!"}
- c.ServeJSON()
- return
- }
- id, _ := c.GetInt("T_id")
- Power_name := c.GetString("Power_name")
- Power_Administration, _ := c.GetInt("Power_Administration")
- Power_User_r, _ := c.GetInt("Power_User_r")
- Power_User_e, _ := c.GetInt("Power_User_e")
- Power_User_entry, _ := c.GetInt("Power_User_entry")
- Power_Device_r, _ := c.GetInt("Power_Device_r")
- Power_Device_a, _ := c.GetInt("Power_Device_a")
- Power_Device_Parameter_e, _ := c.GetInt("Power_Device_Parameter_e")
- Power_DeviceSensor_Parameter_e, _ := c.GetInt("Power_DeviceSensor_Parameter_e")
- Power_Device_Bind_e, _ := c.GetInt("Power_Device_Bind_e")
- Power_DeviceSensor_Compensate_e, _ := c.GetInt("Power_DeviceSensor_Compensate_e")
- Power_DeviceSensor_Class, _ := c.GetInt("Power_DeviceSensor_Class")
- Power_DataScreen_r, _ := c.GetInt("Power_DataScreen_r")
- Logs_Sys_r, _ := c.GetInt("Logs_Sys_r")
- Logs_User_r, _ := c.GetInt("Logs_User_r")
- var_ := Admin.AdminPower{
- Id: id,
- Power_name: Power_name,
- Power_Administration: Power_Administration,
- Power_User_r: Power_User_r,
- Power_User_e: Power_User_e,
- Power_User_entry: Power_User_entry,
- Power_Device_r: Power_Device_r,
- Power_Device_a: Power_Device_a,
- Power_Device_Parameter_e: Power_Device_Parameter_e,
- Power_DeviceSensor_Parameter_e: Power_DeviceSensor_Parameter_e,
- Power_Device_Bind_e: Power_Device_Bind_e,
- Power_DeviceSensor_Class: Power_DeviceSensor_Class,
- Power_DeviceSensor_Compensate_e: Power_DeviceSensor_Compensate_e,
- Power_DataScreen_r: Power_DataScreen_r,
- Logs_Sys_r: Logs_Sys_r,
- Logs_User_r: Logs_User_r,
- T_State: 1,
- }
- err := Admin.Update_AdminPower_ById_Basics(var_)
- if err != nil {
- c.Data["json"] = lib.JSONS{Code: 302, Msg: "修改失败!"}
- c.ServeJSON()
- return
- }
- System.Add_UserLogs_T(admin_r.Admin_uuid, "权限管理", "权限操作", var_)
- c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!"}
- c.ServeJSON()
- return
- }
- func (c *UserController) Power_v2_Del() {
- // 验证登录
- b_, admin_r := lib.Verification(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
- if !b_ {
- c.Data["json"] = lib.JSONS{Code: 201, Msg: "User_tokey Err!"}
- c.ServeJSON()
- return
- }
- if admin_r.Id != 1 {
- c.Data["json"] = lib.JSONS{Code: 202, Msg: "没有权限!"}
- c.ServeJSON()
- return
- }
- if admin_r.Admin_master != 0 {
- c.Data["json"] = lib.JSONS{Code: 202, Msg: "没有权限!"}
- c.ServeJSON()
- return
- }
- id, _ := c.GetInt("T_id")
- if id > 0 {
- admin_r_lod, err := Admin.Read_AdminPower_ById(id)
- if err != nil {
- c.Data["json"] = lib.JSONS{Code: 201, Msg: "e!"}
- c.ServeJSON()
- return
- }
- Admin_List_ALL_AdminPower := Admin.Read_Admin_List_ALL_AdminPower(admin_r_lod.Id)
- if len(Admin_List_ALL_AdminPower) > 0 {
- S_Msg := "无法删除!【"
- for _, v := range Admin_List_ALL_AdminPower {
- S_Msg += v.Admin_name + ","
- }
- c.Data["json"] = lib.JSONS{Code: 205, Msg: S_Msg + "】 属于该权限!删除这些账号后即可删除! "}
- c.ServeJSON()
- return
- }
- Admin.Update_Delete_AdminPower_Byid(admin_r_lod.Id)
- } else {
- c.Data["json"] = lib.JSONS{Code: 204, Msg: "e!"}
- c.ServeJSON()
- return
- }
- System.Add_UserLogs(admin_r.Admin_uuid, "权限管理", "权限删除", strconv.Itoa(id))
- c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!"}
- c.ServeJSON()
- return
- }
- // 同步面板
- func (c *UserController) Panel_plan_Syn() {
- // 验证登录
- b_, admin_r := lib.Verification(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
- if !b_ {
- c.Data["json"] = lib.JSONS{Code: 201, Msg: "User_tokey Err!"}
- c.ServeJSON()
- return
- }
- s_, user_r := Admin.Read_Admin_ByAdmin_uuid(c.GetString("Admin_uuid"))
- if s_ != nil {
- c.Data["json"] = lib.JSONS{Code: 202, Msg: "Admin_uuid Err!"}
- c.ServeJSON()
- return
- }
- user_r.Admin_panel_plan = admin_r.Admin_panel_plan
- Admin.Update_Admin(user_r, "Admin_panel_plan")
- System.Add_UserLogs(admin_r.Admin_uuid, "设备管理", "同步面板操作", "面板:"+admin_r.Admin_panel_plan+"|"+admin_r.Admin_uuid+"->"+user_r.Admin_uuid)
- c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!"}
- c.ServeJSON()
- return
- }
|