|
- package haiwei
-
- import (
- "code.fnuoos.com/EggPlanet/egg_models.git/src/implement"
- "code.fnuoos.com/EggPlanet/egg_models.git/src/model"
- utils "code.fnuoos.com/EggPlanet/egg_system_rules.git/utils"
- "encoding/json"
- "fmt"
- "github.com/syyongx/php2go"
- "github.com/tidwall/gjson"
- "strings"
- "time"
- "xorm.io/xorm"
- )
-
- func Hw365SendUrl(method string, extra, hwShareCode, hwSecret string) (string, error) {
- router := ""
- switch method {
- case "starbucks":
- router = "https://ot.jfshou.cn/sbkplus/auth/index"
- break
- case "movie":
- router = "https://ot.jfshou.cn/ticket/auth/index"
- break
- case "mcdonald":
- router = "https://ot.jfshou.cn/api/mcdonald/entrance"
- break
- case "nayuki":
- router = "https://ot.jfshou.cn/api/nayuki/entrance"
- break
- case "luckin":
- router = "https://ot.jfshou.cn/privilege-api/luckin/auth/index"
- break
- case "pizza":
- router = "https://ot.jfshou.cn/privilege-api/pizzaHut/auth/index"
- break
- case "pagoda":
- router = "https://ot.jfshou.cn/privilege-api/pagoda/auth/index"
- break
- case "burger_king":
- router = "https://ot.jfshou.cn/privilege-api/burgerKing/auth/index"
- break
- case "heytea":
- router = "https://ot.jfshou.cn/privilege-api/heytea/auth/index"
- break
- case "to_kfc":
- router = "https://ot.jfshou.cn/api/entrance"
- break
- case "wallace":
- router = "https://ot.jfshou.cn/privilege-api/wallace/auth/index0327"
- break
- case "flowerCake":
- router = "https://ot.jfshou.cn/privilege-api/flowerCake/auth/index"
- break
- case "delivery":
- router = "https://ot.jfshou.cn/privilege-api/express/delivery/auth/index"
- break
- case "tourism":
- router = "https://ot.jfshou.cn/privilege-api/tourism/auth/index"
- break
- case "near":
- router = "https://ot.jfshou.cn/api/index/entrance"
- break
- }
-
- param := map[string]string{
- "user_id": extra,
- "extra": extra,
- }
-
- param["share_code"] = hwShareCode
- param["timestamp"] = utils.Int64ToStr(time.Now().UnixNano() / 1e6)
- url := HwSend(router, param, hwSecret)
- return url, nil
- }
-
- func HwSend(url string, param map[string]string, secret string) string {
- sign := getSign(param, secret)
- param["sign"] = sign
- for k, v := range param {
- if v == "" {
- continue
- }
- if strings.Contains(url, "?") == false {
- url += "?" + k + "=" + php2go.URLEncode(v)
- } else {
- url += "&" + k + "=" + php2go.URLEncode(v)
- }
- }
- return url
- }
-
- func HwSendOrder(eg *xorm.Engine, hwShareCode, hwSecret, method string, p, timeType string, prd bool) int {
- endTime := time.Now().Unix()
- startTime := endTime - 86400
- param := 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": timeType,
- "page_number": p,
- "page_size": "50",
- }
- 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
- }
- param["share_code"] = hwShareCode
- param["timestamp"] = utils.Int64ToStr(time.Now().UnixNano() / 1e6)
- sign := getSign(param, hwSecret)
- param["sign"] = sign
- for k, v := range param {
- if v == "" {
- continue
- }
- if strings.Contains(router, "?") == false {
- router += "?" + k + "=" + php2go.URLEncode(v)
- } else {
- router += "&" + k + "=" + php2go.URLEncode(v)
- }
- }
- data, _ := utils.CurlGet(router, nil)
- order := gjson.Get(string(data), "data.list").String()
- if order == "" {
- order = gjson.Get(string(data), "data.order").String()
- }
- taskList := gjson.Get(string(data), "data.take_list").String()
-
- 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(eg, method, v, prd)
- }
- }
- if taskList != "" && taskList != "[]" {
- var list = make([]map[string]interface{}, 0)
- json.Unmarshal([]byte(taskList), &list)
- for _, v := range list {
- AddOrder(eg, method, v, prd)
- }
- }
- return count
- }
- func AddOrder(eg *xorm.Engine, method string, order map[string]interface{}, prd bool) {
-
- 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), "ddstar") == false {
- return
- }
- if strings.Contains(utils.AnyToString(userId), "dev") && prd {
- return
- }
- if strings.Contains(utils.AnyToString(userId), "prd") && prd == false {
- return
- }
-
- split := strings.Split(utils.AnyToString(userId), "_")
- uid := split[2]
- 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.LifeOrder{
- PvdOid: utils.AnyToString(order["order_no"]),
- GoodsTitle: utils.AnyToString(order["product_detail"]),
- Commission: utils.AnyToString(order["total_rebate"]),
- Platform: method,
- Uid: utils.StrToInt(uid),
- Payment: utils.AnyToString(order["settle_price"]),
- State: statusArr[utils.AnyToString(order["order_status"])],
- CreateAt: utils.TimeParseStd(utils.AnyToString(order["order_time"])),
- UpdateAt: time.Now(),
- }
- NewLifeOrderDb := implement.NewLifeOrderDb(eg)
- one, _ := NewLifeOrderDb.GetLifeOrder(ord.PvdOid)
- if one == nil {
- insertOne, err := eg.InsertOne(ord)
- fmt.Println(insertOne)
- fmt.Println(err)
- } else {
- ord.SettleAt = one.SettleAt
- eg.Where("id=?", one.Id).AllCols().Update(ord)
- }
- return
- }
-
- func getSign(param map[string]string, secret string) string {
- strMap := utils.KsortToStr(param)
- str := ""
- for _, v := range strMap {
- if v == "sign" || param[v] == "" {
- continue
- }
- str += utils.UderscoreToUpperCamelCase(v) + "=" + param[v] + "&"
- }
- str += "secretKey=" + secret
- return strings.ToUpper(php2go.Md5(str))
- }
|