@@ -14,9 +14,11 @@ func GuideOrderList(c *gin.Context) { | |||||
return | return | ||||
} | } | ||||
platformMap := map[string]string{ | platformMap := map[string]string{ | ||||
"tikTok_life": "抖音本地生活", | |||||
"csjp": "穿山甲抖音", | |||||
"csjp_live": "穿山甲抖音直播商品", | |||||
"tikTok_life": "抖音本地生活", | |||||
"csjp": "穿山甲抖音", | |||||
"csjp_live": "穿山甲抖音直播商品", | |||||
"kuaishou": "快手", | |||||
"kuaishou_live": "快手直播商品", | |||||
} | } | ||||
data, total := platform.GuideOrderList(c, args) | data, total := platform.GuideOrderList(c, args) | ||||
@@ -13,9 +13,11 @@ func GuideOrderList(c *gin.Context, args map[string]string) ([]map[string]string | |||||
list, total := db.GetGuideOrderListTotal(args) | list, total := db.GetGuideOrderListTotal(args) | ||||
var data = make([]map[string]string, 0) | var data = make([]map[string]string, 0) | ||||
platformMap := map[string]string{ | platformMap := map[string]string{ | ||||
"tikTok_life": "抖音本地生活", | |||||
"csjp": "穿山甲抖音", | |||||
"csjp_live": "穿山甲抖音直播商品", | |||||
"tikTok_life": "抖音本地生活", | |||||
"csjp": "穿山甲抖音", | |||||
"csjp_live": "穿山甲抖音直播商品", | |||||
"kuaishou": "快手", | |||||
"kuaishou_live": "快手直播商品", | |||||
} | } | ||||
if len(list) > 0 { | if len(list) > 0 { | ||||
for _, v := range list { | for _, v := range list { | ||||
@@ -72,9 +74,11 @@ func GuideOrderOutput(c *gin.Context, args map[string]string) (string, map[strin | |||||
"I1": "实际佣金", | "I1": "实际佣金", | ||||
} | } | ||||
platformMap := map[string]string{ | platformMap := map[string]string{ | ||||
"tikTok_life": "抖音本地生活", | |||||
"csjp": "穿山甲抖音", | |||||
"csjp_live": "穿山甲抖音直播商品", | |||||
"tikTok_life": "抖音本地生活", | |||||
"csjp": "穿山甲抖音", | |||||
"csjp_live": "穿山甲抖音直播商品", | |||||
"kuaishou": "快手", | |||||
"kuaishou_live": "快手直播商品", | |||||
} | } | ||||
list, _ := db.GetGuideOrderListTotal(args) | list, _ := db.GetGuideOrderListTotal(args) | ||||
@@ -85,7 +85,6 @@ func doTask(fnName string) func() { | |||||
func initTasks() { | func initTasks() { | ||||
jobs[taskMd.ZhimengCronPLayletBihaiOrder] = taskPlayletBihaiOrder // | jobs[taskMd.ZhimengCronPLayletBihaiOrder] = taskPlayletBihaiOrder // | ||||
//jobs[taskMd.ZhimengCronCinema5bms] = taskCinema5bms // | |||||
jobs[taskMd.ZhimengCronCinema5bmsOrder] = taskCinema5bmsOrder // | jobs[taskMd.ZhimengCronCinema5bmsOrder] = taskCinema5bmsOrder // | ||||
jobs[taskMd.ZhimengCronCinema5bmsYesterOrder] = taskCinema5bmsYesterOrder // | jobs[taskMd.ZhimengCronCinema5bmsYesterOrder] = taskCinema5bmsYesterOrder // | ||||
@@ -93,19 +92,11 @@ func initTasks() { | |||||
jobs[taskMd.ZhimengCronTikTokCsjpActivity] = taskTikTokCsjpActivity // | jobs[taskMd.ZhimengCronTikTokCsjpActivity] = taskTikTokCsjpActivity // | ||||
jobs[taskMd.ZhimengCronTikTokCsjpLive] = taskTikTokCsjpLive // | jobs[taskMd.ZhimengCronTikTokCsjpLive] = taskTikTokCsjpLive // | ||||
jobs[taskMd.ZhimengCronTikTokTask] = taskTikTokTask // | |||||
jobs[taskMd.ZhimengCronTikTokTaskRelate] = taskTikTokTaskRelate // | |||||
jobs[taskMd.ZhimengCronTikTokTaskMoney] = taskTikTokTaskMoney // | |||||
jobs[taskMd.ZhimengCronTikTokTaskMoneyByYestday] = taskTikTokTaskMoneyByYestday // | |||||
jobs[taskMd.ZhimengCronDianzhongKuaishouMoney] = taskDianzhongKuaishouMoney // | |||||
//jobs[taskMd.ZhimengCronPlayletVideoOrder] = taskPlayletVideoOrder // | |||||
//jobs[taskMd.ZhimengCronPlayletVideoOrderYesterDay] = taskPlayletVideoOrderYesterday // | |||||
//jobs[taskMd.ZhimengCronPlayletVideoOrderMonth] = taskPlayletVideoOrderMonth // | |||||
//jobs[taskMd.ZhimengCronPlayletAdvOrderMonth] = taskPlayletAdvOrderMonth // | |||||
//jobs[taskMd.ZhimengCronPlayletAdvOrder] = taskPlayletAdvOrder // | |||||
//jobs[taskMd.ZhimengCronPlayletAdvOrderYesterDay] = taskPlayletAdvOrderYesterday // | |||||
//jobs[taskMd.ZhimengCronPlayletAdvOrderYesterDayToMoney] = taskPlayletAdvOrderYesterdayToMoney // | |||||
//jobs[taskMd.ZhimengCronPlayletGoods] = taskPlayletGoods // | |||||
jobs[taskMd.ZhimengCronTikTokTask] = taskTikTokTask // | |||||
jobs[taskMd.ZhimengCronTikTokTaskRelate] = taskTikTokTaskRelate // | |||||
jobs[taskMd.ZhimengCronTikTokTaskMoney] = taskTikTokTaskMoney // | |||||
jobs[taskMd.ZhimengCronTikTokTaskMoneyByYestday] = taskTikTokTaskMoneyByYestday // | |||||
jobs[taskMd.ZhimengCronDianzhongKuaishouMoney] = taskDianzhongKuaishouMoney // | |||||
jobs[taskMd.ZhimengCronPlayletOrderSettle] = taskPlayletOrderSettle // | jobs[taskMd.ZhimengCronPlayletOrderSettle] = taskPlayletOrderSettle // | ||||
jobs[taskMd.ZhimengCronHwOrderSettle] = taskHwOrderSettle // | jobs[taskMd.ZhimengCronHwOrderSettle] = taskHwOrderSettle // | ||||
jobs[taskMd.ZhimengCronMasterMonthSettle] = taskMasterMonthSettle // | jobs[taskMd.ZhimengCronMasterMonthSettle] = taskMasterMonthSettle // | ||||
@@ -125,5 +116,7 @@ func initTasks() { | |||||
jobs[taskMd.ZhimengCronHwTourismOrder] = taskHwTourismOrder // | jobs[taskMd.ZhimengCronHwTourismOrder] = taskHwTourismOrder // | ||||
jobs[taskMd.ZhimengCronTikTokLocalLifeOrder] = taskTikTokLocalLifeOrder // | jobs[taskMd.ZhimengCronTikTokLocalLifeOrder] = taskTikTokLocalLifeOrder // | ||||
jobs[taskMd.ZhimengCronTikTokLocalLifeOrderSettle] = taskTikTokLocalLifeOrderSettle // | jobs[taskMd.ZhimengCronTikTokLocalLifeOrderSettle] = taskTikTokLocalLifeOrderSettle // | ||||
jobs[taskMd.ZhimengCronKuaishouOrder] = taskKuaishouOrder // | |||||
jobs[taskMd.ZhimengCronKuaishouAuth] = taskKuaishouAuth // | |||||
} | } |
@@ -39,6 +39,8 @@ const ( | |||||
ZhimengCronHwFlowerCakeOrder = "zhimeng_cron_hw_flowerCake_order" | ZhimengCronHwFlowerCakeOrder = "zhimeng_cron_hw_flowerCake_order" | ||||
ZhimengCronHwDeliveryOrder = "zhimeng_cron_hw_delivery_order" | ZhimengCronHwDeliveryOrder = "zhimeng_cron_hw_delivery_order" | ||||
ZhimengCronHwTourismOrder = "zhimeng_cron_hw_tourism_order" | ZhimengCronHwTourismOrder = "zhimeng_cron_hw_tourism_order" | ||||
ZhimengCronKuaishouOrder = "zhimeng_cron_kuaishou_order" | |||||
ZhimengCronKuaishouAuth = "zhimeng_cron_kuaishou_auth" | |||||
ZhimengCronTikTokLocalLifeOrder = "zhimeng_cron_tik_tok_local_life_order" | ZhimengCronTikTokLocalLifeOrder = "zhimeng_cron_tik_tok_local_life_order" | ||||
ZhimengCronTikTokLocalLifeOrderSettle = "zhimeng_cron_tik_tok_local_life_order_settle" | ZhimengCronTikTokLocalLifeOrderSettle = "zhimeng_cron_tik_tok_local_life_order_settle" | ||||
) | ) |
@@ -0,0 +1,45 @@ | |||||
package svc | |||||
import ( | |||||
"applet/app/db" | |||||
offical "applet/app/db/official" | |||||
"applet/app/utils" | |||||
"code.fnuoos.com/go_rely_warehouse/zyos_go_third_party_api.git/kuaishou" | |||||
"github.com/tidwall/gjson" | |||||
"time" | |||||
) | |||||
func KuaishouAuth() { | |||||
kuaishouAppkey := offical.MasterListCfgGetOneData("0", "kuaishou_kfx_appkey") | |||||
kuaishouAppSecret := offical.MasterListCfgGetOneData("0", "kuaishou_kfx_app_secret") | |||||
kuaishou_official_expires_in := db.MasterListCfgGetOneData("0", "kuaishou_official_expires_in") | |||||
kuaishou_official_refresh_token := db.MasterListCfgGetOneData("0", "kuaishou_official_refresh_token") | |||||
if utils.StrToInt64(kuaishou_official_expires_in) < time.Now().Unix() { | |||||
args := map[string]string{ | |||||
"app_id": kuaishouAppkey, | |||||
"grant_type": "refresh_token", | |||||
"refresh_token": kuaishou_official_refresh_token, | |||||
"app_secret": kuaishouAppSecret, | |||||
} | |||||
token, _ := kuaishou.GetKuaishouRefreshToken(args) | |||||
if token == "" { | |||||
return | |||||
} | |||||
accessToken := gjson.Get(token, "access_token").String() | |||||
if accessToken == "" { | |||||
return | |||||
} | |||||
teamAccessRefreshToken := gjson.Get(token, "refresh_token").String() | |||||
teamAccessTime := time.Now().Unix() + gjson.Get(token, "expires_in").Int() - 60 | |||||
db.MasterListCfgSave("0", "kuaishou_official_access_token", accessToken) | |||||
db.MasterListCfgSave("0", "kuaishou_official_expires_in", utils.Int64ToStr(teamAccessTime)) | |||||
db.MasterListCfgSave("0", "kuaishou_official_refresh_token", teamAccessRefreshToken) | |||||
args1 := map[string]interface{}{ | |||||
"accessToken": accessToken, | |||||
"teamAccessTime": utils.Int64ToStr(teamAccessTime), | |||||
"teamAccessRefreshToken": teamAccessRefreshToken, | |||||
} | |||||
utils.CurlPost("http://izhim.com/?mod=api&act=kuaishou&ctrl=auth", args1, nil) | |||||
} | |||||
} |
@@ -0,0 +1,231 @@ | |||||
package svc | |||||
import ( | |||||
"applet/app/db" | |||||
"applet/app/db/model" | |||||
offical "applet/app/db/official" | |||||
"applet/app/utils" | |||||
"code.fnuoos.com/go_rely_warehouse/zyos_go_third_party_api.git/kuaishou" | |||||
"code.fnuoos.com/go_rely_warehouse/zyos_go_third_party_api.git/md" | |||||
"encoding/json" | |||||
"fmt" | |||||
"github.com/tidwall/gjson" | |||||
"strings" | |||||
"time" | |||||
) | |||||
func KuaishouOrder() { | |||||
pvdTimeKey := "kuaishou_time" | |||||
// 获得最后时间 | |||||
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 | |||||
} | |||||
var ( | |||||
beginTime int64 = 0 | |||||
endTime int64 = 0 | |||||
pageNo int = 1 | |||||
pageSize int = 50 | |||||
nextPositionIndex string = "" | |||||
) | |||||
//怕时间不是走最新的 | |||||
leave := now - past | |||||
if leave > 500 { | |||||
leave = 0 | |||||
} | |||||
past = past + leave | |||||
beginTime = past - 300 | |||||
endTime = past | |||||
if endTime > now { | |||||
endTime = now | |||||
} | |||||
for { | |||||
count := 0 | |||||
var positionIndex = "" | |||||
if pageNo == 1 { | |||||
nextPositionIndex = "0" | |||||
} | |||||
if nextPositionIndex != "" { | |||||
count, positionIndex = OrdersKuaishouGet(nextPositionIndex, pageSize, beginTime, endTime, "update", 0) | |||||
} | |||||
if count == 0 { | |||||
nextPositionIndex = "" | |||||
goto ChkArg | |||||
} | |||||
// 判断是否分页已经全部取完了 | |||||
if count <= pageSize { | |||||
nextPositionIndex = positionIndex | |||||
pageNo++ | |||||
fmt.Println("========下一页========" + utils.IntToStr(pageNo)) | |||||
count = 0 | |||||
continue | |||||
} | |||||
ChkArg: | |||||
nextPositionIndex = "" | |||||
// 查询完后重置时间, 最后查询时间 | |||||
if endTime < now { | |||||
pageNo = 1 | |||||
offical.DbsSysCfgUpdate(pvdTimeKey, utils.TimeToStr(endTime)) | |||||
beginTime = endTime | |||||
endTime = endTime + 300 | |||||
if endTime > now { | |||||
endTime = now | |||||
} | |||||
count = 0 | |||||
continue | |||||
} | |||||
count = 0 | |||||
break | |||||
} | |||||
} | |||||
func OrdersKuaishouGet(nextPositionIndex string, pageSize int, sTime, eTime int64, timeType string, pvd int) (int, string) { | |||||
arg := map[string]interface{}{ | |||||
"cpsOrderStatus": 0, | |||||
"pageSize": pageSize, | |||||
"sortType": 2, //排序类型 [1:按指定查询类型降序] [2:按指定查询类型升序] | |||||
"queryType": 2, //查询类型 [1:按分销订单创建时间查询] [2:按分销订单更新时间查询] | |||||
"beginTime": time.Unix(sTime, 0).Unix() * 1000, | |||||
"endTime": time.Unix(eTime, 0).Unix() * 1000, | |||||
"pcursor": nextPositionIndex, | |||||
} | |||||
param, kuaishouData := GetKuaishouKey() | |||||
param["param"] = utils.SerializeStr(arg) | |||||
data, err := kuaishou.GetKuishouCpsOrder(kuaishouData["sign_secret"], param) | |||||
goods := gjson.Get(data, "data.orderList").String() | |||||
newPcursor := gjson.Get(data, "data.pcursor").String() | |||||
if goods == "" || err != nil { | |||||
return 0, "" | |||||
} | |||||
var list = make([]md.KuaishouCpsOrder, 0) | |||||
err = json.Unmarshal([]byte(goods), &list) | |||||
if err != nil { | |||||
return 0, "" | |||||
} | |||||
var kuaishouState = map[int]string{ | |||||
30: "订单付款", | |||||
50: "订单完成", | |||||
80: "订单失效", | |||||
60: "订单结算", | |||||
} | |||||
for _, v := range list { | |||||
var res = model.GuideOrder{ | |||||
PvdParentOid: utils.IntToStr(v.Oid), | |||||
Pvd: "kuaishou", | |||||
Status: kuaishouState[v.CpsOrderStatus], | |||||
CreateTime: v.OrderCreateTime / 1000, | |||||
} | |||||
if v.SettlementSuccessTime > 0 { | |||||
res.PlatformSettleTime = int(v.SettlementSuccessTime / 1000) | |||||
} | |||||
for _, v1 := range v.CpsKwaimoneyOrderProductView { | |||||
resNew := res | |||||
if v1.CpsType == 3 { | |||||
resNew.Pvd = "kuaishou_live" | |||||
} | |||||
if strings.Contains(v1.Comments, "official_") == false { | |||||
continue | |||||
} | |||||
v1.Comments = strings.ReplaceAll(v1.Comments, "official_", "") | |||||
ex := strings.Split(v1.Comments, "_") | |||||
if len(ex) < 3 { | |||||
continue | |||||
} | |||||
orderType := 0 | |||||
if ex[0] == "s" { | |||||
orderType = 1 | |||||
} | |||||
// 判断免单 | |||||
if ex[0] == "f" { | |||||
orderType = 2 | |||||
} | |||||
if ex[0] == "cloud" { | |||||
orderType = 10 | |||||
} | |||||
if ex[0] == "sef" { | |||||
orderType = 11 | |||||
} | |||||
if ex[0] == "shareSeFree" { | |||||
orderType = 12 | |||||
} | |||||
if ex[0] == "moref" { | |||||
orderType = 13 | |||||
} | |||||
resNew.Oid = utils.StrToInt64(utils.OrderUUID(utils.StrToInt(ex[1]))) | |||||
resNew.PvdOid = utils.IntToStr(v1.Oid) | |||||
resNew.Uid = utils.StrToInt(ex[2]) | |||||
resNew.StationUid = utils.StrToInt(ex[1]) | |||||
resNew.UpdateTime = int(time.Now().Unix()) | |||||
resNew.Commission = utils.Float64ToStr(float64(v1.EstimatedIncome) / 100) | |||||
resNew.RealCommission = utils.Float64ToStr(float64(v1.EstimatedIncome) / 100) | |||||
resNew.Title = v1.ItemTitle | |||||
resNew.Img = v1.ItemPicUrl | |||||
resNew.Gid = utils.IntToStr(v1.ItemId) | |||||
resNew.IsShare = orderType | |||||
resNew.Payment = utils.Float64ToStr(float64(v1.PaymentFee) / 100) | |||||
one := db.GetGuideOrderByOne(resNew.PvdOid, utils.IntToStr(resNew.Uid), resNew.Pvd) | |||||
if one == nil { | |||||
insertOne, err := db.ZhimengDb.InsertOne(&resNew) | |||||
fmt.Println(insertOne) | |||||
fmt.Println(err) | |||||
} else { | |||||
resNew.SettleTime = one.SettleTime | |||||
if one.PlatformSettleTime > 0 { | |||||
resNew.PlatformSettleTime = one.PlatformSettleTime | |||||
} | |||||
db.ZhimengDb.Where("id=?", one.Id).AllCols().Update(&resNew) | |||||
} | |||||
} | |||||
} | |||||
return len(list), newPcursor | |||||
} | |||||
func GetKuaishouKey() (map[string]string, map[string]string) { | |||||
kuaishouData := CommKuaishou() | |||||
param := map[string]string{ | |||||
"appkey": kuaishouData["appkey"], | |||||
"access_token": kuaishouData["token"], | |||||
} | |||||
return param, kuaishouData | |||||
} | |||||
func CommKuaishou() map[string]string { | |||||
res := OfficialCommKuaishou() | |||||
return res | |||||
} | |||||
func OfficialCommKuaishou() map[string]string { | |||||
kuaishouAppkey := offical.MasterListCfgGetOneData("0", "kuaishou_kfx_appkey") | |||||
kuaishouAppSecret := offical.MasterListCfgGetOneData("0", "kuaishou_kfx_app_secret") | |||||
kuaishouSignSecret := offical.MasterListCfgGetOneData("0", "kuaishou_kfx_sign_secret") | |||||
authType := "0" | |||||
kuaishouToken := db.MasterListCfgGetOneData("0", "kuaishou_official_access_token") | |||||
kuaishouPid := offical.MasterListCfgGetOneData("0", "kuaishou_official_pid") | |||||
res := map[string]string{ | |||||
"pid": kuaishouPid, | |||||
"authType": authType, | |||||
"appkey": kuaishouAppkey, | |||||
"token": kuaishouToken, | |||||
"app_secret": kuaishouAppSecret, | |||||
"sign_secret": kuaishouSignSecret, | |||||
} | |||||
return res | |||||
} |
@@ -31,9 +31,11 @@ func TikTokLocalLifeOrderSettle() { | |||||
} | } | ||||
fmt.Println(utils.SerializeStr(order)) | fmt.Println(utils.SerializeStr(order)) | ||||
platformMap := map[string]string{ | platformMap := map[string]string{ | ||||
"tikTok_life": "抖音本地生活", | |||||
"csjp": "穿山甲抖音", | |||||
"csjp_live": "穿山甲抖音直播商品", | |||||
"tikTok_life": "抖音本地生活", | |||||
"csjp": "穿山甲抖音", | |||||
"csjp_live": "穿山甲抖音直播商品", | |||||
"kuaishou": "快手", | |||||
"kuaishou_live": "快手直播商品", | |||||
} | } | ||||
for _, v := range order { | for _, v := range order { | ||||
fmt.Println("=================00") | fmt.Println("=================00") | ||||
@@ -0,0 +1,21 @@ | |||||
package task | |||||
import ( | |||||
"applet/app/task/svc" | |||||
"math/rand" | |||||
"time" | |||||
) | |||||
func taskKuaishouAuth() { | |||||
for { | |||||
if len(ch) > workerNum { | |||||
time.Sleep(time.Millisecond * time.Duration(rand.Intn(1000))) | |||||
} else { | |||||
goto START | |||||
} | |||||
} | |||||
START: | |||||
ch <- 1 | |||||
svc.KuaishouAuth() | |||||
<-ch | |||||
} |
@@ -0,0 +1,21 @@ | |||||
package task | |||||
import ( | |||||
"applet/app/task/svc" | |||||
"math/rand" | |||||
"time" | |||||
) | |||||
func taskKuaishouOrder() { | |||||
for { | |||||
if len(ch) > workerNum { | |||||
time.Sleep(time.Millisecond * time.Duration(rand.Intn(1000))) | |||||
} else { | |||||
goto START | |||||
} | |||||
} | |||||
START: | |||||
ch <- 1 | |||||
svc.KuaishouOrder() | |||||
<-ch | |||||
} |