作者 yangfu

公告全部已读修改

... ... @@ -47,6 +47,8 @@ const (
SqlUserMsg = "select * from user_msg where source_id=? and receive_user_id=? and msg_type=? " //特定未读消息
//删除消息
SqlDeleteUserMsg = "delete from user_msg where source_id=? and source_type=? and receive_user_id=? and msg_type=? " //特定未读消息
SqlBulletinUnRead = `select id,source_id from user_msg where msg_type=? and is_read =0 and receive_user_id = ?`
)
func (t *UserMsg) TableName() string {
... ... @@ -122,7 +124,7 @@ GROUP BY msg_type`
func UpdateUserMsgSetRead(userId int64, companyId int64, msgType int, msgId int64) (err error) {
o := orm.NewOrm()
sql := `update user_msg set is_read = 1
where receive_user_id = ? and company_id=? and source_type<>3`
where receive_user_id = ? and company_id=?`
if msgType > 0 {
sql += fmt.Sprintf(" and (msg_type & %v)>0", msgType)
}
... ...
... ... @@ -99,6 +99,8 @@ type TemplatesResponse struct {
type TemplateRequest struct {
ChanceTypeId int `json:"chanceTypeId" valid:"Required"`
TemplateId int `json:"templateId" valid:"Required"`
ChanceId int64 `json:"chanceId" ` //机会编号 ios特殊使用
}
type TemplateResponse struct {
Template *Template `json:"template"`
... ...
... ... @@ -255,14 +255,26 @@ func Template(header *protocol.RequestHeader, request *protocol.TemplateRequest)
var (
templates *models.AuditTemplate
forms []*models.AuditForm
chance *models.Chance
)
rsp = &protocol.TemplateResponse{}
if templates, err = models.GetAuditTemplate(header.CompanyId, request.ChanceTypeId, request.TemplateId); err != nil {
log.Error(fmt.Sprintf("公司:%v chance_type_id:%v id:%v无模板 ", header.CompanyId, request.ChanceTypeId, request.TemplateId), err)
return
}
if request.ChanceId > 0 {
if chance, err = models.GetChanceById(request.ChanceId); err == nil {
if chance.EnableStatus == 0 {
err = protocol.NewErrWithMessage(5101)
return
}
if chance.Status == models.ChanceStatusClose { //只有一个报错码5101 机会删除
err = protocol.NewCustomMessage(5101, "该机会已被关闭或您没有权限查看")
return
}
}
}
item := templates
//TODO:检查模板可见
//
//查询表单
if forms, err = models.GetAuditForms(header.CompanyId, item.Id); err != nil {
... ... @@ -510,6 +522,14 @@ func ChanceUpdate(header *protocol.RequestHeader, request *protocol.ChanceUpdate
err = protocol.NewErrWithMessage(5101)
return
}
if chance.EnableStatus == 0 {
err = protocol.NewErrWithMessage(5101)
return
}
if chance.Status == models.ChanceStatusClose { //只有一个报错码5101 机会删除
err = protocol.NewCustomMessage(5101, "该机会已被关闭或您没有权限查看")
return
}
//1.模板是否存在
if template, err = models.GetAuditTemplateById(int64(chance.AuditTemplateId)); err != nil {
log.Error("模板不存在:", chance.AuditTemplateId, err)
... ...
... ... @@ -102,8 +102,23 @@ func checkBulletinCanRead(sourceId int64) bool {
//标记全部已读
func MsgCenterAllRead(header *protocol.RequestHeader, request *protocol.MsgCenterAllReadRequest) (rsp *protocol.MsgCenterAllReadResponse, err error) {
var ()
var (
userMsgs []*models.UserMsg
)
rsp = &protocol.MsgCenterAllReadResponse{}
if request.MsgType == protocol.MsgTypeBulletin {
if e := utils.ExecuteQueryAll(&userMsgs, models.SqlBulletinUnRead, protocol.MsgTypeBulletin, header.UserId); e == nil {
for i := range userMsgs {
if checkBulletinCanRead(userMsgs[i].SourceId) {
e = models.UpdateUserMsgSetRead(header.UserId, header.CompanyId, protocol.MsgTypeBulletin, userMsgs[i].Id)
if e != nil {
log.Error(e)
}
}
}
}
return
}
err = models.UpdateUserMsgSetRead(header.UserId, header.CompanyId, request.MsgType, 0)
if err != nil {
log.Error(err)
... ...