Browse Source

fix:消息推送时,新增返回推送时间

Roc 8 months ago
parent
commit
42f62ebace
3 changed files with 22 additions and 6 deletions
  1. 14 5
      controllers/report.go
  2. 1 1
      controllers/report_chapter.go
  3. 7 0
      models/report.go

+ 14 - 5
controllers/report.go

@@ -1850,7 +1850,7 @@ func (this *ReportController) MarkEditStatus() {
 // @Title 模板消息/客群消息推送接口
 // @Description 模板消息/客群消息推送接口
 // @Param	request	body models.SendTemplateMsgReq true "type json string"
-// @Success 200 Ret=200 推送成功
+// @Success 200 {object} models.SendTemplateMsgResp
 // @router /sendMsg [post]
 func (this *ReportController) SendMsg() {
 	br := new(models.BaseResponse).Init()
@@ -1884,13 +1884,13 @@ func (this *ReportController) SendMsg() {
 		}()
 	}
 
-	report, e := models.GetReportById(req.ReportId)
+	reportInfo, e := models.GetReportByReportId(req.ReportId)
 	if e != nil {
 		br.Msg = "报告不存在或已被删除, 请刷新页面"
 		br.ErrMsg = "获取报告失败, Err: " + e.Error()
 		return
 	}
-	if report.MsgIsSend == 1 && report.ThsMsgIsSend == 1 {
+	if reportInfo.MsgIsSend == 1 && reportInfo.ThsMsgIsSend == 1 {
 		br.Msg = "消息已推送,请勿重复操作"
 		br.ErrMsg = "消息已推送,请勿重复操作"
 		return
@@ -1911,7 +1911,7 @@ func (this *ReportController) SendMsg() {
 
 	// 可能存在历史数据两个只推了一个所以此处加个判断
 	// 推送模板消息
-	if report.MsgIsSend == 0 {
+	if reportInfo.MsgIsSend == 0 {
 		go func() {
 			fmt.Println("推送模板消息:", req.ReportId)
 			_ = services.SendMiniProgramReportWxMsg(req.ReportId)
@@ -1919,7 +1919,12 @@ func (this *ReportController) SendMsg() {
 	}
 
 	// 更新推送消息状态
-	if err = models.ModifyReportMsgIsSendV2(req.ReportId); err != nil {
+	reportInfo.MsgIsSend = 1
+	reportInfo.ThsMsgIsSend = 1
+	reportInfo.MsgSendTime = time.Now()
+	reportInfo.ModifyTime = time.Now()
+	err = reportInfo.UpdateReport([]string{"MsgIsSend", "ThsMsgIsSend", "MsgSendTime", "ModifyTime"})
+	if err != nil {
 		br.Msg = "推送失败"
 		br.ErrMsg = "更新报告消息状态失败, Err:" + err.Error()
 		return
@@ -1929,6 +1934,10 @@ func (this *ReportController) SendMsg() {
 	br.Success = true
 	br.Msg = "推送成功"
 	br.IsAddLog = true
+	br.Data = models.SendTemplateMsgResp{
+		ReportId:    reportInfo.Id,
+		MsgSendTime: reportInfo.MsgSendTime.Format(utils.FormatDateTime),
+	}
 }
 
 // CheckDayWeekReportChapterVideo

+ 1 - 1
controllers/report_chapter.go

@@ -346,7 +346,7 @@ func (this *ReportController) EditDayWeekChapter() {
 		}
 	}
 
-	if req.Title == "" {
+	if req.Title != "" {
 		reportChapterInfo.Title = req.Title
 	}
 	//reportChapterInfo.AddType = req.AddType

+ 7 - 0
models/report.go

@@ -622,6 +622,13 @@ type SendTemplateMsgReq struct {
 	ReportId int `description:"报告id"`
 }
 
+// SendTemplateMsgResp
+// @Description: 报告推送返回结构体
+type SendTemplateMsgResp struct {
+	ReportId    int    `description:"报告id"`
+	MsgSendTime string `description:"报告推送时间"`
+}
+
 func ModifyReportMsgIsSend(reportId int) (err error) {
 	o := orm.NewOrmUsingDB("rddp")
 	report, err := GetReportById(reportId)