ProductProt.go 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  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. c.Data["json"] = lib.JSONR{Code: lib.Success, Msg: "ok!", Data: ProductProt}
  25. c.ServeJSON()
  26. return
  27. }
  28. func (c *ProductProtController) List() {
  29. PageIndex, _ := c.GetInt("PageIndex", 0)
  30. PageSize, _ := c.GetInt("PageSize", 10)
  31. ProductProtr := Product.ProductProt{}
  32. c.ParseForm(&ProductProtr)
  33. ProductProt_r, Total := ProductProtr.Lists(PageIndex, PageSize)
  34. c.Data["json"] = lib.JSONR{Code: lib.Success, Msg: "ok!", Data: lib.C_Page(ProductProt_r, PageIndex, PageSize, Total)}
  35. c.ServeJSON()
  36. return
  37. }
  38. func (c *ProductProtController) Add() {
  39. ProductProt_r := Product.ProductProt{}
  40. c.ParseForm(&ProductProt_r)
  41. ProductProt_r.Id = 0
  42. ProductProt_r.Add()
  43. c.Data["json"] = lib.JSONR{Code: lib.Success, Msg: "ok!", Data: ProductProt_r}
  44. c.ServeJSON()
  45. return
  46. }
  47. func (c *ProductProtController) Update() {
  48. ProductProtr := Product.ProductProt{}
  49. c.ParseForm(&ProductProtr)
  50. if !ProductProtr.Update("T_name", "T_mode", "T_lang", "T_analysis", "T_text", "T_describe") {
  51. c.Data["json"] = lib.JSONR{Code: lib.Error, Msg: "E!"}
  52. c.ServeJSON()
  53. return
  54. }
  55. c.Data["json"] = lib.JSONR{Code: lib.Success, Msg: "ok!"}
  56. c.ServeJSON()
  57. return
  58. }
  59. func (c *ProductProtController) Delete() {
  60. ProductProtr := Product.ProductProt{}
  61. c.ParseForm(&ProductProtr)
  62. if !ProductProtr.Delete() {
  63. c.Data["json"] = lib.JSONR{Code: lib.Error, Msg: "E!"}
  64. c.ServeJSON()
  65. return
  66. }
  67. c.Data["json"] = lib.JSONR{Code: lib.Success, Msg: "ok!"}
  68. c.ServeJSON()
  69. return
  70. }