Browse Source

no message

xingzai 1 year ago
parent
commit
81d906ee13

+ 50 - 36
controllers/yanxuan_special.go

@@ -234,8 +234,6 @@ func (this *YanxuanSpecialController) Detail() {
 		resp.HasPermission = 2
 	}
 
-	go services.AddSpecialRecord(this.User, specialId)
-
 	br.Data = resp
 	br.Ret = 200
 	br.Success = true
@@ -372,6 +370,7 @@ func (this *YanxuanSpecialController) Save() {
 	imgUrls := strings.Join(req.ImgUrl, ",")
 	cTags := strings.Join(req.CompanyTags, ",")
 	iTags := strings.Join(req.IndustryTags, ",")
+	isApprovalPersonnel := req.IsApprovalPersonnel
 	item := models.CygxYanxuanSpecial{
 		Id:           req.Id,
 		UserId:       sysUser.UserId,
@@ -393,15 +392,34 @@ func (this *YanxuanSpecialController) Save() {
 		item.Status = 2
 		br.Msg = "已提交审核"
 	}
+	// 如果是审批人员操作的那么就是修改内容,加审批通过
+	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
+	}
 
-	var newId int64
+	specialId := 0
 	if req.Id == 0 {
-		newId, err = models.AddCygxYanxuanSpecial(&item)
+		id, err := models.AddCygxYanxuanSpecial(&item)
 		if err != nil {
 			br.Msg = "新增失败"
 			br.ErrMsg = "新增失败,Err:" + err.Error()
 			return
 		}
+		specialId = int(id)
 	} else {
 		err = models.UpdateYanxuanSpecial(&item)
 		if err != nil {
@@ -409,17 +427,24 @@ func (this *YanxuanSpecialController) Save() {
 			br.ErrMsg = "保存失败,Err:" + err.Error()
 			return
 		}
-		newId = int64(req.Id)
+		specialId = req.Id
 	}
 
-	if req.DoType == 2 {
-		go services.SendReviewTemplateMsgAdmin(int(newId))
-		go services.UpdateYanxuanSpecialResourceData(int(newId)) //  写入首页最新  cygx_resource_data 表
-		go services.EsAddYanxuanSpecial(int(newId))              //  写入es 综合搜索
+	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
 	br.Success = true
-	br.Data = newId
+	br.Data = specialId
 }
 
 // @Title 专栏作者详情
@@ -467,8 +492,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
@@ -501,11 +526,13 @@ func (this *YanxuanSpecialController) Enable() {
 		br.ErrMsg = "审批失败, Err:" + tmpErr.Error()
 		return
 	}
-	//if req.Status == 1 {
-	//	go services.SendWxMsgSpecialFollow(req.Id)
-	//}
-	go services.UpdateYanxuanSpecialResourceData(req.Id) //  写入首页最新  cygx_resource_data 表
-	go services.EsAddYanxuanSpecial(req.Id)              //  写入es 综合搜索
+	if req.Status == 1 {
+		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.AddAddCygxYanxuanSpecialApprovalLog(user, req.Id, req.Status, req.Reason) //  写入es 综合搜索
 	br.Msg = "审批成功"
 	br.Ret = 200
 	br.Success = true
@@ -666,27 +693,14 @@ 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()
+	specialId := req.SpecialId
+	stopTime := req.StopTime
+	if req.SpecialId <= 0 {
+		br.Msg = "文章不存在"
+		br.ErrMsg = "文章不存在,文章ID错误"
 		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()

+ 38 - 9
models/cygx_yanxuan_special.go

@@ -57,6 +57,8 @@ type CygxYanxuanSpecialItem struct {
 	IndustryTags    string
 	Docs            []Doc
 	Annotation      string `description:"核心观点"`
+	Pv              string `description:"Pv"`
+	Uv              string `description:"Uv"`
 }
 
 type CygxYanxuanSpecialResp struct {
@@ -153,15 +155,16 @@ func GetYanxuanSpecialListBycondition(condition string, pars []interface{}, star
 }
 
 type CygxYanxuanSpecialReq struct {
-	Id           int      `orm:"column(id);pk"`
-	Content      string   // 内容
-	IndustryTags []string // 行业标签
-	CompanyTags  []string // 公司标签
-	DoType       int      // 1保存 2发布
-	ImgUrl       []string // 图片链接
-	Docs         []Doc    // 文档链接
-	Title        string   // 标题
-	Type         int      // 类型1:笔记,2:观点
+	Id                  int      `orm:"column(id);pk"`
+	Content             string   // 内容
+	IndustryTags        []string // 行业标签
+	CompanyTags         []string // 公司标签
+	DoType              int      // 1保存 2发布
+	ImgUrl              []string // 图片链接
+	Docs                []Doc    // 文档链接
+	Title               string   // 标题
+	Type                int      // 类型1:笔记,2:观点
+	IsApprovalPersonnel bool     // 是否是审批人员操作
 }
 
 func AddCygxYanxuanSpecial(item *CygxYanxuanSpecial) (lastId int64, err error) {
@@ -179,6 +182,16 @@ func UpdateYanxuanSpecial(item *CygxYanxuanSpecial) (err error) {
 	return
 }
 
+func GetYanxuanSpecialBySpecialId(specialId int) (item *CygxYanxuanSpecialItem, err error) {
+	o := orm.NewOrm()
+	sql := ``
+	sql = `SELECT a.*
+FROM cygx_yanxuan_special AS a
+ WHERE a.id=? `
+	err = o.Raw(sql, specialId).QueryRow(&item)
+	return
+}
+
 func GetYanxuanSpecialIndustry(keyword string) (IndustryNames []string, err error) {
 	o := orm.NewOrm()
 	sql := ``
@@ -253,3 +266,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
+}

+ 34 - 2
models/cygx_yanxuan_special_record.go

@@ -28,5 +28,37 @@ func AddCygxYanxuanSpecialRecord(item *CygxYanxuanSpecialRecord) (lastId int64,
 }
 
 type AddCygxYanxuanSpecialRecordReq struct {
-	SpecialId           int `description:"专栏文章id"`
-}
+	SpecialId int `description:"专栏文章id"`
+	StopTime  int `description:"停留时间"`
+}
+
+// 判断一个用户是否阅读过 某一篇研选专栏
+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

@@ -92,6 +92,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
+}
+
 func GetYanxuanSpecialAuthorBySpecialColumnId(specialColumnId, sysUserId int) (item *CygxYanxuanSpecialAuthorItem, err error) {
 	o := orm.NewOrm()
 	sql := ``
@@ -192,3 +200,21 @@ func GetYanxuanSpecialAuthorById(specialColumnId int) (item *CygxYanxuanSpecialA
 	err = o.Raw(sql, specialColumnId).QueryRow(&item)
 	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

@@ -91,10 +91,12 @@ func init() {
 		new(CygxReportSelectionLogApply),
 		new(CygxIndustryFllowLog),
 		new(CygxYanxuanSpecialRecord),
+		new(CygxYanxuanSpecialRecordLog),
 		new(CygxYanxuanSpecialCollect),
 		new(CygxYanxuanSpecial),
 		new(CygxYanxuanSpecialFollow),
 		new(CygxYanxuanSpecialCompany),
+		new(CygxYanxuanSpecialApprovalLog),
 		new(CygxResourceData),
 		new(CygxMorningMeetingReviewChapterHistory),
 		new(CygxAskserieVideoHistoryRecord),

+ 22 - 0
services/config.go

@@ -107,3 +107,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
+}

+ 200 - 0
services/cygx_yanxuan_special.go

@@ -6,9 +6,97 @@ import (
 	"hongze/hongze_clpt/models"
 	"hongze/hongze_clpt/utils"
 	"strconv"
+	"strings"
 	"time"
 )
 
+// 研选专栏有新内容审核通过时,给关注此专栏的客户发送模板消息
+func SendWxMsgSpecialFollow(specialId int) (err error) {
+	defer func() {
+		if err != nil {
+			go utils.SendAlarmMsg(fmt.Sprint("研选专栏有新内容审核通过时,给关注此专栏的客户发送模板消息失败", specialId, ", specialId", err.Error()), 2)
+		}
+	}()
+	var first string
+	var keyword1 string
+	var keyword2 string
+	var keyword3 string
+	var keyword4 string
+	var remark string
+
+	followers, e := models.GetYanxuanSpecialFollowUserById(specialId)
+	if e != nil {
+		err = errors.New("GetYanxuanSpecialFollowUserById, Err: " + e.Error())
+		return
+	}
+	if len(followers) == 0 {
+		return
+	}
+	specialItem, e := models.GetYanxuanSpecialItemById(specialId)
+	if e != nil {
+		err = errors.New("GetYanxuanSpecialFollowUserById, Err: " + e.Error())
+		return
+	}
+	var allInUserId string
+	for _, v := range followers {
+		allInUserId += strconv.Itoa(v) + ","
+	}
+
+	allInUserId = strings.TrimRight(allInUserId, ",")
+
+	userList, err := models.GetWxUserListByUserIds(allInUserId)
+	if err != nil && err.Error() != utils.ErrNoRow() {
+		return err
+	}
+
+	mobile := ``
+
+	for _, v := range userList {
+		mobile += v.Mobile + ","
+	}
+
+	mobile = strings.TrimRight(mobile, ",")
+
+	openIdList, e := models.GetWxOpenIdByMobileList(mobile)
+	if e != nil {
+		err = errors.New("GetSellerByAdminId, Err: " + e.Error())
+		return
+	}
+	if len(openIdList) == 0 {
+		return
+	}
+
+	//first =
+	keyword1 = "研选专栏:" + specialItem.SpecialName
+	keyword2 = "发布了新内容,点击查看详情"
+	keyword3 = "-"
+	//keyword4 = "【" + activityInfo.ResearchTheme + "】已有10人预报名"
+	openIdArr := make([]string, 0)
+	for _, v := range openIdList {
+		openIdArr = append(openIdArr, v.OpenId)
+	}
+	redirectUrl := ""
+	redirectUrl = utils.WX_MSG_PATH_YX_SPECIAL_DETAIL + strconv.Itoa(specialId)
+	sendInfo := new(SendWxTemplate)
+	sendInfo.First = first
+	sendInfo.Keyword1 = keyword1
+	sendInfo.Keyword2 = keyword2
+	sendInfo.Keyword3 = keyword3
+	sendInfo.Keyword4 = keyword4
+	sendInfo.Remark = remark
+	sendInfo.TemplateId = utils.WxMsgTemplateIdAskMsgXzs
+	sendInfo.RedirectUrl = redirectUrl
+	sendInfo.RedirectTarget = 3
+	sendInfo.Resource = strconv.Itoa(specialId)
+	sendInfo.SendType = utils.TEMPLATE_MSG_CYGX_ARTICLE_ADD
+	sendInfo.OpenIdArr = openIdArr
+	err = PublicSendTemplateMsg(sendInfo)
+	if err != nil {
+		return
+	}
+	return
+}
+
 // SendReviewTemplateMsgAdmin 提交审核时给王芳,汪洋发消息
 func SendReviewTemplateMsgAdmin(specialId int) (err error) {
 	defer func() {
@@ -73,6 +161,70 @@ func SendReviewTemplateMsgAdmin(specialId int) (err error) {
 	return
 }
 
+// 研选专栏审核完成时,给提交人发送模板消息
+func SendWxMsgSpecialAuthor(specialId, status int) (err error) {
+	defer func() {
+		if err != nil {
+			go utils.SendAlarmMsg(fmt.Sprint("研选专栏审核完成时,给提交人发送模板消息", specialId, ", specialId", err.Error()), 2)
+		}
+	}()
+	var first string
+	var keyword1 string
+	var keyword2 string
+	var keyword3 string
+	var keyword4 string
+	var remark string
+	var redirectUrl string
+
+	specialItem, e := models.GetYanxuanSpecialItemById(specialId)
+	if e != nil {
+		err = errors.New("GetYanxuanSpecialFollowUserById, Err: " + e.Error())
+		return
+	}
+	user, e := models.GetWxUserItemByUserId(specialItem.UserId)
+	if e != nil {
+		err = errors.New("GetWxUserItemByUserId, Err: " + e.Error())
+		return err
+	}
+
+	openIdList, err := models.GetUserRecordListByMobile(4, user.Mobile)
+	if err != nil && err.Error() != utils.ErrNoRow() {
+		return err
+	}
+
+	keyword1 = "研选专栏内容审核"
+	if status == 1 {
+		keyword2 = "已通过审核,点击查看详情"
+		redirectUrl = utils.WX_MSG_PATH_YX_SPECIAL_DETAIL + strconv.Itoa(specialId)
+	} else {
+		keyword2 = "未通过审核,点击查看驳回原因"
+		redirectUrl = utils.WX_MSG_PATH_YX_SPECIAL_CENTER
+	}
+	keyword3 = "-"
+	openIdArr := make([]string, 0)
+	for _, v := range openIdList {
+		openIdArr = append(openIdArr, v.OpenId)
+	}
+	sendInfo := new(SendWxTemplate)
+	sendInfo.First = first
+	sendInfo.Keyword1 = keyword1
+	sendInfo.Keyword2 = keyword2
+	sendInfo.Keyword3 = keyword3
+	sendInfo.Keyword4 = keyword4
+	sendInfo.Remark = remark
+	sendInfo.TemplateId = utils.WxMsgTemplateIdArticleUserRemind
+	sendInfo.RedirectUrl = redirectUrl
+	sendInfo.RedirectTarget = 3
+	sendInfo.Resource = strconv.Itoa(specialId)
+	sendInfo.SendType = utils.TEMPLATE_MSG_CYGX_ARTICLE_ADD
+	sendInfo.OpenIdArr = openIdArr
+	err = PublicSendTemplateMsg(sendInfo)
+	if err != nil {
+		return
+	}
+	return
+}
+
 // 更新研选专栏  写入首页最新  cygx_resource_data 表
 func UpdateYanxuanSpecialResourceData(sourceId int) {
 	var err error
@@ -189,3 +341,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
+}

+ 95 - 21
services/cygx_yanxuan_special_company.go

@@ -3,6 +3,7 @@ package services
 import (
 	"context"
 	"encoding/json"
+	"errors"
 	"fmt"
 	"hongze/hongze_clpt/models"
 	"hongze/hongze_clpt/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,101 @@ 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
+	itemLog.StopTime = stopTime
+	_, e = models.AddCygxYanxuanSpecialRecordLog(itemLog) // 添加历史记录
+	if e != nil {
+		err = errors.New("AddCygxYanxuanSpecialRecordLog, Err: " + e.Error())
 		return
 	}
-}
+	return
+}