Distributor.go 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  1. package controllers
  2. import (
  3. "ColdVerify_server/conf"
  4. "ColdVerify_server/lib"
  5. "ColdVerify_server/models/Account"
  6. "ColdVerify_server/models/Distributor"
  7. "ColdVerify_server/models/System"
  8. beego "github.com/beego/beego/v2/server/web"
  9. "math"
  10. )
  11. type DistributorController struct {
  12. beego.Controller
  13. }
  14. // 列表 -
  15. func (c *DistributorController) List() {
  16. // 验证登录 User_is, User_r
  17. User_r, 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. if User_r.T_power > 2 || len(User_r.T_Distributor_id) > 0 {
  24. c.Data["json"] = lib.JSONS{Code: 202, Msg: "无权操作!"}
  25. c.ServeJSON()
  26. return
  27. }
  28. var r_jsons lib.R_JSONS
  29. page, _ := c.GetInt("page")
  30. if page < 1 {
  31. page = 1
  32. }
  33. page_z, _ := c.GetInt("page_z")
  34. if page_z < 1 {
  35. page_z = conf.Page_size
  36. }
  37. T_name := c.GetString("T_name")
  38. var cnt int64
  39. List, cnt := Distributor.Read_Distributor_List(T_name, page, page_z)
  40. page_size := math.Ceil(float64(cnt) / float64(page_z))
  41. r_jsons.List = List
  42. r_jsons.Page = page
  43. r_jsons.Page_size = int(page_size)
  44. r_jsons.Pages = lib.Func_page(int64(page), int64(page_size))
  45. r_jsons.Num = int(cnt)
  46. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: r_jsons}
  47. c.ServeJSON()
  48. return
  49. }
  50. // 添加-
  51. func (c *DistributorController) Add() {
  52. // 验证登录 User_is, User_r
  53. User_r, User_is := Account.Verification_Admin(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
  54. if !User_is {
  55. c.Data["json"] = lib.JSONS{Code: 201, Msg: "请重新登录!"}
  56. c.ServeJSON()
  57. return
  58. }
  59. if User_r.T_power > 2 || len(User_r.T_Distributor_id) > 0 {
  60. c.Data["json"] = lib.JSONS{Code: 202, Msg: "无权操作!"}
  61. c.ServeJSON()
  62. return
  63. }
  64. T_name := c.GetString("T_name")
  65. var_ := Distributor.Distributor{
  66. T_name: T_name,
  67. T_State: 1,
  68. }
  69. Id, is := Distributor.Add_Distributor(var_)
  70. if !is {
  71. c.Data["json"] = lib.JSONS{Code: 202, Msg: "添加失败!"}
  72. c.ServeJSON()
  73. return
  74. }
  75. System.Add_UserLogs_T(User_r.T_uuid, "经销商管理", "添加", var_)
  76. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: Id}
  77. c.ServeJSON()
  78. return
  79. }
  80. // 修改-
  81. func (c *DistributorController) Up() {
  82. // 验证登录 User_is, User_r
  83. User_r, User_is := Account.Verification_Admin(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
  84. if !User_is {
  85. c.Data["json"] = lib.JSONS{Code: 201, Msg: "请重新登录!"}
  86. c.ServeJSON()
  87. return
  88. }
  89. if User_r.T_power > 2 || len(User_r.T_Distributor_id) > 0 {
  90. c.Data["json"] = lib.JSONS{Code: 202, Msg: "无权操作!"}
  91. c.ServeJSON()
  92. return
  93. }
  94. T_name := c.GetString("T_name")
  95. T_Distributor_id := c.GetString("T_Distributor_id")
  96. r, is := Distributor.Read_Distributor(T_Distributor_id)
  97. if !is {
  98. c.Data["json"] = lib.JSONS{Code: 202, Msg: "Id 错误!"}
  99. c.ServeJSON()
  100. return
  101. }
  102. // .......
  103. if len(T_name) > 0 {
  104. r.T_name = T_name
  105. }
  106. if !Distributor.Update_Distributor(r, "T_name") {
  107. c.Data["json"] = lib.JSONS{Code: 202, Msg: "修改失败!"}
  108. c.ServeJSON()
  109. return
  110. }
  111. System.Add_UserLogs_T(User_r.T_uuid, "经销商管理", "修改", r)
  112. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!"}
  113. c.ServeJSON()
  114. return
  115. }
  116. // 删除-
  117. func (c *DistributorController) Del() {
  118. // 验证登录 User_is, User_r
  119. User_r, User_is := Account.Verification_Admin(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
  120. if !User_is {
  121. c.Data["json"] = lib.JSONS{Code: 201, Msg: "请重新登录!"}
  122. c.ServeJSON()
  123. return
  124. }
  125. if User_r.T_power > 2 || len(User_r.T_Distributor_id) > 0 {
  126. c.Data["json"] = lib.JSONS{Code: 202, Msg: "无权操作!"}
  127. c.ServeJSON()
  128. return
  129. }
  130. T_Distributor_id := c.GetString("T_Distributor_id")
  131. r, is := Distributor.Read_Distributor(T_Distributor_id)
  132. if !is {
  133. c.Data["json"] = lib.JSONS{Code: 202, Msg: "Id 错误!"}
  134. c.ServeJSON()
  135. return
  136. }
  137. if !Distributor.Delete_Distributor(r) {
  138. c.Data["json"] = lib.JSONS{Code: 202, Msg: "删除失败!"}
  139. c.ServeJSON()
  140. return
  141. }
  142. // TODO 删除经销商下的用户
  143. System.Add_UserLogs_T(User_r.T_uuid, "经销商管理", "删除", r)
  144. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!"}
  145. c.ServeJSON()
  146. return
  147. }
  148. // 管理员-全部列表-
  149. func (c *DistributorController) List_All() {
  150. // 验证登录 User_is, User_r
  151. User_r, User_is := Account.Verification_Admin(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
  152. if !User_is {
  153. c.Data["json"] = lib.JSONS{Code: 201, Msg: "请重新登录!"}
  154. c.ServeJSON()
  155. return
  156. }
  157. if User_r.T_power > 2 || len(User_r.T_Distributor_id) > 0 {
  158. c.Data["json"] = lib.JSONS{Code: 202, Msg: "无权操作!"}
  159. c.ServeJSON()
  160. return
  161. }
  162. T_name := c.GetString("T_name")
  163. var r_jsons lib.R_JSONS
  164. r_jsons.List = Distributor.Read_Distributor_List_ALL(T_name)
  165. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: r_jsons}
  166. c.ServeJSON()
  167. return
  168. }