@@ -15,6 +15,8 @@ var SettlePvd = map[string]string{ | |||
"own_oilstation": "加油", | |||
"own_king_flower": "花小猪打车", | |||
"xiaoju": "加油", | |||
"cinema": "电影票", | |||
"kfc": "肯德基", | |||
} | |||
var LifeSettlePvd = map[string]string{ | |||
"meituan": "美团", | |||
@@ -26,4 +28,6 @@ var LifeSettlePvd = map[string]string{ | |||
"xiaoju": "加油", | |||
"own_oilstation": "加油", | |||
"own_king_flower": "花小猪打车", | |||
"cinema": "电影票", | |||
"kfc": "肯德基", | |||
} |
@@ -134,5 +134,7 @@ func initTasks() { | |||
jobs[taskMd.ZhimengCronOilOrder] = taskOilOrder //加油订单 | |||
jobs[taskMd.ZhimengCronPayLifeOrderSettle] = taskPayLifeOrderSettle // | |||
jobs[taskMd.ZhimengCronHwRechargeOrder] = taskHwRechargeOrder //加油订单 | |||
jobs[taskMd.ZhimengCronMovieOrder] = taskMovieOrder //加油订单 | |||
jobs[taskMd.ZhimengCronKfcOrder] = taskKfcOrder //加油订单 | |||
} |
@@ -57,5 +57,7 @@ const ( | |||
ZhimengCronPayLifeOrderSettle = "zhimeng_cron_pay_life_order_settle" | |||
ZhimengCronOilAddEs = "zhimeng_cron_oil_add_es" | |||
ZhimengCronOilOrder = "zhimeng_cron_oil_order" | |||
ZhimengCronMovieOrder = "zhimeng_cron_movie_order" | |||
ZhimengCronKfcOrder = "zhimeng_cron_kfc_order" | |||
ZhimengCronHwRechargeOrder = "zhimeng_cron_hw_recharge_order" | |||
) |
@@ -0,0 +1,169 @@ | |||
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 | |||
} |
@@ -0,0 +1,166 @@ | |||
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 MovieOrder() { | |||
pvdTimeKey := "movie_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, _ = OrdersMovieGet(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 OrdersMovieGet(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/api/v1/platform/movieOrder/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 { | |||
commMovie(v) | |||
} | |||
return count, "" | |||
} | |||
func commMovie(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: "cinema", | |||
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()) | |||
res.Title = utils.AnyToString(data["filmName"]) + "(" + utils.AnyToString(data["seatsDesc"]) + ")" | |||
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 | |||
} |
@@ -0,0 +1,21 @@ | |||
package task | |||
import ( | |||
"applet/app/task/svc" | |||
"math/rand" | |||
"time" | |||
) | |||
func taskKfcOrder() { | |||
for { | |||
if len(ch) > workerNum { | |||
time.Sleep(time.Millisecond * time.Duration(rand.Intn(1000))) | |||
} else { | |||
goto START | |||
} | |||
} | |||
START: | |||
ch <- 1 | |||
svc.KfcOrder() | |||
<-ch | |||
} |
@@ -0,0 +1,21 @@ | |||
package task | |||
import ( | |||
"applet/app/task/svc" | |||
"math/rand" | |||
"time" | |||
) | |||
func taskMovieOrder() { | |||
for { | |||
if len(ch) > workerNum { | |||
time.Sleep(time.Millisecond * time.Duration(rand.Intn(1000))) | |||
} else { | |||
goto START | |||
} | |||
} | |||
START: | |||
ch <- 1 | |||
svc.MovieOrder() | |||
<-ch | |||
} |