瀏覽代碼

Merge branch 'cygx_12.8' of http://8.136.199.33:3000/hongze/hongze_cygx into debug

xingzai 1 年之前
父節點
當前提交
4414228e8b

+ 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)

+ 165 - 32
controllers/yanxuan_special.go

@@ -6,6 +6,7 @@ import (
 	"hongze/hongze_cygx/models"
 	"hongze/hongze_cygx/services"
 	"hongze/hongze_cygx/utils"
+	"strconv"
 	"strings"
 	"time"
 )
@@ -205,9 +206,6 @@ func (this *YanxuanSpecialController) Detail() {
 		resp.CygxYanxuanSpecialItem = *new(models.CygxYanxuanSpecialItem) // 如果内容不可见,就把内容置空
 		resp.HasPermission = 2
 	}
-
-	go services.AddSpecialRecord(this.User, specialId)
-
 	br.Data = resp
 	br.Ret = 200
 	br.Success = true
@@ -328,7 +326,7 @@ func (this *YanxuanSpecialController) Save() {
 		br.Msg = "请至少输入一个标签"
 		return
 	}
-
+	isApprovalPersonnel := req.IsApprovalPersonnel
 	item := models.CygxYanxuanSpecial{
 		Id:           req.Id,
 		UserId:       sysUser.UserId,
@@ -348,6 +346,24 @@ func (this *YanxuanSpecialController) Save() {
 	} else {
 		item.Status = 2
 	}
+	// 如果是审批人员操作的那么就是修改内容,加审批通过
+	if isApprovalPersonnel {
+		item.Status = 3
+		//校验是否属于审核人员
+		if !services.CheckYxSpecialIsApprovalPersonnel(sysUser.Mobile) {
+			br.Msg = "操作失败"
+			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
 
@@ -369,10 +385,17 @@ func (this *YanxuanSpecialController) Save() {
 		specialId = req.Id
 	}
 
-	if req.DoType == 2 {
-		go services.SendReviewTemplateMsgAdmin(specialId)
+	if isApprovalPersonnel {
 		go services.UpdateYanxuanSpecialResourceData(specialId) //  写入首页最新  cygx_resource_data 表
 		go services.EsAddYanxuanSpecial(specialId)              //  写入es 综合搜索
+		go services.SendWxMsgSpecialFollow(req.Id)              //研选专栏有新内容审核通过时,给关注此专栏的客户发送模板消息
+		go services.SendWxMsgSpecialAuthor(req.Id, 2)           //研选专栏审核完成时,给提交人发送模板消息
+	} else {
+		if req.DoType == 2 {
+			go services.SendReviewTemplateMsgAdmin(specialId)
+			go services.UpdateYanxuanSpecialResourceData(specialId) //  写入首页最新  cygx_resource_data 表
+			go services.EsAddYanxuanSpecial(specialId)              //  写入es 综合搜索
+		}
 	}
 
 	br.Ret = 200
@@ -427,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
@@ -465,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
@@ -615,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()
@@ -636,32 +660,14 @@ func (this *YanxuanSpecialController) Record() {
 		br.ErrMsg = "参数解析失败,Err:" + err.Error()
 		return
 	}
+	specialId := req.SpecialId
+	stopTime := req.StopTime
 	if req.SpecialId <= 0 {
 		br.Msg = "文章不存在"
 		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()
@@ -1117,3 +1123,130 @@ func (this *YanxuanSpecialController) Check() {
 	br.Success = true
 	br.Msg = "校验成功"
 }
+
+// @Title 上传文章阅读时间
+// @Description 上传文章阅读时间接口
+// @Param  request	body models.AddStopTimeRep true "type json string"
+// @Success 200 {object} models.ArticleDetailResp
+// @router /addStopTime [post]
+func (this *YanxuanSpecialController) AddStopTime() {
+	br := new(models.BaseResponse).Init()
+	defer func() {
+		this.Data["json"] = br
+		this.ServeJSON()
+	}()
+	user := this.User
+	if user == nil {
+		br.Msg = "请登录"
+		br.ErrMsg = "请登录,用户信息为空"
+		br.Ret = 408
+		return
+	}
+	var req models.AddStopTimeRep
+	err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
+	if err != nil {
+		br.Msg = "参数解析异常!"
+		br.ErrMsg = "参数解析失败,Err:" + err.Error()
+		return
+	}
+	uid := user.UserId
+	articleId := req.ArticleId
+	stopTime := req.StopTime
+	outType := req.OutType
+	source := req.Source
+	if articleId <= 0 {
+		br.Msg = "参数错误"
+		br.ErrMsg = "参数错误"
+		return
+	}
+	if stopTime == 0 {
+		stopTime = 1
+	}
+	if outType != 2 {
+		outType = 1
+	}
+	if source != "PC" {
+		source = "MOBILE"
+	}
+
+	detail := new(models.ArticleDetail)
+	hasPermission := 0
+	hasFree := 0
+
+	//判断是否已经申请过
+	applyCount, err := models.GetApplyRecordCount(uid)
+	if err != nil && err.Error() != utils.ErrNoRow() {
+		br.Msg = "获取信息失败"
+		br.ErrMsg = "判断是否已申请过试用失败,Err:" + err.Error()
+		return
+	}
+	//`description:"1:有该行业权限,正常展示,2:无该行业权限,不存在权益客户下,3:无该品类权限,4:潜在客户,未提交过申请,5:潜在客户,已提交过申请"`
+	if user.CompanyId > 1 {
+		companyPermission, err := models.GetCompanyPermission(user.CompanyId)
+		if err != nil {
+			br.Msg = "获取信息失败"
+			br.ErrMsg = "判断是否已申请访谈失败,Err:" + strconv.Itoa(uid) + ";articleId" + strconv.Itoa(articleId)
+			return
+		}
+		detail, err = models.GetArticleDetailById(articleId)
+		if err != nil {
+			br.Msg = "获取信息失败"
+			br.ErrMsg = "获取文章信息失败,Err:" + err.Error() + strconv.Itoa(uid) + ";articleId" + strconv.Itoa(articleId)
+			return
+		}
+		if companyPermission == "" {
+			if applyCount > 0 {
+				hasPermission = 5
+			} else {
+				hasPermission = 2
+			}
+			hasFree = 2
+			goto Loop
+		} else {
+			hasFree = 1
+			var articlePermissionPermissionName string
+			if detail.CategoryId > 0 {
+				articlePermission, err := models.GetArticlePermission(detail.CategoryId)
+				if err != nil {
+					br.Msg = "获取信息失败"
+					br.ErrMsg = "获取报告权限失败,Err:" + err.Error() + strconv.Itoa(uid) + ";articleId" + strconv.Itoa(articleId)
+					return
+				}
+				if articlePermission == nil {
+					br.Msg = "获取信息失败"
+					br.ErrMsg = "报告权限不存在,Err:" + strconv.Itoa(uid) + ";articleId" + strconv.Itoa(articleId)
+					return
+				}
+				articlePermissionPermissionName = articlePermission.PermissionName
+			} else {
+				articlePermissionPermissionName = detail.CategoryName
+			}
+			var hasPersion bool
+			slice := strings.Split(articlePermissionPermissionName, ",")
+			for _, v := range slice {
+				if strings.Contains(companyPermission, v) {
+					hasPersion = true
+				}
+			}
+			if hasPersion {
+				go services.ArticleHistoryStopTime(articleId, stopTime, outType, user)
+			} else { //无该行业权限
+				hasPermission = 3
+			}
+		}
+	} else { //潜在客户
+		if applyCount > 0 {
+			hasPermission = 5
+		} else {
+			hasPermission = 4
+		}
+	}
+Loop:
+	resp := new(models.ArticleDetailAddStopTimeRep)
+	resp.HasPermission = hasPermission
+	resp.HasFree = hasFree
+	br.Ret = 200
+	br.Success = true
+	br.Msg = "操作成功"
+	br.Data = resp
+}

+ 31 - 10
models/cygx_yanxuan_special.go

@@ -53,6 +53,8 @@ type CygxYanxuanSpecialItem struct {
 	IndustryTags  string
 	ContentHasImg int //正文是否包含图片 1包含 0不包含
 	Docs          []Doc
+	Pv            string `description:"Pv"`
+	Uv            string `description:"Uv"`
 }
 
 type CygxYanxuanSpecialResp struct {
@@ -97,6 +99,8 @@ type CygxYanxuanSpecialCenterResp struct {
 	Docs            []Doc
 	Annotation      string `description:"核心观点"`
 	Source          string `description:"来源"`
+	Pv              string `description:"Pv"`
+	Uv              string `description:"Uv"`
 	PublishDate     string // 提审过审或驳回时间      string `description:"核心观点"`
 }
 
@@ -190,16 +194,17 @@ FROM cygx_yanxuan_special AS a
 }
 
 type CygxYanxuanSpecialReq struct {
-	Id           int    `orm:"column(id);pk"`
-	Content      string // 内容
-	Tags         string // 标签
-	DoType       int    // 1保存 2发布
-	ImgUrl       string // 图片链接
-	DocUrl       string // 文档链接
-	Title        string // 标题
-	Type         int    // 类型1:笔记,2:观点
-	IndustryTags string // 行业标签
-	CompanyTags  string // 公司标签
+	Id                  int    `orm:"column(id);pk"`
+	Content             string // 内容
+	Tags                string // 标签
+	DoType              int    // 1保存 2发布
+	ImgUrl              string // 图片链接
+	DocUrl              string // 文档链接
+	Title               string // 标题
+	Type                int    // 类型1:笔记,2:观点
+	IndustryTags        string // 行业标签
+	CompanyTags         string // 公司标签
+	IsApprovalPersonnel bool   // 是否是审批人员操作
 }
 
 func AddCygxYanxuanSpecial(item *CygxYanxuanSpecial) (lastId int64, err error) {
@@ -291,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
+}

+ 45 - 2
models/cygx_yanxuan_special_record.go

@@ -28,5 +28,48 @@ func AddCygxYanxuanSpecialRecord(item *CygxYanxuanSpecialRecord) (lastId int64,
 }
 
 type AddCygxYanxuanSpecialRecordReq struct {
-	SpecialId           int `description:"专栏文章id"`
-}
+	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),

+ 23 - 0
services/config.go

@@ -6,6 +6,7 @@ import (
 	"hongze/hongze_cygx/models"
 	"hongze/hongze_cygx/utils"
 	"strconv"
+	"strings"
 	"time"
 )
 
@@ -108,3 +109,25 @@ func AddCygxAboutUsVideoHistory(user *models.WxUserItem) (err error) {
 	_, err = models.AddCygxAboutUsVideoHistory(historyRecord)
 	return
 }
+
+// CheckYxSpecialIsApprovalPersonnel 校验手机号是否属于研选专栏的审核人员
+func CheckYxSpecialIsApprovalPersonnel(mobile string) (isApprovalPersonnel bool) {
+	var err error
+	defer func() {
+		if err != nil {
+			go utils.SendAlarmMsg(fmt.Sprint("CheckYxSpecialIsApprovalPersonnel 校验手机号是否属于研选专栏的审核人员失败, mobile:", mobile, "ErrMsg", err.Error()), 2)
+		}
+	}()
+	var configCode string
+	//获取配置项里面审核人员的手机号
+	configCode = utils.TPL_MSG_WANG_FANG_WANG_YANG
+	cnf, e := models.GetConfigByCode(configCode)
+	if e != nil {
+		err = errors.New("GetConfigByCode, Err: " + e.Error() + configCode)
+		return
+	}
+	if strings.Contains(cnf.ConfigValue, mobile) {
+		isApprovalPersonnel = true
+	}
+	return
+}

+ 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
+}

+ 94 - 21
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"
@@ -44,11 +45,10 @@ func GetStocksFromVmp(cont context.Context) (err error) {
 
 	items := make([]*models.CygxYanxuanSpecialCompany, 0)
 
-
 	for i, _ := range resp.Data {
 		items = append(items, &resp.Data[i])
 		if len(items) > 5000 {
-			err  = models.AddCygxYanxuanSpecialCompanyMulti(items)
+			err = models.AddCygxYanxuanSpecialCompanyMulti(items)
 			if err != nil {
 				fmt.Println("AddCygxYanxuanSpecialCompanyMulti Err:%s", err.Error())
 				return
@@ -57,7 +57,7 @@ func GetStocksFromVmp(cont context.Context) (err error) {
 		}
 	}
 
-	err  = models.AddCygxYanxuanSpecialCompanyMulti(items)
+	err = models.AddCygxYanxuanSpecialCompanyMulti(items)
 	if err != nil {
 		fmt.Println("AddCygxYanxuanSpecialCompanyMulti Err:%s", err.Error())
 		return
@@ -65,27 +65,100 @@ func GetStocksFromVmp(cont context.Context) (err error) {
 	return
 }
 
-func AddSpecialRecord(user *models.WxUserItem, specialId 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
-	sellerName, err := models.GetCompanySellerName(user.CompanyId)
-	if err != nil {
+	//获取销售信息
+	sellerItem, e := models.GetSellerByCompanyIdCheckFicc(user.CompanyId, 2)
+	if e != nil {
+		err = errors.New("GetSellerByCompanyIdCheckFicc, 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,
+	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
+		item.Email = user.Email
+		item.CompanyId = user.CompanyId
+		item.CompanyName = user.CompanyName
+		item.RealName = user.RealName
+		item.SellerName = sellerName
+		item.CreateTime = time.Now().Add(-time.Duration(stopTime) * time.Second) // 往前推迟的时间就是他的阅读时间
+		item.ModifyTime = time.Now()
+		item.RegisterPlatform = utils.REGISTER_PLATFORM
+		item.YanxuanSpecialId = specialId
+		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
+				}
+			}
+		}
 	}
-	_, err = models.AddCygxYanxuanSpecialRecord(&item)
-	if err != nil {
+
+	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没有删除对应的关系