kobe6258 8 сар өмнө
parent
commit
e80a19ceb0

+ 8 - 0
domian/user/user_serivce.go

@@ -43,6 +43,14 @@ func GetUserByMobile(mobile string) (UserDTO, error) {
 	return dto, nil
 }
 
+func GetUserAndCountReadTimes(userId int) (err error) {
+	err = userDao.GetUserByIdAndCountReadTimes(userId)
+	if err != nil {
+		logger.Error("更新用户阅读次数失败:%v", err)
+	}
+	return
+}
+
 func RegisterTemplateUser(dto *UserDTO) (err error) {
 	templateUser := convertToTemplateUser(dto)
 	err = userDao.RegisterTemplateUser(&templateUser)

+ 2 - 0
domian/user/user_source_click_flow_service.go

@@ -23,6 +23,7 @@ func CountReport(record RecordCountDTO) (err error) {
 		logger.Error("插入用户研报点击记录失败:%v", err)
 		return
 	}
+	_ = GetUserAndCountReadTimes(record.UserId)
 	return
 }
 
@@ -33,6 +34,7 @@ func CountMedia(record RecordCountDTO) (err error) {
 		logger.Error("插入用户研报点击记录失败:%v", err)
 		return
 	}
+	_ = GetUserAndCountReadTimes(record.UserId)
 	return
 }
 

+ 14 - 9
models/user/template_user.go

@@ -12,15 +12,17 @@ const (
 )
 
 type TemplateUser struct {
-	Id          int       `gorm:"column:id;primaryKey;autoIncrement:'id'"`
-	Username    string    `gorm:"column:username;type:varchar(20);comment:用户名"`
-	Mobile      string    `gorm:"column:mobile;type:varchar(15);comment:手机号"`
-	OpenId      string    `gorm:"column:open_id;type:varchar(50);comment:open_id"`
-	GzhOpenId   string    `gorm:"column:gzh_open_id;type:varchar(255);comment:gzh_open_id"`
-	UnionId     string    `gorm:"column:union_id;type:varchar(50);comment:union_id"`
-	IsDeleted   int       `gorm:"column:is_deleted;type:int(11);comment:是否删除"`
-	CreatedTime time.Time `gorm:"column:created_time;type:timestamps;comment:创建时间"`
-	UpdatedTime time.Time `gorm:"column:updated_time;type:timestamps;comment:更新时间"`
+	Id           int       `gorm:"column:id;primaryKey;autoIncrement:'id'"`
+	Username     string    `gorm:"column:username;type:varchar(20);comment:用户名"`
+	Mobile       string    `gorm:"column:mobile;type:varchar(15);comment:手机号"`
+	OpenId       string    `gorm:"column:open_id;type:varchar(50);comment:open_id"`
+	GzhOpenId    string    `gorm:"column:gzh_open_id;type:varchar(255);comment:gzh_open_id"`
+	UnionId      string    `gorm:"column:union_id;type:varchar(50);comment:union_id"`
+	ReadCount    int       `gorm:"column:read_count;type:int(11);comment:阅读次数"`
+	LastReadTime time.Time `gorm:"column:last_read_time;type:timestamps;comment:最后阅读时间"`
+	IsDeleted    int       `gorm:"column:is_deleted;type:int(11);comment:是否删除"`
+	CreatedTime  time.Time `gorm:"column:created_time;type:timestamps;comment:创建时间"`
+	UpdatedTime  time.Time `gorm:"column:updated_time;type:timestamps;comment:更新时间"`
 }
 
 func (t *TemplateUser) BeforeCreate(tx *gorm.DB) (err error) {
@@ -32,6 +34,9 @@ func (t *TemplateUser) BeforeCreate(tx *gorm.DB) (err error) {
 func GetUserByMobile(mobile string) (user TemplateUser, err error) {
 	return queryByColumn("mobile", mobile)
 }
+func GetUserByIdAndCountReadTimes(userId int) (err error) {
+	return models.Main().Model(&TemplateUser{}).Where("id = ?", userId).Update("read_count", gorm.Expr("read_count + ?", 1)).Error
+}
 
 func GetUserByOpenId(openId string) (user TemplateUser, err error) {
 	return queryByColumn("open_id", openId)

+ 1 - 1
task/eta/media/eta_media_task.go

@@ -70,6 +70,6 @@ type MediaTask struct {
 }
 
 func init() {
-	reportTask := base.NewTask(taskName, cron, new(MediaTask), base.DEV)
+	reportTask := base.NewTask(taskName, cron, new(MediaTask), base.PROD)
 	base.RegisterTask(&reportTask)
 }