蛋蛋星球 后台端
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

89 line
2.4 KiB

  1. package advertising
  2. import (
  3. "applet/app/db"
  4. "applet/app/e"
  5. "applet/app/md"
  6. "applet/app/utils"
  7. "code.fnuoos.com/EggPlanet/egg_models.git/src/implement"
  8. "code.fnuoos.com/EggPlanet/egg_models.git/src/model"
  9. "github.com/gin-gonic/gin"
  10. )
  11. func FunctionList(c *gin.Context) {
  12. var req *md.AdvertisingFunctionListReq
  13. if err := c.ShouldBindJSON(&req); err != nil {
  14. e.OutErr(c, e.ERR_INVALID_ARGS, err)
  15. return
  16. }
  17. var resp md.AdvertisingFunctionListResp
  18. noticeList := make([]md.AdvertisingFunctionList, 0)
  19. resp.SelectData = []map[string]string{
  20. {"name": "首页砸蛋", "value": "egg"},
  21. {"name": "首页签到", "value": "egg_sign"},
  22. }
  23. NewAdvertisingSpaceDb := implement.NewAdvertisingSpaceDb(db.Db)
  24. adv, _, _ := NewAdvertisingSpaceDb.FindUserFeedbackCateAndTotal("1", "1000", "", "3")
  25. advList := make([]map[string]string, 0)
  26. if adv != nil {
  27. for _, v := range *adv {
  28. tmp := map[string]string{
  29. "name": v.Name,
  30. "value": utils.IntToStr(v.Id),
  31. }
  32. advList = append(advList, tmp)
  33. }
  34. }
  35. resp.AdvData = advList
  36. NewJpushNoticeDb := implement.NewAdvertisingFunctionDb(db.Db)
  37. notice, total, _ := NewJpushNoticeDb.FindUserFeedbackFunctionAndTotal(req.Page, req.Limit)
  38. resp.Total = total
  39. if notice != nil {
  40. for _, v := range *notice {
  41. tmp := md.AdvertisingFunctionList{
  42. Id: utils.Int64ToStr(v.Id),
  43. AdId: utils.IntToStr(v.AdId),
  44. Type: v.Type,
  45. }
  46. noticeList = append(noticeList, tmp)
  47. }
  48. }
  49. resp.List = noticeList
  50. e.OutSuc(c, resp, nil)
  51. return
  52. }
  53. func FunctionDel(c *gin.Context) {
  54. var req *md.ArticleCateDelReq
  55. if err := c.ShouldBindJSON(&req); err != nil {
  56. e.OutErr(c, e.ERR_INVALID_ARGS, err)
  57. return
  58. }
  59. db.Db.In("id", req.Id).Delete(&model.AdvertisingFunction{})
  60. e.OutSuc(c, "success", nil)
  61. return
  62. }
  63. func FunctionSave(c *gin.Context) {
  64. var req *md.AdvertisingFunctionList
  65. if err := c.ShouldBindJSON(&req); err != nil {
  66. e.OutErr(c, e.ERR_INVALID_ARGS, err)
  67. return
  68. }
  69. var data = new(model.AdvertisingFunction)
  70. if utils.StrToInt(req.Id) > 0 {
  71. NewAdvertisingSpaceDb := implement.NewAdvertisingFunctionDb(db.Db)
  72. space, _ := NewAdvertisingSpaceDb.GetAdvertisingFunction(req.Id)
  73. if space == nil {
  74. e.OutErr(c, 400, e.NewErr(400, "记录不存在"))
  75. return
  76. }
  77. data = space
  78. } else {
  79. db.Db.Insert(data)
  80. }
  81. data.Type = req.Type
  82. data.AdId = utils.StrToInt(req.AdId)
  83. db.Db.Where("id=?", data.Id).Update(data)
  84. e.OutSuc(c, "success", nil)
  85. return
  86. }