huangjiajun 2 mesi fa
parent
commit
5482c210f2
8 ha cambiato i file con 256 aggiunte e 1 eliminazioni
  1. +1
    -0
      app/db/model/guide_order.go
  2. +6
    -0
      app/db/official/model/uuid_list.go
  3. +1
    -0
      app/task/init.go
  4. +1
    -0
      app/task/md/cron_key.go
  5. +195
    -0
      app/task/svc/svc_tik_tok_chanxuan.go
  6. +21
    -0
      app/task/task_tik_tok_chanxuan.go
  7. +30
    -0
      app/utils/convert.go
  8. +1
    -1
      go.mod

+ 1
- 0
app/db/model/guide_order.go Vedi File

@@ -24,4 +24,5 @@ type GuideOrder struct {
Gid string `json:"gid" xorm:"VARCHAR(255)"`
TeamType string `json:"team_type" xorm:"VARCHAR(255)"`
TaskType string `json:"task_type" xorm:"VARCHAR(255)"`
ThreeType string `json:"three_type" xorm:"VARCHAR(255)"`
}

+ 6
- 0
app/db/official/model/uuid_list.go Vedi File

@@ -0,0 +1,6 @@
package model

type UuidList struct {
Id int `json:"id" xorm:"not null pk autoincr INT(11)"`
Uuid string `json:"uuid" xorm:"comment('') TEXT"`
}

+ 1
- 0
app/task/init.go Vedi File

@@ -91,6 +91,7 @@ func initTasks() {
jobs[taskMd.ZhimengCronTikTokCsjp] = taskTikTokCsjp //
jobs[taskMd.ZhimengCronTikTokCsjpActivity] = taskTikTokCsjpActivity //
jobs[taskMd.ZhimengCronTikTokCsjpLive] = taskTikTokCsjpLive //
jobs[taskMd.ZhimengCronTikTokChanxuan] = taskTikTokCsjpChanxuan //

jobs[taskMd.ZhimengCronTikTokTask] = taskTikTokTask //
jobs[taskMd.ZhimengCronTikTokTaskRelate] = taskTikTokTaskRelate //


+ 1
- 0
app/task/md/cron_key.go Vedi File

@@ -3,6 +3,7 @@ package md
const (
ZhimengCronTikTokTaskRelate = "zhimeng_cron_tik_tok_relate"
ZhimengCronTikTokCsjp = "zhimeng_cron_tik_tok_csjp"
ZhimengCronTikTokChanxuan = "zhimeng_cron_tik_tok_chanxuan"
ZhimengCronCinema5bms = "zhimeng_cron_cinema5bms"
ZhimengCronPLayletBihaiOrder = "zhimeng_cron_playlet_bihai_order"
ZhimengCronCinema5bmsOrder = "zhimeng_cron_cinema5bms_order"


+ 195
- 0
app/task/svc/svc_tik_tok_chanxuan.go Vedi File

@@ -0,0 +1,195 @@
package svc

import (
"applet/app/db"
"applet/app/db/model"
offical "applet/app/db/official"
model2 "applet/app/db/official/model"
"applet/app/utils"
"applet/app/utils/cache"
"code.fnuoos.com/go_rely_warehouse/zyos_go_third_party_api.git/chanxuanTikTok"
"fmt"
"github.com/tidwall/gjson"
"strings"
"time"
)

func TikTokChanxuan(ordType int) {
pvdTimeKey := "chanxuan_time_" + utils.IntToStr(ordType)

// 获得最后时间
latest := offical.SysCfgByKey(pvdTimeKey)
if latest == nil {
offical.DbsSysCfgInserts(pvdTimeKey, time.Now().String())
latest = offical.SysCfgByKey(pvdTimeKey)
}
// 所有时间都是在操作秒数
now := time.Now().Unix()
strs := strings.Split(latest.V, ":")
timeStr := latest.V
if len(strs) == 3 {
timeStr = strs[0] + ":" + strs[1] + ":00"
}
fmt.Println(timeStr)
past := utils.TimeParseStd(timeStr).Unix()
// 如果上次记录超过30天或者 过去时间大于当前时间戳, 把时间设置为此前20分钟
if past < now-180*86400 || past > now {
past = now
}
userId := offical.SysCfgByKeyStr("tikTok_chanxuan_user_id")
var (
beginTime int64 = 0
endTime int64 = 0
pageNo int = 1
pageSize int = 50
)

//怕时间不是走最新的
leave := now - past
if leave > 500 {
leave = 0
}
past = past + leave
beginTime = past - 300
endTime = past

if endTime > now {
endTime = now
}
token := GetChanxuanToken()
for {
var err error
count := OrdersTikTokChanxuanGet(pageNo, pageSize, beginTime, endTime, userId, ordType, token)
if err != nil || count == 0 {
goto ChkArg
}
if count > 0 {
count = pageSize
}
// 判断是否分页已经全部取完了
if count == pageSize {
pageNo++
fmt.Println("========下一页========" + utils.IntToStr(pageNo))
continue
}
ChkArg:
// 查询完后重置时间, 最后查询时间
if endTime < now {
pageNo = 1
offical.DbsSysCfgUpdate(pvdTimeKey, utils.TimeToStr(endTime))
beginTime = endTime
endTime = endTime + 300
if endTime > now {
endTime = now
}
continue
}
break
}
}

var stationState = map[string]string{
"PAY_SUCC": "订单付款",
"REFUND": "订单退款",
"SETTLE": "订单结算",
"CONFIRM": "订单成功",
}

func OrdersTikTokChanxuanGet(page, pageSize int, sTime, eTime int64, userId string, pvd int, token string) int {

distributionType := pvd
tikTokArgs := map[string]string{
"page_size": utils.IntToStr(pageSize),
"page": utils.IntToStr(page),
"start_time": utils.Int64ToStr(time.Unix(sTime, 0).Unix()),
"end_time": utils.Int64ToStr(time.Unix(eTime, 0).Unix()),
"query_type": utils.IntToStr(distributionType),
"user_id": userId,
}
order := chanxuanTikTok.GetOrder(token, userId, tikTokArgs)
uuidList := make([]model2.UuidList, 0)
uuidMap := make(map[int]string)
db.Db.Find(&uuidList)
for _, v := range uuidList {
uuidMap[v.Id] = v.Uuid
}
for _, v := range order {
if v.VipMsg == "" {
continue
}
vipMsg := utils.Base62Decode(v.VipMsg)
if vipMsg == 0 {
continue
}
vipMsgStr := utils.IntToStr(vipMsg)

orderTypeStr := vipMsgStr[0:1]
orderType := 0
if orderTypeStr == "2" {
orderType = 1
}
mid := uuidMap[utils.StrToInt(vipMsgStr[1:5])]
if mid == "" {
continue
}
uid := vipMsgStr[5:]
var ord = &model.GuideOrder{
Oid: utils.StrToInt64(utils.OrderUUID(utils.StrToInt(uid))),
Uid: utils.StrToInt(mid),
StationUid: utils.StrToInt(uid),
PvdOid: utils.AnyToString(v.OrderId),
Status: stationState[v.FlowPoint],
UpdateTime: int(time.Now().Unix()),
Commission: utils.Float64ToStr(float64(v.EstimatedCommission) / 100),
Title: utils.AnyToString(v.ProductName),
Payment: utils.Float64ToStr(float64(v.TotalPayAmount) / 100),
Pvd: "csjp",
Img: v.ProductImg,
IsShare: orderType,
Gid: v.ProductId,
ThreeType: "chan_xuan",
}
if v.PaySuccessTime != "" {
ord.CreateTime = int(utils.TimeStdParseUnix(v.PaySuccessTime))
}
if v.SettleTime != "" && v.SettleTime != nil {
ord.PlatformSettleTime = int(utils.TimeStdParseUnix(utils.AnyToString(v.SettleTime)))
}
if v.RealCommission > 0 {
ord.RealCommission = utils.Float64ToStr(float64(v.RealCommission) / 100)
}
one := db.GetGuideOrderByOne(ord.PvdOid, utils.IntToStr(ord.Uid), ord.Pvd)
if one == nil {
insertOne, err := db.ZhimengDb.InsertOne(ord)
fmt.Println(insertOne)
fmt.Println(err)
} else {
ord.SettleTime = one.SettleTime
if one.PlatformSettleTime > 0 {
ord.PlatformSettleTime = one.PlatformSettleTime
}
if one.Status == "违规订单" {
one.Status = "违规订单"
}
db.ZhimengDb.Where("id=?", one.Id).AllCols().Update(ord)
}

}
return len(order)
}
func GetChanxuanToken() string {
tiktokChanxuanId := offical.SysCfgByKeyStr("tikTok_chanxuan_id")
tiktokChanxuanSecret := offical.SysCfgByKeyStr("tikTok_chanxuan_secret")
key := "app:chanxuan.token:" + tiktokChanxuanId
getString, err := cache.GetString(key)
if err != nil || getString == "" {
data := chanxuanTikTok.GetToken(tiktokChanxuanId, tiktokChanxuanSecret)
ex := gjson.Get(data, "expires_in_v2").Int() - time.Now().Unix()
token := gjson.Get(data, "access_token").String()
if token != "" {
cache.SetEx(key, token, int(ex))
getString = token
}
}
return getString
}

+ 21
- 0
app/task/task_tik_tok_chanxuan.go Vedi File

@@ -0,0 +1,21 @@
package task

import (
"applet/app/task/svc"
"math/rand"
"time"
)

func taskTikTokCsjpChanxuan() {
for {
if len(ch) > workerNum {
time.Sleep(time.Millisecond * time.Duration(rand.Intn(1000)))
} else {
goto START
}
}
START:
ch <- 1
svc.TikTokChanxuan(3)
<-ch
}

+ 30
- 0
app/utils/convert.go Vedi File

@@ -9,6 +9,36 @@ import (
"strings"
)

const CODE62 = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
const CODE_LENTH = 62

var EDOC = map[string]int{"0": 0, "1": 1, "2": 2, "3": 3, "4": 4, "5": 5, "6": 6, "7": 7, "8": 8, "9": 9, "a": 10, "b": 11, "c": 12, "d": 13, "e": 14, "f": 15, "g": 16, "h": 17, "i": 18, "j": 19, "k": 20, "l": 21, "m": 22, "n": 23, "o": 24, "p": 25, "q": 26, "r": 27, "s": 28, "t": 29, "u": 30, "v": 31, "w": 32, "x": 33, "y": 34, "z": 35, "A": 36, "B": 37, "C": 38, "D": 39, "E": 40, "F": 41, "G": 42, "H": 43, "I": 44, "J": 45, "K": 46, "L": 47, "M": 48, "N": 49, "O": 50, "P": 51, "Q": 52, "R": 53, "S": 54, "T": 55, "U": 56, "V": 57, "W": 58, "X": 59, "Y": 60, "Z": 61}

func Base62Encode(number int) string {
if number == 0 {
return "0"
}
result := make([]byte, 0)
for number > 0 {
round := number / CODE_LENTH
remain := number % CODE_LENTH
result = append(result, CODE62[remain])
number = round
}
return string(result)
}

/**
* 解码字符串为整数
*/
func Base62Decode(str string) int {
str = strings.TrimSpace(str)
var result int = 0
for index, char := range []byte(str) {
result += EDOC[string(char)] * int(math.Pow(CODE_LENTH, float64(index)))
}
return result
}
func ToString(raw interface{}, e error) (res string) {
if e != nil {
return ""


+ 1
- 1
go.mod Vedi File

@@ -4,7 +4,7 @@ go 1.15

require (
code.fnuoos.com/go_rely_warehouse/zyos_go_es.git v1.0.1-0.20230707081910-52e70aa52998
code.fnuoos.com/go_rely_warehouse/zyos_go_third_party_api.git v1.1.21-0.20240731063657-03565dc21651
code.fnuoos.com/go_rely_warehouse/zyos_go_third_party_api.git v1.1.21-0.20241022083957-0babff5f367b
github.com/360EntSecGroup-Skylar/excelize v1.4.1
github.com/afex/hystrix-go v0.0.0-20180502004556-fa1af6a1f4f5
github.com/boombuler/barcode v1.0.1


Caricamento…
Annulla
Salva