蛋蛋星球-客户端
Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

svc_advertising.go 5.5 KiB

3 veckor sedan
3 veckor sedan
3 veckor sedan
3 veckor sedan
1 vecka sedan
3 veckor sedan
3 veckor sedan
3 veckor sedan
3 veckor sedan
3 veckor sedan
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  1. package svc
  2. import (
  3. "applet/app/db"
  4. "applet/app/e"
  5. "applet/app/md"
  6. "applet/app/utils"
  7. "applet/app/utils/cache"
  8. "code.fnuoos.com/EggPlanet/egg_models.git/src/implement"
  9. "code.fnuoos.com/EggPlanet/egg_models.git/src/model"
  10. "encoding/json"
  11. "fmt"
  12. "github.com/gin-gonic/gin"
  13. "time"
  14. )
  15. func Advertising(c *gin.Context) {
  16. eg := db.Db
  17. var res = md.AdvertisingResp{}
  18. NewAdvertisingBasicDb := implement.NewAdvertisingBasicDb(eg)
  19. NewAdvertisingBasic, _ := NewAdvertisingBasicDb.GetAdvertisingBasicDb()
  20. if NewAdvertisingBasic != nil {
  21. var info = make(map[string]interface{})
  22. json.Unmarshal([]byte(NewAdvertisingBasic.Info), &info)
  23. res.Basic = md.AdvertisingBasic{
  24. Info: info,
  25. AndroidAdIsOpen: utils.IntToStr(NewAdvertisingBasic.AndroidOpenAdIsOpen),
  26. IosAdIsOpen: utils.IntToStr(NewAdvertisingBasic.IosAdIsOpen),
  27. AndroidOpenAdIsOpen: utils.IntToStr(NewAdvertisingBasic.AndroidOpenAdIsOpen),
  28. IosOpenAdIsOpen: utils.IntToStr(NewAdvertisingBasic.IosOpenAdIsOpen),
  29. Voice: GetOssUrl(NewAdvertisingBasic.Voice),
  30. }
  31. }
  32. NewAdvertisingLimitDb := implement.NewAdvertisingLimitDb(eg)
  33. NewAdvertisingLimit, _ := NewAdvertisingLimitDb.GetAdvertisingLimit()
  34. if NewAdvertisingLimit != nil {
  35. res.Pop = md.AdvertisingLimit{
  36. PublicImg: GetOssUrl(NewAdvertisingLimit.PublicImg),
  37. PublicStr: NewAdvertisingLimit.PublicStr,
  38. WithdrawImg: GetOssUrl(NewAdvertisingLimit.WithdrawImg),
  39. WithdrawStr: NewAdvertisingLimit.WithdrawStr,
  40. }
  41. }
  42. NewAdvertisingFunctionDb := implement.NewAdvertisingFunctionDb(eg)
  43. NewAdvertisingFunction, _ := NewAdvertisingFunctionDb.AdvertisingFunctionAll()
  44. AdvertisingFunctionTmp := make([]md.AdvertisingFunction, 0)
  45. if NewAdvertisingFunction != nil {
  46. for _, v := range *NewAdvertisingFunction {
  47. tmp := md.AdvertisingFunction{
  48. Name: v.Name,
  49. Type: v.Type,
  50. AdId: utils.IntToStr(v.AdId),
  51. }
  52. AdvertisingFunctionTmp = append(AdvertisingFunctionTmp, tmp)
  53. }
  54. }
  55. res.Function = AdvertisingFunctionTmp
  56. NewAdvertisingSpaceDb := implement.NewAdvertisingSpaceDb(eg)
  57. NewAdvertisingSpace, _ := NewAdvertisingSpaceDb.AdvertisingSpaceAll()
  58. NewAdvertisingSpaceTmp := make([]md.AdvertisingSpace, 0)
  59. if NewAdvertisingSpace != nil {
  60. for _, v := range *NewAdvertisingSpace {
  61. var info = make(map[string]interface{})
  62. json.Unmarshal([]byte(v.Info), &info)
  63. tmp := md.AdvertisingSpace{
  64. Id: utils.IntToStr(v.Id),
  65. Name: v.Name,
  66. Kind: utils.IntToStr(v.Kind),
  67. Info: info,
  68. CountingDown: utils.IntToStr(v.CountingDown),
  69. }
  70. NewAdvertisingSpaceTmp = append(NewAdvertisingSpaceTmp, tmp)
  71. }
  72. }
  73. res.Space = NewAdvertisingSpaceTmp
  74. e.OutSuc(c, res, nil)
  75. return
  76. }
  77. func AdvertisingCheck(c *gin.Context) {
  78. eg := db.Db
  79. var req md.AdvertisingReq
  80. err := c.ShouldBindJSON(&req)
  81. if err != nil {
  82. err = HandleValidateErr(err)
  83. err1 := err.(e.E)
  84. e.OutErr(c, err1.Code, err1.Error())
  85. return
  86. }
  87. user := GetUser(c)
  88. var res = md.AdvertisingCheck{IsCanVisit: "0"}
  89. NewAdvertisingSpaceDb := implement.NewAdvertisingSpaceDb(eg)
  90. NewAdvertisingSpace, _ := NewAdvertisingSpaceDb.GetAdvertisingSpace(req.Id)
  91. if NewAdvertisingSpace != nil {
  92. if NewAdvertisingSpace.Kind != 3 {
  93. res.IsCanVisit = "1"
  94. } else {
  95. NewAdvertisingLimitDb := implement.NewAdvertisingLimitDb(eg)
  96. NewAdvertisingLimit, _ := NewAdvertisingLimitDb.GetAdvertisingLimit()
  97. if NewAdvertisingLimit != nil && NewAdvertisingLimit.ImeiNum > 0 {
  98. sql := `SELECT uid FROM user_imei WHERE create_at>='%s' and ip='%s' GROUP BY imei LIMIT %s`
  99. now := time.Now().Unix() - int64(NewAdvertisingLimit.Minute*60)
  100. sql = fmt.Sprintf(sql, time.Unix(now, 0).Format("2006-01-02 15:04:05"), utils.GetIP(c.Request), NewAdvertisingLimit.ImeiNum)
  101. nativeString, _ := db.QueryNativeString(db.Db, sql)
  102. for _, v := range nativeString {
  103. if utils.StrToInt64(v["uid"]) == user.Id {
  104. res.IsCanVisit = "1"
  105. }
  106. }
  107. if res.IsCanVisit != "1" && len(nativeString) < NewAdvertisingLimit.ImeiNum {
  108. UserImeiAdd(c, user.Id)
  109. res.IsCanVisit = "1"
  110. }
  111. }
  112. }
  113. }
  114. e.OutSuc(c, res, nil)
  115. return
  116. }
  117. func AdvertisingState(c *gin.Context) {
  118. var req md.AdvertisingReq
  119. err := c.ShouldBindJSON(&req)
  120. if err != nil {
  121. err = HandleValidateErr(err)
  122. err1 := err.(e.E)
  123. e.OutErr(c, err1.Code, err1.Error())
  124. return
  125. }
  126. isSuccess := "0"
  127. getString, _ := cache.GetString(req.Id)
  128. integral := "0"
  129. if getString == "" {
  130. var data model.AdvertisingCallback
  131. db.Db.Where("uniq_id=? ", req.Id).Get(&data)
  132. if data.Id > 0 {
  133. isSuccess = "1"
  134. integral = data.Integral
  135. }
  136. } else {
  137. isSuccess = "1"
  138. integral = getString
  139. }
  140. res := md.AdvertisingState{
  141. IsSuccess: isSuccess,
  142. Integral: integral,
  143. }
  144. e.OutSuc(c, res, nil)
  145. return
  146. }
  147. func AdvertisingDetail(c *gin.Context) {
  148. eg := db.Db
  149. var req md.AdvertisingReq
  150. err := c.ShouldBindJSON(&req)
  151. if err != nil {
  152. err = HandleValidateErr(err)
  153. err1 := err.(e.E)
  154. e.OutErr(c, err1.Code, err1.Error())
  155. return
  156. }
  157. var res = md.AdvertisingSpace{}
  158. NewAdvertisingSpaceDb := implement.NewAdvertisingSpaceDb(eg)
  159. NewAdvertisingSpace, _ := NewAdvertisingSpaceDb.GetAdvertisingSpace(req.Id)
  160. if NewAdvertisingSpace != nil {
  161. var info = make(map[string]interface{})
  162. json.Unmarshal([]byte(NewAdvertisingSpace.Info), &info)
  163. tmp := md.AdvertisingSpace{
  164. Id: utils.IntToStr(NewAdvertisingSpace.Id),
  165. Name: NewAdvertisingSpace.Name,
  166. Kind: utils.IntToStr(NewAdvertisingSpace.Kind),
  167. Info: info,
  168. CountingDown: utils.IntToStr(NewAdvertisingSpace.CountingDown),
  169. }
  170. res = tmp
  171. }
  172. e.OutSuc(c, res, nil)
  173. return
  174. }