|
|
@@ -0,0 +1,138 @@ |
|
|
|
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/md/csjp" |
|
|
|
"code.fnuoos.com/go_rely_warehouse/zyos_go_third_party_api.git/tik_tok" |
|
|
|
"fmt" |
|
|
|
"strings" |
|
|
|
"time" |
|
|
|
) |
|
|
|
|
|
|
|
func CsjpLocalLifeOrder() { |
|
|
|
|
|
|
|
p := "" |
|
|
|
for true { |
|
|
|
_, curor, hasMore := GetCsjpLocalLifeOrder(p) |
|
|
|
if hasMore == false { |
|
|
|
break |
|
|
|
} |
|
|
|
p = curor |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
func GetCsjpLocalLifeOrder(p string) (int, string, bool) { |
|
|
|
endTime := time.Now().Unix() |
|
|
|
startTime := endTime - 3600 |
|
|
|
tikTokCsjpAppId := offical.SysCfgByKeyStr("tik_tok_csjp_life_app_id") |
|
|
|
tikTokCsjpAppSecret := offical.SysCfgByKeyStr("tik_tok_csjp_life_app_secret") |
|
|
|
param := map[string]string{ |
|
|
|
"cursor": p, |
|
|
|
"count": "50", |
|
|
|
"update_time_begin": utils.Int64ToStr(startTime), |
|
|
|
"update_time_end": utils.Int64ToStr(endTime), |
|
|
|
} |
|
|
|
param["app_id"] = tikTokCsjpAppId |
|
|
|
param["app_secret"] = tikTokCsjpAppSecret |
|
|
|
data, cursor, hasMore := tik_tok.CsjpLifeGetOrder(param) |
|
|
|
count := 0 |
|
|
|
if data != nil { |
|
|
|
for _, v := range *data { |
|
|
|
AddCsjpLocalLifeOrder(v) |
|
|
|
} |
|
|
|
return count, utils.Int64ToStr(cursor), hasMore |
|
|
|
} |
|
|
|
return count, "", false |
|
|
|
} |
|
|
|
func AddCsjpLocalLifeOrder(order csjp.CsjpOrder) { |
|
|
|
|
|
|
|
statusArr := map[int]string{1: "订单付款", 2: "订单退款", 3: "订单成功", 4: "部分核销", 5: "部分退款"} |
|
|
|
userId := order.CommandExternalInfo |
|
|
|
isShare := 0 |
|
|
|
if strings.Contains(utils.AnyToString(userId), "s") { |
|
|
|
isShare = 1 |
|
|
|
} |
|
|
|
split := strings.Split(utils.AnyToString(userId), "_") |
|
|
|
if len(split) < 3 { |
|
|
|
return |
|
|
|
} |
|
|
|
mid := split[2] |
|
|
|
puid := "" |
|
|
|
if len(split) == 4 { |
|
|
|
puid = split[2] |
|
|
|
} |
|
|
|
uid := split[1] |
|
|
|
title := "" |
|
|
|
img := "" |
|
|
|
if len(order.ProductList) > 0 { |
|
|
|
title = order.ProductList[0].Name |
|
|
|
img = order.ProductList[0].Img |
|
|
|
} |
|
|
|
var ord = &model.GuideOrder{ |
|
|
|
Oid: utils.StrToInt64(utils.OrderUUID(utils.StrToInt(uid))), |
|
|
|
Uid: utils.StrToInt(mid), |
|
|
|
ExtendUid: utils.StrToInt(puid), |
|
|
|
StationUid: utils.StrToInt(uid), |
|
|
|
PvdOid: order.OrderId, |
|
|
|
PvdParentOid: order.RootOrderId, |
|
|
|
Status: statusArr[order.Status], |
|
|
|
CreateTime: order.PayTime, |
|
|
|
UpdateTime: int(time.Now().Unix()), |
|
|
|
Commission: utils.Float64ToStr(float64(order.CommissionAmount) / 100), |
|
|
|
Title: title, |
|
|
|
Payment: utils.Float64ToStr(float64(order.PayAmount) / 100), |
|
|
|
Pvd: "tikTok_life", |
|
|
|
Img: img, |
|
|
|
IsShare: isShare, |
|
|
|
} |
|
|
|
|
|
|
|
if order.SettleFinish || order.Status != 2 { |
|
|
|
var amount int64 = 0 |
|
|
|
isEnd := 1 |
|
|
|
var endTime int64 = 0 |
|
|
|
settleOrders, ok := order.SettleOrders.([]interface{}) |
|
|
|
if ok { |
|
|
|
for _, v := range settleOrders { |
|
|
|
tmp, ok := v.(map[string]interface{}) |
|
|
|
if ok == false || utils.AnyToInt64(tmp["status"]) < 3 { |
|
|
|
isEnd = 0 |
|
|
|
} |
|
|
|
if ok && utils.AnyToInt64(tmp["status"]) == 3 { |
|
|
|
endTime = utils.AnyToInt64(tmp["settle_time"]) |
|
|
|
amount += utils.AnyToInt64(tmp["settle_amount"]) |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
if ok == false || len(settleOrders) == 0 { |
|
|
|
isEnd = 0 |
|
|
|
} |
|
|
|
if isEnd == 1 { |
|
|
|
ord.Status = "订单结算" |
|
|
|
if order.Status == 5 { |
|
|
|
ord.Status = "部分结算" |
|
|
|
} |
|
|
|
ord.PlatformSettleTime = int(endTime) |
|
|
|
if ord.PlatformSettleTime == 0 { |
|
|
|
ord.PlatformSettleTime = ord.UpdateTime |
|
|
|
} |
|
|
|
ord.RealCommission = utils.Float64ToStr(float64(amount) / 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 |
|
|
|
} |
|
|
|
db.ZhimengDb.Where("id=?", one.Id).AllCols().Update(ord) |
|
|
|
} |
|
|
|
return |
|
|
|
} |