banner.go 3.3 KB

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