|
@@ -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
|
|
|
}
|
|
|
|