shop_category.go 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. package fetdata
  2. import (
  3. "golang-fave/engine/wrapper"
  4. "golang-fave/utils"
  5. )
  6. type ShopCategory struct {
  7. wrap *wrapper.Wrapper
  8. object *utils.MySql_shop_category
  9. depth int
  10. user *User
  11. }
  12. func (this *ShopCategory) load(id int) {
  13. if this == nil {
  14. return
  15. }
  16. if this.object != nil {
  17. return
  18. }
  19. this.object = &utils.MySql_shop_category{}
  20. if err := this.wrap.DB.QueryRow(`
  21. SELECT
  22. id,
  23. user,
  24. name,
  25. alias,
  26. lft,
  27. rgt
  28. FROM
  29. shop_cats
  30. WHERE
  31. id = ? AND
  32. id > 1
  33. LIMIT 1;`,
  34. id,
  35. ).Scan(
  36. &this.object.A_id,
  37. &this.object.A_user,
  38. &this.object.A_name,
  39. &this.object.A_alias,
  40. &this.object.A_lft,
  41. &this.object.A_rgt,
  42. ); err != nil {
  43. return
  44. }
  45. }
  46. func (this *ShopCategory) Id() int {
  47. if this == nil {
  48. return 0
  49. }
  50. return this.object.A_id
  51. }
  52. func (this *ShopCategory) User() *User {
  53. if this == nil {
  54. return nil
  55. }
  56. if this.user != nil {
  57. return this.user
  58. }
  59. this.user = &User{wrap: this.wrap}
  60. this.user.load(this.object.A_user)
  61. return this.user
  62. }
  63. func (this *ShopCategory) Name() string {
  64. if this == nil {
  65. return ""
  66. }
  67. return this.object.A_name
  68. }
  69. func (this *ShopCategory) Alias() string {
  70. if this == nil {
  71. return ""
  72. }
  73. return this.object.A_alias
  74. }
  75. func (this *ShopCategory) Left() int {
  76. if this == nil {
  77. return 0
  78. }
  79. return this.object.A_lft
  80. }
  81. func (this *ShopCategory) Right() int {
  82. if this == nil {
  83. return 0
  84. }
  85. return this.object.A_rgt
  86. }
  87. func (this *ShopCategory) Permalink() string {
  88. if this == nil {
  89. return ""
  90. }
  91. return "/shop/category/" + this.object.A_alias + "/"
  92. }
  93. func (this *ShopCategory) Level() int {
  94. if this == nil {
  95. return 0
  96. }
  97. return this.depth
  98. }