User.go 38 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418
  1. package controllers
  2. import (
  3. "Cold_Api/conf"
  4. "Cold_Api/controllers/lib"
  5. "Cold_Api/models/Admin"
  6. "Cold_Api/models/System"
  7. "crypto/md5"
  8. "encoding/hex"
  9. "fmt"
  10. beego "github.com/beego/beego/v2/server/web"
  11. uuid "github.com/satori/go.uuid"
  12. "math"
  13. "strconv"
  14. "time"
  15. )
  16. type UserController struct {
  17. beego.Controller
  18. }
  19. // 管理员
  20. func (c *UserController) Admin_html() {
  21. // 验证登录
  22. b_, admin_r := lib.Verification(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
  23. if !b_ {
  24. c.Ctx.Redirect(302, "Login")
  25. return
  26. }
  27. if admin_r.Id != 1 {
  28. c.Ctx.Redirect(302, "Login")
  29. return
  30. }
  31. fmt.Println("登录OK")
  32. page, _ := c.GetInt("page")
  33. println(page)
  34. if page < 1 {
  35. page = 1
  36. }
  37. c.Data["Admin_Power"], _ = Admin.Read_AdminPower_ById(admin_r.Admin_power)
  38. Name := c.GetString("Name")
  39. c.Data["Name"] = Name
  40. c.Data["Power_List"] = Admin.Read_Power_List_ALL_Power_Administration(1)
  41. var cnt int64
  42. c.Data["List"], cnt = Admin.Read_Admin_List_ALL_Admin_master(page, Name, 0)
  43. fmt.Println("cnt:", cnt)
  44. page_size := math.Ceil(float64(cnt) / float64(conf.Page_size))
  45. c.Data["Page"] = page
  46. c.Data["Page_size"] = page_size
  47. c.Data["Pages"] = lib.Func_page(int64(page), int64(page_size))
  48. c.Data["cnt"] = cnt
  49. c.TplName = "User/Admin.html"
  50. }
  51. // 检查 Tokey 是否过期
  52. func (c *UserController) InspectTokey() {
  53. // 验证登录
  54. b_ := lib.Verification_Tokey(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
  55. if !b_ {
  56. c.Data["json"] = lib.JSONS{Code: 301, Msg: "请退出重新登录!"}
  57. c.ServeJSON()
  58. return
  59. }
  60. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!"}
  61. c.ServeJSON()
  62. return
  63. }
  64. func (c *UserController) Admin_() {
  65. // 验证登录
  66. b_, admin_r := lib.Verification(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
  67. if !b_ {
  68. c.Ctx.Redirect(302, "Login")
  69. return
  70. }
  71. if admin_r.Id != 1 {
  72. c.Ctx.Redirect(302, "Login")
  73. return
  74. }
  75. if admin_r.Admin_master != 0 {
  76. c.Ctx.Redirect(302, "Login")
  77. return
  78. }
  79. id, _ := c.GetInt("id")
  80. c.Data["id"] = id
  81. c.Data["Power_List"] = Admin.Read_Power_List_ALL_Power_Administration(1)
  82. Admin_uuid := c.GetString("Admin_uuid")
  83. c.Data["Admin_uuid"] = Admin_uuid
  84. if len(Admin_uuid) > 0 {
  85. c.Data["Date"], _ = Admin.Read_Admin_ByUuid(Admin_uuid)
  86. }
  87. c.TplName = "User/Admin-.html"
  88. }
  89. func (c *UserController) Admin_Post() {
  90. // 验证登录
  91. b_, admin_r := lib.Verification(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
  92. if !b_ {
  93. c.Ctx.Redirect(302, "Login")
  94. return
  95. }
  96. if admin_r.Id != 1 {
  97. c.Ctx.Redirect(302, "Login")
  98. return
  99. }
  100. if admin_r.Admin_master != 0 {
  101. c.Ctx.Redirect(302, "Login")
  102. return
  103. }
  104. Admin_uuid := c.GetString("Admin_uuid")
  105. Admin_name := c.GetString("Admin_name")
  106. Admin_user := c.GetString("Admin_user")
  107. Admin_telephone := c.GetString("Admin_telephone")
  108. Admin_mail := c.GetString("Admin_mail")
  109. Admin_text := c.GetString("Admin_text")
  110. Admin_gender, _ := c.GetInt("Admin_gender")
  111. Admin_power, _ := c.GetInt("Admin_power")
  112. var_ := Admin.Admin{
  113. Admin_uuid: uuid.NewV4().String(),
  114. Admin_name: Admin_name,
  115. Admin_master: admin_r.Admin_master,
  116. Admin_user: Admin_user,
  117. Admin_telephone: Admin_telephone,
  118. Admin_mail: Admin_mail,
  119. Admin_text: Admin_text,
  120. Admin_gender: Admin_gender,
  121. Admin_power: Admin_power,
  122. Admin_panel_plan: "",
  123. Admin_panel_data: "",
  124. T_State: 1,
  125. }
  126. if len(Admin_uuid) > 0 {
  127. var_.Admin_uuid = Admin_uuid
  128. err := Admin.Update_Admin_ById_Basics(var_)
  129. if err != nil {
  130. c.Data["json"] = lib.JSONS{Code: 302, Msg: "修改失败!"}
  131. c.ServeJSON()
  132. return
  133. }
  134. } else {
  135. s_pass := uuid.NewV4().String()[:6]
  136. h := md5.New()
  137. h.Write([]byte(s_pass))
  138. s := hex.EncodeToString(h.Sum(nil))
  139. fmt.Println(s)
  140. var_.Admin_pass = s
  141. var_.Admin_master = 0
  142. err, _ := Admin.Read_Admin_Admin_user(Admin_user)
  143. if err == nil {
  144. c.Data["json"] = lib.JSONS{Code: 302, Msg: "账户重复!"}
  145. c.ServeJSON()
  146. return
  147. }
  148. _, err = Admin.Add_Admin(var_)
  149. if err != nil {
  150. c.Data["json"] = lib.JSONS{Code: 301, Msg: "添加失败!"}
  151. c.ServeJSON()
  152. return
  153. }
  154. var_.Admin_pass = "***********"
  155. System.Add_UserLogs_T(admin_r.Admin_uuid, "管理员", "管理员操作", var_)
  156. c.Data["json"] = lib.JSONS{Code: 210, Msg: "ok!", Data: s_pass}
  157. c.ServeJSON()
  158. return
  159. }
  160. var_.Admin_pass = "***********"
  161. System.Add_UserLogs_T(admin_r.Admin_uuid, "管理员", "管理员操作", var_)
  162. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!"}
  163. c.ServeJSON()
  164. return
  165. }
  166. func (c *UserController) Admin_Del() {
  167. // 验证登录
  168. b_, admin_r := lib.Verification(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
  169. if !b_ {
  170. c.Ctx.Redirect(302, "Login")
  171. return
  172. }
  173. if admin_r.Id != 1 {
  174. c.Ctx.Redirect(302, "Login")
  175. return
  176. }
  177. if admin_r.Admin_master != 0 {
  178. c.Ctx.Redirect(302, "Login")
  179. return
  180. }
  181. Admin_uuid := c.GetString("Admin_uuid")
  182. if len(Admin_uuid) > 0 {
  183. admin_r_lod, err := Admin.Read_Admin_ByUuid(Admin_uuid)
  184. if err != nil {
  185. c.Data["json"] = lib.JSONS{Code: 201, Msg: "e!"}
  186. c.ServeJSON()
  187. return
  188. }
  189. if admin_r_lod.Admin_master < admin_r.Admin_master {
  190. c.Data["json"] = lib.JSONS{Code: 202, Msg: "e!"}
  191. c.ServeJSON()
  192. return
  193. }
  194. admin_r_lod.T_State = 0
  195. Admin.Update_Admin(admin_r_lod, "T_State")
  196. //Admin.Update_Delete_Admin_ByAdmin_uuid(Admin_uuid)
  197. } else {
  198. c.Data["json"] = lib.JSONS{Code: 203, Msg: "e!"}
  199. c.ServeJSON()
  200. return
  201. }
  202. System.Add_UserLogs(admin_r.Admin_uuid, "管理员", "管理员删除", Admin_uuid)
  203. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!"}
  204. c.ServeJSON()
  205. return
  206. }
  207. func (c *UserController) User_Entry() {
  208. // 验证登录
  209. b_, admin_r := lib.Verification(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
  210. if !b_ {
  211. c.Ctx.Redirect(302, "Login")
  212. return
  213. }
  214. //if(admin_r.Admin_master != 0){
  215. // c.Ctx.Redirect(302, "Login")
  216. // return
  217. //}
  218. Admin_uuid := c.GetString("Admin_uuid")
  219. if len(Admin_uuid) > 0 {
  220. admin_r_a, err := Admin.Read_Admin_ByUuid(Admin_uuid)
  221. if err != nil {
  222. c.Data["json"] = lib.JSONS{Code: 201, Msg: "e!"}
  223. c.ServeJSON()
  224. return
  225. }
  226. if admin_r.Id != admin_r_a.Admin_master {
  227. c.Data["json"] = lib.JSONS{Code: 202, Msg: "e!"}
  228. c.ServeJSON()
  229. return
  230. }
  231. User_tokey := Admin.Add_Tokey_Set(admin_r_a.Admin_uuid)
  232. c.Ctx.SetCookie("User_tokey", User_tokey, time.Second*60*60)
  233. } else {
  234. c.Data["json"] = lib.JSONS{Code: 203, Msg: "e!"}
  235. c.ServeJSON()
  236. return
  237. }
  238. System.Add_UserLogs(admin_r.Admin_uuid, "用户管理", "无钥匙进入", Admin_uuid)
  239. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!"}
  240. c.ServeJSON()
  241. return
  242. }
  243. func (c *UserController) V2_User_Entry() {
  244. // 验证登录
  245. b_, admin_r := lib.Verification(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
  246. if !b_ {
  247. c.Data["json"] = lib.JSONS{Code: 201, Msg: "User_tokey Err!"}
  248. c.ServeJSON()
  249. return
  250. }
  251. if admin_r.Admin_power > 6 {
  252. c.Data["json"] = lib.JSONS{Code: 201, Msg: "没有权限!"}
  253. c.ServeJSON()
  254. return
  255. }
  256. Admin_uuid := c.GetString("T_uuid")
  257. if len(Admin_uuid) > 0 {
  258. admin_r_a, err := Admin.Read_Admin_ByUuid(Admin_uuid)
  259. if err != nil {
  260. c.Data["json"] = lib.JSONS{Code: 201, Msg: "e!"}
  261. c.ServeJSON()
  262. return
  263. }
  264. if admin_r.Id != admin_r_a.Admin_master {
  265. c.Data["json"] = lib.JSONS{Code: 202, Msg: "e!"}
  266. c.ServeJSON()
  267. return
  268. }
  269. User_tokey := Admin.Add_Tokey_Set(admin_r_a.Admin_uuid)
  270. System.Add_UserLogs(admin_r.Admin_uuid, "用户管理", "无钥匙进入", Admin_uuid)
  271. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: User_tokey}
  272. c.ServeJSON()
  273. return
  274. } else {
  275. c.Data["json"] = lib.JSONS{Code: 203, Msg: "e!"}
  276. c.ServeJSON()
  277. return
  278. }
  279. }
  280. // 用户管理
  281. func (c *UserController) User_html() {
  282. // 验证登录
  283. b_, admin_r := lib.Verification(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
  284. if !b_ {
  285. c.Ctx.Redirect(302, "Login")
  286. return
  287. }
  288. page, _ := c.GetInt("page")
  289. println(page)
  290. if page < 1 {
  291. page = 1
  292. }
  293. Name := c.GetString("Name")
  294. c.Data["Name"] = Name
  295. c.Data["Power_List"] = Admin.Read_Power_List_ALL_Power_Administration(0)
  296. Adminpower, _ := Admin.Read_AdminPower_ById(admin_r.Admin_power)
  297. var cnt int64
  298. if Adminpower.Power_User_r != 1 {
  299. c.Ctx.Redirect(302, "Login")
  300. return
  301. }
  302. c.Data["List"], cnt = Admin.Read_Admin_List_ALL_User(page, Name, admin_r.Id)
  303. fmt.Println("cnt:", cnt)
  304. page_size := math.Ceil(float64(cnt) / float64(conf.Page_size))
  305. c.Data["Page"] = page
  306. c.Data["Page_size"] = page_size
  307. c.Data["Pages"] = lib.Func_page(int64(page), int64(page_size))
  308. c.Data["cnt"] = cnt
  309. c.TplName = "User/User.html"
  310. }
  311. // 用户管理
  312. func (c *UserController) V2_User_List() {
  313. // 验证登录
  314. b_, admin_r := lib.Verification(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
  315. if !b_ {
  316. c.Data["json"] = lib.JSONS{Code: 201, Msg: "User_tokey Err!"}
  317. c.ServeJSON()
  318. return
  319. }
  320. type R_JSONS struct {
  321. //必须的大写开头
  322. Data []Admin.Admin
  323. Num int64
  324. Page int
  325. Page_size int
  326. }
  327. var r_jsons R_JSONS
  328. page, _ := c.GetInt("page")
  329. println(page)
  330. if page < 1 {
  331. page = 1
  332. }
  333. page_z, _ := c.GetInt("page_z")
  334. if page_z < 1 {
  335. page_z = conf.Page_size
  336. }
  337. Name := c.GetString("T_name")
  338. r_jsons.Data, r_jsons.Num = Admin.Read_v2_Admin_List(admin_r.Id, Name, page, page_z)
  339. r_jsons.Page = page
  340. r_jsons.Page_size = int(math.Ceil(float64(r_jsons.Num) / float64(page_z)))
  341. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: r_jsons}
  342. c.ServeJSON()
  343. return
  344. }
  345. func (c *UserController) User_() {
  346. // 验证登录
  347. b_, _ := lib.Verification(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
  348. if !b_ {
  349. c.Ctx.Redirect(302, "Login")
  350. return
  351. }
  352. id, _ := c.GetInt("id")
  353. c.Data["id"] = id
  354. c.Data["Power_List"] = Admin.Read_Power_List_ALL_Power_Administration(0)
  355. Admin_uuid := c.GetString("Admin_uuid")
  356. c.Data["Admin_uuid"] = Admin_uuid
  357. if len(Admin_uuid) > 0 {
  358. c.Data["Date"], _ = Admin.Read_Admin_ByUuid(Admin_uuid)
  359. }
  360. c.TplName = "User/User-.html"
  361. }
  362. func (c *UserController) User_Info() {
  363. // 验证登录
  364. b_, admin_r := lib.Verification(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
  365. if !b_ {
  366. c.Ctx.Redirect(302, "Login")
  367. return
  368. }
  369. c.Data["id"] = admin_r.Id
  370. c.Data["Date"] = admin_r
  371. c.TplName = "User/User-Info.html"
  372. }
  373. func (c *UserController) User_Info_() {
  374. // 验证登录
  375. b_, admin_r := lib.Verification(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
  376. if !b_ {
  377. c.Ctx.Redirect(302, "Login")
  378. return
  379. }
  380. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: admin_r}
  381. c.ServeJSON()
  382. return
  383. }
  384. func (c *UserController) User_Get() {
  385. // 验证登录
  386. b_, admin_r := lib.Verification(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
  387. if !b_ {
  388. c.Ctx.Redirect(302, "Login")
  389. return
  390. }
  391. type Admin_ struct {
  392. Admin_uuid string
  393. Admin_power int // 权限
  394. Admin_name string //
  395. Admin_telephone string // 电话
  396. Admin_mail string // 邮箱
  397. Admin_gender int // 性别 0未知 1男 2女
  398. Admin_text string // 详情
  399. Admin_rh int // 显示湿度
  400. }
  401. Admin_r := Admin_{}
  402. Admin_r.Admin_rh = admin_r.Admin_rh
  403. Admin_r.Admin_uuid = admin_r.Admin_uuid
  404. Admin_r.Admin_power = admin_r.Admin_power
  405. Admin_r.Admin_name = admin_r.Admin_name
  406. Admin_r.Admin_telephone = admin_r.Admin_telephone
  407. Admin_r.Admin_mail = admin_r.Admin_mail
  408. Admin_r.Admin_gender = admin_r.Admin_gender
  409. Admin_r.Admin_text = admin_r.Admin_text
  410. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: Admin_r}
  411. c.ServeJSON()
  412. return
  413. }
  414. func (c *UserController) User_v2_Get() {
  415. // 验证登录
  416. b_, admin_r := lib.Verification(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
  417. if !b_ {
  418. c.Data["json"] = lib.JSONS{Code: 201, Msg: "User_tokey Err!"}
  419. c.ServeJSON()
  420. return
  421. }
  422. type User_ struct {
  423. User_uuid string
  424. User_name string //
  425. User_power int //
  426. User_telephone string // 电话
  427. User_mail string // 邮箱
  428. User_gender int // 性别 0未知 1男 2女
  429. User_text string // 详情
  430. User_rh int // 显示湿度
  431. User_Power Admin.AdminPower // 权限
  432. }
  433. User_uuid := c.GetString("User_uuid")
  434. if len(User_uuid) < 8 {
  435. c.Data["json"] = lib.JSONS{Code: 202, Msg: "User_uuid Err!"}
  436. c.ServeJSON()
  437. return
  438. }
  439. admin_r, err := Admin.Read_Admin_ByUuid(User_uuid)
  440. if err != nil {
  441. c.Data["json"] = lib.JSONS{Code: 203, Msg: "User_uuid Err!"}
  442. c.ServeJSON()
  443. return
  444. }
  445. Admin_r := User_{}
  446. Admin_r.User_rh = admin_r.Admin_rh
  447. Admin_r.User_uuid = admin_r.Admin_uuid
  448. Admin_r.User_power = admin_r.Admin_power
  449. Admin_r.User_name = admin_r.Admin_name
  450. Admin_r.User_telephone = admin_r.Admin_telephone
  451. Admin_r.User_mail = admin_r.Admin_mail
  452. Admin_r.User_gender = admin_r.Admin_gender
  453. Admin_r.User_text = admin_r.Admin_text
  454. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: Admin_r}
  455. c.ServeJSON()
  456. return
  457. }
  458. func (c *UserController) User_v2_Info() {
  459. // 验证登录
  460. b_, admin_r := lib.Verification(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
  461. if !b_ {
  462. c.Data["json"] = lib.JSONS{Code: 201, Msg: "User_tokey Err!"}
  463. c.ServeJSON()
  464. return
  465. }
  466. type User_ struct {
  467. User_uuid string
  468. User_name string //
  469. User_telephone string // 电话
  470. User_mail string // 邮箱
  471. User_gender int // 性别 0未知 1男 2女
  472. User_text string // 详情
  473. User_rh int // 显示湿度
  474. User_Power Admin.AdminPower // 权限
  475. }
  476. Admin_r := User_{}
  477. Admin_r.User_rh = admin_r.Admin_rh
  478. Admin_r.User_uuid = admin_r.Admin_uuid
  479. Admin_r.User_name = admin_r.Admin_name
  480. Admin_r.User_telephone = admin_r.Admin_telephone
  481. Admin_r.User_mail = admin_r.Admin_mail
  482. Admin_r.User_gender = admin_r.Admin_gender
  483. Admin_r.User_text = admin_r.Admin_text
  484. Admin_r.User_Power, _ = Admin.Read_AdminPower_ById(admin_r.Admin_power)
  485. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: Admin_r}
  486. c.ServeJSON()
  487. return
  488. }
  489. func (c *UserController) User_Post() {
  490. // 验证登录
  491. b_, admin_r := lib.Verification(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
  492. if !b_ {
  493. c.Data["json"] = lib.JSONS{Code: 201, Msg: "User_tokey Err!"}
  494. c.ServeJSON()
  495. return
  496. }
  497. //Adminpower,_ := Admin.Read_AdminPower_ById(admin_r.Admin_power)
  498. //
  499. //if Adminpower.Power_User_r != 1 {
  500. // c.Data["json"] = lib.JSONS{Code: 307, Msg: "Adminpower.Power_User_r!"}
  501. // c.ServeJSON()
  502. // return
  503. //}
  504. Admin_uuid := c.GetString("Admin_uuid")
  505. Admin_name := c.GetString("Admin_name")
  506. Admin_user := c.GetString("Admin_user")
  507. Admin_pass := c.GetString("Admin_pass")
  508. Admin_telephone := c.GetString("Admin_telephone")
  509. Admin_mail := c.GetString("Admin_mail")
  510. Admin_text := c.GetString("Admin_text")
  511. Admin_gender, _ := c.GetInt("Admin_gender")
  512. Admin_power, _ := c.GetInt("Admin_power")
  513. var_ := Admin.Admin{
  514. Admin_uuid: uuid.NewV4().String(),
  515. Admin_name: Admin_name,
  516. Admin_master: admin_r.Id,
  517. Admin_user: Admin_user,
  518. Admin_telephone: Admin_telephone,
  519. Admin_mail: Admin_mail,
  520. Admin_text: Admin_text,
  521. Admin_pass: Admin_pass,
  522. Admin_gender: Admin_gender,
  523. Admin_power: Admin_power,
  524. T_State: 1,
  525. }
  526. if len(Admin_pass) > 0 && len(Admin_pass) < 7 {
  527. c.Data["json"] = lib.JSONS{Code: 302, Msg: "Admin_pass Err!"}
  528. c.ServeJSON()
  529. return
  530. }
  531. if len(Admin_uuid) > 0 {
  532. var_.Admin_uuid = Admin_uuid
  533. err, _ := Admin.ReadLogin_verification(var_.Admin_user, var_.Admin_pass)
  534. if err == nil {
  535. c.Data["json"] = lib.JSONS{Code: 307, Msg: "ReadLogin_verification !"}
  536. c.ServeJSON()
  537. return
  538. }
  539. err, r_u := Admin.Read_Admin_ByAdmin_uuid(Admin_uuid)
  540. if err != nil {
  541. c.Data["json"] = lib.JSONS{Code: 302, Msg: "修改失败!"}
  542. c.ServeJSON()
  543. return
  544. }
  545. // 修改密码只有本人
  546. if len(Admin_pass) > 0 && r_u.Id != admin_r.Id {
  547. c.Data["json"] = lib.JSONS{Code: 302, Msg: "r_u != admin_r!"}
  548. c.ServeJSON()
  549. return
  550. }
  551. err = Admin.Update_Admin_ById_Basics(var_)
  552. if err != nil {
  553. c.Data["json"] = lib.JSONS{Code: 302, Msg: "修改失败!"}
  554. c.ServeJSON()
  555. return
  556. }
  557. } else {
  558. s_pass := uuid.NewV4().String()[:6]
  559. h := md5.New()
  560. h.Write([]byte(s_pass))
  561. s := hex.EncodeToString(h.Sum(nil))
  562. fmt.Println(s)
  563. var_.Admin_pass = s
  564. // 是否 内部人员
  565. //Adminpower,_ := Admin.Read_AdminPower_ById(admin_r.Admin_power)
  566. //if Adminpower.Power_Administration == 1 {
  567. // var_.Admin_master = 1
  568. //}
  569. err, _ := Admin.Read_Admin_Admin_user(Admin_user)
  570. if err == nil {
  571. c.Data["json"] = lib.JSONS{Code: 302, Msg: "账户重复!"}
  572. c.ServeJSON()
  573. return
  574. }
  575. _, err = Admin.Add_Admin(var_)
  576. if err != nil {
  577. c.Data["json"] = lib.JSONS{Code: 301, Msg: "添加失败!"}
  578. c.ServeJSON()
  579. return
  580. }
  581. var_.Admin_pass = "****************"
  582. System.Add_UserLogs_T(admin_r.Admin_uuid, "用户管理", "操作", var_)
  583. c.Data["json"] = lib.JSONS{Code: 210, Msg: "ok!", Data: s_pass}
  584. c.ServeJSON()
  585. return
  586. }
  587. var_.Admin_pass = "****************"
  588. System.Add_UserLogs_T(admin_r.Admin_uuid, "用户管理", "操作", var_)
  589. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!"}
  590. c.ServeJSON()
  591. return
  592. }
  593. func (c *UserController) User_v2_Add() {
  594. // 验证登录
  595. b_, admin_r := lib.Verification(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
  596. if !b_ {
  597. c.Data["json"] = lib.JSONS{Code: 201, Msg: "User_tokey Err!"}
  598. c.ServeJSON()
  599. return
  600. }
  601. Admin_power, _ := c.GetInt("T_power")
  602. Admin_name := c.GetString("T_name")
  603. Admin_user := c.GetString("T_user")
  604. Admin_pass := c.GetString("T_pass")
  605. Admin_telephone := c.GetString("T_phone")
  606. Admin_mail := c.GetString("T_mail")
  607. Admin_text := c.GetString("T_text")
  608. var_ := Admin.Admin{
  609. Admin_uuid: uuid.NewV4().String(),
  610. Admin_name: Admin_name,
  611. Admin_master: admin_r.Id,
  612. Admin_user: Admin_user,
  613. Admin_telephone: Admin_telephone,
  614. Admin_mail: Admin_mail,
  615. Admin_text: Admin_text,
  616. Admin_pass: Admin_pass,
  617. Admin_power: Admin_power,
  618. T_State: 1,
  619. }
  620. if len(Admin_pass) > 0 && len(Admin_pass) < 7 {
  621. c.Data["json"] = lib.JSONS{Code: 302, Msg: "Admin_pass Err!"}
  622. c.ServeJSON()
  623. return
  624. }
  625. if admin_r.Admin_power > Admin_power {
  626. c.Data["json"] = lib.JSONS{Code: 202, Msg: "你没有权限 配置 权限!"}
  627. c.ServeJSON()
  628. return
  629. }
  630. if len(Admin_pass) < 8 {
  631. c.Data["json"] = lib.JSONS{Code: 202, Msg: "密码异常!"}
  632. c.ServeJSON()
  633. return
  634. }
  635. err, _ := Admin.Read_Admin_Admin_user(Admin_user)
  636. if err == nil {
  637. c.Data["json"] = lib.JSONS{Code: 302, Msg: "账户重复!"}
  638. c.ServeJSON()
  639. return
  640. }
  641. _, err = Admin.Add_Admin(var_)
  642. if err != nil {
  643. c.Data["json"] = lib.JSONS{Code: 301, Msg: "添加失败!"}
  644. c.ServeJSON()
  645. return
  646. }
  647. var_.Admin_pass = "****************"
  648. System.Add_UserLogs_T(admin_r.Admin_uuid, "用户管理", "添加操作", var_)
  649. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!"}
  650. c.ServeJSON()
  651. return
  652. }
  653. func (c *UserController) User_v2_Edit() {
  654. // 验证登录
  655. b_, admin_r := lib.Verification(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
  656. if !b_ {
  657. c.Data["json"] = lib.JSONS{Code: 201, Msg: "User_tokey Err!"}
  658. c.ServeJSON()
  659. return
  660. }
  661. Admin_name := c.GetString("T_name")
  662. Admin_pass := c.GetString("T_pass")
  663. Admin_telephone := c.GetString("T_phone")
  664. Admin_mail := c.GetString("T_mail")
  665. Admin_text := c.GetString("T_text")
  666. if len(Admin_name) > 0 {
  667. admin_r.Admin_name = Admin_name
  668. }
  669. if len(Admin_pass) > 0 {
  670. admin_r.Admin_pass = Admin_pass
  671. }
  672. if len(Admin_telephone) > 0 {
  673. admin_r.Admin_telephone = Admin_telephone
  674. }
  675. if len(Admin_mail) > 0 {
  676. admin_r.Admin_mail = Admin_mail
  677. }
  678. if len(Admin_text) > 0 {
  679. admin_r.Admin_text = Admin_text
  680. }
  681. if len(Admin_pass) > 0 && len(Admin_pass) < 7 {
  682. c.Data["json"] = lib.JSONS{Code: 203, Msg: "Admin_pass Err!"}
  683. c.ServeJSON()
  684. return
  685. }
  686. is := Admin.Update_Admin(admin_r, "Admin_name", "Admin_pass", "Admin_telephone", "Admin_mail", "Admin_text")
  687. if !is {
  688. c.Data["json"] = lib.JSONS{Code: 204, Msg: "修改失败!"}
  689. c.ServeJSON()
  690. return
  691. }
  692. admin_r.Admin_pass = "****************"
  693. System.Add_UserLogs_T(admin_r.Admin_uuid, "用户管理", "操作", admin_r)
  694. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!"}
  695. c.ServeJSON()
  696. return
  697. }
  698. func (c *UserController) User_v2_AEdit() {
  699. // 验证登录
  700. b_, admin_r := lib.Verification(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
  701. if !b_ {
  702. c.Data["json"] = lib.JSONS{Code: 201, Msg: "User_tokey Err!"}
  703. c.ServeJSON()
  704. return
  705. }
  706. if admin_r.Admin_power > 6 {
  707. c.Data["json"] = lib.JSONS{Code: 204, Msg: "没有权限!"}
  708. c.ServeJSON()
  709. return
  710. }
  711. Admin_uuid := c.GetString("T_uuid")
  712. Admin_user := c.GetString("T_user")
  713. Admin_name := c.GetString("T_name")
  714. Admin_pass := c.GetString("T_pass")
  715. Admin_telephone := c.GetString("T_phone")
  716. Admin_mail := c.GetString("T_mail")
  717. Admin_text := c.GetString("T_text")
  718. Admin_power, _ := c.GetInt("T_power")
  719. if len(Admin_uuid) < 5 {
  720. c.Data["json"] = lib.JSONS{Code: 302, Msg: "Admin_uuid Err!"}
  721. c.ServeJSON()
  722. return
  723. }
  724. // 权限超出
  725. if admin_r.Admin_power > Admin_power {
  726. c.Data["json"] = lib.JSONS{Code: 202, Msg: "你没有权限 配置 权限!"}
  727. c.ServeJSON()
  728. return
  729. }
  730. err, r_u := Admin.Read_Admin_ByAdmin_uuid(Admin_uuid)
  731. if err != nil {
  732. c.Data["json"] = lib.JSONS{Code: 302, Msg: "修改失败!"}
  733. c.ServeJSON()
  734. return
  735. }
  736. // 用户名重复
  737. if len(Admin_user) > 0 {
  738. err, y_user := Admin.Read_Admin_Admin_user(Admin_user)
  739. if err == nil {
  740. if y_user.Id != r_u.Id {
  741. c.Data["json"] = lib.JSONS{Code: 302, Msg: "用户名重复!"}
  742. c.ServeJSON()
  743. return
  744. }
  745. }
  746. r_u.Admin_user = Admin_user
  747. }
  748. if len(Admin_name) > 0 {
  749. r_u.Admin_name = Admin_name
  750. }
  751. if len(Admin_pass) > 0 {
  752. r_u.Admin_pass = Admin_pass
  753. }
  754. if Admin_power > 0 {
  755. r_u.Admin_power = Admin_power
  756. }
  757. if len(Admin_telephone) > 0 {
  758. r_u.Admin_telephone = Admin_telephone
  759. }
  760. if len(Admin_mail) > 0 {
  761. r_u.Admin_mail = Admin_mail
  762. }
  763. if len(Admin_text) > 0 {
  764. r_u.Admin_text = Admin_text
  765. }
  766. is := Admin.Update_Admin(r_u, "Admin_user", "Admin_name", "Admin_pass", "Admin_telephone", "Admin_mail", "Admin_text", "Admin_power")
  767. if !is {
  768. c.Data["json"] = lib.JSONS{Code: 204, Msg: "修改失败!"}
  769. c.ServeJSON()
  770. return
  771. }
  772. r_u.Admin_pass = "****************"
  773. System.Add_UserLogs_T(admin_r.Admin_uuid, "用户管理", "操作", r_u)
  774. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!"}
  775. c.ServeJSON()
  776. return
  777. }
  778. func (c *UserController) User_Del() {
  779. // 验证登录
  780. b_, admin_r := lib.Verification(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
  781. if !b_ {
  782. c.Ctx.Redirect(302, "Login")
  783. return
  784. }
  785. if admin_r.Admin_power > 6 {
  786. c.Data["json"] = lib.JSONS{Code: 204, Msg: "没有权限!"}
  787. c.ServeJSON()
  788. return
  789. }
  790. Admin_uuid := c.GetString("Admin_uuid")
  791. if len(Admin_uuid) > 0 {
  792. admin_r_lod, err := Admin.Read_Admin_ByUuid(Admin_uuid)
  793. if err != nil {
  794. c.Data["json"] = lib.JSONS{Code: 201, Msg: "e!"}
  795. c.ServeJSON()
  796. return
  797. }
  798. if admin_r_lod.Admin_master < admin_r.Admin_master {
  799. c.Data["json"] = lib.JSONS{Code: 202, Msg: "e!"}
  800. c.ServeJSON()
  801. return
  802. }
  803. admin_r_lod.T_State = 0
  804. Admin.Update_Admin(admin_r_lod, "T_State")
  805. //Admin.Update_Delete_Admin_ByAdmin_uuid(Admin_uuid)
  806. } else {
  807. c.Data["json"] = lib.JSONS{Code: 203, Msg: "e!"}
  808. c.ServeJSON()
  809. return
  810. }
  811. System.Add_UserLogs_T(admin_r.Admin_uuid, "用户管理", "删除", Admin_uuid)
  812. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!"}
  813. c.ServeJSON()
  814. return
  815. }
  816. func (c *UserController) V2_User_Del() {
  817. // 验证登录
  818. b_, admin_r := lib.Verification(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
  819. if !b_ {
  820. c.Data["json"] = lib.JSONS{Code: 201, Msg: "User_tokey Err!"}
  821. c.ServeJSON()
  822. return
  823. }
  824. if admin_r.Admin_power > 6 {
  825. c.Data["json"] = lib.JSONS{Code: 204, Msg: "没有权限!"}
  826. c.ServeJSON()
  827. return
  828. }
  829. Admin_uuid := c.GetString("T_uuid")
  830. if len(Admin_uuid) > 0 {
  831. admin_r_lod, err := Admin.Read_Admin_ByUuid(Admin_uuid)
  832. if err != nil {
  833. c.Data["json"] = lib.JSONS{Code: 204, Msg: "e!"}
  834. c.ServeJSON()
  835. return
  836. }
  837. if admin_r_lod.Admin_master < admin_r.Admin_master {
  838. c.Data["json"] = lib.JSONS{Code: 202, Msg: "e!"}
  839. c.ServeJSON()
  840. return
  841. }
  842. admin_r_lod.T_State = 0
  843. Admin.Update_Admin(admin_r_lod, "T_State")
  844. //Admin.Update_Delete_Admin_ByAdmin_uuid(Admin_uuid)
  845. } else {
  846. c.Data["json"] = lib.JSONS{Code: 203, Msg: "e!"}
  847. c.ServeJSON()
  848. return
  849. }
  850. System.Add_UserLogs_T(admin_r.Admin_uuid, "用户管理", "删除", Admin_uuid)
  851. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!"}
  852. c.ServeJSON()
  853. return
  854. }
  855. // 权限管理
  856. func (c *UserController) Power_html() {
  857. // 验证登录
  858. b_, admin_r := lib.Verification(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
  859. if !b_ {
  860. c.Ctx.Redirect(302, "Login")
  861. return
  862. }
  863. if admin_r.Id != 1 {
  864. c.Ctx.Redirect(302, "Login")
  865. return
  866. }
  867. if admin_r.Admin_master != 0 {
  868. c.Ctx.Redirect(302, "Login")
  869. return
  870. }
  871. c.Data["Admin_Power"], _ = Admin.Read_AdminPower_ById(admin_r.Admin_power)
  872. fmt.Println("登录OK")
  873. page, _ := c.GetInt("page")
  874. println(page)
  875. if page < 1 {
  876. page = 1
  877. }
  878. Name := c.GetString("Name")
  879. c.Data["Name"] = Name
  880. var cnt int64
  881. c.Data["List"], cnt = Admin.Read_Power_List_ALL(Name, page, 9999)
  882. fmt.Println("cnt:", cnt)
  883. page_size := math.Ceil(float64(cnt) / float64(conf.Page_size))
  884. c.Data["Page"] = page
  885. c.Data["Page_size"] = page_size
  886. c.Data["Pages"] = lib.Func_page(int64(page), int64(page_size))
  887. c.Data["cnt"] = cnt
  888. c.TplName = "User/Power.html"
  889. }
  890. // 权限管理
  891. func (c *UserController) Power_List() {
  892. // 验证登录
  893. b_, _ := lib.Verification(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
  894. if !b_ {
  895. c.Data["json"] = lib.JSONS{Code: 201, Msg: "User_tokey Err!"}
  896. c.ServeJSON()
  897. return
  898. }
  899. //
  900. //if admin_r.Admin_master != 0 {
  901. // c.Data["json"] = lib.JSONS{Code: 202, Msg: "没有权限!"}
  902. // c.ServeJSON()
  903. // return
  904. //}
  905. type R_JSONS struct {
  906. //必须的大写开头
  907. Data []Admin.AdminPower
  908. Num int64
  909. Page int
  910. Page_size int
  911. }
  912. var r_jsons R_JSONS
  913. page, _ := c.GetInt("page")
  914. println(page)
  915. if page < 1 {
  916. page = 1
  917. }
  918. page_z, _ := c.GetInt("page_z")
  919. if page_z < 1 {
  920. page_z = conf.Page_size
  921. }
  922. Name := c.GetString("T_name")
  923. r_jsons.Data, r_jsons.Num = Admin.Read_Power_List_ALL(Name, page, page_z)
  924. r_jsons.Page = page
  925. r_jsons.Page_size = int(math.Ceil(float64(r_jsons.Num) / float64(page_z)))
  926. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: r_jsons}
  927. c.ServeJSON()
  928. return
  929. }
  930. func (c *UserController) Power_() {
  931. // 验证登录
  932. b_, admin_r := lib.Verification(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
  933. if !b_ {
  934. c.Ctx.Redirect(302, "Login")
  935. return
  936. }
  937. if admin_r.Id != 1 {
  938. c.Ctx.Redirect(302, "Login")
  939. return
  940. }
  941. if admin_r.Admin_master != 0 {
  942. c.Ctx.Redirect(302, "Login")
  943. return
  944. }
  945. id, _ := c.GetInt("id")
  946. c.Data["id"] = id
  947. if id > 0 {
  948. c.Data["Date"], _ = Admin.Read_AdminPower_ById(id)
  949. }
  950. c.TplName = "User/Power-.html"
  951. }
  952. func (c *UserController) Power_Get() {
  953. // 验证登录
  954. b_, admin_r := lib.Verification(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
  955. if !b_ {
  956. c.Data["json"] = lib.JSONS{Code: 201, Msg: "User_tokey Err!"}
  957. c.ServeJSON()
  958. return
  959. }
  960. if admin_r.Id != 1 {
  961. c.Data["json"] = lib.JSONS{Code: 202, Msg: "没有权限!"}
  962. c.ServeJSON()
  963. return
  964. }
  965. if admin_r.Admin_master != 0 {
  966. c.Data["json"] = lib.JSONS{Code: 202, Msg: "没有权限!"}
  967. c.ServeJSON()
  968. return
  969. }
  970. id, _ := c.GetInt("T_id")
  971. if id == 0 {
  972. c.Data["json"] = lib.JSONS{Code: 202, Msg: "T_id Err!"}
  973. c.ServeJSON()
  974. return
  975. }
  976. Data, _ := Admin.Read_AdminPower_ById(id)
  977. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: Data}
  978. c.ServeJSON()
  979. return
  980. }
  981. func (c *UserController) Power_Post() {
  982. var err error
  983. // 验证登录
  984. b_, admin_r := lib.Verification(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
  985. if !b_ {
  986. c.Ctx.Redirect(302, "Login")
  987. return
  988. }
  989. if admin_r.Id != 1 {
  990. c.Ctx.Redirect(302, "Login")
  991. return
  992. }
  993. if admin_r.Admin_master != 0 {
  994. c.Ctx.Redirect(302, "Login")
  995. return
  996. }
  997. id, _ := c.GetInt("id")
  998. c.Data["id"] = id
  999. Power_name := c.GetString("Power_name")
  1000. Power_Administration, _ := c.GetInt("Power_Administration")
  1001. Power_User_r, _ := c.GetInt("Power_User_r")
  1002. Power_User_entry, _ := c.GetInt("Power_User_entry")
  1003. Power_Device_r, _ := c.GetInt("Power_Device_r")
  1004. Power_Device_a, _ := c.GetInt("Power_Device_a")
  1005. Power_Device_Parameter_e, _ := c.GetInt("Power_Device_Parameter_e")
  1006. Power_DeviceSensor_Parameter_e, _ := c.GetInt("Power_DeviceSensor_Parameter_e")
  1007. Power_Device_Bind_e, _ := c.GetInt("Power_Device_Bind_e")
  1008. Power_DeviceSensor_Compensate_e, _ := c.GetInt("Power_DeviceSensor_Compensate_e")
  1009. Power_DeviceSensor_Class, _ := c.GetInt("Power_DeviceSensor_Class")
  1010. Power_DataScreen_r, _ := c.GetInt("Power_DataScreen_r")
  1011. Logs_Sys_r, _ := c.GetInt("Logs_Sys_r")
  1012. Logs_User_r, _ := c.GetInt("Logs_User_r")
  1013. var_ := Admin.AdminPower{
  1014. Power_name: Power_name,
  1015. Power_Administration: Power_Administration,
  1016. Power_User_r: Power_User_r,
  1017. Power_User_entry: Power_User_entry,
  1018. Power_Device_r: Power_Device_r,
  1019. Power_Device_a: Power_Device_a,
  1020. Power_Device_Parameter_e: Power_Device_Parameter_e,
  1021. Power_DeviceSensor_Parameter_e: Power_DeviceSensor_Parameter_e,
  1022. Power_Device_Bind_e: Power_Device_Bind_e,
  1023. Power_DeviceSensor_Class: Power_DeviceSensor_Class,
  1024. Power_DeviceSensor_Compensate_e: Power_DeviceSensor_Compensate_e,
  1025. Power_DataScreen_r: Power_DataScreen_r,
  1026. Logs_Sys_r: Logs_Sys_r,
  1027. Logs_User_r: Logs_User_r,
  1028. T_State: 1,
  1029. }
  1030. if id > 0 {
  1031. var_.Id = id
  1032. fmt.Println("Power_DataScreen_r:", var_.Power_DataScreen_r)
  1033. err = Admin.Update_AdminPower_ById_Basics(var_)
  1034. if err != nil {
  1035. c.Data["json"] = lib.JSONS{Code: 302, Msg: "修改失败!"}
  1036. c.ServeJSON()
  1037. return
  1038. }
  1039. } else {
  1040. _, err = Admin.Add_AdminPower(var_)
  1041. if err != nil {
  1042. c.Data["json"] = lib.JSONS{Code: 301, Msg: "添加失败!"}
  1043. c.ServeJSON()
  1044. return
  1045. }
  1046. }
  1047. System.Add_UserLogs_T(admin_r.Admin_uuid, "权限管理", "权限操作", var_)
  1048. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!"}
  1049. c.ServeJSON()
  1050. return
  1051. }
  1052. func (c *UserController) Power_Del() {
  1053. // 验证登录
  1054. b_, admin_r := lib.Verification(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
  1055. if !b_ {
  1056. c.Ctx.Redirect(302, "Login")
  1057. return
  1058. }
  1059. if admin_r.Id != 1 {
  1060. c.Ctx.Redirect(302, "Login")
  1061. return
  1062. }
  1063. if admin_r.Admin_master != 0 {
  1064. c.Data["json"] = lib.JSONS{Code: 203, Msg: "没有权限!"}
  1065. c.ServeJSON()
  1066. return
  1067. }
  1068. id, _ := c.GetInt("Id")
  1069. c.Data["id"] = id
  1070. if id > 0 {
  1071. admin_r_lod, err := Admin.Read_AdminPower_ById(id)
  1072. if err != nil {
  1073. c.Data["json"] = lib.JSONS{Code: 201, Msg: "e!"}
  1074. c.ServeJSON()
  1075. return
  1076. }
  1077. Admin_List_ALL_AdminPower := Admin.Read_Admin_List_ALL_AdminPower(admin_r_lod.Id)
  1078. if len(Admin_List_ALL_AdminPower) > 0 {
  1079. S_Msg := "无法删除!【"
  1080. for _, v := range Admin_List_ALL_AdminPower {
  1081. S_Msg += v.Admin_name + ","
  1082. }
  1083. c.Data["json"] = lib.JSONS{Code: 205, Msg: S_Msg + "】 属于该权限!删除这些账号后即可删除! "}
  1084. c.ServeJSON()
  1085. return
  1086. }
  1087. Admin.Update_Delete_AdminPower_Byid(admin_r_lod.Id)
  1088. } else {
  1089. c.Data["json"] = lib.JSONS{Code: 204, Msg: "e!"}
  1090. c.ServeJSON()
  1091. return
  1092. }
  1093. System.Add_UserLogs(admin_r.Admin_uuid, "权限管理", "权限删除", strconv.Itoa(id))
  1094. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!"}
  1095. c.ServeJSON()
  1096. return
  1097. }
  1098. func (c *UserController) Power_v2_Add() {
  1099. // 验证登录
  1100. b_, admin_r := lib.Verification(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
  1101. if !b_ {
  1102. c.Data["json"] = lib.JSONS{Code: 201, Msg: "User_tokey Err!"}
  1103. c.ServeJSON()
  1104. return
  1105. }
  1106. if admin_r.Id != 1 {
  1107. c.Data["json"] = lib.JSONS{Code: 202, Msg: "没有权限!"}
  1108. c.ServeJSON()
  1109. return
  1110. }
  1111. if admin_r.Admin_master != 0 {
  1112. c.Data["json"] = lib.JSONS{Code: 202, Msg: "没有权限!"}
  1113. c.ServeJSON()
  1114. return
  1115. }
  1116. Power_name := c.GetString("Power_name")
  1117. Power_Administration, _ := c.GetInt("Power_Administration")
  1118. Power_User_r, _ := c.GetInt("Power_User_r")
  1119. Power_User_entry, _ := c.GetInt("Power_User_entry")
  1120. Power_Device_r, _ := c.GetInt("Power_Device_r")
  1121. Power_Device_a, _ := c.GetInt("Power_Device_a")
  1122. Power_Device_Parameter_e, _ := c.GetInt("Power_Device_Parameter_e")
  1123. Power_DeviceSensor_Parameter_e, _ := c.GetInt("Power_DeviceSensor_Parameter_e")
  1124. Power_Device_Bind_e, _ := c.GetInt("Power_Device_Bind_e")
  1125. Power_DeviceSensor_Compensate_e, _ := c.GetInt("Power_DeviceSensor_Compensate_e")
  1126. Power_DeviceSensor_Class, _ := c.GetInt("Power_DeviceSensor_Class")
  1127. Power_DataScreen_r, _ := c.GetInt("Power_DataScreen_r")
  1128. Logs_Sys_r, _ := c.GetInt("Logs_Sys_r")
  1129. Logs_User_r, _ := c.GetInt("Logs_User_r")
  1130. var_ := Admin.AdminPower{
  1131. Power_name: Power_name,
  1132. Power_Administration: Power_Administration,
  1133. Power_User_r: Power_User_r,
  1134. Power_User_entry: Power_User_entry,
  1135. Power_Device_r: Power_Device_r,
  1136. Power_Device_a: Power_Device_a,
  1137. Power_Device_Parameter_e: Power_Device_Parameter_e,
  1138. Power_DeviceSensor_Parameter_e: Power_DeviceSensor_Parameter_e,
  1139. Power_Device_Bind_e: Power_Device_Bind_e,
  1140. Power_DeviceSensor_Class: Power_DeviceSensor_Class,
  1141. Power_DeviceSensor_Compensate_e: Power_DeviceSensor_Compensate_e,
  1142. Power_DataScreen_r: Power_DataScreen_r,
  1143. Logs_Sys_r: Logs_Sys_r,
  1144. Logs_User_r: Logs_User_r,
  1145. T_State: 1,
  1146. }
  1147. _, err := Admin.Add_AdminPower(var_)
  1148. if err != nil {
  1149. c.Data["json"] = lib.JSONS{Code: 301, Msg: "添加失败!"}
  1150. c.ServeJSON()
  1151. return
  1152. }
  1153. System.Add_UserLogs_T(admin_r.Admin_uuid, "权限管理", "权限操作", var_)
  1154. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!"}
  1155. c.ServeJSON()
  1156. return
  1157. }
  1158. func (c *UserController) Power_v2_Edit() {
  1159. // 验证登录
  1160. b_, admin_r := lib.Verification(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
  1161. if !b_ {
  1162. c.Data["json"] = lib.JSONS{Code: 201, Msg: "User_tokey Err!"}
  1163. c.ServeJSON()
  1164. return
  1165. }
  1166. if admin_r.Id != 1 {
  1167. c.Data["json"] = lib.JSONS{Code: 202, Msg: "没有权限!"}
  1168. c.ServeJSON()
  1169. return
  1170. }
  1171. if admin_r.Admin_master != 0 {
  1172. c.Data["json"] = lib.JSONS{Code: 202, Msg: "没有权限!"}
  1173. c.ServeJSON()
  1174. return
  1175. }
  1176. id, _ := c.GetInt("T_id")
  1177. Power_name := c.GetString("Power_name")
  1178. Power_Administration, _ := c.GetInt("Power_Administration")
  1179. Power_User_r, _ := c.GetInt("Power_User_r")
  1180. Power_User_e, _ := c.GetInt("Power_User_e")
  1181. Power_User_entry, _ := c.GetInt("Power_User_entry")
  1182. Power_Device_r, _ := c.GetInt("Power_Device_r")
  1183. Power_Device_a, _ := c.GetInt("Power_Device_a")
  1184. Power_Device_Parameter_e, _ := c.GetInt("Power_Device_Parameter_e")
  1185. Power_DeviceSensor_Parameter_e, _ := c.GetInt("Power_DeviceSensor_Parameter_e")
  1186. Power_Device_Bind_e, _ := c.GetInt("Power_Device_Bind_e")
  1187. Power_DeviceSensor_Compensate_e, _ := c.GetInt("Power_DeviceSensor_Compensate_e")
  1188. Power_DeviceSensor_Class, _ := c.GetInt("Power_DeviceSensor_Class")
  1189. Power_DataScreen_r, _ := c.GetInt("Power_DataScreen_r")
  1190. Logs_Sys_r, _ := c.GetInt("Logs_Sys_r")
  1191. Logs_User_r, _ := c.GetInt("Logs_User_r")
  1192. var_ := Admin.AdminPower{
  1193. Id: id,
  1194. Power_name: Power_name,
  1195. Power_Administration: Power_Administration,
  1196. Power_User_r: Power_User_r,
  1197. Power_User_e: Power_User_e,
  1198. Power_User_entry: Power_User_entry,
  1199. Power_Device_r: Power_Device_r,
  1200. Power_Device_a: Power_Device_a,
  1201. Power_Device_Parameter_e: Power_Device_Parameter_e,
  1202. Power_DeviceSensor_Parameter_e: Power_DeviceSensor_Parameter_e,
  1203. Power_Device_Bind_e: Power_Device_Bind_e,
  1204. Power_DeviceSensor_Class: Power_DeviceSensor_Class,
  1205. Power_DeviceSensor_Compensate_e: Power_DeviceSensor_Compensate_e,
  1206. Power_DataScreen_r: Power_DataScreen_r,
  1207. Logs_Sys_r: Logs_Sys_r,
  1208. Logs_User_r: Logs_User_r,
  1209. T_State: 1,
  1210. }
  1211. err := Admin.Update_AdminPower_ById_Basics(var_)
  1212. if err != nil {
  1213. c.Data["json"] = lib.JSONS{Code: 302, Msg: "修改失败!"}
  1214. c.ServeJSON()
  1215. return
  1216. }
  1217. System.Add_UserLogs_T(admin_r.Admin_uuid, "权限管理", "权限操作", var_)
  1218. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!"}
  1219. c.ServeJSON()
  1220. return
  1221. }
  1222. func (c *UserController) Power_v2_Del() {
  1223. // 验证登录
  1224. b_, admin_r := lib.Verification(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
  1225. if !b_ {
  1226. c.Data["json"] = lib.JSONS{Code: 201, Msg: "User_tokey Err!"}
  1227. c.ServeJSON()
  1228. return
  1229. }
  1230. if admin_r.Id != 1 {
  1231. c.Data["json"] = lib.JSONS{Code: 202, Msg: "没有权限!"}
  1232. c.ServeJSON()
  1233. return
  1234. }
  1235. if admin_r.Admin_master != 0 {
  1236. c.Data["json"] = lib.JSONS{Code: 202, Msg: "没有权限!"}
  1237. c.ServeJSON()
  1238. return
  1239. }
  1240. id, _ := c.GetInt("T_id")
  1241. if id > 0 {
  1242. admin_r_lod, err := Admin.Read_AdminPower_ById(id)
  1243. if err != nil {
  1244. c.Data["json"] = lib.JSONS{Code: 201, Msg: "e!"}
  1245. c.ServeJSON()
  1246. return
  1247. }
  1248. Admin_List_ALL_AdminPower := Admin.Read_Admin_List_ALL_AdminPower(admin_r_lod.Id)
  1249. if len(Admin_List_ALL_AdminPower) > 0 {
  1250. S_Msg := "无法删除!【"
  1251. for _, v := range Admin_List_ALL_AdminPower {
  1252. S_Msg += v.Admin_name + ","
  1253. }
  1254. c.Data["json"] = lib.JSONS{Code: 205, Msg: S_Msg + "】 属于该权限!删除这些账号后即可删除! "}
  1255. c.ServeJSON()
  1256. return
  1257. }
  1258. Admin.Update_Delete_AdminPower_Byid(admin_r_lod.Id)
  1259. } else {
  1260. c.Data["json"] = lib.JSONS{Code: 204, Msg: "e!"}
  1261. c.ServeJSON()
  1262. return
  1263. }
  1264. System.Add_UserLogs(admin_r.Admin_uuid, "权限管理", "权限删除", strconv.Itoa(id))
  1265. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!"}
  1266. c.ServeJSON()
  1267. return
  1268. }
  1269. // 同步面板
  1270. func (c *UserController) Panel_plan_Syn() {
  1271. // 验证登录
  1272. b_, admin_r := lib.Verification(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
  1273. if !b_ {
  1274. c.Data["json"] = lib.JSONS{Code: 201, Msg: "User_tokey Err!"}
  1275. c.ServeJSON()
  1276. return
  1277. }
  1278. s_, user_r := Admin.Read_Admin_ByAdmin_uuid(c.GetString("Admin_uuid"))
  1279. if s_ != nil {
  1280. c.Data["json"] = lib.JSONS{Code: 202, Msg: "Admin_uuid Err!"}
  1281. c.ServeJSON()
  1282. return
  1283. }
  1284. user_r.Admin_panel_plan = admin_r.Admin_panel_plan
  1285. Admin.Update_Admin(user_r, "Admin_panel_plan")
  1286. System.Add_UserLogs(admin_r.Admin_uuid, "设备管理", "同步面板操作", "面板:"+admin_r.Admin_panel_plan+"|"+admin_r.Admin_uuid+"->"+user_r.Admin_uuid)
  1287. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!"}
  1288. c.ServeJSON()
  1289. return
  1290. }