Эх сурвалжийг харах

画像使用情况接口更改

wangkaiyue 4 жил өмнө
parent
commit
a9068c0985

+ 8 - 3
src/jfw/modules/bigmember/src/service/portrait/subvipPortraitAction.go

@@ -135,12 +135,17 @@ func (this *SubVipPortrait) PortraitUsage() {
 		if bigMsg.VipStatus <= 0 && bigMsg.Vip_BuySet.Upgrade != 1 {
 			return nil, fmt.Errorf("非法请求")
 		}
-		total, usage := bigMsg.SubVipPortraitUsage()
-		return map[string]interface{}{
+		entId := util.DecodeId(this.GetString("entId"))
+		total, usage, isUsed := bigMsg.SubVipPortraitUsage(db.Mysql, entId)
+		returnMap := map[string]interface{}{
 			"total":  total,
 			"usage":  usage,
 			"provin": bigMsg.Vip_BuySet.AreaCount,
-		}, nil
+		}
+		if entId != "" {
+			returnMap["visited"] = isUsed
+		}
+		return returnMap, nil
 	}()
 	if errMsg != nil {
 		log.Printf("%s SubVipPortrait-portraitUsage 企业画像浏览量查询出错:%s\n", userId, errMsg.Error())

+ 45 - 27
src/jfw/modules/common/src/qfw/util/jy/subvipPortrait.go

@@ -15,7 +15,7 @@ const (
 	PortraitRecordTable = "portrait_record"
 )
 
-func (this *BigVipBaseMsg) SubVipPortraitUsage() (fullCount, usage int) {
+func (this *BigVipBaseMsg) SubVipPortraitUsage(mysql *mysql.Mysql, entId string) (fullCount, usage int, visited bool) {
 	if this.VipStatus <= 0 {
 		return
 	}
@@ -25,49 +25,67 @@ func (this *BigVipBaseMsg) SubVipPortraitUsage() (fullCount, usage int) {
 		fullCount = this.Vip_BuySet.AreaCount * OneAreaTimes
 	}
 	usage = redis.GetInt(PowerCacheDb, fmt.Sprintf(PortraitRecordTimes, this.Uid, int(time.Now().Month())))
+	if mysql != nil && entId != "" {
+		visited = this.isVisitEnt(mysql, entId)
+	}
 	return
 }
 
+func (this *BigVipBaseMsg) isVisitEnt(mysql *mysql.Mysql, entId string) bool {
+	if this.VipStatus <= 0 || entId == "" {
+		return false
+	}
+	now := time.Now()
+	//浏览缓存
+	visitedCache := fmt.Sprintf(UsePortraitVisited, this.Uid, int(now.Month()), entId)
+	//本月有浏览记录
+	if exists, err := redis.Exists(PowerCacheDb, visitedCache); err == nil && exists {
+		return true
+	}
+	if mysql.CountBySql(fmt.Sprintf("select count(id) from %s where user_id =? and ent_id =? and year(create_time)=? and month(create_time)=?",
+		PortraitRecordTable), this.Uid, entId, now.Year(), int(now.Month())) == 0 {
+		return false
+	}
+	redis.Put(PowerCacheDb, fmt.Sprintf(UsePortraitVisited, this.Uid, int(now.Month()), entId), 1, 60*60*5)
+	return true
+}
+
 func (this *BigVipBaseMsg) SubVipPortraitTimesCheck(mysql *mysql.Mysql, entId string) error {
 	if this.VipStatus <= 0 || entId == "" {
 		return fmt.Errorf("非法请求")
 	}
+
+	//查询本月是否浏览过
+	if this.isVisitEnt(mysql, entId) {
+		return nil
+	}
+
 	fullCount, now := 0, time.Now()
 	if this.Vip_BuySet.AreaCount == -1 {
 		fullCount = 16 * OneAreaTimes //全国全国行业
 	} else {
 		fullCount = this.Vip_BuySet.AreaCount * OneAreaTimes
 	}
-	//浏览缓存
-	visitedCache := fmt.Sprintf(UsePortraitVisited, this.Uid, int(now.Month()), entId)
-	//本月有浏览记录
-	if exists, err := redis.Exists(PowerCacheDb, visitedCache); err == nil && exists {
-		return nil
-	}
 
-	if mysql.CountBySql(fmt.Sprintf("select count(id) from %s where user_id =? and ent_id =? and year(create_time)=? and month(create_time)=?",
-		PortraitRecordTable), this.Uid, entId, now.Year(), int(now.Month())) == 0 {
-		//校验本月次数是否使用完
-		useKey := fmt.Sprintf(PortraitRecordTimes, this.Uid, int(now.Month()))
+	//校验本月次数是否使用完
+	useKey := fmt.Sprintf(PortraitRecordTimes, this.Uid, int(now.Month()))
 
-		useCount := redis.GetInt(PowerCacheDb, useKey)
-		if useCount >= fullCount {
-			return fmt.Errorf("本月次数已使用完")
-		}
+	useCount := redis.GetInt(PowerCacheDb, useKey)
+	if useCount >= fullCount {
+		return fmt.Errorf("本月次数已使用完")
+	}
 
-		//新增使用记录
-		if mysql.Insert(PortraitRecordTable, map[string]interface{}{
-			"user_id":     this.Uid,
-			"ent_id":      entId,
-			"create_time": now.Format("2006-01-02 15:04:05"),
-		}) == 0 {
-			return fmt.Errorf("数据记录异常")
-		}
-		if redis.Incr(PowerCacheDb, useKey) == 1 {
-			_ = redis.SetExpire(PowerCacheDb, useKey, 24*60*60*31) //次数缓存一个月
-		}
+	//新增使用记录
+	if mysql.Insert(PortraitRecordTable, map[string]interface{}{
+		"user_id":     this.Uid,
+		"ent_id":      entId,
+		"create_time": now.Format("2006-01-02 15:04:05"),
+	}) == 0 {
+		return fmt.Errorf("数据记录异常")
+	}
+	if redis.Incr(PowerCacheDb, useKey) == 1 {
+		_ = redis.SetExpire(PowerCacheDb, useKey, 24*60*60*31) //次数缓存一个月
 	}
-	redis.Put(PowerCacheDb, fmt.Sprintf(UsePortraitVisited, this.Uid, int(now.Month()), entId), 1, 60*60*5)
 	return nil
 }