作者 tangxvhui
@@ -29,12 +29,13 @@ func NewMiniCompanySearchJoinedLogic(ctx context.Context, svcCtx *svc.ServiceCon @@ -29,12 +29,13 @@ func NewMiniCompanySearchJoinedLogic(ctx context.Context, svcCtx *svc.ServiceCon
29 29
30 func (l *MiniCompanySearchJoinedLogic) MiniCompanySearchJoined(req *types.CompanySearchRequest) (resp *types.CompanySearchResponse, err error) { 30 func (l *MiniCompanySearchJoinedLogic) MiniCompanySearchJoined(req *types.CompanySearchRequest) (resp *types.CompanySearchResponse, err error) {
31 var ( 31 var (
32 - conn = l.svcCtx.DefaultDBConn()  
33 - companyList []*domain.Company  
34 - total int64  
35 - userToken = contextdata.GetUserTokenFromCtx(l.ctx)  
36 - user *domain.User  
37 - companyIds []int64 32 + conn = l.svcCtx.DefaultDBConn()
  33 + companyList []*domain.Company
  34 + total int64
  35 + userToken = contextdata.GetUserTokenFromCtx(l.ctx)
  36 + user *domain.User
  37 + companyJoinedList []int64
  38 + companyJoiningList []int64
38 ) 39 )
39 queryOptions := domain.NewQueryOptions() 40 queryOptions := domain.NewQueryOptions()
40 if req.Page != 0 { 41 if req.Page != 0 {
@@ -53,15 +54,22 @@ func (l *MiniCompanySearchJoinedLogic) MiniCompanySearchJoined(req *types.Compan @@ -53,15 +54,22 @@ func (l *MiniCompanySearchJoinedLogic) MiniCompanySearchJoined(req *types.Compan
53 MustWithKV("auditStatus", []int{domain.UserAuditStatusPassed}). 54 MustWithKV("auditStatus", []int{domain.UserAuditStatusPassed}).
54 WithFindOnly()) 55 WithFindOnly())
55 lo.ForEach(users, func(item *domain.User, index int) { 56 lo.ForEach(users, func(item *domain.User, index int) {
56 - companyIds = append(companyIds, item.CompanyId) 57 + companyJoinedList = append(companyJoinedList, item.CompanyId)
  58 + })
  59 + _, users, _ = l.svcCtx.UserRepository.Find(l.ctx, conn, domain.NewQueryOptions().
  60 + MustWithKV("phone", user.Phone).
  61 + MustWithKV("auditStatus", []int{domain.UserAuditStatusWait}).
  62 + WithFindOnly())
  63 + lo.ForEach(users, func(item *domain.User, index int) {
  64 + companyJoiningList = append(companyJoiningList, item.CompanyId)
57 }) 65 })
58 if req.Flag == 1 { 66 if req.Flag == 1 {
59 - total, companyList, err = l.svcCtx.CompanyRepository.Find(l.ctx, conn, queryOptions.MustWithKV("ids", companyIds)) 67 + total, companyList, err = l.svcCtx.CompanyRepository.Find(l.ctx, conn, queryOptions.MustWithKV("ids", companyJoinedList))
60 if err != nil { 68 if err != nil {
61 return nil, xerr.NewErrMsgErr("公司列表获取失败", err) 69 return nil, xerr.NewErrMsgErr("公司列表获取失败", err)
62 } 70 }
63 } else if req.Flag == 2 { 71 } else if req.Flag == 2 {
64 - total, companyList, err = l.svcCtx.CompanyRepository.Find(l.ctx, conn, queryOptions.MustWithKV("excludeIds", companyIds)) 72 + total, companyList, err = l.svcCtx.CompanyRepository.Find(l.ctx, conn, queryOptions.MustWithKV("excludeIds", companyJoinedList))
65 if err != nil { 73 if err != nil {
66 return nil, xerr.NewErrMsgErr("公司列表获取失败", err) 74 return nil, xerr.NewErrMsgErr("公司列表获取失败", err)
67 } 75 }
@@ -73,9 +81,13 @@ func (l *MiniCompanySearchJoinedLogic) MiniCompanySearchJoined(req *types.Compan @@ -73,9 +81,13 @@ func (l *MiniCompanySearchJoinedLogic) MiniCompanySearchJoined(req *types.Compan
73 } 81 }
74 lo.ForEach(companyList, func(item *domain.Company, index int) { 82 lo.ForEach(companyList, func(item *domain.Company, index int) {
75 company := NewCompany(item) 83 company := NewCompany(item)
76 - if lo.Contains(companyIds, company.Id) { 84 + company.JoinedFlag = 2
  85 + if lo.Contains(companyJoinedList, company.Id) {
77 company.JoinedFlag = 1 86 company.JoinedFlag = 1
78 } 87 }
  88 + if lo.Contains(companyJoiningList, company.Id) {
  89 + company.JoinedFlag = 0
  90 + }
79 resp.List = append(resp.List, company) 91 resp.List = append(resp.List, company)
80 }) 92 })
81 resp.Total = total 93 resp.Total = total
@@ -171,8 +171,8 @@ func (repository *ArticleRepository) FindAuthorsLatestArticle(ctx context.Contex @@ -171,8 +171,8 @@ func (repository *ArticleRepository) FindAuthorsLatestArticle(ctx context.Contex
171 queryFunc := func() (interface{}, error) { 171 queryFunc := func() (interface{}, error) {
172 tx = tx.Model(&ms). 172 tx = tx.Model(&ms).
173 Where("company_id=?", companyId). 173 Where("company_id=?", companyId).
174 - Where("author_id in (?)", authors).  
175 - Where(fmt.Sprintf("target_user=0 or who_read @>'[%d]'", whoRead)). 174 + Where("author_id in (?)", append(authors, whoRead)). // 包含自己的文章
  175 + Where(fmt.Sprintf("author_id = %d or target_user=0 or who_read @>'[%d]'", whoRead, whoRead)).
176 Where("show = 1") 176 Where("show = 1")
177 if lastId > 0 { 177 if lastId > 0 {
178 tx.Where("id < ?", lastId) 178 tx.Where("id < ?", lastId)