正在显示
15 个修改的文件
包含
560 行增加
和
19 行删除
@@ -14,6 +14,11 @@ | @@ -14,6 +14,11 @@ | ||
14 | |我的评论|完成|2019.11.21|/v1/chance/iComments| | 14 | |我的评论|完成|2019.11.21|/v1/chance/iComments| |
15 | |我的点赞| |2019.11.| | | 15 | |我的点赞| |2019.11.| | |
16 | |我的收藏| |2019.11.| | | 16 | |我的收藏| |2019.11.| | |
17 | +|消息中心|完成|2019.11.|v1/message/messageCenter| | ||
18 | +|标记已读|完成|2019.11.|v1/message/msgCenterRead| | ||
19 | +|标记全部已读|完成|2019.11.|v1/message/msgCenterAllRead| | ||
20 | +|互动消息-点赞| |2019.11.| | | ||
21 | +|互动消息-评论| |2019.11.| | | ||
17 | |我提交的机会| |2019.11.| | | 22 | |我提交的机会| |2019.11.| | |
18 | |我审核的机会| |2019.11.| | | 23 | |我审核的机会| |2019.11.| | |
19 | |待抓住机会列表| |2019.11. | | 24 | |待抓住机会列表| |2019.11. | |
@@ -58,6 +58,10 @@ func (this *BaseController) Valid(obj interface{}) (result bool, msg *protocol.R | @@ -58,6 +58,10 @@ func (this *BaseController) Valid(obj interface{}) (result bool, msg *protocol.R | ||
58 | } | 58 | } |
59 | if !result { | 59 | if !result { |
60 | for _, err := range valid.Errors { | 60 | for _, err := range valid.Errors { |
61 | + if strings.HasSuffix(err.Key, ".Mobile") { | ||
62 | + msg = protocol.BadRequestParam(2001) | ||
63 | + return | ||
64 | + } | ||
61 | log.Error(err.Key, err.Message) | 65 | log.Error(err.Key, err.Message) |
62 | } | 66 | } |
63 | msg = protocol.BadRequestParam(2) | 67 | msg = protocol.BadRequestParam(2) |
@@ -100,6 +104,10 @@ func GetRequestHeader(ctx *context.Context) *protocol.RequestHeader { | @@ -100,6 +104,10 @@ func GetRequestHeader(ctx *context.Context) *protocol.RequestHeader { | ||
100 | h.Uuid = ctx.Input.Header("x-mmm-uuid") | 104 | h.Uuid = ctx.Input.Header("x-mmm-uuid") |
101 | h.TimeStamp = ctx.Input.Header("x-mmm-timestamp") | 105 | h.TimeStamp = ctx.Input.Header("x-mmm-timestamp") |
102 | h.Uid, _ = strconv.ParseInt(ctx.Input.Header("uid"), 10, 64) //需要uid写入到header里面 | 106 | h.Uid, _ = strconv.ParseInt(ctx.Input.Header("uid"), 10, 64) //需要uid写入到header里面 |
107 | + if h.Uid == 0 { | ||
108 | + h.Uid, _ = strconv.ParseInt(ctx.Input.Header("x-mmm-uid"), 10, 64) | ||
109 | + } | ||
110 | + h.CompanyId, _ = strconv.ParseInt(ctx.Input.Header("x-mmm-companyid"), 10, 64) | ||
103 | return h | 111 | return h |
104 | } | 112 | } |
105 | 113 | ||
@@ -112,7 +120,7 @@ func FilterComm(ctx *context.Context) { | @@ -112,7 +120,7 @@ func FilterComm(ctx *context.Context) { | ||
112 | //统计 | 120 | //统计 |
113 | MetricCounter(ctx) | 121 | MetricCounter(ctx) |
114 | 122 | ||
115 | - if beego.BConfig.RunMode != "prod" { | 123 | + if beego.BConfig.RunMode == "dev" { |
116 | return | 124 | return |
117 | } | 125 | } |
118 | 126 | ||
@@ -169,7 +177,7 @@ func CheckToken(ctx *context.Context) (result bool) { | @@ -169,7 +177,7 @@ func CheckToken(ctx *context.Context) (result bool) { | ||
169 | var ( | 177 | var ( |
170 | msg *protocol.ResponseMessage | 178 | msg *protocol.ResponseMessage |
171 | ) | 179 | ) |
172 | - if strings.HasSuffix(ctx.Request.RequestURI,"login"){ | 180 | + if strings.HasSuffix(ctx.Request.RequestURI, "login") { |
173 | return true | 181 | return true |
174 | } | 182 | } |
175 | result = true | 183 | result = true |
@@ -187,7 +195,7 @@ func CheckToken(ctx *context.Context) (result bool) { | @@ -187,7 +195,7 @@ func CheckToken(ctx *context.Context) (result bool) { | ||
187 | } else { | 195 | } else { |
188 | if rsp.UserInfo != nil { | 196 | if rsp.UserInfo != nil { |
189 | //设置附加数据 | 197 | //设置附加数据 |
190 | - ctx.Request.Header.Add("uid", fmt.Sprintf("%v", rsp.UserInfo.UserId)) | 198 | + ctx.Request.Header.Add("x-mmm-uid", fmt.Sprintf("%v", rsp.UserInfo.UserId)) |
191 | } | 199 | } |
192 | } | 200 | } |
193 | return | 201 | return |
@@ -6,7 +6,6 @@ import ( | @@ -6,7 +6,6 @@ import ( | ||
6 | "opp/protocol" | 6 | "opp/protocol" |
7 | "reflect" | 7 | "reflect" |
8 | "testing" | 8 | "testing" |
9 | - "time" | ||
10 | ) | 9 | ) |
11 | 10 | ||
12 | func Test_GenMessage(t *testing.T) { | 11 | func Test_GenMessage(t *testing.T) { |
@@ -41,16 +40,15 @@ func Benchmark_GenMessage(b *testing.B) { | @@ -41,16 +40,15 @@ func Benchmark_GenMessage(b *testing.B) { | ||
41 | } | 40 | } |
42 | } | 41 | } |
43 | 42 | ||
44 | -func Test_RandTask(t *testing.T){ | ||
45 | - time :=time.Now().Unix() | ||
46 | - num :=1 | ||
47 | - for i:=1;i<=num;i++{ | ||
48 | - r :=time%2 | ||
49 | - if r==0{ | ||
50 | - t.Log("xh","yf",time) | ||
51 | - } | ||
52 | - if r==1{ | ||
53 | - t.Log("yf","xh",time) | 43 | +func Test_Valid(t *testing.T) { |
44 | + /*修改手机号*/ | ||
45 | + type ChangePhoneRequest struct { | ||
46 | + Phone string `json:"phone" valid:"Mobile"` | ||
47 | + Captcha string `json:"captcha" valid:"Required"` | ||
54 | } | 48 | } |
49 | + req := &ChangePhoneRequest{ | ||
50 | + "1886018", | ||
51 | + "123", | ||
55 | } | 52 | } |
53 | + DefaultController.Valid(req) | ||
56 | } | 54 | } |
controllers/v1/message.go
0 → 100644
1 | +package v1 | ||
2 | + | ||
3 | +import ( | ||
4 | + "encoding/json" | ||
5 | + "gitlab.fjmaimaimai.com/mmm-go/gocomm/pkg/log" | ||
6 | + "opp/controllers" | ||
7 | + "opp/protocol" | ||
8 | + "opp/services/message" | ||
9 | +) | ||
10 | + | ||
11 | +type MessageController struct { | ||
12 | + controllers.BaseController | ||
13 | +} | ||
14 | + | ||
15 | +//MessageCenter | ||
16 | +// @router /messageCenter [post] | ||
17 | +func (this *MessageController) MessageCenter() { | ||
18 | + var msg *protocol.ResponseMessage | ||
19 | + defer func() { | ||
20 | + this.Resp(msg) | ||
21 | + }() | ||
22 | + var request *protocol.MessageCenterRequest | ||
23 | + if err := json.Unmarshal(this.ByteBody, &request); err != nil { | ||
24 | + log.Error(err) | ||
25 | + msg = protocol.BadRequestParam(1) | ||
26 | + return | ||
27 | + } | ||
28 | + if b, m := this.Valid(request); !b { | ||
29 | + msg = m | ||
30 | + return | ||
31 | + } | ||
32 | + header := controllers.GetRequestHeader(this.Ctx) | ||
33 | + msg = protocol.NewReturnResponse(message.MessageCenter(header, request)) | ||
34 | +} | ||
35 | + | ||
36 | +//MsgCenterRead | ||
37 | +// @router /msgCenterRead [post] | ||
38 | +func (this *MessageController) MsgCenterRead() { | ||
39 | + var msg *protocol.ResponseMessage | ||
40 | + defer func() { | ||
41 | + this.Resp(msg) | ||
42 | + }() | ||
43 | + var request *protocol.MsgCenterReadRequest | ||
44 | + if err := json.Unmarshal(this.ByteBody, &request); err != nil { | ||
45 | + log.Error(err) | ||
46 | + msg = protocol.BadRequestParam(1) | ||
47 | + return | ||
48 | + } | ||
49 | + if b, m := this.Valid(request); !b { | ||
50 | + msg = m | ||
51 | + return | ||
52 | + } | ||
53 | + header := controllers.GetRequestHeader(this.Ctx) | ||
54 | + msg = protocol.NewReturnResponse(message.MsgCenterRead(header, request)) | ||
55 | +} | ||
56 | + | ||
57 | +//MsgCenterAllRead | ||
58 | +// @router /msgCenterAllRead [post] | ||
59 | +func (this *MessageController) MsgCenterAllRead() { | ||
60 | + var msg *protocol.ResponseMessage | ||
61 | + defer func() { | ||
62 | + this.Resp(msg) | ||
63 | + }() | ||
64 | + var request *protocol.MsgCenterAllReadRequest | ||
65 | + if err := json.Unmarshal(this.ByteBody, &request); err != nil { | ||
66 | + log.Error(err) | ||
67 | + msg = protocol.BadRequestParam(1) | ||
68 | + return | ||
69 | + } | ||
70 | + if b, m := this.Valid(request); !b { | ||
71 | + msg = m | ||
72 | + return | ||
73 | + } | ||
74 | + header := controllers.GetRequestHeader(this.Ctx) | ||
75 | + msg = protocol.NewReturnResponse(message.MsgCenterAllRead(header, request)) | ||
76 | +} |
internal/repository/message.go
0 → 100644
1 | +package repository | ||
2 | + | ||
3 | +import "opp/models" | ||
4 | + | ||
5 | +type IMessageRepository interface { | ||
6 | + GetUserMsgTotals(userId int64, companyId int64, msgType int, v interface{}) (err error) | ||
7 | + UpdateUserMsgSetRead(userId int64, companyId int64, msgType int, msgId int64) (err error) | ||
8 | +} | ||
9 | + | ||
10 | +var _ IMessageRepository = (*MessageRepository)(nil) | ||
11 | + | ||
12 | +type MessageRepository struct{} | ||
13 | + | ||
14 | +func (r *MessageRepository) GetUserMsgTotals(userId int64, companyId int64, msgType int, v interface{}) (err error) { | ||
15 | + return models.GetUserMsgTotals(userId, companyId, msgType, v) | ||
16 | +} | ||
17 | + | ||
18 | +func (r *MessageRepository) UpdateUserMsgSetRead(userId int64, companyId int64, msgType int, msgId int64) (err error) { | ||
19 | + return models.UpdateUserMsgSetRead(userId, companyId, msgType, msgId) | ||
20 | +} |
@@ -13,6 +13,7 @@ var ( | @@ -13,6 +13,7 @@ var ( | ||
13 | Position IPositionRepository | 13 | Position IPositionRepository |
14 | Chance IChanceRepository | 14 | Chance IChanceRepository |
15 | Comment ICommentRepository | 15 | Comment ICommentRepository |
16 | + Message IMessageRepository | ||
16 | ) | 17 | ) |
17 | 18 | ||
18 | func init() { | 19 | func init() { |
@@ -28,6 +29,7 @@ func InitRepository() { | @@ -28,6 +29,7 @@ func InitRepository() { | ||
28 | Position = &PositionRepository{} | 29 | Position = &PositionRepository{} |
29 | Chance = &ChanceRepository{} | 30 | Chance = &ChanceRepository{} |
30 | Comment = &CommentRepository{} | 31 | Comment = &CommentRepository{} |
32 | + Message = &MessageRepository{} | ||
31 | } | 33 | } |
32 | 34 | ||
33 | func InitRepositoryMock() { | 35 | func InitRepositoryMock() { |
models/chance_favorite.go
0 → 100644
1 | +package models | ||
2 | + | ||
3 | +import ( | ||
4 | + "errors" | ||
5 | + "fmt" | ||
6 | + "reflect" | ||
7 | + "strings" | ||
8 | + "time" | ||
9 | + | ||
10 | + "github.com/astaxie/beego/orm" | ||
11 | +) | ||
12 | + | ||
13 | +type ChanceFavorite struct { | ||
14 | + Id int64 `orm:"column(id);pk" description:"点赞编号"` | ||
15 | + UserId int64 `orm:"column(user_id)" description:"表user.id 用户编号"` | ||
16 | + ObjectType int `orm:"column(object_type)" description:"类型 1:点赞 2:收藏"` | ||
17 | + SourceType int `orm:"column(source_type)" description:"来源类型 1:机会 2:评论"` | ||
18 | + SourceId int64 `orm:"column(source_id)" description:"来源id 机会编号/评论编号"` | ||
19 | + ChanceTypeId int `orm:"column(chance_type_id)" description:"机会类型编号 - 附加 "` | ||
20 | + EnableStatus int `orm:"column(enable_status)" description:"1:有效 0:无效"` | ||
21 | + CreateAt time.Time `orm:"column(create_at);type(timestamp);null" description:"创建时间"` | ||
22 | + DeleteAt time.Time `orm:"column(delete_at);type(timestamp);null" description:"删除时间"` | ||
23 | +} | ||
24 | + | ||
25 | +func (t *ChanceFavorite) TableName() string { | ||
26 | + return "chance_favorite" | ||
27 | +} | ||
28 | + | ||
29 | +func init() { | ||
30 | + orm.RegisterModel(new(ChanceFavorite)) | ||
31 | +} | ||
32 | + | ||
33 | +// AddChanceFavorite insert a new ChanceFavorite into database and returns | ||
34 | +// last inserted Id on success. | ||
35 | +func AddChanceFavorite(m *ChanceFavorite) (id int64, err error) { | ||
36 | + o := orm.NewOrm() | ||
37 | + id, err = o.Insert(m) | ||
38 | + return | ||
39 | +} | ||
40 | + | ||
41 | +// GetChanceFavoriteById retrieves ChanceFavorite by Id. Returns error if | ||
42 | +// Id doesn't exist | ||
43 | +func GetChanceFavoriteById(id int64) (v *ChanceFavorite, err error) { | ||
44 | + o := orm.NewOrm() | ||
45 | + v = &ChanceFavorite{Id: id} | ||
46 | + if err = o.Read(v); err == nil { | ||
47 | + return v, nil | ||
48 | + } | ||
49 | + return nil, err | ||
50 | +} | ||
51 | + | ||
52 | +// GetAllChanceFavorite retrieves all ChanceFavorite matches certain condition. Returns empty list if | ||
53 | +// no records exist | ||
54 | +func GetAllChanceFavorite(query map[string]string, fields []string, sortby []string, order []string, | ||
55 | + offset int64, limit int64) (ml []interface{}, err error) { | ||
56 | + o := orm.NewOrm() | ||
57 | + qs := o.QueryTable(new(ChanceFavorite)) | ||
58 | + // query k=v | ||
59 | + for k, v := range query { | ||
60 | + // rewrite dot-notation to Object__Attribute | ||
61 | + k = strings.Replace(k, ".", "__", -1) | ||
62 | + if strings.Contains(k, "isnull") { | ||
63 | + qs = qs.Filter(k, (v == "true" || v == "1")) | ||
64 | + } else { | ||
65 | + qs = qs.Filter(k, v) | ||
66 | + } | ||
67 | + } | ||
68 | + // order by: | ||
69 | + var sortFields []string | ||
70 | + if len(sortby) != 0 { | ||
71 | + if len(sortby) == len(order) { | ||
72 | + // 1) for each sort field, there is an associated order | ||
73 | + for i, v := range sortby { | ||
74 | + orderby := "" | ||
75 | + if order[i] == "desc" { | ||
76 | + orderby = "-" + v | ||
77 | + } else if order[i] == "asc" { | ||
78 | + orderby = v | ||
79 | + } else { | ||
80 | + return nil, errors.New("Error: Invalid order. Must be either [asc|desc]") | ||
81 | + } | ||
82 | + sortFields = append(sortFields, orderby) | ||
83 | + } | ||
84 | + qs = qs.OrderBy(sortFields...) | ||
85 | + } else if len(sortby) != len(order) && len(order) == 1 { | ||
86 | + // 2) there is exactly one order, all the sorted fields will be sorted by this order | ||
87 | + for _, v := range sortby { | ||
88 | + orderby := "" | ||
89 | + if order[0] == "desc" { | ||
90 | + orderby = "-" + v | ||
91 | + } else if order[0] == "asc" { | ||
92 | + orderby = v | ||
93 | + } else { | ||
94 | + return nil, errors.New("Error: Invalid order. Must be either [asc|desc]") | ||
95 | + } | ||
96 | + sortFields = append(sortFields, orderby) | ||
97 | + } | ||
98 | + } else if len(sortby) != len(order) && len(order) != 1 { | ||
99 | + return nil, errors.New("Error: 'sortby', 'order' sizes mismatch or 'order' size is not 1") | ||
100 | + } | ||
101 | + } else { | ||
102 | + if len(order) != 0 { | ||
103 | + return nil, errors.New("Error: unused 'order' fields") | ||
104 | + } | ||
105 | + } | ||
106 | + | ||
107 | + var l []ChanceFavorite | ||
108 | + qs = qs.OrderBy(sortFields...) | ||
109 | + if _, err = qs.Limit(limit, offset).All(&l, fields...); err == nil { | ||
110 | + if len(fields) == 0 { | ||
111 | + for _, v := range l { | ||
112 | + ml = append(ml, v) | ||
113 | + } | ||
114 | + } else { | ||
115 | + // trim unused fields | ||
116 | + for _, v := range l { | ||
117 | + m := make(map[string]interface{}) | ||
118 | + val := reflect.ValueOf(v) | ||
119 | + for _, fname := range fields { | ||
120 | + m[fname] = val.FieldByName(fname).Interface() | ||
121 | + } | ||
122 | + ml = append(ml, m) | ||
123 | + } | ||
124 | + } | ||
125 | + return ml, nil | ||
126 | + } | ||
127 | + return nil, err | ||
128 | +} | ||
129 | + | ||
130 | +// UpdateChanceFavorite updates ChanceFavorite by Id and returns error if | ||
131 | +// the record to be updated doesn't exist | ||
132 | +func UpdateChanceFavoriteById(m *ChanceFavorite) (err error) { | ||
133 | + o := orm.NewOrm() | ||
134 | + v := ChanceFavorite{Id: m.Id} | ||
135 | + // ascertain id exists in the database | ||
136 | + if err = o.Read(&v); err == nil { | ||
137 | + var num int64 | ||
138 | + if num, err = o.Update(m); err == nil { | ||
139 | + fmt.Println("Number of records updated in database:", num) | ||
140 | + } | ||
141 | + } | ||
142 | + return | ||
143 | +} | ||
144 | + | ||
145 | +// DeleteChanceFavorite deletes ChanceFavorite by Id and returns error if | ||
146 | +// the record to be deleted doesn't exist | ||
147 | +func DeleteChanceFavorite(id int64) (err error) { | ||
148 | + o := orm.NewOrm() | ||
149 | + v := ChanceFavorite{Id: id} | ||
150 | + // ascertain id exists in the database | ||
151 | + if err = o.Read(&v); err == nil { | ||
152 | + var num int64 | ||
153 | + if num, err = o.Delete(&ChanceFavorite{Id: id}); err == nil { | ||
154 | + fmt.Println("Number of records deleted in database:", num) | ||
155 | + } | ||
156 | + } | ||
157 | + return | ||
158 | +} |
models/user_msg.go
0 → 100644
1 | +package models | ||
2 | + | ||
3 | +import ( | ||
4 | + "errors" | ||
5 | + "fmt" | ||
6 | + "reflect" | ||
7 | + "strings" | ||
8 | + "time" | ||
9 | + | ||
10 | + "github.com/astaxie/beego/orm" | ||
11 | +) | ||
12 | + | ||
13 | +type UserMsg struct { | ||
14 | + Id int64 `orm:"column(id);pk" description:"消息表id"` | ||
15 | + CompanyId int64 `orm:"column(company_id)" description:"公司编号"` | ||
16 | + ReceiveUserId int64 `orm:"column(receive_user_id)" description:"接收用户id"` | ||
17 | + MsgType int `orm:"column(msg_type)" description:"消息类型 1.公司公告 2.表彰通知 4.互动消息 8.机会审核"` | ||
18 | + Message string `orm:"column(message)" description:"消息内容"` | ||
19 | + SourceId int64 `orm:"column(source_id)" description:"来源id (机会编号 /评论编号)"` | ||
20 | + IsPublic int8 `orm:"column(is_public)" description:"1:公开 0:不公开"` | ||
21 | + IsRead int8 `orm:"column(is_read)" description:"1:已读 0:未读"` | ||
22 | + CreateAt time.Time `orm:"column(create_at);type(timestamp);auto_now" description:"创建时间"` | ||
23 | +} | ||
24 | + | ||
25 | +func (t *UserMsg) TableName() string { | ||
26 | + return "user_msg" | ||
27 | +} | ||
28 | + | ||
29 | +func init() { | ||
30 | + orm.RegisterModel(new(UserMsg)) | ||
31 | +} | ||
32 | + | ||
33 | +// AddUserMsg insert a new UserMsg into database and returns | ||
34 | +// last inserted Id on success. | ||
35 | +func AddUserMsg(m *UserMsg) (id int64, err error) { | ||
36 | + o := orm.NewOrm() | ||
37 | + id, err = o.Insert(m) | ||
38 | + return | ||
39 | +} | ||
40 | + | ||
41 | +// GetUserMsgById retrieves UserMsg by Id. Returns error if | ||
42 | +// Id doesn't exist | ||
43 | +func GetUserMsgById(id int64) (v *UserMsg, err error) { | ||
44 | + o := orm.NewOrm() | ||
45 | + v = &UserMsg{Id: id} | ||
46 | + if err = o.Read(v); err == nil { | ||
47 | + return v, nil | ||
48 | + } | ||
49 | + return nil, err | ||
50 | +} | ||
51 | + | ||
52 | +// GetAllUserMsg retrieves all UserMsg matches certain condition. Returns empty list if | ||
53 | +// no records exist | ||
54 | +func GetAllUserMsg(query map[string]string, fields []string, sortby []string, order []string, | ||
55 | + offset int64, limit int64) (ml []interface{}, err error) { | ||
56 | + o := orm.NewOrm() | ||
57 | + qs := o.QueryTable(new(UserMsg)) | ||
58 | + // query k=v | ||
59 | + for k, v := range query { | ||
60 | + // rewrite dot-notation to Object__Attribute | ||
61 | + k = strings.Replace(k, ".", "__", -1) | ||
62 | + if strings.Contains(k, "isnull") { | ||
63 | + qs = qs.Filter(k, (v == "true" || v == "1")) | ||
64 | + } else { | ||
65 | + qs = qs.Filter(k, v) | ||
66 | + } | ||
67 | + } | ||
68 | + // order by: | ||
69 | + var sortFields []string | ||
70 | + if len(sortby) != 0 { | ||
71 | + if len(sortby) == len(order) { | ||
72 | + // 1) for each sort field, there is an associated order | ||
73 | + for i, v := range sortby { | ||
74 | + orderby := "" | ||
75 | + if order[i] == "desc" { | ||
76 | + orderby = "-" + v | ||
77 | + } else if order[i] == "asc" { | ||
78 | + orderby = v | ||
79 | + } else { | ||
80 | + return nil, errors.New("Error: Invalid order. Must be either [asc|desc]") | ||
81 | + } | ||
82 | + sortFields = append(sortFields, orderby) | ||
83 | + } | ||
84 | + qs = qs.OrderBy(sortFields...) | ||
85 | + } else if len(sortby) != len(order) && len(order) == 1 { | ||
86 | + // 2) there is exactly one order, all the sorted fields will be sorted by this order | ||
87 | + for _, v := range sortby { | ||
88 | + orderby := "" | ||
89 | + if order[0] == "desc" { | ||
90 | + orderby = "-" + v | ||
91 | + } else if order[0] == "asc" { | ||
92 | + orderby = v | ||
93 | + } else { | ||
94 | + return nil, errors.New("Error: Invalid order. Must be either [asc|desc]") | ||
95 | + } | ||
96 | + sortFields = append(sortFields, orderby) | ||
97 | + } | ||
98 | + } else if len(sortby) != len(order) && len(order) != 1 { | ||
99 | + return nil, errors.New("Error: 'sortby', 'order' sizes mismatch or 'order' size is not 1") | ||
100 | + } | ||
101 | + } else { | ||
102 | + if len(order) != 0 { | ||
103 | + return nil, errors.New("Error: unused 'order' fields") | ||
104 | + } | ||
105 | + } | ||
106 | + | ||
107 | + var l []UserMsg | ||
108 | + qs = qs.OrderBy(sortFields...) | ||
109 | + if _, err = qs.Limit(limit, offset).All(&l, fields...); err == nil { | ||
110 | + if len(fields) == 0 { | ||
111 | + for _, v := range l { | ||
112 | + ml = append(ml, v) | ||
113 | + } | ||
114 | + } else { | ||
115 | + // trim unused fields | ||
116 | + for _, v := range l { | ||
117 | + m := make(map[string]interface{}) | ||
118 | + val := reflect.ValueOf(v) | ||
119 | + for _, fname := range fields { | ||
120 | + m[fname] = val.FieldByName(fname).Interface() | ||
121 | + } | ||
122 | + ml = append(ml, m) | ||
123 | + } | ||
124 | + } | ||
125 | + return ml, nil | ||
126 | + } | ||
127 | + return nil, err | ||
128 | +} | ||
129 | + | ||
130 | +// UpdateUserMsg updates UserMsg by Id and returns error if | ||
131 | +// the record to be updated doesn't exist | ||
132 | +func UpdateUserMsgById(m *UserMsg) (err error) { | ||
133 | + o := orm.NewOrm() | ||
134 | + v := UserMsg{Id: m.Id} | ||
135 | + // ascertain id exists in the database | ||
136 | + if err = o.Read(&v); err == nil { | ||
137 | + var num int64 | ||
138 | + if num, err = o.Update(m); err == nil { | ||
139 | + fmt.Println("Number of records updated in database:", num) | ||
140 | + } | ||
141 | + } | ||
142 | + return | ||
143 | +} | ||
144 | + | ||
145 | +// DeleteUserMsg deletes UserMsg by Id and returns error if | ||
146 | +// the record to be deleted doesn't exist | ||
147 | +func DeleteUserMsg(id int64) (err error) { | ||
148 | + o := orm.NewOrm() | ||
149 | + v := UserMsg{Id: id} | ||
150 | + // ascertain id exists in the database | ||
151 | + if err = o.Read(&v); err == nil { | ||
152 | + var num int64 | ||
153 | + if num, err = o.Delete(&UserMsg{Id: id}); err == nil { | ||
154 | + fmt.Println("Number of records deleted in database:", num) | ||
155 | + } | ||
156 | + } | ||
157 | + return | ||
158 | +} | ||
159 | + | ||
160 | +func GetUserMsgTotals(userId int64, companyId int64, msgType int, v interface{}) (err error) { | ||
161 | + o := orm.NewOrm() | ||
162 | + sql := `select COUNT(*) as total,msg_type from user_msg | ||
163 | +where (msg_type & ?)>0 and receive_user_id = ? and is_public=1 and is_read=0 and company_id=? | ||
164 | +GROUP BY msg_type` | ||
165 | + if _, err = o.Raw(sql, msgType, userId, companyId).QueryRows(v); err == nil { | ||
166 | + return | ||
167 | + } | ||
168 | + return | ||
169 | +} | ||
170 | + | ||
171 | +func UpdateUserMsgSetRead(userId int64, companyId int64, msgType int, msgId int64) (err error) { | ||
172 | + o := orm.NewOrm() | ||
173 | + sql := `update user_msg set is_read = 1 | ||
174 | + where receive_user_id = ? and company_id=? and is_public=1 ` | ||
175 | + if msgType > 0 { | ||
176 | + sql += fmt.Sprintf(" and (msg_type & %v)>0", msgType) | ||
177 | + } | ||
178 | + if msgId > 0 { | ||
179 | + sql += fmt.Sprintf(" and id=%v", msgId) | ||
180 | + } | ||
181 | + if _, err = o.Raw(sql, userId, companyId).Exec(); err != nil { | ||
182 | + return | ||
183 | + } | ||
184 | + return | ||
185 | +} |
@@ -12,7 +12,7 @@ var errmessge ErrorMap = map[int]string{ | @@ -12,7 +12,7 @@ var errmessge ErrorMap = map[int]string{ | ||
12 | 2001: "请输入正确的手机号码", | 12 | 2001: "请输入正确的手机号码", |
13 | 2002: "后台未配置账号信息,请联系管理员配置", | 13 | 2002: "后台未配置账号信息,请联系管理员配置", |
14 | 2009: "上传的文件流为空", | 14 | 2009: "上传的文件流为空", |
15 | - 2020: "帐号不存在,请联系管理员", | 15 | + //2020: "帐号不存在,请联系管理员", |
16 | 2021: "登录失败,手机号或密码错误", | 16 | 2021: "登录失败,手机号或密码错误", |
17 | 2025: "短信验证码验证失败", | 17 | 2025: "短信验证码验证失败", |
18 | 2026: "两次输入的密码不一致", | 18 | 2026: "两次输入的密码不一致", |
@@ -21,3 +21,31 @@ var errmessge ErrorMap = map[int]string{ | @@ -21,3 +21,31 @@ var errmessge ErrorMap = map[int]string{ | ||
21 | 4141: "accessToken过期或无效,需要进行重新获取令牌", | 21 | 4141: "accessToken过期或无效,需要进行重新获取令牌", |
22 | 4142: "Uuid已存在,请求失败", | 22 | 4142: "Uuid已存在,请求失败", |
23 | } | 23 | } |
24 | + | ||
25 | +/*MessageCenter */ | ||
26 | +type MessageCenterRequest struct { | ||
27 | + MsgType int `json:"msgType" valid:"Required"` | ||
28 | +} | ||
29 | +type MessageCenterResponse struct { | ||
30 | + Totals []*MessageTotal `json:"totals"` | ||
31 | +} | ||
32 | + | ||
33 | +type MessageTotal struct { | ||
34 | + MsgType int `json:"msgType" orm:"column(msg_type)"` | ||
35 | + MsgTotal int `json:"msgTotal" orm:"column(total)"` | ||
36 | +} | ||
37 | + | ||
38 | +/*MsgCenterRead */ | ||
39 | +type MsgCenterReadRequest struct { | ||
40 | + MsgId int64 `json:"msgId" valid:"Required"` | ||
41 | + MsgType int `json:"msgType" valid:"Required"` | ||
42 | +} | ||
43 | +type MsgCenterReadResponse struct { | ||
44 | +} | ||
45 | + | ||
46 | +/*MsgCenterAllRead */ | ||
47 | +type MsgCenterAllReadRequest struct { | ||
48 | + MsgType int `json:"msgType" valid:"Required"` | ||
49 | +} | ||
50 | +type MsgCenterAllReadResponse struct { | ||
51 | +} |
@@ -9,7 +9,7 @@ type CheckSmsCodeResponse struct { | @@ -9,7 +9,7 @@ type CheckSmsCodeResponse struct { | ||
9 | 9 | ||
10 | /*修改手机号*/ | 10 | /*修改手机号*/ |
11 | type ChangePhoneRequest struct { | 11 | type ChangePhoneRequest struct { |
12 | - Phone string `json:"phone" valid:"Required"` | 12 | + Phone string `json:"phone" valid:"Mobile"` |
13 | Captcha string `json:"captcha" valid:"Required"` | 13 | Captcha string `json:"captcha" valid:"Required"` |
14 | } | 14 | } |
15 | type ChangePhoneResponse struct { | 15 | type ChangePhoneResponse struct { |
@@ -79,6 +79,30 @@ func init() { | @@ -79,6 +79,30 @@ func init() { | ||
79 | MethodParams: param.Make(), | 79 | MethodParams: param.Make(), |
80 | Params: nil}) | 80 | Params: nil}) |
81 | 81 | ||
82 | + beego.GlobalControllerRouter["opp/controllers/v1:MessageController"] = append(beego.GlobalControllerRouter["opp/controllers/v1:MessageController"], | ||
83 | + beego.ControllerComments{ | ||
84 | + Method: "MessageCenter", | ||
85 | + Router: `/messageCenter`, | ||
86 | + AllowHTTPMethods: []string{"post"}, | ||
87 | + MethodParams: param.Make(), | ||
88 | + Params: nil}) | ||
89 | + | ||
90 | + beego.GlobalControllerRouter["opp/controllers/v1:MessageController"] = append(beego.GlobalControllerRouter["opp/controllers/v1:MessageController"], | ||
91 | + beego.ControllerComments{ | ||
92 | + Method: "MsgCenterAllRead", | ||
93 | + Router: `/msgCenterAllRead`, | ||
94 | + AllowHTTPMethods: []string{"post"}, | ||
95 | + MethodParams: param.Make(), | ||
96 | + Params: nil}) | ||
97 | + | ||
98 | + beego.GlobalControllerRouter["opp/controllers/v1:MessageController"] = append(beego.GlobalControllerRouter["opp/controllers/v1:MessageController"], | ||
99 | + beego.ControllerComments{ | ||
100 | + Method: "MsgCenterRead", | ||
101 | + Router: `/msgCenterRead`, | ||
102 | + AllowHTTPMethods: []string{"post"}, | ||
103 | + MethodParams: param.Make(), | ||
104 | + Params: nil}) | ||
105 | + | ||
82 | beego.GlobalControllerRouter["opp/controllers/v1:UploadController"] = append(beego.GlobalControllerRouter["opp/controllers/v1:UploadController"], | 106 | beego.GlobalControllerRouter["opp/controllers/v1:UploadController"] = append(beego.GlobalControllerRouter["opp/controllers/v1:UploadController"], |
83 | beego.ControllerComments{ | 107 | beego.ControllerComments{ |
84 | Method: "Image", | 108 | Method: "Image", |
@@ -18,6 +18,7 @@ func init() { | @@ -18,6 +18,7 @@ func init() { | ||
18 | beego.NSNamespace("commend", beego.NSInclude(&v1.CommendController{})), | 18 | beego.NSNamespace("commend", beego.NSInclude(&v1.CommendController{})), |
19 | beego.NSNamespace("user", beego.NSInclude(&v1.UserController{})), | 19 | beego.NSNamespace("user", beego.NSInclude(&v1.UserController{})), |
20 | beego.NSNamespace("chance", beego.NSInclude(&v1.ChanceController{})), | 20 | beego.NSNamespace("chance", beego.NSInclude(&v1.ChanceController{})), |
21 | + beego.NSNamespace("message", beego.NSInclude(&v1.MessageController{})), | ||
21 | ) | 22 | ) |
22 | beego.AddNamespace(nsV1) | 23 | beego.AddNamespace(nsV1) |
23 | beego.SetStaticPath("/file/ab", beego.AppConfig.String("source_path")) | 24 | beego.SetStaticPath("/file/ab", beego.AppConfig.String("source_path")) |
@@ -60,7 +60,7 @@ func (s *AuthService) Login(request *protocol.LoginRequest) (rsp *protocol.Login | @@ -60,7 +60,7 @@ func (s *AuthService) Login(request *protocol.LoginRequest) (rsp *protocol.Login | ||
60 | user, err = repository.User.GetUsersByMobile(request.Phone) | 60 | user, err = repository.User.GetUsersByMobile(request.Phone) |
61 | if err != nil { | 61 | if err != nil { |
62 | log.Error(err) | 62 | log.Error(err) |
63 | - err = protocol.NewErrWithMessage(2020, err) //账号不存在 | 63 | + err = protocol.NewErrWithMessage(2002, err) //账号不存在 |
64 | return | 64 | return |
65 | } | 65 | } |
66 | switch request.GrantType { | 66 | switch request.GrantType { |
@@ -149,8 +149,8 @@ func (s *AuthService) AccessToken(request *protocol.AccessTokenRequest) (rsp *pr | @@ -149,8 +149,8 @@ func (s *AuthService) AccessToken(request *protocol.AccessTokenRequest) (rsp *pr | ||
149 | } | 149 | } |
150 | userAuth.AccessToken = uid.NewV1().StringNoDash() | 150 | userAuth.AccessToken = uid.NewV1().StringNoDash() |
151 | userAuth.RefreshToken = uid.NewV1().StringNoDash() | 151 | userAuth.RefreshToken = uid.NewV1().StringNoDash() |
152 | - userAuth.AccessTokenExp = time.Now().Add(protocol.TokenExpire*time.Second) | ||
153 | - userAuth.RefreshTokenExp = time.Now().Add(protocol.TokenExpire*time.Second) | 152 | + userAuth.AccessTokenExp = time.Now().Add(protocol.TokenExpire * time.Second) |
153 | + userAuth.RefreshTokenExp = time.Now().Add(protocol.TokenExpire * time.Second) | ||
154 | if err = repository.UserAuth.UpdateUserAuthById(userAuth); err != nil { | 154 | if err = repository.UserAuth.UpdateUserAuthById(userAuth); err != nil { |
155 | log.Error(err) | 155 | log.Error(err) |
156 | return | 156 | return |
services/message/message.go
0 → 100644
1 | +package message | ||
2 | + | ||
3 | +import ( | ||
4 | + "gitlab.fjmaimaimai.com/mmm-go/gocomm/pkg/log" | ||
5 | + "opp/internal/repository" | ||
6 | + "opp/protocol" | ||
7 | +) | ||
8 | + | ||
9 | +func MessageCenter(header *protocol.RequestHeader, request *protocol.MessageCenterRequest) (rsp *protocol.MessageCenterResponse, err error) { | ||
10 | + var () | ||
11 | + rsp = &protocol.MessageCenterResponse{} | ||
12 | + err = repository.Message.GetUserMsgTotals(header.Uid, header.CompanyId, request.MsgType, &rsp.Totals) | ||
13 | + return | ||
14 | +} | ||
15 | + | ||
16 | +//标记已读 | ||
17 | +func MsgCenterRead(header *protocol.RequestHeader, request *protocol.MsgCenterReadRequest) (rsp *protocol.MsgCenterReadResponse, err error) { | ||
18 | + var () | ||
19 | + //rsp =&protocol.MsgCenterReadResponse{} | ||
20 | + err = repository.Message.UpdateUserMsgSetRead(header.Uid, header.CompanyId, request.MsgType, request.MsgId) | ||
21 | + if err != nil { | ||
22 | + log.Error(err) | ||
23 | + } | ||
24 | + return | ||
25 | +} | ||
26 | + | ||
27 | +//标记全部已读 | ||
28 | +func MsgCenterAllRead(header *protocol.RequestHeader, request *protocol.MsgCenterAllReadRequest) (rsp *protocol.MsgCenterAllReadResponse, err error) { | ||
29 | + var () | ||
30 | + err = repository.Message.UpdateUserMsgSetRead(header.Uid, header.CompanyId, request.MsgType, 0) | ||
31 | + if err != nil { | ||
32 | + log.Error(err) | ||
33 | + } | ||
34 | + return | ||
35 | +} |
-
请 注册 或 登录 后发表评论