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

130 lines
3.2 KiB

  1. package svc
  2. import (
  3. "applet/app/db"
  4. offical "applet/app/db/official"
  5. "applet/app/utils"
  6. "code.fnuoos.com/go_rely_warehouse/zyos_go_third_party_api.git/thirdParty/wph"
  7. "fmt"
  8. "github.com/syyongx/php2go"
  9. "strings"
  10. "time"
  11. )
  12. func WphRefundOrder() {
  13. pvdTimeKey := "wph_refund_time"
  14. // 获得最后时间
  15. latest := offical.SysCfgByKey(pvdTimeKey)
  16. if latest == nil {
  17. offical.DbsSysCfgInserts(pvdTimeKey, time.Now().String())
  18. latest = offical.SysCfgByKey(pvdTimeKey)
  19. }
  20. // 所有时间都是在操作秒数
  21. now := time.Now().Unix()
  22. strs := strings.Split(latest.V, ":")
  23. timeStr := latest.V
  24. if len(strs) == 3 {
  25. timeStr = strs[0] + ":" + strs[1] + ":00"
  26. }
  27. fmt.Println(timeStr)
  28. past := utils.TimeParseStd(timeStr).Unix()
  29. // 如果上次记录超过30天或者 过去时间大于当前时间戳, 把时间设置为此前20分钟
  30. if past < now-180*86400 || past > now {
  31. past = now
  32. }
  33. var (
  34. beginTime int64 = 0
  35. endTime int64 = 0
  36. pageNo int = 1
  37. pageSize int = 50
  38. nextPositionIndex string = ""
  39. )
  40. //怕时间不是走最新的
  41. leave := now - past
  42. if leave > 500 {
  43. leave = 0
  44. }
  45. past = past + leave
  46. beginTime = past - 300
  47. endTime = past
  48. if endTime > now {
  49. endTime = now
  50. }
  51. wphData := WphComm()
  52. for {
  53. count := 0
  54. var positionIndex = ""
  55. if pageNo == 1 {
  56. nextPositionIndex = "0"
  57. }
  58. if nextPositionIndex != "" {
  59. positionIndex, count, _ = OrdersWphRefundGet(pageNo, pageSize, beginTime, endTime, "update", 1, nextPositionIndex, wphData)
  60. }
  61. if count == 0 {
  62. nextPositionIndex = ""
  63. goto ChkArg
  64. }
  65. // 判断是否分页已经全部取完了
  66. if count <= pageSize {
  67. nextPositionIndex = positionIndex
  68. pageNo++
  69. fmt.Println("========下一页========" + utils.IntToStr(pageNo))
  70. count = 0
  71. continue
  72. }
  73. ChkArg:
  74. nextPositionIndex = ""
  75. // 查询完后重置时间, 最后查询时间
  76. if endTime < now {
  77. pageNo = 1
  78. offical.DbsSysCfgUpdate(pvdTimeKey, utils.TimeToStr(endTime))
  79. beginTime = endTime
  80. endTime = endTime + 300
  81. if endTime > now {
  82. endTime = now
  83. }
  84. count = 0
  85. continue
  86. }
  87. count = 0
  88. break
  89. }
  90. }
  91. func OrdersWphRefundGet(p int, pageSize int, sTime, eTime int64, timeType string, pvd int, nextPositionIndex string, wphData map[string]string) (string, int, string) {
  92. queryModel := map[string]string{
  93. "pageSize": utils.IntToStr(pageSize),
  94. "page": utils.IntToStr(p),
  95. "searchType": "1",
  96. "searchTimeStart": utils.Int64ToStr(sTime * 1000),
  97. "searchTimeEnd": utils.Int64ToStr(eTime * 1000),
  98. "requestId": wphData["uuid"] + utils.Int64ToStr(time.Now().Unix()) + utils.IntToStr(php2go.Rand(1000, 9999)),
  99. }
  100. paramData := map[string]interface{}{
  101. "request": queryModel,
  102. }
  103. param := utils.SerializeStr(paramData)
  104. order := wph.GetRefundOrder(wphData, param)
  105. if order == nil {
  106. return "", 0, ""
  107. }
  108. orderCount := len(order)
  109. for _, v := range order {
  110. one := db.GetGuideOrderByOid(v["oid"], "vip")
  111. if one != nil {
  112. if v["state"] == "-1" {
  113. one.Status = "订单失效"
  114. } else if v["commission"] != "" {
  115. one.Commission = v["commission"]
  116. }
  117. db.ZhimengDb.Where("id=?", one.Id).AllCols().Update(one)
  118. }
  119. }
  120. return "", orderCount, ""
  121. }