智盟项目
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.

213 line
5.3 KiB

  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/thirdParty/wph"
  8. "fmt"
  9. "github.com/syyongx/php2go"
  10. "github.com/tidwall/gjson"
  11. "strings"
  12. "time"
  13. )
  14. func WphComm() map[string]string {
  15. wphData := offical.SysCfgByKeyStr("wph_data")
  16. serviceParam := map[string]string{
  17. "token": "",
  18. "uuid": "353543142",
  19. "key": "8f8c427e",
  20. "secret": "DB9C5A92480618101A15835DD9E8AF69",
  21. "pid": "",
  22. }
  23. serviceParam["token"] = gjson.Get(wphData, "token").String()
  24. serviceParam["pid"] = gjson.Get(wphData, "pid").String()
  25. return serviceParam
  26. }
  27. func WphOrder() {
  28. pvdTimeKey := "wph_time"
  29. // 获得最后时间
  30. latest := offical.SysCfgByKey(pvdTimeKey)
  31. if latest == nil {
  32. offical.DbsSysCfgInserts(pvdTimeKey, time.Now().String())
  33. latest = offical.SysCfgByKey(pvdTimeKey)
  34. }
  35. // 所有时间都是在操作秒数
  36. now := time.Now().Unix()
  37. strs := strings.Split(latest.V, ":")
  38. timeStr := latest.V
  39. if len(strs) == 3 {
  40. timeStr = strs[0] + ":" + strs[1] + ":00"
  41. }
  42. fmt.Println(timeStr)
  43. past := utils.TimeParseStd(timeStr).Unix()
  44. // 如果上次记录超过30天或者 过去时间大于当前时间戳, 把时间设置为此前20分钟
  45. if past < now-180*86400 || past > now {
  46. past = now
  47. }
  48. var (
  49. beginTime int64 = 0
  50. endTime int64 = 0
  51. pageNo int = 1
  52. pageSize int = 50
  53. nextPositionIndex string = ""
  54. )
  55. //怕时间不是走最新的
  56. leave := now - past
  57. if leave > 500 {
  58. leave = 0
  59. }
  60. past = past + leave
  61. beginTime = past - 300
  62. endTime = past
  63. if endTime > now {
  64. endTime = now
  65. }
  66. wphData := WphComm()
  67. for {
  68. count := 0
  69. var positionIndex = ""
  70. if pageNo == 1 {
  71. nextPositionIndex = "0"
  72. }
  73. if nextPositionIndex != "" {
  74. positionIndex, count, _ = OrdersWphGet(pageNo, pageSize, beginTime, endTime, "update", 1, nextPositionIndex, wphData)
  75. }
  76. if count == 0 {
  77. nextPositionIndex = ""
  78. goto ChkArg
  79. }
  80. // 判断是否分页已经全部取完了
  81. if count <= pageSize {
  82. nextPositionIndex = positionIndex
  83. pageNo++
  84. fmt.Println("========下一页========" + utils.IntToStr(pageNo))
  85. count = 0
  86. continue
  87. }
  88. ChkArg:
  89. nextPositionIndex = ""
  90. // 查询完后重置时间, 最后查询时间
  91. if endTime < now {
  92. pageNo = 1
  93. offical.DbsSysCfgUpdate(pvdTimeKey, utils.TimeToStr(endTime))
  94. beginTime = endTime
  95. endTime = endTime + 300
  96. if endTime > now {
  97. endTime = now
  98. }
  99. count = 0
  100. continue
  101. }
  102. count = 0
  103. break
  104. }
  105. }
  106. func OrdersWphGet(p int, pageSize int, sTime, eTime int64, timeType string, pvd int, nextPositionIndex string, wphData map[string]string) (string, int, string) {
  107. queryModel := map[string]string{
  108. "pageSize": utils.IntToStr(pageSize),
  109. "page": utils.IntToStr(p),
  110. "updateTimeStart": utils.Int64ToStr(sTime * 1000),
  111. "updateTimeEnd": utils.Int64ToStr(eTime * 1000),
  112. "requestId": wphData["uuid"] + utils.Int64ToStr(time.Now().Unix()) + utils.IntToStr(php2go.Rand(1000, 9999)),
  113. }
  114. paramData := map[string]interface{}{
  115. "queryModel": queryModel,
  116. }
  117. param := utils.SerializeStr(paramData)
  118. order := wph.GetOrder(wphData, param)
  119. if order == nil {
  120. return "", 0, ""
  121. }
  122. orderCount := len(order)
  123. var kuaishouState = map[string]string{
  124. "已下单": "创建订单",
  125. "已付款": "订单付款",
  126. "已签收": "订单完成",
  127. "待结算": "订单完成",
  128. "已结算": "订单结算",
  129. "已失效": "订单失效",
  130. }
  131. for _, v := range order {
  132. //if v["status"] == "已下单" {
  133. // continue
  134. //}
  135. if v["channelTag"] != wphData["pid"] {
  136. continue
  137. }
  138. userId := v["open_id"]
  139. ex := strings.Split(userId, "_")
  140. if strings.Contains(utils.AnyToString(userId), "off") == false {
  141. continue
  142. }
  143. buyType := ex[1]
  144. if v["statParam"] != "" {
  145. buyType = v["statParam"]
  146. }
  147. if buyType == "" {
  148. buyType = "self"
  149. }
  150. var orderType int
  151. if buyType == "share" {
  152. orderType = 1
  153. }
  154. if buyType == "cloud" {
  155. orderType = 10
  156. }
  157. if buyType == "free" {
  158. orderType = 2
  159. }
  160. taskType := ""
  161. if utils.InArr(buyType, []string{"happy_orchard"}) {
  162. orderType = 1
  163. taskType = buyType
  164. }
  165. var resNew = model.GuideOrder{
  166. PvdParentOid: v["oid"],
  167. Pvd: "vip",
  168. Status: kuaishouState[v["status"]],
  169. CreateTime: utils.StrToInt(v["create_time"]),
  170. }
  171. resNew.TaskType = taskType
  172. resNew.IsShare = orderType
  173. resNew.Oid = utils.StrToInt64(utils.OrderUUID(utils.StrToInt(ex[1])))
  174. resNew.PvdOid = v["oid"]
  175. resNew.Uid = utils.StrToInt(ex[2])
  176. resNew.StationUid = utils.StrToInt(ex[3])
  177. resNew.UpdateTime = int(time.Now().Unix())
  178. resNew.Commission = v["commission"]
  179. resNew.RealCommission = v["commission"]
  180. resNew.Title = v["title"]
  181. resNew.Img = v["img"]
  182. resNew.Gid = v["gid"]
  183. resNew.IsShare = orderType
  184. resNew.Payment = v["payment"]
  185. if utils.StrToInt64(v["js_time"]) > 0 {
  186. resNew.PlatformSettleTime = utils.StrToInt(v["js_time"])
  187. }
  188. one := db.GetGuideOrderByOne(resNew.PvdOid, utils.IntToStr(resNew.Uid), resNew.Pvd)
  189. if one == nil {
  190. insertOne, err := db.ZhimengDb.InsertOne(&resNew)
  191. fmt.Println(insertOne)
  192. fmt.Println(err)
  193. } else {
  194. resNew.SettleTime = one.SettleTime
  195. if one.PlatformSettleTime > 0 {
  196. resNew.PlatformSettleTime = one.PlatformSettleTime
  197. }
  198. db.ZhimengDb.Where("id=?", one.Id).AllCols().Update(&resNew)
  199. }
  200. }
  201. return "", orderCount, ""
  202. }