|
- package svc
-
- import (
- "applet/app/db"
- "applet/app/db/model"
- offical "applet/app/db/official"
- "applet/app/utils"
- zhios_third_party_utils "code.fnuoos.com/go_rely_warehouse/zyos_go_third_party_api.git/utils"
- "encoding/json"
- "fmt"
- "github.com/tidwall/gjson"
- "strings"
- "time"
- )
-
- func KfcOrder() {
- pvdTimeKey := "kfc_time"
-
- // 获得最后时间
- timeStrData := offical.SysCfgByKey(pvdTimeKey)
- timeStr := ""
- if timeStrData == nil {
- offical.DbsSysCfgInserts(pvdTimeKey, time.Now().Format("2006-01-02"))
- timeStr = offical.SysCfgByKeyStr(pvdTimeKey)
- } else {
- timeStr = timeStrData.V
- }
- // 所有时间都是在操作秒数
- now := time.Now().Unix()
- strs := strings.Split(timeStr, ":")
- 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
- )
-
- //怕时间不是走最新的
- leave := now - past
- if leave > 500 {
- leave = 0
- }
- past = past + leave
- beginTime = past - 85000
- endTime = past
-
- if endTime > now {
- endTime = now
- }
- for {
- count := 0
- count, _ = OrdersKfcGet(pageNo, pageSize, beginTime, endTime)
- if count == 0 {
- goto ChkArg
- }
- // 判断是否分页已经全部取完了
- if count <= pageSize {
- pageNo++
- fmt.Println("========下一页========" + utils.IntToStr(pageNo))
- count = 0
- continue
- }
- ChkArg:
- // 查询完后重置时间, 最后查询时间
- 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
- }
- offical.DbsSysCfgUpdate(pvdTimeKey, utils.TimeToStr(endTime))
-
- }
-
- func OrdersKfcGet(p int, pageSize int, sTime, eTime int64) (int, string) {
- param := map[string]string{
- "updateTimeEndTime": time.Unix(eTime, 0).Format("2006-01-02 15:04:05"),
- "updateTimeBeginTime": time.Unix(sTime, 0).Format("2006-01-02 15:04:05"),
- "pageIndex": utils.IntToStr(p),
- "pageSize": utils.IntToStr(pageSize),
- "platformId": "10200",
- "timestamp": utils.Int64ToStr(time.Now().Unix()),
- }
- secret := "V4FNgCUoL2nWnyFS"
- str := ""
- strMap := zhios_third_party_utils.KsortToStr(param)
- for _, v := range strMap {
- if str == "" {
- str += v + "=" + param[v]
- } else {
- str += "&" + v + "=" + param[v]
- }
- }
- str += secret
- param["sign"] = zhios_third_party_utils.Md5(str)
- post, _ := utils.CurlPost("https://live.qianzhu8.com/openApi/v1/kfcOrders/pagedQuery", utils.SerializeStr(param), nil)
- var order = make([]map[string]interface{}, 0)
- json.Unmarshal([]byte(gjson.Get(string(post), "data").String()), &order)
- if len(order) == 0 {
- return 0, ""
- }
- count := len(order)
- for _, v := range order {
- commKfc(v)
- }
- return count, ""
- }
- func commKfc(data map[string]interface{}) error {
- if data["status"] == "0" {
- return nil
- }
- status_arr := map[string]string{"0": "创建订单", "5": "订单付款", "10": "订单完成", "15": "订单结算", "-5": "订单失效"}
- state := status_arr[utils.Int64ToStr(utils.AnyToInt64(data["status"]))]
- ex := strings.Split(utils.AnyToString(data["platformUniqueId"]), "_")
- if strings.Contains(utils.AnyToString(data["platformUniqueId"]), "zhiying") == false {
- return nil
- }
- var res = model.LifeOrder{
- PvdParentOid: utils.AnyToString(data["orderNo"]),
- Pvd: "kfc",
- Status: state,
- CreateTime: int(utils.TimeStdParseUnix(utils.AnyToString(data["createTime"]))),
- }
- res.Uid = utils.StrToInt(ex[3])
- res.StationUid = utils.StrToInt(ex[2])
- res.Oid = utils.StrToInt64(utils.OrderUUID(utils.StrToInt(ex[2])))
- res.PvdOid = utils.AnyToString(data["orderNo"])
- res.UpdateTime = int(time.Now().Unix())
- kfcPlaceOrder, ok := data["kfcPlaceOrder"].(map[string]interface{})
- if ok {
- res.Title = utils.AnyToString(kfcPlaceOrder["cityName"]) + "(" + utils.AnyToString(kfcPlaceOrder["storeName"]) + ")"
- }
- res.Gid = res.PvdOid
- res.Payment = utils.AnyToString(data["amount"])
- var commission = utils.AnyToString(data["commissionPrice"])
- res.Commission = commission
- res.RealCommission = commission
- one := db.GetLifeOrderByOne(res.PvdOid, utils.IntToStr(res.Uid), res.Pvd)
- if one == nil {
- insertOne, err := db.ZhimengDb.InsertOne(&res)
- fmt.Println(insertOne)
- fmt.Println(err)
- } else {
- res.SettleTime = one.SettleTime
- res.CreateTime = one.CreateTime
- if one.PlatformSettleTime > 0 {
- res.PlatformSettleTime = one.PlatformSettleTime
- }
- db.ZhimengDb.Where("id=?", one.Id).AllCols().Update(&res)
- }
- return nil
- }
|