蛋蛋星球-客户端
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.
 
 
 
 
 

168 rader
5.3 KiB

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