소스 검색

no message

xingzai 1 년 전
부모
커밋
e83f4d2bcb

+ 1 - 1
controllers/base_auth.go

@@ -32,7 +32,7 @@ type BaseAuthController struct {
 }
 
 func (this *BaseAuthController) Prepare() {
-	fmt.Println("enter prepare")
+	//fmt.Println("enter prepare")
 	method := this.Ctx.Input.Method()
 	uri := this.Ctx.Input.URI()
 	fmt.Println("Url:", uri)

+ 15 - 28
controllers/yanxuan_special.go

@@ -355,6 +355,14 @@ func (this *YanxuanSpecialController) Save() {
 			br.ErrMsg = "操作失败,该账号不属于审核人员:" + sysUser.Mobile
 			return
 		}
+
+		specialItem, err := models.GetYanxuanSpecialItemById(req.Id)
+		if err != nil {
+			br.Msg = "保存失败"
+			br.ErrMsg = "保存失败,Err:" + err.Error()
+			return
+		}
+		item.UserId = specialItem.UserId // 专栏userid还是原有userId
 	}
 
 	specialId := 0
@@ -442,8 +450,8 @@ func (this *YanxuanSpecialController) Enable() {
 		this.Data["json"] = br
 		this.ServeJSON()
 	}()
-	sysUser := this.User
-	if sysUser == nil {
+	user := this.User
+	if user == nil {
 		br.Msg = "请登录"
 		br.ErrMsg = "请登录,SysUser Is Empty"
 		br.Ret = 408
@@ -480,8 +488,9 @@ func (this *YanxuanSpecialController) Enable() {
 		go services.SendWxMsgSpecialFollow(req.Id)
 	}
 	go services.SendWxMsgSpecialAuthor(req.Id, req.Status)
-	go services.UpdateYanxuanSpecialResourceData(req.Id) //  写入首页最新  cygx_resource_data 表
-	go services.EsAddYanxuanSpecial(req.Id)              //  写入es 综合搜索
+	go services.UpdateYanxuanSpecialResourceData(req.Id)                                  //  写入首页最新  cygx_resource_data 表
+	go services.EsAddYanxuanSpecial(req.Id)                                               //  写入es 综合搜索
+	go services.AddAddCygxYanxuanSpecialApprovalLog(user, req.Id, req.Status, req.Reason) //  写入es 综合搜索
 	br.Msg = "审批成功"
 	br.Ret = 200
 	br.Success = true
@@ -630,7 +639,7 @@ func (this *YanxuanSpecialController) Center() {
 
 // @Title 专栏点击记录
 // @Description 专栏点击记录
-// @Param	request	body models.AddCygxReportSelectionSubjectHistoryReq true "type json string"
+// @Param	request	body models.AddCygxYanxuanSpecialRecordReq true "type json string"
 // @router /record [post]
 func (this *YanxuanSpecialController) Record() {
 	br := new(models.BaseResponse).Init()
@@ -658,34 +667,12 @@ func (this *YanxuanSpecialController) Record() {
 		br.ErrMsg = "文章不存在,文章ID错误"
 		return
 	}
-	var sellerName string
-	sellerName, err = models.GetCompanySellerName(user.CompanyId)
-	if err != nil {
-		br.Msg = "报名失败!"
-		br.ErrMsg = "获取对应销售失败,Err:" + err.Error()
-		return
-	}
-	item := models.CygxYanxuanSpecialRecord{
-		UserId:           user.UserId,
-		Mobile:           user.Mobile,
-		Email:            user.Email,
-		CompanyId:        user.CompanyId,
-		CompanyName:      user.CompanyName,
-		RealName:         user.RealName,
-		SellerName:       sellerName,
-		CreateTime:       time.Now(),
-		ModifyTime:       time.Now(),
-		RegisterPlatform: utils.REGISTER_PLATFORM,
-		YanxuanSpecialId: req.SpecialId,
-	}
-	_, err = models.AddCygxYanxuanSpecialRecord(&item)
+	err = services.AddSpecialRecord(this.User, specialId, stopTime)
 	if err != nil {
 		br.Msg = "记录失败"
 		br.ErrMsg = "记录失败,Err:" + err.Error()
 		return
 	}
-
-	go services.AddSpecialRecord(this.User, specialId, stopTime)
 	br.Ret = 200
 	br.Success = true
 	br.Msg = "记录成功"

+ 16 - 0
models/cygx_yanxuan_special.go

@@ -296,3 +296,19 @@ func GetCygxYanxuanSpecialCount(condition string, pars []interface{}) (count int
 	err = o.Raw(sqlCount, pars).QueryRow(&count)
 	return
 }
+
+// UpdateYanxuanSpecialPv 修改研选专栏的阅读Pv
+func UpdateYanxuanSpecialPv(id int) (err error) {
+	o := orm.NewOrm()
+	sql := `UPDATE cygx_yanxuan_special SET pv=pv+1 WHERE id = ? `
+	_, err = o.Raw(sql, id).Exec()
+	return
+}
+
+// UpdateYanxuanSpecialUv 修改研选专栏的阅读Uv
+func UpdateYanxuanSpecialUv(id int) (err error) {
+	o := orm.NewOrm()
+	sql := `UPDATE cygx_yanxuan_special SET uv=uv+1 WHERE id = ? `
+	_, err = o.Raw(sql, id).Exec()
+	return
+}

+ 34 - 0
models/cygx_yanxuan_special_approval_log.go

@@ -0,0 +1,34 @@
+package models
+
+import (
+	"github.com/beego/beego/v2/client/orm"
+	"time"
+)
+
+type CygxYanxuanSpecialApprovalLog struct {
+	ApprovalLogId    int       `orm:"column(approval_log_id);pk"`
+	UserId           int       // 用户ID
+	CreateTime       time.Time // 创建时间
+	ModifyTime       time.Time // 修改时间
+	Content          string    // 内容
+	Tags             string    // 标签
+	ApprovalStatus   int       // 1通过、2驳回
+	ImgUrl           string    // 图片链接
+	DocUrl           string    // 文档链接
+	Reason           string    // 理由
+	Title            string    // 标题
+	Type             int       // 类型1:笔记,2:观点
+	CompanyTags      string    // 公司标签
+	IndustryTags     string    // 行业标签
+	YanxuanSpecialId int       // cygx_yanxuan_special 表主键ID
+	AdminName        string    // 审核人员姓名
+	AdminUserId      int       // 审核人员用户ID
+	SpecialName      string    // 专栏名称
+	NickName         string    // 昵称
+}
+
+func AddCygxYanxuanSpecialApprovalLog(item *CygxYanxuanSpecialApprovalLog) (err error) {
+	o := orm.NewOrm()
+	_, err = o.Insert(item)
+	return
+}

+ 42 - 0
models/cygx_yanxuan_special_record.go

@@ -31,3 +31,45 @@ type AddCygxYanxuanSpecialRecordReq struct {
 	SpecialId int `description:"专栏文章id"`
 	StopTime  int `description:"停留时间"`
 }
+
+// 获取数量
+func GetCygxYanxuanSpecialRecordCount(condition string, pars []interface{}) (count int, err error) {
+	sqlCount := ` SELECT COUNT(1) AS count  FROM cygx_yanxuan_special_record as a  WHERE 1= 1  `
+	if condition != "" {
+		sqlCount += condition
+	}
+	o := orm.NewOrm()
+	err = o.Raw(sqlCount, pars).QueryRow(&count)
+	return
+}
+
+// 判断一个用户是否阅读过 某一篇研选专栏
+func GetCygxYanxuanSpecialRecordCountByUser(userId, yanxuanSpecialId int) (count int, err error) {
+	sqlCount := ` SELECT COUNT(1) AS count  FROM cygx_yanxuan_special_record as a  WHERE user_id= ?    AND yanxuan_special_id  = ? `
+	o := orm.NewOrm()
+	err = o.Raw(sqlCount, userId, yanxuanSpecialId).QueryRow(&count)
+	return
+}
+
+// 详细日志记录,不过滤时长小于 3 秒的那种
+type CygxYanxuanSpecialRecordLog struct {
+	CygxYanxuanSpecialRecordId int       `orm:"column(cygx_yanxuan_special_record_id);pk"`
+	UserId                     int       // 用户ID
+	Mobile                     string    // 手机号
+	Email                      string    // 邮箱
+	CompanyId                  int       // 公司ID
+	CompanyName                string    // 公司名称
+	RealName                   string    // 用户实际名称
+	SellerName                 string    // 所属销售
+	CreateTime                 time.Time // 创建时间
+	ModifyTime                 time.Time // 修改时间
+	RegisterPlatform           int       // 来源 1小程序,2:网页
+	YanxuanSpecialId           int       // cygx_yanxuan_special 表主键ID
+	StopTime                   int       // 停留时间
+}
+
+func AddCygxYanxuanSpecialRecordLog(item *CygxYanxuanSpecialRecordLog) (lastId int64, err error) {
+	o := orm.NewOrm()
+	lastId, err = o.Insert(item)
+	return
+}

+ 26 - 0
models/cygx_yanxuan_special_user.go

@@ -94,6 +94,14 @@ FROM
 	return
 }
 
+// 根据用户ID获取专栏详情
+func GetCygxYanxuanSpecialAuthorByUserId(userId int) (item *CygxYanxuanSpecialAuthorItem, err error) {
+	o := orm.NewOrm()
+	sql := `SELECT * FROM cygx_yanxuan_special_author  WHERE user_id = ? `
+	err = o.Raw(sql, userId).QueryRow(&item)
+	return
+}
+
 type SaveCygxYanxuanSpecialAuthorReq struct {
 	UserId       int    // 用户ID
 	SpecialName  string // 专栏名称
@@ -158,3 +166,21 @@ func UpdateYanxuanSpecialAuthorHeadImg(item *CygxYanxuanSpecialAuthor) (err erro
 	_, err = o.Raw(sql, item.HeadImg, item.UserId).Exec()
 	return
 }
+
+// UpdateCygxYanxuanSpecialAuthorPv 修改研选专栏作者的阅读Pv
+func UpdateCygxYanxuanSpecialAuthorPv(userId int) (err error) {
+	o := orm.NewOrm()
+	sql := ``
+	sql = `UPDATE cygx_yanxuan_special_author SET pv=pv+1 WHERE user_id = ? `
+	_, err = o.Raw(sql, userId).Exec()
+	return
+}
+
+// UpdateCygxYanxuanSpecialAuthorUv 修改研选专栏作者的阅读Uv
+func UpdateCygxYanxuanSpecialAuthorUv(userId int) (err error) {
+	o := orm.NewOrm()
+	sql := ``
+	sql = `UPDATE cygx_yanxuan_special_author SET uv=uv+1 WHERE user_id = ? `
+	_, err = o.Raw(sql, userId).Exec()
+	return
+}

+ 2 - 0
models/db.go

@@ -173,10 +173,12 @@ func init() {
 		new(CygxResourceDataIndustrialGroupSubject),
 		new(CygxIndustryFllowLog),
 		new(CygxYanxuanSpecialRecord),
+		new(CygxYanxuanSpecialRecordLog),
 		new(CygxYanxuanSpecialCollect),
 		new(CygxYanxuanSpecial),
 		new(CygxYanxuanSpecialFollow),
 		new(CygxYanxuanSpecialCompany),
+		new(CygxYanxuanSpecialApprovalLog),
 		new(CygxQuestionnaireVote),
 		new(CygxQuestionnaireVoteOtherTheme),
 		new(CygxMorningMeetingReviewChapterHistory),

+ 48 - 0
services/cygx_yanxuan_special.go

@@ -361,3 +361,51 @@ func GetBestNewYanxuanSpecialByUserId(userIds []int) (mapResp map[int]*models.Cy
 	}
 	return
 }
+
+// 研选专栏审批记录
+func AddAddCygxYanxuanSpecialApprovalLog(user *models.WxUserItem, specialId, status int, reason string) {
+	var err error
+	defer func() {
+		if err != nil {
+			go utils.SendAlarmMsg(fmt.Sprint("获取研选专栏用户信息失败,GetYanxuanSpecialAuthorInfo Err ", err, "userId", user.UserId), 2)
+		}
+	}()
+	detail, e := models.GetYanxuanSpecialBySpecialId(specialId)
+	if e != nil {
+		err = errors.New("GetYanxuanSpecialBySpecialId, Err: " + e.Error())
+		return
+	}
+
+	specialAuthor, e := models.GetCygxYanxuanSpecialAuthorByUserId(detail.UserId)
+	if e != nil {
+		err = errors.New("GetCygxYanxuanSpecialAuthorByUserId, Err: " + e.Error())
+		return
+	}
+
+	item := new(models.CygxYanxuanSpecialApprovalLog)
+	item.UserId = detail.UserId
+	item.Content = detail.Content
+	item.Tags = detail.Tags
+	item.ApprovalStatus = status
+	item.ImgUrl = detail.ImgUrl
+	item.DocUrl = detail.DocUrl
+	item.Reason = reason
+	item.Title = detail.Title
+	item.Type = detail.Type
+	item.CompanyTags = detail.CompanyTags
+	item.IndustryTags = detail.IndustryTags
+	item.YanxuanSpecialId = specialId
+	item.AdminName = user.RealName
+	item.AdminUserId = user.UserId
+	item.SpecialName = specialAuthor.SpecialName
+	item.NickName = specialAuthor.NickName
+	item.CreateTime = time.Now()
+	item.ModifyTime = time.Now()
+
+	e = models.AddCygxYanxuanSpecialApprovalLog(item)
+	if e != nil {
+		err = errors.New("AddCygxYanxuanSpecialApprovalLog, Err: " + e.Error())
+		return
+	}
+	return
+}

+ 71 - 22
services/cygx_yanxuan_special_company.go

@@ -3,6 +3,7 @@ package services
 import (
 	"context"
 	"encoding/json"
+	"errors"
 	"fmt"
 	"hongze/hongze_cygx/models"
 	"hongze/hongze_cygx/utils"
@@ -64,16 +65,31 @@ func GetStocksFromVmp(cont context.Context) (err error) {
 	return
 }
 
-func AddSpecialRecord(user *models.WxUserItem, specialId, stopTime int) {
+// 记录用户阅读时长
+func AddSpecialRecord(user *models.WxUserItem, specialId, stopTime int) (err error) {
+	defer func() {
+		if err != nil {
+			go utils.SendAlarmMsg(fmt.Sprint("记录用户阅读时长 失败 AddSpecialRecord Err:"+err.Error(), "userId:", user.UserId, "specialId:", specialId), 2)
+		}
+	}()
 	var sellerName string
 	//获取销售信息
-	sellerItem, err := models.GetSellerByCompanyIdCheckFicc(user.CompanyId, 2)
-	if err != nil {
+	sellerItem, e := models.GetSellerByCompanyIdCheckFicc(user.CompanyId, 2)
+	if e != nil {
+		err = errors.New("GetSellerByCompanyIdCheckFicc, Err: " + e.Error())
 		return
 	}
 	sellerName = sellerItem.RealName
 
 	if stopTime >= 3 {
+
+		//判断一个用户是否阅读过 某一篇研选专栏
+		totalRecord, e := models.GetCygxYanxuanSpecialRecordCountByUser(user.UserId, specialId)
+		if e != nil {
+			err = errors.New("GetCygxYanxuanSpecialRecordCountByUser, Err: " + e.Error())
+			return
+		}
+
 		item := new(models.CygxYanxuanSpecialRecord)
 		item.UserId = user.UserId
 		item.Mobile = user.Mobile
@@ -82,34 +98,67 @@ func AddSpecialRecord(user *models.WxUserItem, specialId, stopTime int) {
 		item.CompanyName = user.CompanyName
 		item.RealName = user.RealName
 		item.SellerName = sellerName
-		item.CreateTime = time.Now()
+		item.CreateTime = time.Now().Add(-time.Duration(stopTime) * time.Second) // 往前推迟的时间就是他的阅读时间
 		item.ModifyTime = time.Now()
 		item.RegisterPlatform = utils.REGISTER_PLATFORM
 		item.YanxuanSpecialId = specialId
-
-		_, err = models.AddCygxYanxuanSpecialRecord(item)
-		if err != nil {
+		item.StopTime = stopTime
+		_, e = models.AddCygxYanxuanSpecialRecord(item) // 添加历史记录
+		if e != nil {
+			err = errors.New("AddCygxYanxuanSpecialRecord, Err: " + e.Error())
 			return
 		}
-
 		//如果不是弘则研究的人员阅读的,就修改Pv、Uv数量
 		if user.CompanyId != utils.HZ_COMPANY_ID {
 
+			//专栏Pv数量进行加一
+			e = models.UpdateYanxuanSpecialPv(specialId)
+			if e != nil {
+				err = errors.New("UpdateYanxuanSpecialPv, Err: " + e.Error())
+				return
+			}
+
+			//专栏作者Pv数量进行加一
+			e = models.UpdateCygxYanxuanSpecialAuthorPv(user.UserId)
+			if e != nil {
+				err = errors.New("UpdateCygxYanxuanSpecialAuthorPv, Err: " + e.Error())
+				return
+			}
+
+			//如果没有阅读过,那么就给专栏文章的UV、作者的UV进行加一
+			if totalRecord == 0 {
+				e = models.UpdateYanxuanSpecialUv(specialId)
+				if e != nil {
+					err = errors.New("UpdateYanxuanSpecialUv, Err: " + e.Error())
+					return
+				}
+
+				//专栏作者Uv数量进行加一
+				e = models.UpdateCygxYanxuanSpecialAuthorUv(user.UserId)
+				if e != nil {
+					err = errors.New("UpdateCygxYanxuanSpecialAuthorUv, Err: " + e.Error())
+					return
+				}
+			}
 		}
 	}
 
-	//item := models.CygxYanxuanSpecialRecord{
-	//	UserId:           user.UserId,
-	//	Mobile:           user.Mobile,
-	//	Email:            user.Email,
-	//	CompanyId:        user.CompanyId,
-	//	CompanyName:      user.CompanyName,
-	//	RealName:         user.RealName,
-	//	SellerName:       sellerName,
-	//	CreateTime:       time.Now(),
-	//	ModifyTime:       time.Now(),
-	//	RegisterPlatform: utils.REGISTER_PLATFORM,
-	//	YanxuanSpecialId: specialId,
-	//}
-
+	itemLog := new(models.CygxYanxuanSpecialRecordLog)
+	itemLog.UserId = user.UserId
+	itemLog.Mobile = user.Mobile
+	itemLog.Email = user.Email
+	itemLog.CompanyId = user.CompanyId
+	itemLog.CompanyName = user.CompanyName
+	itemLog.RealName = user.RealName
+	itemLog.SellerName = sellerName
+	itemLog.CreateTime = time.Now().Add(-time.Duration(stopTime) * time.Second) // 往前推迟的时间就是他的阅读时间
+	itemLog.ModifyTime = time.Now()
+	itemLog.RegisterPlatform = utils.REGISTER_PLATFORM
+	itemLog.YanxuanSpecialId = specialId
+	_, e = models.AddCygxYanxuanSpecialRecordLog(itemLog) // 添加历史记录
+	if e != nil {
+		err = errors.New("AddCygxYanxuanSpecialRecordLog, Err: " + e.Error())
+		return
+	}
+	return
 }

+ 2 - 2
services/user.go

@@ -21,7 +21,7 @@ var ERR_USER_NOT_BIND = errors.New("用户没有绑定")
 func GetWxUserItemByOpenId(openid string) (item *models.WxUserItem, err error) {
 	//通过openid获取用户关联信息
 	userRecord, userRecordErr := models.GetUserRecordByOpenId(openid)
-	fmt.Println("userRecordErr", userRecordErr)
+	//fmt.Println("userRecordErr", userRecordErr)
 	if userRecordErr != nil {
 		if userRecordErr.Error() == utils.ErrNoRow() {
 			err = ERR_NO_USER_RECORD
@@ -49,7 +49,7 @@ func GetWxUserItemByOpenId(openid string) (item *models.WxUserItem, err error) {
 
 	//获取用户信息
 	item, wxUserErr := models.GetWxUserItemByUserId(userRecord.UserId)
-	fmt.Println("wxUserErr", wxUserErr)
+	//fmt.Println("wxUserErr", wxUserErr)
 	if wxUserErr != nil {
 		err = wxUserErr
 		//如果是找不到数据,那么可能是该用户被删除了,但是user_record没有删除对应的关系