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

201 lines
6.3 KiB

  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. NewCloudBundleDb := implement.NewCloudBundleDb(db.Db)
  61. os := "1"
  62. if c.GetHeader("platform") == "iOS" {
  63. os = "2"
  64. }
  65. data, _ := NewCloudBundleDb.GetCloudBundleVersion(os, c.GetHeader("appversionname"), c.GetHeader("channel"))
  66. for _, v := range *NewAdvertisingSpace {
  67. var info = make(map[string]interface{})
  68. json.Unmarshal([]byte(v.Info), &info)
  69. if data != nil && data.IsAuditing == 1 {
  70. //审核版本
  71. if v.Kind == 4 {
  72. continue
  73. }
  74. }
  75. tmp := md.AdvertisingSpace{
  76. Id: utils.IntToStr(v.Id),
  77. Name: v.Name,
  78. Kind: utils.IntToStr(v.Kind),
  79. Info: info,
  80. CountingDown: utils.IntToStr(v.CountingDown),
  81. }
  82. NewAdvertisingSpaceTmp = append(NewAdvertisingSpaceTmp, tmp)
  83. }
  84. }
  85. res.Space = NewAdvertisingSpaceTmp
  86. e.OutSuc(c, res, nil)
  87. return
  88. }
  89. func AdvertisingCheck(c *gin.Context) {
  90. eg := db.Db
  91. var req md.AdvertisingReq
  92. err := c.ShouldBindJSON(&req)
  93. if err != nil {
  94. err = HandleValidateErr(err)
  95. err1 := err.(e.E)
  96. e.OutErr(c, err1.Code, err1.Error())
  97. return
  98. }
  99. user := GetUser(c)
  100. var res = md.AdvertisingCheck{IsCanVisit: "0"}
  101. NewAdvertisingSpaceDb := implement.NewAdvertisingSpaceDb(eg)
  102. NewAdvertisingSpace, _ := NewAdvertisingSpaceDb.GetAdvertisingSpace(req.Id)
  103. if NewAdvertisingSpace != nil {
  104. if NewAdvertisingSpace.Kind != 3 {
  105. res.IsCanVisit = "1"
  106. } else {
  107. NewAdvertisingLimitDb := implement.NewAdvertisingLimitDb(eg)
  108. NewAdvertisingLimit, _ := NewAdvertisingLimitDb.GetAdvertisingLimit()
  109. if NewAdvertisingLimit != nil && NewAdvertisingLimit.ImeiNum > 0 {
  110. sql := `SELECT uid FROM user_imei WHERE create_at>='%s' and ip='%s' GROUP BY imei LIMIT %s`
  111. now := time.Now().Unix() - int64(NewAdvertisingLimit.Minute*60)
  112. sql = fmt.Sprintf(sql, time.Unix(now, 0).Format("2006-01-02 15:04:05"), utils.GetIP(c.Request), NewAdvertisingLimit.ImeiNum)
  113. nativeString, _ := db.QueryNativeString(db.Db, sql)
  114. for _, v := range nativeString {
  115. if utils.StrToInt64(v["uid"]) == user.Id {
  116. res.IsCanVisit = "1"
  117. }
  118. }
  119. if res.IsCanVisit != "1" && len(nativeString) < NewAdvertisingLimit.ImeiNum {
  120. UserImeiAdd(c, user.Id)
  121. res.IsCanVisit = "1"
  122. }
  123. }
  124. }
  125. }
  126. e.OutSuc(c, res, nil)
  127. return
  128. }
  129. func AdvertisingState(c *gin.Context) {
  130. var req md.AdvertisingReq
  131. err := c.ShouldBindJSON(&req)
  132. if err != nil {
  133. err = HandleValidateErr(err)
  134. err1 := err.(e.E)
  135. e.OutErr(c, err1.Code, err1.Error())
  136. return
  137. }
  138. isSuccess := "0"
  139. getString, _ := cache.GetString("advEcpm:" + req.Id)
  140. integral := "0"
  141. if getString == "" {
  142. var data model.AdvertisingCallback
  143. db.Db.Where("uniq_id=? ", req.Id).Get(&data)
  144. if data.Id > 0 {
  145. isSuccess = "1"
  146. integral = data.Integral
  147. }
  148. } else {
  149. isSuccess = "1"
  150. integral = getString
  151. }
  152. utils.FilePutContents("AdvertisingState", utils.SerializeStr(map[string]interface{}{
  153. "is_success": isSuccess,
  154. "id": req.Id,
  155. "ecpm": req.Ecpm,
  156. "getString": getString,
  157. "time": time.Now().Format("2006-01-02 15:04:05"),
  158. }))
  159. res := md.AdvertisingState{
  160. IsSuccess: isSuccess,
  161. Integral: integral,
  162. }
  163. if utils.StrToFloat64(req.Ecpm) > 0 {
  164. //db.Db.Where("uniq_id=?", req.Id).Cols("custom_ecpm").Update(&model.AdvertisingCallback{CustomEcpm: req.Ecpm})
  165. }
  166. e.OutSuc(c, res, nil)
  167. return
  168. }
  169. func AdvertisingDetail(c *gin.Context) {
  170. eg := db.Db
  171. var req md.AdvertisingReq
  172. err := c.ShouldBindJSON(&req)
  173. if err != nil {
  174. err = HandleValidateErr(err)
  175. err1 := err.(e.E)
  176. e.OutErr(c, err1.Code, err1.Error())
  177. return
  178. }
  179. var res = md.AdvertisingSpace{}
  180. NewAdvertisingSpaceDb := implement.NewAdvertisingSpaceDb(eg)
  181. NewAdvertisingSpace, _ := NewAdvertisingSpaceDb.GetAdvertisingSpace(req.Id)
  182. if NewAdvertisingSpace != nil {
  183. var info = make(map[string]interface{})
  184. json.Unmarshal([]byte(NewAdvertisingSpace.Info), &info)
  185. tmp := md.AdvertisingSpace{
  186. Id: utils.IntToStr(NewAdvertisingSpace.Id),
  187. Name: NewAdvertisingSpace.Name,
  188. Kind: utils.IntToStr(NewAdvertisingSpace.Kind),
  189. Info: info,
  190. CountingDown: utils.IntToStr(NewAdvertisingSpace.CountingDown),
  191. }
  192. res = tmp
  193. }
  194. e.OutSuc(c, res, nil)
  195. return
  196. }