banner.go 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. package models
  2. import (
  3. "rdluck_tools/orm"
  4. "time"
  5. )
  6. type Banner struct {
  7. Id int `orm:"column(id);pk"`
  8. ClassifyId int `description:"分类id"`
  9. ImageUrl string `description:"图片路径"`
  10. BannerType int `description:"类型 1:轮播图,2:头部海报"`
  11. CreateTime time.Time `description:"创建时间"`
  12. ModifyTime time.Time `description:"修改时间"`
  13. ClassifyName string `description:"分类名称"`
  14. JumpUrl string `description:"跳转地址"`
  15. }
  16. type BannerAddReq struct {
  17. ImgUrl string `description:"图片路径"`
  18. BannerType int `description:"类型"`
  19. ClassifyId int `description:"分类id"`
  20. ClassifyName string `description:"分类名称"`
  21. JumpUrl string `description:"跳转地址"`
  22. }
  23. //添加banner
  24. func AddBanner(item *Banner) (err error) {
  25. o := orm.NewOrm()
  26. o.Using("rddp")
  27. _, err = o.Insert(item)
  28. return
  29. }
  30. type BannerEditReq struct {
  31. BannerId int `description:"BannerId"`
  32. ImgUrl string `description:"图片路径"`
  33. BannerType int `description:"类型"`
  34. ClassifyId int `description:"分类id"`
  35. ClassifyName string `description:"分类名称"`
  36. JumpUrl string `description:"跳转地址"`
  37. }
  38. //编辑banner
  39. func EditBanner(item *BannerEditReq) (err error) {
  40. o := orm.NewOrm()
  41. o.Using("rddp")
  42. sql := " UPDATE banner SET classify_id = ?, image_url = ?, banner_type = ?,classify_name=?,jump_url=?, modify_time = NOW() WHERE id = ? "
  43. o.Raw(sql, item.ClassifyId, item.ImgUrl, item.BannerType, item.ClassifyName, item.JumpUrl, item.BannerId).Exec()
  44. return
  45. }
  46. type BannerDeleteReq struct {
  47. BannerId int `description:"BannerId"`
  48. }
  49. func DeleteBanner(bannerId int) (err error) {
  50. sql := `DELETE FROM banner WHERE id=? `
  51. o := orm.NewOrm()
  52. o.Using("rddp")
  53. _, err = o.Raw(sql, bannerId).Exec()
  54. return
  55. }
  56. func GetClassify() (items []*Classify, err error) {
  57. sql := `SELECT * FROM classify WHERE parent_id>0 ORDER BY id DESC `
  58. o := orm.NewOrm()
  59. o.Using("rddp")
  60. _, err = o.Raw(sql).QueryRows(&items)
  61. return
  62. }
  63. type BannerList struct {
  64. Id int `orm:"column(id);pk"`
  65. ClassifyId int `description:"分类id"`
  66. ImageUrl string `description:"图片路径"`
  67. BannerType int `description:"类型 1:轮播图,2:头部海报"`
  68. CreateTime time.Time `description:"创建时间"`
  69. ModifyTime time.Time `description:"修改时间"`
  70. ClassifyName string `description:"分类名称"`
  71. JumpUrl string `description:"跳转地址"`
  72. }
  73. //获取轮播图列表
  74. func GetBannerList(condition string, pars []interface{},startSize, pageSize int) (items []*BannerList, err error) {
  75. sql := ` SELECT * FROM banner WHERE 1=1 `
  76. if condition!="" {
  77. sql+=condition
  78. }
  79. sql+=` ORDER BY id DESC LIMIT ?,? `
  80. o := orm.NewOrm()
  81. o.Using("rddp")
  82. _, err = o.Raw(sql,pars, startSize, pageSize).QueryRows(&items)
  83. return
  84. }
  85. func GetBannerListCount(condition string, pars []interface{}) (count int, err error) {
  86. sqlCount := ` SELECT * FROM banner WHERE 1=1 `
  87. if condition!="" {
  88. sqlCount+=condition
  89. }
  90. o := orm.NewOrm()
  91. o.Using("rddp")
  92. err = o.Raw(sqlCount,pars).QueryRow(&count)
  93. return
  94. }
  95. type BannerListResp struct {
  96. List []*BannerList
  97. Paging *PagingItem `description:"分页数据"`
  98. }