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

185 lines
7.7 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. if v.GoodsName == "" {
  99. continue
  100. }
  101. tmp := make(map[string]string)
  102. tmp["gid"] = zhios_third_party_utils.Int64ToStr(v.GoodsId)
  103. tmp["goods_title"] = v.GoodsName
  104. tmp["commission"] = zhios_third_party_utils.Float64ToStr(float64(v.PromotionRate) / 10)
  105. tmp["coupon_start_time"] = "0"
  106. tmp["coupon_end_time"] = "0"
  107. if v.CouponStartTime > 0 {
  108. tmp["coupon_start_time"] = zhios_third_party_utils.IntToStr(v.CouponStartTime)
  109. }
  110. if v.CouponEndTime > 0 {
  111. tmp["coupon_end_time"] = zhios_third_party_utils.IntToStr(v.CouponEndTime)
  112. }
  113. tmp["coupon_price"] = zhios_third_party_utils.Float64ToStr(float64(v.CouponDiscount) / 100)
  114. tmp["shop_name"] = v.MallName
  115. tmp["mall_id"] = zhios_third_party_utils.IntToStr(v.MallId)
  116. tmp["min_normal_price"] = zhios_third_party_utils.Float64ToStr(float64(v.MinNormalPrice) / 100)
  117. tmp["min_group_price"] = zhios_third_party_utils.Float64ToStr(float64(v.MinGroupPrice) / 100)
  118. //销量处理
  119. tmp["goods_sales"] = v.SalesTip
  120. if strings.Contains(tmp["goods_sales"], "万+") {
  121. tmp["goods_sales"] = strings.ReplaceAll(tmp["goods_sales"], "万+", "")
  122. tmp["goods_sales"] = zhios_third_party_utils.IntToStr(int(zhios_third_party_utils.StrToFloat64(tmp["goods_sales"]) * 10000))
  123. }
  124. if strings.Contains(tmp["goods_sales"], "万") {
  125. tmp["goods_sales"] = strings.ReplaceAll(tmp["goods_sales"], "万", "")
  126. tmp["goods_sales"] = zhios_third_party_utils.IntToStr(int(zhios_third_party_utils.StrToFloat64(tmp["goods_sales"]) * 10000))
  127. }
  128. tmp["goods_img"] = v.GoodsImageUrl
  129. tmp["goods_min_img"] = v.GoodsThumbnailUrl
  130. tmp["goods_desc"] = v.GoodsDesc
  131. tmp["goods_sign"] = v.GoodsSign
  132. data = append(data, tmp)
  133. }
  134. return data
  135. }
  136. func GetGoodsDetail(keyArr map[string]string, param map[string]interface{}) map[string]interface{} {
  137. send, _ := Send(keyArr, "pdd.ddk.oauth.goods.detail", param)
  138. var res cps_pdd.GoodsDetail
  139. json.Unmarshal([]byte(send), &res)
  140. data := make(map[string]interface{})
  141. for _, v := range res.GoodsDetailResponse.GoodsDetails {
  142. tmp := make(map[string]interface{})
  143. tmp["gid"] = zhios_third_party_utils.Int64ToStr(v.GoodsId)
  144. tmp["goods_title"] = v.GoodsName
  145. tmp["commission"] = zhios_third_party_utils.Float64ToStr(float64(v.PromotionRate) / 10)
  146. tmp["coupon_start_time"] = "0"
  147. tmp["coupon_end_time"] = "0"
  148. if v.CouponStartTime > 0 {
  149. tmp["coupon_start_time"] = zhios_third_party_utils.IntToStr(v.CouponStartTime)
  150. }
  151. if v.CouponEndTime > 0 {
  152. tmp["coupon_end_time"] = zhios_third_party_utils.IntToStr(v.CouponEndTime)
  153. }
  154. tmp["coupon_price"] = zhios_third_party_utils.Float64ToStr(float64(v.CouponDiscount) / 100)
  155. tmp["shop_name"] = v.MallName
  156. tmp["mall_id"] = zhios_third_party_utils.IntToStr(v.MallId)
  157. tmp["min_normal_price"] = zhios_third_party_utils.Float64ToStr(float64(v.MinNormalPrice) / 100)
  158. tmp["min_group_price"] = zhios_third_party_utils.Float64ToStr(float64(v.MinGroupPrice) / 100)
  159. //销量处理
  160. tmp["goods_sales"] = v.SalesTip
  161. if strings.Contains(zhios_third_party_utils.AnyToString(tmp["goods_sales"]), "万+") {
  162. tmp["goods_sales"] = strings.ReplaceAll(zhios_third_party_utils.AnyToString(tmp["goods_sales"]), "万+", "")
  163. tmp["goods_sales"] = zhios_third_party_utils.Float64ToStr(zhios_third_party_utils.StrToFloat64(zhios_third_party_utils.AnyToString(tmp["goods_sales"])) * 10000)
  164. }
  165. if strings.Contains(zhios_third_party_utils.AnyToString(tmp["goods_sales"]), "万") {
  166. tmp["goods_sales"] = strings.ReplaceAll(zhios_third_party_utils.AnyToString(tmp["goods_sales"]), "万", "")
  167. tmp["goods_sales"] = zhios_third_party_utils.Float64ToStr(zhios_third_party_utils.StrToFloat64(zhios_third_party_utils.AnyToString(tmp["goods_sales"])) * 10000)
  168. }
  169. tmp["goods_img"] = v.GoodsImageUrl
  170. tmp["goods_min_img"] = v.GoodsThumbnailUrl
  171. tmp["goods_desc"] = v.GoodsDesc
  172. tmp["goods_sign"] = v.GoodsSign
  173. if len(v.GoodsGalleryUrls) > 0 {
  174. tmp["goods_img_list"] = v.GoodsGalleryUrls
  175. }
  176. data = tmp
  177. }
  178. return data
  179. }