第三方api接口
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.

118 lines
4.1 KiB

  1. package dataoke
  2. import (
  3. "code.fnuoos.com/go_rely_warehouse/zyos_go_third_party_api.git/md"
  4. zhios_third_party_utils "code.fnuoos.com/go_rely_warehouse/zyos_go_third_party_api.git/utils"
  5. "encoding/json"
  6. "github.com/tidwall/gjson"
  7. "net/url"
  8. )
  9. func DataokeFriendsCircleList(params map[string]string) []map[string]string {
  10. var goods = make([]map[string]string, 0)
  11. resp, err := SendReq("https://openapi.dataoke.com/api/goods/friends-circle-list", params)
  12. if err != nil {
  13. return goods
  14. }
  15. data := gjson.Get(string(resp), "data.list").String()
  16. if data == "" {
  17. return goods
  18. }
  19. var oldGoods []md.DataokeFriendCircleList
  20. json.Unmarshal([]byte(data), &oldGoods)
  21. for _, v := range oldGoods {
  22. m, _ := url.QueryUnescape(v.CircleText)
  23. pvd := md.PVD_TB
  24. if v.ShopType == 1 {
  25. pvd = md.PVD_TM
  26. }
  27. var tmp = map[string]string{
  28. "gid": v.GoodsID,
  29. "title": v.Dtitle,
  30. "img": v.MainPic,
  31. "sales": zhios_third_party_utils.IntToStr(v.MonthSales),
  32. "day_sales": zhios_third_party_utils.IntToStr(v.DailySales),
  33. "price": zhios_third_party_utils.Float64ToStr(v.ActualPrice),
  34. "cost_price": zhios_third_party_utils.Float64ToStr(v.OriginalPrice),
  35. "coupon": zhios_third_party_utils.Float64ToStr(v.CouponPrice),
  36. "commission_rate": zhios_third_party_utils.Float64ToStr(v.CommissionRate),
  37. "commission": zhios_third_party_utils.Float64ToStr(v.ActualPrice * (v.CommissionRate / 100)),
  38. "pvd": pvd,
  39. "share_content": m,
  40. }
  41. goods = append(goods, tmp)
  42. }
  43. return goods
  44. }
  45. func DataokeTaobaoRankList(params map[string]string) []map[string]string {
  46. var goods = make([]map[string]string, 0)
  47. resp, err := SendReq("https://openapi.dataoke.com/api/goods/get-ranking-list", params)
  48. if err != nil {
  49. return goods
  50. }
  51. data := gjson.Get(string(resp), "data").String()
  52. if data == "" {
  53. return goods
  54. }
  55. var oldGoods []md.DataokeTaobaoRankList
  56. json.Unmarshal([]byte(data), &oldGoods)
  57. for _, v := range oldGoods {
  58. pvd := md.PVD_TB
  59. var tmp = map[string]string{
  60. "gid": v.Goodsid,
  61. "title": v.Dtitle,
  62. "img": v.Mainpic,
  63. "sales": zhios_third_party_utils.IntToStr(v.Monthsales),
  64. "day_sales": zhios_third_party_utils.IntToStr(v.Dailysales),
  65. "price": zhios_third_party_utils.AnyToString(v.Originalprice),
  66. "cost_price": zhios_third_party_utils.AnyToString(v.Actualprice),
  67. "coupon": zhios_third_party_utils.AnyToString(v.Couponprice),
  68. "commission_rate": zhios_third_party_utils.AnyToString(v.Commissionrate),
  69. "commission": zhios_third_party_utils.Float64ToStr(zhios_third_party_utils.AnyToFloat64(v.Actualprice) * (zhios_third_party_utils.AnyToFloat64(v.Commissionrate) / 100)),
  70. "pvd": pvd,
  71. "share_content": v.Desc,
  72. }
  73. goods = append(goods, tmp)
  74. }
  75. return goods
  76. }
  77. func DataokeTikTokRankList(params map[string]string) []map[string]string {
  78. var goods = make([]map[string]string, 0)
  79. resp, err := SendReq("https://openapi.dataoke.com/api/tiktok/tiktok-sx-goods-rank", params)
  80. if err != nil {
  81. return goods
  82. }
  83. data := gjson.Get(string(resp), "data.list").String()
  84. if data == "" {
  85. return goods
  86. }
  87. var oldGoods []md.DataokeTikTokRankList
  88. json.Unmarshal([]byte(data), &oldGoods)
  89. for _, v := range oldGoods {
  90. pvd := md.PVD_TIKTOK
  91. if v.Cover != "" {
  92. v.ItemImg = v.Cover
  93. }
  94. if len(v.Imgs) > 0 {
  95. v.ItemImg = v.Imgs[0]
  96. }
  97. var tmp = map[string]string{
  98. "gid": v.ID,
  99. "title": v.Title,
  100. "img": v.ItemImg,
  101. "sales": zhios_third_party_utils.Int64ToStr(v.Sales),
  102. "day_sales": "",
  103. "price": zhios_third_party_utils.AnyToString(v.Price - v.Coupon),
  104. "cost_price": zhios_third_party_utils.AnyToString(v.Price),
  105. "coupon": zhios_third_party_utils.AnyToString(v.Coupon),
  106. "commission_rate": zhios_third_party_utils.AnyToString(v.CosRatio),
  107. "commission": zhios_third_party_utils.Float64ToStr((v.Price - v.Coupon) * (zhios_third_party_utils.AnyToFloat64(v.CosRatio) / 100)),
  108. "pvd": pvd,
  109. "share_content": "",
  110. }
  111. goods = append(goods, tmp)
  112. }
  113. return goods
  114. }