golang 的 rabbitmq 消费项目
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.

featured.go 11 KiB

6 months ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309
  1. package taobao
  2. import (
  3. "applet/app/utils"
  4. "applet/app/utils/cachesecond"
  5. "applet/app/utils/logx"
  6. "encoding/json"
  7. "errors"
  8. "fmt"
  9. "github.com/tidwall/gjson"
  10. "time"
  11. )
  12. type DgOptimusMaterialStruct struct {
  13. TbkDgOptimusMaterialResponse struct {
  14. ResultList struct {
  15. MapData []TBFeatureStruct `json:"map_data"`
  16. } `json:"result_list"`
  17. } `json:"tbk_dg_optimus_material_response"`
  18. }
  19. type dgTbkDgMaterialRecommendResponse struct {
  20. TbkDgMaterialRecommendResponse struct {
  21. ResultList struct {
  22. MapData []NewMarterial `json:"result_list"`
  23. }
  24. IsDefault string `json:"is_default"`
  25. TotalCount int `json:"total_count"`
  26. UvidMsg string `json:"uvid_msg"`
  27. } `json:"tbk_dg_material_recommend_response"`
  28. }
  29. type ScOptimusMaterialStruct struct {
  30. TbkScOptimusMaterialResponse struct {
  31. ResultList struct {
  32. MapData []TBFeatureStruct `json:"map_data"`
  33. } `json:"result_list"`
  34. } `json:"tbk_sc_optimus_material_response"`
  35. }
  36. type scTbkScMaterialRecommendResponse struct {
  37. TbkScMaterialRecommendResponse struct {
  38. ResultList struct {
  39. MapData []NewMarterial `json:"map_data"`
  40. } `json:"result_list"`
  41. } `json:"tbk_sc_material_recommend_response"`
  42. }
  43. type TBFeatureStruct struct {
  44. CategoryID int `json:"category_id"`
  45. CategoryName string `json:"category_name"`
  46. ClickURL string `json:"click_url"`
  47. CommissionRate string `json:"commission_rate"`
  48. CouponAmount float64 `json:"coupon_amount"`
  49. CouponClickURL string `json:"coupon_click_url"`
  50. CouponEndTime string `json:"coupon_end_time"`
  51. GoodsCoupon string `json:"goods_coupon"`
  52. CouponRemainCount int `json:"coupon_remain_count"`
  53. CouponShareURL string `json:"coupon_share_url"`
  54. CouponStartFee string `json:"coupon_start_fee"`
  55. CouponStartTime string `json:"coupon_start_time"`
  56. CouponTotalCount int `json:"coupon_total_count"`
  57. ItemDescription string `json:"item_description"`
  58. ItemID interface{} `json:"item_id"`
  59. JhsPriceUspList string `json:"jhs_price_usp_list"`
  60. LevelOneCategoryID int `json:"level_one_category_id"`
  61. LevelOneCategoryName string `json:"level_one_category_name"`
  62. Nick string `json:"nick"`
  63. PictURL string `json:"pict_url"`
  64. ReservePrice string `json:"reserve_price"`
  65. SellerID int64 `json:"seller_id"`
  66. ShopTitle string `json:"shop_title"`
  67. ShortTitle string `json:"short_title"`
  68. SmallImages struct {
  69. String []string `json:"string"`
  70. } `json:"small_images"`
  71. SubTitle string `json:"sub_title"`
  72. Title string `json:"title"`
  73. UserType int `json:"user_type"`
  74. Volume int `json:"volume"`
  75. WhiteImage string `json:"white_image"`
  76. ZkFinalPrice string `json:"zk_final_price"`
  77. }
  78. type TBSearchFeatureStruct struct {
  79. CategoryID int `json:"category_id"`
  80. CategoryName string `json:"category_name"`
  81. ClickURL string `json:"click_url"`
  82. CommissionRate string `json:"commission_rate"`
  83. CouponAmount string `json:"coupon_amount"`
  84. CouponClickURL string `json:"coupon_click_url"`
  85. CouponEndTime string `json:"coupon_end_time"`
  86. CouponRemainCount int `json:"coupon_remain_count"`
  87. CouponShareURL string `json:"coupon_share_url"`
  88. CouponStartFee string `json:"coupon_start_fee"`
  89. CouponStartTime string `json:"coupon_start_time"`
  90. CouponTotalCount int `json:"coupon_total_count"`
  91. ItemDescription string `json:"item_description"`
  92. ItemID interface{} `json:"item_id"`
  93. JhsPriceUspList string `json:"jhs_price_usp_list"`
  94. LevelOneCategoryID int `json:"level_one_category_id"`
  95. LevelOneCategoryName string `json:"level_one_category_name"`
  96. Nick string `json:"nick"`
  97. PictURL string `json:"pict_url"`
  98. ReservePrice string `json:"reserve_price"`
  99. SellerID int64 `json:"seller_id"`
  100. ShopTitle string `json:"shop_title"`
  101. ShortTitle string `json:"short_title"`
  102. SmallImages struct {
  103. String []string `json:"string"`
  104. } `json:"small_images"`
  105. SubTitle string `json:"sub_title"`
  106. Title string `json:"title"`
  107. UserType int `json:"user_type"`
  108. Volume int `json:"volume"`
  109. WhiteImage string `json:"white_image"`
  110. ZkFinalPrice string `json:"zk_final_price"`
  111. }
  112. type TBKShopData struct {
  113. UserId string `json:"user_id"`
  114. PictUrl string `json:"pict_url"`
  115. }
  116. type Autogenerated struct {
  117. TbkShopGetResponse struct {
  118. Results struct {
  119. NTbkShop []TBKShopData `json:"n_tbk_shop"`
  120. } `json:"results"`
  121. TotalResults int `json:"total_results"`
  122. RequestID string `json:"request_id"`
  123. } `json:"tbk_shop_get_response"`
  124. }
  125. // 淘宝客-推广者-店铺搜索
  126. // https://open.taobao.com/api.htm?spm=a219a.7386797.0.0.6180669aZ2HyFi&source=search&docId=24521&docType=2
  127. // taobao.tbk.shop.get
  128. func (t *TB) TBKShopGet(SellerId, Nick string) (*TBKShopData, error) {
  129. var res *TBKShopData
  130. var Autogenerated struct {
  131. TbkShopGetResponse struct {
  132. Results struct {
  133. NTbkShop []struct {
  134. PictURL string `json:"pict_url"`
  135. UserID interface{} `json:"user_id"`
  136. } `json:"n_tbk_shop"`
  137. } `json:"results"`
  138. TotalResults int `json:"total_results"`
  139. RequestID string `json:"request_id"`
  140. } `json:"tbk_shop_get_response"`
  141. }
  142. cacheKey := fmt.Sprintf("tb_shop_get:%s", Nick)
  143. err := cachesecond.GetJson(cacheKey, &res)
  144. if err != nil || res == nil {
  145. method := "taobao.tbk.shop.get"
  146. Sid := t.SID
  147. if t.AuthType == 1 {
  148. Sid = t.UserSID
  149. }
  150. args := map[string]string{
  151. "fields": "user_id,pict_url",
  152. "q": Nick,
  153. "page_no": "1",
  154. "page_size": "20",
  155. "session": Sid,
  156. }
  157. resp, err := send(args, method, t.User_Web_AK, t.User_Web_SK)
  158. if err != nil {
  159. return nil, err
  160. }
  161. if gjson.GetBytes(resp, "error_response.sub_msg").String() != "" {
  162. return nil, logx.Warn(errors.New("Not Result"))
  163. //return nil, logx.Warn(errors.New(gjson.GetBytes(resp, "error_response.sub_msg").String()))
  164. }
  165. var data TBKShopData
  166. utils.Unserialize(resp, &Autogenerated)
  167. for _, v := range Autogenerated.TbkShopGetResponse.Results.NTbkShop {
  168. if utils.AnyToString(utils.AnyToInt64(v.UserID)) == SellerId {
  169. data.UserId = utils.AnyToString(utils.AnyToInt64(v.UserID))
  170. data.PictUrl = v.PictURL
  171. }
  172. }
  173. res = &data
  174. if data.UserId != "" {
  175. cachesecond.SetJson(cacheKey, res, 60*3)
  176. }
  177. }
  178. return res, nil
  179. }
  180. // 精选列表(淘宝客-服务商-物料精选)
  181. // https://open.taobao.com/api.htm?spm=a219a.7386797.0.0.1f6f669aNUCptn&source=search&docId=37884&docType=2
  182. // TODO 物料id查找 https://market.m.taobao.com/app/qn/toutiao-new/index-pc.html#/detail/10628875?_k=gpov9a
  183. func (t *TB) Featured(pageIndex, pageSize, materialID, deviceValue, gid string) (*[]TBFeatureStruct, error) {
  184. var resp []byte
  185. method := "taobao.tbk.dg.material.recommend"
  186. //判断是否跟随官方 如果是官方的要用服务商接口
  187. Sid := t.SID
  188. if t.AuthType == 1 {
  189. method = "taobao.tbk.sc.material.recommend"
  190. Sid = t.UserSID
  191. }
  192. args := map[string]string{
  193. "material_id": materialID,
  194. "page_no": pageIndex,
  195. "page_size": pageSize,
  196. "session": Sid,
  197. }
  198. if deviceValue != "" {
  199. args["device_value"] = deviceValue
  200. args["device_type"] = "UTDID"
  201. }
  202. if gid != "" {
  203. args["item_id"] = gid
  204. }
  205. _, args["site_id"], args["adzone_id"] = SplitPid(t.SelfPromoIdWeb)
  206. fmt.Println(args)
  207. resp, _ = send(args, method, t.Web_AK, t.Web_SK)
  208. fmt.Println("======淘宝=====", string(resp))
  209. if gjson.GetBytes(resp, "error_response.sub_msg").String() != "" {
  210. return nil, logx.Warn(errors.New("Not Result"))
  211. //return nil, logx.Warn(errors.New(gjson.GetBytes(resp, "error_response.sub_msg").String()))
  212. }
  213. if t.AuthType == 1 {
  214. var tmp = scTbkScMaterialRecommendResponse{}
  215. err := json.Unmarshal(resp, &tmp)
  216. fmt.Println(err)
  217. if len(tmp.TbkScMaterialRecommendResponse.ResultList.MapData) == 0 {
  218. return nil, logx.Warn(resp)
  219. }
  220. data := tmp.TbkScMaterialRecommendResponse.ResultList.MapData
  221. list := make([]TBFeatureStruct, 0)
  222. for _, v := range data {
  223. tmp1 := TBFeatureStruct{
  224. CategoryID: v.ItemBasicInfo.CategoryId,
  225. CategoryName: v.ItemBasicInfo.CategoryName,
  226. CommissionRate: v.PublishInfo.IncomeRate,
  227. ItemID: v.ItemId,
  228. Nick: v.ItemBasicInfo.ShopTitle,
  229. PictURL: v.ItemBasicInfo.PictUrl,
  230. SellerID: int64(v.ItemBasicInfo.SellerId),
  231. ShopTitle: v.ItemBasicInfo.ShopTitle,
  232. ShortTitle: v.ItemBasicInfo.ShortTitle,
  233. Title: v.ItemBasicInfo.Title,
  234. ZkFinalPrice: v.PricePromotionInfo.ZkFinalPrice,
  235. ReservePrice: v.PricePromotionInfo.ReservePrice,
  236. Volume: v.ItemBasicInfo.Volume,
  237. }
  238. tmp1.SmallImages.String = []string{tmp1.PictURL}
  239. if utils.StrToFloat64(v.PricePromotionInfo.FinalPromotionPrice) > 0 {
  240. for _, v1 := range v.PricePromotionInfo.FinalPromotionPathList.FinalPromotionPathMapData {
  241. tmp1.CouponAmount = utils.StrToFloat64(v1.PromotionFee) + tmp1.CouponAmount
  242. tmp1.CouponStartTime = utils.IntToStr(utils.StrToInt(v1.PromotionStartTime) / 1000)
  243. tmp1.CouponEndTime = utils.IntToStr(utils.StrToInt(v1.PromotionEndTime) / 1000)
  244. if v1.PromotionTitle == "商品券" || v1.PromotionTitle == "店铺券" {
  245. if utils.StrToInt64(v1.PromotionEndTime)/1000 > time.Now().Unix() {
  246. tmp1.GoodsCoupon = "1"
  247. }
  248. }
  249. }
  250. }
  251. list = append(list, tmp1)
  252. }
  253. return &list, nil
  254. } else {
  255. var tmp = dgTbkDgMaterialRecommendResponse{}
  256. utils.Unserialize(resp, &tmp)
  257. if len(tmp.TbkDgMaterialRecommendResponse.ResultList.MapData) == 0 {
  258. return nil, logx.Warn(resp)
  259. }
  260. data := tmp.TbkDgMaterialRecommendResponse.ResultList.MapData
  261. list := make([]TBFeatureStruct, 0)
  262. for _, v := range data {
  263. tmp1 := TBFeatureStruct{
  264. CategoryID: v.ItemBasicInfo.CategoryId,
  265. CategoryName: v.ItemBasicInfo.CategoryName,
  266. CommissionRate: v.PublishInfo.IncomeRate,
  267. ItemID: v.ItemId,
  268. Nick: v.ItemBasicInfo.ShopTitle,
  269. PictURL: v.ItemBasicInfo.PictUrl,
  270. SellerID: int64(v.ItemBasicInfo.SellerId),
  271. ShopTitle: v.ItemBasicInfo.ShopTitle,
  272. ShortTitle: v.ItemBasicInfo.ShortTitle,
  273. Title: v.ItemBasicInfo.Title,
  274. ZkFinalPrice: v.PricePromotionInfo.ZkFinalPrice,
  275. ReservePrice: v.PricePromotionInfo.ReservePrice,
  276. Volume: v.ItemBasicInfo.Volume,
  277. }
  278. tmp1.SmallImages.String = []string{tmp1.PictURL}
  279. if utils.StrToFloat64(v.PricePromotionInfo.FinalPromotionPrice) > 0 {
  280. for _, v1 := range v.PricePromotionInfo.FinalPromotionPathList.FinalPromotionPathMapData {
  281. tmp1.CouponAmount = utils.StrToFloat64(v1.PromotionFee) + tmp1.CouponAmount
  282. tmp1.CouponStartTime = utils.IntToStr(utils.StrToInt(v1.PromotionStartTime) / 1000)
  283. tmp1.CouponEndTime = utils.IntToStr(utils.StrToInt(v1.PromotionEndTime) / 1000)
  284. if v1.PromotionTitle == "商品券" || v1.PromotionTitle == "店铺券" {
  285. if utils.StrToInt64(v1.PromotionEndTime)/1000 > time.Now().Unix() {
  286. tmp1.GoodsCoupon = "1"
  287. }
  288. }
  289. }
  290. }
  291. list = append(list, tmp1)
  292. }
  293. return &list, nil
  294. }
  295. }