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

haodanku.go 6.4 KiB

1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192
  1. package haodanku
  2. import (
  3. "code.fnuoos.com/go_rely_warehouse/zyos_go_third_party_api.git/md"
  4. "code.fnuoos.com/go_rely_warehouse/zyos_go_third_party_api.git/taobao"
  5. zhios_third_party_utils "code.fnuoos.com/go_rely_warehouse/zyos_go_third_party_api.git/utils"
  6. "encoding/json"
  7. "fmt"
  8. "github.com/tidwall/gjson"
  9. "strings"
  10. )
  11. func HaodankuFriendsCircleItems(params map[string]string) []map[string]string {
  12. var goods = make([]map[string]string, 0)
  13. reqNew, err := SendReqNew("http://v3.api.haodanku.com/friends_circle_items", params)
  14. if err != nil {
  15. return goods
  16. }
  17. data := gjson.Get(string(reqNew), "data").String()
  18. if data == "" {
  19. return goods
  20. }
  21. var oldGoods []md.HaodankuFriendsCircleItems
  22. json.Unmarshal([]byte(data), &oldGoods)
  23. for _, v := range oldGoods {
  24. v.Comment.CopyContent = strings.ReplaceAll(v.Comment.CopyContent, "<br>", "\r\n")
  25. var tmp = map[string]string{
  26. "gid": v.Items.Itemid,
  27. "title": v.Items.Itemshorttitle,
  28. "img": v.Items.Itempic,
  29. "sales": "",
  30. "price": v.Items.Itemendprice,
  31. "cost_price": v.Items.Itemprice,
  32. "coupon": v.Items.Couponmoney,
  33. "commission_rate": v.Items.Tkrates,
  34. "commission": v.Items.Tkmoney,
  35. "pvd": "taobao",
  36. "share_content": v.Comment.CopyContent,
  37. }
  38. goods = append(goods, tmp)
  39. }
  40. return goods
  41. }
  42. func HaodankuSelectedItem(params map[string]string) []map[string]string {
  43. var goods = make([]map[string]string, 0)
  44. reqNew, err := SendReqNew("http://v2.api.haodanku.com/selected_item", params)
  45. if err != nil {
  46. return goods
  47. }
  48. data := gjson.Get(string(reqNew), "data").String()
  49. if data == "" {
  50. return goods
  51. }
  52. var oldGoods []md.HaodankuSelectedItem
  53. json.Unmarshal([]byte(data), &oldGoods)
  54. for _, v := range oldGoods {
  55. content := v.CopyContent
  56. content = strings.ReplaceAll(content, "&lt;br&gt;", "\r\n")
  57. img := ""
  58. if len(v.Itempic) > 0 {
  59. img = v.Itempic[0]
  60. }
  61. var tmp = map[string]string{
  62. "gid": v.Itemid,
  63. "title": v.Title,
  64. "img": img,
  65. "sales": "",
  66. "price": v.Itemendprice,
  67. "cost_price": v.Itemprice,
  68. "coupon": v.Couponmoney,
  69. "commission_rate": v.Tkrates,
  70. "commission": zhios_third_party_utils.Float64ToStr(zhios_third_party_utils.StrToFloat64(v.Itemendprice) * (zhios_third_party_utils.StrToFloat64(v.Tkrates) / 100)),
  71. "pvd": "taobao",
  72. "share_content": content,
  73. }
  74. goods = append(goods, tmp)
  75. }
  76. return goods
  77. }
  78. func HaodankuTikTok(params map[string]string) []map[string]string {
  79. var goods = make([]map[string]string, 0)
  80. reqNew, err := SendReqNew("https://v3.api.haodanku.com/dy_rankitem_list", params)
  81. if err != nil {
  82. return goods
  83. }
  84. data := gjson.Get(string(reqNew), "data").String()
  85. if data == "" {
  86. return goods
  87. }
  88. var oldGoods []md.HaodankuTikTok
  89. json.Unmarshal([]byte(data), &oldGoods)
  90. for _, v := range oldGoods {
  91. var tmp = map[string]string{
  92. "gid": v.ProductID,
  93. "title": v.Itemshorttitle,
  94. "img": v.Itempic,
  95. "sales": "",
  96. "price": v.Itemendprice,
  97. "cost_price": v.Itemprice,
  98. "coupon": "",
  99. "commission_rate": zhios_third_party_utils.AnyToString(v.Dyrates),
  100. "commission": zhios_third_party_utils.Float64ToStr(zhios_third_party_utils.StrToFloat64(v.Itemendprice) * (zhios_third_party_utils.AnyToFloat64(v.Dyrates) / 100)),
  101. "pvd": md.PVD_TIKTOK,
  102. "share_content": "",
  103. }
  104. goods = append(goods, tmp)
  105. }
  106. return goods
  107. }
  108. func HaodankuTaobaoRankList(params map[string]string) []map[string]string {
  109. var goods = make([]map[string]string, 0)
  110. reqNew, err := SendReqNew("http://v2.api.haodanku.com/sales_list", params)
  111. if err != nil {
  112. return goods
  113. }
  114. data := gjson.Get(string(reqNew), "data").String()
  115. if data == "" {
  116. return goods
  117. }
  118. var oldGoods []md.HDKGoodsTaobaoRankList
  119. json.Unmarshal([]byte(data), &oldGoods)
  120. for _, v := range oldGoods {
  121. var tmp = map[string]string{
  122. "gid": v.Itemid,
  123. "title": v.Itemtitle,
  124. "img": v.Itempic,
  125. "sales": "",
  126. "price": v.Itemendprice,
  127. "cost_price": v.Itemprice,
  128. "coupon": v.Couponmoney,
  129. "commission_rate": zhios_third_party_utils.AnyToString(v.Tkrates),
  130. "commission": zhios_third_party_utils.Float64ToStr(zhios_third_party_utils.StrToFloat64(v.Itemendprice) * (zhios_third_party_utils.AnyToFloat64(v.Tkrates) / 100)),
  131. "pvd": "taobao",
  132. "share_content": "",
  133. }
  134. goods = append(goods, tmp)
  135. }
  136. return goods
  137. }
  138. // 好单库详情接口
  139. func HaodankuDetail(Id string) (res *taobao.Material, err error) {
  140. params := map[string]string{
  141. "version": "v2.0.0",
  142. "itemid": Id,
  143. }
  144. resp, err := SendReq("http://v2.api.haodanku.com/item_detail", params)
  145. if err != nil {
  146. return nil, err
  147. }
  148. var featuredList struct {
  149. Data md.HDKDetailStruct `json:"data"`
  150. }
  151. zhios_third_party_utils.Unserialize(resp, &featuredList)
  152. var imgs = strings.Split(featuredList.Data.TaobaoImage, ",")
  153. var Shoptype int
  154. if featuredList.Data.Shoptype == "B" {
  155. Shoptype = 1
  156. } else {
  157. Shoptype = 0
  158. }
  159. if strings.Contains(featuredList.Data.Itempic, "http") == false {
  160. featuredList.Data.Itempic = fmt.Sprintf("https:%s", featuredList.Data.Itempic)
  161. }
  162. var data = taobao.Material{
  163. CommissionRate: zhios_third_party_utils.Float64ToStr(zhios_third_party_utils.StrToFloat64(featuredList.Data.Tkrates) * 100),
  164. ItemDescription: featuredList.Data.Itemdesc,
  165. ItemID: featuredList.Data.Itemid,
  166. Nick: featuredList.Data.Shopname,
  167. PictURL: featuredList.Data.Itempic,
  168. SellerID: featuredList.Data.UserId,
  169. ShopTitle: featuredList.Data.Sellernick,
  170. Title: featuredList.Data.Itemtitle,
  171. TkTotalSales: featuredList.Data.Itemsale,
  172. Volume: zhios_third_party_utils.StrToInt(featuredList.Data.Itemsale),
  173. ZkFinalPrice: zhios_third_party_utils.Float64ToStr(zhios_third_party_utils.StrToFloat64(featuredList.Data.Itemendprice) + zhios_third_party_utils.StrToFloat64(featuredList.Data.Couponmoney)),
  174. ReservePrice: featuredList.Data.Itemprice,
  175. CouponAmount: featuredList.Data.Couponmoney,
  176. CouponEndTime: featuredList.Data.Couponendtime,
  177. CouponStartTime: featuredList.Data.Couponstarttime,
  178. ActivityId: featuredList.Data.Activityid,
  179. UserType: Shoptype,
  180. }
  181. data.SmallImages = struct {
  182. String []string `json:"string"`
  183. }(struct{ String []string }{String: imgs})
  184. res = &data
  185. return res, nil
  186. }