|
|
@@ -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 |
|
|
|
} |