|
@@ -26,6 +26,7 @@ const (
|
|
RedisPoly = "poly" // 查白名单用户用的redis
|
|
RedisPoly = "poly" // 查白名单用户用的redis
|
|
WhitelistRedisKey = "white_%s" // 白名单用户用的redis key
|
|
WhitelistRedisKey = "white_%s" // 白名单用户用的redis key
|
|
TabelOriginalPowerRecord = "original_power_record"
|
|
TabelOriginalPowerRecord = "original_power_record"
|
|
|
|
+ TableOriginalUserAccount = "original_user_account" // 用户每个月使用的查看原文次数表
|
|
)
|
|
)
|
|
|
|
|
|
type UserInfo struct {
|
|
type UserInfo struct {
|
|
@@ -441,12 +442,26 @@ func (o *OriginalPower) CountRecord() int {
|
|
// 付费用户 查询当月
|
|
// 付费用户 查询当月
|
|
where = fmt.Sprintf(`and create_time >="%s"`, timeStart)
|
|
where = fmt.Sprintf(`and create_time >="%s"`, timeStart)
|
|
}
|
|
}
|
|
- sourceStr := ""
|
|
|
|
- if len(o.NoCheckStype) > 0 {
|
|
|
|
- sourceStr = "and source not in (\"" + strings.Join(o.NoCheckStype, "\",\"") + "\")"
|
|
|
|
|
|
+ // UseUserAccountTime 此时间之后使用新表统计数据
|
|
|
|
+ if initjson.UseUserAccountTime.Before(time.Now()) {
|
|
|
|
+ // 查询条数
|
|
|
|
+ qCount := fmt.Sprintf("select usage_count from %s where position_id=? %s", TableOriginalUserAccount, where)
|
|
|
|
+ countRs := db.Mysql.SelectBySql(qCount, o.PositionId)
|
|
|
|
+ // 已经有数据
|
|
|
|
+ if countRs != nil && len(*countRs) > 0 {
|
|
|
|
+ return util.IntAll((*countRs)[0]["usage_count"])
|
|
|
|
+ } else {
|
|
|
|
+ return 0
|
|
|
|
+ }
|
|
|
|
+ } else {
|
|
|
|
+ // 配置时间之前的 走老逻辑 count统计
|
|
|
|
+ sourceStr := ""
|
|
|
|
+ if len(o.NoCheckStype) > 0 {
|
|
|
|
+ sourceStr = "and source not in (\"" + strings.Join(o.NoCheckStype, "\",\"") + "\")"
|
|
|
|
+ }
|
|
|
|
+ q := fmt.Sprintf(" SELECT count(distinct(bidding_id)) FROM %s where position_id=? and user_type=? %s %s;", TabelOriginalPowerRecord, sourceStr, where)
|
|
|
|
+ return int(db.Mysql.CountBySql(q, o.PositionId, o.UserType))
|
|
}
|
|
}
|
|
- q := fmt.Sprintf(" SELECT count(distinct(bidding_id)) FROM %s where position_id=? and user_type=? %s %s;", TabelOriginalPowerRecord, sourceStr, where)
|
|
|
|
- return int(db.Mysql.CountBySql(q, o.PositionId, o.UserType))
|
|
|
|
}
|
|
}
|
|
|
|
|
|
// SavePowerRecord 保存查看原文记录
|
|
// SavePowerRecord 保存查看原文记录
|
|
@@ -464,8 +479,8 @@ func (o *OriginalPower) SavePowerRecord(originalUrl string) {
|
|
if rs != nil && len(*rs) > 0 && util.IntAll((*rs)[0]["id"]) != 0 {
|
|
if rs != nil && len(*rs) > 0 && util.IntAll((*rs)[0]["id"]) != 0 {
|
|
// 存在则直接次数加一,更新更新时间
|
|
// 存在则直接次数加一,更新更新时间
|
|
id := util.IntAll((*rs)[0]["id"])
|
|
id := util.IntAll((*rs)[0]["id"])
|
|
- updateSql := fmt.Sprintf("update %s set views_times = views_times+1,update_time=? where id =?", TabelOriginalPowerRecord)
|
|
|
|
- _, err := db.Mysql.ExecBySql(updateSql, date.NowFormat(date.Date_Full_Layout), id)
|
|
|
|
|
|
+ updateSql := fmt.Sprintf("update %s set views_times = views_times+1,update_time=?,client=? where id =?", TabelOriginalPowerRecord)
|
|
|
|
+ _, err := db.Mysql.ExecBySql(updateSql, date.NowFormat(date.Date_Full_Layout), o.Client, id)
|
|
if err != nil {
|
|
if err != nil {
|
|
log.Println("更新浏览次数失败:", err, updateSql, date.NowFormat(date.Date_Full_Layout), id)
|
|
log.Println("更新浏览次数失败:", err, updateSql, date.NowFormat(date.Date_Full_Layout), id)
|
|
}
|
|
}
|
|
@@ -492,6 +507,39 @@ func (o *OriginalPower) SavePowerRecord(originalUrl string) {
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+// IncOriginalUserAccount 次数加一
|
|
|
|
+func (o *OriginalPower) IncOriginalUserAccount() {
|
|
|
|
+ // 存在则加一
|
|
|
|
+ where := ""
|
|
|
|
+ if o.UserType == UserTypePay {
|
|
|
|
+ timeStart := GetMonthStart()
|
|
|
|
+ // 付费用户 查询当月
|
|
|
|
+ where = fmt.Sprintf(`and create_time >="%s"`, timeStart)
|
|
|
|
+ }
|
|
|
|
+ // 查询条数
|
|
|
|
+ qCount := fmt.Sprintf("select id from %s where position_id=? %s", TableOriginalUserAccount, where)
|
|
|
|
+ countRs := db.Mysql.SelectBySql(qCount, o.PositionId)
|
|
|
|
+ if countRs != nil && len(*countRs) > 0 {
|
|
|
|
+ id := (*countRs)[0]["id"]
|
|
|
|
+ // 存在则执行更新
|
|
|
|
+ _, err := db.Mysql.ExecBySql(fmt.Sprintf("update %s set usage_count=usage_count+1 where id=?", TableOriginalUserAccount), id)
|
|
|
|
+ if err != nil {
|
|
|
|
+ log.Println("更新条数信息失败:", err, o.Phone, o.UserId, o.Client, o.PositionId)
|
|
|
|
+ return
|
|
|
|
+ }
|
|
|
|
+ } else {
|
|
|
|
+ // 不存在则插入
|
|
|
|
+ db.Mysql.Insert(TableOriginalUserAccount, map[string]interface{}{
|
|
|
|
+ "user_id": o.UserId,
|
|
|
|
+ "position_id": o.PositionId,
|
|
|
|
+ "phone": o.Phone,
|
|
|
|
+ "usage_count": 1,
|
|
|
|
+ "create_time": date.NowFormat(date.Date_Full_Layout),
|
|
|
|
+ "update_time": date.NowFormat(date.Date_Full_Layout),
|
|
|
|
+ })
|
|
|
|
+ }
|
|
|
|
+}
|
|
|
|
+
|
|
// CNode 获取留资信息和判断是否满足
|
|
// CNode 获取留资信息和判断是否满足
|
|
func (o *OriginalPower) CNode() (leadOk bool) {
|
|
func (o *OriginalPower) CNode() (leadOk bool) {
|
|
// 查留资source
|
|
// 查留资source
|