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.
159 lines
4.3 KiB
159 lines
4.3 KiB
5 years ago
|
package recook
|
||
|
|
||
|
import (
|
||
|
"errors"
|
||
|
"net/url"
|
||
|
"strconv"
|
||
|
)
|
||
|
|
||
|
const (
|
||
|
actionTrendList = "/live/trend/list"
|
||
|
actionTrendInfo = "/live/trend/info"
|
||
|
actionTrendInfos = "/live/trend/infos"
|
||
|
actionTrendGoods = "/live/trend/goods"
|
||
|
actionTrendAddShort = "/live/trend/addshort"
|
||
|
actionTrendChange = "/live/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"`
|
||
|
}
|
||
|
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) 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); 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:"user_id" json:"userId"`
|
||
|
OriginId uint `mapstructure:"trend_id" json:"originId"`
|
||
|
TrendType int `mapstructure:"trend_type" json:"trendType"`
|
||
|
CreatedAt string `mapstructure:"created_at" json:"createdAt"`
|
||
|
UpdatedAt string `mapstructure:"updated_at" json:"updatedAt"`
|
||
|
IsShow int `mapstructure:"is_show" 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
|
||
|
}
|