作者 yangfu

增加 首页公告 消息中心-公告列表

@@ -13,3 +13,4 @@ EnableDocs = true @@ -13,3 +13,4 @@ EnableDocs = true
13 include "dev.conf" 13 include "dev.conf"
14 include "prod.conf" 14 include "prod.conf"
15 include "test.conf" 15 include "test.conf"
  16 +include "local.conf"
@@ -35,3 +35,6 @@ user_center_url ="http://suplus-ucenter-dev.fjmaimaimai.com" @@ -35,3 +35,6 @@ user_center_url ="http://suplus-ucenter-dev.fjmaimaimai.com"
35 user_center_salt ="rsF0pL!6DwjBO735" 35 user_center_salt ="rsF0pL!6DwjBO735"
36 user_center_app_key ="39aefef9e22744a3b2d2d3791824ae7b" 36 user_center_app_key ="39aefef9e22744a3b2d2d3791824ae7b"
37 user_center_app_secret ="cykbjnfqgctn" 37 user_center_app_secret ="cykbjnfqgctn"
  38 +
  39 +#Html5
  40 +h5_host = "https://web-open.fjmaimaimai.com"
  1 +[local]
  2 +#数据库相关
  3 +mysql_user = "${MYSQL_USER||root}"
  4 +mysql_password = "${MYSQL_PASSWORD||sutianxia2015}"
  5 +mysql_host = "${MYSQL_HOST||115.29.205.99}"
  6 +mysql_port = "${MYSQL_PORT||3306}"
  7 +mysql_db_name = "${MYSQL_DB_NAME||opportunity}"
  8 +
  9 +#日志
  10 +log_level = "${LOG_LEVEL||debug}"
  11 +aliyun_logs_access ="${aliyun_logs_access||F:/log/app.log}"
  12 +
  13 +
  14 +#redis相关配置
  15 +redis_add = "${REDIS_HOST||192.168.100.102}"
  16 +redis_add_port = "${REDIS_PORT||6379}"
  17 +redis_auth = "123456"
  18 +
  19 +#sms相关配置
  20 +yunpian_sms_sdk_url ="https://sms.yunpian.com/v2/sms/single_send.json"
  21 +yunpian_app_key ="0bf6fb10a11a68a95dee80901eb545b5"
  22 +
  23 +#存储 http://ability.fjmaimaimai.com:8080/
  24 +source_host ="http://192.168.139.137:8080/"
  25 +source_virtual_path=file/opp
  26 +source_path ="${aliyun_file_access||F:/file}
  27 +
  28 +#网易云信 IM
  29 +net_im_base_url ="https://api.netease.im/nimserver"
  30 +net_im_app_secret ="a8d231f5c13a"
  31 +net_im_app_key ="9c5410602597a7fe367aeeebd8210262"
  32 +
  33 +#统一用户中心 39aefef9e22744a3b2d2d3791824ae7b
  34 +user_center_url ="http://suplus-ucenter-dev.fjmaimaimai.com"
  35 +user_center_salt ="rsF0pL!6DwjBO735"
  36 +user_center_app_key ="39aefef9e22744a3b2d2d3791824ae7b"
  37 +user_center_app_secret ="cykbjnfqgctn"
  1 +package controllers
  2 +
  3 +import (
  4 + "encoding/json"
  5 + "gitlab.fjmaimaimai.com/mmm-go/gocomm/pkg/log"
  6 + "opp/protocol"
  7 + "opp/services/message"
  8 +)
  9 +
  10 +type H5Controller struct {
  11 + BaseController
  12 +}
  13 +
  14 +//Announcement H5公告详情
  15 +//@router /announcement [post]
  16 +func (this *H5Controller) Announcement() {
  17 + var msg *protocol.ResponseMessage
  18 + defer func() {
  19 + this.Resp(msg)
  20 + }()
  21 + var request *protocol.AnnouncementRequest
  22 + if err := json.Unmarshal(this.ByteBody, &request); err != nil {
  23 + log.Error(err)
  24 + msg = protocol.BadRequestParam(1)
  25 + return
  26 + }
  27 + if b, m := this.Valid(request); !b {
  28 + msg = m
  29 + return
  30 + }
  31 + header := GetRequestHeader(this.Ctx)
  32 + msg = protocol.NewReturnResponse(message.H5Announcement(header, request))
  33 +}
  34 +
  35 +//AnnouncementSubmit 完成公告操作
  36 +//@router /announcementSubmit [post]
  37 +func (this *H5Controller) AnnouncementSubmit() {
  38 + var msg *protocol.ResponseMessage
  39 + defer func() {
  40 + this.Resp(msg)
  41 + }()
  42 + var request *protocol.AnnouncementSubmitRequest
  43 + if err := json.Unmarshal(this.ByteBody, &request); err != nil {
  44 + log.Error(err)
  45 + msg = protocol.BadRequestParam(1)
  46 + return
  47 + }
  48 + if b, m := this.Valid(request); !b {
  49 + msg = m
  50 + return
  51 + }
  52 + header := GetRequestHeader(this.Ctx)
  53 + msg = protocol.NewReturnResponse(message.H5AnnouncementSubmit(header, request))
  54 +}
@@ -96,7 +96,7 @@ func (this *MessageController) MsgInteractive() { @@ -96,7 +96,7 @@ func (this *MessageController) MsgInteractive() {
96 msg = protocol.NewReturnResponse(message.MsgInteractive(header, request)) 96 msg = protocol.NewReturnResponse(message.MsgInteractive(header, request))
97 } 97 }
98 98
99 -//Announcements 99 +//Announcements 公告列表
100 //@router /announcements [post] 100 //@router /announcements [post]
101 func (this *MessageController) Announcements() { 101 func (this *MessageController) Announcements() {
102 var msg *protocol.ResponseMessage 102 var msg *protocol.ResponseMessage
@@ -116,3 +116,45 @@ func (this *MessageController) Announcements() { @@ -116,3 +116,45 @@ func (this *MessageController) Announcements() {
116 header := controllers.GetRequestHeader(this.Ctx) 116 header := controllers.GetRequestHeader(this.Ctx)
117 msg = protocol.NewReturnResponse(message.Announcements(header, request)) 117 msg = protocol.NewReturnResponse(message.Announcements(header, request))
118 } 118 }
  119 +
  120 +//AnnouncementRead 公告已读
  121 +//@router /announcementRead [post]
  122 +func (this *MessageController) AnnouncementRead() {
  123 + var msg *protocol.ResponseMessage
  124 + defer func() {
  125 + this.Resp(msg)
  126 + }()
  127 + var request *protocol.AnnouncementReadRequest
  128 + if err := json.Unmarshal(this.ByteBody, &request); err != nil {
  129 + log.Error(err)
  130 + msg = protocol.BadRequestParam(1)
  131 + return
  132 + }
  133 + if b, m := this.Valid(request); !b {
  134 + msg = m
  135 + return
  136 + }
  137 + header := controllers.GetRequestHeader(this.Ctx)
  138 + msg = protocol.NewReturnResponse(message.AnnouncementRead(header, request))
  139 +}
  140 +
  141 +//MsgCompanyNotice 消息中心-公司公告
  142 +//@router /msgCompanyNotice [post]
  143 +func (this *MessageController) MsgCompanyNotice() {
  144 + var msg *protocol.ResponseMessage
  145 + defer func() {
  146 + this.Resp(msg)
  147 + }()
  148 + var request *protocol.MsgCompanyNoticeRequest
  149 + if err := json.Unmarshal(this.ByteBody, &request); err != nil {
  150 + log.Error(err)
  151 + msg = protocol.BadRequestParam(1)
  152 + return
  153 + }
  154 + if b, m := this.Valid(request); !b {
  155 + msg = m
  156 + return
  157 + }
  158 + header := controllers.GetRequestHeader(this.Ctx)
  159 + msg = protocol.NewReturnResponse(message.MsgCompanyNotice(header, request))
  160 +}
@@ -130,7 +130,7 @@ func PrintLogSql(sql string, param ...interface{}) { @@ -130,7 +130,7 @@ func PrintLogSql(sql string, param ...interface{}) {
130 130
131 //ExecuteQueryOne 执行原生sql查询单条记录;结果用结构体接收 131 //ExecuteQueryOne 执行原生sql查询单条记录;结果用结构体接收
132 func ExecuteQueryOne(result interface{}, sqlstr string, param ...interface{}) error { 132 func ExecuteQueryOne(result interface{}, sqlstr string, param ...interface{}) error {
133 - PrintLogSql(sqlstr, param...) 133 + //PrintLogSql(sqlstr, param...)
134 var err error 134 var err error
135 o := orm.NewOrm() 135 o := orm.NewOrm()
136 err = ExecuteQueryOneWithOrmer(o, result, sqlstr, param) 136 err = ExecuteQueryOneWithOrmer(o, result, sqlstr, param)
@@ -49,6 +49,7 @@ func init() { @@ -49,6 +49,7 @@ func init() {
49 MaxIdle: 100, 49 MaxIdle: 100,
50 MaxOpen: 100, 50 MaxOpen: 100,
51 }) 51 })
  52 +
52 //TODO:邮件服务配置 53 //TODO:邮件服务配置
53 common.InitMailService(&common.MailConfig{ 54 common.InitMailService(&common.MailConfig{
54 //Host:"smtp.qq.com", 55 //Host:"smtp.qq.com",
1 package models 1 package models
2 2
3 import ( 3 import (
4 - "errors"  
5 "fmt" 4 "fmt"
6 - "reflect"  
7 - "strings"  
8 "time" 5 "time"
9 6
10 "github.com/astaxie/beego/orm" 7 "github.com/astaxie/beego/orm"
@@ -12,19 +9,20 @@ import ( @@ -12,19 +9,20 @@ import (
12 9
13 type Bulletin struct { 10 type Bulletin struct {
14 Id int `orm:"column(id);auto"` 11 Id int `orm:"column(id);auto"`
15 - Title string `orm:"column(title);size(2000)" description:"标题"` 12 + Title string `orm:"column(title);size(2000);null" description:"标题"`
16 Content string `orm:"column(content);null" description:"内容"` 13 Content string `orm:"column(content);null" description:"内容"`
17 Cover string `orm:"column(cover);size(255);null" description:"封面地址"` 14 Cover string `orm:"column(cover);size(255);null" description:"封面地址"`
18 W int `orm:"column(w);null" description:"宽"` 15 W int `orm:"column(w);null" description:"宽"`
19 H int `orm:"column(h);null" description:"高"` 16 H int `orm:"column(h);null" description:"高"`
20 - Type int8 `orm:"column(type);null" description:"公告类型(0图+跳转链接、1链接)"` 17 + Type int8 `orm:"column(type);null" description:"公告类型(1图+跳转链接、2纯文本)"`
21 Receiver string `orm:"column(receiver);null" description:"接收者"` 18 Receiver string `orm:"column(receiver);null" description:"接收者"`
22 - QuestionSwitch int8 `orm:"column(question_switch);null" description:"设置问题开关"`  
23 - CreateTime time.Time `orm:"column(createTime);type(timestamp);null" description:"创建时间"`  
24 - UpdateTime time.Time `orm:"column(updateTime);type(timestamp);null" description:"更新时间"`  
25 - AllowClose int8 `orm:"column(allowClose);null" description:"允许关闭公告(0允许,1禁止)"`  
26 - CompanyId int `orm:"column(company_id);null" description:"公司Id"`  
27 - Status uint8 `orm:"column(status)" description:"状态 0-下架 1- 上架"` 19 + QuestionSwitch int8 `orm:"column(question_switch);null" description:"设置问题开关 (是否有问题)"`
  20 + CreateAt time.Time `orm:"column(create_at);type(timestamp);null" description:"创建时间"`
  21 + UpdateAt time.Time `orm:"column(update_at);type(timestamp);null" description:"更新时间"`
  22 + AllowClose int8 `orm:"column(allow_close);null" description:"允许关闭公告(0允许关闭窗口,1阅读完才能关闭,2选项打勾后才能关闭)"`
  23 + //AllowCondition int8 `orm:"column(allow_condition);null" description:"关闭条件 (1(bit 0):公告内容查看完 2(bit 1):回答完问题)"`
  24 + CompanyId int64 `orm:"column(company_id);null" description:"公司Id"`
  25 + Status int8 `orm:"column(status)" description:"状态 1-下架 2-上架"`
28 } 26 }
29 27
30 func (t *Bulletin) TableName() string { 28 func (t *Bulletin) TableName() string {
@@ -54,84 +52,6 @@ func GetBulletinById(id int) (v *Bulletin, err error) { @@ -54,84 +52,6 @@ func GetBulletinById(id int) (v *Bulletin, err error) {
54 return nil, err 52 return nil, err
55 } 53 }
56 54
57 -// GetAllBulletin retrieves all Bulletin matches certain condition. Returns empty list if  
58 -// no records exist  
59 -func GetAllBulletin(query map[string]string, fields []string, sortby []string, order []string,  
60 - offset int64, limit int64) (ml []interface{}, err error) {  
61 - o := orm.NewOrm()  
62 - qs := o.QueryTable(new(Bulletin))  
63 - // query k=v  
64 - for k, v := range query {  
65 - // rewrite dot-notation to Object__Attribute  
66 - k = strings.Replace(k, ".", "__", -1)  
67 - if strings.Contains(k, "isnull") {  
68 - qs = qs.Filter(k, (v == "true" || v == "1"))  
69 - } else {  
70 - qs = qs.Filter(k, v)  
71 - }  
72 - }  
73 - // order by:  
74 - var sortFields []string  
75 - if len(sortby) != 0 {  
76 - if len(sortby) == len(order) {  
77 - // 1) for each sort field, there is an associated order  
78 - for i, v := range sortby {  
79 - orderby := ""  
80 - if order[i] == "desc" {  
81 - orderby = "-" + v  
82 - } else if order[i] == "asc" {  
83 - orderby = v  
84 - } else {  
85 - return nil, errors.New("Error: Invalid order. Must be either [asc|desc]")  
86 - }  
87 - sortFields = append(sortFields, orderby)  
88 - }  
89 - qs = qs.OrderBy(sortFields...)  
90 - } else if len(sortby) != len(order) && len(order) == 1 {  
91 - // 2) there is exactly one order, all the sorted fields will be sorted by this order  
92 - for _, v := range sortby {  
93 - orderby := ""  
94 - if order[0] == "desc" {  
95 - orderby = "-" + v  
96 - } else if order[0] == "asc" {  
97 - orderby = v  
98 - } else {  
99 - return nil, errors.New("Error: Invalid order. Must be either [asc|desc]")  
100 - }  
101 - sortFields = append(sortFields, orderby)  
102 - }  
103 - } else if len(sortby) != len(order) && len(order) != 1 {  
104 - return nil, errors.New("Error: 'sortby', 'order' sizes mismatch or 'order' size is not 1")  
105 - }  
106 - } else {  
107 - if len(order) != 0 {  
108 - return nil, errors.New("Error: unused 'order' fields")  
109 - }  
110 - }  
111 -  
112 - var l []Bulletin  
113 - qs = qs.OrderBy(sortFields...)  
114 - if _, err = qs.Limit(limit, offset).All(&l, fields...); err == nil {  
115 - if len(fields) == 0 {  
116 - for _, v := range l {  
117 - ml = append(ml, v)  
118 - }  
119 - } else {  
120 - // trim unused fields  
121 - for _, v := range l {  
122 - m := make(map[string]interface{})  
123 - val := reflect.ValueOf(v)  
124 - for _, fname := range fields {  
125 - m[fname] = val.FieldByName(fname).Interface()  
126 - }  
127 - ml = append(ml, m)  
128 - }  
129 - }  
130 - return ml, nil  
131 - }  
132 - return nil, err  
133 -}  
134 -  
135 // UpdateBulletin updates Bulletin by Id and returns error if 55 // UpdateBulletin updates Bulletin by Id and returns error if
136 // the record to be updated doesn't exist 56 // the record to be updated doesn't exist
137 func UpdateBulletinById(m *Bulletin) (err error) { 57 func UpdateBulletinById(m *Bulletin) (err error) {
@@ -9,12 +9,12 @@ import ( @@ -9,12 +9,12 @@ import (
9 9
10 type BulletinQuestion struct { 10 type BulletinQuestion struct {
11 Id int `orm:"column(id);auto"` 11 Id int `orm:"column(id);auto"`
12 - BulletinId int `orm:"column(bulletin_id)" description:"公告id"`  
13 - Type int8 `orm:"column(type)" description:"类型:0-单选,1-多选"`  
14 - Title string `orm:"column(title);size(2000)" description:"标题"`  
15 - Option string `orm:"column(option);size(2000)" description:"内容"`  
16 - CreateTime time.Time `orm:"column(createTime);type(timestamp)" description:"创建时间"`  
17 - UpdateTime time.Time `orm:"column(updateTime);type(timestamp)" description:"更新时间"` 12 + BulletinId int `orm:"column(bulletin_id);null" description:"公告id"`
  13 + Type int8 `orm:"column(type);null" description:"类型:0-单选,1-多选"`
  14 + Title string `orm:"column(title);size(2000);null" description:"标题"`
  15 + Content string `orm:"column(content);size(2000);null" description:"内容"`
  16 + CreateAt time.Time `orm:"column(create_at);type(timestamp);null" description:"创建时间"`
  17 + UpdateAt time.Time `orm:"column(update_at);type(timestamp);null" description:"更新时间"`
18 } 18 }
19 19
20 func (t *BulletinQuestion) TableName() string { 20 func (t *BulletinQuestion) TableName() string {
@@ -64,3 +64,12 @@ func UpdateBulletinQuestionById(m *BulletinQuestion) (err error) { @@ -64,3 +64,12 @@ func UpdateBulletinQuestionById(m *BulletinQuestion) (err error) {
64 } 64 }
65 return 65 return
66 } 66 }
  67 +
  68 +func GetBulletinQuestionByBulletinId(id int) (v *BulletinQuestion, err error) {
  69 + o := orm.NewOrm()
  70 + sql := "select * from bulletin_question where bulletin_id=?"
  71 + if err = o.Raw(sql, id).QueryRow(&v); err == nil {
  72 + return v, nil
  73 + }
  74 + return nil, err
  75 +}
@@ -9,12 +9,12 @@ import ( @@ -9,12 +9,12 @@ import (
9 9
10 type BulletinQuestionAnswer struct { 10 type BulletinQuestionAnswer struct {
11 Id int `orm:"column(id);auto"` 11 Id int `orm:"column(id);auto"`
12 - Answer string `orm:"column(answer)" description:"答案"`  
13 - BulletinId int `orm:"column(bulletin_id)" description:"公告id"`  
14 - BulletinQuestionId int `orm:"column(bulletin_question_id)" description:"公告问题id"`  
15 - Uid int64 `orm:"column(uid)" description:"用户id"`  
16 - CreateTime time.Time `orm:"column(createTime);type(timestamp)" description:"创建时间"`  
17 - UpdateTime time.Time `orm:"column(updateTime);type(timestamp)" description:"更新时间"` 12 + Answer string `orm:"column(answer);null" description:"答案"`
  13 + BulletinId int `orm:"column(bulletin_id);null" description:"公告id"`
  14 + BulletinQuestionId int `orm:"column(bulletin_question_id);null" description:"公告问题id"`
  15 + Uid int64 `orm:"column(uid);null" description:"用户id"`
  16 + CreateAt time.Time `orm:"column(create_at);type(timestamp);null" description:"创建时间"`
  17 + UpdateAt time.Time `orm:"column(update_at);type(timestamp);null" description:"更新时间"`
18 } 18 }
19 19
20 func (t *BulletinQuestionAnswer) TableName() string { 20 func (t *BulletinQuestionAnswer) TableName() string {
@@ -79,3 +79,12 @@ func DeleteBulletinQuestionAnswer(id int) (err error) { @@ -79,3 +79,12 @@ func DeleteBulletinQuestionAnswer(id int) (err error) {
79 } 79 }
80 return 80 return
81 } 81 }
  82 +
  83 +func GetBulletinQuestionAnswerBy(bulletinId int, uid int64) (v *BulletinQuestionAnswer, err error) {
  84 + o := orm.NewOrm()
  85 + sql := "select * from bulletin_question_answer where bulletin_id=? and uid=?"
  86 + if err = o.Raw(sql, bulletinId, uid).QueryRow(&v); err == nil {
  87 + return v, nil
  88 + }
  89 + return nil, err
  90 +}
@@ -3,6 +3,7 @@ package models @@ -3,6 +3,7 @@ package models
3 import ( 3 import (
4 "fmt" 4 "fmt"
5 "gitlab.fjmaimaimai.com/mmm-go/gocomm/pkg/mybeego" 5 "gitlab.fjmaimaimai.com/mmm-go/gocomm/pkg/mybeego"
  6 + "opp/internal/utils"
6 "time" 7 "time"
7 8
8 "github.com/astaxie/beego/orm" 9 "github.com/astaxie/beego/orm"
@@ -22,7 +23,20 @@ type UserMsg struct { @@ -22,7 +23,20 @@ type UserMsg struct {
22 } 23 }
23 24
24 const ( 25 const (
25 - SqlUserMsgUnRead = "select * from user_msg where company_id=? and receive_user_id=? and msg_type=? and is_read=0" 26 + MsgTypeBulletin = 1 //公告
  27 + MsgTypeCommend = 2 //表彰
  28 + MsgTypeInteraction = 4 //互动消息
  29 + MsgTypeAudit = 8 //机会审核
  30 +)
  31 +const (
  32 + SourceTypeChance = 1
  33 + SourceTypeComment = 2
  34 + SourceTypeBulletin = 3
  35 +)
  36 +const (
  37 + SqlUserMsgsUnRead = "select * from user_msg where company_id=? and receive_user_id=? and msg_type=? and is_read=0 order by create_at desc" //所有未读消息
  38 + SqlUserMsgUnRead = "select * from user_msg where source_id=? and company_id=? and receive_user_id=? and msg_type=? and is_read=0 order by create_at desc" //特定未读消息
  39 + SqlUserMsg = "select * from user_msg where source_id=? and receive_user_id=? and msg_type=? " //特定未读消息
26 ) 40 )
27 41
28 func (t *UserMsg) TableName() string { 42 func (t *UserMsg) TableName() string {
@@ -130,3 +144,25 @@ func GetUserMsgs(userId, companyId int64, msgType int, sourceType int, lastId in @@ -130,3 +144,25 @@ func GetUserMsgs(userId, companyId int64, msgType int, sourceType int, lastId in
130 } 144 }
131 return 145 return
132 } 146 }
  147 +
  148 +func GetUserMsgsBulletin(userId, companyId int64, msgType int, lastId int64, pageSize int, v interface{}) (total int, err error) {
  149 + sql := `select b.id,b.title,unix_timestamp(b.update_at) update_at,a.is_read `
  150 + sqlCount := `select count(0) `
  151 + where := `from user_msg a,bulletin b where a.receive_user_id =? and a.company_id=? and a.source_id = b.id and a.msg_type=? and a.company_id=? and b.status=2 `
  152 + sqlCount += where
  153 + if err = utils.ExecuteQueryOne(&total, sqlCount, userId, companyId, msgType, companyId); err != nil {
  154 + return
  155 + }
  156 + if lastId > 0 {
  157 + where += fmt.Sprintf(` and b.id>%v`, lastId)
  158 + }
  159 + if v == nil {
  160 + return
  161 + }
  162 + where += ` order by b.update_at desc`
  163 + sql += where + " limit ?"
  164 + if err = utils.ExecuteQueryAll(v, sql, userId, companyId, msgType, companyId, pageSize); err != nil {
  165 + return
  166 + }
  167 + return
  168 +}
@@ -22,6 +22,7 @@ var errmessge ErrorMap = map[int]string{ @@ -22,6 +22,7 @@ var errmessge ErrorMap = map[int]string{
22 2027: "密码必须至少有6个字符", 22 2027: "密码必须至少有6个字符",
23 2028: "请输入正确的旧密码", 23 2028: "请输入正确的旧密码",
24 2029: "当前手机号已存在,请重新输入", 24 2029: "当前手机号已存在,请重新输入",
  25 + 2060: "读取公告失败",
25 4139: "authCode无效或过期", 26 4139: "authCode无效或过期",
26 4140: "refreshToken过期,需要重新登录授权", 27 4140: "refreshToken过期,需要重新登录授权",
27 4141: "accessToken过期或无效,需要进行重新获取令牌", 28 4141: "accessToken过期或无效,需要进行重新获取令牌",
@@ -94,9 +95,9 @@ func (m Message) Unmarshal(v interface{}) error { @@ -94,9 +95,9 @@ func (m Message) Unmarshal(v interface{}) error {
94 /**************公告****************/ 95 /**************公告****************/
95 type Question struct { 96 type Question struct {
96 Id int `json:"id"` 97 Id int `json:"id"`
97 - Type int `json:"type" valid:"Required"` 98 + Type int `json:"way" valid:"Required"`
98 Title string `json:"title" valid:"Required"` 99 Title string `json:"title" valid:"Required"`
99 - Content []QuestionContent `json:"content" valid:"Required"` 100 + Content []QuestionContent `json:"options" valid:"Required"`
100 } 101 }
101 type QuestionContent struct { 102 type QuestionContent struct {
102 Id int `json:"id" valid:"Required"` 103 Id int `json:"id" valid:"Required"`
@@ -134,7 +135,7 @@ type Receiver struct { @@ -134,7 +135,7 @@ type Receiver struct {
134 type AnnouncementsRequest struct { 135 type AnnouncementsRequest struct {
135 } 136 }
136 type AnnouncementsResponse struct { 137 type AnnouncementsResponse struct {
137 - Lists []Announcement `json:"lists"` 138 + Lists []Announcement `json:"lists,omitempty"`
138 } 139 }
139 140
140 type Announcement struct { 141 type Announcement struct {
@@ -145,3 +146,56 @@ type Announcement struct { @@ -145,3 +146,56 @@ type Announcement struct {
145 Link string `json:"link"` 146 Link string `json:"link"`
146 Control int `json:"Control"` 147 Control int `json:"Control"`
147 } 148 }
  149 +
  150 +/*AnnouncementRead */
  151 +type AnnouncementReadRequest struct {
  152 + Id int `json:"id" valid:"Required"` //公告id
  153 +}
  154 +type AnnouncementReadResponse struct {
  155 +}
  156 +
  157 +/*MsgCompanyNotice 消息中心-公司公告 */
  158 +type MsgCompanyNoticeRequest struct {
  159 + LastId int64 `json:"lastId"`
  160 + PageSize int `json:"pageSize" valid:"Required"`
  161 +}
  162 +type MsgCompanyNoticeResponse struct {
  163 + Lists []UserMsg `json:"lists"`
  164 + Total int `json:"total"`
  165 +}
  166 +
  167 +/*Announcement H5公告详情*/
  168 +type AnnouncementRequest struct {
  169 + Id int `json:"id" valid:"Required"`
  170 + Uid int `json:"uid" valid:"Required"`
  171 +}
  172 +type AnnouncementResponse struct {
  173 + Announcement H5Announcement `json:"announcement"`
  174 +}
  175 +
  176 +type H5Announcement struct {
  177 + Id int `json:"id"`
  178 + Title string `json:"title"`
  179 + Content string `json:"content"`
  180 + Control int `json:"control"`
  181 + IsRead int `json:"isRead"`
  182 + Vote Question `json:"vote"`
  183 + VoteResults []int `json:"voteResults"`
  184 + EditContent string `json:"editContent"`
  185 +}
  186 +
  187 +/*AnnouncementSubmit H5完成公告操作*/
  188 +type AnnouncementSubmitRequest struct {
  189 + Id int `json:"id" valid:"Required"` //公告id
  190 + Uid int64 `json:"uid"`
  191 + VoteResults []int `json:"voteResults"`
  192 + VoteId int `json:"voteId"` //投票问题id
  193 + EditContent string `json:"editContent"`
  194 +}
  195 +type AnnouncementSubmitResponse struct {
  196 +}
  197 +
  198 +type Answer struct {
  199 + VoteResults []int `json:"voteResults"`
  200 + EditContent string `json:"editContent"`
  201 +}
  1 +package routers
  2 +
  3 +import (
  4 + "github.com/astaxie/beego"
  5 + "github.com/astaxie/beego/context/param"
  6 +)
  7 +
  8 +func init() {
  9 +
  10 + beego.GlobalControllerRouter["opp/controllers:H5Controller"] = append(beego.GlobalControllerRouter["opp/controllers:H5Controller"],
  11 + beego.ControllerComments{
  12 + Method: "Announcement",
  13 + Router: `/announcement`,
  14 + AllowHTTPMethods: []string{"post"},
  15 + MethodParams: param.Make(),
  16 + Params: nil})
  17 +
  18 + beego.GlobalControllerRouter["opp/controllers:H5Controller"] = append(beego.GlobalControllerRouter["opp/controllers:H5Controller"],
  19 + beego.ControllerComments{
  20 + Method: "AnnouncementSubmit",
  21 + Router: `/announcementSubmit`,
  22 + AllowHTTPMethods: []string{"post"},
  23 + MethodParams: param.Make(),
  24 + Params: nil})
  25 +
  26 +}
  1 +package routers
  2 +
  3 +import (
  4 + "github.com/astaxie/beego"
  5 + "github.com/astaxie/beego/context/param"
  6 +)
  7 +
  8 +func init() {
  9 +
  10 + beego.GlobalControllerRouter["opp/controllers:H5Controller"] = append(beego.GlobalControllerRouter["opp/controllers:H5Controller"],
  11 + beego.ControllerComments{
  12 + Method: "Announcement",
  13 + Router: `/announcement`,
  14 + AllowHTTPMethods: []string{"post"},
  15 + MethodParams: param.Make(),
  16 + Params: nil})
  17 +
  18 + beego.GlobalControllerRouter["opp/controllers:H5Controller"] = append(beego.GlobalControllerRouter["opp/controllers:H5Controller"],
  19 + beego.ControllerComments{
  20 + Method: "AnnouncementSubmit",
  21 + Router: `/announcementSubmit`,
  22 + AllowHTTPMethods: []string{"post"},
  23 + MethodParams: param.Make(),
  24 + Params: nil})
  25 +
  26 +}
@@ -153,6 +153,22 @@ func init() { @@ -153,6 +153,22 @@ func init() {
153 153
154 beego.GlobalControllerRouter["opp/controllers/v1:MessageController"] = append(beego.GlobalControllerRouter["opp/controllers/v1:MessageController"], 154 beego.GlobalControllerRouter["opp/controllers/v1:MessageController"] = append(beego.GlobalControllerRouter["opp/controllers/v1:MessageController"],
155 beego.ControllerComments{ 155 beego.ControllerComments{
  156 + Method: "AnnouncementRead",
  157 + Router: `/announcementRead`,
  158 + AllowHTTPMethods: []string{"post"},
  159 + MethodParams: param.Make(),
  160 + Params: nil})
  161 +
  162 + beego.GlobalControllerRouter["opp/controllers/v1:MessageController"] = append(beego.GlobalControllerRouter["opp/controllers/v1:MessageController"],
  163 + beego.ControllerComments{
  164 + Method: "Announcements",
  165 + Router: `/announcements`,
  166 + AllowHTTPMethods: []string{"post"},
  167 + MethodParams: param.Make(),
  168 + Params: nil})
  169 +
  170 + beego.GlobalControllerRouter["opp/controllers/v1:MessageController"] = append(beego.GlobalControllerRouter["opp/controllers/v1:MessageController"],
  171 + beego.ControllerComments{
156 Method: "MessageCenter", 172 Method: "MessageCenter",
157 Router: `/messageCenter`, 173 Router: `/messageCenter`,
158 AllowHTTPMethods: []string{"post"}, 174 AllowHTTPMethods: []string{"post"},
@@ -177,6 +193,14 @@ func init() { @@ -177,6 +193,14 @@ func init() {
177 193
178 beego.GlobalControllerRouter["opp/controllers/v1:MessageController"] = append(beego.GlobalControllerRouter["opp/controllers/v1:MessageController"], 194 beego.GlobalControllerRouter["opp/controllers/v1:MessageController"] = append(beego.GlobalControllerRouter["opp/controllers/v1:MessageController"],
179 beego.ControllerComments{ 195 beego.ControllerComments{
  196 + Method: "MsgCompanyNotice",
  197 + Router: `/msgCompanyNotice`,
  198 + AllowHTTPMethods: []string{"post"},
  199 + MethodParams: param.Make(),
  200 + Params: nil})
  201 +
  202 + beego.GlobalControllerRouter["opp/controllers/v1:MessageController"] = append(beego.GlobalControllerRouter["opp/controllers/v1:MessageController"],
  203 + beego.ControllerComments{
180 Method: "MsgInteractive", 204 Method: "MsgInteractive",
181 Router: `/msgInteractive`, 205 Router: `/msgInteractive`,
182 AllowHTTPMethods: []string{"post"}, 206 AllowHTTPMethods: []string{"post"},
@@ -24,6 +24,10 @@ func init() { @@ -24,6 +24,10 @@ func init() {
24 beego.NSNamespace("department", beego.NSBefore(controllers.FilterComm), beego.NSInclude(&v1.DepartmentController{})), 24 beego.NSNamespace("department", beego.NSBefore(controllers.FilterComm), beego.NSInclude(&v1.DepartmentController{})),
25 ) 25 )
26 beego.AddNamespace(nsV1) 26 beego.AddNamespace(nsV1)
  27 +
  28 + nsH5 := beego.NewNamespace("h5", beego.NSInclude(&controllers.H5Controller{}))
  29 + beego.AddNamespace(nsH5)
  30 +
27 beego.SetStaticPath("/file/opp", beego.AppConfig.String("source_path")) 31 beego.SetStaticPath("/file/opp", beego.AppConfig.String("source_path"))
28 beego.SetStaticPath("/log/opp", beego.AppConfig.String("aliyun_logs_access")) 32 beego.SetStaticPath("/log/opp", beego.AppConfig.String("aliyun_logs_access"))
29 beego.Handler("/metrics", promhttp.Handler()) 33 beego.Handler("/metrics", promhttp.Handler())
1 package message 1 package message
2 2
3 import ( 3 import (
  4 + "encoding/json"
  5 + "fmt"
  6 + "github.com/astaxie/beego"
  7 + "github.com/astaxie/beego/orm"
  8 + "gitlab.fjmaimaimai.com/mmm-go/gocomm/common"
4 "gitlab.fjmaimaimai.com/mmm-go/gocomm/pkg/log" 9 "gitlab.fjmaimaimai.com/mmm-go/gocomm/pkg/log"
5 "opp/internal/repository" 10 "opp/internal/repository"
  11 + "opp/internal/utils"
6 "opp/models" 12 "opp/models"
7 "opp/protocol" 13 "opp/protocol"
  14 + "time"
8 ) 15 )
9 16
10 func MessageCenter(header *protocol.RequestHeader, request *protocol.MessageCenterRequest) (rsp *protocol.MessageCenterResponse, err error) { 17 func MessageCenter(header *protocol.RequestHeader, request *protocol.MessageCenterRequest) (rsp *protocol.MessageCenterResponse, err error) {
@@ -71,9 +78,240 @@ func MsgInteractive(header *protocol.RequestHeader, request *protocol.MsgInterac @@ -71,9 +78,240 @@ func MsgInteractive(header *protocol.RequestHeader, request *protocol.MsgInterac
71 //未读公告列表 78 //未读公告列表
72 func Announcements(header *protocol.RequestHeader, request *protocol.AnnouncementsRequest) (rsp *protocol.AnnouncementsResponse, err error) { 79 func Announcements(header *protocol.RequestHeader, request *protocol.AnnouncementsRequest) (rsp *protocol.AnnouncementsResponse, err error) {
73 var ( 80 var (
74 - //userMsg []*models.UserMsg 81 + userMsg []*models.UserMsg
  82 + bulletin *models.Bulletin
75 ) 83 )
76 - //if err = utils.ExecuteQueryAll(&userMsg,models.SqlUserMsgUnRead,header.CompanyId,header.)  
77 rsp = &protocol.AnnouncementsResponse{} 84 rsp = &protocol.AnnouncementsResponse{}
  85 + if err = utils.ExecuteQueryAll(&userMsg, models.SqlUserMsgsUnRead, header.CompanyId, header.UserId, models.MsgTypeBulletin); err != nil {
  86 + if err == orm.ErrNoRows {
  87 + err = nil
  88 + return
  89 + }
  90 + log.Error(err)
  91 + return
  92 + }
  93 + for i := 0; i < len(userMsg); i++ {
  94 + msg := userMsg[i]
  95 + if bulletin, err = models.GetBulletinById(int(msg.SourceId)); err != nil {
  96 + if orm.ErrNoRows == err {
  97 + err = nil
  98 + continue
  99 + }
  100 + log.Error(msg.SourceId, err)
  101 + continue
  102 + }
  103 + item := protocol.Announcement{
  104 + Id: bulletin.Id,
  105 + Type: int(bulletin.Type),
  106 + Title: bulletin.Title,
  107 + Control: int(bulletin.AllowClose),
  108 + //link:'https://web-open.fjmaimaimai.com/#/ability/announcement?id='+announcementCfgData[i].id+'&uid='+param.uid
  109 + Link: fmt.Sprintf("%v#/ability/announcement?id=%v&uid=%v", beego.AppConfig.String("h5_host"), bulletin.Id, msg.ReceiveUserId),
  110 + }
  111 + item.Cover = protocol.Cover{
  112 + Path: bulletin.Cover,
  113 + H: bulletin.H,
  114 + W: bulletin.W,
  115 + }
  116 + rsp.Lists = append(rsp.Lists, item)
  117 + }
  118 + return
  119 +}
  120 +
  121 +//公告已读
  122 +func AnnouncementRead(header *protocol.RequestHeader, request *protocol.AnnouncementReadRequest) (rsp *protocol.AnnouncementReadResponse, err error) {
  123 + var (
  124 + bulletin *models.Bulletin
  125 + userMsg *models.UserMsg
  126 + )
  127 + if bulletin, err = models.GetBulletinById(request.Id); err != nil {
  128 + log.Error(err)
  129 + err = protocol.NewErrWithMessage(2060)
  130 + return
  131 + }
  132 + if int64(bulletin.CompanyId) != header.CompanyId {
  133 + err = protocol.NewErrWithMessage(2060)
  134 + return
  135 + }
  136 + if err = utils.ExecuteQueryOne(&userMsg, models.SqlUserMsgUnRead, bulletin.Id, header.CompanyId, header.UserId, models.MsgTypeBulletin); err != nil {
  137 + //if err==orm.ErrNoRows{
  138 + // err=nil
  139 + // return
  140 + //}
  141 + log.Error(err)
  142 + return
  143 + }
  144 + if userMsg.IsRead == 1 {
  145 + return
  146 + }
  147 + if err = utils.UpdateTableByMap(userMsg, map[string]interface{}{"IsRead": int8(1)}); err != nil {
  148 + log.Error(err)
  149 + return
  150 + }
  151 + rsp = &protocol.AnnouncementReadResponse{}
  152 + return
  153 +}
  154 +
  155 +//消息中心-公司公告
  156 +func MsgCompanyNotice(header *protocol.RequestHeader, request *protocol.MsgCompanyNoticeRequest) (rsp *protocol.MsgCompanyNoticeResponse, err error) {
  157 + type MsgBulletin struct {
  158 + Id int `orm:"column(id)"`
  159 + Title string `orm:"column(title)"`
  160 + UpdateTime int64 `orm:"column(update_at)"`
  161 + IsRead int8 `orm:"column(is_read)"`
  162 + }
  163 + var (
  164 + msgBulletins []*MsgBulletin
  165 + total int
  166 + )
  167 + if total, err = models.GetUserMsgsBulletin(header.UserId, header.CompanyId, models.MsgTypeBulletin, request.LastId, request.PageSize, &msgBulletins); err != nil {
  168 + log.Error(err)
  169 + return
  170 + }
  171 + rsp = &protocol.MsgCompanyNoticeResponse{}
  172 + rsp.Total = total
  173 + for i := range msgBulletins {
  174 + tmp := msgBulletins[i]
  175 + rsp.Lists = append(rsp.Lists, protocol.UserMsg{
  176 + Id: int64(tmp.Id),
  177 + SourceType: models.MsgTypeBulletin,
  178 + Content: tmp.Title,
  179 + CreateAt: tmp.UpdateTime,
  180 + IsRead: int(tmp.IsRead),
  181 + })
  182 + }
  183 + return
  184 +}
  185 +
  186 +//H5公告详情
  187 +func H5Announcement(header *protocol.RequestHeader, request *protocol.AnnouncementRequest) (rsp *protocol.AnnouncementResponse, err error) {
  188 + var (
  189 + bulletin *models.Bulletin
  190 + question *models.BulletinQuestion
  191 + userMsg *models.UserMsg
  192 + bulletinAnswer *models.BulletinQuestionAnswer
  193 + setRead bool = false
  194 + answer *protocol.Answer
  195 + )
  196 + if bulletin, err = models.GetBulletinById(request.Id); err != nil {
  197 + log.Error(err.Error())
  198 + err = protocol.NewErrWithMessage(2060)
  199 + return
  200 + }
  201 + if err = utils.ExecuteQueryOne(&userMsg, models.SqlUserMsg, request.Id, request.Uid, models.MsgTypeBulletin); err != nil {
  202 + log.Error(err)
  203 + err = protocol.NewErrWithMessage(2060)
  204 + return
  205 + }
  206 + rsp = &protocol.AnnouncementResponse{}
  207 + rsp.Announcement = protocol.H5Announcement{
  208 + Id: bulletin.Id,
  209 + Title: bulletin.Title,
  210 + Content: bulletin.Content,
  211 + Control: int(bulletin.AllowClose),
  212 + IsRead: int(userMsg.IsRead),
  213 + }
  214 + if bulletin.QuestionSwitch == 1 {
  215 + if question, err = models.GetBulletinQuestionByBulletinId(bulletin.Id); err != nil {
  216 + log.Error(err.Error())
  217 + return
  218 + }
  219 + rsp.Announcement.Vote = protocol.Question{
  220 + Id: question.Id,
  221 + Type: int(question.Type),
  222 + Title: question.Title,
  223 + }
  224 + if err = json.Unmarshal([]byte(question.Content), &rsp.Announcement.Vote.Content); err != nil {
  225 + log.Error(err.Error())
  226 + return
  227 + }
  228 + }
  229 +
  230 + //获取回答详情数据
  231 + if bulletinAnswer, err = models.GetBulletinQuestionAnswerBy(request.Id, int64(request.Uid)); err == nil {
  232 + if len(bulletinAnswer.Answer) != 0 {
  233 + if err = json.Unmarshal([]byte(bulletinAnswer.Answer), &answer); err != nil {
  234 + log.Error(err)
  235 + } else {
  236 + rsp.Announcement.EditContent = answer.EditContent
  237 + rsp.Announcement.VoteResults = answer.VoteResults
  238 + }
  239 + }
  240 + return
  241 + }
  242 + if userMsg.IsRead == 0 { //判断是否可以置为 已读
  243 + if bulletin.AllowClose == 2 && bulletin != nil && bulletin.Id != 0 {
  244 + setRead = true
  245 + }
  246 + }
  247 + if setRead {
  248 + if err = utils.UpdateTableByMap(userMsg, map[string]interface{}{"IsRead": int8(1)}); err != nil {
  249 + log.Error(err)
  250 + return
  251 + }
  252 + }
  253 + return
  254 +}
  255 +
  256 +//H5完成公告操作
  257 +func H5AnnouncementSubmit(header *protocol.RequestHeader, request *protocol.AnnouncementSubmitRequest) (rsp *protocol.AnnouncementSubmitResponse, err error) {
  258 + var (
  259 + bulletin *models.Bulletin
  260 + userMsg *models.UserMsg
  261 + bulletinAnswer *models.BulletinQuestionAnswer
  262 + )
  263 + if bulletin, err = models.GetBulletinById(request.Id); err != nil {
  264 + log.Error(err)
  265 + err = protocol.NewErrWithMessage(2060)
  266 + return
  267 + }
  268 + if err = utils.ExecuteQueryOne(&userMsg, models.SqlUserMsg, request.Id, request.Uid, models.MsgTypeBulletin); err != nil {
  269 + log.Error(err)
  270 + err = protocol.NewErrWithMessage(2060)
  271 + return
  272 + }
  273 + //获取回答详情数据
  274 + if bulletinAnswer, err = models.GetBulletinQuestionAnswerBy(request.Id, int64(request.Uid)); err == nil {
  275 + bulletinAnswer.Answer = common.AssertJson(protocol.Answer{
  276 + EditContent: request.EditContent,
  277 + VoteResults: request.VoteResults,
  278 + })
  279 + bulletinAnswer.UpdateAt = time.Now()
  280 + if err = models.UpdateBulletinQuestionAnswerById(bulletinAnswer); err != nil {
  281 + return
  282 + }
  283 + return
  284 + }
  285 + orm := orm.NewOrm()
  286 + orm.Begin()
  287 + {
  288 + bulletinAnswer = &models.BulletinQuestionAnswer{
  289 + Answer: common.AssertJson(&protocol.Answer{
  290 + VoteResults: request.VoteResults,
  291 + EditContent: request.EditContent,
  292 + }),
  293 + BulletinId: bulletin.Id,
  294 + BulletinQuestionId: request.VoteId,
  295 + Uid: request.Uid,
  296 + CreateAt: time.Now(),
  297 + UpdateAt: time.Now(),
  298 + }
  299 + if _, err = orm.Insert(bulletinAnswer); err != nil {
  300 + log.Error(err)
  301 + orm.Rollback()
  302 + return
  303 + }
  304 + }
  305 + {
  306 + if userMsg.IsRead != 1 {
  307 + if err = utils.UpdateTableByMapWithOrmer(orm, userMsg, map[string]interface{}{"IsRead": int8(1)}); err != nil {
  308 + log.Error(err)
  309 + orm.Rollback()
  310 + return
  311 + }
  312 + }
  313 + }
  314 + orm.Commit()
  315 + rsp = &protocol.AnnouncementSubmitResponse{}
78 return 316 return
79 } 317 }