智盟项目
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.

96 lines
3.0 KiB

  1. package svc
  2. import (
  3. "applet/app/db"
  4. "applet/app/db/model"
  5. "applet/app/task/md"
  6. "applet/app/utils"
  7. "code.fnuoos.com/go_rely_warehouse/zyos_go_third_party_api.git/tik_tok"
  8. zhios_third_party_utils "code.fnuoos.com/go_rely_warehouse/zyos_go_third_party_api.git/utils"
  9. "encoding/json"
  10. "fmt"
  11. "github.com/tidwall/gjson"
  12. "strings"
  13. "time"
  14. )
  15. func TikTokTaskMoney(types string) {
  16. endTime := time.Now().Unix()
  17. startTime := endTime - 89*86400
  18. now := zhios_third_party_utils.GetTimeRange("today")
  19. if types == "yestday" {
  20. now["start"] = now["start"] - 10
  21. }
  22. if types == "now" {
  23. now["start"] = now["start"] - 10 - 86400
  24. }
  25. date := time.Unix(now["start"], 0).Format("2006-01-02")
  26. p := 1
  27. for {
  28. param := map[string]interface{}{
  29. "page_no": p,
  30. "page_size": 100,
  31. "video_publish_start_time": startTime,
  32. "billing_date": date,
  33. "video_publish_end_time": endTime,
  34. }
  35. api, _ := tik_tok.TaskApi("query_agency_video_daily_data/", TikTokTaskToken(), zhios_third_party_utils.SerializeStr(param))
  36. fmt.Println(api)
  37. orderStr := gjson.Get(api, "data.results").String()
  38. if orderStr == "" {
  39. break
  40. }
  41. var order = make([]md.TikTokTaskOrder, 0)
  42. json.Unmarshal([]byte(orderStr), &order)
  43. for _, v := range order {
  44. discount := float64(v.BillingGMV1D)/100 - float64(v.BillingRefundGMV1D)/100
  45. if discount < 0 {
  46. discount = 0
  47. }
  48. commission := discount - float64(v.TalentProfit1D)/100 - discount*15/100
  49. fee := discount - commission
  50. oid := "douyin" + zhios_third_party_utils.Int64ToStr(v.VideoId) + date
  51. oid = strings.ReplaceAll(oid, "_", "")
  52. oid = strings.ReplaceAll(oid, "-", "")
  53. oid = strings.ReplaceAll(oid, " ", "")
  54. oid = strings.ReplaceAll(oid, ":", "")
  55. var tikTokData model.TikTokPlanTeam
  56. db.ZhimengDb.Where("team_id=? and tik_tok_id=?", v.AgentID, v.DouyinID).Get(&tikTokData)
  57. if tikTokData.Id == 0 || tikTokData.Ext == "" {
  58. continue
  59. }
  60. split := strings.Split(tikTokData.Ext, "_")
  61. var tmp = model.PlayletSaleOrder{
  62. Uid: split[0],
  63. SubUid: utils.StrToInt(split[1]),
  64. Data: utils.SerializeStr(v),
  65. Oid: oid,
  66. Amount: utils.Float64ToStr(discount),
  67. Commission: utils.Float64ToStr(commission),
  68. CreateTime: utils.TimeParseStd(date + " 00:00:00"),
  69. UpdateTime: time.Now(),
  70. Title: v.VideoTitle,
  71. VideoType: "douyin",
  72. PlatformType: "dianzhong",
  73. GoodsType: "playlet",
  74. OrdType: "video",
  75. ExtendUid: v.DouyinID + "_" + v.AgentID,
  76. PlatformFee: utils.Float64ToStr(fee),
  77. TikFee: utils.Float64ToStr(float64(v.TalentProfit1D) / 100),
  78. }
  79. playletSaleOrderDb := db.PlayletSaleOrderDb{}
  80. playletSaleOrderDb.Set()
  81. ord := playletSaleOrderDb.GetPlayletVideoOrderByOid(tmp.Oid, tmp.OrdType)
  82. tmp.Status = "订单付款"
  83. if ord != nil {
  84. playletSaleOrderDb.PlayletVideoOrderUpdate(ord.Id, &tmp)
  85. } else {
  86. tmp.CustomOid = utils.OrderUUID(tmp.SubUid)
  87. playletSaleOrderDb.PlayletVideoOrderInsert(&tmp)
  88. }
  89. }
  90. p++
  91. }
  92. return
  93. }