智盟项目
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

svc_hw_order.go 6.5 KiB

1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  1. package svc
  2. import (
  3. "applet/app/db"
  4. "applet/app/db/model"
  5. offical "applet/app/db/official"
  6. "applet/app/utils"
  7. "code.fnuoos.com/go_rely_warehouse/zyos_go_third_party_api.git/hw"
  8. "encoding/json"
  9. "fmt"
  10. "strings"
  11. "time"
  12. )
  13. func HwLoop(method string) {
  14. all := offical.MasterListCfgGetKeyAll("hw_share_code")
  15. if all == nil {
  16. return
  17. }
  18. for _, v := range *all {
  19. if v.V == "" {
  20. continue
  21. }
  22. data := offical.MasterListCfgGetOneData(v.Uid, "hw_own_open")
  23. if data != "1" && utils.StrToInt(v.Uid) > 0 {
  24. continue
  25. }
  26. p := 1
  27. for true {
  28. count := GetHwOrder(p, method, v.Uid)
  29. if count < 50 {
  30. break
  31. }
  32. p++
  33. }
  34. }
  35. }
  36. func GetHwOrder(p int, method, uid string) int {
  37. hwShareCode := offical.MasterListCfgGetOneData(uid, "hw_share_code")
  38. hwSecret := offical.MasterListCfgGetOneData(uid, "hw_secret")
  39. router := ""
  40. switch method {
  41. case "starbucks":
  42. router = "https://ot.jfshou.cn/sbkplus/queryStarbucksOrder"
  43. break
  44. case "movie":
  45. router = "https://ot.jfshou.cn/ticket/query/order/list"
  46. break
  47. case "mcdonald":
  48. router = "https://ot.jfshou.cn/api/queryMcOrder"
  49. break
  50. case "nayuki":
  51. router = "https://ot.jfshou.cn/api/nayuki/order/queryOrdersByUser"
  52. break
  53. case "luckin":
  54. router = "https://ot.jfshou.cn/privilege-api/luckin/external/queryOrder"
  55. break
  56. case "pizza":
  57. router = "https://ot.jfshou.cn/privilege-api/pizzaHut/external/queryOrder"
  58. break
  59. case "pagoda":
  60. router = "https://ot.jfshou.cn/privilege-api/pagoda/external/queryOrder"
  61. break
  62. case "burger_king":
  63. router = "https://ot.jfshou.cn/privilege-api/burgerKing/external/queryOrder"
  64. break
  65. case "heytea":
  66. router = "https://ot.jfshou.cn/privilege-api/heytea/external/queryOrder"
  67. break
  68. case "to_kfc":
  69. router = "https://ot.jfshou.cn/api/queryOrder"
  70. break
  71. case "wallace":
  72. router = "https://ot.jfshou.cn/privilege-api/wallace/external/queryOrder"
  73. break
  74. case "flowerCake":
  75. router = "https://ot.jfshou.cn/privilege-api/flowercake/external/queryOrder"
  76. break
  77. case "delivery":
  78. router = "https://ot.jfshou.cn/privilege-api/expressDelivery/external/queryOrder"
  79. break
  80. case "tourism":
  81. router = "https://ot.jfshou.cn/privilege-api/tourism/external/queryOrder"
  82. break
  83. }
  84. endTime := time.Now().Unix()
  85. startTime := endTime - 300
  86. params := map[string]string{
  87. "start_time": time.Unix(startTime, 0).Format("2006-01-02 15:04:05"),
  88. "end_time": time.Unix(endTime, 0).Format("2006-01-02 15:04:05"),
  89. "time_type": "1",
  90. "page_number": utils.IntToStr(p),
  91. "page_size": "50",
  92. }
  93. params["share_code"] = hwShareCode
  94. params["timestamp"] = utils.Int64ToStr(time.Now().UnixNano() / 1e6)
  95. order, takeList := hw.HwSendOrder(router, params, hwSecret)
  96. count := 0
  97. if order != "" && order != "[]" {
  98. var list = make([]map[string]interface{}, 0)
  99. json.Unmarshal([]byte(order), &list)
  100. count = len(list)
  101. for _, v := range list {
  102. AddOrder(method, v)
  103. }
  104. }
  105. if takeList != "" && takeList != "[]" {
  106. var list = make([]map[string]interface{}, 0)
  107. json.Unmarshal([]byte(takeList), &list)
  108. for _, v := range list {
  109. AddOrder(method, v)
  110. }
  111. }
  112. return count
  113. }
  114. func AddOrder(method string, order map[string]interface{}) {
  115. 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": "订单成功"}
  116. userId := order["extra"]
  117. if strings.Contains(utils.AnyToString(userId), "m") == false {
  118. return
  119. }
  120. isShare := 0
  121. if strings.Contains(utils.AnyToString(userId), "share") {
  122. isShare = 1
  123. userId = strings.ReplaceAll(utils.AnyToString(userId), "share", "")
  124. }
  125. split := strings.Split(utils.AnyToString(userId), "s")
  126. mid := strings.ReplaceAll(split[0], "m", "")
  127. splitSecond := strings.Split(split[1], "p")
  128. puid := splitSecond[1]
  129. uid := splitSecond[0]
  130. if utils.AnyToFloat64(order["total_rebate"]) == 0 {
  131. order["total_rebate"] = order["rebate"]
  132. }
  133. if order["product_detail"] == "" && order["product_name"] != "" {
  134. order["product_detail"] = order["product_name"]
  135. }
  136. if order["product_detail"] == "" && order["cinema_name"] != "" {
  137. order["product_detail"] = utils.AnyToString(order["cinema_name"]) + "-" + utils.AnyToString(order["movie_name"])
  138. }
  139. if order["product_detail"] == "" && order["delivery_brand_name"] != "" {
  140. order["product_detail"] = utils.AnyToString(order["delivery_brand_name"]) + "-" + utils.AnyToString(order["delivery_goods_name"])
  141. }
  142. var ord = &model.HwOrder{
  143. Oid: utils.AnyToString(order["order_no"]),
  144. Info: utils.AnyToString(order["product_detail"]),
  145. Commission: utils.AnyToFloat64(order["total_rebate"]),
  146. Type: method,
  147. TakePhoneNumber: utils.AnyToString(order["take_phone_number"]),
  148. RestaurantAddress: utils.AnyToString(order["restaurant_address"]),
  149. Uid: utils.StrToInt(mid),
  150. Payment: utils.AnyToFloat64(order["settle_price"]),
  151. Status: statusArr[utils.AnyToString(order["order_status"])],
  152. CreateTime: int(utils.TimeStdParseUnix(utils.AnyToString(order["order_time"]))),
  153. Data: utils.SerializeStr(order),
  154. UpdateTime: int(utils.TimeStdParseUnix(utils.AnyToString(order["modify_time"]))),
  155. Zuid: uid,
  156. Extra: utils.AnyToString(order["extra"]),
  157. Code: utils.AnyToString(order["code"]),
  158. UserId: utils.AnyToString(order["user_id"]),
  159. IsShare: isShare,
  160. OutMealTime: int(utils.TimeStdParseUnix(utils.AnyToString(order["out_meal_time"]))),
  161. ExtendUid: puid,
  162. }
  163. if order["modify_time"] == "" || order["modify_time"] == nil {
  164. ord.UpdateTime = int(time.Now().Unix())
  165. }
  166. if order["refund_time"] != "" && order["refund_time"] != nil {
  167. ord.RefundTime = int(utils.TimeStdParseUnix(utils.AnyToString(order["refund_time"])))
  168. }
  169. one := db.GetHwOrderByOne(ord.Oid, utils.IntToStr(ord.Uid), ord.Type)
  170. if one == nil {
  171. insertOne, err := db.ZhimengDb.InsertOne(ord)
  172. fmt.Println(insertOne)
  173. fmt.Println(err)
  174. } else {
  175. ord.SettleTime = one.SettleTime
  176. db.ZhimengDb.Where("id=?", one.Id).AllCols().Update(ord)
  177. }
  178. return
  179. }