ProductProt.go 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. package controllers
  2. import (
  3. "Yunlot/lib"
  4. "Yunlot/models/Product"
  5. beego "github.com/beego/beego/v2/server/web"
  6. )
  7. type ProductProtController struct {
  8. beego.Controller
  9. }
  10. func (c *ProductProtController) ProductModeLists() {
  11. ProductProt_r, Total := Product.ProductModeLists()
  12. c.Data["json"] = lib.JSONR{Code: lib.Success, Msg: "ok!", Data: lib.C_Page(ProductProt_r, 0, 0, Total)}
  13. c.ServeJSON()
  14. return
  15. }
  16. func (c *ProductProtController) Get() {
  17. ProductProt := Product.ProductProt{}
  18. c.ParseForm(&ProductProt)
  19. if !ProductProt.Read() {
  20. c.Data["json"] = lib.JSONR{Code: lib.Error, Msg: "ID E!"}
  21. c.ServeJSON()
  22. return
  23. }
  24. // 验证 TOKEY
  25. if ProductProt.T_tokey != c.GetString("T_tokey") {
  26. c.Data["json"] = lib.JSONR{Code: lib.Error, Msg: "T_tokey!"}
  27. c.ServeJSON()
  28. return
  29. }
  30. c.Data["json"] = lib.JSONR{Code: lib.Success, Msg: "ok!", Data: ProductProt}
  31. c.ServeJSON()
  32. return
  33. }
  34. func (c *ProductProtController) List() {
  35. PageIndex, _ := c.GetInt("PageIndex", 0)
  36. PageSize, _ := c.GetInt("PageSize", 10)
  37. ProductProtr := Product.ProductProt{}
  38. c.ParseForm(&ProductProtr)
  39. // 验证 TOKEY
  40. if c.Ctx.Input.Host() != "127.0.0.1" {
  41. if len(ProductProtr.T_tokey) != 8 {
  42. c.Data["json"] = lib.JSONR{Code: lib.Error, Msg: "T_tokey!"}
  43. c.ServeJSON()
  44. return
  45. }
  46. }
  47. ProductProt_r, Total := ProductProtr.Lists(PageIndex, PageSize)
  48. c.Data["json"] = lib.JSONR{Code: lib.Success, Msg: "ok!", Data: lib.C_Page(ProductProt_r, PageIndex, PageSize, Total)}
  49. c.ServeJSON()
  50. return
  51. }
  52. func (c *ProductProtController) Add() {
  53. ProductProt_r := Product.ProductProt{}
  54. c.ParseForm(&ProductProt_r)
  55. if len(ProductProt_r.T_tokey) != 8 {
  56. c.Data["json"] = lib.JSONR{Code: lib.Error, Msg: "T_tokey!"}
  57. c.ServeJSON()
  58. return
  59. }
  60. ProductProt_r.Id = 0
  61. ProductProt_r.Add()
  62. c.Data["json"] = lib.JSONR{Code: lib.Success, Msg: "ok!", Data: ProductProt_r}
  63. c.ServeJSON()
  64. return
  65. }
  66. func (c *ProductProtController) Update() {
  67. Id, _ := c.GetInt("Id", 0)
  68. ProductProtr := Product.ProductProt{Id: Id}
  69. if !ProductProtr.Read() {
  70. c.Data["json"] = lib.JSONR{Code: lib.Error, Msg: "T_ProductID E!"}
  71. c.ServeJSON()
  72. return
  73. }
  74. // 验证 TOKEY
  75. if ProductProtr.T_tokey != c.GetString("T_tokey") {
  76. c.Data["json"] = lib.JSONR{Code: lib.Error, Msg: "T_tokey!"}
  77. c.ServeJSON()
  78. return
  79. }
  80. c.ParseForm(&ProductProtr)
  81. if !ProductProtr.Update("T_name", "T_mode", "T_lang", "T_analysis", "T_text", "T_describe") {
  82. c.Data["json"] = lib.JSONR{Code: lib.Error, Msg: "E!"}
  83. c.ServeJSON()
  84. return
  85. }
  86. c.Data["json"] = lib.JSONR{Code: lib.Success, Msg: "ok!"}
  87. c.ServeJSON()
  88. return
  89. }
  90. func (c *ProductProtController) Delete() {
  91. ProductProtr := Product.ProductProt{}
  92. c.ParseForm(&ProductProtr)
  93. if !ProductProtr.Read() {
  94. c.Data["json"] = lib.JSONR{Code: lib.Error, Msg: "ID E!"}
  95. c.ServeJSON()
  96. return
  97. }
  98. // 验证 TOKEY
  99. if ProductProtr.T_tokey != c.GetString("T_tokey") {
  100. c.Data["json"] = lib.JSONR{Code: lib.Error, Msg: "T_tokey!"}
  101. c.ServeJSON()
  102. return
  103. }
  104. if !ProductProtr.Delete() {
  105. c.Data["json"] = lib.JSONR{Code: lib.Error, Msg: "E!"}
  106. c.ServeJSON()
  107. return
  108. }
  109. c.Data["json"] = lib.JSONR{Code: lib.Success, Msg: "ok!"}
  110. c.ServeJSON()
  111. return
  112. }