|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185 |
- 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/hw"
- "encoding/json"
- "fmt"
- "strings"
- "time"
- )
-
- func HwLoop(method string) {
- all := offical.MasterListCfgGetKeyAll("hw_share_code")
- if all == nil {
- return
- }
- for _, v := range *all {
- if v.V == "" {
- continue
- }
- data := offical.MasterListCfgGetOneData(v.Uid, "hw_own_open")
- if data != "1" && utils.StrToInt(v.Uid) > 0 {
- continue
- }
- p := 1
- for true {
- count := GetHwOrder(p, method, v.Uid)
- if count < 50 {
- break
- }
- p++
- }
- }
-
- }
-
- func GetHwOrder(p int, method, uid string) int {
- hwShareCode := offical.MasterListCfgGetOneData(uid, "hw_share_code")
- hwSecret := offical.MasterListCfgGetOneData(uid, "hw_secret")
- router := ""
- switch method {
- case "starbucks":
- router = "https://ot.jfshou.cn/sbkplus/queryStarbucksOrder"
- break
- case "movie":
- router = "https://ot.jfshou.cn/ticket/query/order/list"
- break
- case "mcdonald":
- router = "https://ot.jfshou.cn/api/queryMcOrder"
- break
- case "nayuki":
- router = "https://ot.jfshou.cn/api/nayuki/order/queryOrdersByUser"
- break
- case "luckin":
- router = "https://ot.jfshou.cn/privilege-api/luckin/external/queryOrder"
- break
- case "pizza":
- router = "https://ot.jfshou.cn/privilege-api/pizzaHut/external/queryOrder"
- break
- case "pagoda":
- router = "https://ot.jfshou.cn/privilege-api/pagoda/external/queryOrder"
- break
- case "burger_king":
- router = "https://ot.jfshou.cn/privilege-api/burgerKing/external/queryOrder"
- break
- case "heytea":
- router = "https://ot.jfshou.cn/privilege-api/heytea/external/queryOrder"
- break
- case "to_kfc":
- router = "https://ot.jfshou.cn/api/queryOrder"
- break
- case "wallace":
- router = "https://ot.jfshou.cn/privilege-api/wallace/external/queryOrder"
- break
- case "flowerCake":
- router = "https://ot.jfshou.cn/privilege-api/flowercake/external/queryOrder"
- break
- case "delivery":
- router = "https://ot.jfshou.cn/privilege-api/expressDelivery/external/queryOrder"
- break
- case "tourism":
- router = "https://ot.jfshou.cn/privilege-api/tourism/external/queryOrder"
- break
- }
- endTime := time.Now().Unix()
- startTime := endTime - 86400
- params := map[string]string{
- "start_time": time.Unix(startTime, 0).Format("2006-01-02 15:04:05"),
- "end_time": time.Unix(endTime, 0).Format("2006-01-02 15:04:05"),
- "time_type": "1",
- "page_number": utils.IntToStr(p),
- "page_size": "50",
- }
- params["share_code"] = hwShareCode
- params["timestamp"] = utils.Int64ToStr(time.Now().UnixNano() / 1e6)
- order, takeList := hw.HwSendOrder(router, params, hwSecret)
- count := 0
- if order != "" && order != "[]" {
- var list = make([]map[string]interface{}, 0)
- json.Unmarshal([]byte(order), &list)
- count = len(list)
- for _, v := range list {
- AddOrder(method, v)
- }
- }
- if takeList != "" && takeList != "[]" {
- var list = make([]map[string]interface{}, 0)
- json.Unmarshal([]byte(takeList), &list)
- for _, v := range list {
- AddOrder(method, v)
- }
- }
- return count
- }
- func AddOrder(method string, order map[string]interface{}) {
-
- statusArr := map[string]string{"FINISHED": "订单成功", "GENERATE_SUCCESS": "订单成功", "WAIT_GENERATE": "订单付款", "WAIT_PAY": "创建订单", "CLOSED": "订单失效", "CANCELED": "订单失效", "FAIL": "订单失效", "CLOSE": "订单失效", "RETURNED": "订单失效", "UNPAID": "创建订单", "PAYED": "订单付款", "DEALING": "订单付款", "SENDING": "订单付款", "ORDER_RECEIVED": "订单付款", "RECEIVED": "订单成功", "RECEIVED_ORDER": "订单付款", "WAITING_RECEIVED": "订单付款", "WAIT_OUT_MEAL": "订单付款", "MAKING": "订单付款", "ARRIVED": "订单成功", "COMPLETE": "订单成功", "REFUNDED": "订单退款", "OUT_MEAL": "订单成功"}
- userId := order["extra"]
- if strings.Contains(utils.AnyToString(userId), "m") == false {
- return
- }
- isShare := 0
- if strings.Contains(utils.AnyToString(userId), "share") {
- isShare = 1
- userId = strings.ReplaceAll(utils.AnyToString(userId), "share", "")
- }
- split := strings.Split(utils.AnyToString(userId), "s")
- mid := strings.ReplaceAll(split[0], "m", "")
- splitSecond := strings.Split(split[1], "p")
- puid := splitSecond[1]
- uid := splitSecond[0]
-
- if utils.AnyToFloat64(order["total_rebate"]) == 0 {
- order["total_rebate"] = order["rebate"]
- }
- if (order["product_detail"] == nil || order["product_detail"] == "" || order["product_detail"] == "<nil>") && order["product_name"] != nil {
- order["product_detail"] = order["product_name"]
- }
- if (order["product_detail"] == nil || order["product_detail"] == "" || order["product_detail"] == "<nil>") && order["cinema_name"] != nil {
- order["product_detail"] = utils.AnyToString(order["cinema_name"]) + "-" + utils.AnyToString(order["movie_name"])
- }
- if (order["product_detail"] == nil || order["product_detail"] == "" || order["product_detail"] == "<nil>-<nil>" || order["product_detail"] == "<nil>") && order["delivery_brand_name"] != "" {
- order["product_detail"] = utils.AnyToString(order["delivery_brand_name"]) + "-" + utils.AnyToString(order["delivery_goods_name"])
- }
- var ord = &model.HwOrder{
- Oid: utils.AnyToString(order["order_no"]),
- Info: utils.AnyToString(order["product_detail"]),
- Commission: utils.AnyToFloat64(order["total_rebate"]),
- Type: method,
- TakePhoneNumber: utils.AnyToString(order["take_phone_number"]),
- RestaurantAddress: utils.AnyToString(order["restaurant_address"]),
- Uid: utils.StrToInt(mid),
- Payment: utils.AnyToFloat64(order["settle_price"]),
- Status: statusArr[utils.AnyToString(order["order_status"])],
- CreateTime: int(utils.TimeStdParseUnix(utils.AnyToString(order["order_time"]))),
- Data: utils.SerializeStr(order),
- UpdateTime: int(utils.TimeStdParseUnix(utils.AnyToString(order["modify_time"]))),
- Zuid: uid,
- Extra: utils.AnyToString(order["extra"]),
- Code: utils.AnyToString(order["code"]),
- UserId: utils.AnyToString(order["user_id"]),
- IsShare: isShare,
- OutMealTime: int(utils.TimeStdParseUnix(utils.AnyToString(order["out_meal_time"]))),
- ExtendUid: puid,
- }
- if order["modify_time"] == "" || order["modify_time"] == nil {
- ord.UpdateTime = int(time.Now().Unix())
- }
- if order["refund_time"] != "" && order["refund_time"] != nil {
- ord.RefundTime = int(utils.TimeStdParseUnix(utils.AnyToString(order["refund_time"])))
- }
- one := db.GetHwOrderByOne(ord.Oid, utils.IntToStr(ord.Uid), ord.Type)
- if one == nil {
- insertOne, err := db.ZhimengDb.InsertOne(ord)
- fmt.Println(insertOne)
- fmt.Println(err)
- } else {
- ord.SettleTime = one.SettleTime
- db.ZhimengDb.Where("id=?", one.Id).AllCols().Update(ord)
- }
- return
- }
|