蛋蛋星球-制度模式
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.

251 lines
8.1 KiB

  1. package haiwei
  2. import (
  3. "code.fnuoos.com/EggPlanet/egg_models.git/src/implement"
  4. "code.fnuoos.com/EggPlanet/egg_models.git/src/model"
  5. utils "code.fnuoos.com/EggPlanet/egg_system_rules.git/utils"
  6. "encoding/json"
  7. "fmt"
  8. "github.com/syyongx/php2go"
  9. "github.com/tidwall/gjson"
  10. "strings"
  11. "time"
  12. "xorm.io/xorm"
  13. )
  14. func Hw365SendUrl(method string, extra, hwShareCode, hwSecret string) (string, error) {
  15. router := ""
  16. switch method {
  17. case "starbucks":
  18. router = "https://ot.jfshou.cn/sbkplus/auth/index"
  19. break
  20. case "movie":
  21. router = "https://ot.jfshou.cn/ticket/auth/index"
  22. break
  23. case "mcdonald":
  24. router = "https://ot.jfshou.cn/api/mcdonald/entrance"
  25. break
  26. case "nayuki":
  27. router = "https://ot.jfshou.cn/api/nayuki/entrance"
  28. break
  29. case "luckin":
  30. router = "https://ot.jfshou.cn/privilege-api/luckin/auth/index"
  31. break
  32. case "pizza":
  33. router = "https://ot.jfshou.cn/privilege-api/pizzaHut/auth/index"
  34. break
  35. case "pagoda":
  36. router = "https://ot.jfshou.cn/privilege-api/pagoda/auth/index"
  37. break
  38. case "burger_king":
  39. router = "https://ot.jfshou.cn/privilege-api/burgerKing/auth/index"
  40. break
  41. case "heytea":
  42. router = "https://ot.jfshou.cn/privilege-api/heytea/auth/index"
  43. break
  44. case "to_kfc":
  45. router = "https://ot.jfshou.cn/api/entrance"
  46. break
  47. case "wallace":
  48. router = "https://ot.jfshou.cn/privilege-api/wallace/auth/index0327"
  49. break
  50. case "flowerCake":
  51. router = "https://ot.jfshou.cn/privilege-api/flowerCake/auth/index"
  52. break
  53. case "delivery":
  54. router = "https://ot.jfshou.cn/privilege-api/express/delivery/auth/index"
  55. break
  56. case "tourism":
  57. router = "https://ot.jfshou.cn/privilege-api/tourism/auth/index"
  58. break
  59. case "near":
  60. router = "https://ot.jfshou.cn/api/index/entrance"
  61. break
  62. }
  63. param := map[string]string{
  64. "user_id": extra,
  65. "extra": extra,
  66. }
  67. param["share_code"] = hwShareCode
  68. param["timestamp"] = utils.Int64ToStr(time.Now().UnixNano() / 1e6)
  69. url := HwSend(router, param, hwSecret)
  70. return url, nil
  71. }
  72. func HwSend(url string, param map[string]string, secret string) string {
  73. sign := getSign(param, secret)
  74. param["sign"] = sign
  75. for k, v := range param {
  76. if v == "" {
  77. continue
  78. }
  79. if strings.Contains(url, "?") == false {
  80. url += "?" + k + "=" + php2go.URLEncode(v)
  81. } else {
  82. url += "&" + k + "=" + php2go.URLEncode(v)
  83. }
  84. }
  85. return url
  86. }
  87. func HwSendOrder(eg *xorm.Engine, hwShareCode, hwSecret, method string, p, timeType string, prd bool) int {
  88. endTime := time.Now().Unix()
  89. startTime := endTime - 86400
  90. param := map[string]string{
  91. "start_time": time.Unix(startTime, 0).Format("2006-01-02 15:04:05"),
  92. "end_time": time.Unix(endTime, 0).Format("2006-01-02 15:04:05"),
  93. "time_type": timeType,
  94. "page_number": p,
  95. "page_size": "50",
  96. }
  97. router := ""
  98. switch method {
  99. case "starbucks":
  100. router = "https://ot.jfshou.cn/sbkplus/queryStarbucksOrder"
  101. break
  102. case "movie":
  103. router = "https://ot.jfshou.cn/ticket/query/order/list"
  104. break
  105. case "mcdonald":
  106. router = "https://ot.jfshou.cn/api/queryMcOrder"
  107. break
  108. case "nayuki":
  109. router = "https://ot.jfshou.cn/api/nayuki/order/queryOrdersByUser"
  110. break
  111. case "luckin":
  112. router = "https://ot.jfshou.cn/privilege-api/luckin/external/queryOrder"
  113. break
  114. case "pizza":
  115. router = "https://ot.jfshou.cn/privilege-api/pizzaHut/external/queryOrder"
  116. break
  117. case "pagoda":
  118. router = "https://ot.jfshou.cn/privilege-api/pagoda/external/queryOrder"
  119. break
  120. case "burger_king":
  121. router = "https://ot.jfshou.cn/privilege-api/burgerKing/external/queryOrder"
  122. break
  123. case "heytea":
  124. router = "https://ot.jfshou.cn/privilege-api/heytea/external/queryOrder"
  125. break
  126. case "to_kfc":
  127. router = "https://ot.jfshou.cn/api/queryOrder"
  128. break
  129. case "wallace":
  130. router = "https://ot.jfshou.cn/privilege-api/wallace/external/queryOrder"
  131. break
  132. case "flowerCake":
  133. router = "https://ot.jfshou.cn/privilege-api/flowercake/external/queryOrder"
  134. break
  135. case "delivery":
  136. router = "https://ot.jfshou.cn/privilege-api/expressDelivery/external/queryOrder"
  137. break
  138. case "tourism":
  139. router = "https://ot.jfshou.cn/privilege-api/tourism/external/queryOrder"
  140. break
  141. }
  142. param["share_code"] = hwShareCode
  143. param["timestamp"] = utils.Int64ToStr(time.Now().UnixNano() / 1e6)
  144. sign := getSign(param, hwSecret)
  145. param["sign"] = sign
  146. for k, v := range param {
  147. if v == "" {
  148. continue
  149. }
  150. if strings.Contains(router, "?") == false {
  151. router += "?" + k + "=" + php2go.URLEncode(v)
  152. } else {
  153. router += "&" + k + "=" + php2go.URLEncode(v)
  154. }
  155. }
  156. data, _ := utils.CurlGet(router, nil)
  157. order := gjson.Get(string(data), "data.list").String()
  158. if order == "" {
  159. order = gjson.Get(string(data), "data.order").String()
  160. }
  161. taskList := gjson.Get(string(data), "data.take_list").String()
  162. count := 0
  163. if order != "" && order != "[]" {
  164. var list = make([]map[string]interface{}, 0)
  165. json.Unmarshal([]byte(order), &list)
  166. count = len(list)
  167. for _, v := range list {
  168. AddOrder(eg, method, v, prd)
  169. }
  170. }
  171. if taskList != "" && taskList != "[]" {
  172. var list = make([]map[string]interface{}, 0)
  173. json.Unmarshal([]byte(taskList), &list)
  174. for _, v := range list {
  175. AddOrder(eg, method, v, prd)
  176. }
  177. }
  178. return count
  179. }
  180. func AddOrder(eg *xorm.Engine, method string, order map[string]interface{}, prd bool) {
  181. 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": "订单成功"}
  182. userId := order["extra"]
  183. if strings.Contains(utils.AnyToString(userId), "ddstar") == false {
  184. return
  185. }
  186. if strings.Contains(utils.AnyToString(userId), "dev") && prd {
  187. return
  188. }
  189. if strings.Contains(utils.AnyToString(userId), "prd") && prd == false {
  190. return
  191. }
  192. split := strings.Split(utils.AnyToString(userId), "_")
  193. uid := split[2]
  194. if utils.AnyToFloat64(order["total_rebate"]) == 0 {
  195. order["total_rebate"] = order["rebate"]
  196. }
  197. if (order["product_detail"] == nil || order["product_detail"] == "" || order["product_detail"] == "<nil>") && order["product_name"] != nil {
  198. order["product_detail"] = order["product_name"]
  199. }
  200. if (order["product_detail"] == nil || order["product_detail"] == "" || order["product_detail"] == "<nil>") && order["cinema_name"] != nil {
  201. order["product_detail"] = utils.AnyToString(order["cinema_name"]) + "-" + utils.AnyToString(order["movie_name"])
  202. }
  203. if (order["product_detail"] == nil || order["product_detail"] == "" || order["product_detail"] == "<nil>-<nil>" || order["product_detail"] == "<nil>") && order["delivery_brand_name"] != "" {
  204. order["product_detail"] = utils.AnyToString(order["delivery_brand_name"]) + "-" + utils.AnyToString(order["delivery_goods_name"])
  205. }
  206. var ord = &model.LifeOrder{
  207. PvdOid: utils.AnyToString(order["order_no"]),
  208. GoodsTitle: utils.AnyToString(order["product_detail"]),
  209. Commission: utils.AnyToString(order["total_rebate"]),
  210. Platform: method,
  211. Uid: utils.StrToInt(uid),
  212. Payment: utils.AnyToString(order["settle_price"]),
  213. State: statusArr[utils.AnyToString(order["order_status"])],
  214. CreateAt: utils.TimeParseStd(utils.AnyToString(order["order_time"])),
  215. UpdateAt: time.Now(),
  216. }
  217. NewLifeOrderDb := implement.NewLifeOrderDb(eg)
  218. one, _ := NewLifeOrderDb.GetLifeOrder(ord.PvdOid)
  219. if one == nil {
  220. insertOne, err := eg.InsertOne(ord)
  221. fmt.Println(insertOne)
  222. fmt.Println(err)
  223. } else {
  224. ord.SettleAt = one.SettleAt
  225. eg.Where("id=?", one.Id).AllCols().Update(ord)
  226. }
  227. return
  228. }
  229. func getSign(param map[string]string, secret string) string {
  230. strMap := utils.KsortToStr(param)
  231. str := ""
  232. for _, v := range strMap {
  233. if v == "sign" || param[v] == "" {
  234. continue
  235. }
  236. str += utils.UderscoreToUpperCamelCase(v) + "=" + param[v] + "&"
  237. }
  238. str += "secretKey=" + secret
  239. return strings.ToUpper(php2go.Md5(str))
  240. }