|
- package svc
-
- import (
- "applet/app/db"
- "applet/app/db/model"
- "applet/app/task/md"
- "applet/app/utils"
- "code.fnuoos.com/go_rely_warehouse/zyos_go_third_party_api.git/tik_tok"
- zhios_third_party_utils "code.fnuoos.com/go_rely_warehouse/zyos_go_third_party_api.git/utils"
- "encoding/json"
- "fmt"
- "github.com/tidwall/gjson"
- "strings"
- "time"
- )
-
- func TikTokTaskMoney(types string) {
- endTime := time.Now().Unix()
- startTime := endTime - 89*86400
- now := zhios_third_party_utils.GetTimeRange("today")
- if types == "yestday" {
- now["start"] = now["start"] - 10
- }
- if types == "now" {
- now["start"] = now["start"] - 10 - 86400
- }
- date := time.Unix(now["start"], 0).Format("2006-01-02")
- p := 1
- for {
- param := map[string]interface{}{
- "page_no": p,
- "page_size": 100,
- "video_publish_start_time": startTime,
- "billing_date": date,
- "video_publish_end_time": endTime,
- }
- api, _ := tik_tok.TaskApi("query_agency_video_daily_data/", TikTokTaskToken(), zhios_third_party_utils.SerializeStr(param))
- fmt.Println(api)
- orderStr := gjson.Get(api, "data.results").String()
- if orderStr == "" {
- break
- }
- var order = make([]md.TikTokTaskOrder, 0)
- json.Unmarshal([]byte(orderStr), &order)
- for _, v := range order {
- discount := float64(v.BillingGMV1D)/100 - float64(v.BillingRefundGMV1D)/100
- if discount < 0 {
- discount = 0
- }
- commission := discount - float64(v.TalentProfit1D)/100 - discount*15/100
- fee := discount - commission
- oid := "douyin" + zhios_third_party_utils.Int64ToStr(v.VideoId) + date
- oid = strings.ReplaceAll(oid, "_", "")
- oid = strings.ReplaceAll(oid, "-", "")
- oid = strings.ReplaceAll(oid, " ", "")
- oid = strings.ReplaceAll(oid, ":", "")
- var tikTokData model.TikTokPlanTeam
- db.ZhimengDb.Where("team_id=? and tik_tok_id=?", v.AgentID, v.DouyinID).Get(&tikTokData)
- if tikTokData.Id == 0 || tikTokData.Ext == "" {
- continue
- }
- split := strings.Split(tikTokData.Ext, "_")
- var tmp = model.PlayletSaleOrder{
- Uid: split[0],
- SubUid: utils.StrToInt(split[1]),
- Data: utils.SerializeStr(v),
- Oid: oid,
- Amount: utils.Float64ToStr(discount),
- Commission: utils.Float64ToStr(commission),
- CreateTime: utils.TimeParseStd(date + " 00:00:00"),
- UpdateTime: time.Now(),
- Title: v.VideoTitle,
- VideoType: "douyin",
- PlatformType: "dianzhong",
- GoodsType: "playlet",
- OrdType: "video",
- ExtendUid: v.DouyinID + "_" + v.AgentID,
- PlatformFee: utils.Float64ToStr(fee),
- TikFee: utils.Float64ToStr(float64(v.TalentProfit1D) / 100),
- }
- playletSaleOrderDb := db.PlayletSaleOrderDb{}
- playletSaleOrderDb.Set()
- ord := playletSaleOrderDb.GetPlayletVideoOrderByOid(tmp.Oid, tmp.OrdType)
- tmp.Status = "订单付款"
- if ord != nil {
- playletSaleOrderDb.PlayletVideoOrderUpdate(ord.Id, &tmp)
- } else {
- tmp.CustomOid = utils.OrderUUID(tmp.SubUid)
- playletSaleOrderDb.PlayletVideoOrderInsert(&tmp)
- }
- }
- p++
- }
- return
- }
|