蛋蛋星球-客户端
選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

svc_advertising.go 4.8 KiB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. package svc
  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. "encoding/json"
  9. "fmt"
  10. "github.com/gin-gonic/gin"
  11. "time"
  12. )
  13. func Advertising(c *gin.Context) {
  14. eg := db.Db
  15. var res = md.AdvertisingResp{}
  16. NewAdvertisingBasicDb := implement.NewAdvertisingBasicDb(eg)
  17. NewAdvertisingBasic, _ := NewAdvertisingBasicDb.GetAdvertisingBasicDb()
  18. if NewAdvertisingBasic != nil {
  19. var info = make(map[string]interface{})
  20. json.Unmarshal([]byte(NewAdvertisingBasic.Info), &info)
  21. res.Basic = md.AdvertisingBasic{
  22. Info: info,
  23. AndroidAdIsOpen: utils.IntToStr(NewAdvertisingBasic.AndroidOpenAdIsOpen),
  24. IosAdIsOpen: utils.IntToStr(NewAdvertisingBasic.IosAdIsOpen),
  25. AndroidOpenAdIsOpen: utils.IntToStr(NewAdvertisingBasic.AndroidOpenAdIsOpen),
  26. IosOpenAdIsOpen: utils.IntToStr(NewAdvertisingBasic.IosOpenAdIsOpen),
  27. Voice: GetOssUrl(NewAdvertisingBasic.Voice),
  28. }
  29. }
  30. NewAdvertisingLimitDb := implement.NewAdvertisingLimitDb(eg)
  31. NewAdvertisingLimit, _ := NewAdvertisingLimitDb.GetAdvertisingLimit()
  32. if NewAdvertisingLimit != nil {
  33. res.Pop = md.AdvertisingLimit{
  34. PublicImg: GetOssUrl(NewAdvertisingLimit.PublicImg),
  35. PublicStr: NewAdvertisingLimit.PublicStr,
  36. WithdrawImg: GetOssUrl(NewAdvertisingLimit.WithdrawImg),
  37. WithdrawStr: NewAdvertisingLimit.WithdrawStr,
  38. }
  39. }
  40. NewAdvertisingFunctionDb := implement.NewAdvertisingFunctionDb(eg)
  41. NewAdvertisingFunction, _ := NewAdvertisingFunctionDb.AdvertisingFunctionAll()
  42. AdvertisingFunctionTmp := make([]md.AdvertisingFunction, 0)
  43. if NewAdvertisingFunction != nil {
  44. for _, v := range *NewAdvertisingFunction {
  45. tmp := md.AdvertisingFunction{
  46. Name: v.Name,
  47. Type: v.Type,
  48. AdId: utils.IntToStr(v.AdId),
  49. }
  50. AdvertisingFunctionTmp = append(AdvertisingFunctionTmp, tmp)
  51. }
  52. }
  53. res.Function = AdvertisingFunctionTmp
  54. NewAdvertisingSpaceDb := implement.NewAdvertisingSpaceDb(eg)
  55. NewAdvertisingSpace, _ := NewAdvertisingSpaceDb.AdvertisingSpaceAll()
  56. NewAdvertisingSpaceTmp := make([]md.AdvertisingSpace, 0)
  57. if NewAdvertisingSpace != nil {
  58. for _, v := range *NewAdvertisingSpace {
  59. var info = make(map[string]interface{})
  60. json.Unmarshal([]byte(v.Info), &info)
  61. tmp := md.AdvertisingSpace{
  62. Id: utils.IntToStr(v.Id),
  63. Name: v.Name,
  64. Kind: utils.IntToStr(v.Kind),
  65. Info: info,
  66. CountingDown: utils.IntToStr(v.CountingDown),
  67. }
  68. NewAdvertisingSpaceTmp = append(NewAdvertisingSpaceTmp, tmp)
  69. }
  70. }
  71. res.Space = NewAdvertisingSpaceTmp
  72. e.OutSuc(c, res, nil)
  73. return
  74. }
  75. func AdvertisingCheck(c *gin.Context) {
  76. eg := db.Db
  77. var req md.AdvertisingReq
  78. err := c.ShouldBindJSON(&req)
  79. if err != nil {
  80. err = HandleValidateErr(err)
  81. err1 := err.(e.E)
  82. e.OutErr(c, err1.Code, err1.Error())
  83. return
  84. }
  85. user := GetUser(c)
  86. var res = md.AdvertisingCheck{IsCanVisit: "0"}
  87. NewAdvertisingSpaceDb := implement.NewAdvertisingSpaceDb(eg)
  88. NewAdvertisingSpace, _ := NewAdvertisingSpaceDb.GetAdvertisingSpace(req.Id)
  89. if NewAdvertisingSpace != nil {
  90. if NewAdvertisingSpace.Kind != 3 {
  91. res.IsCanVisit = "1"
  92. } else {
  93. NewAdvertisingLimitDb := implement.NewAdvertisingLimitDb(eg)
  94. NewAdvertisingLimit, _ := NewAdvertisingLimitDb.GetAdvertisingLimit()
  95. if NewAdvertisingLimit != nil && NewAdvertisingLimit.ImeiNum > 0 {
  96. sql := `SELECT uid FROM user_imei WHERE create_at>='%s' and ip='%s' GROUP BY imei LIMIT %s`
  97. now := time.Now().Unix() - int64(NewAdvertisingLimit.Minute*60)
  98. sql = fmt.Sprintf(sql, time.Unix(now, 0).Format("2006-01-02 15:04:05"), c.ClientIP(), NewAdvertisingLimit.ImeiNum)
  99. nativeString, _ := db.QueryNativeString(db.Db, sql)
  100. for _, v := range nativeString {
  101. if utils.StrToInt64(v["uid"]) == user.Id {
  102. res.IsCanVisit = "1"
  103. }
  104. }
  105. if res.IsCanVisit != "1" && len(nativeString) < NewAdvertisingLimit.ImeiNum {
  106. UserImeiAdd(c, user.Id)
  107. res.IsCanVisit = "1"
  108. }
  109. }
  110. }
  111. }
  112. e.OutSuc(c, res, nil)
  113. return
  114. }
  115. func AdvertisingDetail(c *gin.Context) {
  116. eg := db.Db
  117. var req md.AdvertisingReq
  118. err := c.ShouldBindJSON(&req)
  119. if err != nil {
  120. err = HandleValidateErr(err)
  121. err1 := err.(e.E)
  122. e.OutErr(c, err1.Code, err1.Error())
  123. return
  124. }
  125. var res = md.AdvertisingSpace{}
  126. NewAdvertisingSpaceDb := implement.NewAdvertisingSpaceDb(eg)
  127. NewAdvertisingSpace, _ := NewAdvertisingSpaceDb.GetAdvertisingSpace(req.Id)
  128. if NewAdvertisingSpace != nil {
  129. var info = make(map[string]interface{})
  130. json.Unmarshal([]byte(NewAdvertisingSpace.Info), &info)
  131. tmp := md.AdvertisingSpace{
  132. Id: utils.IntToStr(NewAdvertisingSpace.Id),
  133. Name: NewAdvertisingSpace.Name,
  134. Kind: utils.IntToStr(NewAdvertisingSpace.Kind),
  135. Info: info,
  136. CountingDown: utils.IntToStr(NewAdvertisingSpace.CountingDown),
  137. }
  138. res = tmp
  139. }
  140. e.OutSuc(c, res, nil)
  141. return
  142. }