正在显示
22 个修改的文件
包含
350 行增加
和
73 行删除
@@ -12,6 +12,8 @@ | @@ -12,6 +12,8 @@ | ||
12 | |机会评论列表|完成|2019.11.21|/v1/chance/comments| | 12 | |机会评论列表|完成|2019.11.21|/v1/chance/comments| |
13 | |我来评论|完成|2019.11.21|/v1/chance/iComment| | 13 | |我来评论|完成|2019.11.21|/v1/chance/iComment| |
14 | |我的评论|完成|2019.11.21|/v1/chance/iComments| | 14 | |我的评论|完成|2019.11.21|/v1/chance/iComments| |
15 | +|评论详情-继续评论| |2019.11.21|/v1/chance/commentDetailsMulti| | ||
16 | +|评论详情-不能评论| |2019.11.21|/v1/chance/commentDetailsSingle| | ||
15 | |我的点赞| |2019.11.|v1/chance/favorite| | 17 | |我的点赞| |2019.11.|v1/chance/favorite| |
16 | |我的收藏| |2019.11.|v1/chance/favorite| | 18 | |我的收藏| |2019.11.|v1/chance/favorite| |
17 | |消息中心|完成|2019.11.|v1/message/messageCenter| | 19 | |消息中心|完成|2019.11.|v1/message/messageCenter| |
@@ -90,7 +90,8 @@ func GetRequestHeader(ctx *context.Context) *protocol.RequestHeader { | @@ -90,7 +90,8 @@ func GetRequestHeader(ctx *context.Context) *protocol.RequestHeader { | ||
90 | if h.Uid == 0 { | 90 | if h.Uid == 0 { |
91 | h.Uid, _ = strconv.ParseInt(ctx.Input.Header("x-mmm-uid"), 10, 64) | 91 | h.Uid, _ = strconv.ParseInt(ctx.Input.Header("x-mmm-uid"), 10, 64) |
92 | } | 92 | } |
93 | - h.CompanyId, _ = strconv.ParseInt(ctx.Input.Header("x-mmm-companyid"), 10, 64) | 93 | + h.CompanyId, _ = strconv.ParseInt(ctx.Input.Header("x-mmm-cid"), 10, 64) |
94 | + log.Debug(common.AssertJson(h)) | ||
94 | return h | 95 | return h |
95 | } | 96 | } |
96 | 97 | ||
@@ -179,6 +180,7 @@ func CheckToken(ctx *context.Context) (result bool) { | @@ -179,6 +180,7 @@ func CheckToken(ctx *context.Context) (result bool) { | ||
179 | if rsp.UserInfo != nil { | 180 | if rsp.UserInfo != nil { |
180 | //设置附加数据 | 181 | //设置附加数据 |
181 | ctx.Request.Header.Add("x-mmm-uid", fmt.Sprintf("%v", rsp.UserInfo.UserId)) | 182 | ctx.Request.Header.Add("x-mmm-uid", fmt.Sprintf("%v", rsp.UserInfo.UserId)) |
183 | + ctx.Request.Header.Add("x-mmm-cid", fmt.Sprintf("%v", rsp.UserInfo.CurrentCompanyId)) | ||
182 | } | 184 | } |
183 | } | 185 | } |
184 | return | 186 | return |
@@ -72,6 +72,7 @@ func (this *ChanceController) Comments() { | @@ -72,6 +72,7 @@ func (this *ChanceController) Comments() { | ||
72 | return | 72 | return |
73 | } | 73 | } |
74 | header := controllers.GetRequestHeader(this.Ctx) | 74 | header := controllers.GetRequestHeader(this.Ctx) |
75 | + request.SourceType = protocol.SourceType_Chance | ||
75 | msg = protocol.NewReturnResponse(chance.Comments(header, request)) | 76 | msg = protocol.NewReturnResponse(chance.Comments(header, request)) |
76 | } | 77 | } |
77 | 78 | ||
@@ -95,3 +96,45 @@ func (this *ChanceController) Favorite() { | @@ -95,3 +96,45 @@ func (this *ChanceController) Favorite() { | ||
95 | header := controllers.GetRequestHeader(this.Ctx) | 96 | header := controllers.GetRequestHeader(this.Ctx) |
96 | msg = protocol.NewReturnResponse(chance.Favorite(header, request)) | 97 | msg = protocol.NewReturnResponse(chance.Favorite(header, request)) |
97 | } | 98 | } |
99 | + | ||
100 | +//CommentDetailsSingle | ||
101 | +//@router /commentDetailsSingle [post] | ||
102 | +func (this *ChanceController) CommentDetailsSingle() { | ||
103 | + var msg *protocol.ResponseMessage | ||
104 | + defer func() { | ||
105 | + this.Resp(msg) | ||
106 | + }() | ||
107 | + var request *protocol.CommentDetailsSingleRequest | ||
108 | + if err := json.Unmarshal(this.ByteBody, &request); err != nil { | ||
109 | + log.Error(err) | ||
110 | + msg = protocol.BadRequestParam(1) | ||
111 | + return | ||
112 | + } | ||
113 | + if b, m := this.Valid(request); !b { | ||
114 | + msg = m | ||
115 | + return | ||
116 | + } | ||
117 | + header := controllers.GetRequestHeader(this.Ctx) | ||
118 | + msg = protocol.NewReturnResponse(chance.CommentDetailsSingle(header, request)) | ||
119 | +} | ||
120 | + | ||
121 | +//CommentDetailsMulti | ||
122 | +//@router /commentDetailsMulti [post] | ||
123 | +func (this *ChanceController) CommentDetailsMulti() { | ||
124 | + var msg *protocol.ResponseMessage | ||
125 | + defer func() { | ||
126 | + this.Resp(msg) | ||
127 | + }() | ||
128 | + var request *protocol.CommentDetailsMultiRequest | ||
129 | + if err := json.Unmarshal(this.ByteBody, &request); err != nil { | ||
130 | + log.Error(err) | ||
131 | + msg = protocol.BadRequestParam(1) | ||
132 | + return | ||
133 | + } | ||
134 | + if b, m := this.Valid(request); !b { | ||
135 | + msg = m | ||
136 | + return | ||
137 | + } | ||
138 | + header := controllers.GetRequestHeader(this.Ctx) | ||
139 | + msg = protocol.NewReturnResponse(chance.CommentDetailsMulti(header, request)) | ||
140 | +} |
@@ -16,6 +16,7 @@ func (r *ChanceRepository) GetChanceById(id int64) (v *models.Chance, err error) | @@ -16,6 +16,7 @@ func (r *ChanceRepository) GetChanceById(id int64) (v *models.Chance, err error) | ||
16 | 16 | ||
17 | type IChanceFavoriteRepository interface { | 17 | type IChanceFavoriteRepository interface { |
18 | GetChanceFavorites(userId, companyId int64, objectType, chanceType int, lastId int64, pageSize int) (v []*models.ChanceFavorite, total int, err error) | 18 | GetChanceFavorites(userId, companyId int64, objectType, chanceType int, lastId int64, pageSize int) (v []*models.ChanceFavorite, total int, err error) |
19 | + ExitsChanceFavorite(userId, companyId int64, sourceId int64, objectType int) (exits bool, err error) | ||
19 | } | 20 | } |
20 | 21 | ||
21 | var _ IChanceFavoriteRepository = (*ChanceFavoriteRepository)(nil) | 22 | var _ IChanceFavoriteRepository = (*ChanceFavoriteRepository)(nil) |
@@ -25,3 +26,6 @@ type ChanceFavoriteRepository struct{} | @@ -25,3 +26,6 @@ type ChanceFavoriteRepository struct{} | ||
25 | func (r *ChanceFavoriteRepository) GetChanceFavorites(userId, companyId int64, objectType, chanceType int, lastId int64, pageSize int) (v []*models.ChanceFavorite, total int, err error) { | 26 | func (r *ChanceFavoriteRepository) GetChanceFavorites(userId, companyId int64, objectType, chanceType int, lastId int64, pageSize int) (v []*models.ChanceFavorite, total int, err error) { |
26 | return models.GetChanceFavorites(userId, companyId, objectType, chanceType, lastId, pageSize) | 27 | return models.GetChanceFavorites(userId, companyId, objectType, chanceType, lastId, pageSize) |
27 | } | 28 | } |
29 | +func (r *ChanceFavoriteRepository) ExitsChanceFavorite(userId, companyId int64, sourceId int64, objectType int) (exits bool, err error) { | ||
30 | + return models.ExitsChanceFavorite(userId, companyId, sourceId, objectType) | ||
31 | +} |
@@ -3,13 +3,13 @@ package repository | @@ -3,13 +3,13 @@ package repository | ||
3 | import "opp/models" | 3 | import "opp/models" |
4 | 4 | ||
5 | type ICommendRepository interface { | 5 | type ICommendRepository interface { |
6 | - GetCommends(companyId int, llastId int, pageSize int) (v []*models.Commend, total int, err error) | 6 | + GetCommends(companyId int64, llastId int, pageSize int) (v []*models.Commend, total int, err error) |
7 | } | 7 | } |
8 | 8 | ||
9 | var _ ICommendRepository = (*CommendRepository)(nil) | 9 | var _ ICommendRepository = (*CommendRepository)(nil) |
10 | 10 | ||
11 | type CommendRepository struct{} | 11 | type CommendRepository struct{} |
12 | 12 | ||
13 | -func (r *CommendRepository) GetCommends(companyId int, lastId int, pageSize int) (v []*models.Commend, total int, err error) { | 13 | +func (r *CommendRepository) GetCommends(companyId int64, lastId int, pageSize int) (v []*models.Commend, total int, err error) { |
14 | return models.GetCommends(companyId, lastId, pageSize) | 14 | return models.GetCommends(companyId, lastId, pageSize) |
15 | } | 15 | } |
@@ -5,7 +5,7 @@ import "opp/models" | @@ -5,7 +5,7 @@ import "opp/models" | ||
5 | type ICommentRepository interface { | 5 | type ICommentRepository interface { |
6 | GetCommentById(id int64) (v *models.Comment, err error) | 6 | GetCommentById(id int64) (v *models.Comment, err error) |
7 | AddComment(m *models.Comment) (id int64, err error) | 7 | AddComment(m *models.Comment) (id int64, err error) |
8 | - GetComments(userId int64, sourceType int, sourceId int64, lastId int, pageSize int) (v []*models.Comment, total int, err error) | 8 | + GetComments(userId int64, sourceType int, sourceId int64, lastId int64, pageSize int) (v []*models.Comment, total int, err error) |
9 | } | 9 | } |
10 | 10 | ||
11 | var _ ICommentRepository = (*CommentRepository)(nil) | 11 | var _ ICommentRepository = (*CommentRepository)(nil) |
@@ -20,6 +20,6 @@ func (r *CommentRepository) AddComment(m *models.Comment) (id int64, err error) | @@ -20,6 +20,6 @@ func (r *CommentRepository) AddComment(m *models.Comment) (id int64, err error) | ||
20 | return models.AddComment(m) | 20 | return models.AddComment(m) |
21 | } | 21 | } |
22 | 22 | ||
23 | -func (r *CommentRepository) GetComments(userId int64, sourceType int, sourceId int64, lastId int, pageSize int) (v []*models.Comment, total int, err error) { | 23 | +func (r *CommentRepository) GetComments(userId int64, sourceType int, sourceId int64, lastId int64, pageSize int) (v []*models.Comment, total int, err error) { |
24 | return models.GetComments(userId, sourceType, sourceId, lastId, pageSize) | 24 | return models.GetComments(userId, sourceType, sourceId, lastId, pageSize) |
25 | } | 25 | } |
@@ -15,6 +15,7 @@ var ( | @@ -15,6 +15,7 @@ var ( | ||
15 | ChanceFavorite IChanceFavoriteRepository | 15 | ChanceFavorite IChanceFavoriteRepository |
16 | Comment ICommentRepository | 16 | Comment ICommentRepository |
17 | Message IMessageRepository | 17 | Message IMessageRepository |
18 | + UserCompany IUserCompanyRepository | ||
18 | ) | 19 | ) |
19 | 20 | ||
20 | func init() { | 21 | func init() { |
@@ -32,6 +33,7 @@ func InitRepository() { | @@ -32,6 +33,7 @@ func InitRepository() { | ||
32 | Comment = &CommentRepository{} | 33 | Comment = &CommentRepository{} |
33 | Message = &MessageRepository{} | 34 | Message = &MessageRepository{} |
34 | ChanceFavorite = &ChanceFavoriteRepository{} | 35 | ChanceFavorite = &ChanceFavoriteRepository{} |
36 | + UserCompany = &UserCompanyRepository{} | ||
35 | } | 37 | } |
36 | 38 | ||
37 | func InitRepositoryMock() { | 39 | func InitRepositoryMock() { |
@@ -23,3 +23,15 @@ func (r *UserRepository) GetUsersByMobile(mobile string) (v *models.User, err er | @@ -23,3 +23,15 @@ func (r *UserRepository) GetUsersByMobile(mobile string) (v *models.User, err er | ||
23 | func (r *UserRepository) UpdateUserInfo(m *models.User) (err error) { | 23 | func (r *UserRepository) UpdateUserInfo(m *models.User) (err error) { |
24 | return models.UpdateUsersById(m) | 24 | return models.UpdateUsersById(m) |
25 | } | 25 | } |
26 | + | ||
27 | +type IUserCompanyRepository interface { | ||
28 | + GetUserCompanyByUserId(uid int64, companyId int64) (v *models.UserCompany, err error) | ||
29 | +} | ||
30 | + | ||
31 | +var _ IUserCompanyRepository = (*UserCompanyRepository)(nil) | ||
32 | + | ||
33 | +type UserCompanyRepository struct{} | ||
34 | + | ||
35 | +func (r *UserCompanyRepository) GetUserCompanyByUserId(uid int64, companyId int64) (v *models.UserCompany, err error) { | ||
36 | + return models.GetUserCompanyByUserId(uid, companyId) | ||
37 | +} |
@@ -82,7 +82,7 @@ func DeleteChanceFavorite(id int64) (err error) { | @@ -82,7 +82,7 @@ func DeleteChanceFavorite(id int64) (err error) { | ||
82 | func GetChanceFavorites(userId, companyId int64, objectType, chanceType int, lastId int64, pageSize int) (v []*ChanceFavorite, total int, err error) { | 82 | func GetChanceFavorites(userId, companyId int64, objectType, chanceType int, lastId int64, pageSize int) (v []*ChanceFavorite, total int, err error) { |
83 | sql := mybeego.NewSqlExutor().Table("chance_favorite").Order("create_at desc") | 83 | sql := mybeego.NewSqlExutor().Table("chance_favorite").Order("create_at desc") |
84 | sql.Where(fmt.Sprintf("user_id=%d", userId)) | 84 | sql.Where(fmt.Sprintf("user_id=%d", userId)) |
85 | - sql.Where(fmt.Sprintf("company_id=%d", userId)) | 85 | + sql.Where(fmt.Sprintf("company_id=%d", companyId)) |
86 | if chanceType > 0 { | 86 | if chanceType > 0 { |
87 | sql.Where(fmt.Sprintf("chance_type=%d", chanceType)) | 87 | sql.Where(fmt.Sprintf("chance_type=%d", chanceType)) |
88 | } | 88 | } |
@@ -102,3 +102,13 @@ func GetChanceFavorites(userId, companyId int64, objectType, chanceType int, las | @@ -102,3 +102,13 @@ func GetChanceFavorites(userId, companyId int64, objectType, chanceType int, las | ||
102 | return | 102 | return |
103 | 103 | ||
104 | } | 104 | } |
105 | + | ||
106 | +func ExitsChanceFavorite(userId, companyId int64, sourceId int64, objectType int) (exits bool, err error) { | ||
107 | + sql := mybeego.NewSqlExutor().Table("chance_favorite") | ||
108 | + sql.Where(fmt.Sprintf("source_id=%d", sourceId)). | ||
109 | + Where(fmt.Sprintf("user_id=%d", userId)). | ||
110 | + Where(fmt.Sprintf("company_id=%d", companyId)). | ||
111 | + Where(fmt.Sprintf("(object_type&%d)>0", objectType)). | ||
112 | + Where(fmt.Sprintf("enable_status=1")) | ||
113 | + return sql.QueryExists() | ||
114 | +} |
@@ -12,10 +12,10 @@ import ( | @@ -12,10 +12,10 @@ import ( | ||
12 | ) | 12 | ) |
13 | 13 | ||
14 | type Commend struct { | 14 | type Commend struct { |
15 | - Id int64 `orm:"column(id);auto" description:"表彰编号"` | 15 | + Id int64 `orm:"column(id);auto" description:"表彰编号"` |
16 | Content string `orm:"column(content);size(255)" description:"表彰内容"` | 16 | Content string `orm:"column(content);size(255)" description:"表彰内容"` |
17 | CommendAt time.Time `orm:"column(commend_at);type(timestamp)" description:"表彰时间"` | 17 | CommendAt time.Time `orm:"column(commend_at);type(timestamp)" description:"表彰时间"` |
18 | - UserId int64 `orm:"column(user_id)" description:"表user.id 表彰用户id"` | 18 | + UserId int64 `orm:"column(user_id)" description:"表user.id 表彰用户id"` |
19 | CompanyId int64 `orm:"column(company_id)" description:"表company.id 公司id"` | 19 | CompanyId int64 `orm:"column(company_id)" description:"表company.id 公司id"` |
20 | CreateAt time.Time `orm:"column(create_at);type(timestamp);auto_now_add" description:"创建时间"` | 20 | CreateAt time.Time `orm:"column(create_at);type(timestamp);auto_now_add" description:"创建时间"` |
21 | EnableStatus int8 `orm:"column(enable_status)" description:"状态 1可见 2不可见"` | 21 | EnableStatus int8 `orm:"column(enable_status)" description:"状态 1可见 2不可见"` |
@@ -156,14 +156,14 @@ func DeleteCommend(id int64) (err error) { | @@ -156,14 +156,14 @@ func DeleteCommend(id int64) (err error) { | ||
156 | return | 156 | return |
157 | } | 157 | } |
158 | 158 | ||
159 | -func GetCommends(companyId int,lastId int,pageSize int)(v []*Commend,total int, err error) { | ||
160 | - sql :=mybeego.NewSqlExutor().Table("commend").Order("create_at desc") | ||
161 | - sql.Where(fmt.Sprintf("company_id=%d",companyId)) | ||
162 | - if pageSize>0{ | ||
163 | - sql.Limit(0,pageSize) | 159 | +func GetCommends(companyId int64, lastId int, pageSize int) (v []*Commend, total int, err error) { |
160 | + sql := mybeego.NewSqlExutor().Table("commend").Order("create_at desc") | ||
161 | + sql.Where(fmt.Sprintf("company_id=%d", companyId)) | ||
162 | + if pageSize > 0 { | ||
163 | + sql.Limit(0, pageSize) | ||
164 | } | 164 | } |
165 | - if lastId>0{ | ||
166 | - sql.Where(fmt.Sprintf("id>%d",lastId)) | 165 | + if lastId > 0 { |
166 | + sql.Where(fmt.Sprintf("id>%d", lastId)) | ||
167 | } | 167 | } |
168 | if total, err = sql.Querys(&v); err == nil { | 168 | if total, err = sql.Querys(&v); err == nil { |
169 | return | 169 | return |
@@ -3,6 +3,7 @@ package models | @@ -3,6 +3,7 @@ package models | ||
3 | import ( | 3 | import ( |
4 | "errors" | 4 | "errors" |
5 | "fmt" | 5 | "fmt" |
6 | + "gitlab.fjmaimaimai.com/mmm-go/gocomm/pkg/log" | ||
6 | "gitlab.fjmaimaimai.com/mmm-go/gocomm/pkg/mybeego" | 7 | "gitlab.fjmaimaimai.com/mmm-go/gocomm/pkg/mybeego" |
7 | "reflect" | 8 | "reflect" |
8 | "strings" | 9 | "strings" |
@@ -158,7 +159,7 @@ func DeleteComment(id int64) (err error) { | @@ -158,7 +159,7 @@ func DeleteComment(id int64) (err error) { | ||
158 | return | 159 | return |
159 | } | 160 | } |
160 | 161 | ||
161 | -func GetComments(userId int64, sourceType int, sourceId int64, lastId int, pageSize int) (v []*Comment, total int, err error) { | 162 | +func GetComments(userId int64, sourceType int, sourceId int64, lastId int64, pageSize int) (v []*Comment, total int, err error) { |
162 | sql := mybeego.NewSqlExutor().Table("comment").Order("create_at desc") | 163 | sql := mybeego.NewSqlExutor().Table("comment").Order("create_at desc") |
163 | if userId > 0 { | 164 | if userId > 0 { |
164 | sql.Where(fmt.Sprintf("user_id=%d", userId)) | 165 | sql.Where(fmt.Sprintf("user_id=%d", userId)) |
@@ -176,7 +177,11 @@ func GetComments(userId int64, sourceType int, sourceId int64, lastId int, pageS | @@ -176,7 +177,11 @@ func GetComments(userId int64, sourceType int, sourceId int64, lastId int, pageS | ||
176 | sql.Where(fmt.Sprintf("id>%d", lastId)) | 177 | sql.Where(fmt.Sprintf("id>%d", lastId)) |
177 | } | 178 | } |
178 | if total, err = sql.Querys(&v); err == nil { | 179 | if total, err = sql.Querys(&v); err == nil { |
180 | + if total == 0 { | ||
181 | + log.Debug(sql.Strings()) | ||
182 | + } | ||
179 | return | 183 | return |
180 | } | 184 | } |
185 | + | ||
181 | return | 186 | return |
182 | } | 187 | } |
@@ -11,13 +11,13 @@ import ( | @@ -11,13 +11,13 @@ import ( | ||
11 | ) | 11 | ) |
12 | 12 | ||
13 | type Company struct { | 13 | type Company struct { |
14 | - Id int64 `orm:"column(id);auto"` | ||
15 | - Name string `orm:"column(name);size(40)"` | ||
16 | - UserId int64 `orm:"column(user_id)"` | ||
17 | - CreateAt time.Time `orm:"column(create_at);type(timestamp);auto_now"` | ||
18 | - UpdateAt time.Time `orm:"column(update_at);type(timestamp)"` | ||
19 | - DeleteAt time.Time `orm:"column(delete_at);type(timestamp)"` | ||
20 | - Logo string `orm:"column(logo);size(255)"` | 14 | + Id int64 `orm:"column(id);auto"` |
15 | + Name string `orm:"column(name);size(40)" description:"公司名称"` | ||
16 | + Logo string `orm:"column(logo);size(255)" description:"公司log地址"` | ||
17 | + AdminId int64 `orm:"column(admin_id)" description:"管理员用户id"` | ||
18 | + CreateAt time.Time `orm:"column(create_at);type(timestamp);auto_now" description:"创建时间"` | ||
19 | + UpdateAt time.Time `orm:"column(update_at);type(timestamp)" description:"更新时间"` | ||
20 | + DeleteAt time.Time `orm:"column(delete_at);type(timestamp)" description:"删除时间"` | ||
21 | } | 21 | } |
22 | 22 | ||
23 | func (t *Company) TableName() string { | 23 | func (t *Company) TableName() string { |
@@ -11,14 +11,20 @@ import ( | @@ -11,14 +11,20 @@ import ( | ||
11 | ) | 11 | ) |
12 | 12 | ||
13 | type UserAuth struct { | 13 | type UserAuth struct { |
14 | - Id int `orm:"column(id);auto"` | ||
15 | - UserId int64 `orm:"column(user_id)" description:"表user.id "` | ||
16 | - RefreshToken string `orm:"column(refresh_token);size(64)" description:"refresh token "` | ||
17 | - RefreshTokenExp time.Time `orm:"column(refresh_token_exp);type(timestamp);auto_now_add" description:"refresh token 过期时间"` | ||
18 | - AccessToken string `orm:"column(access_token);size(64)" description:"access_token "` | ||
19 | - AccessTokenExp time.Time `orm:"column(access_token_exp);type(timestamp);auto_now_add" description:"access token 过期时间"` | ||
20 | - AuthCode string `orm:"column(auth_code);size(64)" description:"auth_code"` | ||
21 | - AuthCodeExp time.Time `orm:"column(auth_code_exp);type(timestamp);auto_now_add" description:"auth_code过期时间"` | 14 | + Id int `orm:"column(id);auto" description:"唯一编号"` |
15 | + UserId int64 `orm:"column(user_id)" description:"表user.id "` | ||
16 | + RefreshToken string `orm:"column(refresh_token);size(64)" description:"refresh token "` | ||
17 | + RefreshTokenExp time.Time `orm:"column(refresh_token_exp);type(timestamp)" description:"refresh token 过期时间"` | ||
18 | + AccessToken string `orm:"column(access_token);size(64)" description:"access_token "` | ||
19 | + AccessTokenExp time.Time `orm:"column(access_token_exp);type(timestamp)" description:"access token 过期时间"` | ||
20 | + AuthCode string `orm:"column(auth_code);size(64)" description:"auth_code"` | ||
21 | + AuthCodeExp time.Time `orm:"column(auth_code_exp);type(timestamp)" description:"auth_code过期时间"` | ||
22 | + DeviceType int8 `orm:"column(device_type)" description:"设备类型 0:ios 1:安卓 2:web "` | ||
23 | + ClientId string `orm:"column(client_id);size(100)" description:"设备识别码 推送标识"` | ||
24 | + DeviceToken string `orm:"column(device_token);size(100)" description:"设备识别码 推送标识"` | ||
25 | + CreateAt time.Time `orm:"column(create_at);type(timestamp)" description:"创建时间"` | ||
26 | + UpdateAt time.Time `orm:"column(update_at);type(timestamp)" description:"更新时间"` | ||
27 | + CurrentCompanyId int64 `orm:"column(current_company_id)" description:"当前登录的公司id "` | ||
22 | } | 28 | } |
23 | 29 | ||
24 | func (t *UserAuth) TableName() string { | 30 | func (t *UserAuth) TableName() string { |
models/user_company.go
0 → 100644
1 | +package models | ||
2 | + | ||
3 | +import ( | ||
4 | + "fmt" | ||
5 | + "time" | ||
6 | + | ||
7 | + "github.com/astaxie/beego/orm" | ||
8 | +) | ||
9 | + | ||
10 | +type UserCompany struct { | ||
11 | + Id int `orm:"column(id);auto" description:"唯一标识"` | ||
12 | + CompanyId int64 `orm:"column(company_id)" description:"表company.id 公司编号"` | ||
13 | + UserId int64 `orm:"column(user_id)" description:"表user.id 用户编号"` | ||
14 | + DepartmentId int `orm:"column(department_id)" description:"部门id"` | ||
15 | + PositionId int `orm:"column(position_id)" description:"职位id"` | ||
16 | + ChanceTotal int `orm:"column(chance_total)" description:"发表机会数"` | ||
17 | + CommentTotal int `orm:"column(comment_total)" description:"发表评论总数"` | ||
18 | + CreateAt time.Time `orm:"column(create_at);type(timestamp)" description:"创建时间"` | ||
19 | + UpdateAt time.Time `orm:"column(update_at);type(timestamp)" description:"更新时间"` | ||
20 | +} | ||
21 | + | ||
22 | +func (t *UserCompany) TableName() string { | ||
23 | + return "user_company" | ||
24 | +} | ||
25 | + | ||
26 | +func init() { | ||
27 | + orm.RegisterModel(new(UserCompany)) | ||
28 | +} | ||
29 | + | ||
30 | +// AddUserCompany insert a new UserCompany into database and returns | ||
31 | +// last inserted Id on success. | ||
32 | +func AddUserCompany(m *UserCompany) (id int64, err error) { | ||
33 | + o := orm.NewOrm() | ||
34 | + id, err = o.Insert(m) | ||
35 | + return | ||
36 | +} | ||
37 | + | ||
38 | +// GetUserCompanyById retrieves UserCompany by Id. Returns error if | ||
39 | +// Id doesn't exist | ||
40 | +func GetUserCompanyById(id int) (v *UserCompany, err error) { | ||
41 | + o := orm.NewOrm() | ||
42 | + v = &UserCompany{Id: id} | ||
43 | + if err = o.Read(v); err == nil { | ||
44 | + return v, nil | ||
45 | + } | ||
46 | + return nil, err | ||
47 | +} | ||
48 | + | ||
49 | +// UpdateUserCompany updates UserCompany by Id and returns error if | ||
50 | +// the record to be updated doesn't exist | ||
51 | +func UpdateUserCompanyById(m *UserCompany) (err error) { | ||
52 | + o := orm.NewOrm() | ||
53 | + v := UserCompany{Id: m.Id} | ||
54 | + // ascertain id exists in the database | ||
55 | + if err = o.Read(&v); err == nil { | ||
56 | + var num int64 | ||
57 | + if num, err = o.Update(m); err == nil { | ||
58 | + fmt.Println("Number of records updated in database:", num) | ||
59 | + } | ||
60 | + } | ||
61 | + return | ||
62 | +} | ||
63 | + | ||
64 | +// DeleteUserCompany deletes UserCompany by Id and returns error if | ||
65 | +// the record to be deleted doesn't exist | ||
66 | +func DeleteUserCompany(id int) (err error) { | ||
67 | + o := orm.NewOrm() | ||
68 | + v := UserCompany{Id: id} | ||
69 | + // ascertain id exists in the database | ||
70 | + if err = o.Read(&v); err == nil { | ||
71 | + var num int64 | ||
72 | + if num, err = o.Delete(&UserCompany{Id: id}); err == nil { | ||
73 | + fmt.Println("Number of records deleted in database:", num) | ||
74 | + } | ||
75 | + } | ||
76 | + return | ||
77 | +} | ||
78 | + | ||
79 | +// GetUserAuthById retrieves UserAuth by Id. Returns error if | ||
80 | +// Id doesn't exist | ||
81 | +func GetUserCompanyByUserId(uid int64, companyId int64) (v *UserCompany, err error) { | ||
82 | + o := orm.NewOrm() | ||
83 | + sql := "select * from user_company where user_id=? and company_id=?" // | ||
84 | + if err = o.Raw(sql, uid, companyId).QueryRow(&v); err == nil { | ||
85 | + return v, nil | ||
86 | + } | ||
87 | + return nil, err | ||
88 | +} |
@@ -11,14 +11,14 @@ import ( | @@ -11,14 +11,14 @@ import ( | ||
11 | ) | 11 | ) |
12 | 12 | ||
13 | type User struct { | 13 | type User struct { |
14 | - Id int64 `orm:"column(id);pk" description:"用户id"` | ||
15 | - NickName string `orm:"column(nick_name);size(100)" description:"昵称"` | ||
16 | - Phone string `orm:"column(phone);size(40)" description:"手机号码"` | ||
17 | - Passwd string `orm:"column(passwd);size(128)" description:"密码"` | ||
18 | - Icon string `orm:"column(icon);size(255)" description:"头像"` | ||
19 | - CompanyId int `orm:"column(company_id)" description:"公司Id"` | ||
20 | - DepartmentId int `orm:"column(department_id)" description:"部门id"` | ||
21 | - PositionId int `orm:"column(position_id)" description:"职位id"` | 14 | + Id int64 `orm:"column(id);pk" description:"用户id"` |
15 | + NickName string `orm:"column(nick_name);size(100)" description:"昵称"` | ||
16 | + Phone string `orm:"column(phone);size(40)" description:"手机号码"` | ||
17 | + Passwd string `orm:"column(passwd);size(128)" description:"密码"` | ||
18 | + Icon string `orm:"column(icon);size(255)" description:"头像"` | ||
19 | + //CompanyId int `orm:"column(company_id)" description:"公司Id"` | ||
20 | + //DepartmentId int `orm:"column(department_id)" description:"部门id"` | ||
21 | + //PositionId int `orm:"column(position_id)" description:"职位id"` | ||
22 | CsAccount int64 `orm:"column(cs_account)" description:"客服有话说ID"` | 22 | CsAccount int64 `orm:"column(cs_account)" description:"客服有话说ID"` |
23 | IsKefu int8 `orm:"column(is_kefu)" description:"是否是客服 0:否 1:是"` | 23 | IsKefu int8 `orm:"column(is_kefu)" description:"是否是客服 0:否 1:是"` |
24 | ImToken string `orm:"column(im_token);size(128)" description:"网易云token"` | 24 | ImToken string `orm:"column(im_token);size(128)" description:"网易云token"` |
@@ -6,8 +6,9 @@ import "opp/models" | @@ -6,8 +6,9 @@ import "opp/models" | ||
6 | 6 | ||
7 | //用户基础聚合 | 7 | //用户基础聚合 |
8 | type UserBaseInfoAggregation struct { | 8 | type UserBaseInfoAggregation struct { |
9 | - User *models.User | ||
10 | - Company *models.Company | ||
11 | - Department *models.Department | ||
12 | - Position *models.Position | 9 | + User *models.User |
10 | + Company *models.Company | ||
11 | + Department *models.Department | ||
12 | + Position *models.Position | ||
13 | + UserCompany *models.UserCompany | ||
13 | } | 14 | } |
@@ -20,8 +20,8 @@ type ICommentResponse struct { | @@ -20,8 +20,8 @@ type ICommentResponse struct { | ||
20 | 20 | ||
21 | /*IComments */ | 21 | /*IComments */ |
22 | type ICommentsRequest struct { | 22 | type ICommentsRequest struct { |
23 | - LastId int `json:"lastId"` | ||
24 | - PageSize int `json:"pageSize" valid:"Required"` | 23 | + LastId int64 `json:"lastId"` |
24 | + PageSize int `json:"pageSize" valid:"Required"` | ||
25 | } | 25 | } |
26 | type ICommentsResponse struct { | 26 | type ICommentsResponse struct { |
27 | Comments []*IComments `json:"comments"` | 27 | Comments []*IComments `json:"comments"` |
@@ -35,9 +35,10 @@ type IComments struct { | @@ -35,9 +35,10 @@ type IComments struct { | ||
35 | 35 | ||
36 | /*机会评论*/ | 36 | /*机会评论*/ |
37 | type CommentsRequest struct { | 37 | type CommentsRequest struct { |
38 | - LastId int `json:"lastId"` | ||
39 | - PageSize int `json:"pageSize" valid:"Required"` | ||
40 | - SourceId int64 `json:"id" valid:"Required"` | 38 | + LastId int64 `json:"lastId"` |
39 | + PageSize int `json:"pageSize" valid:"Required"` | ||
40 | + SourceId int64 `json:"id" valid:"Required"` | ||
41 | + SourceType int | ||
41 | } | 42 | } |
42 | type CommentsResponse struct { | 43 | type CommentsResponse struct { |
43 | Total int `json:"total"` | 44 | Total int `json:"total"` |
@@ -53,4 +54,24 @@ type Comments struct { | @@ -53,4 +54,24 @@ type Comments struct { | ||
53 | CommentTotal int `json:"commentTotal"` | 54 | CommentTotal int `json:"commentTotal"` |
54 | ZanTotal int `json:"zanTotal"` | 55 | ZanTotal int `json:"zanTotal"` |
55 | CreateTime int64 `json:"createTime"` | 56 | CreateTime int64 `json:"createTime"` |
57 | + IsZan int `json:"is_zan"` //0:未点赞 1:点赞 | ||
58 | +} | ||
59 | + | ||
60 | +/*CommentDetailsMulti */ | ||
61 | +type CommentDetailsMultiRequest struct { | ||
62 | + SourceId int64 `json:"cid"` | ||
63 | + LastId int64 `json:"commentLastId"` | ||
64 | + PageSize int `json:"commentPageSize" valid:"Required"` | ||
65 | +} | ||
66 | +type CommentDetailsMultiResponse struct { | ||
67 | + Comment *Comments `json:"comment"` | ||
68 | + Comments []*Comments `json:"comments"` | ||
69 | +} | ||
70 | + | ||
71 | +/*CommentDetailsSingle */ | ||
72 | +type CommentDetailsSingleRequest struct { | ||
73 | + Id int64 `json:"cid" valid:"Required"` | ||
74 | +} | ||
75 | +type CommentDetailsSingleResponse struct { | ||
76 | + Comment *Comments `json:"comment"` | ||
56 | } | 77 | } |
@@ -49,6 +49,22 @@ func init() { | @@ -49,6 +49,22 @@ func init() { | ||
49 | 49 | ||
50 | beego.GlobalControllerRouter["opp/controllers/v1:ChanceController"] = append(beego.GlobalControllerRouter["opp/controllers/v1:ChanceController"], | 50 | beego.GlobalControllerRouter["opp/controllers/v1:ChanceController"] = append(beego.GlobalControllerRouter["opp/controllers/v1:ChanceController"], |
51 | beego.ControllerComments{ | 51 | beego.ControllerComments{ |
52 | + Method: "CommentDetailsMulti", | ||
53 | + Router: `/commentDetailsMulti`, | ||
54 | + AllowHTTPMethods: []string{"post"}, | ||
55 | + MethodParams: param.Make(), | ||
56 | + Params: nil}) | ||
57 | + | ||
58 | + beego.GlobalControllerRouter["opp/controllers/v1:ChanceController"] = append(beego.GlobalControllerRouter["opp/controllers/v1:ChanceController"], | ||
59 | + beego.ControllerComments{ | ||
60 | + Method: "CommentDetailsSingle", | ||
61 | + Router: `/commentDetailsSingle`, | ||
62 | + AllowHTTPMethods: []string{"post"}, | ||
63 | + MethodParams: param.Make(), | ||
64 | + Params: nil}) | ||
65 | + | ||
66 | + beego.GlobalControllerRouter["opp/controllers/v1:ChanceController"] = append(beego.GlobalControllerRouter["opp/controllers/v1:ChanceController"], | ||
67 | + beego.ControllerComments{ | ||
52 | Method: "Comments", | 68 | Method: "Comments", |
53 | Router: `/comments`, | 69 | Router: `/comments`, |
54 | AllowHTTPMethods: []string{"post"}, | 70 | AllowHTTPMethods: []string{"post"}, |
@@ -8,18 +8,21 @@ import ( | @@ -8,18 +8,21 @@ import ( | ||
8 | "sync" | 8 | "sync" |
9 | ) | 9 | ) |
10 | 10 | ||
11 | -func GetUserBaseInfoAggregation(uid int64) (v *protocol.UserBaseInfoAggregation, err error) { | 11 | +func GetUserBaseInfoAggregation(uid int64, companyId int64) (v *protocol.UserBaseInfoAggregation, err error) { |
12 | v = &protocol.UserBaseInfoAggregation{} | 12 | v = &protocol.UserBaseInfoAggregation{} |
13 | var wg sync.WaitGroup | 13 | var wg sync.WaitGroup |
14 | if v.User, err = repository.User.GetUsersById(uid); err != nil { | 14 | if v.User, err = repository.User.GetUsersById(uid); err != nil { |
15 | log.Error(err) | 15 | log.Error(err) |
16 | return | 16 | return |
17 | } | 17 | } |
18 | + if v.UserCompany, err = repository.UserCompany.GetUserCompanyByUserId(uid, companyId); err != nil { | ||
19 | + log.Error(err) | ||
20 | + return | ||
21 | + } | ||
18 | wg.Add(3) | 22 | wg.Add(3) |
19 | - | ||
20 | go func() { | 23 | go func() { |
21 | defer wg.Done() | 24 | defer wg.Done() |
22 | - if v.Company, err = repository.Company.GetCompanyById(int64(v.User.CompanyId)); err != nil { | 25 | + if v.Company, err = repository.Company.GetCompanyById(int64(v.UserCompany.CompanyId)); err != nil { |
23 | log.Error(err) | 26 | log.Error(err) |
24 | return | 27 | return |
25 | } | 28 | } |
@@ -27,7 +30,7 @@ func GetUserBaseInfoAggregation(uid int64) (v *protocol.UserBaseInfoAggregation, | @@ -27,7 +30,7 @@ func GetUserBaseInfoAggregation(uid int64) (v *protocol.UserBaseInfoAggregation, | ||
27 | 30 | ||
28 | go func() { | 31 | go func() { |
29 | defer wg.Done() | 32 | defer wg.Done() |
30 | - if v.Department, err = repository.Department.GetDepartmentById(v.User.DepartmentId); err != nil { | 33 | + if v.Department, err = repository.Department.GetDepartmentById(v.UserCompany.DepartmentId); err != nil { |
31 | log.Error(err) | 34 | log.Error(err) |
32 | return | 35 | return |
33 | } | 36 | } |
@@ -35,7 +38,7 @@ func GetUserBaseInfoAggregation(uid int64) (v *protocol.UserBaseInfoAggregation, | @@ -35,7 +38,7 @@ func GetUserBaseInfoAggregation(uid int64) (v *protocol.UserBaseInfoAggregation, | ||
35 | 38 | ||
36 | go func() { | 39 | go func() { |
37 | defer wg.Done() | 40 | defer wg.Done() |
38 | - if v.Position, err = repository.Position.GetPositionById(v.User.PositionId); err != nil { | 41 | + if v.Position, err = repository.Position.GetPositionById(v.UserCompany.PositionId); err != nil { |
39 | log.Error(err) | 42 | log.Error(err) |
40 | return | 43 | return |
41 | } | 44 | } |
@@ -44,11 +47,11 @@ func GetUserBaseInfoAggregation(uid int64) (v *protocol.UserBaseInfoAggregation, | @@ -44,11 +47,11 @@ func GetUserBaseInfoAggregation(uid int64) (v *protocol.UserBaseInfoAggregation, | ||
44 | return | 47 | return |
45 | } | 48 | } |
46 | 49 | ||
47 | -func GetUserBaseInfo(uid int64) (v *protocol.BaseUserInfo, err error) { | 50 | +func GetUserBaseInfo(uid int64, companyId int64) (v *protocol.BaseUserInfo, err error) { |
48 | var ( | 51 | var ( |
49 | agg *protocol.UserBaseInfoAggregation | 52 | agg *protocol.UserBaseInfoAggregation |
50 | ) | 53 | ) |
51 | - if agg, err = GetUserBaseInfoAggregation(uid); err != nil { | 54 | + if agg, err = GetUserBaseInfoAggregation(uid, companyId); err != nil { |
52 | return | 55 | return |
53 | } | 56 | } |
54 | v = &protocol.BaseUserInfo{ | 57 | v = &protocol.BaseUserInfo{ |
@@ -60,7 +63,7 @@ func GetUserBaseInfo(uid int64) (v *protocol.BaseUserInfo, err error) { | @@ -60,7 +63,7 @@ func GetUserBaseInfo(uid int64) (v *protocol.BaseUserInfo, err error) { | ||
60 | return | 63 | return |
61 | } | 64 | } |
62 | 65 | ||
63 | -func GetChance(chanceId int64) (v *protocol.Chance, err error) { | 66 | +func GetChance(chanceId int64, companyId int64) (v *protocol.Chance, err error) { |
64 | var ( | 67 | var ( |
65 | c *models.Chance | 68 | c *models.Chance |
66 | baseUserInfo *protocol.BaseUserInfo | 69 | baseUserInfo *protocol.BaseUserInfo |
@@ -69,7 +72,7 @@ func GetChance(chanceId int64) (v *protocol.Chance, err error) { | @@ -69,7 +72,7 @@ func GetChance(chanceId int64) (v *protocol.Chance, err error) { | ||
69 | if c, err = repository.Chance.GetChanceById(chanceId); err != nil { | 72 | if c, err = repository.Chance.GetChanceById(chanceId); err != nil { |
70 | return | 73 | return |
71 | } | 74 | } |
72 | - if baseUserInfo, err = GetUserBaseInfo(c.UserId); err != nil { | 75 | + if baseUserInfo, err = GetUserBaseInfo(c.UserId, companyId); err != nil { |
73 | return | 76 | return |
74 | } | 77 | } |
75 | v = &protocol.Chance{ | 78 | v = &protocol.Chance{ |
@@ -33,7 +33,7 @@ func Favorite(header *protocol.RequestHeader, request *protocol.FavoriteRequest) | @@ -33,7 +33,7 @@ func Favorite(header *protocol.RequestHeader, request *protocol.FavoriteRequest) | ||
33 | } | 33 | } |
34 | switch f.SourceType { | 34 | switch f.SourceType { |
35 | case protocol.SourceType_Chance: | 35 | case protocol.SourceType_Chance: |
36 | - chance, err = agg.GetChance(f.SourceId) | 36 | + chance, err = agg.GetChance(f.SourceId, f.CompanyId) |
37 | if err != nil { | 37 | if err != nil { |
38 | log.Error(err) | 38 | log.Error(err) |
39 | return | 39 | return |
@@ -18,6 +18,8 @@ func IComment(header *protocol.RequestHeader, request *protocol.ICommentRequest) | @@ -18,6 +18,8 @@ func IComment(header *protocol.RequestHeader, request *protocol.ICommentRequest) | ||
18 | comment *models.Comment | 18 | comment *models.Comment |
19 | baseUserInfo *protocol.BaseUserInfo | 19 | baseUserInfo *protocol.BaseUserInfo |
20 | chance *models.Chance | 20 | chance *models.Chance |
21 | + updateTable interface{} | ||
22 | + updateMap = make(map[string]interface{}) | ||
21 | ) | 23 | ) |
22 | switch request.SourceType { | 24 | switch request.SourceType { |
23 | case protocol.SourceType_Chance: | 25 | case protocol.SourceType_Chance: |
@@ -25,15 +27,19 @@ func IComment(header *protocol.RequestHeader, request *protocol.ICommentRequest) | @@ -25,15 +27,19 @@ func IComment(header *protocol.RequestHeader, request *protocol.ICommentRequest) | ||
25 | log.Error(err) | 27 | log.Error(err) |
26 | return | 28 | return |
27 | } | 29 | } |
30 | + updateTable = chance | ||
31 | + updateMap["CommentTotal"] = chance.CommentTotal + 1 | ||
28 | case protocol.SourceType_Comment: | 32 | case protocol.SourceType_Comment: |
29 | - if _, err = repository.Comment.GetCommentById(request.Id); err != nil { | 33 | + if comment, err = repository.Comment.GetCommentById(request.Id); err != nil { |
30 | log.Error(err) | 34 | log.Error(err) |
31 | return | 35 | return |
32 | } | 36 | } |
37 | + updateTable = comment | ||
38 | + updateMap["CommentTotal"] = comment.CommentTotal + 1 | ||
33 | default: | 39 | default: |
34 | err = fmt.Errorf("unknow source_type:%v", request.SourceType) | 40 | err = fmt.Errorf("unknow source_type:%v", request.SourceType) |
35 | } | 41 | } |
36 | - comment = &models.Comment{ | 42 | + newComment := &models.Comment{ |
37 | Id: idgen.Next(), | 43 | Id: idgen.Next(), |
38 | UserId: header.Uid, | 44 | UserId: header.Uid, |
39 | SourceType: int8(request.SourceType), | 45 | SourceType: int8(request.SourceType), |
@@ -41,22 +47,21 @@ func IComment(header *protocol.RequestHeader, request *protocol.ICommentRequest) | @@ -41,22 +47,21 @@ func IComment(header *protocol.RequestHeader, request *protocol.ICommentRequest) | ||
41 | CreateAt: time.Now(), | 47 | CreateAt: time.Now(), |
42 | SourceId: request.Id, | 48 | SourceId: request.Id, |
43 | } | 49 | } |
44 | - if _, err = repository.Comment.AddComment(comment); err != nil { | 50 | + if _, err = repository.Comment.AddComment(newComment); err != nil { |
45 | log.Error(err) | 51 | log.Error(err) |
46 | return | 52 | return |
47 | } | 53 | } |
48 | - if baseUserInfo, err = agg.GetUserBaseInfo(header.Uid); err != nil { | 54 | + if baseUserInfo, err = agg.GetUserBaseInfo(header.Uid, header.CompanyId); err != nil { |
49 | log.Error(err) | 55 | log.Error(err) |
50 | return | 56 | return |
51 | } | 57 | } |
52 | - if chance != nil { | ||
53 | - //TODO:sql更新 | ||
54 | - utils.UpdateTableByMap(chance, map[string]interface{}{"CommentTotal": chance.CommentTotal + 1}) | 58 | + if updateTable != nil { |
59 | + utils.UpdateTableByMap(updateTable, updateMap) | ||
55 | } | 60 | } |
56 | rsp = &protocol.ICommentResponse{ | 61 | rsp = &protocol.ICommentResponse{ |
57 | - Id: comment.Id, | ||
58 | - Content: comment.Content, | ||
59 | - CreateTime: comment.CreateAt.Unix(), | 62 | + Id: newComment.Id, |
63 | + Content: newComment.Content, | ||
64 | + CreateTime: newComment.CreateAt.Unix(), | ||
60 | Provider: baseUserInfo, | 65 | Provider: baseUserInfo, |
61 | } | 66 | } |
62 | return | 67 | return |
@@ -76,7 +81,7 @@ func IComments(header *protocol.RequestHeader, request *protocol.ICommentsReques | @@ -76,7 +81,7 @@ func IComments(header *protocol.RequestHeader, request *protocol.ICommentsReques | ||
76 | rsp = &protocol.ICommentsResponse{ | 81 | rsp = &protocol.ICommentsResponse{ |
77 | Total: total, | 82 | Total: total, |
78 | } | 83 | } |
79 | - if baseUserInfo, err = agg.GetUserBaseInfo(header.Uid); err != nil { | 84 | + if baseUserInfo, err = agg.GetUserBaseInfo(header.Uid, header.CompanyId); err != nil { |
80 | log.Error(err) | 85 | log.Error(err) |
81 | return | 86 | return |
82 | } | 87 | } |
@@ -105,8 +110,9 @@ func Comments(header *protocol.RequestHeader, request *protocol.CommentsRequest) | @@ -105,8 +110,9 @@ func Comments(header *protocol.RequestHeader, request *protocol.CommentsRequest) | ||
105 | comments []*models.Comment | 110 | comments []*models.Comment |
106 | baseUserInfo *protocol.BaseUserInfo | 111 | baseUserInfo *protocol.BaseUserInfo |
107 | total int | 112 | total int |
113 | + exists bool | ||
108 | ) | 114 | ) |
109 | - if comments, total, err = repository.Comment.GetComments(header.Uid, protocol.SourceType_Chance, request.SourceId, request.LastId, request.PageSize); err != nil { | 115 | + if comments, total, err = repository.Comment.GetComments(header.Uid, request.SourceType, request.SourceId, request.LastId, request.PageSize); err != nil { |
110 | log.Error(err) | 116 | log.Error(err) |
111 | return | 117 | return |
112 | } | 118 | } |
@@ -115,7 +121,7 @@ func Comments(header *protocol.RequestHeader, request *protocol.CommentsRequest) | @@ -115,7 +121,7 @@ func Comments(header *protocol.RequestHeader, request *protocol.CommentsRequest) | ||
115 | } | 121 | } |
116 | for i := range comments { | 122 | for i := range comments { |
117 | comment := comments[i] | 123 | comment := comments[i] |
118 | - if baseUserInfo, err = agg.GetUserBaseInfo(comment.UserId); err != nil { | 124 | + if baseUserInfo, err = agg.GetUserBaseInfo(comment.UserId, header.CompanyId); err != nil { |
119 | log.Error(err) | 125 | log.Error(err) |
120 | //return | 126 | //return |
121 | } | 127 | } |
@@ -128,7 +134,63 @@ func Comments(header *protocol.RequestHeader, request *protocol.CommentsRequest) | @@ -128,7 +134,63 @@ func Comments(header *protocol.RequestHeader, request *protocol.CommentsRequest) | ||
128 | ZanTotal: comment.ZanTotal, | 134 | ZanTotal: comment.ZanTotal, |
129 | CommentTotal: comment.CommentTotal, | 135 | CommentTotal: comment.CommentTotal, |
130 | } | 136 | } |
137 | + if exists, _ = repository.ChanceFavorite.ExitsChanceFavorite(header.Uid, header.CompanyId, comment.Id, protocol.ObjectType_Zan); exists { | ||
138 | + item.IsZan = 1 | ||
139 | + } | ||
131 | rsp.Comments = append(rsp.Comments, item) | 140 | rsp.Comments = append(rsp.Comments, item) |
132 | } | 141 | } |
133 | return | 142 | return |
134 | } | 143 | } |
144 | + | ||
145 | +//评论详情-不带地下评论 | ||
146 | +func CommentDetailsSingle(header *protocol.RequestHeader, request *protocol.CommentDetailsSingleRequest) (rsp *protocol.CommentDetailsSingleResponse, err error) { | ||
147 | + var ( | ||
148 | + comment *models.Comment | ||
149 | + baseUserInfo *protocol.BaseUserInfo | ||
150 | + exists bool | ||
151 | + ) | ||
152 | + rsp = &protocol.CommentDetailsSingleResponse{} | ||
153 | + if comment, err = repository.Comment.GetCommentById(request.Id); err != nil { | ||
154 | + log.Error(err) | ||
155 | + return | ||
156 | + } | ||
157 | + if baseUserInfo, err = agg.GetUserBaseInfo(comment.UserId, header.CompanyId); err != nil { | ||
158 | + log.Error(err) | ||
159 | + //return | ||
160 | + } | ||
161 | + rsp.Comment = &protocol.Comments{ | ||
162 | + Id: comment.Id, | ||
163 | + Provider: baseUserInfo, | ||
164 | + Content: comment.Content, | ||
165 | + CreateTime: comment.CreateAt.Unix(), | ||
166 | + ViewTotal: comment.ViewTotal, | ||
167 | + ZanTotal: comment.ZanTotal, | ||
168 | + CommentTotal: comment.CommentTotal, | ||
169 | + } | ||
170 | + if exists, _ = repository.ChanceFavorite.ExitsChanceFavorite(header.Uid, header.CompanyId, comment.Id, protocol.ObjectType_Zan); exists { | ||
171 | + rsp.Comment.IsZan = 1 | ||
172 | + } | ||
173 | + return | ||
174 | +} | ||
175 | + | ||
176 | +//评论详情-带底下评论 | ||
177 | +func CommentDetailsMulti(header *protocol.RequestHeader, request *protocol.CommentDetailsMultiRequest) (rsp *protocol.CommentDetailsMultiResponse, err error) { | ||
178 | + var ( | ||
179 | + commentDetailSingle *protocol.CommentDetailsSingleResponse | ||
180 | + commentDetailMulti *protocol.CommentsResponse | ||
181 | + ) | ||
182 | + rsp = &protocol.CommentDetailsMultiResponse{} | ||
183 | + //LastId=0时(返回comment对象和comments列表),commentLastId>0(返回comments列表) | ||
184 | + if request.LastId == 0 { | ||
185 | + if commentDetailSingle, err = CommentDetailsSingle(header, &protocol.CommentDetailsSingleRequest{Id: request.SourceId}); err != nil { | ||
186 | + return | ||
187 | + } | ||
188 | + rsp.Comment = commentDetailSingle.Comment | ||
189 | + } | ||
190 | + if commentDetailMulti, err = Comments(header, &protocol.CommentsRequest{LastId: request.LastId, SourceId: request.SourceId, PageSize: request.PageSize, SourceType: protocol.SourceType_Comment}); err != nil { | ||
191 | + log.Error(err) | ||
192 | + return | ||
193 | + } | ||
194 | + rsp.Comments = commentDetailMulti.Comments | ||
195 | + return | ||
196 | +} |
@@ -19,12 +19,12 @@ func Commend(header *protocol.RequestHeader, request *protocol.CommendRequest) ( | @@ -19,12 +19,12 @@ func Commend(header *protocol.RequestHeader, request *protocol.CommendRequest) ( | ||
19 | if err != nil { | 19 | if err != nil { |
20 | return | 20 | return |
21 | } | 21 | } |
22 | - if commends, rsp.Total, err = repository.Commend.GetCommends(user.CompanyId, request.LastId, request.PageSize); err != nil { | 22 | + if commends, rsp.Total, err = repository.Commend.GetCommends(header.CompanyId, request.LastId, request.PageSize); err != nil { |
23 | return | 23 | return |
24 | } | 24 | } |
25 | for i := 0; i < len(commends); i++ { | 25 | for i := 0; i < len(commends); i++ { |
26 | c := commends[i] | 26 | c := commends[i] |
27 | - userBaseInfo, err = agg.GetUserBaseInfoAggregation(c.UserId) | 27 | + userBaseInfo, err = agg.GetUserBaseInfoAggregation(c.UserId, header.CompanyId) |
28 | if err != nil { | 28 | if err != nil { |
29 | continue | 29 | continue |
30 | } | 30 | } |
-
请 注册 或 登录 后发表评论