|
- package svc
-
- import (
- "applet/app/db"
- md2 "applet/app/es/md"
- "applet/app/task/md"
- "applet/app/utils"
- "code.fnuoos.com/go_rely_warehouse/zyos_go_es.git/es"
- "code.fnuoos.com/go_rely_warehouse/zyos_go_third_party_api.git/tpdaren"
- "encoding/json"
- "fmt"
- "github.com/syyongx/php2go"
- "github.com/tidwall/gjson"
- "time"
- )
-
- func PlayletGoods() {
- sysCfgDb := db.MasterListCfgDb{}
- sysCfgDb.Set()
- uid := "0"
- tpdarenAppidData, _ := sysCfgDb.MasterListCfgGetOne(uid, "tpdaren_appid")
- tpdarenAppsecretData, _ := sysCfgDb.MasterListCfgGetOne(uid, "tpdaren_appsecret")
- if tpdarenAppidData == nil || tpdarenAppsecretData == nil {
- return
- }
- token := GetTpdarenToken(uid)
- if token == "" {
- return
- }
- i := 1
- size := 200
- for {
- param := map[string]interface{}{
- "page_size": size,
- "page_index": i,
- }
- paging, err := tpdaren.TheaterFindPaging(token, param)
- if err != nil || paging == "" {
- break
- }
- listMap := gjson.Get(paging, "data.data").String()
- var list = make([]md.TpdarenList, 0)
- err = json.Unmarshal([]byte(listMap), &list)
- if err != nil {
- break
- }
- for _, v := range list {
- isEnd := "0"
- if v.IsEnd {
- isEnd = "1"
- }
- var tmp = md.Tpdaren{
- Description: v.Description,
- Episode: v.Episode,
- ImageUrl: v.ImageUrl,
- IsEnd: isEnd,
- PayEpisode: v.PayEpisode,
- Material: v.Material,
- OnlineTime: v.OnlineTime,
- Type: "tpdaren",
- Title: v.Title,
- Data: utils.SerializeStr(v),
- ChannelTheaterId: v.ChannelTheaterId,
- DouyinTheaterId: v.DouyinTheaterId,
- KuaishouTheaterId: v.KuaishouTheaterId,
- UpdateTime: int(time.Now().Unix()),
- Time: int(utils.TimeStdParseUnix(v.OnlineTime + " 00:00:00")),
- Appid: tpdarenAppidData.V,
- }
- var uniqueId = ""
- if v.ChannelTheaterId > 0 {
- tmp.VideoType = "channel"
- uniqueId = php2go.Md5(tmp.Appid + "_" + tmp.Type + "_" + tmp.VideoType + "_" + utils.IntToStr(v.ChannelTheaterId))
- tmp.Id = v.ChannelTheaterId
- commAdd(uniqueId, tmp)
- }
- if v.DouyinTheaterId > 0 {
- tmp.VideoType = "douyin"
- uniqueId = php2go.Md5(tmp.Appid + "_" + tmp.Type + "_" + tmp.VideoType + "_" + utils.IntToStr(v.DouyinTheaterId))
- tmp.Id = v.DouyinTheaterId
- commAdd(uniqueId, tmp)
- }
- if v.KuaishouTheaterId > 0 {
- tmp.VideoType = "kuaishou"
- uniqueId = php2go.Md5(tmp.Appid + "_" + tmp.Type + "_" + tmp.VideoType + "_" + utils.IntToStr(v.KuaishouTheaterId))
- tmp.Id = v.KuaishouTheaterId
- commAdd(uniqueId, tmp)
- }
-
- }
- if len(list) < 200 {
- break
- }
- i++
- }
- }
- func commAdd(uniqueId string, tmp md.Tpdaren) {
- doc, _ := es.FirstDoc(md2.ZhiosTpdarenEsIndex, uniqueId)
- if doc == nil {
- createDocRet, err := es.CreateDoc(md2.ZhiosTpdarenEsIndex, uniqueId, tmp)
- if err != nil {
- return
- }
- fmt.Printf("CreateDoc ==> %+v \n\n", createDocRet)
- } else {
- createDocRet, err := es.UpdateDoc(md2.ZhiosTpdarenEsIndex, uniqueId, tmp)
- if err != nil {
- return
- }
- fmt.Printf("CreateDoc ==> %+v \n\n", createDocRet)
- }
- }
|