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

175 lines
4.5 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/elm"
  8. "fmt"
  9. "strings"
  10. "time"
  11. )
  12. func ElmOrder() {
  13. pvdTimeKey := "elm_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. )
  39. //怕时间不是走最新的
  40. leave := now - past
  41. if leave > 500 {
  42. leave = 0
  43. }
  44. past = past + leave
  45. beginTime = past - 300
  46. endTime = past
  47. if endTime > now {
  48. endTime = now
  49. }
  50. for {
  51. count := 0
  52. count, _ = OrdersElmGet(pageNo, pageSize, beginTime, endTime, "update", 1)
  53. if count == 0 {
  54. goto ChkArg
  55. }
  56. // 判断是否分页已经全部取完了
  57. if count <= pageSize {
  58. pageNo++
  59. fmt.Println("========下一页========" + utils.IntToStr(pageNo))
  60. count = 0
  61. continue
  62. }
  63. ChkArg:
  64. // 查询完后重置时间, 最后查询时间
  65. if endTime < now {
  66. pageNo = 1
  67. offical.DbsSysCfgUpdate(pvdTimeKey, utils.TimeToStr(endTime))
  68. beginTime = endTime
  69. endTime = endTime + 300
  70. if endTime > now {
  71. endTime = now
  72. }
  73. count = 0
  74. continue
  75. }
  76. count = 0
  77. break
  78. }
  79. offical.DbsSysCfgUpdate(pvdTimeKey, utils.TimeToStr(endTime))
  80. }
  81. func OrdersElmGet(p int, pageSize int, sTime, eTime int64, timeType string, pvd int) (int, string) {
  82. key := "34319215"
  83. secret := "bb07710660e60a321350a35e1e3b91e8"
  84. args := map[string]string{
  85. "end_time": time.Unix(eTime, 0).Format("2006-01-02 15:04:05"),
  86. "start_time": time.Unix(sTime, 0).Format("2006-01-02 15:04:05"),
  87. "p": utils.IntToStr(p),
  88. "size": utils.IntToStr(pageSize),
  89. }
  90. order, _ := elm.ElemePromotionOrder(key, secret, args)
  91. if order == nil {
  92. return 0, ""
  93. }
  94. var stateList = map[string]string{
  95. "2": "订单付款",
  96. "4": "订单完成",
  97. "1": "创建订单",
  98. "0": "订单失效",
  99. }
  100. for _, v := range order.Result {
  101. if *v.OrderState == 1 {
  102. continue
  103. }
  104. createTime := utils.TimeStdParseUnix(*v.TkCreateTime)
  105. if v.PayTime != nil {
  106. createTime = utils.TimeStdParseUnix(*v.PayTime)
  107. }
  108. var res = model.LifeOrder{
  109. PvdParentOid: utils.Int64ToStr(*v.ParentOrderId),
  110. Pvd: "own_ele",
  111. Status: stateList[utils.Int64ToStr(*v.OrderState)],
  112. CreateTime: int(createTime),
  113. }
  114. if *v.SettleState == 1 && v.SettleTime != nil {
  115. res.Status = "订单结算"
  116. res.PlatformSettleTime = int(utils.TimeStdParseUnix(*v.SettleTime))
  117. }
  118. ex := strings.Split(*v.Sid, "_")
  119. if len(ex) < 4 || strings.Contains(*v.Sid, "own") == false {
  120. continue
  121. }
  122. orderType := 0
  123. if ex[1] == "share" {
  124. orderType = 1
  125. }
  126. res.Uid = utils.StrToInt(ex[2])
  127. res.StationUid = utils.StrToInt(ex[3])
  128. res.Oid = utils.StrToInt64(utils.OrderUUID(utils.StrToInt(ex[2])))
  129. res.PvdOid = utils.Int64ToStr(*v.BizOrderId)
  130. res.UpdateTime = int(time.Now().Unix())
  131. if utils.StrToFloat64(*v.PlatformCommissionFee) == 0 {
  132. amount := utils.StrToFloat64(*v.Income)
  133. if utils.StrToFloat64(*v.Settle) > 0 {
  134. amount = utils.StrToFloat64(*v.Settle)
  135. }
  136. fee := float64(int(amount*0.1*100)) / 100
  137. *v.PlatformCommissionFee = utils.Float64ToStr(fee)
  138. }
  139. res.Commission = utils.Float64ToStr(utils.StrToFloat64(*v.Income) - utils.StrToFloat64(*v.PlatformCommissionFee))
  140. if v.Settle != nil && utils.StrToFloat64(*v.Settle) > 0 {
  141. res.RealCommission = utils.Float64ToStr(utils.StrToFloat64(*v.Settle) - utils.StrToFloat64(*v.PlatformCommissionFee))
  142. }
  143. res.Title = *v.Title
  144. res.Img = *v.PicUrl
  145. res.Gid = res.PvdOid
  146. res.IsShare = orderType
  147. res.Payment = *v.PayAmount
  148. one := db.GetLifeOrderByOne(res.PvdOid, utils.IntToStr(res.Uid), res.Pvd)
  149. if one == nil {
  150. insertOne, err := db.ZhimengDb.InsertOne(&res)
  151. fmt.Println(insertOne)
  152. fmt.Println(err)
  153. } else {
  154. res.SettleTime = one.SettleTime
  155. res.CreateTime = one.CreateTime
  156. if one.PlatformSettleTime > 0 {
  157. res.PlatformSettleTime = one.PlatformSettleTime
  158. }
  159. db.ZhimengDb.Where("id=?", one.Id).AllCols().Update(&res)
  160. }
  161. }
  162. return len(order.Result), ""
  163. }