|
|
@@ -0,0 +1,123 @@ |
|
|
|
package svc |
|
|
|
|
|
|
|
import ( |
|
|
|
"applet/app/cfg" |
|
|
|
"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/thirdParty/ali1688" |
|
|
|
"fmt" |
|
|
|
"github.com/tidwall/gjson" |
|
|
|
"strings" |
|
|
|
"time" |
|
|
|
) |
|
|
|
|
|
|
|
func Ali1688Order(timeType string) { |
|
|
|
var ( |
|
|
|
beginTime int64 = 0 |
|
|
|
endTime int64 = 0 |
|
|
|
pageNo int = 1 |
|
|
|
pageSize int = 50 |
|
|
|
) |
|
|
|
today := utils.GetTimeRange("today") |
|
|
|
beginTime = today["start"] |
|
|
|
endTime = today["end"] |
|
|
|
unionData := offical.SysCfgByKeyStr("ali1688_data") |
|
|
|
for { |
|
|
|
count := 0 |
|
|
|
count, _ = OrdersAli1688Get(pageNo, pageSize, beginTime, endTime, timeType, 1, unionData) |
|
|
|
if count == 0 { |
|
|
|
break |
|
|
|
} |
|
|
|
// 判断是否分页已经全部取完了 |
|
|
|
if count <= pageSize { |
|
|
|
pageNo++ |
|
|
|
fmt.Println("========下一页========" + utils.IntToStr(pageNo)) |
|
|
|
count = 0 |
|
|
|
continue |
|
|
|
} |
|
|
|
} |
|
|
|
return |
|
|
|
} |
|
|
|
|
|
|
|
func OrdersAli1688Get(p int, pageSize int, sTime, eTime int64, timeType string, pvd int, unionData string) (int, string) { |
|
|
|
args := map[string]string{ |
|
|
|
"queryOrderType": "orderAll", |
|
|
|
"queryStartTime": time.Unix(sTime, 0).Format("2006-01-02"), |
|
|
|
"queryEndTime": time.Unix(eTime, 0).Format("2006-01-02"), |
|
|
|
"pageNo": utils.IntToStr(p), |
|
|
|
"pageSize": utils.IntToStr(pageSize), |
|
|
|
"queryTimeType": timeType, |
|
|
|
} |
|
|
|
key := gjson.Get(unionData, "key").String() |
|
|
|
secret := gjson.Get(unionData, "secret").String() |
|
|
|
token := gjson.Get(unionData, "token").String() |
|
|
|
order := ali1688.AliGoodsOrder(key, secret, token, args) |
|
|
|
if order == nil || len(order) == 0 { |
|
|
|
return 0, "" |
|
|
|
} |
|
|
|
count := len(order) |
|
|
|
stateArr := map[int]string{ |
|
|
|
20: "订单付款", |
|
|
|
50: "订单完成", |
|
|
|
80: "订单失败", |
|
|
|
} |
|
|
|
for _, v := range order { |
|
|
|
if v.OrderState == 10 { |
|
|
|
continue |
|
|
|
} |
|
|
|
status := stateArr[v.OrderState] |
|
|
|
ex := strings.Split(v.Ext, "_") |
|
|
|
if strings.Contains(utils.AnyToString(v.Ext), "zhiying") == false { |
|
|
|
continue |
|
|
|
} |
|
|
|
if strings.Contains(utils.AnyToString(v.Ext), "dev") && cfg.Prd { |
|
|
|
continue |
|
|
|
} |
|
|
|
if strings.Contains(utils.AnyToString(v.Ext), "prd") && cfg.Prd == false { |
|
|
|
continue |
|
|
|
} |
|
|
|
var ord = &model.GuideOrder{ |
|
|
|
Oid: utils.StrToInt64(utils.OrderUUID(utils.StrToInt(ex[3]))), |
|
|
|
Uid: utils.StrToInt(ex[2]), |
|
|
|
StationUid: utils.StrToInt(ex[3]), |
|
|
|
PvdOid: utils.Int64ToStr(v.BizSubId), |
|
|
|
Status: status, |
|
|
|
UpdateTime: int(time.Now().Unix()), |
|
|
|
Title: utils.AnyToString(v.Name), |
|
|
|
Payment: utils.Float64ToStr(v.TradeAmount), |
|
|
|
Pvd: "ali1688", |
|
|
|
IsShare: utils.StrToInt(ex[4]), |
|
|
|
ThreeType: "ali1688", |
|
|
|
PvdParentOid: utils.Int64ToStr(v.BizId), |
|
|
|
CreateTime: int(utils.TimeStdParseUnix(v.CreateTime)), |
|
|
|
} |
|
|
|
if v.SettleState == 1 { |
|
|
|
ord.Status = "订单结算" |
|
|
|
ord.PlatformSettleTime = int(utils.TimeStdParseUnix(v.SettleTime)) |
|
|
|
} |
|
|
|
if v.RightsState == 30 { |
|
|
|
ord.Status = "订单失败" |
|
|
|
} |
|
|
|
ord.Commission = utils.Float64ToStr(v.Commission) |
|
|
|
ord.RealCommission = utils.Float64ToStr(v.Commission) |
|
|
|
one := db.GetGuideOrderByOid(utils.AnyToString(v.BizSubId), "ali1688") |
|
|
|
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 == "违规订单" { |
|
|
|
ord.Status = "违规订单" |
|
|
|
} |
|
|
|
db.ZhimengDb.Where("id=?", one.Id).AllCols().Update(ord) |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
return count, "" |
|
|
|
} |