广告平台(总站长使用)
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.
 
 
 
 
 
 

127 lines
3.6 KiB

  1. package svc
  2. import (
  3. "applet/app/md"
  4. "applet/app/utils"
  5. db "code.fnuoos.com/zhimeng/model.git/src"
  6. implement2 "code.fnuoos.com/zhimeng/model.git/src/implement"
  7. model2 "code.fnuoos.com/zhimeng/model.git/src/model"
  8. "code.fnuoos.com/zhimeng/model.git/src/super/implement"
  9. "github.com/gin-gonic/gin"
  10. "strings"
  11. )
  12. func DataCenterOriginalDataList(c *gin.Context, req md.DataCenterOriginalDataReq) md.DataCenterOriginalDataRes {
  13. engine := db.Db
  14. NewOriginalWxAdDataDb := implement.NewOriginalWxAdDataDb(engine)
  15. appId := GetAppletId(c, req.Name, req.Platform)
  16. slotId := GetSlotId(c, req.State)
  17. MediumList, total, _ := NewOriginalWxAdDataDb.FindOriginalWxAdDataList("", appId, slotId, req.StartTime, req.EndTime, utils.StrToInt(req.Page), utils.StrToInt(req.Limit))
  18. data := make([]md.DataCenterOriginalDataData, 0)
  19. if len(MediumList) > 0 {
  20. for _, v := range MediumList {
  21. var tmp = md.DataCenterOriginalDataData{
  22. Id: utils.IntToStr(v.Id),
  23. ReqSuccCount: utils.IntToStr(v.ReqSuccCount),
  24. ExposureCount: utils.IntToStr(v.ExposureCount),
  25. ExposureRate: v.ExposureRate,
  26. ClickCount: utils.IntToStr(v.ClickCount),
  27. ClickRate: v.ClickRate,
  28. Date: v.Date,
  29. PublisherIncome: utils.Float64ToStr(float64(v.PublisherIncome) / 100),
  30. Ecpm: utils.Float64ToStr(utils.StrToFloat64(v.Ecpm) / 100),
  31. IsApply: utils.IntToStr(v.IsApply),
  32. }
  33. tmpApplet := GetAppletInfo(c, v.AppId)
  34. if tmpApplet["platform"] != "" {
  35. tmp.Platform = tmpApplet["platform"]
  36. }
  37. if tmpApplet["name"] != "" {
  38. tmp.Name = tmpApplet["name"]
  39. }
  40. tmpSlot := GetSlotInfo(c, v.SlotId)
  41. if tmpSlot["state"] != "" {
  42. tmp.State = tmpSlot["state"]
  43. }
  44. if tmpSlot["name"] != "" {
  45. tmp.AdvName = tmpSlot["name"]
  46. }
  47. data = append(data, tmp)
  48. }
  49. }
  50. res := md.DataCenterOriginalDataRes{
  51. List: data,
  52. Total: total,
  53. State: md.AdState,
  54. Platform: md.AdPlatform,
  55. }
  56. return res
  57. }
  58. // 应用
  59. func GetAppletId(c *gin.Context, name, platform string) string {
  60. mediumId := ""
  61. sess := MasterDb(c).Where("1=1")
  62. if name != "" || platform != "" {
  63. ids := []string{"-1"}
  64. var tmp []model2.AppletApplication
  65. if name != "" {
  66. sess.And("name like ? ", "%"+name+"%")
  67. }
  68. if platform != "" {
  69. sess.And("platform = ? ", platform)
  70. }
  71. sess.Find(&tmp)
  72. for _, v := range tmp {
  73. ids = append(ids, utils.IntToStr(v.MediumId))
  74. }
  75. mediumId = strings.Join(ids, ",")
  76. }
  77. return mediumId
  78. }
  79. // 广告位
  80. func GetSlotId(c *gin.Context, state string) string {
  81. mediumId := ""
  82. if state != "" {
  83. ids := []string{"-1"}
  84. var tmp []model2.AppletApplicationAdSpaceList
  85. MasterDb(c).Where("state=?", state).Find(&tmp)
  86. for _, v := range tmp {
  87. ids = append(ids, utils.IntToStr(v.MediumId))
  88. }
  89. mediumId = strings.Join(ids, ",")
  90. }
  91. return mediumId
  92. }
  93. // 应用
  94. func GetAppletInfo(c *gin.Context, id string) map[string]string {
  95. var res = map[string]string{
  96. "platform": "",
  97. "name": "",
  98. }
  99. NewAppletApplicationDb := implement2.NewAppletApplicationDb(MasterDb(c))
  100. data, _ := NewAppletApplicationDb.GetAppletApplicationListByAppid(id)
  101. if data != nil {
  102. res["platform"] = data.Platform
  103. res["name"] = data.Name
  104. }
  105. return res
  106. }
  107. // 广告位
  108. func GetSlotInfo(c *gin.Context, id string) map[string]string {
  109. var res = map[string]string{
  110. "state": "",
  111. "name": "",
  112. }
  113. NewAppletApplicationAdSpaceListDb := implement2.NewAppletApplicationAdSpaceListDb(MasterDb(c))
  114. data, _ := NewAppletApplicationAdSpaceListDb.GetAppletApplicationAdSpaceListByAdId(id)
  115. if data != nil {
  116. res["name"] = data.Name
  117. res["state"] = utils.IntToStr(data.State)
  118. }
  119. return res
  120. }