|
|
@@ -64,9 +64,9 @@ func QueryNotice(c *gin.Context) {
|
|
|
return
|
|
|
}
|
|
|
|
|
|
- // 获取登录账号已读公告ID
|
|
|
+ // 获取登录账号已读公告ID, 这里要使用的是个人的UserID来查询
|
|
|
var msgReceivers []int
|
|
|
- engine.Table("MSGRECEIVER").Select("AUTOID").Where("RECEIVERTYPE = 2 and MANAGERID = ?", userAccount.Memberuserid).Find(&msgReceivers)
|
|
|
+ engine.Table("MSGRECEIVER").Select("AUTOID").Where("RECEIVERTYPE = 2 and MANAGERID = ?", userAccount.Userid).Find(&msgReceivers)
|
|
|
|
|
|
// 查询SENDTYPE = 1的数据
|
|
|
datas1 := make([]QueryNoticeRsp, 0)
|
|
|
@@ -165,5 +165,80 @@ func QueryNotice(c *gin.Context) {
|
|
|
logger.GetLogger().Infof("QueryNotice successed: %v", rst)
|
|
|
appG.Response(http.StatusOK, e.SUCCESS, rst)
|
|
|
}
|
|
|
+}
|
|
|
+
|
|
|
+// NoticeReadedReq 通知公告设置已读请求参数
|
|
|
+type NoticeReadedReq struct {
|
|
|
+ LoginID int `form:"loginID" binding:"requried"` // 登录账号
|
|
|
+ NoticeID int `form:"noticeID" binding:"requried"` // 通知公告ID
|
|
|
+}
|
|
|
+
|
|
|
+// NoticeReaded 通知公告设置已读请求
|
|
|
+// @Summary 通知公告设置已读请求
|
|
|
+// @Produce json
|
|
|
+// @Security ApiKeyAuth
|
|
|
+// @Param loginID query int true "登录账号"
|
|
|
+// @Param noticeID query int true "通知公告ID"
|
|
|
+// @Success 200 {object} app.Response
|
|
|
+// @Failure 500 {object} app.Response
|
|
|
+// @Router /Common/NoticeReaded [post]
|
|
|
+// @Tags 通用服务
|
|
|
+func NoticeReaded(c *gin.Context) {
|
|
|
+ appG := app.Gin{C: c}
|
|
|
+
|
|
|
+ // 获取请求参数
|
|
|
+ var req NoticeReadedReq
|
|
|
+ if err := appG.C.ShouldBindQuery(&req); err != nil {
|
|
|
+ logger.GetLogger().Errorf("NoticeReaded failed: %s", err.Error())
|
|
|
+ appG.Response(http.StatusBadRequest, e.INVALID_PARAMS, nil)
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ engine := db.GetEngine()
|
|
|
+ // 获取登录账号所属会员信息
|
|
|
+ var userAccount models.Useraccount
|
|
|
+ if has, _ := engine.Join("LEFT", "LOGINACCOUNT", "LOGINACCOUNT.USERID = USERACCOUNT.USERID").
|
|
|
+ Where("LOGINACCOUNT.LOGINID = ?", req.LoginID).Get(&userAccount); !has {
|
|
|
+ // 查询失败
|
|
|
+ logger.GetLogger().Errorf("NoticeReaded failed: %s", "获取登录账号所属会员ID失败")
|
|
|
+ appG.Response(http.StatusBadRequest, e.ERROR_OPERATION_FAILED, nil)
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ // 尝试获取指定已读数据
|
|
|
+ msgReceiver := &models.Msgreceiver{Autoid: int32(req.NoticeID), Managerid: userAccount.Userid, Receivertype: 2}
|
|
|
+ has, err := engine.Get(msgReceiver)
|
|
|
+ if err != nil {
|
|
|
+ // 执行失败
|
|
|
+ logger.GetLogger().Errorf("NoticeReaded failed: %s", err.Error())
|
|
|
+ appG.Response(http.StatusBadRequest, e.ERROR_OPERATION_FAILED, nil)
|
|
|
+ return
|
|
|
+ }
|
|
|
+ if has {
|
|
|
+ // 找到记录则更新已读状态
|
|
|
+ msgReceiver.Readstatus = 2
|
|
|
+ if _, err := engine.Update(msgReceiver); err != nil {
|
|
|
+ // 执行失败
|
|
|
+ logger.GetLogger().Errorf("NoticeReaded failed: %s", err.Error())
|
|
|
+ appG.Response(http.StatusBadRequest, e.ERROR_OPERATION_FAILED, nil)
|
|
|
+ return
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ // 找不到记录则新建一条
|
|
|
+ m := new(models.Msgreceiver)
|
|
|
+ m.Autoid = int32(req.NoticeID)
|
|
|
+ m.Managerid = userAccount.Userid
|
|
|
+ m.Readstatus = 2
|
|
|
+ m.Receivertype = 2
|
|
|
+ if _, err := engine.Insert(m); err != nil {
|
|
|
+ // 执行失败
|
|
|
+ logger.GetLogger().Errorf("NoticeReaded failed: %s", err.Error())
|
|
|
+ appG.Response(http.StatusBadRequest, e.ERROR_OPERATION_FAILED, nil)
|
|
|
+ return
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
+ // 执行成功
|
|
|
+ logger.GetLogger().Infof("NoticeReaded successed: %v", "ok")
|
|
|
+ appG.Response(http.StatusOK, e.SUCCESS, "")
|
|
|
}
|