shop_product.go 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  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. }
  14. func (this *ShopProduct) Id() int {
  15. if this == nil {
  16. return 0
  17. }
  18. return this.object.A_id
  19. }
  20. func (this *ShopProduct) User() *User {
  21. if this == nil {
  22. return nil
  23. }
  24. if this.user != nil {
  25. return this.user
  26. }
  27. this.user = &User{wrap: this.wrap}
  28. this.user.load(this.object.A_user)
  29. return this.user
  30. }
  31. func (this *ShopProduct) Currency() *Currency {
  32. if this == nil {
  33. return nil
  34. }
  35. if this.currency != nil {
  36. return this.currency
  37. }
  38. this.currency = &Currency{wrap: this.wrap}
  39. this.currency.load(this.object.A_currency)
  40. return this.currency
  41. }
  42. func (this *ShopProduct) Price() float64 {
  43. if this == nil {
  44. return 0
  45. }
  46. return this.object.A_price
  47. }
  48. func (this *ShopProduct) PriceFormat(format string) string {
  49. if this == nil {
  50. return ""
  51. }
  52. return utils.Float64ToStrF(this.object.A_price, format)
  53. }
  54. func (this *ShopProduct) Name() string {
  55. if this == nil {
  56. return ""
  57. }
  58. return this.object.A_name
  59. }
  60. func (this *ShopProduct) Alias() string {
  61. if this == nil {
  62. return ""
  63. }
  64. return this.object.A_alias
  65. }
  66. func (this *ShopProduct) Briefly() template.HTML {
  67. if this == nil {
  68. return template.HTML("")
  69. }
  70. return template.HTML(this.object.A_briefly)
  71. }
  72. func (this *ShopProduct) Content() template.HTML {
  73. if this == nil {
  74. return template.HTML("")
  75. }
  76. return template.HTML(this.object.A_content)
  77. }
  78. func (this *ShopProduct) DateTimeUnix() int {
  79. if this == nil {
  80. return 0
  81. }
  82. return this.object.A_datetime
  83. }
  84. func (this *ShopProduct) DateTimeFormat(format string) string {
  85. if this == nil {
  86. return ""
  87. }
  88. return time.Unix(int64(this.object.A_datetime), 0).Format(format)
  89. }
  90. func (this *ShopProduct) Active() bool {
  91. if this == nil {
  92. return false
  93. }
  94. return this.object.A_active > 0
  95. }
  96. func (this *ShopProduct) Permalink() string {
  97. if this == nil {
  98. return ""
  99. }
  100. return "/shop/" + this.object.A_alias + "/"
  101. }