shop_product.go 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. package fetdata
  2. import (
  3. "html/template"
  4. "time"
  5. "golang-fave/engine/wrapper"
  6. "golang-fave/utils"
  7. )
  8. type ShopProduct struct {
  9. wrap *wrapper.Wrapper
  10. object *utils.MySql_shop_product
  11. user *User
  12. currency *Currency
  13. category *ShopCategory
  14. }
  15. func (this *ShopProduct) Id() int {
  16. if this == nil {
  17. return 0
  18. }
  19. return this.object.A_id
  20. }
  21. func (this *ShopProduct) User() *User {
  22. if this == nil {
  23. return nil
  24. }
  25. if this.user != nil {
  26. return this.user
  27. }
  28. this.user = &User{wrap: this.wrap}
  29. this.user.load(this.object.A_user)
  30. return this.user
  31. }
  32. func (this *ShopProduct) Currency() *Currency {
  33. if this == nil {
  34. return nil
  35. }
  36. if this.currency != nil {
  37. return this.currency
  38. }
  39. this.currency = &Currency{wrap: this.wrap}
  40. this.currency.load(this.object.A_currency)
  41. return this.currency
  42. }
  43. func (this *ShopProduct) Price() float64 {
  44. if this == nil {
  45. return 0
  46. }
  47. return this.object.A_price
  48. }
  49. func (this *ShopProduct) PriceFormat(format string) string {
  50. if this == nil {
  51. return ""
  52. }
  53. return utils.Float64ToStrF(this.object.A_price, format)
  54. }
  55. func (this *ShopProduct) Name() string {
  56. if this == nil {
  57. return ""
  58. }
  59. return this.object.A_name
  60. }
  61. func (this *ShopProduct) Alias() string {
  62. if this == nil {
  63. return ""
  64. }
  65. return this.object.A_alias
  66. }
  67. func (this *ShopProduct) Vendor() string {
  68. if this == nil {
  69. return ""
  70. }
  71. return this.object.A_vendor
  72. }
  73. func (this *ShopProduct) Quantity() int {
  74. if this == nil {
  75. return 0
  76. }
  77. return this.object.A_quantity
  78. }
  79. func (this *ShopProduct) Category() *ShopCategory {
  80. if this == nil {
  81. return nil
  82. }
  83. if this.category != nil {
  84. return this.category
  85. }
  86. this.category = &ShopCategory{wrap: this.wrap}
  87. this.category.load(this.object.A_category)
  88. return this.category
  89. }
  90. func (this *ShopProduct) Briefly() template.HTML {
  91. if this == nil {
  92. return template.HTML("")
  93. }
  94. return template.HTML(this.object.A_briefly)
  95. }
  96. func (this *ShopProduct) Content() template.HTML {
  97. if this == nil {
  98. return template.HTML("")
  99. }
  100. return template.HTML(this.object.A_content)
  101. }
  102. func (this *ShopProduct) DateTimeUnix() int {
  103. if this == nil {
  104. return 0
  105. }
  106. return this.object.A_datetime
  107. }
  108. func (this *ShopProduct) DateTimeFormat(format string) string {
  109. if this == nil {
  110. return ""
  111. }
  112. return time.Unix(int64(this.object.A_datetime), 0).Format(format)
  113. }
  114. func (this *ShopProduct) Active() bool {
  115. if this == nil {
  116. return false
  117. }
  118. return this.object.A_active > 0
  119. }
  120. func (this *ShopProduct) Permalink() string {
  121. if this == nil {
  122. return ""
  123. }
  124. return "/shop/" + this.object.A_alias + "/"
  125. }