|
@@ -32,9 +32,6 @@ func (this *BigVipBaseMsg) SubVipPortraitUsage(mysql *mysql.Mysql, entId string)
|
|
|
}
|
|
|
|
|
|
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)
|
|
@@ -54,37 +51,40 @@ func (this *BigVipBaseMsg) SubVipPortraitTimesCheck(mysql *mysql.Mysql, entId st
|
|
|
if this.VipStatus <= 0 || entId == "" {
|
|
|
return fmt.Errorf("非法请求")
|
|
|
}
|
|
|
-
|
|
|
+ fullCount, now := 0, time.Now()
|
|
|
//查询本月是否浏览过
|
|
|
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
|
|
|
- }
|
|
|
+ //并发控制
|
|
|
+ if redis.Incr(PowerCacheDb, fmt.Sprintf(UsePortraitVisited, this.Uid, int(now.Month()), entId)) == 1 {
|
|
|
+ _ = redis.SetExpire(PowerCacheDb, fmt.Sprintf(UsePortraitVisited, this.Uid, int(now.Month()), entId), 60*60*5)
|
|
|
+ if this.Vip_BuySet.AreaCount == -1 {
|
|
|
+ fullCount = 16 * OneAreaTimes //全国全国行业
|
|
|
+ } else {
|
|
|
+ fullCount = this.Vip_BuySet.AreaCount * OneAreaTimes
|
|
|
+ }
|
|
|
|
|
|
- //校验本月次数是否使用完
|
|
|
- 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) //次数缓存一个月
|
|
|
+ }
|
|
|
}
|
|
|
return nil
|
|
|
}
|