智盟项目
No puede seleccionar más de 25 temas Los temas deben comenzar con una letra o número, pueden incluir guiones ('-') y pueden tener hasta 35 caracteres de largo.

113 líneas
3.0 KiB

  1. package svc
  2. import (
  3. "applet/app/db"
  4. md2 "applet/app/es/md"
  5. "applet/app/task/md"
  6. "applet/app/utils"
  7. "code.fnuoos.com/go_rely_warehouse/zyos_go_es.git/es"
  8. "code.fnuoos.com/go_rely_warehouse/zyos_go_third_party_api.git/tpdaren"
  9. "encoding/json"
  10. "fmt"
  11. "github.com/syyongx/php2go"
  12. "github.com/tidwall/gjson"
  13. "time"
  14. )
  15. func PlayletGoods() {
  16. sysCfgDb := db.MasterListCfgDb{}
  17. sysCfgDb.Set()
  18. uid := "0"
  19. tpdarenAppidData, _ := sysCfgDb.MasterListCfgGetOne(uid, "tpdaren_appid")
  20. tpdarenAppsecretData, _ := sysCfgDb.MasterListCfgGetOne(uid, "tpdaren_appsecret")
  21. if tpdarenAppidData == nil || tpdarenAppsecretData == nil {
  22. return
  23. }
  24. token := GetTpdarenToken(uid)
  25. if token == "" {
  26. return
  27. }
  28. i := 1
  29. size := 200
  30. for {
  31. param := map[string]interface{}{
  32. "page_size": size,
  33. "page_index": i,
  34. }
  35. paging, err := tpdaren.TheaterFindPaging(token, param)
  36. if err != nil || paging == "" {
  37. break
  38. }
  39. listMap := gjson.Get(paging, "data.data").String()
  40. var list = make([]md.TpdarenList, 0)
  41. err = json.Unmarshal([]byte(listMap), &list)
  42. if err != nil {
  43. break
  44. }
  45. for _, v := range list {
  46. isEnd := "0"
  47. if v.IsEnd {
  48. isEnd = "1"
  49. }
  50. var tmp = md.Tpdaren{
  51. Description: v.Description,
  52. Episode: v.Episode,
  53. ImageUrl: v.ImageUrl,
  54. IsEnd: isEnd,
  55. PayEpisode: v.PayEpisode,
  56. Material: v.Material,
  57. OnlineTime: v.OnlineTime,
  58. Type: "tpdaren",
  59. Title: v.Title,
  60. Data: utils.SerializeStr(v),
  61. ChannelTheaterId: v.ChannelTheaterId,
  62. DouyinTheaterId: v.DouyinTheaterId,
  63. KuaishouTheaterId: v.KuaishouTheaterId,
  64. UpdateTime: int(time.Now().Unix()),
  65. Time: int(utils.TimeStdParseUnix(v.OnlineTime + " 00:00:00")),
  66. Appid: tpdarenAppidData.V,
  67. }
  68. var uniqueId = ""
  69. if v.ChannelTheaterId > 0 {
  70. tmp.VideoType = "channel"
  71. uniqueId = php2go.Md5(tmp.Appid + "_" + tmp.Type + "_" + tmp.VideoType + "_" + utils.IntToStr(v.ChannelTheaterId))
  72. tmp.Id = v.ChannelTheaterId
  73. commAdd(uniqueId, tmp)
  74. }
  75. if v.DouyinTheaterId > 0 {
  76. tmp.VideoType = "douyin"
  77. uniqueId = php2go.Md5(tmp.Appid + "_" + tmp.Type + "_" + tmp.VideoType + "_" + utils.IntToStr(v.DouyinTheaterId))
  78. tmp.Id = v.DouyinTheaterId
  79. commAdd(uniqueId, tmp)
  80. }
  81. if v.KuaishouTheaterId > 0 {
  82. tmp.VideoType = "kuaishou"
  83. uniqueId = php2go.Md5(tmp.Appid + "_" + tmp.Type + "_" + tmp.VideoType + "_" + utils.IntToStr(v.KuaishouTheaterId))
  84. tmp.Id = v.KuaishouTheaterId
  85. commAdd(uniqueId, tmp)
  86. }
  87. }
  88. if len(list) < 200 {
  89. break
  90. }
  91. i++
  92. }
  93. }
  94. func commAdd(uniqueId string, tmp md.Tpdaren) {
  95. doc, _ := es.FirstDoc(md2.ZhiosTpdarenEsIndex, uniqueId)
  96. if doc == nil {
  97. createDocRet, err := es.CreateDoc(md2.ZhiosTpdarenEsIndex, uniqueId, tmp)
  98. if err != nil {
  99. return
  100. }
  101. fmt.Printf("CreateDoc ==> %+v \n\n", createDocRet)
  102. } else {
  103. createDocRet, err := es.UpdateDoc(md2.ZhiosTpdarenEsIndex, uniqueId, tmp)
  104. if err != nil {
  105. return
  106. }
  107. fmt.Printf("CreateDoc ==> %+v \n\n", createDocRet)
  108. }
  109. }