ProductType.go 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. package controllers
  2. import (
  3. "Yunlot/lib"
  4. "Yunlot/models/Product"
  5. beego "github.com/beego/beego/v2/server/web"
  6. )
  7. type ProductTypeController struct {
  8. beego.Controller
  9. }
  10. func (c *ProductTypeController) List() {
  11. PageIndex, _ := c.GetInt("PageIndex", 0)
  12. PageSize, _ := c.GetInt("PageSize", 10)
  13. ProductTyper := Product.ProductType{}
  14. c.ParseForm(&ProductTyper)
  15. ProductType_r, Total := ProductTyper.Lists(PageIndex, PageSize)
  16. c.Data["json"] = lib.JSONR{Code: lib.Success, Msg: "ok!", Data: lib.C_Page(ProductType_r, PageIndex, PageSize, Total)}
  17. c.ServeJSON()
  18. return
  19. }
  20. func (c *ProductTypeController) Get() {
  21. ProductTyper := Product.ProductType{}
  22. c.ParseForm(&ProductTyper)
  23. if !ProductTyper.Read() {
  24. c.Data["json"] = lib.JSONR{Code: lib.Error, Msg: "ProductID E!"}
  25. c.ServeJSON()
  26. return
  27. }
  28. c.Data["json"] = lib.JSONR{Code: lib.Success, Msg: "ok!", Data: ProductTyper}
  29. c.ServeJSON()
  30. return
  31. }
  32. func (c *ProductTypeController) Add() {
  33. ProductType_r := Product.ProductType{}
  34. c.ParseForm(&ProductType_r)
  35. ProductType_r.T_ProductID = lib.GetRandstring(8, "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ", 0)
  36. ProductType_r.T_akey = lib.GetRandstring(32, "", 0)
  37. ProductType_r.Add()
  38. c.Data["json"] = lib.JSONR{Code: lib.Success, Msg: "ok!", Data: ProductType_r}
  39. c.ServeJSON()
  40. return
  41. }
  42. func (c *ProductTypeController) Update() {
  43. ProductTyper := Product.ProductType{}
  44. c.ParseForm(&ProductTyper)
  45. if !ProductTyper.Update("T_name", "T_img", "T_prot", "T_TabData") {
  46. c.Data["json"] = lib.JSONR{Code: lib.Error, Msg: "E!"}
  47. c.ServeJSON()
  48. return
  49. }
  50. c.Data["json"] = lib.JSONR{Code: lib.Success, Msg: "ok!"}
  51. c.ServeJSON()
  52. return
  53. }
  54. func (c *ProductTypeController) Delete() {
  55. ProductTyper := Product.ProductType{}
  56. c.ParseForm(&ProductTyper)
  57. if !ProductTyper.Delete() {
  58. c.Data["json"] = lib.JSONR{Code: lib.Error, Msg: "E!"}
  59. c.ServeJSON()
  60. return
  61. }
  62. c.Data["json"] = lib.JSONR{Code: lib.Success, Msg: "ok!"}
  63. c.ServeJSON()
  64. return
  65. }