shop_category.go 1.7 KB

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