From 69dba283e5f5bcd4d8b1832f4b266d9ed1bf4fff Mon Sep 17 00:00:00 2001 From: huangjiajun <582604932@qq.com> Date: Tue, 31 Oct 2023 10:36:19 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/task/svc/svc_tik_tok_task_money.go | 55 ++++++++++++++++++++++++-- go.mod | 1 + 2 files changed, 52 insertions(+), 4 deletions(-) diff --git a/app/task/svc/svc_tik_tok_task_money.go b/app/task/svc/svc_tik_tok_task_money.go index 1302826..7256adb 100644 --- a/app/task/svc/svc_tik_tok_task_money.go +++ b/app/task/svc/svc_tik_tok_task_money.go @@ -3,12 +3,17 @@ package svc import ( "applet/app/db" "applet/app/db/model" + 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/tik_tok" zhios_third_party_utils "code.fnuoos.com/go_rely_warehouse/zyos_go_third_party_api.git/utils" + "context" "encoding/json" "fmt" + "github.com/olivere/elastic/v7" + "github.com/syyongx/php2go" "github.com/tidwall/gjson" "strings" "time" @@ -25,6 +30,7 @@ func TikTokTaskMoney(types string) { now["start"] = now["start"] - 10 - 86400 } date := time.Unix(now["start"], 0).Format("2006-01-02") + date = "2023-10-25" p := 1 for { param := map[string]interface{}{ @@ -43,13 +49,54 @@ func TikTokTaskMoney(types string) { var order = make([]md.TikTokTaskOrder, 0) json.Unmarshal([]byte(orderStr), &order) for _, v := range order { + if v.BillingGMV1D <= 0 { + continue + } + var TalentProfit1D float64 = 0 + var result *elastic.SearchResult + boolQuery := elastic.NewBoolQuery() // 创建bool查询 + rangeQuery := elastic.NewMatchQuery("task_id", v.TaskId) + boolQuery.Must(rangeQuery) + rangeQuery1 := elastic.NewRangeQuery("task_end_time").Gt(time.Now().Unix()) + boolQuery.Must(rangeQuery1) + key := md2.ZhiosTikTokTaskDetailEsIndex + esWhere := es.EsClient.Search(). + Index(key). + TrackTotalHits(true). + Query(boolQuery) + var err error + result, err = esWhere. // 设置查询条件 + Size(1). // 设置分页参数 - 每页大小,设置为0,代表不返回搜索结果,仅返回聚合分析结果 + From(0). + Pretty(true). // 返回可读的json格式 + Do(context.Background()) + fmt.Println(result) + fmt.Println(err) + if result != nil && len(result.Hits.Hits) > 0 { + for _, hit := range result.Hits.Hits { + if hit == nil { + continue + } + jsonByte, marErr := hit.Source.MarshalJSON() + var tmps md.TikTokTaskDetailSecond + if marErr == nil { + err := json.Unmarshal(jsonByte, &tmps) + if err == nil { + bili := float64(tmps.PaymentAllocateRatio) / 10000 * (10.0 / 11.0) * 1000 + TalentProfit1D = float64(int(bili)) / 10 + } + } + } + } discount := float64(v.BillingGMV1D)/100 - float64(v.BillingRefundGMV1D)/100 if discount < 0 { discount = 0 } - commission := discount - float64(v.TalentProfit1D)/100 - discount*15/100 + talentBili := float64(int(discount*(TalentProfit1D/100)*100)) / 100 + platformBili := php2go.Round(discount*(15.0/100), 2) + commission := discount - talentBili - platformBili fee := discount - commission - oid := "douyin" + zhios_third_party_utils.Int64ToStr(v.VideoId) + date + oid := "douyin" + zhios_third_party_utils.Int64ToStr(v.VideoId) + v.AgentID + v.DouyinID + date oid = strings.ReplaceAll(oid, "_", "") oid = strings.ReplaceAll(oid, "-", "") oid = strings.ReplaceAll(oid, " ", "") @@ -64,7 +111,7 @@ func TikTokTaskMoney(types string) { Uid: split[0], SubUid: utils.StrToInt(split[1]), Data: utils.SerializeStr(v), - Oid: oid, + Oid: php2go.Md5(oid), Amount: utils.Float64ToStr(discount), Commission: utils.Float64ToStr(commission), CreateTime: utils.TimeParseStd(date + " 00:00:00"), @@ -76,7 +123,7 @@ func TikTokTaskMoney(types string) { OrdType: "video", ExtendUid: v.DouyinID + "_" + v.AgentID, PlatformFee: utils.Float64ToStr(fee), - TikFee: utils.Float64ToStr(float64(v.TalentProfit1D) / 100), + TikFee: utils.Float64ToStr(talentBili), } playletSaleOrderDb := db.PlayletSaleOrderDb{} playletSaleOrderDb.Set() diff --git a/go.mod b/go.mod index 0690c35..a5c1bcc 100644 --- a/go.mod +++ b/go.mod @@ -22,6 +22,7 @@ require ( github.com/jinzhu/copier v0.3.5 github.com/makiuchi-d/gozxing v0.1.1 github.com/mcuadros/go-defaults v1.2.0 + github.com/olivere/elastic/v7 v7.0.32 github.com/qiniu/api.v7/v7 v7.8.2 github.com/robfig/cron/v3 v3.0.1 github.com/sony/sonyflake v1.1.0