shop_category.go 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  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. users
  30. WHERE
  31. id = ?
  32. LIMIT 1;`,
  33. id,
  34. ).Scan(
  35. &this.object.A_id,
  36. &this.object.A_user,
  37. &this.object.A_name,
  38. &this.object.A_alias,
  39. &this.object.A_lft,
  40. &this.object.A_rgt,
  41. ); err != nil {
  42. return
  43. }
  44. }
  45. func (this *ShopCategory) Id() int {
  46. if this == nil {
  47. return 0
  48. }
  49. return this.object.A_id
  50. }
  51. func (this *ShopCategory) User() *User {
  52. if this == nil {
  53. return nil
  54. }
  55. if this.user != nil {
  56. return this.user
  57. }
  58. this.user = &User{wrap: this.wrap}
  59. this.user.load(this.object.A_user)
  60. return this.user
  61. }
  62. func (this *ShopCategory) Name() string {
  63. if this == nil {
  64. return ""
  65. }
  66. return this.object.A_name
  67. }
  68. func (this *ShopCategory) Alias() string {
  69. if this == nil {
  70. return ""
  71. }
  72. return this.object.A_alias
  73. }
  74. func (this *ShopCategory) Left() int {
  75. if this == nil {
  76. return 0
  77. }
  78. return this.object.A_lft
  79. }
  80. func (this *ShopCategory) Right() int {
  81. if this == nil {
  82. return 0
  83. }
  84. return this.object.A_rgt
  85. }
  86. func (this *ShopCategory) Permalink() string {
  87. if this == nil {
  88. return ""
  89. }
  90. return "/shop/category/" + this.object.A_alias + "/"
  91. }
  92. func (this *ShopCategory) Level() int {
  93. if this == nil {
  94. return 0
  95. }
  96. return this.depth
  97. }