Couriers.go 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. package controllers
  2. import (
  3. "Cold_GoodsOrder/Nats/NatsServer"
  4. "Cold_GoodsOrder/conf"
  5. "Cold_GoodsOrder/lib"
  6. "Cold_GoodsOrder/models/Account"
  7. "Cold_GoodsOrder/models/Function"
  8. beego "github.com/beego/beego/v2/server/web"
  9. "math"
  10. )
  11. // CouriersController Handle
  12. type CouriersController struct {
  13. beego.Controller
  14. User_r Account.User // 登陆的用户
  15. T_pid int // 公司id
  16. }
  17. func (c *CouriersController) Prepare() {
  18. c.User_r = *Account.User_r
  19. c.T_pid = *Account.T_pid
  20. }
  21. func (c *CouriersController) Couriers_List() {
  22. type R_JSONS struct {
  23. //必须的大写开头
  24. Data []Function.CouriersR
  25. Num int64
  26. Page int
  27. Page_size int
  28. }
  29. var r_jsons R_JSONS
  30. page, _ := c.GetInt("page")
  31. if page < 1 {
  32. page = 1
  33. }
  34. page_z, _ := c.GetInt("page_z")
  35. if page_z < 1 {
  36. page_z = conf.Page_size
  37. }
  38. Name := c.GetString("T_name")
  39. r_jsons.Data, r_jsons.Num = Function.Read_Couriers_List(c.User_r.T_pid, page, page_z, Name)
  40. r_jsons.Page = page
  41. r_jsons.Page_size = int(math.Ceil(float64(r_jsons.Num) / float64(page_z)))
  42. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: r_jsons}
  43. c.ServeJSON()
  44. return
  45. }
  46. func (c *CouriersController) CouriersAdd() {
  47. Phone := c.GetString("Phone")
  48. Name := c.GetString("T_name")
  49. var_ := Function.Couriers{
  50. UserId: c.User_r.T_pid,
  51. Phone: Phone,
  52. Name: Name,
  53. }
  54. id, err := Function.Add_Couriers(var_)
  55. if err != nil {
  56. c.Data["json"] = lib.JSONS{Code: 301, Msg: "添加失败!"}
  57. c.ServeJSON()
  58. return
  59. }
  60. NatsServer.AddUserLogs(Account.User_r.T_uuid, "配送员管理", "添加", var_)
  61. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: id}
  62. c.ServeJSON()
  63. return
  64. }
  65. func (c *CouriersController) CouriersGet() {
  66. id, _ := c.GetInt("T_id")
  67. r := Function.Read_Couriers_ById(id)
  68. // 记录不存在
  69. if r.Id == 0 {
  70. c.Data["json"] = lib.JSONS{Code: 204, Msg: "T_id Err!"}
  71. c.ServeJSON()
  72. return
  73. }
  74. if c.User_r.T_pid != r.UserId {
  75. c.Data["json"] = lib.JSONS{Code: 205, Msg: "没有权限!"}
  76. c.ServeJSON()
  77. return
  78. }
  79. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: Function.CouriersToCouriersR(r)}
  80. c.ServeJSON()
  81. return
  82. }
  83. func (c *CouriersController) CouriersEdit() {
  84. id, _ := c.GetInt("T_id")
  85. r := Function.Read_Couriers_ById(id)
  86. if r.Id == 0 {
  87. c.Data["json"] = lib.JSONS{Code: 204, Msg: "T_id !"}
  88. c.ServeJSON()
  89. return
  90. }
  91. if c.User_r.T_pid != r.UserId {
  92. c.Data["json"] = lib.JSONS{Code: 205, Msg: "没有权限!"}
  93. c.ServeJSON()
  94. return
  95. }
  96. Phone := c.GetString("Phone")
  97. Name := c.GetString("T_name")
  98. if len(Phone) > 0 {
  99. r.Phone = Phone
  100. }
  101. if len(Name) > 0 {
  102. r.Name = Name
  103. }
  104. is := Function.Update_Couriers(r, "phone", "name")
  105. if !is {
  106. c.Data["json"] = lib.JSONS{Code: 202, Msg: "修改失败!"}
  107. c.ServeJSON()
  108. return
  109. }
  110. NatsServer.AddUserLogs(Account.User_r.T_uuid, "配送员管理", "修改", r)
  111. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!"}
  112. c.ServeJSON()
  113. return
  114. }
  115. func (c *CouriersController) CouriersDel() {
  116. id, _ := c.GetInt("T_id")
  117. r := Function.Read_Couriers_ById(id)
  118. if r.Id == 0 {
  119. c.Data["json"] = lib.JSONS{Code: 204, Msg: "T_id !"}
  120. c.ServeJSON()
  121. return
  122. }
  123. if c.User_r.T_pid != r.UserId {
  124. c.Data["json"] = lib.JSONS{Code: 205, Msg: "没有权限!"}
  125. c.ServeJSON()
  126. return
  127. }
  128. if is := Function.Delete_Couriers(r); !is {
  129. c.Data["json"] = lib.JSONS{Code: 202, Msg: "删除失败!"}
  130. c.ServeJSON()
  131. return
  132. }
  133. NatsServer.AddUserLogs(Account.User_r.T_uuid, "配送员管理", "删除", r)
  134. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!"}
  135. c.ServeJSON()
  136. return
  137. }