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

182 lines
7.6 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]interface{} {
  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]interface{}, 0)
  13. for _, v := range res.GoodsBasicDetailResponse.List {
  14. tmp := make(map[string]interface{})
  15. tmp["gid"] = zhios_third_party_utils.Int64ToStr(v.GoodsId)
  16. tmp["goods_title"] = v.GoodsName
  17. tmp["commission"] = 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"] = v.CouponStartTime
  22. }
  23. if v.CouponEndTime > 0 {
  24. tmp["coupon_end_time"] = v.CouponEndTime
  25. }
  26. tmp["coupon_price"] = float64(v.CouponDiscount) / 100
  27. tmp["shop_name"] = v.MallName
  28. tmp["mall_id"] = v.MallId
  29. tmp["min_normal_price"] = float64(v.MinNormalPrice) / 100
  30. tmp["min_group_price"] = float64(v.MinGroupPrice) / 100
  31. //销量处理
  32. goodsSale := v.SalesTip
  33. if strings.Contains(goodsSale, "万+") {
  34. goodsSale = strings.ReplaceAll(goodsSale, "万+", "")
  35. goodsSale = zhios_third_party_utils.IntToStr(int(zhios_third_party_utils.StrToFloat64(goodsSale) * 10000))
  36. }
  37. if strings.Contains(goodsSale, "万") {
  38. goodsSale = strings.ReplaceAll(goodsSale, "万", "")
  39. goodsSale = zhios_third_party_utils.IntToStr(int(zhios_third_party_utils.StrToFloat64(goodsSale) * 10000))
  40. }
  41. tmp["goods_sales"] = goodsSale
  42. tmp["goods_img"] = v.GoodsImageUrl
  43. tmp["goods_min_img"] = v.GoodsThumbnailUrl
  44. tmp["goods_desc"] = v.GoodsDesc
  45. tmp["goods_sign"] = v.GoodsSign
  46. data = append(data, tmp)
  47. }
  48. return data
  49. }
  50. func GetSearchGoods(keyArr map[string]string, param map[string]interface{}) []map[string]interface{} {
  51. send, _ := Send(keyArr, "pdd.ddk.oauth.goods.search", param)
  52. var res cps_pdd.SearchGoods
  53. json.Unmarshal([]byte(send), &res)
  54. data := make([]map[string]interface{}, 0)
  55. for _, v := range res.GoodsSearchResponse.GoodsList {
  56. tmp := make(map[string]interface{})
  57. tmp["gid"] = zhios_third_party_utils.Int64ToStr(v.GoodsId)
  58. tmp["goods_title"] = v.GoodsName
  59. tmp["commission"] = float64(v.PromotionRate) / 10
  60. tmp["coupon_start_time"] = 0
  61. tmp["coupon_end_time"] = 0
  62. if v.CouponStartTime > 0 {
  63. tmp["coupon_start_time"] = v.CouponStartTime
  64. }
  65. if v.CouponEndTime > 0 {
  66. tmp["coupon_end_time"] = v.CouponEndTime
  67. }
  68. tmp["coupon_price"] = float64(v.CouponDiscount) / 100
  69. tmp["shop_name"] = v.MallName
  70. tmp["mall_id"] = v.MallId
  71. tmp["min_normal_price"] = float64(v.MinNormalPrice) / 100
  72. tmp["min_group_price"] = float64(v.MinGroupPrice) / 100
  73. //销量处理
  74. goodsSale := v.SalesTip
  75. if strings.Contains(goodsSale, "万+") {
  76. goodsSale = strings.ReplaceAll(goodsSale, "万+", "")
  77. goodsSale = zhios_third_party_utils.IntToStr(int(zhios_third_party_utils.StrToFloat64(goodsSale) * 10000))
  78. }
  79. if strings.Contains(goodsSale, "万") {
  80. goodsSale = strings.ReplaceAll(goodsSale, "万", "")
  81. goodsSale = zhios_third_party_utils.IntToStr(int(zhios_third_party_utils.StrToFloat64(goodsSale) * 10000))
  82. }
  83. tmp["goods_sales"] = goodsSale
  84. tmp["goods_img"] = v.GoodsImageUrl
  85. tmp["goods_min_img"] = v.GoodsThumbnailUrl
  86. tmp["goods_desc"] = v.GoodsDesc
  87. tmp["goods_sign"] = v.GoodsSign
  88. data = append(data, tmp)
  89. }
  90. return data
  91. }
  92. func GetSearchGoodsDetail(keyArr map[string]string, param map[string]interface{}) []map[string]string {
  93. send, _ := Send(keyArr, "pdd.ddk.oauth.goods.search", param)
  94. var res cps_pdd.SearchGoods
  95. json.Unmarshal([]byte(send), &res)
  96. data := make([]map[string]string, 0)
  97. for _, v := range res.GoodsSearchResponse.GoodsList {
  98. tmp := make(map[string]string)
  99. tmp["gid"] = zhios_third_party_utils.Int64ToStr(v.GoodsId)
  100. tmp["goods_title"] = v.GoodsName
  101. tmp["commission"] = zhios_third_party_utils.Float64ToStr(float64(v.PromotionRate) / 10)
  102. tmp["coupon_start_time"] = "0"
  103. tmp["coupon_end_time"] = "0"
  104. if v.CouponStartTime > 0 {
  105. tmp["coupon_start_time"] = zhios_third_party_utils.IntToStr(v.CouponStartTime)
  106. }
  107. if v.CouponEndTime > 0 {
  108. tmp["coupon_end_time"] = zhios_third_party_utils.IntToStr(v.CouponEndTime)
  109. }
  110. tmp["coupon_price"] = zhios_third_party_utils.Float64ToStr(float64(v.CouponDiscount) / 100)
  111. tmp["shop_name"] = v.MallName
  112. tmp["mall_id"] = zhios_third_party_utils.IntToStr(v.MallId)
  113. tmp["min_normal_price"] = zhios_third_party_utils.Float64ToStr(float64(v.MinNormalPrice) / 100)
  114. tmp["min_group_price"] = zhios_third_party_utils.Float64ToStr(float64(v.MinGroupPrice) / 100)
  115. //销量处理
  116. tmp["goods_sales"] = v.SalesTip
  117. if strings.Contains(tmp["goods_sales"], "万+") {
  118. tmp["goods_sales"] = strings.ReplaceAll(tmp["goods_sales"], "万+", "")
  119. tmp["goods_sales"] = zhios_third_party_utils.IntToStr(int(zhios_third_party_utils.StrToFloat64(tmp["goods_sales"]) * 10000))
  120. }
  121. if strings.Contains(tmp["goods_sales"], "万") {
  122. tmp["goods_sales"] = strings.ReplaceAll(tmp["goods_sales"], "万", "")
  123. tmp["goods_sales"] = zhios_third_party_utils.IntToStr(int(zhios_third_party_utils.StrToFloat64(tmp["goods_sales"]) * 10000))
  124. }
  125. tmp["goods_img"] = v.GoodsImageUrl
  126. tmp["goods_min_img"] = v.GoodsThumbnailUrl
  127. tmp["goods_desc"] = v.GoodsDesc
  128. tmp["goods_sign"] = v.GoodsSign
  129. data = append(data, tmp)
  130. }
  131. return data
  132. }
  133. func GetGoodsDetail(keyArr map[string]string, param map[string]interface{}) map[string]interface{} {
  134. send, _ := Send(keyArr, "pdd.ddk.oauth.goods.detail", param)
  135. var res cps_pdd.GoodsDetail
  136. json.Unmarshal([]byte(send), &res)
  137. data := make(map[string]interface{})
  138. for _, v := range res.GoodsDetailResponse.GoodsDetails {
  139. tmp := make(map[string]interface{})
  140. tmp["gid"] = zhios_third_party_utils.Int64ToStr(v.GoodsId)
  141. tmp["goods_title"] = v.GoodsName
  142. tmp["commission"] = zhios_third_party_utils.Float64ToStr(float64(v.PromotionRate) / 10)
  143. tmp["coupon_start_time"] = "0"
  144. tmp["coupon_end_time"] = "0"
  145. if v.CouponStartTime > 0 {
  146. tmp["coupon_start_time"] = zhios_third_party_utils.IntToStr(v.CouponStartTime)
  147. }
  148. if v.CouponEndTime > 0 {
  149. tmp["coupon_end_time"] = zhios_third_party_utils.IntToStr(v.CouponEndTime)
  150. }
  151. tmp["coupon_price"] = zhios_third_party_utils.Float64ToStr(float64(v.CouponDiscount) / 100)
  152. tmp["shop_name"] = v.MallName
  153. tmp["mall_id"] = zhios_third_party_utils.IntToStr(v.MallId)
  154. tmp["min_normal_price"] = zhios_third_party_utils.Float64ToStr(float64(v.MinNormalPrice) / 100)
  155. tmp["min_group_price"] = zhios_third_party_utils.Float64ToStr(float64(v.MinGroupPrice) / 100)
  156. //销量处理
  157. tmp["goods_sales"] = v.SalesTip
  158. if strings.Contains(zhios_third_party_utils.AnyToString(tmp["goods_sales"]), "万+") {
  159. tmp["goods_sales"] = strings.ReplaceAll(zhios_third_party_utils.AnyToString(tmp["goods_sales"]), "万+", "")
  160. tmp["goods_sales"] = zhios_third_party_utils.Float64ToStr(zhios_third_party_utils.StrToFloat64(zhios_third_party_utils.AnyToString(tmp["goods_sales"])) * 10000)
  161. }
  162. if strings.Contains(zhios_third_party_utils.AnyToString(tmp["goods_sales"]), "万") {
  163. tmp["goods_sales"] = strings.ReplaceAll(zhios_third_party_utils.AnyToString(tmp["goods_sales"]), "万", "")
  164. tmp["goods_sales"] = zhios_third_party_utils.Float64ToStr(zhios_third_party_utils.StrToFloat64(zhios_third_party_utils.AnyToString(tmp["goods_sales"])) * 10000)
  165. }
  166. tmp["goods_img"] = v.GoodsImageUrl
  167. tmp["goods_min_img"] = v.GoodsThumbnailUrl
  168. tmp["goods_desc"] = v.GoodsDesc
  169. tmp["goods_sign"] = v.GoodsSign
  170. if len(v.GoodsGalleryUrls) > 0 {
  171. tmp["goods_img_list"] = v.GoodsGalleryUrls
  172. }
  173. data = tmp
  174. }
  175. return data
  176. }