Browse Source

消息弹框

wangchuanjin 2 năm trước cách đây
mục cha
commit
e12f174415
2 tập tin đã thay đổi với 28 bổ sung9 xóa
  1. 4 1
      src/config.json
  2. 24 8
      src/jfw/front/websocket.go

+ 4 - 1
src/config.json

@@ -384,6 +384,9 @@
 	"messageCenter": {
 		"appid": "10000",
         "dbName": "messagetest",
-        "interval": 300
+        "interval": 300,
+        "createtime": "2023-01-04 00:00:00",
+        "limitDay": 7,
+        "limitCount": 3
     }
 }

+ 24 - 8
src/jfw/front/websocket.go

@@ -330,7 +330,9 @@ func GetBuoyMsg(conn *websocket.Conn) {
 	messageCenter, _ := Sysconfig["messageCenter"].(map[string]interface{})
 	appid, _ := messageCenter["appid"].(string)
 	dbName, _ := messageCenter["dbName"].(string)
+	createtime := qutil.ObjToString(messageCenter["createtime"])
 	interval := qutil.IntAllDef(messageCenter["interval"], 300)
+	limitCount := qutil.IntAllDef(messageCenter["limitCount"], 3)
 	go func() {
 		defer qutil.Catch()
 		for {
@@ -349,15 +351,29 @@ func GetBuoyMsg(conn *websocket.Conn) {
 	}()
 	//发送消息
 	for {
-		reply := `{}`
-		list := public.BaseMysql.SelectBySql(`select id,title,link,content,show_content from `+dbName+`.message where receive_userid=? and isdel=1 and appid=? and isRead=0 and show_buoy=1 order by createtime desc limit 1`, userid, appid)
-		if list != nil && len(*list) == 1 {
-			reply = fmt.Sprintf(`{"id":%d,"title":"%s","content":"%s","show_content":"%s","link":"%s"}`, qutil.Int64All((*list)[0]["id"]), qutil.ObjToString((*list)[0]["title"]), qutil.ObjToString((*list)[0]["content"]), qutil.ObjToString((*list)[0]["show_content"]), strings.Split(qutil.ObjToString((*list)[0]["link"]), ",")[0])
+		timeA := time.Now().AddDate(0, 0, -qutil.IntAllDef(messageCenter["limitDay"], 7))
+		timeB, err := time.ParseInLocation(qutil.Date_Full_Layout, createtime, time.Local)
+		if err == nil && timeA.After(timeB) {
+			createtime = qutil.FormatDate(&timeA, qutil.Date_Full_Layout)
 		}
-		if err := websocket.Message.Send(conn, reply); err != nil {
-			//log.Println("websocket发送失败!", err)
-			conn.Close()
-			return
+		list := public.BaseMysql.SelectBySql(`select id,title,link,content,show_content,pc_tip from `+dbName+`.message where receive_userid=? and isdel=1 and appid=? and isRead=0 and createtime>? order by createtime desc limit ?`, userid, appid, createtime, limitCount)
+		if list != nil {
+			for _, v := range *list {
+				if qutil.IntAll(v["pc_tip"]) == 1 {
+					continue
+				}
+				id := qutil.Int64All(v["id"])
+				reply := fmt.Sprintf(`{"id":%d,"title":"%s","content":"%s","show_content":"%s","link":"%s"}`, id, qutil.ObjToString(v["title"]), qutil.ObjToString(v["content"]), qutil.ObjToString(v["show_content"]), strings.Split(qutil.ObjToString(v["link"]), ",")[0])
+				if err := websocket.Message.Send(conn, reply); err != nil {
+					//log.Println("websocket发送失败!", err)
+					conn.Close()
+					return
+				}
+				if id > 0 {
+					public.BaseMysql.UpdateOrDeleteBySql(`update `+dbName+`.message set pc_tip=1 where id=?`, id)
+				}
+				time.Sleep(time.Second)
+			}
 		}
 		time.Sleep(time.Duration(interval) * time.Second)
 	}