作者 tangxvhui
@@ -144,7 +144,9 @@ type( @@ -144,7 +144,9 @@ type(
144 AuthorId int64 `json:"authorId"` // 特定作者ID 144 AuthorId int64 `json:"authorId"` // 特定作者ID
145 LastArticleId int64 `json:"lastArticleId,optional"`// 最后文章ID 145 LastArticleId int64 `json:"lastArticleId,optional"`// 最后文章ID
146 Size int `json:"size"` // 数量 146 Size int `json:"size"` // 数量
147 - OrderByHotScore string `json:"orderByHotScore,options=asc|desc,optional,default=desc"` // 热度排序 升序 asc 降序 desc 147 + //OrderByHotScore string `json:"orderByHotScore,options=asc|desc,optional,default=desc"` // 热度排序 升序 asc 降序 desc
  148 + OrderByKey string `json:"orderByKey,options=HotScore|All|Time,optional,default=desc"` // 按规则排序 (热度:HotScore All:时间排序 Time:时间排序)
  149 + OrderByValue string `json:"orderByValue,options=asc||desc,optional"` // 排序值 升序 asc 降序 desc
148 Keywords string `json:"keywords,optional"` // 关键字 150 Keywords string `json:"keywords,optional"` // 关键字
149 BeginTime int64 `json:"beginTime,optional"`// 开始时间 151 BeginTime int64 `json:"beginTime,optional"`// 开始时间
150 EndTime int64 `json:"endTime,optional"`// 结束时间 152 EndTime int64 `json:"endTime,optional"`// 结束时间
@@ -54,8 +54,8 @@ func (l *MiniHomePageUserInfoLogic) MiniHomePageUserInfo(req *types.MiniHomePage @@ -54,8 +54,8 @@ func (l *MiniHomePageUserInfoLogic) MiniHomePageUserInfo(req *types.MiniHomePage
54 Enable: user.Enable, 54 Enable: user.Enable,
55 }, 55 },
56 TotalFollower: len(user.Follower), 56 TotalFollower: len(user.Follower),
57 - Followed: lo.Contains(currentUser.Following, user.Id),  
58 - MutualFollowed: lo.Contains(user.Following, currentUser.Id), 57 + Followed: currentUser.IsFollowed(user.Id),
  58 + MutualFollowed: currentUser.IsFriend(user.Id),
59 } 59 }
60 if company, _ := domain.LazyLoad(companyMap, l.ctx, conn, user.CompanyId, l.svcCtx.CompanyRepository.FindOne); company != nil { 60 if company, _ := domain.LazyLoad(companyMap, l.ctx, conn, user.CompanyId, l.svcCtx.CompanyRepository.FindOne); company != nil {
61 resp.User.CompanyName = company.Name 61 resp.User.CompanyName = company.Name
@@ -50,9 +50,17 @@ func (l *MiniHomepageUserNewsLogic) MiniHomepageUserNews(req *types.MiniHomepage @@ -50,9 +50,17 @@ func (l *MiniHomepageUserNewsLogic) MiniHomepageUserNews(req *types.MiniHomepage
50 queryOptions := domain.IndexCompanyId(userToken.CompanyId)(). 50 queryOptions := domain.IndexCompanyId(userToken.CompanyId)().
51 WithKV("beginTime", req.BeginTime). 51 WithKV("beginTime", req.BeginTime).
52 WithKV("endTime", req.EndTime). 52 WithKV("endTime", req.EndTime).
53 - WithKV("keywords", req.Keywords).  
54 - WithKV("orderByHotScore", req.OrderByHotScore)  
55 - 53 + WithKV("keywords", req.Keywords)
  54 + if len(req.OrderByKey) > 0 && len(req.OrderByValue) > 0 {
  55 + switch req.OrderByKey {
  56 + case "HotScore":
  57 + queryOptions.WithKV("orderByHotScore", req.OrderByValue)
  58 + case "All":
  59 + queryOptions.WithKV("orderByAll", req.OrderByValue)
  60 + case "Time":
  61 + queryOptions.WithKV("orderByAll", req.OrderByValue)
  62 + }
  63 + }
56 var users = []int64{req.AuthorId} 64 var users = []int64{req.AuthorId}
57 if _, articles, err = l.svcCtx.ArticleRepository.FindAuthorsLatestArticle(l.ctx, conn, user.CompanyId, users, currentUser.Id, req.LastArticleId, req.Size, queryOptions.Copy().WithFindOnly()); err != nil { 65 if _, articles, err = l.svcCtx.ArticleRepository.FindAuthorsLatestArticle(l.ctx, conn, user.CompanyId, users, currentUser.Id, req.LastArticleId, req.Size, queryOptions.Copy().WithFindOnly()); err != nil {
58 return nil, xerr.NewErrMsgErr("获取快讯异常", err) 66 return nil, xerr.NewErrMsgErr("获取快讯异常", err)
@@ -76,7 +76,7 @@ func follower(ctx context.Context, svcCtx *svc.ServiceContext, user *domain.User @@ -76,7 +76,7 @@ func follower(ctx context.Context, svcCtx *svc.ServiceContext, user *domain.User
76 Avatar: foundUser.Avatar, 76 Avatar: foundUser.Avatar,
77 Position: foundUser.Position, 77 Position: foundUser.Position,
78 Followed: true, 78 Followed: true,
79 - MutualFollowed: lo.Contains(user.Following, item), 79 + MutualFollowed: user.IsFriend(item),
80 }) 80 })
81 } 81 }
82 }) 82 })
@@ -64,6 +64,7 @@ func (l *MiniAtUsersListLogic) MiniAtUsersList(req *types.MiniUsersListRequest) @@ -64,6 +64,7 @@ func (l *MiniAtUsersListLogic) MiniAtUsersList(req *types.MiniUsersListRequest)
64 Name: item.Name, 64 Name: item.Name,
65 PinYinName: item.PinYinName, 65 PinYinName: item.PinYinName,
66 Avatar: item.Avatar, 66 Avatar: item.Avatar,
  67 + Position: item.Position,
67 }) 68 })
68 }) 69 })
69 return map[string]interface{}{ 70 return map[string]interface{}{
@@ -488,7 +488,8 @@ type MiniHomepageUserNewsRequest struct { @@ -488,7 +488,8 @@ type MiniHomepageUserNewsRequest struct {
488 AuthorId int64 `json:"authorId"` // 特定作者ID 488 AuthorId int64 `json:"authorId"` // 特定作者ID
489 LastArticleId int64 `json:"lastArticleId,optional"` // 最后文章ID 489 LastArticleId int64 `json:"lastArticleId,optional"` // 最后文章ID
490 Size int `json:"size"` // 数量 490 Size int `json:"size"` // 数量
491 - OrderByHotScore string `json:"orderByHotScore,options=asc|desc,optional,default=desc"` // 热度排序 升序 asc 降序 desc 491 + OrderByKey string `json:"orderByKey,options=HotScore|All|Time,optional,default=desc"` // 按规则排序 (热度:HotScore All:时间排序 Time:时间排序)
  492 + OrderByValue string `json:"orderByValue,options=asc||desc,optional"`
492 Keywords string `json:"keywords,optional"` // 关键字 493 Keywords string `json:"keywords,optional"` // 关键字
493 BeginTime int64 `json:"beginTime,optional"` // 开始时间 494 BeginTime int64 `json:"beginTime,optional"` // 开始时间
494 EndTime int64 `json:"endTime,optional"` // 结束时间 495 EndTime int64 `json:"endTime,optional"` // 结束时间
@@ -234,6 +234,8 @@ func (repository *ArticleRepository) FindAuthorsLatestArticle(ctx context.Contex @@ -234,6 +234,8 @@ func (repository *ArticleRepository) FindAuthorsLatestArticle(ctx context.Contex
234 } 234 }
235 if v, ok := queryOptions["orderByHotScore"]; ok { 235 if v, ok := queryOptions["orderByHotScore"]; ok {
236 tx.Order(fmt.Sprintf("(count_comment+count_love) %v", v)) 236 tx.Order(fmt.Sprintf("(count_comment+count_love) %v", v))
  237 + } else if v, ok := queryOptions["orderByAll"]; ok {
  238 + tx.Order(fmt.Sprintf("id %v", v))
237 } else { 239 } else {
238 tx.Order("id desc") 240 tx.Order("id desc")
239 } 241 }
@@ -136,6 +136,15 @@ func (m *User) WithName(name string) *User { @@ -136,6 +136,15 @@ func (m *User) WithName(name string) *User {
136 return m 136 return m
137 } 137 }
138 138
  139 +func (m *User) IsFollowed(userId int64) bool {
  140 + return lo.Contains(m.Following, userId)
  141 +}
  142 +
  143 +// IsFriend 如果是好友,为互相关注
  144 +func (m *User) IsFriend(userId int64) bool {
  145 + return lo.Contains(m.Following, userId) && lo.Contains(m.Follower, userId)
  146 +}
  147 +
139 type ( 148 type (
140 LoginCreator interface { 149 LoginCreator interface {
141 WechatLogin(r WechatLoginRequest) (*LoginInfo, error) 150 WechatLogin(r WechatLoginRequest) (*LoginInfo, error)