作者 yangfu

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

... ... @@ -12,4 +12,5 @@ EnableDocs = true
include "dev.conf"
include "prod.conf"
include "test.conf"
\ No newline at end of file
include "test.conf"
include "local.conf"
\ No newline at end of file
... ...
... ... @@ -34,4 +34,7 @@ net_im_app_key ="9c5410602597a7fe367aeeebd8210262"
user_center_url ="http://suplus-ucenter-dev.fjmaimaimai.com"
user_center_salt ="rsF0pL!6DwjBO735"
user_center_app_key ="39aefef9e22744a3b2d2d3791824ae7b"
user_center_app_secret ="cykbjnfqgctn"
\ No newline at end of file
user_center_app_secret ="cykbjnfqgctn"
#Html5
h5_host = "https://web-open.fjmaimaimai.com"
\ No newline at end of file
... ...
[local]
#数据库相关
mysql_user = "${MYSQL_USER||root}"
mysql_password = "${MYSQL_PASSWORD||sutianxia2015}"
mysql_host = "${MYSQL_HOST||115.29.205.99}"
mysql_port = "${MYSQL_PORT||3306}"
mysql_db_name = "${MYSQL_DB_NAME||opportunity}"
#日志
log_level = "${LOG_LEVEL||debug}"
aliyun_logs_access ="${aliyun_logs_access||F:/log/app.log}"
#redis相关配置
redis_add = "${REDIS_HOST||192.168.100.102}"
redis_add_port = "${REDIS_PORT||6379}"
redis_auth = "123456"
#sms相关配置
yunpian_sms_sdk_url ="https://sms.yunpian.com/v2/sms/single_send.json"
yunpian_app_key ="0bf6fb10a11a68a95dee80901eb545b5"
#存储 http://ability.fjmaimaimai.com:8080/
source_host ="http://192.168.139.137:8080/"
source_virtual_path=file/opp
source_path ="${aliyun_file_access||F:/file}
#网易云信 IM
net_im_base_url ="https://api.netease.im/nimserver"
net_im_app_secret ="a8d231f5c13a"
net_im_app_key ="9c5410602597a7fe367aeeebd8210262"
#统一用户中心 39aefef9e22744a3b2d2d3791824ae7b
user_center_url ="http://suplus-ucenter-dev.fjmaimaimai.com"
user_center_salt ="rsF0pL!6DwjBO735"
user_center_app_key ="39aefef9e22744a3b2d2d3791824ae7b"
user_center_app_secret ="cykbjnfqgctn"
\ No newline at end of file
... ...
package controllers
import (
"encoding/json"
"gitlab.fjmaimaimai.com/mmm-go/gocomm/pkg/log"
"opp/protocol"
"opp/services/message"
)
type H5Controller struct {
BaseController
}
//Announcement H5公告详情
//@router /announcement [post]
func (this *H5Controller) Announcement() {
var msg *protocol.ResponseMessage
defer func() {
this.Resp(msg)
}()
var request *protocol.AnnouncementRequest
if err := json.Unmarshal(this.ByteBody, &request); err != nil {
log.Error(err)
msg = protocol.BadRequestParam(1)
return
}
if b, m := this.Valid(request); !b {
msg = m
return
}
header := GetRequestHeader(this.Ctx)
msg = protocol.NewReturnResponse(message.H5Announcement(header, request))
}
//AnnouncementSubmit 完成公告操作
//@router /announcementSubmit [post]
func (this *H5Controller) AnnouncementSubmit() {
var msg *protocol.ResponseMessage
defer func() {
this.Resp(msg)
}()
var request *protocol.AnnouncementSubmitRequest
if err := json.Unmarshal(this.ByteBody, &request); err != nil {
log.Error(err)
msg = protocol.BadRequestParam(1)
return
}
if b, m := this.Valid(request); !b {
msg = m
return
}
header := GetRequestHeader(this.Ctx)
msg = protocol.NewReturnResponse(message.H5AnnouncementSubmit(header, request))
}
... ...
... ... @@ -96,7 +96,7 @@ func (this *MessageController) MsgInteractive() {
msg = protocol.NewReturnResponse(message.MsgInteractive(header, request))
}
//Announcements
//Announcements 公告列表
//@router /announcements [post]
func (this *MessageController) Announcements() {
var msg *protocol.ResponseMessage
... ... @@ -116,3 +116,45 @@ func (this *MessageController) Announcements() {
header := controllers.GetRequestHeader(this.Ctx)
msg = protocol.NewReturnResponse(message.Announcements(header, request))
}
//AnnouncementRead 公告已读
//@router /announcementRead [post]
func (this *MessageController) AnnouncementRead() {
var msg *protocol.ResponseMessage
defer func() {
this.Resp(msg)
}()
var request *protocol.AnnouncementReadRequest
if err := json.Unmarshal(this.ByteBody, &request); err != nil {
log.Error(err)
msg = protocol.BadRequestParam(1)
return
}
if b, m := this.Valid(request); !b {
msg = m
return
}
header := controllers.GetRequestHeader(this.Ctx)
msg = protocol.NewReturnResponse(message.AnnouncementRead(header, request))
}
//MsgCompanyNotice 消息中心-公司公告
//@router /msgCompanyNotice [post]
func (this *MessageController) MsgCompanyNotice() {
var msg *protocol.ResponseMessage
defer func() {
this.Resp(msg)
}()
var request *protocol.MsgCompanyNoticeRequest
if err := json.Unmarshal(this.ByteBody, &request); err != nil {
log.Error(err)
msg = protocol.BadRequestParam(1)
return
}
if b, m := this.Valid(request); !b {
msg = m
return
}
header := controllers.GetRequestHeader(this.Ctx)
msg = protocol.NewReturnResponse(message.MsgCompanyNotice(header, request))
}
... ...
... ... @@ -130,7 +130,7 @@ func PrintLogSql(sql string, param ...interface{}) {
//ExecuteQueryOne 执行原生sql查询单条记录;结果用结构体接收
func ExecuteQueryOne(result interface{}, sqlstr string, param ...interface{}) error {
PrintLogSql(sqlstr, param...)
//PrintLogSql(sqlstr, param...)
var err error
o := orm.NewOrm()
err = ExecuteQueryOneWithOrmer(o, result, sqlstr, param)
... ...
... ... @@ -49,6 +49,7 @@ func init() {
MaxIdle: 100,
MaxOpen: 100,
})
//TODO:邮件服务配置
common.InitMailService(&common.MailConfig{
//Host:"smtp.qq.com",
... ...
package models
import (
"errors"
"fmt"
"reflect"
"strings"
"time"
"github.com/astaxie/beego/orm"
... ... @@ -12,19 +9,20 @@ import (
type Bulletin struct {
Id int `orm:"column(id);auto"`
Title string `orm:"column(title);size(2000)" description:"标题"`
Title string `orm:"column(title);size(2000);null" description:"标题"`
Content string `orm:"column(content);null" description:"内容"`
Cover string `orm:"column(cover);size(255);null" description:"封面地址"`
W int `orm:"column(w);null" description:"宽"`
H int `orm:"column(h);null" description:"高"`
Type int8 `orm:"column(type);null" description:"公告类型(0图+跳转链接、1链接)"`
Type int8 `orm:"column(type);null" description:"公告类型(1图+跳转链接、2纯文本)"`
Receiver string `orm:"column(receiver);null" description:"接收者"`
QuestionSwitch int8 `orm:"column(question_switch);null" description:"设置问题开关"`
CreateTime time.Time `orm:"column(createTime);type(timestamp);null" description:"创建时间"`
UpdateTime time.Time `orm:"column(updateTime);type(timestamp);null" description:"更新时间"`
AllowClose int8 `orm:"column(allowClose);null" description:"允许关闭公告(0允许,1禁止)"`
CompanyId int `orm:"column(company_id);null" description:"公司Id"`
Status uint8 `orm:"column(status)" description:"状态 0-下架 1- 上架"`
QuestionSwitch int8 `orm:"column(question_switch);null" description:"设置问题开关 (是否有问题)"`
CreateAt time.Time `orm:"column(create_at);type(timestamp);null" description:"创建时间"`
UpdateAt time.Time `orm:"column(update_at);type(timestamp);null" description:"更新时间"`
AllowClose int8 `orm:"column(allow_close);null" description:"允许关闭公告(0允许关闭窗口,1阅读完才能关闭,2选项打勾后才能关闭)"`
//AllowCondition int8 `orm:"column(allow_condition);null" description:"关闭条件 (1(bit 0):公告内容查看完 2(bit 1):回答完问题)"`
CompanyId int64 `orm:"column(company_id);null" description:"公司Id"`
Status int8 `orm:"column(status)" description:"状态 1-下架 2-上架"`
}
func (t *Bulletin) TableName() string {
... ... @@ -54,84 +52,6 @@ func GetBulletinById(id int) (v *Bulletin, err error) {
return nil, err
}
// GetAllBulletin retrieves all Bulletin matches certain condition. Returns empty list if
// no records exist
func GetAllBulletin(query map[string]string, fields []string, sortby []string, order []string,
offset int64, limit int64) (ml []interface{}, err error) {
o := orm.NewOrm()
qs := o.QueryTable(new(Bulletin))
// query k=v
for k, v := range query {
// rewrite dot-notation to Object__Attribute
k = strings.Replace(k, ".", "__", -1)
if strings.Contains(k, "isnull") {
qs = qs.Filter(k, (v == "true" || v == "1"))
} else {
qs = qs.Filter(k, v)
}
}
// order by:
var sortFields []string
if len(sortby) != 0 {
if len(sortby) == len(order) {
// 1) for each sort field, there is an associated order
for i, v := range sortby {
orderby := ""
if order[i] == "desc" {
orderby = "-" + v
} else if order[i] == "asc" {
orderby = v
} else {
return nil, errors.New("Error: Invalid order. Must be either [asc|desc]")
}
sortFields = append(sortFields, orderby)
}
qs = qs.OrderBy(sortFields...)
} else if len(sortby) != len(order) && len(order) == 1 {
// 2) there is exactly one order, all the sorted fields will be sorted by this order
for _, v := range sortby {
orderby := ""
if order[0] == "desc" {
orderby = "-" + v
} else if order[0] == "asc" {
orderby = v
} else {
return nil, errors.New("Error: Invalid order. Must be either [asc|desc]")
}
sortFields = append(sortFields, orderby)
}
} else if len(sortby) != len(order) && len(order) != 1 {
return nil, errors.New("Error: 'sortby', 'order' sizes mismatch or 'order' size is not 1")
}
} else {
if len(order) != 0 {
return nil, errors.New("Error: unused 'order' fields")
}
}
var l []Bulletin
qs = qs.OrderBy(sortFields...)
if _, err = qs.Limit(limit, offset).All(&l, fields...); err == nil {
if len(fields) == 0 {
for _, v := range l {
ml = append(ml, v)
}
} else {
// trim unused fields
for _, v := range l {
m := make(map[string]interface{})
val := reflect.ValueOf(v)
for _, fname := range fields {
m[fname] = val.FieldByName(fname).Interface()
}
ml = append(ml, m)
}
}
return ml, nil
}
return nil, err
}
// UpdateBulletin updates Bulletin by Id and returns error if
// the record to be updated doesn't exist
func UpdateBulletinById(m *Bulletin) (err error) {
... ...
... ... @@ -9,12 +9,12 @@ import (
type BulletinQuestion struct {
Id int `orm:"column(id);auto"`
BulletinId int `orm:"column(bulletin_id)" description:"公告id"`
Type int8 `orm:"column(type)" description:"类型:0-单选,1-多选"`
Title string `orm:"column(title);size(2000)" description:"标题"`
Option string `orm:"column(option);size(2000)" description:"内容"`
CreateTime time.Time `orm:"column(createTime);type(timestamp)" description:"创建时间"`
UpdateTime time.Time `orm:"column(updateTime);type(timestamp)" description:"更新时间"`
BulletinId int `orm:"column(bulletin_id);null" description:"公告id"`
Type int8 `orm:"column(type);null" description:"类型:0-单选,1-多选"`
Title string `orm:"column(title);size(2000);null" description:"标题"`
Content string `orm:"column(content);size(2000);null" description:"内容"`
CreateAt time.Time `orm:"column(create_at);type(timestamp);null" description:"创建时间"`
UpdateAt time.Time `orm:"column(update_at);type(timestamp);null" description:"更新时间"`
}
func (t *BulletinQuestion) TableName() string {
... ... @@ -64,3 +64,12 @@ func UpdateBulletinQuestionById(m *BulletinQuestion) (err error) {
}
return
}
func GetBulletinQuestionByBulletinId(id int) (v *BulletinQuestion, err error) {
o := orm.NewOrm()
sql := "select * from bulletin_question where bulletin_id=?"
if err = o.Raw(sql, id).QueryRow(&v); err == nil {
return v, nil
}
return nil, err
}
... ...
... ... @@ -9,12 +9,12 @@ import (
type BulletinQuestionAnswer struct {
Id int `orm:"column(id);auto"`
Answer string `orm:"column(answer)" description:"答案"`
BulletinId int `orm:"column(bulletin_id)" description:"公告id"`
BulletinQuestionId int `orm:"column(bulletin_question_id)" description:"公告问题id"`
Uid int64 `orm:"column(uid)" description:"用户id"`
CreateTime time.Time `orm:"column(createTime);type(timestamp)" description:"创建时间"`
UpdateTime time.Time `orm:"column(updateTime);type(timestamp)" description:"更新时间"`
Answer string `orm:"column(answer);null" description:"答案"`
BulletinId int `orm:"column(bulletin_id);null" description:"公告id"`
BulletinQuestionId int `orm:"column(bulletin_question_id);null" description:"公告问题id"`
Uid int64 `orm:"column(uid);null" description:"用户id"`
CreateAt time.Time `orm:"column(create_at);type(timestamp);null" description:"创建时间"`
UpdateAt time.Time `orm:"column(update_at);type(timestamp);null" description:"更新时间"`
}
func (t *BulletinQuestionAnswer) TableName() string {
... ... @@ -79,3 +79,12 @@ func DeleteBulletinQuestionAnswer(id int) (err error) {
}
return
}
func GetBulletinQuestionAnswerBy(bulletinId int, uid int64) (v *BulletinQuestionAnswer, err error) {
o := orm.NewOrm()
sql := "select * from bulletin_question_answer where bulletin_id=? and uid=?"
if err = o.Raw(sql, bulletinId, uid).QueryRow(&v); err == nil {
return v, nil
}
return nil, err
}
... ...
... ... @@ -3,6 +3,7 @@ package models
import (
"fmt"
"gitlab.fjmaimaimai.com/mmm-go/gocomm/pkg/mybeego"
"opp/internal/utils"
"time"
"github.com/astaxie/beego/orm"
... ... @@ -22,7 +23,20 @@ type UserMsg struct {
}
const (
SqlUserMsgUnRead = "select * from user_msg where company_id=? and receive_user_id=? and msg_type=? and is_read=0"
MsgTypeBulletin = 1 //公告
MsgTypeCommend = 2 //表彰
MsgTypeInteraction = 4 //互动消息
MsgTypeAudit = 8 //机会审核
)
const (
SourceTypeChance = 1
SourceTypeComment = 2
SourceTypeBulletin = 3
)
const (
SqlUserMsgsUnRead = "select * from user_msg where company_id=? and receive_user_id=? and msg_type=? and is_read=0 order by create_at desc" //所有未读消息
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" //特定未读消息
SqlUserMsg = "select * from user_msg where source_id=? and receive_user_id=? and msg_type=? " //特定未读消息
)
func (t *UserMsg) TableName() string {
... ... @@ -130,3 +144,25 @@ func GetUserMsgs(userId, companyId int64, msgType int, sourceType int, lastId in
}
return
}
func GetUserMsgsBulletin(userId, companyId int64, msgType int, lastId int64, pageSize int, v interface{}) (total int, err error) {
sql := `select b.id,b.title,unix_timestamp(b.update_at) update_at,a.is_read `
sqlCount := `select count(0) `
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 `
sqlCount += where
if err = utils.ExecuteQueryOne(&total, sqlCount, userId, companyId, msgType, companyId); err != nil {
return
}
if lastId > 0 {
where += fmt.Sprintf(` and b.id>%v`, lastId)
}
if v == nil {
return
}
where += ` order by b.update_at desc`
sql += where + " limit ?"
if err = utils.ExecuteQueryAll(v, sql, userId, companyId, msgType, companyId, pageSize); err != nil {
return
}
return
}
... ...
... ... @@ -22,6 +22,7 @@ var errmessge ErrorMap = map[int]string{
2027: "密码必须至少有6个字符",
2028: "请输入正确的旧密码",
2029: "当前手机号已存在,请重新输入",
2060: "读取公告失败",
4139: "authCode无效或过期",
4140: "refreshToken过期,需要重新登录授权",
4141: "accessToken过期或无效,需要进行重新获取令牌",
... ... @@ -94,9 +95,9 @@ func (m Message) Unmarshal(v interface{}) error {
/**************公告****************/
type Question struct {
Id int `json:"id"`
Type int `json:"type" valid:"Required"`
Type int `json:"way" valid:"Required"`
Title string `json:"title" valid:"Required"`
Content []QuestionContent `json:"content" valid:"Required"`
Content []QuestionContent `json:"options" valid:"Required"`
}
type QuestionContent struct {
Id int `json:"id" valid:"Required"`
... ... @@ -134,7 +135,7 @@ type Receiver struct {
type AnnouncementsRequest struct {
}
type AnnouncementsResponse struct {
Lists []Announcement `json:"lists"`
Lists []Announcement `json:"lists,omitempty"`
}
type Announcement struct {
... ... @@ -145,3 +146,56 @@ type Announcement struct {
Link string `json:"link"`
Control int `json:"Control"`
}
/*AnnouncementRead */
type AnnouncementReadRequest struct {
Id int `json:"id" valid:"Required"` //公告id
}
type AnnouncementReadResponse struct {
}
/*MsgCompanyNotice 消息中心-公司公告 */
type MsgCompanyNoticeRequest struct {
LastId int64 `json:"lastId"`
PageSize int `json:"pageSize" valid:"Required"`
}
type MsgCompanyNoticeResponse struct {
Lists []UserMsg `json:"lists"`
Total int `json:"total"`
}
/*Announcement H5公告详情*/
type AnnouncementRequest struct {
Id int `json:"id" valid:"Required"`
Uid int `json:"uid" valid:"Required"`
}
type AnnouncementResponse struct {
Announcement H5Announcement `json:"announcement"`
}
type H5Announcement struct {
Id int `json:"id"`
Title string `json:"title"`
Content string `json:"content"`
Control int `json:"control"`
IsRead int `json:"isRead"`
Vote Question `json:"vote"`
VoteResults []int `json:"voteResults"`
EditContent string `json:"editContent"`
}
/*AnnouncementSubmit H5完成公告操作*/
type AnnouncementSubmitRequest struct {
Id int `json:"id" valid:"Required"` //公告id
Uid int64 `json:"uid"`
VoteResults []int `json:"voteResults"`
VoteId int `json:"voteId"` //投票问题id
EditContent string `json:"editContent"`
}
type AnnouncementSubmitResponse struct {
}
type Answer struct {
VoteResults []int `json:"voteResults"`
EditContent string `json:"editContent"`
}
... ...
package routers
import (
"github.com/astaxie/beego"
"github.com/astaxie/beego/context/param"
)
func init() {
beego.GlobalControllerRouter["opp/controllers:H5Controller"] = append(beego.GlobalControllerRouter["opp/controllers:H5Controller"],
beego.ControllerComments{
Method: "Announcement",
Router: `/announcement`,
AllowHTTPMethods: []string{"post"},
MethodParams: param.Make(),
Params: nil})
beego.GlobalControllerRouter["opp/controllers:H5Controller"] = append(beego.GlobalControllerRouter["opp/controllers:H5Controller"],
beego.ControllerComments{
Method: "AnnouncementSubmit",
Router: `/announcementSubmit`,
AllowHTTPMethods: []string{"post"},
MethodParams: param.Make(),
Params: nil})
}
... ...
package routers
import (
"github.com/astaxie/beego"
"github.com/astaxie/beego/context/param"
)
func init() {
beego.GlobalControllerRouter["opp/controllers:H5Controller"] = append(beego.GlobalControllerRouter["opp/controllers:H5Controller"],
beego.ControllerComments{
Method: "Announcement",
Router: `/announcement`,
AllowHTTPMethods: []string{"post"},
MethodParams: param.Make(),
Params: nil})
beego.GlobalControllerRouter["opp/controllers:H5Controller"] = append(beego.GlobalControllerRouter["opp/controllers:H5Controller"],
beego.ControllerComments{
Method: "AnnouncementSubmit",
Router: `/announcementSubmit`,
AllowHTTPMethods: []string{"post"},
MethodParams: param.Make(),
Params: nil})
}
... ...
... ... @@ -9,266 +9,290 @@ func init() {
beego.GlobalControllerRouter["opp/controllers/v1:AuthController"] = append(beego.GlobalControllerRouter["opp/controllers/v1:AuthController"],
beego.ControllerComments{
Method: "AccessToken",
Router: `/accessToken`,
Method: "AccessToken",
Router: `/accessToken`,
AllowHTTPMethods: []string{"post"},
MethodParams: param.Make(),
Params: nil})
MethodParams: param.Make(),
Params: nil})
beego.GlobalControllerRouter["opp/controllers/v1:AuthController"] = append(beego.GlobalControllerRouter["opp/controllers/v1:AuthController"],
beego.ControllerComments{
Method: "Login",
Router: `/login`,
Method: "Login",
Router: `/login`,
AllowHTTPMethods: []string{"post"},
MethodParams: param.Make(),
Params: nil})
MethodParams: param.Make(),
Params: nil})
beego.GlobalControllerRouter["opp/controllers/v1:AuthController"] = append(beego.GlobalControllerRouter["opp/controllers/v1:AuthController"],
beego.ControllerComments{
Method: "RefreshToken",
Router: `/refreshToken`,
Method: "RefreshToken",
Router: `/refreshToken`,
AllowHTTPMethods: []string{"post"},
MethodParams: param.Make(),
Params: nil})
MethodParams: param.Make(),
Params: nil})
beego.GlobalControllerRouter["opp/controllers/v1:AuthController"] = append(beego.GlobalControllerRouter["opp/controllers/v1:AuthController"],
beego.ControllerComments{
Method: "Revoke",
Router: `/revoke`,
Method: "Revoke",
Router: `/revoke`,
AllowHTTPMethods: []string{"post"},
MethodParams: param.Make(),
Params: nil})
MethodParams: param.Make(),
Params: nil})
beego.GlobalControllerRouter["opp/controllers/v1:AuthController"] = append(beego.GlobalControllerRouter["opp/controllers/v1:AuthController"],
beego.ControllerComments{
Method: "SmsCode",
Router: `/smsCode`,
Method: "SmsCode",
Router: `/smsCode`,
AllowHTTPMethods: []string{"post"},
MethodParams: param.Make(),
Params: nil})
MethodParams: param.Make(),
Params: nil})
beego.GlobalControllerRouter["opp/controllers/v1:AuthController"] = append(beego.GlobalControllerRouter["opp/controllers/v1:AuthController"],
beego.ControllerComments{
Method: "UpdateDevice",
Router: `/updateDevice`,
Method: "UpdateDevice",
Router: `/updateDevice`,
AllowHTTPMethods: []string{"post"},
MethodParams: param.Make(),
Params: nil})
MethodParams: param.Make(),
Params: nil})
beego.GlobalControllerRouter["opp/controllers/v1:ChanceController"] = append(beego.GlobalControllerRouter["opp/controllers/v1:ChanceController"],
beego.ControllerComments{
Method: "ChanceType",
Router: `/chanceType`,
Method: "ChanceType",
Router: `/chanceType`,
AllowHTTPMethods: []string{"post"},
MethodParams: param.Make(),
Params: nil})
MethodParams: param.Make(),
Params: nil})
beego.GlobalControllerRouter["opp/controllers/v1:ChanceController"] = append(beego.GlobalControllerRouter["opp/controllers/v1:ChanceController"],
beego.ControllerComments{
Method: "CommentDetailsMulti",
Router: `/commentDetailsMulti`,
Method: "CommentDetailsMulti",
Router: `/commentDetailsMulti`,
AllowHTTPMethods: []string{"post"},
MethodParams: param.Make(),
Params: nil})
MethodParams: param.Make(),
Params: nil})
beego.GlobalControllerRouter["opp/controllers/v1:ChanceController"] = append(beego.GlobalControllerRouter["opp/controllers/v1:ChanceController"],
beego.ControllerComments{
Method: "CommentDetailsSingle",
Router: `/commentDetailsSingle`,
Method: "CommentDetailsSingle",
Router: `/commentDetailsSingle`,
AllowHTTPMethods: []string{"post"},
MethodParams: param.Make(),
Params: nil})
MethodParams: param.Make(),
Params: nil})
beego.GlobalControllerRouter["opp/controllers/v1:ChanceController"] = append(beego.GlobalControllerRouter["opp/controllers/v1:ChanceController"],
beego.ControllerComments{
Method: "Comments",
Router: `/comments`,
Method: "Comments",
Router: `/comments`,
AllowHTTPMethods: []string{"post"},
MethodParams: param.Make(),
Params: nil})
MethodParams: param.Make(),
Params: nil})
beego.GlobalControllerRouter["opp/controllers/v1:ChanceController"] = append(beego.GlobalControllerRouter["opp/controllers/v1:ChanceController"],
beego.ControllerComments{
Method: "Favorite",
Router: `/favorite`,
Method: "Favorite",
Router: `/favorite`,
AllowHTTPMethods: []string{"post"},
MethodParams: param.Make(),
Params: nil})
MethodParams: param.Make(),
Params: nil})
beego.GlobalControllerRouter["opp/controllers/v1:ChanceController"] = append(beego.GlobalControllerRouter["opp/controllers/v1:ChanceController"],
beego.ControllerComments{
Method: "IComment",
Router: `/iComment`,
Method: "IComment",
Router: `/iComment`,
AllowHTTPMethods: []string{"post"},
MethodParams: param.Make(),
Params: nil})
MethodParams: param.Make(),
Params: nil})
beego.GlobalControllerRouter["opp/controllers/v1:ChanceController"] = append(beego.GlobalControllerRouter["opp/controllers/v1:ChanceController"],
beego.ControllerComments{
Method: "IComments",
Router: `/iComments`,
Method: "IComments",
Router: `/iComments`,
AllowHTTPMethods: []string{"post"},
MethodParams: param.Make(),
Params: nil})
MethodParams: param.Make(),
Params: nil})
beego.GlobalControllerRouter["opp/controllers/v1:ChanceController"] = append(beego.GlobalControllerRouter["opp/controllers/v1:ChanceController"],
beego.ControllerComments{
Method: "ChanceSubmit",
Router: `/submit`,
Method: "ChanceSubmit",
Router: `/submit`,
AllowHTTPMethods: []string{"post"},
MethodParams: param.Make(),
Params: nil})
MethodParams: param.Make(),
Params: nil})
beego.GlobalControllerRouter["opp/controllers/v1:ChanceController"] = append(beego.GlobalControllerRouter["opp/controllers/v1:ChanceController"],
beego.ControllerComments{
Method: "SympathyAction",
Router: `/sympathyAction`,
Method: "SympathyAction",
Router: `/sympathyAction`,
AllowHTTPMethods: []string{"post"},
MethodParams: param.Make(),
Params: nil})
MethodParams: param.Make(),
Params: nil})
beego.GlobalControllerRouter["opp/controllers/v1:ChanceController"] = append(beego.GlobalControllerRouter["opp/controllers/v1:ChanceController"],
beego.ControllerComments{
Method: "Templates",
Router: `/templates`,
Method: "Templates",
Router: `/templates`,
AllowHTTPMethods: []string{"post"},
MethodParams: param.Make(),
Params: nil})
MethodParams: param.Make(),
Params: nil})
beego.GlobalControllerRouter["opp/controllers/v1:CommendController"] = append(beego.GlobalControllerRouter["opp/controllers/v1:CommendController"],
beego.ControllerComments{
Method: "Company",
Router: `/company`,
Method: "Company",
Router: `/company`,
AllowHTTPMethods: []string{"post"},
MethodParams: param.Make(),
Params: nil})
MethodParams: param.Make(),
Params: nil})
beego.GlobalControllerRouter["opp/controllers/v1:DepartmentController"] = append(beego.GlobalControllerRouter["opp/controllers/v1:DepartmentController"],
beego.ControllerComments{
Method: "Departments",
Router: `/departments`,
Method: "Departments",
Router: `/departments`,
AllowHTTPMethods: []string{"post"},
MethodParams: param.Make(),
Params: nil})
MethodParams: param.Make(),
Params: nil})
beego.GlobalControllerRouter["opp/controllers/v1:MessageController"] = append(beego.GlobalControllerRouter["opp/controllers/v1:MessageController"],
beego.ControllerComments{
Method: "MessageCenter",
Router: `/messageCenter`,
Method: "AnnouncementRead",
Router: `/announcementRead`,
AllowHTTPMethods: []string{"post"},
MethodParams: param.Make(),
Params: nil})
MethodParams: param.Make(),
Params: nil})
beego.GlobalControllerRouter["opp/controllers/v1:MessageController"] = append(beego.GlobalControllerRouter["opp/controllers/v1:MessageController"],
beego.ControllerComments{
Method: "MsgCenterAllRead",
Router: `/msgCenterAllRead`,
Method: "Announcements",
Router: `/announcements`,
AllowHTTPMethods: []string{"post"},
MethodParams: param.Make(),
Params: nil})
MethodParams: param.Make(),
Params: nil})
beego.GlobalControllerRouter["opp/controllers/v1:MessageController"] = append(beego.GlobalControllerRouter["opp/controllers/v1:MessageController"],
beego.ControllerComments{
Method: "MsgCenterRead",
Router: `/msgCenterRead`,
Method: "MessageCenter",
Router: `/messageCenter`,
AllowHTTPMethods: []string{"post"},
MethodParams: param.Make(),
Params: nil})
MethodParams: param.Make(),
Params: nil})
beego.GlobalControllerRouter["opp/controllers/v1:MessageController"] = append(beego.GlobalControllerRouter["opp/controllers/v1:MessageController"],
beego.ControllerComments{
Method: "MsgInteractive",
Router: `/msgInteractive`,
Method: "MsgCenterAllRead",
Router: `/msgCenterAllRead`,
AllowHTTPMethods: []string{"post"},
MethodParams: param.Make(),
Params: nil})
MethodParams: param.Make(),
Params: nil})
beego.GlobalControllerRouter["opp/controllers/v1:MessageController"] = append(beego.GlobalControllerRouter["opp/controllers/v1:MessageController"],
beego.ControllerComments{
Method: "MsgCenterRead",
Router: `/msgCenterRead`,
AllowHTTPMethods: []string{"post"},
MethodParams: param.Make(),
Params: nil})
beego.GlobalControllerRouter["opp/controllers/v1:MessageController"] = append(beego.GlobalControllerRouter["opp/controllers/v1:MessageController"],
beego.ControllerComments{
Method: "MsgCompanyNotice",
Router: `/msgCompanyNotice`,
AllowHTTPMethods: []string{"post"},
MethodParams: param.Make(),
Params: nil})
beego.GlobalControllerRouter["opp/controllers/v1:MessageController"] = append(beego.GlobalControllerRouter["opp/controllers/v1:MessageController"],
beego.ControllerComments{
Method: "MsgInteractive",
Router: `/msgInteractive`,
AllowHTTPMethods: []string{"post"},
MethodParams: param.Make(),
Params: nil})
beego.GlobalControllerRouter["opp/controllers/v1:UcenterController"] = append(beego.GlobalControllerRouter["opp/controllers/v1:UcenterController"],
beego.ControllerComments{
Method: "UCenterLogin",
Router: `/login`,
Method: "UCenterLogin",
Router: `/login`,
AllowHTTPMethods: []string{"post"},
MethodParams: param.Make(),
Params: nil})
MethodParams: param.Make(),
Params: nil})
beego.GlobalControllerRouter["opp/controllers/v1:UploadController"] = append(beego.GlobalControllerRouter["opp/controllers/v1:UploadController"],
beego.ControllerComments{
Method: "Image",
Router: `/image`,
Method: "Image",
Router: `/image`,
AllowHTTPMethods: []string{"post"},
MethodParams: param.Make(),
Params: nil})
MethodParams: param.Make(),
Params: nil})
beego.GlobalControllerRouter["opp/controllers/v1:UploadController"] = append(beego.GlobalControllerRouter["opp/controllers/v1:UploadController"],
beego.ControllerComments{
Method: "Video",
Router: `/video`,
Method: "Video",
Router: `/video`,
AllowHTTPMethods: []string{"post"},
MethodParams: param.Make(),
Params: nil})
MethodParams: param.Make(),
Params: nil})
beego.GlobalControllerRouter["opp/controllers/v1:UploadController"] = append(beego.GlobalControllerRouter["opp/controllers/v1:UploadController"],
beego.ControllerComments{
Method: "Voice",
Router: `/voice`,
Method: "Voice",
Router: `/voice`,
AllowHTTPMethods: []string{"post"},
MethodParams: param.Make(),
Params: nil})
MethodParams: param.Make(),
Params: nil})
beego.GlobalControllerRouter["opp/controllers/v1:UserController"] = append(beego.GlobalControllerRouter["opp/controllers/v1:UserController"],
beego.ControllerComments{
Method: "ChangePassword",
Router: `/changePassword`,
Method: "ChangePassword",
Router: `/changePassword`,
AllowHTTPMethods: []string{"post"},
MethodParams: param.Make(),
Params: nil})
MethodParams: param.Make(),
Params: nil})
beego.GlobalControllerRouter["opp/controllers/v1:UserController"] = append(beego.GlobalControllerRouter["opp/controllers/v1:UserController"],
beego.ControllerComments{
Method: "ChangePhone",
Router: `/changePhone`,
Method: "ChangePhone",
Router: `/changePhone`,
AllowHTTPMethods: []string{"post"},
MethodParams: param.Make(),
Params: nil})
MethodParams: param.Make(),
Params: nil})
beego.GlobalControllerRouter["opp/controllers/v1:UserController"] = append(beego.GlobalControllerRouter["opp/controllers/v1:UserController"],
beego.ControllerComments{
Method: "CheckSmsCode",
Router: `/checkSmsCode`,
Method: "CheckSmsCode",
Router: `/checkSmsCode`,
AllowHTTPMethods: []string{"post"},
MethodParams: param.Make(),
Params: nil})
MethodParams: param.Make(),
Params: nil})
beego.GlobalControllerRouter["opp/controllers/v1:UserController"] = append(beego.GlobalControllerRouter["opp/controllers/v1:UserController"],
beego.ControllerComments{
Method: "ResetPassword",
Router: `/resetPassword`,
Method: "ResetPassword",
Router: `/resetPassword`,
AllowHTTPMethods: []string{"post"},
MethodParams: param.Make(),
Params: nil})
MethodParams: param.Make(),
Params: nil})
beego.GlobalControllerRouter["opp/controllers/v1:UserController"] = append(beego.GlobalControllerRouter["opp/controllers/v1:UserController"],
beego.ControllerComments{
Method: "SwitchCompany",
Router: `/switchCompany`,
Method: "SwitchCompany",
Router: `/switchCompany`,
AllowHTTPMethods: []string{"post"},
MethodParams: param.Make(),
Params: nil})
MethodParams: param.Make(),
Params: nil})
beego.GlobalControllerRouter["opp/controllers/v1:UserController"] = append(beego.GlobalControllerRouter["opp/controllers/v1:UserController"],
beego.ControllerComments{
Method: "UserCompanys",
Router: `/userCompanys`,
Method: "UserCompanys",
Router: `/userCompanys`,
AllowHTTPMethods: []string{"post"},
MethodParams: param.Make(),
Params: nil})
MethodParams: param.Make(),
Params: nil})
beego.GlobalControllerRouter["opp/controllers/v1:UserController"] = append(beego.GlobalControllerRouter["opp/controllers/v1:UserController"],
beego.ControllerComments{
Method: "UserInfo",
Router: `/userInfo`,
Method: "UserInfo",
Router: `/userInfo`,
AllowHTTPMethods: []string{"post"},
MethodParams: param.Make(),
Params: nil})
MethodParams: param.Make(),
Params: nil})
}
... ...
... ... @@ -24,6 +24,10 @@ func init() {
beego.NSNamespace("department", beego.NSBefore(controllers.FilterComm), beego.NSInclude(&v1.DepartmentController{})),
)
beego.AddNamespace(nsV1)
nsH5 := beego.NewNamespace("h5", beego.NSInclude(&controllers.H5Controller{}))
beego.AddNamespace(nsH5)
beego.SetStaticPath("/file/opp", beego.AppConfig.String("source_path"))
beego.SetStaticPath("/log/opp", beego.AppConfig.String("aliyun_logs_access"))
beego.Handler("/metrics", promhttp.Handler())
... ...
package message
import (
"encoding/json"
"fmt"
"github.com/astaxie/beego"
"github.com/astaxie/beego/orm"
"gitlab.fjmaimaimai.com/mmm-go/gocomm/common"
"gitlab.fjmaimaimai.com/mmm-go/gocomm/pkg/log"
"opp/internal/repository"
"opp/internal/utils"
"opp/models"
"opp/protocol"
"time"
)
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
//未读公告列表
func Announcements(header *protocol.RequestHeader, request *protocol.AnnouncementsRequest) (rsp *protocol.AnnouncementsResponse, err error) {
var (
//userMsg []*models.UserMsg
userMsg []*models.UserMsg
bulletin *models.Bulletin
)
//if err = utils.ExecuteQueryAll(&userMsg,models.SqlUserMsgUnRead,header.CompanyId,header.)
rsp = &protocol.AnnouncementsResponse{}
if err = utils.ExecuteQueryAll(&userMsg, models.SqlUserMsgsUnRead, header.CompanyId, header.UserId, models.MsgTypeBulletin); err != nil {
if err == orm.ErrNoRows {
err = nil
return
}
log.Error(err)
return
}
for i := 0; i < len(userMsg); i++ {
msg := userMsg[i]
if bulletin, err = models.GetBulletinById(int(msg.SourceId)); err != nil {
if orm.ErrNoRows == err {
err = nil
continue
}
log.Error(msg.SourceId, err)
continue
}
item := protocol.Announcement{
Id: bulletin.Id,
Type: int(bulletin.Type),
Title: bulletin.Title,
Control: int(bulletin.AllowClose),
//link:'https://web-open.fjmaimaimai.com/#/ability/announcement?id='+announcementCfgData[i].id+'&uid='+param.uid
Link: fmt.Sprintf("%v#/ability/announcement?id=%v&uid=%v", beego.AppConfig.String("h5_host"), bulletin.Id, msg.ReceiveUserId),
}
item.Cover = protocol.Cover{
Path: bulletin.Cover,
H: bulletin.H,
W: bulletin.W,
}
rsp.Lists = append(rsp.Lists, item)
}
return
}
//公告已读
func AnnouncementRead(header *protocol.RequestHeader, request *protocol.AnnouncementReadRequest) (rsp *protocol.AnnouncementReadResponse, err error) {
var (
bulletin *models.Bulletin
userMsg *models.UserMsg
)
if bulletin, err = models.GetBulletinById(request.Id); err != nil {
log.Error(err)
err = protocol.NewErrWithMessage(2060)
return
}
if int64(bulletin.CompanyId) != header.CompanyId {
err = protocol.NewErrWithMessage(2060)
return
}
if err = utils.ExecuteQueryOne(&userMsg, models.SqlUserMsgUnRead, bulletin.Id, header.CompanyId, header.UserId, models.MsgTypeBulletin); err != nil {
//if err==orm.ErrNoRows{
// err=nil
// return
//}
log.Error(err)
return
}
if userMsg.IsRead == 1 {
return
}
if err = utils.UpdateTableByMap(userMsg, map[string]interface{}{"IsRead": int8(1)}); err != nil {
log.Error(err)
return
}
rsp = &protocol.AnnouncementReadResponse{}
return
}
//消息中心-公司公告
func MsgCompanyNotice(header *protocol.RequestHeader, request *protocol.MsgCompanyNoticeRequest) (rsp *protocol.MsgCompanyNoticeResponse, err error) {
type MsgBulletin struct {
Id int `orm:"column(id)"`
Title string `orm:"column(title)"`
UpdateTime int64 `orm:"column(update_at)"`
IsRead int8 `orm:"column(is_read)"`
}
var (
msgBulletins []*MsgBulletin
total int
)
if total, err = models.GetUserMsgsBulletin(header.UserId, header.CompanyId, models.MsgTypeBulletin, request.LastId, request.PageSize, &msgBulletins); err != nil {
log.Error(err)
return
}
rsp = &protocol.MsgCompanyNoticeResponse{}
rsp.Total = total
for i := range msgBulletins {
tmp := msgBulletins[i]
rsp.Lists = append(rsp.Lists, protocol.UserMsg{
Id: int64(tmp.Id),
SourceType: models.MsgTypeBulletin,
Content: tmp.Title,
CreateAt: tmp.UpdateTime,
IsRead: int(tmp.IsRead),
})
}
return
}
//H5公告详情
func H5Announcement(header *protocol.RequestHeader, request *protocol.AnnouncementRequest) (rsp *protocol.AnnouncementResponse, err error) {
var (
bulletin *models.Bulletin
question *models.BulletinQuestion
userMsg *models.UserMsg
bulletinAnswer *models.BulletinQuestionAnswer
setRead bool = false
answer *protocol.Answer
)
if bulletin, err = models.GetBulletinById(request.Id); err != nil {
log.Error(err.Error())
err = protocol.NewErrWithMessage(2060)
return
}
if err = utils.ExecuteQueryOne(&userMsg, models.SqlUserMsg, request.Id, request.Uid, models.MsgTypeBulletin); err != nil {
log.Error(err)
err = protocol.NewErrWithMessage(2060)
return
}
rsp = &protocol.AnnouncementResponse{}
rsp.Announcement = protocol.H5Announcement{
Id: bulletin.Id,
Title: bulletin.Title,
Content: bulletin.Content,
Control: int(bulletin.AllowClose),
IsRead: int(userMsg.IsRead),
}
if bulletin.QuestionSwitch == 1 {
if question, err = models.GetBulletinQuestionByBulletinId(bulletin.Id); err != nil {
log.Error(err.Error())
return
}
rsp.Announcement.Vote = protocol.Question{
Id: question.Id,
Type: int(question.Type),
Title: question.Title,
}
if err = json.Unmarshal([]byte(question.Content), &rsp.Announcement.Vote.Content); err != nil {
log.Error(err.Error())
return
}
}
//获取回答详情数据
if bulletinAnswer, err = models.GetBulletinQuestionAnswerBy(request.Id, int64(request.Uid)); err == nil {
if len(bulletinAnswer.Answer) != 0 {
if err = json.Unmarshal([]byte(bulletinAnswer.Answer), &answer); err != nil {
log.Error(err)
} else {
rsp.Announcement.EditContent = answer.EditContent
rsp.Announcement.VoteResults = answer.VoteResults
}
}
return
}
if userMsg.IsRead == 0 { //判断是否可以置为 已读
if bulletin.AllowClose == 2 && bulletin != nil && bulletin.Id != 0 {
setRead = true
}
}
if setRead {
if err = utils.UpdateTableByMap(userMsg, map[string]interface{}{"IsRead": int8(1)}); err != nil {
log.Error(err)
return
}
}
return
}
//H5完成公告操作
func H5AnnouncementSubmit(header *protocol.RequestHeader, request *protocol.AnnouncementSubmitRequest) (rsp *protocol.AnnouncementSubmitResponse, err error) {
var (
bulletin *models.Bulletin
userMsg *models.UserMsg
bulletinAnswer *models.BulletinQuestionAnswer
)
if bulletin, err = models.GetBulletinById(request.Id); err != nil {
log.Error(err)
err = protocol.NewErrWithMessage(2060)
return
}
if err = utils.ExecuteQueryOne(&userMsg, models.SqlUserMsg, request.Id, request.Uid, models.MsgTypeBulletin); err != nil {
log.Error(err)
err = protocol.NewErrWithMessage(2060)
return
}
//获取回答详情数据
if bulletinAnswer, err = models.GetBulletinQuestionAnswerBy(request.Id, int64(request.Uid)); err == nil {
bulletinAnswer.Answer = common.AssertJson(protocol.Answer{
EditContent: request.EditContent,
VoteResults: request.VoteResults,
})
bulletinAnswer.UpdateAt = time.Now()
if err = models.UpdateBulletinQuestionAnswerById(bulletinAnswer); err != nil {
return
}
return
}
orm := orm.NewOrm()
orm.Begin()
{
bulletinAnswer = &models.BulletinQuestionAnswer{
Answer: common.AssertJson(&protocol.Answer{
VoteResults: request.VoteResults,
EditContent: request.EditContent,
}),
BulletinId: bulletin.Id,
BulletinQuestionId: request.VoteId,
Uid: request.Uid,
CreateAt: time.Now(),
UpdateAt: time.Now(),
}
if _, err = orm.Insert(bulletinAnswer); err != nil {
log.Error(err)
orm.Rollback()
return
}
}
{
if userMsg.IsRead != 1 {
if err = utils.UpdateTableByMapWithOrmer(orm, userMsg, map[string]interface{}{"IsRead": int8(1)}); err != nil {
log.Error(err)
orm.Rollback()
return
}
}
}
orm.Commit()
rsp = &protocol.AnnouncementSubmitResponse{}
return
}
... ...