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

137 lines
6.2 KiB

  1. package pdd_union
  2. import (
  3. "code.fnuoos.com/go_rely_warehouse/zyos_go_third_party_api.git/md/cps_pdd"
  4. zhios_third_party_utils "code.fnuoos.com/go_rely_warehouse/zyos_go_third_party_api.git/utils"
  5. "encoding/json"
  6. "strings"
  7. )
  8. func GetRecommendGoods(keyArr map[string]string, param map[string]interface{}) []map[string]string {
  9. send, _ := Send(keyArr, "pdd.ddk.oauth.goods.recommend.get", param)
  10. var res cps_pdd.RecommendGoods
  11. json.Unmarshal([]byte(send), &res)
  12. data := make([]map[string]string, 0)
  13. for _, v := range res.GoodsBasicDetailResponse.List {
  14. tmp := make(map[string]string)
  15. tmp["gid"] = v.GoodsSign
  16. tmp["goods_title"] = v.GoodsName
  17. tmp["commission"] = zhios_third_party_utils.Float64ToStr(float64(v.PromotionRate) / 10)
  18. tmp["coupon_start_time"] = "0"
  19. tmp["coupon_end_time"] = "0"
  20. if v.CouponStartTime > 0 {
  21. tmp["coupon_start_time"] = zhios_third_party_utils.IntToStr(v.CouponStartTime)
  22. }
  23. if v.CouponEndTime > 0 {
  24. tmp["coupon_end_time"] = zhios_third_party_utils.IntToStr(v.CouponEndTime)
  25. }
  26. tmp["coupon_price"] = zhios_third_party_utils.Float64ToStr(float64(v.CouponDiscount) / 100)
  27. tmp["shop_name"] = v.MallName
  28. tmp["mall_id"] = zhios_third_party_utils.IntToStr(v.MallId)
  29. tmp["min_normal_price"] = zhios_third_party_utils.Float64ToStr(float64(v.MinNormalPrice) / 100)
  30. tmp["min_group_price"] = zhios_third_party_utils.Float64ToStr(float64(v.MinGroupPrice) / 100)
  31. //销量处理
  32. tmp["goods_sales"] = v.SalesTip
  33. if strings.Contains(tmp["goods_sales"], "万+") {
  34. tmp["goods_sales"] = strings.ReplaceAll(tmp["goods_sales"], "万+", "")
  35. tmp["goods_sales"] = zhios_third_party_utils.Float64ToStr(zhios_third_party_utils.StrToFloat64(tmp["goods_sales"]) * 10000)
  36. }
  37. if strings.Contains(tmp["goods_sales"], "万") {
  38. tmp["goods_sales"] = strings.ReplaceAll(tmp["goods_sales"], "万", "")
  39. tmp["goods_sales"] = zhios_third_party_utils.Float64ToStr(zhios_third_party_utils.StrToFloat64(tmp["goods_sales"]) * 10000)
  40. }
  41. tmp["goods_img"] = v.GoodsImageUrl
  42. tmp["goods_min_img"] = v.GoodsThumbnailUrl
  43. tmp["goods_desc"] = v.GoodsDesc
  44. tmp["goods_sign"] = v.GoodsSign
  45. data = append(data, tmp)
  46. }
  47. return data
  48. }
  49. func GetSearchGoods(keyArr map[string]string, param map[string]interface{}) []map[string]string {
  50. send, _ := Send(keyArr, "pdd.ddk.oauth.goods.search", param)
  51. var res cps_pdd.SearchGoods
  52. json.Unmarshal([]byte(send), &res)
  53. data := make([]map[string]string, 0)
  54. for _, v := range res.GoodsSearchResponse.GoodsList {
  55. tmp := make(map[string]string)
  56. tmp["gid"] = v.GoodsSign
  57. tmp["goods_title"] = v.GoodsName
  58. tmp["commission"] = zhios_third_party_utils.Float64ToStr(float64(v.PromotionRate) / 10)
  59. tmp["coupon_start_time"] = "0"
  60. tmp["coupon_end_time"] = "0"
  61. if v.CouponStartTime > 0 {
  62. tmp["coupon_start_time"] = zhios_third_party_utils.IntToStr(v.CouponStartTime)
  63. }
  64. if v.CouponEndTime > 0 {
  65. tmp["coupon_end_time"] = zhios_third_party_utils.IntToStr(v.CouponEndTime)
  66. }
  67. tmp["coupon_price"] = zhios_third_party_utils.Float64ToStr(float64(v.CouponDiscount) / 100)
  68. tmp["shop_name"] = v.MallName
  69. tmp["mall_id"] = zhios_third_party_utils.IntToStr(v.MallId)
  70. tmp["min_normal_price"] = zhios_third_party_utils.Float64ToStr(float64(v.MinNormalPrice) / 100)
  71. tmp["min_group_price"] = zhios_third_party_utils.Float64ToStr(float64(v.MinGroupPrice) / 100)
  72. //销量处理
  73. tmp["goods_sales"] = v.SalesTip
  74. if strings.Contains(tmp["goods_sales"], "万+") {
  75. tmp["goods_sales"] = strings.ReplaceAll(tmp["goods_sales"], "万+", "")
  76. tmp["goods_sales"] = zhios_third_party_utils.Float64ToStr(zhios_third_party_utils.StrToFloat64(tmp["goods_sales"]) * 10000)
  77. }
  78. if strings.Contains(tmp["goods_sales"], "万") {
  79. tmp["goods_sales"] = strings.ReplaceAll(tmp["goods_sales"], "万", "")
  80. tmp["goods_sales"] = zhios_third_party_utils.Float64ToStr(zhios_third_party_utils.StrToFloat64(tmp["goods_sales"]) * 10000)
  81. }
  82. tmp["goods_img"] = v.GoodsImageUrl
  83. tmp["goods_min_img"] = v.GoodsThumbnailUrl
  84. tmp["goods_desc"] = v.GoodsDesc
  85. tmp["goods_sign"] = v.GoodsSign
  86. data = append(data, tmp)
  87. }
  88. return data
  89. }
  90. func GetGoodsDetail(keyArr map[string]string, param map[string]interface{}) map[string]interface{} {
  91. send, _ := Send(keyArr, "pdd.ddk.oauth.goods.detail", param)
  92. var res cps_pdd.GoodsDetail
  93. json.Unmarshal([]byte(send), &res)
  94. data := make(map[string]interface{})
  95. for _, v := range res.GoodsDetailResponse.GoodsDetails {
  96. tmp := make(map[string]interface{})
  97. tmp["gid"] = v.GoodsSign
  98. tmp["goods_title"] = v.GoodsName
  99. tmp["commission"] = zhios_third_party_utils.Float64ToStr(float64(v.PromotionRate) / 10)
  100. tmp["coupon_start_time"] = "0"
  101. tmp["coupon_end_time"] = "0"
  102. if v.CouponStartTime > 0 {
  103. tmp["coupon_start_time"] = zhios_third_party_utils.IntToStr(v.CouponStartTime)
  104. }
  105. if v.CouponEndTime > 0 {
  106. tmp["coupon_end_time"] = zhios_third_party_utils.IntToStr(v.CouponEndTime)
  107. }
  108. tmp["coupon_price"] = zhios_third_party_utils.Float64ToStr(float64(v.CouponDiscount) / 100)
  109. tmp["shop_name"] = v.MallName
  110. tmp["mall_id"] = zhios_third_party_utils.IntToStr(v.MallId)
  111. tmp["min_normal_price"] = zhios_third_party_utils.Float64ToStr(float64(v.MinNormalPrice) / 100)
  112. tmp["min_group_price"] = zhios_third_party_utils.Float64ToStr(float64(v.MinGroupPrice) / 100)
  113. //销量处理
  114. tmp["goods_sales"] = v.SalesTip
  115. if strings.Contains(zhios_third_party_utils.AnyToString(tmp["goods_sales"]), "万+") {
  116. tmp["goods_sales"] = strings.ReplaceAll(zhios_third_party_utils.AnyToString(tmp["goods_sales"]), "万+", "")
  117. tmp["goods_sales"] = zhios_third_party_utils.Float64ToStr(zhios_third_party_utils.StrToFloat64(zhios_third_party_utils.AnyToString(tmp["goods_sales"])) * 10000)
  118. }
  119. if strings.Contains(zhios_third_party_utils.AnyToString(tmp["goods_sales"]), "万") {
  120. tmp["goods_sales"] = strings.ReplaceAll(zhios_third_party_utils.AnyToString(tmp["goods_sales"]), "万", "")
  121. tmp["goods_sales"] = zhios_third_party_utils.Float64ToStr(zhios_third_party_utils.StrToFloat64(zhios_third_party_utils.AnyToString(tmp["goods_sales"])) * 10000)
  122. }
  123. tmp["goods_img"] = v.GoodsImageUrl
  124. tmp["goods_min_img"] = v.GoodsThumbnailUrl
  125. tmp["goods_desc"] = v.GoodsDesc
  126. tmp["goods_sign"] = v.GoodsSign
  127. if len(v.GoodsThumbnailUrl) > 0 {
  128. tmp["goods_img_list"] = v.GoodsThumbnailUrl
  129. }
  130. data = tmp
  131. }
  132. return data
  133. }