Explorar o código

wip:详情页超限制日志

wangshan hai 9 meses
pai
achega
76223f29bc
Modificáronse 1 ficheiros con 31 adicións e 0 borrados
  1. 31 0
      src/jfw/modules/publicapply/src/detail/dao/bidding.go

+ 31 - 0
src/jfw/modules/publicapply/src/detail/dao/bidding.go

@@ -22,6 +22,7 @@ import (
 	"regexp"
 	"strconv"
 	"strings"
+	"sync"
 	"time"
 )
 
@@ -157,6 +158,34 @@ func CNode(userId string) bool {
 	return false
 }
 
+var (
+	limitLogsLock  = sync.Mutex{}
+	limitLogsChan  = make(chan struct{}, 4)
+	limitLogsCount = 30
+	limitLogsData  []map[string]interface{}
+)
+
+// 免费未留资用户查看公告超过免费次数限制记录
+func SeeDetailLimitLogs(userId, sid string) {
+	limitLogsChan <- struct{}{}
+	defer func() {
+		<-limitLogsChan
+	}()
+	//保存日志
+	limitLogsLock.Lock()
+	limitLogsData = append(limitLogsData, map[string]interface{}{
+		"userId":     userId,
+		"biddingId":  sid,
+		"createDate": time.Now().Unix(),
+	})
+	if len(limitLogsData) > limitLogsCount {
+		tmp := limitLogsData
+		limitLogsData = make([]map[string]interface{}, 0)
+		db.Mgo_Log.SaveBulk("detail_limit_logs", tmp...)
+	}
+	limitLogsLock.Unlock()
+}
+
 // 查看公告详情次数限制
 func SeeDetailLimit(obj map[string]interface{}, userId, sid string) bool {
 	if obj != nil {
@@ -185,6 +214,8 @@ func SeeDetailLimit(obj map[string]interface{}, userId, sid string) bool {
 							return true
 						}
 					}
+					//超过限制次数 记录
+					go SeeDetailLimitLogs(userId, sid)
 					return false
 				}
 			}