Template.go 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256
  1. package controllers
  2. import (
  3. "ColdVerify_server/conf"
  4. "ColdVerify_server/lib"
  5. "ColdVerify_server/models/Account"
  6. "ColdVerify_server/models/System"
  7. "ColdVerify_server/models/Template"
  8. beego "github.com/beego/beego/v2/server/web"
  9. "math"
  10. )
  11. type TemplateController struct {
  12. beego.Controller
  13. }
  14. // 列表 -
  15. func (c *TemplateController) List_html() {
  16. // 验证登录 User_is, User_r
  17. _, User_is := Account.Verification_Admin(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
  18. if !User_is {
  19. c.Data["json"] = lib.JSONS{Code: 201, Msg: "请重新登录!"}
  20. c.ServeJSON()
  21. return
  22. }
  23. page, _ := c.GetInt("page")
  24. println(page)
  25. if page < 1 {
  26. page = 1
  27. }
  28. page_z, _ := c.GetInt("page_z")
  29. if page_z < 1 {
  30. page_z = conf.Page_size
  31. }
  32. T_name := c.GetString("T_name")
  33. T_class, _ := c.GetInt("T_class")
  34. c.Data["T_name"] = T_name
  35. c.Data["T_class"] = T_class
  36. var cnt int64
  37. c.Data["List"], cnt = Template.Read_Template_List(T_name, T_class, page, page_z)
  38. page_size := math.Ceil(float64(cnt) / float64(conf.Page_size))
  39. c.Data["Page"] = page
  40. c.Data["Page_size"] = page_size
  41. c.Data["Pages"] = lib.Func_page(int64(page), int64(page_size))
  42. c.Data["cnt"] = cnt
  43. c.TplName = "Template/Template.html"
  44. }
  45. // 二级页面
  46. func (c *TemplateController) List_() {
  47. // 验证登录 User_is, User_r
  48. _, User_is := Account.Verification_Admin(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
  49. if !User_is {
  50. c.Data["json"] = lib.JSONS{Code: 201, Msg: "请重新登录!"}
  51. c.ServeJSON()
  52. return
  53. }
  54. Id, _ := c.GetInt("Id")
  55. c.Data["Id"] = Id
  56. if Id > 0 {
  57. c.Data["Date"], _ = Template.Read_Template_ById(Id)
  58. //c.Data["FormulaList"] = Formula.ReadFormulaListByid_List(id)
  59. }
  60. c.TplName = "Template/Template-.html"
  61. }
  62. // 获取-
  63. func (c *TemplateController) Get() {
  64. // 验证登录 User_is, User_r
  65. _, User_is := Account.Verification_Admin(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
  66. if !User_is {
  67. c.Data["json"] = lib.JSONS{Code: 201, Msg: "请重新登录!"}
  68. c.ServeJSON()
  69. return
  70. }
  71. Id, err := c.GetInt("Id")
  72. if err != nil {
  73. c.Data["json"] = lib.JSONS{Code: 202, Msg: "Id 错误!"}
  74. c.ServeJSON()
  75. return
  76. }
  77. r, is := Template.Read_Template_ById(Id)
  78. if !is {
  79. c.Data["json"] = lib.JSONS{Code: 202, Msg: "Id 错误!"}
  80. c.ServeJSON()
  81. return
  82. }
  83. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: r}
  84. c.ServeJSON()
  85. return
  86. }
  87. // 列表 -
  88. func (c *TemplateController) List() {
  89. // 验证登录 User_is, User_r
  90. _, User_is := Account.Verification_Admin(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
  91. if !User_is {
  92. c.Data["json"] = lib.JSONS{Code: 201, Msg: "请重新登录!"}
  93. c.ServeJSON()
  94. return
  95. }
  96. var r_jsons lib.R_JSONS
  97. page, _ := c.GetInt("page")
  98. if page < 1 {
  99. page = 1
  100. }
  101. page_z, _ := c.GetInt("page_z")
  102. if page_z < 1 {
  103. page_z = conf.Page_size
  104. }
  105. T_name := c.GetString("T_name")
  106. T_class, _ := c.GetInt("T_class")
  107. var cnt int64
  108. List, cnt := Template.Read_Template_List(T_name, T_class, page, page_z)
  109. page_size := math.Ceil(float64(cnt) / float64(page_z))
  110. r_jsons.List = List
  111. r_jsons.Page = page
  112. r_jsons.Page_size = int(page_size)
  113. r_jsons.Pages = lib.Func_page(int64(page), int64(page_size))
  114. r_jsons.Num = int(cnt)
  115. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: r_jsons}
  116. c.ServeJSON()
  117. return
  118. }
  119. // 添加-
  120. func (c *TemplateController) Add() {
  121. // 验证登录 User_is, User_r
  122. User_r, User_is := Account.Verification_Admin(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
  123. if !User_is {
  124. c.Data["json"] = lib.JSONS{Code: 201, Msg: "请重新登录!"}
  125. c.ServeJSON()
  126. return
  127. }
  128. T_name := c.GetString("T_name")
  129. T_class, _ := c.GetInt("T_class")
  130. //T_img := c.GetString("T_img")
  131. //T_int, _ := c.GetInt("T_int")
  132. //T_text := c.GetString("T_text")
  133. var_ := Template.Template{
  134. T_name: T_name,
  135. T_class: T_class,
  136. T_State: 1,
  137. }
  138. Id, is := Template.Add_Template(var_)
  139. if !is {
  140. c.Data["json"] = lib.JSONS{Code: 202, Msg: "添加失败!"}
  141. c.ServeJSON()
  142. return
  143. }
  144. System.Add_UserLogs_T(User_r.T_uuid, "模板管理", "添加", var_)
  145. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: Id}
  146. c.ServeJSON()
  147. return
  148. }
  149. // 修改-
  150. func (c *TemplateController) Up() {
  151. // 验证登录 User_is, User_r
  152. User_r, User_is := Account.Verification_Admin(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
  153. if !User_is {
  154. c.Data["json"] = lib.JSONS{Code: 201, Msg: "请重新登录!"}
  155. c.ServeJSON()
  156. return
  157. }
  158. T_name := c.GetString("T_name")
  159. T_class, T_class_err := c.GetInt("T_class")
  160. //T_img := c.GetString("T_img")
  161. //T_int, _ := c.GetInt("T_int")
  162. //T_text := c.GetString("T_text")
  163. Id, err := c.GetInt("Id")
  164. if err != nil {
  165. c.Data["json"] = lib.JSONS{Code: 202, Msg: "Id 错误!"}
  166. c.ServeJSON()
  167. return
  168. }
  169. r, is := Template.Read_Template_ById(Id)
  170. if !is {
  171. c.Data["json"] = lib.JSONS{Code: 202, Msg: "Id 错误!"}
  172. c.ServeJSON()
  173. return
  174. }
  175. // .......
  176. if len(T_name) > 0 {
  177. r.T_name = T_name
  178. }
  179. if T_class_err == nil {
  180. r.T_class = T_class
  181. }
  182. // .......
  183. if !Template.Update_Template(r, "T_name", "T_class") {
  184. c.Data["json"] = lib.JSONS{Code: 202, Msg: "修改失败!"}
  185. c.ServeJSON()
  186. return
  187. }
  188. System.Add_UserLogs_T(User_r.T_uuid, "模板管理", "修改", r)
  189. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!"}
  190. c.ServeJSON()
  191. return
  192. }
  193. // 删除-
  194. func (c *TemplateController) Del() {
  195. // 验证登录 User_is, User_r
  196. User_r, User_is := Account.Verification_Admin(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
  197. if !User_is {
  198. c.Data["json"] = lib.JSONS{Code: 201, Msg: "请重新登录!"}
  199. c.ServeJSON()
  200. return
  201. }
  202. Id, err := c.GetInt("Id")
  203. if err != nil {
  204. c.Data["json"] = lib.JSONS{Code: 202, Msg: "Id 错误!"}
  205. c.ServeJSON()
  206. return
  207. }
  208. if r, is := Template.Read_Template_ById(Id); is {
  209. if !Template.Delete_Template(r) {
  210. c.Data["json"] = lib.JSONS{Code: 202, Msg: "删除失败!"}
  211. c.ServeJSON()
  212. return
  213. }
  214. System.Add_UserLogs_T(User_r.T_uuid, "模板管理", "删除", r)
  215. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!"}
  216. c.ServeJSON()
  217. return
  218. }
  219. c.Data["json"] = lib.JSONS{Code: 202, Msg: "Id 错误!"}
  220. c.ServeJSON()
  221. return
  222. }