浏览代码

Merge branch 'feature/v4.8.81_ws' of https://jygit.jydev.jianyu360.cn/qmx/jy into feature/v4.8.81_ws

wangshan 1 年之前
父节点
当前提交
1364287d49

+ 55 - 7
src/jfw/modules/publicapply/src/userbase/entity/entity.go

@@ -26,6 +26,7 @@ const (
 	RedisPoly                = "poly"     // 查白名单用户用的redis
 	WhitelistRedisKey        = "white_%s" // 白名单用户用的redis key
 	TabelOriginalPowerRecord = "original_power_record"
+	TableOriginalUserAccount = "original_user_account" // 用户每个月使用的查看原文次数表
 )
 
 type UserInfo struct {
@@ -441,12 +442,26 @@ func (o *OriginalPower) CountRecord() int {
 		// 付费用户 查询当月
 		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 保存查看原文记录
@@ -464,8 +479,8 @@ func (o *OriginalPower) SavePowerRecord(originalUrl string) {
 	if rs != nil && len(*rs) > 0 && util.IntAll((*rs)[0]["id"]) != 0 {
 		// 存在则直接次数加一,更新更新时间
 		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 {
 			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  获取留资信息和判断是否满足
 func (o *OriginalPower) CNode() (leadOk bool) {
 	// 查留资source

+ 7 - 1
src/jfw/modules/publicapply/src/userbase/initjson/ub.go

@@ -2,7 +2,9 @@ package initjson
 
 import (
 	util "app.yhyue.com/moapp/jybase/common"
+	"app.yhyue.com/moapp/jybase/date"
 	"log"
+	"time"
 )
 
 type BaseFunc struct {
@@ -36,7 +38,8 @@ type MenuInfo struct {
 	Isusable bool   `json:"isusable"` //是否可用
 }
 type OriginalConfig struct {
-	Stype []StypeInfo `json:"stype"`
+	Stype              []StypeInfo `json:"stype"`
+	UseUserAccountTime string      `json:"use_user_account_time"` // 此时间之后使用新表original_user_account统计数量
 }
 type StypeInfo struct {
 	Name  string `json:"name"`  // stype
@@ -47,6 +50,8 @@ type StypeInfo struct {
 var MenuMap []*MenuLevel
 var OriginalC *OriginalConfig
 var NoCheckStype []string // 不用校验权限的stype
+var UseUserAccountTime time.Time
+
 func init() {
 	log.Println("初始化 常用功能配置")
 	util.ReadConfig("./userbase/commonfunctions.json", &BaseFuncInfo)
@@ -59,4 +64,5 @@ func init() {
 			NoCheckStype = append(NoCheckStype, OriginalC.Stype[i].Name)
 		}
 	}
+	UseUserAccountTime, _ = time.ParseInLocation(date.Date_Full_Layout, OriginalC.UseUserAccountTime, time.Local)
 }

+ 2 - 1
src/jfw/modules/publicapply/src/userbase/original_power.json

@@ -35,5 +35,6 @@
       "login": true,
       "check": true
     }
-  ]
+  ],
+  "use_user_account_time": "2023-11-30 23:59:59"
 }

+ 3 - 0
src/jfw/modules/publicapply/src/userbase/service/service.go

@@ -262,6 +262,7 @@ func (this *ServiceStruct) GetOriginalText() {
 		}
 		//存记录
 		op.SavePowerRecord(url)
+		op.IncOriginalUserAccount()
 		this.ServeJson(Result{Data: map[string]interface{}{
 			"url":     url,
 			"surplus": op.TotalCount - int64(count) - 1,
@@ -312,6 +313,8 @@ func (this *ServiceStruct) GetOriginalText() {
 		}
 		//存记录
 		op.SavePowerRecord(url)
+		// 更新用户使用数量表
+		op.IncOriginalUserAccount()
 		this.ServeJson(Result{Data: map[string]interface{}{
 			"url":     url,
 			"surplus": op.TotalCount - int64(count) - 1,