package recook import ( "errors" "net/url" "strconv" ) const ( actionTrendList = "/lives/trend/list" actionTrendInfo = "/lives/trend/info" actionTrendInfos = "/lives/trend/infos" actionTrendGoods = "/lives/trend/goods" actionTrendAddShort = "/lives/trend/addshort" actionTrendChange = "/lives/trend/change" ) type trend struct { } var Trend = &trend{} type TrendGoods struct { ID uint `json:"id"` MainPhotoURL string `json:"mainPhotoURL"` Name string `json:"name"` Price string `json:"price"` } type Short struct { MediaUrl string `json:"media_url"` CoverUrl string `json:"cover_url"` } type TrendItem struct { Content string `json:"content"` Goods TrendGoods `json:"goods"` ID uint `json:"id"` ImgList []struct { Height uint `json:"height"` ID uint `json:"id"` MomentsCopyID uint `json:"momentsCopyId"` URL string `json:"url"` Width uint `json:"width"` } `json:"imgList"` OriginID uint `json:"originId"` TrendType int `json:"trendType"` UpdatedAt string `json:"updatedAt"` Short Short `json:"short"` Praise uint `json:"praise"` IsPraise uint `json:"isPraise"` TopicId uint `json:"topicId"` TopicName string `json:"topicName"` } type TrendList struct { List []TrendItem `json:"list"` Total int64 `json:"total"` } // @Title 获取会员动态列表 func (t *trend) GetList(userId uint, page, limit int) (result *TrendList) { result = &TrendList{} if err := RecookClient.Exec(actionTrendList, url.Values{ "userId": []string{strconv.FormatUint(uint64(userId), 10)}, "page": []string{strconv.Itoa(page)}, "limit": []string{strconv.Itoa(limit)}, }, result); err != nil { return } return } // @Title 获取动态商品信息 func (t *trend) GetGoods(goodsIds []uint) (result map[uint]TrendGoods) { result = map[uint]TrendGoods{} if len(goodsIds) == 0 { return } strIds := []string{} for _, id := range goodsIds { strIds = append(strIds, strconv.FormatUint(uint64(id), 10)) } if err := RecookClient.Exec(actionTrendGoods, url.Values{ "goodsIds": strIds, }, &result); err != nil { return } return } // @Title 添加会员动态 func (t *trend) AddTrend(userId, originId uint, trendType, isShow int, id, token, deviceType string) error { result := "" if userId <= 0 || originId <= 0 || trendType <= 0 { return errors.New("参数错误") } if err := RecookClient.Exec(actionTrendAddShort, url.Values{ "userId": []string{strconv.FormatUint(uint64(userId), 10)}, "originId": []string{strconv.FormatUint(uint64(originId), 10)}, "trendType": []string{strconv.Itoa(trendType)}, "isShow": []string{strconv.Itoa(isShow)}, }, &result, map[string]string{ "X-Recook-ID": id, "X-Recook-Token": token, "Device-Type": deviceType, }); err != nil { return err } return nil } // @Title 更改会员动态是否显示 func (t *trend) Change(userId, originId uint, trendType, isShow int) error { result := "" if userId <= 0 || originId <= 0 || trendType <= 0 { return errors.New("参数错误") } if err := RecookClient.Exec(actionTrendChange, url.Values{ "userId": []string{strconv.FormatUint(uint64(userId), 10)}, "originId": []string{strconv.FormatUint(uint64(originId), 10)}, "trendType": []string{strconv.Itoa(trendType)}, "isShow": []string{strconv.Itoa(isShow)}, }, &result); err != nil { return err } return nil } type TrendInfo struct { Id uint `mapstructure:"id" json:"id"` UserId uint `mapstructure:"userId" json:"userId"` OriginId uint `mapstructure:"originId" json:"originId"` TrendType int `mapstructure:"trendType" json:"trendType"` CreatedAt string `mapstructure:"createdAt" json:"createdAt"` UpdatedAt string `mapstructure:"updatedAt" json:"updatedAt"` IsShow int `mapstructure:"isShow" json:"isShow"` } // 获取单个详情 func (t *trend) Info(trendId uint) (result *TrendInfo) { result = &TrendInfo{} if err := RecookClient.Exec(actionTrendInfo, url.Values{ "trendId": []string{strconv.FormatUint(uint64(trendId), 10)}, }, result); err != nil { return } return } // 批量获取详情 func (t *trend) Infos(originIds []uint, trendType int) (result *[]TrendInfo) { result = &[]TrendInfo{} if len(originIds) == 0 { return } strIds := []string{} for _, id := range originIds { strIds = append(strIds, strconv.FormatUint(uint64(id), 10)) } if err := RecookClient.Exec(actionTrendInfos, url.Values{ "originIds": strIds, "trendType": []string{strconv.Itoa(trendType)}, }, result); err != nil { return } return }